diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2016-11-16 11:07:43 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-16 11:07:43 -0800 |
commit | 99564c3347223b92e49bd40f37b8c0d6fc6a3971 (patch) | |
tree | 4f5de7e413798a02a9a66847560de13c973090d1 /php/ext | |
parent | fc27ead10719f768eb990accac434f48efe10d16 (diff) | |
download | protobuf-99564c3347223b92e49bd40f37b8c0d6fc6a3971.tar.gz protobuf-99564c3347223b92e49bd40f37b8c0d6fc6a3971.tar.bz2 protobuf-99564c3347223b92e49bd40f37b8c0d6fc6a3971.zip |
Rename Empty to GPBEmpty in php generated file.
In php, class name cannot be "Empty". Modified code generator to (#2375) generate GPBEmpty instead (for google.protobuf.Empty only). Also change
runtime code to work with the new generated code accordingly.
Diffstat (limited to 'php/ext')
-rw-r--r-- | php/ext/google/protobuf/def.c | 11 | ||||
-rw-r--r-- | php/ext/google/protobuf/message.c | 4 |
2 files changed, 11 insertions, 4 deletions
diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 5a8c3c25..6ea2cc93 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -257,6 +257,11 @@ static void convert_to_class_name_inplace(char *class_name, bool first_char = false; size_t pkg_name_len = package_name == NULL ? 0 : strlen(package_name); + // In php, class name cannot be Empty. + if (strcmp("google.protobuf.Empty", fullname) == 0) { + fullname = "google.protobuf.GPBEmpty"; + } + if (pkg_name_len == 0) { strcpy(class_name, fullname); } else { @@ -330,9 +335,11 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { upb_msgdef_mapentry(upb_downcast_msgdef(def))) { \ break; \ } \ - /* Prepend '.' to package name to make it absolute. */ \ + /* Prepend '.' to package name to make it absolute. In the 5 additional \ + * bytes allocated, one for '.', one for trailing 0, and 3 for 'GPB' if \ + * given message is google.protobuf.Empty.*/ \ const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \ - char *klass_name = ecalloc(sizeof(char), 2 + strlen(fullname)); \ + char *klass_name = ecalloc(sizeof(char), 5 + strlen(fullname)); \ convert_to_class_name_inplace(klass_name, fullname, \ upb_filedef_package(files[0])); \ zend_class_entry **pce; \ diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index cb46031e..d8fbbe11 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -177,8 +177,8 @@ static zend_object_value message_create(zend_class_entry* ce TSRMLS_DC) { zend_object_std_init(&msg->std, ce TSRMLS_CC); object_properties_init(&msg->std, ce); - layout_init(desc->layout, message_data(msg), msg->std.properties_table - TSRMLS_CC); + layout_init(desc->layout, message_data(msg), + msg->std.properties_table TSRMLS_CC); return_value.handle = zend_objects_store_put( msg, (zend_objects_store_dtor_t)zend_objects_destroy_object, message_free, |