@@ -57,10 +57,6 @@ typedef unsigned long long uint64_t;
5757#error Unknown __BYTE_ORDER
5858#endif
5959
60- #ifndef Z_ADDREF_P
61- #define Z_ADDREF_P ZVAL_ADDREF
62- #endif
63-
6460enum TType {
6561 T_STOP = 0 ,
6662 T_VOID = 1 ,
@@ -768,7 +764,6 @@ void binary_deserialize_spec(zval* zthis, PHPInputTransport& transport, HashTabl
768764}
769765
770766void binary_serialize (int8_t thrift_typeID, PHPOutputTransport& transport, zval** value, HashTable* fieldspec) {
771- Z_ADDREF_P (*value);
772767 // At this point the typeID (and field num, if applicable) should've already been written to the output so all we need to do is write the payload.
773768 switch (thrift_typeID) {
774769 case T_STOP:
@@ -786,51 +781,29 @@ void binary_serialize(int8_t thrift_typeID, PHPOutputTransport& transport, zval*
786781 binary_serialize_spec (*value, transport, Z_ARRVAL_P (spec));
787782 } return ;
788783 case T_BOOL:
789- if (Z_TYPE_PP (value) != IS_BOOL) {
790- SEPARATE_ZVAL (value);
791- convert_to_boolean (*value);
792- }
784+ if (Z_TYPE_PP (value) != IS_BOOL) convert_to_boolean (*value);
793785 transport.writeI8 (Z_BVAL_PP (value) ? 1 : 0 );
794- zval_ptr_dtor (value);
795786 return ;
796787 case T_BYTE:
797- if (Z_TYPE_PP (value) != IS_LONG) {
798- SEPARATE_ZVAL (value);
799- convert_to_long (*value);
800- }
788+ if (Z_TYPE_PP (value) != IS_LONG) convert_to_long (*value);
801789 transport.writeI8 (Z_LVAL_PP (value));
802- zval_ptr_dtor (value);
803790 return ;
804791 case T_I16:
805- if (Z_TYPE_PP (value) != IS_LONG) {
806- SEPARATE_ZVAL (value);
807- convert_to_long (*value);
808- }
792+ if (Z_TYPE_PP (value) != IS_LONG) convert_to_long (*value);
809793 transport.writeI16 (Z_LVAL_PP (value));
810- zval_ptr_dtor (value);
811794 return ;
812795 case T_I32:
813- if (Z_TYPE_PP (value) != IS_LONG) {
814- SEPARATE_ZVAL (value);
815- convert_to_long (*value);
816- }
796+ if (Z_TYPE_PP (value) != IS_LONG) convert_to_long (*value);
817797 transport.writeI32 (Z_LVAL_PP (value));
818- zval_ptr_dtor (value);
819798 return ;
820799 case T_I64:
821800 case T_U64: {
822801 int64_t l_data;
823802#if defined(_LP64) || defined(_WIN64)
824- if (Z_TYPE_PP (value) != IS_LONG) {
825- SEPARATE_ZVAL (value);
826- convert_to_long (*value);
827- }
803+ if (Z_TYPE_PP (value) != IS_LONG) convert_to_long (*value);
828804 l_data = Z_LVAL_PP (value);
829805#else
830- if (Z_TYPE_PP (value) != IS_DOUBLE) {
831- SEPARATE_ZVAL (value);
832- convert_to_double (*value);
833- }
806+ if (Z_TYPE_PP (value) != IS_DOUBLE) convert_to_double (*value);
834807 l_data = (int64_t )Z_DVAL_PP (value);
835808#endif
836809 transport.writeI64 (l_data);
@@ -840,32 +813,20 @@ void binary_serialize(int8_t thrift_typeID, PHPOutputTransport& transport, zval*
840813 int64_t c;
841814 double d;
842815 } a;
843- if (Z_TYPE_PP (value) != IS_DOUBLE) {
844- SEPARATE_ZVAL (value);
845- convert_to_double (*value);
846- }
816+ if (Z_TYPE_PP (value) != IS_DOUBLE) convert_to_double (*value);
847817 a.d = Z_DVAL_PP (value);
848818 transport.writeI64 (a.c );
849- zval_ptr_dtor (value);
850819 } return ;
851820 // case T_UTF7:
852821 case T_UTF8:
853822 case T_UTF16:
854823 case T_STRING:
855- if (Z_TYPE_PP (value) != IS_STRING) {
856- SEPARATE_ZVAL (value);
857- convert_to_string (*value);
858- }
824+ if (Z_TYPE_PP (value) != IS_STRING) convert_to_string (*value);
859825 transport.writeString (Z_STRVAL_PP (value), Z_STRLEN_PP (value));
860- zval_ptr_dtor (value);
861826 return ;
862827 case T_MAP: {
828+ if (Z_TYPE_PP (value) != IS_ARRAY) convert_to_array (*value);
863829 if (Z_TYPE_PP (value) != IS_ARRAY) {
864- SEPARATE_ZVAL (value);
865- convert_to_array (*value);
866- }
867- if (Z_TYPE_PP (value) != IS_ARRAY) {
868- zval_ptr_dtor (value);
869830 throw_tprotocolexception (" Attempt to send an incompatible type as an array (T_MAP)" , INVALID_DATA);
870831 }
871832 HashTable* ht = Z_ARRVAL_PP (value);
@@ -889,15 +850,10 @@ void binary_serialize(int8_t thrift_typeID, PHPOutputTransport& transport, zval*
889850 binary_serialize_hashtable_key (keytype, transport, ht, key_ptr);
890851 binary_serialize (valtype, transport, val_ptr, valspec);
891852 }
892- zval_ptr_dtor (value);
893853 } return ;
894854 case T_LIST: {
855+ if (Z_TYPE_PP (value) != IS_ARRAY) convert_to_array (*value);
895856 if (Z_TYPE_PP (value) != IS_ARRAY) {
896- SEPARATE_ZVAL (value);
897- convert_to_array (*value);
898- }
899- if (Z_TYPE_PP (value) != IS_ARRAY) {
900- zval_ptr_dtor (value);
901857 throw_tprotocolexception (" Attempt to send an incompatible type as an array (T_LIST)" , INVALID_DATA);
902858 }
903859 HashTable* ht = Z_ARRVAL_PP (value);
@@ -916,15 +872,10 @@ void binary_serialize(int8_t thrift_typeID, PHPOutputTransport& transport, zval*
916872 for (zend_hash_internal_pointer_reset_ex (ht, &key_ptr); zend_hash_get_current_data_ex (ht, (void **)&val_ptr, &key_ptr) == SUCCESS; zend_hash_move_forward_ex (ht, &key_ptr)) {
917873 binary_serialize (valtype, transport, val_ptr, valspec);
918874 }
919- zval_ptr_dtor (value);
920875 } return ;
921876 case T_SET: {
877+ if (Z_TYPE_PP (value) != IS_ARRAY) convert_to_array (*value);
922878 if (Z_TYPE_PP (value) != IS_ARRAY) {
923- SEPARATE_ZVAL (value);
924- convert_to_array (*value);
925- }
926- if (Z_TYPE_PP (value) != IS_ARRAY) {
927- zval_ptr_dtor (value);
928879 throw_tprotocolexception (" Attempt to send an incompatible type as an array (T_SET)" , INVALID_DATA);
929880 }
930881 HashTable* ht = Z_ARRVAL_PP (value);
@@ -940,11 +891,8 @@ void binary_serialize(int8_t thrift_typeID, PHPOutputTransport& transport, zval*
940891 for (zend_hash_internal_pointer_reset_ex (ht, &key_ptr); zend_hash_get_current_data_ex (ht, (void **)&val_ptr, &key_ptr) == SUCCESS; zend_hash_move_forward_ex (ht, &key_ptr)) {
941892 binary_serialize_hashtable_key (keytype, transport, ht, key_ptr);
942893 }
943- zval_ptr_dtor (value);
944894 } return ;
945895 };
946-
947- zval_ptr_dtor (value);
948896 char errbuf[128 ];
949897 sprintf (errbuf, " Unknown thrift typeID %d" , thrift_typeID);
950898 throw_tprotocolexception (errbuf, INVALID_DATA);
0 commit comments