From e3ef2010a9ffb8bcc46a3d5a5a93ad1b048e3f96 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Wed, 15 Apr 2020 16:58:27 +0200 Subject: [PATCH] fix build with php 8 --- msgpack_convert.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/msgpack_convert.c b/msgpack_convert.c index c89aff5..93e55b2 100644 --- a/msgpack_convert.c +++ b/msgpack_convert.c @@ -64,7 +64,15 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object *properties = NULL; } ZVAL_LONG(&key_zv, key_index); +#if PHP_VERSION_ID < 80000 zend_std_write_property(object, &key_zv, val, NULL); +#else + { + zend_string *key = zval_get_string(&key_zv); + zend_std_write_property(Z_OBJ_P(object), key, val, NULL); + zend_string_release(key); + } +#endif return SUCCESS; } /* }}} */ @@ -87,7 +95,11 @@ static inline int msgpack_convert_string_to_properties(zval *object, zend_string zend_update_property_ex(ce, object, key, val); return_code = SUCCESS; } else { +#if PHP_VERSION_ID < 80000 zend_std_write_property(object, &pub_name, val, NULL); +#else + zend_std_write_property(Z_OBJ_P(object), key, val, NULL); +#endif return_code = FAILURE; } zend_hash_add(var, Z_STR(pub_name), val); @@ -358,7 +370,11 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */ } ZEND_HASH_FOREACH_END(); /* index */ +#if PHP_VERSION_ID < 80000 properties = Z_OBJ_HT_P(return_value)->get_properties(return_value); +#else + properties = Z_OBJ_HT_P(return_value)->get_properties(Z_OBJ_P(return_value)); +#endif if (HASH_OF(tpl)) { properties = HASH_OF(tpl); } @@ -433,7 +449,11 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */ HashTable *properties = NULL; HashPosition prop_pos; +#if PHP_VERSION_ID < 80000 properties = Z_OBJ_HT_P(return_value)->get_properties(return_value); +#else + properties = Z_OBJ_HT_P(return_value)->get_properties(Z_OBJ_P(return_value)); +#endif zend_hash_internal_pointer_reset_ex(properties, &prop_pos); if (msgpack_convert_long_to_properties(HASH_OF(return_value), return_value, &properties, &prop_pos, 0, value, NULL) != SUCCESS) { From f933cf5df92dbb2da8665905f1f44317f62a4765 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 31 Jul 2020 06:51:51 +0200 Subject: [PATCH] remove interned strings optimization causing exhaustive memory usage fixes #153 and possibly fixes #147 --- msgpack_unpack.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/msgpack_unpack.c b/msgpack_unpack.c index c743078..8dc9480 100644 --- a/msgpack_unpack.c +++ b/msgpack_unpack.c @@ -12,9 +12,6 @@ #if PHP_VERSION_ID < 70400 # define zval_try_get_string zval_get_string #endif -#if PHP_VERSION_ID < 70200 -# define zend_string_init_interned zend_string_init -#endif typedef struct { zend_long used_slots; @@ -523,12 +520,7 @@ int msgpack_unserialize_str(msgpack_unserialize_data *unpack, const char* base, ZVAL_EMPTY_STRING(*obj); } else { /* TODO: check malformed input? */ - if (len < 1<<8) { - zend_string *zs = zend_string_init_interned(data, len, 0); - ZVAL_STR(*obj, zs); - } else { - ZVAL_STRINGL(*obj, data, len); - } + ZVAL_STRINGL(*obj, data, len); } return 0; From 780b0b457693180f5f8a82ef1aef02f23f322e03 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 3 Sep 2020 09:37:26 +0200 Subject: [PATCH] more fix for PHP 8 --- msgpack_class.c | 2 +- msgpack_convert.c | 17 +++++++++-------- msgpack_pack.c | 4 ++-- msgpack_unpack.c | 8 ++++++-- php_msgpack.h | 6 ++++++ 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/msgpack_class.c b/msgpack_class.c index 69f3803..1b0ffe7 100644 --- a/msgpack_class.c +++ b/msgpack_class.c @@ -274,7 +274,7 @@ static ZEND_METHOD(msgpack, unpacker) /* {{{ */ { ZVAL_STRING(&func_name, "__construct"); object_init_ex(return_value, msgpack_unpacker_ce); - call_user_function_ex(CG(function_table), return_value, &func_name, &construct_return, 1, args, 0, NULL); + call_user_function(CG(function_table), return_value, &func_name, &construct_return, 1, args); zval_ptr_dtor(&func_name); } diff --git a/msgpack_convert.c b/msgpack_convert.c index 93e55b2..8f9e1d0 100644 --- a/msgpack_convert.c +++ b/msgpack_convert.c @@ -36,7 +36,7 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object if (msgpack_convert_array(&tplval, data, dataval) == SUCCESS) { zend_hash_move_forward_ex(props, prop_pos); - zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval); + zend_update_property(Z_OBJCE_P(object), OBJ_FOR_PROP(object), prop_name, prop_len, &tplval); return SUCCESS; } return FAILURE; @@ -45,14 +45,14 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object { if (msgpack_convert_object(&tplval, data, val) == SUCCESS) { zend_hash_move_forward_ex(props, prop_pos); - zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval); + zend_update_property(Z_OBJCE_P(object), OBJ_FOR_PROP(object), prop_name, prop_len, &tplval); return SUCCESS; } return FAILURE; } default: zend_hash_move_forward_ex(props, prop_pos); - zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, val); + zend_update_property(Z_OBJCE_P(object), OBJ_FOR_PROP(object), prop_name, prop_len, val); return SUCCESS; } } @@ -89,10 +89,10 @@ static inline int msgpack_convert_string_to_properties(zval *object, zend_string prot_name = zend_mangle_property_name("*", 1, ZSTR_VAL(key), ZSTR_LEN(key), 1); if (zend_hash_find(propers, priv_name) != NULL) { - zend_update_property_ex(ce, object, key, val); + zend_update_property_ex(ce, OBJ_FOR_PROP(object), key, val); return_code = SUCCESS; } else if (zend_hash_find(propers, prot_name) != NULL) { - zend_update_property_ex(ce, object, key, val); + zend_update_property_ex(ce, OBJ_FOR_PROP(object), key, val); return_code = SUCCESS; } else { #if PHP_VERSION_ID < 80000 @@ -310,8 +310,9 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */ fci.retval = &retval; fci.param_count = 0; fci.params = ¶ms; +#if PHP_VERSION_ID < 80000 fci.no_separation = 1; - +#endif #if PHP_VERSION_ID < 70300 fcc.initialized = 1; #endif @@ -434,10 +435,10 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */ return FAILURE; } - zend_update_property_ex(ce, return_value, str_key, &nv); + zend_update_property_ex(ce, OBJ_FOR_PROP(return_value), str_key, &nv); zval_ptr_dtor(&nv); } else { - zend_update_property(ce, return_value, prop_name, prop_len, aryval); + zend_update_property(ce, OBJ_FOR_PROP(return_value), prop_name, prop_len, aryval); } num_key++; } ZEND_HASH_FOREACH_END(); diff --git a/msgpack_pack.c b/msgpack_pack.c index c5da6d9..f9d1ad0 100644 --- a/msgpack_pack.c +++ b/msgpack_pack.c @@ -223,7 +223,7 @@ static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable if (object) { #if PHP_VERSION_ID >= 70400 if (Z_OBJ_HANDLER_P(val, get_properties_for)) { - ht = Z_OBJ_HANDLER_P(val, get_properties_for)(val, ZEND_PROP_PURPOSE_ARRAY_CAST); + ht = Z_OBJ_HANDLER_P(val, get_properties_for)(OBJ_FOR_PROP(val), ZEND_PROP_PURPOSE_ARRAY_CAST); free_ht = 1; } else { ht = Z_OBJPROP_P(val); @@ -409,7 +409,7 @@ static inline void msgpack_serialize_object(smart_str *buf, zval *val, HashTable if (ce && ce != PHP_IC_ENTRY && zend_hash_exists(&ce->function_table, sleep_zstring)) { - if ((res = call_user_function_ex(CG(function_table), val_noref, &fname, &retval, 0, 0, 1, NULL)) == SUCCESS) { + if ((res = call_user_function(CG(function_table), val_noref, &fname, &retval, 0, 0)) == SUCCESS) { if (EG(exception)) { zval_ptr_dtor(&retval); diff --git a/msgpack_unpack.c b/msgpack_unpack.c index 9ce1961..a602c52 100644 --- a/msgpack_unpack.c +++ b/msgpack_unpack.c @@ -282,7 +282,7 @@ static zend_class_entry* msgpack_unserialize_class(zval **container, zend_string ZVAL_STRING(&user_func, PG(unserialize_callback_func)); ZVAL_STR(&args[0], class_name); - func_call_status = call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL); + func_call_status = call_user_function(CG(function_table), NULL, &user_func, &retval, 1, args); zval_ptr_dtor(&user_func); if (func_call_status != SUCCESS) { MSGPACK_WARNING("[msgpack] (%s) defined (%s) but not found", @@ -329,7 +329,11 @@ static zend_class_entry* msgpack_unserialize_class(zval **container, zend_string /* store incomplete class name */ if (incomplete_class) { +#if PHP_VERSION_ID < 80000 php_store_class_name(container_val, ZSTR_VAL(class_name), ZSTR_LEN(class_name)); +#else + php_store_class_name(container_val, class_name); +#endif } return ce; @@ -836,7 +840,7 @@ int msgpack_unserialize_map_item(msgpack_unserialize_data *unpack, zval **contai zend_hash_str_exists(&Z_OBJCE_P(container_val)->function_table, "__wakeup", sizeof("__wakeup") - 1)) { zval wakeup, r; ZVAL_STRING(&wakeup, "__wakeup"); - call_user_function_ex(CG(function_table), container_val, &wakeup, &r, 0, NULL, 1, NULL); + call_user_function(CG(function_table), container_val, &wakeup, &r, 0, NULL); zval_ptr_dtor(&r); zval_ptr_dtor(&wakeup); } diff --git a/php_msgpack.h b/php_msgpack.h index d5f9164..6ecd5f4 100644 --- a/php_msgpack.h +++ b/php_msgpack.h @@ -52,4 +52,10 @@ PHP_MSGPACK_API int php_msgpack_unserialize( # define MSGPACK_ENDIAN_BIG_BYTE 0 #endif +#if PHP_VERSION_ID < 80000 +# define OBJ_FOR_PROP(zv) (zv) +#else +# define OBJ_FOR_PROP(zv) Z_OBJ_P(zv) +#endif + #endif /* PHP_MSGPACK_H */ From 77368369d8c9b7a9f135d3b6aef2c26656dd4b55 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 23 Sep 2020 09:13:30 +0200 Subject: [PATCH] msgpack_convert: fix crash on callback with PHP 8 --- msgpack_convert.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/msgpack_convert.c b/msgpack_convert.c index 8f9e1d0..1f90ef4 100644 --- a/msgpack_convert.c +++ b/msgpack_convert.c @@ -296,28 +296,27 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */ /* Run the constructor if there is one */ if (ce->constructor && (ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { - zval retval, params, function_name; + zval retval; zend_fcall_info fci; zend_fcall_info_cache fcc; + memset(&fci, 0, sizeof(fci)); + memset(&fcc, 0, sizeof(fcc)); + fci.size = sizeof(fci); #if PHP_VERSION_ID < 70100 fci.function_table = EG(function_table); - fci.symbol_table = NULL; #endif - fci.function_name = function_name; fci.object = Z_OBJ_P(return_value); fci.retval = &retval; - fci.param_count = 0; - fci.params = ¶ms; #if PHP_VERSION_ID < 80000 fci.no_separation = 1; #endif + #if PHP_VERSION_ID < 70300 fcc.initialized = 1; #endif fcc.function_handler = ce->constructor; - #if PHP_VERSION_ID < 70100 fcc.calling_scope = EG(scope); #else From 87e0424e81e9187e39b3d1e7e4d1bb47a94d95e0 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 23 Sep 2020 09:36:34 +0200 Subject: [PATCH] tests: do not depend on ext/curl for a simple resource --- tests/023.phpt | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tests/023.phpt b/tests/023.phpt index 442fe3d..c1c72c3 100644 --- a/tests/023.phpt +++ b/tests/023.phpt @@ -19,24 +19,10 @@ function test($type, $variable, $test) { echo $test || $unserialized === null ? 'OK' : 'FAIL', PHP_EOL; } -if (function_exists('curl_init')) { - $test = 'curl'; - $res = curl_init('http://php.net/'); -} else { - $test = 'dir'; - $res = opendir('/tmp'); -} - +$res = opendir('/tmp'); test('resource', $res, false); +closedir($res); -switch ($test) { - case 'curl': - curl_close($res); - break; - default: - closedir($res); - break; -} ?> --EXPECT-- resource From 80d82ac7b21b660501886c5b29ea1186e025de91 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 23 Sep 2020 09:53:29 +0200 Subject: [PATCH] tests: PHP 8 somehow detects recursion earlier --- package.xml | 242 ++++++++++++++++++++++++------------------------ tests/009.phpt | 7 +- tests/009a.phpt | 99 ++++++++++++++++++++ tests/026.phpt | 7 +- tests/026a.phpt | 109 ++++++++++++++++++++++ 5 files changed, 336 insertions(+), 128 deletions(-) create mode 100644 tests/009a.phpt create mode 100644 tests/026a.phpt diff --git a/tests/009.phpt b/tests/009.phpt index feed76f..b917e98 100644 --- a/tests/009.phpt +++ b/tests/009.phpt @@ -2,11 +2,10 @@ Check for reference serialization --SKIPIF-- = 0 && - version_compare(PHP_VERSION, '5.3.2') <= 0)) { - echo "skip tests in PHP 5.2.14/5.3.3 or newer"; +if (version_compare(PHP_VERSION, "8.0.0dev", ">=")) { + die("skip PHP >= 8.0\n"); } +?> --FILE-- +--FILE-- + + array(1) { + [0]=> + string(3) "foo" + } + [1]=> + array(1) { + [0]=> + string(3) "foo" + } +} +OK +array(&$a, &$a) +9282c00100a3666f6f82c0020002 +array(2) { + [0]=> + &array(1) { + [0]=> + string(3) "foo" + } + [1]=> + &array(1) { + [0]=> + string(3) "foo" + } +} +OK +cyclic +9182c0010082c0010082c0020002 +array(1) { + [0]=> + &array(1) { + [0]=> + array(1) { + [0]=> + *RECURSION* + } + } +} +OK +array(1) { + [0]=> + &array(1) { + [0]=> + *RECURSION* + } +} +array(1) { + [0]=> + &array(1) { + [0]=> + array(1) { + [0]=> + *RECURSION* + } + } +} diff --git a/tests/026.phpt b/tests/026.phpt index d89654d..ba59a71 100644 --- a/tests/026.phpt +++ b/tests/026.phpt @@ -3,11 +3,10 @@ Cyclic array test --INI-- --SKIPIF-- = 0 && - version_compare(PHP_VERSION, '5.3.2') <= 0)) { - echo "skip tests in PHP 5.2.14/5.3.3 or newer"; +if (version_compare(PHP_VERSION, "8.0.0dev", ">=")) { + die("skip PHP >= 8.0"); } +?> --FILE-- +--FILE-- + array( + 'b' => 'c', + 'd' => 'e' + ), +); + +$a['f'] = &$a; + +test('array', $a, true); + +$a = array("foo" => &$b); +$b = array(1, 2, $a); +var_dump($a); +var_dump($k = msgpack_unserialize(msgpack_serialize($a))); + +$k["foo"][1] = "b"; +var_dump($k); +?> +--EXPECT-- +array +82a16182a162a163a164a165a16683c001a16182a162a163a164a165a16682c0020003 +array(2) { + ["a"]=> + array(2) { + ["b"]=> + string(1) "c" + ["d"]=> + string(1) "e" + } + ["f"]=> + &array(2) { + ["a"]=> + array(2) { + ["b"]=> + string(1) "c" + ["d"]=> + string(1) "e" + } + ["f"]=> + *RECURSION* + } +} +OK +array(1) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + *RECURSION* + } +} +array(1) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + ["foo"]=> + *RECURSION* + } + } +} +array(1) { + ["foo"]=> + &array(3) { + [0]=> + int(1) + [1]=> + string(1) "b" + [2]=> + array(1) { + ["foo"]=> + *RECURSION* + } + } +}