Skip to content

Commit cebe750

Browse files
committed
Refactor ZPP API to use uint32_t as everywhere else
Closes phpGH-5609
1 parent bc3ee2e commit cebe750

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

Zend/zend_API.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ ZEND_API int ZEND_FASTCALL zend_parse_arg_str_or_long_slow(zval *arg, zend_strin
527527
}
528528
/* }}} */
529529

530-
static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, const char **spec, char **error) /* {{{ */
530+
static const char *zend_parse_arg_impl(zval *arg, va_list *va, const char **spec, char **error) /* {{{ */
531531
{
532532
const char *spec_walk = *spec;
533533
char c = *spec_walk++;
@@ -796,12 +796,12 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons
796796
}
797797
/* }}} */
798798

799-
static int zend_parse_arg(int arg_num, zval *arg, va_list *va, const char **spec, int flags) /* {{{ */
799+
static int zend_parse_arg(uint32_t arg_num, zval *arg, va_list *va, const char **spec, int flags) /* {{{ */
800800
{
801801
const char *expected_type = NULL;
802802
char *error = NULL;
803803

804-
expected_type = zend_parse_arg_impl(arg_num, arg, va, spec, &error);
804+
expected_type = zend_parse_arg_impl(arg, va, spec, &error);
805805
if (expected_type) {
806806
if (EG(exception)) {
807807
return FAILURE;
@@ -824,7 +824,7 @@ static int zend_parse_arg(int arg_num, zval *arg, va_list *va, const char **spec
824824
}
825825
/* }}} */
826826

827-
ZEND_API int zend_parse_parameter(int flags, int arg_num, zval *arg, const char *spec, ...)
827+
ZEND_API int zend_parse_parameter(int flags, uint32_t arg_num, zval *arg, const char *spec, ...)
828828
{
829829
va_list va;
830830
int ret;
@@ -845,16 +845,17 @@ static ZEND_COLD void zend_parse_parameters_debug_error(const char *msg) {
845845
ZSTR_VAL(active_function->common.function_name), msg);
846846
}
847847

848-
static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va, int flags) /* {{{ */
848+
static int zend_parse_va_args(uint32_t num_args, const char *type_spec, va_list *va, int flags) /* {{{ */
849849
{
850850
const char *spec_walk;
851-
int c, i;
852-
int min_num_args = -1;
853-
int max_num_args = 0;
854-
int post_varargs = 0;
851+
char c;
852+
uint32_t i;
853+
uint32_t min_num_args = 0;
854+
uint32_t max_num_args = 0;
855+
uint32_t post_varargs = 0;
855856
zval *arg;
856-
int arg_count;
857857
zend_bool have_varargs = 0;
858+
zend_bool have_optional_args = 0;
858859
zval **varargs = NULL;
859860
int *n_varargs = NULL;
860861

@@ -876,6 +877,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
876877

877878
case '|':
878879
min_num_args = max_num_args;
880+
have_optional_args = 1;
879881
break;
880882

881883
case '/':
@@ -905,17 +907,18 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
905907
}
906908
}
907909

908-
if (min_num_args < 0) {
910+
/* with no optional arguments the minimum number of arguments must be the same as the maximum */
911+
if (!have_optional_args) {
909912
min_num_args = max_num_args;
910913
}
911914

912915
if (have_varargs) {
913916
/* calculate how many required args are at the end of the specifier list */
914917
post_varargs = max_num_args - post_varargs;
915-
max_num_args = -1;
918+
max_num_args = UINT32_MAX;
916919
}
917920

918-
if (num_args < min_num_args || (num_args > max_num_args && max_num_args >= 0)) {
921+
if (num_args < min_num_args || num_args > max_num_args) {
919922
if (!(flags & ZEND_PARSE_PARAMS_QUIET)) {
920923
zend_function *active_function = EG(current_execute_data)->func;
921924
const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
@@ -931,9 +934,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
931934
return FAILURE;
932935
}
933936

934-
arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
935-
936-
if (num_args > arg_count) {
937+
if (num_args > ZEND_CALL_NUM_ARGS(EG(current_execute_data))) {
937938
zend_parse_parameters_debug_error("could not obtain parameters for parsing");
938939
return FAILURE;
939940
}
@@ -981,7 +982,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
981982
}
982983
/* }}} */
983984

984-
ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...) /* {{{ */
985+
ZEND_API int zend_parse_parameters_ex(int flags, uint32_t num_args, const char *type_spec, ...) /* {{{ */
985986
{
986987
va_list va;
987988
int retval;
@@ -994,7 +995,7 @@ ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_
994995
}
995996
/* }}} */
996997

997-
ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...) /* {{{ */
998+
ZEND_API int zend_parse_parameters(uint32_t num_args, const char *type_spec, ...) /* {{{ */
998999
{
9991000
va_list va;
10001001
int retval;
@@ -1008,7 +1009,7 @@ ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...) /*
10081009
}
10091010
/* }}} */
10101011

1011-
ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...) /* {{{ */
1012+
ZEND_API int zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec, ...) /* {{{ */
10121013
{
10131014
va_list va;
10141015
int retval;
@@ -1048,7 +1049,7 @@ ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const ch
10481049
}
10491050
/* }}} */
10501051

1051-
ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this_ptr, const char *type_spec, ...) /* {{{ */
1052+
ZEND_API int zend_parse_method_parameters_ex(int flags, uint32_t num_args, zval *this_ptr, const char *type_spec, ...) /* {{{ */
10521053
{
10531054
va_list va;
10541055
int retval;

Zend/zend_API.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,18 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
295295

296296
#define ZEND_PARSE_PARAMS_THROW 0 /* No longer used, zpp always uses exceptions */
297297
#define ZEND_PARSE_PARAMS_QUIET (1<<1)
298-
ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...);
299-
ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...);
298+
ZEND_API int zend_parse_parameters(uint32_t num_args, const char *type_spec, ...);
299+
ZEND_API int zend_parse_parameters_ex(int flags, uint32_t num_args, const char *type_spec, ...);
300300
/* NOTE: This must have at least one value in __VA_ARGS__ for the expression to be valid */
301301
#define zend_parse_parameters_throw(num_args, ...) \
302302
zend_parse_parameters(num_args, __VA_ARGS__)
303303
ZEND_API const char *zend_zval_type_name(const zval *arg);
304304
ZEND_API zend_string *zend_zval_get_legacy_type(const zval *arg);
305305

306-
ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...);
307-
ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this_ptr, const char *type_spec, ...);
306+
ZEND_API int zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
307+
ZEND_API int zend_parse_method_parameters_ex(int flags, uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
308308

309-
ZEND_API int zend_parse_parameter(int flags, int arg_num, zval *arg, const char *spec, ...);
309+
ZEND_API int zend_parse_parameter(int flags, uint32_t arg_num, zval *arg, const char *spec, ...);
310310

311311
/* End of parameter parsing API -- andrei */
312312

0 commit comments

Comments
 (0)