diff --git a/BUILD b/BUILD index 1f1a047467cb2..44beeb298186a 100644 --- a/BUILD +++ b/BUILD @@ -219,7 +219,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"], ) @@ -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/Makefile.am b/Makefile.am index 8396f6e0c7857..c03b45c78a98a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1230,6 +1230,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 \ diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 0995d3563a009..5ddb3a90bd7e8 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})", diff --git a/conformance/failure_list_php.txt b/conformance/failure_list_php.txt index f76e9d731ff7b..28ca461d472bf 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/conformance/failure_list_php_c.txt b/conformance/failure_list_php_c.txt index eff09ffe10f0f..8f7af61855ece 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 a36f056fd4b9c..fc6455d8e44e3 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 19be38a3092c3..153b0a2019477 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/docs/options.md b/docs/options.md index 72e265634b5ef..f240f0c8bc5da 100644 --- a/docs/options.md +++ b/docs/options.md @@ -201,3 +201,7 @@ with info about your project (name and website) so we can add an entry for you. * Website: https://twirpql.dev * Extensions: 1070 +1. Protoc-gen-validate + * Website: https://github.com/envoyproxy/protoc-gen-validate + * Extensions: 1071 + diff --git a/java/compatibility_tests/v2.5.0/test.sh b/java/compatibility_tests/v2.5.0/test.sh index eea8328504e78..860437809c7a9 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" diff --git a/java/lite/pom.xml b/java/lite/pom.xml index a1a8b4dcf47e5..f6e1c250fc9ce 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -84,6 +84,7 @@ ${basedir}/../core/src/main/java/com/google/protobuf + AbstractMessageLite.java AbstractParser.java AbstractProtobufList.java diff --git a/kokoro/linux/dockerfile/release/ruby_rake_compiler/Dockerfile b/kokoro/linux/dockerfile/release/ruby_rake_compiler/Dockerfile index 9ba664d8b05ac..866b289343d7d 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" diff --git a/php/ext/google/protobuf/upb.c b/php/ext/google/protobuf/upb.c index 1d977437f6b03..cc5a54ab84d32 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/php/src/Google/Protobuf/Internal/DescriptorProto.php b/php/src/Google/Protobuf/Internal/DescriptorProto.php index 3b215d52ae4d3..2d52831451ce8 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto.php @@ -15,7 +15,7 @@ * * 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 a2057fd5d17e1..fb98f7d5a0908 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php @@ -13,7 +13,7 @@ /** * 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 73c964faa0b59..fa46419a53ae3 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php @@ -17,7 +17,7 @@ * * 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/EnumDescriptor.php b/php/src/Google/Protobuf/Internal/EnumDescriptor.php index 82a427670cb61..7af4f84012e59 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptor.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptor.php @@ -39,17 +39,26 @@ public function addValue($number, $value) 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/EnumDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php index da30fa99067f6..b7c3a208bec22 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php @@ -15,7 +15,7 @@ * * 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 e1079585ec013..0103a1b301780 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php @@ -19,7 +19,7 @@ * * 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 3d74c81c21766..4c73d527409d2 100644 --- a/php/src/Google/Protobuf/Internal/EnumOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumOptions.php @@ -13,7 +13,7 @@ /** * 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 50bda008e8992..d5a0a9afb532a 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php @@ -15,7 +15,7 @@ * * 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 a267c6d5e25ed..50ac904ff9727 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumValueOptions.php @@ -13,7 +13,7 @@ /** * 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 00fbebecaf6ac..97ad2c055f85e 100644 --- a/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php +++ b/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php @@ -13,7 +13,7 @@ /** * 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 e578197515f8c..6f8643c8d72cb 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php @@ -15,7 +15,7 @@ * * 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 751c278d7823b..47d1951d1659b 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions.php @@ -13,7 +13,7 @@ /** * 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 cb10aa79390fc..e95205476cf8e 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php @@ -15,7 +15,7 @@ * * 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 9907b17d73c59..c9a38808fb4c1 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php @@ -16,7 +16,7 @@ * * 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 6fea195ec18aa..911000501643a 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions.php +++ b/php/src/Google/Protobuf/Internal/FileOptions.php @@ -13,7 +13,7 @@ /** * 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/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 0beedba3330d1..7ec3ca2294b82 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -504,17 +504,29 @@ public static function parseDuration($value) 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) { diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php index f5a65bea46108..c99d77afa3ad9 100644 --- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php +++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php @@ -17,7 +17,7 @@ * * 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 09f958d2512c6..8cc3cdf4573fb 100644 --- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php +++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php @@ -13,7 +13,7 @@ /** * 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 4453942110283..9032c97e9b10d 100644 --- a/php/src/Google/Protobuf/Internal/MessageOptions.php +++ b/php/src/Google/Protobuf/Internal/MessageOptions.php @@ -13,7 +13,7 @@ /** * 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 1bd5dd3e1c439..25a2c166fd650 100644 --- a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php @@ -15,7 +15,7 @@ * * 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 a2c729a9bbed7..a9c093ad5d765 100644 --- a/php/src/Google/Protobuf/Internal/MethodOptions.php +++ b/php/src/Google/Protobuf/Internal/MethodOptions.php @@ -13,7 +13,7 @@ /** * 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 9ecfe5cbfe967..a703fcb702caf 100644 --- a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php @@ -15,7 +15,7 @@ * * 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 46b516f3019fc..749051f31fe87 100644 --- a/php/src/Google/Protobuf/Internal/OneofOptions.php +++ b/php/src/Google/Protobuf/Internal/OneofOptions.php @@ -13,7 +13,7 @@ /** * 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 8de7afd0bcd94..9534f0480e767 100644 --- a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php @@ -15,7 +15,7 @@ * * 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 67162f3764e63..55bf7a77582a4 100644 --- a/php/src/Google/Protobuf/Internal/ServiceOptions.php +++ b/php/src/Google/Protobuf/Internal/ServiceOptions.php @@ -13,7 +13,7 @@ /** * 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 dfeb69ff69789..3ddd892262029 100644 --- a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php +++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php @@ -16,7 +16,7 @@ * * 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 bad247a11f662..470d64c6e23de 100644 --- a/php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php +++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php @@ -13,7 +13,7 @@ /** * 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 3b517ec552c11..39273d62fa7ad 100644 --- a/php/src/Google/Protobuf/Internal/UninterpretedOption.php +++ b/php/src/Google/Protobuf/Internal/UninterpretedOption.php @@ -20,7 +20,7 @@ * * 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 92ee4b44b92fa..a2f9250f936f4 100644 --- a/php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php +++ b/php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php @@ -19,7 +19,7 @@ * * 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/php/tests/proto/test_wrapper_type_setters.proto b/php/tests/proto/test_wrapper_type_setters.proto index 119bd2547ac1f..41ca7f3f311e7 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 35e3a7dec151f..ad9f7181dd059 100644 --- a/php/tests/wrapper_type_setters_test.php +++ b/php/tests/wrapper_type_setters_test.php @@ -16,44 +16,6 @@ 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 */ @@ -98,26 +60,26 @@ public function testGettersAndSetters( 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], @@ -125,14 +87,14 @@ public function gettersAndSettersDataProvider() [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], @@ -140,12 +102,12 @@ public function gettersAndSettersDataProvider() [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], @@ -155,7 +117,7 @@ public function gettersAndSettersDataProvider() [-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], @@ -165,12 +127,12 @@ public function gettersAndSettersDataProvider() [-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], @@ -195,47 +157,47 @@ public function testInvalidSetters($class, $setter, $value) public function invalidSettersDataProvider() { return [ - [TestWrapperSetters::class, "setDoubleValueValue", "abc"], - [TestWrapperSetters::class, "setDoubleValueValue", []], - [TestWrapperSetters::class, "setDoubleValueValue", new stdClass()], - [TestWrapperSetters::class, "setDoubleValueValue", new DoubleValue()], - - [TestWrapperSetters::class, "setFloatValueValue", "abc"], - [TestWrapperSetters::class, "setFloatValueValue", []], - [TestWrapperSetters::class, "setFloatValueValue", new stdClass()], - [TestWrapperSetters::class, "setFloatValueValue", new FloatValue()], - - [TestWrapperSetters::class, "setInt64ValueValue", "abc"], - [TestWrapperSetters::class, "setInt64ValueValue", []], - [TestWrapperSetters::class, "setInt64ValueValue", new stdClass()], - [TestWrapperSetters::class, "setInt64ValueValue", new Int64Value()], - - [TestWrapperSetters::class, "setUInt64ValueValue", "abc"], - [TestWrapperSetters::class, "setUInt64ValueValue", []], - [TestWrapperSetters::class, "setUInt64ValueValue", new stdClass()], - [TestWrapperSetters::class, "setUInt64ValueValue", new UInt64Value()], - - [TestWrapperSetters::class, "setInt32ValueValue", "abc"], - [TestWrapperSetters::class, "setInt32ValueValue", []], - [TestWrapperSetters::class, "setInt32ValueValue", new stdClass()], - [TestWrapperSetters::class, "setInt32ValueValue", new Int32Value()], - - [TestWrapperSetters::class, "setUInt32ValueValue", "abc"], - [TestWrapperSetters::class, "setUInt32ValueValue", []], - [TestWrapperSetters::class, "setUInt32ValueValue", new stdClass()], - [TestWrapperSetters::class, "setUInt32ValueValue", new UInt32Value()], - - [TestWrapperSetters::class, "setBoolValueValue", []], - [TestWrapperSetters::class, "setBoolValueValue", new stdClass()], - [TestWrapperSetters::class, "setBoolValueValue", new BoolValue()], - - [TestWrapperSetters::class, "setStringValueValue", []], - [TestWrapperSetters::class, "setStringValueValue", new stdClass()], - [TestWrapperSetters::class, "setStringValueValue", new StringValue()], - - [TestWrapperSetters::class, "setBytesValueValue", []], - [TestWrapperSetters::class, "setBytesValueValue", new stdClass()], - [TestWrapperSetters::class, "setBytesValueValue", new BytesValue()], + [TestWrapperSetters::class, "setDoubleValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setDoubleValueUnwrapped", []], + [TestWrapperSetters::class, "setDoubleValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setDoubleValueUnwrapped", new DoubleValue()], + + [TestWrapperSetters::class, "setFloatValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setFloatValueUnwrapped", []], + [TestWrapperSetters::class, "setFloatValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setFloatValueUnwrapped", new FloatValue()], + + [TestWrapperSetters::class, "setInt64ValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setInt64ValueUnwrapped", []], + [TestWrapperSetters::class, "setInt64ValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setInt64ValueUnwrapped", new Int64Value()], + + [TestWrapperSetters::class, "setUInt64ValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setUInt64ValueUnwrapped", []], + [TestWrapperSetters::class, "setUInt64ValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setUInt64ValueUnwrapped", new UInt64Value()], + + [TestWrapperSetters::class, "setInt32ValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setInt32ValueUnwrapped", []], + [TestWrapperSetters::class, "setInt32ValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setInt32ValueUnwrapped", new Int32Value()], + + [TestWrapperSetters::class, "setUInt32ValueUnwrapped", "abc"], + [TestWrapperSetters::class, "setUInt32ValueUnwrapped", []], + [TestWrapperSetters::class, "setUInt32ValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setUInt32ValueUnwrapped", new UInt32Value()], + + [TestWrapperSetters::class, "setBoolValueUnwrapped", []], + [TestWrapperSetters::class, "setBoolValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setBoolValueUnwrapped", new BoolValue()], + + [TestWrapperSetters::class, "setStringValueUnwrapped", []], + [TestWrapperSetters::class, "setStringValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setStringValueUnwrapped", new StringValue()], + + [TestWrapperSetters::class, "setBytesValueUnwrapped", []], + [TestWrapperSetters::class, "setBytesValueUnwrapped", new stdClass()], + [TestWrapperSetters::class, "setBytesValueUnwrapped", new BytesValue()], ]; } diff --git a/ruby/ext/google/protobuf_c/upb.c b/ruby/ext/google/protobuf_c/upb.c index 3d96c5ccc70b8..748205083dccc 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 2945003b03ab1..fa1e2ff7d9dda 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -1108,9 +1108,9 @@ def test_json_emit_defaults expected = { optionalInt32: 0, - optionalInt64: 0, + optionalInt64: "0", optionalUint32: 0, - optionalUint64: 0, + optionalUint64: "0", optionalBool: false, optionalFloat: 0, optionalDouble: 0, @@ -1142,9 +1142,9 @@ def test_json_emit_defaults_submsg expected = { optionalInt32: 0, - optionalInt64: 0, + optionalInt64: "0", optionalUint32: 0, - optionalUint64: 0, + optionalUint64: "0", optionalBool: false, optionalFloat: 0, optionalDouble: 0, @@ -1177,9 +1177,9 @@ def test_json_emit_defaults_repeated_submsg expected = { optionalInt32: 0, - optionalInt64: 0, + optionalInt64: "0", optionalUint32: 0, - optionalUint64: 0, + optionalUint64: "0", optionalBool: false, optionalFloat: 0, optionalDouble: 0, diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index 33c5619843090..978fdf02b6fb6 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 d4a4d708f1160..7bc585e9bafec 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 ed7fad80a5692..fd57263484b31 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 a9e845397b835..6731e37a77feb 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 1d41628f6899e..55eda0b8efe94 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 diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index c47ea33f798ba..232db80b50340 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -655,88 +655,50 @@ 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 + // 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^field_number1^()\n" + "public function get^camel_name^Unwrapped()\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^Unwrapped($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. @@ -1307,7 +1265,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);