From 2f17af7fa209e6d693c7ab884690990a146aee39 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Fri, 10 Dec 2021 17:28:22 +0100 Subject: [PATCH] Use new param API in ext/pcntl --- ext/pcntl/pcntl.c | 161 ++++++++++++++++++++++++++-------------------- 1 file changed, 92 insertions(+), 69 deletions(-) diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 645b211952b9f..61fe69d123e93 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -521,9 +521,7 @@ PHP_FUNCTION(pcntl_fork) { pid_t id; - if (zend_parse_parameters_none() == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_NONE(); id = fork(); if (id == -1) { @@ -540,9 +538,9 @@ PHP_FUNCTION(pcntl_alarm) { zend_long seconds; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &seconds) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(seconds); + ZEND_PARSE_PARAMETERS_END(); RETURN_LONG((zend_long) alarm(seconds)); } @@ -592,9 +590,13 @@ PHP_FUNCTION(pcntl_waitpid) struct rusage rusage; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz|lz", &pid, &z_status, &options, &z_rusage) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_LONG(pid) + Z_PARAM_ZVAL(z_status) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(options) + Z_PARAM_ZVAL(z_rusage) + ZEND_PARSE_PARAMETERS_END(); status = zval_get_long(z_status); @@ -641,9 +643,12 @@ PHP_FUNCTION(pcntl_wait) struct rusage rusage; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|lz", &z_status, &options, &z_rusage) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ZVAL(z_status) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(options) + Z_PARAM_ZVAL(z_rusage) + ZEND_PARSE_PARAMETERS_END(); status = zval_get_long(z_status); #ifdef HAVE_WAIT3 @@ -689,9 +694,9 @@ PHP_FUNCTION(pcntl_wifexited) { zend_long status_word; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(status_word) + ZEND_PARSE_PARAMETERS_END(); #ifdef WIFEXITED int int_status_word = (int) status_word; @@ -709,9 +714,9 @@ PHP_FUNCTION(pcntl_wifstopped) { zend_long status_word; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(status_word) + ZEND_PARSE_PARAMETERS_END(); #ifdef WIFSTOPPED int int_status_word = (int) status_word; @@ -729,9 +734,9 @@ PHP_FUNCTION(pcntl_wifsignaled) { zend_long status_word; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(status_word) + ZEND_PARSE_PARAMETERS_END(); #ifdef WIFSIGNALED int int_status_word = (int) status_word; @@ -743,14 +748,15 @@ PHP_FUNCTION(pcntl_wifsignaled) RETURN_FALSE; } /* }}} */ + /* {{{ Returns true if the child status code represents a process that was resumed due to a SIGCONT signal */ PHP_FUNCTION(pcntl_wifcontinued) { zend_long status_word; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(status_word) + ZEND_PARSE_PARAMETERS_END(); #ifdef HAVE_WCONTINUED int int_status_word = (int) status_word; @@ -768,9 +774,9 @@ PHP_FUNCTION(pcntl_wexitstatus) { zend_long status_word; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(status_word) + ZEND_PARSE_PARAMETERS_END(); #ifdef WEXITSTATUS int int_status_word = (int) status_word; @@ -786,9 +792,9 @@ PHP_FUNCTION(pcntl_wtermsig) { zend_long status_word; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(status_word) + ZEND_PARSE_PARAMETERS_END(); #ifdef WTERMSIG int int_status_word = (int) status_word; @@ -804,9 +810,9 @@ PHP_FUNCTION(pcntl_wstopsig) { zend_long status_word; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(status_word) + ZEND_PARSE_PARAMETERS_END(); #ifdef WSTOPSIG int int_status_word = (int) status_word; @@ -833,9 +839,12 @@ PHP_FUNCTION(pcntl_exec) size_t path_len; zend_ulong key_num; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|aa", &path, &path_len, &args, &envs) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_PATH(path, path_len) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY(args) + Z_PARAM_ARRAY(envs) + ZEND_PARSE_PARAMETERS_END(); if (ZEND_NUM_ARGS() > 1) { /* Build argument list */ @@ -932,9 +941,12 @@ PHP_FUNCTION(pcntl_signal) bool restart_syscalls_is_null = 1; char *error = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz|b!", &signo, &handle, &restart_syscalls, &restart_syscalls_is_null) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_LONG(signo) + Z_PARAM_ZVAL(handle) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL_OR_NULL(restart_syscalls, restart_syscalls_is_null) + ZEND_PARSE_PARAMETERS_END(); if (signo < 1) { zend_argument_value_error(1, "must be greater than or equal to 1"); @@ -1011,9 +1023,9 @@ PHP_FUNCTION(pcntl_signal_get_handler) zval *prev_handle; zend_long signo; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &signo) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(signo) + ZEND_PARSE_PARAMETERS_END(); if (signo < 1 || signo > 32) { zend_argument_value_error(1, "must be between 1 and 32"); @@ -1030,9 +1042,7 @@ PHP_FUNCTION(pcntl_signal_get_handler) /* {{{ Dispatch signals to signal handlers */ PHP_FUNCTION(pcntl_signal_dispatch) { - if (zend_parse_parameters_none() == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_NONE(); pcntl_signal_dispatch(); RETURN_TRUE; @@ -1047,9 +1057,12 @@ PHP_FUNCTION(pcntl_sigprocmask) zval *user_set, *user_oldset = NULL, *user_signo; sigset_t set, oldset; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "la|z", &how, &user_set, &user_oldset) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_LONG(how) + Z_PARAM_ARRAY(user_set) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL(user_oldset) + ZEND_PARSE_PARAMETERS_END(); if (sigemptyset(&set) != 0 || sigemptyset(&oldset) != 0) { PCNTL_G(last_error) = errno; @@ -1103,13 +1116,19 @@ static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{ struct timespec timeout; if (timedwait) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|zll", &user_set, &user_siginfo, &tv_sec, &tv_nsec) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 4) + Z_PARAM_ARRAY(user_set) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL(user_siginfo) + Z_PARAM_LONG(tv_sec) + Z_PARAM_LONG(tv_nsec) + ZEND_PARSE_PARAMETERS_END(); } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|z", &user_set, &user_siginfo) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(user_set) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL(user_siginfo) + ZEND_PARSE_PARAMETERS_END(); } if (sigemptyset(&set) != 0) { @@ -1231,9 +1250,11 @@ PHP_FUNCTION(pcntl_getpriority) bool pid_is_null = 1; int pri; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!l", &pid, &pid_is_null, &who) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(0, 2) + Z_PARAM_OPTIONAL + Z_PARAM_LONG_OR_NULL(pid, pid_is_null) + Z_PARAM_LONG(who) + ZEND_PARSE_PARAMETERS_END(); /* needs to be cleared, since any returned value is valid */ errno = 0; @@ -1270,9 +1291,12 @@ PHP_FUNCTION(pcntl_setpriority) bool pid_is_null = 1; zend_long pri; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l!l", &pri, &pid, &pid_is_null, &who) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_LONG(pri) + Z_PARAM_OPTIONAL + Z_PARAM_LONG_OR_NULL(pid, pid_is_null) + Z_PARAM_LONG(who) + ZEND_PARSE_PARAMETERS_END(); if (setpriority(who, pid_is_null ? getpid() : pid, pri)) { PCNTL_G(last_error) = errno; @@ -1304,9 +1328,7 @@ PHP_FUNCTION(pcntl_setpriority) /* {{{ Retrieve the error number set by the last pcntl function which failed. */ PHP_FUNCTION(pcntl_get_last_error) { - if (zend_parse_parameters_none() == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_NONE(); RETURN_LONG(PCNTL_G(last_error)); } @@ -1317,9 +1339,9 @@ PHP_FUNCTION(pcntl_strerror) { zend_long error; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &error) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(error) + ZEND_PARSE_PARAMETERS_END(); RETURN_STRING(strerror(error)); } @@ -1437,9 +1459,10 @@ PHP_FUNCTION(pcntl_async_signals) { bool on, on_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b!", &on, &on_is_null) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL_OR_NULL(on, on_is_null) + ZEND_PARSE_PARAMETERS_END(); if (on_is_null) { RETURN_BOOL(PCNTL_G(async_signals));