55#include "msgpack_convert.h"
66#include "msgpack_errors.h"
77
8- #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3 )
9- # define Z_REFCOUNT_P (pz ) ((pz)->refcount)
10- # define Z_SET_ISREF_P (pz ) (pz)->is_ref = 1
11- # define Z_UNSET_ISREF_P (pz ) (pz)->is_ref = 0
12- #endif
13-
148#define MSGPACK_CONVERT_COPY_ZVAL (_pz , _ppz ) \
15- ALLOC_INIT_ZVAL(_pz); \
16- *(_pz) = **(_ppz); \
17- if (PZVAL_IS_REF(*(_ppz))) { \
18- if (Z_REFCOUNT_P(*(_ppz)) > 0) { \
19- zval_copy_ctor(_pz); \
20- } else { \
21- FREE_ZVAL(*(_ppz)); \
22- } \
23- INIT_PZVAL(_pz); \
24- Z_SET_ISREF_P(_pz); \
25- } else { \
26- zval_copy_ctor(_pz); \
27- INIT_PZVAL(_pz); \
28- }
9+ // ALLOC_INIT_ZVAL(_pz); \
10+ // *(_pz) = **(_ppz); \
11+ // if (PZVAL_IS_REF(*(_ppz))) { \
12+ // if (Z_REFCOUNT_P(*(_ppz)) > 0) { \
13+ // zval_copy_ctor(_pz); \
14+ // } else { \
15+ // FREE_ZVAL(*(_ppz)); \
16+ // } \
17+ // INIT_PZVAL(_pz); \
18+ // Z_SET_ISREF_P(_pz); \
19+ // } else { \
20+ // zval_copy_ctor(_pz); \
21+ // INIT_PZVAL(_pz); \
22+ // }
2923
3024#define MSGPACK_CONVERT_UPDATE_PROPERTY (_ht , _key , _val , _var ) \
3125 if ((val = zend_symtable_update(_ht, _key, _val)) != NULL) { \
3630static inline int msgpack_convert_long_to_properties (HashTable * ht , HashTable * * properties ,
3731 uint key_index , zval * val , HashTable * var )
3832{
39- TSRMLS_FETCH ();
40-
41- if (* properties != NULL )
42- {
33+ if (* properties != NULL ) {
4334 zend_string * key_str ;
4435 ulong key_long ;
4536 zval * data ;
@@ -49,8 +40,7 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, HashTable **
4940
5041 ZEND_HASH_FOREACH_KEY_VAL (ht , key_long , key_str , data ) {
5142 if (key_str ) {
52- switch (Z_TYPE_P (data ))
53- {
43+ switch (Z_TYPE_P (data )) {
5444 case IS_ARRAY :
5545 {
5646 HashTable * dataht ;
@@ -78,7 +68,7 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, HashTable **
7868 return FAILURE ;
7969 }
8070 default :
81- return (zend_symtable_update (ht , key_str , tplval ) != NULL );
71+ return (zend_symtable_update (ht , key_str , val ) != NULL );
8272 }
8373 }
8474 } ZEND_HASH_FOREACH_END ();
@@ -275,7 +265,7 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval **value)
275265 continue ;
276266 } else if (key_long ) {
277267 zval * aryval , * rv ;
278- // MSGPACK_CONVERT_COPY_ZVAL(aryval, data);
268+ MSGPACK_CONVERT_COPY_ZVAL (aryval , data );
279269 if (convert_function )
280270 {
281271 if (convert_function (rv , data , & aryval ) != SUCCESS )
@@ -332,12 +322,11 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval **value)
332322}
333323int msgpack_convert_object (zval * return_value , zval * tpl , zval * * value ) {
334324 zend_class_entry * ce ;
335- TSRMLS_FETCH ();
336325
337- switch (Z_TYPE_P (tpl ))
338- {
326+ switch (Z_TYPE_P (tpl )) {
339327 case IS_STRING :
340- if ((ce = zend_lookup_class (zend_string_init ( Z_STRVAL_P (tpl ), Z_STRLEN_P (tpl ), 0 ))) != SUCCESS ) {
328+
329+ if ((ce = zend_lookup_class (zval_get_string (tpl ))) == NULL ) {
341330 MSGPACK_ERROR ("[msgpack] (%s) Class '%s' not found" ,
342331 __FUNCTION__ , Z_STRVAL_P (tpl ));
343332 return FAILURE ;
@@ -352,7 +341,7 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) {
352341 return FAILURE ;
353342 }
354343
355- if (Z_TYPE_PP ( value ) == IS_OBJECT ) {
344+ if (Z_TYPE_P ( * value ) == IS_OBJECT ) {
356345 zend_class_entry * vce ;
357346
358347 vce = Z_OBJ_P (tpl )-> ce ;
@@ -368,13 +357,8 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) {
368357 object_init_ex (return_value , ce );
369358
370359 /* Run the constructor if there is one */
371- if (ce -> constructor
372- && (ce -> constructor -> common .fn_flags & ZEND_ACC_PUBLIC ))
373- {
374- zval * retval_ptr = NULL ;
375- zval * params = NULL ;
376- zval function_name ;
377- int num_args = 0 ;
360+ if (ce -> constructor && (ce -> constructor -> common .fn_flags & ZEND_ACC_PUBLIC )) {
361+ zval retval , params , function_name ;
378362 zend_fcall_info fci ;
379363 zend_fcall_info_cache fcc ;
380364
@@ -383,39 +367,27 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) {
383367 fci .function_name = function_name ;
384368 fci .symbol_table = NULL ;
385369 fci .object = Z_OBJ_P (return_value );
386- fci .retval = retval_ptr ;
387- fci .param_count = num_args ;
388- fci .params = params ;
370+ fci .retval = & retval ;
371+ fci .param_count = 0 ;
372+ fci .params = & params ;
389373 fci .no_separation = 1 ;
390374
391375 fcc .initialized = 1 ;
392376 fcc .function_handler = ce -> constructor ;
393377 fcc .calling_scope = EG (scope );
394378 fcc .called_scope = Z_OBJCE_P (return_value );
379+ fcc .object = Z_OBJ_P (return_value );
395380
396381 if (zend_call_function (& fci , & fcc TSRMLS_CC ) == FAILURE ) {
397- if (params ) {
398- efree (params );
399- }
400- if (retval_ptr ) {
401- zval_ptr_dtor (retval_ptr );
402- }
403-
404382 MSGPACK_WARNING (
405383 "[msgpack] (%s) Invocation of %s's constructor failed" ,
406384 __FUNCTION__ , ce -> name );
407385
408386 return FAILURE ;
409387 }
410- if (retval_ptr ) {
411- zval_ptr_dtor (retval_ptr );
412- }
413- if (params ) {
414- efree (params );
415- }
416388 }
417389
418- switch (Z_TYPE_PP ( value ))
390+ switch (Z_TYPE_P ( * value ))
419391 {
420392 case IS_ARRAY :
421393 {
@@ -472,10 +444,10 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) {
472444 continue ;
473445 }
474446 if (num_key ) {
475- zval * val ;
476- MSGPACK_CONVERT_COPY_ZVAL (val , & data );
477- if (msgpack_convert_long_to_properties (ret , & properties , num_key , val , var ) != SUCCESS ) {
478- zval_ptr_dtor (val );
447+ zval val ;
448+ // MSGPACK_CONVERT_COPY_ZVAL(val, &data);
449+ if (msgpack_convert_long_to_properties (ret , & properties , num_key , & val , var ) != SUCCESS ) {
450+ zval_ptr_dtor (& val );
479451 MSGPACK_WARNING (
480452 "[msgpack] (%s) "
481453 "illegal offset type, skip this decoding" ,
@@ -497,20 +469,18 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) {
497469 } else {
498470 HashPosition valpos ;
499471 int (* convert_function )(zval * , zval * , zval * * ) = NULL ;
500- zval * * arydata , * aryval ;
472+ zval * * arydata , aryval , * aryval_p ;
473+ aryval_p = & aryval ;
501474
502475 ZEND_HASH_FOREACH_KEY_VAL (ret , num_key , str_key , data ) {
503-
504- if (!num_key && !str_key ) {
505- break ;
506- } if (!data ) {
476+ if (!data ) {
507477 MSGPACK_WARNING (
508478 "[msgpack] (%s) can't get data value by index" ,
509479 __FUNCTION__ );
510480 return FAILURE ;
511481 }
512482
513- switch (Z_TYPE_PP (data ))
483+ switch (Z_TYPE_P (data ))
514484 {
515485 case IS_ARRAY :
516486 convert_function = msgpack_convert_array ;
@@ -527,21 +497,20 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) {
527497 MSGPACK_CONVERT_COPY_ZVAL (aryval , & data );
528498
529499 if (convert_function ) {
530- zval * rv ;
531- ALLOC_INIT_ZVAL (rv );
500+ zval rv ;
532501
533- if (convert_function (rv , data , & aryval ) != SUCCESS ) {
534- zval_ptr_dtor (aryval );
502+ if (convert_function (& rv , data , & aryval_p ) != SUCCESS ) {
503+ zval_ptr_dtor (& aryval );
535504 MSGPACK_WARNING (
536505 "[msgpack] (%s) "
537506 "convert failure in convert_object" ,
538507 __FUNCTION__ );
539508 return FAILURE ;
540509 }
541510
542- zend_symtable_update ( ret , str_key , rv );
511+ zend_symtable_update (ret , str_key , & rv );
543512 } else {
544- zend_symtable_update (ret , str_key , aryval );
513+ zend_symtable_update (ret , str_key , & aryval );
545514 }
546515 } ZEND_HASH_FOREACH_END ();
547516
@@ -575,8 +544,6 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval **value) {
575544
576545int msgpack_convert_template (zval * return_value , zval * tpl , zval * * value )
577546{
578- TSRMLS_FETCH ();
579-
580547 switch (Z_TYPE_P (tpl ))
581548 {
582549 case IS_ARRAY :
0 commit comments