From 97dd175a917fcdf1a0e0421659498a974f3a464a Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 2 Nov 2017 14:16:22 -0700 Subject: [PATCH 01/24] Update version number to 3.5.0 --- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 2 +- java/core/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- src/Makefile.am | 6 +++--- src/google/protobuf/stubs/common.h | 10 +++++----- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Protobuf.podspec b/Protobuf.podspec index d559d18afe..b65ac43c24 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.4.1' + s.version = '3.5.0' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 0d3e5fb368..3e36ddc174 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.4.1],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.5.0],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 5b38241a6b..7cd9dc59f6 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.4.1 + 3.5.0 Google Inc. protobuf-packages https://github.com/google/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 75b381753f..bf7a5e7d20 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.4.1 + 3.5.0 Google Inc. netstandard1.0;net45 true diff --git a/java/core/pom.xml b/java/core/pom.xml index b0925f7456..95f6f7fff1 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.4.1 + 3.5.0 protobuf-java diff --git a/java/pom.xml b/java/pom.xml index bc8e89b57c..fa0d0e1372 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -11,7 +11,7 @@ com.google.protobuf protobuf-parent - 3.4.1 + 3.5.0 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 35afb844c4..c3f2a69a31 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.4.1 + 3.5.0 protobuf-java-util diff --git a/js/package.json b/js/package.json index 5231c84622..50ebdac802 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.4.1", + "version": "3.5.0", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index c6f5a77fd1..742fab939f 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -10,7 +10,7 @@ com.google.protobuf protoc - 3.4.1 + 3.5.0 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 9f1a4f1931..76cb51c30f 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.4.1' +__version__ = '3.5.0' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 96606f06b1..c396382231 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.4.1.1" + s.version = "3.5.0" s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." diff --git a/src/Makefile.am b/src/Makefile.am index 73abb7f2d1..bff3ae5ad7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -183,7 +183,7 @@ nobase_include_HEADERS = \ lib_LTLIBRARIES = libprotobuf-lite.la libprotobuf.la libprotoc.la libprotobuf_lite_la_LIBADD = $(PTHREAD_LIBS) -libprotobuf_lite_la_LDFLAGS = -version-info 14:0:0 -export-dynamic -no-undefined +libprotobuf_lite_la_LDFLAGS = -version-info 15:0:0 -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotobuf_lite_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf-lite.map EXTRA_libprotobuf_lite_la_DEPENDENCIES = libprotobuf-lite.map @@ -232,7 +232,7 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/io/zero_copy_stream_impl_lite.cc libprotobuf_la_LIBADD = $(PTHREAD_LIBS) -libprotobuf_la_LDFLAGS = -version-info 14:0:0 -export-dynamic -no-undefined +libprotobuf_la_LDFLAGS = -version-info 15:0:0 -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotobuf_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf.map EXTRA_libprotobuf_la_DEPENDENCIES = libprotobuf.map @@ -323,7 +323,7 @@ libprotobuf_la_SOURCES = \ nodist_libprotobuf_la_SOURCES = $(nodist_libprotobuf_lite_la_SOURCES) libprotoc_la_LIBADD = $(PTHREAD_LIBS) libprotobuf.la -libprotoc_la_LDFLAGS = -version-info 14:0:0 -export-dynamic -no-undefined +libprotoc_la_LDFLAGS = -version-info 15:0:0 -export-dynamic -no-undefined if HAVE_LD_VERSION_SCRIPT libprotoc_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotoc.map EXTRA_libprotoc_la_DEPENDENCIES = libprotoc.map diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index ff36348292..79bb2396cc 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -101,27 +101,27 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3004000 +#define GOOGLE_PROTOBUF_VERSION 3005000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3004000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3005000 // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 3004000; +static const int kMinHeaderVersionForLibrary = 3005000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3004000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3005000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 3004000; +static const int kMinHeaderVersionForProtoc = 3005000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. From 19080127104b24c3448bc8f9ecc736fd9967d9e3 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 2 Nov 2017 14:29:02 -0700 Subject: [PATCH 02/24] Update generated descritpors. --- src/google/protobuf/any.pb.h | 4 ++-- src/google/protobuf/api.pb.h | 4 ++-- src/google/protobuf/compiler/plugin.pb.h | 4 ++-- src/google/protobuf/descriptor.pb.h | 4 ++-- src/google/protobuf/duration.pb.h | 4 ++-- src/google/protobuf/empty.pb.h | 4 ++-- src/google/protobuf/field_mask.pb.h | 4 ++-- src/google/protobuf/source_context.pb.h | 4 ++-- src/google/protobuf/struct.pb.h | 4 ++-- src/google/protobuf/timestamp.pb.h | 4 ++-- src/google/protobuf/type.pb.h | 4 ++-- src/google/protobuf/wrappers.pb.h | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 20a1cbedbf..580acc6ae2 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index e74528e1c2..26af28fb55 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 8f92b6aed4..c3d96e83e1 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index ee3ad7d705..1a35681b74 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 0489df43a2..555122aa23 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 1d7c588774..b7f32f4e1f 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 3275dc5407..9b9032c451 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 1e5499ca40..fdab394caa 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 83b7da6d67..36b56e9544 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 4ec7f0a020..3d5ee5ca2d 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 85bd660fd6..e080339e6e 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index be49c3ec47..9c1ed5f26a 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3004000 +#if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. From 2df472690ec878ff75a2ccea0c7ff6df0ff69ee3 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Sat, 4 Nov 2017 09:33:56 -0700 Subject: [PATCH 03/24] Fix php well known type conformance tests (#3828) (#3840) * Fix php well known type conformance tests * Properly generate code for test.proto * Provide GPBMetadata files in c extensions for generated files to import. * Remove unnecessary test * Clean up code * Add declaration for initOnce. * Refactoring --- conformance/Makefile.am | 4 +- conformance/autoload.php | 2 +- conformance/conformance_php.php | 31 +- conformance/failure_list_php.txt | 87 +----- php/ext/google/protobuf/message.c | 42 +++ php/ext/google/protobuf/protobuf.c | 11 + php/ext/google/protobuf/protobuf.h | 24 +- php/src/Google/Protobuf/Any.php | 8 +- .../Google/Protobuf/Internal/GPBJsonWire.php | 47 ++- php/src/Google/Protobuf/Internal/GPBUtil.php | 139 ++++++++- php/src/Google/Protobuf/Internal/Message.php | 286 ++++++++++++++++-- tests.sh | 3 +- 12 files changed, 520 insertions(+), 164 deletions(-) diff --git a/conformance/Makefile.am b/conformance/Makefile.am index f7ce053bda..765f3588ff 100644 --- a/conformance/Makefile.am +++ b/conformance/Makefile.am @@ -256,7 +256,7 @@ if USE_EXTERNAL_PROTOC protoc_middleman: $(conformance_protoc_inputs) $(conformance_proto2_protoc_inputs) $(well_known_type_protoc_inputs) google-protobuf $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --objc_out=. --python_out=. --php_out=. --js_out=import_style=commonjs,binary:. $(conformance_protoc_inputs) $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --objc_out=. --python_out=. --js_out=import_style=commonjs,binary:. $(conformance_proto2_protoc_inputs) - $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --python_out=. --php_out=. --js_out=import_style=commonjs,binary:google-protobuf $(well_known_type_protoc_inputs) + $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --python_out=. --js_out=import_style=commonjs,binary:google-protobuf $(well_known_type_protoc_inputs) ## $(PROTOC) -I$(srcdir) -I$(top_srcdir) --java_out=lite:lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) touch protoc_middleman @@ -268,7 +268,7 @@ else protoc_middleman: $(top_srcdir)/src/protoc$(EXEEXT) $(conformance_protoc_inputs) $(conformance_proto2_protoc_inputs) $(well_known_type_protoc_inputs) google-protobuf oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --objc_out=$$oldpwd --python_out=$$oldpwd --php_out=$$oldpwd --js_out=import_style=commonjs,binary:$$oldpwd $(conformance_protoc_inputs) ) oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --objc_out=. --python_out=$$oldpwd --js_out=import_style=commonjs,binary:$$oldpwd $(conformance_proto2_protoc_inputs) ) - oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --python_out=$$oldpwd --php_out=$$oldpwd --js_out=import_style=commonjs,binary:$$oldpwd/google-protobuf $(well_known_type_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --python_out=$$oldpwd --js_out=import_style=commonjs,binary:$$oldpwd/google-protobuf $(well_known_type_protoc_inputs) ) ## @mkdir -p lite ## oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --java_out=lite:$$oldpwd/lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) ) touch protoc_middleman diff --git a/conformance/autoload.php b/conformance/autoload.php index 2cee31c476..0f49aecb16 100644 --- a/conformance/autoload.php +++ b/conformance/autoload.php @@ -2,7 +2,7 @@ define("GOOGLE_INTERNAL_NAMESPACE", "Google\\Protobuf\\Internal\\"); define("GOOGLE_NAMESPACE", "Google\\Protobuf\\"); -define("GOOGLE_GPBMETADATA_NAMESPACE", "GPBMetadata\\Google\\Protobuf\\Internal\\"); +define("GOOGLE_GPBMETADATA_NAMESPACE", "GPBMetadata\\Google\\Protobuf\\"); function protobuf_autoloader_impl($class, $prefix) { $length = strlen($prefix); diff --git a/conformance/conformance_php.php b/conformance/conformance_php.php index 4dc18f591f..19f9a0926c 100755 --- a/conformance/conformance_php.php +++ b/conformance/conformance_php.php @@ -3,24 +3,6 @@ require_once("Conformance/WireFormat.php"); require_once("Conformance/ConformanceResponse.php"); require_once("Conformance/ConformanceRequest.php"); -require_once("Google/Protobuf/Any.php"); -require_once("Google/Protobuf/Duration.php"); -require_once("Google/Protobuf/FieldMask.php"); -require_once("Google/Protobuf/Struct.php"); -require_once("Google/Protobuf/Value.php"); -require_once("Google/Protobuf/ListValue.php"); -require_once("Google/Protobuf/NullValue.php"); -require_once("Google/Protobuf/Timestamp.php"); -require_once("Google/Protobuf/DoubleValue.php"); -require_once("Google/Protobuf/BytesValue.php"); -require_once("Google/Protobuf/FloatValue.php"); -require_once("Google/Protobuf/Int64Value.php"); -require_once("Google/Protobuf/UInt32Value.php"); -require_once("Google/Protobuf/BoolValue.php"); -require_once("Google/Protobuf/DoubleValue.php"); -require_once("Google/Protobuf/Int32Value.php"); -require_once("Google/Protobuf/StringValue.php"); -require_once("Google/Protobuf/UInt64Value.php"); require_once("Protobuf_test_messages/Proto3/ForeignMessage.php"); require_once("Protobuf_test_messages/Proto3/ForeignEnum.php"); require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3.php"); @@ -28,12 +10,6 @@ require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3_NestedMessage.php require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3_NestedEnum.php"); require_once("GPBMetadata/Conformance.php"); -require_once("GPBMetadata/Google/Protobuf/Any.php"); -require_once("GPBMetadata/Google/Protobuf/Duration.php"); -require_once("GPBMetadata/Google/Protobuf/FieldMask.php"); -require_once("GPBMetadata/Google/Protobuf/Struct.php"); -require_once("GPBMetadata/Google/Protobuf/Timestamp.php"); -require_once("GPBMetadata/Google/Protobuf/Wrappers.php"); require_once("GPBMetadata/Google/Protobuf/TestMessagesProto3.php"); use \Conformance\WireFormat; @@ -78,7 +54,12 @@ function doTest($request) } elseif ($request->getRequestedOutputFormat() == WireFormat::PROTOBUF) { $response->setProtobufPayload($test_message->serializeToString()); } elseif ($request->getRequestedOutputFormat() == WireFormat::JSON) { - $response->setJsonPayload($test_message->serializeToJsonString()); + try { + $response->setJsonPayload($test_message->serializeToJsonString()); + } catch (Exception $e) { + $response->setSerializeError($e->getMessage()); + return $response; + } } return $response; diff --git a/conformance/failure_list_php.txt b/conformance/failure_list_php.txt index c1713cb1ce..0d2341127e 100644 --- a/conformance/failure_list_php.txt +++ b/conformance/failure_list_php.txt @@ -7,92 +7,7 @@ Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas9FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHasZeroFractionalDigit.Validator -Required.DurationProtoInputTooLarge.JsonOutput -Required.DurationProtoInputTooSmall.JsonOutput -Required.Proto3.JsonInput.Any.JsonOutput -Required.Proto3.JsonInput.Any.ProtobufOutput -Required.Proto3.JsonInput.AnyNested.JsonOutput -Required.Proto3.JsonInput.AnyNested.ProtobufOutput -Required.Proto3.JsonInput.AnyUnorderedTypeTag.JsonOutput -Required.Proto3.JsonInput.AnyUnorderedTypeTag.ProtobufOutput -Required.Proto3.JsonInput.AnyWithDuration.JsonOutput -Required.Proto3.JsonInput.AnyWithDuration.ProtobufOutput -Required.Proto3.JsonInput.AnyWithFieldMask.JsonOutput -Required.Proto3.JsonInput.AnyWithFieldMask.ProtobufOutput -Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.JsonOutput -Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput -Required.Proto3.JsonInput.AnyWithStruct.JsonOutput -Required.Proto3.JsonInput.AnyWithStruct.ProtobufOutput -Required.Proto3.JsonInput.AnyWithTimestamp.JsonOutput -Required.Proto3.JsonInput.AnyWithTimestamp.ProtobufOutput -Required.Proto3.JsonInput.AnyWithValueForInteger.JsonOutput -Required.Proto3.JsonInput.AnyWithValueForInteger.ProtobufOutput -Required.Proto3.JsonInput.AnyWithValueForJsonObject.JsonOutput -Required.Proto3.JsonInput.AnyWithValueForJsonObject.ProtobufOutput -Required.Proto3.JsonInput.DurationMaxValue.JsonOutput -Required.Proto3.JsonInput.DurationMaxValue.ProtobufOutput -Required.Proto3.JsonInput.DurationMinValue.JsonOutput -Required.Proto3.JsonInput.DurationMinValue.ProtobufOutput -Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput -Required.Proto3.JsonInput.DurationRepeatedValue.ProtobufOutput -Required.Proto3.JsonInput.FieldMask.JsonOutput -Required.Proto3.JsonInput.FieldMask.ProtobufOutput -Required.Proto3.JsonInput.OptionalBoolWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalBoolWrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalBytesWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalBytesWrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalDoubleWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalDoubleWrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalFloatWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalFloatWrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalInt32Wrapper.JsonOutput -Required.Proto3.JsonInput.OptionalInt32Wrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalInt64Wrapper.JsonOutput -Required.Proto3.JsonInput.OptionalInt64Wrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalStringWrapper.JsonOutput -Required.Proto3.JsonInput.OptionalStringWrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalUint32Wrapper.JsonOutput -Required.Proto3.JsonInput.OptionalUint32Wrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalUint64Wrapper.JsonOutput -Required.Proto3.JsonInput.OptionalUint64Wrapper.ProtobufOutput -Required.Proto3.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput -Required.Proto3.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput -Required.Proto3.JsonInput.RepeatedBoolWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedBoolWrapper.ProtobufOutput -Required.Proto3.JsonInput.RepeatedBytesWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedBytesWrapper.ProtobufOutput -Required.Proto3.JsonInput.RepeatedDoubleWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedDoubleWrapper.ProtobufOutput -Required.Proto3.JsonInput.RepeatedFloatWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedFloatWrapper.ProtobufOutput -Required.Proto3.JsonInput.RepeatedInt32Wrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedInt32Wrapper.ProtobufOutput -Required.Proto3.JsonInput.RepeatedInt64Wrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedInt64Wrapper.ProtobufOutput -Required.Proto3.JsonInput.RepeatedStringWrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedStringWrapper.ProtobufOutput -Required.Proto3.JsonInput.RepeatedUint32Wrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedUint32Wrapper.ProtobufOutput -Required.Proto3.JsonInput.RepeatedUint64Wrapper.JsonOutput -Required.Proto3.JsonInput.RepeatedUint64Wrapper.ProtobufOutput -Required.Proto3.JsonInput.Struct.JsonOutput -Required.Proto3.JsonInput.Struct.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptBool.JsonOutput -Required.Proto3.JsonInput.ValueAcceptBool.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptFloat.JsonOutput -Required.Proto3.JsonInput.ValueAcceptFloat.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptInteger.JsonOutput -Required.Proto3.JsonInput.ValueAcceptInteger.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptList.JsonOutput -Required.Proto3.JsonInput.ValueAcceptList.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptNull.JsonOutput -Required.Proto3.JsonInput.ValueAcceptNull.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptObject.JsonOutput -Required.Proto3.JsonInput.ValueAcceptObject.ProtobufOutput -Required.Proto3.JsonInput.ValueAcceptString.JsonOutput -Required.Proto3.JsonInput.ValueAcceptString.ProtobufOutput -Required.TimestampProtoInputTooLarge.JsonOutput -Required.TimestampProtoInputTooSmall.JsonOutput +Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter Required.Proto3.JsonInput.FloatFieldTooLarge Required.Proto3.JsonInput.FloatFieldTooSmall Required.Proto3.JsonInput.DoubleFieldTooSmall diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 291f5c248a..3fce2c1741 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -2029,3 +2029,45 @@ PHP_PROTO_ONEOF_FIELD_ACCESSORS(Value, value, BoolValue, "bool_value") PHP_PROTO_ONEOF_FIELD_ACCESSORS(Value, value, StructValue, "struct_value") PHP_PROTO_ONEOF_FIELD_ACCESSORS(Value, value, ListValue, "list_value") PHP_PROTO_ONEOF_ACCESSORS(Value, value, Kind, "kind") + +// ----------------------------------------------------------------------------- +// GPBMetadata files for well known types +// ----------------------------------------------------------------------------- + +#define DEFINE_GPBMETADATA_FILE(LOWERNAME, CAMELNAME, CLASSNAME) \ + zend_class_entry* gpb_metadata_##LOWERNAME##_type; \ + static zend_function_entry gpb_metadata_##LOWERNAME##_methods[] = { \ + PHP_ME(GPBMetadata_##CAMELNAME, initOnce, NULL, \ + ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) \ + ZEND_FE_END \ + }; \ + void gpb_metadata_##LOWERNAME##_init(TSRMLS_D) { \ + zend_class_entry class_type; \ + INIT_CLASS_ENTRY(class_type, CLASSNAME, \ + gpb_metadata_##LOWERNAME##_methods); \ + gpb_metadata_##LOWERNAME##_type = \ + zend_register_internal_class(&class_type TSRMLS_CC); \ + } \ + PHP_METHOD(GPBMetadata_##CAMELNAME, initOnce) { \ + init_file_##LOWERNAME(TSRMLS_C); \ + } + +DEFINE_GPBMETADATA_FILE(any, Any, "GPBMetadata\\Google\\Protobuf\\Any"); +DEFINE_GPBMETADATA_FILE(api, Api, "GPBMetadata\\Google\\Protobuf\\Api"); +DEFINE_GPBMETADATA_FILE(duration, Duration, + "GPBMetadata\\Google\\Protobuf\\Duration"); +DEFINE_GPBMETADATA_FILE(field_mask, FieldMask, + "GPBMetadata\\Google\\Protobuf\\FieldMask"); +DEFINE_GPBMETADATA_FILE(empty, Empty, + "GPBMetadata\\Google\\Protobuf\\GPBEmpty"); +DEFINE_GPBMETADATA_FILE(source_context, SourceContext, + "GPBMetadata\\Google\\Protobuf\\SourceContext"); +DEFINE_GPBMETADATA_FILE(struct, Struct, + "GPBMetadata\\Google\\Protobuf\\Struct"); +DEFINE_GPBMETADATA_FILE(timestamp, Timestamp, + "GPBMetadata\\Google\\Protobuf\\Timestamp"); +DEFINE_GPBMETADATA_FILE(type, Type, "GPBMetadata\\Google\\Protobuf\\Type"); +DEFINE_GPBMETADATA_FILE(wrappers, Wrappers, + "GPBMetadata\\Google\\Protobuf\\Wrappers"); + +#undef DEFINE_GPBMETADATA_FILE diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index b67089e0c9..265d636e3a 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -300,6 +300,17 @@ static PHP_MINIT_FUNCTION(protobuf) { repeated_field_iter_init(TSRMLS_C); util_init(TSRMLS_C); + gpb_metadata_any_init(TSRMLS_C); + gpb_metadata_api_init(TSRMLS_C); + gpb_metadata_duration_init(TSRMLS_C); + gpb_metadata_field_mask_init(TSRMLS_C); + gpb_metadata_empty_init(TSRMLS_C); + gpb_metadata_source_context_init(TSRMLS_C); + gpb_metadata_struct_init(TSRMLS_C); + gpb_metadata_timestamp_init(TSRMLS_C); + gpb_metadata_type_init(TSRMLS_C); + gpb_metadata_wrappers_init(TSRMLS_C); + any_init(TSRMLS_C); api_init(TSRMLS_C); bool_value_init(TSRMLS_C); diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index cb0987477c..1834377297 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -610,7 +610,6 @@ typedef struct BytesValue BytesValue; typedef struct Descriptor Descriptor; typedef struct Descriptor Descriptor; typedef struct DescriptorPool DescriptorPool; -typedef struct DescriptorPool DescriptorPool; typedef struct DoubleValue DoubleValue; typedef struct Duration Duration; typedef struct Enum Enum; @@ -630,7 +629,6 @@ typedef struct GPBEmpty GPBEmpty; typedef struct Int32Value Int32Value; typedef struct Int64Value Int64Value; typedef struct InternalDescriptorPool InternalDescriptorPool; -typedef struct InternalDescriptorPool InternalDescriptorPool; typedef struct ListValue ListValue; typedef struct Map Map; typedef struct Map Map; @@ -714,6 +712,17 @@ void uint64_value_init(TSRMLS_D); void util_init(TSRMLS_D); void value_init(TSRMLS_D); +void gpb_metadata_any_init(TSRMLS_D); +void gpb_metadata_api_init(TSRMLS_D); +void gpb_metadata_duration_init(TSRMLS_D); +void gpb_metadata_field_mask_init(TSRMLS_D); +void gpb_metadata_empty_init(TSRMLS_D); +void gpb_metadata_source_context_init(TSRMLS_D); +void gpb_metadata_struct_init(TSRMLS_D); +void gpb_metadata_timestamp_init(TSRMLS_D); +void gpb_metadata_type_init(TSRMLS_D); +void gpb_metadata_wrappers_init(TSRMLS_D); + // Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor // instances. void add_def_obj(const void* def, PHP_PROTO_HASHTABLE_VALUE value); @@ -1170,6 +1179,17 @@ extern zend_class_entry* oneof_descriptor_type; // Well Known Type. // ----------------------------------------------------------------------------- +PHP_METHOD(GPBMetadata_Any, initOnce); +PHP_METHOD(GPBMetadata_Api, initOnce); +PHP_METHOD(GPBMetadata_Duration, initOnce); +PHP_METHOD(GPBMetadata_FieldMask, initOnce); +PHP_METHOD(GPBMetadata_Empty, initOnce); +PHP_METHOD(GPBMetadata_SourceContext, initOnce); +PHP_METHOD(GPBMetadata_Struct, initOnce); +PHP_METHOD(GPBMetadata_Timestamp, initOnce); +PHP_METHOD(GPBMetadata_Type, initOnce); +PHP_METHOD(GPBMetadata_Wrappers, initOnce); + PHP_METHOD(Any, __construct); PHP_METHOD(Any, getTypeUrl); PHP_METHOD(Any, setTypeUrl); diff --git a/php/src/Google/Protobuf/Any.php b/php/src/Google/Protobuf/Any.php index a39c4e6ab9..91ba4bd5d0 100644 --- a/php/src/Google/Protobuf/Any.php +++ b/php/src/Google/Protobuf/Any.php @@ -207,9 +207,9 @@ class Any extends \Google\Protobuf\Internal\Message public function unpack() { // Get fully qualifed name from type url. - $url_prifix_len = strlen(Any::TYPE_URL_PREFIX); + $url_prifix_len = strlen(GPBUtil::TYPE_URL_PREFIX); if (substr($this->type_url, 0, $url_prifix_len) != - Any::TYPE_URL_PREFIX) { + GPBUtil::TYPE_URL_PREFIX) { throw new \Exception( "Type url needs to be type.googleapis.com/fully-qulified"); } @@ -251,7 +251,7 @@ class Any extends \Google\Protobuf\Internal\Message $pool = DescriptorPool::getGeneratedPool(); $desc = $pool->getDescriptorByClassName(get_class($msg)); $fully_qualifed_name = $desc->getFullName(); - $this->type_url = Any::TYPE_URL_PREFIX.substr( + $this->type_url = GPBUtil::TYPE_URL_PREFIX.substr( $fully_qualifed_name, 1, strlen($fully_qualifed_name)); } @@ -265,7 +265,7 @@ class Any extends \Google\Protobuf\Internal\Message $pool = DescriptorPool::getGeneratedPool(); $desc = $pool->getDescriptorByClassName($klass); $fully_qualifed_name = $desc->getFullName(); - $type_url = Any::TYPE_URL_PREFIX.substr( + $type_url = GPBUtil::TYPE_URL_PREFIX.substr( $fully_qualifed_name, 1, strlen($fully_qualifed_name)); return $this->type_url === $type_url; } diff --git a/php/src/Google/Protobuf/Internal/GPBJsonWire.php b/php/src/Google/Protobuf/Internal/GPBJsonWire.php index 97789356c2..9ae57ab36c 100644 --- a/php/src/Google/Protobuf/Internal/GPBJsonWire.php +++ b/php/src/Google/Protobuf/Internal/GPBJsonWire.php @@ -38,19 +38,26 @@ class GPBJsonWire public static function serializeFieldToStream( $value, $field, - &$output) + &$output, $has_field_name = true) { - $output->writeRaw("\"", 1); - $field_name = GPBJsonWire::formatFieldName($field); - $output->writeRaw($field_name, strlen($field_name)); - $output->writeRaw("\":", 2); - return static::serializeFieldValueToStream($value, $field, $output); + if ($has_field_name) { + $output->writeRaw("\"", 1); + $field_name = GPBJsonWire::formatFieldName($field); + $output->writeRaw($field_name, strlen($field_name)); + $output->writeRaw("\":", 2); + } + return static::serializeFieldValueToStream( + $value, + $field, + $output, + !$has_field_name); } - private static function serializeFieldValueToStream( + public static function serializeFieldValueToStream( $values, $field, - &$output) + &$output, + $is_well_known = false) { if ($field->isMap()) { $output->writeRaw("{", 1); @@ -84,7 +91,8 @@ class GPBJsonWire if (!static::serializeSingularFieldValueToStream( $key, $key_field, - $output)) { + $output, + $is_well_known)) { return false; } if ($additional_quote) { @@ -94,7 +102,8 @@ class GPBJsonWire if (!static::serializeSingularFieldValueToStream( $value, $value_field, - $output)) { + $output, + $is_well_known)) { return false; } } @@ -112,7 +121,8 @@ class GPBJsonWire if (!static::serializeSingularFieldValueToStream( $value, $field, - $output)) { + $output, + $is_well_known)) { return false; } } @@ -122,14 +132,15 @@ class GPBJsonWire return static::serializeSingularFieldValueToStream( $values, $field, - $output); + $output, + $is_well_known); } } private static function serializeSingularFieldValueToStream( $value, $field, - &$output) + &$output, $is_well_known = false) { switch ($field->getType()) { case GPBType::SFIXED32: @@ -186,6 +197,10 @@ class GPBJsonWire break; case GPBType::ENUM: $enum_desc = $field->getEnumType(); + if ($enum_desc->getClass() === "Google\Protobuf\NullValue") { + $output->writeRaw("null", 4); + break; + } $enum_value_desc = $enum_desc->getValueByNumber($value); if (!is_null($enum_value_desc)) { $str_value = $enum_value_desc->getName(); @@ -205,7 +220,11 @@ class GPBJsonWire } break; case GPBType::BYTES: - $value = base64_encode($value); + $bytes_value = base64_encode($value); + $output->writeRaw("\"", 1); + $output->writeRaw($bytes_value, strlen($bytes_value)); + $output->writeRaw("\"", 1); + break; case GPBType::STRING: $value = json_encode($value); $output->writeRaw($value, strlen($value)); diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 7fa4a67374..76f84cbdfb 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -32,14 +32,29 @@ namespace Google\Protobuf\Internal; +use Google\Protobuf\Duration; +use Google\Protobuf\FieldMask; use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\MapField; +function camel2underscore($input) { + preg_match_all( + '!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', + $input, + $matches); + $ret = $matches[0]; + foreach ($ret as &$match) { + $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match); + } + return implode('_', $ret); +} + class GPBUtil { const NANOS_PER_MILLISECOND = 1000000; const NANOS_PER_MICROSECOND = 1000; + const TYPE_URL_PREFIX = 'type.googleapis.com/'; public static function divideInt64ToInt32($value, &$high, &$low, $trim = false) { @@ -358,7 +373,7 @@ class GPBUtil } return $result; } - + public static function parseTimestamp($timestamp) { // prevent parsing timestamps containing with the non-existant year "0000" @@ -370,7 +385,7 @@ class GPBUtil if (substr($timestamp, -1, 1) === "z") { throw new \Exception("Timezone cannot be a lowercase z."); } - + $nanoseconds = 0; $periodIndex = strpos($timestamp, "."); if ($periodIndex !== false) { @@ -411,9 +426,15 @@ class GPBUtil $value->setNanos($nanoseconds); return $value; } - + public static function formatTimestamp($value) { + if (bccomp($value->getSeconds(), "253402300800") != -1) { + throw new GPBDecodeException("Duration number too large."); + } + if (bccomp($value->getSeconds(), "-62135596801") != 1) { + throw new GPBDecodeException("Duration number too small."); + } $nanoseconds = static::getNanosecondsForTimestamp($value->getNanos()); if (!empty($nanoseconds)) { $nanoseconds = ".".$nanoseconds; @@ -422,6 +443,93 @@ class GPBUtil return $date->format("Y-m-d\TH:i:s".$nanoseconds."\Z"); } + public static function parseDuration($value) + { + if (strlen($value) < 2 || substr($value, -1) !== "s") { + throw new GPBDecodeException("Missing s after duration string"); + } + $number = substr($value, 0, -1); + if (bccomp($number, "315576000001") != -1) { + throw new GPBDecodeException("Duration number too large."); + } + if (bccomp($number, "-315576000001") != 1) { + throw new GPBDecodeException("Duration number too small."); + } + $pos = strrpos($number, "."); + if ($pos !== false) { + $seconds = substr($number, 0, $pos); + if (bccomp($seconds, 0) < 0) { + $nanos = bcmul("0" . substr($number, $pos), -1000000000); + } else { + $nanos = bcmul("0" . substr($number, $pos), 1000000000); + } + } else { + $seconds = $number; + $nanos = 0; + } + $duration = new Duration(); + $duration->setSeconds($seconds); + $duration->setNanos($nanos); + return $duration; + } + + public static function formatDuration($value) + { + if (bccomp($value->getSeconds(), "315576000001") != -1) { + throw new GPBDecodeException("Duration number too large."); + } + if (bccomp($value->getSeconds(), "-315576000001") != 1) { + throw new GPBDecodeException("Duration number too small."); + } + return strval(bcadd($value->getSeconds(), + $value->getNanos() / 1000000000.0, 9)); + } + + + + public static function parseFieldMask($paths_string) + { + $path_strings = explode(",", $paths_string); + $field_mask = new FieldMask(); + $paths = $field_mask->getPaths(); + foreach($path_strings as &$path_string) { + $field_strings = explode(".", $path_string); + foreach($field_strings as &$field_string) { + $field_string = camel2underscore($field_string); + } + $path_string = implode(".", $field_strings); + $paths[] = $path_string; + } + return $field_mask; + } + + public static function formatFieldMask($field_mask) + { + $converted_paths = []; + foreach($field_mask->getPaths() as $path) { + $fields = explode('.', $path); + $converted_path = []; + foreach ($fields as $field) { + $segments = explode('_', $field); + $start = true; + $converted_segments = ""; + foreach($segments as $segment) { + if (!$start) { + $converted = ucfirst($segment); + } else { + $converted = $segment; + $start = false; + } + $converted_segments .= $converted; + } + $converted_path []= $converted_segments; + } + $converted_path = implode(".", $converted_path); + $converted_paths []= $converted_path; + } + return implode(",", $converted_paths); + } + public static function getNanosecondsForTimestamp($nanoseconds) { if ($nanoseconds == 0) { @@ -435,4 +543,29 @@ class GPBUtil } return sprintf('%09d', $nanoseconds); } + + public static function hasSpecialJsonMapping($msg) + { + return is_a($msg, 'Google\Protobuf\Any') || + is_a($msg, "Google\Protobuf\ListValue") || + is_a($msg, "Google\Protobuf\Struct") || + is_a($msg, "Google\Protobuf\Value") || + is_a($msg, "Google\Protobuf\Duration") || + is_a($msg, "Google\Protobuf\Timestamp") || + is_a($msg, "Google\Protobuf\FieldMask") || + static::hasJsonValue($msg); + } + + public static function hasJsonValue($msg) + { + return is_a($msg, "Google\Protobuf\DoubleValue") || + is_a($msg, "Google\Protobuf\FloatValue") || + is_a($msg, "Google\Protobuf\Int64Value") || + is_a($msg, "Google\Protobuf\UInt64Value") || + is_a($msg, "Google\Protobuf\Int32Value") || + is_a($msg, "Google\Protobuf\UInt32Value") || + is_a($msg, "Google\Protobuf\BoolValue") || + is_a($msg, "Google\Protobuf\StringValue") || + is_a($msg, "Google\Protobuf\BytesValue"); + } } diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index b3c4e6f18d..9785be302a 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -44,6 +44,10 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\MapEntry; use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\ListValue; +use Google\Protobuf\Value; +use Google\Protobuf\Struct; +use Google\Protobuf\NullValue; /** * Parent class of all proto messages. Users should not instantiate this class @@ -701,16 +705,22 @@ class Message $field, $is_map_key = false) { - if (is_null($value)) { - return $this->defaultValue($field); - } switch ($field->getType()) { case GPBType::MESSAGE: $klass = $field->getMessageType()->getClass(); $submsg = new $klass; - if ($field->isTimestamp()) { - if (!is_string($value)) { + if (is_a($submsg, "Google\Protobuf\Duration")) { + if (is_null($value)) { + return $this->defaultValue($field); + } else if (!is_string($value)) { + throw new GPBDecodeException("Expect string."); + } + return GPBUtil::parseDuration($value); + } else if ($field->isTimestamp()) { + if (is_null($value)) { + return $this->defaultValue($field); + } else if (!is_string($value)) { throw new GPBDecodeException("Expect string."); } try { @@ -721,16 +731,31 @@ class Message $submsg->setSeconds($timestamp->getSeconds()); $submsg->setNanos($timestamp->getNanos()); - } else if ($klass !== "Google\Protobuf\Any") { - if (!is_object($value) && !is_array($value)) { + } else if (is_a($submsg, "Google\Protobuf\FieldMask")) { + if (is_null($value)) { + return $this->defaultValue($field); + } + try { + return GPBUtil::parseFieldMask($value); + } catch (\Exception $e) { + throw new GPBDecodeException("Invalid FieldMask: ".$e->getMessage()); + } + } else { + if (is_null($value) && + !is_a($submsg, "Google\Protobuf\Value")) { + return $this->defaultValue($field); + } + if (GPBUtil::hasSpecialJsonMapping($submsg)) { + } elseif (!is_object($value) && !is_array($value)) { throw new GPBDecodeException("Expect message."); } - $submsg->mergeFromJsonArray($value); } return $submsg; case GPBType::ENUM: - if (is_integer($value)) { + if (is_null($value)) { + return $this->defaultValue($field); + } else if (is_integer($value)) { return $value; } else { $enum_value = @@ -740,11 +765,17 @@ class Message return $enum_value->getNumber(); } case GPBType::STRING: + if (is_null($value)) { + return $this->defaultValue($field); + } if (!is_string($value)) { throw new GPBDecodeException("Expect string"); } return $value; case GPBType::BYTES: + if (is_null($value)) { + return $this->defaultValue($field); + } if (!is_string($value)) { throw new GPBDecodeException("Expect string"); } @@ -755,6 +786,9 @@ class Message } return $proto_value; case GPBType::BOOL: + if (is_null($value)) { + return $this->defaultValue($field); + } if ($is_map_key) { if ($value === "true") { return true; @@ -771,6 +805,9 @@ class Message } return $value; case GPBType::FLOAT: + if (is_null($value)) { + return $this->defaultValue($field); + } if ($value === "Infinity") { return INF; } @@ -782,6 +819,9 @@ class Message } return $value; case GPBType::DOUBLE: + if (is_null($value)) { + return $this->defaultValue($field); + } if ($value === "Infinity") { return INF; } @@ -793,6 +833,9 @@ class Message } return $value; case GPBType::INT32: + if (is_null($value)) { + return $this->defaultValue($field); + } if (!is_numeric($value)) { throw new GPBDecodeException( "Invalid data type for int32 field"); @@ -807,6 +850,9 @@ class Message } return $value; case GPBType::UINT32: + if (is_null($value)) { + return $this->defaultValue($field); + } if (!is_numeric($value)) { throw new GPBDecodeException( "Invalid data type for uint32 field"); @@ -817,6 +863,9 @@ class Message } return $value; case GPBType::INT64: + if (is_null($value)) { + return $this->defaultValue($field); + } if (!is_numeric($value)) { throw new GPBDecodeException( "Invalid data type for int64 field"); @@ -831,6 +880,9 @@ class Message } return $value; case GPBType::UINT64: + if (is_null($value)) { + return $this->defaultValue($field); + } if (!is_numeric($value)) { throw new GPBDecodeException( "Invalid data type for int64 field"); @@ -844,14 +896,107 @@ class Message } return $value; case GPBType::FIXED64: + if (is_null($value)) { + return $this->defaultValue($field); + } return $value; default: return $value; } } - private function mergeFromJsonArray($array) + protected function mergeFromJsonArray($array) { + if (is_a($this, "Google\Protobuf\Any")) { + $this->clear(); + $this->setTypeUrl($array["@type"]); + $msg = $this->unpack(); + if (GPBUtil::hasSpecialJsonMapping($msg)) { + $msg->mergeFromJsonArray($array["value"]); + } else { + unset($array["@type"]); + $msg->mergeFromJsonArray($array); + } + $this->setValue($msg->serializeToString()); + return; + } + if (is_a($this, "Google\Protobuf\DoubleValue") || + is_a($this, "Google\Protobuf\FloatValue") || + is_a($this, "Google\Protobuf\Int64Value") || + is_a($this, "Google\Protobuf\UInt64Value") || + is_a($this, "Google\Protobuf\Int32Value") || + is_a($this, "Google\Protobuf\UInt32Value") || + is_a($this, "Google\Protobuf\BoolValue") || + is_a($this, "Google\Protobuf\StringValue")) { + $this->setValue($array); + return; + } + if (is_a($this, "Google\Protobuf\BytesValue")) { + $this->setValue(base64_decode($array)); + return; + } + if (is_a($this, "Google\Protobuf\Duration")) { + $this->mergeFrom(GPBUtil::parseDuration($array)); + return; + } + if (is_a($this, "Google\Protobuf\FieldMask")) { + $this->mergeFrom(GPBUtil::parseFieldMask($array)); + return; + } + if (is_a($this, "Google\Protobuf\Timestamp")) { + $this->mergeFrom(GPBUtil::parseTimestamp($array)); + return; + } + if (is_a($this, "Google\Protobuf\Struct")) { + $fields = $this->getFields(); + foreach($array as $key => $value) { + $v = new Value(); + $v->mergeFromJsonArray($value); + $fields[$key] = $v; + } + } + if (is_a($this, "Google\Protobuf\Value")) { + if (is_bool($array)) { + $this->setBoolValue($array); + } elseif (is_string($array)) { + $this->setStringValue($array); + } elseif (is_null($array)) { + $this->setNullValue(0); + } elseif (is_double($array) || is_integer($array)) { + $this->setNumberValue($array); + } elseif (is_array($array)) { + if (array_values($array) !== $array) { + // Associative array + $struct_value = $this->getStructValue(); + if (is_null($struct_value)) { + $struct_value = new Struct(); + $this->setStructValue($struct_value); + } + foreach ($array as $key => $v) { + $value = new Value(); + $value->mergeFromJsonArray($v); + $values = $struct_value->getFields(); + $values[$key]= $value; + } + } else { + // Array + $list_value = $this->getListValue(); + if (is_null($list_value)) { + $list_value = new ListValue(); + $this->setListValue($list_value); + } + foreach ($array as $v) { + $value = new Value(); + $value->mergeFromJsonArray($v); + $values = $list_value->getValues(); + $values[]= $value; + } + } + } else { + throw new GPBDecodeException("Invalid type for Value."); + } + return; + } foreach ($array as $key => $value) { $field = $this->desc->getFieldByJsonName($key); if (is_null($field)) { @@ -1037,7 +1182,8 @@ class Message { $getter = $field->getGetter(); $values = $this->$getter(); - return GPBJsonWire::serializeFieldToStream($values, $field, $output); + return GPBJsonWire::serializeFieldToStream( + $values, $field, $output, !GPBUtil::hasSpecialJsonMapping($this)); } /** @@ -1060,16 +1206,57 @@ class Message */ public function serializeToJsonStream(&$output) { - if (get_class($this) === 'Google\Protobuf\Timestamp') { + if (is_a($this, 'Google\Protobuf\Any')) { + $output->writeRaw("{", 1); + $type_field = $this->desc->getFieldByNumber(1); + $value_msg = $this->unpack(); + + // Serialize type url. + $output->writeRaw("\"@type\":", 8); + $output->writeRaw("\"", 1); + $output->writeRaw($this->getTypeUrl(), strlen($this->getTypeUrl())); + $output->writeRaw("\"", 1); + + // Serialize value + if (GPBUtil::hasSpecialJsonMapping($value_msg)) { + $output->writeRaw(",\"value\":", 9); + $value_msg->serializeToJsonStream($output); + } else { + $value_fields = $value_msg->desc->getField(); + foreach ($value_fields as $field) { + if ($value_msg->existField($field)) { + $output->writeRaw(",", 1); + if (!$value_msg->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } + } + + $output->writeRaw("}", 1); + } elseif (is_a($this, 'Google\Protobuf\FieldMask')) { + $field_mask = GPBUtil::formatFieldMask($this); + $output->writeRaw("\"", 1); + $output->writeRaw($field_mask, strlen($field_mask)); + $output->writeRaw("\"", 1); + } elseif (is_a($this, 'Google\Protobuf\Duration')) { + $duration = GPBUtil::formatDuration($this) . "s"; + $output->writeRaw("\"", 1); + $output->writeRaw($duration, strlen($duration)); + $output->writeRaw("\"", 1); + } elseif (get_class($this) === 'Google\Protobuf\Timestamp') { $timestamp = GPBUtil::formatTimestamp($this); $timestamp = json_encode($timestamp); $output->writeRaw($timestamp, strlen($timestamp)); } else { - $output->writeRaw("{", 1); + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $output->writeRaw("{", 1); + } $fields = $this->desc->getField(); $first = true; foreach ($fields as $field) { - if ($this->existField($field)) { + if ($this->existField($field) || + GPBUtil::hasJsonValue($this)) { if ($first) { $first = false; } else { @@ -1080,7 +1267,9 @@ class Message } } } - $output->writeRaw("}", 1); + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $output->writeRaw("}", 1); + } } return true; } @@ -1263,6 +1452,10 @@ class Message break; case GPBType::ENUM: $enum_desc = $field->getEnumType(); + if ($enum_desc->getClass() === "Google\Protobuf\NullValue") { + $size += 4; + break; + } $enum_value_desc = $enum_desc->getValueByNumber($value); if (!is_null($enum_value_desc)) { $size += 2; // size for "" @@ -1284,6 +1477,12 @@ class Message $size += strlen($value); break; case GPBType::BYTES: + # if (is_a($this, "Google\Protobuf\BytesValue")) { + # $size += strlen(json_encode($value)); + # } else { + # $size += strlen(base64_encode($value)); + # $size += 2; // size for \"\" + # } $size += strlen(base64_encode($value)); $size += 2; // size for \"\" break; @@ -1375,8 +1574,11 @@ class Message $values = $this->$getter(); $count = count($values); if ($count !== 0) { - $size += 5; // size for "\"\":{}". - $size += strlen($field->getJsonName()); // size for field name + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } + $size += 2; // size for "{}". $size += $count - 1; // size for commas $getter = $field->getGetter(); $map_entry = $field->getMessageType(); @@ -1408,17 +1610,22 @@ class Message $values = $this->$getter(); $count = count($values); if ($count !== 0) { - $size += 5; // size for "\"\":[]". - $size += strlen($field->getJsonName()); // size for field name + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } + $size += 2; // size for "[]". $size += $count - 1; // size for commas $getter = $field->getGetter(); foreach ($values as $value) { $size += $this->fieldDataOnlyJsonByteSize($field, $value); } } - } elseif ($this->existField($field)) { - $size += 3; // size for "\"\":". - $size += strlen($field->getJsonName()); // size for field name + } elseif ($this->existField($field) || GPBUtil::hasJsonValue($this)) { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } $getter = $field->getGetter(); $value = $this->$getter(); $size += $this->fieldDataOnlyJsonByteSize($field, $value); @@ -1473,14 +1680,41 @@ class Message public function jsonByteSize() { $size = 0; - if (get_class($this) === 'Google\Protobuf\Timestamp') { + if (is_a($this, 'Google\Protobuf\Any')) { + // Size for "{}". + $size += 2; + + // Size for "\"@type\":". + $size += 8; + + // Size for url. +2 for "" /. + $size += strlen($this->getTypeUrl()) + 2; + + $value_msg = $this->unpack(); + if (GPBUtil::hasSpecialJsonMapping($value_msg)) { + // Size for "\",value\":". + $size += 9; + $size += $value_msg->jsonByteSize(); + } else { + // Size for value. +1 for comma, -2 for "{}". + $size += $value_msg->jsonByteSize() -1; + } + } elseif (get_class($this) === 'Google\Protobuf\FieldMask') { + $field_mask = GPBUtil::formatFieldMask($this); + $size += strlen($field_mask) + 2; // 2 for "" + } elseif (get_class($this) === 'Google\Protobuf\Duration') { + $duration = GPBUtil::formatDuration($this) . "s"; + $size += strlen($duration) + 2; // 2 for "" + } elseif (get_class($this) === 'Google\Protobuf\Timestamp') { $timestamp = GPBUtil::formatTimestamp($this); $timestamp = json_encode($timestamp); $size += strlen($timestamp); } else { - // Size for "{}". - $size += 2; - + if (!GPBUtil::hasSpecialJsonMapping($this)) { + // Size for "{}". + $size += 2; + } + $fields = $this->desc->getField(); $count = 0; foreach ($fields as $field) { diff --git a/tests.sh b/tests.sh index 66baeb15df..6733e83587 100755 --- a/tests.sh +++ b/tests.sh @@ -363,7 +363,8 @@ generate_php_test_proto() { proto/test_service_namespace.proto \ proto/test_descriptors.proto pushd ../../src - ./protoc --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto + ./protoc --php_out=../php/tests/generated -I../php/tests -I. \ + ../php/tests/proto/test_import_descriptor_proto.proto popd popd } From ce2d5282b797372bb67eee318148e4c3be522f58 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 8 Nov 2017 13:50:25 -0800 Subject: [PATCH 04/24] Changelog for 3.5.0 --- CHANGES.txt | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index c83da2d6b6..b6964f8250 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,78 @@ +2017-11-09 version 3.5.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + Planned Future Changes + * Make C++ implementation C++11 only: we plan to require C++11 to build + protobuf code starting from 3.6.0 release. Please join this github issue: + https://github.com/google/protobuf/issues/2780 to provide your feedback. + + General + * Unknown fields are now preserved in proto3 for most of the language + implementations for proto3 by default. See the per-language section for + details. + * reserve keyword are now supported in enums + + C++ + * Proto3 messages are now preserving unknown fields by default. If you rely on + unknowns fields being dropped. Please use DiscardUnknownFields() explicitly. + * Deprecated the unsafe_arena_release_* and unsafe_arena_add_allocated_* + methods for string fields. + * Added move constructor and move assignment to RepeatedField, + RepeatedPtrField and google::protobuf::Any. + * Added perfect forwarding in Arena::CreateMessage + * In-progress experimental support for implicit weak fields with lite protos. + This feature allows the linker to strip out more unused messages and reduce + binary size. + * Various performance optimizations. + + Java + * Proto3 messages are now preserving unknown fields by default. If you’d like + to drop unknown fields, please use the DiscardUnknownFieldsParser  API. For + example: + * Parser parser = DiscardUnknownFieldsParser.wrap(Foo.parser()); + * Foo foo = parser.parseFrom(input); + * Added a new CodedInputStream decoder for Iterable with direct + ByteBuffers. + * TextFormat now prints unknown length-delimited fields as messages if + possible. + * FieldMaskUtil.merge() no longer creates unnecessary empty messages when a + message field is unset in both source message and destination message. + * Various performance optimizations. + + Python + * Proto3 messages are now preserving unknown fields by default. Use + message.DiscardUnknownFields() to drop unknown fields. + * Add FieldDescriptor.file in generated code. + * Add descriptor pool FindOneofByName in pure python. + * Change unknown enum values into unknown field set . + * Add more Python dict/list compatibility for Struct/ListValue. + * Add utf-8 support for text_format.Merge()/Parse(). + * Support numeric unknown enum values for proto3 JSON format. + * Add warning for Unexpected end-group tag in cpp extension. + + PHP + * Proto3 messages are now preserving unknown fields. + * Provide well known type messages in runtime. + * Add prefix ‘PB’ to generated class of reserved names. + * Fixed all conformance tests for encode/decode json in php runtime. C + extension needs more work. + + Objective-C + * Fixed some issues around copying of messages with unknown fields and then + mutating the unknown fields in the copy. + + C# + * Added unknown field support in JsonParser. + * Fixed oneof message field merge. + + Ruby + * Unknown fields are now preserved by default. + * Fixed several bugs for segment fault. + + Javascript + * Decoder can handle both paced and unpacked data no matter how the proto is + defined. + * Decoder now accept long varint for 32 bit integers. + + 2017-08-14 version 3.4.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Planned Future Changes * There are some changes that are not included in this release but are planned From 8a3c5cc992836815cc6fe4169450d8d9f4f63411 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 8 Nov 2017 13:55:55 -0800 Subject: [PATCH 05/24] Fix java code example --- CHANGES.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index b6964f8250..9fe31583ff 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -27,8 +27,8 @@ * Proto3 messages are now preserving unknown fields by default. If you’d like to drop unknown fields, please use the DiscardUnknownFieldsParser  API. For example: - * Parser parser = DiscardUnknownFieldsParser.wrap(Foo.parser()); - * Foo foo = parser.parseFrom(input); + Parser parser = DiscardUnknownFieldsParser.wrap(Foo.parser()); + Foo foo = parser.parseFrom(input); * Added a new CodedInputStream decoder for Iterable with direct ByteBuffers. * TextFormat now prints unknown length-delimited fields as messages if From 181e284b55dd234320b0e4fd5fbc81a5dfa6b580 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 8 Nov 2017 15:27:48 -0800 Subject: [PATCH 06/24] Fix Atomic32/AtomicWord on some platforms. - Removed the redefination in the atomicword_compat.h. Now Atomic32 will alwyas be intptr_t in 32bit platforms, the bridge is no longer needed. - Change NaCl 64bit to use intptr_t instead of int32 for Atomic32, otherwise AtmoicWord APIs will miss the definations. After this change, the AtmoicWord will always be either Atomic32 or Atmoic64 depending on the platforms. --- cmake/extract_includes.bat.in | 1 - src/Makefile.am | 1 - src/google/protobuf/stubs/atomicops.h | 9 +- .../atomicops_internals_atomicword_compat.h | 122 ------------------ 4 files changed, 2 insertions(+), 131 deletions(-) delete mode 100644 src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h diff --git a/cmake/extract_includes.bat.in b/cmake/extract_includes.bat.in index deb6de3bfb..5212d00a15 100644 --- a/cmake/extract_includes.bat.in +++ b/cmake/extract_includes.bat.in @@ -83,7 +83,6 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops.h" in copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm64_gcc.h" include\google\protobuf\stubs\atomicops_internals_arm64_gcc.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm_gcc.h" include\google\protobuf\stubs\atomicops_internals_arm_gcc.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm_qnx.h" include\google\protobuf\stubs\atomicops_internals_arm_qnx.h -copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_atomicword_compat.h" include\google\protobuf\stubs\atomicops_internals_atomicword_compat.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_generic_c11_atomic.h" include\google\protobuf\stubs\atomicops_internals_generic_c11_atomic.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_generic_gcc.h" include\google\protobuf\stubs\atomicops_internals_generic_gcc.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_mips_gcc.h" include\google\protobuf\stubs\atomicops_internals_mips_gcc.h diff --git a/src/Makefile.am b/src/Makefile.am index bff3ae5ad7..1d651dc8c5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -71,7 +71,6 @@ nobase_include_HEADERS = \ google/protobuf/stubs/atomicops_internals_arm64_gcc.h \ google/protobuf/stubs/atomicops_internals_arm_gcc.h \ google/protobuf/stubs/atomicops_internals_arm_qnx.h \ - google/protobuf/stubs/atomicops_internals_atomicword_compat.h \ google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h \ google/protobuf/stubs/atomicops_internals_generic_gcc.h \ google/protobuf/stubs/atomicops_internals_mips_gcc.h \ diff --git a/src/google/protobuf/stubs/atomicops.h b/src/google/protobuf/stubs/atomicops.h index 64c838fbe2..cb4553b1ee 100644 --- a/src/google/protobuf/stubs/atomicops.h +++ b/src/google/protobuf/stubs/atomicops.h @@ -67,15 +67,16 @@ namespace internal { typedef intptr_t Atomic32; typedef int64 Atomic64; #else - typedef int32 Atomic32; // We need to be able to go between Atomic64 and AtomicWord implicitly. This // means Atomic64 and AtomicWord should be the same type on 64-bit. #if defined(__ILP32__) || defined(GOOGLE_PROTOBUF_OS_NACL) // NaCl's intptr_t is not actually 64-bits on 64-bit! // http://code.google.com/p/nativeclient/issues/detail?id=1162 // sparcv9's pointer type is 32bits + typedef intptr_t Atomic32; typedef int64 Atomic64; #else + typedef int32 Atomic32; typedef intptr_t Atomic64; #endif #endif @@ -229,12 +230,6 @@ Atomic64 Release_Load(volatile const Atomic64* ptr); #error GOOGLE_PROTOBUF_ATOMICOPS_ERROR #endif -// On some platforms we need additional declarations to make AtomicWord -// compatible with our other Atomic* types. -#if defined(GOOGLE_PROTOBUF_OS_APPLE) -#include -#endif - #undef GOOGLE_PROTOBUF_ATOMICOPS_ERROR #endif // GOOGLE_PROTOBUF_NO_THREAD_SAFETY diff --git a/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h b/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h deleted file mode 100644 index eb198ff5cc..0000000000 --- a/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h +++ /dev/null @@ -1,122 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ - -// AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32, -// which in turn means int. On some LP32 platforms, intptr_t is an int, but -// on others, it's a long. When AtomicWord and Atomic32 are based on different -// fundamental types, their pointers are incompatible. -// -// This file defines function overloads to allow both AtomicWord and Atomic32 -// data to be used with this interface. -// -// On LP64 platforms, AtomicWord and Atomic64 are both always long, -// so this problem doesn't occur. - -#if !defined(GOOGLE_PROTOBUF_ARCH_64_BIT) - -namespace google { -namespace protobuf { -namespace internal { - -inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr, - AtomicWord old_value, - AtomicWord new_value) { - return NoBarrier_CompareAndSwap( - reinterpret_cast(ptr), old_value, new_value); -} - -inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr, - AtomicWord new_value) { - return NoBarrier_AtomicExchange( - reinterpret_cast(ptr), new_value); -} - -inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr, - AtomicWord increment) { - return NoBarrier_AtomicIncrement( - reinterpret_cast(ptr), increment); -} - -inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr, - AtomicWord increment) { - return Barrier_AtomicIncrement( - reinterpret_cast(ptr), increment); -} - -inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr, - AtomicWord old_value, - AtomicWord new_value) { - return Acquire_CompareAndSwap( - reinterpret_cast(ptr), old_value, new_value); -} - -inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr, - AtomicWord old_value, - AtomicWord new_value) { - return Release_CompareAndSwap( - reinterpret_cast(ptr), old_value, new_value); -} - -inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) { - NoBarrier_Store(reinterpret_cast(ptr), value); -} - -inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) { - return Acquire_Store(reinterpret_cast(ptr), value); -} - -inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) { - return Release_Store(reinterpret_cast(ptr), value); -} - -inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) { - return NoBarrier_Load(reinterpret_cast(ptr)); -} - -inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) { - return Acquire_Load(reinterpret_cast(ptr)); -} - -inline AtomicWord Release_Load(volatile const AtomicWord* ptr) { - return Release_Load(reinterpret_cast(ptr)); -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // !defined(GOOGLE_PROTOBUF_ARCH_64_BIT) - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ From 662e8b20bcc67ff11bd8a8a514484481b7e68839 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 8 Nov 2017 15:39:47 -0800 Subject: [PATCH 07/24] Provide util funtions to figure out correct php class names. (#3850) --- .../protobuf/compiler/php/php_generator.cc | 36 ++++++++++++++----- .../protobuf/compiler/php/php_generator.h | 9 +++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index e4364ac294..dd4392c240 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -215,19 +215,12 @@ std::string NamespacedName(const string& classname, template std::string FullClassName(const DescriptorType* desc, bool is_descriptor) { - string classname = desc->name(); - const Descriptor* containing = desc->containing_type(); - while (containing != NULL) { - classname = containing->name() + '_' + classname; - containing = containing->containing_type(); - } - classname = ClassNamePrefix(classname, desc) + classname; + string classname = GeneratedClassName(desc); return NamespacedName(classname, desc, is_descriptor); } std::string FullClassName(const ServiceDescriptor* desc, bool is_descriptor) { - string classname = desc->name(); - classname = ClassNamePrefix(classname, desc) + classname; + string classname = GeneratedClassName(desc); return NamespacedName(classname, desc, is_descriptor); } @@ -1419,6 +1412,31 @@ bool Generator::Generate(const FileDescriptor* file, const string& parameter, return true; } +std::string GeneratedClassName(const Descriptor* desc) { + std::string classname = desc->name(); + const Descriptor* containing = desc->containing_type(); + while (containing != NULL) { + classname = containing->name() + '_' + classname; + containing = containing->containing_type(); + } + return ClassNamePrefix(classname, desc) + classname; +} + +std::string GeneratedClassName(const EnumDescriptor* desc) { + std::string classname = desc->name(); + const Descriptor* containing = desc->containing_type(); + while (containing != NULL) { + classname = containing->name() + '_' + classname; + containing = containing->containing_type(); + } + return ClassNamePrefix(classname, desc) + classname; +} + +std::string GeneratedClassName(const ServiceDescriptor* desc) { + std::string classname = desc->name(); + return ClassNamePrefix(classname, desc) + classname; +} + } // namespace php } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/php/php_generator.h b/src/google/protobuf/compiler/php/php_generator.h index ce2b000adb..67e70bc7b5 100644 --- a/src/google/protobuf/compiler/php/php_generator.h +++ b/src/google/protobuf/compiler/php/php_generator.h @@ -32,6 +32,7 @@ #define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ #include +#include #include @@ -47,8 +48,16 @@ class LIBPROTOC_EXPORT Generator const string& parameter, GeneratorContext* generator_context, string* error) const; + }; +// To skip reserved keywords in php, some generated classname are prefixed. +// Other code generators may need following API to figure out the actual +// classname. +std::string GeneratedClassName(const google::protobuf::Descriptor* desc); +std::string GeneratedClassName(const google::protobuf::EnumDescriptor* desc); +std::string GeneratedClassName(const google::protobuf::ServiceDescriptor* desc); + } // namespace php } // namespace compiler } // namespace protobuf From b879abc8116518821a0da6ac5b72f7b1fda34375 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 9 Nov 2017 17:16:42 -0800 Subject: [PATCH 08/24] Supports Arm64 (aarch64) protoc artifacts --- protoc-artifacts/build-protoc.sh | 13 +++++++++++++ protoc-artifacts/build-zip.sh | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/protoc-artifacts/build-protoc.sh b/protoc-artifacts/build-protoc.sh index 57523a41bf..fe1dec24f3 100755 --- a/protoc-artifacts/build-protoc.sh +++ b/protoc-artifacts/build-protoc.sh @@ -6,6 +6,12 @@ # Usage: build-protoc.sh # and are ${os.detected.name} and ${os.detected.arch} from os-maven-plugin # can be "protoc" or "protoc-gen-javalite" +# +# The script now supports cross-compiling windows and linux-arm64 in linux-x86 +# environment. Required packages: +# - Windows: i686-w64-mingw32-gcc (32bit) and x86_64-w64-mingw32-gcc (64bit) +# - Arm64: g++-aarch64-linux-gnu + OS=$1 ARCH=$2 MAKE_TARGET=$3 @@ -73,6 +79,8 @@ checkArch () assertEq $format "elf32-i386" $LINENO elif [[ "$ARCH" == x86_64 ]]; then assertEq $format "elf64-x86-64" $LINENO + elif [[ "$ARCH" == aarch_64 ]]; then + assertEq $format "elf64-little" $LINENO else fail "Unsupported arch: $ARCH" fi @@ -116,6 +124,9 @@ checkDependencies () white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2" elif [[ "$ARCH" == x86_64 ]]; then white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2" + elif [[ "$ARCH" == aarch_64 ]]; then + dump_cmd='objdump -p '"$1"' | grep NEEDED' + white_list="libpthread\.so\.0\|libc\.so\.6\|ld-linux-aarch64\.so\.1" fi elif [[ "$OS" == osx ]]; then dump_cmd='otool -L '"$1"' | fgrep dylib' @@ -180,6 +191,8 @@ elif [[ "$(uname)" == Linux* ]]; then CXXFLAGS="$CXXFLAGS -m64" elif [[ "$ARCH" == x86_32 ]]; then CXXFLAGS="$CXXFLAGS -m32" + elif [[ "$ARCH" == aarch_64 ]]; then + CONFIGURE_ARGS="$CONFIGURE_ARGS --host=aarch64-linux-gnu" else fail "Unsupported arch: $ARCH" fi diff --git a/protoc-artifacts/build-zip.sh b/protoc-artifacts/build-zip.sh index a124ed7ccf..0427e616b9 100755 --- a/protoc-artifacts/build-zip.sh +++ b/protoc-artifacts/build-zip.sh @@ -13,12 +13,13 @@ Example: This script will download pre-built protoc or protoc plugin binaries from maven repository and create .zip packages suitable to be included in the github release page. If the target is protoc, well-known type .proto files will also be -included. Each invocation will create 5 zip packages: +included. Each invocation will create 6 zip packages: dist/--win32.zip dist/--osx-x86_32.zip dist/--osx-x86_64.zip dist/--linux-x86_32.zip dist/--linux-x86_64.zip + dist/--linux-aarch64.zip EOF exit 1 fi @@ -33,6 +34,7 @@ declare -a FILE_NAMES=( \ osx-x86_64.zip osx-x86_64.exe \ linux-x86_32.zip linux-x86_32.exe \ linux-x86_64.zip linux-x86_64.exe \ + linux-aarch64.zip linux-aarch64.exe \ ) # List of all well-known types to be included. From 5eb717c3006ad7da9aa6e49d40328a3963ad22a3 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 9 Nov 2017 17:22:03 -0800 Subject: [PATCH 09/24] Fix arm64 name --- protoc-artifacts/build-zip.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protoc-artifacts/build-zip.sh b/protoc-artifacts/build-zip.sh index 0427e616b9..f08e2758d9 100755 --- a/protoc-artifacts/build-zip.sh +++ b/protoc-artifacts/build-zip.sh @@ -19,7 +19,7 @@ included. Each invocation will create 6 zip packages: dist/--osx-x86_64.zip dist/--linux-x86_32.zip dist/--linux-x86_64.zip - dist/--linux-aarch64.zip + dist/--linux-aarch_64.zip EOF exit 1 fi @@ -34,7 +34,7 @@ declare -a FILE_NAMES=( \ osx-x86_64.zip osx-x86_64.exe \ linux-x86_32.zip linux-x86_32.exe \ linux-x86_64.zip linux-x86_64.exe \ - linux-aarch64.zip linux-aarch64.exe \ + linux-aarch_64.zip linux-aarch_64.exe \ ) # List of all well-known types to be included. From 435f61102bf23b9c9be2592d27b8935a8717e610 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 9 Nov 2017 14:23:14 +0100 Subject: [PATCH 10/24] allow message parsing from an array slice --- csharp/src/Google.Protobuf/MessageExtensions.cs | 16 ++++++++++++++++ csharp/src/Google.Protobuf/MessageParser.cs | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/csharp/src/Google.Protobuf/MessageExtensions.cs b/csharp/src/Google.Protobuf/MessageExtensions.cs index 047156c3ee..9dbc49d6bf 100644 --- a/csharp/src/Google.Protobuf/MessageExtensions.cs +++ b/csharp/src/Google.Protobuf/MessageExtensions.cs @@ -53,6 +53,22 @@ namespace Google.Protobuf input.CheckReadEndOfStreamTag(); } + /// + /// Merges data from the given byte array slice into an existing message. + /// + /// The message to merge the data into. + /// The data containing the slice to merge, which must be protobuf-encoded binary data. + /// The offset of the slice to merge. + /// The length of the slice to merge. + public static void MergeFrom(this IMessage message, byte[] data, int offset, int length) + { + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(data, "data"); + CodedInputStream input = new CodedInputStream(data, offset, length); + message.MergeFrom(input); + input.CheckReadEndOfStreamTag(); + } + /// /// Merges data from the given byte string into an existing message. /// diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs index 8889638b20..569414b0c7 100644 --- a/csharp/src/Google.Protobuf/MessageParser.cs +++ b/csharp/src/Google.Protobuf/MessageParser.cs @@ -70,6 +70,21 @@ namespace Google.Protobuf return message; } + /// + /// Parses a message from a byte array slice. + /// + /// The byte array containing the message. Must not be null. + /// The offset of the slice to parse. + /// The length of the slice to parse. + /// The newly parsed message. + public IMessage ParseFrom(byte[] data, int offset, int length) + { + ProtoPreconditions.CheckNotNull(data, "data"); + IMessage message = factory(); + message.MergeFrom(data, offset, length); + return message; + } + /// /// Parses a message from the given byte string. /// From 4a5e1bd043c8ed01b172ca0ad91af00ed45b0640 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 9 Nov 2017 18:25:25 +0100 Subject: [PATCH 11/24] check already performed by MergeFrom --- csharp/src/Google.Protobuf/MessageParser.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs index 569414b0c7..e533459179 100644 --- a/csharp/src/Google.Protobuf/MessageParser.cs +++ b/csharp/src/Google.Protobuf/MessageParser.cs @@ -64,7 +64,6 @@ namespace Google.Protobuf /// The newly parsed message. public IMessage ParseFrom(byte[] data) { - ProtoPreconditions.CheckNotNull(data, "data"); IMessage message = factory(); message.MergeFrom(data); return message; @@ -79,7 +78,6 @@ namespace Google.Protobuf /// The newly parsed message. public IMessage ParseFrom(byte[] data, int offset, int length) { - ProtoPreconditions.CheckNotNull(data, "data"); IMessage message = factory(); message.MergeFrom(data, offset, length); return message; @@ -92,7 +90,6 @@ namespace Google.Protobuf /// The parsed message. public IMessage ParseFrom(ByteString data) { - ProtoPreconditions.CheckNotNull(data, "data"); IMessage message = factory(); message.MergeFrom(data); return message; @@ -206,7 +203,6 @@ namespace Google.Protobuf /// The newly parsed message. public new T ParseFrom(byte[] data) { - ProtoPreconditions.CheckNotNull(data, "data"); T message = factory(); message.MergeFrom(data); return message; @@ -219,7 +215,6 @@ namespace Google.Protobuf /// The parsed message. public new T ParseFrom(ByteString data) { - ProtoPreconditions.CheckNotNull(data, "data"); T message = factory(); message.MergeFrom(data); return message; From 5f961914594abed32180d3c664cc04fe5f7b242c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 9 Nov 2017 18:33:15 +0100 Subject: [PATCH 12/24] ParseFrom for array slice is missing --- csharp/src/Google.Protobuf/MessageParser.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs index e533459179..66d4413591 100644 --- a/csharp/src/Google.Protobuf/MessageParser.cs +++ b/csharp/src/Google.Protobuf/MessageParser.cs @@ -208,6 +208,20 @@ namespace Google.Protobuf return message; } + /// + /// Parses a message from a byte array slice. + /// + /// The byte array containing the message. Must not be null. + /// The offset of the slice to parse. + /// The length of the slice to parse. + /// The newly parsed message. + public new T ParseFrom(byte[] data, int offset, int length) + { + T message = factory(); + message.MergeFrom(data, offset, length); + return message; + } + /// /// Parses a message from the given byte string. /// From 07df2307b2f339e57b4e7f42b9f87bc1575a5ca1 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 10 Nov 2017 18:37:33 +0100 Subject: [PATCH 13/24] update changelog --- CHANGES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.txt b/CHANGES.txt index 9fe31583ff..fe90cb9a33 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -62,6 +62,7 @@ C# * Added unknown field support in JsonParser. * Fixed oneof message field merge. + * Simplify parsing messages from array slices. Ruby * Unknown fields are now preserved by default. From 9c197b7ecba6019b7c81c673cf100b2fad4033ad Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 10 Nov 2017 10:28:14 -0800 Subject: [PATCH 14/24] Support win32 long path for cross compiled build --- .../protobuf/compiler/command_line_interface.cc | 2 +- .../compiler/command_line_interface_unittest.cc | 2 +- src/google/protobuf/compiler/importer.cc | 2 +- .../compiler/objectivec/objectivec_helpers.cc | 17 +++++++++++------ src/google/protobuf/compiler/plugin.cc | 2 +- src/google/protobuf/io/zero_copy_stream_impl.cc | 3 --- .../protobuf/io/zero_copy_stream_unittest.cc | 3 --- src/google/protobuf/message_unittest.cc | 2 +- src/google/protobuf/stubs/io_win32.cc | 4 ++-- src/google/protobuf/stubs/io_win32.h | 6 ------ src/google/protobuf/stubs/io_win32_unittest.cc | 4 ++-- src/google/protobuf/testing/file.cc | 2 +- src/google/protobuf/testing/googletest.cc | 2 +- 13 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 6c2fc164f4..1f6d748d4f 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -100,7 +100,7 @@ namespace compiler { #endif namespace { -#if defined(_MSC_VER) +#if defined(_WIN32) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 38d0e3882d..ef7579a26c 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -70,7 +70,7 @@ namespace google { namespace protobuf { namespace compiler { -#if defined(_MSC_VER) +#if defined(_WIN32) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc index 9792ffe84a..a5341e0dd0 100644 --- a/src/google/protobuf/compiler/importer.cc +++ b/src/google/protobuf/compiler/importer.cc @@ -65,7 +65,7 @@ namespace google { namespace protobuf { namespace compiler { -#ifdef _MSC_VER +#ifdef _WIN32 // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 54dc7455d9..14715ef6fe 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -50,11 +50,6 @@ #include #include -#if defined(_MSC_VER) -// DO NOT include , instead create functions in io_win32.{h,cc} and import -// them like we do below. -using google::protobuf::internal::win32::open; -#endif // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for errors. @@ -64,6 +59,16 @@ namespace protobuf { namespace compiler { namespace objectivec { +// is transitively included in this file. Import the functions explicitly +// in this port namespace to avoid ambiguous definition. +namespace posix { +#ifdef _WIN32 +using ::google::protobuf::internal::win32::open; +#else +using ::open; +#endif +} // namespace port + Options::Options() { // Default is the value of the env for the package prefixes. const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES"); @@ -1469,7 +1474,7 @@ bool ParseSimpleFile( const string& path, LineConsumer* line_consumer, string* out_error) { int fd; do { - fd = open(path.c_str(), O_RDONLY); + fd = posix::open(path.c_str(), O_RDONLY); } while (fd < 0 && errno == EINTR); if (fd < 0) { *out_error = diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc index 7f975510b5..bde3d79829 100644 --- a/src/google/protobuf/compiler/plugin.cc +++ b/src/google/protobuf/compiler/plugin.cc @@ -54,7 +54,7 @@ namespace google { namespace protobuf { namespace compiler { -#if defined(_MSC_VER) +#if defined(_WIN32) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::setmode; diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc index 83dec3e620..dd92113573 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl.cc @@ -56,9 +56,6 @@ namespace io { // Win32 lseek is broken: If invoked on a non-seekable file descriptor, its // return value is undefined. We re-define it to always produce an error. #define lseek(fd, offset, origin) ((off_t)-1) -#endif - -#ifdef _MSC_VER // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index dfc383a313..91792f1808 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -83,9 +83,6 @@ namespace { #ifdef _WIN32 #define pipe(fds) _pipe(fds, 4096, O_BINARY) -#endif - -#ifdef _MSC_VER // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index d328f9dd82..a27036e75f 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -63,7 +63,7 @@ namespace google { namespace protobuf { -#if defined(_MSC_VER) +#if defined(_WIN32) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::close; diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index 7e1cf785d1..fa2cb8b130 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -39,7 +39,7 @@ // // This file is only used on Windows, it's empty on other platforms. -#if defined(_MSC_VER) +#if defined(_WIN32) // Comment this out to fall back to using the ANSI versions (open, mkdir, ...) // instead of the Unicode ones (_wopen, _wmkdir, ...). Doing so can be useful to @@ -358,5 +358,5 @@ wstring testonly_path_to_winpath(const string& path) { } // namespace protobuf } // namespace google -#endif // defined(_MSC_VER) +#endif // defined(_WIN32) diff --git a/src/google/protobuf/stubs/io_win32.h b/src/google/protobuf/stubs/io_win32.h index a20e64c716..5316008968 100644 --- a/src/google/protobuf/stubs/io_win32.h +++ b/src/google/protobuf/stubs/io_win32.h @@ -52,7 +52,6 @@ // Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the // following functions already, except for mkdir. -#ifdef _MSC_VER namespace google { namespace protobuf { namespace internal { @@ -77,9 +76,6 @@ LIBPROTOBUF_EXPORT std::wstring testonly_path_to_winpath( } // namespace internal } // namespace protobuf } // namespace google -#else // _MSC_VER -#define mkdir(name, mode) mkdir(name) -#endif // !_MSC_VER #ifndef W_OK #define W_OK 02 // not defined by MSVC for whatever reason @@ -100,5 +96,3 @@ LIBPROTOBUF_EXPORT std::wstring testonly_path_to_winpath( #endif // defined(_WIN32) #endif // GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ - - diff --git a/src/google/protobuf/stubs/io_win32_unittest.cc b/src/google/protobuf/stubs/io_win32_unittest.cc index 288f27ab00..ce6f716256 100644 --- a/src/google/protobuf/stubs/io_win32_unittest.cc +++ b/src/google/protobuf/stubs/io_win32_unittest.cc @@ -34,7 +34,7 @@ // // This file is only used on Windows, it's empty on other platforms. -#if defined(_MSC_VER) +#if defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include @@ -369,5 +369,5 @@ TEST_F(IoWin32Test, AsWindowsPathTest) { } // namespace protobuf } // namespace google -#endif // defined(_MSC_VER) +#endif // defined(_WIN32) diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc index f68aba9a29..26cb0a67c2 100644 --- a/src/google/protobuf/testing/file.cc +++ b/src/google/protobuf/testing/file.cc @@ -57,7 +57,7 @@ namespace protobuf { // them like we do below. #endif -#ifdef _MSC_VER +#ifdef _WIN32 using google::protobuf::internal::win32::access; using google::protobuf::internal::win32::chdir; using google::protobuf::internal::win32::fopen; diff --git a/src/google/protobuf/testing/googletest.cc b/src/google/protobuf/testing/googletest.cc index 91f0ef89d7..c329b6c1e5 100644 --- a/src/google/protobuf/testing/googletest.cc +++ b/src/google/protobuf/testing/googletest.cc @@ -52,7 +52,7 @@ namespace google { namespace protobuf { -#ifdef _MSC_VER +#ifdef _WIN32 // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::close; From 188f18044feb1ca82ecc922f3e59e37078473ddf Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 13 Nov 2017 09:31:28 -0800 Subject: [PATCH 15/24] All integer types should accept null in json. (#3869) --- conformance/conformance_test.cc | 16 ++++++++++++++++ php/src/Google/Protobuf/Internal/Message.php | 11 ++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index c54d4ccd12..98c2eae4dd 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -1842,6 +1842,14 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, "optionalInt64": null, "optionalUint32": null, "optionalUint64": null, + "optionalSint32": null, + "optionalSint64": null, + "optionalFixed32": null, + "optionalFixed64": null, + "optionalSfixed32": null, + "optionalSfixed64": null, + "optionalFloat": null, + "optionalDouble": null, "optionalBool": null, "optionalString": null, "optionalBytes": null, @@ -1851,6 +1859,14 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, "repeatedInt64": null, "repeatedUint32": null, "repeatedUint64": null, + "repeatedSint32": null, + "repeatedSint64": null, + "repeatedFixed32": null, + "repeatedFixed64": null, + "repeatedSfixed32": null, + "repeatedSfixed64": null, + "repeatedFloat": null, + "repeatedDouble": null, "repeatedBool": null, "repeatedString": null, "repeatedBytes": null, diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 9785be302a..a7a4f272db 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -833,6 +833,8 @@ class Message } return $value; case GPBType::INT32: + case GPBType::SINT32: + case GPBType::SFIXED32: if (is_null($value)) { return $this->defaultValue($field); } @@ -850,6 +852,7 @@ class Message } return $value; case GPBType::UINT32: + case GPBType::FIXED32: if (is_null($value)) { return $this->defaultValue($field); } @@ -863,6 +866,8 @@ class Message } return $value; case GPBType::INT64: + case GPBType::SINT64: + case GPBType::SFIXED64: if (is_null($value)) { return $this->defaultValue($field); } @@ -880,6 +885,7 @@ class Message } return $value; case GPBType::UINT64: + case GPBType::FIXED64: if (is_null($value)) { return $this->defaultValue($field); } @@ -895,11 +901,6 @@ class Message $value = bcsub($value, "18446744073709551616"); } return $value; - case GPBType::FIXED64: - if (is_null($value)) { - return $this->defaultValue($field); - } - return $value; default: return $value; } From 4493595f8c77e9d094351987111cbf4aa2246f37 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Mon, 13 Nov 2017 10:47:48 -0800 Subject: [PATCH 16/24] Update release date --- CHANGES.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9fe31583ff..fe2de89df8 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -2017-11-09 version 3.5.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) +2017-11-13 version 3.5.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Planned Future Changes * Make C++ implementation C++11 only: we plan to require C++11 to build protobuf code starting from 3.6.0 release. Please join this github issue: @@ -25,7 +25,7 @@ Java * Proto3 messages are now preserving unknown fields by default. If you’d like - to drop unknown fields, please use the DiscardUnknownFieldsParser  API. For + to drop unknown fields, please use the DiscardUnknownFieldsParser API. For example: Parser parser = DiscardUnknownFieldsParser.wrap(Foo.parser()); Foo foo = parser.parseFrom(input); @@ -167,7 +167,7 @@ * Note: AppEngine 2.5 is deprecated on June 2017 that AppEngine 2.5 will never update protobuf runtime. Users who depend on AppEngine 2.5 should use old protoc. - + PHP * Support PHP generic services. Specify file option php_generic_service=true to enable generating service interface. From 0cd2ad11b8a114c3767aafe9912c09c89bfd0f3e Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Mon, 13 Nov 2017 12:29:06 -0800 Subject: [PATCH 17/24] Update protoc-artfacts --- protoc-artifacts/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/protoc-artifacts/README.md b/protoc-artifacts/README.md index 17eb77f840..fc8ef58643 100644 --- a/protoc-artifacts/README.md +++ b/protoc-artifacts/README.md @@ -70,9 +70,9 @@ support. DO NOT close the staging repository until you have done the deployment for all platforms. Currently the following platforms are supported: - Linux (x86_32 and x86_64) - Windows (x86_32 and x86_64) with - - Cygwin64 with MinGW compilers (x86_64) - - MSYS with MinGW32 (x86_32) - - Cross compile in Linux with MinGW-w64 (x86_32, x86_64) + - Cygwin64 with MinGW compilers (x86_64) + - MSYS with MinGW32 (x86_32) + - Cross compile in Linux with MinGW-w64 (x86_32, x86_64) - MacOSX (x86_32 and x86_64) As for MSYS2/MinGW64 for Windows: protoc will build, but it insists on @@ -174,8 +174,9 @@ stored: ### Tested build environments We have successfully built artifacts on the following environments: - Linux x86_32 and x86_64: - - Centos 6.6 (within Docker 1.6.1) - - Ubuntu 14.04.2 64-bit + - Centos 6.6 (within Docker 1.6.1) + - Ubuntu 14.04.2 64-bit +- Linux aarch_64: Cross compiled with `g++-aarch64-linux-gnu` on Ubuntu 14.04.2 64-bit - Windows x86_32: MSYS with ``mingw32-gcc-g++ 4.8.1-4`` on Windows 7 64-bit - Windows x86_32: Cross compile with ``i686-w64-mingw32-g++ 4.8.2`` on Ubuntu 14.04.2 64-bit - Windows x86_64: Cygwin64 with ``mingw64-x86_64-gcc-g++ 4.8.3-1`` on Windows 7 64-bit From 857a021645e0c553886cf57816d22dc06a92f606 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 15 Nov 2017 11:09:14 -0800 Subject: [PATCH 18/24] Use fully qualifed name for DescriptorPool in Any.php to avoid name (#3886) conflict --- php/src/Google/Protobuf/Any.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/php/src/Google/Protobuf/Any.php b/php/src/Google/Protobuf/Any.php index 91ba4bd5d0..f027b05d2e 100644 --- a/php/src/Google/Protobuf/Any.php +++ b/php/src/Google/Protobuf/Any.php @@ -4,7 +4,6 @@ namespace Google\Protobuf; -use Google\Protobuf\Internal\DescriptorPool; use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBUtil; use Google\Protobuf\Internal\Message; @@ -217,7 +216,7 @@ class Any extends \Google\Protobuf\Internal\Message substr($this->type_url, $url_prifix_len); // Create message according to fully qualified name. - $pool = DescriptorPool::getGeneratedPool(); + $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool(); $desc = $pool->getDescriptorByProtoName( ".".$fully_qualifed_name); if (is_null($desc)) { throw new \Exception("Class ".$fully_qualifed_name @@ -248,7 +247,7 @@ class Any extends \Google\Protobuf\Internal\Message $this->value = $msg->serializeToString(); // Set type url. - $pool = DescriptorPool::getGeneratedPool(); + $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool(); $desc = $pool->getDescriptorByClassName(get_class($msg)); $fully_qualifed_name = $desc->getFullName(); $this->type_url = GPBUtil::TYPE_URL_PREFIX.substr( @@ -262,7 +261,7 @@ class Any extends \Google\Protobuf\Internal\Message */ public function is($klass) { - $pool = DescriptorPool::getGeneratedPool(); + $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool(); $desc = $pool->getDescriptorByClassName($klass); $fully_qualifed_name = $desc->getFullName(); $type_url = GPBUtil::TYPE_URL_PREFIX.substr( From 1ec45f81ef2df945a07dfb9404bf4f4a0a1081f2 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 15 Nov 2017 15:06:47 -0800 Subject: [PATCH 19/24] Add protobuf-all in post release --- post_process_dist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post_process_dist.sh b/post_process_dist.sh index a5f95800b8..eb5f584d76 100755 --- a/post_process_dist.sh +++ b/post_process_dist.sh @@ -27,7 +27,7 @@ fi set -ex -LANGUAGES="cpp csharp java javanano js objectivec python ruby php" +LANGUAGES="cpp csharp java javanano js objectivec python ruby php all" BASENAME=`basename $1 .tar.gz` VERSION=${BASENAME:9} From 98836a56e616f3bc387e3c66133b1ad320f36d80 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 15 Nov 2017 17:17:36 -0800 Subject: [PATCH 20/24] Update version number for php c extension (#3896) --- php/ext/google/protobuf/package.xml | 22 +++++++++++++++++++--- php/ext/google/protobuf/protobuf.h | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 4a47380173..53aa4c7ff7 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2017-09-14 + 2017-11-15 - 3.4.1 - 3.4.1 + 3.5.0 + 3.5.0 stable @@ -165,6 +165,22 @@ GA release. 3-Clause BSD License +GA release. + + + + + 3.5.0 + 3.5.0 + + + stable + stable + + 2017-11-15 + + 3-Clause BSD License + GA release. diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 1834377297..967b21f1d6 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.1" +#define PHP_PROTOBUF_VERSION "3.5.0" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 From 45d99a15f369a698a7f5be790ced1fe7029e6139 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Wed, 22 Nov 2017 13:59:11 -0800 Subject: [PATCH 21/24] Add _file_desc_by_toplevel_extension back Add _file_desc_by_toplevel_extension back for compatibility issue with 3.4.1. _file_desc_by_toplevel_extension is a temporary solution for FieldDescriptor.file. FieldDescriptor.file was added in code gen. However, we need to keep it for some time for compatibility reason (with 3.4.1 only). May try to remove it after 2 years. --- python/google/protobuf/descriptor_pool.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/python/google/protobuf/descriptor_pool.py b/python/google/protobuf/descriptor_pool.py index cb7146b6a4..f4c533a48a 100644 --- a/python/google/protobuf/descriptor_pool.py +++ b/python/google/protobuf/descriptor_pool.py @@ -127,6 +127,9 @@ class DescriptorPool(object): self._service_descriptors = {} self._file_descriptors = {} self._toplevel_extensions = {} + # TODO(jieluo): Remove _file_desc_by_toplevel_extension after + # maybe year 2020 for compatibility issue (with 3.4.1 only). + self._file_desc_by_toplevel_extension = {} # We store extensions in two two-level mappings: The first key is the # descriptor of the message being extended, the second key is the extension # full name or its tag number. @@ -252,6 +255,12 @@ class DescriptorPool(object): """ self._AddFileDescriptor(file_desc) + # TODO(jieluo): This is a temporary solution for FieldDescriptor.file. + # FieldDescriptor.file is added in code gen. Remove this solution after + # maybe 2020 for compatibility reason (with 3.4.1 only). + for extension in file_desc.extensions_by_name.values(): + self._file_desc_by_toplevel_extension[ + extension.full_name] = file_desc def _AddFileDescriptor(self, file_desc): """Adds a FileDescriptor to the pool, non-recursively. @@ -331,7 +340,7 @@ class DescriptorPool(object): pass try: - return self._toplevel_extensions[symbol].file + return self._file_desc_by_toplevel_extension[symbol] except KeyError: pass From cf65a7946fb42e941708d10adbce69924c6d1ee0 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 22 Nov 2017 14:05:10 -0800 Subject: [PATCH 22/24] Update version for 3.5.0.post1 --- python/google/protobuf/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 76cb51c30f..0f4d63b0ce 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.5.0' +__version__ = '3.5.0.post1' if __name__ != '__main__': try: From 74e7decbbf130485a5bc5d792fb4f9285143bce3 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 30 Nov 2017 12:19:50 -0800 Subject: [PATCH 23/24] Provide discardUnknonwnFields API in php (#3976) * Provide discardUnknownFields API in php implementation * Provide discardUnknownFields API in php c extension. --- php/ext/google/protobuf/encode_decode.c | 9 +++++++++ php/ext/google/protobuf/message.c | 1 + php/ext/google/protobuf/protobuf.h | 1 + php/src/Google/Protobuf/Internal/Message.php | 9 +++++++++ php/tests/encode_decode_test.php | 7 +++++++ 5 files changed, 27 insertions(+) diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 7e2b3ae6cc..ae5a61f54b 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -1614,3 +1614,12 @@ PHP_METHOD(Message, mergeFromJsonString) { stackenv_uninit(&se); } } + +PHP_METHOD(Message, discardUnknownFields) { + MessageHeader* msg = UNBOX(MessageHeader, getThis()); + stringsink* unknown = DEREF(message_data(msg), 0, stringsink*); + if (unknown != NULL) { + stringsink_uninit(unknown); + DEREF(message_data(msg), 0, stringsink*) = NULL; + } +} diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 3fce2c1741..6db010c519 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -42,6 +42,7 @@ static void hex_to_binary(const char* hex, char** binary, int* binary_len); static zend_function_entry message_methods[] = { PHP_ME(Message, clear, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Message, discardUnknownFields, NULL, ZEND_ACC_PUBLIC) PHP_ME(Message, serializeToString, NULL, ZEND_ACC_PUBLIC) PHP_ME(Message, mergeFromString, NULL, ZEND_ACC_PUBLIC) PHP_ME(Message, serializeToJsonString, NULL, ZEND_ACC_PUBLIC) diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 967b21f1d6..ac42e714ec 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -969,6 +969,7 @@ PHP_METHOD(Message, serializeToString); PHP_METHOD(Message, mergeFromString); PHP_METHOD(Message, serializeToJsonString); PHP_METHOD(Message, mergeFromJsonString); +PHP_METHOD(Message, discardUnknownFields); // ----------------------------------------------------------------------------- // Type check / conversion. diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index a7a4f272db..26d205753b 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -576,6 +576,15 @@ class Message } } + /** + * Clear all unknown fields previously parsed. + * @return null. + */ + public function discardUnknownFields() + { + $this->unknown = ""; + } + /** * Merges the contents of the specified message into current message. * diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 4dca922bfd..4512c87164 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -466,6 +466,13 @@ class EncodeDecodeTest extends TestBase $m->mergeFromString($from); $to = $m->serializeToString(); $this->assertSame(bin2hex($from), bin2hex($to)); + + $m = new TestMessage(); + $from = hex2bin('F80601'); + $m->mergeFromString($from); + $m->discardUnknownFields(); + $to = $m->serializeToString(); + $this->assertSame("", bin2hex($to)); } public function testJsonEncode() From 94bb1eed17209cacfdf2571be5a1ae91b3964cff Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 30 Nov 2017 12:21:00 -0800 Subject: [PATCH 24/24] Remove duplicate typedef. (#3975) --- php/ext/google/protobuf/protobuf.h | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index ac42e714ec..bd475144b0 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -608,48 +608,36 @@ typedef struct Api Api; typedef struct BoolValue BoolValue; typedef struct BytesValue BytesValue; typedef struct Descriptor Descriptor; -typedef struct Descriptor Descriptor; typedef struct DescriptorPool DescriptorPool; typedef struct DoubleValue DoubleValue; typedef struct Duration Duration; -typedef struct Enum Enum; typedef struct EnumDescriptor EnumDescriptor; -typedef struct EnumDescriptor EnumDescriptor; -typedef struct EnumValue EnumValue; -typedef struct EnumValueDescriptor EnumValueDescriptor; +typedef struct Enum Enum; typedef struct EnumValueDescriptor EnumValueDescriptor; -typedef struct Field Field; -typedef struct FieldDescriptor FieldDescriptor; -typedef struct FieldDescriptor FieldDescriptor; -typedef struct FieldMask FieldMask; +typedef struct EnumValue EnumValue; typedef struct Field_Cardinality Field_Cardinality; +typedef struct FieldDescriptor FieldDescriptor; +typedef struct Field Field; typedef struct Field_Kind Field_Kind; +typedef struct FieldMask FieldMask; typedef struct FloatValue FloatValue; typedef struct GPBEmpty GPBEmpty; typedef struct Int32Value Int32Value; typedef struct Int64Value Int64Value; typedef struct InternalDescriptorPool InternalDescriptorPool; typedef struct ListValue ListValue; -typedef struct Map Map; -typedef struct Map Map; -typedef struct MapIter MapIter; typedef struct MapIter MapIter; +typedef struct Map Map; typedef struct MessageField MessageField; -typedef struct MessageField MessageField; -typedef struct MessageHeader MessageHeader; typedef struct MessageHeader MessageHeader; typedef struct MessageLayout MessageLayout; -typedef struct MessageLayout MessageLayout; typedef struct Method Method; typedef struct Mixin Mixin; typedef struct NullValue NullValue; typedef struct Oneof Oneof; -typedef struct Oneof Oneof; typedef struct Option Option; -typedef struct RepeatedField RepeatedField; -typedef struct RepeatedField RepeatedField; -typedef struct RepeatedFieldIter RepeatedFieldIter; typedef struct RepeatedFieldIter RepeatedFieldIter; +typedef struct RepeatedField RepeatedField; typedef struct SourceContext SourceContext; typedef struct StringValue StringValue; typedef struct Struct Struct;