Skip to content

Commit

Permalink
Port php c extension for php8
Browse files Browse the repository at this point in the history
  • Loading branch information
TeBoring committed Nov 30, 2020
1 parent 51b2c4d commit f8b032f
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 271 deletions.
7 changes: 4 additions & 3 deletions php/ext/google/protobuf/array.c
Expand Up @@ -453,9 +453,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()

static zend_function_entry repeated_field_methods[] = {
PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC)
Expand Down Expand Up @@ -636,7 +633,11 @@ void Array_ModuleInit() {
h = &RepeatedField_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = RepeatedField_destructor;
#if PHP_VERSION_ID < 80000
h->compare_objects = RepeatedField_compare_objects;
#else
h->compare = RepeatedField_compare_objects;
#endif
h->get_properties = RepeatedField_GetProperties;
h->get_property_ptr_ptr = RepeatedField_GetPropertyPtrPtr;

Expand Down
61 changes: 33 additions & 28 deletions php/ext/google/protobuf/def.c
Expand Up @@ -103,8 +103,8 @@ PHP_METHOD(EnumValueDescriptor, getNumber) {
}

static zend_function_entry EnumValueDescriptor_methods[] = {
PHP_ME(EnumValueDescriptor, getName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(EnumValueDescriptor, getNumber, NULL, ZEND_ACC_PUBLIC)
PHP_ME(EnumValueDescriptor, getName, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(EnumValueDescriptor, getNumber, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

Expand Down Expand Up @@ -224,9 +224,9 @@ PHP_METHOD(EnumDescriptor, getPublicDescriptor) {
}

static zend_function_entry EnumDescriptor_methods[] = {
PHP_ME(EnumDescriptor, getPublicDescriptor, NULL, ZEND_ACC_PUBLIC)
PHP_ME(EnumDescriptor, getValueCount, NULL, ZEND_ACC_PUBLIC)
PHP_ME(EnumDescriptor, getValue, NULL, ZEND_ACC_PUBLIC)
PHP_ME(EnumDescriptor, getPublicDescriptor, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(EnumDescriptor, getValueCount, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(EnumDescriptor, getValue, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

Expand Down Expand Up @@ -316,9 +316,9 @@ PHP_METHOD(OneofDescriptor, getFieldCount) {
}

static zend_function_entry OneofDescriptor_methods[] = {
PHP_ME(OneofDescriptor, getName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(OneofDescriptor, getField, NULL, ZEND_ACC_PUBLIC)
PHP_ME(OneofDescriptor, getFieldCount, NULL, ZEND_ACC_PUBLIC)
PHP_ME(OneofDescriptor, getName, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(OneofDescriptor, getField, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(OneofDescriptor, getFieldCount, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

Expand Down Expand Up @@ -480,13 +480,13 @@ PHP_METHOD(FieldDescriptor, getMessageType) {
}

static zend_function_entry FieldDescriptor_methods[] = {
PHP_ME(FieldDescriptor, getName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getNumber, NULL, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getLabel, NULL, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getType, NULL, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, isMap, NULL, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getEnumType, NULL, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getMessageType, NULL, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getName, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getNumber, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getLabel, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getType, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, isMap, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getEnumType, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(FieldDescriptor, getMessageType, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

Expand Down Expand Up @@ -700,13 +700,13 @@ PHP_METHOD(Descriptor, getClass) {


static zend_function_entry Descriptor_methods[] = {
PHP_ME(Descriptor, getClass, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getFullName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getField, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getFieldCount, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getOneofDecl, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getOneofDeclCount, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getPublicDescriptor, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getClass, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getFullName, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getField, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getFieldCount, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getOneofDecl, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getOneofDeclCount, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Descriptor, getPublicDescriptor, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

Expand Down Expand Up @@ -1000,13 +1000,18 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) {
upb_arena_free(arena);
}

ZEND_BEGIN_ARG_INFO_EX(arginfo_addgeneratedfile, 0, 0, 2)
ZEND_ARG_INFO(0, data)
ZEND_ARG_INFO(0, data_len)
ZEND_END_ARG_INFO()

static zend_function_entry DescriptorPool_methods[] = {
PHP_ME(DescriptorPool, getGeneratedPool, NULL,
PHP_ME(DescriptorPool, getGeneratedPool, arginfo_void,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(DescriptorPool, getDescriptorByClassName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(DescriptorPool, getDescriptorByProtoName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(DescriptorPool, getEnumDescriptorByClassName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(DescriptorPool, internalAddGeneratedFile, NULL, ZEND_ACC_PUBLIC)
PHP_ME(DescriptorPool, getDescriptorByClassName, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(DescriptorPool, getDescriptorByProtoName, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(DescriptorPool, getEnumDescriptorByClassName, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(DescriptorPool, internalAddGeneratedFile, arginfo_addgeneratedfile, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

Expand Down Expand Up @@ -1034,7 +1039,7 @@ PHP_METHOD(InternalDescriptorPool, getGeneratedPool) {
}

static zend_function_entry InternalDescriptorPool_methods[] = {
PHP_ME(InternalDescriptorPool, getGeneratedPool, NULL,
PHP_ME(InternalDescriptorPool, getGeneratedPool, arginfo_void,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_FE_END
};
Expand Down
7 changes: 4 additions & 3 deletions php/ext/google/protobuf/map.c
Expand Up @@ -437,9 +437,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()

static zend_function_entry MapField_methods[] = {
PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
Expand Down Expand Up @@ -622,7 +619,11 @@ void Map_ModuleInit() {
h = &MapField_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = MapField_destructor;
#if PHP_VERSION_ID < 80000
h->compare_objects = MapField_compare_objects;
#else
h->compare = MapField_compare_objects;
#endif
h->get_properties = Map_GetProperties;
h->get_property_ptr_ptr = Map_GetPropertyPtrPtr;

Expand Down
17 changes: 9 additions & 8 deletions php/ext/google/protobuf/message.c
Expand Up @@ -1021,9 +1021,6 @@ PHP_METHOD(Message, writeOneof) {
upb_msg_set(intern->msg, f, msgval, arena);
}

ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mergeFrom, 0, 0, 1)
ZEND_ARG_INFO(0, data)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -1106,7 +1103,7 @@ PHP_METHOD(google_protobuf_Any, unpack) {
if (!TryStripUrlPrefix(&type_url)) {
zend_throw_exception(
NULL, "Type url needs to be type.googleapis.com/fully-qualified",
0 TSRMLS_CC);
0);
return;
}

Expand All @@ -1115,7 +1112,7 @@ PHP_METHOD(google_protobuf_Any, unpack) {
if (m == NULL) {
zend_throw_exception(
NULL, "Specified message in any hasn't been added to descriptor pool",
0 TSRMLS_CC);
0);
return;
}

Expand Down Expand Up @@ -1149,7 +1146,7 @@ PHP_METHOD(google_protobuf_Any, pack) {
const char *full_name;
char *buf;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &val) ==
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &val) ==
FAILURE) {
return;
}
Expand Down Expand Up @@ -1182,7 +1179,7 @@ PHP_METHOD(google_protobuf_Any, is) {
zend_class_entry *klass = NULL;
const upb_msgdef *m;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "C", &klass) ==
if (zend_parse_parameters(ZEND_NUM_ARGS(), "C", &klass) ==
FAILURE) {
return;
}
Expand All @@ -1209,7 +1206,7 @@ PHP_METHOD(google_protobuf_Timestamp, fromDateTime) {
return;
}

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &datetime,
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &datetime,
date_interface_ce) == FAILURE) {
zend_error(E_USER_ERROR, "Expect DatetimeInterface.");
return;
Expand Down Expand Up @@ -1326,7 +1323,11 @@ void Message_ModuleInit() {

memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = Message_dtor;
#if PHP_VERSION_ID < 80000
h->compare_objects = Message_compare_objects;
#else
h->compare = Message_compare_objects;
#endif
h->read_property = Message_read_property;
h->write_property = Message_write_property;
h->has_property = Message_has_property;
Expand Down
7 changes: 7 additions & 0 deletions php/ext/google/protobuf/protobuf.h
Expand Up @@ -69,6 +69,13 @@ const zval *get_generated_pool();
#define PROTO_STRLEN_P(obj) ZSTR_LEN(obj)
#endif

ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

#define PHP_PROTOBUF_VERSION "3.14.0"

// ptr -> PHP object cache. This is a weak map that caches lazily-created
Expand Down

0 comments on commit f8b032f

Please sign in to comment.