Skip to content

Commit 3b92a96

Browse files
authored
Convert return type of various object handlers from int to zend_result (#8755)
1 parent 30cc0c1 commit 3b92a96

19 files changed

+46
-41
lines changed

UPGRADING.INTERNALS

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ PHP 8.2 INTERNALS UPGRADE NOTES
3232
* Deprecated zend_atoi() and zend_atol(). Use ZEND_STRTOL() for general purpose
3333
string to long conversion, or a variant of zend_ini_parse_quantity() for
3434
parsing ini quantities.
35+
* The return types of the following object handlers has changed from int to zend_result
36+
- zend_object_cast_t
37+
- zend_object_count_elements_t
38+
- zend_object_get_closure_t
39+
- zend_object_do_operation_t
3540

3641
========================
3742
2. Build system changes

Zend/zend_closures.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static zend_object *zend_closure_clone(zend_object *zobject) /* {{{ */
523523
}
524524
/* }}} */
525525

526-
int zend_closure_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */
526+
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) /* {{{ */
527527
{
528528
zend_closure *closure = (zend_closure*)obj;
529529

Zend/zend_object_handlers.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ ZEND_API zend_string *zend_std_get_class_name(const zend_object *zobj) /* {{{ */
18411841
}
18421842
/* }}} */
18431843

1844-
ZEND_API int zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type) /* {{{ */
1844+
ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type) /* {{{ */
18451845
{
18461846
switch (type) {
18471847
case IS_STRING: {
@@ -1871,7 +1871,7 @@ ZEND_API int zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj,
18711871
}
18721872
/* }}} */
18731873

1874-
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) /* {{{ */
1874+
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) /* {{{ */
18751875
{
18761876
zend_class_entry *ce = obj->ce;
18771877
zval *func = zend_hash_find_known_hash(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE));

Zend/zend_object_handlers.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,17 @@ typedef int (*zend_object_compare_t)(zval *object1, zval *object2);
144144
/* Cast an object to some other type.
145145
* readobj and retval must point to distinct zvals.
146146
*/
147-
typedef int (*zend_object_cast_t)(zend_object *readobj, zval *retval, int type);
147+
typedef zend_result (*zend_object_cast_t)(zend_object *readobj, zval *retval, int type);
148148

149149
/* updates *count to hold the number of elements present and returns SUCCESS.
150150
* Returns FAILURE if the object does not have any sense of overloaded dimensions */
151-
typedef int (*zend_object_count_elements_t)(zend_object *object, zend_long *count);
151+
typedef zend_result (*zend_object_count_elements_t)(zend_object *object, zend_long *count);
152152

153-
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);
153+
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);
154154

155155
typedef HashTable *(*zend_object_get_gc_t)(zend_object *object, zval **table, int *n);
156156

157-
typedef int (*zend_object_do_operation_t)(zend_uchar opcode, zval *result, zval *op1, zval *op2);
157+
typedef zend_result (*zend_object_do_operation_t)(zend_uchar opcode, zval *result, zval *op1, zval *op2);
158158

