Skip to content

Commit 22503a0

Browse files
authored
fix for API change in PHP 7.3 (#4898)
1 parent e529d16 commit 22503a0

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed

php/ext/google/protobuf/def.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ PHP_METHOD(Descriptor, getField) {
253253
#else
254254
field_hashtable_value =
255255
field_descriptor_type->create_object(field_descriptor_type TSRMLS_CC);
256-
--GC_REFCOUNT(field_hashtable_value);
256+
GC_DELREF(field_hashtable_value);
257257
#endif
258258
FieldDescriptor *field_php =
259259
UNBOX_HASHTABLE_VALUE(FieldDescriptor, field_hashtable_value);
@@ -264,7 +264,7 @@ PHP_METHOD(Descriptor, getField) {
264264
#if PHP_MAJOR_VERSION < 7
265265
RETURN_ZVAL(field_hashtable_value, 1, 0);
266266
#else
267-
++GC_REFCOUNT(field_hashtable_value);
267+
GC_ADDREF(field_hashtable_value);
268268
RETURN_OBJ(field_hashtable_value);
269269
#endif
270270
}
@@ -492,7 +492,7 @@ PHP_METHOD(FieldDescriptor, getEnumType) {
492492
#if PHP_MAJOR_VERSION < 7
493493
RETURN_ZVAL(desc, 1, 0);
494494
#else
495-
++GC_REFCOUNT(desc);
495+
GC_ADDREF(desc);
496496
RETURN_OBJ(desc);
497497
#endif
498498
}
@@ -512,7 +512,7 @@ PHP_METHOD(FieldDescriptor, getMessageType) {
512512
#if PHP_MAJOR_VERSION < 7
513513
RETURN_ZVAL(desc, 1, 0);
514514
#else
515-
++GC_REFCOUNT(desc);
515+
GC_ADDREF(desc);
516516
RETURN_OBJ(desc);
517517
#endif
518518
}
@@ -585,7 +585,7 @@ PHP_METHOD(Oneof, getField) {
585585
#if PHP_MAJOR_VERSION < 7
586586
RETURN_ZVAL(field_hashtable_value, 1, 0);
587587
#else
588-
++GC_REFCOUNT(field_hashtable_value);
588+
GC_ADDREF(field_hashtable_value);
589589
RETURN_OBJ(field_hashtable_value);
590590
#endif
591591
}
@@ -703,7 +703,7 @@ PHP_METHOD(DescriptorPool, getGeneratedPool) {
703703
#if PHP_MAJOR_VERSION < 7
704704
RETURN_ZVAL(generated_pool_php, 1, 0);
705705
#else
706-
++GC_REFCOUNT(generated_pool_php);
706+
GC_ADDREF(generated_pool_php);
707707
RETURN_OBJ(generated_pool_php);
708708
#endif
709709
}
@@ -713,7 +713,7 @@ PHP_METHOD(InternalDescriptorPool, getGeneratedPool) {
713713
#if PHP_MAJOR_VERSION < 7
714714
RETURN_ZVAL(internal_generated_pool_php, 1, 0);
715715
#else
716-
++GC_REFCOUNT(internal_generated_pool_php);
716+
GC_ADDREF(internal_generated_pool_php);
717717
RETURN_OBJ(internal_generated_pool_php);
718718
#endif
719719
}
@@ -1033,7 +1033,7 @@ PHP_METHOD(DescriptorPool, getDescriptorByClassName) {
10331033
#if PHP_MAJOR_VERSION < 7
10341034
RETURN_ZVAL(desc, 1, 0);
10351035
#else
1036-
++GC_REFCOUNT(desc);
1036+
GC_ADDREF(desc);
10371037
RETURN_OBJ(desc);
10381038
#endif
10391039
}
@@ -1070,7 +1070,7 @@ PHP_METHOD(DescriptorPool, getEnumDescriptorByClassName) {
10701070
#if PHP_MAJOR_VERSION < 7
10711071
RETURN_ZVAL(desc, 1, 0);
10721072
#else
1073-
++GC_REFCOUNT(desc);
1073+
GC_ADDREF(desc);
10741074
RETURN_OBJ(desc);
10751075
#endif
10761076
}

php/ext/google/protobuf/encode_decode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static void map_slot_value(upb_fieldtype_t type, const void* from,
577577
break;
578578
case UPB_TYPE_MESSAGE:
579579
*(zend_object**)to = Z_OBJ_P(*(zval**)from);
580-
++GC_REFCOUNT(*(zend_object**)to);
580+
GC_ADDREF(*(zend_object**)to);
581581
break;
582582
#endif
583583
default:

php/ext/google/protobuf/map.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ static inline void php_proto_map_string_release(void *value) {
192192
}
193193
static inline void php_proto_map_object_release(void *value) {
194194
zend_object* object = *(zend_object**)value;
195-
if(--GC_REFCOUNT(object) == 0) {
195+
GC_DELREF(object);
196+
if(GC_REFCOUNT(object) == 0) {
196197
zend_objects_store_del(object);
197198
}
198199
}
@@ -302,7 +303,8 @@ static bool map_index_unset(Map *intern, const char* keyval, int length) {
302303
zval_ptr_dtor(upb_value_memory(&old_value));
303304
#else
304305
zend_object* object = *(zend_object**)upb_value_memory(&old_value);
305-
if(--GC_REFCOUNT(object) == 0) {
306+
GC_DELREF(object);
307+
if(GC_REFCOUNT(object) == 0) {
306308
zend_objects_store_del(object);
307309
}
308310
#endif

php/ext/google/protobuf/message.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,11 @@ PHP_PROTO_INIT_ENUMCLASS_START("Google\\Protobuf\\Field\\Cardinality",
869869
zend_declare_class_constant_long(field_cardinality_type,
870870
"CARDINALITY_REPEATED", 20, 3 TSRMLS_CC);
871871
const char *alias = "Google\\Protobuf\\Field_Cardinality";
872+
#if PHP_VERSION_ID < 70300
872873
zend_register_class_alias_ex(alias, strlen(alias), field_cardinality_type TSRMLS_CC);
874+
#else
875+
zend_register_class_alias_ex(alias, strlen(alias), field_cardinality_type, 1);
876+
#endif
873877
PHP_PROTO_INIT_ENUMCLASS_END
874878

875879
// -----------------------------------------------------------------------------
@@ -924,7 +928,11 @@ PHP_PROTO_INIT_ENUMCLASS_START("Google\\Protobuf\\Field\\Kind",
924928
zend_declare_class_constant_long(field_kind_type,
925929
"TYPE_SINT64", 11, 18 TSRMLS_CC);
926930
const char *alias = "Google\\Protobuf\\Field_Kind";
931+
#if PHP_VERSION_ID < 70300
927932
zend_register_class_alias_ex(alias, strlen(alias), field_kind_type TSRMLS_CC);
933+
#else
934+
zend_register_class_alias_ex(alias, strlen(alias), field_kind_type, 1);
935+
#endif
928936
PHP_PROTO_INIT_ENUMCLASS_END
929937

930938
// -----------------------------------------------------------------------------

php/ext/google/protobuf/protobuf.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void add_def_obj(const void* def, PHP_PROTO_HASHTABLE_VALUE value) {
104104
#if PHP_MAJOR_VERSION < 7
105105
Z_ADDREF_P(value);
106106
#else
107-
++GC_REFCOUNT(value);
107+
GC_ADDREF(value);
108108
#endif
109109
add_to_table(upb_def_to_php_obj_map, def, value);
110110
}
@@ -117,7 +117,7 @@ void add_ce_obj(const void* ce, PHP_PROTO_HASHTABLE_VALUE value) {
117117
#if PHP_MAJOR_VERSION < 7
118118
Z_ADDREF_P(value);
119119
#else
120-
++GC_REFCOUNT(value);
120+
GC_ADDREF(value);
121121
#endif
122122
add_to_table(ce_to_php_obj_map, ce, value);
123123
}
@@ -134,7 +134,7 @@ void add_proto_obj(const char* proto, PHP_PROTO_HASHTABLE_VALUE value) {
134134
#if PHP_MAJOR_VERSION < 7
135135
Z_ADDREF_P(value);
136136
#else
137-
++GC_REFCOUNT(value);
137+
GC_ADDREF(value);
138138
#endif
139139
add_to_strtable(proto_to_php_obj_map, proto, strlen(proto), value);
140140
}
@@ -235,7 +235,8 @@ static PHP_GSHUTDOWN_FUNCTION(protobuf) {
235235
static void php_proto_hashtable_descriptor_release(zval* value) {
236236
void* ptr = Z_PTR_P(value);
237237
zend_object* object = *(zend_object**)ptr;
238-
if(--GC_REFCOUNT(object) == 0) {
238+
GC_DELREF(object);
239+
if(GC_REFCOUNT(object) == 0) {
239240
zend_objects_store_del(object);
240241
}
241242
efree(ptr);

php/ext/google/protobuf/protobuf.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
// PHP7 Wrappers
4747
// ----------------------------------------------------------------------------
4848

49+
#if PHP_VERSION_ID < 70300
50+
#define GC_ADDREF(h) ++GC_REFCOUNT(h)
51+
#define GC_DELREF(h) --GC_REFCOUNT(h)
52+
#endif
53+
4954
#if PHP_MAJOR_VERSION < 7
5055

5156
#define php_proto_zend_literal const zend_literal*
@@ -496,7 +501,7 @@ static inline int php_proto_zend_hash_get_current_data_ex(HashTable* ht,
496501
PHP_PROTO_HASHTABLE_VALUE WRAPPED_OBJ; \
497502
WRAPPED_OBJ = OBJ_CLASS_ENTRY->create_object(OBJ_CLASS_ENTRY); \
498503
OBJ = UNBOX_HASHTABLE_VALUE(OBJ_TYPE, WRAPPED_OBJ); \
499-
--GC_REFCOUNT(WRAPPED_OBJ);
504+
GC_DELREF(WRAPPED_OBJ);
500505

501506
#define PHP_PROTO_CE_DECLARE zend_class_entry*
502507
#define PHP_PROTO_CE_UNREF(ce) (ce)

php/ext/google/protobuf/storage.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ bool native_slot_set_by_array(upb_fieldtype_t type,
200200
}
201201
#else
202202
DEREF(memory, zval*) = value;
203-
++GC_REFCOUNT(Z_OBJ_P(value));
203+
GC_ADDREF(Z_OBJ_P(value));
204204
#endif
205205
break;
206206
}
@@ -251,7 +251,7 @@ bool native_slot_set_by_map(upb_fieldtype_t type, const zend_class_entry* klass,
251251
}
252252
#else
253253
DEREF(memory, zend_object*) = Z_OBJ_P(value);
254-
++GC_REFCOUNT(Z_OBJ_P(value));
254+
GC_ADDREF(Z_OBJ_P(value));
255255
#endif
256256
break;
257257
}
@@ -428,7 +428,7 @@ void native_slot_get_by_map_value(upb_fieldtype_t type, const void* memory,
428428
ZVAL_ZVAL(CACHED_PTR_TO_ZVAL_PTR(cache), value, 1, 0);
429429
}
430430
#else
431-
++GC_REFCOUNT(*(zend_object**)memory);
431+
GC_ADDREF(*(zend_object**)memory);
432432
ZVAL_OBJ(cache, *(zend_object**)memory);
433433
#endif
434434
return;

0 commit comments

Comments
 (0)