aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/ext
diff options
context:
space:
mode:
authorGravatar Paul Yang <TeBoring@users.noreply.github.com>2016-10-11 10:36:25 -0700
committerGravatar GitHub <noreply@github.com>2016-10-11 10:36:25 -0700
commit60d95f36c0081a03b947c2b625c10841bb19736c (patch)
tree18a505eb1da4f6072afb9344af72880f0d789d3a /php/ext
parent0321baf9e855a2b664436605c7067f348e1d7284 (diff)
Fix the bug that message without namespace is not found in the descriptor pool. (#2240)
Diffstat (limited to 'php/ext')
-rw-r--r--php/ext/google/protobuf/def.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c
index 156eca07..5a8c3c25 100644
--- a/php/ext/google/protobuf/def.c
+++ b/php/ext/google/protobuf/def.c
@@ -250,28 +250,36 @@ PHP_METHOD(DescriptorPool, getGeneratedPool) {
RETURN_ZVAL(generated_pool_php, 1, 0);
}
-static void convert_to_class_name_inplace(char *proto_name,
- size_t pkg_name_len) {
+static void convert_to_class_name_inplace(char *class_name,
+ const char* fullname,
+ const char* package_name) {
size_t i;
bool first_char = false;
-
- for (i = 0; i <= pkg_name_len + 1; i++) {
- // PHP package uses camel case.
- if (!first_char && proto_name[i] != '.') {
- first_char = true;
- proto_name[i] += 'A' - 'a';
- }
- // php packages are divided by '\'.
- if (proto_name[i] == '.') {
- first_char = false;
- proto_name[i] = '\\';
+ size_t pkg_name_len = package_name == NULL ? 0 : strlen(package_name);
+
+ if (pkg_name_len == 0) {
+ strcpy(class_name, fullname);
+ } else {
+ class_name[0] = '.';
+ strcpy(&class_name[1], fullname);
+ for (i = 0; i <= pkg_name_len + 1; i++) {
+ // PHP package uses camel case.
+ if (!first_char && class_name[i] != '.') {
+ first_char = true;
+ class_name[i] += 'A' - 'a';
+ }
+ // php packages are divided by '\'.
+ if (class_name[i] == '.') {
+ first_char = false;
+ class_name[i] = '\\';
+ }
}
}
// Submessage is concatenated with its containing messages by '_'.
- for (i = pkg_name_len; i < strlen(proto_name); i++) {
- if (proto_name[i] == '.') {
- proto_name[i] = '_';
+ for (i = pkg_name_len; i < strlen(class_name); i++) {
+ if (class_name[i] == '.') {
+ class_name[i] = '_';
}
}
}
@@ -325,10 +333,8 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) {
/* Prepend '.' to package name to make it absolute. */ \
const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \
char *klass_name = ecalloc(sizeof(char), 2 + strlen(fullname)); \
- klass_name[0] = '.'; \
- strcpy(&klass_name[1], fullname); \
- size_t pkg_name_len = strlen(upb_filedef_package(files[0])); \
- convert_to_class_name_inplace(klass_name, pkg_name_len); \
+ convert_to_class_name_inplace(klass_name, fullname, \
+ upb_filedef_package(files[0])); \
zend_class_entry **pce; \
if (zend_lookup_class(klass_name, strlen(klass_name), &pce TSRMLS_CC) == \
FAILURE) { \