PROTOBUF_SYNC_PIPER
pull/8546/head
Joshua Haberman 4 years ago
commit f5fd897c1d
  1. 4
      .github/workflows/codespell.yml
  2. 156
      BUILD
  3. 1
      CHANGES.txt
  4. 2
      Protobuf-C++.podspec
  5. 75
      WORKSPACE
  6. 2
      build_files_updated_unittest.sh
  7. 2
      configure.ac
  8. 6
      csharp/src/AddressBook/Addressbook.cs
  9. 1
      docs/third_party.md
  10. 2
      examples/CMakeLists.txt
  11. 14
      examples/Makefile
  12. 4
      examples/addressbook.proto
  13. 8
      java/BUILD
  14. 5
      java/README.md
  15. 208
      java/core/BUILD
  16. 30
      java/core/src/main/java/com/google/protobuf/Descriptors.java
  17. 4
      java/core/src/test/java/com/google/protobuf/DescriptorsTest.java
  18. 1
      java/internal/BUILD
  19. 19
      java/kotlin-lite/generate-sources-build.xml
  20. 34
      java/kotlin-lite/generate-test-sources-build.xml
  21. 284
      java/kotlin-lite/pom.xml
  22. 7
      java/kotlin-lite/process-lite-sources-build.xml
  23. 20
      java/kotlin/generate-sources-build.xml
  24. 34
      java/kotlin/generate-test-sources-build.xml
  25. 240
      java/kotlin/pom.xml
  26. 42
      java/lite/BUILD
  27. 1
      java/lite/pom.xml
  28. 37
      java/util/BUILD
  29. 1
      js/compatibility_tests/v3.1.0/binary/decoder_test.js
  30. 2
      js/package.json
  31. 21
      kokoro/linux/aarch64/cpp_crosscompile_and_run_tests_with_qemu_aarch64.sh
  32. 33
      kokoro/linux/aarch64/dockcross_helpers/run_dockcross_linux_aarch64.sh
  33. 9
      kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh
  34. 19
      kokoro/linux/aarch64/javascript_build_and_run_tests_with_qemu_aarch64.sh
  35. 9
      kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh
  36. 19
      kokoro/linux/aarch64/python_crosscompile_aarch64.sh
  37. 26
      kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh
  38. 17
      kokoro/linux/aarch64/ruby_build_and_run_tests_with_qemu_aarch64.sh
  39. 14
      kokoro/linux/aarch64/test_cpp_aarch64.sh
  40. 29
      kokoro/linux/aarch64/test_csharp_aarch64.sh
  41. 32
      kokoro/linux/aarch64/test_java_aarch64.sh
  42. 29
      kokoro/linux/aarch64/test_javascript_aarch64.sh
  43. 9
      kokoro/linux/aarch64/test_python_aarch64.sh
  44. 27
      kokoro/linux/aarch64/test_ruby_aarch64.sh
  45. 11
      kokoro/linux/cpp_aarch64/build.sh
  46. 4
      kokoro/linux/cpp_aarch64/continuous.cfg
  47. 4
      kokoro/linux/cpp_aarch64/presubmit.cfg
  48. 16
      kokoro/linux/csharp_aarch64/build.sh
  49. 11
      kokoro/linux/csharp_aarch64/continuous.cfg
  50. 11
      kokoro/linux/csharp_aarch64/presubmit.cfg
  51. 16
      kokoro/linux/java_aarch64/build.sh
  52. 11
      kokoro/linux/java_aarch64/continuous.cfg
  53. 11
      kokoro/linux/java_aarch64/presubmit.cfg
  54. 17
      kokoro/linux/java_compatibility/build.sh
  55. 16
      kokoro/linux/javascript_aarch64/build.sh
  56. 11
      kokoro/linux/javascript_aarch64/continuous.cfg
  57. 11
      kokoro/linux/javascript_aarch64/presubmit.cfg
  58. 13
      kokoro/linux/python_aarch64/build.sh
  59. 11
      kokoro/linux/python_aarch64/continuous.cfg
  60. 11
      kokoro/linux/python_aarch64/presubmit.cfg
  61. 16
      kokoro/linux/ruby_aarch64/build.sh
  62. 11
      kokoro/linux/ruby_aarch64/continuous.cfg
  63. 11
      kokoro/linux/ruby_aarch64/presubmit.cfg
  64. 8
      kokoro/release/python/linux/build_artifacts.sh
  65. 10
      protobuf.bzl
  66. 8
      protobuf_deps.bzl
  67. 2
      python/google/protobuf/__init__.py
  68. 18
      python/google/protobuf/descriptor.py
  69. 4
      python/google/protobuf/internal/descriptor_test.py
  70. 18
      python/google/protobuf/internal/proto_builder_test.py
  71. 11
      python/google/protobuf/proto_builder.py
  72. 21
      python/google/protobuf/pyext/repeated_composite_container.cc
  73. 43
      ruby/ext/google/protobuf_c/defs.c
  74. 6
      ruby/tests/encode_decode_test.rb
  75. 4
      ruby/tests/generated_code.proto
  76. 2
      src/Makefile.am
  77. 30
      src/google/protobuf/any.pb.cc
  78. 51
      src/google/protobuf/any.pb.h
  79. 108
      src/google/protobuf/api.pb.cc
  80. 179
      src/google/protobuf/api.pb.h
  81. 41
      src/google/protobuf/arena.h
  82. 67
      src/google/protobuf/arenastring.h
  83. 173
      src/google/protobuf/arenastring_unittest.cc
  84. 12
      src/google/protobuf/compiler/cpp/cpp_generator.cc
  85. 30
      src/google/protobuf/compiler/cpp/cpp_helpers.cc
  86. 11
      src/google/protobuf/compiler/cpp/cpp_helpers.h
  87. 18
      src/google/protobuf/compiler/cpp/cpp_map_field.cc
  88. 1
      src/google/protobuf/compiler/cpp/cpp_map_field.h
  89. 66
      src/google/protobuf/compiler/cpp/cpp_message.cc
  90. 3
      src/google/protobuf/compiler/cpp/cpp_message.h
  91. 51
      src/google/protobuf/compiler/cpp/cpp_message_field.cc
  92. 5
      src/google/protobuf/compiler/cpp/cpp_options.h
  93. 963
      src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc
  94. 57
      src/google/protobuf/compiler/cpp/cpp_parse_function_generator.h
  95. 56
      src/google/protobuf/compiler/cpp/cpp_string_field.cc
  96. 3
      src/google/protobuf/compiler/cpp/cpp_unittest.inc
  97. 11
      src/google/protobuf/compiler/java/java_message.cc
  98. 4
      src/google/protobuf/compiler/parser.cc
  99. 37
      src/google/protobuf/compiler/parser_unittest.cc
  100. 62
      src/google/protobuf/compiler/plugin.pb.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -12,5 +12,5 @@ jobs:
- uses: codespell-project/actions-codespell@master
with:
check_filenames: true
skip: ./.git,./conformance/third_party,*.snk,*.pb,*.pb.cc,*.pb.h,./src/google/protobuf/testdata,./objectivec/Tests,./python/compatibility_tests/v2.5.0/tests/google/protobuf/internal,./.github/workflows/codespell.yml
ignore_words_list: "alow,alse,ba,cleare,copyable,cloneable,dedup,dur,errorprone,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,OptIn"
skip: ./.git,./conformance/third_party,*.snk,*.pb,*.pb.cc,*.pb.h,./src/google/protobuf/testdata,./objectivec/Tests,./python/compatibility_tests/v2.5.0/tests/google/protobuf/internal,./github/workflows/codespell.yml
ignore_words_list: "alow,alse,ba,cleare,copyable,cloneable,dedup,dur,errorprone,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin"

156
BUILD

