diff --git a/ext/standard/array.c b/ext/standard/array.c index 73a5f1ee4a328..1a5c8f795ff9f 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -372,7 +372,7 @@ DEFINE_SORT_VARIANTS(data_compare_string_locale); DEFINE_SORT_VARIANTS(natural_compare); DEFINE_SORT_VARIANTS(natural_case_compare); -static bucket_compare_func_t php_get_key_compare_func(zend_long sort_type, int reverse) /* {{{ */ +static bucket_compare_func_t php_get_key_compare_func(zend_long sort_type, bool reverse) /* {{{ */ { switch (sort_type & ~PHP_SORT_FLAG_CASE) { case PHP_SORT_NUMERIC: @@ -436,7 +436,7 @@ static bucket_compare_func_t php_get_key_compare_func(zend_long sort_type, int r } /* }}} */ -static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int reverse) /* {{{ */ +static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, bool reverse) /* {{{ */ { switch (sort_type & ~PHP_SORT_FLAG_CASE) { case PHP_SORT_NUMERIC: @@ -500,7 +500,7 @@ static bucket_compare_func_t php_get_data_compare_func(zend_long sort_type, int } /* }}} */ -static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_type, int reverse) /* {{{ */ +static bucket_compare_func_t php_get_data_compare_func_unstable(zend_long sort_type, bool reverse) /* {{{ */ { switch (sort_type & ~PHP_SORT_FLAG_CASE) { case PHP_SORT_NUMERIC: @@ -577,9 +577,9 @@ PHP_FUNCTION(krsort) Z_PARAM_LONG(sort_type) ZEND_PARSE_PARAMETERS_END(); - cmp = php_get_key_compare_func(sort_type, 1); + cmp = php_get_key_compare_func(sort_type, true); - zend_hash_sort(Z_ARRVAL_P(array), cmp, 0); + zend_hash_sort(Z_ARRVAL_P(array), cmp, false); RETURN_TRUE; } @@ -598,9 +598,9 @@ PHP_FUNCTION(ksort) Z_PARAM_LONG(sort_type) ZEND_PARSE_PARAMETERS_END(); - cmp = php_get_key_compare_func(sort_type, 0); + cmp = php_get_key_compare_func(sort_type, false); - zend_hash_sort(Z_ARRVAL_P(array), cmp, 0); + zend_hash_sort(Z_ARRVAL_P(array), cmp, false); RETURN_TRUE; } @@ -691,7 +691,7 @@ PHP_FUNCTION(count) } /* }}} */ -static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, int fold_case) /* {{{ */ +static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, bool fold_case) /* {{{ */ { zval *array; @@ -700,9 +700,9 @@ static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, int fold_case) /* {{{ */ ZEND_PARSE_PARAMETERS_END(); if (fold_case) { - zend_array_sort(Z_ARRVAL_P(array), php_array_natural_case_compare, 0); + zend_array_sort(Z_ARRVAL_P(array), php_array_natural_case_compare, false); } else { - zend_array_sort(Z_ARRVAL_P(array), php_array_natural_compare, 0); + zend_array_sort(Z_ARRVAL_P(array), php_array_natural_compare, false); } RETURN_TRUE; @@ -712,14 +712,14 @@ static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, int fold_case) /* {{{ */ /* {{{ Sort an array using natural sort */ PHP_FUNCTION(natsort) { - php_natsort(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + php_natsort(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); } /* }}} */ /* {{{ Sort an array using case-insensitive natural sort */ PHP_FUNCTION(natcasesort) { - php_natsort(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_natsort(INTERNAL_FUNCTION_PARAM_PASSTHRU, true); } /* }}} */ @@ -736,9 +736,9 @@ PHP_FUNCTION(asort) Z_PARAM_LONG(sort_type) ZEND_PARSE_PARAMETERS_END(); - cmp = php_get_data_compare_func(sort_type, 0); + cmp = php_get_data_compare_func(sort_type, false); - zend_array_sort(Z_ARRVAL_P(array), cmp, 0); + zend_array_sort(Z_ARRVAL_P(array), cmp, false); RETURN_TRUE; } @@ -757,9 +757,9 @@ PHP_FUNCTION(arsort) Z_PARAM_LONG(sort_type) ZEND_PARSE_PARAMETERS_END(); - cmp = php_get_data_compare_func(sort_type, 1); + cmp = php_get_data_compare_func(sort_type, true); - zend_array_sort(Z_ARRVAL_P(array), cmp, 0); + zend_array_sort(Z_ARRVAL_P(array), cmp, false); RETURN_TRUE; } @@ -778,9 +778,9 @@ PHP_FUNCTION(sort) Z_PARAM_LONG(sort_type) ZEND_PARSE_PARAMETERS_END(); - cmp = php_get_data_compare_func(sort_type, 0); + cmp = php_get_data_compare_func(sort_type, false); - zend_array_sort(Z_ARRVAL_P(array), cmp, 1); + zend_array_sort(Z_ARRVAL_P(array), cmp, true); RETURN_TRUE; } @@ -799,9 +799,9 @@ PHP_FUNCTION(rsort) Z_PARAM_LONG(sort_type) ZEND_PARSE_PARAMETERS_END(); - cmp = php_get_data_compare_func(sort_type, 1); + cmp = php_get_data_compare_func(sort_type, true); - zend_array_sort(Z_ARRVAL_P(array), cmp, 1); + zend_array_sort(Z_ARRVAL_P(array), cmp, true); RETURN_TRUE; } @@ -914,14 +914,14 @@ static void php_usort(INTERNAL_FUNCTION_PARAMETERS, bucket_compare_func_t compar /* {{{ Sort an array by values using a user-defined comparison function */ PHP_FUNCTION(usort) { - php_usort(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_array_user_compare, 1); + php_usort(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_array_user_compare, true); } /* }}} */ /* {{{ Sort an array with a user-defined comparison function and maintain index association */ PHP_FUNCTION(uasort) { - php_usort(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_array_user_compare, 0); + php_usort(INTERNAL_FUNCTION_PARAM_PASSTHRU, php_array_user_compare, false); } /* }}} */ @@ -1627,11 +1627,7 @@ PHP_FUNCTION(array_walk_recursive) } /* }}} */ -/* void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) - * 0 = return boolean - * 1 = return key - */ -static inline void _php_search_array(zval *return_value, zval *value, zval *array, bool strict, int behavior) /* {{{ */ +static inline void _php_search_array(zval *return_value, zval *value, zval *array, bool strict, bool return_as_keys) { zval *entry; /* pointer to array entry */ zend_ulong num_idx; @@ -1642,14 +1638,14 @@ static inline void _php_search_array(zval *return_value, zval *value, zval *arra ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG && Z_LVAL_P(entry) == Z_LVAL_P(value)) { - if (behavior == 0) { - RETURN_TRUE; - } else { + if (return_as_keys) { if (str_idx) { RETURN_STR_COPY(str_idx); } else { RETURN_LONG(num_idx); } + } else { + RETURN_TRUE; } } } ZEND_HASH_FOREACH_END(); @@ -1657,14 +1653,14 @@ static inline void _php_search_array(zval *return_value, zval *value, zval *arra ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (fast_is_identical_function(value, entry)) { - if (behavior == 0) { - RETURN_TRUE; - } else { + if (return_as_keys) { if (str_idx) { RETURN_STR_COPY(str_idx); } else { RETURN_LONG(num_idx); } + } else { + RETURN_TRUE; } } } ZEND_HASH_FOREACH_END(); @@ -1673,42 +1669,42 @@ static inline void _php_search_array(zval *return_value, zval *value, zval *arra if (Z_TYPE_P(value) == IS_LONG) { ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_long(value, entry)) { - if (behavior == 0) { - RETURN_TRUE; - } else { + if (return_as_keys) { if (str_idx) { RETURN_STR_COPY(str_idx); } else { RETURN_LONG(num_idx); } + } else { + RETURN_TRUE; } } } ZEND_HASH_FOREACH_END(); } else if (Z_TYPE_P(value) == IS_STRING) { ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_string(value, entry)) { - if (behavior == 0) { - RETURN_TRUE; - } else { + if (return_as_keys) { if (str_idx) { RETURN_STR_COPY(str_idx); } else { RETURN_LONG(num_idx); } + } else { + RETURN_TRUE; } } } ZEND_HASH_FOREACH_END(); } else { ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_function(value, entry)) { - if (behavior == 0) { - RETURN_TRUE; - } else { + if (return_as_keys) { if (str_idx) { RETURN_STR_COPY(str_idx); } else { RETURN_LONG(num_idx); } + } else { + RETURN_TRUE; } } } ZEND_HASH_FOREACH_END(); @@ -1717,13 +1713,8 @@ static inline void _php_search_array(zval *return_value, zval *value, zval *arra RETURN_FALSE; } -/* }}} */ -/* void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) - * 0 = return boolean - * 1 = return key - */ -static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) +static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, bool return_as_keys) { zval *value, /* value to check for */ *array; /* array to check in */ @@ -1736,13 +1727,13 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) Z_PARAM_BOOL(strict) ZEND_PARSE_PARAMETERS_END(); - _php_search_array(return_value, value, array, strict, behavior); + _php_search_array(return_value, value, array, strict, return_as_keys); } /* {{{ Checks if the given value exists in the array */ PHP_FUNCTION(in_array) { - php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); } /* }}} */ @@ -1753,7 +1744,7 @@ ZEND_FRAMELESS_FUNCTION(in_array, 2) Z_FLF_PARAM_ZVAL(1, value); Z_FLF_PARAM_ARRAY(2, array); - _php_search_array(return_value, value, array, false, 0); + _php_search_array(return_value, value, array, false, false); flf_clean:; } @@ -1767,7 +1758,7 @@ ZEND_FRAMELESS_FUNCTION(in_array, 3) Z_FLF_PARAM_ARRAY(2, array); Z_FLF_PARAM_BOOL(3, strict); - _php_search_array(return_value, value, array, strict, 0); + _php_search_array(return_value, value, array, strict, false); flf_clean:; } @@ -1775,11 +1766,11 @@ flf_clean:; /* {{{ Searches the array for a given value and returns the corresponding key if successful */ PHP_FUNCTION(array_search) { - php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, true); } /* }}} */ -static zend_always_inline int php_valid_var_name(const char *var_name, size_t var_name_len) /* {{{ */ +static zend_always_inline bool php_valid_var_name(const char *var_name, size_t var_name_len) /* {{{ */ { #if 1 /* first 256 bits for first character, and second 256 bits for the next */ @@ -1796,7 +1787,7 @@ static zend_always_inline int php_valid_var_name(const char *var_name, size_t va uint32_t ch; if (UNEXPECTED(!var_name_len)) { - return 0; + return false; } /* These are allowed as first char: [a-zA-Z_\x7f-\xff] */ @@ -1810,7 +1801,7 @@ static zend_always_inline int php_valid_var_name(const char *var_name, size_t va (ch < 127 /* 0x7f */ || /* 0xff */ ch > 255) ) { #endif - return 0; + return false; } /* And these as the rest: [a-zA-Z0-9_\x7f-\xff] */ @@ -1828,11 +1819,11 @@ static zend_always_inline int php_valid_var_name(const char *var_name, size_t va (ch < 127 /* 0x7f */ || /* 0xff */ ch > 255) ) { #endif - return 0; + return false; } } while (++i < var_name_len); } - return 1; + return true; } /* }}} */ @@ -3672,7 +3663,7 @@ PHP_FUNCTION(array_shift) Z_ARRVAL_P(stack)->nNextFreeElement = k; } else { uint32_t k = 0; - int should_rehash = 0; + bool should_rehash = false; Bucket *p; /* Get the first value and copy it into the return value */ @@ -3699,7 +3690,7 @@ PHP_FUNCTION(array_shift) if (p->key == NULL) { if (p->h != k) { p->h = k++; - should_rehash = 1; + should_rehash = true; } else { k++; } @@ -3778,8 +3769,8 @@ PHP_FUNCTION(array_splice) HashTable *rem_hash = NULL; zend_long offset, length = 0; - bool length_is_null = 1; - int num_in; /* Number of elements in the input array */ + bool length_is_null = true; + uint32_t num_in; /* Number of elements in the input array */ ZEND_PARSE_PARAMETERS_START(2, 4) Z_PARAM_ARRAY_EX(array, 0, 1) @@ -3815,7 +3806,7 @@ PHP_FUNCTION(array_splice) /* ..and the length */ if (length < 0) { size = num_in - offset + length; - } else if (((zend_ulong) offset + (zend_ulong) length) > (uint32_t) num_in) { + } else if (((zend_ulong) offset + (zend_ulong) length) > num_in) { size = num_in - offset; } @@ -4014,7 +4005,7 @@ PHP_FUNCTION(array_slice) } /* }}} */ -PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ +PHPAPI bool php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ { zval *src_entry, *dest_entry; zend_string *string_key; @@ -4026,14 +4017,13 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ zval *dest_zval = dest_entry; HashTable *thash; zval tmp; - int ret; ZVAL_DEREF(src_zval); ZVAL_DEREF(dest_zval); thash = Z_TYPE_P(dest_zval) == IS_ARRAY ? Z_ARRVAL_P(dest_zval) : NULL; if ((thash && GC_IS_RECURSIVE(thash)) || (src_entry == dest_entry && Z_ISREF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) { zend_throw_error(NULL, "Recursion detected"); - return 0; + return false; } ZEND_ASSERT(!Z_ISREF_P(dest_entry) || Z_REFCOUNT_P(dest_entry) > 1); @@ -4057,12 +4047,12 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ if (thash) { GC_TRY_PROTECT_RECURSION(thash); } - ret = php_array_merge_recursive(Z_ARRVAL_P(dest_zval), Z_ARRVAL_P(src_zval)); + bool was_correctly_merged = php_array_merge_recursive(Z_ARRVAL_P(dest_zval), Z_ARRVAL_P(src_zval)); if (thash) { GC_TRY_UNPROTECT_RECURSION(thash); } - if (!ret) { - return 0; + if (!was_correctly_merged) { + return false; } } else { Z_TRY_ADDREF_P(src_zval); @@ -4070,7 +4060,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ if (EXPECTED(!zv)) { Z_TRY_DELREF_P(src_zval); zend_cannot_add_element(); - return 0; + return false; } } zval_ptr_dtor(&tmp); @@ -4082,12 +4072,12 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ zval *zv = zend_hash_next_index_insert(dest, src_entry); if (UNEXPECTED(!zv)) { zend_cannot_add_element(); - return 0; + return false; } zval_add_ref(zv); } } ZEND_HASH_FOREACH_END(); - return 1; + return true; } /* }}} */ @@ -4097,7 +4087,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */ zend_string *string_key; if (HT_IS_PACKED(dest) && HT_IS_PACKED(src)) { - zend_hash_extend(dest, zend_hash_num_elements(dest) + zend_hash_num_elements(src), 1); + zend_hash_extend(dest, zend_hash_num_elements(dest) + zend_hash_num_elements(src), true); ZEND_HASH_FILL_PACKED(dest) { ZEND_HASH_PACKED_FOREACH_VAL(src, src_entry) { if (UNEXPECTED(Z_ISREF_P(src_entry)) && @@ -4126,12 +4116,11 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */ } /* }}} */ -PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ */ +PHPAPI bool php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ */ { zval *src_entry, *dest_entry, *src_zval, *dest_zval; zend_string *string_key; zend_ulong num_key; - int ret; ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { src_zval = src_entry; @@ -4164,7 +4153,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ * Z_IS_RECURSIVE_P(src_zval) || (Z_ISREF_P(src_entry) && Z_ISREF_P(dest_entry) && Z_REF_P(src_entry) == Z_REF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) { zend_throw_error(NULL, "Recursion detected"); - return 0; + return false; } ZEND_ASSERT(!Z_ISREF_P(dest_entry) || Z_REFCOUNT_P(dest_entry) > 1); @@ -4178,7 +4167,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ * Z_PROTECT_RECURSION_P(src_zval); } - ret = php_array_replace_recursive(Z_ARRVAL_P(dest_zval), Z_ARRVAL_P(src_zval)); + bool was_replaced_correctly = php_array_replace_recursive(Z_ARRVAL_P(dest_zval), Z_ARRVAL_P(src_zval)); if (Z_REFCOUNTED_P(dest_zval)) { Z_UNPROTECT_RECURSION_P(dest_zval); @@ -4187,16 +4176,16 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ * Z_UNPROTECT_RECURSION_P(src_zval); } - if (!ret) { - return 0; + if (!was_replaced_correctly) { + return false; } } ZEND_HASH_FOREACH_END(); - return 1; + return true; } /* }}} */ -static zend_always_inline void php_array_replace_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive) /* {{{ */ +static zend_always_inline void php_array_replace_wrapper(INTERNAL_FUNCTION_PARAMETERS, bool recursive) /* {{{ */ { zval *args = NULL; zval *arg; @@ -4246,7 +4235,7 @@ static zend_always_inline void php_array_replace_wrapper(INTERNAL_FUNCTION_PARAM } /* }}} */ -static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive) /* {{{ */ +static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, bool recursive) /* {{{ */ { zval *args = NULL; zval *arg; @@ -4371,28 +4360,28 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET /* {{{ Merges elements from passed arrays into one array */ PHP_FUNCTION(array_merge) { - php_array_merge_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + php_array_merge_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); } /* }}} */ /* {{{ Recursively merges elements from passed arrays into one array */ PHP_FUNCTION(array_merge_recursive) { - php_array_merge_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_array_merge_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, true); } /* }}} */ /* {{{ Replaces elements from passed arrays into one array */ PHP_FUNCTION(array_replace) { - php_array_replace_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + php_array_replace_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); } /* }}} */ /* {{{ Recursively replaces elements from passed arrays into one array */ PHP_FUNCTION(array_replace_recursive) { - php_array_replace_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_array_replace_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, true); } /* }}} */ @@ -4632,10 +4621,10 @@ PHP_FUNCTION(array_column) zval *colval, *data, rv; zend_string *column_str = NULL; zend_long column_long = 0; - bool column_is_null = 0; + bool column_is_null = false; zend_string *index_str = NULL; zend_long index_long = 0; - bool index_is_null = 1; + bool index_is_null = true; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_ARRAY_HT(input) @@ -4764,8 +4753,7 @@ PHP_FUNCTION(array_pad) if (input_size >= pad_size_abs) { /* Copy the original array */ - ZVAL_COPY(return_value, input); - return; + RETURN_COPY(input); } num_pads = pad_size_abs - input_size; @@ -4927,8 +4915,7 @@ PHP_FUNCTION(array_unique) ZEND_PARSE_PARAMETERS_END(); if (Z_ARRVAL_P(array)->nNumOfElements <= 1) { /* nothing to do */ - ZVAL_COPY(return_value, array); - return; + RETURN_COPY(array); } if (sort_type == PHP_SORT_STRING) { @@ -4970,7 +4957,7 @@ PHP_FUNCTION(array_unique) return; } - cmp = php_get_data_compare_func_unstable(sort_type, 0); + cmp = php_get_data_compare_func_unstable(sort_type, false); bool in_place = zend_may_modify_arg_in_place(array); if (in_place) { @@ -6515,8 +6502,7 @@ PHP_FUNCTION(array_filter) ZEND_PARSE_PARAMETERS_END(); if (zend_hash_num_elements(Z_ARRVAL_P(array)) == 0) { - RETVAL_EMPTY_ARRAY(); - return; + RETURN_EMPTY_ARRAY(); } array_init(return_value); @@ -6743,12 +6729,11 @@ PHP_FUNCTION(array_all) PHP_FUNCTION(array_map) { zval *arrays = NULL; - int n_arrays = 0; + uint32_t n_arrays = 0; zval result; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fci_cache = empty_fcall_info_cache; - int i; - uint32_t k, maxlen = 0; + uint32_t maxlen = 0; ZEND_PARSE_PARAMETERS_START(2, -1) Z_PARAM_FUNC_OR_NULL(fci, fci_cache) @@ -6759,7 +6744,6 @@ PHP_FUNCTION(array_map) zend_ulong num_key; zend_string *str_key; zval *zv, arg; - int ret; if (Z_TYPE(arrays[0]) != IS_ARRAY) { zend_argument_type_error(2, "must be of type array, %s given", zend_zval_value_name(&arrays[0])); @@ -6769,8 +6753,7 @@ PHP_FUNCTION(array_map) /* Short-circuit: if no callback and only one array, just return it. */ if (!ZEND_FCI_INITIALIZED(fci) || !maxlen) { - ZVAL_COPY(return_value, &arrays[0]); - return; + RETURN_COPY(&arrays[0]); } array_init_size(return_value, maxlen); @@ -6782,7 +6765,7 @@ PHP_FUNCTION(array_map) fci.params = &arg; ZVAL_COPY(&arg, zv); - ret = zend_call_function(&fci, &fci_cache); + zend_result ret = zend_call_function(&fci, &fci_cache); i_zval_ptr_dtor(&arg); if (ret != SUCCESS || Z_TYPE(result) == IS_UNDEF) { zend_array_destroy(Z_ARR_P(return_value)); @@ -6797,7 +6780,7 @@ PHP_FUNCTION(array_map) } else { uint32_t *array_pos = (HashPosition *)ecalloc(n_arrays, sizeof(HashPosition)); - for (i = 0; i < n_arrays; i++) { + for (uint32_t i = 0; i < n_arrays; i++) { if (Z_TYPE(arrays[i]) != IS_ARRAY) { zend_argument_type_error(i + 2, "must be of type array, %s given", zend_zval_value_name(&arrays[i])); efree(array_pos); @@ -6814,13 +6797,13 @@ PHP_FUNCTION(array_map) zval zv; /* We iterate through all the arrays at once. */ - for (k = 0; k < maxlen; k++) { + for (uint32_t k = 0; k < maxlen; k++) { /* If no callback, the result will be an array, consisting of current * entries from all arrays. */ array_init_size(&result, n_arrays); - for (i = 0; i < n_arrays; i++) { + for (uint32_t i = 0; i < n_arrays; i++) { /* If this array still has elements, add the current one to the * parameter list, otherwise use null value. */ uint32_t pos = array_pos[i]; @@ -6858,8 +6841,8 @@ PHP_FUNCTION(array_map) zval *params = (zval *)safe_emalloc(n_arrays, sizeof(zval), 0); /* We iterate through all the arrays at once. */ - for (k = 0; k < maxlen; k++) { - for (i = 0; i < n_arrays; i++) { + for (uint32_t k = 0; k < maxlen; k++) { + for (uint32_t i = 0; i < n_arrays; i++) { /* If this array still has elements, add the current one to the * parameter list, otherwise use null value. */ uint32_t pos = array_pos[i]; @@ -6897,13 +6880,13 @@ PHP_FUNCTION(array_map) if (zend_call_function(&fci, &fci_cache) != SUCCESS || Z_TYPE(result) == IS_UNDEF) { efree(array_pos); zend_array_destroy(Z_ARR_P(return_value)); - for (i = 0; i < n_arrays; i++) { + for (uint32_t i = 0; i < n_arrays; i++) { zval_ptr_dtor(¶ms[i]); } efree(params); RETURN_NULL(); } else { - for (i = 0; i < n_arrays; i++) { + for (uint32_t i = 0; i < n_arrays; i++) { zval_ptr_dtor(¶ms[i]); } } @@ -6962,7 +6945,6 @@ PHP_FUNCTION(array_key_exists) /* {{{ Split array into chunks */ PHP_FUNCTION(array_chunk) { - int num_in; zend_long size, current = 0; zend_string *str_key; zend_ulong num_key; @@ -6984,12 +6966,11 @@ PHP_FUNCTION(array_chunk) RETURN_THROWS(); } - num_in = zend_hash_num_elements(Z_ARRVAL_P(input)); + uint32_t num_in = zend_hash_num_elements(Z_ARRVAL_P(input)); if (size > num_in) { if (num_in == 0) { - RETVAL_EMPTY_ARRAY(); - return; + RETURN_EMPTY_ARRAY(); } size = num_in; } @@ -7037,15 +7018,14 @@ PHP_FUNCTION(array_combine) HashTable *values, *keys; uint32_t pos_values = 0; zval *entry_keys, *entry_values; - int num_keys, num_values; 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); + uint32_t num_keys = zend_hash_num_elements(keys); + uint32_t num_values = zend_hash_num_elements(values); if (num_keys != num_values) { zend_argument_value_error(1, "and argument #2 ($values) must have the same number of elements"); diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h index 2a35af6038083..1998e460352bf 100644 --- a/ext/standard/php_array.h +++ b/ext/standard/php_array.h @@ -26,8 +26,8 @@ PHP_MINIT_FUNCTION(array); PHP_MSHUTDOWN_FUNCTION(array); PHPAPI int php_array_merge(HashTable *dest, HashTable *src); -PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src); -PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src); +PHPAPI bool php_array_merge_recursive(HashTable *dest, HashTable *src); +PHPAPI bool php_array_replace_recursive(HashTable *dest, HashTable *src); PHPAPI int php_multisort_compare(const void *a, const void *b); PHPAPI zend_long php_count_recursive(HashTable *ht);