SPL: minor refactoring (#8341)

Use more appropriate types and return macros
This commit is contained in:
George Peter Banyard 2022-04-13 20:34:23 +01:00 committed by GitHub
parent 8233e06109
commit cfc38a6014
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 32 deletions

View file

@ -1304,7 +1304,7 @@ PHP_METHOD(ArrayObject, count)
RETURN_LONG(spl_array_object_count_elements_helper(intern));
} /* }}} */
static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fname_len, int use_arg) /* {{{ */
static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, size_t fname_len, int use_arg) /* {{{ */
{
spl_array_object *intern = Z_SPLARRAY_P(ZEND_THIS);
HashTable **ht_ptr = spl_array_get_hash_table_ptr(intern);
@ -1393,12 +1393,12 @@ PHP_METHOD(ArrayIterator, current)
}
if ((entry = zend_hash_get_current_data_ex(aht, spl_array_get_pos_ptr(aht, intern))) == NULL) {
return;
RETURN_NULL();
}
if (Z_TYPE_P(entry) == IS_INDIRECT) {
entry = Z_INDIRECT_P(entry);
if (Z_TYPE_P(entry) == IS_UNDEF) {
return;
RETURN_NULL();
}
}
RETURN_COPY_DEREF(entry);
@ -1490,7 +1490,7 @@ PHP_METHOD(RecursiveArrayIterator, getChildren)
}
if ((entry = zend_hash_get_current_data_ex(aht, spl_array_get_pos_ptr(aht, intern))) == NULL) {
return;
RETURN_NULL();
}
if (Z_TYPE_P(entry) == IS_INDIRECT) {
@ -1500,7 +1500,7 @@ PHP_METHOD(RecursiveArrayIterator, getChildren)
ZVAL_DEREF(entry);
if (Z_TYPE_P(entry) == IS_OBJECT) {
if ((intern->ar_flags & SPL_ARRAY_CHILD_ARRAYS_ONLY) != 0) {
return;
RETURN_NULL();
}
if (instanceof_function(Z_OBJCE_P(entry), Z_OBJCE_P(ZEND_THIS))) {
RETURN_OBJ_COPY(Z_OBJ_P(entry));

View file

@ -1215,7 +1215,7 @@ PHP_METHOD(SplDoublyLinkedList, add)
PHP_METHOD(SplDoublyLinkedList, __debugInfo)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
RETURN_THROWS();
}
RETURN_ARR(spl_dllist_object_get_debug_info(Z_OBJ_P(ZEND_THIS)));

View file

@ -781,7 +781,7 @@ PHP_METHOD(SplFixedArray, offsetUnset)
PHP_METHOD(SplFixedArray, getIterator)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
RETURN_THROWS();
}
zend_create_internal_iterator_zval(return_value, ZEND_THIS);

View file

@ -19,8 +19,6 @@
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_spl.h"
/* {{{ spl_add_class_name */
@ -41,11 +39,9 @@ void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_fla
/* {{{ spl_add_interfaces */
void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
{
uint32_t num_interfaces;
if (pce->num_interfaces) {
ZEND_ASSERT(pce->ce_flags & ZEND_ACC_LINKED);
for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
for (uint32_t num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags);
}
}
@ -55,10 +51,9 @@ void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_fl
/* {{{ spl_add_traits */
void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
{
uint32_t num_traits;
zend_class_entry *trait;
for (num_traits = 0; num_traits < pce->num_traits; num_traits++) {
for (uint32_t num_traits = 0; num_traits < pce->num_traits; num_traits++) {
trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
pce->trait_names[num_traits].lc_name, ZEND_FETCH_CLASS_TRAIT);
ZEND_ASSERT(trait);
@ -69,11 +64,9 @@ void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
/* {{{ spl_add_classes */
int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags)
void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags)
{
if (!pce) {
return 0;
}
ZEND_ASSERT(pce);
spl_add_class_name(list, pce, allow, ce_flags);
if (sub) {
spl_add_interfaces(list, pce, allow, ce_flags);
@ -82,11 +75,10 @@ int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int c
spl_add_classes(pce, list, sub, allow, ce_flags);
}
}
return 0;
}
/* }}} */
zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len) /* {{{ */
zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, size_t prop_len) /* {{{ */
{
return zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), prop_name, prop_len, 0);
}

