Skip to content

Commit 31e98e4

Browse files
authored
Merge pull request #148 from remicollet/issue-php8
fix build with php 8
2 parents f933cf5 + 780b0b4 commit 31e98e4

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

msgpack_class.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static ZEND_METHOD(msgpack, unpacker) /* {{{ */ {
274274
ZVAL_STRING(&func_name, "__construct");
275275

276276
object_init_ex(return_value, msgpack_unpacker_ce);
277-
call_user_function_ex(CG(function_table), return_value, &func_name, &construct_return, 1, args, 0, NULL);
277+
call_user_function(CG(function_table), return_value, &func_name, &construct_return, 1, args);
278278

279279
zval_ptr_dtor(&func_name);
280280
}

msgpack_convert.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object
3636

3737
if (msgpack_convert_array(&tplval, data, dataval) == SUCCESS) {
3838
zend_hash_move_forward_ex(props, prop_pos);
39-
zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval);
39+
zend_update_property(Z_OBJCE_P(object), OBJ_FOR_PROP(object), prop_name, prop_len, &tplval);
4040
return SUCCESS;
4141
}
4242
return FAILURE;
@@ -45,14 +45,14 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object
4545
{
4646
if (msgpack_convert_object(&tplval, data, val) == SUCCESS) {
4747
zend_hash_move_forward_ex(props, prop_pos);
48-
zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval);
48+
zend_update_property(Z_OBJCE_P(object), OBJ_FOR_PROP(object), prop_name, prop_len, &tplval);
4949
return SUCCESS;
5050
}
5151
return FAILURE;
5252
}
5353
default:
5454
zend_hash_move_forward_ex(props, prop_pos);
55-
zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, val);
55+
zend_update_property(Z_OBJCE_P(object), OBJ_FOR_PROP(object), prop_name, prop_len, val);
5656
return SUCCESS;
5757
}
5858
}
@@ -64,7 +64,15 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object
6464
*properties = NULL;
6565
}
6666
ZVAL_LONG(&key_zv, key_index);
67+
#if PHP_VERSION_ID < 80000
6768
zend_std_write_property(object, &key_zv, val, NULL);
69+
#else
70+
{
71+
zend_string *key = zval_get_string(&key_zv);
72+
zend_std_write_property(Z_OBJ_P(object), key, val, NULL);
73+
zend_string_release(key);
74+
}
75+
#endif
6876
return SUCCESS;
6977
}
7078
/* }}} */
@@ -81,13 +89,17 @@ static inline int msgpack_convert_string_to_properties(zval *object, zend_string
8189
prot_name = zend_mangle_property_name("*", 1, ZSTR_VAL(key), ZSTR_LEN(key), 1);
8290

8391
if (zend_hash_find(propers, priv_name) != NULL) {
84-
zend_update_property_ex(ce, object, key, val);
92+
zend_update_property_ex(ce, OBJ_FOR_PROP(object), key, val);
8593
return_code = SUCCESS;
8694
} else if (zend_hash_find(propers, prot_name) != NULL) {
87-
zend_update_property_ex(ce, object, key, val);
95+
zend_update_property_ex(ce, OBJ_FOR_PROP(object), key, val);
8896
return_code = SUCCESS;
8997
} else {
98+
#if PHP_VERSION_ID < 80000
9099
zend_std_write_property(object, &pub_name, val, NULL);
100+
#else
101+
zend_std_write_property(Z_OBJ_P(object), key, val, NULL);
102+
#endif
91103
return_code = FAILURE;
92104
}
93105
zend_hash_add(var, Z_STR(pub_name), val);
@@ -298,8 +310,9 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */
298310
fci.retval = &retval;
299311
fci.param_count = 0;
300312
fci.params = &params;
313+
#if PHP_VERSION_ID < 80000
301314
fci.no_separation = 1;
302-
315+
#endif
303316
#if PHP_VERSION_ID < 70300
304317
fcc.initialized = 1;
305318
#endif
@@ -358,7 +371,11 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */
358371
} ZEND_HASH_FOREACH_END();
359372

360373
/* index */
374+
#if PHP_VERSION_ID < 80000
361375
properties = Z_OBJ_HT_P(return_value)->get_properties(return_value);
376+
#else
377+
properties = Z_OBJ_HT_P(return_value)->get_properties(Z_OBJ_P(return_value));
378+
#endif
362379
if (HASH_OF(tpl)) {
363380
properties = HASH_OF(tpl);
364381
}
@@ -418,10 +435,10 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */
418435
return FAILURE;
419436
}
420437

