Skip to content

Use new param API in ext/pcntl #7751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 92 additions & 69 deletions ext/pcntl/pcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -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));
Expand Down