@@ -126,61 +126,53 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
126126 }
127127
128128 /* string */
129- if (ht -> nNumOfElements != ht -> nNextFreeElement ) {
130- htval = HASH_OF (value );
131- if (!htval ) {
132- MSGPACK_WARNING ("[msgpack] (%s) input data is not array" , __FUNCTION__ );
133- return FAILURE ;
134- }
135-
136- zend_hash_internal_pointer_reset_ex (ht , & pos );
137- zend_hash_internal_pointer_reset_ex (htval , & valpos );
138- for (;; zend_hash_move_forward_ex (ht , & pos ), zend_hash_move_forward_ex (htval , & valpos ))
139- {
140- key_type = zend_hash_get_current_key_ex (ht , & key , & key_index , & pos );
141-
142- if (key_type == HASH_KEY_NON_EXISTENT ) {
143- break ;
144- }
145-
146- if ((data = zend_hash_get_current_data_ex (ht , & pos )) == NULL ) {
147- continue ;
148- }
149-
150- if (key_type == HASH_KEY_IS_STRING ) {
151- int (* convert_function )(zval * , zval * , zval * ) = NULL ;
152- zval * dataval ;
153-
154- switch (Z_TYPE_P (data )) {
155- case IS_ARRAY :
156- convert_function = msgpack_convert_array ;
157- break ;
158- case IS_OBJECT :
159- // case IS_STRING:
160- convert_function = msgpack_convert_object ;
161- break ;
162- default :
163- break ;
164- }
129+ if (ht -> nNumOfElements != ht -> nNextFreeElement ) {
130+ htval = HASH_OF (value );
131+
132+ if (!htval ) {
133+ MSGPACK_WARNING ("[msgpack] (%s) input data is not array" , __FUNCTION__ );
134+ return FAILURE ;
135+ }
136+
137+ zend_hash_internal_pointer_reset_ex (htval , & valpos );
138+ ZEND_HASH_FOREACH_KEY_VAL (ht , key_index , key , data ) {
139+ if (key ) {
140+ int (* convert_function )(zval * , zval * , zval * ) = NULL ;
141+ zval * dataval ;
142+
143+ switch (Z_TYPE_P (data )) {
144+ case IS_ARRAY :
145+ convert_function = msgpack_convert_array ;
146+ break ;
147+ case IS_OBJECT :
148+ // case IS_STRING:
149+ convert_function = msgpack_convert_object ;
150+ break ;
151+ default :
152+ break ;
153+ }
165154
166- if ((dataval = zend_hash_get_current_data_ex (htval , & valpos )) == NULL ) {
167- MSGPACK_WARNING ("[msgpack] (%s) can't get data" , __FUNCTION__ );
168- return FAILURE ;
169- }
155+ if ((dataval = zend_hash_get_current_data_ex (htval , & valpos )) == NULL ) {
156+ MSGPACK_WARNING ("[msgpack] (%s) can't get data" , __FUNCTION__ );
157+ return FAILURE ;
158+ }
170159
171- if (convert_function ) {
172- zval rv ;
173- if (convert_function (& rv , data , dataval ) != SUCCESS ) {
174- return FAILURE ;
175- }
176- add_assoc_zval_ex (return_value , key -> val , key -> len , dataval );
177- } else {
178- add_assoc_zval_ex (return_value , key -> val , key -> len , dataval );
179- }
180- }
181- }
160+ if (convert_function ) {
161+ zval rv ;
162+ if (convert_function (& rv , data , dataval ) != SUCCESS ) {
163+ return FAILURE ;
164+ }
165+ Z_TRY_ADDREF_P (dataval );
166+ zend_symtable_update (Z_ARRVAL_P (return_value ), key , dataval );
167+ } else {
168+ Z_TRY_ADDREF_P (dataval );
169+ zend_symtable_update (Z_ARRVAL_P (return_value ), key , dataval );
170+ }
171+ }
172+ zend_hash_move_forward_ex (htval , & valpos );
173+ } ZEND_HASH_FOREACH_END ();
182174
183- return SUCCESS ;
175+ return SUCCESS ;
184176 } else {
185177 /* index */
186178 int (* convert_function )(zval * , zval * , zval * ) = NULL ;
@@ -218,7 +210,7 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
218210 }
219211
220212 htval = HASH_OF (value );
221- if (zend_hash_num_elements (htval ) < = 0 ) {
213+ if (zend_hash_num_elements (htval ) = = 0 ) {
222214 MSGPACK_WARNING ("[msgpack] (%s) array length is 0 in unserialized data" , __FUNCTION__ );
223215 return FAILURE ;
224216 }
@@ -237,8 +229,7 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
237229 }
238230
239231 switch (key_type ) {
240- case HASH_KEY_IS_LONG :
241- {
232+ case HASH_KEY_IS_LONG : {
242233 zval rv ;
243234 if (convert_function ) {
244235 if (convert_function (& rv , data , arydata ) != SUCCESS ) {
@@ -249,8 +240,9 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
249240 __FUNCTION__ );
250241 return FAILURE ;
251242 }
252- add_next_index_zval (return_value , arydata );
243+ add_next_index_zval (return_value , & rv );
253244 } else {
245+ Z_TRY_ADDREF_P (arydata );
254246 add_next_index_zval (return_value , arydata );
255247 }
256248 break ;
@@ -263,7 +255,6 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
263255 return FAILURE ;
264256 }
265257 }
266-
267258 return SUCCESS ;
268259 }
269260
@@ -423,14 +414,14 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */
423414 if (convert_function ) {
424415 zval nv ;
425416 if (convert_function (& nv , data , aryval ) != SUCCESS ) {
426- //zval_ptr_dtor(aryval);
427417 MSGPACK_WARNING ("[msgpack] (%s) "
428418 "convert failure in convert_object" ,
429419 __FUNCTION__ );
430420 return FAILURE ;
431421 }
432422
433- zend_update_property (ce , return_value , str_key -> val , str_key -> len , & nv );
423+ zend_update_property_ex (ce , return_value , str_key , & nv );
424+ zval_ptr_dtor (& nv );
434425 } else {
435426 zend_update_property (ce , return_value , prop_name , prop_len , aryval );
436427 }
@@ -462,19 +453,14 @@ int msgpack_convert_template(zval *return_value, zval *tpl, zval *value) /* {{{
462453 switch (Z_TYPE_P (tpl )) {
463454 case IS_ARRAY :
464455 return msgpack_convert_array (return_value , tpl , value );
465- break ;
466456 case IS_STRING :
467457 case IS_OBJECT :
468458 return msgpack_convert_object (return_value , tpl , value );
469- break ;
470459 default :
471460 MSGPACK_ERROR ("[msgpack] (%s) Template type is unsupported" ,
472461 __FUNCTION__ );
473462 return FAILURE ;
474463 }
475-
476- // shouldn't reach
477- return FAILURE ;
478464}
479465/* }}} */
480466
0 commit comments