From 5acedabfc04ddbb53d68a52a4ebcccca3090cbdc Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 3 Sep 2019 09:43:22 +0200 Subject: Clarify failure behavior of spl_iterator_apply() It only fails if it throws, in which case it is meaningless to set a return value. --- ext/spl/php_spl.c | 2 -- ext/spl/spl_iterators.c | 21 ++++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index e4e1774bd7..c509c24759 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -983,11 +983,9 @@ static const zend_function_entry spl_functions[] = { PHP_FE(class_uses, arginfo_class_uses) PHP_FE(spl_object_hash, arginfo_spl_object_hash) PHP_FE(spl_object_id, arginfo_spl_object_id) -#ifdef SPL_ITERATORS_H PHP_FE(iterator_to_array, arginfo_iterator_to_array) PHP_FE(iterator_count, arginfo_iterator) PHP_FE(iterator_apply, arginfo_iterator_apply) -#endif /* SPL_ITERATORS_H */ PHP_FE_END }; /* }}} */ diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 8c3c2b454e..cce9477ed5 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -3573,11 +3573,7 @@ PHP_FUNCTION(iterator_to_array) } array_init(return_value); - - if (spl_iterator_apply(obj, use_keys ? spl_iterator_to_array_apply : spl_iterator_to_values_apply, (void*)return_value) != SUCCESS) { - zval_ptr_dtor(return_value); - RETURN_NULL(); - } + spl_iterator_apply(obj, use_keys ? spl_iterator_to_array_apply : spl_iterator_to_values_apply, (void*)return_value); } /* }}} */ static int spl_iterator_count_apply(zend_object_iterator *iter, void *puser) /* {{{ */ @@ -3598,9 +3594,11 @@ PHP_FUNCTION(iterator_count) RETURN_FALSE; } - if (spl_iterator_apply(obj, spl_iterator_count_apply, (void*)&count) == SUCCESS) { - RETURN_LONG(count); + if (spl_iterator_apply(obj, spl_iterator_count_apply, (void*)&count) == FAILURE) { + return; } + + RETURN_LONG(count); } /* }}} */ @@ -3639,12 +3637,13 @@ PHP_FUNCTION(iterator_apply) apply_info.count = 0; zend_fcall_info_args(&apply_info.fci, apply_info.args); - if (spl_iterator_apply(apply_info.obj, spl_iterator_func_apply, (void*)&apply_info) == SUCCESS) { - RETVAL_LONG(apply_info.count); - } else { - RETVAL_FALSE; + if (spl_iterator_apply(apply_info.obj, spl_iterator_func_apply, (void*)&apply_info) == FAILURE) { + zend_fcall_info_args(&apply_info.fci, NULL); + return; } + zend_fcall_info_args(&apply_info.fci, NULL); + RETURN_LONG(apply_info.count); } /* }}} */ -- cgit v1.2.1 From c0e9b1532e13d97196d67d687d4c3bc1d6918537 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 3 Sep 2019 09:50:08 +0200 Subject: Add zpp check to spl_classes() --- ext/spl/php_spl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index c509c24759..b147a96128 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -237,6 +237,10 @@ PHP_FUNCTION(class_uses) Return an array containing the names of all clsses and interfaces defined in SPL */ PHP_FUNCTION(spl_classes) { + if (zend_parse_parameters_none() == FAILURE) { + return; + } + array_init(return_value); SPL_LIST_CLASSES(return_value, 0, 0, 0) -- cgit v1.2.1 From 1a905bcb1effab8909138fff1c7ef38682ce3fea Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Mon, 2 Sep 2019 22:14:11 -0400 Subject: Add new missing functions from ext/hash --- ext/opcache/Optimizer/zend_func_info.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 0582b54f67..a06ac05b6b 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -1207,9 +1207,12 @@ static const func_info_t func_infos[] = { /* ext/hash */ F1("hash", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING), + F0("hash_equals", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE), F1("hash_file", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING), F1("hash_hmac", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING), + F1("hash_hmac_algos", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING), F1("hash_hmac_file", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING), + F1("hash_hkdf", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING), F1("hash_init", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_OBJECT), F0("hash_update", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE), F0("hash_update_stream", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_LONG), -- cgit v1.2.1 From 4de8503c225ab9f6130d335b21e7646a0142ed5e Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Mon, 2 Sep 2019 22:14:11 -0400 Subject: Add missing opcache return info for ext/standard. array_key_first/last returns null for invalid args, wrong argument counts, and empty arrays. random_bytes returns a string or throws. --- ext/opcache/Optimizer/zend_func_info.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index a06ac05b6b..9cae08701e 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -412,6 +412,7 @@ static const func_info_t func_infos[] = { F0("proc_nice", MAY_BE_FALSE | MAY_BE_TRUE), #endif F0("rand", MAY_BE_NULL | MAY_BE_LONG), + F1("random_bytes", MAY_BE_STRING), F0("srand", MAY_BE_NULL), F0("getrandmax", MAY_BE_NULL | MAY_BE_LONG), F0("mt_rand", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_LONG), @@ -848,6 +849,8 @@ static const func_info_t func_infos[] = { F1("array_chunk", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_ARRAY_OF_ANY), F1("array_combine", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_ARRAY_OF_ANY), F0("array_key_exists", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE), + FN("array_key_first", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_STRING), + FN("array_key_last", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_STRING), F1("pos", UNKNOWN_INFO), F0("sizeof", MAY_BE_NULL | MAY_BE_LONG), F0("key_exists", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE), -- cgit v1.2.1