From b44a1364ecfb274dc2c6546cfe673b94cbf6f451 Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Fri, 24 May 2019 07:44:51 -0400 Subject: [PATCH 01/17] Add extension number for protoc-gen-validate This project is used by the [Envoy proxy](https://www.envoyproxy.io/) and several others. The existing code is using the extension value [919191](https://github.com/envoyproxy/protoc-gen-validate/blob/54b08a686ff6548d8a248218664254c422fc4599/validate/validate.proto#L29) but since maintaining binary compatibility is not important, it shouldn't be a problem to change once this allocation is approved. --- docs/options.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/options.md b/docs/options.md index c1775d17b6..ee88ef96c3 100644 --- a/docs/options.md +++ b/docs/options.md @@ -197,3 +197,7 @@ with info about your project (name and website) so we can add an entry for you. * Website: https://github.com/container-storage-interface/spec * Extensions: 1059-1069 +1. Protoc-gen-validate + * Website: https://github.com/envoyproxy/protoc-gen-validate + * Extensions: 1070 + From 5c25f4142359755c1a302db94068b04fae6f9710 Mon Sep 17 00:00:00 2001 From: Carmi Grushko Date: Fri, 24 May 2019 17:26:07 +0300 Subject: [PATCH 02/17] Add `protobuf_java_lite` Bazel target that builds the JavaLite runtime. Contents based on java/lite/pom.xml. --- BUILD | 101 ++++++++++++++++++++++++++++++++++++++++++++++ java/lite/pom.xml | 1 + 2 files changed, 102 insertions(+) diff --git a/BUILD b/BUILD index d681994fec..5a86751469 100644 --- a/BUILD +++ b/BUILD @@ -647,6 +647,107 @@ java_library( visibility = ["//visibility:public"], ) +java_library( + name = "protobuf_javalite", + srcs = [ + # Keep in sync with java/lite/pom.xml + "java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java", + "java/core/src/main/java/com/google/protobuf/AbstractParser.java", + "java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java", + "java/core/src/main/java/com/google/protobuf/AllocatedBuffer.java", + "java/core/src/main/java/com/google/protobuf/Android.java", + "java/core/src/main/java/com/google/protobuf/ArrayDecoders.java", + "java/core/src/main/java/com/google/protobuf/BinaryReader.java", + "java/core/src/main/java/com/google/protobuf/BinaryWriter.java", + "java/core/src/main/java/com/google/protobuf/BooleanArrayList.java", + "java/core/src/main/java/com/google/protobuf/BufferAllocator.java", + "java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java", + "java/core/src/main/java/com/google/protobuf/ByteOutput.java", + "java/core/src/main/java/com/google/protobuf/ByteString.java", + "java/core/src/main/java/com/google/protobuf/CodedInputStream.java", + "java/core/src/main/java/com/google/protobuf/CodedInputStreamReader.java", + "java/core/src/main/java/com/google/protobuf/CodedOutputStream.java", + "java/core/src/main/java/com/google/protobuf/CodedOutputStreamWriter.java", + "java/core/src/main/java/com/google/protobuf/DoubleArrayList.java", + "java/core/src/main/java/com/google/protobuf/ExperimentalApi.java", + "java/core/src/main/java/com/google/protobuf/ExtensionLite.java", + "java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java", + "java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java", + "java/core/src/main/java/com/google/protobuf/ExtensionSchema.java", + "java/core/src/main/java/com/google/protobuf/ExtensionSchemaLite.java", + "java/core/src/main/java/com/google/protobuf/ExtensionSchemas.java", + "java/core/src/main/java/com/google/protobuf/FieldInfo.java", + "java/core/src/main/java/com/google/protobuf/FieldSet.java", + "java/core/src/main/java/com/google/protobuf/FieldType.java", + "java/core/src/main/java/com/google/protobuf/FloatArrayList.java", + "java/core/src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java", + "java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java", + "java/core/src/main/java/com/google/protobuf/IntArrayList.java", + "java/core/src/main/java/com/google/protobuf/Internal.java", + "java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java", + "java/core/src/main/java/com/google/protobuf/IterableByteBufferInputStream.java", + "java/core/src/main/java/com/google/protobuf/JavaType.java", + "java/core/src/main/java/com/google/protobuf/LazyField.java", + "java/core/src/main/java/com/google/protobuf/LazyFieldLite.java", + "java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java", + "java/core/src/main/java/com/google/protobuf/LazyStringList.java", + "java/core/src/main/java/com/google/protobuf/ListFieldSchema.java", + "java/core/src/main/java/com/google/protobuf/LongArrayList.java", + "java/core/src/main/java/com/google/protobuf/ManifestSchemaFactory.java", + "java/core/src/main/java/com/google/protobuf/MapEntryLite.java", + "java/core/src/main/java/com/google/protobuf/MapFieldLite.java", + "java/core/src/main/java/com/google/protobuf/MapFieldSchema.java", + "java/core/src/main/java/com/google/protobuf/MapFieldSchemaLite.java", + "java/core/src/main/java/com/google/protobuf/MapFieldSchemas.java", + "java/core/src/main/java/com/google/protobuf/MessageInfo.java", + "java/core/src/main/java/com/google/protobuf/MessageInfoFactory.java", + "java/core/src/main/java/com/google/protobuf/MessageLite.java", + "java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java", + "java/core/src/main/java/com/google/protobuf/MessageLiteToString.java", + "java/core/src/main/java/com/google/protobuf/MessageSchema.java", + "java/core/src/main/java/com/google/protobuf/MessageSetSchema.java", + "java/core/src/main/java/com/google/protobuf/MutabilityOracle.java", + "java/core/src/main/java/com/google/protobuf/NewInstanceSchema.java", + "java/core/src/main/java/com/google/protobuf/NewInstanceSchemaLite.java", + "java/core/src/main/java/com/google/protobuf/NewInstanceSchemas.java", + "java/core/src/main/java/com/google/protobuf/NioByteString.java", + "java/core/src/main/java/com/google/protobuf/OneofInfo.java", + "java/core/src/main/java/com/google/protobuf/Parser.java", + "java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java", + "java/core/src/main/java/com/google/protobuf/ProtoSyntax.java", + "java/core/src/main/java/com/google/protobuf/Protobuf.java", + "java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java", + "java/core/src/main/java/com/google/protobuf/ProtobufLists.java", + "java/core/src/main/java/com/google/protobuf/ProtocolStringList.java", + "java/core/src/main/java/com/google/protobuf/RawMessageInfo.java", + "java/core/src/main/java/com/google/protobuf/Reader.java", + "java/core/src/main/java/com/google/protobuf/RopeByteString.java", + "java/core/src/main/java/com/google/protobuf/Schema.java", + "java/core/src/main/java/com/google/protobuf/SchemaFactory.java", + "java/core/src/main/java/com/google/protobuf/SchemaUtil.java", + "java/core/src/main/java/com/google/protobuf/SmallSortedMap.java", + "java/core/src/main/java/com/google/protobuf/StructuralMessageInfo.java", + "java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java", + "java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java", + "java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java", + "java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java", + "java/core/src/main/java/com/google/protobuf/UnknownFieldSetLiteSchema.java", + "java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java", + "java/core/src/main/java/com/google/protobuf/UnsafeUtil.java", + "java/core/src/main/java/com/google/protobuf/Utf8.java", + "java/core/src/main/java/com/google/protobuf/WireFormat.java", + "java/core/src/main/java/com/google/protobuf/Writer.java", + ], + javacopts = select({ + "//:jdk9": ["--add-modules=jdk.unsupported"], + "//conditions:default": [ + "-source 7", + "-target 7", + ], + }), + visibility = ["//visibility:public"], +) + java_library( name = "protobuf_java_util", srcs = glob([ diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 800cdded9a..c09cfb7061 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -86,6 +86,7 @@ ${basedir}/../core/src/main/java/com/google/protobuf + AbstractMessageLite.java AbstractParser.java AbstractProtobufList.java From 005a5e37310d2a9ac118fd7f572e572f16c5872d Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Sun, 9 Jun 2019 05:48:34 -0700 Subject: [PATCH 03/17] Fix JavaLite version --- java/lite/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 0e360a7080..14254ed324 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.8.0-rc-1 + 3.8.0 protobuf-javalite From 8147e7db8aefd587ecb195f67f174f4306887cbd Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Tue, 11 Jun 2019 22:23:37 -0400 Subject: [PATCH 04/17] Compatibility tests pull artifacts over HTTPS --- java/compatibility_tests/v2.5.0/test.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/java/compatibility_tests/v2.5.0/test.sh b/java/compatibility_tests/v2.5.0/test.sh index eea8328504..860437809c 100755 --- a/java/compatibility_tests/v2.5.0/test.sh +++ b/java/compatibility_tests/v2.5.0/test.sh @@ -24,23 +24,23 @@ case "$1" in ;; 2.6.1) OLD_VERSION=2.6.1 - OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/2.6.1-build2/protoc-2.6.1-build2-linux-x86_64.exe + OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/2.6.1-build2/protoc-2.6.1-build2-linux-x86_64.exe ;; 3.0.0-beta-1) OLD_VERSION=3.0.0-beta-1 - OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-1/protoc-3.0.0-beta-1-linux-x86_64.exe + OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-1/protoc-3.0.0-beta-1-linux-x86_64.exe ;; 3.0.0-beta-2) OLD_VERSION=3.0.0-beta-2 - OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_64.exe + OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_64.exe ;; 3.0.0-beta-3) OLD_VERSION=3.0.0-beta-3 - OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-3/protoc-3.0.0-beta-3-linux-x86_64.exe + OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-3/protoc-3.0.0-beta-3-linux-x86_64.exe ;; 3.0.0-beta-4) OLD_VERSION=3.0.0-beta-4 - OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-4/protoc-3.0.0-beta-4-linux-x86_64.exe + OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-4/protoc-3.0.0-beta-4-linux-x86_64.exe ;; *) echo "[ERROR]: Unknown version number: $1" From ce0dca83abe28731301484b766fee542ddcbc30c Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 21 May 2019 17:31:34 -0700 Subject: [PATCH 05/17] Move tool out of inputs in bazel config This fixes compatibility with bazel when passing `--incompatible_no_support_tools_in_action_inputs` which will be flipped in an upcoming release. --- protobuf.bzl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protobuf.bzl b/protobuf.bzl index e764859b4a..2fd31d081c 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -158,10 +158,11 @@ def _proto_gen_impl(ctx): if generated_out != out.path: command += ";mv %s %s" % (generated_out, out.path) ctx.actions.run_shell( - inputs = inputs + [ctx.executable.protoc], + inputs = inputs, outputs = [out], command = command, mnemonic = "ProtoCompile", + tools = [ctx.executable.protoc], use_default_shell_env = True, ) From 310ba5ee72661c081129eb878c1bbcec936b20f0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 3 Jun 2019 08:56:33 -0700 Subject: [PATCH 06/17] Treat plugins as host tools. As a followup to ca3ead7745581b24d9e84471b5dee6921fcd369d, treat plugin executables as well as protoc as host tools. --- protobuf.bzl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/protobuf.bzl b/protobuf.bzl index 2fd31d081c..e0653321f8 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -117,6 +117,7 @@ def _proto_gen_impl(ctx): outs = [ctx.actions.declare_file(out, sibling = src) for out in outs] inputs = [src] + deps + tools = [ctx.executable.protoc] if ctx.executable.plugin: plugin = ctx.executable.plugin lang = ctx.attr.plugin_language @@ -131,11 +132,12 @@ def _proto_gen_impl(ctx): outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir args += [("--plugin=protoc-gen-%s=" + path_tpl) % (lang, plugin.path)] args += ["--%s_out=%s" % (lang, outdir)] - inputs += [plugin] + tools.append(plugin) if not in_gen_dir: ctx.actions.run( inputs = inputs, + tools = tools, outputs = outs, arguments = args + import_flags + [src.path], executable = ctx.executable.protoc, @@ -162,7 +164,7 @@ def _proto_gen_impl(ctx): outputs = [out], command = command, mnemonic = "ProtoCompile", - tools = [ctx.executable.protoc], + tools = tools, use_default_shell_env = True, ) From 444354f41a60740a01d6c47c4e6fa1b82c505d9a Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 17 Jun 2019 09:53:12 -0700 Subject: [PATCH 07/17] Update gem to 2.7.9 (#6265) New bundler doesn't work with old gem: https://github.com/rbenv/rbenv/issues/1138 --- kokoro/linux/dockerfile/release/ruby_rake_compiler/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kokoro/linux/dockerfile/release/ruby_rake_compiler/Dockerfile b/kokoro/linux/dockerfile/release/ruby_rake_compiler/Dockerfile index 9ba664d8b0..866b289343 100644 --- a/kokoro/linux/dockerfile/release/ruby_rake_compiler/Dockerfile +++ b/kokoro/linux/dockerfile/release/ruby_rake_compiler/Dockerfile @@ -1,3 +1,3 @@ FROM grpctesting/rake-compiler-dock_53c22085d091183c528303791e7771359f699bcf -RUN /bin/bash -l -c "gem install bundler" +RUN /bin/bash -l -c "gem update --system '2.7.9' && gem install bundler" From abb4fb00408eff18c92bef388d963ad163f94e7f Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 17 Jun 2019 13:13:54 -0700 Subject: [PATCH 08/17] Change offset of Timestamp conformance test to distinguish from the default (#6263) Fixes #4079 --- conformance/binary_json_conformance_suite.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 0995d3563a..5ddb3a90bd 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -1980,12 +1980,12 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { "repeated_timestamp: {seconds: 253402300799 nanos: 999999999}"); RunValidJsonTest( "TimestampWithPositiveOffset", REQUIRED, - R"({"optionalTimestamp": "1970-01-01T08:00:00+08:00"})", - "optional_timestamp: {seconds: 0}"); + R"({"optionalTimestamp": "1970-01-01T08:00:01+08:00"})", + "optional_timestamp: {seconds: 1}"); RunValidJsonTest( "TimestampWithNegativeOffset", REQUIRED, - R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})", - "optional_timestamp: {seconds: 0}"); + R"({"optionalTimestamp": "1969-12-31T16:00:01-08:00"})", + "optional_timestamp: {seconds: 1}"); RunValidJsonTest( "TimestampNull", REQUIRED, R"({"optionalTimestamp": null})", From 640423f15722d5f5274df8fcb0be5418c9ae0a1e Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 17 Jun 2019 13:14:27 -0700 Subject: [PATCH 09/17] Change int64 json encoding to be string for php and ruby (#6251) * Change int64 json encoding to be string for php and ruby * Fix ruby test * Sync upb change --- conformance/failure_list_php_c.txt | 2 -- conformance/failure_list_ruby.txt | 2 -- conformance/failure_list_ruby_mac.txt | 2 -- php/ext/google/protobuf/upb.c | 41 +++++++++++++++++++-------- ruby/ext/google/protobuf_c/upb.c | 41 +++++++++++++++++++-------- ruby/tests/common_tests.rb | 12 ++++---- 6 files changed, 64 insertions(+), 36 deletions(-) diff --git a/conformance/failure_list_php_c.txt b/conformance/failure_list_php_c.txt index b0405618a7..d1a961a990 100644 --- a/conformance/failure_list_php_c.txt +++ b/conformance/failure_list_php_c.txt @@ -6,7 +6,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter -Recommended.Proto3.JsonInput.Int64FieldBeString.Validator Recommended.Proto3.JsonInput.MapFieldValueIsNull Recommended.Proto3.JsonInput.OneofZeroBytes.JsonOutput Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull @@ -17,7 +16,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput diff --git a/conformance/failure_list_ruby.txt b/conformance/failure_list_ruby.txt index 651cb55f57..cf8777cd8a 100644 --- a/conformance/failure_list_ruby.txt +++ b/conformance/failure_list_ruby.txt @@ -6,7 +6,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter -Recommended.Proto3.JsonInput.Int64FieldBeString.Validator Recommended.Proto3.JsonInput.MapFieldValueIsNull Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull @@ -16,7 +15,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput diff --git a/conformance/failure_list_ruby_mac.txt b/conformance/failure_list_ruby_mac.txt index 876184deb6..ceb2054fa4 100644 --- a/conformance/failure_list_ruby_mac.txt +++ b/conformance/failure_list_ruby_mac.txt @@ -5,7 +5,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.Int64FieldBeString.Validator Recommended.Proto3.JsonInput.MapFieldValueIsNull Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull @@ -15,7 +14,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput diff --git a/php/ext/google/protobuf/upb.c b/php/ext/google/protobuf/upb.c index 1d977437f6..cc5a54ab84 100644 --- a/php/ext/google/protobuf/upb.c +++ b/php/ext/google/protobuf/upb.c @@ -12431,18 +12431,32 @@ static size_t fmt_bool(bool val, char* buf, size_t length) { return n; } -static size_t fmt_int64(long val, char* buf, size_t length) { - size_t n = _upb_snprintf(buf, length, "%ld", val); +static size_t fmt_int64_as_number(long long val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "%lld", val); CHKLENGTH(n > 0 && n < length); return n; } -static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) { +static size_t fmt_uint64_as_number( + unsigned long long val, char* buf, size_t length) { size_t n = _upb_snprintf(buf, length, "%llu", val); CHKLENGTH(n > 0 && n < length); return n; } +static size_t fmt_int64_as_string(long long val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "\"%lld\"", val); + CHKLENGTH(n > 0 && n < length); + return n; +} + +static size_t fmt_uint64_as_string( + unsigned long long val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "\"%llu\"", val); + CHKLENGTH(n > 0 && n < length); + return n; +} + /* Print a map key given a field name. Called by scalar field handlers and by * startseq for repeated fields. */ static bool putkey(void *closure, const void *handler_data) { @@ -12486,8 +12500,11 @@ static bool putkey(void *closure, const void *handler_data) { static bool putmapkey_##type(void *closure, const void *handler_data, \ type val) { \ upb_json_printer *p = closure; \ + char data[64]; \ + size_t length = fmt_func(val, data, sizeof(data)); \ + UPB_UNUSED(handler_data); \ print_data(p, "\"", 1); \ - CHK(put##type(closure, handler_data, val)); \ + print_data(p, data, length); \ print_data(p, "\":", 2); \ return true; \ } @@ -12495,17 +12512,17 @@ static bool putkey(void *closure, const void *handler_data) { TYPE_HANDLERS(double, fmt_double) TYPE_HANDLERS(float, fmt_float) TYPE_HANDLERS(bool, fmt_bool) -TYPE_HANDLERS(int32_t, fmt_int64) -TYPE_HANDLERS(uint32_t, fmt_int64) -TYPE_HANDLERS(int64_t, fmt_int64) -TYPE_HANDLERS(uint64_t, fmt_uint64) +TYPE_HANDLERS(int32_t, fmt_int64_as_number) +TYPE_HANDLERS(uint32_t, fmt_int64_as_number) +TYPE_HANDLERS(int64_t, fmt_int64_as_string) +TYPE_HANDLERS(uint64_t, fmt_uint64_as_string) /* double and float are not allowed to be map keys. */ TYPE_HANDLERS_MAPKEY(bool, fmt_bool) -TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64) -TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64) -TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64) -TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64) +TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64_as_number) +TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64_as_number) +TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64_as_number) +TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64_as_number) #undef TYPE_HANDLERS #undef TYPE_HANDLERS_MAPKEY diff --git a/ruby/ext/google/protobuf_c/upb.c b/ruby/ext/google/protobuf_c/upb.c index 3d96c5ccc7..748205083d 100644 --- a/ruby/ext/google/protobuf_c/upb.c +++ b/ruby/ext/google/protobuf_c/upb.c @@ -16289,18 +16289,32 @@ static size_t fmt_bool(bool val, char* buf, size_t length) { return n; } -static size_t fmt_int64(long val, char* buf, size_t length) { - size_t n = _upb_snprintf(buf, length, "%ld", val); +static size_t fmt_int64_as_number(long long val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "%lld", val); CHKLENGTH(n > 0 && n < length); return n; } -static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) { +static size_t fmt_uint64_as_number( + unsigned long long val, char* buf, size_t length) { size_t n = _upb_snprintf(buf, length, "%llu", val); CHKLENGTH(n > 0 && n < length); return n; } +static size_t fmt_int64_as_string(long long val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "\"%lld\"", val); + CHKLENGTH(n > 0 && n < length); + return n; +} + +static size_t fmt_uint64_as_string( + unsigned long long val, char* buf, size_t length) { + size_t n = _upb_snprintf(buf, length, "\"%llu\"", val); + CHKLENGTH(n > 0 && n < length); + return n; +} + /* Print a map key given a field name. Called by scalar field handlers and by * startseq for repeated fields. */ static bool putkey(void *closure, const void *handler_data) { @@ -16344,8 +16358,11 @@ static bool putkey(void *closure, const void *handler_data) { static bool putmapkey_##type(void *closure, const void *handler_data, \ type val) { \ upb_json_printer *p = closure; \ + char data[64]; \ + size_t length = fmt_func(val, data, sizeof(data)); \ + UPB_UNUSED(handler_data); \ print_data(p, "\"", 1); \ - CHK(put##type(closure, handler_data, val)); \ + print_data(p, data, length); \ print_data(p, "\":", 2); \ return true; \ } @@ -16353,17 +16370,17 @@ static bool putkey(void *closure, const void *handler_data) { TYPE_HANDLERS(double, fmt_double) TYPE_HANDLERS(float, fmt_float) TYPE_HANDLERS(bool, fmt_bool) -TYPE_HANDLERS(int32_t, fmt_int64) -TYPE_HANDLERS(uint32_t, fmt_int64) -TYPE_HANDLERS(int64_t, fmt_int64) -TYPE_HANDLERS(uint64_t, fmt_uint64) +TYPE_HANDLERS(int32_t, fmt_int64_as_number) +TYPE_HANDLERS(uint32_t, fmt_int64_as_number) +TYPE_HANDLERS(int64_t, fmt_int64_as_string) +TYPE_HANDLERS(uint64_t, fmt_uint64_as_string) /* double and float are not allowed to be map keys. */ TYPE_HANDLERS_MAPKEY(bool, fmt_bool) -TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64) -TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64) -TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64) -TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64) +TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64_as_number) +TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64_as_number) +TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64_as_number) +TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64_as_number) #undef TYPE_HANDLERS #undef TYPE_HANDLERS_MAPKEY diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb index 2945003b03..fa1e2ff7d9 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -1108,9 +1108,9 @@ module CommonTests expected = { optionalInt32: 0, - optionalInt64: 0, + optionalInt64: "0", optionalUint32: 0, - optionalUint64: 0, + optionalUint64: "0", optionalBool: false, optionalFloat: 0, optionalDouble: 0, @@ -1142,9 +1142,9 @@ module CommonTests expected = { optionalInt32: 0, - optionalInt64: 0, + optionalInt64: "0", optionalUint32: 0, - optionalUint64: 0, + optionalUint64: "0", optionalBool: false, optionalFloat: 0, optionalDouble: 0, @@ -1177,9 +1177,9 @@ module CommonTests expected = { optionalInt32: 0, - optionalInt64: 0, + optionalInt64: "0", optionalUint32: 0, - optionalUint64: 0, + optionalUint64: "0", optionalBool: false, optionalFloat: 0, optionalDouble: 0, From 8ccdc44dde33eed7f02fc40f2d2b51576cdd7d71 Mon Sep 17 00:00:00 2001 From: Hao Nguyen Date: Mon, 17 Jun 2019 13:20:44 -0700 Subject: [PATCH 10/17] Update GSON version --- java/util/pom.xml | 268 +++++++++++++++++++++++----------------------- 1 file changed, 134 insertions(+), 134 deletions(-) diff --git a/java/util/pom.xml b/java/util/pom.xml index 657f9fe91f..5bb4bafae8 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -1,139 +1,139 @@ - - - 4.0.0 - - com.google.protobuf - protobuf-parent - 3.8.0 - - - protobuf-java-util - bundle - - Protocol Buffers [Util] - Utilities for Protocol Buffers - - - - ${project.groupId} - protobuf-java - - - com.google.guava - guava - - - com.google.errorprone - error_prone_annotations - 2.3.2 - - - com.google.guava - guava-testlib - test - - - com.google.code.gson - gson - 2.7 - - - junit - junit - - - org.easymock - easymock - - - org.easymock - easymockclassextension - + + + 4.0.0 + + com.google.protobuf + protobuf-parent + 3.8.0 + + + protobuf-java-util + bundle + + Protocol Buffers [Util] + Utilities for Protocol Buffers + + + + ${project.groupId} + protobuf-java + + + com.google.guava + guava + + + com.google.errorprone + error_prone_annotations + 2.3.2 + + + com.google.guava + guava-testlib + test + + + com.google.code.gson + gson + 2.8.5 + + + junit + junit + + + org.easymock + easymock + + + org.easymock + easymockclassextension + com.google.truth truth test - - - - - ../core/src/test/proto - - - - - - maven-antrun-plugin - - - - generate-test-sources - generate-test-sources - - - - - - - - - - - - - - - - run - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-generated-test-sources - generate-test-sources - - add-test-source - - - - ${generated.testsources.dir} - - - - - - - - - org.apache.felix - maven-bundle-plugin - true - - - https://developers.google.com/protocol-buffers/ - com.google.protobuf.util - com.google.protobuf.util;version=${project.version} - - - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - - - + + + + + ../core/src/test/proto + + + + + + maven-antrun-plugin + + + + generate-test-sources + generate-test-sources + + + + + + + + + + + + + + + + run + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-generated-test-sources + generate-test-sources + + add-test-source + + + + ${generated.testsources.dir} + + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + https://developers.google.com/protocol-buffers/ + com.google.protobuf.util + com.google.protobuf.util;version=${project.version} + + + + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + + + From f98b3401bf731786d8e990d203b060186ff1f634 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 18 Jun 2019 00:45:53 -0700 Subject: [PATCH 11/17] Removed all use of STLDelete*() in ObjC and C# Generators. Other languages will have this removed inside Google first. These functions are subject to ADL and cause problems. --- .../csharp/csharp_bootstrap_unittest.cc | 22 ++- .../compiler/objectivec/objectivec_file.cc | 67 ++++----- .../compiler/objectivec/objectivec_file.h | 6 +- .../compiler/objectivec/objectivec_message.cc | 127 ++++++------------ .../compiler/objectivec/objectivec_message.h | 8 +- 5 files changed, 83 insertions(+), 147 deletions(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index 33c5619843..978fdf02b6 100644 --- a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc @@ -77,23 +77,19 @@ class MockErrorCollector : public MultiFileErrorCollector { class MockGeneratorContext : public GeneratorContext { public: - MockGeneratorContext() {} - ~MockGeneratorContext() { - STLDeleteValues(&files_); - } - void ExpectFileMatches(const string& virtual_filename, const string& physical_filename) { - string* expected_contents = FindPtrOrNull(files_, virtual_filename); - ASSERT_TRUE(expected_contents != NULL) + auto it = files_.find(virtual_filename); + ASSERT_TRUE(it != files_.end()) << "Generator failed to generate file: " << virtual_filename; + string expected_contents = *it->second; string actual_contents; GOOGLE_CHECK_OK( File::GetContentsAsText(TestSourceDir() + "/" + physical_filename, &actual_contents, true)) << "Unable to get " << physical_filename; - EXPECT_TRUE(actual_contents == *expected_contents) + EXPECT_TRUE(actual_contents == expected_contents) << physical_filename << " needs to be regenerated. Please run " "generate_descriptor_proto.sh. Then add this file " "to your CL."; @@ -102,15 +98,13 @@ class MockGeneratorContext : public GeneratorContext { // implements GeneratorContext -------------------------------------- virtual io::ZeroCopyOutputStream* Open(const string& filename) { - string** map_slot = &files_[filename]; - delete *map_slot; - *map_slot = new string; - - return new io::StringOutputStream(*map_slot); + auto& map_slot = files_[filename]; + map_slot.reset(new std::string); + return new io::StringOutputStream(map_slot.get()); } private: - std::map files_; + std::map> files_; }; class GenerateAndTest { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index d4a4d708f1..7bc585e9ba 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -192,27 +192,21 @@ FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options) options_(options) { for (int i = 0; i < file_->enum_type_count(); i++) { EnumGenerator *generator = new EnumGenerator(file_->enum_type(i)); - enum_generators_.push_back(generator); + enum_generators_.emplace_back(generator); } for (int i = 0; i < file_->message_type_count(); i++) { MessageGenerator *generator = new MessageGenerator(root_class_name_, file_->message_type(i), options_); - message_generators_.push_back(generator); + message_generators_.emplace_back(generator); } for (int i = 0; i < file_->extension_count(); i++) { ExtensionGenerator *generator = new ExtensionGenerator(root_class_name_, file_->extension(i)); - extension_generators_.push_back(generator); + extension_generators_.emplace_back(generator); } } -FileGenerator::~FileGenerator() { - STLDeleteContainerPointers(enum_generators_.begin(), enum_generators_.end()); - STLDeleteContainerPointers(message_generators_.begin(), - message_generators_.end()); - STLDeleteContainerPointers(extension_generators_.begin(), - extension_generators_.end()); -} +FileGenerator::~FileGenerator() {} void FileGenerator::GenerateHeader(io::Printer *printer) { std::set headers; @@ -270,9 +264,8 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { "\n"); std::set fwd_decls; - for (std::vector::iterator iter = message_generators_.begin(); - iter != message_generators_.end(); ++iter) { - (*iter)->DetermineForwardDeclarations(&fwd_decls); + for (const auto& generator : message_generators_) { + generator->DetermineForwardDeclarations(&fwd_decls); } for (std::set::const_iterator i(fwd_decls.begin()); i != fwd_decls.end(); ++i) { @@ -287,14 +280,12 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { "\n"); // need to write out all enums first - for (std::vector::iterator iter = enum_generators_.begin(); - iter != enum_generators_.end(); ++iter) { - (*iter)->GenerateHeader(printer); + for (const auto& generator : enum_generators_) { + generator->GenerateHeader(printer); } - for (std::vector::iterator iter = message_generators_.begin(); - iter != message_generators_.end(); ++iter) { - (*iter)->GenerateEnumHeader(printer); + for (const auto& generator : message_generators_) { + generator->GenerateEnumHeader(printer); } // For extensions to chain together, the Root gets created even if there @@ -323,18 +314,15 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { "@interface $root_class_name$ (DynamicMethods)\n", "root_class_name", root_class_name_); - for (std::vector::iterator iter = - extension_generators_.begin(); - iter != extension_generators_.end(); ++iter) { - (*iter)->GenerateMembersHeader(printer); + for (const auto& generator : extension_generators_) { + generator->GenerateMembersHeader(printer); } printer->Print("@end\n\n"); } // extension_generators_.size() > 0 - for (std::vector::iterator iter = message_generators_.begin(); - iter != message_generators_.end(); ++iter) { - (*iter)->GenerateMessageHeader(printer); + for (const auto& generator : message_generators_) { + generator->GenerateMessageHeader(printer); } printer->Print( @@ -403,9 +391,8 @@ void FileGenerator::GenerateSource(io::Printer *printer) { } bool includes_oneof = false; - for (std::vector::iterator iter = message_generators_.begin(); - iter != message_generators_.end(); ++iter) { - if ((*iter)->IncludesOneOfDefinition()) { + for (const auto& generator : message_generators_) { + if (generator->IncludesOneOfDefinition()) { includes_oneof = true; break; } @@ -456,15 +443,11 @@ void FileGenerator::GenerateSource(io::Printer *printer) { printer->Print( "static GPBExtensionDescription descriptions[] = {\n"); printer->Indent(); - for (std::vector::iterator iter = - extension_generators_.begin(); - iter != extension_generators_.end(); ++iter) { - (*iter)->GenerateStaticVariablesInitialization(printer); + for (const auto& generator : extension_generators_) { + generator->GenerateStaticVariablesInitialization(printer); } - for (std::vector::iterator iter = - message_generators_.begin(); - iter != message_generators_.end(); ++iter) { - (*iter)->GenerateStaticVariablesInitialization(printer); + for (const auto& generator : message_generators_) { + generator->GenerateStaticVariablesInitialization(printer); } printer->Outdent(); printer->Print( @@ -561,13 +544,11 @@ void FileGenerator::GenerateSource(io::Printer *printer) { "\n"); } - for (std::vector::iterator iter = enum_generators_.begin(); - iter != enum_generators_.end(); ++iter) { - (*iter)->GenerateSource(printer); + for (const auto& generator : enum_generators_) { + generator->GenerateSource(printer); } - for (std::vector::iterator iter = message_generators_.begin(); - iter != message_generators_.end(); ++iter) { - (*iter)->GenerateSource(printer); + for (const auto& generator : message_generators_) { + generator->GenerateSource(printer); } printer->Print( diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.h b/src/google/protobuf/compiler/objectivec/objectivec_file.h index ed7fad80a5..fd57263484 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.h @@ -65,9 +65,9 @@ class FileGenerator { string root_class_name_; bool is_bundled_proto_; - std::vector enum_generators_; - std::vector message_generators_; - std::vector extension_generators_; + std::vector> enum_generators_; + std::vector> message_generators_; + std::vector> extension_generators_; const Options options_; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index a9e845397b..6731e37a77 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -184,18 +184,18 @@ MessageGenerator::MessageGenerator(const string& root_classname, GetOptionalDeprecatedAttribute(descriptor, descriptor->file(), false, true)) { for (int i = 0; i < descriptor_->extension_count(); i++) { - extension_generators_.push_back( + extension_generators_.emplace_back( new ExtensionGenerator(class_name_, descriptor_->extension(i))); } for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { OneofGenerator* generator = new OneofGenerator(descriptor_->oneof_decl(i)); - oneof_generators_.push_back(generator); + oneof_generators_.emplace_back(generator); } for (int i = 0; i < descriptor_->enum_type_count(); i++) { EnumGenerator* generator = new EnumGenerator(descriptor_->enum_type(i)); - enum_generators_.push_back(generator); + enum_generators_.emplace_back(generator); } for (int i = 0; i < descriptor_->nested_type_count(); i++) { @@ -203,32 +203,20 @@ MessageGenerator::MessageGenerator(const string& root_classname, new MessageGenerator(root_classname_, descriptor_->nested_type(i), options); - nested_message_generators_.push_back(generator); + nested_message_generators_.emplace_back(generator); } } -MessageGenerator::~MessageGenerator() { - STLDeleteContainerPointers(extension_generators_.begin(), - extension_generators_.end()); - STLDeleteContainerPointers(enum_generators_.begin(), enum_generators_.end()); - STLDeleteContainerPointers(nested_message_generators_.begin(), - nested_message_generators_.end()); - STLDeleteContainerPointers(oneof_generators_.begin(), - oneof_generators_.end()); -} +MessageGenerator::~MessageGenerator() {} void MessageGenerator::GenerateStaticVariablesInitialization( io::Printer* printer) { - for (std::vector::iterator iter = - extension_generators_.begin(); - iter != extension_generators_.end(); ++iter) { - (*iter)->GenerateStaticVariablesInitialization(printer); + for (const auto& generator : extension_generators_) { + generator->GenerateStaticVariablesInitialization(printer); } - for (std::vector::iterator iter = - nested_message_generators_.begin(); - iter != nested_message_generators_.end(); ++iter) { - (*iter)->GenerateStaticVariablesInitialization(printer); + for (const auto& generator : nested_message_generators_) { + generator->GenerateStaticVariablesInitialization(printer); } } @@ -241,10 +229,8 @@ void MessageGenerator::DetermineForwardDeclarations(std::set* fwd_decls) } } - for (std::vector::iterator iter = - nested_message_generators_.begin(); - iter != nested_message_generators_.end(); ++iter) { - (*iter)->DetermineForwardDeclarations(fwd_decls); + for (const auto& generator : nested_message_generators_) { + generator->DetermineForwardDeclarations(fwd_decls); } } @@ -253,10 +239,8 @@ bool MessageGenerator::IncludesOneOfDefinition() const { return true; } - for (std::vector::const_iterator iter = - nested_message_generators_.begin(); - iter != nested_message_generators_.end(); ++iter) { - if ((*iter)->IncludesOneOfDefinition()) { + for (const auto& generator : nested_message_generators_) { + if (generator->IncludesOneOfDefinition()) { return true; } } @@ -265,40 +249,31 @@ bool MessageGenerator::IncludesOneOfDefinition() const { } void MessageGenerator::GenerateEnumHeader(io::Printer* printer) { - for (std::vector::iterator iter = enum_generators_.begin(); - iter != enum_generators_.end(); ++iter) { - (*iter)->GenerateHeader(printer); + for (const auto& generator : enum_generators_) { + generator->GenerateHeader(printer); } - for (std::vector::iterator iter = - nested_message_generators_.begin(); - iter != nested_message_generators_.end(); ++iter) { - (*iter)->GenerateEnumHeader(printer); + for (const auto& generator : nested_message_generators_) { + generator->GenerateEnumHeader(printer); } } void MessageGenerator::GenerateExtensionRegistrationSource( io::Printer* printer) { - for (std::vector::iterator iter = - extension_generators_.begin(); - iter != extension_generators_.end(); ++iter) { - (*iter)->GenerateRegistrationSource(printer); + for (const auto& generator : extension_generators_) { + generator->GenerateRegistrationSource(printer); } - for (std::vector::iterator iter = - nested_message_generators_.begin(); - iter != nested_message_generators_.end(); ++iter) { - (*iter)->GenerateExtensionRegistrationSource(printer); + for (const auto& generator : nested_message_generators_) { + generator->GenerateExtensionRegistrationSource(printer); } } void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { // This a a map entry message, just recurse and do nothing directly. if (IsMapEntryMessage(descriptor_)) { - for (std::vector::iterator iter = - nested_message_generators_.begin(); - iter != nested_message_generators_.end(); ++iter) { - (*iter)->GenerateMessageHeader(printer); + for (const auto& generator : nested_message_generators_) { + generator->GenerateMessageHeader(printer); } return; } @@ -325,9 +300,8 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { printer->Print("};\n\n"); } - for (std::vector::iterator iter = oneof_generators_.begin(); - iter != oneof_generators_.end(); ++iter) { - (*iter)->GenerateCaseEnum(printer); + for (const auto& generator : oneof_generators_) { + generator->GenerateCaseEnum(printer); } string message_comments; @@ -366,9 +340,8 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { } if (!oneof_generators_.empty()) { - for (std::vector::iterator iter = oneof_generators_.begin(); - iter != oneof_generators_.end(); ++iter) { - (*iter)->GenerateClearFunctionDeclaration(printer); + for (const auto& generator : oneof_generators_) { + generator->GenerateClearFunctionDeclaration(printer); } printer->Print("\n"); } @@ -376,18 +349,14 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { if (descriptor_->extension_count() > 0) { printer->Print("@interface $classname$ (DynamicMethods)\n\n", "classname", class_name_); - for (std::vector::iterator iter = - extension_generators_.begin(); - iter != extension_generators_.end(); ++iter) { - (*iter)->GenerateMembersHeader(printer); + for (const auto& generator : extension_generators_) { + generator->GenerateMembersHeader(printer); } printer->Print("@end\n\n"); } - for (std::vector::iterator iter = - nested_message_generators_.begin(); - iter != nested_message_generators_.end(); ++iter) { - (*iter)->GenerateMessageHeader(printer); + for (const auto& generator : nested_message_generators_) { + generator->GenerateMessageHeader(printer); } } @@ -409,9 +378,8 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { printer->Print("@implementation $classname$\n\n", "classname", class_name_); - for (std::vector::iterator iter = oneof_generators_.begin(); - iter != oneof_generators_.end(); ++iter) { - (*iter)->GeneratePropertyImplementation(printer); + for (const auto& generator : oneof_generators_) { + generator->GeneratePropertyImplementation(printer); } for (int i = 0; i < descriptor_->field_count(); i++) { @@ -447,9 +415,8 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { sizeof_has_storage = 1; } // Tell all the fields the oneof base. - for (std::vector::iterator iter = oneof_generators_.begin(); - iter != oneof_generators_.end(); ++iter) { - (*iter)->SetOneofIndexBase(sizeof_has_storage); + for (const auto& generator : oneof_generators_) { + generator->SetOneofIndexBase(sizeof_has_storage); } field_generators_.SetOneofIndexBase(sizeof_has_storage); // sizeof_has_storage needs enough bits for the single fields that aren't in @@ -547,11 +514,9 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { if (oneof_generators_.size() != 0) { printer->Print( " static const char *oneofs[] = {\n"); - for (std::vector::iterator iter = oneof_generators_.begin(); - iter != oneof_generators_.end(); ++iter) { - printer->Print( - " \"$name$\",\n", - "name", (*iter)->DescriptorName()); + for (const auto& generator : oneof_generators_) { + printer->Print(" \"$name$\",\n", "name", + generator->DescriptorName()); } printer->Print( " };\n" @@ -624,21 +589,17 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { .GenerateCFunctionImplementations(printer); } - for (std::vector::iterator iter = oneof_generators_.begin(); - iter != oneof_generators_.end(); ++iter) { - (*iter)->GenerateClearFunctionImplementation(printer); + for (const auto& generator : oneof_generators_) { + generator->GenerateClearFunctionImplementation(printer); } } - for (std::vector::iterator iter = enum_generators_.begin(); - iter != enum_generators_.end(); ++iter) { - (*iter)->GenerateSource(printer); + for (const auto& generator : enum_generators_) { + generator->GenerateSource(printer); } - for (std::vector::iterator iter = - nested_message_generators_.begin(); - iter != nested_message_generators_.end(); ++iter) { - (*iter)->GenerateSource(printer); + for (const auto& generator : nested_message_generators_) { + generator->GenerateSource(printer); } } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h index 1d41628f68..55eda0b8ef 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -85,10 +85,10 @@ class MessageGenerator { FieldGeneratorMap field_generators_; const string class_name_; const string deprecated_attribute_; - std::vector extension_generators_; - std::vector enum_generators_; - std::vector nested_message_generators_; - std::vector oneof_generators_; + std::vector> extension_generators_; + std::vector> enum_generators_; + std::vector> nested_message_generators_; + std::vector> oneof_generators_; }; } // namespace objectivec From 21773efa23d26b1d653514a96de8372ce081567a Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 18 Jun 2019 10:07:18 -0700 Subject: [PATCH 12/17] Include protobuf_deps.bzl in generated release archives This fixes #5918. --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 33616c5854..290c7b5b07 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1218,6 +1218,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ examples/pubspec.yaml \ examples/third_party/zlib.BUILD \ protobuf.bzl \ + protobuf_deps.bzl \ python/release/wheel/build_wheel_manylinux.sh \ python/release/wheel/Dockerfile \ python/release/wheel/protobuf_optimized_pip.sh \ From 43307d4da09e1a27b132cd3a2c29824efaafef25 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Tue, 18 Jun 2019 19:31:50 +0200 Subject: [PATCH 13/17] php: Fix formatting of Duration (#6155) * php: Fixed php notices for unknown enum indices * php: Fixed formatting of Duration This fixes: * Missing nanoseconds. The nanoseconds where divided as a float and implicitly converted to a string before being passed to bcadd. This can result in a float formatted in scientific/exponential notation, which bcmath doesn't understand. * Durations are supposed to be formatted without trailing zeroes. --- conformance/failure_list_php.txt | 4 --- .../Protobuf/Internal/EnumDescriptor.php | 15 ++++++++--- php/src/Google/Protobuf/Internal/GPBUtil.php | 26 ++++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/conformance/failure_list_php.txt b/conformance/failure_list_php.txt index f76e9d731f..28ca461d47 100644 --- a/conformance/failure_list_php.txt +++ b/conformance/failure_list_php.txt @@ -3,10 +3,6 @@ Recommended.FieldMaskPathsDontRoundTrip.JsonOutput Recommended.FieldMaskTooManyUnderscore.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput -Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator -Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator -Recommended.Proto3.JsonInput.DurationHas9FractionalDigits.Validator -Recommended.Proto3.JsonInput.DurationHasZeroFractionalDigit.Validator Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter Required.Proto3.JsonInput.FloatFieldTooLarge Required.Proto3.JsonInput.FloatFieldTooSmall diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptor.php b/php/src/Google/Protobuf/Internal/EnumDescriptor.php index 82a427670c..7af4f84012 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptor.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptor.php @@ -39,17 +39,26 @@ class EnumDescriptor public function getValueByNumber($number) { - return $this->value[$number]; + if (isset($this->value[$number])) { + return $this->value[$number]; + } + return null; } public function getValueByName($name) { - return $this->name_to_value[$name]; + if (isset($this->name_to_value[$name])) { + return $this->name_to_value[$name]; + } + return null; } public function getValueDescriptorByIndex($index) { - return $this->value_descriptor[$index]; + if (isset($this->value_descriptor[$index])) { + return $this->value_descriptor[$index]; + } + return null; } public function getValueCount() diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 0beedba333..7ec3ca2294 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -504,17 +504,29 @@ class GPBUtil 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 large.'); } - if (bccomp($value->getSeconds(), "-315576000001") != 1) { - throw new GPBDecodeException("Duration number too small."); + if (bccomp($value->getSeconds(), '-315576000001') != 1) { + throw new GPBDecodeException('Duration number too small.'); + } + + $nanos = $value->getNanos(); + if ($nanos === 0) { + return (string) $value->getSeconds(); } - return strval(bcadd($value->getSeconds(), - $value->getNanos() / 1000000000.0, 9)); - } + if ($nanos % 1000000 === 0) { + $digits = 3; + } elseif ($nanos % 1000 === 0) { + $digits = 6; + } else { + $digits = 9; + } + $nanos = bcdiv($nanos, '1000000000', $digits); + return bcadd($value->getSeconds(), $nanos, $digits); + } public static function parseFieldMask($paths_string) { From 7f84a943667358a53bd5d255ee9769ca83e75cd9 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 18 Jun 2019 17:12:55 -0700 Subject: [PATCH 14/17] Make php message class final to avoid mocking (#6277) * Make php message class final Because proto messages are just data object, they should not be mocked. Explicitly make them final to avoid accidental usage. * Update generated descriptors --- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 205207 -> 205207 bytes .../Protobuf/Internal/DescriptorProto.php | 2 +- .../DescriptorProto/ExtensionRange.php | 2 +- .../DescriptorProto/ReservedRange.php | 2 +- .../Protobuf/Internal/EnumDescriptorProto.php | 2 +- .../EnumDescriptorProto/EnumReservedRange.php | 2 +- .../Google/Protobuf/Internal/EnumOptions.php | 2 +- .../Internal/EnumValueDescriptorProto.php | 2 +- .../Protobuf/Internal/EnumValueOptions.php | 2 +- .../Internal/ExtensionRangeOptions.php | 2 +- .../Internal/FieldDescriptorProto.php | 2 +- .../Google/Protobuf/Internal/FieldOptions.php | 2 +- .../Protobuf/Internal/FileDescriptorProto.php | 2 +- .../Protobuf/Internal/FileDescriptorSet.php | 2 +- .../Google/Protobuf/Internal/FileOptions.php | 2 +- .../Protobuf/Internal/GeneratedCodeInfo.php | 2 +- .../Internal/GeneratedCodeInfo/Annotation.php | 2 +- .../Protobuf/Internal/MessageOptions.php | 2 +- .../Internal/MethodDescriptorProto.php | 2 +- .../Protobuf/Internal/MethodOptions.php | 2 +- .../Internal/OneofDescriptorProto.php | 2 +- .../Google/Protobuf/Internal/OneofOptions.php | 2 +- .../Internal/ServiceDescriptorProto.php | 2 +- .../Protobuf/Internal/ServiceOptions.php | 2 +- .../Protobuf/Internal/SourceCodeInfo.php | 2 +- .../Internal/SourceCodeInfo/Location.php | 2 +- .../Protobuf/Internal/UninterpretedOption.php | 2 +- .../Internal/UninterpretedOption/NamePart.php | 2 +- .../protobuf/compiler/php/php_generator.cc | 2 +- 29 files changed, 28 insertions(+), 28 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index bc3979e965ef354b8491b637c3ca441bb1050365..71256aea778e8a7f1d74a709e2c84ab3acef5727 100644 GIT binary patch delta 5317 zcmYjVYiv}<72dgbX6)R3c=vjF`GFT>8?Z?+k2Xa>QwT_fD5Ponkn9LmA*P{fOTwdV zDm5z;OiKD=Ra$bR$T1O?s{jGjDrl?xNPfgn>RE@2|Otb`@zvtDm~ zJ$rp^uWdO_)DhgVlG5e9c6h#lj9|@518ss|TkX8b9Gg4B}p2sRd@_m$SoViXRZWa&~-?fwakPY%;Kv;L>#lmJobmtuw|{ z2<#p3)-!a{(&UG1M$*s>5HZ`U-NRRqY}jmw<(rK$kV6WL2k zS*^WhB8Xrk!bA|kMuZ7FK2LMlw8^fjcIt3=VI1CFuc?_eEWK-oBfg6|wPJ`m6s*xZ zro3M_vjtz73U*MNiXnC=_^e8kyL{UAKHJQ;YzSLiAuUcoh;!PA6A(nxMx201cACW5 zLZMOD1N-;4zWn~yuz=1U7=Z#|8=x;xK*WDQ0wtYAT=~!rUFW{eBJg}@mnNNV3%Nxs z@U&+iE@$;D-OhDZup+B=9*(Pq0Af=+Ps}zDS+(zT?Q{pe7jsrXz1C{TKy$3mu z796PWFq8%c>^R7Al4b|+Z#bV-a3Hqde){poYi@Ib^aMRJl>!)>M0}*pI>QSg{{)kM|b*7W5SRQMEnfH$fvXLUr_I2UoLKWouth zJl)E^pn-HN`*=L5%cEP_$LE+{*eJe_&ucWRD87%^Eph%qgC%0&3iW%(zRCXC(jNri z2+$t{pqtds^Nk9-5vUD0)eR*;*=GnnG$v75D(qr%>M>P;X1@IRH(ctX>XXydwK)@ z##s%UA^}n4uqhG{8;4DifGBd<6d6U4H&v0(M5)M|rbr-c1N4goL~1vwNJ=f{%FlV| zz8-fmcz(`H%bg!0vlwMI;x%nzFRmLgIl+iPBj#WMv1NqED^(i+k<$pDU*n9B_F{Bt z$GrYc?C&jO0R>Hmv4DbZN39qDb-G##tpnKVrYM0S&==`j>?Pc?mOjGBJW zG#v=r0R5%|BH%sK^fFgY^U!|be`CtvIn7JwI{&7Yl~LDcyhGn&4_anSQZORYjA
*7bo`Cd9|chuN`GWZ$11s+(g6|Wktw|l z3AGElRNg0BnAqGd^rb3Or33n<1ETbHq4gGb0xFH*<#i{g6Hu^Lh zW~~{aKd-PNR7U8J2_QCQgdSCZ$SNbMYm@*1QF}(DmK%uLGoqW-_r0sXoGQTGv3cfytLh|pPG zcLLn+h|*ckAl03qy1TP`wz53i)@>4k6;ZlP-GJECZR!R@LfxirK-ArB>IOvJ-BkA^ zi7G+wiVuYKp?Cb-Y~ra8M9CcW$%ma{9~Znzec=^G7#QXR2Gns}R8-;#D2a)hc)}Zg zjy2St5WKwLM<2iwV)h*83GD}b(p&f)wmN-M@L0i*?%qj}aMiat0XBI`Sf@pUIx%3J z3Jm_w5kQ>EDG~PP3m}4@5>@`|2@p*^-q5T z0OIrpap>0fn$yQB;`9oA`hbYjYfe9bb2+1=zbZku{)~|T5VisO5&%TRGbDlE+L*Pj zD?b*Yf$V>uXK%6ck40&v^EV5py=GmWS;q0dtt^tL2Y>ic=& z&JPSAJuep2s*j;dXw1VnEyh;X@C1=j_U^j|Mn1=9tAms}@F)m4xB zi{9uDSXcUDz(E;Z6#6yjs(daAw^mb<4lauN2AvJso)gv*y+|hwXtJT7RJnkOPC6&t zI^ztcoLID&n9|4w@RG0=>s1?6fQE`*X_th4_`?@emqcQraaMa97U`t0^|G+cBK@!d zG)(jyyBs7%&#}uQjegVX0zCoM<)GVez9KABJRArbDtdWc36i3h*AS~acdSnTAflf+2vP50IbAv(M<#^z|C|RzmL0MtrDjAq-H(IP8j}96B4BtQ zl(;2tl;D~GQ;@Fg|F*LZ`{geD_)#)dc2v+Mqi$fp)-GA@k2mFkP+bz^jijy&7$RM= zs>z8vrP=^Jb;;^RXTZ|oK+==_@<;5uEZtKaj#S!H9FFcyPjNU>YEN-Enpr)?;aDlc z^-#E;hz?cKR!rz*THwPWW`yrX;A>Wx_TJ4*y4#5<<5%Ag36 zHLA19fF$n7+J(+9bOb~k_p0`?*EWq8Gm)6ai_0M~jmz@61tt>DxWoV-Hl2ZC%Db_b leYR?{{gyel28Bu delta 5317 zcmYjVYiv}<72dgbX6)R3c=vjF`GFT>8?Z?+k2Xa>69`C!D5Ponkn9LmA*P{fOTwdV zDm80rBbrolgi3p*7}MZ7N_a_@KwafWlpls7*Nd@>{J;njBAg=QVhnOips4-M+?l=m z&)=Cd-+9b8=g!*eiFiGc?i0i8{+W}*YwBgjW-GR)ylKh4^``pH) z)^^*L<3t_79V;na-ff5H8^{P&tTfOj_>I-hLFU-p5iURLJ*sAJr_b8axxSAGVGCfw zK#Sn4xlWjNJmK=c+E&boI2<5EC>-@YpP-HT5E~VYI2I4P@?$&nmCY1Q7@i;7g|nSe z0iLiGLR#63T*St##;mCYX5^Q(!$pc85WBK=e35~)$*!$4u#n)=bp{p?d}^(8o2d}k zJLs*cW&dg%3<59&7z_e1aA zb?k2AND#n6fRP}8g#aUVyhKx22ry!o`)3ulECd*_E9%WE0*u(T%bfS6ssPS+GW|1(5Wz--J3#~+5$@RWd78tfO?FwiQ-#9|0LV<@m z?fs^nE%@4Wu!Gu^53xhR7gU_2=q`Gc)t0i8WC0tLc0KwqGMi2r~DN;-?U@{t`H=DyA%@O)$!CY`@n$Sq=l zr#bWA<*b^eo4L*kR%F%8!*SIRKx}H}iP;7st7bmWKQpZ2keYevlV%l%)XZy^Ixz~s zL$2J1CmU*^QMpBF@&3P;j1WzfQTQHl5dN>-l6pN>=H6!=T1qlHIfpz?jO_W!0R%@oFD=t; zBl>!R#$l}-;crXSiT={m-i0*7IfwNQMFysEF!GbLa(988;0Yrdat_KSs0`zhWmZudzn6loN>)HB-Y``zb8t@D7XM+L+ z__KVDKV>480DqR3_>&kA{8?UI>(D@mkPZgC{TtYeYX<^;Nmi~uQ}6-*0N0->K=2Q6 zJqaR6f05eZ`Tmr9r|nnfhiy2loh0z5_RP$4_)WX{{}|kI?6FrsJtj?Z;Z-&ZUg?t zS&f+@0a4_bDH0GH$4rrcD00jc8AXxTRFTg|smN=lNFZzj^os;UYS*YpN-gHf&w1#+ z9(OT#e$ESvogX2y7-e?TtJ}n0S$EUq1S107GzSZaEjM|*RJ8#RIo;&*E1YrCUW_j7 zg!lJN?4J!20R>HmiGYG`?Pc?mOjGBJW zG#v=r0R5%|BH%sK^deWz@X&tYe`AW^Il~L*I{%@T6;an8dT)Q5ebw;LBn2ZPJv1!? z#GZ$yWq>w8eO&?3vWKQ+fN0r6Y8jPYMD;xOOUK_R{c#Y5q4dY5bgYuADIE||9-GpO zkWjOrOXYpKg^A70LSL#PRXU(wIv`4K7Fus{SGI`IA9d+*1ZWX>#$BQ(J=s{N2qZ;SN+ zDE?3ohKfHV^hCj`^3@Xs5Md4pJyGJw=&;xSJbQWbVN-Wp)eY#^4T!oAo4OOO^hD^a zt~&v4PZZ8_hN;oaWQ+2^OW`jKH)9=E?b>GA$Tn3M|bapNVw|ToB*3VC9Kn;Mx7Wi zP6Y=4=LjH9<&+5f^92yWPl+=B^#q6}oD%i^XCDwvI4xwgp+XZ*i$qmKoqmD>cl)Qm z0RVBjgE(~SyUpoi6>++SK7ByM={BdIz`2}J(qEOJTYtt#00`RveF*>};u(^_?`_Ol z*Oi}$&|v2AOY9w1{D~+mb^7QP<=Qx%9%210^WOK_7MAW24mC&80v*pe!7Ekw6h_)G zL;?e{IVYn2IVcb0a84x40}mvBPNWv(IN@+!@P#=CYB>y=GmWS;q0dtt^tL2Y>ic=& z&JPSAJuenis*j;dXw1VnEyh;Xr41=j_U^j|Mn1=9tAm)sGOs;eIL zecqQpWJl9|0S9H&C-iI3Rr&M@w^CD*4*EoOjm`#b&kAdaUZj%-G}+Kks%*eSC!G~; zm2n1BRxDafOlf2Tcu`o3^{NdjKtn~Zw2MMN{NW3#iz2bmIIF!ii*!=h+Al1#NIz@< z4HG@b`h%qCIo2=I=r_GC&=XMg2i=DAC1IK3;Xu$((aY;nkQBYVE{TLW8hUwMA~DeG z(^YRPVfl9t2uuS3(@F`dfgmgO$P(@Xos@cHiK=R6j6vPSc;txC6>n7oyAmIzq5j(h zLKKrUS~KO1thI1ktJGP-3Qe?1tqDM6*(#I%a~=>`w#tf>ni0ixKMqK1RQkV)fZ=^W z;+C`&;FZUHRc?W_9I;xdipplDL~kkliAN+OL9 z$z)ZoMw0cAgvx2mkO%OvPH; z+0~-!vT&aBD~K*hdbr_b-eAApcEe~6MriJa49`;f1w^nLa(2oOTNpoLF z>z>veFucEzPSSaop=ZDpW88apH#?LbH$^EkiW)Z>PzLNAHyTg|L>f05PzGpV+-Sfz z;K;{G125=c;J77uRmsz-&9657eDBU3J5}LLsU16i>iu~STfGs>erJh*gm}wzRv8pQ zvO;xM8IZ&+S-H^prH+7zlU~_g_U5L^d?pgpWPUj$rb$^mH^)TcnUomdS50SNnD)l@ lvTLiR^QlNf)A>}Sp=nt>J4Z!7Y^M+2-p4Yx_gSY-{vX!_kkSAE diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto.php b/php/src/Google/Protobuf/Internal/DescriptorProto.php index 3b215d52ae..2d52831451 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto.php @@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.DescriptorProto */ -class DescriptorProto extends \Google\Protobuf\Internal\Message +final class DescriptorProto extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field optional string name = 1; diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php index a2057fd5d1..fb98f7d5a0 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.DescriptorProto.ExtensionRange */ -class ExtensionRange extends \Google\Protobuf\Internal\Message +final class ExtensionRange extends \Google\Protobuf\Internal\Message { /** * Inclusive. diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php index 73c964faa0..fa46419a53 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php @@ -17,7 +17,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.DescriptorProto.ReservedRange */ -class ReservedRange extends \Google\Protobuf\Internal\Message +final class ReservedRange extends \Google\Protobuf\Internal\Message { /** * Inclusive. diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php index da30fa9906..b7c3a208be 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php @@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.EnumDescriptorProto */ -class EnumDescriptorProto extends \Google\Protobuf\Internal\Message +final class EnumDescriptorProto extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field optional string name = 1; diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php index e1079585ec..0103a1b301 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php @@ -19,7 +19,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.EnumDescriptorProto.EnumReservedRange */ -class EnumReservedRange extends \Google\Protobuf\Internal\Message +final class EnumReservedRange extends \Google\Protobuf\Internal\Message { /** * Inclusive. diff --git a/php/src/Google/Protobuf/Internal/EnumOptions.php b/php/src/Google/Protobuf/Internal/EnumOptions.php index 3d74c81c21..4c73d52740 100644 --- a/php/src/Google/Protobuf/Internal/EnumOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.EnumOptions */ -class EnumOptions extends \Google\Protobuf\Internal\Message +final class EnumOptions extends \Google\Protobuf\Internal\Message { /** * Set this option to true to allow mapping different tag names to the same diff --git a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php index 50bda008e8..d5a0a9afb5 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php @@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.EnumValueDescriptorProto */ -class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message +final class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field optional string name = 1; diff --git a/php/src/Google/Protobuf/Internal/EnumValueOptions.php b/php/src/Google/Protobuf/Internal/EnumValueOptions.php index a267c6d5e2..50ac904ff9 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumValueOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.EnumValueOptions */ -class EnumValueOptions extends \Google\Protobuf\Internal\Message +final class EnumValueOptions extends \Google\Protobuf\Internal\Message { /** * Is this enum value deprecated? diff --git a/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php b/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php index 00fbebecaf..97ad2c055f 100644 --- a/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php +++ b/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.ExtensionRangeOptions */ -class ExtensionRangeOptions extends \Google\Protobuf\Internal\Message +final class ExtensionRangeOptions extends \Google\Protobuf\Internal\Message { /** * The parser stores options it doesn't recognize here. See above. diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php index e578197515..6f8643c8d7 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php @@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.FieldDescriptorProto */ -class FieldDescriptorProto extends \Google\Protobuf\Internal\Message +final class FieldDescriptorProto extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field optional string name = 1; diff --git a/php/src/Google/Protobuf/Internal/FieldOptions.php b/php/src/Google/Protobuf/Internal/FieldOptions.php index 751c278d78..47d1951d16 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.FieldOptions */ -class FieldOptions extends \Google\Protobuf\Internal\Message +final class FieldOptions extends \Google\Protobuf\Internal\Message { /** * The ctype option instructs the C++ code generator to use a different diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php index cb10aa7939..e95205476c 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php @@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.FileDescriptorProto */ -class FileDescriptorProto extends \Google\Protobuf\Internal\Message +final class FileDescriptorProto extends \Google\Protobuf\Internal\Message { /** * file name, relative to root of source tree diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php index 9907b17d73..c9a38808fb 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php @@ -16,7 +16,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.FileDescriptorSet */ -class FileDescriptorSet extends \Google\Protobuf\Internal\Message +final class FileDescriptorSet extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field repeated .google.protobuf.FileDescriptorProto file = 1; diff --git a/php/src/Google/Protobuf/Internal/FileOptions.php b/php/src/Google/Protobuf/Internal/FileOptions.php index 6fea195ec1..9110005016 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions.php +++ b/php/src/Google/Protobuf/Internal/FileOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.FileOptions */ -class FileOptions extends \Google\Protobuf\Internal\Message +final class FileOptions extends \Google\Protobuf\Internal\Message { /** * Sets the Java package where classes generated from this .proto will be diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php index f5a65bea46..c99d77afa3 100644 --- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php +++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php @@ -17,7 +17,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.GeneratedCodeInfo */ -class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message +final class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message { /** * An Annotation connects some span of text in generated code to an element diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php index 09f958d251..8cc3cdf457 100644 --- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php +++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.GeneratedCodeInfo.Annotation */ -class Annotation extends \Google\Protobuf\Internal\Message +final class Annotation extends \Google\Protobuf\Internal\Message { /** * Identifies the element in the original source .proto file. This field diff --git a/php/src/Google/Protobuf/Internal/MessageOptions.php b/php/src/Google/Protobuf/Internal/MessageOptions.php index 4453942110..9032c97e9b 100644 --- a/php/src/Google/Protobuf/Internal/MessageOptions.php +++ b/php/src/Google/Protobuf/Internal/MessageOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.MessageOptions */ -class MessageOptions extends \Google\Protobuf\Internal\Message +final class MessageOptions extends \Google\Protobuf\Internal\Message { /** * Set true to use the old proto1 MessageSet wire format for extensions. diff --git a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php index 1bd5dd3e1c..25a2c166fd 100644 --- a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php @@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.MethodDescriptorProto */ -class MethodDescriptorProto extends \Google\Protobuf\Internal\Message +final class MethodDescriptorProto extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field optional string name = 1; diff --git a/php/src/Google/Protobuf/Internal/MethodOptions.php b/php/src/Google/Protobuf/Internal/MethodOptions.php index a2c729a9bb..a9c093ad5d 100644 --- a/php/src/Google/Protobuf/Internal/MethodOptions.php +++ b/php/src/Google/Protobuf/Internal/MethodOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.MethodOptions */ -class MethodOptions extends \Google\Protobuf\Internal\Message +final class MethodOptions extends \Google\Protobuf\Internal\Message { /** * Is this method deprecated? diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php index 9ecfe5cbfe..a703fcb702 100644 --- a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php @@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.OneofDescriptorProto */ -class OneofDescriptorProto extends \Google\Protobuf\Internal\Message +final class OneofDescriptorProto extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field optional string name = 1; diff --git a/php/src/Google/Protobuf/Internal/OneofOptions.php b/php/src/Google/Protobuf/Internal/OneofOptions.php index 46b516f301..749051f31f 100644 --- a/php/src/Google/Protobuf/Internal/OneofOptions.php +++ b/php/src/Google/Protobuf/Internal/OneofOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.OneofOptions */ -class OneofOptions extends \Google\Protobuf\Internal\Message +final class OneofOptions extends \Google\Protobuf\Internal\Message { /** * The parser stores options it doesn't recognize here. See above. diff --git a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php index 8de7afd0bc..9534f0480e 100644 --- a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php @@ -15,7 +15,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.ServiceDescriptorProto */ -class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message +final class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field optional string name = 1; diff --git a/php/src/Google/Protobuf/Internal/ServiceOptions.php b/php/src/Google/Protobuf/Internal/ServiceOptions.php index 67162f3764..55bf7a7758 100644 --- a/php/src/Google/Protobuf/Internal/ServiceOptions.php +++ b/php/src/Google/Protobuf/Internal/ServiceOptions.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.ServiceOptions */ -class ServiceOptions extends \Google\Protobuf\Internal\Message +final class ServiceOptions extends \Google\Protobuf\Internal\Message { /** * Is this service deprecated? diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php index dfeb69ff69..3ddd892262 100644 --- a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php +++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php @@ -16,7 +16,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.SourceCodeInfo */ -class SourceCodeInfo extends \Google\Protobuf\Internal\Message +final class SourceCodeInfo extends \Google\Protobuf\Internal\Message { /** * A Location identifies a piece of source code in a .proto file which diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php index bad247a11f..470d64c6e2 100644 --- a/php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php +++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php @@ -13,7 +13,7 @@ use Google\Protobuf\Internal\GPBUtil; /** * Generated from protobuf message google.protobuf.SourceCodeInfo.Location */ -class Location extends \Google\Protobuf\Internal\Message +final class Location extends \Google\Protobuf\Internal\Message { /** * Identifies which part of the FileDescriptorProto was defined at this diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption.php b/php/src/Google/Protobuf/Internal/UninterpretedOption.php index 3b517ec552..39273d62fa 100644 --- a/php/src/Google/Protobuf/Internal/UninterpretedOption.php +++ b/php/src/Google/Protobuf/Internal/UninterpretedOption.php @@ -20,7 +20,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.UninterpretedOption */ -class UninterpretedOption extends \Google\Protobuf\Internal\Message +final class UninterpretedOption extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field repeated .google.protobuf.UninterpretedOption.NamePart name = 2; diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php b/php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php index 92ee4b44b9..a2f9250f93 100644 --- a/php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php +++ b/php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php @@ -19,7 +19,7 @@ use Google\Protobuf\Internal\GPBUtil; * * Generated from protobuf message google.protobuf.UninterpretedOption.NamePart */ -class NamePart extends \Google\Protobuf\Internal\Message +final class NamePart extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field required string name_part = 1; diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index c47ea33f79..60d7d8b73b 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -1307,7 +1307,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, } printer.Print( - "class ^name^ extends \\Google\\Protobuf\\Internal\\Message\n" + "final class ^name^ extends \\Google\\Protobuf\\Internal\\Message\n" "{\n", "name", fullname); Indent(&printer); From 6e58040a712c58c22b639506ae759909d5b980e4 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Fri, 14 Jun 2019 13:29:16 +0200 Subject: [PATCH 15/17] Add "src/**/*.inc" to //:protobuf_headers Otherwise, sandbox and remote execution will complain `google/protobuf/port_def.inc` doesn't exist. --- BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 2fb2605093..f3f1569b9b 100644 --- a/BUILD +++ b/BUILD @@ -218,7 +218,7 @@ cc_library( # TODO(keveman): Remove this target once the support gets added to Bazel. cc_library( name = "protobuf_headers", - hdrs = glob(["src/**/*.h"]), + hdrs = glob(["src/**/*.h", "src/**/*.inc"]), includes = ["src/"], visibility = ["//visibility:public"], ) From 815ff7e1fb2d417d5aebcbf5fc46e626b18dc834 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 20 Jun 2019 20:59:48 -0700 Subject: [PATCH 16/17] Revert "Append field number to accessors if there is conflict (#6169)" (#6282) This reverts commit 9a8ef05a34dab7583b6f253daca294d6b1bfb187. --- .../proto/test_wrapper_type_setters.proto | 11 --- php/tests/wrapper_type_setters_test.php | 38 ----------- .../protobuf/compiler/php/php_generator.cc | 68 ++++--------------- 3 files changed, 13 insertions(+), 104 deletions(-) diff --git a/php/tests/proto/test_wrapper_type_setters.proto b/php/tests/proto/test_wrapper_type_setters.proto index 119bd2547a..41ca7f3f31 100644 --- a/php/tests/proto/test_wrapper_type_setters.proto +++ b/php/tests/proto/test_wrapper_type_setters.proto @@ -24,14 +24,3 @@ message TestWrapperSetters { map map_string_value = 13; } - -message TestWrapperAccessorConflicts { - int32 normal_vs_wrapper_value = 1; - google.protobuf.Int32Value normal_vs_wrapper = 2; - - int32 normal_vs_normal_value = 3; - int32 normal_vs_normal = 4; - - google.protobuf.Int32Value wrapper_vs_wrapper_value = 5; - google.protobuf.Int32Value wrapper_vs_wrapper = 6; -} diff --git a/php/tests/wrapper_type_setters_test.php b/php/tests/wrapper_type_setters_test.php index 35e3a7dec1..5509a175a1 100644 --- a/php/tests/wrapper_type_setters_test.php +++ b/php/tests/wrapper_type_setters_test.php @@ -16,44 +16,6 @@ use Google\Protobuf\UInt64Value; class WrapperTypeSettersTest extends TestBase { - public function testConflictNormalVsWrapper() - { - $m = new Foo\TestWrapperAccessorConflicts(); - - $m->setNormalVsWrapperValue1(1); - $this->assertSame(1, $m->getNormalVsWrapperValue1()); - - $m->setNormalVsWrapperValue2(1); - $this->assertSame(1, $m->getNormalVsWrapperValue2()); - - $wrapper = new Int32Value(["value" => 1]); - $m->setNormalVsWrapper($wrapper); - $this->assertSame(1, $m->getNormalVsWrapper()->getValue()); - } - - public function testConflictNormalVsNormal() - { - $m = new Foo\TestWrapperAccessorConflicts(); - - $m->setNormalVsNormalValue(1); - $this->assertSame(1, $m->getNormalVsNormalValue()); - - $m->setNormalVsNormal(1); - $this->assertSame(1, $m->getNormalVsNormal()); - } - - public function testConflictWrapperVsWrapper() - { - $m = new Foo\TestWrapperAccessorConflicts(); - - $m->setWrapperVsWrapperValueValue(1); - $this->assertSame(1, $m->getWrapperVsWrapperValueValue()); - - $wrapper = new Int32Value(["value" => 1]); - $m->setWrapperVsWrapperValue5($wrapper); - $this->assertSame(1, $m->getWrapperVsWrapperValue5()->getValue()); - } - /** * @dataProvider gettersAndSettersDataProvider */ diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 8e405608a8..d7e33b2c06 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -655,58 +655,27 @@ void GenerateOneofField(const OneofDescriptor* oneof, io::Printer* printer) { void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, io::Printer* printer) { - bool need_other_name_for_accessor = false; - bool need_other_name_for_wrapper_accessor = false; - const Descriptor* desc = field->containing_type(); - - if (!field->is_repeated() && - field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && - IsWrapperType(field)) { - // Check if there is any field called xxx_value - const FieldDescriptor* other = - desc->FindFieldByName(StrCat(field->name(), "_value")); - if (other != NULL) { - need_other_name_for_wrapper_accessor = true; - } - } - - if (strings::EndsWith(field->name(), "_value")) { - std::size_t pos = (field->name()).find("_value"); - string name = (field->name()).substr(0, pos); - const FieldDescriptor* other = desc->FindFieldByName(name); - if (other != NULL && - !other->is_repeated() && - other->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && - IsWrapperType(other)) { - need_other_name_for_accessor = true; - } - } - const OneofDescriptor* oneof = field->containing_oneof(); // Generate getter. if (oneof != NULL) { GenerateFieldDocComment(printer, field, is_descriptor, kFieldGetter); printer->Print( - "public function get^camel_name^^field_number^()\n" + "public function get^camel_name^()\n" "{\n" " return $this->readOneof(^number^);\n" "}\n\n", "camel_name", UnderscoresToCamelCase(field->name(), true), - "number", IntToString(field->number()), - "field_number", need_other_name_for_accessor ? - StrCat(field->number()) : ""); + "number", IntToString(field->number())); } else { GenerateFieldDocComment(printer, field, is_descriptor, kFieldGetter); printer->Print( - "public function get^camel_name^^field_number^()\n" + "public function get^camel_name^()\n" "{\n" " return $this->^name^;\n" "}\n\n", - "camel_name", UnderscoresToCamelCase(field->name(), true), - "name", field->name(), - "field_number", need_other_name_for_accessor ? - StrCat(field->number()) : ""); + "camel_name", UnderscoresToCamelCase(field->name(), true), "name", + field->name()); } // For wrapper types, generate an additional getXXXValue getter @@ -715,28 +684,21 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && IsWrapperType(field)) { GenerateWrapperFieldGetterDocComment(printer, field); - printer->Print( - "public function get^camel_name^Value^field_number1^()\n" + "public function get^camel_name^Value()\n" "{\n" - " $wrapper = $this->get^camel_name^^field_number2^();\n" + " $wrapper = $this->get^camel_name^();\n" " return is_null($wrapper) ? null : $wrapper->getValue();\n" "}\n\n", - "camel_name", UnderscoresToCamelCase(field->name(), true), - "field_number1", need_other_name_for_wrapper_accessor ? - StrCat(field->number()) : "", - "field_number2", need_other_name_for_accessor ? - StrCat(field->number()) : ""); + "camel_name", UnderscoresToCamelCase(field->name(), true)); } // Generate setter. GenerateFieldDocComment(printer, field, is_descriptor, kFieldSetter); printer->Print( - "public function set^camel_name^^field_number^($var)\n" + "public function set^camel_name^($var)\n" "{\n", - "camel_name", UnderscoresToCamelCase(field->name(), true), - "field_number", need_other_name_for_accessor ? - StrCat(field->number()) : ""); + "camel_name", UnderscoresToCamelCase(field->name(), true)); Indent(printer); @@ -836,17 +798,13 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, IsWrapperType(field)) { GenerateWrapperFieldSetterDocComment(printer, field); printer->Print( - "public function set^camel_name^Value^field_number1^($var)\n" + "public function set^camel_name^Value($var)\n" "{\n" " $wrappedVar = is_null($var) ? null : new \\^wrapper_type^(['value' => $var]);\n" - " return $this->set^camel_name^^field_number2^($wrappedVar);\n" + " return $this->set^camel_name^($wrappedVar);\n" "}\n\n", "camel_name", UnderscoresToCamelCase(field->name(), true), - "wrapper_type", LegacyFullClassName(field->message_type(), is_descriptor), - "field_number1", need_other_name_for_wrapper_accessor ? - StrCat(field->number()) : "", - "field_number2", need_other_name_for_accessor ? - StrCat(field->number()) : ""); + "wrapper_type", LegacyFullClassName(field->message_type(), is_descriptor)); } // Generate has method for proto2 only. From 54288a01cebfd0bfa62ca581dd07ffd6f9c77f2c Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 21 Jun 2019 13:25:23 -0700 Subject: [PATCH 17/17] Rename get/setXXXValue to get/setXXXUnwrapped (#6295) --- php/tests/wrapper_type_setters_test.php | 88 +++++++++---------- .../protobuf/compiler/php/php_generator.cc | 6 +- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/php/tests/wrapper_type_setters_test.php b/php/tests/wrapper_type_setters_test.php index 5509a175a1..ad9f7181dd 100644 --- a/php/tests/wrapper_type_setters_test.php +++ b/php/tests/wrapper_type_setters_test.php @@ -60,26 +60,26 @@ class WrapperTypeSettersTest extends TestBase public function gettersAndSettersDataProvider() { return [ - [TestWrapperSetters::class, DoubleValue::class, "setDoubleValue", "setDoubleValueValue", "getDoubleValue", "getDoubleValueValue", [ + [TestWrapperSetters::class, DoubleValue::class, "setDoubleValue", "setDoubleValueUnwrapped", "getDoubleValue", "getDoubleValueUnwrapped", [ [1.1, new DoubleValue(["value" => 1.1])], [2.2, new DoubleValue(["value" => 2.2])], [null, null], [0, new DoubleValue()], ]], - [TestWrapperSetters::class, FloatValue::class, "setFloatValue", "setFloatValueValue", "getFloatValue", "getFloatValueValue", [ + [TestWrapperSetters::class, FloatValue::class, "setFloatValue", "setFloatValueUnwrapped", "getFloatValue", "getFloatValueUnwrapped", [ [1.1, new FloatValue(["value" => 1.1])], [2.2, new FloatValue(["value" => 2.2])], [null, null], [0, new FloatValue()], ]], - [TestWrapperSetters::class, Int64Value::class, "setInt64Value", "setInt64ValueValue", "getInt64Value", "getInt64ValueValue", [ + [TestWrapperSetters::class, Int64Value::class, "setInt64Value", "setInt64ValueUnwrapped", "getInt64Value", "getInt64ValueUnwrapped", [ [123, new Int64Value(["value" => 123])], [-789, new Int64Value(["value" => -789])], [null, null], [0, new Int64Value()], [5.5, new Int64Value(["value" => 5])], // Test conversion from float to int ]], - [TestWrapperSetters::class, UInt64Value::class, "setUInt64Value", "setUInt64ValueValue", "getUInt64Value", "getUInt64ValueValue", [ + [TestWrapperSetters::class, UInt64Value::class, "setUInt64Value", "setUInt64ValueUnwrapped", "getUInt64Value", "getUInt64ValueUnwrapped", [ [123, new UInt64Value(["value" => 123])], [789, new UInt64Value(["value" => 789])], [null, null], @@ -87,14 +87,14 @@ class WrapperTypeSettersTest extends TestBase [5.5, new UInt64Value(["value" => 5])], // Test conversion from float to int [-7, new UInt64Value(["value" => -7])], // Test conversion from -ve to +ve ]], - [TestWrapperSetters::class, Int32Value::class, "setInt32Value", "setInt32ValueValue", "getInt32Value", "getInt32ValueValue", [ + [TestWrapperSetters::class, Int32Value::class, "setInt32Value", "setInt32ValueUnwrapped", "getInt32Value", "getInt32ValueUnwrapped", [ [123, new Int32Value(["value" => 123])], [-789, new Int32Value(["value" => -789])], [null, null], [0, new Int32Value()], [5.5, new Int32Value(["value" => 5])], // Test conversion from float to int ]], - [TestWrapperSetters::class, UInt32Value::class, "setUInt32Value", "setUInt32ValueValue", "getUInt32Value", "getUInt32ValueValue", [ + [TestWrapperSetters::class, UInt32Value::class, "setUInt32Value", "setUInt32ValueUnwrapped", "getUInt32Value", "getUInt32ValueUnwrapped", [ [123, new UInt32Value(["value" => 123])], [789, new UInt32Value(["value" => 789])], [null, null], @@ -102,12 +102,12 @@ class WrapperTypeSettersTest extends TestBase [5.5, new UInt32Value(["value" => 5])], // Test conversion from float to int [-7, new UInt32Value(["value" => -7])], // Test conversion from -ve to +ve ]], - [TestWrapperSetters::class, BoolValue::class, "setBoolValue", "setBoolValueValue", "getBoolValue", "getBoolValueValue", [ + [TestWrapperSetters::class, BoolValue::class, "setBoolValue", "setBoolValueUnwrapped", "getBoolValue", "getBoolValueUnwrapped", [ [true, new BoolValue(["value" => true])], [false, new BoolValue(["value" => false])], [null, null], ]], - [TestWrapperSetters::class, StringValue::class, "setStringValue", "setStringValueValue", "getStringValue", "getStringValueValue", [ + [TestWrapperSetters::class, StringValue::class, "setStringValue", "setStringValueUnwrapped", "getStringValue", "getStringValueUnwrapped", [ ["asdf", new StringValue(["value" => "asdf"])], ["", new StringValue(["value" => ""])], [null, null], @@ -117,7 +117,7 @@ class WrapperTypeSettersTest extends TestBase [-7, new StringValue(["value" => "-7"])], // Test conversion from number to string [-7.5, new StringValue(["value" => "-7.5"])], // Test conversion from number to string ]], - [TestWrapperSetters::class, BytesValue::class, "setBytesValue", "setBytesValueValue", "getBytesValue", "getBytesValueValue", [ + [TestWrapperSetters::class, BytesValue::class, "setBytesValue", "setBytesValueUnwrapped", "getBytesValue", "getBytesValueUnwrapped", [ ["asdf", new BytesValue(["value" => "asdf"])], ["", new BytesValue(["value" => ""])], [null, null], @@ -127,12 +127,12 @@ class WrapperTypeSettersTest extends TestBase [-7, new BytesValue(["value" => "-7"])], // Test conversion from number to bytes [-7.5, new BytesValue(["value" => "-7.5"])], // Test conversion from number to bytes ]], - [TestWrapperSetters::class, DoubleValue::class, "setDoubleValueOneof", "setDoubleValueOneofValue", "getDoubleValueOneof", "getDoubleValueOneofValue", [ + [TestWrapperSetters::class, DoubleValue::class, "setDoubleValueOneof", "setDoubleValueOneofUnwrapped", "getDoubleValueOneof", "getDoubleValueOneofUnwrapped", [ [1.1, new DoubleValue(["value" => 1.1])], [2.2, new DoubleValue(["value" => 2.2])], [null, null], [0, new DoubleValue()], - ]],[TestWrapperSetters::class, StringValue::class, "setStringValueOneof", "setStringValueOneofValue", "getStringValueOneof", "getStringValueOneofValue", [ + ]],[TestWrapperSetters::class, StringValue::class, "setStringValueOneof", "setStringValueOneofUnwrapped", "getStringValueOneof", "getStringValueOneofUnwrapped", [ ["asdf", new StringValue(["value" => "asdf"])], ["", new StringValue(["value" => ""])], [null, null], @@ -157,47 +157,47 @@ class WrapperTypeSettersTest extends TestBase public function invalidSettersDataProvider() { return [ - [TestWrapperSetters::class, "setDoubleValueValue", "abc"], - [TestWrapperSetters::class, "setDoubleValueValue", []], - [TestWrapperSetters::class, "setDoubleValueValue", new stdClass()], - [TestWrapperSetters::class, "setDoubleValueValue", new DoubleValue()], + [TestWrapperSetters::class, "setDoubleValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setDoubleValueUnwrapped", []], + [TestWrapperSetters::class, "setDoubleValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setDoubleValueUnwrapped", new DoubleValue()], - [TestWrapperSetters::class, "setFloatValueValue", "abc"], - [TestWrapperSetters::class, "setFloatValueValue", []], - [TestWrapperSetters::class, "setFloatValueValue", new stdClass()], - [TestWrapperSetters::class, "setFloatValueValue", new FloatValue()], + [TestWrapperSetters::class, "setFloatValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setFloatValueUnwrapped", []], + [TestWrapperSetters::class, "setFloatValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setFloatValueUnwrapped", new FloatValue()], - [TestWrapperSetters::class, "setInt64ValueValue", "abc"], - [TestWrapperSetters::class, "setInt64ValueValue", []], - [TestWrapperSetters::class, "setInt64ValueValue", new stdClass()], - [TestWrapperSetters::class, "setInt64ValueValue", new Int64Value()], + [TestWrapperSetters::class, "setInt64ValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setInt64ValueUnwrapped", []], + [TestWrapperSetters::class, "setInt64ValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setInt64ValueUnwrapped", new Int64Value()], - [TestWrapperSetters::class, "setUInt64ValueValue", "abc"], - [TestWrapperSetters::class, "setUInt64ValueValue", []], - [TestWrapperSetters::class, "setUInt64ValueValue", new stdClass()], - [TestWrapperSetters::class, "setUInt64ValueValue", new UInt64Value()], + [TestWrapperSetters::class, "setUInt64ValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setUInt64ValueUnwrapped", []], + [TestWrapperSetters::class, "setUInt64ValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setUInt64ValueUnwrapped", new UInt64Value()], - [TestWrapperSetters::class, "setInt32ValueValue", "abc"], - [TestWrapperSetters::class, "setInt32ValueValue", []], - [TestWrapperSetters::class, "setInt32ValueValue", new stdClass()], - [TestWrapperSetters::class, "setInt32ValueValue", new Int32Value()], + [TestWrapperSetters::class, "setInt32ValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setInt32ValueUnwrapped", []], + [TestWrapperSetters::class, "setInt32ValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setInt32ValueUnwrapped", new Int32Value()], - [TestWrapperSetters::class, "setUInt32ValueValue", "abc"], - [TestWrapperSetters::class, "setUInt32ValueValue", []], - [TestWrapperSetters::class, "setUInt32ValueValue", new stdClass()], - [TestWrapperSetters::class, "setUInt32ValueValue", new UInt32Value()], + [TestWrapperSetters::class, "setUInt32ValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setUInt32ValueUnwrapped", []], + [TestWrapperSetters::class, "setUInt32ValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setUInt32ValueUnwrapped", new UInt32Value()], - [TestWrapperSetters::class, "setBoolValueValue", []], - [TestWrapperSetters::class, "setBoolValueValue", new stdClass()], - [TestWrapperSetters::class, "setBoolValueValue", new BoolValue()], + [TestWrapperSetters::class, "setBoolValueUnwrapped", []], + [TestWrapperSetters::class, "setBoolValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setBoolValueUnwrapped", new BoolValue()], - [TestWrapperSetters::class, "setStringValueValue", []], - [TestWrapperSetters::class, "setStringValueValue", new stdClass()], - [TestWrapperSetters::class, "setStringValueValue", new StringValue()], + [TestWrapperSetters::class, "setStringValueUnwrapped", []], + [TestWrapperSetters::class, "setStringValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setStringValueUnwrapped", new StringValue()], - [TestWrapperSetters::class, "setBytesValueValue", []], - [TestWrapperSetters::class, "setBytesValueValue", new stdClass()], - [TestWrapperSetters::class, "setBytesValueValue", new BytesValue()], + [TestWrapperSetters::class, "setBytesValueUnwrapped", []], + [TestWrapperSetters::class, "setBytesValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setBytesValueUnwrapped", new BytesValue()], ]; } diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 735300f780..232db80b50 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -678,14 +678,14 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, field->name()); } - // For wrapper types, generate an additional getXXXValue getter + // For wrapper types, generate an additional getXXXUnwrapped getter if (!field->is_map() && !field->is_repeated() && field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && IsWrapperType(field)) { GenerateWrapperFieldGetterDocComment(printer, field); printer->Print( - "public function get^camel_name^Value()\n" + "public function get^camel_name^Unwrapped()\n" "{\n" " $wrapper = $this->get^camel_name^();\n" " return is_null($wrapper) ? null : $wrapper->getValue();\n" @@ -798,7 +798,7 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, IsWrapperType(field)) { GenerateWrapperFieldSetterDocComment(printer, field); printer->Print( - "public function set^camel_name^Value($var)\n" + "public function set^camel_name^Unwrapped($var)\n" "{\n" " $wrappedVar = is_null($var) ? null : new \\^wrapper_type^(['value' => $var]);\n" " return $this->set^camel_name^($wrappedVar);\n"