From a5223cc1bb59e17ab563312c6945de6e9a112642 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 9 Jul 2024 20:33:09 +0100 Subject: [PATCH] ext/pcntl adding Pcntl namespace for Qos class. --- ext/pcntl/pcntl.c | 6 +- ext/pcntl/pcntl.stub.php | 107 +++++++++++++++------------- ext/pcntl/pcntl_arginfo.h | 16 ++--- ext/pcntl/tests/pcntl_qosclass.phpt | 8 +-- 4 files changed, 68 insertions(+), 69 deletions(-) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 6e206f950a90..cf66057fc8f6 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -123,7 +123,6 @@ typedef psetid_t cpu_set_t; #if defined(HAVE_PTHREAD_SET_QOS_CLASS_SELF_NP) #include -static zend_class_entry *QosClass_ce; #endif #ifdef HAVE_PIDFD_OPEN @@ -144,6 +143,7 @@ static zend_class_entry *QosClass_ce; #include "Zend/zend_max_execution_timer.h" #include "pcntl_arginfo.h" +static zend_class_entry *QosClass_ce; ZEND_DECLARE_MODULE_GLOBALS(pcntl) static PHP_GINIT_FUNCTION(pcntl); @@ -212,9 +212,7 @@ PHP_RINIT_FUNCTION(pcntl) PHP_MINIT_FUNCTION(pcntl) { -#if defined(HAVE_PTHREAD_SET_QOS_CLASS_SELF_NP) - QosClass_ce = register_class_QosClass(); -#endif + QosClass_ce = register_class_Pcntl_QosClass(); register_pcntl_symbols(module_number); orig_interrupt_function = zend_interrupt_function; zend_interrupt_function = pcntl_interrupt_function; diff --git a/ext/pcntl/pcntl.stub.php b/ext/pcntl/pcntl.stub.php index 7b72c0045396..bdae57414b4c 100644 --- a/ext/pcntl/pcntl.stub.php +++ b/ext/pcntl/pcntl.stub.php @@ -4,6 +4,8 @@ /* Wait Constants */ +namespace +{ #ifdef WNOHANG /** * @var int @@ -995,120 +997,123 @@ const PCNTL_ECAPMODE = UNKNOWN; #endif -function pcntl_fork(): int {} + function pcntl_fork(): int {} -/** - * @param int $status - * @param array $resource_usage - */ -function pcntl_waitpid(int $process_id, &$status, int $flags = 0, &$resource_usage = []): int {} + /** + * @param int $status + * @param array $resource_usage + */ + function pcntl_waitpid(int $process_id, &$status, int $flags = 0, &$resource_usage = []): int {} #if defined (HAVE_WAITID) && defined (HAVE_POSIX_IDTYPES) && defined (HAVE_DECL_WEXITED) && HAVE_DECL_WEXITED == 1 -/** @param array $info */ -function pcntl_waitid(int $idtype = P_ALL, ?int $id = null, &$info = [], int $flags = WEXITED): bool {} + /** @param array $info */ + function pcntl_waitid(int $idtype = P_ALL, ?int $id = null, &$info = [], int $flags = WEXITED): bool {} #endif -/** - * @param int $status - * @param array $resource_usage - */ -function pcntl_wait(&$status, int $flags = 0, &$resource_usage = []): int {} + /** + * @param int $status + * @param array $resource_usage + */ + function pcntl_wait(&$status, int $flags = 0, &$resource_usage = []): int {} -/** @param callable|int $handler */ -function pcntl_signal(int $signal, $handler, bool $restart_syscalls = true): bool {} + /** @param callable|int $handler */ + function pcntl_signal(int $signal, $handler, bool $restart_syscalls = true): bool {} -/** @return callable|int */ -function pcntl_signal_get_handler(int $signal) {} + /** @return callable|int */ + function pcntl_signal_get_handler(int $signal) {} -function pcntl_signal_dispatch(): bool {} + function pcntl_signal_dispatch(): bool {} #ifdef HAVE_SIGPROCMASK /** @param array $old_signals */ -function pcntl_sigprocmask(int $mode, array $signals, &$old_signals = null): bool {} + function pcntl_sigprocmask(int $mode, array $signals, &$old_signals = null): bool {} #endif #ifdef HAVE_STRUCT_SIGINFO_T #if (defined(HAVE_SIGWAITINFO) && defined(HAVE_SIGTIMEDWAIT)) -/** @param array $info */ -function pcntl_sigwaitinfo(array $signals, &$info = []): int|false {} + /** @param array $info */ + function pcntl_sigwaitinfo(array $signals, &$info = []): int|false {} -/** @param array $info */ -function pcntl_sigtimedwait(array $signals, &$info = [], int $seconds = 0, int $nanoseconds = 0): int|false {} + /** @param array $info */ + function pcntl_sigtimedwait(array $signals, &$info = [], int $seconds = 0, int $nanoseconds = 0): int|false {} #endif #endif -function pcntl_wifexited(int $status): bool {} + function pcntl_wifexited(int $status): bool {} -function pcntl_wifstopped(int $status): bool {} + function pcntl_wifstopped(int $status): bool {} #ifdef HAVE_WCONTINUED function pcntl_wifcontinued(int $status): bool {} #endif -function pcntl_wifsignaled(int $status): bool {} + function pcntl_wifsignaled(int $status): bool {} -function pcntl_wexitstatus(int $status): int|false {} + function pcntl_wexitstatus(int $status): int|false {} -function pcntl_wtermsig(int $status): int|false {} + function pcntl_wtermsig(int $status): int|false {} -function pcntl_wstopsig(int $status): int|false {} + function pcntl_wstopsig(int $status): int|false {} -function pcntl_exec(string $path, array $args = [], array $env_vars = []): bool {} + function pcntl_exec(string $path, array $args = [], array $env_vars = []): bool {} -function pcntl_alarm(int $seconds): int {} + function pcntl_alarm(int $seconds): int {} -function pcntl_get_last_error(): int {} + function pcntl_get_last_error(): int {} -/** @alias pcntl_get_last_error */ -function pcntl_errno(): int {} + /** @alias pcntl_get_last_error */ + function pcntl_errno(): int {} #ifdef HAVE_GETPRIORITY -function pcntl_getpriority(?int $process_id = null, int $mode = PRIO_PROCESS): int|false {} + function pcntl_getpriority(?int $process_id = null, int $mode = PRIO_PROCESS): int|false {} #endif #ifdef HAVE_SETPRIORITY -function pcntl_setpriority(int $priority, ?int $process_id = null, int $mode = PRIO_PROCESS): bool{} + function pcntl_setpriority(int $priority, ?int $process_id = null, int $mode = PRIO_PROCESS): bool{} #endif -function pcntl_strerror(int $error_code): string {} + function pcntl_strerror(int $error_code): string {} -function pcntl_async_signals(?bool $enable = null): bool {} + function pcntl_async_signals(?bool $enable = null): bool {} #ifdef HAVE_UNSHARE -function pcntl_unshare(int $flags): bool {} + function pcntl_unshare(int $flags): bool {} #endif #ifdef HAVE_RFORK -function pcntl_rfork(int $flags, int $signal = 0): int{} + function pcntl_rfork(int $flags, int $signal = 0): int{} #endif #ifdef HAVE_FORKX -function pcntl_forkx(int $flags): int{} + function pcntl_forkx(int $flags): int{} #endif #ifdef HAVE_PIDFD_OPEN -function pcntl_setns(?int $process_id = null, int $nstype = CLONE_NEWNET): bool {} + function pcntl_setns(?int $process_id = null, int $nstype = CLONE_NEWNET): bool {} #endif #ifdef HAVE_SCHED_SETAFFINITY -function pcntl_getcpuaffinity(?int $process_id = null): array|false {} -function pcntl_setcpuaffinity(?int $process_id = null, array $cpu_ids = []): bool {} + function pcntl_getcpuaffinity(?int $process_id = null): array|false {} + function pcntl_setcpuaffinity(?int $process_id = null, array $cpu_ids = []): bool {} #endif #ifdef HAVE_SCHED_GETCPU -function pcntl_getcpu(): int {} + function pcntl_getcpu(): int {} #endif - #ifdef HAVE_PTHREAD_SET_QOS_CLASS_SELF_NP -enum QosClass + function pcntl_getqos_class(): Pcntl\QosClass {} + function pcntl_setqos_class(Pcntl\QosClass $qos_class = Pcntl\QosClass::Default): void {} +#endif +} + +namespace Pcntl { + enum QosClass + { case UserInteractive; case UserInitiated; case Default; case Utility; case Background; + } } - -function pcntl_getqos_class(): QosClass {} -function pcntl_setqos_class(QosClass $qos_class = QosClass::Default): void {} -#endif diff --git a/ext/pcntl/pcntl_arginfo.h b/ext/pcntl/pcntl_arginfo.h index c919bbc1007b..c7a90e138372 100644 --- a/ext/pcntl/pcntl_arginfo.h +++ b/ext/pcntl/pcntl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 71d0cbd8d2b1ae57d289ec421e9dcaa4040d857b */ + * Stub hash: 897062ad1dfe06326e561429509360174820379e */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pcntl_fork, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -167,13 +167,13 @@ ZEND_END_ARG_INFO() #endif #if defined(HAVE_PTHREAD_SET_QOS_CLASS_SELF_NP) -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_pcntl_getqos_class, 0, 0, QosClass, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_pcntl_getqos_class, 0, 0, Pcntl\\QosClass, 0) ZEND_END_ARG_INFO() #endif #if defined(HAVE_PTHREAD_SET_QOS_CLASS_SELF_NP) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pcntl_setqos_class, 0, 0, IS_VOID, 0) - ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, qos_class, QosClass, 0, "QosClass::Default") + ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, qos_class, Pcntl\\QosClass, 0, "Pcntl\\QosClass::Default") ZEND_END_ARG_INFO() #endif @@ -313,11 +313,9 @@ static const zend_function_entry ext_functions[] = { ZEND_FE_END }; -#if defined(HAVE_PTHREAD_SET_QOS_CLASS_SELF_NP) -static const zend_function_entry class_QosClass_methods[] = { +static const zend_function_entry class_Pcntl_QosClass_methods[] = { ZEND_FE_END }; -#endif static void register_pcntl_symbols(int module_number) { @@ -712,10 +710,9 @@ static void register_pcntl_symbols(int module_number) #endif } -#if defined(HAVE_PTHREAD_SET_QOS_CLASS_SELF_NP) -static zend_class_entry *register_class_QosClass(void) +static zend_class_entry *register_class_Pcntl_QosClass(void) { - zend_class_entry *class_entry = zend_register_internal_enum("QosClass", IS_UNDEF, class_QosClass_methods); + zend_class_entry *class_entry = zend_register_internal_enum("Pcntl\\QosClass", IS_UNDEF, class_Pcntl_QosClass_methods); zend_enum_add_case_cstr(class_entry, "UserInteractive", NULL); @@ -729,4 +726,3 @@ static zend_class_entry *register_class_QosClass(void) return class_entry; } -#endif diff --git a/ext/pcntl/tests/pcntl_qosclass.phpt b/ext/pcntl/tests/pcntl_qosclass.phpt index 61b425928869..f8ca1a706bd2 100644 --- a/ext/pcntl/tests/pcntl_qosclass.phpt +++ b/ext/pcntl/tests/pcntl_qosclass.phpt @@ -9,10 +9,10 @@ if (getenv('SKIP_REPEAT')) die("skip Not repeatable"); ?> --FILE-- --EXPECT-- bool(true)