159159
struct _zend_object_handlers {
160160
/* 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
209209
ZEND_API HashTable *zend_std_get_properties(zend_object *object);
210210
ZEND_API HashTable *zend_std_get_gc(zend_object *object, zval **table, int *n);
211211
ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp);
212-
ZEND_API int zend_std_cast_object_tostring(zend_object *object, zval *writeobj, int type);
212+
ZEND_API zend_result zend_std_cast_object_tostring(zend_object *object, zval *writeobj, int type);
213213
ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot);
214214
ZEND_API zval *zend_std_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv);
215215
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);
222222
ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *method_name, const zval *key);
223223
ZEND_API zend_string *zend_std_get_class_name(const zend_object *zobj);
224224
ZEND_API int zend_std_compare_objects(zval *o1, zval *o2);
225-
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);
225+
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);
226226
ZEND_API void rebuild_object_properties(zend_object *zobj);
227227

228228
ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj);

Zend/zend_weakrefs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static void zend_weakmap_unset_dimension(zend_object *object, zval *offset)
424424
zend_weakref_unregister(obj_addr, ZEND_WEAKREF_ENCODE(&wm->ht, ZEND_WEAKREF_TAG_MAP), 1);
425425
}
426426

427-
static int zend_weakmap_count_elements(zend_object *object, zend_long *count)
427+
static zend_result zend_weakmap_count_elements(zend_object *object, zend_long *count)
428428
{
429429
zend_weakmap *wm = zend_weakmap_from(object);
430430
*count = zend_hash_num_elements(&wm->ht);

ext/com_dotnet/com_handlers.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static int com_objects_compare(zval *object1, zval *object2)
429429
return ret;
430430
}
431431

432-
static int com_object_cast(zend_object *readobj, zval *writeobj, int type)
432+
static zend_result com_object_cast(zend_object *readobj, zval *writeobj, int type)
433433
{
434434
php_com_dotnet_object *obj;
435435
VARIANT v;
@@ -490,7 +490,7 @@ static int com_object_cast(zend_object *readobj, zval *writeobj, int type)
490490
return zend_std_cast_object_tostring(readobj, writeobj, type);
491491
}
492492

493-
static int com_object_count(zend_object *object, zend_long *count)
493+
static zend_result com_object_count(zend_object *object, zend_long *count)
494494
{
495495
php_com_dotnet_object *obj;
496496
LONG ubound = 0, lbound = 0;

ext/com_dotnet/com_saproxy.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ static int saproxy_objects_compare(zval *object1, zval *object2)
332332
return -1;
333333
}
334334

335-
static int saproxy_object_cast(zend_object *readobj, zval *writeobj, int type)
335+
static zend_result saproxy_object_cast(zend_object *readobj, zval *writeobj, int type)
336336
{
337337
return FAILURE;
338338
}
339339

340-
static int saproxy_count_elements(zend_object *object, zend_long *count)
340+
static zend_result saproxy_count_elements(zend_object *object, zend_long *count)
341341
{
342342
php_com_saproxy *proxy = (php_com_saproxy*) object;
343343
LONG ubound, lbound;

ext/curl/curl_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,6 @@ static inline php_curlsh *curl_share_from_obj(zend_object *obj) {
159159
void curl_multi_register_handlers(void);
160160
void curl_share_register_handlers(void);
161161
void curlfile_register_class(void);
162-
int curl_cast_object(zend_object *obj, zval *result, int type);
162+
zend_result curl_cast_object(zend_object *obj, zval *result, int type);
163163

164164
#endif /* _PHP_CURL_PRIVATE_H */

ext/curl/interface.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n)
14431443
return zend_std_get_properties(object);
14441444
}
14451445

1446-
int curl_cast_object(zend_object *obj, zval *result, int type)
1446+
zend_result curl_cast_object(zend_object *obj, zval *result, int type)
14471447
{
14481448
if (type == IS_LONG) {
14491449
/* For better backward compatibility, make (int) $curl_handle return the object ID,

ext/ffi/ffi.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ static zval *zend_ffi_cdata_set(zend_object *obj, zend_string *member, zval *val
10811081
}
10821082
/* }}} */
10831083

1084-
static int zend_ffi_cdata_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */
1084+
static zend_result zend_ffi_cdata_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */
10851085
{
10861086
if (type == IS_STRING) {
10871087
zend_ffi_cdata *cdata = (zend_ffi_cdata*)readobj;
@@ -1703,7 +1703,7 @@ static int zend_ffi_cdata_compare_objects(zval *o1, zval *o2) /* {{{ */
17031703
}
17041704
/* }}} */
17051705

1706-
static int zend_ffi_cdata_count_elements(zend_object *obj, zend_long *count) /* {{{ */
1706+
static zend_result zend_ffi_cdata_count_elements(zend_object *obj, zend_long *count) /* {{{ */
17071707
{
17081708
zend_ffi_cdata *cdata = (zend_ffi_cdata*)obj;
17091709
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
17741774
}
17751775
/* }}} */
17761776

1777-
static int zend_ffi_cdata_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
1777+
static zend_result zend_ffi_cdata_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
17781778
{
17791779
zend_long offset;
17801780

@@ -2056,7 +2056,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zend_object *obj, int *is_temp)
20562056
}
20572057
/* }}} */
20582058

2059-
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) /* {{{ */
2059+
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) /* {{{ */
20602060
{
20612061
zend_ffi_cdata *cdata = (zend_ffi_cdata*)obj;
20622062
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) /* {{{
50215021
}
50225022
/* }}} */
50235023