421-
zend_update_property_ex(ce, return_value, str_key, &nv);
438+
zend_update_property_ex(ce, OBJ_FOR_PROP(return_value), str_key, &nv);
422439
zval_ptr_dtor(&nv);
423440
} else {
424-
zend_update_property(ce, return_value, prop_name, prop_len, aryval);
441+
zend_update_property(ce, OBJ_FOR_PROP(return_value), prop_name, prop_len, aryval);
425442
}
426443
num_key++;
427444
} ZEND_HASH_FOREACH_END();
@@ -433,7 +450,11 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */
433450
HashTable *properties = NULL;
434451
HashPosition prop_pos;
435452

453+
#if PHP_VERSION_ID < 80000
436454
properties = Z_OBJ_HT_P(return_value)->get_properties(return_value);
455+
#else
456+
properties = Z_OBJ_HT_P(return_value)->get_properties(Z_OBJ_P(return_value));
457+
#endif
437458
zend_hash_internal_pointer_reset_ex(properties, &prop_pos);
438459

439460
if (msgpack_convert_long_to_properties(HASH_OF(return_value), return_value, &properties, &prop_pos, 0, value, NULL) != SUCCESS) {

msgpack_pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable
223223
if (object) {
224224
#if PHP_VERSION_ID >= 70400
225225
if (Z_OBJ_HANDLER_P(val, get_properties_for)) {
226-
ht = Z_OBJ_HANDLER_P(val, get_properties_for)(val, ZEND_PROP_PURPOSE_ARRAY_CAST);
226+
ht = Z_OBJ_HANDLER_P(val, get_properties_for)(OBJ_FOR_PROP(val), ZEND_PROP_PURPOSE_ARRAY_CAST);
227227
free_ht = 1;
228228
} else {
229229
ht = Z_OBJPROP_P(val);
@@ -409,7 +409,7 @@ static inline void msgpack_serialize_object(smart_str *buf, zval *val, HashTable
409409

410410
if (ce && ce != PHP_IC_ENTRY &&
411411
zend_hash_exists(&ce->function_table, sleep_zstring)) {
412-
if ((res = call_user_function_ex(CG(function_table), val_noref, &fname, &retval, 0, 0, 1, NULL)) == SUCCESS) {
412+
if ((res = call_user_function(CG(function_table), val_noref, &fname, &retval, 0, 0)) == SUCCESS) {
413413

414414
if (EG(exception)) {
415415
zval_ptr_dtor(&retval);

msgpack_unpack.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static zend_class_entry* msgpack_unserialize_class(zval **container, zend_string
279279
ZVAL_STRING(&user_func, PG(unserialize_callback_func));
280280
ZVAL_STR(&args[0], class_name);
281281

282-
func_call_status = call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL);
282+
func_call_status = call_user_function(CG(function_table), NULL, &user_func, &retval, 1, args);
283283
zval_ptr_dtor(&user_func);
284284
if (func_call_status != SUCCESS) {
285285
MSGPACK_WARNING("[msgpack] (%s) defined (%s) but not found",
@@ -326,7 +326,11 @@ static zend_class_entry* msgpack_unserialize_class(zval **container, zend_string
326326

327327
/* store incomplete class name */
328328
if (incomplete_class) {
329+
#if PHP_VERSION_ID < 80000
329330
php_store_class_name(container_val, ZSTR_VAL(class_name), ZSTR_LEN(class_name));
331+
#else
332+
php_store_class_name(container_val, class_name);
333+
#endif
330334
}
331335

332336
return ce;
@@ -828,7 +832,7 @@ int msgpack_unserialize_map_item(msgpack_unserialize_data *unpack, zval **contai
828832
zend_hash_str_exists(&Z_OBJCE_P(container_val)->function_table, "__wakeup", sizeof("__wakeup") - 1)) {
829833
zval wakeup, r;
830834
ZVAL_STRING(&wakeup, "__wakeup");
831-
call_user_function_ex(CG(function_table), container_val, &wakeup, &r, 0, NULL, 1, NULL);
835+
call_user_function(CG(function_table), container_val, &wakeup, &r, 0, NULL);
832836
zval_ptr_dtor(&r);
833837
zval_ptr_dtor(&wakeup);
834838
}

php_msgpack.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ PHP_MSGPACK_API int php_msgpack_unserialize(
5252
# define MSGPACK_ENDIAN_BIG_BYTE 0
5353
#endif
5454

55+
#if PHP_VERSION_ID < 80000
56+
# define OBJ_FOR_PROP(zv) (zv)
57+
#else
58+
# define OBJ_FOR_PROP(zv) Z_OBJ_P(zv)
59+
#endif
60+
5561
#endif /* PHP_MSGPACK_H */

0 commit comments

Comments
 (0)