From 55fdbe58f08071b34e96ce97a294afa06e4cb3e9 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 23 Aug 2017 11:35:48 -0700 Subject: Make distcheck aware of test proto files. --- src/Makefile.am | 10 ++++++++-- tests.sh | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 1999213c..9ab987d1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -561,8 +561,8 @@ protoc_inputs = \ google/protobuf/unittest_preserve_unknown_enum.proto \ google/protobuf/unittest.proto \ google/protobuf/unittest_proto3_arena.proto \ - google/protobuf/unittest_proto3_arena_lite.proto \ - google/protobuf/unittest_proto3_lite.proto \ + google/protobuf/unittest_proto3_arena_lite.proto \ + google/protobuf/unittest_proto3_lite.proto \ google/protobuf/unittest_well_known_types.proto \ google/protobuf/util/internal/testdata/anys.proto \ google/protobuf/util/internal/testdata/books.proto \ @@ -583,6 +583,12 @@ EXTRA_DIST = \ $(protoc_inputs) \ $(js_well_known_types_sources) \ solaris/libstdc++.la \ + google/protobuf/unittest_proto3.proto \ + google/protobuf/unittest_import_public_proto3.proto \ + google/protobuf/unittest_import_proto3.proto \ + google/protobuf/test_messages_proto3.proto \ + google/protobuf/test_messages_proto2.proto \ + google/protobuf/map_unittest_proto3.proto \ google/protobuf/io/gzip_stream.h \ google/protobuf/io/gzip_stream_unittest.sh \ google/protobuf/testdata/golden_message \ diff --git a/tests.sh b/tests.sh index cfc08c35..d1778465 100755 --- a/tests.sh +++ b/tests.sh @@ -61,7 +61,7 @@ build_cpp_distcheck() { make dist # List all files that should be included in the distribution package. - git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\)" |\ + git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\|src/google/protobuf/.*\.proto\)" |\ grep -v ".gitignore" | grep -v "java/compatibility_tests" |\ grep -v "cmake/protobuf.*\.pc\.cmake" |\ grep -v "python/compatibility_tests" | grep -v "csharp/compatibility_tests" > dist.lst -- cgit v1.2.3 From 78432eab4341fd3f4ba5bdf05fbe26be98287137 Mon Sep 17 00:00:00 2001 From: Matt Kwong Date: Tue, 22 Aug 2017 17:16:58 -0700 Subject: Remove pre-installed softwares --- kokoro/macos/prepare_build_macos_rc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kokoro/macos/prepare_build_macos_rc b/kokoro/macos/prepare_build_macos_rc index 2b9f4df2..dfe66ff8 100755 --- a/kokoro/macos/prepare_build_macos_rc +++ b/kokoro/macos/prepare_build_macos_rc @@ -17,8 +17,10 @@ export CXX=g++ # Install Brew and core softwares ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +source $HOME/.rvm/scripts/rvm brew tap homebrew/homebrew-php -brew install autoconf automake ccache cmake gflags gpg gpg2 libtool maven node pcre php56 ruby wget +brew uninstall node icu4c +brew install gflags gpg gpg2 node pcre php56 ruby ## # Install Tox -- cgit v1.2.3 From d8c6193d2c18105b9c130ec5adb030ba0945347d Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 24 Aug 2017 14:11:37 -0700 Subject: Add mising cmake files in dist --- Makefile.am | 2 ++ tests.sh | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 52d7ce9d..323cc683 100644 --- a/Makefile.am +++ b/Makefile.am @@ -982,8 +982,10 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ cmake/libprotoc.cmake \ cmake/protobuf-config-version.cmake.in \ cmake/protobuf-config.cmake.in \ + cmake/protobuf-lite.pc.cmake \ cmake/protobuf-module.cmake.in \ cmake/protobuf-options.cmake \ + cmake/protobuf.pc.cmake \ cmake/protoc.cmake \ cmake/tests.cmake \ editors/README.txt \ diff --git a/tests.sh b/tests.sh index d1778465..0bdc1284 100755 --- a/tests.sh +++ b/tests.sh @@ -63,7 +63,6 @@ build_cpp_distcheck() { # List all files that should be included in the distribution package. git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\|src/google/protobuf/.*\.proto\)" |\ grep -v ".gitignore" | grep -v "java/compatibility_tests" |\ - grep -v "cmake/protobuf.*\.pc\.cmake" |\ grep -v "python/compatibility_tests" | grep -v "csharp/compatibility_tests" > dist.lst # Unzip the dist tar file. DIST=`ls *.tar.gz` -- cgit v1.2.3 From 2807436cd828a526c5c38dd235c0d0d9cdc67b1f Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 30 Aug 2017 16:50:07 -0700 Subject: change the field number of php_generic_service to fix the conflict with (#3576) internal descriptor.proto --- Makefile.am | 1 + .../src/Google.Protobuf/Reflection/Descriptor.cs | 20 +-- .../Google/Protobuf/Internal/Descriptor.php | 2 +- .../Protobuf/Internal/ExtensionRangeOptions.php | 64 +++++++ php/src/Google/Protobuf/Internal/FileOptions.php | 6 +- src/google/protobuf/descriptor.pb.cc | 196 ++++++++++----------- src/google/protobuf/descriptor.pb.h | 76 ++++---- src/google/protobuf/descriptor.proto | 2 +- 8 files changed, 216 insertions(+), 151 deletions(-) create mode 100644 php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php diff --git a/Makefile.am b/Makefile.am index 323cc683..7831a09e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -619,6 +619,7 @@ php_EXTRA_DIST= \ php/src/Google/Protobuf/Internal/EnumOptions.php \ php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php \ php/src/Google/Protobuf/Internal/EnumValueOptions.php \ + php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php \ php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php \ php/src/Google/Protobuf/Internal/FieldDescriptorProto.php \ php/src/Google/Protobuf/Internal/FieldDescriptor.php \ diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 8311a2c6..b778e058 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -92,7 +92,7 @@ namespace Google.Protobuf.Reflection { "T3B0aW1pemVNb2RlOgVTUEVFRBISCgpnb19wYWNrYWdlGAsgASgJEiIKE2Nj", "X2dlbmVyaWNfc2VydmljZXMYECABKAg6BWZhbHNlEiQKFWphdmFfZ2VuZXJp", "Y19zZXJ2aWNlcxgRIAEoCDoFZmFsc2USIgoTcHlfZ2VuZXJpY19zZXJ2aWNl", - "cxgSIAEoCDoFZmFsc2USIwoUcGhwX2dlbmVyaWNfc2VydmljZXMYEyABKAg6", + "cxgSIAEoCDoFZmFsc2USIwoUcGhwX2dlbmVyaWNfc2VydmljZXMYKiABKAg6", "BWZhbHNlEhkKCmRlcHJlY2F0ZWQYFyABKAg6BWZhbHNlEh8KEGNjX2VuYWJs", "ZV9hcmVuYXMYHyABKAg6BWZhbHNlEhkKEW9iamNfY2xhc3NfcHJlZml4GCQg", "ASgJEhgKEGNzaGFycF9uYW1lc3BhY2UYJSABKAkSFAoMc3dpZnRfcHJlZml4", @@ -3135,7 +3135,7 @@ namespace Google.Protobuf.Reflection { } /// Field number for the "php_generic_services" field. - public const int PhpGenericServicesFieldNumber = 19; + public const int PhpGenericServicesFieldNumber = 42; private bool phpGenericServices_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public bool PhpGenericServices { @@ -3366,10 +3366,6 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(144, 1); output.WriteBool(PyGenericServices); } - if (PhpGenericServices != false) { - output.WriteRawTag(152, 1); - output.WriteBool(PhpGenericServices); - } if (JavaGenerateEqualsAndHash != false) { output.WriteRawTag(160, 1); output.WriteBool(JavaGenerateEqualsAndHash); @@ -3406,6 +3402,10 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(202, 2); output.WriteString(PhpNamespace); } + if (PhpGenericServices != false) { + output.WriteRawTag(208, 2); + output.WriteBool(PhpGenericServices); + } uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); } @@ -3572,10 +3572,6 @@ namespace Google.Protobuf.Reflection { PyGenericServices = input.ReadBool(); break; } - case 152: { - PhpGenericServices = input.ReadBool(); - break; - } case 160: { JavaGenerateEqualsAndHash = input.ReadBool(); break; @@ -3612,6 +3608,10 @@ namespace Google.Protobuf.Reflection { PhpNamespace = input.ReadString(); break; } + case 336: { + PhpGenericServices = input.ReadBool(); + break; + } case 7994: { uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec); break; diff --git a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php index 60722d00..bb9024f8 100644 --- a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php +++ b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php @@ -144,7 +144,7 @@ class Descriptor ->optional('cc_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 16) ->optional('java_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 17) ->optional('py_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 18) - ->optional('php_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 19) + ->optional('php_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 42) ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 23) ->optional('cc_enable_arenas', \Google\Protobuf\Internal\GPBType::BOOL, 31) ->optional('objc_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 36) diff --git a/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php b/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php new file mode 100644 index 00000000..ee9e38bb --- /dev/null +++ b/php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php @@ -0,0 +1,64 @@ +google.protobuf.ExtensionRangeOptions + */ +class ExtensionRangeOptions extends \Google\Protobuf\Internal\Message +{ + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct(); + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getUninterpretedOption() + { + return $this->uninterpreted_option; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setUninterpretedOption($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); + $this->uninterpreted_option = $arr; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/php/src/Google/Protobuf/Internal/FileOptions.php b/php/src/Google/Protobuf/Internal/FileOptions.php index c2dd5e08..ee64e4e0 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions.php +++ b/php/src/Google/Protobuf/Internal/FileOptions.php @@ -109,7 +109,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message private $py_generic_services = false; private $has_py_generic_services = false; /** - * Generated from protobuf field optional bool php_generic_services = 19 [default = false]; + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; */ private $php_generic_services = false; private $has_php_generic_services = false; @@ -553,7 +553,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * Generated from protobuf field optional bool php_generic_services = 19 [default = false]; + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; * @return bool */ public function getPhpGenericServices() @@ -562,7 +562,7 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * Generated from protobuf field optional bool php_generic_services = 19 [default = false]; + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; * @param bool $var * @return $this */ diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 69c0ab0d..1827b97d 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -398,17 +398,17 @@ const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, uninterpreted_option_), 0, 1, - 8, 9, 10, + 11, 17, 2, - 11, 12, 13, 14, 15, 16, + 8, 3, 4, 5, @@ -812,7 +812,7 @@ void AddDescriptorsImpl() { "_package\030\013 \001(\t\022\"\n\023cc_generic_services\030\020 " "\001(\010:\005false\022$\n\025java_generic_services\030\021 \001(" "\010:\005false\022\"\n\023py_generic_services\030\022 \001(\010:\005f" - "alse\022#\n\024php_generic_services\030\023 \001(\010:\005fals" + "alse\022#\n\024php_generic_services\030* \001(\010:\005fals" "e\022\031\n\ndeprecated\030\027 \001(\010:\005false\022\037\n\020cc_enabl" "e_arenas\030\037 \001(\010:\005false\022\031\n\021objc_class_pref" "ix\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022\024\n\014sw" @@ -8871,9 +8871,9 @@ FileOptions::FileOptions(const FileOptions& from) if (from.has_php_namespace()) { php_namespace_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.php_namespace_); } - ::memcpy(&java_multiple_files_, &from.java_multiple_files_, + ::memcpy(&cc_enable_arenas_, &from.cc_enable_arenas_, static_cast(reinterpret_cast(&optimize_for_) - - reinterpret_cast(&java_multiple_files_)) + sizeof(optimize_for_)); + reinterpret_cast(&cc_enable_arenas_)) + sizeof(optimize_for_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.FileOptions) } @@ -8887,9 +8887,9 @@ void FileOptions::SharedCtor() { swift_prefix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); php_class_prefix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); php_namespace_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - ::memset(&java_multiple_files_, 0, static_cast( - reinterpret_cast(&cc_enable_arenas_) - - reinterpret_cast(&java_multiple_files_)) + sizeof(cc_enable_arenas_)); + ::memset(&cc_enable_arenas_, 0, static_cast( + reinterpret_cast(&deprecated_) - + reinterpret_cast(&cc_enable_arenas_)) + sizeof(deprecated_)); optimize_for_ = 1; } @@ -8976,12 +8976,12 @@ void FileOptions::Clear() { } } if (cached_has_bits & 65280u) { - ::memset(&java_multiple_files_, 0, static_cast( - reinterpret_cast(&deprecated_) - - reinterpret_cast(&java_multiple_files_)) + sizeof(deprecated_)); + ::memset(&cc_enable_arenas_, 0, static_cast( + reinterpret_cast(&php_generic_services_) - + reinterpret_cast(&cc_enable_arenas_)) + sizeof(php_generic_services_)); } if (cached_has_bits & 196608u) { - cc_enable_arenas_ = false; + deprecated_ = false; optimize_for_ = 1; } _has_bits_.Clear(); @@ -9122,20 +9122,6 @@ bool FileOptions::MergePartialFromCodedStream( break; } - // optional bool php_generic_services = 19 [default = false]; - case 19: { - if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(152u /* 152 & 0xFF */)) { - set_has_php_generic_services(); - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< - bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( - input, &php_generic_services_))); - } else { - goto handle_unusual; - } - break; - } - // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; case 20: { if (static_cast< ::google::protobuf::uint8>(tag) == @@ -9272,6 +9258,20 @@ bool FileOptions::MergePartialFromCodedStream( break; } + // optional bool php_generic_services = 42 [default = false]; + case 42: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(80u /* 336 & 0xFF */)) { + set_has_php_generic_services(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( + input, &php_generic_services_))); + } else { + goto handle_unusual; + } + break; + } + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == @@ -9344,7 +9344,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional bool java_multiple_files = 10 [default = false]; - if (cached_has_bits & 0x00000100u) { + if (cached_has_bits & 0x00000200u) { ::google::protobuf::internal::WireFormatLite::WriteBool(10, this->java_multiple_files(), output); } @@ -9359,42 +9359,37 @@ void FileOptions::SerializeWithCachedSizes( } // optional bool cc_generic_services = 16 [default = false]; - if (cached_has_bits & 0x00000800u) { + if (cached_has_bits & 0x00001000u) { ::google::protobuf::internal::WireFormatLite::WriteBool(16, this->cc_generic_services(), output); } // optional bool java_generic_services = 17 [default = false]; - if (cached_has_bits & 0x00001000u) { + if (cached_has_bits & 0x00002000u) { ::google::protobuf::internal::WireFormatLite::WriteBool(17, this->java_generic_services(), output); } // optional bool py_generic_services = 18 [default = false]; - if (cached_has_bits & 0x00002000u) { - ::google::protobuf::internal::WireFormatLite::WriteBool(18, this->py_generic_services(), output); - } - - // optional bool php_generic_services = 19 [default = false]; if (cached_has_bits & 0x00004000u) { - ::google::protobuf::internal::WireFormatLite::WriteBool(19, this->php_generic_services(), output); + ::google::protobuf::internal::WireFormatLite::WriteBool(18, this->py_generic_services(), output); } // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; - if (cached_has_bits & 0x00000200u) { + if (cached_has_bits & 0x00000400u) { ::google::protobuf::internal::WireFormatLite::WriteBool(20, this->java_generate_equals_and_hash(), output); } // optional bool deprecated = 23 [default = false]; - if (cached_has_bits & 0x00008000u) { + if (cached_has_bits & 0x00010000u) { ::google::protobuf::internal::WireFormatLite::WriteBool(23, this->deprecated(), output); } // optional bool java_string_check_utf8 = 27 [default = false]; - if (cached_has_bits & 0x00000400u) { + if (cached_has_bits & 0x00000800u) { ::google::protobuf::internal::WireFormatLite::WriteBool(27, this->java_string_check_utf8(), output); } // optional bool cc_enable_arenas = 31 [default = false]; - if (cached_has_bits & 0x00010000u) { + if (cached_has_bits & 0x00000100u) { ::google::protobuf::internal::WireFormatLite::WriteBool(31, this->cc_enable_arenas(), output); } @@ -9448,6 +9443,11 @@ void FileOptions::SerializeWithCachedSizes( 41, this->php_namespace(), output); } + // optional bool php_generic_services = 42 [default = false]; + if (cached_has_bits & 0x00008000u) { + ::google::protobuf::internal::WireFormatLite::WriteBool(42, this->php_generic_services(), output); + } + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; for (unsigned int i = 0, n = static_cast(this->uninterpreted_option_size()); i < n; i++) { @@ -9503,7 +9503,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional bool java_multiple_files = 10 [default = false]; - if (cached_has_bits & 0x00000100u) { + if (cached_has_bits & 0x00000200u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(10, this->java_multiple_files(), target); } @@ -9519,42 +9519,37 @@ void FileOptions::SerializeWithCachedSizes( } // optional bool cc_generic_services = 16 [default = false]; - if (cached_has_bits & 0x00000800u) { + if (cached_has_bits & 0x00001000u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(16, this->cc_generic_services(), target); } // optional bool java_generic_services = 17 [default = false]; - if (cached_has_bits & 0x00001000u) { + if (cached_has_bits & 0x00002000u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(17, this->java_generic_services(), target); } // optional bool py_generic_services = 18 [default = false]; - if (cached_has_bits & 0x00002000u) { - target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(18, this->py_generic_services(), target); - } - - // optional bool php_generic_services = 19 [default = false]; if (cached_has_bits & 0x00004000u) { - target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(19, this->php_generic_services(), target); + target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(18, this->py_generic_services(), target); } // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; - if (cached_has_bits & 0x00000200u) { + if (cached_has_bits & 0x00000400u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(20, this->java_generate_equals_and_hash(), target); } // optional bool deprecated = 23 [default = false]; - if (cached_has_bits & 0x00008000u) { + if (cached_has_bits & 0x00010000u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(23, this->deprecated(), target); } // optional bool java_string_check_utf8 = 27 [default = false]; - if (cached_has_bits & 0x00000400u) { + if (cached_has_bits & 0x00000800u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(27, this->java_string_check_utf8(), target); } // optional bool cc_enable_arenas = 31 [default = false]; - if (cached_has_bits & 0x00010000u) { + if (cached_has_bits & 0x00000100u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(31, this->cc_enable_arenas(), target); } @@ -9613,6 +9608,11 @@ void FileOptions::SerializeWithCachedSizes( 41, this->php_namespace(), target); } + // optional bool php_generic_services = 42 [default = false]; + if (cached_has_bits & 0x00008000u) { + target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(42, this->php_generic_services(), target); + } + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; for (unsigned int i = 0, n = static_cast(this->uninterpreted_option_size()); i < n; i++) { @@ -9714,6 +9714,11 @@ size_t FileOptions::ByteSizeLong() const { } if (_has_bits_[8 / 32] & 65280u) { + // optional bool cc_enable_arenas = 31 [default = false]; + if (has_cc_enable_arenas()) { + total_size += 2 + 1; + } + // optional bool java_multiple_files = 10 [default = false]; if (has_java_multiple_files()) { total_size += 1 + 1; @@ -9744,20 +9749,15 @@ size_t FileOptions::ByteSizeLong() const { total_size += 2 + 1; } - // optional bool php_generic_services = 19 [default = false]; + // optional bool php_generic_services = 42 [default = false]; if (has_php_generic_services()) { total_size += 2 + 1; } - // optional bool deprecated = 23 [default = false]; - if (has_deprecated()) { - total_size += 2 + 1; - } - } if (_has_bits_[16 / 32] & 196608u) { - // optional bool cc_enable_arenas = 31 [default = false]; - if (has_cc_enable_arenas()) { + // optional bool deprecated = 23 [default = false]; + if (has_deprecated()) { total_size += 2 + 1; } @@ -9836,34 +9836,34 @@ void FileOptions::MergeFrom(const FileOptions& from) { } if (cached_has_bits & 65280u) { if (cached_has_bits & 0x00000100u) { - java_multiple_files_ = from.java_multiple_files_; + cc_enable_arenas_ = from.cc_enable_arenas_; } if (cached_has_bits & 0x00000200u) { - java_generate_equals_and_hash_ = from.java_generate_equals_and_hash_; + java_multiple_files_ = from.java_multiple_files_; } if (cached_has_bits & 0x00000400u) { - java_string_check_utf8_ = from.java_string_check_utf8_; + java_generate_equals_and_hash_ = from.java_generate_equals_and_hash_; } if (cached_has_bits & 0x00000800u) { - cc_generic_services_ = from.cc_generic_services_; + java_string_check_utf8_ = from.java_string_check_utf8_; } if (cached_has_bits & 0x00001000u) { - java_generic_services_ = from.java_generic_services_; + cc_generic_services_ = from.cc_generic_services_; } if (cached_has_bits & 0x00002000u) { - py_generic_services_ = from.py_generic_services_; + java_generic_services_ = from.java_generic_services_; } if (cached_has_bits & 0x00004000u) { - php_generic_services_ = from.php_generic_services_; + py_generic_services_ = from.py_generic_services_; } if (cached_has_bits & 0x00008000u) { - deprecated_ = from.deprecated_; + php_generic_services_ = from.php_generic_services_; } _has_bits_[0] |= cached_has_bits; } if (cached_has_bits & 196608u) { if (cached_has_bits & 0x00010000u) { - cc_enable_arenas_ = from.cc_enable_arenas_; + deprecated_ = from.deprecated_; } if (cached_has_bits & 0x00020000u) { optimize_for_ = from.optimize_for_; @@ -9910,6 +9910,7 @@ void FileOptions::InternalSwap(FileOptions* other) { swift_prefix_.Swap(&other->swift_prefix_); php_class_prefix_.Swap(&other->php_class_prefix_); php_namespace_.Swap(&other->php_namespace_); + swap(cc_enable_arenas_, other->cc_enable_arenas_); swap(java_multiple_files_, other->java_multiple_files_); swap(java_generate_equals_and_hash_, other->java_generate_equals_and_hash_); swap(java_string_check_utf8_, other->java_string_check_utf8_); @@ -9918,7 +9919,6 @@ void FileOptions::InternalSwap(FileOptions* other) { swap(py_generic_services_, other->py_generic_services_); swap(php_generic_services_, other->php_generic_services_); swap(deprecated_, other->deprecated_); - swap(cc_enable_arenas_, other->cc_enable_arenas_); swap(optimize_for_, other->optimize_for_); swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); @@ -10062,13 +10062,13 @@ void FileOptions::set_allocated_java_outer_classname(::std::string* java_outer_c // optional bool java_multiple_files = 10 [default = false]; bool FileOptions::has_java_multiple_files() const { - return (_has_bits_[0] & 0x00000100u) != 0; + return (_has_bits_[0] & 0x00000200u) != 0; } void FileOptions::set_has_java_multiple_files() { - _has_bits_[0] |= 0x00000100u; + _has_bits_[0] |= 0x00000200u; } void FileOptions::clear_has_java_multiple_files() { - _has_bits_[0] &= ~0x00000100u; + _has_bits_[0] &= ~0x00000200u; } void FileOptions::clear_java_multiple_files() { java_multiple_files_ = false; @@ -10086,13 +10086,13 @@ void FileOptions::set_java_multiple_files(bool value) { // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; bool FileOptions::has_java_generate_equals_and_hash() const { - return (_has_bits_[0] & 0x00000200u) != 0; + return (_has_bits_[0] & 0x00000400u) != 0; } void FileOptions::set_has_java_generate_equals_and_hash() { - _has_bits_[0] |= 0x00000200u; + _has_bits_[0] |= 0x00000400u; } void FileOptions::clear_has_java_generate_equals_and_hash() { - _has_bits_[0] &= ~0x00000200u; + _has_bits_[0] &= ~0x00000400u; } void FileOptions::clear_java_generate_equals_and_hash() { java_generate_equals_and_hash_ = false; @@ -10110,13 +10110,13 @@ void FileOptions::set_java_generate_equals_and_hash(bool value) { // optional bool java_string_check_utf8 = 27 [default = false]; bool FileOptions::has_java_string_check_utf8() const { - return (_has_bits_[0] & 0x00000400u) != 0; + return (_has_bits_[0] & 0x00000800u) != 0; } void FileOptions::set_has_java_string_check_utf8() { - _has_bits_[0] |= 0x00000400u; + _has_bits_[0] |= 0x00000800u; } void FileOptions::clear_has_java_string_check_utf8() { - _has_bits_[0] &= ~0x00000400u; + _has_bits_[0] &= ~0x00000800u; } void FileOptions::clear_java_string_check_utf8() { java_string_check_utf8_ = false; @@ -10222,13 +10222,13 @@ void FileOptions::set_allocated_go_package(::std::string* go_package) { // optional bool cc_generic_services = 16 [default = false]; bool FileOptions::has_cc_generic_services() const { - return (_has_bits_[0] & 0x00000800u) != 0; + return (_has_bits_[0] & 0x00001000u) != 0; } void FileOptions::set_has_cc_generic_services() { - _has_bits_[0] |= 0x00000800u; + _has_bits_[0] |= 0x00001000u; } void FileOptions::clear_has_cc_generic_services() { - _has_bits_[0] &= ~0x00000800u; + _has_bits_[0] &= ~0x00001000u; } void FileOptions::clear_cc_generic_services() { cc_generic_services_ = false; @@ -10246,13 +10246,13 @@ void FileOptions::set_cc_generic_services(bool value) { // optional bool java_generic_services = 17 [default = false]; bool FileOptions::has_java_generic_services() const { - return (_has_bits_[0] & 0x00001000u) != 0; + return (_has_bits_[0] & 0x00002000u) != 0; } void FileOptions::set_has_java_generic_services() { - _has_bits_[0] |= 0x00001000u; + _has_bits_[0] |= 0x00002000u; } void FileOptions::clear_has_java_generic_services() { - _has_bits_[0] &= ~0x00001000u; + _has_bits_[0] &= ~0x00002000u; } void FileOptions::clear_java_generic_services() { java_generic_services_ = false; @@ -10270,13 +10270,13 @@ void FileOptions::set_java_generic_services(bool value) { // optional bool py_generic_services = 18 [default = false]; bool FileOptions::has_py_generic_services() const { - return (_has_bits_[0] & 0x00002000u) != 0; + return (_has_bits_[0] & 0x00004000u) != 0; } void FileOptions::set_has_py_generic_services() { - _has_bits_[0] |= 0x00002000u; + _has_bits_[0] |= 0x00004000u; } void FileOptions::clear_has_py_generic_services() { - _has_bits_[0] &= ~0x00002000u; + _has_bits_[0] &= ~0x00004000u; } void FileOptions::clear_py_generic_services() { py_generic_services_ = false; @@ -10292,15 +10292,15 @@ void FileOptions::set_py_generic_services(bool value) { // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.py_generic_services) } -// optional bool php_generic_services = 19 [default = false]; +// optional bool php_generic_services = 42 [default = false]; bool FileOptions::has_php_generic_services() const { - return (_has_bits_[0] & 0x00004000u) != 0; + return (_has_bits_[0] & 0x00008000u) != 0; } void FileOptions::set_has_php_generic_services() { - _has_bits_[0] |= 0x00004000u; + _has_bits_[0] |= 0x00008000u; } void FileOptions::clear_has_php_generic_services() { - _has_bits_[0] &= ~0x00004000u; + _has_bits_[0] &= ~0x00008000u; } void FileOptions::clear_php_generic_services() { php_generic_services_ = false; @@ -10318,13 +10318,13 @@ void FileOptions::set_php_generic_services(bool value) { // optional bool deprecated = 23 [default = false]; bool FileOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00008000u) != 0; + return (_has_bits_[0] & 0x00010000u) != 0; } void FileOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00008000u; + _has_bits_[0] |= 0x00010000u; } void FileOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00008000u; + _has_bits_[0] &= ~0x00010000u; } void FileOptions::clear_deprecated() { deprecated_ = false; @@ -10342,13 +10342,13 @@ void FileOptions::set_deprecated(bool value) { // optional bool cc_enable_arenas = 31 [default = false]; bool FileOptions::has_cc_enable_arenas() const { - return (_has_bits_[0] & 0x00010000u) != 0; + return (_has_bits_[0] & 0x00000100u) != 0; } void FileOptions::set_has_cc_enable_arenas() { - _has_bits_[0] |= 0x00010000u; + _has_bits_[0] |= 0x00000100u; } void FileOptions::clear_has_cc_enable_arenas() { - _has_bits_[0] &= ~0x00010000u; + _has_bits_[0] &= ~0x00000100u; } void FileOptions::clear_cc_enable_arenas() { cc_enable_arenas_ = false; diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 7ec516ab..c67d748b 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -2570,6 +2570,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* release_php_namespace(); void set_allocated_php_namespace(::std::string* php_namespace); + // optional bool cc_enable_arenas = 31 [default = false]; + bool has_cc_enable_arenas() const; + void clear_cc_enable_arenas(); + static const int kCcEnableArenasFieldNumber = 31; + bool cc_enable_arenas() const; + void set_cc_enable_arenas(bool value); + // optional bool java_multiple_files = 10 [default = false]; bool has_java_multiple_files() const; void clear_java_multiple_files(); @@ -2612,10 +2619,10 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p bool py_generic_services() const; void set_py_generic_services(bool value); - // optional bool php_generic_services = 19 [default = false]; + // optional bool php_generic_services = 42 [default = false]; bool has_php_generic_services() const; void clear_php_generic_services(); - static const int kPhpGenericServicesFieldNumber = 19; + static const int kPhpGenericServicesFieldNumber = 42; bool php_generic_services() const; void set_php_generic_services(bool value); @@ -2626,13 +2633,6 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p bool deprecated() const; void set_deprecated(bool value); - // optional bool cc_enable_arenas = 31 [default = false]; - bool has_cc_enable_arenas() const; - void clear_cc_enable_arenas(); - static const int kCcEnableArenasFieldNumber = 31; - bool cc_enable_arenas() const; - void set_cc_enable_arenas(bool value); - // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; bool has_optimize_for() const; void clear_optimize_for(); @@ -2694,6 +2694,7 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::google::protobuf::internal::ArenaStringPtr swift_prefix_; ::google::protobuf::internal::ArenaStringPtr php_class_prefix_; ::google::protobuf::internal::ArenaStringPtr php_namespace_; + bool cc_enable_arenas_; bool java_multiple_files_; bool java_generate_equals_and_hash_; bool java_string_check_utf8_; @@ -2702,7 +2703,6 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p bool py_generic_services_; bool php_generic_services_; bool deprecated_; - bool cc_enable_arenas_; int optimize_for_; friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct; }; @@ -7205,13 +7205,13 @@ inline void FileOptions::set_allocated_java_outer_classname(::std::string* java_ // optional bool java_multiple_files = 10 [default = false]; inline bool FileOptions::has_java_multiple_files() const { - return (_has_bits_[0] & 0x00000100u) != 0; + return (_has_bits_[0] & 0x00000200u) != 0; } inline void FileOptions::set_has_java_multiple_files() { - _has_bits_[0] |= 0x00000100u; + _has_bits_[0] |= 0x00000200u; } inline void FileOptions::clear_has_java_multiple_files() { - _has_bits_[0] &= ~0x00000100u; + _has_bits_[0] &= ~0x00000200u; } inline void FileOptions::clear_java_multiple_files() { java_multiple_files_ = false; @@ -7229,13 +7229,13 @@ inline void FileOptions::set_java_multiple_files(bool value) { // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; inline bool FileOptions::has_java_generate_equals_and_hash() const { - return (_has_bits_[0] & 0x00000200u) != 0; + return (_has_bits_[0] & 0x00000400u) != 0; } inline void FileOptions::set_has_java_generate_equals_and_hash() { - _has_bits_[0] |= 0x00000200u; + _has_bits_[0] |= 0x00000400u; } inline void FileOptions::clear_has_java_generate_equals_and_hash() { - _has_bits_[0] &= ~0x00000200u; + _has_bits_[0] &= ~0x00000400u; } inline void FileOptions::clear_java_generate_equals_and_hash() { java_generate_equals_and_hash_ = false; @@ -7253,13 +7253,13 @@ inline void FileOptions::set_java_generate_equals_and_hash(bool value) { // optional bool java_string_check_utf8 = 27 [default = false]; inline bool FileOptions::has_java_string_check_utf8() const { - return (_has_bits_[0] & 0x00000400u) != 0; + return (_has_bits_[0] & 0x00000800u) != 0; } inline void FileOptions::set_has_java_string_check_utf8() { - _has_bits_[0] |= 0x00000400u; + _has_bits_[0] |= 0x00000800u; } inline void FileOptions::clear_has_java_string_check_utf8() { - _has_bits_[0] &= ~0x00000400u; + _has_bits_[0] &= ~0x00000800u; } inline void FileOptions::clear_java_string_check_utf8() { java_string_check_utf8_ = false; @@ -7365,13 +7365,13 @@ inline void FileOptions::set_allocated_go_package(::std::string* go_package) { // optional bool cc_generic_services = 16 [default = false]; inline bool FileOptions::has_cc_generic_services() const { - return (_has_bits_[0] & 0x00000800u) != 0; + return (_has_bits_[0] & 0x00001000u) != 0; } inline void FileOptions::set_has_cc_generic_services() { - _has_bits_[0] |= 0x00000800u; + _has_bits_[0] |= 0x00001000u; } inline void FileOptions::clear_has_cc_generic_services() { - _has_bits_[0] &= ~0x00000800u; + _has_bits_[0] &= ~0x00001000u; } inline void FileOptions::clear_cc_generic_services() { cc_generic_services_ = false; @@ -7389,13 +7389,13 @@ inline void FileOptions::set_cc_generic_services(bool value) { // optional bool java_generic_services = 17 [default = false]; inline bool FileOptions::has_java_generic_services() const { - return (_has_bits_[0] & 0x00001000u) != 0; + return (_has_bits_[0] & 0x00002000u) != 0; } inline void FileOptions::set_has_java_generic_services() { - _has_bits_[0] |= 0x00001000u; + _has_bits_[0] |= 0x00002000u; } inline void FileOptions::clear_has_java_generic_services() { - _has_bits_[0] &= ~0x00001000u; + _has_bits_[0] &= ~0x00002000u; } inline void FileOptions::clear_java_generic_services() { java_generic_services_ = false; @@ -7413,13 +7413,13 @@ inline void FileOptions::set_java_generic_services(bool value) { // optional bool py_generic_services = 18 [default = false]; inline bool FileOptions::has_py_generic_services() const { - return (_has_bits_[0] & 0x00002000u) != 0; + return (_has_bits_[0] & 0x00004000u) != 0; } inline void FileOptions::set_has_py_generic_services() { - _has_bits_[0] |= 0x00002000u; + _has_bits_[0] |= 0x00004000u; } inline void FileOptions::clear_has_py_generic_services() { - _has_bits_[0] &= ~0x00002000u; + _has_bits_[0] &= ~0x00004000u; } inline void FileOptions::clear_py_generic_services() { py_generic_services_ = false; @@ -7435,15 +7435,15 @@ inline void FileOptions::set_py_generic_services(bool value) { // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.py_generic_services) } -// optional bool php_generic_services = 19 [default = false]; +// optional bool php_generic_services = 42 [default = false]; inline bool FileOptions::has_php_generic_services() const { - return (_has_bits_[0] & 0x00004000u) != 0; + return (_has_bits_[0] & 0x00008000u) != 0; } inline void FileOptions::set_has_php_generic_services() { - _has_bits_[0] |= 0x00004000u; + _has_bits_[0] |= 0x00008000u; } inline void FileOptions::clear_has_php_generic_services() { - _has_bits_[0] &= ~0x00004000u; + _has_bits_[0] &= ~0x00008000u; } inline void FileOptions::clear_php_generic_services() { php_generic_services_ = false; @@ -7461,13 +7461,13 @@ inline void FileOptions::set_php_generic_services(bool value) { // optional bool deprecated = 23 [default = false]; inline bool FileOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00008000u) != 0; + return (_has_bits_[0] & 0x00010000u) != 0; } inline void FileOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00008000u; + _has_bits_[0] |= 0x00010000u; } inline void FileOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00008000u; + _has_bits_[0] &= ~0x00010000u; } inline void FileOptions::clear_deprecated() { deprecated_ = false; @@ -7485,13 +7485,13 @@ inline void FileOptions::set_deprecated(bool value) { // optional bool cc_enable_arenas = 31 [default = false]; inline bool FileOptions::has_cc_enable_arenas() const { - return (_has_bits_[0] & 0x00010000u) != 0; + return (_has_bits_[0] & 0x00000100u) != 0; } inline void FileOptions::set_has_cc_enable_arenas() { - _has_bits_[0] |= 0x00010000u; + _has_bits_[0] |= 0x00000100u; } inline void FileOptions::clear_has_cc_enable_arenas() { - _has_bits_[0] &= ~0x00010000u; + _has_bits_[0] &= ~0x00000100u; } inline void FileOptions::clear_cc_enable_arenas() { cc_enable_arenas_ = false; diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index f1ec5735..4d4fb378 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -361,7 +361,7 @@ message FileOptions { optional bool cc_generic_services = 16 [default=false]; optional bool java_generic_services = 17 [default=false]; optional bool py_generic_services = 18 [default=false]; - optional bool php_generic_services = 19 [default=false]; + optional bool php_generic_services = 42 [default=false]; // Is this file deprecated? // Depending on the target platform, this can emit Deprecated annotations -- cgit v1.2.3 From 50a64759ddac6c63bff9a76a4ae9935092e8924d Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 5 Sep 2017 17:59:03 +0200 Subject: Google.Protobuf should target net45 --- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 1d21fdc5..4e63646b 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -6,7 +6,7 @@ Google Protocol Buffers 3.4.0 Google Inc. - netstandard1.0;net451 + netstandard1.0;net45 true ../../keys/Google.Protobuf.snk true -- cgit v1.2.3 From e5d000cbb7bcf8fadddfbdb544070e31ce36fa26 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Fri, 8 Sep 2017 15:11:49 -0700 Subject: Add prefix to php reserved keywords. --- Makefile.am | 4 + php/ext/google/protobuf/def.c | 30 ++- php/src/Google/Protobuf/Internal/GPBUtil.php | 18 +- php/tests/generated_class_test.php | 222 ++++++++++++++++++++++ php/tests/proto/test_reserved_enum_lower.proto | 79 ++++++++ php/tests/proto/test_reserved_enum_upper.proto | 79 ++++++++ php/tests/proto/test_reserved_message_lower.proto | 77 ++++++++ php/tests/proto/test_reserved_message_upper.proto | 77 ++++++++ src/google/protobuf/compiler/php/php_generator.cc | 24 ++- tests.sh | 22 ++- 10 files changed, 615 insertions(+), 17 deletions(-) create mode 100644 php/tests/proto/test_reserved_enum_lower.proto create mode 100644 php/tests/proto/test_reserved_enum_upper.proto create mode 100644 php/tests/proto/test_reserved_message_lower.proto create mode 100644 php/tests/proto/test_reserved_message_upper.proto diff --git a/Makefile.am b/Makefile.am index 7831a09e..f4d09fa0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -686,6 +686,10 @@ php_EXTRA_DIST= \ php/tests/proto/test_no_namespace.proto \ php/tests/proto/test_php_namespace.proto \ php/tests/proto/test_prefix.proto \ + php/tests/proto/test_reserved_enum_lower.proto \ + php/tests/proto/test_reserved_enum_upper.proto \ + php/tests/proto/test_reserved_message_lower.proto \ + php/tests/proto/test_reserved_message_upper.proto \ php/tests/proto/test_service.proto \ php/tests/proto/test_service_namespace.proto \ php/tests/test.sh \ diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index f885c145..d615cb3c 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -30,8 +30,23 @@ #include "protobuf.h" -const char* const kReservedNames[] = {"Empty", "ECHO", "ARRAY"}; -const int kReservedNamesSize = 3; +const char *const kReservedNames[] = { + "abstract", "and", "array", "as", "break", + "callable", "case", "catch", "class", "clone", + "const", "continue", "declare", "default", "die", + "do", "echo", "else", "elseif", "empty", + "enddeclare", "endfor", "endforeach", "endif", "endswitch", + "endwhile", "eval", "exit", "extends", "final", + "for", "foreach", "function", "global", "goto", + "if", "implements", "include", "include_once", "instanceof", + "insteadof", "interface", "isset", "list", "namespace", + "new", "or", "print", "private", "protected", + "public", "require", "require_once", "return", "static", + "switch", "throw", "trait", "try", "unset", + "use", "var", "while", "xor", "int", + "float", "bool", "string", "true", "false", + "null", "void", "iterable"}; +const int kReservedNamesSize = 73; // Forward declare. static void descriptor_init_c_instance(Descriptor* intern TSRMLS_DC); @@ -774,12 +789,21 @@ static const char *classname_prefix(const char *classname, return prefix_given; } + char* lower = ALLOC_N(char, strlen(classname) + 1); + i = 0; + while(classname[i]) { + lower[i] = (char)tolower(classname[i]); + i++; + } + lower[i] = 0; + for (i = 0; i < kReservedNamesSize; i++) { - if (strcmp(kReservedNames[i], classname) == 0) { + if (strcmp(kReservedNames[i], lower) == 0) { is_reserved = true; break; } } + FREE(lower); if (is_reserved) { if (package_name != NULL && strcmp("google.protobuf", package_name) == 0) { diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 84e8ecf0..659a4ee3 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -252,9 +252,23 @@ class GPBUtil return $prefix; } - $reserved_words = array("Empty", "ECHO", "ARRAY"); + $reserved_words = array( + "abstract", "and", "array", "as", "break", "callable", "case", + "catch", "class", "clone", "const", "continue", "declare", + "default", "die", "do", "echo", "else", "elseif", "empty", + "enddeclare", "endfor", "endforeach", "endif", "endswitch", + "endwhile", "eval", "exit", "extends", "final", "for", "foreach", + "function", "global", "goto", "if", "implements", "include", + "include_once", "instanceof", "insteadof", "interface", "isset", + "list", "namespace", "new", "or", "print", "private", "protected", + "public", "require", "require_once", "return", "static", "switch", + "throw", "trait", "try", "unset", "use", "var", "while", "xor", + "int", "float", "bool", "string", "true", "false", "null", "void", + "iterable" + + ); foreach ($reserved_words as $reserved_word) { - if ($classname === $reserved_word) { + if (strtolower($classname) === $reserved_word) { if ($file_proto->getPackage() === "google.protobuf") { return "GPB"; } else { diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index 98918bce..c63318a9 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -691,6 +691,228 @@ class GeneratedClassTest extends TestBase $m = new \Foo\PBEmpty(); $m = new \PrefixEmpty(); $m = new \Foo\PBARRAY(); + + $m = new \Lower\PBabstract(); + $m = new \Lower\PBand(); + $m = new \Lower\PBarray(); + $m = new \Lower\PBas(); + $m = new \Lower\PBbreak(); + $m = new \Lower\PBcallable(); + $m = new \Lower\PBcase(); + $m = new \Lower\PBcatch(); + $m = new \Lower\PBclass(); + $m = new \Lower\PBclone(); + $m = new \Lower\PBconst(); + $m = new \Lower\PBcontinue(); + $m = new \Lower\PBdeclare(); + $m = new \Lower\PBdefault(); + $m = new \Lower\PBdie(); + $m = new \Lower\PBdo(); + $m = new \Lower\PBecho(); + $m = new \Lower\PBelse(); + $m = new \Lower\PBelseif(); + $m = new \Lower\PBempty(); + $m = new \Lower\PBenddeclare(); + $m = new \Lower\PBendfor(); + $m = new \Lower\PBendforeach(); + $m = new \Lower\PBendif(); + $m = new \Lower\PBendswitch(); + $m = new \Lower\PBendwhile(); + $m = new \Lower\PBeval(); + $m = new \Lower\PBexit(); + $m = new \Lower\PBextends(); + $m = new \Lower\PBfinal(); + $m = new \Lower\PBfor(); + $m = new \Lower\PBforeach(); + $m = new \Lower\PBfunction(); + $m = new \Lower\PBglobal(); + $m = new \Lower\PBgoto(); + $m = new \Lower\PBif(); + $m = new \Lower\PBimplements(); + $m = new \Lower\PBinclude(); + $m = new \Lower\PBinclude_once(); + $m = new \Lower\PBinstanceof(); + $m = new \Lower\PBinsteadof(); + $m = new \Lower\PBinterface(); + $m = new \Lower\PBisset(); + $m = new \Lower\PBlist(); + $m = new \Lower\PBnamespace(); + $m = new \Lower\PBnew(); + $m = new \Lower\PBor(); + $m = new \Lower\PBprint(); + $m = new \Lower\PBprivate(); + $m = new \Lower\PBprotected(); + $m = new \Lower\PBpublic(); + $m = new \Lower\PBrequire(); + $m = new \Lower\PBrequire_once(); + $m = new \Lower\PBreturn(); + $m = new \Lower\PBstatic(); + $m = new \Lower\PBswitch(); + $m = new \Lower\PBthrow(); + $m = new \Lower\PBtrait(); + $m = new \Lower\PBtry(); + $m = new \Lower\PBunset(); + $m = new \Lower\PBuse(); + $m = new \Lower\PBvar(); + $m = new \Lower\PBwhile(); + $m = new \Lower\PBxor(); + $m = new \Lower\PBint(); + $m = new \Lower\PBfloat(); + $m = new \Lower\PBbool(); + $m = new \Lower\PBstring(); + $m = new \Lower\PBtrue(); + $m = new \Lower\PBfalse(); + $m = new \Lower\PBnull(); + $m = new \Lower\PBvoid(); + $m = new \Lower\PBiterable(); + + $m = new \Upper\PBABSTRACT(); + $m = new \Upper\PBAND(); + $m = new \Upper\PBARRAY(); + $m = new \Upper\PBAS(); + $m = new \Upper\PBBREAK(); + $m = new \Upper\PBCALLABLE(); + $m = new \Upper\PBCASE(); + $m = new \Upper\PBCATCH(); + $m = new \Upper\PBCLASS(); + $m = new \Upper\PBCLONE(); + $m = new \Upper\PBCONST(); + $m = new \Upper\PBCONTINUE(); + $m = new \Upper\PBDECLARE(); + $m = new \Upper\PBDEFAULT(); + $m = new \Upper\PBDIE(); + $m = new \Upper\PBDO(); + $m = new \Upper\PBECHO(); + $m = new \Upper\PBELSE(); + $m = new \Upper\PBELSEIF(); + $m = new \Upper\PBEMPTY(); + $m = new \Upper\PBENDDECLARE(); + $m = new \Upper\PBENDFOR(); + $m = new \Upper\PBENDFOREACH(); + $m = new \Upper\PBENDIF(); + $m = new \Upper\PBENDSWITCH(); + $m = new \Upper\PBENDWHILE(); + $m = new \Upper\PBEVAL(); + $m = new \Upper\PBEXIT(); + $m = new \Upper\PBEXTENDS(); + $m = new \Upper\PBFINAL(); + $m = new \Upper\PBFOR(); + $m = new \Upper\PBFOREACH(); + $m = new \Upper\PBFUNCTION(); + $m = new \Upper\PBGLOBAL(); + $m = new \Upper\PBGOTO(); + $m = new \Upper\PBIF(); + $m = new \Upper\PBIMPLEMENTS(); + $m = new \Upper\PBINCLUDE(); + $m = new \Upper\PBINCLUDE_ONCE(); + $m = new \Upper\PBINSTANCEOF(); + $m = new \Upper\PBINSTEADOF(); + $m = new \Upper\PBINTERFACE(); + $m = new \Upper\PBISSET(); + $m = new \Upper\PBLIST(); + $m = new \Upper\PBNAMESPACE(); + $m = new \Upper\PBNEW(); + $m = new \Upper\PBOR(); + $m = new \Upper\PBPRINT(); + $m = new \Upper\PBPRIVATE(); + $m = new \Upper\PBPROTECTED(); + $m = new \Upper\PBPUBLIC(); + $m = new \Upper\PBREQUIRE(); + $m = new \Upper\PBREQUIRE_ONCE(); + $m = new \Upper\PBRETURN(); + $m = new \Upper\PBSTATIC(); + $m = new \Upper\PBSWITCH(); + $m = new \Upper\PBTHROW(); + $m = new \Upper\PBTRAIT(); + $m = new \Upper\PBTRY(); + $m = new \Upper\PBUNSET(); + $m = new \Upper\PBUSE(); + $m = new \Upper\PBVAR(); + $m = new \Upper\PBWHILE(); + $m = new \Upper\PBXOR(); + $m = new \Upper\PBINT(); + $m = new \Upper\PBFLOAT(); + $m = new \Upper\PBBOOL(); + $m = new \Upper\PBSTRING(); + $m = new \Upper\PBTRUE(); + $m = new \Upper\PBFALSE(); + $m = new \Upper\PBNULL(); + $m = new \Upper\PBVOID(); + $m = new \Upper\PBITERABLE(); + + $m = \Lower_enum\NotAllowed::PBabstract; + $m = \Lower_enum\NotAllowed::PBand; + $m = \Lower_enum\NotAllowed::PBarray; + $m = \Lower_enum\NotAllowed::PBas; + $m = \Lower_enum\NotAllowed::PBbreak; + $m = \Lower_enum\NotAllowed::PBcallable; + $m = \Lower_enum\NotAllowed::PBcase; + $m = \Lower_enum\NotAllowed::PBcatch; + $m = \Lower_enum\NotAllowed::PBclass; + $m = \Lower_enum\NotAllowed::PBclone; + $m = \Lower_enum\NotAllowed::PBconst; + $m = \Lower_enum\NotAllowed::PBcontinue; + $m = \Lower_enum\NotAllowed::PBdeclare; + $m = \Lower_enum\NotAllowed::PBdefault; + $m = \Lower_enum\NotAllowed::PBdie; + $m = \Lower_enum\NotAllowed::PBdo; + $m = \Lower_enum\NotAllowed::PBecho; + $m = \Lower_enum\NotAllowed::PBelse; + $m = \Lower_enum\NotAllowed::PBelseif; + $m = \Lower_enum\NotAllowed::PBempty; + $m = \Lower_enum\NotAllowed::PBenddeclare; + $m = \Lower_enum\NotAllowed::PBendfor; + $m = \Lower_enum\NotAllowed::PBendforeach; + $m = \Lower_enum\NotAllowed::PBendif; + $m = \Lower_enum\NotAllowed::PBendswitch; + $m = \Lower_enum\NotAllowed::PBendwhile; + $m = \Lower_enum\NotAllowed::PBeval; + $m = \Lower_enum\NotAllowed::PBexit; + $m = \Lower_enum\NotAllowed::PBextends; + $m = \Lower_enum\NotAllowed::PBfinal; + $m = \Lower_enum\NotAllowed::PBfor; + $m = \Lower_enum\NotAllowed::PBforeach; + $m = \Lower_enum\NotAllowed::PBfunction; + $m = \Lower_enum\NotAllowed::PBglobal; + $m = \Lower_enum\NotAllowed::PBgoto; + $m = \Lower_enum\NotAllowed::PBif; + $m = \Lower_enum\NotAllowed::PBimplements; + $m = \Lower_enum\NotAllowed::PBinclude; + $m = \Lower_enum\NotAllowed::PBinclude_once; + $m = \Lower_enum\NotAllowed::PBinstanceof; + $m = \Lower_enum\NotAllowed::PBinsteadof; + $m = \Lower_enum\NotAllowed::PBinterface; + $m = \Lower_enum\NotAllowed::PBisset; + $m = \Lower_enum\NotAllowed::PBlist; + $m = \Lower_enum\NotAllowed::PBnamespace; + $m = \Lower_enum\NotAllowed::PBnew; + $m = \Lower_enum\NotAllowed::PBor; + $m = \Lower_enum\NotAllowed::PBprint; + $m = \Lower_enum\NotAllowed::PBprivate; + $m = \Lower_enum\NotAllowed::PBprotected; + $m = \Lower_enum\NotAllowed::PBpublic; + $m = \Lower_enum\NotAllowed::PBrequire; + $m = \Lower_enum\NotAllowed::PBrequire_once; + $m = \Lower_enum\NotAllowed::PBreturn; + $m = \Lower_enum\NotAllowed::PBstatic; + $m = \Lower_enum\NotAllowed::PBswitch; + $m = \Lower_enum\NotAllowed::PBthrow; + $m = \Lower_enum\NotAllowed::PBtrait; + $m = \Lower_enum\NotAllowed::PBtry; + $m = \Lower_enum\NotAllowed::PBunset; + $m = \Lower_enum\NotAllowed::PBuse; + $m = \Lower_enum\NotAllowed::PBvar; + $m = \Lower_enum\NotAllowed::PBwhile; + $m = \Lower_enum\NotAllowed::PBxor; + $m = \Lower_enum\NotAllowed::PBint; + $m = \Lower_enum\NotAllowed::PBfloat; + $m = \Lower_enum\NotAllowed::PBbool; + $m = \Lower_enum\NotAllowed::PBstring; + $m = \Lower_enum\NotAllowed::PBtrue; + $m = \Lower_enum\NotAllowed::PBfalse; + $m = \Lower_enum\NotAllowed::PBnull; + $m = \Lower_enum\NotAllowed::PBvoid; + $m = \Lower_enum\NotAllowed::PBiterable; } ######################################################### diff --git a/php/tests/proto/test_reserved_enum_lower.proto b/php/tests/proto/test_reserved_enum_lower.proto new file mode 100644 index 00000000..e2144c0c --- /dev/null +++ b/php/tests/proto/test_reserved_enum_lower.proto @@ -0,0 +1,79 @@ +syntax = "proto3"; + +package lower_enum; + +enum NotAllowed { + abstract = 0; + and = 1; + array = 2; + as = 3; + break = 4; + callable = 5; + case = 6; + catch = 7; + class = 8; + clone = 9; + const = 10; + continue = 11; + declare = 12; + default = 13; + die = 14; + do = 15; + echo = 16; + else = 17; + elseif = 18; + empty = 19; + enddeclare = 20; + endfor = 21; + endforeach = 22; + endif = 23; + endswitch = 24; + endwhile = 25; + eval = 26; + exit = 27; + extends = 28; + final = 29; + for = 30; + foreach = 31; + function = 32; + global = 33; + goto = 34; + if = 35; + implements = 36; + include = 37; + include_once = 38; + instanceof = 39; + insteadof = 40; + interface = 41; + isset = 42; + list = 43; + namespace = 44; + new = 45; + or = 46; + print = 47; + private = 48; + protected = 49; + public = 50; + require = 51; + require_once = 52; + return = 53; + static = 54; + switch = 55; + throw = 56; + trait = 57; + try = 58; + unset = 59; + use = 60; + var = 61; + while = 62; + xor = 63; + int = 64; + float = 65; + bool = 66; + string = 67; + true = 68; + false = 69; + null = 70; + void = 71; + iterable = 72; +} diff --git a/php/tests/proto/test_reserved_enum_upper.proto b/php/tests/proto/test_reserved_enum_upper.proto new file mode 100644 index 00000000..a4cc1f4b --- /dev/null +++ b/php/tests/proto/test_reserved_enum_upper.proto @@ -0,0 +1,79 @@ +syntax = "proto3"; + +package upper_enum; + +enum NotAllowed { + ABSTRACT = 0; + AND = 1; + ARRAY = 2; + AS = 3; + BREAK = 4; + CALLABLE = 5; + CASE = 6; + CATCH = 7; + CLASS = 8; + CLONE = 9; + CONST = 10; + CONTINUE = 11; + DECLARE = 12; + DEFAULT = 13; + DIE = 14; + DO = 15; + ECHO = 16; + ELSE = 17; + ELSEIF = 18; + EMPTY = 19; + ENDDECLARE = 20; + ENDFOR = 21; + ENDFOREACH = 22; + ENDIF = 23; + ENDSWITCH = 24; + ENDWHILE = 25; + EVAL = 26; + EXIT = 27; + EXTENDS = 28; + FINAL = 29; + FOR = 30; + FOREACH = 31; + FUNCTION = 32; + GLOBAL = 33; + GOTO = 34; + IF = 35; + IMPLEMENTS = 36; + INCLUDE = 37; + INCLUDE_ONCE = 38; + INSTANCEOF = 39; + INSTEADOF = 40; + INTERFACE = 41; + ISSET = 42; + LIST = 43; + NAMESPACE = 44; + NEW = 45; + OR = 46; + PRINT = 47; + PRIVATE = 48; + PROTECTED = 49; + PUBLIC = 50; + REQUIRE = 51; + REQUIRE_ONCE = 52; + RETURN = 53; + STATIC = 54; + SWITCH = 55; + THROW = 56; + TRAIT = 57; + TRY = 58; + UNSET = 59; + USE = 60; + VAR = 61; + WHILE = 62; + XOR = 63; + INT = 64; + FLOAT = 65; + BOOL = 66; + STRING = 67; + TRUE = 68; + FALSE = 69; + NULL = 70; + VOID = 71; + ITERABLE = 72; +} diff --git a/php/tests/proto/test_reserved_message_lower.proto b/php/tests/proto/test_reserved_message_lower.proto new file mode 100644 index 00000000..ed120808 --- /dev/null +++ b/php/tests/proto/test_reserved_message_lower.proto @@ -0,0 +1,77 @@ +syntax = "proto3"; + +package lower; + +message abstract {} +message and {} +message array {} +message as {} +message break {} +message callable {} +message case {} +message catch {} +message class {} +message clone {} +message const {} +message continue {} +message declare {} +message default {} +message die {} +message do {} +message echo {} +message else {} +message elseif {} +message empty {} +message enddeclare {} +message endfor {} +message endforeach {} +message endif {} +message endswitch {} +message endwhile {} +message eval {} +message exit {} +message extends {} +message final {} +message for {} +message foreach {} +message function {} +message global {} +message goto {} +message if {} +message implements {} +message include {} +message include_once {} +message instanceof {} +message insteadof {} +message interface {} +message isset {} +message list {} +message namespace {} +message new {} +message or {} +message print {} +message private {} +message protected {} +message public {} +message require {} +message require_once {} +message return {} +message static {} +message switch {} +message throw {} +message trait {} +message try {} +message unset {} +message use {} +message var {} +message while {} +message xor {} +message int {} +message float {} +message bool {} +message string {} +message true {} +message false {} +message null {} +message void {} +message iterable {} diff --git a/php/tests/proto/test_reserved_message_upper.proto b/php/tests/proto/test_reserved_message_upper.proto new file mode 100644 index 00000000..2917fd11 --- /dev/null +++ b/php/tests/proto/test_reserved_message_upper.proto @@ -0,0 +1,77 @@ +syntax = "proto3"; + +package upper; + +message ABSTRACT {} +message AND {} +message ARRAY {} +message AS {} +message BREAK {} +message CALLABLE {} +message CASE {} +message CATCH {} +message CLASS {} +message CLONE {} +message CONST {} +message CONTINUE {} +message DECLARE {} +message DEFAULT {} +message DIE {} +message DO {} +message ECHO {} +message ELSE {} +message ELSEIF {} +message EMPTY {} +message ENDDECLARE {} +message ENDFOR {} +message ENDFOREACH {} +message ENDIF {} +message ENDSWITCH {} +message ENDWHILE {} +message EVAL {} +message EXIT {} +message EXTENDS {} +message FINAL {} +message FOR {} +message FOREACH {} +message FUNCTION {} +message GLOBAL {} +message GOTO {} +message IF {} +message IMPLEMENTS {} +message INCLUDE {} +message INCLUDE_ONCE {} +message INSTANCEOF {} +message INSTEADOF {} +message INTERFACE {} +message ISSET {} +message LIST {} +message NAMESPACE {} +message NEW {} +message OR {} +message PRINT {} +message PRIVATE {} +message PROTECTED {} +message PUBLIC {} +message REQUIRE {} +message REQUIRE_ONCE {} +message RETURN {} +message STATIC {} +message SWITCH {} +message THROW {} +message TRAIT {} +message TRY {} +message UNSET {} +message USE {} +message VAR {} +message WHILE {} +message XOR {} +message INT {} +message FLOAT {} +message BOOL {} +message STRING {} +message TRUE {} +message FALSE {} +message NULL {} +message VOID {} +message ITERABLE {} diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 60e6fce9..fe781df2 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -49,8 +49,23 @@ const std::string kDescriptorMetadataFile = "GPBMetadata/Google/Protobuf/Internal/Descriptor.php"; const std::string kDescriptorDirName = "Google/Protobuf/Internal"; const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal"; -const char* const kReservedNames[] = {"ARRAY", "Empty", "ECHO"}; -const int kReservedNamesSize = 3; +const char* const kReservedNames[] = { + "abstract", "and", "array", "as", "break", + "callable", "case", "catch", "class", "clone", + "const", "continue", "declare", "default", "die", + "do", "echo", "else", "elseif", "empty", + "enddeclare", "endfor", "endforeach", "endif", "endswitch", + "endwhile", "eval", "exit", "extends", "final", + "for", "foreach", "function", "global", "goto", + "if", "implements", "include", "include_once", "instanceof", + "insteadof", "interface", "isset", "list", "namespace", + "new", "or", "print", "private", "protected", + "public", "require", "require_once", "return", "static", + "switch", "throw", "trait", "try", "unset", + "use", "var", "while", "xor", "int", + "float", "bool", "string", "true", "false", + "null", "void", "iterable"}; +const int kReservedNamesSize = 73; const int kFieldSetter = 1; const int kFieldGetter = 2; const int kFieldProperty = 3; @@ -125,8 +140,11 @@ std::string ClassNamePrefix(const string& classname, bool is_reserved = false; + string lower = classname; + transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + for (int i = 0; i < kReservedNamesSize; i++) { - if (classname == kReservedNames[i]) { + if (lower == kReservedNames[i]) { is_reserved = true; break; } diff --git a/tests.sh b/tests.sh index 0bdc1284..a29ba647 100755 --- a/tests.sh +++ b/tests.sh @@ -346,15 +346,19 @@ generate_php_test_proto() { # Generate test file rm -rf generated mkdir generated - ../../src/protoc --php_out=generated \ - proto/test.proto \ - proto/test_include.proto \ - proto/test_no_namespace.proto \ - proto/test_prefix.proto \ - proto/test_php_namespace.proto \ - proto/test_empty_php_namespace.proto \ - proto/test_service.proto \ - proto/test_service_namespace.proto \ + ../../src/protoc --php_out=generated \ + proto/test.proto \ + proto/test_include.proto \ + proto/test_no_namespace.proto \ + proto/test_prefix.proto \ + proto/test_php_namespace.proto \ + proto/test_empty_php_namespace.proto \ + proto/test_reserved_enum_lower.proto \ + proto/test_reserved_enum_upper.proto \ + proto/test_reserved_message_lower.proto \ + proto/test_reserved_message_upper.proto \ + proto/test_service.proto \ + proto/test_service_namespace.proto \ proto/test_descriptors.proto pushd ../../src ./protoc --php_out=../php/tests/generated google/protobuf/empty.proto -- cgit v1.2.3 From 89069ded5a34d552e63c541ed1132cefe34d91d1 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 11 Sep 2017 12:30:24 -0700 Subject: Change array to associate array. --- php/src/Google/Protobuf/Internal/GPBUtil.php | 41 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 659a4ee3..964d4f68 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -253,27 +253,28 @@ class GPBUtil } $reserved_words = array( - "abstract", "and", "array", "as", "break", "callable", "case", - "catch", "class", "clone", "const", "continue", "declare", - "default", "die", "do", "echo", "else", "elseif", "empty", - "enddeclare", "endfor", "endforeach", "endif", "endswitch", - "endwhile", "eval", "exit", "extends", "final", "for", "foreach", - "function", "global", "goto", "if", "implements", "include", - "include_once", "instanceof", "insteadof", "interface", "isset", - "list", "namespace", "new", "or", "print", "private", "protected", - "public", "require", "require_once", "return", "static", "switch", - "throw", "trait", "try", "unset", "use", "var", "while", "xor", - "int", "float", "bool", "string", "true", "false", "null", "void", - "iterable" - + "abstract"=>0, "and"=>0, "array"=>0, "as"=>0, "break"=>0, + "callable"=>0, "case"=>0, "catch"=>0, "class"=>0, "clone"=>0, + "const"=>0, "continue"=>0, "declare"=>0, "default"=>0, "die"=>0, + "do"=>0, "echo"=>0, "else"=>0, "elseif"=>0, "empty"=>0, + "enddeclare"=>0, "endfor"=>0, "endforeach"=>0, "endif"=>0, + "endswitch"=>0, "endwhile"=>0, "eval"=>0, "exit"=>0, "extends"=>0, + "final"=>0, "for"=>0, "foreach"=>0, "function"=>0, "global"=>0, + "goto"=>0, "if"=>0, "implements"=>0, "include"=>0, + "include_once"=>0, "instanceof"=>0, "insteadof"=>0, "interface"=>0, + "isset"=>0, "list"=>0, "namespace"=>0, "new"=>0, "or"=>0, + "print"=>0, "private"=>0, "protected"=>0, "public"=>0, "require"=>0, + "require_once"=>0, "return"=>0, "static"=>0, "switch"=>0, + "throw"=>0, "trait"=>0, "try"=>0, "unset"=>0, "use"=>0, "var"=>0, + "while"=>0, "xor"=>0, "int"=>0, "float"=>0, "bool"=>0, "string"=>0, + "true"=>0, "false"=>0, "null"=>0, "void"=>0, "iterable"=>0 ); - foreach ($reserved_words as $reserved_word) { - if (strtolower($classname) === $reserved_word) { - if ($file_proto->getPackage() === "google.protobuf") { - return "GPB"; - } else { - return "PB"; - } + + if (array_key_exists(strtolower($classname), $reserved_words)) { + if ($file_proto->getPackage() === "google.protobuf") { + return "GPB"; + } else { + return "PB"; } } -- cgit v1.2.3 From ddb9ef9cc3f9a7eab1ddf7ff90ecf2400e93c2b8 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 11 Sep 2017 15:51:57 -0700 Subject: Change array to map for reserved names in c extension --- php/ext/google/protobuf/def.c | 25 +--------------------- php/ext/google/protobuf/protobuf.c | 43 ++++++++++++++++++++++++++++++++++++++ php/ext/google/protobuf/protobuf.h | 25 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 24 deletions(-) diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index d615cb3c..d07c664c 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -30,24 +30,6 @@ #include "protobuf.h" -const char *const kReservedNames[] = { - "abstract", "and", "array", "as", "break", - "callable", "case", "catch", "class", "clone", - "const", "continue", "declare", "default", "die", - "do", "echo", "else", "elseif", "empty", - "enddeclare", "endfor", "endforeach", "endif", "endswitch", - "endwhile", "eval", "exit", "extends", "final", - "for", "foreach", "function", "global", "goto", - "if", "implements", "include", "include_once", "instanceof", - "insteadof", "interface", "isset", "list", "namespace", - "new", "or", "print", "private", "protected", - "public", "require", "require_once", "return", "static", - "switch", "throw", "trait", "try", "unset", - "use", "var", "while", "xor", "int", - "float", "bool", "string", "true", "false", - "null", "void", "iterable"}; -const int kReservedNamesSize = 73; - // Forward declare. static void descriptor_init_c_instance(Descriptor* intern TSRMLS_DC); static void descriptor_free_c(Descriptor* object TSRMLS_DC); @@ -797,12 +779,7 @@ static const char *classname_prefix(const char *classname, } lower[i] = 0; - for (i = 0; i < kReservedNamesSize; i++) { - if (strcmp(kReservedNames[i], lower) == 0) { - is_reserved = true; - break; - } - } + is_reserved = is_reserved_name(lower); FREE(lower); if (is_reserved) { diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index dc730030..43b4e584 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -46,6 +46,7 @@ static HashTable* upb_def_to_php_obj_map; // Global map from message/enum's php class entry to corresponding wrapper // Descriptor/EnumDescriptor instances. static HashTable* ce_to_php_obj_map; +static HashTable* reserved_names; // ----------------------------------------------------------------------------- // Global maps. @@ -110,6 +111,36 @@ bool class_added(const void* ce) { return exist_in_table(ce_to_php_obj_map, ce); } +// ----------------------------------------------------------------------------- +// Reserved Name. +// ----------------------------------------------------------------------------- + +// Although we already have kReservedNames, we still add them to hash table to +// speed up look up. +const char *const kReservedNames[] = { + "abstract", "and", "array", "as", "break", + "callable", "case", "catch", "class", "clone", + "const", "continue", "declare", "default", "die", + "do", "echo", "else", "elseif", "empty", + "enddeclare", "endfor", "endforeach", "endif", "endswitch", + "endwhile", "eval", "exit", "extends", "final", + "for", "foreach", "function", "global", "goto", + "if", "implements", "include", "include_once", "instanceof", + "insteadof", "interface", "isset", "list", "namespace", + "new", "or", "print", "private", "protected", + "public", "require", "require_once", "return", "static", + "switch", "throw", "trait", "try", "unset", + "use", "var", "while", "xor", "int", + "float", "bool", "string", "true", "false", + "null", "void", "iterable"}; +const int kReservedNamesSize = 73; + +bool is_reserved_name(const char* name) { + void** value; + return (php_proto_zend_hash_find(reserved_names, name, strlen(name), + (void**)&value) == SUCCESS); +} + // ----------------------------------------------------------------------------- // Utilities. // ----------------------------------------------------------------------------- @@ -157,12 +188,21 @@ static void php_proto_hashtable_descriptor_release(zval* value) { #endif static PHP_RINIT_FUNCTION(protobuf) { + int i = 0; + ALLOC_HASHTABLE(upb_def_to_php_obj_map); zend_hash_init(upb_def_to_php_obj_map, 16, NULL, HASHTABLE_VALUE_DTOR, 0); ALLOC_HASHTABLE(ce_to_php_obj_map); zend_hash_init(ce_to_php_obj_map, 16, NULL, HASHTABLE_VALUE_DTOR, 0); + ALLOC_HASHTABLE(reserved_names); + zend_hash_init(reserved_names, 16, NULL, NULL, 0); + for (i = 0; i < kReservedNamesSize; i++) { + php_proto_zend_hash_update(reserved_names, kReservedNames[i], + strlen(kReservedNames[i])); + } + generated_pool = NULL; generated_pool_php = NULL; internal_generated_pool_php = NULL; @@ -177,6 +217,9 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) { zend_hash_destroy(ce_to_php_obj_map); FREE_HASHTABLE(ce_to_php_obj_map); + zend_hash_destroy(reserved_names); + FREE_HASHTABLE(reserved_names); + #if PHP_MAJOR_VERSION < 7 if (generated_pool_php != NULL) { zval_dtor(generated_pool_php); diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index b2838e56..010cb25f 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -77,12 +77,18 @@ #define php_proto_zend_hash_index_update_zval(ht, h, pData) \ zend_hash_index_update(ht, h, &(pData), sizeof(void*), NULL) +#define php_proto_zend_hash_update(ht, key, key_len) \ + zend_hash_update(ht, key, key_len, 0, 0, NULL) + #define php_proto_zend_hash_index_update_mem(ht, h, pData, nDataSize, pDest) \ zend_hash_index_update(ht, h, pData, nDataSize, pDest) #define php_proto_zend_hash_index_find_zval(ht, h, pDest) \ zend_hash_index_find(ht, h, pDest) +#define php_proto_zend_hash_find(ht, key, key_len, pDest) \ + zend_hash_find(ht, key, key_len, pDest) + #define php_proto_zend_hash_index_find_mem(ht, h, pDest) \ zend_hash_index_find(ht, h, pDest) @@ -234,6 +240,15 @@ static inline int php_proto_zend_hash_index_update_zval(HashTable* ht, ulong h, return result != NULL ? SUCCESS : FAILURE; } +static inline int php_proto_zend_hash_update(HashTable* ht, const char* key, + size_t key_len) { + void* result = NULL; + zval temp; + ZVAL_LONG(&temp, 0); + result = zend_hash_str_update(ht, key, key_len, &temp); + return result != NULL ? SUCCESS : FAILURE; +} + static inline int php_proto_zend_hash_index_update_mem(HashTable* ht, ulong h, void* pData, uint nDataSize, void** pDest) { @@ -250,6 +265,13 @@ static inline int php_proto_zend_hash_index_find_zval(const HashTable* ht, return result != NULL ? SUCCESS : FAILURE; } +static inline int php_proto_zend_hash_find(const HashTable* ht, const char* key, + size_t key_len, void** pDest) { + void* result = NULL; + result = zend_hash_str_find(ht, key, key_len); + return result != NULL ? SUCCESS : FAILURE; +} + static inline int php_proto_zend_hash_index_find_mem(const HashTable* ht, ulong h, void** pDest) { void* result = NULL; @@ -910,4 +932,7 @@ const zend_class_entry* field_type_class( .bucket.obj.object)) #endif +// Reserved name +bool is_reserved_name(const char* name); + #endif // __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__ -- cgit v1.2.3 From f46a01d0c13295eec279b9a17021b38d85b41205 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 12 Sep 2017 15:04:34 -0700 Subject: Exclude valid constant name from reserved name. --- Makefile.am | 2 + php/ext/google/protobuf/protobuf.h | 1 + php/tests/generated_class_test.php | 368 +++++++++++++++++---- php/tests/proto/test_reserved_enum_lower.proto | 148 ++++----- php/tests/proto/test_reserved_enum_upper.proto | 148 ++++----- .../proto/test_reserved_enum_value_lower.proto | 79 +++++ .../proto/test_reserved_enum_value_upper.proto | 79 +++++ src/google/protobuf/compiler/php/php_generator.cc | 37 ++- tests.sh | 28 +- 9 files changed, 652 insertions(+), 238 deletions(-) create mode 100644 php/tests/proto/test_reserved_enum_value_lower.proto create mode 100644 php/tests/proto/test_reserved_enum_value_upper.proto diff --git a/Makefile.am b/Makefile.am index f4d09fa0..33236189 100644 --- a/Makefile.am +++ b/Makefile.am @@ -688,6 +688,8 @@ php_EXTRA_DIST= \ php/tests/proto/test_prefix.proto \ php/tests/proto/test_reserved_enum_lower.proto \ php/tests/proto/test_reserved_enum_upper.proto \ + php/tests/proto/test_reserved_enum_value_lower.proto \ + php/tests/proto/test_reserved_enum_value_upper.proto \ php/tests/proto/test_reserved_message_lower.proto \ php/tests/proto/test_reserved_message_upper.proto \ php/tests/proto/test_service.proto \ diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 010cb25f..24bccb14 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -934,5 +934,6 @@ const zend_class_entry* field_type_class( // Reserved name bool is_reserved_name(const char* name); +bool is_valid_constant_name(const char* name); #endif // __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__ diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index c63318a9..53d18ee7 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -840,79 +840,301 @@ class GeneratedClassTest extends TestBase $m = new \Upper\PBVOID(); $m = new \Upper\PBITERABLE(); - $m = \Lower_enum\NotAllowed::PBabstract; - $m = \Lower_enum\NotAllowed::PBand; - $m = \Lower_enum\NotAllowed::PBarray; - $m = \Lower_enum\NotAllowed::PBas; - $m = \Lower_enum\NotAllowed::PBbreak; - $m = \Lower_enum\NotAllowed::PBcallable; - $m = \Lower_enum\NotAllowed::PBcase; - $m = \Lower_enum\NotAllowed::PBcatch; - $m = \Lower_enum\NotAllowed::PBclass; - $m = \Lower_enum\NotAllowed::PBclone; - $m = \Lower_enum\NotAllowed::PBconst; - $m = \Lower_enum\NotAllowed::PBcontinue; - $m = \Lower_enum\NotAllowed::PBdeclare; - $m = \Lower_enum\NotAllowed::PBdefault; - $m = \Lower_enum\NotAllowed::PBdie; - $m = \Lower_enum\NotAllowed::PBdo; - $m = \Lower_enum\NotAllowed::PBecho; - $m = \Lower_enum\NotAllowed::PBelse; - $m = \Lower_enum\NotAllowed::PBelseif; - $m = \Lower_enum\NotAllowed::PBempty; - $m = \Lower_enum\NotAllowed::PBenddeclare; - $m = \Lower_enum\NotAllowed::PBendfor; - $m = \Lower_enum\NotAllowed::PBendforeach; - $m = \Lower_enum\NotAllowed::PBendif; - $m = \Lower_enum\NotAllowed::PBendswitch; - $m = \Lower_enum\NotAllowed::PBendwhile; - $m = \Lower_enum\NotAllowed::PBeval; - $m = \Lower_enum\NotAllowed::PBexit; - $m = \Lower_enum\NotAllowed::PBextends; - $m = \Lower_enum\NotAllowed::PBfinal; - $m = \Lower_enum\NotAllowed::PBfor; - $m = \Lower_enum\NotAllowed::PBforeach; - $m = \Lower_enum\NotAllowed::PBfunction; - $m = \Lower_enum\NotAllowed::PBglobal; - $m = \Lower_enum\NotAllowed::PBgoto; - $m = \Lower_enum\NotAllowed::PBif; - $m = \Lower_enum\NotAllowed::PBimplements; - $m = \Lower_enum\NotAllowed::PBinclude; - $m = \Lower_enum\NotAllowed::PBinclude_once; - $m = \Lower_enum\NotAllowed::PBinstanceof; - $m = \Lower_enum\NotAllowed::PBinsteadof; - $m = \Lower_enum\NotAllowed::PBinterface; - $m = \Lower_enum\NotAllowed::PBisset; - $m = \Lower_enum\NotAllowed::PBlist; - $m = \Lower_enum\NotAllowed::PBnamespace; - $m = \Lower_enum\NotAllowed::PBnew; - $m = \Lower_enum\NotAllowed::PBor; - $m = \Lower_enum\NotAllowed::PBprint; - $m = \Lower_enum\NotAllowed::PBprivate; - $m = \Lower_enum\NotAllowed::PBprotected; - $m = \Lower_enum\NotAllowed::PBpublic; - $m = \Lower_enum\NotAllowed::PBrequire; - $m = \Lower_enum\NotAllowed::PBrequire_once; - $m = \Lower_enum\NotAllowed::PBreturn; - $m = \Lower_enum\NotAllowed::PBstatic; - $m = \Lower_enum\NotAllowed::PBswitch; - $m = \Lower_enum\NotAllowed::PBthrow; - $m = \Lower_enum\NotAllowed::PBtrait; - $m = \Lower_enum\NotAllowed::PBtry; - $m = \Lower_enum\NotAllowed::PBunset; - $m = \Lower_enum\NotAllowed::PBuse; - $m = \Lower_enum\NotAllowed::PBvar; - $m = \Lower_enum\NotAllowed::PBwhile; - $m = \Lower_enum\NotAllowed::PBxor; - $m = \Lower_enum\NotAllowed::PBint; - $m = \Lower_enum\NotAllowed::PBfloat; - $m = \Lower_enum\NotAllowed::PBbool; - $m = \Lower_enum\NotAllowed::PBstring; - $m = \Lower_enum\NotAllowed::PBtrue; - $m = \Lower_enum\NotAllowed::PBfalse; - $m = \Lower_enum\NotAllowed::PBnull; - $m = \Lower_enum\NotAllowed::PBvoid; - $m = \Lower_enum\NotAllowed::PBiterable; + $m = new \Lower_enum\PBabstract(); + $m = new \Lower_enum\PBand(); + $m = new \Lower_enum\PBarray(); + $m = new \Lower_enum\PBas(); + $m = new \Lower_enum\PBbreak(); + $m = new \Lower_enum\PBcallable(); + $m = new \Lower_enum\PBcase(); + $m = new \Lower_enum\PBcatch(); + $m = new \Lower_enum\PBclass(); + $m = new \Lower_enum\PBclone(); + $m = new \Lower_enum\PBconst(); + $m = new \Lower_enum\PBcontinue(); + $m = new \Lower_enum\PBdeclare(); + $m = new \Lower_enum\PBdefault(); + $m = new \Lower_enum\PBdie(); + $m = new \Lower_enum\PBdo(); + $m = new \Lower_enum\PBecho(); + $m = new \Lower_enum\PBelse(); + $m = new \Lower_enum\PBelseif(); + $m = new \Lower_enum\PBempty(); + $m = new \Lower_enum\PBenddeclare(); + $m = new \Lower_enum\PBendfor(); + $m = new \Lower_enum\PBendforeach(); + $m = new \Lower_enum\PBendif(); + $m = new \Lower_enum\PBendswitch(); + $m = new \Lower_enum\PBendwhile(); + $m = new \Lower_enum\PBeval(); + $m = new \Lower_enum\PBexit(); + $m = new \Lower_enum\PBextends(); + $m = new \Lower_enum\PBfinal(); + $m = new \Lower_enum\PBfor(); + $m = new \Lower_enum\PBforeach(); + $m = new \Lower_enum\PBfunction(); + $m = new \Lower_enum\PBglobal(); + $m = new \Lower_enum\PBgoto(); + $m = new \Lower_enum\PBif(); + $m = new \Lower_enum\PBimplements(); + $m = new \Lower_enum\PBinclude(); + $m = new \Lower_enum\PBinclude_once(); + $m = new \Lower_enum\PBinstanceof(); + $m = new \Lower_enum\PBinsteadof(); + $m = new \Lower_enum\PBinterface(); + $m = new \Lower_enum\PBisset(); + $m = new \Lower_enum\PBlist(); + $m = new \Lower_enum\PBnamespace(); + $m = new \Lower_enum\PBnew(); + $m = new \Lower_enum\PBor(); + $m = new \Lower_enum\PBprint(); + $m = new \Lower_enum\PBprivate(); + $m = new \Lower_enum\PBprotected(); + $m = new \Lower_enum\PBpublic(); + $m = new \Lower_enum\PBrequire(); + $m = new \Lower_enum\PBrequire_once(); + $m = new \Lower_enum\PBreturn(); + $m = new \Lower_enum\PBstatic(); + $m = new \Lower_enum\PBswitch(); + $m = new \Lower_enum\PBthrow(); + $m = new \Lower_enum\PBtrait(); + $m = new \Lower_enum\PBtry(); + $m = new \Lower_enum\PBunset(); + $m = new \Lower_enum\PBuse(); + $m = new \Lower_enum\PBvar(); + $m = new \Lower_enum\PBwhile(); + $m = new \Lower_enum\PBxor(); + $m = new \Lower_enum\PBint(); + $m = new \Lower_enum\PBfloat(); + $m = new \Lower_enum\PBbool(); + $m = new \Lower_enum\PBstring(); + $m = new \Lower_enum\PBtrue(); + $m = new \Lower_enum\PBfalse(); + $m = new \Lower_enum\PBnull(); + $m = new \Lower_enum\PBvoid(); + $m = new \Lower_enum\PBiterable(); + + $m = new \Upper_enum\PBABSTRACT(); + $m = new \Upper_enum\PBAND(); + $m = new \Upper_enum\PBARRAY(); + $m = new \Upper_enum\PBAS(); + $m = new \Upper_enum\PBBREAK(); + $m = new \Upper_enum\PBCALLABLE(); + $m = new \Upper_enum\PBCASE(); + $m = new \Upper_enum\PBCATCH(); + $m = new \Upper_enum\PBCLASS(); + $m = new \Upper_enum\PBCLONE(); + $m = new \Upper_enum\PBCONST(); + $m = new \Upper_enum\PBCONTINUE(); + $m = new \Upper_enum\PBDECLARE(); + $m = new \Upper_enum\PBDEFAULT(); + $m = new \Upper_enum\PBDIE(); + $m = new \Upper_enum\PBDO(); + $m = new \Upper_enum\PBECHO(); + $m = new \Upper_enum\PBELSE(); + $m = new \Upper_enum\PBELSEIF(); + $m = new \Upper_enum\PBEMPTY(); + $m = new \Upper_enum\PBENDDECLARE(); + $m = new \Upper_enum\PBENDFOR(); + $m = new \Upper_enum\PBENDFOREACH(); + $m = new \Upper_enum\PBENDIF(); + $m = new \Upper_enum\PBENDSWITCH(); + $m = new \Upper_enum\PBENDWHILE(); + $m = new \Upper_enum\PBEVAL(); + $m = new \Upper_enum\PBEXIT(); + $m = new \Upper_enum\PBEXTENDS(); + $m = new \Upper_enum\PBFINAL(); + $m = new \Upper_enum\PBFOR(); + $m = new \Upper_enum\PBFOREACH(); + $m = new \Upper_enum\PBFUNCTION(); + $m = new \Upper_enum\PBGLOBAL(); + $m = new \Upper_enum\PBGOTO(); + $m = new \Upper_enum\PBIF(); + $m = new \Upper_enum\PBIMPLEMENTS(); + $m = new \Upper_enum\PBINCLUDE(); + $m = new \Upper_enum\PBINCLUDE_ONCE(); + $m = new \Upper_enum\PBINSTANCEOF(); + $m = new \Upper_enum\PBINSTEADOF(); + $m = new \Upper_enum\PBINTERFACE(); + $m = new \Upper_enum\PBISSET(); + $m = new \Upper_enum\PBLIST(); + $m = new \Upper_enum\PBNAMESPACE(); + $m = new \Upper_enum\PBNEW(); + $m = new \Upper_enum\PBOR(); + $m = new \Upper_enum\PBPRINT(); + $m = new \Upper_enum\PBPRIVATE(); + $m = new \Upper_enum\PBPROTECTED(); + $m = new \Upper_enum\PBPUBLIC(); + $m = new \Upper_enum\PBREQUIRE(); + $m = new \Upper_enum\PBREQUIRE_ONCE(); + $m = new \Upper_enum\PBRETURN(); + $m = new \Upper_enum\PBSTATIC(); + $m = new \Upper_enum\PBSWITCH(); + $m = new \Upper_enum\PBTHROW(); + $m = new \Upper_enum\PBTRAIT(); + $m = new \Upper_enum\PBTRY(); + $m = new \Upper_enum\PBUNSET(); + $m = new \Upper_enum\PBUSE(); + $m = new \Upper_enum\PBVAR(); + $m = new \Upper_enum\PBWHILE(); + $m = new \Upper_enum\PBXOR(); + $m = new \Upper_enum\PBINT(); + $m = new \Upper_enum\PBFLOAT(); + $m = new \Upper_enum\PBBOOL(); + $m = new \Upper_enum\PBSTRING(); + $m = new \Upper_enum\PBTRUE(); + $m = new \Upper_enum\PBFALSE(); + $m = new \Upper_enum\PBNULL(); + $m = new \Upper_enum\PBVOID(); + $m = new \Upper_enum\PBITERABLE(); + + $m = \Lower_enum_value\NotAllowed::PBabstract; + $m = \Lower_enum_value\NotAllowed::PBand; + $m = \Lower_enum_value\NotAllowed::PBarray; + $m = \Lower_enum_value\NotAllowed::PBas; + $m = \Lower_enum_value\NotAllowed::PBbreak; + $m = \Lower_enum_value\NotAllowed::PBcallable; + $m = \Lower_enum_value\NotAllowed::PBcase; + $m = \Lower_enum_value\NotAllowed::PBcatch; + $m = \Lower_enum_value\NotAllowed::PBclass; + $m = \Lower_enum_value\NotAllowed::PBclone; + $m = \Lower_enum_value\NotAllowed::PBconst; + $m = \Lower_enum_value\NotAllowed::PBcontinue; + $m = \Lower_enum_value\NotAllowed::PBdeclare; + $m = \Lower_enum_value\NotAllowed::PBdefault; + $m = \Lower_enum_value\NotAllowed::PBdie; + $m = \Lower_enum_value\NotAllowed::PBdo; + $m = \Lower_enum_value\NotAllowed::PBecho; + $m = \Lower_enum_value\NotAllowed::PBelse; + $m = \Lower_enum_value\NotAllowed::PBelseif; + $m = \Lower_enum_value\NotAllowed::PBempty; + $m = \Lower_enum_value\NotAllowed::PBenddeclare; + $m = \Lower_enum_value\NotAllowed::PBendfor; + $m = \Lower_enum_value\NotAllowed::PBendforeach; + $m = \Lower_enum_value\NotAllowed::PBendif; + $m = \Lower_enum_value\NotAllowed::PBendswitch; + $m = \Lower_enum_value\NotAllowed::PBendwhile; + $m = \Lower_enum_value\NotAllowed::PBeval; + $m = \Lower_enum_value\NotAllowed::PBexit; + $m = \Lower_enum_value\NotAllowed::PBextends; + $m = \Lower_enum_value\NotAllowed::PBfinal; + $m = \Lower_enum_value\NotAllowed::PBfor; + $m = \Lower_enum_value\NotAllowed::PBforeach; + $m = \Lower_enum_value\NotAllowed::PBfunction; + $m = \Lower_enum_value\NotAllowed::PBglobal; + $m = \Lower_enum_value\NotAllowed::PBgoto; + $m = \Lower_enum_value\NotAllowed::PBif; + $m = \Lower_enum_value\NotAllowed::PBimplements; + $m = \Lower_enum_value\NotAllowed::PBinclude; + $m = \Lower_enum_value\NotAllowed::PBinclude_once; + $m = \Lower_enum_value\NotAllowed::PBinstanceof; + $m = \Lower_enum_value\NotAllowed::PBinsteadof; + $m = \Lower_enum_value\NotAllowed::PBinterface; + $m = \Lower_enum_value\NotAllowed::PBisset; + $m = \Lower_enum_value\NotAllowed::PBlist; + $m = \Lower_enum_value\NotAllowed::PBnamespace; + $m = \Lower_enum_value\NotAllowed::PBnew; + $m = \Lower_enum_value\NotAllowed::PBor; + $m = \Lower_enum_value\NotAllowed::PBprint; + $m = \Lower_enum_value\NotAllowed::PBprivate; + $m = \Lower_enum_value\NotAllowed::PBprotected; + $m = \Lower_enum_value\NotAllowed::PBpublic; + $m = \Lower_enum_value\NotAllowed::PBrequire; + $m = \Lower_enum_value\NotAllowed::PBrequire_once; + $m = \Lower_enum_value\NotAllowed::PBreturn; + $m = \Lower_enum_value\NotAllowed::PBstatic; + $m = \Lower_enum_value\NotAllowed::PBswitch; + $m = \Lower_enum_value\NotAllowed::PBthrow; + $m = \Lower_enum_value\NotAllowed::PBtrait; + $m = \Lower_enum_value\NotAllowed::PBtry; + $m = \Lower_enum_value\NotAllowed::PBunset; + $m = \Lower_enum_value\NotAllowed::PBuse; + $m = \Lower_enum_value\NotAllowed::PBvar; + $m = \Lower_enum_value\NotAllowed::PBwhile; + $m = \Lower_enum_value\NotAllowed::PBxor; + $m = \Lower_enum_value\NotAllowed::int; + $m = \Lower_enum_value\NotAllowed::float; + $m = \Lower_enum_value\NotAllowed::bool; + $m = \Lower_enum_value\NotAllowed::string; + $m = \Lower_enum_value\NotAllowed::true; + $m = \Lower_enum_value\NotAllowed::false; + $m = \Lower_enum_value\NotAllowed::null; + $m = \Lower_enum_value\NotAllowed::void; + $m = \Lower_enum_value\NotAllowed::iterable; + + $m = \Upper_enum_value\NotAllowed::PBABSTRACT; + $m = \Upper_enum_value\NotAllowed::PBAND; + $m = \Upper_enum_value\NotAllowed::PBARRAY; + $m = \Upper_enum_value\NotAllowed::PBAS; + $m = \Upper_enum_value\NotAllowed::PBBREAK; + $m = \Upper_enum_value\NotAllowed::PBCALLABLE; + $m = \Upper_enum_value\NotAllowed::PBCASE; + $m = \Upper_enum_value\NotAllowed::PBCATCH; + $m = \Upper_enum_value\NotAllowed::PBCLASS; + $m = \Upper_enum_value\NotAllowed::PBCLONE; + $m = \Upper_enum_value\NotAllowed::PBCONST; + $m = \Upper_enum_value\NotAllowed::PBCONTINUE; + $m = \Upper_enum_value\NotAllowed::PBDECLARE; + $m = \Upper_enum_value\NotAllowed::PBDEFAULT; + $m = \Upper_enum_value\NotAllowed::PBDIE; + $m = \Upper_enum_value\NotAllowed::PBDO; + $m = \Upper_enum_value\NotAllowed::PBECHO; + $m = \Upper_enum_value\NotAllowed::PBELSE; + $m = \Upper_enum_value\NotAllowed::PBELSEIF; + $m = \Upper_enum_value\NotAllowed::PBEMPTY; + $m = \Upper_enum_value\NotAllowed::PBENDDECLARE; + $m = \Upper_enum_value\NotAllowed::PBENDFOR; + $m = \Upper_enum_value\NotAllowed::PBENDFOREACH; + $m = \Upper_enum_value\NotAllowed::PBENDIF; + $m = \Upper_enum_value\NotAllowed::PBENDSWITCH; + $m = \Upper_enum_value\NotAllowed::PBENDWHILE; + $m = \Upper_enum_value\NotAllowed::PBEVAL; + $m = \Upper_enum_value\NotAllowed::PBEXIT; + $m = \Upper_enum_value\NotAllowed::PBEXTENDS; + $m = \Upper_enum_value\NotAllowed::PBFINAL; + $m = \Upper_enum_value\NotAllowed::PBFOR; + $m = \Upper_enum_value\NotAllowed::PBFOREACH; + $m = \Upper_enum_value\NotAllowed::PBFUNCTION; + $m = \Upper_enum_value\NotAllowed::PBGLOBAL; + $m = \Upper_enum_value\NotAllowed::PBGOTO; + $m = \Upper_enum_value\NotAllowed::PBIF; + $m = \Upper_enum_value\NotAllowed::PBIMPLEMENTS; + $m = \Upper_enum_value\NotAllowed::PBINCLUDE; + $m = \Upper_enum_value\NotAllowed::PBINCLUDE_ONCE; + $m = \Upper_enum_value\NotAllowed::PBINSTANCEOF; + $m = \Upper_enum_value\NotAllowed::PBINSTEADOF; + $m = \Upper_enum_value\NotAllowed::PBINTERFACE; + $m = \Upper_enum_value\NotAllowed::PBISSET; + $m = \Upper_enum_value\NotAllowed::PBLIST; + $m = \Upper_enum_value\NotAllowed::PBNAMESPACE; + $m = \Upper_enum_value\NotAllowed::PBNEW; + $m = \Upper_enum_value\NotAllowed::PBOR; + $m = \Upper_enum_value\NotAllowed::PBPRINT; + $m = \Upper_enum_value\NotAllowed::PBPRIVATE; + $m = \Upper_enum_value\NotAllowed::PBPROTECTED; + $m = \Upper_enum_value\NotAllowed::PBPUBLIC; + $m = \Upper_enum_value\NotAllowed::PBREQUIRE; + $m = \Upper_enum_value\NotAllowed::PBREQUIRE_ONCE; + $m = \Upper_enum_value\NotAllowed::PBRETURN; + $m = \Upper_enum_value\NotAllowed::PBSTATIC; + $m = \Upper_enum_value\NotAllowed::PBSWITCH; + $m = \Upper_enum_value\NotAllowed::PBTHROW; + $m = \Upper_enum_value\NotAllowed::PBTRAIT; + $m = \Upper_enum_value\NotAllowed::PBTRY; + $m = \Upper_enum_value\NotAllowed::PBUNSET; + $m = \Upper_enum_value\NotAllowed::PBUSE; + $m = \Upper_enum_value\NotAllowed::PBVAR; + $m = \Upper_enum_value\NotAllowed::PBWHILE; + $m = \Upper_enum_value\NotAllowed::PBXOR; + $m = \Upper_enum_value\NotAllowed::INT; + $m = \Upper_enum_value\NotAllowed::FLOAT; + $m = \Upper_enum_value\NotAllowed::BOOL; + $m = \Upper_enum_value\NotAllowed::STRING; + $m = \Upper_enum_value\NotAllowed::TRUE; + $m = \Upper_enum_value\NotAllowed::FALSE; + $m = \Upper_enum_value\NotAllowed::NULL; + $m = \Upper_enum_value\NotAllowed::VOID; + $m = \Upper_enum_value\NotAllowed::ITERABLE; } ######################################################### diff --git a/php/tests/proto/test_reserved_enum_lower.proto b/php/tests/proto/test_reserved_enum_lower.proto index e2144c0c..d2daeaff 100644 --- a/php/tests/proto/test_reserved_enum_lower.proto +++ b/php/tests/proto/test_reserved_enum_lower.proto @@ -2,78 +2,76 @@ syntax = "proto3"; package lower_enum; -enum NotAllowed { - abstract = 0; - and = 1; - array = 2; - as = 3; - break = 4; - callable = 5; - case = 6; - catch = 7; - class = 8; - clone = 9; - const = 10; - continue = 11; - declare = 12; - default = 13; - die = 14; - do = 15; - echo = 16; - else = 17; - elseif = 18; - empty = 19; - enddeclare = 20; - endfor = 21; - endforeach = 22; - endif = 23; - endswitch = 24; - endwhile = 25; - eval = 26; - exit = 27; - extends = 28; - final = 29; - for = 30; - foreach = 31; - function = 32; - global = 33; - goto = 34; - if = 35; - implements = 36; - include = 37; - include_once = 38; - instanceof = 39; - insteadof = 40; - interface = 41; - isset = 42; - list = 43; - namespace = 44; - new = 45; - or = 46; - print = 47; - private = 48; - protected = 49; - public = 50; - require = 51; - require_once = 52; - return = 53; - static = 54; - switch = 55; - throw = 56; - trait = 57; - try = 58; - unset = 59; - use = 60; - var = 61; - while = 62; - xor = 63; - int = 64; - float = 65; - bool = 66; - string = 67; - true = 68; - false = 69; - null = 70; - void = 71; - iterable = 72; -} +enum abstract { ZERO1 = 0; } +enum and { ZERO2 = 0; } +enum array { ZERO3 = 0; } +enum as { ZERO4 = 0; } +enum break { ZERO5 = 0; } +enum callable { ZERO6 = 0; } +enum case { ZERO7 = 0; } +enum catch { ZERO8 = 0; } +enum class { ZERO9 = 0; } +enum clone { ZERO10 = 0; } +enum const { ZERO11 = 0; } +enum continue { ZERO12 = 0; } +enum declare { ZERO13 = 0; } +enum default { ZERO14 = 0; } +enum die { ZERO15 = 0; } +enum do { ZERO16 = 0; } +enum echo { ZERO17 = 0; } +enum else { ZERO18 = 0; } +enum elseif { ZERO19 = 0; } +enum empty { ZERO20 = 0; } +enum enddeclare { ZERO21 = 0; } +enum endfor { ZERO22 = 0; } +enum endforeach { ZERO23 = 0; } +enum endif { ZERO24 = 0; } +enum endswitch { ZERO25 = 0; } +enum endwhile { ZERO26 = 0; } +enum eval { ZERO27 = 0; } +enum exit { ZERO28 = 0; } +enum extends { ZERO29 = 0; } +enum final { ZERO30 = 0; } +enum for { ZERO31 = 0; } +enum foreach { ZERO32 = 0; } +enum function { ZERO33 = 0; } +enum global { ZERO34 = 0; } +enum goto { ZERO35 = 0; } +enum if { ZERO36 = 0; } +enum implements { ZERO37 = 0; } +enum include { ZERO38 = 0; } +enum include_once { ZERO39 = 0; } +enum instanceof { ZERO40 = 0; } +enum insteadof { ZERO41 = 0; } +enum interface { ZERO42 = 0; } +enum isset { ZERO43 = 0; } +enum list { ZERO44 = 0; } +enum namespace { ZERO45 = 0; } +enum new { ZERO46 = 0; } +enum or { ZERO47 = 0; } +enum print { ZERO48 = 0; } +enum private { ZERO49 = 0; } +enum protected { ZERO50 = 0; } +enum public { ZERO51 = 0; } +enum require { ZERO52 = 0; } +enum require_once { ZERO53 = 0; } +enum return { ZERO54 = 0; } +enum static { ZERO55 = 0; } +enum switch { ZERO56 = 0; } +enum throw { ZERO57 = 0; } +enum trait { ZERO58 = 0; } +enum try { ZERO59 = 0; } +enum unset { ZERO60 = 0; } +enum use { ZERO61 = 0; } +enum var { ZERO62 = 0; } +enum while { ZERO63 = 0; } +enum xor { ZERO64 = 0; } +enum int { ZERO65 = 0; } +enum float { ZERO66 = 0; } +enum bool { ZERO67 = 0; } +enum string { ZERO68 = 0; } +enum true { ZERO69 = 0; } +enum false { ZERO70 = 0; } +enum null { ZERO71 = 0; } +enum void { ZERO72 = 0; } +enum iterable { ZERO73 = 0; } diff --git a/php/tests/proto/test_reserved_enum_upper.proto b/php/tests/proto/test_reserved_enum_upper.proto index a4cc1f4b..a396fea3 100644 --- a/php/tests/proto/test_reserved_enum_upper.proto +++ b/php/tests/proto/test_reserved_enum_upper.proto @@ -2,78 +2,76 @@ syntax = "proto3"; package upper_enum; -enum NotAllowed { - ABSTRACT = 0; - AND = 1; - ARRAY = 2; - AS = 3; - BREAK = 4; - CALLABLE = 5; - CASE = 6; - CATCH = 7; - CLASS = 8; - CLONE = 9; - CONST = 10; - CONTINUE = 11; - DECLARE = 12; - DEFAULT = 13; - DIE = 14; - DO = 15; - ECHO = 16; - ELSE = 17; - ELSEIF = 18; - EMPTY = 19; - ENDDECLARE = 20; - ENDFOR = 21; - ENDFOREACH = 22; - ENDIF = 23; - ENDSWITCH = 24; - ENDWHILE = 25; - EVAL = 26; - EXIT = 27; - EXTENDS = 28; - FINAL = 29; - FOR = 30; - FOREACH = 31; - FUNCTION = 32; - GLOBAL = 33; - GOTO = 34; - IF = 35; - IMPLEMENTS = 36; - INCLUDE = 37; - INCLUDE_ONCE = 38; - INSTANCEOF = 39; - INSTEADOF = 40; - INTERFACE = 41; - ISSET = 42; - LIST = 43; - NAMESPACE = 44; - NEW = 45; - OR = 46; - PRINT = 47; - PRIVATE = 48; - PROTECTED = 49; - PUBLIC = 50; - REQUIRE = 51; - REQUIRE_ONCE = 52; - RETURN = 53; - STATIC = 54; - SWITCH = 55; - THROW = 56; - TRAIT = 57; - TRY = 58; - UNSET = 59; - USE = 60; - VAR = 61; - WHILE = 62; - XOR = 63; - INT = 64; - FLOAT = 65; - BOOL = 66; - STRING = 67; - TRUE = 68; - FALSE = 69; - NULL = 70; - VOID = 71; - ITERABLE = 72; -} +enum ABSTRACT { ZERO1 = 0; } +enum AND { ZERO2 = 0; } +enum ARRAY { ZERO3 = 0; } +enum AS { ZERO4 = 0; } +enum BREAK { ZERO5 = 0; } +enum CALLABLE { ZERO6 = 0; } +enum CASE { ZERO7 = 0; } +enum CATCH { ZERO8 = 0; } +enum CLASS { ZERO9 = 0; } +enum CLONE { ZERO10 = 0; } +enum CONST { ZERO11 = 0; } +enum CONTINUE { ZERO12 = 0; } +enum DECLARE { ZERO13 = 0; } +enum DEFAULT { ZERO14 = 0; } +enum DIE { ZERO15 = 0; } +enum DO { ZERO16 = 0; } +enum ECHO { ZERO17 = 0; } +enum ELSE { ZERO18 = 0; } +enum ELSEIF { ZERO19 = 0; } +enum EMPTY { ZERO20 = 0; } +enum ENDDECLARE { ZERO21 = 0; } +enum ENDFOR { ZERO22 = 0; } +enum ENDFOREACH { ZERO23 = 0; } +enum ENDIF { ZERO24 = 0; } +enum ENDSWITCH { ZERO25 = 0; } +enum ENDWHILE { ZERO26 = 0; } +enum EVAL { ZERO27 = 0; } +enum EXIT { ZERO28 = 0; } +enum EXTENDS { ZERO29 = 0; } +enum FINAL { ZERO30 = 0; } +enum FOR { ZERO31 = 0; } +enum FOREACH { ZERO32 = 0; } +enum FUNCTION { ZERO33 = 0; } +enum GLOBAL { ZERO34 = 0; } +enum GOTO { ZERO35 = 0; } +enum IF { ZERO36 = 0; } +enum IMPLEMENTS { ZERO37 = 0; } +enum INCLUDE { ZERO38 = 0; } +enum INCLUDE_ONCE { ZERO39 = 0; } +enum INSTANCEOF { ZERO40 = 0; } +enum INSTEADOF { ZERO41 = 0; } +enum INTERFACE { ZERO42 = 0; } +enum ISSET { ZERO43 = 0; } +enum LIST { ZERO44 = 0; } +enum NAMESPACE { ZERO45 = 0; } +enum NEW { ZERO46 = 0; } +enum OR { ZERO47 = 0; } +enum PRINT { ZERO48 = 0; } +enum PRIVATE { ZERO49 = 0; } +enum PROTECTED { ZERO50 = 0; } +enum PUBLIC { ZERO51 = 0; } +enum REQUIRE { ZERO52 = 0; } +enum REQUIRE_ONCE { ZERO53 = 0; } +enum RETURN { ZERO54 = 0; } +enum STATIC { ZERO55 = 0; } +enum SWITCH { ZERO56 = 0; } +enum THROW { ZERO57 = 0; } +enum TRAIT { ZERO58 = 0; } +enum TRY { ZERO59 = 0; } +enum UNSET { ZERO60 = 0; } +enum USE { ZERO61 = 0; } +enum VAR { ZERO62 = 0; } +enum WHILE { ZERO63 = 0; } +enum XOR { ZERO64 = 0; } +enum INT { ZERO65 = 0; } +enum FLOAT { ZERO66 = 0; } +enum BOOL { ZERO67 = 0; } +enum STRING { ZERO68 = 0; } +enum TRUE { ZERO69 = 0; } +enum FALSE { ZERO70 = 0; } +enum NULL { ZERO71 = 0; } +enum VOID { ZERO72 = 0; } +enum ITERABLE { ZERO73 = 0; } diff --git a/php/tests/proto/test_reserved_enum_value_lower.proto b/php/tests/proto/test_reserved_enum_value_lower.proto new file mode 100644 index 00000000..96da319e --- /dev/null +++ b/php/tests/proto/test_reserved_enum_value_lower.proto @@ -0,0 +1,79 @@ +syntax = "proto3"; + +package lower_enum_value; + +enum NotAllowed { + abstract = 0; + and = 1; + array = 2; + as = 3; + break = 4; + callable = 5; + case = 6; + catch = 7; + class = 8; + clone = 9; + const = 10; + continue = 11; + declare = 12; + default = 13; + die = 14; + do = 15; + echo = 16; + else = 17; + elseif = 18; + empty = 19; + enddeclare = 20; + endfor = 21; + endforeach = 22; + endif = 23; + endswitch = 24; + endwhile = 25; + eval = 26; + exit = 27; + extends = 28; + final = 29; + for = 30; + foreach = 31; + function = 32; + global = 33; + goto = 34; + if = 35; + implements = 36; + include = 37; + include_once = 38; + instanceof = 39; + insteadof = 40; + interface = 41; + isset = 42; + list = 43; + namespace = 44; + new = 45; + or = 46; + print = 47; + private = 48; + protected = 49; + public = 50; + require = 51; + require_once = 52; + return = 53; + static = 54; + switch = 55; + throw = 56; + trait = 57; + try = 58; + unset = 59; + use = 60; + var = 61; + while = 62; + xor = 63; + int = 64; + float = 65; + bool = 66; + string = 67; + true = 68; + false = 69; + null = 70; + void = 71; + iterable = 72; +} diff --git a/php/tests/proto/test_reserved_enum_value_upper.proto b/php/tests/proto/test_reserved_enum_value_upper.proto new file mode 100644 index 00000000..b026a858 --- /dev/null +++ b/php/tests/proto/test_reserved_enum_value_upper.proto @@ -0,0 +1,79 @@ +syntax = "proto3"; + +package upper_enum_value; + +enum NotAllowed { + ABSTRACT = 0; + AND = 1; + ARRAY = 2; + AS = 3; + BREAK = 4; + CALLABLE = 5; + CASE = 6; + CATCH = 7; + CLASS = 8; + CLONE = 9; + CONST = 10; + CONTINUE = 11; + DECLARE = 12; + DEFAULT = 13; + DIE = 14; + DO = 15; + ECHO = 16; + ELSE = 17; + ELSEIF = 18; + EMPTY = 19; + ENDDECLARE = 20; + ENDFOR = 21; + ENDFOREACH = 22; + ENDIF = 23; + ENDSWITCH = 24; + ENDWHILE = 25; + EVAL = 26; + EXIT = 27; + EXTENDS = 28; + FINAL = 29; + FOR = 30; + FOREACH = 31; + FUNCTION = 32; + GLOBAL = 33; + GOTO = 34; + IF = 35; + IMPLEMENTS = 36; + INCLUDE = 37; + INCLUDE_ONCE = 38; + INSTANCEOF = 39; + INSTEADOF = 40; + INTERFACE = 41; + ISSET = 42; + LIST = 43; + NAMESPACE = 44; + NEW = 45; + OR = 46; + PRINT = 47; + PRIVATE = 48; + PROTECTED = 49; + PUBLIC = 50; + REQUIRE = 51; + REQUIRE_ONCE = 52; + RETURN = 53; + STATIC = 54; + SWITCH = 55; + THROW = 56; + TRAIT = 57; + TRY = 58; + UNSET = 59; + USE = 60; + VAR = 61; + WHILE = 62; + XOR = 63; + INT = 64; + FLOAT = 65; + BOOL = 66; + STRING = 67; + TRUE = 68; + FALSE = 69; + NULL = 70; + VOID = 71; + ITERABLE = 72; +} diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index fe781df2..b73062de 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -65,7 +65,12 @@ const char* const kReservedNames[] = { "use", "var", "while", "xor", "int", "float", "bool", "string", "true", "false", "null", "void", "iterable"}; +const char* const kValidConstantNames[] = { + "int", "float", "bool", "string", "true", + "false", "null", "void", "iterable", +}; const int kReservedNamesSize = 73; +const int kValidConstantNamesSize = 9; const int kFieldSetter = 1; const int kFieldGetter = 2; const int kFieldProperty = 3; @@ -161,6 +166,34 @@ std::string ClassNamePrefix(const string& classname, return ""; } +std::string ClassNamePrefix(const string& classname, + const EnumValueDescriptor* desc) { + bool is_reserved = false; + + string lower = classname; + transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + + for (int i = 0; i < kReservedNamesSize; i++) { + if (lower == kReservedNames[i]) { + is_reserved = true; + break; + } + } + + for (int i = 0; i < kValidConstantNamesSize; i++) { + if (lower == kValidConstantNames[i]) { + is_reserved = false; + break; + } + } + + if (is_reserved) { + return "PB"; + } + + return ""; +} + template std::string NamespacedName(const string& classname, const DescriptorType* desc, bool is_descriptor) { @@ -696,7 +729,7 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) { const EnumValueDescriptor* value = en->value(i); printer->Print( "->value(\"^name^\", ^number^)\n", - "name", ClassNamePrefix(value->name(), en) + value->name(), + "name", ClassNamePrefix(value->name(), value) + value->name(), "number", IntToString(value->number())); } printer->Print("->finalizeToPool();\n\n"); @@ -999,7 +1032,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, const EnumValueDescriptor* value = en->value(i); GenerateEnumValueDocComment(&printer, value); printer.Print("const ^name^ = ^number^;\n", - "name", ClassNamePrefix(value->name(), en) + value->name(), + "name", ClassNamePrefix(value->name(), value) + value->name(), "number", IntToString(value->number())); } diff --git a/tests.sh b/tests.sh index a29ba647..d74acb12 100755 --- a/tests.sh +++ b/tests.sh @@ -346,19 +346,21 @@ generate_php_test_proto() { # Generate test file rm -rf generated mkdir generated - ../../src/protoc --php_out=generated \ - proto/test.proto \ - proto/test_include.proto \ - proto/test_no_namespace.proto \ - proto/test_prefix.proto \ - proto/test_php_namespace.proto \ - proto/test_empty_php_namespace.proto \ - proto/test_reserved_enum_lower.proto \ - proto/test_reserved_enum_upper.proto \ - proto/test_reserved_message_lower.proto \ - proto/test_reserved_message_upper.proto \ - proto/test_service.proto \ - proto/test_service_namespace.proto \ + ../../src/protoc --php_out=generated \ + proto/test.proto \ + proto/test_include.proto \ + proto/test_no_namespace.proto \ + proto/test_prefix.proto \ + proto/test_php_namespace.proto \ + proto/test_empty_php_namespace.proto \ + proto/test_reserved_enum_lower.proto \ + proto/test_reserved_enum_upper.proto \ + proto/test_reserved_enum_value_lower.proto \ + proto/test_reserved_enum_value_upper.proto \ + proto/test_reserved_message_lower.proto \ + proto/test_reserved_message_upper.proto \ + proto/test_service.proto \ + proto/test_service_namespace.proto \ proto/test_descriptors.proto pushd ../../src ./protoc --php_out=../php/tests/generated google/protobuf/empty.proto -- cgit v1.2.3 From 2bd55a9fbcd2815b3332bf309bc20f59eef0b36b Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 12 Sep 2017 15:09:47 -0700 Subject: Fix js conformance tests. (#3604) * Fix js conformance tests. * Remove old incorrect compatibility tests --- conformance/failure_list_js.txt | 19 ------------ js/binary/decoder.js | 27 ++++++++--------- js/binary/decoder_test.js | 19 +----------- .../v3.0.0/binary/decoder_test.js | 19 +----------- .../v3.1.0/binary/decoder_test.js | 19 +----------- src/google/protobuf/compiler/js/js_generator.cc | 34 ++++++++++++++++++---- 6 files changed, 44 insertions(+), 93 deletions(-) diff --git a/conformance/failure_list_js.txt b/conformance/failure_list_js.txt index eb20f659..e69de29b 100644 --- a/conformance/failure_list_js.txt +++ b/conformance/failure_list_js.txt @@ -1,19 +0,0 @@ -Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput -Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput -Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput -Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput -Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput -Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput -Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput diff --git a/js/binary/decoder.js b/js/binary/decoder.js index 6db28e7c..a38a5011 100644 --- a/js/binary/decoder.js +++ b/js/binary/decoder.js @@ -582,27 +582,24 @@ jspb.BinaryDecoder.prototype.readUnsignedVarint32 = function() { x |= (temp & 0x0F) << 28; if (temp < 128) { // We're reading the high bits of an unsigned varint. The byte we just read - // also contains bits 33 through 35, which we're going to discard. Those - // bits _must_ be zero, or the encoding is invalid. - goog.asserts.assert((temp & 0xF0) == 0); + // also contains bits 33 through 35, which we're going to discard. this.cursor_ += 5; goog.asserts.assert(this.cursor_ <= this.end_); return x >>> 0; } - // If we get here, we're reading the sign extension of a negative 32-bit int. - // We can skip these bytes, as we know in advance that they have to be all - // 1's if the varint is correctly encoded. Since we also know the value is - // negative, we don't have to coerce it to unsigned before we return it. - - goog.asserts.assert((temp & 0xF0) == 0xF0); - goog.asserts.assert(bytes[this.cursor_ + 5] == 0xFF); - goog.asserts.assert(bytes[this.cursor_ + 6] == 0xFF); - goog.asserts.assert(bytes[this.cursor_ + 7] == 0xFF); - goog.asserts.assert(bytes[this.cursor_ + 8] == 0xFF); - goog.asserts.assert(bytes[this.cursor_ + 9] == 0x01); + // If we get here, we need to truncate coming bytes. However we need to make + // sure cursor place is correct. + var i = 5; + do { + goog.asserts.assert(i < 10); + if (bytes[this.cursor_ + i] < 128) { + break; + } + i++; + } while (1); - this.cursor_ += 10; + this.cursor_ += i + 1; goog.asserts.assert(this.cursor_ <= this.end_); return x; }; diff --git a/js/binary/decoder_test.js b/js/binary/decoder_test.js index d0139e29..b19e1d1b 100644 --- a/js/binary/decoder_test.js +++ b/js/binary/decoder_test.js @@ -270,24 +270,7 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - - // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 - // should trigger assertions. - decoder.setBlock([255, 255, 255, 255, 0x1F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x2F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x4F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - // Negative 32-bit varints encoded with non-1 bits in the high dword should - // trigger assertions. - decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); + decoder.reset(); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/js/compatibility_tests/v3.0.0/binary/decoder_test.js b/js/compatibility_tests/v3.0.0/binary/decoder_test.js index ac312648..fce2fe18 100644 --- a/js/compatibility_tests/v3.0.0/binary/decoder_test.js +++ b/js/compatibility_tests/v3.0.0/binary/decoder_test.js @@ -228,24 +228,7 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - - // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 - // should trigger assertions. - decoder.setBlock([255, 255, 255, 255, 0x1F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x2F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x4F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - // Negative 32-bit varints encoded with non-1 bits in the high dword should - // trigger assertions. - decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); + decoder.reset(); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/js/compatibility_tests/v3.1.0/binary/decoder_test.js b/js/compatibility_tests/v3.1.0/binary/decoder_test.js index ac312648..fce2fe18 100644 --- a/js/compatibility_tests/v3.1.0/binary/decoder_test.js +++ b/js/compatibility_tests/v3.1.0/binary/decoder_test.js @@ -228,24 +228,7 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - - // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 - // should trigger assertions. - decoder.setBlock([255, 255, 255, 255, 0x1F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x2F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x4F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - // Negative 32-bit varints encoded with non-1 bits in the high dword should - // trigger assertions. - decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); + decoder.reset(); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 73d32762..a25de76c 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2876,6 +2876,29 @@ void Generator::GenerateClassDeserializeBinaryField( "Group" : "Message", "grpfield", (field->type() == FieldDescriptor::TYPE_GROUP) ? (SimpleItoa(field->number()) + ", ") : ""); + } else if (field->is_repeated() && + field->cpp_type() != FieldDescriptor::CPPTYPE_STRING) { + printer->Print( + " if (reader.getWireType() == 2) {\n" + " var value = /** @type {$fieldtype_packed$} */ " + "(reader.readPacked$reader$());\n" + " msg.set$list_name$(value);\n" + " } else {\n" + " var value = /** @type {$fieldtype$} */ " + "(reader.read$reader$());\n" + " msg.add$name$(value);\n" + " }\n", + "fieldtype_packed", JSFieldTypeAnnotation(options, field, false, true, + /* singular_if_not_packed */ false, + BYTES_U8), + "fieldtype", JSFieldTypeAnnotation(options, field, false, true, + /* singular_if_not_packed */ true, + BYTES_U8), + "reader", JSBinaryReaderMethodType(field), + "list_name", JSGetterName(options, field), + "name", JSGetterName(options, field, + BYTES_DEFAULT, /* drop_list = */ true) + ); } else { printer->Print( " var value = /** @type {$fieldtype$} */ " @@ -2887,14 +2910,15 @@ void Generator::GenerateClassDeserializeBinaryField( JSBinaryReadWriteMethodName(field, /* is_writer = */ false)); } - if (field->is_repeated() && !field->is_packed()) { + if (field->is_repeated() && + (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE || + field->cpp_type() == FieldDescriptor::CPPTYPE_STRING)) { printer->Print( " msg.add$name$(value);\n", "name", JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true)); - } else { - // Singular fields, and packed repeated fields, receive a |value| either - // as the field's value or as the array of all the field's values; set - // this as the field's value directly. + } else if (!field->is_repeated()) { + // Singular fields, receive a |value| as the field's value ; set this as + // the field's value directly. printer->Print( " msg.set$name$(value);\n", "name", JSGetterName(options, field)); -- cgit v1.2.3 From a425dd97f210cd4bab979d7aad980655a7409bfe Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 13 Sep 2017 10:45:37 -0700 Subject: Rename ClassNamePrefix to ConstantNamePrefix --- src/google/protobuf/compiler/php/php_generator.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index b73062de..e4364ac2 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -166,8 +166,7 @@ std::string ClassNamePrefix(const string& classname, return ""; } -std::string ClassNamePrefix(const string& classname, - const EnumValueDescriptor* desc) { +std::string ConstantNamePrefix(const string& classname) { bool is_reserved = false; string lower = classname; @@ -729,7 +728,7 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) { const EnumValueDescriptor* value = en->value(i); printer->Print( "->value(\"^name^\", ^number^)\n", - "name", ClassNamePrefix(value->name(), value) + value->name(), + "name", ConstantNamePrefix(value->name()) + value->name(), "number", IntToString(value->number())); } printer->Print("->finalizeToPool();\n\n"); @@ -1032,7 +1031,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, const EnumValueDescriptor* value = en->value(i); GenerateEnumValueDocComment(&printer, value); printer.Print("const ^name^ = ^number^;\n", - "name", ClassNamePrefix(value->name(), value) + value->name(), + "name", ConstantNamePrefix(value->name()) + value->name(), "number", IntToString(value->number())); } -- cgit v1.2.3 From 8741da3e45876f8c55ca062a08726f542f646423 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 13 Sep 2017 14:23:59 -0700 Subject: Revert "Fix js conformance tests. (#3604)" (#3633) This reverts commit 2bd55a9fbcd2815b3332bf309bc20f59eef0b36b. --- conformance/failure_list_js.txt | 19 ++++++++++++ js/binary/decoder.js | 27 +++++++++-------- js/binary/decoder_test.js | 19 +++++++++++- .../v3.0.0/binary/decoder_test.js | 19 +++++++++++- .../v3.1.0/binary/decoder_test.js | 19 +++++++++++- src/google/protobuf/compiler/js/js_generator.cc | 34 ++++------------------ 6 files changed, 93 insertions(+), 44 deletions(-) diff --git a/conformance/failure_list_js.txt b/conformance/failure_list_js.txt index e69de29b..eb20f659 100644 --- a/conformance/failure_list_js.txt +++ b/conformance/failure_list_js.txt @@ -0,0 +1,19 @@ +Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput +Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput +Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput +Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput diff --git a/js/binary/decoder.js b/js/binary/decoder.js index a38a5011..6db28e7c 100644 --- a/js/binary/decoder.js +++ b/js/binary/decoder.js @@ -582,24 +582,27 @@ jspb.BinaryDecoder.prototype.readUnsignedVarint32 = function() { x |= (temp & 0x0F) << 28; if (temp < 128) { // We're reading the high bits of an unsigned varint. The byte we just read - // also contains bits 33 through 35, which we're going to discard. + // also contains bits 33 through 35, which we're going to discard. Those + // bits _must_ be zero, or the encoding is invalid. + goog.asserts.assert((temp & 0xF0) == 0); this.cursor_ += 5; goog.asserts.assert(this.cursor_ <= this.end_); return x >>> 0; } - // If we get here, we need to truncate coming bytes. However we need to make - // sure cursor place is correct. - var i = 5; - do { - goog.asserts.assert(i < 10); - if (bytes[this.cursor_ + i] < 128) { - break; - } - i++; - } while (1); + // If we get here, we're reading the sign extension of a negative 32-bit int. + // We can skip these bytes, as we know in advance that they have to be all + // 1's if the varint is correctly encoded. Since we also know the value is + // negative, we don't have to coerce it to unsigned before we return it. + + goog.asserts.assert((temp & 0xF0) == 0xF0); + goog.asserts.assert(bytes[this.cursor_ + 5] == 0xFF); + goog.asserts.assert(bytes[this.cursor_ + 6] == 0xFF); + goog.asserts.assert(bytes[this.cursor_ + 7] == 0xFF); + goog.asserts.assert(bytes[this.cursor_ + 8] == 0xFF); + goog.asserts.assert(bytes[this.cursor_ + 9] == 0x01); - this.cursor_ += i + 1; + this.cursor_ += 10; goog.asserts.assert(this.cursor_ <= this.end_); return x; }; diff --git a/js/binary/decoder_test.js b/js/binary/decoder_test.js index b19e1d1b..d0139e29 100644 --- a/js/binary/decoder_test.js +++ b/js/binary/decoder_test.js @@ -270,7 +270,24 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - decoder.reset(); + + // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 + // should trigger assertions. + decoder.setBlock([255, 255, 255, 255, 0x1F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 0x2F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 0x4F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + // Negative 32-bit varints encoded with non-1 bits in the high dword should + // trigger assertions. + decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/js/compatibility_tests/v3.0.0/binary/decoder_test.js b/js/compatibility_tests/v3.0.0/binary/decoder_test.js index fce2fe18..ac312648 100644 --- a/js/compatibility_tests/v3.0.0/binary/decoder_test.js +++ b/js/compatibility_tests/v3.0.0/binary/decoder_test.js @@ -228,7 +228,24 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - decoder.reset(); + + // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 + // should trigger assertions. + decoder.setBlock([255, 255, 255, 255, 0x1F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 0x2F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 0x4F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + // Negative 32-bit varints encoded with non-1 bits in the high dword should + // trigger assertions. + decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/js/compatibility_tests/v3.1.0/binary/decoder_test.js b/js/compatibility_tests/v3.1.0/binary/decoder_test.js index fce2fe18..ac312648 100644 --- a/js/compatibility_tests/v3.1.0/binary/decoder_test.js +++ b/js/compatibility_tests/v3.1.0/binary/decoder_test.js @@ -228,7 +228,24 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - decoder.reset(); + + // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 + // should trigger assertions. + decoder.setBlock([255, 255, 255, 255, 0x1F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 0x2F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 0x4F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + // Negative 32-bit varints encoded with non-1 bits in the high dword should + // trigger assertions. + decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index a25de76c..73d32762 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2876,29 +2876,6 @@ void Generator::GenerateClassDeserializeBinaryField( "Group" : "Message", "grpfield", (field->type() == FieldDescriptor::TYPE_GROUP) ? (SimpleItoa(field->number()) + ", ") : ""); - } else if (field->is_repeated() && - field->cpp_type() != FieldDescriptor::CPPTYPE_STRING) { - printer->Print( - " if (reader.getWireType() == 2) {\n" - " var value = /** @type {$fieldtype_packed$} */ " - "(reader.readPacked$reader$());\n" - " msg.set$list_name$(value);\n" - " } else {\n" - " var value = /** @type {$fieldtype$} */ " - "(reader.read$reader$());\n" - " msg.add$name$(value);\n" - " }\n", - "fieldtype_packed", JSFieldTypeAnnotation(options, field, false, true, - /* singular_if_not_packed */ false, - BYTES_U8), - "fieldtype", JSFieldTypeAnnotation(options, field, false, true, - /* singular_if_not_packed */ true, - BYTES_U8), - "reader", JSBinaryReaderMethodType(field), - "list_name", JSGetterName(options, field), - "name", JSGetterName(options, field, - BYTES_DEFAULT, /* drop_list = */ true) - ); } else { printer->Print( " var value = /** @type {$fieldtype$} */ " @@ -2910,15 +2887,14 @@ void Generator::GenerateClassDeserializeBinaryField( JSBinaryReadWriteMethodName(field, /* is_writer = */ false)); } - if (field->is_repeated() && - (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE || - field->cpp_type() == FieldDescriptor::CPPTYPE_STRING)) { + if (field->is_repeated() && !field->is_packed()) { printer->Print( " msg.add$name$(value);\n", "name", JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true)); - } else if (!field->is_repeated()) { - // Singular fields, receive a |value| as the field's value ; set this as - // the field's value directly. + } else { + // Singular fields, and packed repeated fields, receive a |value| either + // as the field's value or as the array of all the field's values; set + // this as the field's value directly. printer->Print( " msg.set$name$(value);\n", "name", JSGetterName(options, field)); -- cgit v1.2.3 From c1dd8e85a1314a7bcb2059b842c6830d854fbefa Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 23 Aug 2017 22:03:18 -0700 Subject: Move parse frame array to the Map object This makes the frame stack per-parser, and per-thread. Fixes #3250 --- ruby/ext/google/protobuf_c/encode_decode.c | 21 ++------------------- ruby/ext/google/protobuf_c/map.c | 12 ++++++++++++ ruby/ext/google/protobuf_c/protobuf.c | 2 -- ruby/ext/google/protobuf_c/protobuf.h | 5 +++-- ruby/tests/basic.rb | 25 +++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index 6ce6d083..1427f4b8 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -280,11 +280,6 @@ rb_data_type_t MapParseFrame_type = { { MapParseFrame_mark, MapParseFrame_free, NULL }, }; -// Array of Ruby objects wrapping map_parse_frame_t. -// We don't allow multiple concurrent decodes, so we assume that this global -// variable is specific to the "current" decode. -VALUE map_parse_frames; - static map_parse_frame_t* map_push_frame(VALUE map, const map_handlerdata_t* handlerdata) { map_parse_frame_t* frame = ALLOC(map_parse_frame_t); @@ -293,16 +288,12 @@ static map_parse_frame_t* map_push_frame(VALUE map, native_slot_init(handlerdata->key_field_type, &frame->key_storage); native_slot_init(handlerdata->value_field_type, &frame->value_storage); - rb_ary_push(map_parse_frames, + Map_push_frame(map, TypedData_Wrap_Struct(rb_cObject, &MapParseFrame_type, frame)); return frame; } -static void map_pop_frame() { - rb_ary_pop(map_parse_frames); -} - // Handler to begin a map entry: allocates a temporary frame. This is the // 'startsubmsg' handler on the msgdef that contains the map field. static void *startmapentry_handler(void *closure, const void *hd) { @@ -336,7 +327,7 @@ static bool endmap_handler(void *closure, const void *hd, upb_status* s) { &frame->value_storage); Map_index_set(frame->map, key, value); - map_pop_frame(); + Map_pop_frame(frame->map); return true; } @@ -775,10 +766,6 @@ VALUE Message_decode(VALUE klass, VALUE data) { msg_rb = rb_class_new_instance(0, NULL, msgklass); TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); - // We generally expect this to be clear already, but clear it in case parsing - // previously got interrupted somehow. - rb_ary_clear(map_parse_frames); - { const upb_pbdecodermethod* method = msgdef_decodermethod(desc); const upb_handlers* h = upb_pbdecodermethod_desthandlers(method); @@ -823,10 +810,6 @@ VALUE Message_decode_json(VALUE klass, VALUE data) { msg_rb = rb_class_new_instance(0, NULL, msgklass); TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); - // We generally expect this to be clear already, but clear it in case parsing - // previously got interrupted somehow. - rb_ary_clear(map_parse_frames); - { const upb_json_parsermethod* method = msgdef_jsonparsermethod(desc); stackenv se; diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index 4be54c39..0787f6d5 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -146,6 +146,7 @@ void Map_mark(void* _self) { Map* self = _self; rb_gc_mark(self->value_type_class); + rb_gc_mark(self->parse_frames); if (self->value_type == UPB_TYPE_STRING || self->value_type == UPB_TYPE_BYTES || @@ -174,6 +175,16 @@ VALUE Map_alloc(VALUE klass) { return TypedData_Wrap_Struct(klass, &Map_type, self); } +VALUE Map_push_frame(VALUE map, VALUE val) { + Map* self = ruby_to_Map(map); + return rb_ary_push(self->parse_frames, val); +} + +VALUE Map_pop_frame(VALUE map) { + Map* self = ruby_to_Map(map); + return rb_ary_pop(self->parse_frames); +} + static bool needs_typeclass(upb_fieldtype_t type) { switch (type) { case UPB_TYPE_MESSAGE: @@ -227,6 +238,7 @@ VALUE Map_init(int argc, VALUE* argv, VALUE _self) { self->key_type = ruby_to_fieldtype(argv[0]); self->value_type = ruby_to_fieldtype(argv[1]); + self->parse_frames = rb_ary_new(); // Check that the key type is an allowed type. switch (self->key_type) { diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index 98963667..7cde4aec 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c @@ -112,6 +112,4 @@ void Init_protobuf_c() { upb_def_to_ruby_obj_map = rb_hash_new(); rb_gc_register_address(&upb_def_to_ruby_obj_map); - map_parse_frames = rb_ary_new(); - rb_gc_register_address(&map_parse_frames); } diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 520e9d9b..8fd1bc64 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -166,8 +166,6 @@ extern VALUE cBuilder; extern VALUE cError; extern VALUE cParseError; -extern VALUE map_parse_frames; - // We forward-declare all of the Ruby method implementations here because we // sometimes call the methods directly across .c files, rather than going // through Ruby's method dispatching (e.g. during message parse). It's cleaner @@ -397,6 +395,7 @@ typedef struct { upb_fieldtype_t key_type; upb_fieldtype_t value_type; VALUE value_type_class; + VALUE parse_frames; upb_strtable table; } Map; @@ -405,6 +404,8 @@ void Map_free(void* self); VALUE Map_alloc(VALUE klass); VALUE Map_init(int argc, VALUE* argv, VALUE self); void Map_register(VALUE module); +VALUE Map_push_frame(VALUE self, VALUE val); +VALUE Map_pop_frame(VALUE self); extern const rb_data_type_t Map_type; extern VALUE cMap; diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 020effb0..94071ca0 100644 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -96,8 +96,18 @@ module BasicTest optional :d, :enum, 4, "TestEnum" end end + + add_message "repro.Outer" do + map :items, :int32, :message, 1, "repro.Inner" + end + + add_message "repro.Inner" do + end end + + Outer = pool.lookup("repro.Outer").msgclass + Inner = pool.lookup("repro.Inner").msgclass Foo = pool.lookup("Foo").msgclass Bar = pool.lookup("Bar").msgclass Baz = pool.lookup("Baz").msgclass @@ -675,6 +685,21 @@ module BasicTest m.map_string_int32['aaa'] = 3 end + def test_concurrent_decoding + o = Outer.new + o.items[0] = Inner.new + raw = Outer.encode(o) + + thds = 2.times.map do + Thread.new do + 100000.times do + assert_equal o, Outer.decode(raw) + end + end + end + thds.map(&:join) + end + def test_map_encode_decode m = MapMessage.new( :map_string_int32 => {"a" => 1, "b" => 2}, -- cgit v1.2.3 From a459b224b5fbc30c328715a06f95ca494f1e5d6a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 30 Aug 2017 11:16:57 -0700 Subject: Storing the frame on the map means we don't need the array --- ruby/ext/google/protobuf_c/encode_decode.c | 4 ++-- ruby/ext/google/protobuf_c/map.c | 14 +++++--------- ruby/ext/google/protobuf_c/protobuf.h | 5 ++--- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index 1427f4b8..edbbe6a5 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -288,7 +288,7 @@ static map_parse_frame_t* map_push_frame(VALUE map, native_slot_init(handlerdata->key_field_type, &frame->key_storage); native_slot_init(handlerdata->value_field_type, &frame->value_storage); - Map_push_frame(map, + Map_set_frame(map, TypedData_Wrap_Struct(rb_cObject, &MapParseFrame_type, frame)); return frame; @@ -327,7 +327,7 @@ static bool endmap_handler(void *closure, const void *hd, upb_status* s) { &frame->value_storage); Map_index_set(frame->map, key, value); - Map_pop_frame(frame->map); + Map_set_frame(frame->map, Qnil); return true; } diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index 0787f6d5..26e22dc7 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -146,7 +146,7 @@ void Map_mark(void* _self) { Map* self = _self; rb_gc_mark(self->value_type_class); - rb_gc_mark(self->parse_frames); + rb_gc_mark(self->parse_frame); if (self->value_type == UPB_TYPE_STRING || self->value_type == UPB_TYPE_BYTES || @@ -175,14 +175,10 @@ VALUE Map_alloc(VALUE klass) { return TypedData_Wrap_Struct(klass, &Map_type, self); } -VALUE Map_push_frame(VALUE map, VALUE val) { +VALUE Map_set_frame(VALUE map, VALUE val) { Map* self = ruby_to_Map(map); - return rb_ary_push(self->parse_frames, val); -} - -VALUE Map_pop_frame(VALUE map) { - Map* self = ruby_to_Map(map); - return rb_ary_pop(self->parse_frames); + self->parse_frame = val; + return val; } static bool needs_typeclass(upb_fieldtype_t type) { @@ -238,7 +234,7 @@ VALUE Map_init(int argc, VALUE* argv, VALUE _self) { self->key_type = ruby_to_fieldtype(argv[0]); self->value_type = ruby_to_fieldtype(argv[1]); - self->parse_frames = rb_ary_new(); + self->parse_frame = Qnil; // Check that the key type is an allowed type. switch (self->key_type) { diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index 8fd1bc64..f4b110fe 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -395,7 +395,7 @@ typedef struct { upb_fieldtype_t key_type; upb_fieldtype_t value_type; VALUE value_type_class; - VALUE parse_frames; + VALUE parse_frame; upb_strtable table; } Map; @@ -404,8 +404,7 @@ void Map_free(void* self); VALUE Map_alloc(VALUE klass); VALUE Map_init(int argc, VALUE* argv, VALUE self); void Map_register(VALUE module); -VALUE Map_push_frame(VALUE self, VALUE val); -VALUE Map_pop_frame(VALUE self); +VALUE Map_set_frame(VALUE self, VALUE val); extern const rb_data_type_t Map_type; extern VALUE cMap; -- cgit v1.2.3 From dba647a6b2252e1876b0b8b63d42893c5b16ba14 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 14 Sep 2017 11:12:55 -0700 Subject: Bump version for minor release --- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 2 +- java/core/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 24 +++++++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- 13 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Protobuf.podspec b/Protobuf.podspec index 88bd5b7d..d559d18a 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.4.0' + s.version = '3.4.1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 04f7eb7a..0d3e5fb3 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.4.0],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.4.1],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index d32fd943..5b38241a 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.4.0 + 3.4.1 Google Inc. protobuf-packages https://github.com/google/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 4e63646b..75b38175 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.4.0 + 3.4.1 Google Inc. netstandard1.0;net45 true diff --git a/java/core/pom.xml b/java/core/pom.xml index 4608fce6..b0925f74 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.4.0 + 3.4.1 protobuf-java diff --git a/java/pom.xml b/java/pom.xml index dd3ba3b8..bc8e89b5 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -11,7 +11,7 @@ com.google.protobuf protobuf-parent - 3.4.0 + 3.4.1 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 61abd146..35afb844 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.4.0 + 3.4.1 protobuf-java-util diff --git a/js/package.json b/js/package.json index c8b75385..5231c846 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.4.0", + "version": "3.4.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 2d318517..4a473801 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2017-01-13 - + 2017-09-14 + - 3.4.0 - 3.4.0 + 3.4.1 + 3.4.1 stable @@ -149,6 +149,22 @@ GA release. 3-Clause BSD License +GA release. + + + + + 3.4.1 + 3.4.1 + + + stable + stable + + 2017-09-14 + + 3-Clause BSD License + GA release. diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index b2838e56..eeb145e6 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.4.0" +#define PHP_PROTOBUF_VERSION "3.4.1" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index d68709ea..c6f5a77f 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -10,7 +10,7 @@ com.google.protobuf protoc - 3.4.0 + 3.4.1 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index d26da0df..9f1a4f19 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.4.0' +__version__ = '3.4.1' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index bd1e39f1..550941c9 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.4.0.2" + s.version = "3.4.1" s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." -- cgit v1.2.3 From 2eb1bacc266ec9496edf66d38f080004edca46bd Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 15 Sep 2017 13:57:16 -0700 Subject: Bumping minor version for ruby gems --- ruby/google-protobuf.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 550941c9..96606f06 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.4.1" + s.version = "3.4.1.1" s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." -- cgit v1.2.3 From 6d0cf1b3fe35909c22a1d3fc6d1e4d4ab3c02cf2 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 27 Sep 2017 10:27:58 -0700 Subject: Remove ranged based for in io_win32.cc --- src/google/protobuf/stubs/io_win32.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index 51656a78..7e1cf785 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -195,12 +195,12 @@ string normalize(string path) { // Join all segments. bool first = true; std::ostringstream result; - for (const auto& s : segments) { + for (int i = 0; i < segments.size(); ++i) { if (!first) { result << '\\'; } first = false; - result << s; + result << segments[i]; } // Preserve trailing separator if the input contained it. if (!path.empty() && is_separator(path[path.size() - 1])) { -- cgit v1.2.3 From 5a501c64c7b448a025d3107379e8d1cf2287d18e Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 27 Sep 2017 10:33:04 -0700 Subject: Fix C++11 string accessors --- src/google/protobuf/testing/file.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc index f32222b7..b9cfe8be 100644 --- a/src/google/protobuf/testing/file.cc +++ b/src/google/protobuf/testing/file.cc @@ -121,7 +121,7 @@ void File::WriteStringToFileOrDie(const string& contents, const string& name) { bool File::CreateDir(const string& name, int mode) { if (!name.empty()) { - GOOGLE_CHECK_OK(name.back() != '.'); + GOOGLE_CHECK_OK(name[name.size()-1] != '.'); } return mkdir(name.c_str(), mode) == 0; } -- cgit v1.2.3 From d2738c04f5406ad99907727aad631787c703da69 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 27 Sep 2017 10:56:19 -0700 Subject: Add spaces --- src/google/protobuf/testing/file.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc index b9cfe8be..f68aba9a 100644 --- a/src/google/protobuf/testing/file.cc +++ b/src/google/protobuf/testing/file.cc @@ -121,7 +121,7 @@ void File::WriteStringToFileOrDie(const string& contents, const string& name) { bool File::CreateDir(const string& name, int mode) { if (!name.empty()) { - GOOGLE_CHECK_OK(name[name.size()-1] != '.'); + GOOGLE_CHECK_OK(name[name.size() - 1] != '.'); } return mkdir(name.c_str(), mode) == 0; } -- cgit v1.2.3