diff options
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | jenkins/docker/Dockerfile | 58 | ||||
-rwxr-xr-x | jenkins/pull_request_in_docker.sh | 1 | ||||
-rw-r--r-- | js/message_test.js | 14 | ||||
-rw-r--r-- | js/test.proto | 8 | ||||
-rw-r--r-- | js/test2.proto | 6 | ||||
-rw-r--r-- | php/ext/google/protobuf/array.c | 12 | ||||
-rw-r--r-- | php/ext/google/protobuf/def.c | 3 | ||||
-rw-r--r-- | php/ext/google/protobuf/encode_decode.c | 68 | ||||
-rw-r--r-- | php/ext/google/protobuf/map.c | 30 | ||||
-rw-r--r-- | php/ext/google/protobuf/message.c | 5 | ||||
-rw-r--r-- | php/ext/google/protobuf/protobuf.c | 12 | ||||
-rw-r--r-- | php/ext/google/protobuf/protobuf.h | 24 | ||||
-rw-r--r-- | php/ext/google/protobuf/storage.c | 31 | ||||
-rw-r--r-- | php/ext/google/protobuf/type_check.c | 1 | ||||
-rw-r--r-- | php/ext/google/protobuf/utf8.c | 2 | ||||
-rw-r--r-- | php/tests/array_test.php | 40 | ||||
-rwxr-xr-x | php/tests/test.sh | 5 | ||||
-rw-r--r-- | python/tox.ini | 2 | ||||
-rwxr-xr-x | src/google/protobuf/compiler/js/js_generator.cc | 30 | ||||
-rw-r--r-- | src/google/protobuf/descriptor.cc | 19 | ||||
-rw-r--r-- | src/google/protobuf/descriptor_unittest.cc | 17 | ||||
-rwxr-xr-x | tests.sh | 121 |
24 files changed, 364 insertions, 147 deletions
diff --git a/.travis.yml b/.travis.yml index 094235e0..fd54ed1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,7 @@ env: - CONFIG=ruby21 - CONFIG=ruby22 - CONFIG=jruby + - CONFIG=php5.6_mac matrix: exclude: # It's nontrivial to programmatically install a new JDK from the command diff --git a/Makefile.am b/Makefile.am index 83f1043d..69d162e1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -54,6 +54,7 @@ csharp_EXTRA_DIST= \ csharp/Google.Protobuf.Tools.nuspec \ csharp/README.md \ csharp/build_packages.bat \ + csharp/build_tools.sh \ csharp/buildall.sh \ csharp/generate_protos.sh \ csharp/keys/Google.Protobuf.public.snk \ diff --git a/jenkins/docker/Dockerfile b/jenkins/docker/Dockerfile index 9c2a834d..4bfbef34 100644 --- a/jenkins/docker/Dockerfile +++ b/jenkins/docker/Dockerfile @@ -14,25 +14,29 @@ RUN echo 'deb http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main' > / apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DB82666C # Apt source for Oracle Java. -run echo 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main' > /etc/apt/sources.list.d/webupd8team-java-trusty.list && \ +RUN echo 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main' > /etc/apt/sources.list.d/webupd8team-java-trusty.list && \ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 && \ echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections # Apt source for Mono -run echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list && \ +RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list && \ echo "deb http://download.mono-project.com/repo/debian wheezy-libjpeg62-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list && \ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF +# Apt source for php +RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu trusty main" | tee /etc/apt/sources.list.d/various-php.list && \ + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F4FCBB07 + # Install dotnet SDK based on https://www.microsoft.com/net/core#debian # (Ubuntu instructions need apt to support https) -RUN apt-get update && apt-get install -y curl libunwind8 gettext && \ - curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809130 && \ +RUN apt-get update && apt-get install -y --force-yes curl libunwind8 gettext && \ + curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809130 && \ mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet && \ ln -s /opt/dotnet/dotnet /usr/local/bin # Install dependencies. We start with the basic ones require to build protoc # and the C++ build -RUN apt-get update && apt-get install -y \ +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ autoconf \ autotools-dev \ build-essential \ @@ -71,6 +75,19 @@ RUN apt-get update && apt-get install -y \ python3.4-dev \ # -- For Ruby -- ruby \ + # -- For PHP -- + php5.5 \ + php5.5-dev \ + php5.5-xml \ + php5.6 \ + php5.6-dev \ + php5.6-xml \ + php7.0 \ + php7.0-dev \ + php7.0-xml \ + phpunit \ + valgrind \ + libxml2-dev \ && apt-get clean ################## @@ -122,6 +139,35 @@ RUN cd /tmp && \ $MVN install dependency:go-offline -Dmaven.repo.local=$MAVEN_REPO ################## +# PHP dependencies. +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +RUN php composer-setup.php +RUN mv composer.phar /usr/bin/composer +RUN php -r "unlink('composer-setup.php');" +RUN cd /tmp && \ + cd protobuf && \ + ln -sfn /usr/bin/php5.5 /usr/bin/php && \ + ln -sfn /usr/bin/php-config5.5 /usr/bin/php-config && \ + ln -sfn /usr/bin/phpize5.5 /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-5.5 && \ + ln -sfn /usr/bin/php5.6 /usr/bin/php && \ + ln -sfn /usr/bin/php-config5.6 /usr/bin/php-config && \ + ln -sfn /usr/bin/phpize5.6 /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-5.6 && \ + ln -sfn /usr/bin/php7.0 /usr/bin/php && \ + ln -sfn /usr/bin/php-config7.0 /usr/bin/php-config && \ + ln -sfn /usr/bin/phpize7.0 /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-7.0 +RUN wget http://am1.php.net/get/php-5.5.38.tar.bz2/from/this/mirror +RUN mv mirror php-5.5.38.tar.bz2 +RUN tar -xvf php-5.5.38.tar.bz2 +RUN cd php-5.5.38 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts && \ + make && make install + +################## # Go dependencies. RUN apt-get install -y \ # -- For go -- \ @@ -129,7 +175,7 @@ RUN apt-get install -y \ ################## # Javascript dependencies. -Run apt-get install -y \ +RUN apt-get install -y \ # -- For javascript -- \ npm diff --git a/jenkins/pull_request_in_docker.sh b/jenkins/pull_request_in_docker.sh index 78a9253a..b843a355 100755 --- a/jenkins/pull_request_in_docker.sh +++ b/jenkins/pull_request_in_docker.sh @@ -58,6 +58,7 @@ parallel --results $LOG_OUTPUT_DIR --joblog $OUTPUT_DIR/joblog $TEST_SCRIPT ::: ruby_all \ javascript \ golang \ + php_all \ || true # Process test results even if tests fail. cat $OUTPUT_DIR/joblog diff --git a/js/message_test.js b/js/message_test.js index 97c594c8..b0a0a72e 100644 --- a/js/message_test.js +++ b/js/message_test.js @@ -1040,4 +1040,18 @@ describe('Message test suite', function() { assertNan(message.getDefaultDoubleField()); }); + // Verify that we can successfully use a field referring to a nested message + // from a different .proto file. + it('testForeignNestedMessage', function() { + var msg = new proto.jspb.test.ForeignNestedFieldMessage(); + var nested = new proto.jspb.test.Deeply.Nested.Message(); + nested.setCount(5); + msg.setDeeplyNestedMessage(nested); + + // After a serialization-deserialization round trip we should get back the + // same data we started with. + var serialized = msg.serializeBinary(); + var deserialized = proto.jspb.test.ForeignNestedFieldMessage.deserializeBinary(serialized); + assertEquals(5, deserialized.getDeeplyNestedMessage().getCount()); + }); }); diff --git a/js/test.proto b/js/test.proto index 48cb37e1..db238e1a 100644 --- a/js/test.proto +++ b/js/test.proto @@ -260,3 +260,11 @@ enum MapValueEnumNoBinary { message MapValueMessageNoBinary { optional int32 foo = 1; } + +message Deeply { + message Nested { + message Message { + optional int32 count = 1; + } + } +} diff --git a/js/test2.proto b/js/test2.proto index 44e55eff..b67f93fa 100644 --- a/js/test2.proto +++ b/js/test2.proto @@ -35,6 +35,8 @@ option java_multiple_files = true; package jspb.test; +import "test.proto"; + message TestExtensionsMessage { optional int32 intfield = 1; extensions 100 to max; @@ -52,3 +54,7 @@ extend TestExtensionsMessage { optional ExtensionMessage floating_msg_field = 101; optional string floating_str_field = 102; } + +message ForeignNestedFieldMessage { + optional Deeply.Nested.Message deeply_nested_message = 1; +} diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index fde4f726..215dcd46 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -160,7 +160,7 @@ static void repeated_field_write_dimension(zval *object, zval *offset, unsigned char memory[NATIVE_SLOT_MAX_SIZE]; memset(memory, 0, NATIVE_SLOT_MAX_SIZE); - if (!native_slot_set(intern->type, intern->msg_ce, memory, value)) { + if (!native_slot_set(intern->type, intern->msg_ce, memory, value TSRMLS_CC)) { return; } @@ -169,7 +169,7 @@ static void repeated_field_write_dimension(zval *object, zval *offset, } else { if (protobuf_convert_to_uint64(offset, &index)) { if (!zend_hash_index_exists(ht, index)) { - zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index); + zend_error(E_USER_ERROR, "Element at %llu doesn't exist.\n", index); return; } } else { @@ -192,7 +192,7 @@ static HashTable *repeated_field_get_gc(zval *object, zval ***table, // C RepeatedField Utilities // ----------------------------------------------------------------------------- -void *repeated_field_index_native(RepeatedField *intern, int index) { +void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC) { HashTable *ht = HASH_OF(intern->array); void *value; @@ -222,7 +222,7 @@ void repeated_field_create_with_type(zend_class_entry *ce, zend_object_store_get_object(*repeated_field TSRMLS_CC); intern->type = upb_fielddef_type(field); if (intern->type == UPB_TYPE_MESSAGE) { - upb_msgdef *msg = upb_fielddef_msgsubdef(field); + const upb_msgdef *msg = upb_fielddef_msgsubdef(field); zval *desc_php = get_def_obj(msg); Descriptor *desc = zend_object_store_get_object(desc_php TSRMLS_CC); intern->msg_ce = desc->klass; @@ -321,7 +321,7 @@ PHP_METHOD(RepeatedField, offsetGet) { HashTable *table = HASH_OF(intern->array); if (zend_hash_index_find(table, index, (void **)&memory) == FAILURE) { - zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index); + zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index); return; } @@ -365,7 +365,7 @@ PHP_METHOD(RepeatedField, offsetUnset) { // Only the element at the end of the array can be removed. if (index == -1 || index != (zend_hash_num_elements(HASH_OF(intern->array)) - 1)) { - zend_error(E_USER_ERROR, "Cannot remove element at %d.\n", index); + zend_error(E_USER_ERROR, "Cannot remove element at %ld.\n", index); return; } diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index cbd0ec62..156eca07 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -318,7 +318,8 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { add_def_obj(desc->def_type_lower, desc_php); \ /* Unlike other messages, MapEntry is shared by all map fields and doesn't \ * have generated PHP class.*/ \ - if (upb_def_type(def) == UPB_DEF_MSG && upb_msgdef_mapentry(def)) { \ + if (upb_def_type(def) == UPB_DEF_MSG && \ + upb_msgdef_mapentry(upb_downcast_msgdef(def))) { \ break; \ } \ /* Prepend '.' to package name to make it absolute. */ \ diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 4b51dabe..eafe1ae8 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -29,6 +29,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "protobuf.h" +#include "utf8.h" /* stringsink *****************************************************************/ @@ -201,9 +202,10 @@ static void *startseq_handler(void* closure, const void* hd) { static bool append##type##_handler(void* closure, const void* hd, \ ctype val) { \ zval* array = (zval*)closure; \ + TSRMLS_FETCH(); \ RepeatedField* intern = \ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); \ - repeated_field_push_native(intern, &val); \ + repeated_field_push_native(intern, &val TSRMLS_CC); \ return true; \ } @@ -220,6 +222,7 @@ static void* appendstr_handler(void *closure, const void *hd, size_t size_hint) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -236,6 +239,7 @@ static void* appendbytes_handler(void *closure, const void *hd, size_t size_hint) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -298,6 +302,7 @@ static size_t stringdata_handler(void* closure, const void* hd, // Appends a submessage to a repeated field. static void *appendsubmsg_handler(void *closure, const void *hd) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -323,6 +328,7 @@ static void *submsg_handler(void *closure, const void *hd) { MessageHeader* msg = closure; const submsg_handlerdata_t* submsgdata = hd; zval* subdesc_php = get_def_obj((void*)submsgdata->md); + TSRMLS_FETCH(); Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); zend_class_entry* subklass = subdesc->klass; zval* submsg_php; @@ -411,7 +417,8 @@ static void map_slot_uninit(void* memory, upb_fieldtype_t type) { } } -static void map_slot_key(upb_fieldtype_t type, const void* from, char** keyval, +static void map_slot_key(upb_fieldtype_t type, const void* from, + const char** keyval, size_t* length) { if (type == UPB_TYPE_STRING) { zval* key_php = **(zval***)from; @@ -423,7 +430,8 @@ static void map_slot_key(upb_fieldtype_t type, const void* from, char** keyval, } } -static void map_slot_value(upb_fieldtype_t type, const void* from, upb_value* v) { +static void map_slot_value(upb_fieldtype_t type, const void* from, + upb_value* v) { size_t len; void* to = upb_value_memory(v); #ifndef NDEBUG @@ -464,10 +472,11 @@ static void *startmapentry_handler(void *closure, const void *hd) { // Handler to end a map entry: inserts the value defined during the message into // the map. This is the 'endmsg' handler on the map entry msgdef. -static bool endmap_handler(void *closure, const void *hd, upb_status* s) { +static bool endmap_handler(void* closure, const void* hd, upb_status* s) { map_parse_frame_t* frame = closure; const map_handlerdata_t* mapdata = hd; + TSRMLS_FETCH(); Map *map = (Map *)zend_object_store_get_object(frame->map TSRMLS_CC); const char* keyval = NULL; @@ -573,12 +582,12 @@ static void *oneofbytes_handler(void *closure, } // Handler for a submessage field in a oneof. -static void *oneofsubmsg_handler(void *closure, - const void *hd) { +static void* oneofsubmsg_handler(void* closure, const void* hd) { MessageHeader* msg = closure; const oneof_handlerdata_t *oneofdata = hd; uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t); zval* subdesc_php = get_def_obj((void*)oneofdata->md); + TSRMLS_FETCH(); Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); zend_class_entry* subklass = subdesc->klass; zval* submsg_php; @@ -771,8 +780,10 @@ static void add_handlers_for_oneof_field(upb_handlers *h, upb_handlerattr_uninit(&attr); } -static void add_handlers_for_message(const void *closure, upb_handlers *h) { +static void add_handlers_for_message(const void* closure, + upb_handlers* h) { const upb_msgdef* msgdef = upb_handlers_msgdef(h); + TSRMLS_FETCH(); Descriptor* desc = (Descriptor*)zend_object_store_get_object( get_def_obj((void*)msgdef) TSRMLS_CC); upb_msg_field_iter i; @@ -860,7 +871,7 @@ static const upb_pbdecodermethod *msgdef_decodermethod(Descriptor* desc) { // ----------------------------------------------------------------------------- static void putmsg(zval* msg, const Descriptor* desc, upb_sink* sink, - int depth); + int depth TSRMLS_DC); static void putstr(zval* str, const upb_fielddef* f, upb_sink* sink); @@ -868,11 +879,12 @@ static void putrawstr(const char* str, int len, const upb_fielddef* f, upb_sink* sink); static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, - int depth); + int depth TSRMLS_DC); static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, - int depth); -static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, int depth); + int depth TSRMLS_DC); +static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, int depth + TSRMLS_DC); static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) { upb_selector_t ret; @@ -881,8 +893,8 @@ static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) { return ret; } -static void put_optional_value(void* memory, int len, const upb_fielddef* f, - int depth, upb_sink* sink) { +static void put_optional_value(const void* memory, int len, const upb_fielddef* f, + int depth, upb_sink* sink TSRMLS_DC) { assert(upb_fielddef_label(f) == UPB_LABEL_OPTIONAL); switch (upb_fielddef_type(f)) { @@ -911,7 +923,7 @@ static void put_optional_value(void* memory, int len, const upb_fielddef* f, break; case UPB_TYPE_MESSAGE: { zval* submsg = *(zval**)memory; - putsubmsg(submsg, f, sink, depth); + putsubmsg(submsg, f, sink, depth TSRMLS_CC); break; } default: @@ -943,7 +955,7 @@ static int raw_value_len(void* memory, int len, const upb_fielddef* f) { } static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, - int depth) { + int depth TSRMLS_DC) { Map* self; upb_sink subsink; const upb_fielddef* key_field; @@ -960,7 +972,7 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, key_field = map_field_key(f); value_field = map_field_value(f); - for (map_begin(map, &it); !map_done(&it); map_next(&it)) { + for (map_begin(map, &it TSRMLS_CC); !map_done(&it); map_next(&it)) { upb_status status; upb_sink entry_sink; @@ -970,13 +982,13 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, // Serialize key. const char *key = map_iter_key(&it, &len); - put_optional_value(key, len, key_field, depth + 1, &entry_sink); + put_optional_value(key, len, key_field, depth + 1, &entry_sink TSRMLS_CC); // Serialize value. upb_value value = map_iter_value(&it, &len); put_optional_value(raw_value(upb_value_memory(&value), value_field), raw_value_len(upb_value_memory(&value), len, value_field), - value_field, depth + 1, &entry_sink); + value_field, depth + 1, &entry_sink TSRMLS_CC); upb_sink_endmsg(&entry_sink, &status); upb_sink_endsubmsg(&subsink, getsel(f, UPB_HANDLER_ENDSUBMSG)); @@ -986,7 +998,7 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, } static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, - int depth) { + int depth TSRMLS_DC) { upb_msg_field_iter i; upb_status status; @@ -1023,12 +1035,12 @@ static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, if (is_map_field(f)) { zval* map = *DEREF(msg, offset, zval**); if (map != NULL) { - putmap(map, f, sink, depth); + putmap(map, f, sink, depth TSRMLS_CC); } } else if (upb_fielddef_isseq(f)) { zval* array = *DEREF(msg, offset, zval**); if (array != NULL) { - putarray(array, f, sink, depth); + putarray(array, f, sink, depth TSRMLS_CC); } } else if (upb_fielddef_isstring(f)) { zval* str = *DEREF(msg, offset, zval**); @@ -1036,7 +1048,7 @@ static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, putstr(str, f, sink); } } else if (upb_fielddef_issubmsg(f)) { - putsubmsg(*DEREF(msg, offset, zval**), f, sink, depth); + putsubmsg(*DEREF(msg, offset, zval**), f, sink, depth TSRMLS_CC); } else { upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); @@ -1113,7 +1125,7 @@ static void putrawstr(const char* str, int len, const upb_fielddef* f, } static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, - int depth) { + int depth TSRMLS_DC) { upb_sink subsink; if (Z_TYPE_P(submsg) == IS_NULL) return; @@ -1123,12 +1135,12 @@ static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC); upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink); - putmsg(submsg, subdesc, &subsink, depth + 1); + putmsg(submsg, subdesc, &subsink, depth + 1 TSRMLS_CC); upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG)); } static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, - int depth) { + int depth TSRMLS_DC) { upb_sink subsink; upb_fieldtype_t type = upb_fielddef_type(f); upb_selector_t sel = 0; @@ -1147,7 +1159,7 @@ static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, } for (i = 0; i < size; i++) { - void* memory = repeated_field_index_native(intern, i); + void* memory = repeated_field_index_native(intern, i TSRMLS_CC); switch (type) { #define T(upbtypeconst, upbtype, ctype) \ case upbtypeconst: \ @@ -1168,7 +1180,7 @@ static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, putstr(*((zval**)memory), f, &subsink); break; case UPB_TYPE_MESSAGE: - putsubmsg(*((zval**)memory), f, &subsink, depth); + putsubmsg(*((zval**)memory), f, &subsink, depth TSRMLS_CC); break; #undef T @@ -1206,7 +1218,7 @@ PHP_METHOD(Message, encode) { stackenv_init(&se, "Error occurred during encoding: %s"); encoder = upb_pb_encoder_create(&se.env, serialize_handlers, &sink.sink); - putmsg(getThis(), desc, upb_pb_encoder_input(encoder), 0); + putmsg(getThis(), desc, upb_pb_encoder_input(encoder), 0 TSRMLS_CC); RETVAL_STRINGL(sink.ptr, sink.len, 1); diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index 6d822fff..35747b05 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -33,6 +33,7 @@ #include <Zend/zend_interfaces.h> #include "protobuf.h" +#include "utf8.h" ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) ZEND_ARG_INFO(0, index) @@ -88,7 +89,7 @@ void* upb_value_memory(upb_value* v) { static bool table_key(Map* self, zval* key, char* buf, const char** out_key, - size_t* out_length) { + size_t* out_length TSRMLS_DC) { switch (self->key_type) { case UPB_TYPE_STRING: if (!protobuf_convert_to_string(key)) { @@ -108,7 +109,7 @@ static bool table_key(Map* self, zval* key, if (!protobuf_convert_to_##type(key, &type##_value)) { \ return false; \ } \ - native_slot_set(self->key_type, NULL, buf, key); \ + native_slot_set(self->key_type, NULL, buf, key TSRMLS_CC); \ *out_key = buf; \ *out_length = native_slot_size(self->key_type); \ break; \ @@ -152,7 +153,7 @@ static zend_function_entry map_field_methods[] = { zend_class_entry* map_field_type; zend_object_handlers* map_field_handlers; -static map_begin_internal(Map *map, MapIter *iter) { +static void map_begin_internal(Map *map, MapIter *iter) { iter->self = map; upb_strtable_begin(&iter->it, &map->table); } @@ -248,7 +249,7 @@ void map_field_create_with_type(zend_class_entry *ce, const upb_fielddef *field, const upb_fielddef *value_field = map_field_value(field); intern->key_type = upb_fielddef_type(key_field); intern->value_type = upb_fielddef_type(value_field); - intern->msg_ce = field_type_class(value_field); + intern->msg_ce = field_type_class(value_field TSRMLS_CC); } static void map_field_free_element(void *object) { @@ -258,8 +259,8 @@ static void map_field_free_element(void *object) { // MapField Handlers // ----------------------------------------------------------------------------- -static bool *map_field_read_dimension(zval *object, zval *key, int type, - zval **retval TSRMLS_DC) { +static bool map_field_read_dimension(zval *object, zval *key, int type, + zval **retval TSRMLS_DC) { Map *intern = (Map *)zend_object_store_get_object(object TSRMLS_CC); @@ -270,7 +271,7 @@ static bool *map_field_read_dimension(zval *object, zval *key, int type, #ifndef NDEBUG v.ctype = UPB_CTYPE_UINT64; #endif - if (!table_key(intern, key, keybuf, &keyval, &length)) { + if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { return false; } @@ -303,13 +304,14 @@ static bool map_field_write_dimension(zval *object, zval *key, size_t length = 0; upb_value v; void* mem; - if (!table_key(intern, key, keybuf, &keyval, &length)) { + if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { return false; } mem = upb_value_memory(&v); memset(mem, 0, native_slot_size(intern->value_type)); - if(!native_slot_set(intern->value_type, intern->msg_ce, mem, value)) { + if (!native_slot_set(intern->value_type, intern->msg_ce, mem, value + TSRMLS_CC)) { return false; } #ifndef NDEBUG @@ -333,7 +335,7 @@ static bool map_field_unset_dimension(zval *object, zval *key TSRMLS_DC) { const char* keyval = NULL; size_t length = 0; upb_value v; - if (!table_key(intern, key, keybuf, &keyval, &length)) { + if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { return false; } #ifndef NDEBUG @@ -396,8 +398,8 @@ PHP_METHOD(MapField, offsetExists) { #ifndef NDEBUG v.ctype = UPB_CTYPE_UINT64; #endif - if (!table_key(intern, key, keybuf, &keyval, &length)) { - return false; + if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { + RETURN_BOOL(false); } RETURN_BOOL(upb_strtable_lookup2(&intern->table, keyval, length, &v)); @@ -433,7 +435,7 @@ PHP_METHOD(MapField, offsetUnset) { PHP_METHOD(MapField, count) { Map *intern = - (MapField *)zend_object_store_get_object(getThis() TSRMLS_CC); + (Map *)zend_object_store_get_object(getThis() TSRMLS_CC); if (zend_parse_parameters_none() == FAILURE) { return; @@ -446,7 +448,7 @@ PHP_METHOD(MapField, count) { // Map Iterator // ----------------------------------------------------------------------------- -void map_begin(zval *map_php, MapIter *iter) { +void map_begin(zval *map_php, MapIter *iter TSRMLS_DC) { Map *self = UNBOX(Map, map_php); map_begin_internal(self, iter); } diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 0cae6dba..cb46031e 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -96,7 +96,7 @@ static void message_set_property(zval* object, zval* member, zval* value, zend_error(E_USER_ERROR, "Unknown field: %s", Z_STRVAL_P(member)); } - layout_set(self->descriptor->layout, self, field, value); + layout_set(self->descriptor->layout, self, field, value TSRMLS_CC); } static zval* message_get_property(zval* object, zval* member, int type, @@ -177,7 +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); + 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, diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index d8ad3c88..019bca29 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -55,7 +55,7 @@ static void add_to_table(HashTable* t, const void* def, void* value) { uint nIndex = (ulong)def & t->nTableMask; zval* pDest = NULL; - zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), &pDest); + zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), (void**)&pDest); } static void* get_from_table(const HashTable* t, const void* def) { @@ -69,7 +69,7 @@ static void* get_from_table(const HashTable* t, const void* def) { static void add_to_list(HashTable* t, void* value) { zval* pDest = NULL; - zend_hash_next_index_insert(t, &value, sizeof(void*), &pDest); + zend_hash_next_index_insert(t, &value, sizeof(void*), (void**)&pDest); } void add_def_obj(const void* def, zval* value) { @@ -134,6 +134,8 @@ static PHP_RINIT_FUNCTION(protobuf) { generated_pool = NULL; generated_pool_php = NULL; + + return 0; } static PHP_RSHUTDOWN_FUNCTION(protobuf) { @@ -147,6 +149,8 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) { zval_dtor(generated_pool_php); FREE_ZVAL(generated_pool_php); } + + return 0; } static PHP_MINIT_FUNCTION(protobuf) { @@ -158,10 +162,14 @@ static PHP_MINIT_FUNCTION(protobuf) { descriptor_init(TSRMLS_C); enum_descriptor_init(TSRMLS_C); util_init(TSRMLS_C); + + return 0; } static PHP_MSHUTDOWN_FUNCTION(protobuf) { PEFREE(message_handlers); PEFREE(repeated_field_handlers); PEFREE(map_field_handlers); + + return 0; } diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index b3ad20dd..8a1d9261 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -70,14 +70,6 @@ typedef struct MapField MapField; ZEND_BEGIN_MODULE_GLOBALS(protobuf) ZEND_END_MODULE_GLOBALS(protobuf) -ZEND_DECLARE_MODULE_GLOBALS(protobuf) - -#ifdef ZTS -#define PROTOBUF_G(v) TSRMG(protobuf_globals_id, zend_protobuf_globals*, v) -#else -#define PROTOBUF_G(v) (protobuf_globals.v) -#endif - // Init module and PHP classes. void descriptor_init(TSRMLS_D); void enum_descriptor_init(TSRMLS_D); @@ -233,11 +225,12 @@ struct MessageHeader { }; MessageLayout* create_layout(const upb_msgdef* msgdef); -void layout_init(MessageLayout* layout, void* storage, zval** properties_table); +void layout_init(MessageLayout* layout, void* storage, zval** properties_table + TSRMLS_DC); zval* layout_get(MessageLayout* layout, const void* storage, const upb_fielddef* field, zval** cache TSRMLS_DC); void layout_set(MessageLayout* layout, MessageHeader* header, - const upb_fielddef* field, zval* val); + const upb_fielddef* field, zval* val TSRMLS_DC); void free_layout(MessageLayout* layout); PHP_METHOD(Message, readOneof); @@ -293,7 +286,7 @@ PHP_METHOD(Util, checkRepeatedField); size_t native_slot_size(upb_fieldtype_t type); bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, - void* memory, zval* value); + void* memory, zval* value TSRMLS_DC); void native_slot_init(upb_fieldtype_t type, void* memory, zval** cache); // For each property, in order to avoid conversion between the zval object and // the actual data type during parsing/serialization, the containing message @@ -325,7 +318,7 @@ typedef struct { upb_strtable_iter it; } MapIter; -void map_begin(zval* self, MapIter* iter); +void map_begin(zval* self, MapIter* iter TSRMLS_DC); void map_next(MapIter* iter); bool map_done(MapIter* iter); const char* map_iter_key(MapIter* iter, int* len); @@ -346,6 +339,7 @@ void* upb_value_memory(upb_value* v); // These operate on a map field (i.e., a repeated field of submessages whose // submessage type is a map-entry msgdef). +bool is_map_field(const upb_fielddef* field); const upb_fielddef* map_field_key(const upb_fielddef* field); const upb_fielddef* map_field_value(const upb_fielddef* field); @@ -377,10 +371,10 @@ void repeated_field_create_with_type(zend_class_entry* ce, zval** repeated_field TSRMLS_DC); // Return the element at the index position from the repeated field. There is // not restriction on the type of stored elements. -void *repeated_field_index_native(RepeatedField *intern, int index); +void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC); // Add the element to the end of the repeated field. There is not restriction on // the type of stored elements. -void repeated_field_push_native(RepeatedField *intern, void *value); +void repeated_field_push_native(RepeatedField *intern, void *value TSRMLS_DC); PHP_METHOD(RepeatedField, __construct); PHP_METHOD(RepeatedField, append); @@ -411,7 +405,7 @@ typedef struct { // ----------------------------------------------------------------------------- upb_fieldtype_t to_fieldtype(upb_descriptortype_t type); -const zend_class_entry *field_type_class(const upb_fielddef *field); +const zend_class_entry *field_type_class(const upb_fielddef *field TSRMLS_DC); // ----------------------------------------------------------------------------- // Utilities. diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index 7423552b..e94aa319 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -32,6 +32,8 @@ #include <protobuf.h> #include <Zend/zend.h> +#include "utf8.h" + // ----------------------------------------------------------------------------- // Native slot storage. // ----------------------------------------------------------------------------- @@ -56,7 +58,7 @@ size_t native_slot_size(upb_fieldtype_t type) { } bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, - void* memory, zval* value) { + void* memory, zval* value TSRMLS_DC) { switch (type) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { @@ -210,7 +212,7 @@ CASE(ENUM, LONG, uint32_t) return; } default: - return EG(uninitialized_zval_ptr); + return; } } @@ -245,7 +247,7 @@ void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC) { return; } default: - return EG(uninitialized_zval_ptr); + return; } } @@ -295,7 +297,7 @@ const upb_fielddef* map_entry_value(const upb_msgdef* msgdef) { return value_field; } -const zend_class_entry* field_type_class(const upb_fielddef* field) { +const zend_class_entry* field_type_class(const upb_fielddef* field TSRMLS_DC) { if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) { zval* desc_php = get_def_obj(upb_fielddef_subdef(field)); Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); @@ -305,6 +307,7 @@ const zend_class_entry* field_type_class(const upb_fielddef* field) { EnumDescriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); return desc->klass; } + return NULL; } // ----------------------------------------------------------------------------- @@ -435,7 +438,8 @@ void free_layout(MessageLayout* layout) { FREE(layout); } -void layout_init(MessageLayout* layout, void* storage, zval** properties_table) { +void layout_init(MessageLayout* layout, void* storage, zval** properties_table + TSRMLS_DC) { int i; upb_msg_field_iter it; for (upb_msg_field_begin(&it, layout->msgdef), i = 0; !upb_msg_field_done(&it); @@ -451,11 +455,12 @@ void layout_init(MessageLayout* layout, void* storage, zval** properties_table) *oneof_case = ONEOF_CASE_NONE; } else if (is_map_field(field)) { zval_ptr_dtor(property_ptr); - map_field_create_with_type(map_field_type, field, property_ptr); + map_field_create_with_type(map_field_type, field, property_ptr TSRMLS_CC); DEREF(memory, zval**) = property_ptr; } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { zval_ptr_dtor(property_ptr); - repeated_field_create_with_type(repeated_field_type, field, property_ptr); + repeated_field_create_with_type(repeated_field_type, field, property_ptr + TSRMLS_CC); DEREF(memory, zval**) = property_ptr; } else { native_slot_init(upb_fielddef_type(field), memory, property_ptr); @@ -501,8 +506,8 @@ zval* layout_get(MessageLayout* layout, const void* storage, } } -void layout_set(MessageLayout* layout, MessageHeader* header, const upb_fielddef* field, - zval* val) { +void layout_set(MessageLayout* layout, MessageHeader* header, + const upb_fielddef* field, zval* val TSRMLS_DC) { void* storage = message_data(header); void* memory = slot_memory(layout, storage, field); uint32_t* oneof_case = slot_oneof_case(layout, storage, field); @@ -515,7 +520,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, const upb_fielddef // zval in properties table first. switch (type) { case UPB_TYPE_MESSAGE: { - upb_msgdef* msg = upb_fielddef_msgsubdef(field); + const upb_msgdef* msg = upb_fielddef_msgsubdef(field); zval* desc_php = get_def_obj(msg); Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); ce = desc->klass; @@ -535,7 +540,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, const upb_fielddef break; } - native_slot_set(type, ce, memory, val); + native_slot_set(type, ce, memory, val TSRMLS_CC); *oneof_case = upb_fielddef_number(field); } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { // Works for both repeated and map fields @@ -549,11 +554,11 @@ void layout_set(MessageLayout* layout, MessageHeader* header, const upb_fielddef upb_fieldtype_t type = upb_fielddef_type(field); zend_class_entry *ce = NULL; if (type == UPB_TYPE_MESSAGE) { - upb_msgdef* msg = upb_fielddef_msgsubdef(field); + const upb_msgdef* msg = upb_fielddef_msgsubdef(field); zval* desc_php = get_def_obj(msg); Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); ce = desc->klass; } - native_slot_set(type, ce, value_memory(field, memory), val); + native_slot_set(type, ce, value_memory(field, memory), val TSRMLS_CC); } } diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index fe9359fc..c215d72e 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -214,7 +214,6 @@ bool protobuf_convert_to_bool(zval* from, int8_t* to) { } else { *to = 1; } - STR_FREE(strval); } break; default: { zend_error(E_USER_ERROR, "Given value cannot be converted to bool."); diff --git a/php/ext/google/protobuf/utf8.c b/php/ext/google/protobuf/utf8.c index a1541636..2752a08b 100644 --- a/php/ext/google/protobuf/utf8.c +++ b/php/ext/google/protobuf/utf8.c @@ -58,7 +58,7 @@ bool is_structurally_valid_utf8(const char* buf, int len) { return false; } for (j = i + 1; j < i + offset; j++) { - if (buf[j] & 0xc0 != 0x80) { + if ((buf[j] & 0xc0) != 0x80) { return false; } } diff --git a/php/tests/array_test.php b/php/tests/array_test.php index d683add5..09d4dc82 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -789,26 +789,26 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $this->assertSame(1, count($arr)); } - public function testInsertRemoval() - { - $arr = new RepeatedField(GPBType::INT32); - - $arr []= 0; - $arr []= 1; - $arr []= 2; - $this->assertSame(3, count($arr)); - - unset($arr[2]); - $this->assertSame(2, count($arr)); - $this->assertSame(0, $arr[0]); - $this->assertSame(1, $arr[1]); - - $arr [] = 3; - $this->assertSame(3, count($arr)); - $this->assertSame(0, $arr[0]); - $this->assertSame(1, $arr[1]); - $this->assertSame(3, $arr[2]); - } + public function testInsertRemoval() + { + $arr = new RepeatedField(GPBType::INT32); + + $arr []= 0; + $arr []= 1; + $arr []= 2; + $this->assertSame(3, count($arr)); + + unset($arr[2]); + $this->assertSame(2, count($arr)); + $this->assertSame(0, $arr[0]); + $this->assertSame(1, $arr[1]); + + $arr [] = 3; + $this->assertSame(3, count($arr)); + $this->assertSame(0, $arr[0]); + $this->assertSame(1, $arr[1]); + $this->assertSame(3, $arr[2]); + } /** * @expectedException PHPUnit_Framework_Error diff --git a/php/tests/test.sh b/php/tests/test.sh index f3f04a47..888e93eb 100755 --- a/php/tests/test.sh +++ b/php/tests/test.sh @@ -1,10 +1,5 @@ #!/bin/bash -# Compile protoc -pushd ../../ -./autogen.sh && ./configure && make -popd - # Generate test file ../../src/protoc --php_out=. test.proto test_include.proto diff --git a/python/tox.ini b/python/tox.ini index cf8d5401..1600db21 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -12,7 +12,7 @@ setenv = commands = python setup.py -q build_py python: python setup.py -q build - cpp: python setup.py -q build --cpp_implementation --warnings_as_errors + cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension python: python setup.py -q test -q cpp: python setup.py -q test -q --cpp_implementation python: python setup.py -q test_conformance diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index fec465fe..58597b4c 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -208,28 +208,28 @@ string GetPath(const GeneratorOptions& options, } } -// Forward declare, so that GetPrefix can call this method, -// which in turn, calls GetPrefix. -string GetPath(const GeneratorOptions& options, - const Descriptor* descriptor); +// Returns the name of the message with a leading dot and taking into account +// nesting, for example ".OuterMessage.InnerMessage", or returns empty if +// descriptor is null. This function does not handle namespacing, only message +// nesting. +string GetNestedMessageName(const Descriptor* descriptor) { + if (descriptor == NULL) { + return ""; + } + return StripPrefixString(descriptor->full_name(), + descriptor->file()->package()); +} // Returns the path prefix for a message or enumeration that // lives under the given file and containing type. string GetPrefix(const GeneratorOptions& options, const FileDescriptor* file_descriptor, const Descriptor* containing_type) { - string prefix = ""; - - if (containing_type == NULL) { - prefix = GetPath(options, file_descriptor); - } else { - prefix = GetPath(options, containing_type); - } - + string prefix = GetPath(options, file_descriptor) + + GetNestedMessageName(containing_type); if (!prefix.empty()) { prefix += "."; } - return prefix; } @@ -277,7 +277,9 @@ string MaybeCrossFileRef(const GeneratorOptions& options, from_file != to_message->file()) { // Cross-file ref in CommonJS needs to use the module alias instead of // the global name. - return ModuleAlias(to_message->file()->name()) + "." + to_message->name(); + return ModuleAlias(to_message->file()->name()) + + GetNestedMessageName(to_message->containing_type()) + + "." + to_message->name(); } else { // Within a single file we use a full name. return GetPath(options, to_message); diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 4dccb585..be1e1d69 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -4707,11 +4707,20 @@ void DescriptorBuilder::CheckEnumValueUniqueness( // stripping should de-dup the labels in this case). if (!inserted && insert_result.first->second->name() != value->name() && insert_result.first->second->number() != value->number()) { - AddError(value->full_name(), proto.value(i), - DescriptorPool::ErrorCollector::NAME, - "When enum name is stripped and label is PascalCased (" + - stripped + "), this value label conflicts with " + - values[stripped]->name()); + string error_message = + "When enum name is stripped and label is PascalCased (" + stripped + + "), this value label conflicts with " + values[stripped]->name() + + ". This will make the proto fail to compile for some languages, such " + "as C#."; + // There are proto2 enums out there with conflicting names, so to preserve + // compatibility we issue only a warning for proto2. + if (result->file()->syntax() == FileDescriptor::SYNTAX_PROTO2) { + AddWarning(value->full_name(), proto.value(i), + DescriptorPool::ErrorCollector::NAME, error_message); + } else { + AddError(value->full_name(), proto.value(i), + DescriptorPool::ErrorCollector::NAME, error_message); + } } } } diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 07953416..f6b3f1c5 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -5565,6 +5565,7 @@ TEST_F(ValidationErrorTest, MapEntryConflictsWithEnum) { TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { BuildFileWithErrors( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -5572,9 +5573,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { " value { name: 'BAZ' number: 1 }" "}", "foo.proto: BAZ: NAME: When enum name is stripped and label is " - "PascalCased (Baz), this value label conflicts with FOO_ENUM_BAZ\n"); + "PascalCased (Baz), this value label conflicts with FOO_ENUM_BAZ. This " + "will make the proto fail to compile for some languages, such as C#.\n"); BuildFileWithErrors( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -5582,9 +5585,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { " value { name: 'BAZ' number: 1 }" "}", "foo.proto: BAZ: NAME: When enum name is stripped and label is " - "PascalCased (Baz), this value label conflicts with FOOENUM_BAZ\n"); + "PascalCased (Baz), this value label conflicts with FOOENUM_BAZ. This " + "will make the proto fail to compile for some languages, such as C#.\n"); BuildFileWithErrors( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -5593,9 +5598,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR__BAZ: NAME: When enum name is stripped and label is " "PascalCased (BarBaz), this value label conflicts with " - "FOO_ENUM_BAR_BAZ\n"); + "FOO_ENUM_BAR_BAZ. This " + "will make the proto fail to compile for some languages, such as C#.\n"); BuildFileWithErrors( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -5604,11 +5611,13 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR_BAZ: NAME: When enum name is stripped and label is " "PascalCased (BarBaz), this value label conflicts with " - "FOO_ENUM__BAR_BAZ\n"); + "FOO_ENUM__BAR_BAZ. This " + "will make the proto fail to compile for some languages, such as C#.\n"); // This isn't an error because the underscore will cause the PascalCase to // differ by case (BarBaz vs. Barbaz). BuildFile( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -28,21 +28,21 @@ internal_build_cpp() { fi ./autogen.sh - ./configure + ./configure CXXFLAGS="-fPIC" # -fPIC is needed for python cpp test. + # See python/setup.py for more details make -j2 } build_cpp() { internal_build_cpp make check -j2 - pushd conformance - make test_cpp - popd + cd conformance && make test_cpp && cd .. # Verify benchmarking code can build successfully. - pushd benchmarks - make && ./generate-datasets - popd + git submodule init + git submodule update + cd third_party/benchmark && cmake -DCMAKE_BUILD_TYPE=Release && make && cd ../.. + cd benchmarks && make && ./generate-datasets && cd .. } build_cpp_distcheck() { @@ -51,7 +51,7 @@ build_cpp_distcheck() { make dist # List all files that should be included in the distribution package. - git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\)" |\ + git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|cmake\|examples\)" |\ grep -v ".gitignore" | grep -v "java/compatibility_tests" > dist.lst # Unzip the dist tar file. DIST=`ls *.tar.gz` @@ -296,6 +296,8 @@ build_python() { build_python_cpp() { internal_build_cpp internal_install_python_deps + export LD_LIBRARY_PATH=../src/.libs # for Linux + export DYLD_LIBRARY_PATH=../src/.libs # for OS X cd python # Only test Python 2.6/3.x on Linux if [ $(uname -s) == "Linux" ]; then @@ -333,6 +335,100 @@ build_javascript() { cd js && npm install && npm test && cd .. } +use_php() { + VERSION=$1 + PHP=`which php` + PHP_CONFIG=`which php-config` + PHPIZE=`which phpize` + rm $PHP + rm $PHP_CONFIG + rm $PHPIZE + cp "/usr/bin/php$VERSION" $PHP + cp "/usr/bin/php-config$VERSION" $PHP_CONFIG + cp "/usr/bin/phpize$VERSION" $PHPIZE +} + +use_php_zts() { + VERSION=$1 + PHP=`which php` + PHP_CONFIG=`which php-config` + PHPIZE=`which phpize` + ln -sfn "/usr/local/php-${VERSION}-zts/bin/php" $PHP + ln -sfn "/usr/local/php-${VERSION}-zts/bin/php-config" $PHP_CONFIG + ln -sfn "/usr/local/php-${VERSION}-zts/bin/phpize" $PHPIZE +} + +build_php5.5() { + use_php 5.5 + rm -rf vendor + cp -r /usr/local/vendor-5.5 vendor + ./vendor/bin/phpunit +} + +build_php5.5_c() { + use_php 5.5 + cd php/tests && /bin/bash ./test.sh && cd ../.. +} + +build_php5.5_zts_c() { + use_php_zts 5.5 + wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit + cd php/tests && /bin/bash ./test.sh && cd ../.. +} + +build_php5.6() { + use_php 5.6 + rm -rf vendor + cp -r /usr/local/vendor-5.6 vendor + ./vendor/bin/phpunit +} + +build_php5.6_c() { + use_php 5.6 + cd php/tests && /bin/bash ./test.sh && cd ../.. +} + +build_php5.6_mac() { + # Install PHP + curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6 + export PATH="/usr/local/php5-5.6.25-20160831-101628/bin:$PATH" + + # Install phpunit + curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar + chmod +x phpunit.phar + sudo mv phpunit.phar /usr/local/bin/phpunit + + # Install valgrind + echo "#! /bin/bash" > valgrind + chmod ug+x valgrind + sudo mv valgrind /usr/local/bin/valgrind + + # Test + cd php/tests && /bin/bash ./test.sh && cd ../.. +} + +build_php7.0() { + use_php 7.0 + rm -rf vendor + cp -r /usr/local/vendor-7.0 vendor + ./vendor/bin/phpunit +} + +build_php7.0_c() { + use_php 7.0 + cd php/tests && /bin/bash ./test.sh && cd ../.. +} + +build_php_all() { + build_php5.5 + build_php5.6 + build_php7.0 + build_php5.5_c + build_php5.6_c + # build_php7.0_c + build_php5.5_zts_c +} + # Note: travis currently does not support testing more than one language so the # .travis.yml cheats and claims to only be cpp. If they add multiple language # support, this should probably get updated to install steps and/or @@ -363,7 +459,14 @@ Usage: $0 { cpp | ruby21 | ruby22 | jruby | - ruby_all) + ruby_all | + php5.5 | + php5.5_c | + php5.6 | + php5.6_c | + php7.0 | + php7.0_c | + php_all) " exit 1 fi |