diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2017-10-11 14:44:03 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2017-10-11 14:44:03 -0700 |
commit | de15e73d5862e8ac618bc7be90594adacbaa1ec6 (patch) | |
tree | 9d1f71f76902010963e0dc28db266de22b82646d /php/ext | |
parent | c4083bb3d1231f8a94f2f000434e38528bdff64a (diff) | |
parent | bd798dfc81443cb95ff3b6e0b787c92031b113e5 (diff) | |
download | protobuf-de15e73d5862e8ac618bc7be90594adacbaa1ec6.tar.gz protobuf-de15e73d5862e8ac618bc7be90594adacbaa1ec6.tar.bz2 protobuf-de15e73d5862e8ac618bc7be90594adacbaa1ec6.zip |
Merge remote-tracking branch 'origin/3.4.x' into master
Diffstat (limited to 'php/ext')
-rw-r--r-- | php/ext/google/protobuf/def.c | 17 | ||||
-rw-r--r-- | php/ext/google/protobuf/package.xml | 24 | ||||
-rw-r--r-- | php/ext/google/protobuf/protobuf.c | 43 | ||||
-rw-r--r-- | php/ext/google/protobuf/protobuf.h | 28 |
4 files changed, 99 insertions, 13 deletions
diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 421b84e5..13f7cdd6 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -30,9 +30,6 @@ #include "protobuf.h" -const char* const kReservedNames[] = {"Empty", "ECHO", "ARRAY"}; -const int kReservedNamesSize = 3; - // Forward declare. static void descriptor_init_c_instance(Descriptor* intern TSRMLS_DC); static void descriptor_free_c(Descriptor* object TSRMLS_DC); @@ -747,12 +744,16 @@ static const char *classname_prefix(const char *classname, return prefix_given; } - for (i = 0; i < kReservedNamesSize; i++) { - if (strcmp(kReservedNames[i], classname) == 0) { - is_reserved = true; - break; - } + char* lower = ALLOC_N(char, strlen(classname) + 1); + i = 0; + while(classname[i]) { + lower[i] = (char)tolower(classname[i]); + i++; } + lower[i] = 0; + + is_reserved = is_reserved_name(lower); + FREE(lower); if (is_reserved) { if (package_name != NULL && strcmp("google.protobuf", package_name) == 0) { diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 2d318517..4a473801 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ <email>protobuf-opensource@google.com</email> <active>yes</active> </lead> - <date>2017-01-13</date> - <time>16:06:07</time> + <date>2017-09-14</date> + <time>11:02:07</time> <version> - <release>3.4.0</release> - <api>3.4.0</api> + <release>3.4.1</release> + <api>3.4.1</api> </version> <stability> <release>stable</release> @@ -152,5 +152,21 @@ GA release. GA release. </notes> </release> + <release> + <version> + <release>3.4.1</release> + <api>3.4.1</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <date>2017-09-14</date> + <time>11:02:07</time> + <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license> + <notes> +GA release. + </notes> + </release> </changelog> </package> diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index 2f394ba5..b67089e0 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -49,6 +49,7 @@ static HashTable* ce_to_php_obj_map; // Global map from message/enum's proto fully-qualified name to corresponding // wrapper Descriptor/EnumDescriptor instances. static HashTable* proto_to_php_obj_map; +static HashTable* reserved_names; // ----------------------------------------------------------------------------- // Global maps. @@ -144,6 +145,36 @@ PHP_PROTO_HASHTABLE_VALUE get_proto_obj(const char* proto) { } // ----------------------------------------------------------------------------- +// Reserved Name. +// ----------------------------------------------------------------------------- + +// Although we already have kReservedNames, we still add them to hash table to +// speed up look up. +const char *const kReservedNames[] = { + "abstract", "and", "array", "as", "break", + "callable", "case", "catch", "class", "clone", + "const", "continue", "declare", "default", "die", + "do", "echo", "else", "elseif", "empty", + "enddeclare", "endfor", "endforeach", "endif", "endswitch", + "endwhile", "eval", "exit", "extends", "final", + "for", "foreach", "function", "global", "goto", + "if", "implements", "include", "include_once", "instanceof", + "insteadof", "interface", "isset", "list", "namespace", + "new", "or", "print", "private", "protected", + "public", "require", "require_once", "return", "static", + "switch", "throw", "trait", "try", "unset", + "use", "var", "while", "xor", "int", + "float", "bool", "string", "true", "false", + "null", "void", "iterable"}; +const int kReservedNamesSize = 73; + +bool is_reserved_name(const char* name) { + void** value; + return (php_proto_zend_hash_find(reserved_names, name, strlen(name), + (void**)&value) == SUCCESS); +} + +// ----------------------------------------------------------------------------- // Utilities. // ----------------------------------------------------------------------------- @@ -190,6 +221,8 @@ static void php_proto_hashtable_descriptor_release(zval* value) { #endif static PHP_RINIT_FUNCTION(protobuf) { + int i = 0; + ALLOC_HASHTABLE(upb_def_to_php_obj_map); zend_hash_init(upb_def_to_php_obj_map, 16, NULL, HASHTABLE_VALUE_DTOR, 0); @@ -199,6 +232,13 @@ static PHP_RINIT_FUNCTION(protobuf) { ALLOC_HASHTABLE(proto_to_php_obj_map); zend_hash_init(proto_to_php_obj_map, 16, NULL, HASHTABLE_VALUE_DTOR, 0); + ALLOC_HASHTABLE(reserved_names); + zend_hash_init(reserved_names, 16, NULL, NULL, 0); + for (i = 0; i < kReservedNamesSize; i++) { + php_proto_zend_hash_update(reserved_names, kReservedNames[i], + strlen(kReservedNames[i])); + } + generated_pool = NULL; generated_pool_php = NULL; internal_generated_pool_php = NULL; @@ -216,6 +256,9 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) { zend_hash_destroy(proto_to_php_obj_map); FREE_HASHTABLE(proto_to_php_obj_map); + zend_hash_destroy(reserved_names); + FREE_HASHTABLE(reserved_names); + #if PHP_MAJOR_VERSION < 7 if (generated_pool_php != NULL) { zval_dtor(generated_pool_php); diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index c8a360d8..cb098747 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.4.0" +#define PHP_PROTOBUF_VERSION "3.4.1" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 @@ -80,6 +80,9 @@ #define php_proto_zend_hash_update_zval(ht, key, key_len, value) \ zend_hash_update(ht, key, key_len, value, sizeof(void*), NULL) +#define php_proto_zend_hash_update(ht, key, key_len) \ + zend_hash_update(ht, key, key_len, 0, 0, NULL) + #define php_proto_zend_hash_index_update_mem(ht, h, pData, nDataSize, pDest) \ zend_hash_index_update(ht, h, pData, nDataSize, pDest) @@ -90,6 +93,9 @@ #define php_proto_zend_hash_index_find_zval(ht, h, pDest) \ zend_hash_index_find(ht, h, pDest) +#define php_proto_zend_hash_find(ht, key, key_len, pDest) \ + zend_hash_find(ht, key, key_len, pDest) + #define php_proto_zend_hash_index_find_mem(ht, h, pDest) \ zend_hash_index_find(ht, h, pDest) @@ -270,6 +276,15 @@ static inline int php_proto_zend_hash_index_update_zval(HashTable* ht, ulong h, return result != NULL ? SUCCESS : FAILURE; } +static inline int php_proto_zend_hash_update(HashTable* ht, const char* key, + size_t key_len) { + void* result = NULL; + zval temp; + ZVAL_LONG(&temp, 0); + result = zend_hash_str_update(ht, key, key_len, &temp); + return result != NULL ? SUCCESS : FAILURE; +} + static inline int php_proto_zend_hash_index_update_mem(HashTable* ht, ulong h, void* pData, uint nDataSize, void** pDest) { @@ -303,6 +318,13 @@ static inline int php_proto_zend_hash_index_find_zval(const HashTable* ht, return result != NULL ? SUCCESS : FAILURE; } +static inline int php_proto_zend_hash_find(const HashTable* ht, const char* key, + size_t key_len, void** pDest) { + void* result = NULL; + result = zend_hash_str_find(ht, key, key_len); + return result != NULL ? SUCCESS : FAILURE; +} + static inline int php_proto_zend_hash_index_find_mem(const HashTable* ht, ulong h, void** pDest) { void* result = NULL; @@ -1413,4 +1435,8 @@ static inline zval* php_proto_message_read_property( #endif } +// Reserved name +bool is_reserved_name(const char* name); +bool is_valid_constant_name(const char* name); + #endif // __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__ |