@ -4,6 +4,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_python//python:defs.bzl", "py_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_proto_library", "java_lite_proto_library")
load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
licenses(["notice"])
@ -402,6 +403,7 @@ cc_library(
"src/google/protobuf/compiler/java/java_generator.cc",
"src/google/protobuf/compiler/java/java_generator_factory.cc",
"src/google/protobuf/compiler/java/java_helpers.cc",
"src/google/protobuf/compiler/java/java_kotlin_generator.cc",
"src/google/protobuf/compiler/java/java_map_field.cc",
"src/google/protobuf/compiler/java/java_map_field_lite.cc",
"src/google/protobuf/compiler/java/java_message.cc",
@ -458,6 +460,12 @@ cc_binary(
# Tests
################################################################################
filegroup(
name = "testdata",
visibility = ["//:__subpackages__"],
srcs = glob(["src/google/protobuf/testdata/**/*"]),
)
RELATIVE_LITE_TEST_PROTOS = [
# AUTOGEN(lite_test_protos)
"google/protobuf/map_lite_unittest.proto",
@ -519,6 +527,57 @@ RELATIVE_TEST_PROTOS = [
TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
GENERIC_RELATIVE_TEST_PROTOS = [
"google/protobuf/unittest.proto",
"google/protobuf/unittest_arena.proto",
"google/protobuf/unittest_custom_options.proto",
"google/protobuf/unittest_drop_unknown_fields.proto",
"google/protobuf/unittest_embed_optimize_for.proto",
"google/protobuf/unittest_empty.proto",
"google/protobuf/unittest_enormous_descriptor.proto",
"google/protobuf/unittest_import.proto",
"google/protobuf/unittest_import_public.proto",
"google/protobuf/unittest_lazy_dependencies.proto",
"google/protobuf/unittest_lazy_dependencies_custom_option.proto",
"google/protobuf/unittest_lazy_dependencies_enum.proto",
"google/protobuf/unittest_lite_imports_nonlite.proto",
"google/protobuf/unittest_mset.proto",
"google/protobuf/unittest_mset_wire_format.proto",
"google/protobuf/unittest_no_field_presence.proto",
"google/protobuf/unittest_no_generic_services.proto",
"google/protobuf/unittest_optimize_for.proto",
"google/protobuf/unittest_preserve_unknown_enum.proto",
"google/protobuf/unittest_preserve_unknown_enum2.proto",
"google/protobuf/unittest_proto3.proto",
"google/protobuf/unittest_proto3_arena.proto",
"google/protobuf/unittest_proto3_arena_lite.proto",
"google/protobuf/unittest_proto3_lite.proto",
"google/protobuf/unittest_proto3_optional.proto",
"google/protobuf/unittest_well_known_types.proto",
]
GENERIC_TEST_PROTOS = ["src/" + s for s in GENERIC_RELATIVE_TEST_PROTOS]
proto_library(
name = "generic_test_protos",
visibility = ["//:__subpackages__"],
strip_import_prefix = "src",
srcs = LITE_TEST_PROTOS + GENERIC_TEST_PROTOS,
deps = [
"//:any_proto",
"//:api_proto",
"//:descriptor_proto",
"//:duration_proto",
"//:empty_proto",
"//:field_mask_proto",
"//:source_context_proto",
"//:struct_proto",
"//:timestamp_proto",
"//:type_proto",
"//:wrappers_proto",
],
)
cc_proto_library(
name = "cc_test_protos",
srcs = LITE_TEST_PROTOS + TEST_PROTOS,
@ -685,6 +744,15 @@ internal_gen_well_known_protos_java(
],
)
internal_gen_well_known_protos_java(
name = "gen_well_known_protos_javalite",
deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
javalite = True,
visibility = [
"//java:__subpackages__",
],
)
alias(
name = "protobuf_java",
actual = "//java/core",
@ -1111,3 +1179,91 @@ sh_test(
"update_file_lists.sh",
],
)
java_proto_library(
name = "test_messages_proto2_java_proto",
visibility = [
"//java:__subpackages__",
],
deps = [":test_messages_proto2_proto"],
)
java_proto_library(
name = "test_messages_proto3_java_proto",
visibility = [
"//java:__subpackages__",
],
deps = [":test_messages_proto3_proto"],
)
java_proto_library(
name = "conformance_java_proto",
visibility = [
"//java:__subpackages__",
],
deps = [":conformance_proto"],
)
java_lite_proto_library(
name = "test_messages_proto2_java_proto_lite",
visibility = [
"//java:__subpackages__",
],
deps = [":test_messages_proto2_proto"],
)
java_lite_proto_library(
name = "conformance_java_proto_lite",
visibility = [
"//java:__subpackages__",
],
deps = [":conformance_proto"],
)
java_lite_proto_library(
name = "test_messages_proto3_java_proto_lite",
visibility = [
"//java:__subpackages__",
],
deps = [":test_messages_proto3_proto"],
)
java_binary(
name = "conformance_java",
srcs = ["conformance/ConformanceJava.java"],
visibility = [
"//java:__subpackages__",
],
main_class = "ConformanceJava",
deps = [
":conformance_java_proto",
":test_messages_proto2_java_proto",
":test_messages_proto3_java_proto",
"//:protobuf_java",
"//:protobuf_java_util",
],
)
java_binary(
name = "conformance_java_lite",
srcs = ["conformance/ConformanceJavaLite.java"],
visibility = [
"//java:__subpackages__",
],
main_class = "ConformanceJavaLite",
deps = [
":conformance_java_proto_lite",
":test_messages_proto2_java_proto_lite",
":test_messages_proto3_java_proto_lite",
"//:protobuf_javalite",
"//:protobuf_java_util",
],
)
exports_files([
"conformance/conformance_test_runner.sh",
"conformance/failure_list_java.txt",
"conformance/failure_list_java_lite.txt",
"conformance/text_format_failure_list_java.txt",
"conformance/text_format_failure_list_java_lite.txt",
])

@ -5,6 +5,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
* Fix bug where `Descriptor::DebugString()` printed proto3 synthetic oneofs.
* Provide stable versions of `SortAndUnique()`.
* Make sure to cache proto3 optional message fields when they are cleared.
* Expose UnsafeArena methods to Reflection.
Kotlin
* Restrict extension setter and getter operators to non-nullable T.

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Protobuf-C++'
s.version = '3.15.6'
s.version = '3.15.8'
s.summary = 'Protocol Buffers v3 runtime library for C++.'
s.homepage = 'https://github.com/google/protobuf'
s.license = '3-Clause BSD License'

@ -26,64 +26,73 @@ http_archive(
],
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//:protobuf_deps.bzl", "protobuf_deps")
# Load common dependencies.
load("//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")
bind(
name = "python_headers",
actual = "//util/python:python_headers",
)
jvm_maven_import_external(
name = "guava_maven",
artifact = "com.google.guava:guava:18.0",
artifact_sha256 = "d664fbfc03d2e5ce9cab2a44fb01f1d0bf9dfebeccc1a473b1f9ea31f79f6f99",
server_urls = [
"https://jcenter.bintray.com/",
load("@rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
artifacts = [
"com.google.guava:guava:30.1.1-jre",
"com.google.code.gson:gson:2.8.6",
"com.google.errorprone:error_prone_annotations:2.3.2",
"junit:junit:4.12",
"org.easymock:easymock:3.2",
"org.easymock:easymockclassextension:3.2",
"com.google.truth:truth:1.1.2",
],
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
],
# For updating instructions, see:
# https://github.com/bazelbuild/rules_jvm_external#updating-maven_installjson
maven_install_json = "//:maven_install.json",
)
load("@maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()
bind(
name = "guava",
actual = "@guava_maven//jar",
actual = "@maven//:com_google_guava_guava",
)
jvm_maven_import_external(
name = "gson_maven",
artifact = "com.google.code.gson:gson:2.7",
artifact_sha256 = "2d43eb5ea9e133d2ee2405cc14f5ee08951b8361302fdd93494a3a997b508d32",
server_urls = [
"https://jcenter.bintray.com/",
"https://repo1.maven.org/maven2",
],
bind(
name = "gson",
actual = "@maven//:com_google_code_gson_gson",
)
bind(
name = "gson",
actual = "@gson_maven//jar",
name = "error_prone_annotations",
actual = "@maven//:com_google_errorprone_error_prone_annotations",
)
jvm_maven_import_external(
name = "error_prone_annotations_maven",
artifact = "com.google.errorprone:error_prone_annotations:2.3.2",
artifact_sha256 = "357cd6cfb067c969226c442451502aee13800a24e950fdfde77bcdb4565a668d",
server_urls = [
"https://jcenter.bintray.com/",
"https://repo1.maven.org/maven2",
],
bind(
name = "junit",
actual = "@maven//:junit_junit",
)
bind(
name = "error_prone_annotations",
actual = "@error_prone_annotations_maven//jar",
name = "easymock",
actual = "@maven//:org_easymock_easymock",
)
# For `cc_proto_blacklist_test`.
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bind(
name = "easymock_classextension",
actual = "@maven//:org_easymock_easymockclassextension",
)
bind(
name = "truth",
actual = "@maven//:com_google_truth_truth",
)
# For `cc_proto_blacklist_test` and `build_test`.
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()

@ -58,5 +58,5 @@ bash "${test_dir}/update_file_lists.sh"
# Test whether there are any differences
for file in ${generated_files[@]}; do
diff "${golden_dir}/${file}" "${test_dir}/${file}"
diff -du "${golden_dir}/${file}" "${test_dir}/${file}"
done

@ -17,7 +17,7 @@ AC_PREREQ(2.59)
# In the SVN trunk, the version should always be the next anticipated release
# version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed
# the size of one file name in the dist tarfile over the 99-char limit.)
AC_INIT([Protocol Buffers],[3.15.6],[protobuf@googlegroups.com],[protobuf])
AC_INIT([Protocol Buffers],[3.15.8],[protobuf@googlegroups.com],[protobuf])
AM_MAINTAINER_MODE([enable])

@ -32,9 +32,9 @@ namespace Google.Protobuf.Examples.AddressBook {
"Eg4KBm51bWJlchgBIAEoCRIoCgR0eXBlGAIgASgOMhoudHV0b3JpYWwuUGVy",
"c29uLlBob25lVHlwZSIrCglQaG9uZVR5cGUSCgoGTU9CSUxFEAASCAoESE9N",
"RRABEggKBFdPUksQAiIvCgtBZGRyZXNzQm9vaxIgCgZwZW9wbGUYASADKAsy",
"EC50dXRvcmlhbC5QZXJzb25CWQobY29tLmV4YW1wbGUudHV0b3JpYWwucHJv",
"dG9zQhFBZGRyZXNzQm9va1Byb3Rvc1ABqgIkR29vZ2xlLlByb3RvYnVmLkV4",
"YW1wbGVzLkFkZHJlc3NCb29rYgZwcm90bzM="));
"EC50dXRvcmlhbC5QZXJzb25CZgobY29tLmV4YW1wbGUudHV0b3JpYWwucHJv",
"dG9zQhFBZGRyZXNzQm9va1Byb3Rvc1ABWgsuLi90dXRvcmlhbKoCJEdvb2ds",
"ZS5Qcm90b2J1Zi5FeGFtcGxlcy5BZGRyZXNzQm9va2IGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {

@ -104,6 +104,7 @@ These are projects we know about implementing Protocol Buffers for other program
* Solidity: https://github.com/celer-network/pb3-gen-sol
* Swift: https://github.com/alexeyxo/protobuf-swift
* Swift: https://github.com/apple/swift-protobuf/
* Typescript: https://github.com/thesayyn/protoc-gen-ts
* Vala: https://launchpad.net/protobuf-vala
* Visual Basic: http://code.google.com/p/protobuf-net/

@ -8,7 +8,7 @@ project(protobuf-examples)
find_package(protobuf CONFIG REQUIRED)
if(protobuf_VERBOSE)
message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")
message(STATUS "Using Protocol Buffers ${protobuf_VERSION}")
endif()
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)

@ -16,7 +16,7 @@ clean:
rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/*.class
rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/AddressBookProtos.java
rm -f *.pyc
rm -f protoc_middleman_go tutorial/*.pb.go add_person_go list_people_go
rm -f protoc_middleman_go tutorial/*.pb.go add_person_go list_people_go go.mod go.sum
rm -f protoc_middleman_dart dart_tutorial/*.pb*.dart
rmdir dart_tutorial 2>/dev/null || true
rmdir tutorial 2>/dev/null || true
@ -51,16 +51,20 @@ add_person_dart: add_person.dart protoc_middleman_dart
list_people_dart: list_people.dart protoc_middleman_dart
add_person_go: add_person.go protoc_middleman_go
go_mod:
go mod init github.com/protocolbuffers/protobuf/examples
go mod tidy
add_person_go: add_person.go protoc_middleman_go go_mod
go build -o add_person_go add_person.go
add_person_gotest: add_person_test.go add_person_go
add_person_gotest: add_person_test.go add_person_go go_mod
go test add_person.go add_person_test.go
list_people_go: list_people.go protoc_middleman_go
list_people_go: list_people.go protoc_middleman_go go_mod
go build -o list_people_go list_people.go
list_people_gotest: list_people.go list_people_go
list_people_gotest: list_people.go list_people_go go_mod
go test list_people.go list_people_test.go
javac_middleman: AddPerson.java ListPeople.java protoc_middleman

@ -23,6 +23,10 @@ option java_outer_classname = "AddressBookProtos";
option csharp_namespace = "Google.Protobuf.Examples.AddressBook";
// [END csharp_declaration]
// [START go_declaration]
option go_package = "../tutorial";
// [END go_declaration]
// [START messages]
message Person {
string name = 1;

@ -0,0 +1,8 @@
test_suite(
name = "tests",
tests = [
"//java/core:tests",
"//java/lite:tests",
"//java/util:tests",
],
)

@ -178,3 +178,8 @@ The complete documentation for Protocol Buffers is available via the
web at:
https://developers.google.com/protocol-buffers/
## Kotlin Protocol Buffers
Code to support more idiomatic Kotlin protocol buffers has been added to the
repository, and Kotlin support will be launched in the next numbered release.

@ -1,5 +1,8 @@
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_java//java:defs.bzl", "java_library", "java_proto_library", "java_lite_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("//:internal.bzl", "conformance_test")
load("//java/internal:testing.bzl", "junit_tests")
LITE_SRCS = [
# Keep in sync with `//java/lite:pom.xml`.
@ -95,12 +98,19 @@ LITE_SRCS = [
# Should be used as `//java/lite`.
java_library(
name = "lite",
srcs = LITE_SRCS,
srcs = LITE_SRCS + [
"//:gen_well_known_protos_javalite"
],
visibility = [
"//java/lite:__pkg__",
],
)
java_library(
name = "lite_runtime_only",
srcs = LITE_SRCS,
)
java_library(
name = "core",
srcs = glob(
@ -113,10 +123,10 @@ java_library(
],
visibility = ["//visibility:public"],
exports = [
"//java/lite",
":lite_runtime_only",
],
deps = [
"//java/lite",
":lite_runtime_only",
],
)
@ -126,3 +136,191 @@ proto_lang_toolchain(
runtime = ":core",
visibility = ["//visibility:public"],
)
proto_library(
name = "java_test_protos",
srcs = glob(["src/test/proto/**/*.proto"]),
strip_import_prefix = "src/test/proto",
deps = [
"//:any_proto",
"//:descriptor_proto",
"//:generic_test_protos",
"//:wrappers_proto",
],
)
java_proto_library(
name = "generic_test_protos_java_proto",
visibility = [
"//java:__subpackages__",
],
deps = ["//:generic_test_protos"],
)
java_proto_library(
name = "java_test_protos_java_proto",
deps = [":java_test_protos"],
)
java_library(
name = "test_util",
srcs = [
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java"
],
deps = [
":core",
":generic_test_protos_java_proto",
":java_test_protos_java_proto",
"//external:guava",
"//external:junit",
],
)
test_suite(
name = "tests",
tests = [
"core_build_test",
"conformance_test",
"core_tests",
],
)
build_test(
name = "core_build_test",
targets = [
":core",
],
)
conformance_test(
name = "conformance_test",
testee = "//:conformance_java",
failure_list = "//:conformance/failure_list_java.txt",
text_format_failure_list = "//:conformance/text_format_failure_list_java.txt",
)
junit_tests(
name = "core_tests",
srcs = glob(["src/test/java/**/*.java"], exclude = [
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
]),
data = ["//:testdata"],
size = "large",
deps = [
":core",
":generic_test_protos_java_proto",
":java_test_protos_java_proto",
":test_util",
"//external:easymock",
"//external:easymock_classextension",
"//external:junit",
"//external:truth",
]
)
java_lite_proto_library(
name = "generic_test_protos_java_proto_lite",
visibility = [
"//java/lite:__pkg__",
],
deps = ["//:generic_test_protos"],
)
java_lite_proto_library(
name = "java_test_protos_java_proto_lite",
visibility = [
"//java/lite:__pkg__",
],
deps = [":java_test_protos"],
)
genrule(
name = "rewrite_javalite_test_util",
srcs = [
"//java/lite:lite.awk",
"src/test/java/com/google/protobuf/TestUtil.java"
],
outs = ["TestUtil.java"],
cmd = "awk -f $(location //java/lite:lite.awk) $(location src/test/java/com/google/protobuf/TestUtil.java) > $@"
)
java_library(
name = "test_util_lite",
srcs = [
":rewrite_javalite_test_util",
"src/test/java/com/google/protobuf/TestUtilLite.java"
],
visibility = [
"//java/lite:__pkg__",
],
deps = [
":generic_test_protos_java_proto_lite",
":java_test_protos_java_proto_lite",
":lite_runtime_only",
"//external:guava",
"//external:junit",
],
)
LITE_TEST_EXCLUSIONS = [
# Keep in sync with //java/lite:pom.xml id=copy-test-source-files execution.
"src/test/java/com/google/protobuf/AbstractMessageTest.java",
"src/test/java/com/google/protobuf/AbstractProto2SchemaTest.java",
"src/test/java/com/google/protobuf/AnyTest.java",
"src/test/java/com/google/protobuf/CodedInputStreamTest.java",
"src/test/java/com/google/protobuf/DeprecatedFieldTest.java",
"src/test/java/com/google/protobuf/DescriptorsTest.java",
"src/test/java/com/google/protobuf/DiscardUnknownFieldsTest.java",
"src/test/java/com/google/protobuf/DynamicMessageTest.java",
"src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java",
"src/test/java/com/google/protobuf/FieldPresenceTest.java",
"src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java",
"src/test/java/com/google/protobuf/GeneratedMessageTest.java",
"src/test/java/com/google/protobuf/LazyFieldTest.java",
"src/test/java/com/google/protobuf/LazyStringEndToEndTest.java",
"src/test/java/com/google/protobuf/MapForProto2Test.java",
"src/test/java/com/google/protobuf/MapTest.java",
"src/test/java/com/google/protobuf/MessageTest.java",
"src/test/java/com/google/protobuf/NestedBuildersTest.java",
"src/test/java/com/google/protobuf/PackedFieldTest.java",
"src/test/java/com/google/protobuf/ParserTest.java",
"src/test/java/com/google/protobuf/ParseExceptionsTest.java",
"src/test/java/com/google/protobuf/Proto2ExtensionLookupSchemaTest.java",
"src/test/java/com/google/protobuf/Proto2SchemaTest.java",
"src/test/java/com/google/protobuf/Proto2UnknownEnumValueTest.java",
"src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java",
"src/test/java/com/google/protobuf/ServiceTest.java",
"src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java",
"src/test/java/com/google/protobuf/TestBadIdentifiers.java",
"src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java",
"src/test/java/com/google/protobuf/TextFormatParseLocationTest.java",
"src/test/java/com/google/protobuf/TextFormatTest.java",
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
"src/test/java/com/google/protobuf/TypeRegistryTest.java",
"src/test/java/com/google/protobuf/UnknownEnumValueTest.java",
"src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java",
"src/test/java/com/google/protobuf/UnknownFieldSetTest.java",
"src/test/java/com/google/protobuf/WellKnownTypesTest.java",
"src/test/java/com/google/protobuf/WireFormatTest.java",
]
junit_tests(
name = "lite_tests",
srcs = glob(["src/test/java/**/*.java"], exclude = LITE_TEST_EXCLUSIONS),
data = ["//:testdata"],
test_prefix = "Lite",
size = "large",
deps = [
":lite",
":generic_test_protos_java_proto_lite",
":java_test_protos_java_proto_lite",
":test_util_lite",
"//external:easymock",
"//external:easymock_classextension",
"//external:junit",
"//external:truth",
]
)

@ -724,12 +724,12 @@ public final class Descriptors {
/** Determines if the given field number is an extension. */
public boolean isExtensionNumber(final int number) {
for (final DescriptorProto.ExtensionRange range : proto.getExtensionRangeList()) {
if (range.getStart() <= number && number < range.getEnd()) {
return true;
}
int index = Arrays.binarySearch(extensionRangeLowerBounds, number);
if (index < 0) {
index = ~index - 1;
}
return false;
// extensionRangeLowerBounds[index] is the biggest value <= number
return index >= 0 && number < extensionRangeUpperBounds[index];
}
/** Determines if the given field number is reserved. */
@ -831,6 +831,9 @@ public final class Descriptors {
private final OneofDescriptor[] oneofs;
private final int realOneofCount;
private final int[] extensionRangeLowerBounds;
private final int[] extensionRangeUpperBounds;
// Used to create a placeholder when the type cannot be found.
Descriptor(final String fullname) throws DescriptorValidationException {
String name = fullname;
@ -859,6 +862,9 @@ public final class Descriptors {
// Create a placeholder FileDescriptor to hold this message.
this.file = new FileDescriptor(packageName, this);
extensionRangeLowerBounds = new int[] {1};
extensionRangeUpperBounds = new int[] {536870912};
}
private Descriptor(
@ -922,6 +928,20 @@ public final class Descriptors {
this.realOneofCount = this.oneofs.length - syntheticOneofCount;
file.pool.addSymbol(this);
// NOTE: The defined extension ranges are guaranteed to be disjoint.
extensionRangeLowerBounds = new int[proto.getExtensionRangeCount()];
extensionRangeUpperBounds = new int[proto.getExtensionRangeCount()];
int i = 0;
for (final DescriptorProto.ExtensionRange range : proto.getExtensionRangeList()) {
extensionRangeLowerBounds[i] = range.getStart();
extensionRangeUpperBounds[i] = range.getEnd();
i++;
}
// Since the ranges are disjoint, sorting these independently must still produce the correct
// order.
Arrays.sort(extensionRangeLowerBounds);
Arrays.sort(extensionRangeUpperBounds);
}
/** Look up and cross-link all field types, etc. */

@ -804,4 +804,8 @@ public class DescriptorsTest extends TestCase {
.build();
assertEquals(8, msg.getExtension(NestedExtension.MyNestedExtension.default_).intValue());
}
public void testDefaultDescriptorExtensionRange() throws Exception {
assertTrue(new Descriptor("default").isExtensionNumber(1));
}
}

@ -0,0 +1 @@
package(default_visibility = ["//java:__subpackages__"])

@ -0,0 +1,19 @@
<project name="generate-sources">
<echo message="Running protoc ..."/>
<mkdir dir="${generated.sources.dir}"/>
<exec executable="${protoc}">
<arg value="--kotlin_out=lite:${generated.sources.dir}"/>
<arg value="--proto_path=${protobuf.source.dir}"/>
<arg value="${protobuf.source.dir}/google/protobuf/any.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/api.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/duration.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/empty.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/field_mask.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/source_context.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/struct.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/timestamp.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/type.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/wrappers.proto"/>
</exec>
</project>

@ -0,0 +1,34 @@
<project name="generate-test-sources">
<mkdir dir="${generated.testsources.dir}"/>
<exec executable="${protoc}">
<arg value="--java_out=lite:${generated.testsources.dir}"/>
<arg value="--proto_path=${protobuf.source.dir}"/>
<arg value="--proto_path=${protobuf.basedir}/java/kotlin/${test.proto.dir}"/>
<arg value="--experimental_allow_proto3_optional"/>
<arg value="${protobuf.source.dir}/google/protobuf/map_lite_unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import_lite.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import_public.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import_public_lite.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_lite.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_proto3.proto"/>
<arg value="${protobuf.basedir}/java/kotlin/${test.proto.dir}/com/google/protobuf/evil_names_proto2.proto"/>
<arg value="${protobuf.basedir}/java/kotlin/${test.proto.dir}/com/google/protobuf/evil_names_proto3.proto"/>
<arg value="${protobuf.basedir}/java/kotlin/${test.proto.dir}/com/google/protobuf/example_extensible_message.proto"/>
<arg value="${protobuf.basedir}/java/kotlin/${test.proto.dir}/com/google/protobuf/multiple_files_proto3.proto"/>
</exec>
<exec executable="${protoc}">
<arg value="--kotlin_out=lite:${generated.testsources.dir}"/>
<arg value="--proto_path=${protobuf.source.dir}"/>
<arg value="--proto_path=${protobuf.basedir}/java/kotlin/${test.proto.dir}"/>
<arg value="--experimental_allow_proto3_optional"/>
<arg value="${protobuf.source.dir}/google/protobuf/map_lite_unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_lite.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_proto3.proto"/>
<arg value="${protobuf.basedir}/java/kotlin/${test.proto.dir}/com/google/protobuf/evil_names_proto2.proto"/>
<arg value="${protobuf.basedir}/java/kotlin/${test.proto.dir}/com/google/protobuf/evil_names_proto3.proto"/>
<arg value="${protobuf.basedir}/java/kotlin/${test.proto.dir}/com/google/protobuf/example_extensible_message.proto"/>
<arg value="${protobuf.basedir}/java/kotlin/${test.proto.dir}/com/google/protobuf/multiple_files_proto3.proto"/>
</exec>
</project>

@ -0,0 +1,284 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId>
<version>3.15.6</version>
</parent>
<artifactId>protobuf-kotlin-lite</artifactId>
<packaging>bundle</packaging>
<name>Protocol Buffers [Lite]</name>
<description>
Lite version of Protocol Buffers library. This version is optimized for code size, but does
not guarantee API/ABI stability.
</description>
<properties>
<kotlin.version>1.4.31</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>protobuf-javalite</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<!-- Include core protos in the bundle as resources -->
<resources>
<resource>
<directory>${protobuf.source.dir}</directory>
<includes>
<include>google/protobuf/any.proto</include>
<include>google/protobuf/api.proto</include>
<include>google/protobuf/duration.proto</include>
<include>google/protobuf/empty.proto</include>
<include>google/protobuf/field_mask.proto</include>
<include>google/protobuf/source_context.proto</include>
<include>google/protobuf/struct.proto</include>
<include>google/protobuf/timestamp.proto</include>
<include>google/protobuf/type.proto</include>
<include>google/protobuf/wrappers.proto</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>${protobuf.source.dir}</directory>
<includes>
<include>google/protobuf/testdata/golden_message_oneof_implemented</include>
<include>google/protobuf/testdata/golden_packed_fields_message</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-kotlin-source-files</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${generated.sources.dir}/com/google/protobuf</outputDirectory>
<resources>
<resource>
<directory>${basedir}/../kotlin/src/main/kotlin/com/google/protobuf</directory>
<includes>
<include>DslList.kt</include>
<include>DslMap.kt</include>
<include>DslProxy.kt</include>
<include>ExtendableMessageLiteExtensions.kt</include>
<include>ExtensionList.kt</include>
<include>OnlyForUseByGeneratedProtoCode.kt</include>
<include>ProtoDslMarker.kt</include>
<include>UnmodifiableCollections.kt</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-test-source-files</id>
<phase>generate-test-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${generated.testsources.dir}/com/google/protobuf</outputDirectory>
<resources>
<resource>
<directory>${basedir}/../core/src/test/java/com/google/protobuf</directory>
<includes>
<include>TestUtilLite.java</include>
</includes>
</resource>
<resource>
<directory>${basedir}/../kotlin/src/test/kotlin/com/google/protobuf</directory>
<excludes>
<exclude>ExtendableMessageExtensionsTest.kt</exclude>
<exclude>Proto2Test.kt</exclude>
<exclude>ProtoUtil.java</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Use Antrun plugin to generate sources with protoc -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<!-- Generate core protos -->
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<target>
<ant antfile="generate-sources-build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<!-- Generate the test protos -->
<execution>
<id>generate-test-sources</id>
<phase>generate-test-sources</phase>
<configuration>
<target>
<ant antfile="generate-test-sources-build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>process-lite-sources</id>
<phase>generate-test-sources</phase>
<configuration>
<target>
<ant antfile="process-lite-sources-build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-generated-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${generated.sources.dir}</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-generated-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${generated.testsources.dir}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${generated.sources.dir}</sourceDir>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${generated.testsources.dir}</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<!-- OSGI bundle configuration -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Automatic-Module-Name>com.google.protobuf</Automatic-Module-Name> <!-- Java9+ Jigsaw module name -->
<Bundle-DocURL>https://developers.google.com/protocol-buffers/</Bundle-DocURL>
<Bundle-SymbolicName>com.google.protobuf</Bundle-SymbolicName>
<Export-Package>com.google.protobuf;version=${project.version}</Export-Package>
<Import-Package>sun.misc;resolution:=optional,*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,7 @@
<project name="process-lite-sources">
<exec executable="awk" output="${generated.testsources.dir}/com/google/protobuf/TestUtil.java">
<arg value="-f" />
<arg value="${basedir}/lite.awk" />
<arg value="${basedir}/../core/src/test/java/com/google/protobuf/TestUtil.java" />
</exec>
</project>

@ -0,0 +1,20 @@
<project name="generate-sources">
<echo message="Running protoc ..."/>
<mkdir dir="${generated.sources.dir}"/>
<exec executable="${protoc}">
<arg value="--kotlin_out=${generated.sources.dir}"/>
<arg value="--proto_path=${protobuf.source.dir}"/>
<arg value="${protobuf.source.dir}/google/protobuf/any.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/api.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/descriptor.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/duration.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/empty.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/field_mask.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/source_context.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/struct.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/timestamp.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/type.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/wrappers.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/compiler/plugin.proto"/>
</exec>
</project>

@ -0,0 +1,34 @@
<project name="generate-test-sources">
<mkdir dir="${generated.testsources.dir}"/>
<exec executable="${protoc}">
<arg value="--java_out=${generated.testsources.dir}"/>
<arg value="--proto_path=${protobuf.source.dir}"/>
<arg value="--proto_path=${test.proto.dir}"/>
<arg value="--experimental_allow_proto3_optional"/>
<arg value="${protobuf.source.dir}/google/protobuf/map_proto2_unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import_lite.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import_public.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_import_public_lite.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_lite.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_proto3.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/evil_names_proto2.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/evil_names_proto3.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/example_extensible_message.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/multiple_files_proto3.proto"/>
</exec>
<exec executable="${protoc}">
<arg value="--kotlin_out=${generated.testsources.dir}"/>
<arg value="--proto_path=${protobuf.source.dir}"/>
<arg value="--proto_path=${test.proto.dir}"/>
<arg value="--experimental_allow_proto3_optional"/>
<arg value="${protobuf.source.dir}/google/protobuf/map_proto2_unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/>
<arg value="${protobuf.source.dir}/google/protobuf/unittest_proto3.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/evil_names_proto2.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/evil_names_proto3.proto"/>
<arg value="${test.proto.dir}/com/google/protobuf/multiple_files_proto3.proto"/>
</exec>
</project>

@ -0,0 +1,240 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId>
<version>3.15.6</version>
</parent>
<artifactId>protobuf-kotlin</artifactId>
<packaging>bundle</packaging>
<name>Protocol Buffers [Core]</name>
<description>
Core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an
efficient yet extensible format.
</description>
<properties>
<kotlin.version>1.4.31</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Include core protos in the bundle as resources -->
<resources>
<resource>
<directory>${protobuf.source.dir}</directory>
<includes>
<include>google/protobuf/any.proto</include>
<include>google/protobuf/api.proto</include>
<include>google/protobuf/descriptor.proto</include>
<include>google/protobuf/duration.proto</include>
<include>google/protobuf/empty.proto</include>
<include>google/protobuf/field_mask.proto</include>
<include>google/protobuf/source_context.proto</include>
<include>google/protobuf/struct.proto</include>
<include>google/protobuf/timestamp.proto</include>
<include>google/protobuf/type.proto</include>
<include>google/protobuf/wrappers.proto</include>
<include>google/protobuf/compiler/plugin.proto</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>${protobuf.source.dir}</directory>
<includes>
<include>google/protobuf/testdata/golden_message_oneof_implemented</include>
<include>google/protobuf/testdata/golden_packed_fields_message</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-test-source-files</id>
<phase>generate-test-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${generated.testsources.dir}/com/google/protobuf</outputDirectory>
<resources>
<resource>
<directory>${basedir}/../core/src/test/java/com/google/protobuf</directory>
<includes>
<include>TestUtil.java</include>
<include>TestUtilLite.java</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Use Antrun plugin to generate sources with protoc -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<!-- Generate core protos -->
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<target>
<ant antfile="generate-sources-build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<!-- Generate the test protos -->
<execution>
<id>generate-test-sources</id>
<phase>generate-test-sources</phase>
<configuration>
<target>
<ant antfile="generate-test-sources-build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Add the generated sources to the build -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-generated-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${generated.sources.dir}</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-generated-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${generated.testsources.dir}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${generated.sources.dir}</sourceDir>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${generated.testsources.dir}</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<!-- OSGI bundle configuration -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Automatic-Module-Name>com.google.protobuf</Automatic-Module-Name> <!-- Java9+ Jigsaw module name -->
<Bundle-DocURL>https://developers.google.com/protocol-buffers/</Bundle-DocURL>
<Bundle-SymbolicName>com.google.protobuf</Bundle-SymbolicName>
<Export-Package>com.google.protobuf;version=${project.version}</Export-Package>
<Import-Package>sun.misc;resolution:=optional,*</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -1,4 +1,9 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain")
load("//:internal.bzl", "conformance_test")
load("//java/internal:testing.bzl", "junit_tests")
exports_files(["lite.awk"], visibility = ["//java/core:__pkg__"])
alias(
name = "lite",
@ -12,3 +17,40 @@ proto_lang_toolchain(
runtime = ":lite",
visibility = ["//visibility:public"],
)
test_suite(
name = "tests",
tests = [
"lite_build_test",
"conformance_test",
"lite_tests",
"//java/core:lite_tests",
],
)
build_test(
name = "lite_build_test",
targets = [
":lite",
],
)
conformance_test(
name = "conformance_test",
testee = "//:conformance_java_lite",
failure_list = "//:conformance/failure_list_java_lite.txt",
text_format_failure_list = "//:conformance/text_format_failure_list_java_lite.txt",
)
junit_tests(
name = "lite_tests",
srcs = glob(["src/test/**/*.java"]),
size = "small",
deps = [
":lite",
"//external:junit",
"//java/core:generic_test_protos_java_proto_lite",
"//java/core:java_test_protos_java_proto_lite",
"//java/core:test_util_lite",
],
)

@ -199,6 +199,7 @@
and exclude only the full runtime exclusive tests so we don't accidentally miss
any test. -->
<excludes>
<!-- Keep in sync with //java/core:lite_tests BUILD rule. -->
<exclude>AbstractMessageTest.java</exclude>
<exclude>AbstractProto2SchemaTest.java</exclude>
<exclude>AnyTest.java</exclude>

@ -1,4 +1,6 @@
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_java//java:defs.bzl", "java_library", "java_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//java/internal:testing.bzl", "junit_tests")
java_library(
name = "util",
@ -14,3 +16,36 @@ java_library(
"//java/lite",
],
)
proto_library(
name = "test_protos",
srcs = glob(["src/test/proto/**/*.proto"]),
deps = [
"//:any_proto",
"//:duration_proto",
"//:field_mask_proto",
"//:struct_proto",
"//:timestamp_proto",
"//:wrappers_proto",
],
)
java_proto_library(
name = "test_protos_java_proto",
deps = [":test_protos"],
)
junit_tests(
name = "tests",
srcs = glob(["src/test/java/**/*.java"]),
package_name = "com.google.protobuf.util",
deps = [
":test_protos_java_proto",
":util",
"//external:guava",
"//external:junit",
"//external:truth",
"//java/core",
"//java/core:generic_test_protos_java_proto",
],
)

@ -224,7 +224,6 @@ describe('binaryDecoderTest', function() {
/**
* Verifies that misuse of the decoder class triggers assertions.
* @suppress {checkTypes|visibility}
*/
it('testDecodeErrors', function() {
// Reading a value past the end of the stream should trigger an assertion.

@ -1,6 +1,6 @@
{
"name": "google-protobuf",
"version": "3.15.6",
"version": "3.15.8",
"description": "Protocol Buffers for JavaScript",
"main": "google-protobuf.js",
"files": [

@ -0,0 +1,21 @@
#!/bin/bash
#
# Builds protobuf C++ with aarch64 crosscompiler and runs a basic set of tests under an emulator.
# NOTE: This script is expected to run under the dockcross/linux-arm64 docker image.
set -ex
mkdir -p cmake/crossbuild_aarch64
cd cmake/crossbuild_aarch64
# the build commands are expected to run under dockcross docker image
# where the CC, CXX and other toolchain variables already point to the crosscompiler
cmake ..
make -j8
# check that the resulting test binary is indeed an aarch64 ELF
(file ./tests | grep -q "ELF 64-bit LSB executable, ARM aarch64") || (echo "Test binary in not an aarch64 binary"; exit 1)
# run the basic set of C++ tests under QEMU
# there are other tests we could run (e.g. ./lite-test), but this is sufficient as a smoketest
qemu-aarch64 ./tests

@ -0,0 +1,33 @@
#!/bin/bash
set -e
# go to the repo root
cd $(dirname $0)/../../../..
if [[ -t 0 ]]; then
DOCKER_TTY_ARGS="-it"
else
# The input device on kokoro is not a TTY, so -it does not work.
DOCKER_TTY_ARGS=
fi
# running dockcross image without any arguments generates a wrapper
# scripts that can be used to run commands under the dockcross image
# easily.
# See https://github.com/dockcross/dockcross#usage for details
docker run $DOCKER_TTY_ARGS --rm dockcross/linux-arm64 >dockcross-linux-arm64.sh
chmod +x dockcross-linux-arm64.sh
# the wrapper script has CRLF line endings and bash doesn't like that
# so we change CRLF line endings into LF.
sed -i 's/\r//g' dockcross-linux-arm64.sh
# The dockcross wrapper script runs arbitrary commands under the selected dockcross
# image with the following properties which make its use very convenient:
# * the current working directory is mounted under /work so the container can easily
# access the current workspace
# * the processes in the container run under the same UID and GID as the host process so unlike
# vanilla "docker run" invocations, the workspace doesn't get polluted with files
# owned by root.
./dockcross-linux-arm64.sh "$@"

@ -5,11 +5,18 @@ set -e
# go to the repo root
cd $(dirname $0)/../../../..
if [[ -t 0 ]]; then
DOCKER_TTY_ARGS="-it"
else
# The input device on kokoro is not a TTY, so -it does not work.
DOCKER_TTY_ARGS=
fi
# running dockcross image without any arguments generates a wrapper
# scripts that can be used to run commands under the dockcross image
# easily.
# See https://github.com/dockcross/dockcross#usage for details
docker run --rm -it dockcross/manylinux2014-aarch64 >dockcross-manylinux2014-aarch64.sh
docker run $DOCKER_TTY_ARGS --rm dockcross/manylinux2014-aarch64 >dockcross-manylinux2014-aarch64.sh
chmod +x dockcross-manylinux2014-aarch64.sh
# the wrapper script has CRLF line endings and bash doesn't like that

@ -0,0 +1,19 @@
#!/bin/bash
set -ex
# install the same version of node as in /tests.sh
NODE_VERSION=node-v12.16.3-linux-arm64
NODE_TGZ="$NODE_VERSION.tar.gz"
pushd /tmp
curl -OL https://nodejs.org/dist/v12.16.3/$NODE_TGZ
tar zxvf $NODE_TGZ
export PATH=$PATH:`pwd`/$NODE_VERSION/bin
popd
# go to the repo root
cd $(dirname $0)/../../..
cd js
npm install
npm test

@ -0,0 +1,9 @@
#!/bin/bash
#
# Builds protobuf C++ with aarch64 crosscompiler.
set -ex
./autogen.sh
CXXFLAGS="-fPIC -g -O2" ./configure --host=aarch64
make -j8

@ -1,21 +1,28 @@
#!/bin/bash
#
# Builds protobuf C++ with aarch64 crosscompiler and runs a basic set of tests under an emulator.
# NOTE: This script is expected to run under the dockcross/linux-arm64 docker image.
# Builds protobuf python including the C++ extension with aarch64 crosscompiler.
# The outputs of this script are laid out so that we can later test them under an aarch64 emulator.
# NOTE: This script is expected to run under the dockcross/manylinux2014-aarch64 docker image.
set -ex
PYTHON="/opt/python/cp38-cp38/bin/python"
./autogen.sh
CXXFLAGS="-fPIC -g -O2" ./configure
CXXFLAGS="-fPIC -g -O2" ./configure --host=aarch64
make -j8
# create a simple shell wrapper that runs crosscompiled protoc under qemu
echo '#!/bin/bash' >protoc_qemu_wrapper.sh
echo 'exec qemu-aarch64 "../src/protoc" "$@"' >>protoc_qemu_wrapper.sh
chmod ugo+x protoc_qemu_wrapper.sh
# PROTOC variable is by build_py step that runs under ./python directory
export PROTOC=../protoc_qemu_wrapper.sh
pushd python
# TODO: currently this step relies on qemu being registered with binfmt_misc so that
# aarch64 binaries are automatically run with an emulator. This works well once
# "sudo apt install qemu-user-static binfmt-support" is installed on the host machine.
# NOTE: this step will use protoc_qemu_wrapper.sh to generate protobuf files.
${PYTHON} setup.py build_py
# when crosscompiling for aarch64, --plat-name needs to be set explicitly

@ -0,0 +1,26 @@
#!/bin/bash
#
# Setup and configure qemu userspace emulator on kokoro worker so that we can seamlessly emulate processes running
# inside docker containers.
set -ex
# show pre-existing qemu registration
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
# Kokoro ubuntu1604 workers have already qemu-user and qemu-user-static packages installed, but it's and old version that:
# * prints warning about some syscalls (e.g "qemu: Unsupported syscall: 278")
# * doesn't register with binfmt_misc with the persistent ("F") flag we need (see below)
#
# To overcome the above limitations, we use the https://github.com/multiarch/qemu-user-static
# docker image to provide a new enough version of qemu-user-static and register it with
# the desired binfmt_misc flags. The most important flag we need is "F" (set by "--persistent yes"),
# which allows the qemu-aarch64-static binary to be loaded eagerly at the time of registration with binfmt_misc.
# That way, we can emulate aarch64 binaries running inside docker containers transparently, without needing the emulator
# binary to be accessible from the docker image we're emulating.
# Note that on newer distributions (such as glinux), simply "apt install qemu-user-static" is sufficient
# to install qemu-user-static with the right flags.
docker run --rm --privileged multiarch/qemu-user-static:5.2.0-2 --reset --credential yes --persistent yes
# Print current qemu reqistration to make sure everything is setup correctly.
cat /proc/sys/fs/binfmt_misc/qemu-aarch64

@ -0,0 +1,17 @@
#!/bin/bash
set -ex
# go to the repo root
cd $(dirname $0)/../../..
gem install bundler
cd ruby
bundle
rake
rake clobber_package gem
# run all the tests
rake test

@ -0,0 +1,14 @@
#!/bin/bash
#
# Crosscompiles protobuf C++ under dockcross docker image and runs the tests under an emulator.
set -e
# go to the repo root
cd $(dirname $0)/../../..
# Initialize any submodules.
git submodule update --init --recursive
# run the C++ build and test script under dockcross/linux-arm64 image
kokoro/linux/aarch64/dockcross_helpers/run_dockcross_linux_aarch64.sh kokoro/linux/aarch64/cpp_crosscompile_and_run_tests_with_qemu_aarch64.sh

@ -0,0 +1,29 @@
#!/bin/bash
set -ex
# go to the repo root
cd $(dirname $0)/../../..
if [[ -t 0 ]]; then
DOCKER_TTY_ARGS="-it"
else
# The input device on kokoro is not a TTY, so -it does not work.
DOCKER_TTY_ARGS=
fi
# First, build protobuf C# tests under x86_64 docker image
# Tests are built "dotnet publish" because we want all the dependencies to the copied to the destination directory
# (we want to avoid references to ~/.nuget that won't be available in the subsequent docker run)
CSHARP_BUILD_COMMAND="dotnet publish -c Release -f net50 csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj"
docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "DOTNET_CLI_TELEMETRY_OPTOUT=true" -e "DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work mcr.microsoft.com/dotnet/sdk:5.0.202-buster-slim bash -c "$CSHARP_BUILD_COMMAND"
# Use an actual aarch64 docker image to run protobuf C# tests with an emulator. "dotnet vstest" allows
# running tests from a pre-built project.
# * mount the protobuf root as /work to be able to access the crosscompiled files
# * to avoid running the process inside docker as root (which can pollute the workspace with files owned by root), we force
# running under current user's UID and GID. To be able to do that, we need to provide a home directory for the user
# otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity,
# we just run map the user's home to a throwaway temporary directory
CSHARP_TEST_COMMAND="dotnet vstest csharp/src/Google.Protobuf.Test/bin/Release/net50/publish/Google.Protobuf.Test.dll"
docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "DOTNET_CLI_TELEMETRY_OPTOUT=true" -e "DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work mcr.microsoft.com/dotnet/sdk:5.0.202-buster-slim-arm64v8 bash -c "$CSHARP_TEST_COMMAND"

@ -0,0 +1,32 @@
#!/bin/bash
set -ex
# go to the repo root
cd $(dirname $0)/../../..
if [[ -t 0 ]]; then
DOCKER_TTY_ARGS="-it"
else
# The input device on kokoro is not a TTY, so -it does not work.
DOCKER_TTY_ARGS=
fi
# crosscompile protoc as we will later need it for the java build.
# we build it under the dockcross/manylinux2014-aarch64 image so that the resulting protoc binary is compatible
# with a wide range of linux distros (including any docker images we will use later to build and test java)
kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh
# the command that will be used to build and test java under an emulator
# * IsValidUtf8Test and DecodeUtf8Test tests are being skipped because that take very long under an emulator.
TEST_JAVA_COMMAND="mvn --batch-mode -DskipTests install && mvn --batch-mode -Dtest='**/*Test, !**/*IsValidUtf8Test, !**/*DecodeUtf8Test' -DfailIfNoTests=false surefire:test"
# use an actual aarch64 docker image (with a real aarch64 java and maven) to run build & test protobuf java under an emulator
# * mount the protobuf root as /work to be able to access the crosscompiled files
# * to avoid running the process inside docker as root (which can pollute the workspace with files owned by root), we force
# running under current user's UID and GID. To be able to do that, we need to provide a home directory for the user
# otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity,
# we just run map the user's home to a throwaway temporary directory
# * the JAVA_OPTS and MAVEN_CONFIG variables are being set mostly to silence warnings about non-existent home directory
# and to avoid polluting the workspace.
docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "JAVA_OPTS=-Duser.home=/home/fake-user" -e "MAVEN_CONFIG=/home/fake-user/.m2" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work arm64v8/maven:3.8-openjdk-11 bash -c "cd java && $TEST_JAVA_COMMAND"

@ -0,0 +1,29 @@
#!/bin/bash
set -ex
# go to the repo root
cd $(dirname $0)/../../..
if [[ -t 0 ]]; then
DOCKER_TTY_ARGS="-it"
else
# The input device on kokoro is not a TTY, so -it does not work.
DOCKER_TTY_ARGS=
fi
# crosscompile protoc as we will later need it for the javascript build.
# we build it under the dockcross/manylinux2014-aarch64 image so that the resulting protoc binary is compatible
# with a wide range of linux distros (including any docker images we will use later to build and test javascript)
kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh
# use an actual aarch64 docker image (with a real aarch64 nodejs) to run build & test protobuf javascript under an emulator
# * mount the protobuf root as /work to be able to access the crosscompiled files
# * to avoid running the process inside docker as root (which can pollute the workspace with files owned by root), we force
# running under current user's UID and GID. To be able to do that, we need to provide a home directory for the user
# otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity,
# we just run map the user's home to a throwaway temporary directory
# Note that the docker image used for running the tests is arm64v8/openjdk, not arm64v8/node
# This is because some of the node tests require java to be available and adding node
# binary distribution into a java image is easier than vice versa.
docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work arm64v8/openjdk:11-jdk-buster kokoro/linux/aarch64/javascript_build_and_run_tests_with_qemu_aarch64.sh

@ -5,6 +5,13 @@ set -e
# go to the repo root
cd $(dirname $0)/../../..
if [[ -t 0 ]]; then
DOCKER_TTY_ARGS="-it"
else
# The input device on kokoro is not a TTY, so -it does not work.
DOCKER_TTY_ARGS=
fi
# crosscompile python extension and the binary wheel under dockcross/manylinux2014-aarch64 image
kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh kokoro/linux/aarch64/python_crosscompile_aarch64.sh
@ -16,4 +23,4 @@ kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh ko
# running under current user's UID and GID. To be able to do that, we need to provide a home directory for the user
# otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity,
# we just run map the user's home to a throwaway temporary directory
docker run -it --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work quay.io/pypa/manylinux_2_24_aarch64 kokoro/linux/aarch64/python_run_tests_with_qemu_aarch64.sh
docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work quay.io/pypa/manylinux_2_24_aarch64 kokoro/linux/aarch64/python_run_tests_with_qemu_aarch64.sh

@ -0,0 +1,27 @@
#!/bin/bash
set -ex
# go to the repo root
cd $(dirname $0)/../../..
if [[ -t 0 ]]; then
DOCKER_TTY_ARGS="-it"
else
# The input device on kokoro is not a TTY, so -it does not work.
DOCKER_TTY_ARGS=
fi
# crosscompile protoc as we will later need it for the ruby build.
# we build it under the dockcross/manylinux2014-aarch64 image so that the resulting protoc binary is compatible
# with a wide range of linux distros (including any docker images we will use later to build and test ruby)
kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh
# use an actual aarch64 docker image (with a real aarch64 ruby) to run build & test protobuf ruby under an emulator
# * mount the protobuf root as /work to be able to access the crosscompiled files
# * to avoid running the process inside docker as root (which can pollute the workspace with files owned by root), we force
# running under current user's UID and GID. To be able to do that, we need to provide a home directory for the user
# otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity,
# we just run map the user's home to a throwaway temporary directory
docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work arm64v8/ruby:2.7.3-buster kokoro/linux/aarch64/ruby_build_and_run_tests_with_qemu_aarch64.sh

@ -0,0 +1,11 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "continuous" and "presubmit" jobs.
set -ex
# Change to repo root
cd $(dirname $0)/../../..
kokoro/linux/aarch64/test_cpp_aarch64.sh

@ -1,5 +1,5 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/java_compatibility/build.sh"
timeout_mins: 1440
build_file: "protobuf/kokoro/linux/cpp_aarch64/build.sh"
timeout_mins: 120

@ -1,5 +1,5 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/java_compatibility/build.sh"
timeout_mins: 1440
build_file: "protobuf/kokoro/linux/cpp_aarch64/build.sh"
timeout_mins: 120

@ -0,0 +1,16 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "continuous" and "presubmit" jobs.
set -ex
# Change to repo root
cd $(dirname $0)/../../..
# Initialize any submodules.
git submodule update --init --recursive
kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh
kokoro/linux/aarch64/test_csharp_aarch64.sh

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

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

@ -0,0 +1,16 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "continuous" and "presubmit" jobs.
set -ex
# Change to repo root
cd $(dirname $0)/../../..
# Initialize any submodules.
git submodule update --init --recursive
kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh
kokoro/linux/aarch64/test_java_aarch64.sh

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

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

@ -1,17 +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 DOCKERFILE_DIR=kokoro/linux/64-bit
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
export OUTPUT_DIR=testoutput
export TEST_SET="java_compatibility"
./kokoro/linux/build_and_run_docker.sh

@ -0,0 +1,16 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "continuous" and "presubmit" jobs.
set -ex
# Change to repo root
cd $(dirname $0)/../../..
# Initialize any submodules.
git submodule update --init --recursive
kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh
kokoro/linux/aarch64/test_javascript_aarch64.sh

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

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

@ -0,0 +1,13 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "continuous" and "presubmit" jobs.
set -ex
# Change to repo root
cd $(dirname $0)/../../..
kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh
kokoro/linux/aarch64/test_python_aarch64.sh

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

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

@ -0,0 +1,16 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "continuous" and "presubmit" jobs.
set -ex
# Change to repo root
cd $(dirname $0)/../../..
# Initialize any submodules.
git submodule update --init --recursive
kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh
kokoro/linux/aarch64/test_ruby_aarch64.sh

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

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

@ -69,11 +69,3 @@ build_artifact_version 3.9
build_crosscompiled_aarch64_artifact_version 3.7
build_crosscompiled_aarch64_artifact_version 3.8
build_crosscompiled_aarch64_artifact_version 3.9
# Put the aarch64 manylinux wheels under the "unofficial" subdirectory.
# Only wheels directly under the artifacts/ directory will be published
# to PyPI as part of the protobuf release process.
# TODO(jtattermusch): include aarch64 wheels in the release
# once they are sufficiently tested.
mkdir -p $ARTIFACT_DIR/unofficial
mv $ARTIFACT_DIR/protobuf-*-manylinux*_aarch64.whl $ARTIFACT_DIR/unofficial

@ -328,7 +328,12 @@ def _internal_gen_well_known_protos_java_impl(ctx):
deps = [d[ProtoInfo] for d in ctx.attr.deps]
srcjar = ctx.actions.declare_file("{}.srcjar".format(ctx.attr.name))
args.add("--java_out", srcjar)
if ctx.attr.javalite:
java_out = "lite:%s" % srcjar.path
else:
java_out = srcjar
args.add("--java_out", java_out)
descriptors = depset(
transitive = [dep.transitive_descriptor_sets for dep in deps],
@ -368,6 +373,9 @@ internal_gen_well_known_protos_java = rule(
mandatory = True,
providers = [ProtoInfo],
),
"javalite": attr.bool(
default = False,
),
"_protoc": attr.label(
executable = True,
cfg = "host",

@ -63,3 +63,11 @@ def protobuf_deps():
strip_prefix = "rules_python-4b84ad270387a7c439ebdccfd530e2339601ef27",
urls = ["https://github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz"],
)
if not native.existing_rule("rules_jvm_external"):
http_archive(
name = "rules_jvm_external",
sha256 = "31701ad93dbfe544d597dbe62c9a1fdd76d81d8a9150c2bf1ecf928ecdf97169",
strip_prefix = "rules_jvm_external-4.0",
urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/4.0.zip"],
)

@ -30,4 +30,4 @@
# Copyright 2007 Google Inc. All Rights Reserved.
__version__ = '3.15.6'
__version__ = '3.15.8'

@ -913,6 +913,24 @@ class MethodDescriptor(DescriptorBase):
self.input_type = input_type
self.output_type = output_type
def CopyToProto(self, proto):
"""Copies this to a descriptor_pb2.MethodDescriptorProto.
Args:
proto (descriptor_pb2.MethodDescriptorProto): An empty descriptor proto.
Raises:
Error: If self couldn't be serialized, due to too few constructor
arguments.
"""
if self.containing_service is not None:
from google.protobuf import descriptor_pb2
service_proto = descriptor_pb2.ServiceDescriptorProto()
self.containing_service.CopyToProto(service_proto)
proto.CopyFrom(service_proto.method[self.index])
else:
raise Error('Descriptor does not contain a service.')
class FileDescriptor(DescriptorBase):
"""Descriptor for a file. Mimics the descriptor_pb2.FileDescriptorProto.

@ -907,10 +907,6 @@ class DescriptorCopyToProtoTest(unittest.TestCase):
descriptor_pb2.ServiceDescriptorProto,
TEST_SERVICE_ASCII)
@unittest.skipIf(
api_implementation.Type() == 'python',
'It is not implemented in python.')
# TODO(jieluo): Add support for pure python or remove in c extension.
def testCopyToProto_MethodDescriptor(self):
expected_ascii = """
name: 'Foo'

@ -42,6 +42,7 @@ except ImportError:
import unittest
from google.protobuf import descriptor_pb2
from google.protobuf import descriptor
from google.protobuf import descriptor_pool
from google.protobuf import proto_builder
from google.protobuf import text_format
@ -91,6 +92,23 @@ class ProtoBuilderTest(unittest.TestCase):
pool=pool)
self.assertIs(proto_cls1.DESCRIPTOR, proto_cls2.DESCRIPTOR)
def testMakeLargeProtoClass(self):
"""Test that large created protos don't use reserved field numbers."""
num_fields = 123456
fields = {
'foo%d' % i: descriptor_pb2.FieldDescriptorProto.TYPE_INT64
for i in range(num_fields)
}
proto_cls = proto_builder.MakeSimpleProtoClass(
fields,
full_name='net.proto2.python.public.proto_builder_test.LargeProtoTest')
reserved_field_numbers = set(
range(descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER,
descriptor.FieldDescriptor.LAST_RESERVED_FIELD_NUMBER + 1))
proto_field_numbers = set(proto_cls.DESCRIPTOR.fields_by_number)
self.assertFalse(reserved_field_numbers.intersection(proto_field_numbers))
if __name__ == '__main__':
unittest.main()

@ -31,13 +31,14 @@
"""Dynamic Protobuf class creator."""
try:
from collections import OrderedDict
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict #PY26
from ordereddict import OrderedDict #PY26
import hashlib
import os
from google.protobuf import descriptor_pb2
from google.protobuf import descriptor
from google.protobuf import message_factory
@ -124,6 +125,12 @@ def _MakeFileDescriptorProto(proto_file_name, full_name, field_items):
for f_number, (f_name, f_type) in enumerate(field_items, 1):
field_proto = desc_proto.field.add()
field_proto.name = f_name
# # If the number falls in the reserved range, reassign it to the correct
# # number after the range.
if f_number >= descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER:
f_number += (
descriptor.FieldDescriptor.LAST_RESERVED_FIELD_NUMBER -
descriptor.FieldDescriptor.FIRST_RESERVED_FIELD_NUMBER + 1)
field_proto.number = f_number
field_proto.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
field_proto.type = f_type

@ -379,16 +379,19 @@ static void ReorderAttached(RepeatedCompositeContainer* self,
const FieldDescriptor* descriptor = self->parent_field_descriptor;
const Py_ssize_t length = Length(reinterpret_cast<PyObject*>(self));
// Since Python protobuf objects are never arena-allocated, adding and
// removing message pointers to the underlying array is just updating
// pointers.
for (Py_ssize_t i = 0; i < length; ++i)
reflection->ReleaseLast(message, descriptor);
// We need to rearrange things to match python's sort order. Because there
// was already an O(n*log(n)) step in python and a bunch of reflection, we
// expect an O(n**2) step in C++ won't hurt too much.
for (Py_ssize_t i = 0; i < length; ++i) {
CMessage* py_cmsg = reinterpret_cast<CMessage*>(
PyList_GET_ITEM(child_list, i));
reflection->AddAllocatedMessage(message, descriptor, py_cmsg->message);
Message* child_message =
reinterpret_cast<CMessage*>(PyList_GET_ITEM(child_list, i))->message;
for (Py_ssize_t j = i; j < length; ++j) {
if (child_message ==
&reflection->GetRepeatedMessage(*message, descriptor, j)) {
reflection->SwapElements(message, descriptor, i, j);
break;
}
}
}
}

@ -868,6 +868,20 @@ static VALUE FieldDescriptor_default(VALUE _self) {
return Convert_UpbToRuby(default_val, TypeInfo_get(self->fielddef), Qnil);
}
/*
* call-seq:
* FieldDescriptor.json_name => json_name
*
* Returns this field's json_name, as a Ruby string, or nil if not yet set.
*/
static VALUE FieldDescriptor_json_name(VALUE _self) {
FieldDescriptor* self = ruby_to_FieldDescriptor(_self);
const upb_fielddef *f = self->fielddef;
const char *json_name = upb_fielddef_jsonname(f);
return rb_str_new2(json_name);
}
/*
* call-seq:
* FieldDescriptor.label => label
@ -1043,6 +1057,7 @@ static void FieldDescriptor_register(VALUE module) {
rb_define_method(klass, "name", FieldDescriptor_name, 0);
rb_define_method(klass, "type", FieldDescriptor__type, 0);
rb_define_method(klass, "default", FieldDescriptor_default, 0);
rb_define_method(klass, "json_name", FieldDescriptor_json_name, 0);
rb_define_method(klass, "label", FieldDescriptor_label, 0);
rb_define_method(klass, "number", FieldDescriptor_number, 0);
rb_define_method(klass, "submsg_name", FieldDescriptor_submsg_name, 0);
@ -1750,6 +1765,16 @@ static void msgdef_add_field(VALUE msgbuilder_rb, upb_label_t label, VALUE name,
field_proto,
FileBuilderContext_strdup(self->file_builder, default_value));
}
if (rb_funcall(options, rb_intern("key?"), 1,
ID2SYM(rb_intern("json_name"))) == Qtrue) {
VALUE json_name =
rb_hash_lookup(options, ID2SYM(rb_intern("json_name")));
google_protobuf_FieldDescriptorProto_set_json_name(
field_proto,
FileBuilderContext_strdup(self->file_builder, json_name));
}
}
if (oneof_index >= 0) {
@ -1899,18 +1924,20 @@ static VALUE MessageBuilderContext_required(int argc, VALUE* argv,
*/
static VALUE MessageBuilderContext_repeated(int argc, VALUE* argv,
VALUE _self) {
VALUE name, type, number, type_class;
VALUE name, type, number;
VALUE type_class, options = Qnil;
if (argc < 3) {
rb_raise(rb_eArgError, "Expected at least 3 arguments.");
rb_scan_args(argc, argv, "32", &name, &type, &number, &type_class, &options);
// Allow passing (name, type, number, options) or
// (name, type, number, type_class, options)
if (argc == 4 && RB_TYPE_P(type_class, T_HASH)) {
options = type_class;
type_class = Qnil;
}
name = argv[0];
type = argv[1];
number = argv[2];
type_class = (argc > 3) ? argv[3] : Qnil;
msgdef_add_field(_self, UPB_LABEL_REPEATED, name, type, number, type_class,
Qnil, -1, false);
options, -1, false);
return Qnil;
}

@ -95,4 +95,10 @@ class EncodeDecodeTest < Test::Unit::TestCase
end
end
def test_json_name
msg = A::B::C::TestJsonName.new(:value => 42)
json = msg.to_json
assert_match json, "{\"CustomJsonName\":42}"
end
end

@ -83,3 +83,7 @@ message TestUnknown {
map<string, TestUnknown> map_unknown = 67;
int32 unknown_field = 89;
}
message TestJsonName {
int32 value = 1 [json_name = "CustomJsonName"];
}

@ -18,7 +18,7 @@ else
PTHREAD_DEF =
endif
PROTOBUF_VERSION = 26:6:0
PROTOBUF_VERSION = 26:8:0
if GCC
# Turn on all warnings except for sign comparison (we ignore sign comparison

@ -110,12 +110,12 @@ Any::Any(const Any& from)
type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_type_url().empty()) {
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_type_url(),
GetArena());
GetArenaForAllocation());
}
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_value().empty()) {
value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_value(),
GetArena());
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
}
@ -132,7 +132,7 @@ Any::~Any() {
}
void Any::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
type_url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
@ -211,7 +211,7 @@ failure:
(void) cached_has_bits;
// string type_url = 1;
if (this->type_url().size() > 0) {
if (!this->type_url().empty()) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(
this->_internal_type_url().data(), static_cast<int>(this->_internal_type_url().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,
@ -221,7 +221,7 @@ failure:
}
// bytes value = 2;
if (this->value().size() > 0) {
if (!this->value().empty()) {
target = stream->WriteBytesMaybeAliased(
2, this->_internal_value(), target);
}
@ -243,14 +243,14 @@ size_t Any::ByteSizeLong() const {
(void) cached_has_bits;
// string type_url = 1;
if (this->type_url().size() > 0) {
if (!this->type_url().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_type_url());
}
// bytes value = 2;
if (this->value().size() > 0) {
if (!this->value().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize(
this->_internal_value());
@ -287,10 +287,10 @@ void Any::MergeFrom(const Any& from) {
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from.type_url().size() > 0) {
if (!from.type_url().empty()) {
_internal_set_type_url(from._internal_type_url());
}
if (from.value().size() > 0) {
if (!from.value().empty()) {
_internal_set_value(from._internal_value());
}
}
@ -316,8 +316,16 @@ bool Any::IsInitialized() const {
void Any::InternalSwap(Any* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
type_url_.Swap(&other->type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
value_.Swap(&other->value_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&type_url_, GetArenaForAllocation(),
&other->type_url_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&value_, GetArenaForAllocation(),
&other->value_, other->GetArenaForAllocation()
);
}
::PROTOBUF_NAMESPACE_ID::Metadata Any::GetMetadata() const {

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3015006 < PROTOBUF_MIN_PROTOC_VERSION
#if 3015008 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
@ -65,7 +65,7 @@ PROTOBUF_NAMESPACE_OPEN
// ===================================================================
class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
class PROTOBUF_EXPORT Any final :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ {
public:
inline Any() : Any(nullptr) {}
@ -83,8 +83,9 @@ class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
return *this;
}
inline Any& operator=(Any&& from) noexcept {
if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from);
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()) {
InternalSwap(&from);
} else {
CopyFrom(from);
}
@ -148,7 +149,7 @@ class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
}
inline void Swap(Any* other) {
if (other == this) return;
if (GetArena() == other->GetArena()) {
if (GetOwningArena() == other->GetOwningArena()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -156,14 +157,14 @@ class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
}
void UnsafeArenaSwap(Any* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArena() == other->GetArena());
GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena());
InternalSwap(other);
}
// implements Message ----------------------------------------------
inline Any* New() const final {
return CreateMaybeMessage<Any>(nullptr);
return new Any();
}
Any* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
@ -214,11 +215,11 @@ class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_type_url(ArgT0&& arg0, ArgT... args);
std::string* mutable_type_url();
std::string* release_type_url();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_type_url();
void set_allocated_type_url(std::string* type_url);
private:
const std::string& _internal_type_url() const;
void _internal_set_type_url(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_type_url(const std::string& value);
std::string* _internal_mutable_type_url();
public:
@ -228,11 +229,11 @@ class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_value(ArgT0&& arg0, ArgT... args);
std::string* mutable_value();
std::string* release_value();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_value();
void set_allocated_value(std::string* value);
private:
const std::string& _internal_value() const;
void _internal_set_value(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_value(const std::string& value);
std::string* _internal_mutable_value();
public:
@ -269,10 +270,10 @@ inline const std::string& Any::type_url() const {
return _internal_type_url();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Any::set_type_url(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Any.type_url)
}
inline std::string* Any::mutable_type_url() {
@ -284,15 +285,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, GetArena());
type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Any::_internal_mutable_type_url() {
return type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, 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(), GetArena());
return type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Any::set_allocated_type_url(std::string* type_url) {
if (type_url != nullptr) {
@ -301,7 +302,7 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
}
type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
}
@ -314,10 +315,10 @@ inline const std::string& Any::value() const {
return _internal_value();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Any::set_value(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
value_.SetBytes(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Any.value)
}
inline std::string* Any::mutable_value() {
@ -329,15 +330,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, GetArena());
value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Any::_internal_mutable_value() {
return value_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return value_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
}
inline std::string* Any::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.value)
return value_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
return value_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Any::set_allocated_value(std::string* value) {
if (value != nullptr) {
@ -346,7 +347,7 @@ inline void Any::set_allocated_value(std::string* value) {
}
value_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)
}

@ -173,7 +173,7 @@ void Api::clear_options() {
options_.Clear();
}
void Api::clear_source_context() {
if (GetArena() == nullptr && source_context_ != nullptr) {
if (GetArenaForAllocation() == nullptr && source_context_ != nullptr) {
delete source_context_;
}
source_context_ = nullptr;
@ -196,12 +196,12 @@ Api::Api(const Api& from)
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
GetArena());
GetArenaForAllocation());
}
version_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_version().empty()) {
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_version(),
GetArena());
GetArenaForAllocation());
}
if (from._internal_has_source_context()) {
source_context_ = new PROTOBUF_NAMESPACE_ID::SourceContext(*from.source_context_);
@ -228,7 +228,7 @@ Api::~Api() {
}
void Api::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
version_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (this != internal_default_instance()) delete source_context_;
@ -255,7 +255,7 @@ void Api::Clear() {
mixins_.Clear();
name_.ClearToEmpty();
version_.ClearToEmpty();
if (GetArena() == nullptr && source_context_ != nullptr) {
if (GetArenaForAllocation() == nullptr && source_context_ != nullptr) {
delete source_context_;
}
source_context_ = nullptr;
@ -368,7 +368,7 @@ failure:
(void) cached_has_bits;
// string name = 1;
if (this->name().size() > 0) {
if (!this->name().empty()) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(
this->_internal_name().data(), static_cast<int>(this->_internal_name().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,
@ -394,7 +394,7 @@ failure:
}
// string version = 4;
if (this->version().size() > 0) {
if (!this->version().empty()) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(
this->_internal_version().data(), static_cast<int>(this->_internal_version().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,
@ -464,14 +464,14 @@ size_t Api::ByteSizeLong() const {
}
// string name = 1;
if (this->name().size() > 0) {
if (!this->name().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_name());
}
// string version = 4;
if (this->version().size() > 0) {
if (!this->version().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_version());
@ -524,10 +524,10 @@ void Api::MergeFrom(const Api& from) {
methods_.MergeFrom(from.methods_);
options_.MergeFrom(from.options_);
mixins_.MergeFrom(from.mixins_);
if (from.name().size() > 0) {
if (!from.name().empty()) {
_internal_set_name(from._internal_name());
}
if (from.version().size() > 0) {
if (!from.version().empty()) {
_internal_set_version(from._internal_version());
}
if (from.has_source_context()) {
@ -562,8 +562,16 @@ void Api::InternalSwap(Api* other) {
methods_.InternalSwap(&other->methods_);
options_.InternalSwap(&other->options_);
mixins_.InternalSwap(&other->mixins_);
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
version_.Swap(&other->version_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, GetArenaForAllocation(),
&other->name_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&version_, GetArenaForAllocation(),
&other->version_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(Api, syntax_)
+ sizeof(Api::syntax_)
@ -601,17 +609,17 @@ Method::Method(const Method& from)
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
GetArena());
GetArenaForAllocation());
}
request_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_request_type_url().empty()) {
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_request_type_url(),
GetArena());
GetArenaForAllocation());
}
response_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_response_type_url().empty()) {
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_response_type_url(),
GetArena());
GetArenaForAllocation());
}
::memcpy(&request_streaming_, &from.request_streaming_,
static_cast<size_t>(reinterpret_cast<char*>(&syntax_) -
@ -636,7 +644,7 @@ Method::~Method() {
}
void Method::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
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());
@ -765,7 +773,7 @@ failure:
(void) cached_has_bits;
// string name = 1;
if (this->name().size() > 0) {
if (!this->name().empty()) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(
this->_internal_name().data(), static_cast<int>(this->_internal_name().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,
@ -775,7 +783,7 @@ failure:
}
// string request_type_url = 2;
if (this->request_type_url().size() > 0) {
if (!this->request_type_url().empty()) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(
this->_internal_request_type_url().data(), static_cast<int>(this->_internal_request_type_url().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,
@ -791,7 +799,7 @@ failure:
}
// string response_type_url = 4;
if (this->response_type_url().size() > 0) {
if (!this->response_type_url().empty()) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(
this->_internal_response_type_url().data(), static_cast<int>(this->_internal_response_type_url().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,
@ -845,21 +853,21 @@ size_t Method::ByteSizeLong() const {
}
// string name = 1;
if (this->name().size() > 0) {
if (!this->name().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_name());
}
// string request_type_url = 2;
if (this->request_type_url().size() > 0) {
if (!this->request_type_url().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_request_type_url());
}
// string response_type_url = 4;
if (this->response_type_url().size() > 0) {
if (!this->response_type_url().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_response_type_url());
@ -913,13 +921,13 @@ void Method::MergeFrom(const Method& from) {
(void) cached_has_bits;
options_.MergeFrom(from.options_);
if (from.name().size() > 0) {
if (!from.name().empty()) {
_internal_set_name(from._internal_name());
}
if (from.request_type_url().size() > 0) {
if (!from.request_type_url().empty()) {
_internal_set_request_type_url(from._internal_request_type_url());
}
if (from.response_type_url().size() > 0) {
if (!from.response_type_url().empty()) {
_internal_set_response_type_url(from._internal_response_type_url());
}
if (from.request_streaming() != 0) {
@ -955,9 +963,21 @@ void Method::InternalSwap(Method* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
options_.InternalSwap(&other->options_);
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
request_type_url_.Swap(&other->request_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
response_type_url_.Swap(&other->response_type_url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, GetArenaForAllocation(),
&other->name_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&request_type_url_, GetArenaForAllocation(),
&other->request_type_url_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&response_type_url_, GetArenaForAllocation(),
&other->response_type_url_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(Method, syntax_)
+ sizeof(Method::syntax_)
@ -990,12 +1010,12 @@ Mixin::Mixin(const Mixin& from)
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_name().empty()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
GetArena());
GetArenaForAllocation());
}
root_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (!from._internal_root().empty()) {
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_root(),
GetArena());
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin)
}
@ -1012,7 +1032,7 @@ Mixin::~Mixin() {
}
void Mixin::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
root_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
@ -1092,7 +1112,7 @@ failure:
(void) cached_has_bits;
// string name = 1;
if (this->name().size() > 0) {
if (!this->name().empty()) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(
this->_internal_name().data(), static_cast<int>(this->_internal_name().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,
@ -1102,7 +1122,7 @@ failure:
}
// string root = 2;
if (this->root().size() > 0) {
if (!this->root().empty()) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(
this->_internal_root().data(), static_cast<int>(this->_internal_root().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,
@ -1128,14 +1148,14 @@ size_t Mixin::ByteSizeLong() const {
(void) cached_has_bits;
// string name = 1;
if (this->name().size() > 0) {
if (!this->name().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_name());
}
// string root = 2;
if (this->root().size() > 0) {
if (!this->root().empty()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_root());
@ -1172,10 +1192,10 @@ void Mixin::MergeFrom(const Mixin& from) {
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from.name().size() > 0) {
if (!from.name().empty()) {
_internal_set_name(from._internal_name());
}
if (from.root().size() > 0) {
if (!from.root().empty()) {
_internal_set_root(from._internal_root());
}
}
@ -1201,8 +1221,16 @@ bool Mixin::IsInitialized() const {
void Mixin::InternalSwap(Mixin* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
root_.Swap(&other->root_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, GetArenaForAllocation(),
&other->name_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&root_, GetArenaForAllocation(),
&other->root_, other->GetArenaForAllocation()
);
}
::PROTOBUF_NAMESPACE_ID::Metadata Mixin::GetMetadata() const {

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3015006 < PROTOBUF_MIN_PROTOC_VERSION
#if 3015008 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
@ -75,7 +75,7 @@ PROTOBUF_NAMESPACE_OPEN
// ===================================================================
class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
class PROTOBUF_EXPORT Api final :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ {
public:
inline Api() : Api(nullptr) {}
@ -93,8 +93,9 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
return *this;
}
inline Api& operator=(Api&& from) noexcept {
if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from);
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()) {
InternalSwap(&from);
} else {
CopyFrom(from);
}
@ -125,7 +126,7 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
}
inline void Swap(Api* other) {
if (other == this) return;
if (GetArena() == other->GetArena()) {
if (GetOwningArena() == other->GetOwningArena()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -133,14 +134,14 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
}
void UnsafeArenaSwap(Api* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArena() == other->GetArena());
GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena());
InternalSwap(other);
}
// implements Message ----------------------------------------------
inline Api* New() const final {
return CreateMaybeMessage<Api>(nullptr);
return new Api();
}
Api* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
@ -250,11 +251,11 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_name(ArgT0&& arg0, ArgT... args);
std::string* mutable_name();
std::string* release_name();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_name();
void set_allocated_name(std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_name(const std::string& value);
std::string* _internal_mutable_name();
public:
@ -264,11 +265,11 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_version(ArgT0&& arg0, ArgT... args);
std::string* mutable_version();
std::string* release_version();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_version();
void set_allocated_version(std::string* version);
private:
const std::string& _internal_version() const;
void _internal_set_version(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_version(const std::string& value);
std::string* _internal_mutable_version();
public:
@ -318,7 +319,7 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
};
// -------------------------------------------------------------------
class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
class PROTOBUF_EXPORT Method final :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ {
public:
inline Method() : Method(nullptr) {}
@ -336,8 +337,9 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
return *this;
}
inline Method& operator=(Method&& from) noexcept {
if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from);
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()) {
InternalSwap(&from);
} else {
CopyFrom(from);
}
@ -368,7 +370,7 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
}
inline void Swap(Method* other) {
if (other == this) return;
if (GetArena() == other->GetArena()) {
if (GetOwningArena() == other->GetOwningArena()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -376,14 +378,14 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
}
void UnsafeArenaSwap(Method* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArena() == other->GetArena());
GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena());
InternalSwap(other);
}
// implements Message ----------------------------------------------
inline Method* New() const final {
return CreateMaybeMessage<Method>(nullptr);
return new Method();
}
Method* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
@ -457,11 +459,11 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_name(ArgT0&& arg0, ArgT... args);
std::string* mutable_name();
std::string* release_name();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_name();
void set_allocated_name(std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_name(const std::string& value);
std::string* _internal_mutable_name();
public:
@ -471,11 +473,11 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_request_type_url(ArgT0&& arg0, ArgT... args);
std::string* mutable_request_type_url();
std::string* release_request_type_url();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_request_type_url();
void set_allocated_request_type_url(std::string* request_type_url);
private:
const std::string& _internal_request_type_url() const;
void _internal_set_request_type_url(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_request_type_url(const std::string& value);
std::string* _internal_mutable_request_type_url();
public:
@ -485,11 +487,11 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_response_type_url(ArgT0&& arg0, ArgT... args);
std::string* mutable_response_type_url();
std::string* release_response_type_url();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_response_type_url();
void set_allocated_response_type_url(std::string* response_type_url);
private:
const std::string& _internal_response_type_url() const;
void _internal_set_response_type_url(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_response_type_url(const std::string& value);
std::string* _internal_mutable_response_type_url();
public:
@ -539,7 +541,7 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
};
// -------------------------------------------------------------------
class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
class PROTOBUF_EXPORT Mixin final :
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ {
public:
inline Mixin() : Mixin(nullptr) {}
@ -557,8 +559,9 @@ class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
return *this;
}
inline Mixin& operator=(Mixin&& from) noexcept {
if (GetArena() == from.GetArena()) {
if (this != &from) InternalSwap(&from);
if (this == &from) return *this;
if (GetOwningArena() == from.GetOwningArena()) {
InternalSwap(&from);
} else {
CopyFrom(from);
}
@ -589,7 +592,7 @@ class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
}
inline void Swap(Mixin* other) {
if (other == this) return;
if (GetArena() == other->GetArena()) {
if (GetOwningArena() == other->GetOwningArena()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -597,14 +600,14 @@ class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
}
void UnsafeArenaSwap(Mixin* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArena() == other->GetArena());
GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena());
InternalSwap(other);
}
// implements Message ----------------------------------------------
inline Mixin* New() const final {
return CreateMaybeMessage<Mixin>(nullptr);
return new Mixin();
}
Mixin* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
@ -655,11 +658,11 @@ class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_name(ArgT0&& arg0, ArgT... args);
std::string* mutable_name();
std::string* release_name();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_name();
void set_allocated_name(std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_name(const std::string& value);
std::string* _internal_mutable_name();
public:
@ -669,11 +672,11 @@ class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
template <typename ArgT0 = const std::string&, typename... ArgT>
void set_root(ArgT0&& arg0, ArgT... args);
std::string* mutable_root();
std::string* release_root();
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* release_root();
void set_allocated_root(std::string* root);
private:
const std::string& _internal_root() const;
void _internal_set_root(const std::string& value);
inline PROTOBUF_ALWAYS_INLINE void _internal_set_root(const std::string& value);
std::string* _internal_mutable_root();
public:
@ -709,10 +712,10 @@ inline const std::string& Api::name() const {
return _internal_name();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Api::set_name(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Api.name)
}
inline std::string* Api::mutable_name() {
@ -724,15 +727,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, GetArena());
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Api::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
}
inline std::string* Api::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Api::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -741,7 +744,7 @@ inline void Api::set_allocated_name(std::string* name) {
}
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name)
}
@ -829,10 +832,10 @@ inline const std::string& Api::version() const {
return _internal_version();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Api::set_version(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Api.version)
}
inline std::string* Api::mutable_version() {
@ -844,15 +847,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, GetArena());
version_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Api::_internal_mutable_version() {
return version_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return version_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
}
inline std::string* Api::release_version() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.version)
return version_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
return version_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Api::set_allocated_version(std::string* version) {
if (version != nullptr) {
@ -861,7 +864,7 @@ inline void Api::set_allocated_version(std::string* version) {
}
version_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), version,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
}
@ -883,7 +886,7 @@ inline const PROTOBUF_NAMESPACE_ID::SourceContext& Api::source_context() const {
}
inline void Api::unsafe_arena_set_allocated_source_context(
PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
if (GetArena() == nullptr) {
if (GetArenaForAllocation() == nullptr) {
delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
}
source_context_ = source_context;
@ -898,7 +901,7 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() {
PROTOBUF_NAMESPACE_ID::SourceContext* temp = source_context_;
source_context_ = nullptr;
if (GetArena() != nullptr) {
if (GetArenaForAllocation() != nullptr) {
temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp);
}
return temp;
@ -913,7 +916,7 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::unsafe_arena_release_source_co
inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::_internal_mutable_source_context() {
if (source_context_ == nullptr) {
auto* p = CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::SourceContext>(GetArena());
auto* p = CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::SourceContext>(GetArenaForAllocation());
source_context_ = p;
}
return source_context_;
@ -923,13 +926,15 @@ inline PROTOBUF_NAMESPACE_ID::SourceContext* Api::mutable_source_context() {
return _internal_mutable_source_context();
}
inline void Api::set_allocated_source_context(PROTOBUF_NAMESPACE_ID::SourceContext* source_context) {
::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArena();
::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaForAllocation();
if (message_arena == nullptr) {
delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context_);
}
if (source_context) {
::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena =
reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context)->GetArena();
::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper<
::PROTOBUF_NAMESPACE_ID::MessageLite>::GetOwningArena(
reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(source_context));
if (message_arena != submessage_arena) {
source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage(
message_arena, source_context, submessage_arena);
@ -1014,10 +1019,10 @@ inline const std::string& Method::name() const {
return _internal_name();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Method::set_name(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Method.name)
}
inline std::string* Method::mutable_name() {
@ -1029,15 +1034,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, GetArena());
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
}
inline std::string* Method::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Method.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Method::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -1046,7 +1051,7 @@ inline void Method::set_allocated_name(std::string* name) {
}
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
}
@ -1059,10 +1064,10 @@ inline const std::string& Method::request_type_url() const {
return _internal_request_type_url();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Method::set_request_type_url(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, 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() {
@ -1074,15 +1079,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, GetArena());
request_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_request_type_url() {
return request_type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return request_type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, 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(), GetArena());
return request_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Method::set_allocated_request_type_url(std::string* request_type_url) {
if (request_type_url != nullptr) {
@ -1091,7 +1096,7 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
}
request_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), request_type_url,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
}
@ -1124,10 +1129,10 @@ inline const std::string& Method::response_type_url() const {
return _internal_response_type_url();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Method::set_response_type_url(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, 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() {
@ -1139,15 +1144,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, GetArena());
response_type_url_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Method::_internal_mutable_response_type_url() {
return response_type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return response_type_url_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, 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(), GetArena());
return response_type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Method::set_allocated_response_type_url(std::string* response_type_url) {
if (response_type_url != nullptr) {
@ -1156,7 +1161,7 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
}
response_type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), response_type_url,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
}
@ -1249,10 +1254,10 @@ inline const std::string& Mixin::name() const {
return _internal_name();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Mixin::set_name(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.name)
}
inline std::string* Mixin::mutable_name() {
@ -1264,15 +1269,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, GetArena());
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Mixin::_internal_mutable_name() {
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
}
inline std::string* Mixin::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.name)
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Mixin::set_allocated_name(std::string* name) {
if (name != nullptr) {
@ -1281,7 +1286,7 @@ inline void Mixin::set_allocated_name(std::string* name) {
}
name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
}
@ -1294,10 +1299,10 @@ inline const std::string& Mixin::root() const {
return _internal_root();
}
template <typename ArgT0, typename... ArgT>
PROTOBUF_ALWAYS_INLINE
inline void Mixin::set_root(ArgT0&& arg0, ArgT... args) {
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..., GetArena());
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.root)
}
inline std::string* Mixin::mutable_root() {
@ -1309,15 +1314,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, GetArena());
root_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* Mixin::_internal_mutable_root() {
return root_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArena());
return root_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
}
inline std::string* Mixin::release_root() {
// @@protoc_insertion_point(field_release:google.protobuf.Mixin.root)
return root_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
return root_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void Mixin::set_allocated_root(std::string* root) {
if (root != nullptr) {
@ -1326,7 +1331,7 @@ inline void Mixin::set_allocated_root(std::string* root) {
}
root_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), root,
GetArena());
GetArenaForAllocation());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)
}

@ -93,8 +93,8 @@ class EpsCopyInputStream; // defined in parse_context.h
template <typename Type>
class GenericTypeHandler; // defined in repeated_field.h
PROTOBUF_ALWAYS_INLINE
inline void* AlignTo(void* ptr, size_t align) {
inline PROTOBUF_ALWAYS_INLINE
void* AlignTo(void* ptr, size_t align) {
return reinterpret_cast<void*>(
(reinterpret_cast<uintptr_t>(ptr) + align - 1) & (~align + 1));
}
@ -399,6 +399,16 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
template <typename T>
class InternalHelper {
public:
// 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 p->GetArenaForAllocation();
}
private:
template <typename U>
static char DestructorSkippable(const typename U::DestructorSkippable_*);
template <typename U>
@ -439,6 +449,10 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
return new (ptr) T(std::forward<Args>(args)...);
}
static T* New() {
return new T(nullptr);
}
static Arena* GetArena(const T* p) { return p->GetArena(); }
friend class Arena;
@ -490,7 +504,9 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
InternalHelper<T>::is_arena_constructable::value,
"CreateMessage can only construct types that are ArenaConstructable");
if (arena == NULL) {
return new T();
// Generated arena constructor T(Arena*) is protected. Call via
// InternalHelper.
return InternalHelper<T>::New();
} else {
return arena->DoCreateMessage<T>();
}
@ -678,6 +694,25 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
return nullptr;
}
template <typename T>
PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArena(const T* value) {
return GetOwningArenaInternal(
value, std::is_convertible<T*, MessageLite*>());
}
// Implementation for GetOwningArena(). All and only message objects have
// GetOwningArena() method.
template <typename T>
PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArenaInternal(
const T* value, std::true_type) {
return InternalHelper<T>::GetOwningArena(value);
}
template <typename T>
PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArenaInternal(
const T* value, std::false_type) {
return nullptr;
}
// For friends of arena.
void* AllocateAligned(size_t n, size_t align = 8) {
if (align <= 8) {

@ -223,11 +223,11 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
}
// Basic accessors.
const std::string& Get() const PROTOBUF_NDEBUG_INLINE {
PROTOBUF_NDEBUG_INLINE const std::string& Get() const {
// Unconditionally mask away the tag.
return *tagged_ptr_.Get();
}
const std::string* GetPointer() const PROTOBUF_NDEBUG_INLINE {
PROTOBUF_NDEBUG_INLINE const std::string* GetPointer() const {
// Unconditionally mask away the tag.
return tagged_ptr_.Get();
}
@ -241,10 +241,10 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// Own()'d by any arena. If the field is not set, this returns NULL. The
// caller retains ownership. Clears this field back to NULL state. Used to
// implement release_<field>() methods on generated classes.
std::string* Release(const std::string* default_value,
::google::protobuf::Arena* arena);
std::string* ReleaseNonDefault(const std::string* default_value,
::google::protobuf::Arena* arena);
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* Release(
const std::string* default_value, ::google::protobuf::Arena* arena);
PROTOBUF_FUTURE_MUST_USE_RESULT std::string* ReleaseNonDefault(
const std::string* default_value, ::google::protobuf::Arena* arena);
// Takes a std::string that is heap-allocated, and takes ownership. The
// std::string's destructor is registered with the arena. Used to implement
@ -255,8 +255,9 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// 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 void Swap(ArenaStringPtr* other, const std::string* default_value,
Arena* arena) PROTOBUF_NDEBUG_INLINE;
inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(
const std::string* default_value, ArenaStringPtr* rhs, Arena* rhs_arena,
ArenaStringPtr* lhs, Arena* lhs_arena);
// Frees storage (if not on an arena).
void Destroy(const std::string* default_value, ::google::protobuf::Arena* arena);
@ -340,36 +341,28 @@ inline void ArenaStringPtr::UnsafeSetDefault(const std::string* value) {
tagged_ptr_.Set(const_cast<std::string*>(value));
}
inline void ArenaStringPtr::Swap(ArenaStringPtr* other,
const std::string* default_value,
Arena* arena) {
#ifndef NDEBUG
// For debug builds, we swap the contents of the string, rather than the
// std::string instances themselves. This invalidates previously taken const
// references that are (per our documentation) invalidated by calling Swap()
// on the message.
//
// If both strings are the default_value, swapping is uninteresting.
// Otherwise, we use ArenaStringPtr::Mutable() to access the std::string, to
// ensure that we do not try to mutate default_value itself.
if (IsDefault(default_value) && other->IsDefault(default_value)) {
return;
}
if (default_value == nullptr) {
// If we have non-empty default, then `default_value` is null and we can't
// call Mutable the same way. Just do the regular swap.
std::swap(tagged_ptr_, other->tagged_ptr_);
} else {
std::string* this_ptr = Mutable(EmptyDefault{}, arena);
std::string* other_ptr = other->Mutable(EmptyDefault{}, arena);
this_ptr->swap(*other_ptr);
}
#else
inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap( //
const std::string* default_value, //
ArenaStringPtr* rhs, Arena* rhs_arena, //
ArenaStringPtr* lhs, Arena* lhs_arena) {
(void)default_value;
(void)arena;
std::swap(tagged_ptr_, other->tagged_ptr_);
std::swap(lhs_arena, rhs_arena);
std::swap(lhs->tagged_ptr_, rhs->tagged_ptr_);
#if 0 // TODO(b/186650244): renable this
#ifndef NDEBUG
auto force_realloc = [default_value](ArenaStringPtr* p, Arena* arena) {
if (p->IsDefault(default_value)) return;
std::string* old_value = p->tagged_ptr_.Get();
std::string* new_value =
p->IsDonatedString()
? Arena::Create<std::string>(arena, *old_value)
: Arena::Create<std::string>(arena, std::move(*old_value));
if (arena == nullptr) delete old_value;
p->tagged_ptr_.Set(new_value);
};
force_realloc(lhs, lhs_arena);
force_realloc(rhs, rhs_arena);
#endif
#endif
}

@ -54,121 +54,100 @@ namespace protobuf {
using internal::ArenaStringPtr;
static std::string WrapString(const char* value) { return value; }
using EmptyDefault = ArenaStringPtr::EmptyDefault;
const internal::LazyString nonempty_default{{{"default", 7}}, {nullptr}};
const std::string* empty_default = &internal::GetEmptyString();
class SingleArena : public testing::TestWithParam<bool> {
public:
std::unique_ptr<Arena> GetArena() {
if (this->GetParam()) return nullptr;
return std::unique_ptr<Arena>(new Arena());
}
};
INSTANTIATE_TEST_SUITE_P(ArenaString, SingleArena, testing::Bool());
// Test ArenaStringPtr with arena == NULL.
TEST(ArenaStringPtrTest, ArenaStringPtrOnHeap) {
TEST_P(SingleArena, GetSet) {
auto arena = GetArena();
ArenaStringPtr field;
const std::string* empty_default = &internal::GetEmptyString();
field.UnsafeSetDefault(empty_default);
EXPECT_EQ(std::string(""), field.Get());
field.Set(empty_default, WrapString("Test short"), NULL);
EXPECT_EQ(std::string("Test short"), field.Get());
field.Set(empty_default, WrapString("Test long long long long value"), NULL);
EXPECT_EQ(std::string("Test long long long long value"), field.Get());
field.Set(empty_default, std::string(""), NULL);
field.Destroy(empty_default, NULL);
ArenaStringPtr field2;
field2.UnsafeSetDefault(empty_default);
std::string* mut = field2.Mutable(EmptyDefault{}, NULL);
EXPECT_EQ(mut, field2.Mutable(EmptyDefault{}, NULL));
EXPECT_EQ(mut, &field2.Get());
EXPECT_NE(empty_default, mut);
EXPECT_EQ(std::string(""), *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ(std::string("Test long long long long value"), field2.Get());
field2.Destroy(empty_default, NULL);
ArenaStringPtr field3;
field3.UnsafeSetDefault(nullptr);
mut = field3.Mutable(nonempty_default, NULL);
EXPECT_EQ(mut, field3.Mutable(nonempty_default, NULL));
EXPECT_EQ(mut, &field3.Get());
EXPECT_NE(nullptr, mut);
EXPECT_EQ(std::string("default"), *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ(std::string("Test long long long long value"), field3.Get());
field3.Destroy(nullptr, NULL);
EXPECT_EQ("", field.Get());
field.Set(empty_default, "Test short", arena.get());
EXPECT_EQ("Test short", field.Get());
field.Set(empty_default, "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());
}
TEST(ArenaStringPtrTest, ArenaStringPtrOnArena) {
Arena arena;
TEST_P(SingleArena, MutableAccessor) {
auto arena = GetArena();
ArenaStringPtr field;
const std::string* empty_default = &internal::GetEmptyString();
field.UnsafeSetDefault(empty_default);
EXPECT_EQ(std::string(""), field.Get());
field.Set(empty_default, WrapString("Test short"), &arena);
EXPECT_EQ(std::string("Test short"), field.Get());
field.Set(empty_default, WrapString("Test long long long long value"),
&arena);
EXPECT_EQ(std::string("Test long long long long value"), field.Get());
field.Set(empty_default, std::string(""), &arena);
field.Destroy(empty_default, &arena);
ArenaStringPtr field2;
field2.UnsafeSetDefault(empty_default);
std::string* mut = field2.Mutable(EmptyDefault{}, &arena);
EXPECT_EQ(mut, field2.Mutable(EmptyDefault{}, &arena));
EXPECT_EQ(mut, &field2.Get());
std::string* mut = field.Mutable(EmptyDefault{}, arena.get());
EXPECT_EQ(mut, field.Mutable(EmptyDefault{}, arena.get()));
EXPECT_EQ(mut, &field.Get());
EXPECT_NE(empty_default, mut);
EXPECT_EQ(std::string(""), *mut);
EXPECT_EQ("", *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ(std::string("Test long long long long value"), field2.Get());
field2.Destroy(empty_default, &arena);
ArenaStringPtr field3;
field3.UnsafeSetDefault(nullptr);
mut = field3.Mutable(nonempty_default, &arena);
EXPECT_EQ(mut, field3.Mutable(nonempty_default, &arena));
EXPECT_EQ(mut, &field3.Get());
EXPECT_NE(nullptr, mut);
EXPECT_EQ(std::string("default"), *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ(std::string("Test long long long long value"), field3.Get());
field3.Destroy(nullptr, &arena);
EXPECT_EQ("Test long long long long value", field.Get());
field.Destroy(empty_default, arena.get());
}
TEST(ArenaStringPtrTest, ArenaStringPtrOnArenaNoSSO) {
Arena arena;
TEST_P(SingleArena, NullDefault) {
auto arena = GetArena();
ArenaStringPtr field;
const std::string* empty_default = &internal::GetEmptyString();
field.UnsafeSetDefault(empty_default);
EXPECT_EQ(std::string(""), field.Get());
// Avoid triggering the SSO optimization by setting the string to something
// larger than the internal buffer.
field.Set(empty_default, WrapString("Test long long long long value"),
&arena);
EXPECT_EQ(std::string("Test long long long long value"), field.Get());
field.Set(empty_default, std::string(""), &arena);
field.Destroy(empty_default, &arena);
ArenaStringPtr field2;
field2.UnsafeSetDefault(empty_default);
std::string* mut = field2.Mutable(EmptyDefault{}, &arena);
EXPECT_EQ(mut, field2.Mutable(EmptyDefault{}, &arena));
EXPECT_EQ(mut, &field2.Get());
EXPECT_NE(empty_default, mut);
EXPECT_EQ(std::string(""), *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ(std::string("Test long long long long value"), field2.Get());
field2.Destroy(empty_default, &arena);
ArenaStringPtr field3;
field3.UnsafeSetDefault(nullptr);
mut = field3.Mutable(nonempty_default, &arena);
EXPECT_EQ(mut, field3.Mutable(nonempty_default, &arena));
EXPECT_EQ(mut, &field3.Get());
field.UnsafeSetDefault(nullptr);
std::string* mut = field.Mutable(nonempty_default, arena.get());
EXPECT_EQ(mut, field.Mutable(nonempty_default, arena.get()));
EXPECT_EQ(mut, &field.Get());
EXPECT_NE(nullptr, mut);
EXPECT_EQ(std::string("default"), *mut);
EXPECT_EQ("default", *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
EXPECT_EQ(std::string("Test long long long long value"), field3.Get());
field3.Destroy(nullptr, &arena);
EXPECT_EQ("Test long long long long value", field.Get());
field.Destroy(nullptr, arena.get());
}
class DualArena : public testing::TestWithParam<std::tuple<bool, bool>> {
public:
std::unique_ptr<Arena> GetLhsArena() {
if (std::get<0>(this->GetParam())) return nullptr;
return std::unique_ptr<Arena>(new Arena());
}
std::unique_ptr<Arena> GetRhsArena() {
if (std::get<1>(this->GetParam())) return nullptr;
return std::unique_ptr<Arena>(new Arena());
}
};
INSTANTIATE_TEST_SUITE_P(ArenaString, DualArena,
testing::Combine(testing::Bool(), testing::Bool()));
TEST_P(DualArena, Swap) {
auto lhs_arena = GetLhsArena();
ArenaStringPtr lhs;
lhs.UnsafeSetDefault(empty_default);
ArenaStringPtr rhs;
rhs.UnsafeSetDefault(empty_default);
{
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(), //
&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());
}
EXPECT_EQ("lhs value that has some heft", rhs.Get());
rhs.Destroy(empty_default, lhs_arena.get());
}

@ -108,6 +108,18 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_options.table_driven_parsing = true;
} else if (options[i].first == "table_driven_serialization") {
file_options.table_driven_serialization = true;
} else if (options[i].first == "experimental_tail_call_table_mode") {
if (options[i].second == "never") {
file_options.tctable_mode = Options::kTCTableNever;
} else if (options[i].second == "guarded") {
file_options.tctable_mode = Options::kTCTableGuarded;
} else if (options[i].second == "always") {
file_options.tctable_mode = Options::kTCTableAlways;
} else {
*error = "Unknown value for experimental_tail_call_table_mode: " +
options[i].second;
return false;
}
} else {
*error = "Unknown generator option: " + options[i].first;
return false;

@ -648,25 +648,25 @@ std::string Int32ToString(int number) {
}
}
std::string Int64ToString(const std::string& macro_prefix, int64_t number) {
static std::string Int64ToString(int64_t number) {
if (number == std::numeric_limits<int64_t>::min()) {
// This needs to be special-cased, see explanation here:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661
return StrCat(macro_prefix, "_LONGLONG(", number + 1, ") - 1");
return StrCat("int64_t{", number + 1, "} - 1");
}
return StrCat(macro_prefix, "_LONGLONG(", number, ")");
return StrCat("int64_t{", number, "}");
}
std::string UInt64ToString(const std::string& macro_prefix, uint64_t number) {
return StrCat(macro_prefix, "_ULONGLONG(", number, ")");
static std::string UInt64ToString(uint64_t number) {
return StrCat("uint64_t{", number, "u}");
}
std::string DefaultValue(const FieldDescriptor* field) {
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT64:
return Int64ToString("GG", field->default_value_int64());
return Int64ToString(field->default_value_int64());
case FieldDescriptor::CPPTYPE_UINT64:
return UInt64ToString("GG", field->default_value_uint64());
return UInt64ToString(field->default_value_uint64());
default:
return DefaultValue(Options(), field);
}
@ -679,9 +679,9 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) {
case FieldDescriptor::CPPTYPE_UINT32:
return StrCat(field->default_value_uint32()) + "u";
case FieldDescriptor::CPPTYPE_INT64:
return Int64ToString("PROTOBUF", field->default_value_int64());
return Int64ToString(field->default_value_int64());
case FieldDescriptor::CPPTYPE_UINT64:
return UInt64ToString("PROTOBUF", field->default_value_uint64());
return UInt64ToString(field->default_value_uint64());
case FieldDescriptor::CPPTYPE_DOUBLE: {
double value = field->default_value_double();
if (value == std::numeric_limits<double>::infinity()) {
@ -1022,13 +1022,13 @@ Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field,
const Options& options) {
if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 &&
FieldEnforceUtf8(field, options)) {
return STRICT;
return Utf8CheckMode::kStrict;
} else if (GetOptimizeFor(field->file(), options) !=
FileOptions::LITE_RUNTIME &&
FileUtf8Verification(field->file(), options)) {
return VERIFY;
return Utf8CheckMode::kVerify;
} else {
return NONE;
return Utf8CheckMode::kNone;
}
}
@ -1039,7 +1039,7 @@ static void GenerateUtf8CheckCode(const FieldDescriptor* field,
const char* verify_function,
const Formatter& format) {
switch (GetUtf8CheckMode(field, options)) {
case STRICT: {
case Utf8CheckMode::kStrict: {
if (for_parse) {
format("DO_(");
}
@ -1059,7 +1059,7 @@ static void GenerateUtf8CheckCode(const FieldDescriptor* field,
format.Outdent();
break;
}
case VERIFY: {
case Utf8CheckMode::kVerify: {
format("::$proto_ns$::internal::WireFormat::$1$(\n", verify_function);
format.Indent();
format(parameters);
@ -1072,7 +1072,7 @@ static void GenerateUtf8CheckCode(const FieldDescriptor* field,
format.Outdent();
break;
}
case NONE:
case Utf8CheckMode::kNone:
break;
}
}

@ -220,9 +220,6 @@ const char* DeclaredTypeMethodName(FieldDescriptor::Type type);
// Return the code that evaluates to the number when compiled.
std::string Int32ToString(int number);
// Return the code that evaluates to the number when compiled.
std::string Int64ToString(const Options& options, int64_t number);
// Get code that evaluates to the field's default value.
std::string DefaultValue(const Options& options, const FieldDescriptor* field);
@ -774,10 +771,10 @@ class PROTOC_EXPORT NamespaceOpener {
std::vector<std::string> name_stack_;
};
enum Utf8CheckMode {
STRICT = 0, // Parsing will fail if non UTF-8 data is in string fields.
VERIFY = 1, // Only log an error but parsing will succeed.
NONE = 2, // No UTF-8 check.
enum class Utf8CheckMode {
kStrict = 0, // Parsing will fail if non UTF-8 data is in string fields.
kVerify = 1, // Only log an error but parsing will succeed.
kNone = 2, // No UTF-8 check.
};
Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field,

@ -229,7 +229,10 @@ void MapFieldGenerator::GenerateSerializeWithCachedSizesToArray(
if (utf8_check) {
format(
"struct Utf8Check {\n"
" static void Check(ConstPtr p) {\n");
" static void Check(ConstPtr p) {\n"
// p may be unused when GetUtf8CheckMode evaluates to kNone,
// thus disabling the validation.
" (void)p;\n");
format.Indent();
format.Indent();
if (string_key) {
@ -300,6 +303,19 @@ void MapFieldGenerator::GenerateConstinitInitializer(
}
}
bool MapFieldGenerator::GenerateArenaDestructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (HasDescriptorMethods(descriptor_->file(), options_)) {
// _this is the object being destructed (we are inside a static method
// here).
format("_this->$name$_. ~MapField();\n");
return true;
} else {
return false;
}
}
} // namespace cpp
} // namespace compiler
} // namespace protobuf

@ -58,6 +58,7 @@ class MapFieldGenerator : public FieldGenerator {
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const;
void GenerateByteSize(io::Printer* printer) const;
void GenerateConstinitInitializer(io::Printer* printer) const;
bool GenerateArenaDestructorCode(io::Printer* printer) const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator);

@ -215,7 +215,7 @@ bool EmitFieldNonDefaultCondition(io::Printer* printer,
// if non-zero (numeric) or non-empty (string).
if (!field->is_repeated() && !field->containing_oneof()) {
if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) {
format("if ($prefix$$name$().size() > 0) {\n");
format("if (!$prefix$$name$().empty()) {\n");
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// Message fields still have has_$name$() methods.
format("if ($prefix$has_$name$()) {\n");
@ -571,6 +571,7 @@ MessageGenerator::MessageGenerator(
variables_["classtype"] = QualifiedClassName(descriptor_, options);
variables_["full_name"] = descriptor_->full_name();
variables_["superclass"] = SuperClassName(descriptor_, options_);
SetUnknkownFieldsVariable(descriptor_, options_, &variables_);
// Compute optimized field order to be used for layout and initialization
// purposes.
@ -610,6 +611,8 @@ MessageGenerator::MessageGenerator(
}
table_driven_ = TableDrivenParsingEnabled(descriptor_, options_);
parse_function_generator_.reset(new ParseFunctionGenerator(
descriptor_, max_has_bit_index_, options_, scc_analyzer_));
}
MessageGenerator::~MessageGenerator() = default;
@ -986,9 +989,8 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) {
void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
Formatter format(printer, variables_);
format.Set("class_final", ShouldMarkClassAsFinal(descriptor_, options_)
? "PROTOBUF_FINAL"
: "");
format.Set("class_final",
ShouldMarkClassAsFinal(descriptor_, options_) ? "final" : "");
if (IsMapEntryMessage(descriptor_)) {
std::map<std::string, std::string> vars;
@ -1018,8 +1020,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"$classname$*>(&_$classname$_default_instance_); }\n");
auto utf8_check = GetUtf8CheckMode(descriptor_->field(0), options_);
if (descriptor_->field(0)->type() == FieldDescriptor::TYPE_STRING &&
utf8_check != NONE) {
if (utf8_check == STRICT) {
utf8_check != Utf8CheckMode::kNone) {
if (utf8_check == Utf8CheckMode::kStrict) {
format(
" static bool ValidateKey(std::string* s) {\n"
" return ::$proto_ns$::internal::WireFormatLite::"
@ -1028,7 +1030,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
" }\n",
descriptor_->field(0)->full_name());
} else {
GOOGLE_CHECK_EQ(utf8_check, VERIFY);
GOOGLE_CHECK(utf8_check == Utf8CheckMode::kVerify);
format(
" static bool ValidateKey(std::string* s) {\n"
"#ifndef NDEBUG\n"
@ -1047,8 +1049,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
format(" static bool ValidateKey(void*) { return true; }\n");
}
if (descriptor_->field(1)->type() == FieldDescriptor::TYPE_STRING &&
utf8_check != NONE) {
if (utf8_check == STRICT) {
utf8_check != Utf8CheckMode::kNone) {
if (utf8_check == Utf8CheckMode::kStrict) {
format(
" static bool ValidateValue(std::string* s) {\n"
" return ::$proto_ns$::internal::WireFormatLite::"
@ -1057,7 +1059,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
" }\n",
descriptor_->field(1)->full_name());
} else {
GOOGLE_CHECK_EQ(utf8_check, VERIFY);
GOOGLE_CHECK(utf8_check == Utf8CheckMode::kVerify);
format(
" static bool ValidateValue(std::string* s) {\n"
"#ifndef NDEBUG\n"
@ -1109,8 +1111,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
" return *this;\n"
"}\n"
"inline $classname$& operator=($classname$&& from) noexcept {\n"
" if (GetArena() == from.GetArena()) {\n"
" if (this != &from) InternalSwap(&from);\n"
" if (this == &from) return *this;\n"
" if (GetOwningArena() == from.GetOwningArena()) {\n"
" InternalSwap(&from);\n"
" } else {\n"
" CopyFrom(from);\n"
" }\n"
@ -1126,9 +1129,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"\n");
}
std::map<std::string, std::string> vars;
SetUnknkownFieldsVariable(descriptor_, options_, &vars);
format.AddMap(vars);
if (PublicUnknownFieldsAccessors(descriptor_)) {
format(
"inline const $unknown_fields_type$& unknown_fields() const {\n"
@ -1274,7 +1274,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"}\n"
"inline void Swap($classname$* other) {\n"
" if (other == this) return;\n"
" if (GetArena() == other->GetArena()) {\n"
" if (GetOwningArena() == other->GetOwningArena()) {\n"
" InternalSwap(other);\n"
" } else {\n"
" ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);\n"
@ -1282,7 +1282,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"}\n"
"void UnsafeArenaSwap($classname$* other) {\n"
" if (other == this) return;\n"
" $DCHK$(GetArena() == other->GetArena());\n"
" $DCHK$(GetOwningArena() == other->GetOwningArena());\n"
" InternalSwap(other);\n"
"}\n");
@ -1291,7 +1291,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"// implements Message ----------------------------------------------\n"
"\n"
"inline $classname$* New() const final {\n"
" return CreateMaybeMessage<$classname$>(nullptr);\n"
" return new $classname$();\n"
"}\n"
"\n"
"$classname$* New(::$proto_ns$::Arena* arena) const final {\n"
@ -1324,9 +1324,11 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear()$ clear_final$;\n"
"bool IsInitialized() const final;\n"
"\n"
"size_t ByteSizeLong() const final;\n"
"const char* _InternalParse(const char* ptr, "
"::$proto_ns$::internal::ParseContext* ctx) final;\n"
"size_t ByteSizeLong() const final;\n");
parse_function_generator_->GenerateMethodDecls(printer);
format(
"$uint8$* _InternalSerialize(\n"
" $uint8$* target, ::$proto_ns$::io::EpsCopyOutputStream* stream) "
"const final;\n");
@ -1982,7 +1984,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) {
GenerateClear(printer);
format("\n");
GenerateMergeFromCodedStream(printer);
parse_function_generator_->GenerateMethodImpls(printer);
format("\n");
GenerateSerializeWithCachedSizesToArray(printer);
@ -2317,7 +2319,7 @@ void MessageGenerator::GenerateSharedDestructorCode(io::Printer* printer) {
format("void $classname$::SharedDtor() {\n");
format.Indent();
format("$DCHK$(GetArena() == nullptr);\n");
format("$DCHK$(GetArenaForAllocation() == nullptr);\n");
// Write the destructors for each field except oneof members.
// optimized_order_ does not contain oneof fields.
for (auto field : optimized_order_) {
@ -3240,24 +3242,6 @@ void MessageGenerator::GenerateCopyFrom(io::Printer* printer) {
format("}\n");
}
void MessageGenerator::GenerateMergeFromCodedStream(io::Printer* printer) {
std::map<std::string, std::string> vars = variables_;
SetUnknkownFieldsVariable(descriptor_, options_, &vars);
Formatter format(printer, vars);
if (descriptor_->options().message_set_wire_format()) {
// Special-case MessageSet.
format(
"const char* $classname$::_InternalParse(const char* ptr,\n"
" ::$proto_ns$::internal::ParseContext* ctx) {\n"
" return _extensions_.ParseMessageSet(ptr, \n"
" internal_default_instance(), &_internal_metadata_, ctx);\n"
"}\n");
return;
}
GenerateParseFunction(descriptor_, max_has_bit_index_, options_,
scc_analyzer_, printer);
}
void MessageGenerator::GenerateSerializeOneofFields(
io::Printer* printer, const std::vector<const FieldDescriptor*>& fields) {
Formatter format(printer, variables_);

@ -44,6 +44,7 @@
#include <google/protobuf/compiler/cpp/cpp_helpers.h>
#include <google/protobuf/compiler/cpp/cpp_message_layout_helper.h>
#include <google/protobuf/compiler/cpp/cpp_options.h>
#include <google/protobuf/compiler/cpp/cpp_parse_function_generator.h>
namespace google {
namespace protobuf {
@ -133,7 +134,6 @@ class MessageGenerator {
// Generate standard Message methods.
void GenerateClear(io::Printer* printer);
void GenerateOneofClear(io::Printer* printer);
void GenerateMergeFromCodedStream(io::Printer* printer);
void GenerateSerializeWithCachedSizes(io::Printer* printer);
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer);
void GenerateSerializeWithCachedSizesBody(io::Printer* printer);
@ -204,6 +204,7 @@ class MessageGenerator {
bool table_driven_;
std::unique_ptr<MessageLayoutHelper> message_layout_helper_;
std::unique_ptr<ParseFunctionGenerator> parse_function_generator_;
MessageSCCAnalyzer* scc_analyzer_;

@ -109,7 +109,8 @@ void MessageFieldGenerator::GenerateAccessorDeclarations(
format(
"$deprecated_attr$const $type$& ${1$$name$$}$() const { "
"__builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$$release_name$$}$() { "
"PROTOBUF_FUTURE_MUST_USE_RESULT $deprecated_attr$$type$* "
"${1$$release_name$$}$() { "
"__builtin_trap(); }\n"
"$deprecated_attr$$type$* ${1$mutable_$name$$}$() { "
"__builtin_trap(); }\n"
@ -173,7 +174,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_accessor$"
// 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 (GetArena() == nullptr) {\n"
" if (GetArenaForAllocation() == nullptr) {\n"
" delete reinterpret_cast<::$proto_ns$::MessageLite*>($name$_);\n"
" }\n");
if (implicit_weak_field_) {
@ -198,7 +199,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
" $clear_hasbit$\n"
" $type$* temp = $casted_member$;\n"
" $name$_ = nullptr;\n"
" if (GetArena() != nullptr) {\n"
" if (GetArenaForAllocation() != nullptr) {\n"
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
" }\n"
" return temp;\n"
@ -218,7 +219,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
"$type_reference_function$"
" $set_hasbit$\n"
" if ($name$_ == nullptr) {\n"
" auto* p = CreateMaybeMessage<$type$>(GetArena());\n");
" auto* p = CreateMaybeMessage<$type$>(GetArenaForAllocation());\n");
if (implicit_weak_field_) {
format(" $name$_ = reinterpret_cast<::$proto_ns$::MessageLite*>(p);\n");
} else {
@ -239,7 +240,7 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
format(
"inline void $classname$::set_allocated_$name$($type$* $name$) {\n"
"$annotate_accessor$"
" ::$proto_ns$::Arena* message_arena = GetArena();\n");
" ::$proto_ns$::Arena* message_arena = GetArenaForAllocation();\n");
format(" if (message_arena == nullptr) {\n");
if (IsCrossFileMessage(descriptor_)) {
format(
@ -255,12 +256,15 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions(
// isn't defined in this file.
format(
" ::$proto_ns$::Arena* submessage_arena =\n"
" "
"reinterpret_cast<::$proto_ns$::MessageLite*>($name$)->GetArena();\n");
" ::$proto_ns$::Arena::InternalHelper<\n"
" ::$proto_ns$::MessageLite>::GetOwningArena(\n"
" reinterpret_cast<::$proto_ns$::MessageLite*>("
"$name$));\n");
} else {
format(
" ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::GetArena($name$);\n");
" ::$proto_ns$::Arena::InternalHelper<$type$>::GetOwningArena("
"$name$);\n");
}
format(
" if (message_arena != submessage_arena) {\n"
@ -329,11 +333,12 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions(
" if ($type_default_instance_ptr$ == nullptr) {\n"
" msg->$name$_ = ::$proto_ns$::Arena::CreateMessage<\n"
" ::$proto_ns$::internal::ImplicitWeakMessage>(\n"
" msg->GetArena());\n"
" msg->GetArenaForAllocation());\n"
" } else {\n"
" msg->$name$_ = reinterpret_cast<const "
"::$proto_ns$::MessageLite*>(\n"
" $type_default_instance_ptr$)->New(msg->GetArena());\n"
" msg->$name$_ = \n"
" reinterpret_cast<const ::$proto_ns$::MessageLite*>(\n"
" $type_default_instance_ptr$)->New(\n"
" msg->GetArenaForAllocation());\n"
" }\n"
" }\n"
" return msg->$name$_;\n"
@ -358,7 +363,7 @@ void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
// If we don't have has-bits, message presence is indicated only by ptr !=
// NULL. Thus on clear, we need to delete the object.
format(
"if (GetArena() == nullptr && $name$_ != nullptr) {\n"
"if (GetArenaForAllocation() == nullptr && $name$_ != nullptr) {\n"
" delete $name$_;\n"
"}\n"
"$name$_ = nullptr;\n");
@ -376,7 +381,7 @@ void MessageFieldGenerator::GenerateMessageClearingCode(
// If we don't have has-bits, message presence is indicated only by ptr !=
// NULL. Thus on clear, we need to delete the object.
format(
"if (GetArena() == nullptr && $name$_ != nullptr) {\n"
"if (GetArenaForAllocation() == nullptr && $name$_ != nullptr) {\n"
" delete $name$_;\n"
"}\n"
"$name$_ = nullptr;\n");
@ -490,7 +495,7 @@ void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
format(
"void $classname$::set_allocated_$name$($type$* $name$) {\n"
"$annotate_accessor$"
" ::$proto_ns$::Arena* message_arena = GetArena();\n"
" ::$proto_ns$::Arena* message_arena = GetArenaForAllocation();\n"
" clear_$oneof_name$();\n"
" if ($name$) {\n");
if (descriptor_->file() != descriptor_->message_type()->file()) {
@ -498,12 +503,15 @@ void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions(
// isn't defined in this file.
format(
" ::$proto_ns$::Arena* submessage_arena =\n"
" "
"reinterpret_cast<::$proto_ns$::MessageLite*>($name$)->GetArena();\n");
" ::$proto_ns$::Arena::InternalHelper<\n"
" ::$proto_ns$::MessageLite>::GetOwningArena(\n"
" reinterpret_cast<::$proto_ns$::MessageLite*>("
"$name$));\n");
} else {
format(
" ::$proto_ns$::Arena* submessage_arena =\n"
" ::$proto_ns$::Arena::GetArena($name$);\n");
" ::$proto_ns$::Arena::InternalHelper<"
"$type$>::GetOwningArena($name$);\n");
}
format(
" if (message_arena != submessage_arena) {\n"
@ -527,7 +535,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
" $type$* temp = $field_member$;\n"
" if (GetArena() != nullptr) {\n"
" if (GetArenaForAllocation() != nullptr) {\n"
" temp = ::$proto_ns$::internal::DuplicateIfNonNull(temp);\n"
" }\n"
" $field_member$ = nullptr;\n"
@ -579,7 +587,8 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if (!_internal_has_$name$()) {\n"
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
" $field_member$ = CreateMaybeMessage< $type$ >(GetArena());\n"
" $field_member$ = CreateMaybeMessage< $type$ "
">(GetArenaForAllocation());\n"
" }\n"
" return $field_member$;\n"
"}\n"
@ -596,7 +605,7 @@ void MessageOneofFieldGenerator::GenerateClearingCode(
Formatter format(printer, variables_);
format(
"if (GetArena() == nullptr) {\n"
"if (GetArenaForAllocation() == nullptr) {\n"
" delete $field_member$;\n"
"}\n");
}

@ -69,6 +69,11 @@ struct Options {
std::string annotation_pragma_name;
std::string annotation_guard_name;
const AccessInfoMap* access_info_map = nullptr;
enum {
kTCTableNever,
kTCTableGuarded,
kTCTableAlways
} tctable_mode = kTCTableNever;
};
} // namespace cpp

@ -31,20 +31,69 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_PARSE_FUNCTION_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_CPP_PARSE_FUNCTION_GENERATOR_H__
#include <map>
#include <string>
#include <vector>
#include <google/protobuf/compiler/cpp/cpp_helpers.h>
#include <google/protobuf/compiler/cpp/cpp_options.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/wire_format_lite.h>
namespace google {
namespace protobuf {
namespace compiler {
namespace cpp {
void GenerateParseFunction(const Descriptor* descriptor, int num_hasbits,
const Options& options,
MessageSCCAnalyzer* scc_analyzer,
io::Printer* printer);
// ParseFunctionGenerator generates the _InternalParse function for a message
// (and any associated supporting members).
class ParseFunctionGenerator {
public:
ParseFunctionGenerator(const Descriptor* descriptor, int num_hasbits,
const Options& options,
MessageSCCAnalyzer* scc_analyzer);
// Emits class-level method declarations to `printer`:
void GenerateMethodDecls(io::Printer* printer);
// Emits out-of-class method implementation definitions to `printer`:
void GenerateMethodImpls(io::Printer* printer);
private:
// Returns the proto runtime internal namespace.
std::string pi_ns();
// Generates a looping `_InternalParse` function.
void GenerateLoopingParseFunction(Formatter& format);
// Generates parsing code for an `ArenaString` field.
void GenerateArenaString(Formatter& format, const FieldDescriptor* field);
// Generates parsing code for a string-typed field.
void GenerateStrings(Formatter& format, const FieldDescriptor* field,
bool check_utf8);
// Generates parsing code for a length-delimited field (strings, messages,
// etc.).
void GenerateLengthDelim(Formatter& format, const FieldDescriptor* field);
// Generates the parsing code for a known field.
void GenerateFieldBody(Formatter& format,
google::protobuf::internal::WireFormatLite::WireType wiretype,
const FieldDescriptor* field);
// Generates code to parse the next field from the input stream.
void GenerateParseIterationBody(
Formatter& format, const Descriptor* descriptor,
const std::vector<const FieldDescriptor*>& ordered_fields);
const Descriptor* descriptor_;
MessageSCCAnalyzer* scc_analyzer_;
const Options& options_;
std::map<std::string, std::string> variables_;
int num_hasbits_;
};
} // namespace cpp
} // namespace compiler

@ -162,14 +162,16 @@ void StringFieldGenerator::GenerateAccessorDeclarations(
descriptor_);
format(
"$deprecated_attr$std::string* ${1$mutable_$name$$}$();\n"
"$deprecated_attr$std::string* ${1$$release_name$$}$();\n"
"PROTOBUF_FUTURE_MUST_USE_RESULT $deprecated_attr$std::string* "
"${1$$release_name$$}$();\n"
"$deprecated_attr$void ${1$set_allocated_$name$$}$(std::string* "
"$name$);\n",
descriptor_);
format(
"private:\n"
"const std::string& _internal_$name$() const;\n"
"void _internal_set_$name$(const std::string& value);\n"
"inline PROTOBUF_ALWAYS_INLINE void "
"_internal_set_$name$(const std::string& value);\n"
"std::string* _internal_mutable_$name$();\n"
"public:\n");
@ -196,12 +198,12 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" return _internal_$name$();\n"
"}\n"
"template <typename ArgT0, typename... ArgT>\n"
"PROTOBUF_ALWAYS_INLINE\n"
"inline void $classname$::set_$name$(ArgT0&& arg0, ArgT... args) {\n"
"inline PROTOBUF_ALWAYS_INLINE\n"
"void $classname$::set_$name$(ArgT0&& arg0, ArgT... args) {\n"
"$annotate_accessor$"
" $set_hasbit$\n"
" $name$_.$setter$($default_value_tag$, static_cast<ArgT0 &&>(arg0),"
" args..., GetArena());\n"
" args..., GetArenaForAllocation());\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
"inline std::string* $classname$::mutable_$name$() {\n"
@ -215,12 +217,13 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
"inline void $classname$::_internal_set_$name$(const std::string& "
"value) {\n"
" $set_hasbit$\n"
" $name$_.Set($default_value_tag$, value, GetArena());\n"
" $name$_.Set($default_value_tag$, value, GetArenaForAllocation());\n"
"}\n");
format(
"inline std::string* $classname$::_internal_mutable_$name$() {\n"
" $set_hasbit$\n"
" return $name$_.Mutable($default_variable_or_tag$, GetArena());\n"
" return $name$_.Mutable($default_variable_or_tag$, "
"GetArenaForAllocation());\n"
"}\n"
"inline std::string* $classname$::$release_name$() {\n"
"$annotate_accessor$"
@ -232,9 +235,11 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" return nullptr;\n"
" }\n"
" $clear_hasbit$\n"
" return $name$_.ReleaseNonDefault($init_value$, GetArena());\n");
" return $name$_.ReleaseNonDefault($init_value$, "
"GetArenaForAllocation());\n");
} else {
format(" return $name$_.Release($init_value$, GetArena());\n");
format(
" return $name$_.Release($init_value$, GetArenaForAllocation());\n");
}
format(
@ -247,7 +252,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" $clear_hasbit$\n"
" }\n"
" $name$_.SetAllocated($init_value$, $name$,\n"
" GetArena());\n"
" GetArenaForAllocation());\n"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
"}\n");
}
@ -268,7 +273,8 @@ void StringFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
if (descriptor_->default_value_string().empty()) {
format("$name$_.ClearToEmpty();\n");
} else {
format("$name$_.ClearToDefault($lazy_variable$, GetArena());\n");
format(
"$name$_.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n");
}
}
@ -294,7 +300,8 @@ void StringFieldGenerator::GenerateMessageClearingCode(
} 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$, GetArena());\n ");
format(
"$name$_.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n ");
}
}
@ -306,7 +313,12 @@ void StringFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
void StringFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("$name$_.Swap(&other->$name$_, $init_value$, GetArena());\n");
format(
"::$proto_ns$::internal::ArenaStringPtr::InternalSwap(\n"
" $init_value$,\n"
" &$name$_, GetArenaForAllocation(),\n"
" &other->$name$_, other->GetArenaForAllocation()\n"
");\n");
}
void StringFieldGenerator::GenerateConstructorCode(io::Printer* printer) const {
@ -330,7 +342,7 @@ void StringFieldGenerator::GenerateCopyConstructorCode(
// TODO(gpike): improve this
format(
"$name$_.Set($default_value_tag$, from._internal_$name$(), \n"
" GetArena());\n");
" GetArenaForAllocation());\n");
format.Outdent();
format("}\n");
@ -405,7 +417,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" $field_member$.UnsafeSetDefault($init_value$);\n"
" }\n"
" $field_member$.$setter$($default_value_tag$,"
" static_cast<ArgT0 &&>(arg0), args..., GetArena());\n"
" static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
"inline std::string* $classname$::mutable_$name$() {\n"
@ -426,7 +438,8 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" set_has_$name$();\n"
" $field_member$.UnsafeSetDefault($init_value$);\n"
" }\n"
" $field_member$.Set($default_value_tag$, value, GetArena());\n"
" $field_member$.Set($default_value_tag$, value, "
"GetArenaForAllocation());\n"
"}\n");
format(
"inline std::string* $classname$::_internal_mutable_$name$() {\n"
@ -436,14 +449,15 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" $field_member$.UnsafeSetDefault($init_value$);\n"
" }\n"
" return $field_member$.Mutable(\n"
" $default_variable_or_tag$, GetArena());\n"
" $default_variable_or_tag$, GetArenaForAllocation());\n"
"}\n"
"inline std::string* $classname$::$release_name$() {\n"
"$annotate_accessor$"
" // @@protoc_insertion_point(field_release:$full_name$)\n"
" if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
" return $field_member$.ReleaseNonDefault($init_value$, GetArena());\n"
" return $field_member$.ReleaseNonDefault($init_value$, "
"GetArenaForAllocation());\n"
" } else {\n"
" return nullptr;\n"
" }\n"
@ -456,7 +470,7 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if ($name$ != nullptr) {\n"
" set_has_$name$();\n"
" $field_member$.UnsafeSetDefault($name$);\n"
" ::$proto_ns$::Arena* arena = GetArena();\n"
" ::$proto_ns$::Arena* arena = GetArenaForAllocation();\n"
" if (arena != nullptr) {\n"
" arena->Own($name$);\n"
" }\n"
@ -468,7 +482,9 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
void StringOneofFieldGenerator::GenerateClearingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field_member$.Destroy($default_value_tag$, GetArena());\n");
format(
"$field_member$.Destroy($default_value_tag$, "
"GetArenaForAllocation());\n");
}
void StringOneofFieldGenerator::GenerateMessageClearingCode(

@ -205,9 +205,6 @@ TEST(GENERATED_MESSAGE_TEST_NAME, Trigraph) {
TEST(GENERATED_MESSAGE_TEST_NAME, ExtremeSmallIntegerDefault) {
const UNITTEST::TestExtremeDefaultValues& extreme_default =
UNITTEST::TestExtremeDefaultValues::default_instance();
EXPECT_EQ(~0x7fffffff, std::numeric_limits<int32_t>::min());
EXPECT_EQ(PROTOBUF_LONGLONG(~0x7fffffffffffffff),
std::numeric_limits<int64_t>::min());
EXPECT_EQ(std::numeric_limits<int32_t>::min(),
extreme_default.really_small_int32());
EXPECT_EQ(std::numeric_limits<int64_t>::min(),

@ -211,9 +211,14 @@ void ImmutableMessageGenerator::GenerateFieldAccessorTable(
" com.google.protobuf.GeneratedMessage$ver$.FieldAccessorTable\n"
" internal_$identifier$_fieldAccessorTable;\n");
// The following bytecode_estimate calculation logic must stay in sync with
// the similar logic in the GenerateFieldAccessorTableInitializer method below
// to make sure that the generated static final fields are initialized in the
// static initialization block directly.
//
// 6 bytes per field and oneof
*bytecode_estimate +=
10 + 6 * descriptor_->field_count() + 6 * oneofs_.size();
10 + 6 * descriptor_->field_count() + 6 * descriptor_->oneof_decl_count();
}
int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer(
@ -226,6 +231,10 @@ int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer(
" new java.lang.String[] { ",
"identifier", UniqueFileScopeIdentifier(descriptor_), "ver",
GeneratedCodeVersionSuffix());
// All the bytecode_estimate calculation logic in this method must stay in
// sync with the similar logic in the GenerateFieldAccessorTable method
// above. See the corresponding comment in GenerateFieldAccessorTable for
// details.
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);

@ -1782,12 +1782,12 @@ bool Parser::ParseReserved(EnumDescriptorProto* message,
DO(Consume("reserved"));
if (LookingAtType(io::Tokenizer::TYPE_STRING)) {
LocationRecorder location(message_location,
DescriptorProto::kReservedNameFieldNumber);
EnumDescriptorProto::kReservedNameFieldNumber);
location.StartAt(start_token);
return ParseReservedNames(message, location);
} else {
LocationRecorder location(message_location,
DescriptorProto::kReservedRangeFieldNumber);
EnumDescriptorProto::kReservedRangeFieldNumber);
location.StartAt(start_token);
return ParseReservedNumbers(message, location);
}

@ -3139,6 +3139,43 @@ TEST_F(SourceInfoTest, EnumValues) {
EXPECT_TRUE(HasSpan(file_.enum_type(0), "name"));
}
TEST_F(SourceInfoTest, EnumReservedRange) {
EXPECT_TRUE(
Parse("enum TestEnum {\n"
" $a$reserved $b$1$c$ to $d$10$e$;$f$\n"
"}"));
const EnumDescriptorProto::EnumReservedRange& bar =
file_.enum_type(0).reserved_range(0);
EXPECT_TRUE(HasSpan('a', 'f', file_.enum_type(0), "reserved_range"));
EXPECT_TRUE(HasSpan('b', 'e', bar));
EXPECT_TRUE(HasSpan('b', 'c', bar, "start"));
EXPECT_TRUE(HasSpan('d', 'e', bar, "end"));
// Ignore these.
EXPECT_TRUE(HasSpan(file_));
EXPECT_TRUE(HasSpan(file_.enum_type(0)));
EXPECT_TRUE(HasSpan(file_.enum_type(0), "name"));
}
TEST_F(SourceInfoTest, EnumReservedName) {
EXPECT_TRUE(
Parse("enum TestEnum {\n"
" $a$reserved $b$'foo'$c$;$d$\n"
"}"));
const EnumDescriptorProto& bar = file_.enum_type(0);
EXPECT_TRUE(HasSpan('a', 'd', bar, "reserved_name"));
EXPECT_TRUE(HasSpan('b', 'c', bar, "reserved_name", 0));
// Ignore these.
EXPECT_TRUE(HasSpan(file_));
EXPECT_TRUE(HasSpan(file_.enum_type(0)));
EXPECT_TRUE(HasSpan(file_.enum_type(0), "name"));
}
TEST_F(SourceInfoTest, NestedEnums) {
EXPECT_TRUE(
Parse("message Foo {\n"

@ -67,7 +67,7 @@ constexpr CodeGeneratorResponse::CodeGeneratorResponse(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: file_()
, error_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string)
, supported_features_(PROTOBUF_ULONGLONG(0)){}
, supported_features_(uint64_t{0u}){}
struct CodeGeneratorResponseDefaultTypeInternal {
constexpr CodeGeneratorResponseDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
@ -243,7 +243,7 @@ Version::Version(const Version& from)
suffix_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_suffix()) {
suffix_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_suffix(),
GetArena());
GetArenaForAllocation());
}
::memcpy(&major_, &from.major_,
static_cast<size_t>(reinterpret_cast<char*>(&patch_) -
@ -266,7 +266,7 @@ Version::~Version() {
}
void Version::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
suffix_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
@ -518,7 +518,11 @@ void Version::InternalSwap(Version* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
suffix_.Swap(&other->suffix_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&suffix_, GetArenaForAllocation(),
&other->suffix_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(Version, patch_)
+ sizeof(Version::patch_)
@ -571,7 +575,7 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
parameter_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_parameter()) {
parameter_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_parameter(),
GetArena());
GetArenaForAllocation());
}
if (from._internal_has_compiler_version()) {
compiler_version_ = new PROTOBUF_NAMESPACE_ID::compiler::Version(*from.compiler_version_);
@ -593,7 +597,7 @@ CodeGeneratorRequest::~CodeGeneratorRequest() {
}
void CodeGeneratorRequest::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
parameter_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (this != internal_default_instance()) delete compiler_version_;
}
@ -867,7 +871,11 @@ void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) {
swap(_has_bits_[0], other->_has_bits_[0]);
file_to_generate_.InternalSwap(&other->file_to_generate_);
proto_file_.InternalSwap(&other->proto_file_);
parameter_.Swap(&other->parameter_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&parameter_, GetArenaForAllocation(),
&other->parameter_, other->GetArenaForAllocation()
);
swap(compiler_version_, other->compiler_version_);
}
@ -918,17 +926,17 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_name()) {
name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(),
GetArena());
GetArenaForAllocation());
}
insertion_point_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_insertion_point()) {
insertion_point_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_insertion_point(),
GetArena());
GetArenaForAllocation());
}
content_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_content()) {
content_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_content(),
GetArena());
GetArenaForAllocation());
}
if (from._internal_has_generated_code_info()) {
generated_code_info_ = new PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo(*from.generated_code_info_);
@ -952,7 +960,7 @@ CodeGeneratorResponse_File::~CodeGeneratorResponse_File() {
}
void CodeGeneratorResponse_File::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
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());
@ -1228,9 +1236,21 @@ void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other)
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
insertion_point_.Swap(&other->insertion_point_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
content_.Swap(&other->content_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&name_, GetArenaForAllocation(),
&other->name_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&insertion_point_, GetArenaForAllocation(),
&other->insertion_point_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&content_, GetArenaForAllocation(),
&other->content_, other->GetArenaForAllocation()
);
swap(generated_code_info_, other->generated_code_info_);
}
@ -1268,7 +1288,7 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
error_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_error()) {
error_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_error(),
GetArena());
GetArenaForAllocation());
}
supported_features_ = from.supported_features_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorResponse)
@ -1276,7 +1296,7 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
void CodeGeneratorResponse::SharedCtor() {
error_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
supported_features_ = PROTOBUF_ULONGLONG(0);
supported_features_ = uint64_t{0u};
}
CodeGeneratorResponse::~CodeGeneratorResponse() {
@ -1286,7 +1306,7 @@ CodeGeneratorResponse::~CodeGeneratorResponse() {
}
void CodeGeneratorResponse::SharedDtor() {
GOOGLE_DCHECK(GetArena() == nullptr);
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
error_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
@ -1311,7 +1331,7 @@ void CodeGeneratorResponse::Clear() {
if (cached_has_bits & 0x00000001u) {
error_.ClearNonDefaultToEmpty();
}
supported_features_ = PROTOBUF_ULONGLONG(0);
supported_features_ = uint64_t{0u};
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
@ -1516,7 +1536,11 @@ void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) {
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
file_.InternalSwap(&other->file_);
error_.Swap(&other->error_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&error_, GetArenaForAllocation(),
&other->error_, other->GetArenaForAllocation()
);
swap(supported_features_, other->supported_features_);
}

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

Loading…
Cancel
Save