5024-
static int zend_fake_cast_object(zend_object *obj, zval *result, int type)
5024+
static zend_result zend_fake_cast_object(zend_object *obj, zval *result, int type)
50255025
{
50265026
switch (type) {
50275027
case _IS_BOOL:

ext/gmp/gmp.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static inline void gmp_create(zval *target, mpz_ptr *gmpnum_target) /* {{{ */
276276
}
277277
/* }}} */
278278

279-
static int gmp_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */
279+
static zend_result gmp_cast_object(zend_object *readobj, zval *writeobj, int type) /* {{{ */
280280
{
281281
mpz_ptr gmpnum;
282282
switch (type) {
@@ -372,7 +372,7 @@ static void shift_operator_helper(gmp_binary_ui_op_t op, zval *return_value, zva
372372
} \
373373
return SUCCESS;
374374

375-
static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
375+
static zend_result gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
376376
{
377377
switch (opcode) {
378378
case ZEND_ADD:
@@ -409,7 +409,7 @@ static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval
409409
}
410410
/* }}} */
411411

412-
static int gmp_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
412+
static zend_result gmp_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
413413
{
414414
zval op1_copy;
415415
int retval;

ext/intl/resourcebundle/resourcebundle_class.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ PHP_FUNCTION( resourcebundle_get )
252252
/* }}} */
253253

254254
/* {{{ resourcebundle_array_count */
255-
int resourcebundle_array_count(zend_object *object, zend_long *count)
255+
static zend_result resourcebundle_array_count(zend_object *object, zend_long *count)
256256
{
257257
ResourceBundle_object *rb = php_intl_resourcebundle_fetch_object(object);
258258

ext/simplexml/simplexml.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static zval *php_sxe_iterator_current_data(zend_object_iterator *iter);
5252
static void php_sxe_iterator_current_key(zend_object_iterator *iter, zval *key);
5353
static void php_sxe_iterator_move_forward(zend_object_iterator *iter);
5454
static void php_sxe_iterator_rewind(zend_object_iterator *iter);
55-
static int sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type);
55+
static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type);
5656

5757
/* {{{ _node_as_zval() */
5858
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)
18011801
/* }}} */
18021802

18031803
/* {{{ cast_object() */
1804-
static int cast_object(zval *object, int type, char *contents)
1804+
static zend_result cast_object(zval *object, int type, char *contents)
18051805
{
18061806
if (contents) {
18071807
ZVAL_STRINGL(object, contents, strlen(contents));
@@ -1833,12 +1833,12 @@ static int cast_object(zval *object, int type, char *contents)
18331833
/* }}} */
18341834

18351835
/* {{{ sxe_object_cast() */
1836-
static int sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type)
1836+
static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type)
18371837
{
18381838
php_sxe_object *sxe;
18391839
xmlChar *contents = NULL;
18401840
xmlNodePtr node;
1841-
int rv;
1841+
zend_result rv;
18421842

18431843
sxe = php_sxe_fetch_object(readobj);
18441844

@@ -1882,7 +1882,7 @@ static int sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type)
18821882
/* }}} */
18831883

18841884
/* {{{ Variant of sxe_object_cast_ex that handles overwritten __toString() method */
1885-
static int sxe_object_cast(zend_object *readobj, zval *writeobj, int type)
1885+
static zend_result sxe_object_cast(zend_object *readobj, zval *writeobj, int type)
18861886
{
18871887
if (type == IS_STRING
18881888
&& zend_std_cast_object_tostring(readobj, writeobj, IS_STRING) == SUCCESS
@@ -1908,7 +1908,7 @@ PHP_METHOD(SimpleXMLElement, __toString)
19081908
}
19091909
/* }}} */
19101910

1911-
static int php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count) /* {{{ */
1911+
static zend_result php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count) /* {{{ */
19121912
{
19131913
xmlNodePtr node;
19141914
zval data;
@@ -1935,7 +1935,7 @@ static int php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count)
19351935
}
19361936
/* }}} */
19371937

1938-
static int sxe_count_elements(zend_object *object, zend_long *count) /* {{{ */
1938+
static zend_result sxe_count_elements(zend_object *object, zend_long *count) /* {{{ */
19391939
{
19401940
php_sxe_object *intern;
19411941
intern = php_sxe_fetch_object(object);

ext/spl/spl_array.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ static zend_long spl_array_object_count_elements_helper(spl_array_object *intern
12761276
}
12771277
} /* }}} */
12781278

1279-
int spl_array_object_count_elements(zend_object *object, zend_long *count) /* {{{ */
1279+
static zend_result spl_array_object_count_elements(zend_object *object, zend_long *count) /* {{{ */
12801280
{
12811281
spl_array_object *intern = spl_array_from_obj(object);
12821282

ext/spl/spl_directory.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zva
18541854
/* }}} */
18551855

18561856
/* {{{ spl_filesystem_object_cast */
1857-
static int spl_filesystem_object_cast(zend_object *readobj, zval *writeobj, int type)
1857+
static zend_result spl_filesystem_object_cast(zend_object *readobj, zval *writeobj, int type)
18581858
{
18591859
spl_filesystem_object *intern = spl_filesystem_from_obj(readobj);
18601860

ext/spl/spl_dllist.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static zend_object *spl_dllist_object_clone(zend_object *old_object) /* {{{ */
409409
}
410410
/* }}} */
411411

412-
static int spl_dllist_object_count_elements(zend_object *object, zend_long *count) /* {{{ */
412+
static zend_result spl_dllist_object_count_elements(zend_object *object, zend_long *count) /* {{{ */
413413
{
414414
spl_dllist_object *intern = spl_dllist_from_obj(object);
415415

ext/spl/spl_fixedarray.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static int spl_fixedarray_object_has_dimension(zend_object *object, zval *offset
510510
return spl_fixedarray_object_has_dimension_helper(intern, offset, check_empty);
511511
}
512512

513-
static int spl_fixedarray_object_count_elements(zend_object *object, zend_long *count)
513+
static zend_result spl_fixedarray_object_count_elements(zend_object *object, zend_long *count)
514514
{
515515
spl_fixedarray_object *intern;
516516

ext/spl/spl_heap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static zend_object *spl_heap_object_clone(zend_object *old_object) /* {{{ */
484484
}
485485
/* }}} */
486486

487-
static int spl_heap_object_count_elements(zend_object *object, zend_long *count) /* {{{ */
487+
static zend_result spl_heap_object_count_elements(zend_object *object, zend_long *count) /* {{{ */
488488
{
489489
spl_heap_object *intern = spl_heap_from_obj(object);
490490

ext/tidy/tidy.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ static void tidy_object_free_storage(zend_object *);
149149
static zend_object *tidy_object_new_node(zend_class_entry *);
150150
static zend_object *tidy_object_new_doc(zend_class_entry *);
151151
static zval *tidy_instantiate(zend_class_entry *, zval *);
152-
static int tidy_doc_cast_handler(zend_object *, zval *, int);
153-
static int tidy_node_cast_handler(zend_object *, zval *, int);
152+
static zend_result tidy_doc_cast_handler(zend_object *, zval *, int);
153+
static zend_result tidy_node_cast_handler(zend_object *, zval *, int);
154154
static void tidy_doc_update_properties(PHPTidyObj *);
155155
static void tidy_add_node_default_properties(PHPTidyObj *);
156156
static void *php_tidy_get_opt_val(PHPTidyDoc *, TidyOption, TidyOptionType *);
@@ -462,7 +462,7 @@ static zval *tidy_instantiate(zend_class_entry *pce, zval *object)
462462
return object;
463463
}
464464

465-
static int tidy_doc_cast_handler(zend_object *in, zval *out, int type)
465+
static zend_result tidy_doc_cast_handler(zend_object *in, zval *out, int type)
466466
{
467467
TidyBuffer output;
468468
PHPTidyObj *obj;
@@ -500,7 +500,7 @@ static int tidy_doc_cast_handler(zend_object *in, zval *out, int type)
500500
return SUCCESS;
501501
}
502502

503-
static int tidy_node_cast_handler(zend_object *in, zval *out, int type)
503+
static zend_result tidy_node_cast_handler(zend_object *in, zval *out, int type)
504504
{
505505
TidyBuffer buf;
506506
PHPTidyObj *obj;

0 commit comments

Comments
 (0)