Merge branch 'master' of github.com:protocolbuffers/protobuf into ktExport

pull/9494/head
Deanna Garcia 3 years ago
commit c946f0bb70
  1. 5
      .gitignore
  2. 8
      CHANGES.txt
  3. 5
      CONTRIBUTORS.txt
  4. 2
      Makefile.am
  5. 1
      cmake/CMakeLists.txt
  6. 178
      cmake/README.md
  7. 2
      cmake/libprotobuf-lite.cmake
  8. 2
      cmake/libprotobuf.cmake
  9. 29
      cmake/protobuf-config.cmake.in
  10. 36
      cmake/protobuf-module.cmake.in
  11. 68
      cmake/tests.cmake
  12. 9
      conformance/conformance_nodejs.js
  13. 14
      conformance/conformance_test.cc
  14. 6
      conformance/conformance_test.h
  15. 6
      conformance/conformance_test_runner.cc
  16. 162
      conformance/failure_list_js.txt
  17. 23
      csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs
  18. 7
      java/core/src/main/java/com/google/protobuf/ArrayDecoders.java
  19. 5
      java/core/src/main/java/com/google/protobuf/ByteString.java
  20. 123
      java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
  21. 2
      java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
  22. 4
      java/core/src/main/java/com/google/protobuf/Internal.java
  23. 2
      java/core/src/main/java/com/google/protobuf/MessageReflection.java
  24. 2
      java/core/src/main/java/com/google/protobuf/MessageSetSchema.java
  25. 9
      java/core/src/main/java/com/google/protobuf/TextFormat.java
  26. 42
      java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java
  27. 6
      java/core/src/main/java/com/google/protobuf/Utf8.java
  28. 7
      java/core/src/test/java/com/google/protobuf/TextFormatTest.java
  29. 71
      java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto
  30. 45
      java/kotlin/src/main/kotlin/com/google/protobuf/Anies.kt
  31. 70
      java/kotlin/src/test/kotlin/com/google/protobuf/AniesTest.kt
  32. 11
      kokoro/linux/dockerfile/test/java_stretch/Dockerfile
  33. 18
      kokoro/linux/python36/build.sh
  34. 11
      kokoro/linux/python36/continuous.cfg
  35. 11
      kokoro/linux/python36/presubmit.cfg
  36. 18
      kokoro/linux/python36_cpp/build.sh
  37. 11
      kokoro/linux/python36_cpp/continuous.cfg
  38. 11
      kokoro/linux/python36_cpp/presubmit.cfg
  39. 10
      kokoro/release/python/windows/build_artifacts.bat
  40. 6
      kokoro/release/python/windows/build_single_artifact.bat
  41. 10
      objectivec/README.md
  42. 33
      php/ext/google/protobuf/names.c
  43. 2
      php/src/Google/Protobuf/Internal/DescriptorPool.php
  44. 12
      php/src/Google/Protobuf/Internal/GPBUtil.php
  45. 2
      php/src/Google/Protobuf/Internal/Message.php
  46. 12
      php/tests/GeneratedClassTest.php
  47. 2
      php/tests/proto/test_reserved_enum_lower.proto
  48. 2
      php/tests/proto/test_reserved_enum_upper.proto
  49. 2
      php/tests/proto/test_reserved_enum_value_lower.proto
  50. 2
      php/tests/proto/test_reserved_enum_value_upper.proto
  51. 2
      php/tests/proto/test_reserved_message_lower.proto
  52. 2
      php/tests/proto/test_reserved_message_upper.proto
  53. 2
      python/README.md
  54. 8
      python/google/protobuf/internal/descriptor_pool_test.py
  55. 12
      python/google/protobuf/json_format.py
  56. 2
      python/google/protobuf/pyext/message.cc
  57. 3
      python/google/protobuf/pyext/unknown_fields.cc
  58. 29
      python/google/protobuf/service_reflection.py
  59. 9
      python/setup.py
  60. 4
      python/tox.ini
  61. 65
      ruby/ext/google/protobuf_c/message.c
  62. 8
      ruby/lib/google/protobuf.rb
  63. 4
      ruby/lib/google/protobuf/message_exts.rb
  64. 4
      ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java
  65. 80
      ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
  66. 2
      ruby/tests/common_tests.rb
  67. 51
      ruby/tests/encode_decode_test.rb
  68. 4
      src/google/protobuf/any.cc
  69. 18
      src/google/protobuf/any.pb.cc
  70. 26
      src/google/protobuf/any.pb.h
  71. 6
      src/google/protobuf/any_lite.cc
  72. 63
      src/google/protobuf/api.pb.cc
  73. 94
      src/google/protobuf/api.pb.h
  74. 42
      src/google/protobuf/arena.h
  75. 12
      src/google/protobuf/arena_unittest.cc
  76. 115
      src/google/protobuf/arenastring.cc
  77. 296
      src/google/protobuf/arenastring.h
  78. 39
      src/google/protobuf/arenastring_unittest.cc
  79. 35
      src/google/protobuf/compiler/cpp/cpp_enum_field.cc
  80. 9
      src/google/protobuf/compiler/cpp/cpp_field.cc
  81. 8
      src/google/protobuf/compiler/cpp/cpp_generator.cc
  82. 6
      src/google/protobuf/compiler/cpp/cpp_message.cc
  83. 118
      src/google/protobuf/compiler/cpp/cpp_message_field.cc
  84. 51
      src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc
  85. 43
      src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
  86. 4
      src/google/protobuf/compiler/cpp/cpp_primitive_field.h
  87. 165
      src/google/protobuf/compiler/cpp/cpp_string_field.cc
  88. 4
      src/google/protobuf/compiler/cpp/cpp_string_field.h
  89. 27
      src/google/protobuf/compiler/java/java_helpers.cc
  90. 14
      src/google/protobuf/compiler/objectivec/objectivec_generator.cc
  91. 17
      src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
  92. 4
      src/google/protobuf/compiler/objectivec/objectivec_helpers.h
  93. 4
      src/google/protobuf/compiler/parser_unittest.cc
  94. 43
      src/google/protobuf/compiler/php/php_generator.cc
  95. 54
      src/google/protobuf/compiler/plugin.pb.cc
  96. 95
      src/google/protobuf/compiler/plugin.pb.h
  97. 59
      src/google/protobuf/compiler/subprocess.cc
  98. 89
      src/google/protobuf/descriptor.cc
  99. 297
      src/google/protobuf/descriptor.pb.cc
  100. 515
      src/google/protobuf/descriptor.pb.h
  101. Some files were not shown because too many files have changed in this diff Show More

5
.gitignore vendored

@ -215,5 +215,10 @@ _build/
.idea
*.iml
# Eclipse
**/.settings
**/.project
**/.classpath
# BenchmarkDotNet
BenchmarkDotNet.Artifacts/

@ -21,6 +21,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
* Report original exceptions when parsing JSON
* Add more info to @deprecated javadoc for set/get/has methods
* Fix initialization bug in doc comment line numbers
* Fix comments for message set wire format.
Kotlin
* Add orNull extensions for optional message fields in Kotlin.
@ -46,6 +47,8 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
zone. If omitted or None, the function returns a timezone-naive UTC datetime
(as previously).
* Adds client_streaming and server_streaming fields to MethodDescriptor.
* Add "ensure_ascii" parameter to json_format.MessageToJson. This allows smaller
JSON serializations with UTF-8 or other non-ASCII encodings.
Compiler
* Migrate IsDefault(const std::string*) and UnsafeSetDefault(const std::string*)
@ -63,6 +66,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
* Do not log/report the same descriptor symbol multiple times if it contains
more than one invalid character.
* Add UnknownFieldSet::SerializeToString and SerializeToCodedStream.
* Remove explicit default pointers and deprecated API from protocol compiler
Arenas
* Change Repeated*Field to reuse memory when using arenas.
@ -80,6 +84,10 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
* Generate narrower code
* Fix https://github.com/protocolbuffers/protobuf/issues/9378 by removing
shadowed _cached_size_ field
* Remove GetPointer() and explicit nullptr defaults.
* add proto_h flag for speeding up large builds
* Add missing overload for reference wrapped fields.
2022-01-28 version 3.19.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)

@ -100,3 +100,8 @@ Patch contributors:
Andrew Paprocki <andrew@ishiboo.com>
* Fixed minor IBM xlC compiler build issues
* Added atomicops for AIX (POWER)
Nipunn Koorapati <nipunn1313@gmail.com>
* Provide a type alias field ValueType on EnumTypeWrapper
* Match service argument names to abstract interface

@ -544,6 +544,7 @@ java_EXTRA_DIST=
java/kotlin/generate-test-sources-build.xml \
java/kotlin/pom.xml \
java/kotlin/pom_template.xml \
java/kotlin/src/main/kotlin/com/google/protobuf/Anies.kt \
java/kotlin/src/main/kotlin/com/google/protobuf/ByteStrings.kt \
java/kotlin/src/main/kotlin/com/google/protobuf/DslList.kt \
java/kotlin/src/main/kotlin/com/google/protobuf/DslMap.kt \
@ -553,6 +554,7 @@ java_EXTRA_DIST=
java/kotlin/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt\
java/kotlin/src/main/kotlin/com/google/protobuf/ProtoDslMarker.kt \
java/kotlin/src/main/kotlin/com/google/protobuf/UnmodifiableCollections.kt \
java/kotlin/src/test/kotlin/com/google/protobuf/AniesTest.kt \
java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt \
java/kotlin/src/test/kotlin/com/google/protobuf/DslListTest.kt \
java/kotlin/src/test/kotlin/com/google/protobuf/DslMapTest.kt \

@ -297,6 +297,7 @@ if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLE
endif ()
if (protobuf_BUILD_TESTS)
enable_testing()
include(tests.cmake)
endif (protobuf_BUILD_TESTS)

@ -36,6 +36,10 @@ If *git* command is not available from *Command Prompt*, add it to system *PATH*
C:\Path\to>set PATH=%PATH%;C:\Program Files\Git\cmd
Optionally, you will want to download [ninja](https://ninja-build.org/) and add it to your *PATH* variable.
C:\Path\to>set PATH=%PATH%;C:\tools\ninja
Good. Now you are ready to continue.
Getting Sources
@ -52,29 +56,25 @@ download `protobuf-all-[VERSION].tar.gz`.
Or you can use git to clone from protobuf git repository.
C:\Path\to> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git
C:\Path\to> mkdir src & cd src
C:\Path\to\src> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git
Where *[release_tag]* is a git tag like *v3.0.0-beta-1* or a branch name like *master*
if you want to get the latest code.
Go to the project folder:
C:\Path\to>cd protobuf
C:\Path\to\protobuf>
C:\Path\to\src> cd protobuf
C:\Path\to\src\protobuf>
Remember to update any submodules if you are using git clone (you can skip this
step if you are using a release .tar.gz or .zip package):
```console
C:\Path\to> git submodule update --init --recursive
C:\Path\to\src\protobuf> git submodule update --init --recursive
```
Now go to *cmake* folder in protobuf sources:
C:\Path\to\protobuf>cd cmake
C:\Path\to\protobuf\cmake>
Good. Now you are ready to *CMake* configuration.
Good. Now you are ready for *CMake* configuration.
CMake Configuration
===================
@ -82,71 +82,119 @@ CMake Configuration
*CMake* supports a lot of different
[generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html)
for various native build systems.
We are only interested in
[Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators)
and
[Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators)
generators.
We will use shadow building to separate the temporary files from the protobuf source code.
Of most interest to Windows programmers are the following:
* [Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators).
This generates NMake Makefiles for Visual Studio. These work, but they are rather slow.
* [Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators)
This generates a Visual Studio solution for the project.
* [Ninja](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#ninja-generator)
This uses the external tool [Ninja](https://ninja-build.org/) to build. It is the fastest solution available.
Note that as of Visual Studio 2015, Visual Studio includes
[support for opening directly CMake-based projects](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio).
It is considered good practice not to build CMake projects in the source tree but in a separate folder.
Create a temporary *build* folder and change your working directory to it:
C:\Path\to\protobuf\cmake>mkdir build & cd build
C:\Path\to\protobuf\cmake\build>
mkdir C:\Path\to\build\protobuf
cd C:\Path\to\build\protobuf
C:\Path\to\build\protobuf>
The *Makefile* generator can build the project in only one configuration, so you need to build
The *Makefile* and *Ninja* generators can build the project in only one configuration, so you need to build
a separate folder for each configuration.
To start using a *Release* configuration:
To start using a *Release* configuration via the *NMmake* generator:
C:\Path\to\protobuf\cmake\build>mkdir release & cd release
C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^
C:\Path\to\build\protobuf>mkdir release & cd release
C:\Path\to\build\protobuf\release>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *nmake* *Makefile* in current directory.
It will generate a *NMake* *Makefile* in the current directory.
To use *Debug* configuration:
To use *Debug* configuration using *Ninja*:
C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug
C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" ^
C:\Path\to\build\protobuf>mkdir debug & cd debug
C:\Path\to\build\protobuf\debug>cmake -G "Ninja" ^
-DCMAKE_BUILD_TYPE=Debug ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *nmake* *Makefile* in current directory.
It will generate *Ninja* build scripts in current directory.
To create *Visual Studio* solution file:
The *Visual Studio* generator is multi-configuration: it will generate a single *.sln* file that can be used for both *Debug* and *Release*:
C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution
C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
C:\Path\to\build\protobuf>mkdir solution & cd solution
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *Visual Studio* solution file *protobuf.sln* in current directory.
If the *gmock* directory does not exist, and you do not want to build protobuf unit tests,
you need to add *cmake* command argument `-Dprotobuf_BUILD_TESTS=OFF` to disable testing.
Unit Tests
----------
Unit tests are being built along with the rest of protobuf. The unit tests require Google Mock (now a part of Google Test).
A copy of [Google Test](https://github.com/google/googletest) is included as a Git submodule in the `third-party/googletest` folder.
(You do need to initialize the Git submodules as explained above.)
Alternately, you may want to use protobuf in a larger set-up, you may want to use that standard CMake approach where
you build and install a shared copy of Google Test.
After you've built and installed your Google Test copy, you need add the following definition to your *cmake* command line
during the configuration step: `-Dprotobuf_USE_EXTERNAL_GTEST=ON`.
This will cause the standard CMake `find_package(GTest REQUIRED)` to be used.
To make a *Visual Studio* file for Visual Studio 16 2019, create the *Visual Studio*
solution file above and edit the CMakeCache file.
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html) will search in a default location,
which on Windows is *C:\Program Files*. This is most likely not what you want. You will want instead to search for
Google Test in your project's root directory (i.e. the same directory you've passed to `CMAKE_INSTALL_PREFIX` when
building Google Test). For this, you need to set the `CMAKE_PREFIX_PATH` CMake variable. (There are other ways in CMake,
see the [manual](https://cmake.org/cmake/help/latest/command/find_package.html) for details.)
C:Path\to\protobuf\cmake\build\solution\CMakeCache
For example:
Then create the *Visual Studio* solution file again
C:\Path\to\build\protobuf>mkdir solution & cd solution
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
-DCMAKE_PREFIX_PATH=C:\Path\to\my_big_project ^
-Dprotobuf_USE_EXTERNAL_GTEST=ON ^
C:\Path\to\src\protobuf
In most cases, `CMAKE_PREFIX_PATH` and `CMAKE_INSTALL_PREFIX` will point to the same directory.
To disable testing completely, you need to add the following argument to you *cmake* command line: `-Dprotobuf_BUILD_TESTS=OFF`.
For example:
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
-Dprotobuf_BUILD_TESTS=OFF ^
C:\Path\to\src\protobuf
Compiling
=========
To compile protobuf:
The standard way to compile a *CMake* project is `cmake --build <directory>`.
Note that if your generator supports multiple configurations, you will probably want to specify which one to build:
C:\Path\to\protobuf\cmake\build\release>nmake
cmake --build C:\Path\to\build\protobuf\solution --config Release
You can also run directly the build tool you've configured:
C:\Path\to\build\protobuf\release>nmake
or
C:\Path\to\protobuf\cmake\build\debug>nmake
C:\Path\to\build\protobuf\debug>ninja
And wait for the compilation to finish.
@ -164,11 +212,15 @@ Testing
To run unit-tests, first you must compile protobuf as described above.
Then run:
C:\Path\to\protobuf\cmake\build\release>nmake check
C:\Path\to\protobuf\cmake\build\release>ctest --progress --output-on-failure
You can also build the `check` target (not idiomatic CMake usage, though):
C:\Path\to\protobuf\cmake\build\release>cmake --build . --target check
or
C:\Path\to\protobuf\cmake\build\debug>nmake check
C:\Path\to\build\protobuf\release>ninja check
You can also build project *check* from Visual Studio solution.
Yes, it may sound strange, but it works.
@ -183,9 +235,9 @@ You should see output similar to:
[==========] 1546 tests from 165 test cases ran. (2529 ms total)
[ PASSED ] 1546 tests.
To run specific tests:
To run specific tests, you need to pass some command line arguments to the test program itself:
C:\Path\to\protobuf>cmake\build\release\tests.exe --gtest_filter=AnyTest*
C:\Path\to\build\protobuf\release>tests.exe --gtest_filter=AnyTest*
Running main() from gmock_main.cc
Note: Google Test filter = AnyTest*
[==========] Running 3 tests from 1 test case.
@ -210,13 +262,17 @@ If all tests are passed, safely continue.
Installing
==========
To install protobuf to the specified *install* folder:
To install protobuf to the *install* folder you've specified in the configuration step, you need to build the `install` target:
cmake --build C:\Path\to\build\protobuf\solution --config Release --target install
Or if you prefer:
C:\Path\to\protobuf\cmake\build\release>nmake install
C:\Path\to\build\protobuf\release>nmake install
or
C:\Path\to\protobuf\cmake\build\debug>nmake install
C:\Path\to\build\protobuf\debug>ninja install
You can also build project *INSTALL* from Visual Studio solution.
It sounds not so strange and it works.
@ -280,16 +336,16 @@ You can also compile it from source by yourself.
Getting sources:
C:\Path\to>git clone -b v1.2.8 https://github.com/madler/zlib.git
C:\Path\to>cd zlib
C:\Path\to\src>git clone -b v1.2.8 https://github.com/madler/zlib.git
C:\Path\to\src>cd zlib
Compiling and Installing:
C:\Path\to\zlib>mkdir build & cd build
C:\Path\to\zlib\build>mkdir release & cd release
C:\Path\to\zlib\build\release>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=../../../install ../..
C:\Path\to\zlib\build\release>nmake & nmake install
C:\Path\to\src\zlib>mkdir C:\Path\to\build\zlib & cd C:\Path\to\build\zlib
C:\Path\to\build\zlib>mkdir release & cd release
C:\Path\to\build\zlib\release>cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install C:\Path\to\src\zlib
C:\Path\to\src\zlib\build\release>cmake --build . --target install
You can make *debug* version or use *Visual Studio* generator also as before for the
protobuf project.
@ -308,8 +364,8 @@ the headers or the .lib file in the right directory.
If you already have ZLIB library and headers at some other location on your system then alternatively you can define following configuration flags to locate them:
-DZLIB_INCLUDE_DIR=<path to dir containing zlib headers>
-DZLIB_LIB=<path to dir containing zlib>
-DZLIB_INCLUDE_DIR=<path to dir containing zlib headers>
-DZLIB_LIB=<path to dir containing zlib>
Build and testing protobuf as usual.

@ -101,7 +101,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(libprotobuf-lite log)
endif()
target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf-lite
PUBLIC PROTOBUF_USE_DLLS
PRIVATE LIBPROTOBUF_EXPORTS)

@ -118,7 +118,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(libprotobuf log)
endif()
target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf
PUBLIC PROTOBUF_USE_DLLS
PRIVATE LIBPROTOBUF_EXPORTS)

@ -11,7 +11,7 @@ function(protobuf_generate)
include(CMakeParseArguments)
set(_options APPEND_PATH)
set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN)
set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN PLUGIN_OPTIONS)
if(COMMAND target_sources)
list(APPEND _singleargs TARGET)
endif()
@ -39,9 +39,18 @@ function(protobuf_generate)
endif()
if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp)
set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:")
set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}")
endif()
foreach(_option ${_dll_export_decl} ${protobuf_generate_PLUGIN_OPTIONS})
# append comma - not using CMake lists and string replacement as users
# might have semicolons in options
if(_plugin_options)
set( _plugin_options "${_plugin_options},")
endif()
set(_plugin_options "${_plugin_options}${_option}")
endforeach()
if(protobuf_generate_PLUGIN)
set(_plugin "--plugin=${protobuf_generate_PLUGIN}")
endif()
@ -127,12 +136,20 @@ function(protobuf_generate)
endforeach()
list(APPEND _generated_srcs_all ${_generated_srcs})
set(_comment "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}")
if(protobuf_generate_PROTOC_OPTIONS)
set(_comment "${_comment}, protoc-options: ${protobuf_generate_PROTOC_OPTIONS}")
endif()
if(_plugin_options)
set(_comment "${_comment}, plugin-options: ${_plugin_options}")
endif()
add_custom_command(
OUTPUT ${_generated_srcs}
COMMAND protobuf::protoc
ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file}
COMMAND protobuf::protoc
ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file}
DEPENDS ${_abs_file} protobuf::protoc
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}. Custom options: ${protobuf_generate_PROTOC_OPTIONS}"
COMMENT ${_comment}
VERBATIM )
endforeach()

@ -94,7 +94,7 @@ function(_protobuf_find_libraries name filename)
elseif(${name}_LIBRARY)
# Honor cache entry used by CMake 3.5 and lower.
set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE)
else()
elseif(TARGET protobuf::lib${filename})
get_target_property(${name}_LIBRARY_RELEASE protobuf::lib${filename}
LOCATION_RELEASE)
get_target_property(${name}_LIBRARY_RELWITHDEBINFO protobuf::lib${filename}
@ -134,23 +134,25 @@ get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf
INTERFACE_INCLUDE_DIRECTORIES)
# Set the protoc Executable
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_RELEASE)
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc)
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_RELWITHDEBINFO)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_MINSIZEREL)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_DEBUG)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_NOCONFIG)
IMPORTED_LOCATION_RELEASE)
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_RELWITHDEBINFO)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_MINSIZEREL)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_DEBUG)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_NOCONFIG)
endif()
endif()
# Version info variable

