Skip to content

Commit aa35499

Browse files
authored
Use new param API in ext/pcntl (#7751)
1 parent 9b968ff commit aa35499

File tree

1 file changed

+92
-69
lines changed

1 file changed

+92
-69
lines changed

ext/pcntl/pcntl.c

Lines changed: 92 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,7 @@ PHP_FUNCTION(pcntl_fork)
521521
{
522522
pid_t id;
523523

524-
if (zend_parse_parameters_none() == FAILURE) {
525-
RETURN_THROWS();
526-
}
524+
ZEND_PARSE_PARAMETERS_NONE();
527525

528526
id = fork();
529527
if (id == -1) {
@@ -540,9 +538,9 @@ PHP_FUNCTION(pcntl_alarm)
540538
{
541539
zend_long seconds;
542540

543-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &seconds) == FAILURE) {
544-
RETURN_THROWS();
545-
}
541+
ZEND_PARSE_PARAMETERS_START(1, 1)
542+
Z_PARAM_LONG(seconds);
543+
ZEND_PARSE_PARAMETERS_END();
546544

547545
RETURN_LONG((zend_long) alarm(seconds));
548546
}
@@ -592,9 +590,13 @@ PHP_FUNCTION(pcntl_waitpid)
592590
struct rusage rusage;
593591
#endif
594592

595-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz|lz", &pid, &z_status, &options, &z_rusage) == FAILURE) {
596-
RETURN_THROWS();
597-
}
593+
ZEND_PARSE_PARAMETERS_START(2, 4)
594+
Z_PARAM_LONG(pid)
595+
Z_PARAM_ZVAL(z_status)
596+
Z_PARAM_OPTIONAL
597+
Z_PARAM_LONG(options)
598+
Z_PARAM_ZVAL(z_rusage)
599+
ZEND_PARSE_PARAMETERS_END();
598600

599601
status = zval_get_long(z_status);
600602

@@ -641,9 +643,12 @@ PHP_FUNCTION(pcntl_wait)
641643
struct rusage rusage;
642644
#endif
643645

644-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|lz", &z_status, &options, &z_rusage) == FAILURE) {
645-
RETURN_THROWS();
646-
}
646+
ZEND_PARSE_PARAMETERS_START(1, 3)
647+
Z_PARAM_ZVAL(z_status)
648+
Z_PARAM_OPTIONAL
649+
Z_PARAM_LONG(options)
650+
Z_PARAM_ZVAL(z_rusage)
651+
ZEND_PARSE_PARAMETERS_END();
647652

648653
status = zval_get_long(z_status);
649654
#ifdef HAVE_WAIT3
@@ -689,9 +694,9 @@ PHP_FUNCTION(pcntl_wifexited)
689694
{
690695
zend_long status_word;
691696

692-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) {
693-
RETURN_THROWS();
694-
}
697+
ZEND_PARSE_PARAMETERS_START(1, 1)
698+
Z_PARAM_LONG(status_word)
699+
ZEND_PARSE_PARAMETERS_END();
695700

696701
#ifdef WIFEXITED
697702
int int_status_word = (int) status_word;
@@ -709,9 +714,9 @@ PHP_FUNCTION(pcntl_wifstopped)
709714
{
710715
zend_long status_word;
711716

712-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) {
713-
RETURN_THROWS();
714-
}
717+
ZEND_PARSE_PARAMETERS_START(1, 1)
718+
Z_PARAM_LONG(status_word)
719+
ZEND_PARSE_PARAMETERS_END();
715720

716721
#ifdef WIFSTOPPED
717722
int int_status_word = (int) status_word;
@@ -729,9 +734,9 @@ PHP_FUNCTION(pcntl_wifsignaled)
729734
{
730735
zend_long status_word;
731736

732-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) {
733-
RETURN_THROWS();
734-
}
737+
ZEND_PARSE_PARAMETERS_START(1, 1)
738+
Z_PARAM_LONG(status_word)
739+
ZEND_PARSE_PARAMETERS_END();
735740

736741
#ifdef WIFSIGNALED
737742
int int_status_word = (int) status_word;
@@ -743,14 +748,15 @@ PHP_FUNCTION(pcntl_wifsignaled)
743748
RETURN_FALSE;
744749
}
745750
/* }}} */
751+
746752
/* {{{ Returns true if the child status code represents a process that was resumed due to a SIGCONT signal */
747753
PHP_FUNCTION(pcntl_wifcontinued)
748754
{
749755
zend_long status_word;
750756

751-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) {
752-
RETURN_THROWS();
753-
}
757+
ZEND_PARSE_PARAMETERS_START(1, 1)
758+
Z_PARAM_LONG(status_word)
759+
ZEND_PARSE_PARAMETERS_END();
754760

