diff --git a/msgpack.c b/msgpack.c index 3360b31..9663146 100644 --- a/msgpack.c +++ b/msgpack.c @@ -93,11 +93,8 @@ static ZEND_MINIT_FUNCTION(msgpack) msgpack_init_class(); -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 1) - REGISTER_LONG_CONSTANT( - "MESSAGEPACK_OPT_PHPONLY", MSGPACK_CLASS_OPT_PHPONLY, - CONST_CS | CONST_PERSISTENT); -#endif + REGISTER_LONG_CONSTANT("MESSAGEPACK_OPT_PHPONLY", + MSGPACK_CLASS_OPT_PHPONLY, CONST_CS | CONST_PERSISTENT); return SUCCESS; } @@ -124,9 +121,7 @@ static ZEND_MINFO_FUNCTION(msgpack) } zend_module_entry msgpack_module_entry = { -#if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, -#endif "msgpack", msgpack_functions, ZEND_MINIT(msgpack), @@ -134,9 +129,7 @@ zend_module_entry msgpack_module_entry = { NULL, NULL, ZEND_MINFO(msgpack), -#if ZEND_MODULE_API_NO >= 20010901 PHP_MSGPACK_VERSION, -#endif STANDARD_MODULE_PROPERTIES }; @@ -147,91 +140,60 @@ ZEND_GET_MODULE(msgpack) #if HAVE_PHP_SESSION PS_SERIALIZER_ENCODE_FUNC(msgpack) { - smart_str buf = {0}; + smart_string buf = {0}; + zend_string *z_string; msgpack_serialize_data_t var_hash; msgpack_serialize_var_init(&var_hash); - - msgpack_serialize_zval(&buf, PS(http_session_vars), var_hash TSRMLS_CC); - - if (newlen) - { - *newlen = buf.len; - } - - smart_str_0(&buf); - *newstr = buf.c; - + msgpack_serialize_zval(&buf, &PS(http_session_vars), var_hash); msgpack_serialize_var_destroy(&var_hash); - return SUCCESS; + z_string = zend_string_init(buf.c, buf.len, 0); + smart_string_free(&buf); + + return z_string; } PS_SERIALIZER_DECODE_FUNC(msgpack) { int ret; - HashTable *tmp_hash; - HashPosition tmp_hash_pos; - char *key_str; - ulong key_long; - uint key_len; - zval *tmp; - zval **value; + zend_string *key_str; + zval tmp, *value; size_t off = 0; msgpack_unpack_t mp; msgpack_unserialize_data_t var_hash; - ALLOC_INIT_ZVAL(tmp); - template_init(&mp); msgpack_unserialize_var_init(&var_hash); - mp.user.retval = (zval *)tmp; - mp.user.var_hash = (msgpack_unserialize_data_t *)&var_hash; + mp.user.retval = &tmp; + mp.user.var_hash = &var_hash; - ret = template_execute(&mp, (char *)val, (size_t)vallen, &off); + ret = template_execute(&mp, val, vallen, &off); - if (ret == MSGPACK_UNPACK_EXTRA_BYTES || ret == MSGPACK_UNPACK_SUCCESS) - { + if (ret == MSGPACK_UNPACK_EXTRA_BYTES || ret == MSGPACK_UNPACK_SUCCESS) { + msgpack_unserialize_set_return_value(&var_hash, &tmp); msgpack_unserialize_var_destroy(&var_hash, 0); - tmp_hash = HASH_OF(tmp); - - zend_hash_internal_pointer_reset_ex(tmp_hash, &tmp_hash_pos); - - while (zend_hash_get_current_data_ex( - tmp_hash, (void *)&value, &tmp_hash_pos) == SUCCESS) - { - ret = zend_hash_get_current_key_ex( - tmp_hash, &key_str, &key_len, &key_long, 0, &tmp_hash_pos); - switch (ret) - { - case HASH_KEY_IS_LONG: - /* ??? */ - break; - case HASH_KEY_IS_STRING: - php_set_session_var( - key_str, key_len - 1, *value, NULL TSRMLS_CC); - php_add_session_var(key_str, key_len - 1 TSRMLS_CC); - break; + ZEND_HASH_FOREACH_STR_KEY_VAL(HASH_OF(&tmp), key_str, value) { + if (key_str) { + php_set_session_var(key_str, value, NULL); + php_add_session_var(key_str); } - zend_hash_move_forward_ex(tmp_hash, &tmp_hash_pos); - } - } - else - { + } ZEND_HASH_FOREACH_END(); + zval_ptr_dtor(&tmp); + } else { msgpack_unserialize_var_destroy(&var_hash, 1); } - zval_ptr_dtor(&tmp); - return SUCCESS; } #endif -PHP_MSGPACK_API void php_msgpack_serialize(smart_str *buf, zval *val TSRMLS_DC) +PHP_MSGPACK_API void php_msgpack_serialize(smart_string *buf, zval *val TSRMLS_DC) { + msgpack_serialize_data_t var_hash; msgpack_serialize_var_init(&var_hash); @@ -259,13 +221,12 @@ PHP_MSGPACK_API void php_msgpack_unserialize( msgpack_unserialize_var_init(&var_hash); RETVAL_NULL(); - mp.user.retval = (zval *)return_value; - mp.user.var_hash = (msgpack_unserialize_data_t *)&var_hash; + mp.user.retval = return_value; + mp.user.var_hash = &var_hash; ret = template_execute(&mp, str, (size_t)str_len, &off); - switch (ret) - { + switch (ret) { case MSGPACK_UNPACK_PARSE_ERROR: zval_dtor(return_value); ZVAL_FALSE(return_value); @@ -274,15 +235,16 @@ PHP_MSGPACK_API void php_msgpack_unserialize( break; case MSGPACK_UNPACK_CONTINUE: msgpack_unserialize_var_destroy(&var_hash, 0); + ZVAL_FALSE(return_value); MSGPACK_WARNING( "[msgpack] (%s) Insufficient data for unserializing", __FUNCTION__); break; case MSGPACK_UNPACK_EXTRA_BYTES: case MSGPACK_UNPACK_SUCCESS: + msgpack_unserialize_set_return_value(&var_hash, return_value); msgpack_unserialize_var_destroy(&var_hash, 0); - if (off < (size_t)str_len) - { + if (off < str_len) { MSGPACK_WARNING("[msgpack] (%s) Extra bytes", __FUNCTION__); } break; @@ -298,52 +260,43 @@ PHP_MSGPACK_API void php_msgpack_unserialize( static ZEND_FUNCTION(msgpack_serialize) { zval *parameter; - smart_str buf = {0}; + smart_string buf = {0}; - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meter) == FAILURE) - { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meter) == FAILURE) { return; } php_msgpack_serialize(&buf, parameter TSRMLS_CC); - smart_str_0(&buf); + smart_string_0(&buf); - ZVAL_STRINGL(return_value, buf.c, buf.len, 0); + ZVAL_STRINGL(return_value, buf.c, buf.len); + smart_string_free(&buf); } static ZEND_FUNCTION(msgpack_unserialize) { - char *str; - int str_len; + zend_string *str; zval *object = NULL; - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "s|z", - &str, &str_len, &object) == FAILURE) - { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|z", &str, &object) == FAILURE) { return; } - if (!str_len) - { + if (!str) { RETURN_NULL(); } - if (object == NULL) - { - php_msgpack_unserialize(return_value, str, str_len TSRMLS_CC); - } - else - { - zval *zv; + if (object == NULL) { + php_msgpack_unserialize(return_value, str->val, str->len); + } else { + zval zv, *zv_p; + zv_p = &zv; - ALLOC_INIT_ZVAL(zv); - php_msgpack_unserialize(zv, str, str_len TSRMLS_CC); + php_msgpack_unserialize(&zv, str->val, str->len); - if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) - { + if (msgpack_convert_template(return_value, object, &zv_p) != SUCCESS) { RETURN_NULL(); } + } } diff --git a/msgpack_class.c b/msgpack_class.c index 740ca7a..1b92dc1 100644 --- a/msgpack_class.c +++ b/msgpack_class.c @@ -8,73 +8,35 @@ #include "msgpack_errors.h" typedef struct { - zend_object object; long php_only; + zend_object object; } php_msgpack_base_t; typedef struct { - zend_object object; - smart_str buffer; - zval *retval; + smart_string buffer; + zval retval; long offset; msgpack_unpack_t mp; msgpack_unserialize_data_t var_hash; long php_only; zend_bool finished; int error; + zend_object object; } php_msgpack_unpacker_t; -#if ZEND_MODULE_API_NO >= 20060613 -# define MSGPACK_METHOD_BASE(classname, name) zim_##classname##_##name -#else -# define MSGPACK_METHOD_BASE(classname, name) zif_##classname##_##name -#endif - -#if ZEND_MODULE_API_NO >= 20090115 -# define PUSH_PARAM(arg) zend_vm_stack_push(arg TSRMLS_CC) -# define POP_PARAM() (void)zend_vm_stack_pop(TSRMLS_C) -# define PUSH_EO_PARAM() -# define POP_EO_PARAM() -#else -# define PUSH_PARAM(arg) zend_ptr_stack_push(&EG(argument_stack), arg) -# define POP_PARAM() (void)zend_ptr_stack_pop(&EG(argument_stack)) -# define PUSH_EO_PARAM() zend_ptr_stack_push(&EG(argument_stack), NULL) -# define POP_EO_PARAM() (void)zend_ptr_stack_pop(&EG(argument_stack)) -#endif - -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) -#define MSGPACK_METHOD_HELPER(classname, name, retval, thisptr, num, param) \ - PUSH_PARAM(param); PUSH_PARAM((void*)num); \ - PUSH_EO_PARAM(); \ - MSGPACK_METHOD_BASE(classname, name)(num, retval, NULL, thisptr, 0 TSRMLS_CC); \ - POP_EO_PARAM(); \ - POP_PARAM(); POP_PARAM(); -#define MSGPACK_METHOD(classname, name, retval, thisptr) \ - MSGPACK_METHOD_BASE(classname, name)(0, retval, NULL, thisptr, 0 TSRMLS_CC) -#else -#define MSGPACK_METHOD_HELPER(classname, name, retval, thisptr, num, param) \ - PUSH_PARAM(param); PUSH_PARAM((void*)num); \ - PUSH_EO_PARAM(); \ - MSGPACK_METHOD_BASE(classname, name)(num, retval, thisptr, 0 TSRMLS_CC); \ - POP_EO_PARAM(); \ - POP_PARAM(); POP_PARAM(); -#define MSGPACK_METHOD(classname, name, retval, thisptr) \ - MSGPACK_METHOD_BASE(classname, name)(0, retval, thisptr, 0 TSRMLS_CC) -#endif - -#define MSGPACK_METHOD1(classname, name, retval, thisptr, param1) \ - MSGPACK_METHOD_HELPER(classname, name, retval, thisptr, 1, param1); - -#define MSGPACK_BASE_OBJECT \ - php_msgpack_base_t *base; \ - base = (php_msgpack_base_t *)zend_object_store_get_object(getThis() TSRMLS_CC); - -#define MSGPACK_UNPACKER_OBJECT \ - php_msgpack_unpacker_t *unpacker; \ - unpacker = (php_msgpack_unpacker_t *)zend_object_store_get_object(getThis() TSRMLS_CC); +static inline php_msgpack_base_t *msgpack_base_fetch_object(zend_object *obj) { + return (php_msgpack_base_t *)((char*)(obj) - XtOffsetOf(php_msgpack_base_t, object)); +} +#define Z_MSGPACK_BASE_P(zv) msgpack_base_fetch_object(Z_OBJ_P((zv))) + +static inline php_msgpack_unpacker_t *msgpack_unpacker_fetch_object(zend_object *obj) { + return (php_msgpack_unpacker_t *)((char*)(obj) - XtOffsetOf(php_msgpack_unpacker_t, object)); +} +#define Z_MSGPACK_UNPACKER_P(zv) msgpack_unpacker_fetch_object(Z_OBJ_P((zv))) /* MessagePack */ static zend_class_entry *msgpack_ce = NULL; +zend_object_handlers msgpack_handlers; static ZEND_METHOD(msgpack, __construct); static ZEND_METHOD(msgpack, setOption); @@ -115,6 +77,7 @@ static zend_function_entry msgpack_base_methods[] = { /* MessagePackUnpacker */ static zend_class_entry *msgpack_unpacker_ce = NULL; +zend_object_handlers msgpack_unpacker_handlers; static ZEND_METHOD(msgpack_unpacker, __construct); static ZEND_METHOD(msgpack_unpacker, __destruct); @@ -169,112 +132,50 @@ static zend_function_entry msgpack_unpacker_methods[] = { arginfo_msgpack_unpacker_reset, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; - -static void php_msgpack_base_free(php_msgpack_base_t *base TSRMLS_DC) -{ -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) - zend_object_std_dtor(&base->object TSRMLS_CC); -#else - if (base->object.properties) - { - zend_hash_destroy(base->object.properties); - FREE_HASHTABLE(base->object.properties); +zend_object *php_msgpack_base_new(zend_class_entry *ce TSRMLS_DC) { + php_msgpack_base_t *intern = ecalloc(1, + sizeof(php_msgpack_base_t) + + zend_object_properties_size(ce)); + + zend_object_std_init(&intern->object, ce TSRMLS_CC); + object_properties_init(&intern->object, ce); + intern->object.handlers = &msgpack_handlers; + return &intern->object; +} +static void php_msgpack_base_free(zend_object *object) { + php_msgpack_base_t *intern = msgpack_base_fetch_object(object); + if (!intern) { + return; } -#endif - efree(base); + zend_object_std_dtor(&intern->object); } -static zend_object_value php_msgpack_base_new(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_msgpack_base_t *base; -#if PHP_API_VERSION < 20100412 - zval *tmp; -#endif - - base = emalloc(sizeof(php_msgpack_base_t)); - -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) - zend_object_std_init(&base->object, ce TSRMLS_CC); -#else - ALLOC_HASHTABLE(base->object.properties); - zend_hash_init(base->object.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - base->object.ce = ce; -#endif - -#if PHP_API_VERSION < 20100412 - zend_hash_copy( - base->object.properties, &ce->default_properties, - (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); -#else - object_properties_init(&base->object, ce); -#endif - - retval.handle = zend_objects_store_put( - base, (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_msgpack_base_free, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - - return retval; +zend_object *php_msgpack_unpacker_new(zend_class_entry *ce TSRMLS_DC) { + php_msgpack_unpacker_t *intern = ecalloc(1, + sizeof(php_msgpack_unpacker_t) + + zend_object_properties_size(ce)); + + zend_object_std_init(&intern->object, ce TSRMLS_CC); + object_properties_init(&intern->object, ce); + intern->object.handlers = &msgpack_unpacker_handlers; + return &intern->object; } -static void php_msgpack_unpacker_free( - php_msgpack_unpacker_t *unpacker TSRMLS_DC) +static void php_msgpack_unpacker_free(zend_object *object) { -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) - zend_object_std_dtor(&unpacker->object TSRMLS_CC); -#else - if (unpacker->object.properties) - { - zend_hash_destroy(unpacker->object.properties); - FREE_HASHTABLE(unpacker->object.properties); + php_msgpack_unpacker_t *intern = msgpack_unpacker_fetch_object(object); + if (!intern) { + return; } -#endif - efree(unpacker); + zend_object_std_dtor(&intern->object); } -static zend_object_value php_msgpack_unpacker_new( - zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value retval; - php_msgpack_unpacker_t *unpacker; -#if PHP_API_VERSION < 20100412 - zval *tmp; -#endif - - unpacker = emalloc(sizeof(php_msgpack_unpacker_t)); - -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) - zend_object_std_init(&unpacker->object, ce TSRMLS_CC); -#else - ALLOC_HASHTABLE(unpacker->object.properties); - zend_hash_init(unpacker->object.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - unpacker->object.ce = ce; -#endif - -#if PHP_API_VERSION < 20100412 - zend_hash_copy( - unpacker->object.properties, &ce->default_properties, - (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *)); -#else - object_properties_init(&unpacker->object, ce); -#endif - - retval.handle = zend_objects_store_put( - unpacker, (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)php_msgpack_unpacker_free, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); - - return retval; -} /* MessagePack */ static ZEND_METHOD(msgpack, __construct) { zend_bool php_only = MSGPACK_G(php_only); - MSGPACK_BASE_OBJECT; + php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|b", &php_only) == FAILURE) @@ -289,19 +190,16 @@ static ZEND_METHOD(msgpack, setOption) { long option; zval *value; - MSGPACK_BASE_OBJECT; + php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "lz", &option, &value) == FAILURE) - { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", &option, &value) == FAILURE) { return; } - switch (option) - { + switch (option) { case MSGPACK_CLASS_OPT_PHPONLY: convert_to_boolean(value); - base->php_only = Z_BVAL_P(value); + base->php_only = (Z_TYPE_P(value) == IS_TRUE) ? 1 : 0; break; default: MSGPACK_WARNING("[msgpack] (MessagePack::setOption) " @@ -316,13 +214,11 @@ static ZEND_METHOD(msgpack, setOption) static ZEND_METHOD(msgpack, pack) { zval *parameter; - smart_str buf = {0}; + smart_string buf = {0}; int php_only = MSGPACK_G(php_only); - MSGPACK_BASE_OBJECT; + php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meter) == FAILURE) - { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meter) == FAILURE) { return; } @@ -332,47 +228,38 @@ static ZEND_METHOD(msgpack, pack) MSGPACK_G(php_only) = php_only; - ZVAL_STRINGL(return_value, buf.c, buf.len, 1); + ZVAL_STRINGL(return_value, buf.c, buf.len); - smart_str_free(&buf); + smart_string_free(&buf); } static ZEND_METHOD(msgpack, unpack) { - char *str; - int str_len; + zend_string *str; zval *object = NULL; int php_only = MSGPACK_G(php_only); - MSGPACK_BASE_OBJECT; + php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "s|z", - &str, &str_len, &object) == FAILURE) - { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|z", &str, &object) == FAILURE) { return; } - if (!str_len) - { - RETURN_FALSE; + if (!str) { + RETURN_NULL(); } MSGPACK_G(php_only) = base->php_only; - if (object == NULL) - { - php_msgpack_unserialize(return_value, str, str_len TSRMLS_CC); - } - else - { - zval *zv; + if (object == NULL) { + php_msgpack_unserialize(return_value, str->val, str->len); + } else { + zval zv, *zv_p; + zv_p = &zv; - ALLOC_INIT_ZVAL(zv); - php_msgpack_unserialize(zv, str, str_len TSRMLS_CC); + php_msgpack_unserialize(&zv, str->val, str->len TSRMLS_CC); - if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) - { - RETURN_FALSE; + if (msgpack_convert_template(return_value, object, &zv_p) != SUCCESS) { + RETURN_NULL(); } } @@ -381,28 +268,25 @@ static ZEND_METHOD(msgpack, unpack) static ZEND_METHOD(msgpack, unpacker) { - zval temp, *opt; - MSGPACK_BASE_OBJECT; + zval temp, args[1], func_name, construct_return; + php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); - ALLOC_INIT_ZVAL(opt); - ZVAL_BOOL(opt, base->php_only); + ZVAL_BOOL(&args[0], base->php_only); + 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); - MSGPACK_METHOD1(msgpack_unpacker, __construct, &temp, return_value, opt); - - zval_ptr_dtor(&opt); + zval_ptr_dtor(&func_name); } /* MessagePackUnpacker */ static ZEND_METHOD(msgpack_unpacker, __construct) { zend_bool php_only = MSGPACK_G(php_only); - MSGPACK_UNPACKER_OBJECT; + php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "|b", &php_only) == FAILURE) - { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &php_only) == FAILURE) { return; } @@ -411,7 +295,6 @@ static ZEND_METHOD(msgpack_unpacker, __construct) unpacker->buffer.c = NULL; unpacker->buffer.len = 0; unpacker->buffer.a = 0; - unpacker->retval = NULL; unpacker->offset = 0; unpacker->finished = 0; unpacker->error = 0; @@ -420,21 +303,13 @@ static ZEND_METHOD(msgpack_unpacker, __construct) msgpack_unserialize_var_init(&unpacker->var_hash); - (&unpacker->mp)->user.var_hash = - (msgpack_unserialize_data_t *)&unpacker->var_hash; + (&unpacker->mp)->user.var_hash = &unpacker->var_hash; } static ZEND_METHOD(msgpack_unpacker, __destruct) { - MSGPACK_UNPACKER_OBJECT; - - smart_str_free(&unpacker->buffer); - - if (unpacker->retval != NULL) - { - zval_ptr_dtor(&unpacker->retval); - } - + php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); + smart_string_free(&unpacker->buffer); msgpack_unserialize_var_destroy(&unpacker->var_hash, unpacker->error); } @@ -442,7 +317,8 @@ static ZEND_METHOD(msgpack_unpacker, setOption) { long option; zval *value; - MSGPACK_UNPACKER_OBJECT; + php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); + if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "lz", &option, &value) == FAILURE) @@ -454,7 +330,7 @@ static ZEND_METHOD(msgpack_unpacker, setOption) { case MSGPACK_CLASS_OPT_PHPONLY: convert_to_boolean(value); - unpacker->php_only = Z_BVAL_P(value); + unpacker->php_only = Z_LVAL_P(value); break; default: MSGPACK_WARNING("[msgpack] (MessagePackUnpacker::setOption) " @@ -468,22 +344,18 @@ static ZEND_METHOD(msgpack_unpacker, setOption) static ZEND_METHOD(msgpack_unpacker, feed) { - char *str; - int str_len; - MSGPACK_UNPACKER_OBJECT; + zend_string *str; + php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) - { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { return; } - if (!str_len) - { + if (!str) { RETURN_FALSE; } - smart_str_appendl(&unpacker->buffer, str, str_len); + smart_string_appendl(&unpacker->buffer, str->val, str->len); RETURN_TRUE; } @@ -491,62 +363,41 @@ static ZEND_METHOD(msgpack_unpacker, feed) static ZEND_METHOD(msgpack_unpacker, execute) { char *str = NULL, *data; - long str_len = 0; + size_t len, off, str_len = 0; + int ret, error_display = MSGPACK_G(error_display), php_only = MSGPACK_G(php_only); zval *offset = NULL; - int ret; - size_t len, off; - int error_display = MSGPACK_G(error_display); - int php_only = MSGPACK_G(php_only); - MSGPACK_UNPACKER_OBJECT; + php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "|sz/", - &str, &str_len, &offset) == FAILURE) - { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sz/", &str, &str_len, &offset) == FAILURE) { return; } - if (str != NULL) - { - data = (char *)str; - len = (size_t)str_len; - if (offset != NULL) - { + if (str) { + data = str; + len = str_len; + if (offset != NULL && (Z_TYPE_P(offset) == IS_LONG || Z_TYPE_P(offset) == IS_DOUBLE)) { off = Z_LVAL_P(offset); - } - else - { + } else { off = 0; } - } - else - { - data = (char *)unpacker->buffer.c; + } else { + data = unpacker->buffer.c; len = unpacker->buffer.len; off = unpacker->offset; } - if (unpacker->retval == NULL) - { - ALLOC_INIT_ZVAL(unpacker->retval); - } - else if (unpacker->finished) - { - zval_ptr_dtor(&unpacker->retval); - + if (unpacker->finished) { + msgpack_unserialize_set_return_value(&unpacker->var_hash, &unpacker->retval); msgpack_unserialize_var_destroy(&unpacker->var_hash, unpacker->error); unpacker->error = 0; - ALLOC_INIT_ZVAL(unpacker->retval); - template_init(&unpacker->mp); msgpack_unserialize_var_init(&unpacker->var_hash); - (&unpacker->mp)->user.var_hash = - (msgpack_unserialize_data_t *)&unpacker->var_hash; + (&unpacker->mp)->user.var_hash = &unpacker->var_hash; } - (&unpacker->mp)->user.retval = (zval *)unpacker->retval; + (&unpacker->mp)->user.retval = &unpacker->retval; MSGPACK_G(error_display) = 0; MSGPACK_G(php_only) = unpacker->php_only; @@ -556,20 +407,15 @@ static ZEND_METHOD(msgpack_unpacker, execute) MSGPACK_G(error_display) = error_display; MSGPACK_G(php_only) = php_only; - if (str != NULL) - { - if (offset != NULL) - { + if (str != NULL) { + if (offset != NULL) { ZVAL_LONG(offset, off); } - } - else - { + } else { unpacker->offset = off; } - switch (ret) - { + switch (ret) { case MSGPACK_UNPACK_EXTRA_BYTES: case MSGPACK_UNPACK_SUCCESS: unpacker->finished = 1; @@ -583,54 +429,46 @@ static ZEND_METHOD(msgpack_unpacker, execute) static ZEND_METHOD(msgpack_unpacker, data) { - zval *object = NULL; - MSGPACK_UNPACKER_OBJECT; + zval *object = NULL, func_name, reset_return; + php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, "|z", &object) == FAILURE) - { + if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|z", &object) == FAILURE) { return; } - if (unpacker->retval != NULL) - { - if (object == NULL) - { - ZVAL_ZVAL(return_value, unpacker->retval, 1, 0); - } - else - { - zval *zv; + if (unpacker->finished) { + msgpack_unserialize_set_return_value(&unpacker->var_hash, &unpacker->retval); + } - ALLOC_INIT_ZVAL(zv); - ZVAL_ZVAL(zv, unpacker->retval, 1, 0); + if (object == NULL) { + ZVAL_COPY_VALUE(return_value, &unpacker->retval); + } else { + zval zv, *zv_p; + zv_p = &zv; - if (msgpack_convert_object(return_value, object, &zv) != SUCCESS) - { - RETURN_NULL(); - } - } + ZVAL_COPY_VALUE(zv_p, &unpacker->retval); - MSGPACK_METHOD(msgpack_unpacker, reset, NULL, getThis()); - - return; + if (msgpack_convert_object(return_value, object, &zv_p) != SUCCESS) { + RETURN_NULL(); + } } - RETURN_FALSE; + ZVAL_STRING(&func_name, "reset"); + call_user_function_ex(CG(function_table), getThis(), &func_name, &reset_return, 0, NULL, 0, NULL); + zval_ptr_dtor(&func_name); } static ZEND_METHOD(msgpack_unpacker, reset) { - smart_str buffer = {0}; - MSGPACK_UNPACKER_OBJECT; + smart_string buffer = {0}; + php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); - if (unpacker->buffer.len > unpacker->offset) - { - smart_str_appendl(&buffer, unpacker->buffer.c + unpacker->offset, + if (unpacker->buffer.len > unpacker->offset) { + smart_string_appendl(&buffer, unpacker->buffer.c + unpacker->offset, unpacker->buffer.len - unpacker->offset); } - smart_str_free(&unpacker->buffer); + smart_string_free(&unpacker->buffer); unpacker->buffer.c = NULL; unpacker->buffer.len = 0; @@ -638,18 +476,11 @@ static ZEND_METHOD(msgpack_unpacker, reset) unpacker->offset = 0; unpacker->finished = 0; - if (buffer.len > 0) - { - smart_str_appendl(&unpacker->buffer, buffer.c, buffer.len); + if (buffer.len > 0) { + smart_string_appendl(&unpacker->buffer, buffer.c, buffer.len); } - smart_str_free(&buffer); - - if (unpacker->retval != NULL) - { - zval_ptr_dtor(&unpacker->retval); - unpacker->retval = NULL; - } + smart_string_free(&buffer); msgpack_unserialize_var_destroy(&unpacker->var_hash, unpacker->error); unpacker->error = 0; @@ -659,8 +490,7 @@ static ZEND_METHOD(msgpack_unpacker, reset) msgpack_unserialize_var_init(&unpacker->var_hash); - (&unpacker->mp)->user.var_hash = - (msgpack_unserialize_data_t *)&unpacker->var_hash; + (&unpacker->mp)->user.var_hash = &unpacker->var_hash; } void msgpack_init_class() @@ -672,15 +502,18 @@ void msgpack_init_class() INIT_CLASS_ENTRY(ce, "MessagePack", msgpack_base_methods); msgpack_ce = zend_register_internal_class(&ce TSRMLS_CC); msgpack_ce->create_object = php_msgpack_base_new; + memcpy(&msgpack_handlers, zend_get_std_object_handlers(),sizeof msgpack_handlers); + msgpack_handlers.offset = XtOffsetOf(php_msgpack_base_t, object); + msgpack_handlers.free_obj = php_msgpack_base_free; -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) - zend_declare_class_constant_long( - msgpack_ce, ZEND_STRS("OPT_PHPONLY") - 1, - MSGPACK_CLASS_OPT_PHPONLY TSRMLS_CC); -#endif + zend_declare_class_constant_long(msgpack_ce, ZEND_STRS("OPT_PHPONLY") - 1, MSGPACK_CLASS_OPT_PHPONLY TSRMLS_CC); /* unpacker */ INIT_CLASS_ENTRY(ce, "MessagePackUnpacker", msgpack_unpacker_methods); msgpack_unpacker_ce = zend_register_internal_class(&ce TSRMLS_CC); msgpack_unpacker_ce->create_object = php_msgpack_unpacker_new; + memcpy(&msgpack_unpacker_handlers, zend_get_std_object_handlers(),sizeof msgpack_unpacker_handlers); + msgpack_unpacker_handlers.offset = XtOffsetOf(php_msgpack_unpacker_t, object); + msgpack_handlers.free_obj = php_msgpack_base_free; + } diff --git a/msgpack_convert.c b/msgpack_convert.c index 4f426d3..ea6d86c 100644 --- a/msgpack_convert.c +++ b/msgpack_convert.c @@ -5,448 +5,328 @@ #include "msgpack_convert.h" #include "msgpack_errors.h" -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) -# define Z_REFCOUNT_P(pz) ((pz)->refcount) -# define Z_SET_ISREF_P(pz) (pz)->is_ref = 1 -# define Z_UNSET_ISREF_P(pz) (pz)->is_ref = 0 -#endif - -#define MSGPACK_CONVERT_COPY_ZVAL(_pz, _ppz) \ - ALLOC_INIT_ZVAL(_pz); \ - *(_pz) = **(_ppz); \ - if (PZVAL_IS_REF(*(_ppz))) { \ - if (Z_REFCOUNT_P(*(_ppz)) > 0) { \ - zval_copy_ctor(_pz); \ - } else { \ - FREE_ZVAL(*(_ppz)); \ - } \ - INIT_PZVAL(_pz); \ - Z_SET_ISREF_P(_pz); \ - } else { \ - zval_copy_ctor(_pz); \ - INIT_PZVAL(_pz); \ - } - -#define MSGPACK_CONVERT_UPDATE_PROPERTY(_ht, _key, _key_len, _val, _var) \ - if (zend_symtable_update( \ - _ht, _key, _key_len, &_val, sizeof(_val), NULL) == SUCCESS) { \ - zend_hash_add(_var, _key, _key_len, &_val, sizeof(_val), NULL); \ - return SUCCESS; \ - } - -static inline int msgpack_convert_long_to_properties( - HashTable *ht, HashTable **properties, HashPosition *prop_pos, +inline int msgpack_convert_long_to_properties( + HashTable *ht, zval *object, HashTable **properties, HashPosition *prop_pos, uint key_index, zval *val, HashTable *var) { - TSRMLS_FETCH(); - - if (*properties != NULL) - { - char *prop_key; - uint prop_key_len; + if (*properties != NULL) { + zval *data, tplval, *dataval, prop_key_zv; + zend_string *prop_key, *unmangled_prop_key; ulong prop_key_index; - zval **data = NULL; - zval *tplval = NULL; - zval **dataval = NULL; - - for (;; zend_hash_move_forward_ex(*properties, prop_pos)) - { - if (zend_hash_get_current_key_ex( - *properties, &prop_key, &prop_key_len, - &prop_key_index, 0, prop_pos) == HASH_KEY_IS_STRING) - { - if (var == NULL || - !zend_hash_exists(var, prop_key, prop_key_len)) - { - if (zend_hash_find( - ht, prop_key, prop_key_len, - (void **)&data) == SUCCESS) - { - switch (Z_TYPE_PP(data)) - { + const char *class_name, *prop_name; + size_t prop_len; + + for (;; zend_hash_move_forward_ex(*properties, prop_pos)) { + if (zend_hash_get_current_key_ex(*properties, &prop_key, &prop_key_index, prop_pos) == HASH_KEY_IS_STRING) { + zend_unmangle_property_name_ex(prop_key, &class_name, &prop_name, &prop_len); + ZVAL_NEW_STR(&prop_key_zv, prop_key); + unmangled_prop_key = zend_string_init(prop_name, prop_len, 0); + + if (var == NULL || !zend_hash_exists(var, unmangled_prop_key)) { + if ((data = zend_hash_find(ht, prop_key)) != NULL) { + switch (Z_TYPE_P(data)) { case IS_ARRAY: - { - HashTable *dataht; - dataht = HASH_OF(val); - if (zend_hash_index_find( - dataht, prop_key_index, - (void **)dataval) != SUCCESS) { - MSGPACK_WARNING( - "[msgpack] (%s) " - "can't get data value by index", - __FUNCTION__); + HashTable *dataht; + dataht = HASH_OF(val); + + if ((dataval = zend_hash_index_find(dataht, prop_key_index)) == NULL) { + MSGPACK_WARNING("[msgpack] (%s) " + "can't get data value by index", + __FUNCTION__); + zend_string_release(unmangled_prop_key); + return FAILURE; + } + + if (msgpack_convert_array(&tplval, data, &dataval) == SUCCESS) { + zend_hash_move_forward_ex(*properties, prop_pos); + + zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval); + zend_string_release(unmangled_prop_key); + return SUCCESS; + } + zend_string_release(unmangled_prop_key); return FAILURE; } - - ALLOC_INIT_ZVAL(tplval); - if (msgpack_convert_array( - tplval, *data, dataval) == SUCCESS) - { - zend_hash_move_forward_ex( - *properties, prop_pos); - - return zend_symtable_update( - ht, prop_key, prop_key_len, - &tplval, sizeof(tplval), NULL); - } - // TODO: de we need to call dtor? - return FAILURE; - break; - } case IS_OBJECT: - { - ALLOC_INIT_ZVAL(tplval); - if (msgpack_convert_object( - tplval, *data, &val) == SUCCESS) { - zend_hash_move_forward_ex( - *properties, prop_pos); - - return zend_symtable_update( - ht, prop_key, prop_key_len, - &tplval, sizeof(tplval), NULL); + if (msgpack_convert_object(&tplval, data, &val) == SUCCESS) { + zend_hash_move_forward_ex(*properties, prop_pos); + zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval); + zend_string_release(unmangled_prop_key); + return SUCCESS; + } + zend_string_release(unmangled_prop_key); + return FAILURE; } - // TODO: de we need to call dtor? - return FAILURE; - break; - } default: zend_hash_move_forward_ex(*properties, prop_pos); - return zend_symtable_update( - ht, prop_key, prop_key_len, - &val, sizeof(val), NULL); - break; + zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, val); + zend_string_release(unmangled_prop_key); + return SUCCESS; } } } - } - else - { + zend_string_release(unmangled_prop_key); + } else { break; } } - *properties = NULL; } - - return zend_hash_index_update(ht, key_index, &val, sizeof(val), NULL); + zval key_zv; + ZVAL_LONG(&key_zv, key_index); + zend_std_write_property(object, &key_zv, val, NULL); + return SUCCESS; } static inline int msgpack_convert_string_to_properties( zval *object, char *key, uint key_len, zval *val, HashTable *var) { - zval **data = NULL; - HashTable *ht; - zend_class_entry *ce; - char *prot_name, *priv_name; - int prop_name_len; - TSRMLS_FETCH(); - - ht = HASH_OF(object); - ce = zend_get_class_entry(object TSRMLS_CC); - - /* private */ - zend_mangle_property_name( - &priv_name, &prop_name_len, ce->name, ce->name_length, key, key_len - 1, 1); - if (zend_hash_find( - ht, priv_name, prop_name_len + 1, (void **)&data) == SUCCESS) - { - MSGPACK_CONVERT_UPDATE_PROPERTY(ht, priv_name, prop_name_len + 1, val, var); - } - - /* protected */ - zend_mangle_property_name( - &prot_name, &prop_name_len, "*", 1, key, key_len - 1, 1); - if (zend_hash_find( - ht, prot_name, prop_name_len + 1, (void **)&data) == SUCCESS) - { - MSGPACK_CONVERT_UPDATE_PROPERTY(ht, prot_name, prop_name_len + 1, val, var); + zend_class_entry *ce = Z_OBJCE_P(object); + HashTable *propers = Z_OBJPROP_P(object); + zend_string *prot_name, *priv_name, *pub_name; + zval pub_name_z; + int return_code; + + ZVAL_STRINGL(&pub_name_z, key, key_len); + priv_name = zend_mangle_property_name(ce->name->val, ce->name->len, key, key_len, 1); + prot_name = zend_mangle_property_name("*", 1, key, key_len, 1); + pub_name = zval_get_string(&pub_name_z); + + if (zend_hash_find(propers, priv_name) != NULL) { + zend_update_property(ce, object, key, key_len, val); + return_code = SUCCESS; + } else if (zend_hash_find(propers, prot_name) != NULL) { + zend_update_property(ce, object, key, key_len, val); + return_code = SUCCESS; + } else { + zend_std_write_property(object, &pub_name_z, val, NULL); + return_code = FAILURE; } + zend_hash_add(var, pub_name, val); - /* public */ - MSGPACK_CONVERT_UPDATE_PROPERTY(ht, key, key_len, val, var); + zend_string_release(priv_name); + zend_string_release(prot_name); + zend_string_release(pub_name); + zval_ptr_dtor(&pub_name_z); - return FAILURE; + return return_code; } int msgpack_convert_array(zval *return_value, zval *tpl, zval **value) { - TSRMLS_FETCH(); + if (Z_TYPE_P(tpl) != IS_ARRAY) { + MSGPACK_WARNING("[msgpack] (%s) template is not array", __FUNCTION__); + zval_ptr_dtor(*value); + return FAILURE; + } + if (Z_TYPE_P(*value) == IS_INDIRECT) { + *value = Z_INDIRECT_P(*value); + } - if (Z_TYPE_P(tpl) == IS_ARRAY) - { - char *key; - uint key_len; - int key_type; - ulong key_index; - zval **data, **arydata; - HashPosition pos, valpos; - HashTable *ht, *htval; - int num; - - ht = HASH_OF(tpl); - // TODO: maybe need to release memory? - array_init(return_value); - - num = zend_hash_num_elements(ht); - if (num <= 0) - { - MSGPACK_WARNING( - "[msgpack] (%s) template array length is 0", + zend_string *key; + int key_type; + ulong key_index; + zval *data, *arydata, nv, *nv_p; + HashPosition pos, valpos; + HashTable *ht, *htval; + + ht = HASH_OF(tpl); + array_init(return_value); + + if (zend_hash_num_elements(ht) <= 0) { + MSGPACK_WARNING("[msgpack] (%s) template array length is 0", __FUNCTION__); - zval_ptr_dtor(value); + zval_ptr_dtor(*value); + return FAILURE; + } + + /* string */ + if (ht->nNumOfElements != ht->nNextFreeElement) { + htval = HASH_OF(*value); + if (!htval) { + MSGPACK_WARNING( + "[msgpack] (%s) input data is not array", + __FUNCTION__); + zval_ptr_dtor(*value); return FAILURE; } - /* string */ - if (ht->nNumOfElements != ht->nNextFreeElement) + zend_hash_internal_pointer_reset_ex(ht, &pos); + zend_hash_internal_pointer_reset_ex(htval, &valpos); + for (;; zend_hash_move_forward_ex(ht, &pos), zend_hash_move_forward_ex(htval, &valpos)) { - htval = HASH_OF(*value); - if (!htval) - { - MSGPACK_WARNING( - "[msgpack] (%s) input data is not array", - __FUNCTION__); - zval_ptr_dtor(value); - return FAILURE; - } + key_type = zend_hash_get_current_key_ex(ht, &key, &key_index, &pos); - zend_hash_internal_pointer_reset_ex(ht, &pos); - zend_hash_internal_pointer_reset_ex(htval, &valpos); - for (;; zend_hash_move_forward_ex(ht, &pos), - zend_hash_move_forward_ex(htval, &valpos)) - { - key_type = zend_hash_get_current_key_ex( - ht, &key, &key_len, &key_index, 0, &pos); - - if (key_type == HASH_KEY_NON_EXISTANT) - { - break; - } + if (key_type == HASH_KEY_NON_EXISTENT) { + break; + } - if (zend_hash_get_current_data_ex( - ht, (void *)&data, &pos) != SUCCESS) - { - continue; - } + if ((data = zend_hash_get_current_data_ex(ht, &pos)) == NULL) { + continue; + } - if (key_type == HASH_KEY_IS_STRING) - { - int (*convert_function)(zval *, zval *, zval **) = NULL; - zval **dataval, *val; + if (key_type == HASH_KEY_IS_STRING) { + int (*convert_function)(zval *, zval *, zval **) = NULL; + zval *dataval; - switch (Z_TYPE_PP(data)) - { - case IS_ARRAY: - convert_function = msgpack_convert_array; - break; - case IS_OBJECT: + switch (Z_TYPE_P(data)) { + case IS_ARRAY: + convert_function = msgpack_convert_array; + break; + case IS_OBJECT: // case IS_STRING: - convert_function = msgpack_convert_object; - break; - default: - break; - } + convert_function = msgpack_convert_object; + break; + default: + break; + } - if (zend_hash_get_current_data_ex( - htval, (void *)&dataval, &valpos) != SUCCESS) - { - MSGPACK_WARNING( - "[msgpack] (%s) can't get data", - __FUNCTION__); - zval_ptr_dtor(value); + if ((dataval = zend_hash_get_current_data_ex(htval, &valpos)) == NULL) { + MSGPACK_WARNING("[msgpack] (%s) can't get data", __FUNCTION__); + zval_ptr_dtor(*value); + return FAILURE; + } + nv = *dataval; + nv_p = &nv; + zval_copy_ctor(&nv); + + if (convert_function) { + zval rv; + if (convert_function(&rv, data, &nv_p) != SUCCESS) { + zval_ptr_dtor(*value); return FAILURE; } - - MSGPACK_CONVERT_COPY_ZVAL(val, dataval); - - if (convert_function) - { - zval *rv; - ALLOC_INIT_ZVAL(rv); - if (convert_function(rv, *data, &val) != SUCCESS) - { - zval_ptr_dtor(&val); - return FAILURE; - } - add_assoc_zval_ex(return_value, key, key_len, rv); - } - else - { - add_assoc_zval_ex(return_value, key, key_len, val); - } + add_assoc_zval_ex(return_value, key->val, key->len, &rv); + } else { + add_assoc_zval_ex(return_value, key->val, key->len, &nv); } } - - zval_ptr_dtor(value); - - return SUCCESS; } - else - { - /* index */ - int (*convert_function)(zval *, zval *, zval **) = NULL; - if (Z_TYPE_PP(value) != IS_ARRAY) - { - MSGPACK_WARNING( - "[msgpack] (%s) unserialized data must be array.", - __FUNCTION__); - zval_ptr_dtor(value); - return FAILURE; - } + zval_ptr_dtor(*value); + return SUCCESS; + } else { + /* index */ + int (*convert_function)(zval *, zval *, zval **) = NULL; - zend_hash_internal_pointer_reset_ex(ht, &pos); + if (Z_TYPE_P(*value) != IS_ARRAY) { + MSGPACK_WARNING("[msgpack] (%s) unserialized data must be array.", __FUNCTION__); + zval_ptr_dtor(*value); + return FAILURE; + } - key_type = zend_hash_get_current_key_ex( - ht, &key, &key_len, &key_index, 0, &pos); + zend_hash_internal_pointer_reset_ex(ht, &pos); + key_type = zend_hash_get_current_key_ex(ht, &key, &key_index, &pos); - if (key_type == HASH_KEY_NON_EXISTANT) - { - MSGPACK_WARNING( + if (key_type == HASH_KEY_NON_EXISTENT) { + MSGPACK_WARNING( "[msgpack] (%s) first element in template array is empty", __FUNCTION__); - zval_ptr_dtor(value); - return FAILURE; - } - - if (zend_hash_get_current_data_ex( - ht, (void *)&data, &pos) != SUCCESS) - { - MSGPACK_WARNING( - "[msgpack] (%s) invalid template: empty array?", - __FUNCTION__); - zval_ptr_dtor(value); - return FAILURE; - } + zval_ptr_dtor(*value); + return FAILURE; + } - switch (Z_TYPE_PP(data)) - { - case IS_ARRAY: - convert_function = msgpack_convert_array; - break; - case IS_OBJECT: - case IS_STRING: - convert_function = msgpack_convert_object; - break; - default: - break; - } + if ((data = zend_hash_get_current_data_ex(ht, &pos)) == NULL) { + MSGPACK_WARNING("[msgpack] (%s) invalid template: empty array?", __FUNCTION__); + zval_ptr_dtor(*value); + return FAILURE; + } - htval = HASH_OF(*value); - num = zend_hash_num_elements(htval); - if (num <= 0) - { - MSGPACK_WARNING( - "[msgpack] (%s) array length is 0 in unserialized data", - __FUNCTION__); - zval_ptr_dtor(value); - return FAILURE; - } + switch (Z_TYPE_P(data)) + { + case IS_ARRAY: + convert_function = msgpack_convert_array; + break; + case IS_OBJECT: + case IS_STRING: + convert_function = msgpack_convert_object; + break; + default: + break; + } - zend_hash_internal_pointer_reset_ex(htval, &valpos); - for (;; zend_hash_move_forward_ex(htval, &valpos)) - { - key_type = zend_hash_get_current_key_ex( - htval, &key, &key_len, &key_index, 0, &valpos); + htval = HASH_OF(*value); + if (zend_hash_num_elements(htval) <= 0) { + MSGPACK_WARNING("[msgpack] (%s) array length is 0 in unserialized data", __FUNCTION__); + zval_ptr_dtor(*value); + return FAILURE; + } - if (key_type == HASH_KEY_NON_EXISTANT) - { - break; - } + zend_hash_internal_pointer_reset_ex(htval, &valpos); + for (;; zend_hash_move_forward_ex(htval, &valpos)) { + key_type = zend_hash_get_current_key_ex(htval, &key, &key_index, &valpos); - if (zend_hash_get_current_data_ex( - htval, (void *)&arydata, &valpos) != SUCCESS) - { - MSGPACK_WARNING( - "[msgpack] (%s) can't get next data in indexed array", - __FUNCTION__); - continue; - } + if (key_type == HASH_KEY_NON_EXISTENT) { + break; + } - switch (key_type) - { - case HASH_KEY_IS_LONG: - { - zval *aryval, *rv; - ALLOC_INIT_ZVAL(rv); - MSGPACK_CONVERT_COPY_ZVAL(aryval, arydata); - if (convert_function) - { - if (convert_function(rv, *data, &aryval) != SUCCESS) - { - zval_ptr_dtor(&aryval); + if ((arydata = zend_hash_get_current_data_ex(htval, &valpos)) == NULL) { + MSGPACK_WARNING( "[msgpack] (%s) can't get next data in indexed array", __FUNCTION__); + continue; + } + nv = *arydata; + nv_p = &nv; + zval_copy_ctor(&nv); + + switch (key_type) { + case HASH_KEY_IS_LONG: { + zval rv; + if (convert_function) { + if (convert_function(&rv, data, &nv_p) != SUCCESS) { MSGPACK_WARNING( - "[msgpack] (%s) " - "convert failure in HASH_KEY_IS_LONG " - "in indexed array", - __FUNCTION__); - zval_ptr_dtor(value); + "[msgpack] (%s) " + "convert failure in HASH_KEY_IS_LONG " + "in indexed array", + __FUNCTION__); + zval_ptr_dtor(*value); return FAILURE; } - add_next_index_zval(return_value, rv); - } - else - { - add_next_index_zval(return_value, aryval); + add_next_index_zval(return_value, &rv); + } else { + add_next_index_zval(return_value, &nv); } break; } - case HASH_KEY_IS_STRING: - MSGPACK_WARNING( - "[msgpack] (%s) key is string", - __FUNCTION__); - zval_ptr_dtor(value); - return FAILURE; - default: - MSGPACK_WARNING( - "[msgpack] (%s) key is not string nor array", - __FUNCTION__); - zval_ptr_dtor(value); - return FAILURE; - } + case HASH_KEY_IS_STRING: + MSGPACK_WARNING("[msgpack] (%s) key is string", __FUNCTION__); + zval_ptr_dtor(*value); + return FAILURE; + default: + MSGPACK_WARNING("[msgpack] (%s) key is not string nor array", __FUNCTION__); + zval_ptr_dtor(*value); + return FAILURE; } - - zval_ptr_dtor(value); - return SUCCESS; } - } - else - { - // shouldn't reach - MSGPACK_WARNING( - "[msgpack] (%s) template is not array", - __FUNCTION__); - zval_ptr_dtor(value); - return FAILURE; + + zval_ptr_dtor(*value); + return SUCCESS; } // shouldn't reach - zval_ptr_dtor(value); + zval_ptr_dtor(*value); return FAILURE; + } -int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) -{ - zend_class_entry *ce, **pce; - TSRMLS_FETCH(); +int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) { + zend_class_entry *ce; + zend_string *tpl_zstring; - switch (Z_TYPE_P(tpl)) - { + switch (Z_TYPE_P(tpl)) { case IS_STRING: - if (zend_lookup_class( - Z_STRVAL_P(tpl), Z_STRLEN_P(tpl), - &pce TSRMLS_CC) != SUCCESS) - { + tpl_zstring = zval_get_string(tpl); + ce = zend_lookup_class(tpl_zstring); + zend_string_release(tpl_zstring); + if (ce == NULL) { MSGPACK_ERROR("[msgpack] (%s) Class '%s' not found", __FUNCTION__, Z_STRVAL_P(tpl)); return FAILURE; } - ce = *pce; break; case IS_OBJECT: - ce = zend_get_class_entry(tpl TSRMLS_CC); + ce = Z_OBJCE_P(tpl); break; default: MSGPACK_ERROR("[msgpack] (%s) object type is unsupported", @@ -454,16 +334,14 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) return FAILURE; } - if (Z_TYPE_PP(value) == IS_OBJECT) - { + if (Z_TYPE_P(*value) == IS_OBJECT) { zend_class_entry *vce; - vce = zend_get_class_entry(*value TSRMLS_CC); - if (strcmp(ce->name, vce->name) == 0) - { + vce = Z_OBJCE_P(*value); + if (zend_string_equals(ce->name, vce->name)) { *return_value = **value; zval_copy_ctor(return_value); - zval_ptr_dtor(value); + zval_ptr_dtor(*value); return SUCCESS; } } @@ -471,228 +349,112 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) object_init_ex(return_value, ce); /* Run the constructor if there is one */ - if (ce->constructor - && (ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) - { - zval *retval_ptr = NULL; - zval ***params = NULL; - int num_args = 0; + if (ce->constructor && (ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { + zval retval, params, function_name; zend_fcall_info fci; zend_fcall_info_cache fcc; -#if ZEND_MODULE_API_NO >= 20090626 fci.size = sizeof(fci); fci.function_table = EG(function_table); - fci.function_name = NULL; + fci.function_name = function_name; fci.symbol_table = NULL; - fci.object_ptr = return_value; - fci.retval_ptr_ptr = &retval_ptr; - fci.param_count = num_args; - fci.params = params; + fci.object = Z_OBJ_P(return_value); + fci.retval = &retval; + fci.param_count = 0; + fci.params = ¶ms; fci.no_separation = 1; fcc.initialized = 1; fcc.function_handler = ce->constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); - fcc.object_ptr = return_value; -#else - fci.size = sizeof(fci); - fci.function_table = EG(function_table); - fci.function_name = NULL; - fci.symbol_table = NULL; - fci.object_pp = &return_value; - fci.retval_ptr_ptr = &retval_ptr; - fci.param_count = num_args; - fci.params = params; - fci.no_separation = 1; - - fcc.initialized = 1; - fcc.function_handler = ce->constructor; - fcc.calling_scope = EG(scope); - fcc.object_pp = &return_value; -#endif - - if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) - { - if (params) - { - efree(params); - } - if (retval_ptr) - { - zval_ptr_dtor(&retval_ptr); - } + fcc.object = Z_OBJ_P(return_value); + if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { MSGPACK_WARNING( "[msgpack] (%s) Invocation of %s's constructor failed", __FUNCTION__, ce->name); return FAILURE; } - if (retval_ptr) - { - zval_ptr_dtor(&retval_ptr); - } - if (params) - { - efree(params); - } } - switch (Z_TYPE_PP(value)) - { + switch (Z_TYPE_P(*value)) { case IS_ARRAY: { - char *key; - uint key_len; - int key_type; - ulong key_index; - zval **data; - HashPosition pos; - HashTable *ht, *ret; - HashTable *var = NULL; + HashTable *ht, *ret, *var = NULL; int num; + zend_string *str_key; + zval *data; + ulong num_key; ht = HASH_OF(*value); ret = HASH_OF(return_value); num = zend_hash_num_elements(ht); - if (num <= 0) - { - zval_ptr_dtor(value); + if (num <= 0) { + zval_ptr_dtor(*value); break; } /* string - php_only mode? */ - if (ht->nNumOfElements != ht->nNextFreeElement - || ht->nNumOfElements != ret->nNumOfElements) - { + if (ht->nNumOfElements != ht->nNextFreeElement || ht->nNumOfElements != ret->nNumOfElements) { HashTable *properties = NULL; HashPosition prop_pos; ALLOC_HASHTABLE(var); zend_hash_init(var, num, NULL, NULL, 0); - zend_hash_internal_pointer_reset_ex(ht, &pos); - for (;; zend_hash_move_forward_ex(ht, &pos)) - { - key_type = zend_hash_get_current_key_ex( - ht, &key, &key_len, &key_index, 0, &pos); - - if (key_type == HASH_KEY_NON_EXISTANT) - { - break; - } - - if (zend_hash_get_current_data_ex( - ht, (void *)&data, &pos) != SUCCESS) - { - continue; - } - - if (key_type == HASH_KEY_IS_STRING) - { - zval *val; - MSGPACK_CONVERT_COPY_ZVAL(val, data); - if (msgpack_convert_string_to_properties( - return_value, key, key_len, val, var) != SUCCESS) - { - zval_ptr_dtor(&val); - MSGPACK_WARNING( - "[msgpack] (%s) " - "illegal offset type, skip this decoding", - __FUNCTION__); + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str_key, data) { + if (str_key) { + if (msgpack_convert_string_to_properties(return_value, str_key->val, str_key->len, data, var) != SUCCESS) { + MSGPACK_WARNING("[msgpack] (%s) " + "illegal offset type, skip this decoding", + __FUNCTION__); } } - } + } ZEND_HASH_FOREACH_END(); /* index */ - properties = Z_OBJ_HT_P(return_value)->get_properties( - return_value TSRMLS_CC); - - if (HASH_OF(tpl)) - { + properties = Z_OBJ_HT_P(return_value)->get_properties(return_value TSRMLS_CC); + if (HASH_OF(tpl)) { properties = HASH_OF(tpl); } zend_hash_internal_pointer_reset_ex(properties, &prop_pos); - zend_hash_internal_pointer_reset_ex(ht, &pos); - for (;; zend_hash_move_forward_ex(ht, &pos)) - { - key_type = zend_hash_get_current_key_ex( - ht, &key, &key_len, &key_index, 0, &pos); - if (key_type == HASH_KEY_NON_EXISTANT) - { - break; - } - - if (zend_hash_get_current_data_ex( - ht, (void *)&data, &pos) != SUCCESS) - { - continue; - } - - switch (key_type) - { - case HASH_KEY_IS_LONG: - { - zval *val; - MSGPACK_CONVERT_COPY_ZVAL(val, data); - if (msgpack_convert_long_to_properties( - ret, &properties, &prop_pos, - key_index, val, var) != SUCCESS) - { - zval_ptr_dtor(&val); - MSGPACK_WARNING( - "[msgpack] (%s) " + ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, data) { + if (str_key == NULL) { + if (msgpack_convert_long_to_properties(ret, return_value, &properties, &prop_pos, num_key, data, var) != SUCCESS) { + MSGPACK_WARNING("[msgpack] (%s) " "illegal offset type, skip this decoding", __FUNCTION__); - } - break; } - case HASH_KEY_IS_STRING: - break; - default: - MSGPACK_WARNING( - "[msgpack] (%s) key is not string nor array", - __FUNCTION__); - break; } - } + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(var); FREE_HASHTABLE(var); - } - else - { - HashPosition valpos; + } else { int (*convert_function)(zval *, zval *, zval **) = NULL; - zval **arydata, *aryval; + const char *class_name, *prop_name; + size_t prop_len; + zval *aryval; - /* index */ - zend_hash_internal_pointer_reset_ex(ret, &pos); - zend_hash_internal_pointer_reset_ex(ht, &valpos); - for (;; zend_hash_move_forward_ex(ret, &pos), - zend_hash_move_forward_ex(ht, &valpos)) - { - key_type = zend_hash_get_current_key_ex( - ret, &key, &key_len, &key_index, 0, &pos); - - if (key_type == HASH_KEY_NON_EXISTANT) - { - break; - } + num_key = 0; + ZEND_HASH_FOREACH_STR_KEY_VAL(ret, str_key, data) { + aryval = zend_hash_index_find(ht, num_key); - if (zend_hash_get_current_data_ex( - ret, (void *)&data, &pos) != SUCCESS) - { - continue; + if (data == NULL) { + MSGPACK_WARNING("[msgpack] (%s) can't get data value by index", __FUNCTION__); + return FAILURE; + } + if (Z_TYPE_P(data) == IS_INDIRECT) { + data = Z_INDIRECT_P(data); } - switch (Z_TYPE_PP(data)) - { + + switch (Z_TYPE_P(data)) { case IS_ARRAY: convert_function = msgpack_convert_array; break; @@ -701,48 +463,28 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) // class members, so it's not wise to allow convert_function = msgpack_convert_object; break; - default: - break; - } - - if (zend_hash_get_current_data_ex( - ht, (void *)&arydata, &valpos) != SUCCESS) - { - MSGPACK_WARNING( - "[msgpack] (%s) can't get data value by index", - __FUNCTION__); - return FAILURE; } - MSGPACK_CONVERT_COPY_ZVAL(aryval, arydata); - - if (convert_function) - { - zval *rv; - ALLOC_INIT_ZVAL(rv); + zend_unmangle_property_name_ex(str_key, &class_name, &prop_name, &prop_len); - if (convert_function(rv, *data, &aryval) != SUCCESS) - { - zval_ptr_dtor(&aryval); - MSGPACK_WARNING( - "[msgpack] (%s) " + if (convert_function) { + zval nv; + if (convert_function(&nv, data, &aryval) != SUCCESS) { + //zval_ptr_dtor(aryval); + MSGPACK_WARNING("[msgpack] (%s) " "convert failure in convert_object", __FUNCTION__); return FAILURE; } - zend_symtable_update( - ret, key, key_len, &rv, sizeof(rv), NULL); + zend_update_property(ce, return_value, str_key->val, str_key->len, &nv); + } else { + zend_update_property(ce, return_value, prop_name, prop_len, aryval); } - else - { - zend_symtable_update( - ret, key, key_len, &aryval, sizeof(aryval), NULL); - } - } - } - - zval_ptr_dtor(value); + num_key++; + } ZEND_HASH_FOREACH_END(); + } + zval_ptr_dtor(*value); break; } default: @@ -750,19 +492,14 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) HashTable *properties = NULL; HashPosition prop_pos; - properties = Z_OBJ_HT_P(return_value)->get_properties( - return_value TSRMLS_CC); + properties = Z_OBJ_HT_P(return_value)->get_properties(return_value TSRMLS_CC); zend_hash_internal_pointer_reset_ex(properties, &prop_pos); - if (msgpack_convert_long_to_properties( - HASH_OF(return_value), &properties, &prop_pos, - 0, *value, NULL) != SUCCESS) - { - MSGPACK_WARNING( - "[msgpack] (%s) illegal offset type, skip this decoding", + if (msgpack_convert_long_to_properties(HASH_OF(return_value), return_value, &properties, &prop_pos, 0, *value, NULL) != SUCCESS) { + MSGPACK_WARNING("[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } - break; + zval_ptr_dtor(*value); } } @@ -771,8 +508,6 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) int msgpack_convert_template(zval *return_value, zval *tpl, zval **value) { - TSRMLS_FETCH(); - switch (Z_TYPE_P(tpl)) { case IS_ARRAY: diff --git a/msgpack_pack.c b/msgpack_pack.c index 0e11f4c..21db49e 100644 --- a/msgpack_pack.c +++ b/msgpack_pack.c @@ -1,7 +1,7 @@ #include "php.h" #include "php_ini.h" -#include "ext/standard/php_smart_str.h" +#include "ext/standard/php_smart_string.h" #include "ext/standard/php_incomplete_class.h" #include "ext/standard/php_var.h" @@ -10,242 +10,172 @@ #include "msgpack_errors.h" #include "msgpack/pack_define.h" -#define msgpack_pack_user smart_str* +#define msgpack_pack_user smart_string* #define msgpack_pack_inline_func(name) \ static inline void msgpack_pack ## name #define msgpack_pack_inline_func_cint(name) \ static inline void msgpack_pack ## name #define msgpack_pack_append_buffer(user, buf, len) \ - smart_str_appendl(user, (const void*)buf, len) + smart_string_appendl(user, (const void*)buf, len) #include "msgpack/pack_template.h" +#define Z_REF_AWARE_P(_obj) \ + (Z_ISREF_P(_obj)?Z_REFVAL_P(_obj):_obj) -#if ZEND_MODULE_API_NO < 20090626 -# define Z_ISREF_P(pz) PZVAL_IS_REF(pz) -#endif - -inline static int msgpack_check_ht_is_map(zval *array) +inline static int msgpack_check_ht_is_map(zval *array) { - int count = zend_hash_num_elements(Z_ARRVAL_P(array)); + int count = zend_hash_num_elements(Z_ARRVAL_P(Z_REF_AWARE_P(array))); - if (count != (Z_ARRVAL_P(array))->nNextFreeElement) { + if (count != (Z_ARRVAL_P(Z_REF_AWARE_P(array)))->nNextFreeElement) { return 1; } else { int i; HashPosition pos = {0}; - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(Z_REF_AWARE_P(array)), &pos); for (i = 0; i < count; i++) { - if (zend_hash_get_current_key_type_ex(Z_ARRVAL_P(array), &pos) != HASH_KEY_IS_LONG) { + if (zend_hash_get_current_key_type_ex(Z_ARRVAL_P(Z_REF_AWARE_P(array)), &pos) != HASH_KEY_IS_LONG) { return 1; } - zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos); + zend_hash_move_forward_ex(Z_ARRVAL_P(Z_REF_AWARE_P(array)), &pos); } } return 0; } inline static int msgpack_var_add( - HashTable *var_hash, zval *var, void *var_old TSRMLS_DC) + HashTable *var_hash, zval *var, zval **var_old) { - ulong var_no; char id[32], *p; int len; + zend_string *zstring; + zval zv; - if ((Z_TYPE_P(var) == IS_OBJECT) && Z_OBJ_HT_P(var)->get_class_entry) - { - p = smart_str_print_long( + if ((Z_TYPE_P(Z_REF_AWARE_P(var)) == IS_OBJECT) && Z_OBJCE_P(var)) { + p = zend_print_long_to_buf( id + sizeof(id) - 1, - (((size_t)Z_OBJCE_P(var) << 5) - | ((size_t)Z_OBJCE_P(var) >> (sizeof(long) * 8 - 5))) - + (long)Z_OBJ_HANDLE_P(var)); + (((size_t)Z_OBJCE_P(Z_REF_AWARE_P(var)) << 5) + | ((size_t)Z_OBJCE_P(Z_REF_AWARE_P(var)) >> (sizeof(long) * 8 - 5))) + + (long)Z_OBJ_HANDLE_P(Z_REF_AWARE_P(var))); len = id + sizeof(id) - 1 - p; - } - else if (Z_TYPE_P(var) == IS_ARRAY) - { - p = smart_str_print_long(id + sizeof(id) - 1, (long)var); + } else if (Z_TYPE_P(Z_REF_AWARE_P(var)) == IS_ARRAY) { + p = zend_print_long_to_buf(id + sizeof(id) - 1, (long)Z_REF_AWARE_P(var)); len = id + sizeof(id) - 1 - p; - } - else - { + } else { return FAILURE; } - if (var_old && zend_hash_find(var_hash, p, len, var_old) == SUCCESS) - { - if (!Z_ISREF_P(var)) - { - var_no = -1; - zend_hash_next_index_insert( - var_hash, &var_no, sizeof(var_no), NULL); + zstring = zend_string_init(p, len, 0); + if (var_old && (*var_old = zend_hash_find(var_hash, zstring)) != NULL) { + if (!Z_ISREF_P(var)) { + ZVAL_LONG(&zv, -1); + zend_hash_next_index_insert(var_hash, &zv); } + zend_string_release(zstring); return FAILURE; } - var_no = zend_hash_num_elements(var_hash) + 1; - - zend_hash_add(var_hash, p, len, &var_no, sizeof(var_no), NULL); + ZVAL_LONG(&zv, zend_hash_num_elements(var_hash) + 1); + zend_hash_add(var_hash, zstring, &zv); + zend_string_release(zstring); return SUCCESS; } inline static void msgpack_serialize_string( - smart_str *buf, char *str, size_t len) + smart_string *buf, char *str, size_t len) { msgpack_pack_raw(buf, len); msgpack_pack_raw_body(buf, str, len); } inline static void msgpack_serialize_class( - smart_str *buf, zval *val, zval *retval_ptr, HashTable *var_hash, - char *class_name, zend_uint name_len, zend_bool incomplete_class TSRMLS_DC) + smart_string *buf, zval *val, zval *retval_ptr, HashTable *var_hash, + char *class_name, uint32_t name_len, zend_bool incomplete_class TSRMLS_DC) { int count; HashTable *ht = HASH_OF(retval_ptr); count = zend_hash_num_elements(ht); - if (incomplete_class) - { + if (incomplete_class) { --count; } - if (count > 0) - { - char *key; - zval **data, **name; - ulong key_index; - HashPosition pos; - int n; - zval nval, *nvalp; - + if (count > 0) { msgpack_pack_map(buf, count + 1); - msgpack_pack_nil(buf); msgpack_serialize_string(buf, class_name, name_len); - INIT_ZVAL(nval); + zend_string *key_str; + ulong key_long; + zval *value, *data, nval, *nvalp; ZVAL_NULL(&nval); nvalp = &nval; - zend_hash_internal_pointer_reset_ex(ht, &pos); - - for (;; zend_hash_move_forward_ex(ht, &pos)) - { - n = zend_hash_get_current_key_ex( - ht, &key, NULL, &key_index, 0, &pos); - - if (n == HASH_KEY_NON_EXISTANT) - { - break; - } - if (incomplete_class && strcmp(key, MAGIC_MEMBER) == 0) - { + ZEND_HASH_FOREACH_KEY_VAL(ht, key_long, key_str, value) { + if (incomplete_class && strcmp(key_str->val, MAGIC_MEMBER) == 0) { continue; } - zend_hash_get_current_data_ex(ht, (void **)&name, &pos); - - if (Z_TYPE_PP(name) != IS_STRING) - { + if (Z_TYPE_P(Z_REF_AWARE_P(value)) != IS_STRING) { MSGPACK_NOTICE( - "[msgpack] (%s) __sleep should return an array only " - "containing the names of instance-variables to serialize", - __FUNCTION__); + "[msgpack] (%s) __sleep should return an array only " + "containing the names of instance-variables to serialize", + __FUNCTION__); continue; } - - if (zend_hash_find( - Z_OBJPROP_P(val), Z_STRVAL_PP(name), - Z_STRLEN_PP(name) + 1, (void *)&data) == SUCCESS) - { - msgpack_serialize_string( - buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name)); - msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC); - } - else - { - zend_class_entry *ce; - ce = zend_get_class_entry(val TSRMLS_CC); - if (ce) - { - char *prot_name, *priv_name; - int prop_name_length; - + zend_string *val_zstring = zval_get_string(value); + if ((data = zend_hash_find(Z_OBJPROP_P(val), val_zstring)) != NULL) { + msgpack_serialize_string(buf, Z_STRVAL_P(value), Z_STRLEN_P(value)); + msgpack_serialize_zval(buf, data, var_hash TSRMLS_CC); + } else { + zend_class_entry *ce = Z_OBJCE_P(val); + if (ce) { + zend_string *priv_name, *prot_name; do { - zend_mangle_property_name( - &priv_name, &prop_name_length, ce->name, - ce->name_length, Z_STRVAL_PP(name), - Z_STRLEN_PP(name), - ce->type & ZEND_INTERNAL_CLASS); - if (zend_hash_find( - Z_OBJPROP_P(val), priv_name, - prop_name_length + 1, - (void *)&data) == SUCCESS) - { - msgpack_serialize_string( - buf, priv_name, prop_name_length); - - pefree(priv_name, - ce->type & ZEND_INTERNAL_CLASS); - - msgpack_serialize_zval( - buf, *data, var_hash TSRMLS_CC); + priv_name = zend_mangle_property_name(ce->name->val, ce->name->len, + Z_STRVAL_P(value), Z_STRLEN_P(value), + ce->type & ZEND_INTERNAL_CLASS); + if ((data = zend_hash_find(Z_OBJPROP_P(val), priv_name)) != NULL) { + msgpack_serialize_string(buf, priv_name->val, priv_name->len); + pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS); + msgpack_serialize_zval(buf, data, var_hash TSRMLS_CC); break; } - pefree(priv_name, - ce->type & ZEND_INTERNAL_CLASS); + pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS); - zend_mangle_property_name( - &prot_name, &prop_name_length, "*", 1, - Z_STRVAL_PP(name), Z_STRLEN_PP(name), - ce->type & ZEND_INTERNAL_CLASS); + prot_name = zend_mangle_property_name("*", 1, + Z_STRVAL_P(value), Z_STRLEN_P(value), + ce->type & ZEND_INTERNAL_CLASS); - if (zend_hash_find( - Z_OBJPROP_P(val), prot_name, - prop_name_length + 1, - (void *)&data) == SUCCESS) - { - msgpack_serialize_string( - buf, prot_name, prop_name_length); - - pefree(prot_name, - ce->type & ZEND_INTERNAL_CLASS); - - msgpack_serialize_zval( - buf, *data, var_hash TSRMLS_CC); + if ((data = zend_hash_find(Z_OBJPROP_P(val), prot_name)) != NULL) { + msgpack_serialize_string(buf, prot_name->val, prot_name->len); + pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS); + msgpack_serialize_zval(buf, data, var_hash TSRMLS_CC); break; } - pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS); MSGPACK_NOTICE( "[msgpack] (%s) \"%s\" returned as member " "variable from __sleep() but does not exist", - __FUNCTION__, Z_STRVAL_PP(name)); - - msgpack_serialize_string( - buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name)); - - msgpack_serialize_zval( - buf, nvalp, var_hash TSRMLS_CC); - } - while (0); - } - else - { - msgpack_serialize_string( - buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name)); - + __FUNCTION__, Z_STRVAL_P(value)); + msgpack_serialize_string(buf, Z_STRVAL_P(value), Z_STRLEN_P(value)); + msgpack_serialize_zval(buf, nvalp, var_hash TSRMLS_CC); + } while (0); + } else { + msgpack_serialize_string(buf, Z_STRVAL_P(value), Z_STRLEN_P(value)); msgpack_serialize_zval(buf, nvalp, var_hash TSRMLS_CC); - } + } } - } + zend_string_release(val_zstring); + } ZEND_HASH_FOREACH_END(); } } inline static void msgpack_serialize_array( - smart_str *buf, zval *val, HashTable *var_hash, zend_bool object, - char* class_name, zend_uint name_len, zend_bool incomplete_class TSRMLS_DC) + smart_string *buf, zval *val, HashTable *var_hash, zend_bool object, + char* class_name, uint32_t name_len, zend_bool incomplete_class TSRMLS_DC) { HashTable *ht; size_t n; @@ -253,11 +183,11 @@ inline static void msgpack_serialize_array( if (object) { - ht = Z_OBJPROP_P(val); + ht = Z_OBJPROP_P(Z_REF_AWARE_P(val)); } else { - ht = HASH_OF(val); + ht = HASH_OF(Z_REF_AWARE_P(val)); } if (ht) @@ -324,97 +254,63 @@ inline static void msgpack_serialize_array( { if (object || hash) { - char *key; - uint key_len; - int key_type; - ulong key_index; - zval **data; - HashPosition pos; - - zend_hash_internal_pointer_reset_ex(ht, &pos); - for (;; zend_hash_move_forward_ex(ht, &pos)) - { - key_type = zend_hash_get_current_key_ex( - ht, &key, &key_len, &key_index, 0, &pos); - if (key_type == HASH_KEY_NON_EXISTANT) - { - break; - } - if (incomplete_class && strcmp(key, MAGIC_MEMBER) == 0) - { + zend_string *key_str; + ulong key_long; + zval *value; + + + ZEND_HASH_FOREACH_KEY_VAL(ht, key_long, key_str, value) { + if (key_str && incomplete_class && strcmp(key_str->val, MAGIC_MEMBER) == 0) { continue; } - - if (hash) - { - switch (key_type) - { - case HASH_KEY_IS_LONG: - msgpack_pack_long(buf, key_index); - break; - case HASH_KEY_IS_STRING: - msgpack_serialize_string(buf, key, key_len - 1); - break; - default: - msgpack_serialize_string(buf, "", sizeof("")); - MSGPACK_WARNING( - "[msgpack] (%s) key is not string nor array", - __FUNCTION__); - break; - } + if (key_str && hash) { + msgpack_serialize_string(buf, key_str->val, key_str->len); + } else if (hash) { + msgpack_pack_long(buf, key_long); } - if (zend_hash_get_current_data_ex( - ht, (void *)&data, &pos) != SUCCESS || - !data || data == &val || - (Z_TYPE_PP(data) == IS_ARRAY && - Z_ARRVAL_PP(data)->nApplyCount > 1)) - { + if ((Z_TYPE_P(Z_REF_AWARE_P(value)) == IS_ARRAY && Z_ARRVAL_P(Z_REF_AWARE_P(value))->u.v.nApplyCount > 1)) { msgpack_pack_nil(buf); - } - else - { - if (Z_TYPE_PP(data) == IS_ARRAY) - { - Z_ARRVAL_PP(data)->nApplyCount++; + } else { + if (Z_TYPE_P(Z_REF_AWARE_P(value)) == IS_ARRAY) { + Z_ARRVAL_P(Z_REF_AWARE_P(value))->u.v.nApplyCount++; } - msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC); + msgpack_serialize_zval(buf, value, var_hash TSRMLS_CC); - if (Z_TYPE_PP(data) == IS_ARRAY) - { - Z_ARRVAL_PP(data)->nApplyCount--; + if (Z_TYPE_P(Z_REF_AWARE_P(value)) == IS_ARRAY) { + Z_ARRVAL_P(Z_REF_AWARE_P(value))->u.v.nApplyCount--; } } - } + } ZEND_HASH_FOREACH_END(); } else { - zval **data; + zval *data; uint i; for (i = 0; i < n; i++) { - if (zend_hash_index_find(ht, i, (void *)&data) != SUCCESS || - !data || data == &val || - (Z_TYPE_PP(data) == IS_ARRAY && - Z_ARRVAL_PP(data)->nApplyCount > 1)) + if ((data = zend_hash_index_find(ht, i)) == NULL || + !data || &data == &val || + (Z_TYPE_P(Z_REF_AWARE_P(data)) == IS_ARRAY && + Z_ARRVAL_P(Z_REF_AWARE_P(data))->u.v.nApplyCount > 1)) { msgpack_pack_nil(buf); } else { - if (Z_TYPE_PP(data) == IS_ARRAY) + if (Z_TYPE_P(Z_REF_AWARE_P(data)) == IS_ARRAY) { - Z_ARRVAL_PP(data)->nApplyCount++; + Z_ARRVAL_P(Z_REF_AWARE_P(data))->u.v.nApplyCount++; } - msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC); + msgpack_serialize_zval(buf, data, var_hash TSRMLS_CC); - if (Z_TYPE_PP(data) == IS_ARRAY) + if (Z_TYPE_P(Z_REF_AWARE_P(data)) == IS_ARRAY) { - Z_ARRVAL_PP(data)->nApplyCount--; + Z_ARRVAL_P(Z_REF_AWARE_P(data))->u.v.nApplyCount--; } } } @@ -423,88 +319,71 @@ inline static void msgpack_serialize_array( } inline static void msgpack_serialize_object( - smart_str *buf, zval *val, HashTable *var_hash, - char* class_name, zend_uint name_len, zend_bool incomplete_class TSRMLS_DC) + smart_string *buf, zval *val, HashTable *var_hash, + char* class_name, uint32_t name_len, zend_bool incomplete_class TSRMLS_DC) { - zval *retval_ptr = NULL; - zval fname; + zval retval, fname; int res; zend_class_entry *ce = NULL; + zend_string *sleep_zstring; - if (Z_OBJ_HT_P(val)->get_class_entry) - { - ce = Z_OBJCE_P(val); + if (Z_OBJCE_P(Z_REF_AWARE_P(val))) { + ce = Z_OBJCE_P(Z_REF_AWARE_P(val)); } -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) - if (ce && ce->serialize != NULL) - { + if (ce && ce->serialize != NULL) { unsigned char *serialized_data = NULL; - zend_uint serialized_length; + size_t serialized_length; - if (ce->serialize( - val, &serialized_data, &serialized_length, - (zend_serialize_data *)var_hash TSRMLS_CC) == SUCCESS && - !EG(exception)) - { + if (ce->serialize(val, &serialized_data, &serialized_length, (zend_serialize_data *)var_hash) == SUCCESS && !EG(exception)) { /* has custom handler */ msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT); - msgpack_serialize_string(buf, (char *)ce->name, ce->name_length); + msgpack_serialize_string(buf, ce->name->val, ce->name->len); msgpack_pack_raw(buf, serialized_length); msgpack_pack_raw_body(buf, serialized_data, serialized_length); - } - else - { + } else { msgpack_pack_nil(buf); } - if (serialized_data) - { + if (serialized_data) { efree(serialized_data); } return; } -#endif + + sleep_zstring = zend_string_init("__sleep", sizeof("__sleep") - 1, 0); + ZVAL_STRING(&fname, "__sleep"); if (ce && ce != PHP_IC_ENTRY && - zend_hash_exists(&ce->function_table, "__sleep", sizeof("__sleep"))) + zend_hash_exists(&ce->function_table, sleep_zstring)) { - INIT_PZVAL(&fname); - ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 0); - res = call_user_function_ex(CG(function_table), &val, &fname, - &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); - if (res == SUCCESS && !EG(exception)) + zend_string_release(sleep_zstring); + + if ((res = call_user_function_ex(CG(function_table), val, &fname, &retval, 0, 0, 1, NULL)) == SUCCESS && !EG(exception)) { - if (retval_ptr) - { - if (HASH_OF(retval_ptr)) - { - msgpack_serialize_class( - buf, val, retval_ptr, var_hash, + if (HASH_OF(&retval)) { + msgpack_serialize_class( + buf, val, &retval, var_hash, class_name, name_len, incomplete_class TSRMLS_CC); - } - else - { - MSGPACK_NOTICE( + } else { + MSGPACK_NOTICE( "[msgpack] (%s) __sleep should return an array only " "containing the names of instance-variables " "to serialize", __FUNCTION__); - msgpack_pack_nil(buf); - } - zval_ptr_dtor(&retval_ptr); + msgpack_pack_nil(buf); } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&fname); return; } - } - - if (retval_ptr) - { - zval_ptr_dtor(&retval_ptr); + } else { + zval_ptr_dtor(&fname); + zend_string_release(sleep_zstring); } msgpack_serialize_array( @@ -513,18 +392,21 @@ inline static void msgpack_serialize_object( } void msgpack_serialize_zval( - smart_str *buf, zval *val, HashTable *var_hash TSRMLS_DC) + smart_string *buf, zval *val, HashTable *var_hash TSRMLS_DC) { - ulong *var_already; + zval *var_already; + + if (Z_TYPE_P(val) == IS_INDIRECT) { + val = Z_INDIRECT_P(val); + } if (MSGPACK_G(php_only) && var_hash && - msgpack_var_add( - var_hash, val, (void *)&var_already TSRMLS_CC) == FAILURE) + msgpack_var_add(var_hash, val, &var_already) == FAILURE) { if (Z_ISREF_P(val)) { - if (Z_TYPE_P(val) == IS_ARRAY) + if (Z_TYPE_P(Z_REF_AWARE_P(val)) == IS_ARRAY) { msgpack_pack_map(buf, 2); @@ -532,11 +414,11 @@ void msgpack_serialize_zval( msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_RECURSIVE); msgpack_pack_long(buf, 0); - msgpack_pack_long(buf, *var_already); + msgpack_pack_long(buf, Z_LVAL_P(var_already)); return; } - else if (Z_TYPE_P(val) == IS_OBJECT) + else if (Z_TYPE_P(Z_REF_AWARE_P(val)) == IS_OBJECT) { msgpack_pack_map(buf, 2); @@ -544,12 +426,12 @@ void msgpack_serialize_zval( msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE); msgpack_pack_long(buf, 0); - msgpack_pack_long(buf, *var_already); + msgpack_pack_long(buf, Z_LVAL_P(var_already)); return; } } - else if (Z_TYPE_P(val) == IS_OBJECT) + else if (Z_TYPE_P(Z_REF_AWARE_P(val)) == IS_OBJECT) { msgpack_pack_map(buf, 2); @@ -557,35 +439,28 @@ void msgpack_serialize_zval( msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_OBJECT); msgpack_pack_long(buf, 0); - msgpack_pack_long(buf, *var_already); + msgpack_pack_long(buf, Z_LVAL_P(var_already)); return; } } - switch (Z_TYPE_P(val)) + switch (Z_TYPE_P(Z_REF_AWARE_P(val))) { case IS_NULL: msgpack_pack_nil(buf); break; - case IS_BOOL: - if (Z_BVAL_P(val)) - { - msgpack_pack_true(buf); - } - else - { - msgpack_pack_false(buf); - } + case IS_TRUE: + msgpack_pack_true(buf); + break; + case IS_FALSE: + msgpack_pack_false(buf); break; case IS_LONG: - msgpack_pack_long(buf, Z_LVAL_P(val)); + msgpack_pack_long(buf, zval_get_long(val)); break; case IS_DOUBLE: - { - double dbl = Z_DVAL_P(val); - msgpack_pack_double(buf, dbl); - } + msgpack_pack_double(buf, Z_DVAL_P(val)); break; case IS_STRING: msgpack_serialize_string( @@ -598,10 +473,10 @@ void msgpack_serialize_zval( case IS_OBJECT: { PHP_CLASS_ATTRIBUTES; - PHP_SET_CLASS_ATTRIBUTES(val); + PHP_SET_CLASS_ATTRIBUTES(Z_REF_AWARE_P(val)); msgpack_serialize_object( - buf, val, var_hash, class_name, name_len, + buf, val, var_hash, class_name->val, class_name->len, incomplete_class TSRMLS_CC); PHP_CLEANUP_CLASS_ATTRIBUTES(); diff --git a/msgpack_pack.h b/msgpack_pack.h index 28ae06a..0c87f38 100644 --- a/msgpack_pack.h +++ b/msgpack_pack.h @@ -17,6 +17,6 @@ enum msgpack_serialize_type }; void msgpack_serialize_zval( - smart_str *buf, zval *val, HashTable *var_hash TSRMLS_DC); + smart_string *buf, zval *val, HashTable *var_hash TSRMLS_DC); #endif diff --git a/msgpack_unpack.c b/msgpack_unpack.c index 3bf2ac9..0d49645 100644 --- a/msgpack_unpack.c +++ b/msgpack_unpack.c @@ -8,107 +8,68 @@ #include "msgpack_unpack.h" #include "msgpack_errors.h" -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) -# define Z_ADDREF_PP(ppz) ZVAL_ADDREF(*(ppz)) -# define Z_SET_ISREF_PP(ppz) (*(ppz))->is_ref = 1 -# define Z_UNSET_ISREF_PP(ppz) (*(ppz))->is_ref = 0 -#endif - #define VAR_ENTRIES_MAX 1024 -typedef struct -{ - zval *data[VAR_ENTRIES_MAX]; +typedef struct { + zval data[VAR_ENTRIES_MAX]; long used_slots; void *next; } var_entries; -#define MSGPACK_UNSERIALIZE_ALLOC_STACK(_unpack) \ - if (_unpack->deps <= 0) { \ - *obj = _unpack->retval; \ - msgpack_stack_push(_unpack->var_hash, obj, 0); \ - } else { \ - ALLOC_INIT_ZVAL(*obj); \ - msgpack_stack_push(_unpack->var_hash, obj, 1); \ - } - -#define MSGPACK_UNSERIALIZE_ALLOC_VALUE(_unpack) \ - if (_unpack->deps <= 0) { \ - *obj = _unpack->retval; \ - msgpack_var_push(_unpack->var_hash, obj); \ - } else { \ - ALLOC_INIT_ZVAL(*obj); \ - msgpack_var_push(_unpack->var_hash, obj); \ - } - #define MSGPACK_UNSERIALIZE_FINISH_ITEM(_unpack, _count) \ - msgpack_stack_pop(_unpack->var_hash, _count); \ _unpack->stack[_unpack->deps-1]--; \ if (_unpack->stack[_unpack->deps-1] == 0) { \ _unpack->deps--; \ } #define MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(_unpack, _key, _val) \ - zval_ptr_dtor(&_key); \ - zval_ptr_dtor(&_val); \ + zval_ptr_dtor(_key); \ + zval_ptr_dtor(_val); \ MSGPACK_UNSERIALIZE_FINISH_ITEM(_unpack, 2); -inline static void msgpack_var_push( - msgpack_unserialize_data_t *var_hashx, zval **rval) -{ +inline static void msgpack_var_push(msgpack_unserialize_data_t *var_hashx, zval **rval) { var_entries *var_hash, *prev = NULL; - if (!var_hashx) - { + if (!var_hashx) { return; } var_hash = var_hashx->first; - while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) - { + while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { prev = var_hash; var_hash = var_hash->next; } - if (!var_hash) - { - var_hash = emalloc(sizeof(var_entries)); + if (!var_hash) { + var_hash = ecalloc(1, sizeof(var_entries)); var_hash->used_slots = 0; var_hash->next = 0; - if (!var_hashx->first) - { + if (!var_hashx->first) { var_hashx->first = var_hash; - } - else - { + } else { prev->next = var_hash; } } - var_hash->data[var_hash->used_slots++] = *rval; + *rval = &var_hash->data[var_hash->used_slots++]; } -inline static int msgpack_var_access( - msgpack_unserialize_data_t *var_hashx, long id, zval ***store) +inline static int msgpack_var_access(msgpack_unserialize_data_t *var_hashx, long id, zval **store) { var_entries *var_hash = var_hashx->first; - while (id >= VAR_ENTRIES_MAX && - var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) - { + while (id >= VAR_ENTRIES_MAX && var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { var_hash = var_hash->next; id -= VAR_ENTRIES_MAX; } - if (!var_hash) - { + if (!var_hash) { return !SUCCESS; } - if (id < 0 || id >= var_hash->used_slots) - { + if (id < 0 || id >= var_hash->used_slots) { return !SUCCESS; } @@ -117,96 +78,54 @@ inline static int msgpack_var_access( return SUCCESS; } -inline static void msgpack_stack_push( - msgpack_unserialize_data_t *var_hashx, zval **rval, zend_bool save) +inline static void msgpack_stack_push(msgpack_unserialize_data_t *var_hashx, zval **rval) { var_entries *var_hash, *prev = NULL; - if (!var_hashx) - { + if (!var_hashx) { return; } var_hash = var_hashx->first_dtor; - while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) - { + while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { prev = var_hash; var_hash = var_hash->next; } - if (!var_hash) - { - var_hash = emalloc(sizeof(var_entries)); + if (!var_hash) { + var_hash = ecalloc(1, sizeof(var_entries)); var_hash->used_slots = 0; var_hash->next = 0; - if (!var_hashx->first_dtor) - { + if (!var_hashx->first_dtor) { var_hashx->first_dtor = var_hash; - } - else - { + } else { prev->next = var_hash; } } - if (save) - { - var_hash->data[var_hash->used_slots++] = *rval; - } - else - { - var_hash->data[var_hash->used_slots++] = NULL; - } -} - -inline static void msgpack_stack_pop( - msgpack_unserialize_data_t *var_hashx, long count) -{ - long i; - var_entries *var_hash = var_hashx->first_dtor; - - while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) - { - var_hash = var_hash->next; - } - - if (!var_hash || count <= 0) - { - return; - } - - for (i = count; i > 0; i--) - { - var_hash->used_slots--; - if (var_hash->used_slots < 0) - { - var_hash->used_slots = 0; - var_hash->data[var_hash->used_slots] = NULL; - break; - } - else - { - var_hash->data[var_hash->used_slots] = NULL; - } - } + *rval = &var_hash->data[var_hash->used_slots++]; } inline static zend_class_entry* msgpack_unserialize_class( - zval **container, char *class_name, size_t name_len) + zval **container, char *class_name, size_t name_len, zend_bool init_class) { - zend_class_entry *ce, **pce; + zend_class_entry *ce; zend_bool incomplete_class = 0; - zval *user_func, *retval_ptr, **args[1], *arg_func_name; - TSRMLS_FETCH(); + zval user_func, retval, args[1], arg_func_name, *container_val; + int func_call_status; + zend_string *class_zstring; - do - { + container_val = Z_ISREF_P(*container) ? Z_REFVAL_P(*container) : *container; + + + do { /* Try to find class directly */ - if (zend_lookup_class(class_name, name_len, &pce TSRMLS_CC) == SUCCESS) - { - ce = *pce; + class_zstring = zend_string_init(class_name, name_len, 0); + ce = zend_lookup_class(class_zstring); + zend_string_release(class_zstring); + if (ce != NULL) { break; } @@ -220,36 +139,26 @@ inline static zend_class_entry* msgpack_unserialize_class( } /* Call unserialize callback */ - ALLOC_INIT_ZVAL(user_func); - ZVAL_STRING(user_func, PG(unserialize_callback_func), 1); - args[0] = &arg_func_name; - ALLOC_INIT_ZVAL(arg_func_name); - ZVAL_STRING(arg_func_name, class_name, 1); - if (call_user_function_ex( - CG(function_table), NULL, user_func, &retval_ptr, - 1, args, 0, NULL TSRMLS_CC) != SUCCESS) - { + ZVAL_STRING(&user_func, PG(unserialize_callback_func)); + ZVAL_STRING(&arg_func_name, class_name); + + args[0] = arg_func_name; + + func_call_status = call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL); + zval_ptr_dtor(&arg_func_name); + zval_ptr_dtor(&user_func); + if (func_call_status != SUCCESS) { MSGPACK_WARNING("[msgpack] (%s) defined (%s) but not found", __FUNCTION__, class_name); incomplete_class = 1; ce = PHP_IC_ENTRY; - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); break; } - if (retval_ptr) - { - zval_ptr_dtor(&retval_ptr); - } /* The callback function may have defined the class */ - if (zend_lookup_class(class_name, name_len, &pce TSRMLS_CC) == SUCCESS) - { - ce = *pce; - } - else - { + class_zstring = zend_string_init(class_name, name_len, 0); + if ((ce = zend_lookup_class(class_zstring)) == NULL) { MSGPACK_WARNING("[msgpack] (%s) Function %s() hasn't defined " "the class it was called for", __FUNCTION__, class_name); @@ -257,24 +166,23 @@ inline static zend_class_entry* msgpack_unserialize_class( incomplete_class = 1; ce = PHP_IC_ENTRY; } - - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); + zend_string_release(class_zstring); } while(0); - if (EG(exception)) - { + if (EG(exception)) { MSGPACK_WARNING("[msgpack] (%s) Exception error", __FUNCTION__); return NULL; } - object_init_ex(*container, ce); + if (init_class || incomplete_class) { + object_init_ex(container_val, ce); + } /* store incomplete class name */ if (incomplete_class) { - php_store_class_name(*container, class_name, name_len); + php_store_class_name(container_val, class_name, name_len); } return ce; @@ -283,7 +191,6 @@ inline static zend_class_entry* msgpack_unserialize_class( void msgpack_serialize_var_init(msgpack_serialize_data_t *var_hash) { HashTable **var_hash_ptr = (HashTable **)var_hash; - TSRMLS_FETCH(); if (MSGPACK_G(serialize).level) { *var_hash_ptr = MSGPACK_G(serialize).var_hash; @@ -298,7 +205,6 @@ void msgpack_serialize_var_init(msgpack_serialize_data_t *var_hash) void msgpack_serialize_var_destroy(msgpack_serialize_data_t *var_hash) { HashTable **var_hash_ptr = (HashTable **)var_hash; - TSRMLS_FETCH(); --MSGPACK_G(serialize).level; if (!MSGPACK_G(serialize).level) { @@ -313,51 +219,34 @@ void msgpack_unserialize_var_init(msgpack_unserialize_data_t *var_hashx) var_hashx->first_dtor = 0; } -void msgpack_unserialize_var_destroy( - msgpack_unserialize_data_t *var_hashx, zend_bool err) +void msgpack_unserialize_var_destroy(msgpack_unserialize_data_t *var_hashx, zend_bool err) { void *next; - long i; var_entries *var_hash = var_hashx->first; - - while (var_hash) - { - if (err) - { - for (i = var_hash->used_slots - 1; i > 0; i--) - { - if (var_hash->data[i]) - { - //zval_ptr_dtor(&var_hash->data[i]); - //var_hash->data[i] = NULL; - } - } - } - + while (var_hash) { next = var_hash->next; efree(var_hash); var_hash = next; } var_hash = var_hashx->first_dtor; - - while (var_hash) - { - for (i = var_hash->used_slots - 1; i >= 0; i--) - { - if (var_hash->data[i]) - { - zval_ptr_dtor(&var_hash->data[i]); - var_hash->data[i] = NULL; - } - } - + while (var_hash) { next = var_hash->next; efree(var_hash); var_hash = next; } } +void msgpack_unserialize_set_return_value(msgpack_unserialize_data_t *var_hashx, zval *return_value) { + var_entries *var_hash; + if ((var_hash = var_hashx->first) != NULL) { + ZVAL_COPY_VALUE(return_value, &var_hash->data[0]); + } else if ((var_hash = var_hashx->first_dtor) != NULL) { + ZVAL_COPY_VALUE(return_value, &var_hash->data[0]); + } + +} + void msgpack_unserialize_init(msgpack_unserialize_data *unpack) { unpack->deps = 0; @@ -367,8 +256,7 @@ void msgpack_unserialize_init(msgpack_unserialize_data *unpack) int msgpack_unserialize_uint8( msgpack_unserialize_data *unpack, uint8_t data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_LONG(*obj, data); return 0; @@ -377,8 +265,8 @@ int msgpack_unserialize_uint8( int msgpack_unserialize_uint16( msgpack_unserialize_data *unpack, uint16_t data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); + msgpack_stack_push(unpack->var_hash, obj); ZVAL_LONG(*obj, data); return 0; @@ -387,8 +275,7 @@ int msgpack_unserialize_uint16( int msgpack_unserialize_uint32( msgpack_unserialize_data *unpack, uint32_t data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_LONG(*obj, data); return 0; @@ -397,8 +284,7 @@ int msgpack_unserialize_uint32( int msgpack_unserialize_uint64( msgpack_unserialize_data *unpack, uint64_t data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_LONG(*obj, data); return 0; @@ -407,8 +293,7 @@ int msgpack_unserialize_uint64( int msgpack_unserialize_int8( msgpack_unserialize_data *unpack, int8_t data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_LONG(*obj, data); return 0; @@ -417,8 +302,7 @@ int msgpack_unserialize_int8( int msgpack_unserialize_int16( msgpack_unserialize_data *unpack, int16_t data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_LONG(*obj, data); return 0; @@ -427,8 +311,7 @@ int msgpack_unserialize_int16( int msgpack_unserialize_int32( msgpack_unserialize_data *unpack, int32_t data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_LONG(*obj, data); return 0; @@ -437,8 +320,7 @@ int msgpack_unserialize_int32( int msgpack_unserialize_int64( msgpack_unserialize_data *unpack, int64_t data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_LONG(*obj, data); return 0; @@ -447,8 +329,7 @@ int msgpack_unserialize_int64( int msgpack_unserialize_float( msgpack_unserialize_data *unpack, float data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_DOUBLE(*obj, data); return 0; @@ -457,8 +338,7 @@ int msgpack_unserialize_float( int msgpack_unserialize_double( msgpack_unserialize_data *unpack, double data, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_DOUBLE(*obj, data); return 0; @@ -466,8 +346,7 @@ int msgpack_unserialize_double( int msgpack_unserialize_nil(msgpack_unserialize_data *unpack, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_NULL(*obj); return 0; @@ -475,8 +354,7 @@ int msgpack_unserialize_nil(msgpack_unserialize_data *unpack, zval **obj) int msgpack_unserialize_true(msgpack_unserialize_data *unpack, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_BOOL(*obj, 1); return 0; @@ -484,8 +362,7 @@ int msgpack_unserialize_true(msgpack_unserialize_data *unpack, zval **obj) int msgpack_unserialize_false(msgpack_unserialize_data *unpack, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - + msgpack_stack_push(unpack->var_hash, obj); ZVAL_BOOL(*obj, 0); return 0; @@ -495,15 +372,11 @@ int msgpack_unserialize_raw( msgpack_unserialize_data *unpack, const char* base, const char* data, unsigned int len, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); - - if (len == 0) - { - ZVAL_STRINGL(*obj, "", 0, 1); - } - else - { - ZVAL_STRINGL(*obj, (char *)data, len, 1); + msgpack_stack_push(unpack->var_hash, obj); + if (len == 0) { + ZVAL_STRINGL(*obj, "", 0); + } else { + ZVAL_STRINGL(*obj, data, len); } return 0; @@ -512,8 +385,7 @@ int msgpack_unserialize_raw( int msgpack_unserialize_array( msgpack_unserialize_data *unpack, unsigned int count, zval **obj) { - MSGPACK_UNSERIALIZE_ALLOC_VALUE(unpack); - + msgpack_var_push(unpack->var_hash, obj); array_init(*obj); if (count) unpack->stack[unpack->deps++] = count; @@ -534,21 +406,15 @@ int msgpack_unserialize_array_item( int msgpack_unserialize_map( msgpack_unserialize_data *unpack, unsigned int count, zval **obj) { - TSRMLS_FETCH(); - MSGPACK_UNSERIALIZE_ALLOC_VALUE(unpack); - + msgpack_var_push(unpack->var_hash, obj); if (count) unpack->stack[unpack->deps++] = count; unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; - if (count == 0) - { - if (MSGPACK_G(php_only)) - { + if (count == 0) { + if (MSGPACK_G(php_only)) { object_init(*obj); - } - else - { + } else { array_init(*obj); } } @@ -560,21 +426,16 @@ int msgpack_unserialize_map_item( msgpack_unserialize_data *unpack, zval **container, zval *key, zval *val) { long deps; - TSRMLS_FETCH(); - if (MSGPACK_G(php_only)) - { + if (MSGPACK_G(php_only)) { zend_class_entry *ce; - if (Z_TYPE_P(key) == IS_NULL) - { + if (Z_TYPE_P(key) == IS_NULL) { unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; - if (Z_TYPE_P(val) == IS_LONG) - { - switch (Z_LVAL_P(val)) - { + if (Z_TYPE_P(val) == IS_LONG) { + switch (Z_LVAL_P(val)) { case MSGPACK_SERIALIZE_TYPE_REFERENCE: - Z_SET_ISREF_PP(container); + ZVAL_MAKE_REF(*container); break; case MSGPACK_SERIALIZE_TYPE_RECURSIVE: unpack->type = MSGPACK_SERIALIZE_TYPE_RECURSIVE; @@ -591,14 +452,10 @@ int msgpack_unserialize_map_item( default: break; } - } - else if (Z_TYPE_P(val) == IS_STRING) - { - ce = msgpack_unserialize_class( - container, Z_STRVAL_P(val), Z_STRLEN_P(val)); + } else if (Z_TYPE_P(val) == IS_STRING) { + ce = msgpack_unserialize_class(container, Z_STRVAL_P(val), Z_STRLEN_P(val), 1); - if (ce == NULL) - { + if (ce == NULL) { MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; @@ -608,27 +465,20 @@ int msgpack_unserialize_map_item( MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; - } - else - { - switch (unpack->type) - { + } else { + switch (unpack->type) { case MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; - ce = msgpack_unserialize_class( - container, Z_STRVAL_P(key), Z_STRLEN_P(key)); - if (ce == NULL) - { + ce = msgpack_unserialize_class(container, Z_STRVAL_P(key), Z_STRLEN_P(key), 0); + if (ce == NULL) { MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) /* implementing Serializable */ - if (ce->unserialize == NULL) - { + if (ce->unserialize == NULL) { MSGPACK_WARNING( "[msgpack] (%s) Class %s has no unserializer", __FUNCTION__, ce->name); @@ -638,11 +488,7 @@ int msgpack_unserialize_map_item( return 0; } - ce->unserialize( - container, ce, - (const unsigned char *)Z_STRVAL_P(val), - Z_STRLEN_P(val) + 1, NULL TSRMLS_CC); -#endif + ce->unserialize(*container, ce, Z_STRVAL_P(val), Z_STRLEN_P(val) + 1, NULL); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); @@ -651,41 +497,31 @@ int msgpack_unserialize_map_item( case MSGPACK_SERIALIZE_TYPE_OBJECT: case MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE: { - zval **rval; + zval *rval; int type = unpack->type; unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; - if (msgpack_var_access( - unpack->var_hash, - Z_LVAL_P(val) - 1, &rval) != SUCCESS) - { - MSGPACK_WARNING( - "[msgpack] (%s) Invalid references value: %ld", + if (msgpack_var_access(unpack->var_hash, Z_LVAL_P(val) - 1, &rval) != SUCCESS) { + MSGPACK_WARNING("[msgpack] (%s) Invalid references value: %ld", __FUNCTION__, Z_LVAL_P(val) - 1); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); - return 0; } - if (container != NULL) - { - zval_ptr_dtor(container); + if (container != NULL) { + zval_ptr_dtor(*container); } - *container = *rval; - - Z_ADDREF_PP(container); - - if (type == MSGPACK_SERIALIZE_TYPE_OBJECT) - { - Z_UNSET_ISREF_PP(container); + *container = rval; + if (type == MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE) { + ZVAL_MAKE_REF(*container); } - else if (type == MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE) - { - Z_SET_ISREF_PP(container); + if (Z_REFCOUNTED_P(*container)) { + Z_TRY_ADDREF_P(*container); } + MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; @@ -694,70 +530,64 @@ int msgpack_unserialize_map_item( } } - if (Z_TYPE_PP(container) != IS_ARRAY && Z_TYPE_PP(container) != IS_OBJECT) - { - array_init(*container); + zval *container_val = Z_ISREF_P(*container) ? Z_REFVAL_P(*container) : *container; + + if (Z_TYPE_P(container_val) != IS_ARRAY && Z_TYPE_P(container_val) != IS_OBJECT) { + array_init(container_val); } - switch (Z_TYPE_P(key)) - { - case IS_LONG: - if (zend_hash_index_update( - HASH_OF(*container), Z_LVAL_P(key), &val, - sizeof(val), NULL) == FAILURE) - { - zval_ptr_dtor(&val); - MSGPACK_WARNING( - "[msgpack] (%s) illegal offset type, skip this decoding", - __FUNCTION__); - } - zval_ptr_dtor(&key); - break; - case IS_STRING: - if (zend_symtable_update( - HASH_OF(*container), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, - &val, sizeof(val), NULL) == FAILURE) - { - zval_ptr_dtor(&val); - MSGPACK_WARNING( - "[msgpack] (%s) illegal offset type, skip this decoding", - __FUNCTION__); - } - zval_ptr_dtor(&key); - break; - default: - MSGPACK_WARNING("[msgpack] (%s) illegal key type", __FUNCTION__); + if (Z_TYPE_P(container_val) == IS_OBJECT && Z_OBJCE_P(container_val) != PHP_IC_ENTRY) { + const char *class_name, *prop_name; + size_t prop_len; + zend_string *key_zstring = zval_get_string(key); - if (MSGPACK_G(illegal_key_insert)) - { - if (zend_hash_next_index_insert( - HASH_OF(*container), &key, sizeof(key), NULL) == FAILURE) - { - zval_ptr_dtor(&val); + zend_unmangle_property_name_ex(key_zstring, &class_name, &prop_name, &prop_len); + zend_update_property(Z_OBJCE_P(container_val), container_val, prop_name, prop_len, val); + + zend_string_release(key_zstring); + zval_ptr_dtor(key); + zval_ptr_dtor(val); + } else { + switch (Z_TYPE_P(key)) { + case IS_LONG: + if ((val = zend_hash_index_update(HASH_OF(container_val), Z_LVAL_P(key), val)) == NULL) { + zval_ptr_dtor(val); + MSGPACK_WARNING( + "[msgpack] (%s) illegal offset type, skip this decoding", + __FUNCTION__); } - if (zend_hash_next_index_insert( - HASH_OF(*container), &val, sizeof(val), NULL) == FAILURE) - { - zval_ptr_dtor(&val); + zval_ptr_dtor(key); + break; + case IS_STRING: + if ((val = zend_hash_update(HASH_OF(container_val), Z_STR(*key), val)) == NULL) { + zval_ptr_dtor(val); + MSGPACK_WARNING( + "[msgpack] (%s) illegal offset type, skip this decoding", + __FUNCTION__); } - } - else - { - convert_to_string(key); - if (zend_symtable_update( - HASH_OF(*container), - Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, - &val, sizeof(val), NULL) == FAILURE) - { - zval_ptr_dtor(&val); + zval_ptr_dtor(key); + break; + default: + MSGPACK_WARNING("[msgpack] (%s) illegal key type", __FUNCTION__); + + if (MSGPACK_G(illegal_key_insert)) { + if ((key = zend_hash_next_index_insert(HASH_OF(container_val), key)) == NULL) { + zval_ptr_dtor(val); + } + if ((val = zend_hash_next_index_insert(HASH_OF(container_val), val)) == NULL) { + zval_ptr_dtor(val); + } + } else { + convert_to_string(key); + if ((zend_symtable_update(HASH_OF(container_val), zend_string_init(Z_STRVAL_P(key), Z_STRLEN_P(key), 0), val)) == NULL) { + zval_ptr_dtor(val); + } + zval_ptr_dtor(key); } - zval_ptr_dtor(&key); - } - break; + break; + } } - msgpack_stack_pop(unpack->var_hash, 2); - deps = unpack->deps - 1; unpack->stack[deps]--; if (unpack->stack[deps] == 0) @@ -765,24 +595,22 @@ int msgpack_unserialize_map_item( unpack->deps--; /* wakeup */ + zend_string *wakeup_zstring = zend_string_init("__wakeup", sizeof("__wakeup") - 1, 0); + if (MSGPACK_G(php_only) && - Z_TYPE_PP(container) == IS_OBJECT && - Z_OBJCE_PP(container) != PHP_IC_ENTRY && - zend_hash_exists( - &Z_OBJCE_PP(container)->function_table, - "__wakeup", sizeof("__wakeup"))) + Z_TYPE_P(container_val) == IS_OBJECT && + Z_OBJCE_P(container_val) != PHP_IC_ENTRY && + zend_hash_exists(&Z_OBJCE_P(container_val)->function_table, wakeup_zstring)) { - zval f, *h = NULL; - - INIT_PZVAL(&f); - ZVAL_STRINGL(&f, "__wakeup", sizeof("__wakeup") - 1, 0); - call_user_function_ex( - CG(function_table), container, &f, &h, 0, 0, 1, NULL TSRMLS_CC); - if (h) - { - zval_ptr_dtor(&h); - } + zval f, h; + ZVAL_STRING(&f, "__wakeup"); + + call_user_function_ex(CG(function_table), container_val, &f, &h, 0, NULL, 1, NULL TSRMLS_CC); + + zval_ptr_dtor(&h); + zval_ptr_dtor(&f); } + zend_string_release(wakeup_zstring); } return 0; diff --git a/msgpack_unpack.h b/msgpack_unpack.h index e140145..a6a288a 100644 --- a/msgpack_unpack.h +++ b/msgpack_unpack.h @@ -29,8 +29,7 @@ typedef struct { void msgpack_serialize_var_init(msgpack_serialize_data_t *var_hash); void msgpack_serialize_var_destroy(msgpack_serialize_data_t *var_hash); void msgpack_unserialize_var_init(msgpack_unserialize_data_t *var_hashx); -void msgpack_unserialize_var_destroy( - msgpack_unserialize_data_t *var_hashx, zend_bool err); +void msgpack_unserialize_var_destroy(msgpack_unserialize_data_t *var_hashx, zend_bool err); void msgpack_unserialize_init(msgpack_unserialize_data *unpack); diff --git a/php_msgpack.h b/php_msgpack.h index 492c448..b08282b 100644 --- a/php_msgpack.h +++ b/php_msgpack.h @@ -1,7 +1,7 @@ #ifndef PHP_MSGPACK_H #define PHP_MSGPACK_H -#include "ext/standard/php_smart_str.h" /* for smart_str */ +#include "ext/standard/php_smart_string.h" /* for smart_string */ #define PHP_MSGPACK_VERSION "0.5.7-dev" @@ -39,7 +39,7 @@ ZEND_EXTERN_MODULE_GLOBALS(msgpack) #endif PHP_MSGPACK_API void php_msgpack_serialize( - smart_str *buf, zval *val TSRMLS_DC); + smart_string *buf, zval *val TSRMLS_DC); PHP_MSGPACK_API void php_msgpack_unserialize( zval *return_value, char *str, size_t str_len TSRMLS_DC); diff --git a/tests/090.phpt b/tests/090.phpt index b2a1224..92a4ee7 100644 --- a/tests/090.phpt +++ b/tests/090.phpt @@ -76,7 +76,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); @@ -84,10 +83,6 @@ test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new O $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); -test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); - -test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); -test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( @@ -122,15 +117,6 @@ $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); -$o = new Obj2(1, 2, 3); -test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array($o, &$o), 'Obj', new Obj($o, $o)); - --EXPECTF-- object(Obj)#%d (3) { ["a"]=> @@ -304,7 +290,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -339,17 +325,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) @@ -392,51 +367,6 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK object(Obj)#%d (4) { ["a"]=> array(2) { @@ -504,72 +434,3 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK diff --git a/tests/091.phpt b/tests/091.phpt index 33bb875..80ad0a5 100644 --- a/tests/091.phpt +++ b/tests/091.phpt @@ -78,7 +78,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); @@ -86,10 +85,6 @@ test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), n $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); -test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); - -test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); -test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( @@ -124,15 +119,6 @@ $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); -$o = new Obj2(1, 2, 3); -test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array($o, &$o), new Obj(), new Obj($o, $o)); - --EXPECTF-- object(Obj)#%d (3) { ["a"]=> @@ -306,7 +292,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -341,17 +327,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) @@ -394,51 +369,6 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK object(Obj)#%d (4) { ["a"]=> array(2) { @@ -506,72 +436,3 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK diff --git a/tests/092.phpt b/tests/092.phpt index 9c5dd1a..8c342bf 100644 --- a/tests/092.phpt +++ b/tests/092.phpt @@ -77,7 +77,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); @@ -292,7 +291,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -327,17 +326,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) diff --git a/tests/093.phpt b/tests/093.phpt index f66511e..73980ab 100644 --- a/tests/093.phpt +++ b/tests/093.phpt @@ -79,7 +79,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); @@ -294,7 +293,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -329,17 +328,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) diff --git a/tests/094.phpt b/tests/094.phpt index a0a40d6..6f6f5b5 100644 --- a/tests/094.phpt +++ b/tests/094.phpt @@ -79,7 +79,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); @@ -87,10 +86,6 @@ test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new O $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); -test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); - -test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); -test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( @@ -125,15 +120,6 @@ $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); -$o = new Obj2(1, 2, 3); -test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array($o, &$o), 'Obj', new Obj($o, $o)); - --EXPECTF-- object(Obj)#%d (3) { ["a"]=> @@ -307,7 +293,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -342,17 +328,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) @@ -395,51 +370,6 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK object(Obj)#%d (4) { ["a"]=> array(2) { @@ -507,72 +437,3 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK diff --git a/tests/095.phpt b/tests/095.phpt index a0feafc..b03eb60 100644 --- a/tests/095.phpt +++ b/tests/095.phpt @@ -81,7 +81,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); @@ -89,10 +88,6 @@ test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), n $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); -test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); - -test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); -test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( @@ -127,15 +122,6 @@ $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); -$o = new Obj2(1, 2, 3); -test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array($o, &$o), new Obj(), new Obj($o, $o)); - --EXPECTF-- object(Obj)#%d (3) { ["a"]=> @@ -309,7 +295,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -344,17 +330,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) @@ -397,51 +372,6 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK object(Obj)#%d (4) { ["a"]=> array(2) { @@ -509,72 +439,3 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK diff --git a/tests/096.phpt b/tests/096.phpt index 06ff215..3ef47e4 100644 --- a/tests/096.phpt +++ b/tests/096.phpt @@ -80,7 +80,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); @@ -295,7 +294,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -330,17 +329,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) diff --git a/tests/097.phpt b/tests/097.phpt index 055a5e4..dd0e4b9 100644 --- a/tests/097.phpt +++ b/tests/097.phpt @@ -82,7 +82,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); @@ -297,7 +296,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -332,17 +331,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) diff --git a/tests/098.phpt b/tests/098.phpt index 23f3427..0687401 100644 --- a/tests/098.phpt +++ b/tests/098.phpt @@ -80,7 +80,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); @@ -295,7 +294,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -330,17 +329,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) diff --git a/tests/099.phpt b/tests/099.phpt index 01da2ac..3b7e4e8 100644 --- a/tests/099.phpt +++ b/tests/099.phpt @@ -85,7 +85,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); @@ -93,10 +92,6 @@ test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new O $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); -test('array(&$a, &$a)', array(&$a, &$a), 'Obj', new Obj($a, $a, null)); - -test('array(&$a, $a)', array($a, &$a), 'Obj', new Obj($a, $a, null)); -test('array(&$a, $a)', array(&$a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( @@ -131,15 +126,6 @@ $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); -$o = new Obj2(1, 2, 3); -test('object', array(&$o, &$o), 'Obj', new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array(&$o, $o), 'Obj', new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array($o, &$o), 'Obj', new Obj($o, $o)); - --EXPECTF-- object(Obj)#%d (3) { ["a"]=> @@ -313,7 +299,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -348,17 +334,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) @@ -401,51 +376,6 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK object(Obj)#%d (4) { ["a"]=> array(2) { @@ -513,72 +443,3 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK diff --git a/tests/100.phpt b/tests/100.phpt index 0b82563..270cdb8 100644 --- a/tests/100.phpt +++ b/tests/100.phpt @@ -87,7 +87,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); @@ -95,10 +94,6 @@ test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), n $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); -test('array(&$a, &$a)', array(&$a, &$a), new Obj(), new Obj($a, $a, null)); - -test('array(&$a, $a)', array($a, &$a), new Obj(), new Obj($a, $a, null)); -test('array(&$a, $a)', array(&$a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( @@ -133,15 +128,6 @@ $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); -$o = new Obj2(1, 2, 3); -test('object', array(&$o, &$o), new Obj(), new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array(&$o, $o), new Obj(), new Obj($o, $o)); - -$o = new Obj2(1, 2, 3); -test('object', array($o, &$o), new Obj(), new Obj($o, $o)); - --EXPECTF-- object(Obj)#%d (3) { ["a"]=> @@ -315,7 +301,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -350,17 +336,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) @@ -403,51 +378,6 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &array(1) { - [0]=> - string(3) "foo" - } - [%r"?b"?:protected"?%r]=> - array(1) { - [0]=> - string(3) "foo" - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK object(Obj)#%d (4) { ["a"]=> array(2) { @@ -515,72 +445,3 @@ object(Obj)#%d (3) { NULL } OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK -object(Obj)#%d (3) { - ["a"]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?b"?:protected"?%r]=> - &object(Obj2)#%d (3) { - ["A"]=> - int(1) - [%r"?B"?:protected"?%r]=> - int(2) - [%r"?C"?:("Obj2":)?private"?%r]=> - int(3) - } - [%r"?c"?:("Obj":)?private"?%r]=> - NULL -} -OK diff --git a/tests/101.phpt b/tests/101.phpt index c6f09d5..ba64390 100644 --- a/tests/101.phpt +++ b/tests/101.phpt @@ -86,7 +86,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); @@ -301,7 +300,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -336,17 +335,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) diff --git a/tests/102.phpt b/tests/102.phpt index c91eba5..7644635 100644 --- a/tests/102.phpt +++ b/tests/102.phpt @@ -88,7 +88,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), new Obj()); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); @@ -303,7 +302,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -338,17 +337,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1) diff --git a/tests/103.phpt b/tests/103.phpt index 60b3da1..d563781 100644 --- a/tests/103.phpt +++ b/tests/103.phpt @@ -86,7 +86,6 @@ test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); -test('array("" => "empty")', array("" => "empty"), 'Obj'); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); @@ -301,7 +300,7 @@ object(Obj)#%d (4) { int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) - [3]=> + ["3"]=> int(4) } SKIP @@ -336,17 +335,6 @@ object(Obj)#%d (5) { int(2) } OK -object(Obj)#%d (4) { - ["a"]=> - NULL - [%r"?b"?:protected"?%r]=> - NULL - [%r"?c"?:("Obj":)?private"?%r]=> - NULL - [""]=> - string(5) "empty" -} -SKIP object(Obj)#%d (3) { ["a"]=> int(1)