View file

@ -32,9 +32,9 @@ typedef zend_object* (*create_object_func_t)(zend_class_entry *class_type);
void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags);
void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags);
void spl_add_traits(zval * list, zend_class_entry * pce, int allow, int ce_flags);
int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags);
void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags);
/* caller must efree(return) */
zend_string *spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len);
zend_string *spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, size_t prop_len);
#endif /* PHP_FUNCTIONS_H */

View file

@ -1053,7 +1053,7 @@ PHP_METHOD(SplPriorityQueue, current)
PHP_METHOD(SplHeap, __debugInfo)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
RETURN_THROWS();
}
RETURN_ARR(spl_heap_object_get_debug_info(spl_ce_SplHeap, Z_OBJ_P(ZEND_THIS)));
@ -1063,7 +1063,7 @@ PHP_METHOD(SplHeap, __debugInfo)
PHP_METHOD(SplPriorityQueue, __debugInfo)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
RETURN_THROWS();
}
RETURN_ARR(spl_heap_object_get_debug_info(spl_ce_SplPriorityQueue, Z_OBJ_P(ZEND_THIS)));

View file

@ -870,7 +870,7 @@ PHP_METHOD(RecursiveIteratorIterator, callGetChildren)
zobject = &object->iterators[object->level].zobject;
if (Z_TYPE_P(zobject) == IS_UNDEF) {
return;
RETURN_NULL();
} else {
zend_call_method_with_0_params(Z_OBJ_P(zobject), ce, &object->iterators[object->level].getchildren, "getchildren", return_value);
if (Z_TYPE_P(return_value) == IS_UNDEF) {

View file

@ -82,7 +82,7 @@ void spl_SplObjectStorage_free_storage(zend_object *object) /* {{{ */
zend_hash_destroy(&intern->storage);
} /* }}} */
static int spl_object_storage_get_hash(zend_hash_key *key, spl_SplObjectStorage *intern, zend_object *obj) {
static zend_result spl_object_storage_get_hash(zend_hash_key *key, spl_SplObjectStorage *intern, zend_object *obj) {
if (UNEXPECTED(intern->fptr_get_hash)) {
zval param;
zval rv;
@ -218,12 +218,12 @@ spl_SplObjectStorageElement *spl_object_storage_attach(spl_SplObjectStorage *int
return pelement;
} /* }}} */
static int spl_object_storage_detach(spl_SplObjectStorage *intern, zend_object *obj) /* {{{ */
static zend_result spl_object_storage_detach(spl_SplObjectStorage *intern, zend_object *obj) /* {{{ */
{
if (EXPECTED(!(intern->flags & SOS_OVERRIDDEN_UNSET_DIMENSION))) {
return zend_hash_index_del(&intern->storage, obj->handle);
}
int ret = FAILURE;
zend_result ret = FAILURE;
zend_hash_key key;
if (spl_object_storage_get_hash(&key, intern, obj) == FAILURE) {
return ret;
@ -544,7 +544,7 @@ PHP_METHOD(SplObjectStorage, offsetGet)
ZEND_PARSE_PARAMETERS_END();
if (spl_object_storage_get_hash(&key, intern, obj) == FAILURE) {
return;
RETURN_NULL();
}
element = spl_object_storage_get(intern, &key);
@ -723,7 +723,7 @@ PHP_METHOD(SplObjectStorage, getInfo)
}
if ((element = zend_hash_get_current_data_ptr_ex(&intern->storage, &intern->pos)) == NULL) {
return;
RETURN_NULL();
}
ZVAL_COPY(return_value, &element->inf);
} /* }}} */
@ -740,7 +740,7 @@ PHP_METHOD(SplObjectStorage, setInfo)
}
if ((element = zend_hash_get_current_data_ptr_ex(&intern->storage, &intern->pos)) == NULL) {
return;
RETURN_NULL();
}
zval_ptr_dtor(&element->inf);
ZVAL_COPY(&element->inf, inf);
@ -1008,7 +1008,7 @@ PHP_METHOD(SplObjectStorage, __unserialize)
PHP_METHOD(SplObjectStorage, __debugInfo)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
RETURN_THROWS();
}
RETURN_ARR(spl_object_storage_debug_info(Z_OBJ_P(ZEND_THIS)));