755761
#ifdef HAVE_WCONTINUED
756762
int int_status_word = (int) status_word;
@@ -768,9 +774,9 @@ PHP_FUNCTION(pcntl_wexitstatus)
768774
{
769775
zend_long status_word;
770776

771-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) {
772-
RETURN_THROWS();
773-
}
777+
ZEND_PARSE_PARAMETERS_START(1, 1)
778+
Z_PARAM_LONG(status_word)
779+
ZEND_PARSE_PARAMETERS_END();
774780

775781
#ifdef WEXITSTATUS
776782
int int_status_word = (int) status_word;
@@ -786,9 +792,9 @@ PHP_FUNCTION(pcntl_wtermsig)
786792
{
787793
zend_long status_word;
788794

789-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) {
790-
RETURN_THROWS();
791-
}
795+
ZEND_PARSE_PARAMETERS_START(1, 1)
796+
Z_PARAM_LONG(status_word)
797+
ZEND_PARSE_PARAMETERS_END();
792798

793799
#ifdef WTERMSIG
794800
int int_status_word = (int) status_word;
@@ -804,9 +810,9 @@ PHP_FUNCTION(pcntl_wstopsig)
804810
{
805811
zend_long status_word;
806812

807-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) {
808-
RETURN_THROWS();
809-
}
813+
ZEND_PARSE_PARAMETERS_START(1, 1)
814+
Z_PARAM_LONG(status_word)
815+
ZEND_PARSE_PARAMETERS_END();
810816

811817
#ifdef WSTOPSIG
812818
int int_status_word = (int) status_word;
@@ -833,9 +839,12 @@ PHP_FUNCTION(pcntl_exec)
833839
size_t path_len;
834840
zend_ulong key_num;
835841

836-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|aa", &path, &path_len, &args, &envs) == FAILURE) {
837-
RETURN_THROWS();
838-
}
842+
ZEND_PARSE_PARAMETERS_START(1, 3)
843+
Z_PARAM_PATH(path, path_len)
844+
Z_PARAM_OPTIONAL
845+
Z_PARAM_ARRAY(args)
846+
Z_PARAM_ARRAY(envs)
847+
ZEND_PARSE_PARAMETERS_END();
839848

840849
if (ZEND_NUM_ARGS() > 1) {
841850
/* Build argument list */
@@ -932,9 +941,12 @@ PHP_FUNCTION(pcntl_signal)
932941
bool restart_syscalls_is_null = 1;
933942
char *error = NULL;
934943

935-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz|b!", &signo, &handle, &restart_syscalls, &restart_syscalls_is_null) == FAILURE) {
936-
RETURN_THROWS();
937-
}
944+
ZEND_PARSE_PARAMETERS_START(2, 3)
945+
Z_PARAM_LONG(signo)
946+
Z_PARAM_ZVAL(handle)
947+
Z_PARAM_OPTIONAL
948+
Z_PARAM_BOOL_OR_NULL(restart_syscalls, restart_syscalls_is_null)
949+
ZEND_PARSE_PARAMETERS_END();
938950

939951
if (signo < 1) {
940952
zend_argument_value_error(1, "must be greater than or equal to 1");
@@ -1011,9 +1023,9 @@ PHP_FUNCTION(pcntl_signal_get_handler)
10111023
zval *prev_handle;
10121024
zend_long signo;
10131025

1014-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &signo) == FAILURE) {
1015-
RETURN_THROWS();
1016-
}
1026+
ZEND_PARSE_PARAMETERS_START(1, 1)
1027+
Z_PARAM_LONG(signo)
1028+
ZEND_PARSE_PARAMETERS_END();
10171029

10181030
if (signo < 1 || signo > 32) {
10191031
zend_argument_value_error(1, "must be between 1 and 32");
@@ -1030,9 +1042,7 @@ PHP_FUNCTION(pcntl_signal_get_handler)
10301042
/* {{{ Dispatch signals to signal handlers */
10311043
PHP_FUNCTION(pcntl_signal_dispatch)
10321044
{
1033-
if (zend_parse_parameters_none() == FAILURE) {
1034-
RETURN_THROWS();
1035-
}
1045+
ZEND_PARSE_PARAMETERS_NONE();
10361046

10371047
pcntl_signal_dispatch();
10381048
RETURN_TRUE;
@@ -1047,9 +1057,12 @@ PHP_FUNCTION(pcntl_sigprocmask)
10471057
zval *user_set, *user_oldset = NULL, *user_signo;
10481058
sigset_t set, oldset;
10491059

1050-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "la|z", &how, &user_set, &user_oldset) == FAILURE) {
1051-
RETURN_THROWS();
1052-
}
1060+
ZEND_PARSE_PARAMETERS_START(2, 3)
1061+
Z_PARAM_LONG(how)
1062+
Z_PARAM_ARRAY(user_set)
1063+
Z_PARAM_OPTIONAL
1064+
Z_PARAM_ZVAL(user_oldset)
1065+
ZEND_PARSE_PARAMETERS_END();
10531066

