Skip to content

Commit 3b354d9

Browse files
committed
PHP 8.1 support
1 parent e1ab5ef commit 3b354d9

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

protobuf.c

+18-10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
*int64_out_p = (int64_t)Z_LVAL_P(zval); \
5656
}
5757

58+
59+
60+
5861
enum
5962
{
6063
PB_TYPE_DOUBLE = 1,
@@ -89,11 +92,9 @@ static int pb_is_field_packed(zval *field_descriptor);
8992

9093
PHP_METHOD(ProtobufMessage, __construct)
9194
{
92-
zval values;
93-
array_init(&values);
94-
95-
add_property_zval(getThis(), PB_VALUES_PROPERTY, &values);
96-
zval_ptr_dtor(&values);
95+
zval values_array;
96+
array_init(&values_array);
97+
zend_update_property(pb_entry, getThis(), PB_VALUES_PROPERTY, sizeof(PB_VALUES_PROPERTY) - 1, &values_array);
9798
}
9899

99100
PHP_METHOD(ProtobufMessage, append)
@@ -703,6 +704,8 @@ PHP_MINIT_FUNCTION(protobuf)
703704

704705
INIT_CLASS_ENTRY(ce, "ProtobufMessage", pb_methods);
705706
pb_entry = zend_register_internal_class(&ce TSRMLS_CC);
707+
708+
zend_declare_property_null(pb_entry, PB_VALUES_PROPERTY, sizeof(PB_VALUES_PROPERTY) - 1, ZEND_ACC_PUBLIC);
706709

707710
PB_CONSTANT(PB_TYPE_DOUBLE);
708711
PB_CONSTANT(PB_TYPE_FIXED32);
@@ -929,7 +932,7 @@ static int pb_get_field_descriptors(zval *this, zval* return_value)
929932
TSRMLS_FETCH();
930933

931934
ZVAL_STRINGL(&method, PB_FIELDS_METHOD, sizeof(PB_FIELDS_METHOD) - 1);
932-
if (call_user_function_impl(NULL, this, &method, &descriptors, 0, NULL, 0, NULL TSRMLS_CC) == FAILURE) {
935+
if (call_user_function(NULL, this, &method, &descriptors, 0, NULL) == FAILURE) {
933936
return -1;
934937
}
935938
*return_value = descriptors;
@@ -1041,11 +1044,16 @@ static zval *pb_get_value(zval *this, zval *values, zend_ulong field_number)
10411044

10421045
static zval *pb_get_values(zval *this)
10431046
{
1044-
zval *values = NULL;
1045-
TSRMLS_FETCH();
1047+
zend_class_entry *ce = Z_OBJCE_P(this);
1048+
1049+
zend_property_info *property_info;
1050+
if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, PB_VALUES_PROPERTY, strlen(PB_VALUES_PROPERTY))) == NULL) {
1051+
return NULL;
1052+
}
1053+
1054+
zval *property = (zval *)((char *)Z_OBJ_P(this) + property_info->offset);
10461055

1047-
values = zend_hash_str_find(Z_OBJPROP_P(this), PB_VALUES_PROPERTY, sizeof(PB_VALUES_PROPERTY) - 1);
1048-
return values;
1056+
return property;
10491057
}
10501058

10511059
static int pb_parse_field_value(zval *this, reader_t *reader, zend_ulong field_number, zend_long field_type, zval *value)

protobuf.h

+31
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@
66
#define PB_FOREACH(iter, hash) \
77
for (zend_hash_internal_pointer_reset_ex((hash), (iter)); zend_hash_has_more_elements_ex((hash), (iter)) == SUCCESS; zend_hash_move_forward_ex((hash), (iter)))
88

9+
#ifndef convert_to_explicit_type
10+
#define convert_to_explicit_type(pzv, type) \
11+
do { \
12+
switch (type) { \
13+
case IS_NULL: \
14+
convert_to_null(pzv); \
15+
break; \
16+
case IS_LONG: \
17+
convert_to_long(pzv); \
18+
break; \
19+
case IS_DOUBLE: \
20+
convert_to_double(pzv); \
21+
break; \
22+
case _IS_BOOL: \
23+
convert_to_boolean(pzv); \
24+
break; \
25+
case IS_ARRAY: \
26+
convert_to_array(pzv); \
27+
break; \
28+
case IS_OBJECT: \
29+
convert_to_object(pzv); \
30+
break; \
31+
case IS_STRING: \
32+
convert_to_string(pzv); \
33+
break; \
34+
default: \
35+
assert(0); \
36+
break; \
37+
} \
38+
} while (0);
39+
#endif
940

1041
#if ZEND_MODULE_API_NO >= 20190128
1142
#ifndef TSRMLS_CC

0 commit comments

Comments
 (0)