@ -1,32 +1,42 @@
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../third_party/googletest/CMakeLists.txt")
message(FATAL_ERROR
"Cannot find third_party/googletest directory that's needed to "
"build tests. If you use git, make sure you have cloned submodules:\n"
" git submodule update --init --recursive\n"
"If instead you want to skip tests, run cmake with:\n"
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
endif()
option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF)
option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
"Using absolute test_plugin path in tests" ON)
mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
set(googlemock_source_dir "${protobuf_source_dir}/third_party/googletest/googlemock")
set(googletest_source_dir "${protobuf_source_dir}/third_party/googletest/googletest")
include_directories(
${googlemock_source_dir}
${googletest_source_dir}
${googletest_source_dir}/include
${googlemock_source_dir}/include
)
if (protobuf_USE_EXTERNAL_GTEST)
find_package(GTest REQUIRED)
else()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../third_party/googletest/CMakeLists.txt")
message(FATAL_ERROR
"Cannot find third_party/googletest directory that's needed to "
"build tests. If you use git, make sure you have cloned submodules:\n"
" git submodule update --init --recursive\n"
"If instead you want to skip tests, run cmake with:\n"
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
endif()
set(googlemock_source_dir "${protobuf_source_dir}/third_party/googletest/googlemock")
set(googletest_source_dir "${protobuf_source_dir}/third_party/googletest/googletest")
include_directories(
${googlemock_source_dir}
${googletest_source_dir}
${googletest_source_dir}/include
${googlemock_source_dir}/include
)
add_library(gmock STATIC
"${googlemock_source_dir}/src/gmock-all.cc"
"${googletest_source_dir}/src/gtest-all.cc"
)
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc")
target_link_libraries(gmock_main gmock)
add_library(GTest::gmock ALIAS gmock)
add_library(GTest::gmock_main ALIAS gmock_main)
endif()
add_library(gmock STATIC
"${googlemock_source_dir}/src/gmock-all.cc"
"${googletest_source_dir}/src/gtest-all.cc"
)
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc")
target_link_libraries(gmock_main gmock)
set(lite_test_protos
google/protobuf/map_lite_unittest.proto
@ -229,7 +239,7 @@ if (MSVC)
/wd4146 # unary minus operator applied to unsigned type, result still unsigned
)
endif()
target_link_libraries(tests libprotoc libprotobuf gmock_main)
target_link_libraries(tests libprotoc libprotobuf GTest::gmock_main)
set(test_plugin_files
${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
@ -239,21 +249,25 @@ set(test_plugin_files
)
add_executable(test_plugin ${test_plugin_files})
target_link_libraries(test_plugin libprotoc libprotobuf gmock)
target_link_libraries(test_plugin libprotoc libprotobuf GTest::gmock)
set(lite_test_files
${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc
)
add_executable(lite-test ${lite_test_files} ${common_lite_test_files} ${lite_test_proto_files})
target_link_libraries(lite-test libprotobuf-lite gmock_main)
target_link_libraries(lite-test libprotobuf-lite GTest::gmock_main)
set(lite_arena_test_files
${protobuf_source_dir}/src/google/protobuf/lite_arena_unittest.cc
)
add_executable(lite-arena-test ${lite_arena_test_files} ${common_lite_test_files} ${lite_test_proto_files})
target_link_libraries(lite-arena-test libprotobuf-lite gmock_main)
target_link_libraries(lite-arena-test libprotobuf-lite GTest::gmock_main)
add_custom_target(check
COMMAND tests
DEPENDS tests test_plugin
WORKING_DIRECTORY ${protobuf_source_dir})
add_test(NAME check
COMMAND tests
WORKING_DIRECTORY "${protobuf_source_dir}")

@ -41,11 +41,16 @@ function doTest(request) {
var response = new conformance.ConformanceResponse();
try {
if (request.getRequestedOutputFormat() === conformance.WireFormat.JSON) {
if (request.getRequestedOutputFormat() == conformance.WireFormat.JSON) {
response.setSkipped("JSON not supported.");
return response;
}
if (request.getRequestedOutputFormat() == conformance.WireFormat.TEXT_FORMAT) {
response.setSkipped('Text format is not supported as output format.');
return response;
}
switch (request.getPayloadCase()) {
case conformance.ConformanceRequest.PayloadCase.PROTOBUF_PAYLOAD: {
if (request.getMessageType() == "protobuf_test_messages.proto3.TestAllTypesProto3") {
@ -67,7 +72,7 @@ function doTest(request) {
} else {
throw "Protobuf request doesn\'t have specific payload type";
}
}
} break;
case conformance.ConformanceRequest.PayloadCase.JSON_PAYLOAD:
response.setSkipped("JSON not supported.");

@ -350,7 +350,17 @@ bool ConformanceTestSuite::CheckSetEmpty(
StringAppendF(&output_, "\n");
if (!write_to_file.empty()) {
std::ofstream os(write_to_file);
std::string full_filename;
const std::string* filename = &write_to_file;
if (!output_dir_.empty()) {
full_filename = output_dir_;
if (*output_dir_.rbegin() != '/') {
full_filename.push_back('/');
}
full_filename += write_to_file;
filename = &full_filename;
}
std::ofstream os(*filename);
if (os) {
for (std::set<string>::const_iterator iter = set_to_check.begin();
iter != set_to_check.end(); ++iter) {
@ -358,7 +368,7 @@ bool ConformanceTestSuite::CheckSetEmpty(
}
} else {
StringAppendF(&output_, "Failed to open file: %s\n",
write_to_file.c_str());
filename->c_str());
}
}

@ -174,6 +174,11 @@ class ConformanceTestSuite {
failure_list_flag_name_ = failure_list_flag_name;
}
// Sets the path of the output directory.
void SetOutputDir(const char* output_dir) {
output_dir_ = output_dir;
}
// Run all the conformance tests against the given test runner.
// Test output will be stored in "output".
//
@ -296,6 +301,7 @@ class ConformanceTestSuite {
bool verbose_;
bool enforce_recommended_;
std::string output_;
std::string output_dir_;
std::string failure_list_flag_name_;
std::string failure_list_filename_;

@ -141,6 +141,9 @@ void UsageError() {
" strictly conforming to protobuf\n");
fprintf(stderr,
" spec.\n");
fprintf(stderr,
" --output_dir <dirname> Directory to write\n"
" output files.\n");
exit(1);
}
@ -208,6 +211,9 @@ int ForkPipeRunner::Run(
suite->SetVerbose(true);
} else if (strcmp(argv[arg], "--enforce_recommended") == 0) {
suite->SetEnforceRecommended(true);
} else if (strcmp(argv[arg], "--output_dir") == 0) {
if (++arg == argc) UsageError();
suite->SetOutputDir(argv[arg]);
} else if (argv[arg][0] == '-') {
bool recognized_flag = false;
for (ConformanceTestSuite* suite : suites) {

@ -0,0 +1,162 @@
Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.ENUM[5].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.FIXED64[2].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.INT32[7].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.INT64[2].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.SFIXED64[2].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.SINT64[2].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.UINT32[8].ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.UINT64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[5].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.FIXED64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.INT32[7].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.INT64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.SFIXED64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.SINT64[2].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT32[8].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT64[2].ProtobufOutput
Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.ENUM.ProtobufOutput
Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput
Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.ENUM[4].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.ENUM[5].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.FIXED64[2].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.INT32[7].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.INT64[2].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.SFIXED64[2].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.SINT64[2].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.UINT32[8].ProtobufOutput
Required.Proto2.ProtobufInput.ValidDataScalar.UINT64[2].ProtobufOutput
Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.ProtobufOutput
Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput
Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[4].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[5].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.INT32[7].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.INT64[2].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[2].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[8].ProtobufOutput
Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].ProtobufOutput

@ -138,6 +138,29 @@ namespace Google.Protobuf
Assert.AreEqual(message.ToByteArray(), otherEmptyMessage.ToByteArray());
}
[Test]
public void TestClone_LengthDelimited()
{
var unknownVarintField = new UnknownField();
unknownVarintField.AddVarint(99);
var unknownLengthDelimitedField1 = new UnknownField();
unknownLengthDelimitedField1.AddLengthDelimited(ByteString.CopyFromUtf8("some data"));
var unknownLengthDelimitedField2 = new UnknownField();
unknownLengthDelimitedField2.AddLengthDelimited(ByteString.CopyFromUtf8("some more data"));
var destUnknownFieldSet = new UnknownFieldSet();
destUnknownFieldSet.AddOrReplaceField(997, unknownVarintField);
destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField1);
destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField2);
var clone = UnknownFieldSet.Clone(destUnknownFieldSet);
Assert.IsTrue(clone.HasField(997));
Assert.IsTrue(clone.HasField(999));
}
[Test]
[TestCaseSource(typeof(Data), "Messages")]
public void TestDiscardUnknownFields(IMessage message)

@ -45,14 +45,15 @@ import java.io.IOException;
*/
@CheckReturnValue
final class ArrayDecoders {
private ArrayDecoders() {
}
/**
* A helper used to return multiple values in a Java function. Java doesn't natively support
* returning multiple values in a function. Creating a new Object to hold the return values will
* be too expensive. Instead, we pass a Registers instance to functions that want to return
* multiple values and let the function set the return value in this Registers instance instead.
*
* <p>TODO(xiaofeng): This could be merged into CodedInputStream or CodedInputStreamReader which
* is already being passed through all the parsing routines.
*/
static final class Registers {
public int int1;

@ -316,13 +316,8 @@ public abstract class ByteString implements Iterable<Byte>, Serializable {
};
/**
<<<<<<< HEAD
* Returns a {@link Comparator} which compares {@link ByteString}-s lexicographically
* as sequences of unsigned byte values between 0 and 255, inclusive.
=======
* Returns a {@link Comparator} which compares {@link ByteString}-s lexicographically as sequences
* of unsigned bytes (i.e. values between 0 and 255, inclusive).
>>>>>>> refs/tags/sync-piper
*
* <p>For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because it
* is interpreted as an unsigned value, {@code 255}:

@ -61,8 +61,31 @@ import java.util.concurrent.ConcurrentHashMap;
final class DescriptorMessageInfoFactory implements MessageInfoFactory {
private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
private static final DescriptorMessageInfoFactory instance = new DescriptorMessageInfoFactory();
/**
* Names that should be avoided (in UpperCamelCase format).
* Using them causes the compiler to generate accessors whose names
* collide with methods defined in base classes.
*
* Keep this list in sync with kForbiddenWordList in
* src/google/protobuf/compiler/java/java_helpers.cc
*/
private static final Set<String> specialFieldNames =
new HashSet<>(Arrays.asList("cached_size", "serialized_size", "class"));
new HashSet<>(Arrays.asList(
// java.lang.Object:
"Class",
// com.google.protobuf.MessageLiteOrBuilder:
"DefaultInstanceForType",
// com.google.protobuf.MessageLite:
"ParserForType",
"SerializedSize",
// com.google.protobuf.MessageOrBuilder:
"AllFields",
"DescriptorForType",
"InitializationErrorString",
"UnknownFields",
// obsolete. kept for backwards compatibility of generated code
"CachedSize"));
// Disallow construction - it's a singleton.
private DescriptorMessageInfoFactory() {}
@ -593,21 +616,101 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
String name = (fd.getType() == FieldDescriptor.Type.GROUP)
? fd.getMessageType().getName()
: fd.getName();
String suffix = specialFieldNames.contains(name) ? "__" : "_";
return snakeCaseToCamelCase(name) + suffix;
// convert to UpperCamelCase for comparison to the specialFieldNames
// (which are in UpperCamelCase)
String upperCamelCaseName = snakeCaseToUpperCamelCase(name);
// Append underscores to match the behavior of the protoc java compiler
final String suffix;
if (specialFieldNames.contains(upperCamelCaseName)) {
// For proto field names that match the specialFieldNames,
// the protoc java compiler appends "__" to the java field name
// to prevent the field's accessor method names from clashing with other methods.
// For example:
// proto field name = "class"
// java field name = "class__"
// accessor method name = "getClass_()" (so that it does not clash with Object.getClass())
suffix = "__";
} else {
// For other proto field names,
// the protoc java compiler appends "_" to the java field name
// to prevent field names from clashing with java keywords.
// For example:
// proto field name = "int"
// java field name = "int_" (so that it does not clash with int keyword)
// accessor method name = "getInt()"
suffix = "_";
}
return snakeCaseToLowerCamelCase(name) + suffix;
}
private static String getCachedSizeFieldName(FieldDescriptor fd) {
return snakeCaseToCamelCase(fd.getName()) + "MemoizedSerializedSize";
return snakeCaseToLowerCamelCase(fd.getName()) + "MemoizedSerializedSize";
}
/**
* Converts a snake case string into lower camel case.
*
* <p>Some examples:</p>
* <pre>
* snakeCaseToLowerCamelCase("foo_bar") => "fooBar"
* snakeCaseToLowerCamelCase("foo") => "foo"
* </pre>
*
* @param snakeCase the string in snake case to convert
* @return the string converted to camel case, with a lowercase first character
*/
private static String snakeCaseToLowerCamelCase(String snakeCase) {
return snakeCaseToCamelCase(snakeCase, false);
}
/**
* This method must match exactly with the corresponding function in protocol compiler. See:
* https://github.com/google/protobuf/blob/v3.0.0/src/google/protobuf/compiler/java/java_helpers.cc#L153
* Converts a snake case string into upper camel case.
*
* <p>Some examples:</p>
* <pre>
* snakeCaseToUpperCamelCase("foo_bar") => "FooBar"
* snakeCaseToUpperCamelCase("foo") => "Foo"
* </pre>
*
* @param snakeCase the string in snake case to convert
* @return the string converted to camel case, with an uppercase first character
*/
private static String snakeCaseToUpperCamelCase(String snakeCase) {
return snakeCaseToCamelCase(snakeCase, true);
}
/**
* Converts a snake case string into camel case.
*
* <p>For better readability, prefer calling either
* {@link #snakeCaseToLowerCamelCase(String)} or {@link #snakeCaseToUpperCamelCase(String)}.</p>
*
* <p>Some examples:</p>
* <pre>
* snakeCaseToCamelCase("foo_bar", false) => "fooBar"
* snakeCaseToCamelCase("foo_bar", true) => "FooBar"
* snakeCaseToCamelCase("foo", false) => "foo"
* snakeCaseToCamelCase("foo", true) => "Foo"
* snakeCaseToCamelCase("Foo", false) => "foo"
* snakeCaseToCamelCase("fooBar", false) => "fooBar"
* </pre>
*
* <p>This implementation of this method must exactly match the corresponding
* function in the protocol compiler. Specifically, the
* {@code UnderscoresToCamelCase} function in
* {@code src/google/protobuf/compiler/java/java_helpers.cc}.</p>
*
* @param snakeCase the string in snake case to convert
* @param capFirst true if the first letter of the returned string should be uppercase.
* false if the first letter of the returned string should be lowercase.
* @return the string converted to camel case, with an uppercase or lowercase first
* character depending on if {@code capFirst} is true or false, respectively
*/
private static String snakeCaseToCamelCase(String snakeCase) {
private static String snakeCaseToCamelCase(String snakeCase, boolean capFirst) {
StringBuilder sb = new StringBuilder(snakeCase.length() + 1);
boolean capNext = false;
boolean capNext = capFirst;
for (int ctr = 0; ctr < snakeCase.length(); ctr++) {
char next = snakeCase.charAt(ctr);
if (next == '_') {
@ -653,7 +756,7 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
/** Constructs the name of the get method for the given field in the proto. */
private static String getterForField(String snakeCase) {
String camelCase = snakeCaseToCamelCase(snakeCase);
String camelCase = snakeCaseToLowerCamelCase(snakeCase);
StringBuilder builder = new StringBuilder("get");
// Capitalize the first character in the field name.
builder.append(Character.toUpperCase(camelCase.charAt(0)));
@ -679,7 +782,7 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
}
private static OneofInfo newInfo(Class<?> messageType, OneofDescriptor desc) {
String camelCase = snakeCaseToCamelCase(desc.getName());
String camelCase = snakeCaseToLowerCamelCase(desc.getName());
String valueFieldName = camelCase + "_";
String caseFieldName = camelCase + "Case_";

@ -692,7 +692,7 @@ public abstract class GeneratedMessageLite<
// The wire format for MessageSet is:
// message MessageSet {
// repeated group Item = 1 {
// required int32 typeId = 2;
// required uint32 typeId = 2;
// required bytes message = 3;
// }
// }

@ -259,7 +259,9 @@ public final class Internal {
/** Helper method for implementing {@link Message#equals(Object)} for bytes field. */
public static boolean equals(List<byte[]> a, List<byte[]> b) {
if (a.size() != b.size()) return false;
if (a.size() != b.size()) {
return false;
}
for (int i = 0; i < a.size(); ++i) {
if (!Arrays.equals(a.get(i), b.get(i))) {
return false;

@ -882,7 +882,7 @@ class MessageReflection {
// The wire format for MessageSet is:
// message MessageSet {
// repeated group Item = 1 {
// required int32 typeId = 2;
// required uint32 typeId = 2;
// required bytes message = 3;
// }
// }

@ -300,7 +300,7 @@ final class MessageSetSchema<T> implements Schema<T> {
// The wire format for MessageSet is:
// message MessageSet {
// repeated group Item = 1 {
// required int32 typeId = 2;
// required uint32 typeId = 2;
// required bytes message = 3;
// }
// }

@ -49,7 +49,7 @@ import java.util.regex.Pattern;
/**
* Provide text parsing and formatting support for proto2 instances. The implementation largely
* follows google/protobuf/text_format.cc.
* follows text_format.cc.
*
* @author wenboz@google.com Wenbo Zhu
* @author kenton@google.com Kenton Varda
@ -2307,7 +2307,7 @@ public final class TextFormat {
* Un-escape a byte sequence as escaped using {@link #escapeBytes(ByteString)}. Two-digit hex
* escapes (starting with "\x") are also recognized.
*/
public static ByteString unescapeBytes(final CharSequence charString)
public static ByteString unescapeBytes(CharSequence charString)
throws InvalidEscapeSequenceException {
// First convert the Java character sequence to UTF-8 bytes.
ByteString input = ByteString.copyFromUtf8(charString.toString());
@ -2444,9 +2444,10 @@ public final class TextFormat {
+ "' is not a valid code point value");
}
Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(codepoint);
if (unicodeBlock.equals(Character.UnicodeBlock.LOW_SURROGATES)
if (unicodeBlock != null
&& (unicodeBlock.equals(Character.UnicodeBlock.LOW_SURROGATES)
|| unicodeBlock.equals(Character.UnicodeBlock.HIGH_SURROGATES)
|| unicodeBlock.equals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES)) {
|| unicodeBlock.equals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES))) {
throw new InvalidEscapeSequenceException(
"Invalid escape sequence: '\\U"
+ input.substring(i, i + 8).toStringUtf8()

@ -30,7 +30,24 @@
package com.google.protobuf;
/** Provide text format escaping support for proto2 instances. */
/**
* Provide text format escaping of proto instances. These ASCII characters are escaped:
*
* ASCII #7 (bell) --> \a
* ASCII #8 (backspace) --> \b
* ASCII #9 (horizontal tab) --> \t
* ASCII #10 (linefeed) --> \n
* ASCII #11 (vertical tab) --> \v
* ASCII #13 (carriage return) --> \r
* ASCII #12 (formfeed) --> \f
* ASCII #34 (apostrophe) --> \'
* ASCII #39 (straight double quote) --> \"
* ASCII #92 (backslash) --> \\
*
* Other printable ASCII characters between 32 and 127 inclusive are output as is, unescaped.
* Other ASCII characters less than 32 and all Unicode characters 128 or greater are
* first encoded as UTF-8, then each byte is escaped individually as a 3-digit octal escape.
*/
final class TextFormatEscaper {
private TextFormatEscaper() {}
@ -41,17 +58,13 @@ final class TextFormatEscaper {
}
/**
* Escapes bytes in the format used in protocol buffer text format, which is the same as the
* format used for C string literals. All bytes that are not printable 7-bit ASCII characters are
* escaped, as well as backslash, single-quote, and double-quote characters. Characters for which
* no defined short-hand escape sequence is defined will be escaped using 3-digit octal sequences.
* Backslash escapes bytes in the format used in protocol buffer text format.
*/
static String escapeBytes(final ByteSequence input) {
static String escapeBytes(ByteSequence input) {
final StringBuilder builder = new StringBuilder(input.size());
for (int i = 0; i < input.size(); i++) {
final byte b = input.byteAt(i);
byte b = input.byteAt(i);
switch (b) {
// Java does not recognize \a or \v, apparently.
case 0x07:
builder.append("\\a");
break;
@ -100,10 +113,7 @@ final class TextFormatEscaper {
}
/**
* Escapes bytes in the format used in protocol buffer text format, which is the same as the
* format used for C string literals. All bytes that are not printable 7-bit ASCII characters are
* escaped, as well as backslash, single-quote, and double-quote characters. Characters for which
* no defined short-hand escape sequence is defined will be escaped using 3-digit octal sequences.
* Backslash escapes bytes in the format used in protocol buffer text format.
*/
static String escapeBytes(final ByteString input) {
return escapeBytes(
@ -137,16 +147,14 @@ final class TextFormatEscaper {
}
/**
* Like {@link #escapeBytes(ByteString)}, but escapes a text string. Non-ASCII characters are
* first encoded as UTF-8, then each byte is escaped individually as a 3-digit octal escape. Yes,
* it's weird.
* Like {@link #escapeBytes(ByteString)}, but escapes a text string.
*/
static String escapeText(final String input) {
static String escapeText(String input) {
return escapeBytes(ByteString.copyFromUtf8(input));
}
/** Escape double quotes and backslashes in a String for unicode output of a message. */
static String escapeDoubleQuotesAndBackslashes(final String input) {
static String escapeDoubleQuotesAndBackslashes(String input) {
return input.replace("\\", "\\\\").replace("\"", "\\\"");
}
}

@ -64,9 +64,9 @@ import java.nio.ByteBuffer;
* <em>Well Formed UTF-8 Byte Sequences</em>.
*
* <p>This class supports decoding of partial byte sequences, so that the bytes in a complete UTF-8
* byte sequences can be stored in multiple segments. Methods typically return {@link #MALFORMED} if
* the partial byte sequence is definitely not well-formed, {@link #COMPLETE} if it is well-formed
* in the absence of additional input, or if the byte sequence apparently terminated in the middle
* byte sequence can be stored in multiple segments. Methods typically return {@link #MALFORMED} if
* the partial byte sequence is definitely not well-formed; {@link #COMPLETE} if it is well-formed
* in the absence of additional input; or, if the byte sequence apparently terminated in the middle
* of a character, an opaque integer "state" value containing enough information to decode the
* character when passed to a subsequent invocation of a partial decoding method.
*

@ -170,6 +170,13 @@ public class TextFormatTest {
assertThat(javaText).isEqualTo(ALL_FIELDS_SET_TEXT);
}
@Test
// https://github.com/protocolbuffers/protobuf/issues/9447
public void testCharacterNotInUnicodeBlock() throws TextFormat.InvalidEscapeSequenceException {
ByteString actual = TextFormat.unescapeBytes("\\U000358da");
assertThat(actual.size()).isEqualTo(4);
}
/** Print TestAllTypes as Builder and compare with golden file. */
@Test
public void testPrintMessageBuilder() throws Exception {

@ -41,10 +41,61 @@ option java_generic_services = true; // auto-added
option java_package = "com.google.protobuf";
option java_outer_classname = "TestBadIdentifiersProto";
message TestMessage {
optional string cached_size = 1;
optional string serialized_size = 2;
optional string class = 3;
// Message with field names using underscores that conflict with accessors in the base message class in java.
// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc
message ForbiddenWordsUnderscoreMessage {
// java.lang.Object
optional bool class = 1;
// com.google.protobuf.MessageLiteOrBuilder
optional bool default_instance_for_type = 2;
// com.google.protobuf.MessageLite
optional bool parser_for_type = 3;
optional bool serialized_size = 4;
// com.google.protobuf.MessageOrBuilder
optional bool all_fields = 5;
optional bool descriptor_for_type = 6;
optional bool initialization_error_string = 7;
optional bool unknown_fields = 8;
// obsolete. kept for backwards compatibility of generated code
optional bool cached_size = 9;
}
// Message with field names using leading underscores that conflict with accessors in the base message class in java.
// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc
message ForbiddenWordsLeadingUnderscoreMessage {
// java.lang.Object
optional bool _class = 1;
// com.google.protobuf.MessageLiteOrBuilder
optional bool _default_instance_for_type = 2;
// com.google.protobuf.MessageLite
optional bool _parser_for_type = 3;
optional bool _serialized_size = 4;
// com.google.protobuf.MessageOrBuilder
optional bool _all_fields = 5;
optional bool _descriptor_for_type = 6;
optional bool _initialization_error_string = 7;
optional bool _unknown_fields = 8;
// obsolete. kept for backwards compatibility of generated code
optional bool _cached_size = 9;
}
// Message with field names in camel case that conflict with accessors in the base message class in java.
// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc
message ForbiddenWordsCamelMessage {
// java.lang.Object
optional bool class = 1;
// com.google.protobuf.MessageLiteOrBuilder
optional bool defaultInstanceForType = 2;
// com.google.protobuf.MessageLite
optional bool serializedSize = 3;
optional bool parserForType = 4;
// com.google.protobuf.MessageOrBuilder:
optional bool initializationErrorString = 5;
optional bool descriptorForType = 6;
optional bool allFields = 7;
optional bool unknownFields = 8;
// obsolete. kept for backwards compatibility of generated code
optional bool cachedSize = 9;
}
message Descriptor {
@ -82,7 +133,7 @@ message Deprecated {
optional int32 field1 = 1 [deprecated = true];
optional TestEnum field2 = 2 [deprecated = true];
optional TestMessage field3 = 3 [deprecated = true];
optional ForbiddenWordsUnderscoreMessage field3 = 3 [deprecated = true];
}
message Override {
@ -115,7 +166,7 @@ message Double {
}
service TestConflictingMethodNames {
rpc Override(TestMessage) returns (TestMessage);
rpc Override(ForbiddenWordsUnderscoreMessage) returns (ForbiddenWordsUnderscoreMessage);
}
message TestConflictingFieldNames {
@ -123,24 +174,24 @@ message TestConflictingFieldNames {
UNKNOWN = 0;
FOO = 1;
}
message TestMessage {}
message ForbiddenWordsUnderscoreMessage {}
repeated int32 int32_field = 1;
repeated TestEnum enum_field = 2;
repeated string string_field = 3;
repeated bytes bytes_field = 4;
repeated TestMessage message_field = 5;
repeated ForbiddenWordsUnderscoreMessage message_field = 5;
optional int32 int32_field_count = 11;
optional TestEnum enum_field_count = 12;
optional string string_field_count = 13;
optional bytes bytes_field_count = 14;
optional TestMessage message_field_count = 15;
optional ForbiddenWordsUnderscoreMessage message_field_count = 15;
repeated int32 Int32Field = 21; // NO_PROTO3
repeated TestEnum EnumField = 22; // NO_PROTO3
repeated string StringField = 23; // NO_PROTO3
repeated bytes BytesField = 24; // NO_PROTO3
repeated TestMessage MessageField = 25; // NO_PROTO3
repeated ForbiddenWordsUnderscoreMessage MessageField = 25; // NO_PROTO3
// This field conflicts with "int32_field" as they both generate
// the method getInt32FieldList().

@ -0,0 +1,45 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.protobuf.kotlin
import com.google.protobuf.Any as ProtoAny
import com.google.protobuf.Message
/** Returns `true` if this [com.google.protobuf.Any] contains a message of type `T`. */
inline fun <reified T : Message> ProtoAny.isA(): Boolean = this.`is`(T::class.java)
/**
* Returns the message of type `T` encoded in this [com.google.protobuf.Any].
*
* @throws InvalidProtocolBufferException if this [com.google.protobuf.Any] does not contain a `T`
* message.
*/
inline fun <reified T : Message> ProtoAny.unpack(): T = unpack(T::class.java)

@ -0,0 +1,70 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.protobuf.kotlin
import com.google.common.truth.Truth.assertThat
import com.google.protobuf.Any as ProtoAny
import com.google.protobuf.InvalidProtocolBufferException
import protobuf_unittest.UnittestProto.BoolMessage
import protobuf_unittest.UnittestProto.Int32Message
import protobuf_unittest.int32Message
import kotlin.test.assertFailsWith
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
/** Tests for extension methods on [ProtoAny]. */
@RunWith(JUnit4::class)
class AniesTest {
companion object {
val anAny = ProtoAny.pack(int32Message { data = 5 })
}
@Test
fun isA_Positive() {
assertThat(anAny.isA<Int32Message>()).isTrue()
}
@Test
fun isA_Negative() {
assertThat(anAny.isA<BoolMessage>()).isFalse()
}
@Test
fun unpackValid() {
assertThat(anAny.unpack<Int32Message>().data).isEqualTo(5)
}
@Test
fun unpackInvalid() {
assertFailsWith<InvalidProtocolBufferException> { anAny.unpack<BoolMessage>() }
}
}

@ -1,4 +1,7 @@
FROM debian:stretch
# Despite the name of this image, we are no longer on stretch.
# We should consider renaming this image, and/or evaluating what
# software versions we actually need.
FROM debian:bullseye
# Install dependencies. We start with the basic ones required to build protoc
# and the C++ build
@ -22,9 +25,11 @@ RUN apt-get update && apt-get install -y \
wget \
# Java dependencies
maven \
openjdk-8-jdk \
openjdk-11-jdk \
# Required for the gtest build.
python2 \
# Python dependencies
python3-setuptools \
python3-pip \
virtualenv \
python3-venv \
&& apt-get clean

@ -1,18 +0,0 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "pull request" project:
#
# This script selects a specific Dockerfile (for building a Docker image) and
# a script to run inside that image. Then we delegate to the general
# build_and_run_docker.sh script.
# Change to repo root
cd $(dirname $0)/../../..
export DOCKERHUB_ORGANIZATION=protobuftesting
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python36
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
export OUTPUT_DIR=testoutput
export TEST_SET="python36"
./kokoro/linux/build_and_run_docker.sh

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,18 +0,0 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "pull request" project:
#
# This script selects a specific Dockerfile (for building a Docker image) and
# a script to run inside that image. Then we delegate to the general
# build_and_run_docker.sh script.
# Change to repo root
cd $(dirname $0)/../../..
export DOCKERHUB_ORGANIZATION=protobuftesting
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python36
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
export OUTPUT_DIR=testoutput
export TEST_SET="python36_cpp"
./kokoro/linux/build_and_run_docker.sh

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36_cpp/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36_cpp/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -40,16 +40,6 @@ mkdir %ARTIFACT_DIR%
REM Build wheel
SET PYTHON=C:\python36_32bit
SET PYTHON_VERSION=3.6
SET PYTHON_ARCH=32
CALL build_single_artifact.bat || goto :error
SET PYTHON=C:\python36
SET PYTHON_VERSION=3.6
SET PYTHON_ARCH=64
CALL build_single_artifact.bat || goto :error
SET PYTHON=C:\python37_32bit
SET PYTHON_VERSION=3.7
SET PYTHON_ARCH=32

@ -1,11 +1,5 @@
setlocal
if %PYTHON%==C:\python36_32bit set generator=Visual Studio 14
if %PYTHON%==C:\python36_32bit set vcplatform=Win32
if %PYTHON%==C:\python36 set generator=Visual Studio 14 Win64
if %PYTHON%==C:\python36 set vcplatform=x64
if %PYTHON%==C:\python37_32bit set generator=Visual Studio 14
if %PYTHON%==C:\python37_32bit set vcplatform=Win32

@ -133,8 +133,8 @@ This options allow you to provide a custom prefix for all the symbols generated
from a proto file (classes (from message), enums, the Root for extension
support).
If not set, the generation option `use_package_as_prefix` (documented below)
controls what is used instead. Since Objective C uses a global namespace for all
If not set, the generation options `default_objc_class_prefix` and `use_package_as_prefix`
(documented below) control what is used instead. Since Objective C uses a global namespace for all
of its classes, there can be collisions. `use_package_as_prefix=yes` should
avoid collisions since proto package are used to scope/name things in other
languages, but this option can be used to get shorter names instead. Convention
@ -182,6 +182,12 @@ supported keys are:
having to add the runtime directory to the header search path since the
generate `#import` will be more complete.
* `default_objc_class_prefix`: The default ObjC prefix value to use when
generating sources. The generator will use this if the `objc_class_prefix`
file option is not set. This option can be useful if multiple iOS apps
consume the same proto file but wish to use a different prefix for their
generated sources.
* `use_package_as_prefix` and `proto_package_prefix_exceptions_path`: The
`value` for `use_package_as_prefix` can be `yes` or `no`, and indicates
if a prefix should be derived from the proto package for all the symbols

@ -71,22 +71,23 @@ static void stringsink_uninit(stringsink *sink) { free(sink->ptr); }
/* def name -> classname ******************************************************/
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",
"finally", "fn", "for", "foreach", "function",
"if", "implements", "include", "include_once", "instanceof",
"global", "goto", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "object",
"or", "print", "private", "protected", "public",
"require", "require_once", "return", "static", "switch",
"throw", "trait", "try", "unset", "use",
"var", "while", "xor", "yield", "int",
"float", "bool", "string", "true", "false",
"null", "void", "iterable", NULL};
"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",
"finally", "fn", "for", "foreach", "function",
"if", "implements", "include", "include_once", "instanceof",
"global", "goto", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "object",
"or", "parent", "print", "private", "protected",
"public", "require", "require_once", "return", "self",
"static", "switch", "throw", "trait", "try",
"unset", "use", "var", "while", "xor",
"yield", "int", "float", "bool", "string",
"true", "false", "null", "void", "iterable",
NULL};
bool is_reserved_name(const char* name) {
int i;

@ -159,7 +159,7 @@ class DescriptorPool
if (is_null($subdesc)) {
trigger_error(
'proto not added: ' . $proto
. " for " . $desc->getFullName(), E_ERROR);
. " for " . $desc->getFullName(), E_USER_ERROR);
}
$field->setMessageType($subdesc);
break;

@ -284,12 +284,12 @@ class GPBUtil
"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, "match"=>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, "yield"=>0,
"int"=>0, "float"=>0, "bool"=>0, "string"=>0, "true"=>0, "false"=>0,
"null"=>0, "void"=>0, "iterable"=>0
"new"=>0, "or"=>0, "parent"=>0, "print"=>0, "private"=>0,
"protected"=>0,"public"=>0, "require"=>0, "require_once"=>0,
"return"=>0, "self"=>0, "static"=>0, "switch"=>0, "throw"=>0,
"trait"=>0, "try"=>0,"unset"=>0, "use"=>0, "var"=>0, "while"=>0,
"xor"=>0, "yield"=>0, "int"=>0, "float"=>0, "bool"=>0, "string"=>0,
"true"=>0, "false"=>0, "null"=>0, "void"=>0, "iterable"=>0
);
if (array_key_exists(strtolower($classname), $reserved_words)) {

@ -423,7 +423,7 @@ class Message
}
break;
case GPBType::GROUP:
trigger_error("Not implemented.", E_ERROR);
trigger_error("Not implemented.", E_USER_ERROR);
break;
case GPBType::MESSAGE:
if ($field->isMap()) {

@ -934,6 +934,7 @@ class GeneratedClassTest extends TestBase
$m = new \Lower\PBnamespace();
$m = new \Lower\PBnew();
$m = new \Lower\PBor();
$m = new \Lower\PBparent();
$m = new \Lower\PBprint();
$m = new \Lower\PBprivate();
$m = new \Lower\PBprotected();
@ -941,6 +942,7 @@ class GeneratedClassTest extends TestBase
$m = new \Lower\PBrequire();
$m = new \Lower\PBrequire_once();
$m = new \Lower\PBreturn();
$m = new \Lower\PBself();
$m = new \Lower\PBstatic();
$m = new \Lower\PBswitch();
$m = new \Lower\PBthrow();
@ -1012,6 +1014,7 @@ class GeneratedClassTest extends TestBase
$m = new \Upper\PBNAMESPACE();
$m = new \Upper\PBNEW();
$m = new \Upper\PBOR();
$m = new \Upper\PBPARENT();
$m = new \Upper\PBPRINT();
$m = new \Upper\PBPRIVATE();
$m = new \Upper\PBPROTECTED();
@ -1019,6 +1022,7 @@ class GeneratedClassTest extends TestBase
$m = new \Upper\PBREQUIRE();
$m = new \Upper\PBREQUIRE_ONCE();
$m = new \Upper\PBRETURN();
$m = new \Upper\PBSELF();
$m = new \Upper\PBSTATIC();
$m = new \Upper\PBSWITCH();
$m = new \Upper\PBTHROW();
@ -1090,6 +1094,7 @@ class GeneratedClassTest extends TestBase
$m = new \Lower_enum\PBnamespace();
$m = new \Lower_enum\PBnew();
$m = new \Lower_enum\PBor();
$m = new \Lower_enum\PBparent();
$m = new \Lower_enum\PBprint();
$m = new \Lower_enum\PBprivate();
$m = new \Lower_enum\PBprotected();
@ -1097,6 +1102,7 @@ class GeneratedClassTest extends TestBase
$m = new \Lower_enum\PBrequire();
$m = new \Lower_enum\PBrequire_once();
$m = new \Lower_enum\PBreturn();
$m = new \Lower_enum\PBself();
$m = new \Lower_enum\PBstatic();
$m = new \Lower_enum\PBswitch();
$m = new \Lower_enum\PBthrow();
@ -1168,6 +1174,7 @@ class GeneratedClassTest extends TestBase
$m = new \Upper_enum\PBNAMESPACE();
$m = new \Upper_enum\PBNEW();
$m = new \Upper_enum\PBOR();
$m = new \Upper_enum\PBPARENT();
$m = new \Upper_enum\PBPRINT();
$m = new \Upper_enum\PBPRIVATE();
$m = new \Upper_enum\PBPROTECTED();
@ -1175,6 +1182,7 @@ class GeneratedClassTest extends TestBase
$m = new \Upper_enum\PBREQUIRE();
$m = new \Upper_enum\PBREQUIRE_ONCE();
$m = new \Upper_enum\PBRETURN();
$m = new \Upper_enum\PBSELF();
$m = new \Upper_enum\PBSTATIC();
$m = new \Upper_enum\PBSWITCH();
$m = new \Upper_enum\PBTHROW();
@ -1273,6 +1281,8 @@ class GeneratedClassTest extends TestBase
$m = \Lower_enum_value\NotAllowed::null;
$m = \Lower_enum_value\NotAllowed::void;
$m = \Lower_enum_value\NotAllowed::iterable;
$m = \Lower_enum_value\NotAllowed::parent;
$m = \Lower_enum_value\NotAllowed::self;
$m = \Upper_enum_value\NotAllowed::PBABSTRACT;
$m = \Upper_enum_value\NotAllowed::PBAND;
@ -1351,6 +1361,8 @@ class GeneratedClassTest extends TestBase
$m = \Upper_enum_value\NotAllowed::NULL;
$m = \Upper_enum_value\NotAllowed::VOID;
$m = \Upper_enum_value\NotAllowed::ITERABLE;
$m = \Upper_enum_value\NotAllowed::PARENT;
$m = \Upper_enum_value\NotAllowed::SELF;
$this->assertTrue(true);
}

@ -52,6 +52,7 @@ enum match { ZERO47 = 0; }
enum namespace { ZERO48 = 0; }
enum new { ZERO49 = 0; }
enum or { ZERO50 = 0; }
enum parent { ZERO78 = 0; }
enum print { ZERO51 = 0; }
enum private { ZERO52 = 0; }
enum protected { ZERO53 = 0; }
@ -59,6 +60,7 @@ enum public { ZERO54 = 0; }
enum require { ZERO55 = 0; }
enum require_once { ZERO56 = 0; }
enum return { ZERO57 = 0; }
enum self { ZERO79 = 0; }
enum static { ZERO58 = 0; }
enum switch { ZERO59 = 0; }
enum throw { ZERO60 = 0; }

@ -52,6 +52,7 @@ enum MATCH { ZERO47 = 0; }
enum NAMESPACE { ZERO48 = 0; }
enum NEW { ZERO49 = 0; }
enum OR { ZERO50 = 0; }
enum PARENT { ZERO78 = 0; }
enum PRINT { ZERO51 = 0; }
enum PRIVATE { ZERO52 = 0; }
enum PROTECTED { ZERO53 = 0; }
@ -59,6 +60,7 @@ enum PUBLIC { ZERO54 = 0; }
enum REQUIRE { ZERO55 = 0; }
enum REQUIRE_ONCE { ZERO56 = 0; }
enum RETURN { ZERO57 = 0; }
enum SELF { ZERO79 = 0; }
enum STATIC { ZERO58 = 0; }
enum SWITCH { ZERO59 = 0; }
enum THROW { ZERO60 = 0; }

@ -53,6 +53,7 @@ enum NotAllowed {
namespace = 47;
new = 48;
or = 49;
parent = 77;
print = 50;
private = 51;
protected = 52;
@ -60,6 +61,7 @@ enum NotAllowed {
require = 54;
require_once = 55;
return = 56;
self = 78;
static = 57;
switch = 58;
throw = 59;

@ -53,6 +53,7 @@ enum NotAllowed {
NAMESPACE = 47;
NEW = 48;
OR = 49;
PARENT = 77;
PRINT = 50;
PRIVATE = 51;
PROTECTED = 52;
@ -60,6 +61,7 @@ enum NotAllowed {
REQUIRE = 54;
REQUIRE_ONCE = 55;
RETURN = 56;
SELF = 78;
STATIC = 57;
SWITCH = 58;
THROW = 59;

@ -52,6 +52,7 @@ message match {}
message namespace {}
message new {}
message or {}
message parent {}
message print {}
message private {}
message protected {}
@ -59,6 +60,7 @@ message public {}
message require {}
message require_once {}
message return {}
message self {}
message static {}
message switch {}
message throw {}

@ -52,6 +52,7 @@ message MATCH {}
message NAMESPACE {}
message NEW {}
message OR {}
message PARENT {}
message PRINT {}
message PRIVATE {}
message PROTECTED {}
@ -59,6 +60,7 @@ message PUBLIC {}
message REQUIRE {}
message REQUIRE_ONCE {}
message RETURN {}
message SELF {}
message STATIC {}
message SWITCH {}
message THROW {}

@ -26,7 +26,7 @@ use python c++ implementation.
Installation
============
1) Make sure you have Python 3.5 or newer. If in doubt, run:
1) Make sure you have Python 3.7 or newer. If in doubt, run:
$ python -V

@ -541,7 +541,13 @@ class DescriptorPoolTestBase(object):
pool._AddExtensionDescriptor(
file_descriptor.extensions_by_name['optional_int32_extension'])
pool.Add(unittest_fd)
pool.Add(conflict_fd)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
pool.Add(conflict_fd)
self.assertTrue(len(w))
self.assertIs(w[0].category, RuntimeWarning)
self.assertIn('Conflict register for file "other_file": ',
str(w[0].message))
pool.FindFileByName(unittest_fd.name)
with self.assertRaises(TypeError):
pool.FindFileByName(conflict_fd.name)

@ -95,7 +95,8 @@ def MessageToJson(
sort_keys=False,
use_integers_for_enums=False,
descriptor_pool=None,
float_precision=None):
float_precision=None,
ensure_ascii=True):
"""Converts protobuf message to JSON format.
Args:
@ -114,6 +115,8 @@ def MessageToJson(
descriptor_pool: A Descriptor Pool for resolving types. If None use the
default.
float_precision: If set, use this to specify float field valid digits.
ensure_ascii: If True, strings with non-ASCII characters are escaped.
If False, Unicode strings are returned unchanged.
Returns:
A string containing the JSON formatted protocol buffer message.
@ -124,7 +127,7 @@ def MessageToJson(
use_integers_for_enums,
descriptor_pool,
float_precision=float_precision)
return printer.ToJsonString(message, indent, sort_keys)
return printer.ToJsonString(message, indent, sort_keys, ensure_ascii)
def MessageToDict(
@ -190,9 +193,10 @@ class _Printer(object):
else:
self.float_format = None
def ToJsonString(self, message, indent, sort_keys):
def ToJsonString(self, message, indent, sort_keys, ensure_ascii):
js = self._MessageToJsonObject(message)
return json.dumps(js, indent=indent, sort_keys=sort_keys)
return json.dumps(
js, indent=indent, sort_keys=sort_keys, ensure_ascii=ensure_ascii)
def _MessageToJsonObject(self, message):
"""Converts message to an object according to Proto3 JSON Specification."""

@ -1002,7 +1002,7 @@ int DeleteRepeatedField(
}
}
Arena* arena = Arena::InternalHelper<Message>::GetArenaForAllocation(message);
Arena* arena = Arena::InternalGetArenaForAllocation(message);
GOOGLE_DCHECK_EQ(arena, nullptr)
<< "python protobuf is expected to be allocated from heap";
// Remove items, starting from the end.

@ -138,8 +138,9 @@ static void Dealloc(PyObject* pself) {
reinterpret_cast<CMessage*>(self->parent)->unknown_field_set = nullptr;
}
Py_CLEAR(self->parent);
auto* py_type = Py_TYPE(pself);
self->~PyUnknownFields();
Py_TYPE(pself)->tp_free(pself);
py_type->tp_free(pself);
}
static PySequenceMethods SqMethods = {

@ -133,7 +133,7 @@ class _ServiceBuilder(object):
"""
self.descriptor = service_descriptor
def BuildService(self, cls):
def BuildService(builder, cls):
"""Constructs the service class.
Args:
@ -143,18 +143,25 @@ class _ServiceBuilder(object):
# CallMethod needs to operate with an instance of the Service class. This
# internal wrapper function exists only to be able to pass the service
# instance to the method that does the real CallMethod work.
def _WrapCallMethod(srvc, method_descriptor,
rpc_controller, request, callback):
return self._CallMethod(srvc, method_descriptor,
rpc_controller, request, callback)
self.cls = cls
# Making sure to use exact argument names from the abstract interface in
# service.py to match the type signature
def _WrapCallMethod(self, method_descriptor,
rpc_controller, request, done):
return builder._CallMethod(self, method_descriptor,
rpc_controller, request, done)
def _WrapGetRequestClass(self, method_descriptor):
return builder._GetRequestClass(method_descriptor)
def _WrapGetResponseClass(self, method_descriptor):
return builder._GetResponseClass(method_descriptor)
builder.cls = cls
cls.CallMethod = _WrapCallMethod
cls.GetDescriptor = staticmethod(lambda: self.descriptor)
cls.GetDescriptor = staticmethod(lambda: builder.descriptor)
cls.GetDescriptor.__doc__ = "Returns the service descriptor."
cls.GetRequestClass = self._GetRequestClass
cls.GetResponseClass = self._GetResponseClass
for method in self.descriptor.methods:
setattr(cls, method.name, self._GenerateNonImplementedMethod(method))
cls.GetRequestClass = _WrapGetRequestClass
cls.GetResponseClass = _WrapGetResponseClass
for method in builder.descriptor.methods:
setattr(cls, method.name, builder._GenerateNonImplementedMethod(method))
def _CallMethod(self, srvc, method_descriptor,
rpc_controller, request, callback):

@ -301,11 +301,10 @@ if __name__ == '__main__':
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
namespace_packages=['google'],
packages=find_packages(
@ -322,5 +321,5 @@ if __name__ == '__main__':
},
install_requires=install_requires,
ext_modules=ext_module_list,
python_requires=">=3.5",
python_requires=">=3.7",
)

@ -1,6 +1,6 @@
[tox]
envlist =
py{35,36,37,38,39,310}-{cpp,python}
py{37,38,39,310}-{cpp,python}
[testenv]
usedevelop=true
@ -14,7 +14,7 @@ setenv =
commands =
python setup.py -q build_py
python: python setup.py -q build
py{35,36,37,38,39,310}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension
py{37,38,39,310}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension
python: python setup.py -q test -q
cpp: python setup.py -q test -q --cpp_implementation
python: python setup.py -q test_conformance

@ -953,13 +953,35 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
/*
* call-seq:
* MessageClass.decode(data) => message
* MessageClass.decode(data, options) => message
*
* Decodes the given data (as a string containing bytes in protocol buffers wire
* format) under the interpretration given by this message class's definition
* and returns a message object with the corresponding field values.
* @param options [Hash] options for the decoder
* recursion_limit: set to maximum decoding depth for message (default is 64)
*/
static VALUE Message_decode(VALUE klass, VALUE data) {
static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) {
VALUE data = argv[0];
int options = 0;
if (argc < 1 || argc > 2) {
rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
}
if (argc == 2) {
VALUE hash_args = argv[1];
if (TYPE(hash_args) != T_HASH) {
rb_raise(rb_eArgError, "Expected hash arguments.");
}
VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
}
}
if (TYPE(data) != T_STRING) {
rb_raise(rb_eArgError, "Expected string for binary protobuf data.");
}
@ -969,7 +991,7 @@ static VALUE Message_decode(VALUE klass, VALUE data) {
upb_DecodeStatus status = upb_Decode(
RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg,
upb_MessageDef_MiniTable(msg->msgdef), NULL, 0, Arena_get(msg->arena));
upb_MessageDef_MiniTable(msg->msgdef), NULL, options, Arena_get(msg->arena));
if (status != kUpb_DecodeStatus_Ok) {
rb_raise(cParseError, "Error occurred during parsing");
@ -1043,24 +1065,43 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) {
/*
* call-seq:
* MessageClass.encode(msg) => bytes
* MessageClass.encode(msg, options) => bytes
*
* Encodes the given message object to its serialized form in protocol buffers
* wire format.
* @param options [Hash] options for the encoder
* recursion_limit: set to maximum encoding depth for message (default is 64)
*/
static VALUE Message_encode(VALUE klass, VALUE msg_rb) {
Message* msg = ruby_to_Message(msg_rb);
static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) {
Message* msg = ruby_to_Message(argv[0]);
int options = 0;
const char* data;
size_t size;
if (CLASS_OF(msg_rb) != klass) {
if (CLASS_OF(argv[0]) != klass) {
rb_raise(rb_eArgError, "Message of wrong type.");
}
upb_Arena* arena = upb_Arena_New();
if (argc < 1 || argc > 2) {
rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
}
data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), 0, arena,
&size);
if (argc == 2) {
VALUE hash_args = argv[1];
if (TYPE(hash_args) != T_HASH) {
rb_raise(rb_eArgError, "Expected hash arguments.");
}
VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit")));
if (depth != Qnil && TYPE(depth) == T_FIXNUM) {
options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth));
}
}
upb_Arena *arena = upb_Arena_New();
data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef),
options, arena, &size);
if (data) {
VALUE ret = rb_str_new(data, size);
@ -1186,8 +1227,8 @@ VALUE build_class_from_descriptor(VALUE descriptor) {
rb_define_method(klass, "to_s", Message_inspect, 0);
rb_define_method(klass, "[]", Message_index, 1);
rb_define_method(klass, "[]=", Message_index_set, 2);
rb_define_singleton_method(klass, "decode", Message_decode, 1);
rb_define_singleton_method(klass, "encode", Message_encode, 1);
rb_define_singleton_method(klass, "decode", Message_decode, -1);
rb_define_singleton_method(klass, "encode", Message_encode, -1);
rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);

@ -59,16 +59,16 @@ require 'google/protobuf/repeated_field'
module Google
module Protobuf
def self.encode(msg)
msg.to_proto
def self.encode(msg, options = {})
msg.to_proto(options)
end
def self.encode_json(msg, options = {})
msg.to_json(options)
end
def self.decode(klass, proto)
klass.decode(proto)
def self.decode(klass, proto, options = {})
klass.decode(proto, options)
end
def self.decode_json(klass, json, options = {})

@ -44,8 +44,8 @@ module Google
self.class.encode_json(self, options)
end
def to_proto
self.class.encode(self)
def to_proto(options = {})
self.class.encode(self, options)
end
end

@ -389,7 +389,7 @@ public class RubyMap extends RubyObject {
return newMap;
}
protected List<DynamicMessage> build(ThreadContext context, RubyDescriptor descriptor, int depth) {
protected List<DynamicMessage> build(ThreadContext context, RubyDescriptor descriptor, int depth, int recursionLimit) {
List<DynamicMessage> list = new ArrayList<DynamicMessage>();
RubyClass rubyClass = (RubyClass) descriptor.msgclass(context);
FieldDescriptor keyField = descriptor.getField("key");
@ -398,7 +398,7 @@ public class RubyMap extends RubyObject {
RubyMessage mapMessage = (RubyMessage) rubyClass.newInstance(context, Block.NULL_BLOCK);
mapMessage.setField(context, keyField, key);
mapMessage.setField(context, valueField, table.get(key));
list.add(mapMessage.build(context, depth + 1));
list.add(mapMessage.build(context, depth + 1, recursionLimit));
}
return list;
}

@ -39,6 +39,7 @@ import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.OneofDescriptor;
import com.google.protobuf.ByteString;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.DynamicMessage;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
@ -461,35 +462,63 @@ public class RubyMessage extends RubyObject {
/*
* call-seq:
* MessageClass.encode(msg) => bytes
* MessageClass.encode(msg, options = {}) => bytes
*
* Encodes the given message object to its serialized form in protocol buffers
* wire format.
* @param options [Hash] options for the encoder
* recursion_limit: set to maximum encoding depth for message (default is 64)
*/
@JRubyMethod(meta = true)
public static IRubyObject encode(ThreadContext context, IRubyObject recv, IRubyObject value) {
if (recv != value.getMetaClass()) {
throw context.runtime.newArgumentError("Tried to encode a " + value.getMetaClass() + " message with " + recv);
@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject encode(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
if (recv != args[0].getMetaClass()) {
throw context.runtime.newArgumentError("Tried to encode a " + args[0].getMetaClass() + " message with " + recv);
}
RubyMessage message = (RubyMessage) value;
return context.runtime.newString(new ByteList(message.build(context).toByteArray()));
RubyMessage message = (RubyMessage) args[0];
int recursionLimitInt = SINK_MAXIMUM_NESTING;
if (args.length > 1) {
RubyHash options = (RubyHash) args[1];
IRubyObject recursionLimit = options.fastARef(context.runtime.newSymbol("recursion_limit"));
if (recursionLimit != null) {
recursionLimitInt = ((RubyNumeric) recursionLimit).getIntValue();
}
}
return context.runtime.newString(new ByteList(message.build(context, 0, recursionLimitInt).toByteArray()));
}
/*
* call-seq:
* MessageClass.decode(data) => message
* MessageClass.decode(data, options = {}) => message
*
* Decodes the given data (as a string containing bytes in protocol buffers wire
* format) under the interpretation given by this message class's definition
* and returns a message object with the corresponding field values.
* @param options [Hash] options for the decoder
* recursion_limit: set to maximum decoding depth for message (default is 100)
*/
@JRubyMethod(meta = true)
public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyObject data) {
@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
IRubyObject data = args[0];
byte[] bin = data.convertToString().getBytes();
CodedInputStream input = CodedInputStream.newInstance(bin);
RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK);
if (args.length == 2) {
if (!(args[1] instanceof RubyHash)) {
throw context.runtime.newArgumentError("Expected hash arguments.");
}
IRubyObject recursionLimit = ((RubyHash) args[1]).fastARef(context.runtime.newSymbol("recursion_limit"));
if (recursionLimit != null) {
input.setRecursionLimit(((RubyNumeric) recursionLimit).getIntValue());
}
}
try {
ret.builder.mergeFrom(bin);
} catch (InvalidProtocolBufferException e) {
ret.builder.mergeFrom(input);
} catch (Exception e) {
throw RaiseException.from(context.runtime, (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::ParseError"), e.getMessage());
}
@ -541,7 +570,7 @@ public class RubyMessage extends RubyObject {
printer = printer.usingTypeRegistry(JsonFormat.TypeRegistry.newBuilder().add(message.descriptor).build());
try {
result = printer.print(message.build(context));
result = printer.print(message.build(context, 0, SINK_MAXIMUM_NESTING));
} catch (InvalidProtocolBufferException e) {
throw runtime.newRuntimeError(e.getMessage());
} catch (IllegalArgumentException e) {
@ -635,13 +664,9 @@ public class RubyMessage extends RubyObject {
return ret;
}
protected DynamicMessage build(ThreadContext context) {
return build(context, 0);
}
protected DynamicMessage build(ThreadContext context, int depth) {
if (depth > SINK_MAXIMUM_NESTING) {
throw context.runtime.newRuntimeError("Maximum recursion depth exceeded during encoding.");
protected DynamicMessage build(ThreadContext context, int depth, int recursionLimit) {
if (depth >= recursionLimit) {
throw context.runtime.newRuntimeError("Recursion limit exceeded during encoding.");
}
// Handle the typical case where the fields.keySet contain the fieldDescriptors
@ -651,7 +676,7 @@ public class RubyMessage extends RubyObject {
if (value instanceof RubyMap) {
builder.clearField(fieldDescriptor);
RubyDescriptor mapDescriptor = (RubyDescriptor) getDescriptorForField(context, fieldDescriptor);
for (DynamicMessage kv : ((RubyMap) value).build(context, mapDescriptor, depth)) {
for (DynamicMessage kv : ((RubyMap) value).build(context, mapDescriptor, depth, recursionLimit)) {
builder.addRepeatedField(fieldDescriptor, kv);
}
@ -660,7 +685,7 @@ public class RubyMessage extends RubyObject {
builder.clearField(fieldDescriptor);
for (int i = 0; i < repeatedField.size(); i++) {
Object item = convert(context, fieldDescriptor, repeatedField.get(i), depth,
Object item = convert(context, fieldDescriptor, repeatedField.get(i), depth, recursionLimit,
/*isDefaultValueForBytes*/ false);
builder.addRepeatedField(fieldDescriptor, item);
}
@ -682,7 +707,7 @@ public class RubyMessage extends RubyObject {
fieldDescriptor.getFullName().equals("google.protobuf.FieldDescriptorProto.default_value")) {
isDefaultStringForBytes = true;
}
builder.setField(fieldDescriptor, convert(context, fieldDescriptor, value, depth, isDefaultStringForBytes));
builder.setField(fieldDescriptor, convert(context, fieldDescriptor, value, depth, recursionLimit, isDefaultStringForBytes));
}
}
@ -702,7 +727,7 @@ public class RubyMessage extends RubyObject {
builder.clearField(fieldDescriptor);
RubyDescriptor mapDescriptor = (RubyDescriptor) getDescriptorForField(context,
fieldDescriptor);
for (DynamicMessage kv : ((RubyMap) value).build(context, mapDescriptor, depth)) {
for (DynamicMessage kv : ((RubyMap) value).build(context, mapDescriptor, depth, recursionLimit)) {
builder.addRepeatedField(fieldDescriptor, kv);
}
}
@ -814,7 +839,8 @@ public class RubyMessage extends RubyObject {
// convert a ruby object to protobuf type, skip type check since it is checked on the way in
private Object convert(ThreadContext context,
FieldDescriptor fieldDescriptor,
IRubyObject value, int depth, boolean isDefaultStringForBytes) {
IRubyObject value, int depth, int recursionLimit,
boolean isDefaultStringForBytes) {
Object val = null;
switch (fieldDescriptor.getType()) {
case INT32:
@ -855,7 +881,7 @@ public class RubyMessage extends RubyObject {
}
break;
case MESSAGE:
val = ((RubyMessage) value).build(context, depth + 1);
val = ((RubyMessage) value).build(context, depth + 1, recursionLimit);
break;
case ENUM:
EnumDescriptor enumDescriptor = fieldDescriptor.getEnumType();
@ -1214,7 +1240,7 @@ public class RubyMessage extends RubyObject {
private static final String CONST_SUFFIX = "_const";
private static final String HAS_PREFIX = "has_";
private static final String QUESTION_MARK = "?";
private static final int SINK_MAXIMUM_NESTING = 63;
private static final int SINK_MAXIMUM_NESTING = 64;
private Descriptor descriptor;
private DynamicMessage.Builder builder;

@ -1245,7 +1245,7 @@ module CommonTests
struct = struct_from_ruby(JSON.parse(json))
assert_equal json, struct.to_json
assert_raise(RuntimeError, "Maximum recursion depth exceeded during encoding") do
assert_raise(RuntimeError, "Recursion limit exceeded during encoding") do
struct = Google::Protobuf::Struct.new
struct.fields["foobar"] = Google::Protobuf::Value.new(struct_value: struct)
Google::Protobuf::Struct.encode(struct)

@ -101,4 +101,55 @@ class EncodeDecodeTest < Test::Unit::TestCase
assert_match json, "{\"CustomJsonName\":42}"
end
def test_decode_depth_limit
msg = A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
)
)
)
)
)
)
msg_encoded = A::B::C::TestMessage.encode(msg)
msg_out = A::B::C::TestMessage.decode(msg_encoded)
assert_match msg.to_json, msg_out.to_json
assert_raise Google::Protobuf::ParseError do
A::B::C::TestMessage.decode(msg_encoded, { recursion_limit: 4 })
end
msg_out = A::B::C::TestMessage.decode(msg_encoded, { recursion_limit: 5 })
assert_match msg.to_json, msg_out.to_json
end
def test_encode_depth_limit
msg = A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
optional_msg: A::B::C::TestMessage.new(
)
)
)
)
)
)
msg_encoded = A::B::C::TestMessage.encode(msg)
msg_out = A::B::C::TestMessage.decode(msg_encoded)
assert_match msg.to_json, msg_out.to_json
assert_raise RuntimeError do
A::B::C::TestMessage.encode(msg, { recursion_limit: 5 })
end
msg_encoded = A::B::C::TestMessage.encode(msg, { recursion_limit: 6 })
msg_out = A::B::C::TestMessage.decode(msg_encoded)
assert_match msg.to_json, msg_out.to_json
end
end

@ -49,10 +49,8 @@ bool AnyMetadata::PackFrom(Arena* arena, const Message& message) {
bool AnyMetadata::PackFrom(Arena* arena, const Message& message,
StringPiece type_url_prefix) {
type_url_->Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString(),
GetTypeUrl(message.GetDescriptor()->full_name(), type_url_prefix), arena);
return message.SerializeToString(
value_->Mutable(ArenaStringPtr::EmptyDefault{}, arena));
return message.SerializeToString(value_->Mutable(arena));
}
bool AnyMetadata::UnpackTo(Message* message) const {

@ -119,18 +119,18 @@ Any::Any(const Any& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_type_url().empty()) {
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_type_url(),
type_url_.Set(from._internal_type_url(),
GetArenaForAllocation());
}
value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_value().empty()) {
value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_value(),
value_.Set(from._internal_value(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
@ -139,11 +139,11 @@ Any::Any(const Any& from)
inline void Any::SharedCtor() {
type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
@ -158,8 +158,8 @@ Any::~Any() {
inline void Any::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
type_url_.Destroy();
value_.Destroy();
}
void Any::SetCachedSize(int size) const {
@ -325,12 +325,10 @@ void Any::InternalSwap(Any* other) {
auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&type_url_, lhs_arena,
&other->type_url_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&value_, lhs_arena,
&other->value_, rhs_arena
);

@ -275,7 +275,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Any::set_type_url(ArgT0&& arg0, ArgT... args) {
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Any.type_url)
}
inline std::string* Any::mutable_type_url() {
@ -288,15 +288,15 @@ inline const std::string& Any::_internal_type_url() const {
}
inline void Any::_internal_set_type_url(const std::string& value) {
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
type_url_.Set(value, GetArenaForAllocation());
}
inline std::string* Any::_internal_mutable_type_url() {
return type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return type_url_.Mutable(GetArenaForAllocation());
}
inline std::string* Any::release_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.type_url)
return type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return type_url_.Release();
}
inline void Any::set_allocated_type_url(std::string* type_url) {
if (type_url != nullptr) {
@ -304,11 +304,10 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
} else {
}
type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url,
GetArenaForAllocation());
type_url_.SetAllocated(type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (type_url_.IsDefault()) {
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
type_url_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
@ -326,7 +325,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Any::set_value(ArgT0&& arg0, ArgT... args) {
value_.SetBytes(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
value_.SetBytes(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Any.value)
}
inline std::string* Any::mutable_value() {
@ -339,15 +338,15 @@ inline const std::string& Any::_internal_value() const {
}
inline void Any::_internal_set_value(const std::string& value) {
value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
value_.Set(value, GetArenaForAllocation());
}
inline std::string* Any::_internal_mutable_value() {
return value_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return value_.Mutable(GetArenaForAllocation());
}
inline std::string* Any::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.value)
return value_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return value_.Release();
}
inline void Any::set_allocated_value(std::string* value) {
if (value != nullptr) {
@ -355,11 +354,10 @@ inline void Any::set_allocated_value(std::string* value) {
} else {
}
value_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value,
GetArenaForAllocation());
value_.SetAllocated(value, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (value_.IsDefault()) {
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
value_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)

@ -55,10 +55,8 @@ const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/";
bool AnyMetadata::InternalPackFrom(Arena* arena, const MessageLite& message,
StringPiece type_url_prefix,
StringPiece type_name) {
type_url_->Set(&::google::protobuf::internal::GetEmptyString(),
GetTypeUrl(type_name, type_url_prefix), arena);
return message.SerializeToString(
value_->Mutable(ArenaStringPtr::EmptyDefault{}, arena));
type_url_->Set(GetTypeUrl(type_name, type_url_prefix), arena);
return message.SerializeToString(value_->Mutable(arena));
}
bool AnyMetadata::InternalUnpackTo(StringPiece type_name,

@ -204,18 +204,18 @@ Api::Api(const Api& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
version_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
version_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_version().empty()) {
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_version(),
version_.Set(from._internal_version(),
GetArenaForAllocation());
}
if (from._internal_has_source_context()) {
@ -230,11 +230,11 @@ Api::Api(const Api& from)
inline void Api::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
version_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&source_context_) - reinterpret_cast<char*>(this)),
@ -253,8 +253,8 @@ Api::~Api() {
inline void Api::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
version_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
version_.Destroy();
if (this != internal_default_instance()) delete source_context_;
}
@ -574,12 +574,10 @@ void Api::InternalSwap(Api* other) {
options_.InternalSwap(&other->options_);
mixins_.InternalSwap(&other->mixins_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&version_, lhs_arena,
&other->version_, rhs_arena
);
@ -619,26 +617,26 @@ Method::Method(const Method& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
request_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
request_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_request_type_url().empty()) {
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_request_type_url(),
request_type_url_.Set(from._internal_request_type_url(),
GetArenaForAllocation());
}
response_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
response_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_response_type_url().empty()) {
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_response_type_url(),
response_type_url_.Set(from._internal_response_type_url(),
GetArenaForAllocation());
}
::memcpy(&request_streaming_, &from.request_streaming_,
@ -650,15 +648,15 @@ Method::Method(const Method& from)
inline void Method::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
request_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
response_type_url_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&request_streaming_) - reinterpret_cast<char*>(this)),
@ -677,9 +675,9 @@ Method::~Method() {
inline void Method::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
request_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
response_type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
request_type_url_.Destroy();
response_type_url_.Destroy();
}
void Method::SetCachedSize(int size) const {
@ -984,17 +982,14 @@ void Method::InternalSwap(Method* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
options_.InternalSwap(&other->options_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&request_type_url_, lhs_arena,
&other->request_type_url_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&response_type_url_, lhs_arena,
&other->response_type_url_, rhs_arena
);
@ -1029,18 +1024,18 @@ Mixin::Mixin(const Mixin& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
root_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
root_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (!from._internal_root().empty()) {
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_root(),
root_.Set(from._internal_root(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin)
@ -1049,11 +1044,11 @@ Mixin::Mixin(const Mixin& from)
inline void Mixin::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
root_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
@ -1068,8 +1063,8 @@ Mixin::~Mixin() {
inline void Mixin::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
root_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
root_.Destroy();
}
void Mixin::SetCachedSize(int size) const {
@ -1240,12 +1235,10 @@ void Mixin::InternalSwap(Mixin* other) {
auto* rhs_arena = other->GetArenaForAllocation();
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&root_, lhs_arena,
&other->root_, rhs_arena
);

@ -739,7 +739,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Api::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Api.name)
}
inline std::string* Api::mutable_name() {
@ -752,15 +752,15 @@ inline const std::string& Api::_internal_name() const {
}
inline void Api::_internal_set_name(const std::string& value) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
name_.Set(value, GetArenaForAllocation());
}
inline std::string* Api::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return name_.Mutable(GetArenaForAllocation());
}
inline std::string* Api::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return name_.Release();
}
inline void Api::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -768,11 +768,10 @@ inline void Api::set_allocated_name(std::string* name) {
} else {
}
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArenaForAllocation());
name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name)
@ -867,7 +866,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Api::set_version(ArgT0&& arg0, ArgT... args) {
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
version_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Api.version)
}
inline std::string* Api::mutable_version() {
@ -880,15 +879,15 @@ inline const std::string& Api::_internal_version() const {
}
inline void Api::_internal_set_version(const std::string& value) {
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
version_.Set(value, GetArenaForAllocation());
}
inline std::string* Api::_internal_mutable_version() {
return version_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return version_.Mutable(GetArenaForAllocation());
}
inline std::string* Api::release_version() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.version)
return version_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return version_.Release();
}
inline void Api::set_allocated_version(std::string* version) {
if (version != nullptr) {
@ -896,11 +895,10 @@ inline void Api::set_allocated_version(std::string* version) {
} else {
}
version_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version,
GetArenaForAllocation());
version_.SetAllocated(version, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (version_.IsDefault()) {
version_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
version_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
@ -977,8 +975,7 @@ inline void Api::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCon
}
if (source_context) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<
::PROTOBUF_NAMESPACE_ID::MessageLite>::GetOwningArena(
::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(
reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context));
if (message_arena != submessage_arena) {
source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
@ -1068,7 +1065,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Method::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.name)
}
inline std::string* Method::mutable_name() {
@ -1081,15 +1078,15 @@ inline const std::string& Method::_internal_name() const {
}
inline void Method::_internal_set_name(const std::string& value) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
name_.Set(value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return name_.Mutable(GetArenaForAllocation());
}
inline std::string* Method::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return name_.Release();
}
inline void Method::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -1097,11 +1094,10 @@ inline void Method::set_allocated_name(std::string* name) {
} else {
}
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArenaForAllocation());
name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
@ -1119,7 +1115,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Method::set_request_type_url(ArgT0&& arg0, ArgT... args) {
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
request_type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.request_type_url)
}
inline std::string* Method::mutable_request_type_url() {
@ -1132,15 +1128,15 @@ inline const std::string& Method::_internal_request_type_url() const {
}
inline void Method::_internal_set_request_type_url(const std::string& value) {
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
request_type_url_.Set(value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_request_type_url() {
return request_type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return request_type_url_.Mutable(GetArenaForAllocation());
}
inline std::string* Method::release_request_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url)
return request_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return request_type_url_.Release();
}
inline void Method::set_allocated_request_type_url(std::string* request_type_url) {
if (request_type_url != nullptr) {
@ -1148,11 +1144,10 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
} else {
}
request_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url,
GetArenaForAllocation());
request_type_url_.SetAllocated(request_type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (request_type_url_.IsDefault()) {
request_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
request_type_url_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
@ -1190,7 +1185,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Method::set_response_type_url(ArgT0&& arg0, ArgT... args) {
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
response_type_url_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.response_type_url)
}
inline std::string* Method::mutable_response_type_url() {
@ -1203,15 +1198,15 @@ inline const std::string& Method::_internal_response_type_url() const {
}
inline void Method::_internal_set_response_type_url(const std::string& value) {
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
response_type_url_.Set(value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_response_type_url() {
return response_type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return response_type_url_.Mutable(GetArenaForAllocation());
}
inline std::string* Method::release_response_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url)
return response_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return response_type_url_.Release();
}
inline void Method::set_allocated_response_type_url(std::string* response_type_url) {
if (response_type_url != nullptr) {
@ -1219,11 +1214,10 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
} else {
}
response_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url,
GetArenaForAllocation());
response_type_url_.SetAllocated(response_type_url, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (response_type_url_.IsDefault()) {
response_type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
response_type_url_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
@ -1322,7 +1316,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Mixin::set_name(ArgT0&& arg0, ArgT... args) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.name)
}
inline std::string* Mixin::mutable_name() {
@ -1335,15 +1329,15 @@ inline const std::string& Mixin::_internal_name() const {
}
inline void Mixin::_internal_set_name(const std::string& value) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
name_.Set(value, GetArenaForAllocation());
}
inline std::string* Mixin::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return name_.Mutable(GetArenaForAllocation());
}
inline std::string* Mixin::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return name_.Release();
}
inline void Mixin::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -1351,11 +1345,10 @@ inline void Mixin::set_allocated_name(std::string* name) {
} else {
}
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArenaForAllocation());
name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
@ -1373,7 +1366,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Mixin::set_root(ArgT0&& arg0, ArgT... args) {
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
root_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.root)
}
inline std::string* Mixin::mutable_root() {
@ -1386,15 +1379,15 @@ inline const std::string& Mixin::_internal_root() const {
}
inline void Mixin::_internal_set_root(const std::string& value) {
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
root_.Set(value, GetArenaForAllocation());
}
inline std::string* Mixin::_internal_mutable_root() {
return root_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return root_.Mutable(GetArenaForAllocation());
}
inline std::string* Mixin::release_root() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.root)
return root_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
return root_.Release();
}
inline void Mixin::set_allocated_root(std::string* root) {
if (root != nullptr) {
@ -1402,11 +1395,10 @@ inline void Mixin::set_allocated_root(std::string* root) {
} else {
}
root_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root,
GetArenaForAllocation());
root_.SetAllocated(root, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (root_.IsDefault()) {
root_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
root_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)

@ -410,27 +410,10 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
template <typename T>
class InternalHelper {
public:
private:
// Provides access to protected GetOwningArena to generated messages.
static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); }
// Provides access to protected GetArenaForAllocation to generated messages.
static Arena* GetArenaForAllocation(const T* p) {
return GetArenaForAllocationInternal(
p, std::is_convertible<T*, MessageLite*>());
}
// Creates message-owned arena.
static Arena* CreateMessageOwnedArena() {
return new Arena(internal::MessageOwned{});
}
// Checks whether the given arena is message-owned.
static bool IsMessageOwnedArena(Arena* arena) {
return arena->IsMessageOwned();
}
private:
static Arena* GetArenaForAllocationInternal(
const T* p, std::true_type /*is_derived_from<MessageLite>*/) {
return p->GetArenaForAllocation();
@ -513,6 +496,29 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
friend class TestUtil::ReflectionTester;
};
// Provides access to protected GetOwningArena to generated messages. For
// internal use only.
template <typename T>
static Arena* InternalGetOwningArena(const T* p) {
return InternalHelper<T>::GetOwningArena(p);
}
// Provides access to protected GetArenaForAllocation to generated messages.
// For internal use only.
template <typename T>
static Arena* InternalGetArenaForAllocation(const T* p) {
return InternalHelper<T>::GetArenaForAllocationInternal(
p, std::is_convertible<T*, MessageLite*>());
}
// Creates message-owned arena. For internal use only.
static Arena* InternalCreateMessageOwnedArena() {
return new Arena(internal::MessageOwned{});
}
// Checks whether this arena is message-owned. For internal use only.
bool InternalIsMessageOwnedArena() { return IsMessageOwned(); }
// Helper typetraits that indicates support for arenas in a type T at compile
// time. This is public only to allow construction of higher-level templated
// utilities.

@ -547,13 +547,11 @@ TEST(ArenaTest, UnsafeArenaSwap) {
TEST(ArenaTest, GetOwningArena) {
Arena arena;
auto* m1 = Arena::CreateMessage<TestAllTypes>(&arena);
EXPECT_EQ(Arena::InternalHelper<TestAllTypes>::GetOwningArena(m1), &arena);
EXPECT_EQ(
&arena,
Arena::InternalHelper<RepeatedPtrField<ForeignMessage>>::GetOwningArena(
m1->mutable_repeated_foreign_message()));
EXPECT_EQ(&arena, Arena::InternalHelper<RepeatedField<int>>::GetOwningArena(
m1->mutable_repeated_int32()));
EXPECT_EQ(Arena::InternalGetOwningArena(m1), &arena);
EXPECT_EQ(&arena, Arena::InternalGetOwningArena(
m1->mutable_repeated_foreign_message()));
EXPECT_EQ(&arena,
Arena::InternalGetOwningArena(m1->mutable_repeated_int32()));
}
TEST(ArenaTest, SwapBetweenArenasUsingReflection) {

@ -57,6 +57,8 @@ namespace {
// - alignof(std::string)
#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
constexpr size_t kNewAlign = __STDCPP_DEFAULT_NEW_ALIGNMENT__;
#elif (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900
constexpr size_t kNewAlign = alignof(::max_align_t);
#else
constexpr size_t kNewAlign = alignof(std::max_align_t);
#endif
@ -110,13 +112,7 @@ std::string* ArenaStringPtr::SetAndReturnNewString() {
return new_string;
}
void ArenaStringPtr::DestroyNoArenaSlowPath() {
GOOGLE_DCHECK(tagged_ptr_.IsAllocated());
delete UnsafeMutablePointer();
}
void ArenaStringPtr::Set(const std::string*, ConstStringParam value,
::google::protobuf::Arena* arena) {
void ArenaStringPtr::Set(ConstStringParam value, Arena* arena) {
if (IsDefault()) {
// If we're not on an arena, skip straight to a true string to avoid
// possible copy cost later.
@ -126,8 +122,8 @@ void ArenaStringPtr::Set(const std::string*, ConstStringParam value,
UnsafeMutablePointer()->assign(value.data(), value.length());
}
}
void ArenaStringPtr::Set(const std::string*, std::string&& value,
::google::protobuf::Arena* arena) {
void ArenaStringPtr::Set(std::string&& value, Arena* arena) {
if (IsDefault()) {
NewString(arena, std::move(value));
} else if (IsFixedSizeArena()) {
@ -140,47 +136,26 @@ void ArenaStringPtr::Set(const std::string*, std::string&& value,
}
}
void ArenaStringPtr::Set(EmptyDefault, ConstStringParam value,
::google::protobuf::Arena* arena) {
Set(&GetEmptyStringAlreadyInited(), value, arena);
}
void ArenaStringPtr::Set(EmptyDefault, std::string&& value,
::google::protobuf::Arena* arena) {
Set(&GetEmptyStringAlreadyInited(), std::move(value), arena);
}
void ArenaStringPtr::Set(NonEmptyDefault, ConstStringParam value,
::google::protobuf::Arena* arena) {
Set(nullptr, value, arena);
}
void ArenaStringPtr::Set(NonEmptyDefault, std::string&& value,
::google::protobuf::Arena* arena) {
Set(nullptr, std::move(value), arena);
}
std::string* ArenaStringPtr::Mutable(EmptyDefault, ::google::protobuf::Arena* arena) {
if (!IsFixedSizeArena() && !IsDefault()) {
return UnsafeMutablePointer();
std::string* ArenaStringPtr::Mutable(Arena* arena) {
if (tagged_ptr_.IsMutable()) {
return tagged_ptr_.Get();
} else {
return MutableSlow(arena);
}
}
std::string* ArenaStringPtr::Mutable(const LazyString& default_value,
::google::protobuf::Arena* arena) {
if (!IsFixedSizeArena() && !IsDefault()) {
return UnsafeMutablePointer();
Arena* arena) {
if (tagged_ptr_.IsMutable()) {
return tagged_ptr_.Get();
} else {
return MutableSlow(arena, default_value);
}
}
std::string* ArenaStringPtr::MutableNoCopy(const std::string*,
::google::protobuf::Arena* arena) {
if (!IsFixedSizeArena() && !IsDefault()) {
return UnsafeMutablePointer();
std::string* ArenaStringPtr::MutableNoCopy(Arena* arena) {
if (tagged_ptr_.IsMutable()) {
return tagged_ptr_.Get();
} else {
GOOGLE_DCHECK(IsDefault());
// Allocate empty. The contents are not relevant.
@ -195,45 +170,24 @@ std::string* ArenaStringPtr::MutableSlow(::google::protobuf::Arena* arena,
return NewString(arena, lazy_default.get()...);
}
std::string* ArenaStringPtr::Release(const std::string* default_value,
::google::protobuf::Arena* arena) {
if (IsDefault()) {
return nullptr;
} else {
return ReleaseNonDefault(default_value, arena);
}
}
std::string* ArenaStringPtr::Release() {
if (IsDefault()) return nullptr;
std::string* ArenaStringPtr::ReleaseNonDefault(const std::string* default_value,
::google::protobuf::Arena* arena) {
GOOGLE_DCHECK(!IsDefault());
if (!IsFixedSizeArena()) {
std::string* released;
if (arena != nullptr) {
released = new std::string;
released->swap(*UnsafeMutablePointer());
} else {
released = UnsafeMutablePointer();
}
tagged_ptr_.SetDefault(default_value);
return released;
} else /* IsFixedSizeArena() */ {
GOOGLE_DCHECK(arena != nullptr);
std::string* released = new std::string(Get());
tagged_ptr_.SetDefault(default_value);
return released;
std::string* released = tagged_ptr_.Get();
if (!tagged_ptr_.IsAllocated()) {
released = tagged_ptr_.IsMutable() ? new std::string(std::move(*released))
: new std::string(*released);
}
InitDefault();
return released;
}
void ArenaStringPtr::SetAllocated(const std::string* default_value,
std::string* value, ::google::protobuf::Arena* arena) {
void ArenaStringPtr::SetAllocated(std::string* value, Arena* arena) {
// Release what we have first.
if (arena == nullptr && !IsDefault()) {
delete UnsafeMutablePointer();
}
Destroy();
if (value == nullptr) {
tagged_ptr_.SetDefault(default_value);
InitDefault();
} else {
#ifndef NDEBUG
// On debug builds, copy the string so the address differs. delete will
@ -247,23 +201,12 @@ void ArenaStringPtr::SetAllocated(const std::string* default_value,
}
}
void ArenaStringPtr::Destroy(const std::string*, ::google::protobuf::Arena* arena) {
if (arena == nullptr) {
GOOGLE_DCHECK(!IsFixedSizeArena());
if (!IsDefault()) {
delete UnsafeMutablePointer();
}
void ArenaStringPtr::Destroy() {
if (tagged_ptr_.IsAllocated()) {
delete tagged_ptr_.Get();
}
}
void ArenaStringPtr::Destroy(EmptyDefault, ::google::protobuf::Arena* arena) {
Destroy(&GetEmptyStringAlreadyInited(), arena);
}
void ArenaStringPtr::Destroy(NonEmptyDefault, ::google::protobuf::Arena* arena) {
Destroy(nullptr, arena);
}
void ArenaStringPtr::ClearToEmpty() {
if (IsDefault()) {
// Already set to default -- do nothing.

@ -187,7 +187,7 @@ class TaggedPtr {
}
inline T* TagAs(Type type, T* p) {
GOOGLE_DCHECK(type == kDefault || p != nullptr);
GOOGLE_DCHECK(p != nullptr);
assert_aligned(p);
ptr_ = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(p) | type);
return p;
@ -232,84 +232,84 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
struct EmptyDefault {};
struct NonEmptyDefault {};
void Set(const std::string* default_value, ConstStringParam value,
::google::protobuf::Arena* arena);
void Set(const std::string* default_value, std::string&& value,
::google::protobuf::Arena* arena);
void Set(EmptyDefault, ConstStringParam value, ::google::protobuf::Arena* arena);
void Set(EmptyDefault, std::string&& value, ::google::protobuf::Arena* arena);
void Set(NonEmptyDefault, ConstStringParam value, ::google::protobuf::Arena* arena);
void Set(NonEmptyDefault, std::string&& value, ::google::protobuf::Arena* arena);
template <typename FirstParam>
void Set(FirstParam p1, const char* str, ::google::protobuf::Arena* arena) {
Set(p1, ConstStringParam(str), arena);
}
template <typename FirstParam>
void Set(FirstParam p1, const char* str, size_t size,
::google::protobuf::Arena* arena) {
ConstStringParam sp{str, size}; // for string_view and `const string &`
Set(p1, sp, arena);
}
template <typename FirstParam, typename RefWrappedType>
void Set(FirstParam p1,
std::reference_wrapper<RefWrappedType> const_string_ref,
// Called from generated code / reflection runtime only. Resets value to point
// to a default string pointer, with the semantics that this ArenaStringPtr
// does not own the pointed-to memory. Disregards initial value of ptr_ (so
// this is the *ONLY* safe method to call after construction or when
// reinitializing after becoming the active field in a oneof union).
inline void InitDefault();
// Similar to `InitDefault` except that it allows the default value to be
// initialized to an externally owned string. This method is called from
// parsing code. `str` must not be null and outlive this instance.
inline void InitExternal(const std::string* str);
// Called from generated code / reflection runtime only. Resets the value of
// this instances to the heap allocated value in `str`. `str` must not be
// null. Invokes `arena->Own(str)` to transfer ownership into the arena if
// `arena` is not null, else, `str` will be owned by ArenaStringPtr. This
// function should only be used to initialize a ArenaStringPtr or on an
// instance known to not carry any heap allocated value.
inline void InitAllocated(std::string* str, Arena* arena);
void Set(ConstStringParam value, Arena* arena);
void Set(std::string&& value, Arena* arena);
void Set(const char* s, Arena* arena);
void Set(const char* s, size_t n, Arena* arena);
void SetBytes(ConstStringParam value, Arena* arena);
void SetBytes(std::string&& value, Arena* arena);
void SetBytes(const char* s, Arena* arena);
void SetBytes(const void* p, size_t n, Arena* arena);
template <typename RefWrappedType>
void Set(std::reference_wrapper<RefWrappedType> const_string_ref,
::google::protobuf::Arena* arena) {
Set(p1, const_string_ref.get(), arena);
Set(const_string_ref.get(), arena);
}
template <typename FirstParam, typename SecondParam>
void SetBytes(FirstParam p1, SecondParam&& p2, ::google::protobuf::Arena* arena) {
Set(p1, static_cast<SecondParam&&>(p2), arena);
}
template <typename FirstParam>
void SetBytes(FirstParam p1, const void* str, size_t size,
::google::protobuf::Arena* arena) {
// must work whether ConstStringParam is string_view or `const string &`
ConstStringParam sp{static_cast<const char*>(str), size};
Set(p1, sp, arena);
}
// Returns a mutable std::string reference.
// The version accepting a `LazyString` value is used in the generated code to
// initialize mutable copies for fields with a non-empty default where the
// default value is lazily initialized.
std::string* Mutable(Arena* arena);
std::string* Mutable(const LazyString& default_value, Arena* arena);
// Gets a mutable pointer with unspecified contents.
// This function is identical to Mutable(), except it is optimized for the
// case where the caller is not interested in the current contents. For
// example, if the current field is not mutable, it will re-initialize the
// value with an empty string rather than a (non-empty) default value.
// Likewise, if the current value is a fixed size arena string with contents,
// it will be initialized into an empty mutable arena string.
std::string* MutableNoCopy(Arena* arena);
// Basic accessors.
PROTOBUF_NDEBUG_INLINE const std::string& Get() const {
// Unconditionally mask away the tag.
return *tagged_ptr_.Get();
}
PROTOBUF_NDEBUG_INLINE const std::string* GetPointer() const {
// Unconditionally mask away the tag.
// Returns a pointer to the stored contents for this instance.
// This method is for internal debugging and tracking purposes only.
PROTOBUF_NDEBUG_INLINE const std::string* UnsafeGetPointer() const
PROTOBUF_RETURNS_NONNULL {
return tagged_ptr_.Get();
}
// For fields with an empty default value.
std::string* Mutable(EmptyDefault, ::google::protobuf::Arena* arena);
// For fields with a non-empty default value.
std::string* Mutable(const LazyString& default_value, ::google::protobuf::Arena* arena);
// Release returns a std::string* instance that is heap-allocated and is not
// Own()'d by any arena. If the field is not set, this returns nullptr. The
// caller retains ownership. Clears this field back to nullptr state. Used to
// implement release_<field>() methods on generated classes.
PROTOBUF_NODISCARD std::string* Release(const std::string* default_value,
::google::protobuf::Arena* arena);
PROTOBUF_NODISCARD std::string* ReleaseNonDefault(
const std::string* default_value, ::google::protobuf::Arena* arena);
// caller retains ownership. Clears this field back to the default state.
// Used to implement release_<field>() methods on generated classes.
PROTOBUF_NODISCARD std::string* Release();
// Takes a std::string that is heap-allocated, and takes ownership. The
// std::string's destructor is registered with the arena. Used to implement
// set_allocated_<field> in generated classes.
void SetAllocated(const std::string* default_value, std::string* value,
::google::protobuf::Arena* arena);
// Swaps internal pointers. Arena-safety semantics: this is guarded by the
// logic in Swap()/UnsafeArenaSwap() at the message level, so this method is
// 'unsafe' if called directly.
inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(
const std::string* default_value, ArenaStringPtr* rhs, Arena* rhs_arena,
ArenaStringPtr* lhs, Arena* lhs_arena);
void SetAllocated(std::string* value, Arena* arena);
// Frees storage (if not on an arena).
void Destroy(const std::string* default_value, ::google::protobuf::Arena* arena);
void Destroy(EmptyDefault, ::google::protobuf::Arena* arena);
void Destroy(NonEmptyDefault, ::google::protobuf::Arena* arena);
void Destroy();
// Clears content, but keeps allocated std::string, to avoid the overhead of
// heap operations. After this returns, the content (as seen by the user) will
@ -326,37 +326,109 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// (as seen by the user) will always be equal to |default_value|.
void ClearToDefault(const LazyString& default_value, ::google::protobuf::Arena* arena);
// Called from generated code / reflection runtime only. Resets value to point
// to a default string pointer, with the semantics that this ArenaStringPtr
// does not own the pointed-to memory. Disregards initial value of ptr_ (so
// this is the *ONLY* safe method to call after construction or when
// reinitializing after becoming the active field in a oneof union).
// This function allows an explicit default value other than the default
// global empty string. This is used in unit tests and by fields with
// explicit non-empty default string values using null defaults.
inline void InitDefault();
inline void InitDefault(const std::string* str);
// Swaps internal pointers. Arena-safety semantics: this is guarded by the
// logic in Swap()/UnsafeArenaSwap() at the message level, so this method is
// 'unsafe' if called directly.
inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(ArenaStringPtr* rhs,
Arena* rhs_arena,
ArenaStringPtr* lhs,
Arena* lhs_arena);
// --------------------------------------------------------
// Below functions will be removed in subsequent code change
// --------------------------------------------------------
#ifdef DEPRECATED_METHODS_TO_BE_DELETED
PROTOBUF_NDEBUG_INLINE const std::string* GetPointer() const {
return UnsafeGetPointer();
}
// Called from generated code / reflection runtime only. Resets the value of
// this instances to the heap allocated value in `str`. `str` must not be
// null. Invokes `arena->Own(str)` to transfer ownership into the arena if
// `arena` is not null, else, `str` will be owned by ArenaStringPtr. This
// function should only be used to initialize a ArenaStringPtr or on an
// instance known to not carry any heap allocated value.
inline void InitAllocated(std::string* str, Arena* arena);
template <typename DefaultArg>
void Set(DefaultArg, ConstStringParam value, Arena* arena) {
return Set(value, arena);
}
template <typename DefaultArg>
void Set(DefaultArg, std::string&& value, Arena* arena) {
return Set(std::move(value), arena);
}
template <typename DefaultArg>
void Set(DefaultArg, const char* s, Arena* arena) {
return Set(ConstStringParam{s}, arena);
}
template <typename DefaultArg>
void Set(DefaultArg, const char* s, size_t n, Arena* arena) {
return Set(ConstStringParam{s, n}, arena);
}
// Returns a mutable pointer, but doesn't initialize the string to the
// default value.
std::string* MutableNoArenaNoDefault(const std::string* default_value);
void SetBytes(EmptyDefault, ConstStringParam value, Arena* arena) {
return Set(value, arena);
}
void SetBytes(NonEmptyDefault, ConstStringParam value, Arena* arena) {
return Set(value, arena);
}
void SetBytes(const std::string*, ConstStringParam value, Arena* arena) {
return Set(value, arena);
}
void SetBytes(EmptyDefault, std::string&& value, Arena* arena) {
return Set(std::move(value), arena);
}
void SetBytes(NonEmptyDefault, std::string&& value, Arena* arena) {
return Set(std::move(value), arena);
}
void SetBytes(const std::string*, std::string&& value, Arena* arena) {
return Set(std::move(value), arena);
}
void SetBytes(EmptyDefault, const char* s, Arena* arena) {
return Set(s, arena);
}
void SetBytes(NonEmptyDefault, const char* s, Arena* arena) {
return Set(s, arena);
}
void SetBytes(const std::string*, const char* s, Arena* arena) {
return Set(s, arena);
}
void SetBytes(EmptyDefault, const void* p, size_t n, Arena* arena) {
return SetBytes(p, n, arena);
}
void SetBytes(NonEmptyDefault, const void* p, size_t n, Arena* arena) {
return SetBytes(p, n, arena);
}
void SetBytes(const std::string*, const void* p, size_t n, Arena* arena) {
return SetBytes(p, n, arena);
}
std::string* Mutable(EmptyDefault, Arena* arena) { return Mutable(arena); }
std::string* MutableNoArenaNoDefault(const std::string*) {
return Mutable(nullptr);
}
std::string* MutableNoCopy(const std::string*, ::google::protobuf::Arena* arena) {
return MutableNoCopy(arena);
}
PROTOBUF_NODISCARD std::string* Release(const std::string*, Arena* arena) {
return Release();
}
PROTOBUF_NODISCARD std::string* ReleaseNonDefault(const std::string*,
Arena* arena) {
return Release();
}
// Get a mutable pointer with unspecified contents.
// Similar to `MutableNoArenaNoDefault`, but also handles the arena case.
// If the value was donated, the contents are discarded.
std::string* MutableNoCopy(const std::string* default_value,
::google::protobuf::Arena* arena);
void SetAllocated(const std::string*, std::string* value, Arena* arena) {
SetAllocated(value, arena);
}
// Destroy the string. Assumes `arena == nullptr`.
void DestroyNoArena(const std::string* default_value);
void Destroy(const std::string*, ::google::protobuf::Arena* arena) { Destroy(); }
void Destroy(EmptyDefault, ::google::protobuf::Arena* arena) { Destroy(); }
void Destroy(NonEmptyDefault, ::google::protobuf::Arena* arena) { Destroy(); }
void DestroyNoArena(const std::string*) { Destroy(); }
inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(const std::string*,
ArenaStringPtr* rhs,
Arena* rhs_arena,
ArenaStringPtr* lhs,
Arena* lhs_arena) {
InternalSwap(rhs, rhs_arena, lhs, lhs_arena);
}
#endif // DEPRECATED_METHODS_TO_BE_DELETED
// Internal setter used only at parse time to directly set a donated string
// value.
@ -407,9 +479,6 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// Sets value to a newly allocated string and returns it
std::string* SetAndReturnNewString();
// Destroys the non-default string value out-of-line
void DestroyNoArenaSlowPath();
friend class EpsCopyInputStream;
};
@ -417,7 +486,7 @@ inline void ArenaStringPtr::InitDefault() {
tagged_ptr_ = TaggedPtr<std::string>(&fixed_address_empty_string);
}
inline void ArenaStringPtr::InitDefault(const std::string* str) {
inline void ArenaStringPtr::InitExternal(const std::string* str) {
tagged_ptr_.SetDefault(str);
}
@ -430,9 +499,32 @@ inline void ArenaStringPtr::InitAllocated(std::string* str, Arena* arena) {
}
}
inline void ArenaStringPtr::Set(const char* s, Arena* arena) {
Set(ConstStringParam{s}, arena);
}
inline void ArenaStringPtr::Set(const char* s, size_t n, Arena* arena) {
Set(ConstStringParam{s, n}, arena);
}
inline void ArenaStringPtr::SetBytes(ConstStringParam value, Arena* arena) {
Set(value, arena);
}
inline void ArenaStringPtr::SetBytes(std::string&& value, Arena* arena) {
Set(std::move(value), arena);
}
inline void ArenaStringPtr::SetBytes(const char* s, Arena* arena) {
Set(s, arena);
}
inline void ArenaStringPtr::SetBytes(const void* p, size_t n, Arena* arena) {
Set(ConstStringParam{static_cast<const char*>(p), n}, arena);
}
// Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs.
inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap( //
const std::string*, //
ArenaStringPtr* rhs, Arena* rhs_arena, //
ArenaStringPtr* lhs, Arena* lhs_arena) {
// Silence unused variable warnings in release buildls.
@ -466,28 +558,6 @@ inline void ArenaStringPtr::ClearNonDefaultToEmpty() {
tagged_ptr_.Get()->clear();
}
inline std::string* ArenaStringPtr::MutableNoArenaNoDefault(
const std::string* /* default_value */) {
// VERY IMPORTANT for performance and code size: this will reduce to a member
// variable load, a pointer check (against |default_value|, in practice a
// static global) and a branch to the slowpath (which calls operator new and
// the ctor). DO NOT add any tagged-pointer operations here.
GOOGLE_DCHECK(!tagged_ptr_.IsArena());
if (IsDefault()) {
return SetAndReturnNewString();
} else {
return UnsafeMutablePointer();
}
}
inline void ArenaStringPtr::DestroyNoArena(
const std::string* /* default_value */) {
GOOGLE_DCHECK(!tagged_ptr_.IsArena());
if (!IsDefault()) {
DestroyNoArenaSlowPath();
}
}
inline std::string* ArenaStringPtr::UnsafeMutablePointer() {
GOOGLE_DCHECK(tagged_ptr_.IsMutable());
GOOGLE_DCHECK(tagged_ptr_.Get() != nullptr);

@ -34,6 +34,7 @@
#include <cstdlib>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <google/protobuf/stubs/logging.h>
@ -72,37 +73,36 @@ INSTANTIATE_TEST_SUITE_P(ArenaString, SingleArena, testing::Bool());
TEST_P(SingleArena, GetSet) {
auto arena = GetArena();
ArenaStringPtr field;
field.InitDefault(empty_default);
field.InitDefault();
EXPECT_EQ("", field.Get());
field.Set(empty_default, "Test short", arena.get());
field.Set("Test short", arena.get());
EXPECT_EQ("Test short", field.Get());
field.Set(empty_default, "Test long long long long value", arena.get());
field.Set("Test long long long long value", arena.get());
EXPECT_EQ("Test long long long long value", field.Get());
field.Set(empty_default, "", arena.get());
field.Destroy(empty_default, arena.get());
field.Set("", arena.get());
field.Destroy();
}
TEST_P(SingleArena, MutableAccessor) {
auto arena = GetArena();
ArenaStringPtr field;
const std::string* empty_default = &internal::GetEmptyString();
field.InitDefault(empty_default);
field.InitDefault();
std::string* mut = field.Mutable(EmptyDefault{}, arena.get());
EXPECT_EQ(mut, field.Mutable(EmptyDefault{}, arena.get()));
std::string* mut = field.Mutable(arena.get());
EXPECT_EQ(mut, field.Mutable(arena.get()));
EXPECT_EQ(mut, &field.Get());
EXPECT_NE(empty_default, mut);
EXPECT_EQ("", *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ("Test long long long long value", field.Get());
field.Destroy(empty_default, arena.get());
field.Destroy();
}
TEST_P(SingleArena, NullDefault) {
auto arena = GetArena();
ArenaStringPtr field;
field.InitDefault(nullptr);
field.InitDefault();
std::string* mut = field.Mutable(nonempty_default, arena.get());
EXPECT_EQ(mut, field.Mutable(nonempty_default, arena.get()));
EXPECT_EQ(mut, &field.Get());
@ -110,7 +110,7 @@ TEST_P(SingleArena, NullDefault) {
EXPECT_EQ("default", *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ("Test long long long long value", field.Get());
field.Destroy(nullptr, arena.get());
field.Destroy();
}
class DualArena : public testing::TestWithParam<std::tuple<bool, bool>> {
@ -131,23 +131,22 @@ INSTANTIATE_TEST_SUITE_P(ArenaString, DualArena,
TEST_P(DualArena, Swap) {
auto lhs_arena = GetLhsArena();
ArenaStringPtr lhs;
lhs.InitDefault(empty_default);
lhs.InitDefault();
ArenaStringPtr rhs;
rhs.InitDefault(empty_default);
rhs.InitDefault();
{
auto rhs_arena = GetRhsArena();
lhs.Set(empty_default, "lhs value that has some heft", lhs_arena.get());
rhs.Set(empty_default, "rhs value that has some heft", rhs_arena.get());
ArenaStringPtr::InternalSwap(empty_default, //
&lhs, lhs_arena.get(), //
lhs.Set("lhs value that has some heft", lhs_arena.get());
rhs.Set("rhs value that has some heft", rhs_arena.get());
ArenaStringPtr::InternalSwap(&lhs, lhs_arena.get(), //
&rhs, rhs_arena.get());
EXPECT_EQ("rhs value that has some heft", lhs.Get());
EXPECT_EQ("lhs value that has some heft", rhs.Get());
lhs.Destroy(empty_default, rhs_arena.get());
lhs.Destroy();
}
EXPECT_EQ("lhs value that has some heft", rhs.Get());
rhs.Destroy(empty_default, lhs_arena.get());
rhs.Destroy();
}

@ -91,7 +91,7 @@ void EnumFieldGenerator::GenerateInlineAccessorDefinitions(
Formatter format(printer, variables_);
format(
"inline $type$ $classname$::_internal_$name$() const {\n"
" return static_cast< $type$ >($name$_);\n"
" return static_cast< $type$ >($field$);\n"
"}\n"
"inline $type$ $classname$::$name$() const {\n"
"$annotate_get$"
@ -104,7 +104,7 @@ void EnumFieldGenerator::GenerateInlineAccessorDefinitions(
}
format(
" $set_hasbit$\n"
" $name$_ = value;\n"
" $field$ = value;\n"
"}\n"
"inline void $classname$::set_$name$($type$ value) {\n"
" _internal_set_$name$(value);\n"
@ -115,7 +115,7 @@ void EnumFieldGenerator::GenerateInlineAccessorDefinitions(
void EnumFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_ = $default$;\n");
format("$field$ = $default$;\n");
}
void EnumFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
@ -125,7 +125,7 @@ void EnumFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
void EnumFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("swap($name$_, other->$name$_);\n");
format("swap($field$, other->$field$);\n");
}
void EnumFieldGenerator::GenerateConstructorCode(io::Printer* printer) const {
@ -177,7 +177,7 @@ void EnumOneofFieldGenerator::GenerateInlineAccessorDefinitions(
format(
"inline $type$ $classname$::_internal_$name$() const {\n"
" if (_internal_has_$name$()) {\n"
" return static_cast< $type$ >($field_member$);\n"
" return static_cast< $type$ >($field$);\n"
" }\n"
" return static_cast< $type$ >($default$);\n"
"}\n"
@ -195,7 +195,7 @@ void EnumOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
" }\n"
" $field_member$ = value;\n"
" $field$ = value;\n"
"}\n"
"inline void $classname$::set_$name$($type$ value) {\n"
" _internal_set_$name$(value);\n"
@ -206,7 +206,7 @@ void EnumOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void EnumOneofFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field_member$ = $default$;\n");
format("$field$ = $default$;\n");
}
void EnumOneofFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
@ -264,7 +264,7 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
Formatter format(printer, variables_);
format(
"inline $type$ $classname$::_internal_$name$(int index) const {\n"
" return static_cast< $type$ >($name$_.Get(index));\n"
" return static_cast< $type$ >($field$.Get(index));\n"
"}\n"
"inline $type$ $classname$::$name$(int index) const {\n"
"$annotate_get$"
@ -276,7 +276,7 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
format(" assert($type$_IsValid(value));\n");
}
format(
" $name$_.Set(index, value);\n"
" $field$.Set(index, value);\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
@ -285,7 +285,7 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
format(" assert($type$_IsValid(value));\n");
}
format(
" $name$_.Add(value);\n"
" $field$.Add(value);\n"
"}\n"
"inline void $classname$::add_$name$($type$ value) {\n"
" _internal_add_$name$(value);\n"
@ -296,11 +296,11 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
"$classname$::$name$() const {\n"
"$annotate_list$"
" // @@protoc_insertion_point(field_list:$full_name$)\n"
" return $name$_;\n"
" return $field$;\n"
"}\n"
"inline ::$proto_ns$::RepeatedField<int>*\n"
"$classname$::_internal_mutable_$name$() {\n"
" return &$name$_;\n"
" return &$field$;\n"
"}\n"
"inline ::$proto_ns$::RepeatedField<int>*\n"
"$classname$::mutable_$name$() {\n"
@ -313,19 +313,19 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
void RepeatedEnumFieldGenerator::GenerateClearingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.Clear();\n");
format("$field$.Clear();\n");
}
void RepeatedEnumFieldGenerator::GenerateMergingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n");
format("$field$.MergeFrom(from.$field$);\n");
}
void RepeatedEnumFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n");
format("$field$.InternalSwap(&other->$field$);\n");
}
void RepeatedEnumFieldGenerator::GenerateConstructorCode(
@ -344,7 +344,7 @@ void RepeatedEnumFieldGenerator::GenerateSerializeWithCachedSizesToArray(
"_$name$_cached_byte_size_.load(std::memory_order_relaxed);\n"
" if (byte_size > 0) {\n"
" target = stream->WriteEnumPacked(\n"
" $number$, $name$_, byte_size, target);\n"
" $number$, $field$, byte_size, target);\n"
" }\n"
"}\n");
} else {
@ -375,7 +375,8 @@ void RepeatedEnumFieldGenerator::GenerateByteSize(io::Printer* printer) const {
format(
"if (data_size > 0) {\n"
" total_size += $tag_size$ +\n"
" ::_pbi::WireFormatLite::Int32Size(static_cast<$int32$>(data_size));\n"
" "
"::_pbi::WireFormatLite::Int32Size(static_cast<$int32$>(data_size));\n"
"}\n"
"int cached_size = ::_pbi::ToCachedSize(data_size);\n"
"_$name$_cached_byte_size_.store(cached_size,\n"

@ -81,7 +81,7 @@ std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor,
std::string field_name = google::protobuf::compiler::cpp::FieldName(descriptor);
std::string field_pointer =
descriptor->options().ctype() == google::protobuf::FieldOptions::STRING
? "$0.GetPointer()"
? "$0.UnsafeGetPointer()"
: "$0";
if (descriptor->default_value_string().empty()) {
@ -114,7 +114,7 @@ std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor,
if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING) {
return strings::Substitute(
"$0.IsDefault() ? &$1.get() : $0.GetPointer()", field_member,
"$0.IsDefault() ? &$1.get() : $0.UnsafeGetPointer()", field_member,
MakeDefaultName(descriptor));
}
@ -241,7 +241,12 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
(*variables)["number"] = StrCat(descriptor->number());
(*variables)["classname"] = ClassName(FieldScope(descriptor), false);
(*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type());
// TODO(b/218325252): convert all usages of "field_member" to "field" and
// remove this. The former may unnecessarily cause line breaks in protoc code.
// Note that the length of variables has no effect on the generated code. It
// only affects the readability of code template in protoc.
(*variables)["field_member"] = FieldMemberName(descriptor);
(*variables)["field"] = FieldMemberName(descriptor);
(*variables)["tag_size"] = StrCat(
WireFormat::TagSize(descriptor->number(), descriptor->type()));

@ -82,6 +82,12 @@ bool CppGenerator::Generate(const FileDescriptor* file,
// FOO_EXPORT is a macro which should expand to __declspec(dllexport) or
// __declspec(dllimport) depending on what is being compiled.
//
// If the proto_h option is passed to the compiler, we will generate all
// classes and enums so that they can be forward-declared from files that
// need them from imports.
//
// If the lite option is passed to the compiler, we will generate the
// current files and all transitive dependencies using the LITE runtime.
Options file_options;
file_options.opensource_runtime = opensource_runtime_;
@ -111,6 +117,8 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_options.num_cc_files =
strto32(options[i].second.c_str(), nullptr, 10);
}
} else if (options[i].first == "proto_h") {
file_options.proto_h = true;
} else if (options[i].first == "annotate_accessor") {
file_options.annotate_accessor = true;
} else if (options[i].first == "inject_field_listener_events") {

@ -1240,12 +1240,13 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) {
} else {
format(
"inline int $classname$::_internal_$name$_size() const {\n"
" return $name$_$1$.size();\n"
" return $1$$2$.size();\n"
"}\n"
"inline int $classname$::$name$_size() const {\n"
"$annotate_size$"
" return _internal_$name$_size();\n"
"}\n",
FieldMemberName(field),
IsImplicitWeakField(field, options_, scc_analyzer_) &&
field->message_type()
? ".weak"
@ -1391,8 +1392,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
if (EnableMessageOwnedArena(descriptor_, options_)) {
format(
"inline $classname$() : $classname$("
"::$proto_ns$::Arena::InternalHelper<$classname$>::\n"
" CreateMessageOwnedArena(), true) {}\n");
"::$proto_ns$::Arena::InternalCreateMessageOwnedArena(), true) {}\n");
} else {
format("inline $classname$() : $classname$(nullptr) {}\n");
}

@ -182,14 +182,13 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
// If we're not on an arena, free whatever we were holding before.
// (If we are on arena, we can just forget the earlier pointer.)
" if (GetArenaForAllocation() == nullptr) {\n"
" delete reinterpret_cast<::$proto_ns$::MessageLite*>($name$_);\n"
" delete reinterpret_cast<::$proto_ns$::MessageLite*>($field$);\n"
" }\n");
if (implicit_weak_field_) {
format(
" $name$_ = "
"reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n");
" $field$ = reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n");
} else {
format(" $name$_ = $name$;\n");
format(" $field$ = $name$;\n");
}
format(
" if ($name$) {\n"
@ -207,7 +206,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_release$"
" $clear_hasbit$\n"
" $type$* temp = $casted_member$;\n"
" $name$_ = nullptr;\n"
" $field$ = nullptr;\n"
"#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE\n"
" auto* old = reinterpret_cast<::$proto_ns$::MessageLite*>(temp);\n"
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
@ -225,7 +224,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$type_reference_function$"
" $clear_hasbit$\n"
" $type$* temp = $casted_member$;\n"
" $name$_ = nullptr;\n"
" $field$ = nullptr;\n"
" return temp;\n"
"}\n");
@ -233,12 +232,12 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"inline $type$* $classname$::_internal_mutable_$name$() {\n"
"$type_reference_function$"
" $set_hasbit$\n"
" if ($name$_ == nullptr) {\n"
" if ($field$ == nullptr) {\n"
" auto* p = CreateMaybeMessage<$type$>(GetArenaForAllocation());\n");
if (implicit_weak_field_) {
format(" $name$_ = reinterpret_cast<::$proto_ns$::MessageLite*>(p);\n");
format(" $field$ = reinterpret_cast<::$proto_ns$::MessageLite*>(p);\n");
} else {
format(" $name$_ = p;\n");
format(" $field$ = p;\n");
}
format(
" }\n"
@ -259,9 +258,9 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
format(" if (message_arena == nullptr) {\n");
if (IsCrossFileMessage(descriptor_)) {
format(
" delete reinterpret_cast< ::$proto_ns$::MessageLite*>($name$_);\n");
" delete reinterpret_cast< ::$proto_ns$::MessageLite*>($field$);\n");
} else {
format(" delete $name$_;\n");
format(" delete $field$;\n");
}
format(
" }\n"
@ -271,14 +270,13 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
// isn't defined in this file.
format(
" ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::InternalHelper<\n"
" ::$proto_ns$::MessageLite>::GetOwningArena(\n"
" ::$proto_ns$::Arena::InternalGetOwningArena(\n"
" reinterpret_cast<::$proto_ns$::MessageLite*>("
"$name$));\n");
} else {
format(
" ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::InternalHelper<$type$>::GetOwningArena("
" ::$proto_ns$::Arena::InternalGetOwningArena("
"$name$);\n");
}
format(
@ -291,9 +289,9 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
" $clear_hasbit$\n"
" }\n");
if (implicit_weak_field_) {
format(" $name$_ = reinterpret_cast<MessageLite*>($name$);\n");
format(" $field$ = reinterpret_cast<MessageLite*>($name$);\n");
} else {
format(" $name$_ = $name$;\n");
format(" $field$ = $name$;\n");
}
format(
"$annotate_set$"
@ -328,8 +326,8 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
format(
"const ::$proto_ns$::MessageLite& $classname$::_Internal::$name$(\n"
" const $classname$* msg) {\n"
" if (msg->$field_member$ != nullptr) {\n"
" return *msg->$field_member$;\n"
" if (msg->$field$ != nullptr) {\n"
" return *msg->$field$;\n"
" } else {\n"
" return *$type_default_instance_ptr$;\n"
" }\n"
@ -341,7 +339,7 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
format(" msg->$set_hasbit$\n");
}
if (descriptor_->real_containing_oneof() == nullptr) {
format(" if (msg->$field_member$ == nullptr) {\n");
format(" if (msg->$field$ == nullptr) {\n");
} else {
format(
" if (!msg->_internal_has_$name$()) {\n"
@ -349,10 +347,10 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
" msg->set_has_$name$();\n");
}
format(
" msg->$field_member$ = $type_default_instance_ptr$->New(\n"
" msg->$field$ = $type_default_instance_ptr$->New(\n"
" msg->GetArenaForAllocation());\n"
" }\n"
" return msg->$field_member$;\n"
" return msg->$field$;\n"
"}\n");
} else {
// This inline accessor directly returns member field and is used in
@ -361,7 +359,7 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
format(
"const $type$&\n"
"$classname$::_Internal::$name$(const $classname$* msg) {\n"
" return *msg->$field_member$;\n"
" return *msg->$field$;\n"
"}\n");
}
}
@ -374,12 +372,12 @@ void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
// If we don't have has-bits, message presence is indicated only by ptr !=
// nullptr. Thus on clear, we need to delete the object.
format(
"if (GetArenaForAllocation() == nullptr && $name$_ != nullptr) {\n"
" delete $name$_;\n"
"if (GetArenaForAllocation() == nullptr && $field$ != nullptr) {\n"
" delete $field$;\n"
"}\n"
"$name$_ = nullptr;\n");
"$field$ = nullptr;\n");
} else {
format("if ($name$_ != nullptr) $name$_->Clear();\n");
format("if ($field$ != nullptr) $field$->Clear();\n");
}
}
@ -392,14 +390,14 @@ void MessageFieldGenerator::GenerateMessageClearingCode(
// If we don't have has-bits, message presence is indicated only by ptr !=
// nullptr. Thus on clear, we need to delete the object.
format(
"if (GetArenaForAllocation() == nullptr && $name$_ != nullptr) {\n"
" delete $name$_;\n"
"if (GetArenaForAllocation() == nullptr && $field$ != nullptr) {\n"
" delete $field$;\n"
"}\n"
"$name$_ = nullptr;\n");
"$field$ = nullptr;\n");
} else {
format(
"$DCHK$($name$_ != nullptr);\n"
"$name$_->Clear();\n");
"$DCHK$($field$ != nullptr);\n"
"$field$->Clear();\n");
}
}
@ -422,7 +420,7 @@ void MessageFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_);
format("swap($name$_, other->$name$_);\n");
format("swap($field$, other->$field$);\n");
}
void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
@ -487,7 +485,7 @@ void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const {
format(
"total_size += $tag_size$ +\n"
" ::$proto_ns$::internal::WireFormatLite::$declared_type$Size(\n"
" *$field_member$);\n");
" *$field$);\n");
}
void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const {
@ -498,7 +496,7 @@ void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"if (_internal_has_$name$()) {\n"
" if (!$name$_->IsInitialized()) return false;\n"
" if (!$field$->IsInitialized()) return false;\n"
"}\n");
}
@ -532,15 +530,13 @@ void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
// isn't defined in this file.
format(
" ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::InternalHelper<\n"
" ::$proto_ns$::MessageLite>::GetOwningArena(\n"
" ::$proto_ns$::Arena::InternalGetOwningArena(\n"
" reinterpret_cast<::$proto_ns$::MessageLite*>("
"$name$));\n");
} else {
format(
" ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::InternalHelper<"
"$type$>::GetOwningArena($name$);\n");
" ::$proto_ns$::Arena::InternalGetOwningArena($name$);\n");
}
format(
" if (message_arena != submessage_arena) {\n"
@ -548,7 +544,7 @@ void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
" message_arena, $name$, submessage_arena);\n"
" }\n"
" set_has_$name$();\n"
" $field_member$ = $name$;\n"
" $field$ = $name$;\n"
" }\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
@ -569,7 +565,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (GetArenaForAllocation() != nullptr) {\n"
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
" }\n"
" $field_member$ = nullptr;\n"
" $field$ = nullptr;\n"
" return temp;\n"
" } else {\n"
" return nullptr;\n"
@ -596,7 +592,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
" $type$* temp = $casted_member$;\n"
" $field_member$ = nullptr;\n"
" $field$ = nullptr;\n"
" return temp;\n"
" } else {\n"
" return nullptr;\n"
@ -612,10 +608,10 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" set_has_$name$();\n");
if (implicit_weak_field_) {
format(
" $field_member$ = "
" $field$ = "
"reinterpret_cast<::$proto_ns$::MessageLite*>($name$);\n");
} else {
format(" $field_member$ = $name$;\n");
format(" $field$ = $name$;\n");
}
format(
" }\n"
@ -630,12 +626,12 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" set_has_$name$();\n");
if (implicit_weak_field_) {
format(
" $field_member$ = "
" $field$ = "
"reinterpret_cast<::$proto_ns$::MessageLite*>(CreateMaybeMessage< "
"$type$ >(GetArenaForAllocation()));\n");
} else {
format(
" $field_member$ = CreateMaybeMessage< $type$ "
" $field$ = CreateMaybeMessage< $type$ "
">(GetArenaForAllocation());\n");
}
format(
@ -657,7 +653,7 @@ void MessageOneofFieldGenerator::GenerateClearingCode(
Formatter format(printer, variables_);
format(
"if (GetArenaForAllocation() == nullptr) {\n"
" delete $field_member$;\n"
" delete $field$;\n"
"}\n");
}
@ -690,7 +686,7 @@ void MessageOneofFieldGenerator::GenerateIsInitialized(
Formatter format(printer, variables_);
format(
"if (_internal_has_$name$()) {\n"
" if (!$field_member$->IsInitialized()) return false;\n"
" if (!$field$->IsInitialized()) return false;\n"
"}\n");
}
@ -769,21 +765,21 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
// TODO(dlj): move insertion points
" // @@protoc_insertion_point(field_mutable:$full_name$)\n"
"$type_reference_function$"
" return $name$_$weak$.Mutable(index);\n"
" return $field$$weak$.Mutable(index);\n"
"}\n"
"inline ::$proto_ns$::RepeatedPtrField< $type$ >*\n"
"$classname$::mutable_$name$() {\n"
"$annotate_mutable_list$"
" // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
"$type_reference_function$"
" return &$name$_$weak$;\n"
" return &$field$$weak$;\n"
"}\n");
if (options_.safe_boundary_check) {
format(
"inline const $type$& $classname$::_internal_$name$(int index) const "
"{\n"
" return $name$_$weak$.InternalCheckedGet(index,\n"
" return $field$$weak$.InternalCheckedGet(index,\n"
" reinterpret_cast<const $type$&>($type_default_instance$));\n"
"}\n");
} else {
@ -791,7 +787,7 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
"inline const $type$& $classname$::_internal_$name$(int index) const "
"{\n"
"$type_reference_function$"
" return $name$_$weak$.Get(index);\n"
" return $field$$weak$.Get(index);\n"
"}\n");
}
@ -802,7 +798,7 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
" return _internal_$name$(index);\n"
"}\n"
"inline $type$* $classname$::_internal_add_$name$() {\n"
" return $name$_$weak$.Add();\n"
" return $field$$weak$.Add();\n"
"}\n"
"inline $type$* $classname$::add_$name$() {\n"
" $type$* _add = _internal_add_$name$();\n"
@ -817,7 +813,7 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_list$"
" // @@protoc_insertion_point(field_list:$full_name$)\n"
"$type_reference_function$"
" return $name$_$weak$;\n"
" return $field$$weak$;\n"
"}\n");
}
@ -826,7 +822,7 @@ void RepeatedMessageFieldGenerator::GenerateClearingCode(
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_);
format("$name$_.Clear();\n");
format("$field$.Clear();\n");
}
void RepeatedMessageFieldGenerator::GenerateMergingCode(
@ -834,7 +830,7 @@ void RepeatedMessageFieldGenerator::GenerateMergingCode(
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n");
format("$field$.MergeFrom(from.$field$);\n");
}
void RepeatedMessageFieldGenerator::GenerateSwappingCode(
@ -842,7 +838,7 @@ void RepeatedMessageFieldGenerator::GenerateSwappingCode(
GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_));
Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n");
format("$field$.InternalSwap(&other->$field$);\n");
}
void RepeatedMessageFieldGenerator::GenerateConstructorCode(
@ -857,8 +853,8 @@ void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray(
Formatter format(printer, variables_);
if (implicit_weak_field_) {
format(
"for (auto it = this->$name$_.pointer_begin(),\n"
" end = this->$name$_.pointer_end(); it < end; ++it) {\n");
"for (auto it = this->$field$.pointer_begin(),\n"
" end = this->$field$.pointer_end(); it < end; ++it) {\n");
if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) {
format(
" target = ::$proto_ns$::internal::WireFormatLite::\n"
@ -902,7 +898,7 @@ void RepeatedMessageFieldGenerator::GenerateByteSize(
Formatter format(printer, variables_);
format(
"total_size += $tag_size$UL * this->_internal_$name$_size();\n"
"for (const auto& msg : this->$name$_) {\n"
"for (const auto& msg : this->$field$) {\n"
" total_size +=\n"
" ::$proto_ns$::internal::WireFormatLite::$declared_type$Size(msg);\n"
"}\n");
@ -917,11 +913,11 @@ void RepeatedMessageFieldGenerator::GenerateIsInitialized(
Formatter format(printer, variables_);
if (implicit_weak_field_) {
format(
"if (!::$proto_ns$::internal::AllAreInitializedWeak($name$_.weak))\n"
"if (!::$proto_ns$::internal::AllAreInitializedWeak($field$.weak))\n"
" return false;\n");
} else {
format(
"if (!::$proto_ns$::internal::AllAreInitialized($name$_))\n"
"if (!::$proto_ns$::internal::AllAreInitialized($field$))\n"
" return false;\n");
}
}

@ -88,8 +88,7 @@ bool IsFieldEligibleForFastParsing(
return false;
}
switch (field->type()) {
// Strings, enums, and groups are not handled on the fast path.
case FieldDescriptor::TYPE_STRING:
// Groups are not handled on the fast path.
case FieldDescriptor::TYPE_GROUP:
return false;
@ -105,6 +104,7 @@ bool IsFieldEligibleForFastParsing(
break;
// Some bytes fields can be handled on fast path.
case FieldDescriptor::TYPE_STRING:
case FieldDescriptor::TYPE_BYTES:
if (field->options().ctype() != FieldOptions::STRING ||
!field->default_value_string().empty() ||
@ -233,15 +233,15 @@ std::vector<const FieldDescriptor*> FilterMiniParsedFields(
}
break;
// TODO(b/209516305): add TYPE_STRING once field names are available.
case FieldDescriptor::TYPE_BYTES:
if (IsStringInlined(field, options)) {
// TODO(b/198211897): support InilnedStringField.
handled = false;
} else {
handled = true;
}
break;
case FieldDescriptor::TYPE_BYTES:
case FieldDescriptor::TYPE_STRING:
if (IsStringInlined(field, options)) {
// TODO(b/198211897): support InilnedStringField.
handled = false;
} else {
handled = true;
}
break;
case FieldDescriptor::TYPE_MESSAGE:
// TODO(b/210762816): support remaining field types.
@ -773,9 +773,9 @@ void ParseFunctionGenerator::GenerateFastFieldEntries(Formatter& format) {
} else {
format(
"{$1$,\n"
" {$2$, $3$, $4$, PROTOBUF_FIELD_OFFSET($classname$, $5$_)}},\n",
" {$2$, $3$, $4$, PROTOBUF_FIELD_OFFSET($classname$, $5$)}},\n",
info.func_name, info.coded_tag, info.hasbit_idx, info.aux_idx,
FieldName(info.field));
FieldMemberName(info.field));
}
}
}
@ -999,7 +999,7 @@ void ParseFunctionGenerator::GenerateArenaString(Formatter& format,
"::" + MakeDefaultName(field) + ".get()";
format(
"if (arena != nullptr) {\n"
" ptr = ctx->ReadArenaString(ptr, &$msg$$name$_, arena");
" ptr = ctx->ReadArenaString(ptr, &$msg$$field$, arena");
if (IsStringInlined(field, options_)) {
GOOGLE_DCHECK(!inlined_string_indices_.empty());
int inlined_string_index = inlined_string_indices_[field->index()];
@ -1018,10 +1018,9 @@ void ParseFunctionGenerator::GenerateArenaString(Formatter& format,
");\n"
"} else {\n"
" ptr = ::_pbi::InlineGreedyStringParser("
"$msg$$name$_.MutableNoArenaNoDefault(&$1$), ptr, ctx);\n"
"$msg$$field$.MutableNoCopy(nullptr), ptr, ctx);\n"
"}\n"
"const std::string* str = &$msg$$name$_.Get(); (void)str;\n",
default_string);
"const std::string* str = &$msg$$field$.Get(); (void)str;\n");
}
void ParseFunctionGenerator::GenerateStrings(Formatter& format,
@ -1130,13 +1129,13 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format,
format(
"auto object = "
"::$proto_ns$::internal::InitEnumParseWrapper<"
"$unknown_fields_type$>(&$msg$$name$_, $1$_IsValid, "
"$unknown_fields_type$>(&$msg$$field$, $1$_IsValid, "
"$2$, &$msg$_internal_metadata_);\n"
"ptr = ctx->ParseMessage(&object, ptr);\n",
QualifiedClassName(val->enum_type(), options_),
field->number());
} else {
format("ptr = ctx->ParseMessage(&$msg$$name$_, ptr);\n");
format("ptr = ctx->ParseMessage(&$msg$$field$, ptr);\n");
}
} else if (IsLazy(field, options_, scc_analyzer_)) {
bool eager_verify =
@ -1153,19 +1152,19 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format,
format(
"if (!$msg$_internal_has_$name$()) {\n"
" $msg$clear_$1$();\n"
" $msg$$1$_.$name$_ = ::$proto_ns$::Arena::CreateMessage<\n"
" $msg$$field$ = ::$proto_ns$::Arena::CreateMessage<\n"
" ::$proto_ns$::internal::LazyField>("
"$msg$GetArenaForAllocation());\n"
" $msg$set_has_$name$();\n"
"}\n"
"auto* lazy_field = $msg$$1$_.$name$_;\n",
"auto* lazy_field = $msg$$field$;\n",
field->containing_oneof()->name());
} else if (HasHasbit(field)) {
format(
"_Internal::set_has_$name$(&$has_bits$);\n"
"auto* lazy_field = &$msg$$name$_;\n");
"auto* lazy_field = &$msg$$field$;\n");
} else {
format("auto* lazy_field = &$msg$$name$_;\n");
format("auto* lazy_field = &$msg$$field$;\n");
}
format(
"::$proto_ns$::internal::LazyFieldParseHelper<\n"
@ -1188,7 +1187,7 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format,
"ptr);\n");
} else {
format(
"ptr = ctx->ParseMessage($msg$$name$_.AddWeak("
"ptr = ctx->ParseMessage($msg$$field$.AddWeak("
"reinterpret_cast<const ::$proto_ns$::MessageLite*>($1$ptr_)"
"), ptr);\n",
QualifiedDefaultInstanceName(field->message_type(), options_));
@ -1287,7 +1286,7 @@ void ParseFunctionGenerator::GenerateFieldBody(
format("_Internal::set_has_$name$(&$has_bits$);\n");
}
format(
"$msg$$name$_ = ::$proto_ns$::internal::ReadVarint$1$$2$(&ptr);\n"
"$msg$$field$ = ::$proto_ns$::internal::ReadVarint$1$$2$(&ptr);\n"
"CHK_(ptr);\n",
zigzag, size);
}
@ -1434,6 +1433,8 @@ void ParseFunctionGenerator::GenerateFieldSwitch(
format.Indent();
for (const auto* field : fields) {
// Set abbreviated form instead of field_member.
format.Set("field", FieldMemberName(field));
PrintFieldComment(format, field);
format("case $1$:\n", field->number());
format.Indent();

@ -150,7 +150,7 @@ void PrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
Formatter format(printer, variables_);
format(
"inline $type$ $classname$::_internal_$name$() const {\n"
" return $name$_;\n"
" return $field$;\n"
"}\n"
"inline $type$ $classname$::$name$() const {\n"
"$annotate_get$"
@ -159,7 +159,7 @@ void PrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n"
"inline void $classname$::_internal_set_$name$($type$ value) {\n"
" $set_hasbit$\n"
" $name$_ = value;\n"
" $field$ = value;\n"
"}\n"
"inline void $classname$::set_$name$($type$ value) {\n"
" _internal_set_$name$(value);\n"
@ -170,7 +170,7 @@ void PrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
void PrimitiveFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_ = $default$;\n");
format("$field$ = $default$;\n");
}
void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
@ -180,7 +180,7 @@ void PrimitiveFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
void PrimitiveFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("swap($name$_, other->$name$_);\n");
format("swap($field$, other->$field$);\n");
}
void PrimitiveFieldGenerator::GenerateConstructorCode(
@ -249,7 +249,7 @@ void PrimitiveOneofFieldGenerator::GenerateInlineAccessorDefinitions(
format(
"inline $type$ $classname$::_internal_$name$() const {\n"
" if (_internal_has_$name$()) {\n"
" return $field_member$;\n"
" return $field$;\n"
" }\n"
" return $default$;\n"
"}\n"
@ -258,7 +258,7 @@ void PrimitiveOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
" }\n"
" $field_member$ = value;\n"
" $field$ = value;\n"
"}\n"
"inline $type$ $classname$::$name$() const {\n"
"$annotate_get$"
@ -275,7 +275,7 @@ void PrimitiveOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void PrimitiveOneofFieldGenerator::GenerateClearingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field_member$ = $default$;\n");
format("$field$ = $default$;\n");
}
void PrimitiveOneofFieldGenerator::GenerateSwappingCode(
@ -344,7 +344,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
Formatter format(printer, variables_);
format(
"inline $type$ $classname$::_internal_$name$(int index) const {\n"
" return $name$_.Get(index);\n"
" return $field$.Get(index);\n"
"}\n"
"inline $type$ $classname$::$name$(int index) const {\n"
"$annotate_get$"
@ -353,11 +353,11 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n"
"inline void $classname$::set_$name$(int index, $type$ value) {\n"
"$annotate_set$"
" $name$_.Set(index, value);\n"
" $field$.Set(index, value);\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
"inline void $classname$::_internal_add_$name$($type$ value) {\n"
" $name$_.Add(value);\n"
" $field$.Add(value);\n"
"}\n"
"inline void $classname$::add_$name$($type$ value) {\n"
" _internal_add_$name$(value);\n"
@ -366,7 +366,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n"
"inline const ::$proto_ns$::RepeatedField< $type$ >&\n"
"$classname$::_internal_$name$() const {\n"
" return $name$_;\n"
" return $field$;\n"
"}\n"
"inline const ::$proto_ns$::RepeatedField< $type$ >&\n"
"$classname$::$name$() const {\n"
@ -376,7 +376,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n"
"inline ::$proto_ns$::RepeatedField< $type$ >*\n"
"$classname$::_internal_mutable_$name$() {\n"
" return &$name$_;\n"
" return &$field$;\n"
"}\n"
"inline ::$proto_ns$::RepeatedField< $type$ >*\n"
"$classname$::mutable_$name$() {\n"
@ -389,30 +389,19 @@ void RepeatedPrimitiveFieldGenerator::GenerateInlineAccessorDefinitions(
void RepeatedPrimitiveFieldGenerator::GenerateClearingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.Clear();\n");
format("$field$.Clear();\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateMergingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n");
format("$field$.MergeFrom(from.$field$);\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const {
// Not needed for repeated fields.
}
void RepeatedPrimitiveFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.CopyFrom(from.$name$_);\n");
format("$field$.InternalSwap(&other->$field$);\n");
}
void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray(
@ -456,7 +445,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateByteSize(
if (fixed_size == -1) {
format(
"size_t data_size = ::_pbi::WireFormatLite::\n"
" $declared_type$Size(this->$name$_);\n");
" $declared_type$Size(this->$field$);\n");
} else {
format(
"unsigned int count = static_cast<unsigned "

@ -98,8 +98,8 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override {}
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;

@ -54,8 +54,6 @@ void SetStringVariables(const FieldDescriptor* descriptor,
const std::string kNS = "::" + (*variables)["proto_ns"] + "::internal::";
const std::string kArenaStringPtr = kNS + "ArenaStringPtr";
const std::string kEmptyDefault = kArenaStringPtr + "::EmptyDefault{}";
const std::string kNonEmptyDefault = kArenaStringPtr + "::NonEmptyDefault{}";
(*variables)["default"] = DefaultValue(options, descriptor);
(*variables)["default_length"] =
@ -64,21 +62,17 @@ void SetStringVariables(const FieldDescriptor* descriptor,
(*variables)["default_variable_name"] = default_variable_string;
if (descriptor->default_value_string().empty()) {
(*variables)["init_value"] = "";
(*variables)["default_string"] = kNS + "GetEmptyStringAlreadyInited()";
(*variables)["default_value"] = "&" + (*variables)["default_string"];
(*variables)["default_value_tag"] = kEmptyDefault;
(*variables)["default_variable_or_tag"] = kEmptyDefault;
(*variables)["lazy_variable_args"] = "";
} else {
(*variables)["lazy_variable"] =
QualifiedClassName(descriptor->containing_type(), options) +
"::" + default_variable_string;
(*variables)["init_value"] = "nullptr";
(*variables)["default_string"] = (*variables)["lazy_variable"] + ".get()";
(*variables)["default_value"] = "nullptr";
(*variables)["default_value_tag"] = kNonEmptyDefault;
(*variables)["default_variable_or_tag"] = (*variables)["lazy_variable"];
(*variables)["lazy_variable_args"] = (*variables)["lazy_variable"] + ", ";
}
(*variables)["pointer_type"] =
@ -210,7 +204,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" // @@protoc_insertion_point(field_get:$full_name$)\n");
if (!descriptor_->default_value_string().empty()) {
format(
" if ($name$_.IsDefault()) return "
" if ($field$.IsDefault()) return "
"$default_variable_name$.get();\n");
}
format(
@ -222,7 +216,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline PROTOBUF_ALWAYS_INLINE\n"
"void $classname$::set_$name$(ArgT0&& arg0, ArgT... args) {\n"
" $set_hasbit$\n"
" $name$_.$setter$($default_value_tag$, static_cast<ArgT0 &&>(arg0),"
" $field$.$setter$(static_cast<ArgT0 &&>(arg0),"
" args..., GetArenaForAllocation());\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
@ -233,7 +227,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline PROTOBUF_ALWAYS_INLINE\n"
"void $classname$::set_$name$(ArgT0&& arg0, ArgT... args) {\n"
" $set_hasbit$\n"
" $name$_.$setter$(nullptr, static_cast<ArgT0 &&>(arg0),"
" $field$.$setter$(static_cast<ArgT0 &&>(arg0),"
" args..., GetArenaForAllocation(), _internal_$name$_donated(), "
"&$donating_states_word$, $mask_for_undonate$, this);\n"
"$annotate_set$"
@ -252,18 +246,18 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" return _s;\n"
"}\n"
"inline const std::string& $classname$::_internal_$name$() const {\n"
" return $name$_.Get();\n"
" return $field$.Get();\n"
"}\n"
"inline void $classname$::_internal_set_$name$(const std::string& "
"value) {\n"
" $set_hasbit$\n");
if (!inlined_) {
format(
" $name$_.Set($default_value_tag$, value, GetArenaForAllocation());\n"
" $field$.Set(value, GetArenaForAllocation());\n"
"}\n");
} else {
format(
" $name$_.Set(nullptr, value, GetArenaForAllocation(),\n"
" $field$.Set(value, GetArenaForAllocation(),\n"
" _internal_$name$_donated(), &$donating_states_word$, "
"$mask_for_undonate$, this);\n"
"}\n");
@ -273,12 +267,12 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" $set_hasbit$\n");
if (!inlined_) {
format(
" return $name$_.Mutable($default_variable_or_tag$, "
" return $field$.Mutable($lazy_variable_args$"
"GetArenaForAllocation());\n"
"}\n");
} else {
format(
" return $name$_.Mutable($default_variable_or_tag$, "
" return $field$.Mutable($lazy_variable_args$"
"GetArenaForAllocation(), _internal_$name$_donated(), "
"&$donating_states_word$, $mask_for_undonate$, this);\n"
"}\n");
@ -295,26 +289,23 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" }\n"
" $clear_hasbit$\n");
if (!inlined_) {
format(
" auto* p = $name$_.ReleaseNonDefault($default_value$, "
"GetArenaForAllocation());\n");
format(" auto* p = $field$.Release();\n");
if (descriptor_->default_value_string().empty()) {
format(
"#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"
" if ($name$_.IsDefault()) {\n"
" $name$_.Set($default_value$, \"\", GetArenaForAllocation());\n"
" if ($field$.IsDefault()) {\n"
" $field$.Set(\"\", GetArenaForAllocation());\n"
" }\n"
"#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n");
}
format(" return p;\n");
} else {
format(
" return $name$_.Release(nullptr, GetArenaForAllocation(), "
" return $field$.Release(GetArenaForAllocation(), "
"_internal_$name$_donated());\n");
}
} else {
format(
" return $name$_.Release($default_value$, GetArenaForAllocation());\n");
format(" return $field$.Release();\n");
}
format(
@ -326,21 +317,19 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" $clear_hasbit$\n"
" }\n");
if (!inlined_) {
format(
" $name$_.SetAllocated($default_value$, $name$,\n"
" GetArenaForAllocation());\n");
format(" $field$.SetAllocated($name$, GetArenaForAllocation());\n");
if (descriptor_->default_value_string().empty()) {
format(
"#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"
" if ($name$_.IsDefault()) {\n"
" $name$_.Set($default_value$, \"\", GetArenaForAllocation());\n"
" if ($field$.IsDefault()) {\n"
" $field$.Set(\"\", GetArenaForAllocation());\n"
" }\n"
"#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n");
}
} else {
// Currently, string fields with default value can't be inlined.
format(
" $name$_.SetAllocated(nullptr, $name$, GetArenaForAllocation(), "
" $field$.SetAllocated(nullptr, $name$, GetArenaForAllocation(), "
"_internal_$name$_donated(), &$donating_states_word$, "
"$mask_for_undonate$, this);\n");
}
@ -364,11 +353,11 @@ void StringFieldGenerator::GenerateNonInlineAccessorDefinitions(
void StringFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
if (descriptor_->default_value_string().empty()) {
format("$name$_.ClearToEmpty();\n");
format("$field$.ClearToEmpty();\n");
} else {
GOOGLE_DCHECK(!inlined_);
format(
"$name$_.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n");
"$field$.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n");
}
}
@ -394,20 +383,20 @@ void StringFieldGenerator::GenerateMessageClearingCode(
//
// For non-inlined strings, we distinguish from non-default by comparing
// instances, rather than contents.
format("$DCHK$(!$name$_.IsDefault());\n");
format("$DCHK$(!$field$.IsDefault());\n");
}
if (descriptor_->default_value_string().empty()) {
if (must_be_present) {
format("$name$_.ClearNonDefaultToEmpty();\n");
format("$field$.ClearNonDefaultToEmpty();\n");
} else {
format("$name$_.ClearToEmpty();\n");
format("$field$.ClearToEmpty();\n");
}
} else {
// Clear to a non-empty default is more involved, as we try to use the
// Arena if one is present and may need to reallocate the string.
format(
"$name$_.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n ");
"$field$.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n ");
}
}
@ -422,16 +411,15 @@ void StringFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
if (!inlined_) {
format(
"::$proto_ns$::internal::ArenaStringPtr::InternalSwap(\n"
" $default_value$,\n"
" &$name$_, lhs_arena,\n"
" &other->$name$_, rhs_arena\n"
" &$field$, lhs_arena,\n"
" &other->$field$, rhs_arena\n"
");\n");
} else {
format(
"::$proto_ns$::internal::InlinedStringField::InternalSwap(\n"
" &$name$_, lhs_arena, "
" &$field$, lhs_arena, "
"(_inlined_string_donated_[0] & 0x1u) == 0, this,\n"
" &other->$name$_, rhs_arena, "
" &other->$field$, rhs_arena, "
"(other->_inlined_string_donated_[0] & 0x1u) == 0, other);\n");
}
}
@ -442,12 +430,12 @@ void StringFieldGenerator::GenerateConstructorCode(io::Printer* printer) const {
return;
}
GOOGLE_DCHECK(!inlined_);
format("$name$_.InitDefault($init_value$);\n");
format("$name$_.InitDefault();\n");
if (IsString(descriptor_, options_) &&
descriptor_->default_value_string().empty()) {
format(
"#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"
" $name$_.Set($default_value$, \"\", GetArenaForAllocation());\n"
" $name$_.Set(\"\", GetArenaForAllocation());\n"
"#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n");
}
}
@ -470,11 +458,11 @@ void StringFieldGenerator::GenerateCopyConstructorCode(
if (!inlined_) {
format(
"$name$_.Set($default_value_tag$, from._internal_$name$(), \n"
"$field$.Set(from._internal_$name$(), \n"
" GetArenaForAllocation());\n");
} else {
format(
"$name$_.Set(nullptr, from._internal_$name$(),\n"
"$field$.Set(from._internal_$name$(),\n"
" GetArenaForAllocation(), _internal_$name$_donated(), "
"&$donating_states_word$, $mask_for_undonate$, this);\n");
}
@ -486,14 +474,14 @@ void StringFieldGenerator::GenerateCopyConstructorCode(
void StringFieldGenerator::GenerateDestructorCode(io::Printer* printer) const {
Formatter format(printer, variables_);
if (!inlined_) {
format("$name$_.DestroyNoArena($default_value$);\n");
format("$field$.Destroy();\n");
return;
}
// Explicitly calls ~InlinedStringField as its automatic call is disabled.
// Destructor has been implicitly skipped as a union, and even the
// message-owned arena is enabled, arena could still be missing for
// Arena::CreateMessage(nullptr).
format("$name$_.~InlinedStringField();\n");
format("$field$.~InlinedStringField();\n");
}
ArenaDtorNeeds StringFieldGenerator::NeedsArenaDestructor() const {
@ -507,7 +495,7 @@ void StringFieldGenerator::GenerateArenaDestructorCode(
// _this is the object being destructed (we are inside a static method here).
format(
"if (!_this->_internal_$name$_donated()) {\n"
" _this->$name$_.~InlinedStringField();\n"
" _this->$field$.~InlinedStringField();\n"
"}\n");
}
@ -575,9 +563,9 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (!_internal_has_$name$()) {\n"
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
" $field_member$.InitDefault($init_value$);\n"
" $field$.InitDefault();\n"
" }\n"
" $field_member$.$setter$($default_value_tag$,"
" $field$.$setter$("
" static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
@ -590,7 +578,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
"}\n"
"inline const std::string& $classname$::_internal_$name$() const {\n"
" if (_internal_has_$name$()) {\n"
" return $field_member$.Get();\n"
" return $field$.Get();\n"
" }\n"
" return $default_string$;\n"
"}\n"
@ -599,28 +587,26 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (!_internal_has_$name$()) {\n"
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
" $field_member$.InitDefault($init_value$);\n"
" $field$.InitDefault();\n"
" }\n"
" $field_member$.Set($default_value_tag$, value, "
"GetArenaForAllocation());\n"
" $field$.Set(value, GetArenaForAllocation());\n"
"}\n");
format(
"inline std::string* $classname$::_internal_mutable_$name$() {\n"
" if (!_internal_has_$name$()) {\n"
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
" $field_member$.InitDefault($init_value$);\n"
" $field$.InitDefault();\n"
" }\n"
" return $field_member$.Mutable(\n"
" $default_variable_or_tag$, GetArenaForAllocation());\n"
" return $field$.Mutable($lazy_variable_args$"
" GetArenaForAllocation());\n"
"}\n"
"inline std::string* $classname$::$release_name$() {\n"
"$annotate_release$"
" // @@protoc_insertion_point(field_release:$full_name$)\n"
" if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
" return $field_member$.ReleaseNonDefault($default_value$, "
"GetArenaForAllocation());\n"
" return $field$.Release();\n"
" } else {\n"
" return nullptr;\n"
" }\n"
@ -631,7 +617,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" }\n"
" if ($name$ != nullptr) {\n"
" set_has_$name$();\n"
" $field_member$.InitAllocated($name$, GetArenaForAllocation());\n"
" $field$.InitAllocated($name$, GetArenaForAllocation());\n"
" }\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
@ -641,9 +627,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void StringOneofFieldGenerator::GenerateClearingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"$field_member$.Destroy($default_value_tag$, "
"GetArenaForAllocation());\n");
format("$field$.Destroy();\n");
}
void StringOneofFieldGenerator::GenerateMessageClearingCode(
@ -758,14 +742,14 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
format(
"inline const std::string& $classname$::_internal_$name$(int index) "
"const {\n"
" return $name$_.InternalCheckedGet(\n"
" return $field$.InternalCheckedGet(\n"
" index, ::$proto_ns$::internal::GetEmptyStringAlreadyInited());\n"
"}\n");
} else {
format(
"inline const std::string& $classname$::_internal_$name$(int index) "
"const {\n"
" return $name$_.Get(index);\n"
" return $field$.Get(index);\n"
"}\n");
}
format(
@ -777,23 +761,23 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline std::string* $classname$::mutable_$name$(int index) {\n"
"$annotate_mutable$"
" // @@protoc_insertion_point(field_mutable:$full_name$)\n"
" return $name$_.Mutable(index);\n"
" return $field$.Mutable(index);\n"
"}\n"
"inline void $classname$::set_$name$(int index, const std::string& "
"value) "
"{\n"
" $name$_.Mutable(index)->assign(value);\n"
" $field$.Mutable(index)->assign(value);\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
"inline void $classname$::set_$name$(int index, std::string&& value) {\n"
" $name$_.Mutable(index)->assign(std::move(value));\n"
" $field$.Mutable(index)->assign(std::move(value));\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
"inline void $classname$::set_$name$(int index, const char* value) {\n"
" $null_check$"
" $name$_.Mutable(index)->assign(value);\n"
" $field$.Mutable(index)->assign(value);\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set_char:$full_name$)\n"
"}\n");
@ -801,7 +785,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
format(
"inline void "
"$classname$::set_$name$(int index, StringPiece value) {\n"
" $name$_.Mutable(index)->assign(value.data(), value.size());\n"
" $field$.Mutable(index)->assign(value.data(), value.size());\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
"}\n");
@ -810,34 +794,34 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline void "
"$classname$::set_$name$"
"(int index, const $pointer_type$* value, size_t size) {\n"
" $name$_.Mutable(index)->assign(\n"
" $field$.Mutable(index)->assign(\n"
" reinterpret_cast<const char*>(value), size);\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
"}\n"
"inline std::string* $classname$::_internal_add_$name$() {\n"
" return $name$_.Add();\n"
" return $field$.Add();\n"
"}\n"
"inline void $classname$::add_$name$(const std::string& value) {\n"
" $name$_.Add()->assign(value);\n"
" $field$.Add()->assign(value);\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n"
"inline void $classname$::add_$name$(std::string&& value) {\n"
" $name$_.Add(std::move(value));\n"
" $field$.Add(std::move(value));\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n"
"inline void $classname$::add_$name$(const char* value) {\n"
" $null_check$"
" $name$_.Add()->assign(value);\n"
" $field$.Add()->assign(value);\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add_char:$full_name$)\n"
"}\n");
if (!options_.opensource_runtime) {
format(
"inline void $classname$::add_$name$(StringPiece value) {\n"
" $name$_.Add()->assign(value.data(), value.size());\n"
" $field$.Add()->assign(value.data(), value.size());\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add_string_piece:$full_name$)\n"
"}\n");
@ -845,7 +829,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
format(
"inline void "
"$classname$::add_$name$(const $pointer_type$* value, size_t size) {\n"
" $name$_.Add()->assign(reinterpret_cast<const char*>(value), size);\n"
" $field$.Add()->assign(reinterpret_cast<const char*>(value), size);\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add_pointer:$full_name$)\n"
"}\n"
@ -853,43 +837,32 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"$classname$::$name$() const {\n"
"$annotate_list$"
" // @@protoc_insertion_point(field_list:$full_name$)\n"
" return $name$_;\n"
" return $field$;\n"
"}\n"
"inline ::$proto_ns$::RepeatedPtrField<std::string>*\n"
"$classname$::mutable_$name$() {\n"
"$annotate_mutable_list$"
" // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
" return &$name$_;\n"
" return &$field$;\n"
"}\n");
}
void RepeatedStringFieldGenerator::GenerateClearingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.Clear();\n");
format("$field$.Clear();\n");
}
void RepeatedStringFieldGenerator::GenerateMergingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.MergeFrom(from.$name$_);\n");
format("$field$.MergeFrom(from.$field$);\n");
}
void RepeatedStringFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.InternalSwap(&other->$name$_);\n");
}
void RepeatedStringFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const {
// Not needed for repeated fields.
}
void RepeatedStringFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.CopyFrom(from.$name$_);");
format("$field$.InternalSwap(&other->$field$);\n");
}
void RepeatedStringFieldGenerator::GenerateSerializeWithCachedSizesToArray(
@ -916,11 +889,11 @@ void RepeatedStringFieldGenerator::GenerateByteSize(
Formatter format(printer, variables_);
format(
"total_size += $tag_size$ *\n"
" ::$proto_ns$::internal::FromIntSize($name$_.size());\n"
"for (int i = 0, n = $name$_.size(); i < n; i++) {\n"
" ::$proto_ns$::internal::FromIntSize($field$.size());\n"
"for (int i = 0, n = $field$.size(); i < n; i++) {\n"
" total_size += "
"::$proto_ns$::internal::WireFormatLite::$declared_type$Size(\n"
" $name$_.Get(i));\n"
" $field$.Get(i));\n"
"}\n");
}

@ -111,8 +111,8 @@ class RepeatedStringFieldGenerator : public FieldGenerator {
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override {}
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;

@ -66,15 +66,26 @@ namespace {
const char* kDefaultPackage = "";
// Names that should be avoided as field names.
// Using them will cause the compiler to generate accessors whose names are
// colliding with methods defined in base classes.
// Names that should be avoided (in UpperCamelCase format).
// Using them will cause the compiler to generate accessors whose names
// collide with methods defined in base classes.
// Keep this list in sync with specialFieldNames in
// java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
const char* kForbiddenWordList[] = {
// message base class:
"cached_size",
"serialized_size",
// java.lang.Object:
"class",
"Class",
// com.google.protobuf.MessageLiteOrBuilder:
"DefaultInstanceForType",
// com.google.protobuf.MessageLite:
"ParserForType",
"SerializedSize",
// com.google.protobuf.MessageOrBuilder:
"AllFields",
"DescriptorForType",
"InitializationErrorString",
"UnknownFields",
// obsolete. kept for backwards compatibility of generated code
"CachedSize",
};
const std::unordered_set<std::string>* kReservedNames =
@ -93,7 +104,7 @@ const std::unordered_set<std::string>* kReservedNames =
bool IsForbidden(const std::string& field_name) {
for (int i = 0; i < GOOGLE_ARRAYSIZE(kForbiddenWordList); ++i) {
if (field_name == kForbiddenWordList[i]) {
if (UnderscoresToCamelCase(field_name, true) == kForbiddenWordList[i]) {
return true;
}
}

@ -190,10 +190,20 @@ bool ObjectiveCGenerator::GenerateAll(
// header search path since the generate #import will be more complete.
generation_options.runtime_import_prefix =
StripSuffixString(options[i].second, "/");
} else if (options[i].first == "default_objc_class_prefix") {
// The default objc class prefix to use if specified by the command line
// invocation. The file option is always honored first if one is present.
std::string value = options[i].second;
if (value.empty()) {
*error = "error: default_objc_class_prefix cannot be empty.";
return false;
}
SetDefaultObjcClassPrefix(value);
} else if (options[i].first == "use_package_as_prefix") {
// Controls how the symbols should be prefixed to avoid symbols
// collisions. The objc_class_prefix file option is always honored, this
// is just what to do if that isn't set. The available options are:
// collisions. The objc_class_prefix file option is always honored first
// followed by the default_objc_class_prefix generator option. This is is just
// what to do if either of these options are not set. The available options are:
// "no": Not prefixed (the existing mode).
// "yes": Make a prefix out of the proto package.
bool value = false;

@ -99,6 +99,9 @@ class PrefixModeStorage {
public:
PrefixModeStorage();
const std::string default_objc_class_prefix() const { return default_objc_class_prefix_; }
void set_default_objc_class_prefix(const std::string& default_objc_class_prefix) { default_objc_class_prefix_ = default_objc_class_prefix; }
bool use_package_name() const { return use_package_name_; }
void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; }
@ -116,13 +119,14 @@ class PrefixModeStorage {
private:
bool use_package_name_;
std::string default_objc_class_prefix_;
std::string exception_path_;
std::string forced_prefix_;
std::unordered_set<std::string> exceptions_;
};
PrefixModeStorage::PrefixModeStorage() {
// Even thought there are generation options, have an env back door since some
// Even though there are generation options, have an env back door since some
// of these helpers could be used in other plugins.
use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false);
@ -169,6 +173,10 @@ PrefixModeStorage g_prefix_mode;
} // namespace
void SetDefaultObjcClassPrefix(const std::string& default_objc_class_prefix) {
g_prefix_mode.set_default_objc_class_prefix(default_objc_class_prefix);
}
bool UseProtoPackageAsDefaultPrefix() {
return g_prefix_mode.use_package_name();
}
@ -526,11 +534,16 @@ std::string BaseFileName(const FileDescriptor* file) {
}
std::string FileClassPrefix(const FileDescriptor* file) {
// Always honor the file option.
// Always honor the file option first.
if (file->options().has_objc_class_prefix()) {
return file->options().objc_class_prefix();
}
// If a default prefix is passed through objc_opt then accept it.
if (!g_prefix_mode.default_objc_class_prefix().empty()) {
return g_prefix_mode.default_objc_class_prefix();
}
// If package prefix isn't enabled, done.
if (!g_prefix_mode.use_package_name()) {
return "";

@ -47,6 +47,9 @@ namespace protobuf {
namespace compiler {
namespace objectivec {
// Set the default objc class prefix that should be used. This method is used only
// when default_objc_class_prefix is passed through objc_opt.
void PROTOC_EXPORT SetDefaultObjcClassPrefix(const std::string& objc_class_prefix);
// Get/Set if the proto package should be used to make the default prefix for
// symbols. This will then impact most of the type naming apis below. It is done
// as a global to not break any other generator reusing the methods since they
@ -68,6 +71,7 @@ struct Options {
std::string generate_for_named_framework;
std::string named_framework_to_proto_path_mappings_path;
std::string runtime_import_prefix;
std::string default_objc_class_prefix;
bool prefixes_must_be_registered;
bool require_prefixes;
};

@ -2466,7 +2466,9 @@ TEST_F(ParseDescriptorDebugTest, TestMaps) {
// *output_field to the descriptor of the field, and *output_index to -1.
// Returns true if the path was valid, false otherwise. A gTest failure is
// recorded before returning false.
bool FollowPath(const Message& root, const int* path_begin, const int* path_end,
bool FollowPath(const Message& root,
RepeatedField<int>::const_iterator path_begin,
RepeatedField<int>::const_iterator path_end,
const Message** output_message,
const FieldDescriptor** output_field, int* output_index) {
if (path_begin == path_end) {

@ -48,28 +48,29 @@ const std::string kDescriptorMetadataFile =
const std::string kDescriptorDirName = "Google/Protobuf/Internal";
const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal";
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",
"finally", "fn", "for", "foreach", "function",
"global", "goto", "if", "implements", "include",
"include_once", "instanceof", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "or",
"print", "private", "protected", "public", "require",
"require_once", "return", "static", "switch", "throw",
"trait", "try", "unset", "use", "var",
"while", "xor", "yield", "int", "float",
"bool", "string", "true", "false", "null",
"void", "iterable"};
"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",
"finally", "fn", "for", "foreach", "function",
"global", "goto", "if", "implements", "include",
"include_once", "instanceof", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "or",
"parent", "print", "private", "protected", "public",
"require", "require_once", "return", "self", "static",
"switch", "throw", "trait", "try", "unset",
"use", "var", "while", "xor", "yield",
"int", "float", "bool", "string", "true",
"false", "null", "void", "iterable"};
const char* const kValidConstantNames[] = {
"int", "float", "bool", "string", "true",
"false", "null", "void", "iterable",
"false", "null", "void", "iterable", "parent",
"self"
};
const int kReservedNamesSize = 77;
const int kValidConstantNamesSize = 9;
const int kReservedNamesSize = 79;
const int kValidConstantNamesSize = 11;
const int kFieldSetter = 1;
const int kFieldGetter = 2;
const int kFieldProperty = 3;
@ -1114,7 +1115,7 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options,
std::map<const FileDescriptor*, int> dependency_count;
std::set<const FileDescriptor*> nodes_without_dependency;
FileDescriptorSet sorted_file_set;
AnalyzeDependencyForFile(
file, &nodes_without_dependency, &deps, &dependency_count);
@ -2065,7 +2066,7 @@ void GenerateCMessage(const Descriptor* message, io::Printer* printer) {
break;
default:
break;
}
}
printer->Print(
" ZEND_FE_END\n"

@ -252,10 +252,10 @@ Version::Version(const Version& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
suffix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
suffix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
suffix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_suffix()) {
suffix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_suffix(),
suffix_.Set(from._internal_suffix(),
GetArenaForAllocation());
}
::memcpy(&major_, &from.major_,
@ -267,7 +267,7 @@ Version::Version(const Version& from)
inline void Version::SharedCtor() {
suffix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
suffix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
suffix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&major_) - reinterpret_cast<char*>(this)),
@ -286,7 +286,7 @@ Version::~Version() {
inline void Version::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
suffix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
suffix_.Destroy();
}
void Version::SetCachedSize(int size) const {
@ -517,7 +517,6 @@ void Version::InternalSwap(Version* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&suffix_, lhs_arena,
&other->suffix_, rhs_arena
);
@ -572,10 +571,10 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
parameter_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
parameter_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
parameter_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_parameter()) {
parameter_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_parameter(),
parameter_.Set(from._internal_parameter(),
GetArenaForAllocation());
}
if (from._internal_has_compiler_version()) {
@ -589,7 +588,7 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
inline void CodeGeneratorRequest::SharedCtor() {
parameter_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
parameter_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
parameter_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
compiler_version_ = nullptr;
}
@ -605,7 +604,7 @@ CodeGeneratorRequest::~CodeGeneratorRequest() {
inline void CodeGeneratorRequest::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
parameter_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
parameter_.Destroy();
if (this != internal_default_instance()) delete compiler_version_;
}
@ -864,7 +863,6 @@ void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) {
file_to_generate_.InternalSwap(&other->file_to_generate_);
proto_file_.InternalSwap(&other->proto_file_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&parameter_, lhs_arena,
&other->parameter_, rhs_arena
);
@ -917,26 +915,26 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
insertion_point_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
insertion_point_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
insertion_point_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_insertion_point()) {
insertion_point_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_insertion_point(),
insertion_point_.Set(from._internal_insertion_point(),
GetArenaForAllocation());
}
content_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
content_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_content()) {
content_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_content(),
content_.Set(from._internal_content(),
GetArenaForAllocation());
}
if (from._internal_has_generated_code_info()) {
@ -950,15 +948,15 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon
inline void CodeGeneratorResponse_File::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
insertion_point_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
insertion_point_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
insertion_point_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
content_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
content_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
generated_code_info_ = nullptr;
}
@ -974,9 +972,9 @@ CodeGeneratorResponse_File::~CodeGeneratorResponse_File() {
inline void CodeGeneratorResponse_File::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
insertion_point_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
content_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
insertion_point_.Destroy();
content_.Destroy();
if (this != internal_default_instance()) delete generated_code_info_;
}
@ -1234,17 +1232,14 @@ void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other)
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&insertion_point_, lhs_arena,
&other->insertion_point_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&content_, lhs_arena,
&other->content_, rhs_arena
);
@ -1284,10 +1279,10 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
error_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
error_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
error_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_error()) {
error_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_error(),
error_.Set(from._internal_error(),
GetArenaForAllocation());
}
supported_features_ = from.supported_features_;
@ -1297,7 +1292,7 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
inline void CodeGeneratorResponse::SharedCtor() {
error_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
error_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
error_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
supported_features_ = uint64_t{0u};
}
@ -1313,7 +1308,7 @@ CodeGeneratorResponse::~CodeGeneratorResponse() {
inline void CodeGeneratorResponse::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
error_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
error_.Destroy();
}
void CodeGeneratorResponse::SetCachedSize(int size) const {
@ -1525,7 +1520,6 @@ void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) {
swap(_has_bits_[0], other->_has_bits_[0]);
file_.InternalSwap(&other->file_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&error_, lhs_arena,
&other->error_, rhs_arena
);

@ -1093,7 +1093,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void Version::set_suffix(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000001u;
suffix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
suffix_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.suffix)
}
inline std::string* Version::mutable_suffix() {
@ -1106,11 +1106,11 @@ inline const std::string& Version::_internal_suffix() const {
}
inline void Version::_internal_set_suffix(const std::string& value) {
_has_bits_[0] |= 0x00000001u;
suffix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
suffix_.Set(value, GetArenaForAllocation());
}
inline std::string* Version::_internal_mutable_suffix() {
_has_bits_[0] |= 0x00000001u;
return suffix_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return suffix_.Mutable(GetArenaForAllocation());
}
inline std::string* Version::release_suffix() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.Version.suffix)
@ -1118,10 +1118,10 @@ inline std::string* Version::release_suffix() {
return nullptr;
}
_has_bits_[0] &= ~0x00000001u;
auto* p = suffix_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
auto* p = suffix_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (suffix_.IsDefault()) {
suffix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
suffix_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p;
@ -1132,11 +1132,10 @@ inline void Version::set_allocated_suffix(std::string* suffix) {
} else {
_has_bits_[0] &= ~0x00000001u;
}
suffix_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), suffix,
GetArenaForAllocation());
suffix_.SetAllocated(suffix, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (suffix_.IsDefault()) {
suffix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
suffix_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.Version.suffix)
@ -1241,7 +1240,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorRequest::set_parameter(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000001u;
parameter_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
parameter_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.parameter)
}
inline std::string* CodeGeneratorRequest::mutable_parameter() {
@ -1254,11 +1253,11 @@ inline const std::string& CodeGeneratorRequest::_internal_parameter() const {
}
inline void CodeGeneratorRequest::_internal_set_parameter(const std::string& value) {
_has_bits_[0] |= 0x00000001u;
parameter_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
parameter_.Set(value, GetArenaForAllocation());
}
inline std::string* CodeGeneratorRequest::_internal_mutable_parameter() {
_has_bits_[0] |= 0x00000001u;
return parameter_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return parameter_.Mutable(GetArenaForAllocation());
}
inline std::string* CodeGeneratorRequest::release_parameter() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.parameter)
@ -1266,10 +1265,10 @@ inline std::string* CodeGeneratorRequest::release_parameter() {
return nullptr;
}
_has_bits_[0] &= ~0x00000001u;
auto* p = parameter_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
auto* p = parameter_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (parameter_.IsDefault()) {
parameter_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
parameter_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p;
@ -1280,11 +1279,10 @@ inline void CodeGeneratorRequest::set_allocated_parameter(std::string* parameter
} else {
_has_bits_[0] &= ~0x00000001u;
}
parameter_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), parameter,
GetArenaForAllocation());
parameter_.SetAllocated(parameter, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (parameter_.IsDefault()) {
parameter_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
parameter_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.parameter)
@ -1404,7 +1402,7 @@ inline void CodeGeneratorRequest::set_allocated_compiler_version(::PROTOBUF_NAME
}
if (compiler_version) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<::PROTOBUF_NAMESPACE_ID::compiler::Version>::GetOwningArena(compiler_version);
::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(compiler_version);
if (message_arena != submessage_arena) {
compiler_version = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
message_arena, compiler_version, submessage_arena);
@ -1441,7 +1439,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorResponse_File::set_name(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000001u;
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
name_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.name)
}
inline std::string* CodeGeneratorResponse_File::mutable_name() {
@ -1454,11 +1452,11 @@ inline const std::string& CodeGeneratorResponse_File::_internal_name() const {
}
inline void CodeGeneratorResponse_File::_internal_set_name(const std::string& value) {
_has_bits_[0] |= 0x00000001u;
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
name_.Set(value, GetArenaForAllocation());
}
inline std::string* CodeGeneratorResponse_File::_internal_mutable_name() {
_has_bits_[0] |= 0x00000001u;
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return name_.Mutable(GetArenaForAllocation());
}
inline std::string* CodeGeneratorResponse_File::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.name)
@ -1466,10 +1464,10 @@ inline std::string* CodeGeneratorResponse_File::release_name() {
return nullptr;
}
_has_bits_[0] &= ~0x00000001u;
auto* p = name_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
auto* p = name_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p;
@ -1480,11 +1478,10 @@ inline void CodeGeneratorResponse_File::set_allocated_name(std::string* name) {
} else {
_has_bits_[0] &= ~0x00000001u;
}
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArenaForAllocation());
name_.SetAllocated(name, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (name_.IsDefault()) {
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.name)
@ -1510,7 +1507,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorResponse_File::set_insertion_point(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000002u;
insertion_point_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
insertion_point_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
}
inline std::string* CodeGeneratorResponse_File::mutable_insertion_point() {
@ -1523,11 +1520,11 @@ inline const std::string& CodeGeneratorResponse_File::_internal_insertion_point(
}
inline void CodeGeneratorResponse_File::_internal_set_insertion_point(const std::string& value) {
_has_bits_[0] |= 0x00000002u;
insertion_point_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
insertion_point_.Set(value, GetArenaForAllocation());
}
inline std::string* CodeGeneratorResponse_File::_internal_mutable_insertion_point() {
_has_bits_[0] |= 0x00000002u;
return insertion_point_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return insertion_point_.Mutable(GetArenaForAllocation());
}
inline std::string* CodeGeneratorResponse_File::release_insertion_point() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
@ -1535,10 +1532,10 @@ inline std::string* CodeGeneratorResponse_File::release_insertion_point() {
return nullptr;
}
_has_bits_[0] &= ~0x00000002u;
auto* p = insertion_point_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
auto* p = insertion_point_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (insertion_point_.IsDefault()) {
insertion_point_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
insertion_point_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p;
@ -1549,11 +1546,10 @@ inline void CodeGeneratorResponse_File::set_allocated_insertion_point(std::strin
} else {
_has_bits_[0] &= ~0x00000002u;
}
insertion_point_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), insertion_point,
GetArenaForAllocation());
insertion_point_.SetAllocated(insertion_point, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (insertion_point_.IsDefault()) {
insertion_point_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
insertion_point_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
@ -1579,7 +1575,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorResponse_File::set_content(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000004u;
content_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
content_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.content)
}
inline std::string* CodeGeneratorResponse_File::mutable_content() {
@ -1592,11 +1588,11 @@ inline const std::string& CodeGeneratorResponse_File::_internal_content() const
}
inline void CodeGeneratorResponse_File::_internal_set_content(const std::string& value) {
_has_bits_[0] |= 0x00000004u;
content_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
content_.Set(value, GetArenaForAllocation());
}
inline std::string* CodeGeneratorResponse_File::_internal_mutable_content() {
_has_bits_[0] |= 0x00000004u;
return content_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return content_.Mutable(GetArenaForAllocation());
}
inline std::string* CodeGeneratorResponse_File::release_content() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.content)
@ -1604,10 +1600,10 @@ inline std::string* CodeGeneratorResponse_File::release_content() {
return nullptr;
}
_has_bits_[0] &= ~0x00000004u;
auto* p = content_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
auto* p = content_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (content_.IsDefault()) {
content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
content_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p;
@ -1618,11 +1614,10 @@ inline void CodeGeneratorResponse_File::set_allocated_content(std::string* conte
} else {
_has_bits_[0] &= ~0x00000004u;
}
content_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), content,
GetArenaForAllocation());
content_.SetAllocated(content, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (content_.IsDefault()) {
content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
content_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.content)
@ -1701,8 +1696,7 @@ inline void CodeGeneratorResponse_File::set_allocated_generated_code_info(::PROT
}
if (generated_code_info) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<
::PROTOBUF_NAMESPACE_ID::MessageLite>::GetOwningArena(
::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(
reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(generated_code_info));
if (message_arena != submessage_arena) {
generated_code_info = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
@ -1740,7 +1734,7 @@ template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void CodeGeneratorResponse::set_error(ArgT0&& arg0, ArgT... args) {
_has_bits_[0] |= 0x00000001u;
error_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
error_.Set(static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.error)
}
inline std::string* CodeGeneratorResponse::mutable_error() {
@ -1753,11 +1747,11 @@ inline const std::string& CodeGeneratorResponse::_internal_error() const {
}
inline void CodeGeneratorResponse::_internal_set_error(const std::string& value) {
_has_bits_[0] |= 0x00000001u;
error_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
error_.Set(value, GetArenaForAllocation());
}
inline std::string* CodeGeneratorResponse::_internal_mutable_error() {
_has_bits_[0] |= 0x00000001u;
return error_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
return error_.Mutable(GetArenaForAllocation());
}
inline std::string* CodeGeneratorResponse::release_error() {
// @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.error)
@ -1765,10 +1759,10 @@ inline std::string* CodeGeneratorResponse::release_error() {
return nullptr;
}
_has_bits_[0] &= ~0x00000001u;
auto* p = error_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
auto* p = error_.Release();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (error_.IsDefault()) {
error_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
error_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
return p;
@ -1779,11 +1773,10 @@ inline void CodeGeneratorResponse::set_allocated_error(std::string* error) {
} else {
_has_bits_[0] &= ~0x00000001u;
}
error_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error,
GetArenaForAllocation());
error_.SetAllocated(error, GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (error_.IsDefault()) {
error_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
error_.Set("", GetArenaForAllocation());
}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.error)

@ -73,15 +73,15 @@ static void CloseHandleOrDie(HANDLE handle) {
Subprocess::Subprocess()
: process_start_error_(ERROR_SUCCESS),
child_handle_(NULL),
child_stdin_(NULL),
child_stdout_(NULL) {}
child_handle_(nullptr),
child_stdin_(nullptr),
child_stdout_(nullptr) {}
Subprocess::~Subprocess() {
if (child_stdin_ != NULL) {
if (child_stdin_ != nullptr) {
CloseHandleOrDie(child_stdin_);
}
if (child_stdout_ != NULL) {
if (child_stdout_ != nullptr) {
CloseHandleOrDie(child_stdout_);
}
}
@ -93,10 +93,10 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) {
HANDLE stdout_pipe_read;
HANDLE stdout_pipe_write;
if (!CreatePipe(&stdin_pipe_read, &stdin_pipe_write, NULL, 0)) {
if (!CreatePipe(&stdin_pipe_read, &stdin_pipe_write, nullptr, 0)) {
GOOGLE_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError());
}
if (!CreatePipe(&stdout_pipe_read, &stdout_pipe_write, NULL, 0)) {
if (!CreatePipe(&stdout_pipe_read, &stdout_pipe_write, nullptr, 0)) {
GOOGLE_LOG(FATAL) << "CreatePipe: " << Win32ErrorMessage(GetLastError());
}
@ -134,14 +134,14 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) {
// Create the process.
PROCESS_INFORMATION process_info;
if (CreateProcessA((search_mode == SEARCH_PATH) ? NULL : program.c_str(),
(search_mode == SEARCH_PATH) ? command_line : NULL,
NULL, // process security attributes
NULL, // thread security attributes
TRUE, // inherit handles?
0, // obscure creation flags
NULL, // environment (inherit from parent)
NULL, // current directory (inherit from parent)
if (CreateProcessA((search_mode == SEARCH_PATH) ? nullptr : program.c_str(),
(search_mode == SEARCH_PATH) ? command_line : nullptr,
nullptr, // process security attributes
nullptr, // thread security attributes
TRUE, // inherit handles?
0, // obscure creation flags
nullptr, // environment (inherit from parent)
nullptr, // current directory (inherit from parent)
&startup_info, &process_info)) {
child_handle_ = process_info.hProcess;
CloseHandleOrDie(process_info.hThread);
@ -165,28 +165,28 @@ bool Subprocess::Communicate(const Message& input, Message* output,
return false;
}
GOOGLE_CHECK(child_handle_ != NULL) << "Must call Start() first.";
GOOGLE_CHECK(child_handle_ != nullptr) << "Must call Start() first.";
std::string input_data = input.SerializeAsString();
std::string output_data;
int input_pos = 0;
while (child_stdout_ != NULL) {
while (child_stdout_ != nullptr) {
HANDLE handles[2];
int handle_count = 0;
if (child_stdin_ != NULL) {
if (child_stdin_ != nullptr) {
handles[handle_count++] = child_stdin_;
}
if (child_stdout_ != NULL) {
if (child_stdout_ != nullptr) {
handles[handle_count++] = child_stdout_;
}
DWORD wait_result =
WaitForMultipleObjects(handle_count, handles, FALSE, INFINITE);
HANDLE signaled_handle = NULL;
HANDLE signaled_handle = nullptr;
if (wait_result >= WAIT_OBJECT_0 &&
wait_result < WAIT_OBJECT_0 + handle_count) {
signaled_handle = handles[wait_result - WAIT_OBJECT_0];
@ -201,7 +201,7 @@ bool Subprocess::Communicate(const Message& input, Message* output,
if (signaled_handle == child_stdin_) {
DWORD n;
if (!WriteFile(child_stdin_, input_data.data() + input_pos,
input_data.size() - input_pos, &n, NULL)) {
input_data.size() - input_pos, &n, nullptr)) {
// Child closed pipe. Presumably it will report an error later.
// Pretend we're done for now.
input_pos = input_data.size();
@ -212,27 +212,27 @@ bool Subprocess::Communicate(const Message& input, Message* output,
if (input_pos == input_data.size()) {
// We're done writing. Close.
CloseHandleOrDie(child_stdin_);
child_stdin_ = NULL;
child_stdin_ = nullptr;
}
} else if (signaled_handle == child_stdout_) {
char buffer[4096];
DWORD n;
if (!ReadFile(child_stdout_, buffer, sizeof(buffer), &n, NULL)) {
if (!ReadFile(child_stdout_, buffer, sizeof(buffer), &n, nullptr)) {
// We're done reading. Close.
CloseHandleOrDie(child_stdout_);
child_stdout_ = NULL;
child_stdout_ = nullptr;
} else {
output_data.append(buffer, n);
}
}
}
if (child_stdin_ != NULL) {
if (child_stdin_ != nullptr) {
// Child did not finish reading input before it closed the output.
// Presumably it exited with an error.
CloseHandleOrDie(child_stdin_);
child_stdin_ = NULL;
child_stdin_ = nullptr;
}
DWORD wait_result = WaitForSingleObject(child_handle_, INFINITE);
@ -252,7 +252,7 @@ bool Subprocess::Communicate(const Message& input, Message* output,
}
CloseHandleOrDie(child_handle_);
child_handle_ = NULL;
child_handle_ = nullptr;
if (exit_code != 0) {
*error = strings::Substitute("Plugin failed with status code $0.", exit_code);
@ -273,9 +273,10 @@ std::string Subprocess::Win32ErrorMessage(DWORD error_code) {
// WTF?
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error_code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
nullptr, error_code,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPSTR)&message, // NOT A BUG!
0, NULL);
0, nullptr);
std::string result = message;
LocalFree(message);

@ -49,7 +49,6 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/any.h>
@ -58,6 +57,7 @@
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/descriptor_database.h>
#include <google/protobuf/dynamic_message.h>
@ -1300,10 +1300,6 @@ class FileDescriptorTables {
bool AddFieldByNumber(FieldDescriptor* field);
bool AddEnumValueByNumber(EnumValueDescriptor* value);
// Adds the field to the lowercase_name and camelcase_name maps. Never
// fails because we allow duplicates; the first field by the name wins.
void AddFieldByStylizedNames(const FieldDescriptor* field);
// Populates p->first->locations_by_path_ from p->second.
// Unusual signature dictated by internal::call_once.
static void BuildLocationsByPath(
@ -1330,12 +1326,13 @@ class FileDescriptorTables {
void FieldsByCamelcaseNamesLazyInitInternal() const;
SymbolsByParentSet symbols_by_parent_;
mutable FieldsByNameMap fields_by_lowercase_name_;
std::unique_ptr<FieldsByNameMap> fields_by_lowercase_name_tmp_;
mutable internal::once_flag fields_by_lowercase_name_once_;
mutable FieldsByNameMap fields_by_camelcase_name_;
std::unique_ptr<FieldsByNameMap> fields_by_camelcase_name_tmp_;
mutable internal::once_flag fields_by_camelcase_name_once_;
// Make these fields atomic to avoid race conditions with
// GetEstimatedOwnedMemoryBytesSize. Once the pointer is set the map won't
// change anymore.
mutable std::atomic<const FieldsByNameMap*> fields_by_lowercase_name_{};
mutable std::atomic<const FieldsByNameMap*> fields_by_camelcase_name_{};
FieldsByNumberSet fields_by_number_; // Not including extensions.
EnumValuesByNumberSet enum_values_by_number_;
mutable EnumValuesByNumberSet unknown_enum_values_by_number_
@ -1373,11 +1370,12 @@ DescriptorPool::Tables::Tables() {
DescriptorPool::Tables::~Tables() { GOOGLE_DCHECK(checkpoints_.empty()); }
FileDescriptorTables::FileDescriptorTables()
: fields_by_lowercase_name_tmp_(new FieldsByNameMap()),
fields_by_camelcase_name_tmp_(new FieldsByNameMap()) {}
FileDescriptorTables::FileDescriptorTables() {}
FileDescriptorTables::~FileDescriptorTables() {}
FileDescriptorTables::~FileDescriptorTables() {
delete fields_by_lowercase_name_.load(std::memory_order_acquire);
delete fields_by_camelcase_name_.load(std::memory_order_acquire);
}
inline const FileDescriptorTables& FileDescriptorTables::GetEmptyInstance() {
static auto file_descriptor_tables =
@ -1520,13 +1518,14 @@ void FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic(
}
void FileDescriptorTables::FieldsByLowercaseNamesLazyInitInternal() const {
auto* map = new FieldsByNameMap;
for (Symbol symbol : symbols_by_parent_) {
const FieldDescriptor* field = symbol.field_descriptor();
if (!field) continue;
PointerStringPair lowercase_key(FindParentForFieldsByMap(field),
field->lowercase_name().c_str());
InsertIfNotPresent(&fields_by_lowercase_name_, lowercase_key, field);
(*map)[{FindParentForFieldsByMap(field), field->lowercase_name().c_str()}] =
field;
}
fields_by_lowercase_name_.store(map, std::memory_order_release);
}
inline const FieldDescriptor* FileDescriptorTables::FindFieldByLowercaseName(
@ -1534,8 +1533,9 @@ inline const FieldDescriptor* FileDescriptorTables::FindFieldByLowercaseName(
internal::call_once(
fields_by_lowercase_name_once_,
&FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic, this);
return FindPtrOrNull(fields_by_lowercase_name_,
PointerStringPair(parent, lowercase_name));
return FindPtrOrNull(
*fields_by_lowercase_name_.load(std::memory_order_acquire),
PointerStringPair(parent, lowercase_name));
}
void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic(
@ -1544,13 +1544,14 @@ void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic(
}
void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitInternal() const {
auto* map = new FieldsByNameMap;
for (Symbol symbol : symbols_by_parent_) {
const FieldDescriptor* field = symbol.field_descriptor();
if (!field) continue;
PointerStringPair camelcase_key(FindParentForFieldsByMap(field),
field->camelcase_name().c_str());
InsertIfNotPresent(&fields_by_camelcase_name_, camelcase_key, field);
(*map)[{FindParentForFieldsByMap(field), field->camelcase_name().c_str()}] =
field;
}
fields_by_camelcase_name_.store(map, std::memory_order_release);
}
inline const FieldDescriptor* FileDescriptorTables::FindFieldByCamelcaseName(
@ -1558,8 +1559,9 @@ inline const FieldDescriptor* FileDescriptorTables::FindFieldByCamelcaseName(
internal::call_once(
fields_by_camelcase_name_once_,
FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic, this);
return FindPtrOrNull(fields_by_camelcase_name_,
PointerStringPair(parent, camelcase_name));
return FindPtrOrNull(
*fields_by_camelcase_name_.load(std::memory_order_acquire),
PointerStringPair(parent, camelcase_name));
}
inline const EnumValueDescriptor* FileDescriptorTables::FindEnumValueByNumber(
@ -1619,8 +1621,8 @@ FileDescriptorTables::FindEnumValueByNumberCreatingIfUnknown(
// EnumDescriptor (it's not a part of the enum as originally defined), but
// we do insert it into the table so that we can return the same pointer
// later.
std::string enum_value_name = StringPrintf("UNKNOWN_ENUM_VALUE_%s_%d",
parent->name().c_str(), number);
std::string enum_value_name = StringPrintf(
"UNKNOWN_ENUM_VALUE_%s_%d", parent->name().c_str(), number);
auto* pool = DescriptorPool::generated_pool();
auto* tables = const_cast<DescriptorPool::Tables*>(pool->tables_.get());
internal::FlatAllocator alloc;
@ -1689,39 +1691,7 @@ bool DescriptorPool::Tables::AddFile(const FileDescriptor* file) {
}
}
void FileDescriptorTables::FinalizeTables() {
// Clean up the temporary maps used by AddFieldByStylizedNames().
fields_by_lowercase_name_tmp_ = nullptr;
fields_by_camelcase_name_tmp_ = nullptr;
}
void FileDescriptorTables::AddFieldByStylizedNames(
const FieldDescriptor* field) {
const void* parent = FindParentForFieldsByMap(field);
// We want fields_by_{lower,camel}case_name_ to be lazily built, but
// cross-link order determines which entry will be present in the case of a
// conflict. So we use the temporary maps that get destroyed after
// BuildFileImpl() to detect the conflicts, and only store the conflicts in
// the map that will persist. We will then lazily populate the rest of the
// entries from fields_by_number_.
PointerStringPair lowercase_key(parent, field->lowercase_name().c_str());
if (!InsertIfNotPresent(fields_by_lowercase_name_tmp_.get(),
lowercase_key, field)) {
InsertIfNotPresent(
&fields_by_lowercase_name_, lowercase_key,
FindPtrOrNull(*fields_by_lowercase_name_tmp_, lowercase_key));
}
PointerStringPair camelcase_key(parent, field->camelcase_name().c_str());
if (!InsertIfNotPresent(fields_by_camelcase_name_tmp_.get(),
camelcase_key, field)) {
InsertIfNotPresent(
&fields_by_camelcase_name_, camelcase_key,
FindPtrOrNull(*fields_by_camelcase_name_tmp_, camelcase_key));
}
}
void FileDescriptorTables::FinalizeTables() {}
bool FileDescriptorTables::AddFieldByNumber(FieldDescriptor* field) {
// Skip fields that are at the start of the sequence.
@ -6271,9 +6241,6 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field,
field->options_ = &FieldOptions::default_instance();
}
// Add the field to the lowercase-name and camelcase-name tables.
file_tables_->AddFieldByStylizedNames(field);
if (proto.has_extendee()) {
Symbol extendee =
LookupSymbol(proto.extendee(), field->full_name(),

@ -1506,26 +1506,26 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_package()) {
package_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_package(),
package_.Set(from._internal_package(),
GetArenaForAllocation());
}
syntax_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
syntax_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
syntax_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_syntax()) {
syntax_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_syntax(),
syntax_.Set(from._internal_syntax(),
GetArenaForAllocation());
}
if (from._internal_has_options()) {
@ -1544,15 +1544,15 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from)
inline void FileDescriptorProto::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
syntax_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
syntax_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
syntax_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -1571,9 +1571,9 @@ FileDescriptorProto::~FileDescriptorProto() {
inline void FileDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
package_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
syntax_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
package_.Destroy();
syntax_.Destroy();
if (this != internal_default_instance()) delete options_;
if (this != internal_default_instance()) delete source_code_info_;
}
@ -2102,17 +2102,14 @@ void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) {
public_dependency_.InternalSwap(&other->public_dependency_);
weak_dependency_.InternalSwap(&other->weak_dependency_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&package_, lhs_arena,
&other->package_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&syntax_, lhs_arena,
&other->syntax_, rhs_arena
);
@ -2682,10 +2679,10 @@ DescriptorProto::DescriptorProto(const DescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
if (from._internal_has_options()) {
@ -2699,7 +2696,7 @@ DescriptorProto::DescriptorProto(const DescriptorProto& from)
inline void DescriptorProto::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
options_ = nullptr;
}
@ -2715,7 +2712,7 @@ DescriptorProto::~DescriptorProto() {
inline void DescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
if (this != internal_default_instance()) delete options_;
}
@ -3173,7 +3170,6 @@ void DescriptorProto::InternalSwap(DescriptorProto* other) {
reserved_range_.InternalSwap(&other->reserved_range_);
reserved_name_.InternalSwap(&other->reserved_name_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
@ -3443,42 +3439,42 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
extendee_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
extendee_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
extendee_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_extendee()) {
extendee_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_extendee(),
extendee_.Set(from._internal_extendee(),
GetArenaForAllocation());
}
type_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
type_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_type_name()) {
type_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_type_name(),
type_name_.Set(from._internal_type_name(),
GetArenaForAllocation());
}
default_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
default_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
default_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_default_value()) {
default_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_default_value(),
default_value_.Set(from._internal_default_value(),
GetArenaForAllocation());
}
json_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
json_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
json_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_json_name()) {
json_name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_json_name(),
json_name_.Set(from._internal_json_name(),
GetArenaForAllocation());
}
if (from._internal_has_options()) {
@ -3495,23 +3491,23 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from)
inline void FieldDescriptorProto::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
extendee_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
extendee_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
extendee_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
type_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
type_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
default_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
default_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
default_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
json_name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
json_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
json_name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -3532,11 +3528,11 @@ FieldDescriptorProto::~FieldDescriptorProto() {
inline void FieldDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
extendee_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
type_name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
default_value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
json_name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
extendee_.Destroy();
type_name_.Destroy();
default_value_.Destroy();
json_name_.Destroy();
if (this != internal_default_instance()) delete options_;
}
@ -4010,27 +4006,22 @@ void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&extendee_, lhs_arena,
&other->extendee_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&type_name_, lhs_arena,
&other->type_name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&default_value_, lhs_arena,
&other->default_value_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&json_name_, lhs_arena,
&other->json_name_, rhs_arena
);
@ -4080,10 +4071,10 @@ OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
if (from._internal_has_options()) {
@ -4097,7 +4088,7 @@ OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from)
inline void OneofDescriptorProto::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
options_ = nullptr;
}
@ -4113,7 +4104,7 @@ OneofDescriptorProto::~OneofDescriptorProto() {
inline void OneofDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
if (this != internal_default_instance()) delete options_;
}
@ -4304,7 +4295,6 @@ void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
@ -4583,10 +4573,10 @@ EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
if (from._internal_has_options()) {
@ -4600,7 +4590,7 @@ EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from)
inline void EnumDescriptorProto::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
options_ = nullptr;
}
@ -4616,7 +4606,7 @@ EnumDescriptorProto::~EnumDescriptorProto() {
inline void EnumDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
if (this != internal_default_instance()) delete options_;
}
@ -4909,7 +4899,6 @@ void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) {
reserved_range_.InternalSwap(&other->reserved_range_);
reserved_name_.InternalSwap(&other->reserved_name_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
@ -4955,10 +4944,10 @@ EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProt
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
if (from._internal_has_options()) {
@ -4973,7 +4962,7 @@ EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProt
inline void EnumValueDescriptorProto::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -4992,7 +4981,7 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() {
inline void EnumValueDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
if (this != internal_default_instance()) delete options_;
}
@ -5208,7 +5197,6 @@ void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
@ -5258,10 +5246,10 @@ ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& fro
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
if (from._internal_has_options()) {
@ -5275,7 +5263,7 @@ ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& fro
inline void ServiceDescriptorProto::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
options_ = nullptr;
}
@ -5291,7 +5279,7 @@ ServiceDescriptorProto::~ServiceDescriptorProto() {
inline void ServiceDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
if (this != internal_default_instance()) delete options_;
}
@ -5515,7 +5503,6 @@ void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) {
swap(_has_bits_[0], other->_has_bits_[0]);
method_.InternalSwap(&other->method_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
@ -5570,26 +5557,26 @@ MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
name_.Set(from._internal_name(),
GetArenaForAllocation());
}
input_type_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
input_type_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
input_type_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_input_type()) {
input_type_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_input_type(),
input_type_.Set(from._internal_input_type(),
GetArenaForAllocation());
}
output_type_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
output_type_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
output_type_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_output_type()) {
output_type_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_output_type(),
output_type_.Set(from._internal_output_type(),
GetArenaForAllocation());
}
if (from._internal_has_options()) {
@ -5606,15 +5593,15 @@ MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from)
inline void MethodDescriptorProto::SharedCtor() {
name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
input_type_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
input_type_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
input_type_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
output_type_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
output_type_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
output_type_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -5633,9 +5620,9 @@ MethodDescriptorProto::~MethodDescriptorProto() {
inline void MethodDescriptorProto::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
input_type_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
output_type_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_.Destroy();
input_type_.Destroy();
output_type_.Destroy();
if (this != internal_default_instance()) delete options_;
}
@ -5946,17 +5933,14 @@ void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, lhs_arena,
&other->name_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&input_type_, lhs_arena,
&other->input_type_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&output_type_, lhs_arena,
&other->output_type_, rhs_arena
);
@ -6057,82 +6041,82 @@ FileOptions::FileOptions(const FileOptions& from)
_extensions_.MergeFrom(internal_default_instance(), from._extensions_);
java_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
java_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_java_package()) {
java_package_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_java_package(),
java_package_.Set(from._internal_java_package(),
GetArenaForAllocation());
}
java_outer_classname_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_outer_classname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
java_outer_classname_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_java_outer_classname()) {
java_outer_classname_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_java_outer_classname(),
java_outer_classname_.Set(from._internal_java_outer_classname(),
GetArenaForAllocation());
}
go_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
go_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
go_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_go_package()) {
go_package_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_go_package(),
go_package_.Set(from._internal_go_package(),
GetArenaForAllocation());
}
objc_class_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
objc_class_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
objc_class_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_objc_class_prefix()) {
objc_class_prefix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_objc_class_prefix(),
objc_class_prefix_.Set(from._internal_objc_class_prefix(),
GetArenaForAllocation());
}
csharp_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
csharp_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
csharp_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_csharp_namespace()) {
csharp_namespace_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_csharp_namespace(),
csharp_namespace_.Set(from._internal_csharp_namespace(),
GetArenaForAllocation());
}
swift_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
swift_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
swift_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_swift_prefix()) {
swift_prefix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_swift_prefix(),
swift_prefix_.Set(from._internal_swift_prefix(),
GetArenaForAllocation());
}
php_class_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_class_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
php_class_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_php_class_prefix()) {
php_class_prefix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_php_class_prefix(),
php_class_prefix_.Set(from._internal_php_class_prefix(),
GetArenaForAllocation());
}
php_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
php_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_php_namespace()) {
php_namespace_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_php_namespace(),
php_namespace_.Set(from._internal_php_namespace(),
GetArenaForAllocation());
}
php_metadata_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_metadata_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
php_metadata_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_php_metadata_namespace()) {
php_metadata_namespace_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_php_metadata_namespace(),
php_metadata_namespace_.Set(from._internal_php_metadata_namespace(),
GetArenaForAllocation());
}
ruby_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
ruby_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
ruby_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_ruby_package()) {
ruby_package_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_ruby_package(),
ruby_package_.Set(from._internal_ruby_package(),
GetArenaForAllocation());
}
::memcpy(&java_multiple_files_, &from.java_multiple_files_,
@ -6144,43 +6128,43 @@ FileOptions::FileOptions(const FileOptions& from)
inline void FileOptions::SharedCtor() {
java_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
java_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_outer_classname_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
java_outer_classname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
java_outer_classname_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
go_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
go_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
go_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
objc_class_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
objc_class_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
objc_class_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
csharp_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
csharp_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
csharp_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
swift_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
swift_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
swift_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_class_prefix_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_class_prefix_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
php_class_prefix_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
php_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_metadata_namespace_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
php_metadata_namespace_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
php_metadata_namespace_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
ruby_package_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
ruby_package_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
ruby_package_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&java_multiple_files_) - reinterpret_cast<char*>(this)),
@ -6201,16 +6185,16 @@ FileOptions::~FileOptions() {
inline void FileOptions::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
java_package_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
java_outer_classname_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
go_package_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
objc_class_prefix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
csharp_namespace_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
swift_prefix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
php_class_prefix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
php_namespace_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
php_metadata_namespace_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
ruby_package_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
java_package_.Destroy();
java_outer_classname_.Destroy();
go_package_.Destroy();
objc_class_prefix_.Destroy();
csharp_namespace_.Destroy();
swift_prefix_.Destroy();
php_class_prefix_.Destroy();
php_namespace_.Destroy();
php_metadata_namespace_.Destroy();
ruby_package_.Destroy();
}
void FileOptions::SetCachedSize(int size) const {
@ -6994,52 +6978,42 @@ void FileOptions::InternalSwap(FileOptions* other) {
swap(_has_bits_[0], other->_has_bits_[0]);
uninterpreted_option_.InternalSwap(&other->uninterpreted_option_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&java_package_, lhs_arena,
&other->java_package_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&java_outer_classname_, lhs_arena,
&other->java_outer_classname_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&go_package_, lhs_arena,
&other->go_package_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&objc_class_prefix_, lhs_arena,
&other->objc_class_prefix_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&csharp_namespace_, lhs_arena,
&other->csharp_namespace_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&swift_prefix_, lhs_arena,
&other->swift_prefix_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&php_class_prefix_, lhs_arena,
&other->php_class_prefix_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&php_namespace_, lhs_arena,
&other->php_namespace_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&php_metadata_namespace_, lhs_arena,
&other->php_metadata_namespace_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&ruby_package_, lhs_arena,
&other->ruby_package_, rhs_arena
);
@ -9097,10 +9071,10 @@ UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOp
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
name_part_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_part_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_part_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_name_part()) {
name_part_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name_part(),
name_part_.Set(from._internal_name_part(),
GetArenaForAllocation());
}
is_extension_ = from.is_extension_;
@ -9110,7 +9084,7 @@ UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOp
inline void UninterpretedOption_NamePart::SharedCtor() {
name_part_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
name_part_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
name_part_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
is_extension_ = false;
}
@ -9126,7 +9100,7 @@ UninterpretedOption_NamePart::~UninterpretedOption_NamePart() {
inline void UninterpretedOption_NamePart::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_part_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
name_part_.Destroy();
}
void UninterpretedOption_NamePart::SetCachedSize(int size) const {
@ -9323,7 +9297,6 @@ void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* ot
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_part_, lhs_arena,
&other->name_part_, rhs_arena
);
@ -9375,26 +9348,26 @@ UninterpretedOption::UninterpretedOption(const UninterpretedOption& from)
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
identifier_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
identifier_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
identifier_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_identifier_value()) {
identifier_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_identifier_value(),
identifier_value_.Set(from._internal_identifier_value(),
GetArenaForAllocation());
}
string_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
string_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
string_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_string_value()) {
string_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_string_value(),
string_value_.Set(from._internal_string_value(),
GetArenaForAllocation());
}
aggregate_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
aggregate_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
aggregate_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_aggregate_value()) {
aggregate_value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_aggregate_value(),
aggregate_value_.Set(from._internal_aggregate_value(),
GetArenaForAllocation());
}
::memcpy(&positive_int_value_, &from.positive_int_value_,
@ -9406,15 +9379,15 @@ UninterpretedOption::UninterpretedOption(const UninterpretedOption& from)
inline void UninterpretedOption::SharedCtor() {
identifier_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
identifier_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
identifier_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
string_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
string_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
string_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
aggregate_value_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
aggregate_value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
aggregate_value_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&positive_int_value_) - reinterpret_cast<char*>(this)),
@ -9433,9 +9406,9 @@ UninterpretedOption::~UninterpretedOption() {
inline void UninterpretedOption::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
identifier_value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
string_value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
aggregate_value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
identifier_value_.Destroy();
string_value_.Destroy();
aggregate_value_.Destroy();
}
void UninterpretedOption::SetCachedSize(int size) const {
@ -9764,17 +9737,14 @@ void UninterpretedOption::InternalSwap(UninterpretedOption* other) {
swap(_has_bits_[0], other->_has_bits_[0]);
name_.InternalSwap(&other->name_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&identifier_value_, lhs_arena,
&other->identifier_value_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&string_value_, lhs_arena,
&other->string_value_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&aggregate_value_, lhs_arena,
&other->aggregate_value_, rhs_arena
);
@ -9823,18 +9793,18 @@ SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location&
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
leading_comments_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
leading_comments_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
leading_comments_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_leading_comments()) {
leading_comments_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_leading_comments(),
leading_comments_.Set(from._internal_leading_comments(),
GetArenaForAllocation());
}
trailing_comments_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
trailing_comments_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
trailing_comments_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_trailing_comments()) {
trailing_comments_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_trailing_comments(),
trailing_comments_.Set(from._internal_trailing_comments(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo.Location)
@ -9843,11 +9813,11 @@ SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location&
inline void SourceCodeInfo_Location::SharedCtor() {
leading_comments_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
leading_comments_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
leading_comments_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
trailing_comments_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
trailing_comments_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
trailing_comments_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}
@ -9862,8 +9832,8 @@ SourceCodeInfo_Location::~SourceCodeInfo_Location() {
inline void SourceCodeInfo_Location::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
leading_comments_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
trailing_comments_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
leading_comments_.Destroy();
trailing_comments_.Destroy();
}
void SourceCodeInfo_Location::SetCachedSize(int size) const {
@ -10168,12 +10138,10 @@ void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* other) {
span_.InternalSwap(&other->span_);
leading_detached_comments_.InternalSwap(&other->leading_detached_comments_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&leading_comments_, lhs_arena,
&other->leading_comments_, rhs_arena
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&trailing_comments_, lhs_arena,
&other->trailing_comments_, rhs_arena
);
@ -10393,10 +10361,10 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
source_file_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
source_file_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
source_file_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
if (from._internal_has_source_file()) {
source_file_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_source_file(),
source_file_.Set(from._internal_source_file(),
GetArenaForAllocation());
}
::memcpy(&begin_, &from.begin_,
@ -10408,7 +10376,7 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn
inline void GeneratedCodeInfo_Annotation::SharedCtor() {
source_file_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
source_file_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
source_file_.Set("", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&begin_) - reinterpret_cast<char*>(this)),
@ -10427,7 +10395,7 @@ GeneratedCodeInfo_Annotation::~GeneratedCodeInfo_Annotation() {
inline void GeneratedCodeInfo_Annotation::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
source_file_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
source_file_.Destroy();
}
void GeneratedCodeInfo_Annotation::SetCachedSize(int size) const {
@ -10672,7 +10640,6 @@ void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* ot
swap(_has_bits_[0], other->_has_bits_[0]);
path_.InternalSwap(&other->path_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&source_file_, lhs_arena,
&other->source_file_, rhs_arena
);

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save