10541067
if (sigemptyset(&set) != 0 || sigemptyset(&oldset) != 0) {
10551068
PCNTL_G(last_error) = errno;
@@ -1103,13 +1116,19 @@ static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{
11031116
struct timespec timeout;
11041117

11051118
if (timedwait) {
1106-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|zll", &user_set, &user_siginfo, &tv_sec, &tv_nsec) == FAILURE) {
1107-
RETURN_THROWS();
1108-
}
1119+
ZEND_PARSE_PARAMETERS_START(1, 4)
1120+
Z_PARAM_ARRAY(user_set)
1121+
Z_PARAM_OPTIONAL
1122+
Z_PARAM_ZVAL(user_siginfo)
1123+
Z_PARAM_LONG(tv_sec)
1124+
Z_PARAM_LONG(tv_nsec)
1125+
ZEND_PARSE_PARAMETERS_END();
11091126
} else {
1110-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|z", &user_set, &user_siginfo) == FAILURE) {
1111-
RETURN_THROWS();
1112-
}
1127+
ZEND_PARSE_PARAMETERS_START(1, 2)
1128+
Z_PARAM_ARRAY(user_set)
1129+
Z_PARAM_OPTIONAL
1130+
Z_PARAM_ZVAL(user_siginfo)
1131+
ZEND_PARSE_PARAMETERS_END();
11131132
}
11141133

11151134
if (sigemptyset(&set) != 0) {
@@ -1231,9 +1250,11 @@ PHP_FUNCTION(pcntl_getpriority)
12311250
bool pid_is_null = 1;
12321251
int pri;
12331252

1234-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!l", &pid, &pid_is_null, &who) == FAILURE) {
1235-
RETURN_THROWS();
1236-
}
1253+
ZEND_PARSE_PARAMETERS_START(0, 2)
1254+
Z_PARAM_OPTIONAL
1255+
Z_PARAM_LONG_OR_NULL(pid, pid_is_null)
1256+
Z_PARAM_LONG(who)
1257+
ZEND_PARSE_PARAMETERS_END();
12371258

12381259
/* needs to be cleared, since any returned value is valid */
12391260
errno = 0;
@@ -1270,9 +1291,12 @@ PHP_FUNCTION(pcntl_setpriority)
12701291
bool pid_is_null = 1;
12711292
zend_long pri;
12721293

1273-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l!l", &pri, &pid, &pid_is_null, &who) == FAILURE) {
1274-
RETURN_THROWS();
1275-
}
1294+
ZEND_PARSE_PARAMETERS_START(1, 3)
1295+
Z_PARAM_LONG(pri)
1296+
Z_PARAM_OPTIONAL
1297+
Z_PARAM_LONG_OR_NULL(pid, pid_is_null)
1298+
Z_PARAM_LONG(who)
1299+
ZEND_PARSE_PARAMETERS_END();
12761300

12771301
if (setpriority(who, pid_is_null ? getpid() : pid, pri)) {
12781302
PCNTL_G(last_error) = errno;
@@ -1304,9 +1328,7 @@ PHP_FUNCTION(pcntl_setpriority)
13041328
/* {{{ Retrieve the error number set by the last pcntl function which failed. */
13051329
PHP_FUNCTION(pcntl_get_last_error)
13061330
{
1307-
if (zend_parse_parameters_none() == FAILURE) {
1308-
RETURN_THROWS();
1309-
}
1331+
ZEND_PARSE_PARAMETERS_NONE();
13101332

13111333
RETURN_LONG(PCNTL_G(last_error));
13121334
}
@@ -1317,9 +1339,9 @@ PHP_FUNCTION(pcntl_strerror)
13171339
{
13181340
zend_long error;
13191341

1320-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &error) == FAILURE) {
1321-
RETURN_THROWS();
1322-
}
1342+
ZEND_PARSE_PARAMETERS_START(1, 1)
1343+
Z_PARAM_LONG(error)
1344+
ZEND_PARSE_PARAMETERS_END();
13231345

13241346
RETURN_STRING(strerror(error));
13251347
}
@@ -1437,9 +1459,10 @@ PHP_FUNCTION(pcntl_async_signals)
14371459
{
14381460
bool on, on_is_null = 1;
14391461

1440-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b!", &on, &on_is_null) == FAILURE) {
1441-
RETURN_THROWS();
1442-
}
1462+
ZEND_PARSE_PARAMETERS_START(0, 1)
1463+
Z_PARAM_OPTIONAL
1464+
Z_PARAM_BOOL_OR_NULL(on, on_is_null)
1465+
ZEND_PARSE_PARAMETERS_END();
14431466

14441467
if (on_is_null) {
14451468
RETURN_BOOL(PCNTL_G(async_signals));

0 commit comments

Comments
 (0)