From: Sara Golemon Date: Fri, 30 Dec 2016 18:32:03 +0000 (-0800) Subject: Use new param API in standard/array X-Git-Tag: php-7.2.0alpha1~722 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b0edb3c6c331c5514fa853483d55fb99b195cac;p=php Use new param API in standard/array --- diff --git a/ext/standard/array.c b/ext/standard/array.c index 6098bdbbb8..d5d5c00339 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -839,9 +839,9 @@ static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, int fold_case) /* {{{ */ { zval *array; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/", &array) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY_EX(array, 0, 1) + ZEND_PARSE_PARAMETERS_END(); if (fold_case) { if (zend_hash_sort(Z_ARRVAL_P(array), php_array_natural_case_compare, 0) == FAILURE) { @@ -881,9 +881,11 @@ PHP_FUNCTION(asort) zend_long sort_type = PHP_SORT_REGULAR; compare_func_t cmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY_EX(array, 0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(sort_type) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); cmp = php_get_data_compare_func(sort_type, 0); @@ -902,9 +904,11 @@ PHP_FUNCTION(arsort) zend_long sort_type = PHP_SORT_REGULAR; compare_func_t cmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY_EX(array, 0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(sort_type) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); cmp = php_get_data_compare_func(sort_type, 1); @@ -923,9 +927,11 @@ PHP_FUNCTION(sort) zend_long sort_type = PHP_SORT_REGULAR; compare_func_t cmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY_EX(array, 0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(sort_type) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); cmp = php_get_data_compare_func(sort_type, 0); @@ -944,9 +950,11 @@ PHP_FUNCTION(rsort) zend_long sort_type = PHP_SORT_REGULAR; compare_func_t cmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY_EX(array, 0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(sort_type) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); cmp = php_get_data_compare_func(sort_type, 1); @@ -1026,10 +1034,10 @@ static void php_usort(INTERNAL_FUNCTION_PARAMETERS, compare_func_t compare_func, PHP_ARRAY_CMP_FUNC_BACKUP(); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "af", &array, &BG(user_compare_fci), &BG(user_compare_fci_cache)) == FAILURE) { - PHP_ARRAY_CMP_FUNC_RESTORE(); - return; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY(array) + Z_PARAM_FUNC(BG(user_compare_fci), BG(user_compare_fci_cache)) + ZEND_PARSE_PARAMETERS_END_EX( PHP_ARRAY_CMP_FUNC_RESTORE(); return ); arr = Z_ARR_P(array); if (zend_hash_num_elements(arr) == 0) { @@ -1274,9 +1282,9 @@ PHP_FUNCTION(min) int argc; zval *args = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, -1) + Z_PARAM_VARIADIC('+', args, argc) + ZEND_PARSE_PARAMETERS_END(); /* mixed min ( array $values ) */ if (argc == 1) { @@ -1321,9 +1329,9 @@ PHP_FUNCTION(max) zval *args = NULL; int argc; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, -1) + Z_PARAM_VARIADIC('+', args, argc) + ZEND_PARSE_PARAMETERS_END(); /* mixed max ( array $values ) */ if (argc == 1) { @@ -1533,11 +1541,16 @@ PHP_FUNCTION(array_walk_recursive) orig_array_walk_fci = BG(array_walk_fci); orig_array_walk_fci_cache = BG(array_walk_fci_cache); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "A/f|z/", &array, &BG(array_walk_fci), &BG(array_walk_fci_cache), &userdata) == FAILURE) { + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY_OR_OBJECT_EX(array, 0, 1) + Z_PARAM_FUNC(BG(array_walk_fci), BG(array_walk_fci_cache)) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_DEREF_EX(userdata, 0, 1) + ZEND_PARSE_PARAMETERS_END_EX( BG(array_walk_fci) = orig_array_walk_fci; BG(array_walk_fci_cache) = orig_array_walk_fci_cache; - return; - } + return + ); php_array_walk(array, userdata, 1); BG(array_walk_fci) = orig_array_walk_fci; @@ -1938,9 +1951,9 @@ PHP_FUNCTION(compact) uint32_t num_args, i; zend_array *symbol_table; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &num_args) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, -1) + Z_PARAM_VARIADIC('+', args, num_args) + ZEND_PARSE_PARAMETERS_END(); if (zend_forbid_dynamic_call("compact()") == FAILURE) { return; @@ -1954,13 +1967,13 @@ PHP_FUNCTION(compact) /* compact() is probably most used with a single array of var_names or multiple string names, rather than a combination of both. So quickly guess a minimum result size based on that */ - if (ZEND_NUM_ARGS() == 1 && Z_TYPE(args[0]) == IS_ARRAY) { + if (num_args && Z_TYPE(args[0]) == IS_ARRAY) { array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL(args[0]))); } else { - array_init_size(return_value, ZEND_NUM_ARGS()); + array_init_size(return_value, num_args); } - for (i=0; i 2) { @@ -5231,9 +5270,12 @@ PHP_FUNCTION(array_filter) zend_fcall_info_cache fci_cache = empty_fcall_info_cache; zend_ulong num_key; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|fl", &array, &fci, &fci_cache, &use_type) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ARRAY(array) + Z_PARAM_OPTIONAL + Z_PARAM_FUNC(fci, fci_cache) + Z_PARAM_LONG(use_type) + ZEND_PARSE_PARAMETERS_END(); array_init(return_value); if (zend_hash_num_elements(Z_ARRVAL_P(array)) == 0) { @@ -5501,7 +5543,7 @@ PHP_FUNCTION(array_key_exists) Split array into chunks */ PHP_FUNCTION(array_chunk) { - int argc = ZEND_NUM_ARGS(), num_in; + int num_in; zend_long size, current = 0; zend_string *str_key; zend_ulong num_key; @@ -5510,9 +5552,13 @@ PHP_FUNCTION(array_chunk) zval chunk; zval *entry; - if (zend_parse_parameters(argc, "al|b", &input, &size, &preserve_keys) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(input) + Z_PARAM_LONG(size) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(preserve_keys) + ZEND_PARSE_PARAMETERS_END(); + /* Do bounds checking for size parameter. */ if (size < 1) { php_error_docref(NULL, E_WARNING, "Size parameter expected to be greater than 0"); @@ -5571,9 +5617,10 @@ PHP_FUNCTION(array_combine) zval *entry_keys, *entry_values; int num_keys, num_values; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "hh", &keys, &values) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY_HT(keys) + Z_PARAM_ARRAY_HT(values) + ZEND_PARSE_PARAMETERS_END(); num_keys = zend_hash_num_elements(keys); num_values = zend_hash_num_elements(values);