From 7f6cae020985349cc9c5bb34d8f0dfbdf3d14eae Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Sat, 11 Jun 2022 23:45:06 +0200 Subject: [PATCH] Convert return type of various object handlers from int to zend_result --- UPGRADING.INTERNALS | 5 +++++ Zend/zend_closures.c | 2 +- Zend/zend_object_handlers.c | 4 ++-- Zend/zend_object_handlers.h | 12 ++++++------ Zend/zend_weakrefs.c | 2 +- ext/com_dotnet/com_handlers.c | 4 ++-- ext/com_dotnet/com_saproxy.c | 4 ++-- ext/curl/curl_private.h | 2 +- ext/curl/interface.c | 2 +- ext/ffi/ffi.c | 10 +++++----- ext/gmp/gmp.c | 6 +++--- ext/intl/resourcebundle/resourcebundle_class.c | 2 +- ext/simplexml/simplexml.c | 14 +++++++------- ext/spl/spl_array.c | 2 +- ext/spl/spl_directory.c | 2 +- ext/spl/spl_dllist.c | 2 +- ext/spl/spl_fixedarray.c | 2 +- ext/spl/spl_heap.c | 2 +- ext/tidy/tidy.c | 8 ++++---- 19 files changed, 46 insertions(+), 41 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index e411bdba99031..c752ce4823de6 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -32,6 +32,11 @@ PHP 8.2 INTERNALS UPGRADE NOTES * Deprecated zend_atoi() and zend_atol(). Use ZEND_STRTOL() for general purpose string to long conversion, or a variant of zend_ini_parse_quantity() for parsing ini quantities. +* The return types of the following object handlers has changed from int to zend_result + - zend_object_cast_t + - zend_object_count_elements_t + - zend_object_get_closure_t + - zend_object_do_operation_t ======================== 2. Build system changes diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index e141d0956dc95..1dd7715e55b6a 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -523,7 +523,7 @@ static zend_object *zend_closure_clone(zend_object *zobject) /* {{{ */ } /* }}} */ -int zend_closure_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */ +static zend_result zend_closure_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */ { zend_closure *closure = (zend_closure*)obj; diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 7d589356ac1d1..a8cd6dc11f646 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1841,7 +1841,7 @@ ZEND_API zend_string *zend_std_get_class_name(const zend_object *zobj) /* {{{ */ } /* }}} */ -ZEND_API int zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type) /* {{{ */ +ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type) /* {{{ */ { switch (type) { case IS_STRING: { @@ -1871,7 +1871,7 @@ ZEND_API int zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, } /* }}} */ -ZEND_API int zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */ +ZEND_API zend_result zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */ { zend_class_entry *ce = obj->ce; zval *func = zend_hash_find_known_hash(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE)); diff --git a/Zend/zend_object_handlers.h b/Zend/zend_object_handlers.h index 53eef829282ce..94b7f52cba3aa 100644 --- a/Zend/zend_object_handlers.h +++ b/Zend/zend_object_handlers.h @@ -144,17 +144,17 @@ typedef int (*zend_object_compare_t)(zval *object1, zval *object2); /* Cast an object to some other type. * readobj and retval must point to distinct zvals. */ -typedef int (*zend_object_cast_t)(zend_object *readobj, zval *retval, int type); +typedef zend_result (*zend_object_cast_t)(zend_object *readobj, zval *retval, int type); /* updates *count to hold the number of elements present and returns SUCCESS. * Returns FAILURE if the object does not have any sense of overloaded dimensions */ -typedef int (*zend_object_count_elements_t)(zend_object *object, zend_long *count); +typedef zend_result (*zend_object_count_elements_t)(zend_object *object, zend_long *count); -typedef int (*zend_object_get_closure_t)(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only); +typedef zend_result (*zend_object_get_closure_t)(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only); typedef HashTable *(*zend_object_get_gc_t)(zend_object *object, zval **table, int *n); -typedef int (*zend_object_do_operation_t)(zend_uchar opcode, zval *result, zval *op1, zval *op2); +typedef zend_result (*zend_object_do_operation_t)(zend_uchar opcode, zval *result, zval *op1, zval *op2); struct _zend_object_handlers { /* offset of real object header (usually zero) */ @@ -209,7 +209,7 @@ ZEND_API struct _zend_property_info *zend_get_property_info(zend_class_entry *ce ZEND_API HashTable *zend_std_get_properties(zend_object *object); ZEND_API HashTable *zend_std_get_gc(zend_object *object, zval **table, int *n); ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp); -ZEND_API int zend_std_cast_object_tostring(zend_object *object, zval *writeobj, int type); +ZEND_API zend_result zend_std_cast_object_tostring(zend_object *object, zval *writeobj, int type); ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot); ZEND_API zval *zend_std_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv); ZEND_API zval *zend_std_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot); @@ -222,7 +222,7 @@ ZEND_API void zend_std_unset_dimension(zend_object *object, zval *offset); ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *method_name, const zval *key); ZEND_API zend_string *zend_std_get_class_name(const zend_object *zobj); ZEND_API int zend_std_compare_objects(zval *o1, zval *o2); -ZEND_API int zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only); +ZEND_API zend_result zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only); ZEND_API void rebuild_object_properties(zend_object *zobj); ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj); diff --git a/Zend/zend_weakrefs.c b/Zend/zend_weakrefs.c index 9d530047f902f..14e8bfc599d45 100644 --- a/Zend/zend_weakrefs.c +++ b/Zend/zend_weakrefs.c @@ -424,7 +424,7 @@ static void zend_weakmap_unset_dimension(zend_object *object, zval *offset) zend_weakref_unregister(obj_addr, ZEND_WEAKREF_ENCODE(&wm->ht, ZEND_WEAKREF_TAG_MAP), 1); } -static int zend_weakmap_count_elements(zend_object *object, zend_long *count) +static zend_result zend_weakmap_count_elements(zend_object *object, zend_long *count) { zend_weakmap *wm = zend_weakmap_from(object); *count = zend_hash_num_elements(&wm->ht); diff --git a/ext/com_dotnet/com_handlers.c b/ext/com_dotnet/com_handlers.c index bb45e98e90ed0..db96118ea31c6 100644 --- a/ext/com_dotnet/com_handlers.c +++ b/ext/com_dotnet/com_handlers.c @@ -429,7 +429,7 @@ static int com_objects_compare(zval *object1, zval *object2) return ret; } -static int com_object_cast(zend_object *readobj, zval *writeobj, int type) +static zend_result com_object_cast(zend_object *readobj, zval *writeobj, int type) { php_com_dotnet_object *obj; VARIANT v; @@ -490,7 +490,7 @@ static int com_object_cast(zend_object *readobj, zval *writeobj, int type) return zend_std_cast_object_tostring(readobj, writeobj, type); } -static int com_object_count(zend_object *object, zend_long *count) +static zend_result com_object_count(zend_object *object, zend_long *count) { php_com_dotnet_object *obj; LONG ubound = 0, lbound = 0; diff --git a/ext/com_dotnet/com_saproxy.c b/ext/com_dotnet/com_saproxy.c index 4e19f6e78e5d2..6ad4680c0fe65 100644 --- a/ext/com_dotnet/com_saproxy.c +++ b/ext/com_dotnet/com_saproxy.c @@ -332,12 +332,12 @@ static int saproxy_objects_compare(zval *object1, zval *object2) return -1; } -static int saproxy_object_cast(zend_object *readobj, zval *writeobj, int type) +static zend_result saproxy_object_cast(zend_object *readobj, zval *writeobj, int type) { return FAILURE; } -static int saproxy_count_elements(zend_object *object, zend_long *count) +static zend_result saproxy_count_elements(zend_object *object, zend_long *count) { php_com_saproxy *proxy = (php_com_saproxy*) object; LONG ubound, lbound; diff --git a/ext/curl/curl_private.h b/ext/curl/curl_private.h index edf19c86f8354..ca3024bcd4926 100644 --- a/ext/curl/curl_private.h +++ b/ext/curl/curl_private.h @@ -159,6 +159,6 @@ static inline php_curlsh *curl_share_from_obj(zend_object *obj) { void curl_multi_register_handlers(void); void curl_share_register_handlers(void); void curlfile_register_class(void); -int curl_cast_object(zend_object *obj, zval *result, int type); +zend_result curl_cast_object(zend_object *obj, zval *result, int type); #endif /* _PHP_CURL_PRIVATE_H */ diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 0d574a605a6d7..0e9aae4b76458 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1443,7 +1443,7 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n) return zend_std_get_properties(object); } -int curl_cast_object(zend_object *obj, zval *result, int type) +zend_result curl_cast_object(zend_object *obj, zval *result, int type) { if (type == IS_LONG) { /* For better backward compatibility, make (int) $curl_handle return the object ID, diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 7080a5141a4d1..cb82c3a3c3118 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -1081,7 +1081,7 @@ static zval *zend_ffi_cdata_set(zend_object *obj, zend_string *member, zval *val } /* }}} */ -static int zend_ffi_cdata_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */ +static zend_result zend_ffi_cdata_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */ { if (type == IS_STRING) { zend_ffi_cdata *cdata = (zend_ffi_cdata*)readobj; @@ -1703,7 +1703,7 @@ static int zend_ffi_cdata_compare_objects(zval *o1, zval *o2) /* {{{ */ } /* }}} */ -static int zend_ffi_cdata_count_elements(zend_object *obj, zend_long *count) /* {{{ */ +static zend_result zend_ffi_cdata_count_elements(zend_object *obj, zend_long *count) /* {{{ */ { zend_ffi_cdata *cdata = (zend_ffi_cdata*)obj; zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); @@ -1774,7 +1774,7 @@ static zend_object* zend_ffi_add(zend_ffi_cdata *base_cdata, zend_ffi_type *base } /* }}} */ -static int zend_ffi_cdata_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */ +static zend_result zend_ffi_cdata_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */ { zend_long offset; @@ -2056,7 +2056,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zend_object *obj, int *is_temp) } /* }}} */ -static int zend_ffi_cdata_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */ +static zend_result zend_ffi_cdata_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */ { zend_ffi_cdata *cdata = (zend_ffi_cdata*)obj; zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); @@ -5021,7 +5021,7 @@ static HashTable *zend_fake_get_gc(zend_object *ob, zval **table, int *n) /* {{{ } /* }}} */ -static int zend_fake_cast_object(zend_object *obj, zval *result, int type) +static zend_result zend_fake_cast_object(zend_object *obj, zval *result, int type) { switch (type) { case _IS_BOOL: diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 2cb43c371ae2a..39d0da5d154af 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -276,7 +276,7 @@ static inline void gmp_create(zval *target, mpz_ptr *gmpnum_target) /* {{{ */ } /* }}} */ -static int gmp_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */ +static zend_result gmp_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */ { mpz_ptr gmpnum; switch (type) { @@ -372,7 +372,7 @@ static void shift_operator_helper(gmp_binary_ui_op_t op, zval *return_value, zva } \ return SUCCESS; -static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */ +static zend_result gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */ { switch (opcode) { case ZEND_ADD: @@ -409,7 +409,7 @@ static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval } /* }}} */ -static int gmp_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */ +static zend_result gmp_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */ { zval op1_copy; int retval; diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.c index aa4671a1b1310..5e1e9e5312e29 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.c +++ b/ext/intl/resourcebundle/resourcebundle_class.c @@ -252,7 +252,7 @@ PHP_FUNCTION( resourcebundle_get ) /* }}} */ /* {{{ resourcebundle_array_count */ -int resourcebundle_array_count(zend_object *object, zend_long *count) +static zend_result resourcebundle_array_count(zend_object *object, zend_long *count) { ResourceBundle_object *rb = php_intl_resourcebundle_fetch_object(object); diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index a57929c5f44cf..763886730158b 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -52,7 +52,7 @@ static zval *php_sxe_iterator_current_data(zend_object_iterator *iter); static void php_sxe_iterator_current_key(zend_object_iterator *iter, zval *key); static void php_sxe_iterator_move_forward(zend_object_iterator *iter); static void php_sxe_iterator_rewind(zend_object_iterator *iter); -static int sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type); +static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type); /* {{{ _node_as_zval() */ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE_ITER itertype, char *name, const xmlChar *nsprefix, int isprefix) @@ -1801,7 +1801,7 @@ PHP_METHOD(SimpleXMLElement, addAttribute) /* }}} */ /* {{{ cast_object() */ -static int cast_object(zval *object, int type, char *contents) +static zend_result cast_object(zval *object, int type, char *contents) { if (contents) { ZVAL_STRINGL(object, contents, strlen(contents)); @@ -1833,12 +1833,12 @@ static int cast_object(zval *object, int type, char *contents) /* }}} */ /* {{{ sxe_object_cast() */ -static int sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type) +static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type) { php_sxe_object *sxe; xmlChar *contents = NULL; xmlNodePtr node; - int rv; + zend_result rv; sxe = php_sxe_fetch_object(readobj); @@ -1882,7 +1882,7 @@ static int sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type) /* }}} */ /* {{{ Variant of sxe_object_cast_ex that handles overwritten __toString() method */ -static int sxe_object_cast(zend_object *readobj, zval *writeobj, int type) +static zend_result sxe_object_cast(zend_object *readobj, zval *writeobj, int type) { if (type == IS_STRING && zend_std_cast_object_tostring(readobj, writeobj, IS_STRING) == SUCCESS @@ -1908,7 +1908,7 @@ PHP_METHOD(SimpleXMLElement, __toString) } /* }}} */ -static int php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count) /* {{{ */ +static zend_result php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count) /* {{{ */ { xmlNodePtr node; zval data; @@ -1935,7 +1935,7 @@ static int php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count) } /* }}} */ -static int sxe_count_elements(zend_object *object, zend_long *count) /* {{{ */ +static zend_result sxe_count_elements(zend_object *object, zend_long *count) /* {{{ */ { php_sxe_object *intern; intern = php_sxe_fetch_object(object); diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index db9a4f6f6b3ee..f4b1f8c427945 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1276,7 +1276,7 @@ static zend_long spl_array_object_count_elements_helper(spl_array_object *intern } } /* }}} */ -int spl_array_object_count_elements(zend_object *object, zend_long *count) /* {{{ */ +static zend_result spl_array_object_count_elements(zend_object *object, zend_long *count) /* {{{ */ { spl_array_object *intern = spl_array_from_obj(object); diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 766828ef80204..382ec91cc235f 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1854,7 +1854,7 @@ zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zva /* }}} */ /* {{{ spl_filesystem_object_cast */ -static int spl_filesystem_object_cast(zend_object *readobj, zval *writeobj, int type) +static zend_result spl_filesystem_object_cast(zend_object *readobj, zval *writeobj, int type) { spl_filesystem_object *intern = spl_filesystem_from_obj(readobj); diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index 5fd3830014a3d..2c7534a03228c 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -409,7 +409,7 @@ static zend_object *spl_dllist_object_clone(zend_object *old_object) /* {{{ */ } /* }}} */ -static int spl_dllist_object_count_elements(zend_object *object, zend_long *count) /* {{{ */ +static zend_result spl_dllist_object_count_elements(zend_object *object, zend_long *count) /* {{{ */ { spl_dllist_object *intern = spl_dllist_from_obj(object); diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 5f8dca8dd1812..fd18c3d86c378 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -510,7 +510,7 @@ static int spl_fixedarray_object_has_dimension(zend_object *object, zval *offset return spl_fixedarray_object_has_dimension_helper(intern, offset, check_empty); } -static int spl_fixedarray_object_count_elements(zend_object *object, zend_long *count) +static zend_result spl_fixedarray_object_count_elements(zend_object *object, zend_long *count) { spl_fixedarray_object *intern; diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index 3112666e33651..c541eb3c47416 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -484,7 +484,7 @@ static zend_object *spl_heap_object_clone(zend_object *old_object) /* {{{ */ } /* }}} */ -static int spl_heap_object_count_elements(zend_object *object, zend_long *count) /* {{{ */ +static zend_result spl_heap_object_count_elements(zend_object *object, zend_long *count) /* {{{ */ { spl_heap_object *intern = spl_heap_from_obj(object); diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index d83dbdbc93a27..a59268680cacb 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -149,8 +149,8 @@ static void tidy_object_free_storage(zend_object *); static zend_object *tidy_object_new_node(zend_class_entry *); static zend_object *tidy_object_new_doc(zend_class_entry *); static zval *tidy_instantiate(zend_class_entry *, zval *); -static int tidy_doc_cast_handler(zend_object *, zval *, int); -static int tidy_node_cast_handler(zend_object *, zval *, int); +static zend_result tidy_doc_cast_handler(zend_object *, zval *, int); +static zend_result tidy_node_cast_handler(zend_object *, zval *, int); static void tidy_doc_update_properties(PHPTidyObj *); static void tidy_add_node_default_properties(PHPTidyObj *); static void *php_tidy_get_opt_val(PHPTidyDoc *, TidyOption, TidyOptionType *); @@ -462,7 +462,7 @@ static zval *tidy_instantiate(zend_class_entry *pce, zval *object) return object; } -static int tidy_doc_cast_handler(zend_object *in, zval *out, int type) +static zend_result tidy_doc_cast_handler(zend_object *in, zval *out, int type) { TidyBuffer output; PHPTidyObj *obj; @@ -500,7 +500,7 @@ static int tidy_doc_cast_handler(zend_object *in, zval *out, int type) return SUCCESS; } -static int tidy_node_cast_handler(zend_object *in, zval *out, int type) +static zend_result tidy_node_cast_handler(zend_object *in, zval *out, int type) { TidyBuffer buf; PHPTidyObj *obj;