PROTOBUF_SYNC_PIPER
pull/10623/head
Mike Kruskal 3 years ago
commit d85c9944c5
  1. 2
      .bazelrc
  2. 31
      .github/workflows/generated_cmake.yml
  3. 10
      BUILD.bazel
  4. 5
      CHANGES.txt
  5. 29
      CMakeLists.txt
  6. 2
      Protobuf.podspec
  7. 2
      conformance/README.md
  8. 2
      csharp/Google.Protobuf.Tools.nuspec
  9. 10
      csharp/src/Google.Protobuf.Test/JsonParserTest.cs
  10. 2
      csharp/src/Google.Protobuf/Google.Protobuf.csproj
  11. 16
      csharp/src/Google.Protobuf/JsonParser.cs
  12. 8
      csharp/src/Google.Protobuf/Reflection/Descriptor.cs
  13. 4
      docs/options.md
  14. 1
      examples/.bazelrc
  15. 6
      java/README.md
  16. 2
      java/bom/pom.xml
  17. 2
      java/core/pom.xml
  18. 25
      java/core/src/main/java/com/google/protobuf/TextFormat.java
  19. 3
      java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto
  20. 2
      java/kotlin-lite/pom.xml
  21. 2
      java/kotlin/pom.xml
  22. 2
      java/lite.md
  23. 2
      java/lite/pom.xml
  24. 2
      java/pom.xml
  25. 2
      java/util/pom.xml
  26. 11
      kokoro/linux/32-bit/test_php.sh
  27. 2
      kokoro/linux/bazel/common.cfg
  28. 2
      kokoro/linux/cmake/build.sh
  29. 3
      kokoro/macos/ruby31/build.sh
  30. 4
      kokoro/release/ruby/macos/ruby/ruby_build_environment.sh
  31. 2
      kokoro/windows/bazel/build.bat
  32. 5
      kokoro/windows/cmake/build.bat
  33. 4
      kokoro/windows/cmake_install/build.bat
  34. 4
      kokoro/windows/cmake_nmake/build.bat
  35. 4
      kokoro/windows/cmake_shared/build.bat
  36. 5
      objectivec/GPBCodedInputStream.h
  37. 6
      objectivec/GPBCodedInputStream.m
  38. 4
      objectivec/GPBCodedInputStream_PackagePrivate.h
  39. 4
      objectivec/GPBDictionary.m
  40. 4
      objectivec/GPBDictionary_PackagePrivate.h
  41. 4
      objectivec/GPBExtensionInternals.h
  42. 6
      objectivec/GPBExtensionInternals.m
  43. 32
      objectivec/GPBExtensionRegistry.h
  44. 14
      objectivec/GPBMessage.h
  45. 24
      objectivec/GPBMessage.m
  46. 4
      objectivec/GPBMessage_PackagePrivate.h
  47. 23
      php/ext/google/protobuf/package.xml
  48. 2
      php/ext/google/protobuf/protobuf.h
  49. 4
      php/generate_descriptor_protos.sh
  50. 4
      php/generate_test_protos.sh
  51. 24
      php/src/Google/Protobuf/Internal/MessageOptions.php
  52. 3
      pkg/BUILD.bazel
  53. 6
      protobuf_version.bzl
  54. 2
      protoc-artifacts/pom.xml
  55. 3
      python/google/protobuf/json_format.py
  56. 75
      python/google/protobuf/pyext/descriptor.cc
  57. 1
      python/google/protobuf/pyext/map_container.cc
  58. 43
      python/google/protobuf/pyext/message.cc
  59. 1
      python/google/protobuf/pyext/repeated_composite_container.cc
  60. 2
      python/google/protobuf/text_format.py
  61. 2
      ruby/google-protobuf.gemspec
  62. 4
      ruby/pom.xml
  63. 39
      src/file_lists.cmake
  64. 92
      src/google/protobuf/BUILD.bazel
  65. 2
      src/google/protobuf/any.pb.h
  66. 4
      src/google/protobuf/any_lite.cc
  67. 2
      src/google/protobuf/api.pb.h
  68. 12
      src/google/protobuf/arena.cc
  69. 3
      src/google/protobuf/arena.h
  70. 59
      src/google/protobuf/arena_impl.h
  71. 39
      src/google/protobuf/compiler/BUILD.bazel
  72. 8
      src/google/protobuf/compiler/code_generator.cc
  73. 19
      src/google/protobuf/compiler/command_line_interface.cc
  74. 1
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  75. 3
      src/google/protobuf/compiler/cpp/BUILD.bazel
  76. 1834
      src/google/protobuf/compiler/cpp/file.cc
  77. 119
      src/google/protobuf/compiler/cpp/file.h
  78. 3
      src/google/protobuf/compiler/cpp/generator.cc
  79. 41
      src/google/protobuf/compiler/cpp/helpers.cc
  80. 41
      src/google/protobuf/compiler/cpp/helpers.h
  81. 10
      src/google/protobuf/compiler/cpp/parse_function_generator.cc
  82. 2
      src/google/protobuf/compiler/csharp/BUILD.bazel
  83. 3
      src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
  84. 19
      src/google/protobuf/compiler/csharp/csharp_enum.cc
  85. 10
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  86. 8
      src/google/protobuf/compiler/csharp/csharp_field_base.h
  87. 10
      src/google/protobuf/compiler/csharp/csharp_generator.cc
  88. 4
      src/google/protobuf/compiler/csharp/csharp_helpers.cc
  89. 2
      src/google/protobuf/compiler/csharp/csharp_helpers.h
  90. 10
      src/google/protobuf/compiler/csharp/csharp_map_field.cc
  91. 17
      src/google/protobuf/compiler/csharp/csharp_message.cc
  92. 12
      src/google/protobuf/compiler/csharp/csharp_message_field.cc
  93. 2
      src/google/protobuf/compiler/csharp/csharp_names.h
  94. 13
      src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
  95. 13
      src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
  96. 12
      src/google/protobuf/compiler/importer.cc
  97. 2
      src/google/protobuf/compiler/java/BUILD.bazel
  98. 12
      src/google/protobuf/compiler/java/helpers.cc
  99. 3
      src/google/protobuf/compiler/java/helpers.h
  100. 23
      src/google/protobuf/compiler/mock_code_generator.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -1 +1 @@
build --cxxopt=-std=c++14 build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14

@ -1,24 +1,29 @@
name: Generated CMake File Lists name: Generate CMake File Lists
on: on:
- push push:
- pull_request branches:
- main
- '[0-9]+.x'
# The 21.x branch predates support for auto-generation of the CMake file
# lists, so we make sure to exclude it.
- '!21.x'
jobs: jobs:
cmake: cmake:
if: github.repository == 'protocolbuffers/protobuf'
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false # Don't cancel all jobs if one fails. fail-fast: false # Don't cancel all jobs if one fails.
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Set up Bazel read-only caching with:
run: echo "BAZEL_CACHE_AUTH=--remote_upload_local_results=false" >> $GITHUB_ENV # Note: this token has an expiration date, so if the workflow starts
- name: Generate CMake files # failing then you may need to generate a fresh token.
run: cd ${{ github.workspace }} && bazel build //pkg:gen_src_file_lists --test_output=errors $BAZEL_CACHE $BAZEL_CACHE_AUTH token: ${{ secrets.BOT_ACCESS_TOKEN }}
- name: Compare to Golden file - name: Configure name and email address in Git
run: diff -du bazel-bin/pkg/src_file_lists.cmake src/file_lists.cmake run: cd ${{ github.workspace }} && git config user.name "Protobuf Team Bot" && git config user.email "protobuf-team-bot@google.com"
- name: Report - name: Commit and push update
run: echo "::error file=cmake/update_file_lists.sh::CMake files are stale, please run cmake/update_file_lists.sh" run: cd ${{ github.workspace }} && ./cmake/push_auto_update.sh
if: failure()

@ -294,18 +294,8 @@ alias(
proto_lang_toolchain( proto_lang_toolchain(
name = "cc_toolchain", name = "cc_toolchain",
blacklisted_protos = [ blacklisted_protos = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:api_proto",
"@com_google_protobuf//:compiler_plugin_proto", "@com_google_protobuf//:compiler_plugin_proto",
"@com_google_protobuf//:descriptor_proto", "@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:field_mask_proto",
"@com_google_protobuf//:source_context_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:type_proto",
"@com_google_protobuf//:wrappers_proto",
], ],
command_line = "--cpp_out=$(OUT)", command_line = "--cpp_out=$(OUT)",
runtime = ":protobuf", runtime = ":protobuf",

@ -43,6 +43,11 @@
Compiler Compiler
* Print full path name of source .proto file on error * Print full path name of source .proto file on error
2022-09-13 version 21.6 (C++/Java/Python/PHP/Objective-C/C#/Ruby)
C++
* Reduce memory consumption of MessageSet parsing
2022-08-09 version 21.5 (C++/Java/Python/PHP/Objective-C/C#/Ruby) 2022-08-09 version 21.5 (C++/Java/Python/PHP/Objective-C/C#/Ruby)
PHP PHP

@ -19,6 +19,10 @@ endif()
if(POLICY CMP0091) if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW) cmake_policy(SET CMP0091 NEW)
endif() endif()
# Honor visibility properties for all target types.
if(POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()
# Project # Project
project(protobuf C CXX) project(protobuf C CXX)
@ -32,15 +36,32 @@ if(protobuf_DEPRECATED_CMAKE_SUBDIRECTORY_USAGE)
get_filename_component(protobuf_SOURCE_DIR ${protobuf_SOURCE_DIR} DIRECTORY) get_filename_component(protobuf_SOURCE_DIR ${protobuf_SOURCE_DIR} DIRECTORY)
endif() endif()
# Add c++14 flags # Add C++14 flags
if (CYGWIN) if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
else()
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
endif()
if(CYGWIN)
string(REGEX_MATCH "-std=gnu\\+\\+([0-9]+)" _protobuf_CXX_STD "${CMAKE_CXX_FLAGS}")
endif()
if(NOT _protobuf_CXX_STD)
set(_protobuf_CXX_STD "${CMAKE_CXX_STANDARD}")
endif()
if(_protobuf_CXX_STD LESS "14")
message(FATAL_ERROR "Protocol Buffers requires at least C++14, but is configured for C++${_protobuf_CXX_STD}")
endif()
if(CYGWIN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++${_protobuf_CXX_STD}")
else()
set(CMAKE_CXX_STANDARD ${_protobuf_CXX_STD})
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
endif() endif()
# For -fvisibility=hidden and -fvisibility-inlines-hidden
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
# The Intel compiler isn't able to deal with noinline member functions of # The Intel compiler isn't able to deal with noinline member functions of
# template classes defined in headers. As such it spams the output with # template classes defined in headers. As such it spams the output with
# warning #2196: routine is both "inline" and "noinline" # warning #2196: routine is both "inline" and "noinline"

@ -5,7 +5,7 @@
# dependent projects use the :git notation to refer to the library. # dependent projects use the :git notation to refer to the library.
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Protobuf' s.name = 'Protobuf'
s.version = '3.21.5' s.version = '3.21.6'
s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.'
s.homepage = 'https://github.com/protocolbuffers/protobuf' s.homepage = 'https://github.com/protocolbuffers/protobuf'
s.license = 'BSD-3-Clause' s.license = 'BSD-3-Clause'

@ -81,7 +81,7 @@ Ruby:
JRuby: JRuby:
$ [[ $(ruby --version) == "jruby"* ]] || echo "Switch to Java Ruby!" $ [[ $(ruby --version) == "jruby"* ]] || echo "Switch to Java Ruby!"
$ bazel test //ruby:conformance_test --define=ruby_platform=java \ $ bazel test //ruby:conformance_test_jruby --define=ruby_platform=java \
--action_env=PATH --action_env=GEM_PATH --action_env=GEM_HOME --action_env=PATH --action_env=GEM_PATH --action_env=GEM_HOME
Testing other Protocol Buffer implementations Testing other Protocol Buffer implementations

@ -5,7 +5,7 @@
<title>Google Protocol Buffers tools</title> <title>Google Protocol Buffers tools</title>
<summary>Tools for Protocol Buffers - Google's data interchange format.</summary> <summary>Tools for Protocol Buffers - Google's data interchange format.</summary>
<description>See project site for more info.</description> <description>See project site for more info.</description>
<version>3.21.5</version> <version>3.21.6</version>
<authors>Google Inc.</authors> <authors>Google Inc.</authors>
<owners>protobuf-packages</owners> <owners>protobuf-packages</owners>
<licenseUrl>https://github.com/protocolbuffers/protobuf/blob/main/LICENSE</licenseUrl> <licenseUrl>https://github.com/protocolbuffers/protobuf/blob/main/LICENSE</licenseUrl>

@ -576,6 +576,10 @@ namespace Google.Protobuf
[TestCase("-3.402823e38", -3.402823e38f)] [TestCase("-3.402823e38", -3.402823e38f)]
[TestCase("1.5e1", 15f)] [TestCase("1.5e1", 15f)]
[TestCase("15e-1", 1.5f)] [TestCase("15e-1", 1.5f)]
[TestCase("3.4028235e38", float.MaxValue)]
[TestCase("-3.4028235e38", float.MinValue)]
[TestCase("3.4028235e+38", float.MaxValue)]
[TestCase("-3.4028235e+38", float.MinValue)]
public void NumberToFloat_Valid(string jsonValue, float expectedParsedValue) public void NumberToFloat_Valid(string jsonValue, float expectedParsedValue)
{ {
string json = "{ \"singleFloat\": " + jsonValue + "}"; string json = "{ \"singleFloat\": " + jsonValue + "}";
@ -584,8 +588,10 @@ namespace Google.Protobuf
} }
[Test] [Test]
[TestCase("3.402824e38", typeof(InvalidProtocolBufferException))] [TestCase("3.4028236e38", typeof(InvalidProtocolBufferException))]
[TestCase("-3.402824e38", typeof(InvalidProtocolBufferException))] [TestCase("-3.4028236e38", typeof(InvalidProtocolBufferException))]
[TestCase("3.4028236e+38", typeof(InvalidProtocolBufferException))]
[TestCase("-3.4028236e+38", typeof(InvalidProtocolBufferException))]
[TestCase("1,0", typeof(InvalidJsonException))] [TestCase("1,0", typeof(InvalidJsonException))]
[TestCase("1.0.0", typeof(InvalidJsonException))] [TestCase("1.0.0", typeof(InvalidJsonException))]
[TestCase("+1", typeof(InvalidJsonException))] [TestCase("+1", typeof(InvalidJsonException))]

@ -4,7 +4,7 @@
<Description>C# runtime library for Protocol Buffers - Google's data interchange format.</Description> <Description>C# runtime library for Protocol Buffers - Google's data interchange format.</Description>
<Copyright>Copyright 2015, Google Inc.</Copyright> <Copyright>Copyright 2015, Google Inc.</Copyright>
<AssemblyTitle>Google Protocol Buffers</AssemblyTitle> <AssemblyTitle>Google Protocol Buffers</AssemblyTitle>
<VersionPrefix>3.21.5</VersionPrefix> <VersionPrefix>3.21.6</VersionPrefix>
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<Authors>Google Inc.</Authors> <Authors>Google Inc.</Authors>
<TargetFrameworks>netstandard1.1;netstandard2.0;net45;net50</TargetFrameworks> <TargetFrameworks>netstandard1.1;netstandard2.0;net45;net50</TargetFrameworks>

@ -642,19 +642,15 @@ namespace Google.Protobuf
{ {
return float.NaN; return float.NaN;
} }
if (value > float.MaxValue || value < float.MinValue) float converted = (float) value;
// If the value is out of range of float, the cast representation will be infinite.
// If the original value was infinite as well, that's fine - we'll return the 32-bit
// version (with the correct sign).
if (float.IsInfinity(converted) && !double.IsInfinity(value))
{ {
if (double.IsPositiveInfinity(value))
{
return float.PositiveInfinity;
}
if (double.IsNegativeInfinity(value))
{
return float.NegativeInfinity;
}
throw new InvalidProtocolBufferException($"Value out of range: {value}"); throw new InvalidProtocolBufferException($"Value out of range: {value}");
} }
return (float) value; return converted;
case FieldType.Enum: case FieldType.Enum:
CheckInteger(value); CheckInteger(value);
// Just return it as an int, and let the CLR convert it. // Just return it as an int, and let the CLR convert it.

@ -6641,6 +6641,10 @@ namespace Google.Protobuf.Reflection {
private bool mapEntry_; private bool mapEntry_;
/// <summary> /// <summary>
/// NOTE: Do not set the option in .proto files. Always use the maps syntax
/// instead. The option should only be implicitly set by the proto compiler
/// parser.
///
/// Whether the message is an automatically generated map entry type for the /// Whether the message is an automatically generated map entry type for the
/// maps field. /// maps field.
/// ///
@ -6658,10 +6662,6 @@ namespace Google.Protobuf.Reflection {
/// use a native map in the target language to hold the keys and values. /// use a native map in the target language to hold the keys and values.
/// The reflection APIs in such implementations still need to work as /// The reflection APIs in such implementations still need to work as
/// if the field is a repeated message field. /// if the field is a repeated message field.
///
/// NOTE: Do not set the option in .proto files. Always use the maps syntax
/// instead. The option should only be implicitly set by the proto compiler
/// parser.
/// </summary> /// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]

@ -344,3 +344,7 @@ with info about your project (name and website) so we can add an entry for you.
1. mypy-protobuf 1. mypy-protobuf
* Website: https://github.com/nipunn1313/mypy-protobuf * Website: https://github.com/nipunn1313/mypy-protobuf
* Extension: 1151-1154 * Extension: 1151-1154
1. Pigweed protobuf compiler
* Website: https://pigweed.dev/pw_protobuf
* Extension: 1155

@ -0,0 +1 @@
build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14

@ -23,7 +23,7 @@ If you are using Maven, use the following:
<dependency> <dependency>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId> <artifactId>protobuf-java</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</dependency> </dependency>
``` ```
@ -37,7 +37,7 @@ protobuf-java-util package:
<dependency> <dependency>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId> <artifactId>protobuf-java-util</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</dependency> </dependency>
``` ```
@ -45,7 +45,7 @@ protobuf-java-util package:
If you are using Gradle, add the following to your `build.gradle` file's dependencies: If you are using Gradle, add the following to your `build.gradle` file's dependencies:
``` ```
implementation 'com.google.protobuf:protobuf-java:3.21.5' implementation 'com.google.protobuf:protobuf-java:3.21.6'
``` ```
Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using.

@ -4,7 +4,7 @@
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-bom</artifactId> <artifactId>protobuf-bom</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Protocol Buffers [BOM]</name> <name>Protocol Buffers [BOM]</name>

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</parent> </parent>
<artifactId>protobuf-java</artifactId> <artifactId>protobuf-java</artifactId>

@ -61,7 +61,6 @@ public final class TextFormat {
private static final String DEBUG_STRING_SILENT_MARKER = "\t "; private static final String DEBUG_STRING_SILENT_MARKER = "\t ";
/** /**
* Outputs a textual representation of the Protocol Message supplied into the parameter output. * Outputs a textual representation of the Protocol Message supplied into the parameter output.
* (This representation is the new version of the classic "ProtocolPrinter" output from the * (This representation is the new version of the classic "ProtocolPrinter" output from the
@ -739,9 +738,9 @@ public final class TextFormat {
// Groups must be serialized with their original capitalization. // Groups must be serialized with their original capitalization.
generator.print(field.getMessageType().getName()); generator.print(field.getMessageType().getName());
} else { } else {
generator.print(field.getName()); generator.print(field.getName());
}
} }
}
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
generator.print(" {"); generator.print(" {");
@ -1836,16 +1835,16 @@ public final class TextFormat {
extension = target.findExtensionByName(extensionRegistry, name); extension = target.findExtensionByName(extensionRegistry, name);
if (extension == null) { if (extension == null) {
String message = String message =
(tokenizer.getPreviousLine() + 1) (tokenizer.getPreviousLine() + 1)
+ ":" + ":"
+ (tokenizer.getPreviousColumn() + 1) + (tokenizer.getPreviousColumn() + 1)
+ ":\t" + ":\t"
+ type.getFullName() + type.getFullName()
+ ".[" + ".["
+ name + name
+ "]"; + "]";
unknownFields.add(new UnknownField(message, UnknownField.Type.EXTENSION)); unknownFields.add(new UnknownField(message, UnknownField.Type.EXTENSION));
} else { } else {
if (extension.descriptor.getContainingType() != type) { if (extension.descriptor.getContainingType() != type) {
throw tokenizer.parseExceptionPreviousToken( throw tokenizer.parseExceptionPreviousToken(

@ -125,6 +125,3 @@ message ReservedAsMapFieldWithEnumValue {
// null is not a 'reserved word' per se but as a literal needs similar care // null is not a 'reserved word' per se but as a literal needs similar care
map<string, SampleEnum> null = 10; map<string, SampleEnum> null = 10;
} }
package map_for_proto2_lite_test;
option java_package = "map_lite_test";
option optimize_for = LITE_RUNTIME;

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</parent> </parent>
<artifactId>protobuf-kotlin-lite</artifactId> <artifactId>protobuf-kotlin-lite</artifactId>

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</parent> </parent>
<artifactId>protobuf-kotlin</artifactId> <artifactId>protobuf-kotlin</artifactId>

@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following:
<dependency> <dependency>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-javalite</artifactId> <artifactId>protobuf-javalite</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</dependency> </dependency>
``` ```

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</parent> </parent>
<artifactId>protobuf-javalite</artifactId> <artifactId>protobuf-javalite</artifactId>

@ -4,7 +4,7 @@
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Protocol Buffers [Parent]</name> <name>Protocol Buffers [Parent]</name>

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId> <artifactId>protobuf-parent</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</parent> </parent>
<artifactId>protobuf-java-util</artifactId> <artifactId>protobuf-java-util</artifactId>

@ -36,9 +36,13 @@ build_php_c() {
test_php_c test_php_c
} }
cmake . mkdir build
cmake --build . --target protoc -- -j20 pushd build
cmake ..
cmake --build . -- -j20
ctest --verbose --parallel 20
export PROTOC=$(pwd)/protoc export PROTOC=$(pwd)/protoc
popd
build_php 7.0 build_php 7.0
build_php 7.1 build_php 7.1
@ -49,3 +53,6 @@ build_php_c 7.4
build_php_c 7.1-zts build_php_c 7.1-zts
build_php_c 7.2-zts build_php_c 7.2-zts
build_php_c 7.5-zts build_php_c 7.5-zts
# Cleanup after CMake build
rm -rf build

@ -6,7 +6,7 @@ timeout_mins: 15
env_vars { env_vars {
key: "BAZEL_TARGETS" key: "BAZEL_TARGETS"
value: "//src/..." value: "//src/... @com_google_protobuf_examples//..."
} }
action { action {

@ -19,7 +19,7 @@ docker run \
--cidfile $tmpfile \ --cidfile $tmpfile \
-v $GIT_REPO_ROOT:/workspace \ -v $GIT_REPO_ROOT:/workspace \
$CONTAINER_IMAGE \ $CONTAINER_IMAGE \
/test.sh -Dprotobuf_BUILD_CONFORMANCE=ON /test.sh -Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_EXAMPLES=ON
# Save logs for Kokoro # Save logs for Kokoro
docker cp \ docker cp \

@ -5,6 +5,9 @@
# Change to repo root # Change to repo root
cd $(dirname $0)/../../.. cd $(dirname $0)/../../..
# Fix locale issues in Monterey.
export LC_ALL=en_US.UTF-8
# Prepare worker environment to run tests # Prepare worker environment to run tests
KOKORO_INSTALL_RVM=yes KOKORO_INSTALL_RVM=yes
source kokoro/macos/prepare_build_macos_rc source kokoro/macos/prepare_build_macos_rc

@ -2,6 +2,10 @@
set -ex set -ex
# Fix permissions
sudo chown -R $(whoami) $HOME/.rvm/
sudo chown -R $(whoami) /Library/Ruby/
set +ex # rvm script is very verbose and exits with errorcode set +ex # rvm script is very verbose and exits with errorcode
# Fix permissions # Fix permissions

@ -24,7 +24,7 @@ bazel %BAZEL_STARTUP% build //:protoc //:protobuf //:protobuf_lite %BAZEL_FLAGS%
@rem TODO(b/241484899) Enable conformance tests on windows. @rem TODO(b/241484899) Enable conformance tests on windows.
bazel %BAZEL_STARTUP% test %BAZEL_FLAGS% ^ bazel %BAZEL_STARTUP% test %BAZEL_FLAGS% ^
--test_tag_filters=-conformance --build_tag_filters=-conformance ^ --test_tag_filters=-conformance --build_tag_filters=-conformance ^
//src/... || goto :error //src/... @com_google_protobuf_examples//... || goto :error
goto :EOF goto :EOF

@ -6,13 +6,14 @@ call kokoro\windows\prepare_build_win64.bat || goto :error
@rem TODO(b/241475022) Use docker to guarantee better stability. @rem TODO(b/241475022) Use docker to guarantee better stability.
@rem TODO(b/241484899) Run conformance tests in windows. @rem TODO(b/241484899) Run conformance tests in windows.
md build -ea 0 md build
md %KOKORO_ARTIFACTS_DIR%\logs -ea 0 md %KOKORO_ARTIFACTS_DIR%\logs
cd build cd build
cmake .. ^ cmake .. ^
-G "Visual Studio 15 2017" -A x64 ^ -G "Visual Studio 15 2017" -A x64 ^
-Dprotobuf_BUILD_EXAMPLES=ON ^
-Dprotobuf_BUILD_CONFORMANCE=OFF ^ -Dprotobuf_BUILD_CONFORMANCE=OFF ^
-Dprotobuf_WITH_ZLIB=OFF ^ -Dprotobuf_WITH_ZLIB=OFF ^
-Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error -Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error

@ -6,8 +6,8 @@ call kokoro\windows\prepare_build_win64.bat || goto :error
@rem TODO(b/241475022) Use docker to guarantee better stability. @rem TODO(b/241475022) Use docker to guarantee better stability.
@rem TODO(b/241484899) Run conformance tests in windows. @rem TODO(b/241484899) Run conformance tests in windows.
md build -ea 0 md build
md %KOKORO_ARTIFACTS_DIR%\logs -ea 0 md %KOKORO_ARTIFACTS_DIR%\logs
cd build cd build

@ -6,8 +6,8 @@ call kokoro\windows\prepare_build_win64.bat || goto :error
@rem TODO(b/241475022) Use docker to guarantee better stability. @rem TODO(b/241475022) Use docker to guarantee better stability.
@rem TODO(b/241484899) Run conformance tests in windows. @rem TODO(b/241484899) Run conformance tests in windows.
md build -ea 0 md build
md %KOKORO_ARTIFACTS_DIR%\logs -ea 0 md %KOKORO_ARTIFACTS_DIR%\logs
cd build cd build

@ -6,8 +6,8 @@ call kokoro\windows\prepare_build_win64.bat || goto :error
@rem TODO(b/241475022) Use docker to guarantee better stability. @rem TODO(b/241475022) Use docker to guarantee better stability.
@rem TODO(b/241484899) Run conformance tests in windows. @rem TODO(b/241484899) Run conformance tests in windows.
md build -ea 0 md build
md %KOKORO_ARTIFACTS_DIR%\logs -ea 0 md %KOKORO_ARTIFACTS_DIR%\logs
cd build cd build

@ -30,8 +30,9 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "GPBExtensionRegistry.h"
@class GPBMessage; @class GPBMessage;
@class GPBExtensionRegistry;
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -184,7 +185,7 @@ CF_EXTERN_C_END
* extensions for message. * extensions for message.
**/ **/
- (void)readMessage:(GPBMessage *)message - (void)readMessage:(GPBMessage *)message
extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry;
/** /**
* Reads and discards a single field, given its tag value. * Reads and discards a single field, given its tag value.

@ -434,7 +434,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
- (void)readGroup:(int32_t)fieldNumber - (void)readGroup:(int32_t)fieldNumber
message:(GPBMessage *)message message:(GPBMessage *)message
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
CheckRecursionLimit(&state_); CheckRecursionLimit(&state_);
++state_.recursionDepth; ++state_.recursionDepth;
[message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
@ -454,7 +454,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
} }
- (void)readMessage:(GPBMessage *)message - (void)readMessage:(GPBMessage *)message
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
CheckRecursionLimit(&state_); CheckRecursionLimit(&state_);
int32_t length = ReadRawVarint32(&state_); int32_t length = ReadRawVarint32(&state_);
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
@ -466,7 +466,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
} }
- (void)readMapEntry:(id)mapDictionary - (void)readMapEntry:(id)mapDictionary
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
field:(GPBFieldDescriptor *)field field:(GPBFieldDescriptor *)field
parentMessage:(GPBMessage *)parentMessage { parentMessage:(GPBMessage *)parentMessage {
CheckRecursionLimit(&state_); CheckRecursionLimit(&state_);

@ -61,7 +61,7 @@ typedef struct GPBCodedInputStreamState {
// support for older data. // support for older data.
- (void)readGroup:(int32_t)fieldNumber - (void)readGroup:(int32_t)fieldNumber
message:(GPBMessage *)message message:(GPBMessage *)message
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry; extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry;
// Reads a group field value from the stream and merges it into the given // Reads a group field value from the stream and merges it into the given
// UnknownFieldSet. // UnknownFieldSet.
@ -70,7 +70,7 @@ typedef struct GPBCodedInputStreamState {
// Reads a map entry. // Reads a map entry.
- (void)readMapEntry:(id)mapDictionary - (void)readMapEntry:(id)mapDictionary
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
field:(GPBFieldDescriptor *)field field:(GPBFieldDescriptor *)field
parentMessage:(GPBMessage *)parentMessage; parentMessage:(GPBMessage *)parentMessage;
@end @end

@ -386,7 +386,7 @@ BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescri
static void ReadValue(GPBCodedInputStream *stream, static void ReadValue(GPBCodedInputStream *stream,
GPBGenericValue *valueToFill, GPBGenericValue *valueToFill,
GPBDataType type, GPBDataType type,
GPBExtensionRegistry *registry, id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field) { GPBFieldDescriptor *field) {
switch (type) { switch (type) {
case GPBDataTypeBool: case GPBDataTypeBool:
@ -454,7 +454,7 @@ static void ReadValue(GPBCodedInputStream *stream,
void GPBDictionaryReadEntry(id mapDictionary, void GPBDictionaryReadEntry(id mapDictionary,
GPBCodedInputStream *stream, GPBCodedInputStream *stream,
GPBExtensionRegistry *registry, id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field, GPBFieldDescriptor *field,
GPBMessage *parentMessage) { GPBMessage *parentMessage) {
GPBDataType keyDataType = field.mapKeyDataType; GPBDataType keyDataType = field.mapKeyDataType;

@ -34,7 +34,7 @@
@class GPBCodedInputStream; @class GPBCodedInputStream;
@class GPBCodedOutputStream; @class GPBCodedOutputStream;
@class GPBExtensionRegistry; @protocol GPBExtensionRegistry;
@class GPBFieldDescriptor; @class GPBFieldDescriptor;
@protocol GPBDictionaryInternalsProtocol @protocol GPBDictionaryInternalsProtocol
@ -493,7 +493,7 @@ BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict,
// Helper to read a map instead. // Helper to read a map instead.
void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
GPBExtensionRegistry *registry, id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field, GPBFieldDescriptor *field,
GPBMessage *parentMessage); GPBMessage *parentMessage);

@ -34,12 +34,12 @@
@class GPBCodedInputStream; @class GPBCodedInputStream;
@class GPBCodedOutputStream; @class GPBCodedOutputStream;
@class GPBExtensionRegistry; @protocol GPBExtensionRegistry;
void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
BOOL isPackedOnStream, BOOL isPackedOnStream,
GPBCodedInputStream *input, GPBCodedInputStream *input,
GPBExtensionRegistry *extensionRegistry, id<GPBExtensionRegistry>extensionRegistry,
GPBMessage *message); GPBMessage *message);
size_t GPBComputeExtensionSerializedSizeIncludingTag( size_t GPBComputeExtensionSerializedSizeIncludingTag(

@ -40,7 +40,7 @@
static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension, static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension,
GPBCodedInputStream *input, GPBCodedInputStream *input,
GPBExtensionRegistry *extensionRegistry, id<GPBExtensionRegistry>extensionRegistry,
GPBMessage *existingValue) GPBMessage *existingValue)
__attribute__((ns_returns_retained)); __attribute__((ns_returns_retained));
@ -273,7 +273,7 @@ static void WriteArrayIncludingTagsToCodedOutputStream(
void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
BOOL isPackedOnStream, BOOL isPackedOnStream,
GPBCodedInputStream *input, GPBCodedInputStream *input,
GPBExtensionRegistry *extensionRegistry, id<GPBExtensionRegistry>extensionRegistry,
GPBMessage *message) { GPBMessage *message) {
GPBExtensionDescription *description = extension->description_; GPBExtensionDescription *description = extension->description_;
GPBCodedInputStreamState *state = &input->state_; GPBCodedInputStreamState *state = &input->state_;
@ -334,7 +334,7 @@ size_t GPBComputeExtensionSerializedSizeIncludingTag(
// Note that this returns a retained value intentionally. // Note that this returns a retained value intentionally.
static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension, static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension,
GPBCodedInputStream *input, GPBCodedInputStream *input,
GPBExtensionRegistry *extensionRegistry, id<GPBExtensionRegistry>extensionRegistry,
GPBMessage *existingValue) { GPBMessage *existingValue) {
GPBExtensionDescription *description = extension->description_; GPBExtensionDescription *description = extension->description_;
GPBCodedInputStreamState *state = &input->state_; GPBCodedInputStreamState *state = &input->state_;

@ -41,6 +41,24 @@ NS_ASSUME_NONNULL_BEGIN
* GPBExtensionRegistry in which you have registered any extensions that you * GPBExtensionRegistry in which you have registered any extensions that you
* want to be able to parse. Otherwise, those extensions will just be treated * want to be able to parse. Otherwise, those extensions will just be treated
* like unknown fields. * like unknown fields.
**/
@protocol GPBExtensionRegistry <NSObject>
/**
* Looks for the extension registered for the given field number on a given
* GPBDescriptor.
*
* @param descriptor The descriptor to look for a registered extension on.
* @param fieldNumber The field number of the extension to look for.
*
* @return The registered GPBExtensionDescriptor or nil if none was found.
**/
- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
fieldNumber:(NSInteger)fieldNumber;
@end
/**
* A concrete implementation of `GPBExtensionRegistry`.
* *
* The *Root classes provide `+extensionRegistry` for the extensions defined * The *Root classes provide `+extensionRegistry` for the extensions defined
* in a given file *and* all files it imports. You can also create a * in a given file *and* all files it imports. You can also create a
@ -54,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN
* MyMessage *msg = [MyMessage parseData:data extensionRegistry:registry error:&parseError]; * MyMessage *msg = [MyMessage parseData:data extensionRegistry:registry error:&parseError];
* ``` * ```
**/ **/
@interface GPBExtensionRegistry : NSObject<NSCopying> @interface GPBExtensionRegistry : NSObject<NSCopying, GPBExtensionRegistry>
/** /**
* Adds the given GPBExtensionDescriptor to this registry. * Adds the given GPBExtensionDescriptor to this registry.
@ -70,18 +88,6 @@ NS_ASSUME_NONNULL_BEGIN
**/ **/
- (void)addExtensions:(GPBExtensionRegistry *)registry; - (void)addExtensions:(GPBExtensionRegistry *)registry;
/**
* Looks for the extension registered for the given field number on a given
* GPBDescriptor.
*
* @param descriptor The descriptor to look for a registered extension on.
* @param fieldNumber The field number of the extension to look for.
*
* @return The registered GPBExtensionDescriptor or nil if none was found.
**/
- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
fieldNumber:(NSInteger)fieldNumber;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -31,12 +31,12 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "GPBBootstrap.h" #import "GPBBootstrap.h"
#import "GPBExtensionRegistry.h"
@class GPBDescriptor; @class GPBDescriptor;
@class GPBCodedInputStream; @class GPBCodedInputStream;
@class GPBCodedOutputStream; @class GPBCodedOutputStream;
@class GPBExtensionDescriptor; @class GPBExtensionDescriptor;
@class GPBExtensionRegistry;
@class GPBFieldDescriptor; @class GPBFieldDescriptor;
@class GPBUnknownFieldSet; @class GPBUnknownFieldSet;
@ -147,7 +147,7 @@ CF_EXTERN_C_END
* @return A new instance of the generated class. * @return A new instance of the generated class.
**/ **/
+ (nullable instancetype)parseFromData:(NSData *)data + (nullable instancetype)parseFromData:(NSData *)data
extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr; error:(NSError **)errorPtr;
/** /**
@ -171,7 +171,7 @@ CF_EXTERN_C_END
**/ **/
+ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input + (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry: extensionRegistry:
(nullable GPBExtensionRegistry *)extensionRegistry (nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr; error:(NSError **)errorPtr;
/** /**
@ -196,7 +196,7 @@ CF_EXTERN_C_END
**/ **/
+ (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input + (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry: extensionRegistry:
(nullable GPBExtensionRegistry *)extensionRegistry (nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr; error:(NSError **)errorPtr;
/** /**
@ -239,7 +239,7 @@ CF_EXTERN_C_END
* @return An initialized instance of the generated class. * @return An initialized instance of the generated class.
**/ **/
- (nullable instancetype)initWithData:(NSData *)data - (nullable instancetype)initWithData:(NSData *)data
extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr; error:(NSError **)errorPtr;
/** /**
@ -264,7 +264,7 @@ CF_EXTERN_C_END
**/ **/
- (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input - (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry: extensionRegistry:
(nullable GPBExtensionRegistry *)extensionRegistry (nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr; error:(NSError **)errorPtr;
/** /**
@ -278,7 +278,7 @@ CF_EXTERN_C_END
* unsuccessful. * unsuccessful.
**/ **/
- (void)mergeFromData:(NSData *)data - (void)mergeFromData:(NSData *)data
extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry;
/** /**
* Merges the fields from another message (of the same type) into this * Merges the fields from another message (of the same type) into this

@ -881,7 +881,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
} }
- (instancetype)initWithData:(NSData *)data - (instancetype)initWithData:(NSData *)data
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr { error:(NSError **)errorPtr {
if ((self = [self init])) { if ((self = [self init])) {
@try { @try {
@ -912,7 +912,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
- (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input - (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry: extensionRegistry:
(GPBExtensionRegistry *)extensionRegistry (id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr { error:(NSError **)errorPtr {
if ((self = [self init])) { if ((self = [self init])) {
@try { @try {
@ -1973,7 +1973,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
#pragma mark - mergeFrom #pragma mark - mergeFrom
- (void)mergeFromData:(NSData *)data - (void)mergeFromData:(NSData *)data
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data]; GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data];
[self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry]; [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry];
[input checkLastTagWas:0]; [input checkLastTagWas:0];
@ -1983,7 +1983,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
#pragma mark - mergeDelimitedFrom #pragma mark - mergeDelimitedFrom
- (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input - (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
GPBCodedInputStreamState *state = &input->state_; GPBCodedInputStreamState *state = &input->state_;
if (GPBCodedInputStreamIsAtEnd(state)) { if (GPBCodedInputStreamIsAtEnd(state)) {
return; return;
@ -2003,7 +2003,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
} }
+ (instancetype)parseFromData:(NSData *)data + (instancetype)parseFromData:(NSData *)data
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr { error:(NSError **)errorPtr {
return [[[self alloc] initWithData:data return [[[self alloc] initWithData:data
extensionRegistry:extensionRegistry extensionRegistry:extensionRegistry
@ -2011,7 +2011,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
} }
+ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input + (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr { error:(NSError **)errorPtr {
return return
[[[self alloc] initWithCodedInputStream:input [[[self alloc] initWithCodedInputStream:input
@ -2023,7 +2023,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
+ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input + (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry: extensionRegistry:
(GPBExtensionRegistry *)extensionRegistry (id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr { error:(NSError **)errorPtr {
GPBMessage *message = [[[self alloc] init] autorelease]; GPBMessage *message = [[[self alloc] init] autorelease];
@try { @try {
@ -2065,7 +2065,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
} }
- (void)parseMessageSet:(GPBCodedInputStream *)input - (void)parseMessageSet:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
uint32_t typeId = 0; uint32_t typeId = 0;
NSData *rawBytes = nil; NSData *rawBytes = nil;
GPBExtensionDescriptor *extension = nil; GPBExtensionDescriptor *extension = nil;
@ -2117,7 +2117,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
} }
- (BOOL)parseUnknownField:(GPBCodedInputStream *)input - (BOOL)parseUnknownField:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
tag:(uint32_t)tag { tag:(uint32_t)tag {
GPBWireFormat wireType = GPBWireFormatGetTagWireType(tag); GPBWireFormat wireType = GPBWireFormatGetTagWireType(tag);
int32_t fieldNumber = GPBWireFormatGetTagFieldNumber(tag); int32_t fieldNumber = GPBWireFormatGetTagFieldNumber(tag);
@ -2170,7 +2170,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
static void MergeSingleFieldFromCodedInputStream( static void MergeSingleFieldFromCodedInputStream(
GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax, GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) { GPBCodedInputStream *input, id<GPBExtensionRegistry>extensionRegistry) {
GPBDataType fieldDataType = GPBGetFieldDataType(field); GPBDataType fieldDataType = GPBGetFieldDataType(field);
switch (fieldDataType) { switch (fieldDataType) {
#define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \ #define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \
@ -2306,7 +2306,7 @@ static void MergeRepeatedPackedFieldFromCodedInputStream(
static void MergeRepeatedNotPackedFieldFromCodedInputStream( static void MergeRepeatedNotPackedFieldFromCodedInputStream(
GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax, GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) { GPBCodedInputStream *input, id<GPBExtensionRegistry>extensionRegistry) {
GPBCodedInputStreamState *state = &input->state_; GPBCodedInputStreamState *state = &input->state_;
id genericArray = GetOrCreateArrayIvarWithField(self, field); id genericArray = GetOrCreateArrayIvarWithField(self, field);
switch (GPBGetFieldDataType(field)) { switch (GPBGetFieldDataType(field)) {
@ -2371,7 +2371,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
} }
- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input - (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
GPBDescriptor *descriptor = [self descriptor]; GPBDescriptor *descriptor = [self descriptor];
GPBFileSyntax syntax = descriptor.file.syntax; GPBFileSyntax syntax = descriptor.file.syntax;
GPBCodedInputStreamState *state = &input->state_; GPBCodedInputStreamState *state = &input->state_;

@ -78,13 +78,13 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr;
// or zero for EOF. // or zero for EOF.
// NOTE: This will throw if there is an error while parsing. // NOTE: This will throw if there is an error while parsing.
- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input - (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry; extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry;
// Parses the next delimited message of this type from the input and merges it // Parses the next delimited message of this type from the input and merges it
// with this message. // with this message.
- (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input - (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry: extensionRegistry:
(GPBExtensionRegistry *)extensionRegistry; (id<GPBExtensionRegistry>)extensionRegistry;
- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data; - (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data;

@ -10,11 +10,11 @@
<email>protobuf-packages@google.com</email> <email>protobuf-packages@google.com</email>
<active>yes</active> <active>yes</active>
</lead> </lead>
<date>2022-08-09</date> <date>2022-09-13</date>
<time>09:24:23</time> <time>13:50:07</time>
<version> <version>
<release>3.21.5</release> <release>3.21.6</release>
<api>3.21.5</api> <api>3.21.6</api>
</version> </version>
<stability> <stability>
<release>stable</release> <release>stable</release>
@ -1403,5 +1403,20 @@ G A release.
<notes> <notes>
</notes> </notes>
</release> </release>
<release>
<version>
<release>3.21.6</release>
<api>3.21.6</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2022-09-13</date>
<time>13:50:07</time>
<license uri="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</license>
<notes>
</notes>
</release>
</changelog> </changelog>
</package> </package>

@ -127,7 +127,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1)
ZEND_ARG_INFO(0, value) ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
#define PHP_PROTOBUF_VERSION "3.21.5" #define PHP_PROTOBUF_VERSION "3.21.6"
// ptr -> PHP object cache. This is a weak map that caches lazily-created // ptr -> PHP object cache. This is a weak map that caches lazily-created
// wrapper objects around upb types: // wrapper objects around upb types:

@ -5,7 +5,9 @@
set -e set -e
PROTOC=$(realpath protoc) if [[ -z "${PROTOC}" ]]; then
PROTOC=$(realpath protoc)
fi
if [ ! -f $PROTOC ]; then if [ ! -f $PROTOC ]; then
bazel build -c opt //:protoc bazel build -c opt //:protoc
PROTOC=$(realpath bazel-bin/protoc) PROTOC=$(realpath bazel-bin/protoc)

@ -4,7 +4,9 @@ set -ex
cd `dirname $0`/.. cd `dirname $0`/..
PROTOC=$(pwd)/protoc if [[ -z "${PROTOC}" ]]; then
PROTOC=$(pwd)/protoc
fi
if [ ! -f $PROTOC ]; then if [ ! -f $PROTOC ]; then
bazel build -c opt //:protoc bazel build -c opt //:protoc
PROTOC=$(pwd)/bazel-bin/protoc PROTOC=$(pwd)/bazel-bin/protoc

@ -53,6 +53,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
*/ */
protected $deprecated = null; protected $deprecated = null;
/** /**
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* Whether the message is an automatically generated map entry type for the * Whether the message is an automatically generated map entry type for the
* maps field. * maps field.
* For maps fields: * For maps fields:
@ -68,9 +71,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* use a native map in the target language to hold the keys and values. * use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as * The reflection APIs in such implementations still need to work as
* if the field is a repeated message field. * if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* *
* Generated from protobuf field <code>optional bool map_entry = 7;</code> * Generated from protobuf field <code>optional bool map_entry = 7;</code>
*/ */
@ -114,6 +114,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* for the message, or it will be completely ignored; in the very least, * for the message, or it will be completely ignored; in the very least,
* this is a formalization for deprecating messages. * this is a formalization for deprecating messages.
* @type bool $map_entry * @type bool $map_entry
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* Whether the message is an automatically generated map entry type for the * Whether the message is an automatically generated map entry type for the
* maps field. * maps field.
* For maps fields: * For maps fields:
@ -129,9 +132,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* use a native map in the target language to hold the keys and values. * use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as * The reflection APIs in such implementations still need to work as
* if the field is a repeated message field. * if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option * @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above. * The parser stores options it doesn't recognize here. See above.
* } * }
@ -288,6 +288,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
} }
/** /**
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* Whether the message is an automatically generated map entry type for the * Whether the message is an automatically generated map entry type for the
* maps field. * maps field.
* For maps fields: * For maps fields:
@ -303,9 +306,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* use a native map in the target language to hold the keys and values. * use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as * The reflection APIs in such implementations still need to work as
* if the field is a repeated message field. * if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* *
* Generated from protobuf field <code>optional bool map_entry = 7;</code> * Generated from protobuf field <code>optional bool map_entry = 7;</code>
* @return bool * @return bool
@ -326,6 +326,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
} }
/** /**
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* Whether the message is an automatically generated map entry type for the * Whether the message is an automatically generated map entry type for the
* maps field. * maps field.
* For maps fields: * For maps fields:
@ -341,9 +344,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* use a native map in the target language to hold the keys and values. * use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as * The reflection APIs in such implementations still need to work as
* if the field is a repeated message field. * if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* *
* Generated from protobuf field <code>optional bool map_entry = 7;</code> * Generated from protobuf field <code>optional bool map_entry = 7;</code>
* @param bool $var * @param bool $var

@ -365,7 +365,8 @@ cc_dist_library(
}), }),
tags = ["manual"], tags = ["manual"],
deps = [ deps = [
"//src/google/protobuf", "//src/google/protobuf:wkt_cc_proto",
"//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf:arena", "//src/google/protobuf:arena",
"//src/google/protobuf:protobuf_lite", "//src/google/protobuf:protobuf_lite",
"//src/google/protobuf/compiler:importer", "//src/google/protobuf/compiler:importer",

@ -1,3 +1,3 @@
PROTOC_VERSION = '21.5' PROTOC_VERSION = '21.6'
PROTOBUF_JAVA_VERSION = '3.21.5' PROTOBUF_JAVA_VERSION = '3.21.6'
PROTOBUF_PYTHON_VERSION = '4.21.5' PROTOBUF_PYTHON_VERSION = '4.21.6'

@ -8,7 +8,7 @@
</parent> </parent>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protoc</artifactId> <artifactId>protoc</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Protobuf Compiler</name> <name>Protobuf Compiler</name>
<description> <description>

@ -109,7 +109,8 @@ def MessageToJson(
names as defined in the .proto file. If False, convert the field names as defined in the .proto file. If False, convert the field
names to lowerCamelCase. names to lowerCamelCase.
indent: The JSON object will be pretty-printed with this indent level. indent: The JSON object will be pretty-printed with this indent level.
An indent level of 0 or negative will only insert newlines. An indent level of 0 or negative will only insert newlines. If the
indent level is None, no newlines will be inserted.
sort_keys: If True, then the output will be sorted by field names. sort_keys: If True, then the output will be sorted by field names.
use_integers_for_enums: If true, print integers instead of enum names. use_integers_for_enums: If true, print integers instead of enum names.
descriptor_pool: A Descriptor Pool for resolving types. If None use the descriptor_pool: A Descriptor Pool for resolving types. If None use the

@ -58,6 +58,37 @@
: 0) \ : 0) \
: PyBytes_AsStringAndSize(ob, (charpp), (sizep))) : PyBytes_AsStringAndSize(ob, (charpp), (sizep)))
#if PY_VERSION_HEX < 0x030900B1 && !defined(PYPY_VERSION)
static PyCodeObject* PyFrame_GetCode(PyFrameObject *frame)
{
Py_INCREF(frame->f_code);
return frame->f_code;
}
static PyFrameObject* PyFrame_GetBack(PyFrameObject *frame)
{
Py_XINCREF(frame->f_back);
return frame->f_back;
}
#endif
#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
static PyObject* PyFrame_GetLocals(PyFrameObject *frame)
{
if (PyFrame_FastToLocalsWithError(frame) < 0) {
return NULL;
}
Py_INCREF(frame->f_locals);
return frame->f_locals;
}
static PyObject* PyFrame_GetGlobals(PyFrameObject *frame)
{
Py_INCREF(frame->f_globals);
return frame->f_globals;
}
#endif
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace python { namespace python {
@ -96,48 +127,66 @@ bool _CalledFromGeneratedFile(int stacklevel) {
// This check is not critical and is somewhat difficult to implement correctly // This check is not critical and is somewhat difficult to implement correctly
// in PyPy. // in PyPy.
PyFrameObject* frame = PyEval_GetFrame(); PyFrameObject* frame = PyEval_GetFrame();
PyCodeObject* frame_code = nullptr;
PyObject* frame_globals = nullptr;
PyObject* frame_locals = nullptr;
bool result = false;
if (frame == nullptr) { if (frame == nullptr) {
return false; goto exit;
} }
Py_INCREF(frame);
while (stacklevel-- > 0) { while (stacklevel-- > 0) {
frame = frame->f_back; PyFrameObject* next_frame = PyFrame_GetBack(frame);
Py_DECREF(frame);
frame = next_frame;
if (frame == nullptr) { if (frame == nullptr) {
return false; goto exit;
} }
} }
if (frame->f_code->co_filename == nullptr) { frame_code = PyFrame_GetCode(frame);
return false; if (frame_code->co_filename == nullptr) {
goto exit;
} }
char* filename; char* filename;
Py_ssize_t filename_size; Py_ssize_t filename_size;
if (PyString_AsStringAndSize(frame->f_code->co_filename, if (PyString_AsStringAndSize(frame_code->co_filename,
&filename, &filename_size) < 0) { &filename, &filename_size) < 0) {
// filename is not a string. // filename is not a string.
PyErr_Clear(); PyErr_Clear();
return false; goto exit;
} }
if ((filename_size < 3) || if ((filename_size < 3) ||
(strcmp(&filename[filename_size - 3], ".py") != 0)) { (strcmp(&filename[filename_size - 3], ".py") != 0)) {
// Cython's stack does not have .py file name and is not at global module // Cython's stack does not have .py file name and is not at global module
// scope. // scope.
return true; result = true;
goto exit;
} }
if (filename_size < 7) { if (filename_size < 7) {
// filename is too short. // filename is too short.
return false; goto exit;
} }
if (strcmp(&filename[filename_size - 7], "_pb2.py") != 0) { if (strcmp(&filename[filename_size - 7], "_pb2.py") != 0) {
// Filename is not ending with _pb2. // Filename is not ending with _pb2.
return false; goto exit;
} }
if (frame->f_globals != frame->f_locals) { frame_globals = PyFrame_GetGlobals(frame);
frame_locals = PyFrame_GetLocals(frame);
if (frame_globals != frame_locals) {
// Not at global module scope // Not at global module scope
return false; goto exit;
} }
#endif #endif
return true; result = true;
exit:
Py_XDECREF(frame_globals);
Py_XDECREF(frame_locals);
Py_XDECREF(frame_code);
Py_XDECREF(frame);
return result;
} }
// If the calling code is not a _pb2.py file, raise AttributeError. // If the calling code is not a _pb2.py file, raise AttributeError.

@ -45,7 +45,6 @@
#include "google/protobuf/pyext/message_factory.h" #include "google/protobuf/pyext/message_factory.h"
#include "google/protobuf/pyext/repeated_composite_container.h" #include "google/protobuf/pyext/repeated_composite_container.h"
#include "google/protobuf/pyext/scoped_pyobject_ptr.h" #include "google/protobuf/pyext/scoped_pyobject_ptr.h"
#include "util/gtl/map_util.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {

@ -42,7 +42,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "google/protobuf/stubs/strutil.h" #include "absl/strings/match.h"
#ifndef PyVarObject_HEAD_INIT #ifndef PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, #define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
@ -70,11 +70,11 @@
#include "google/protobuf/pyext/unknown_field_set.h" #include "google/protobuf/pyext/unknown_field_set.h"
#include "google/protobuf/pyext/unknown_fields.h" #include "google/protobuf/pyext/unknown_fields.h"
#include "google/protobuf/util/message_differencer.h" #include "google/protobuf/util/message_differencer.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/strtod.h" #include "google/protobuf/io/strtod.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "util/gtl/map_util.h"
// clang-format off // clang-format off
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"
@ -410,7 +410,7 @@ static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) {
Py_ssize_t attr_size; Py_ssize_t attr_size;
static const char kSuffix[] = "_FIELD_NUMBER"; static const char kSuffix[] = "_FIELD_NUMBER";
if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 && if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 &&
HasSuffixString(absl::string_view(attr, attr_size), kSuffix)) { absl::EndsWith(absl::string_view(attr, attr_size), kSuffix)) {
std::string field_name(attr, attr_size - sizeof(kSuffix) + 1); std::string field_name(attr, attr_size - sizeof(kSuffix) + 1);
LowerString(&field_name); LowerString(&field_name);
@ -2678,22 +2678,22 @@ CMessage* CMessage::BuildSubMessageFromPointer(
if (!this->child_submessages) { if (!this->child_submessages) {
this->child_submessages = new CMessage::SubMessagesMap(); this->child_submessages = new CMessage::SubMessagesMap();
} }
CMessage* cmsg = gtl::FindPtrOrNull( auto it = this->child_submessages->find(sub_message);
*this->child_submessages, sub_message); if (it != this->child_submessages->end()) {
if (cmsg) { Py_INCREF(it->second);
Py_INCREF(cmsg); return it->second;
} else { }
cmsg = cmessage::NewEmptyMessage(message_class);
if (cmsg == nullptr) { CMessage* cmsg = cmessage::NewEmptyMessage(message_class);
return nullptr;
} if (cmsg == nullptr) {
cmsg->message = sub_message; return nullptr;
Py_INCREF(this);
cmsg->parent = this;
cmsg->parent_field_descriptor = field_descriptor;
cmessage::SetSubmessage(this, cmsg);
} }
cmsg->message = sub_message;
Py_INCREF(this);
cmsg->parent = this;
cmsg->parent_field_descriptor = field_descriptor;
cmessage::SetSubmessage(this, cmsg);
return cmsg; return cmsg;
} }
@ -2701,11 +2701,10 @@ CMessage* CMessage::MaybeReleaseSubMessage(Message* sub_message) {
if (!this->child_submessages) { if (!this->child_submessages) {
return nullptr; return nullptr;
} }
CMessage* released = gtl::FindPtrOrNull( auto it = this->child_submessages->find(sub_message);
*this->child_submessages, sub_message); if (it == this->child_submessages->end()) return nullptr;
if (!released) { CMessage* released = it->second;
return nullptr;
}
// The target message will now own its content. // The target message will now own its content.
Py_CLEAR(released->parent); Py_CLEAR(released->parent);
released->parent_field_descriptor = nullptr; released->parent_field_descriptor = nullptr;

@ -46,7 +46,6 @@
#include "google/protobuf/pyext/message.h" #include "google/protobuf/pyext/message.h"
#include "google/protobuf/pyext/message_factory.h" #include "google/protobuf/pyext/message_factory.h"
#include "google/protobuf/pyext/scoped_pyobject_ptr.h" #include "google/protobuf/pyext/scoped_pyobject_ptr.h"
#include "util/gtl/map_util.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {

@ -1013,6 +1013,8 @@ class _Parser(object):
if not tokenizer.TryConsume(','): if not tokenizer.TryConsume(','):
tokenizer.TryConsume(';') tokenizer.TryConsume(';')
def _LogSilentMarker(self, field_name):
pass pass
def _DetectSilentMarker(self, tokenizer, field_name): def _DetectSilentMarker(self, tokenizer, field_name):

@ -1,6 +1,6 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "google-protobuf" s.name = "google-protobuf"
s.version = "3.21.5" s.version = "3.21.6"
git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag
s.licenses = ["BSD-3-Clause"] s.licenses = ["BSD-3-Clause"]
s.summary = "Protocol Buffers" s.summary = "Protocol Buffers"

@ -9,7 +9,7 @@
<groupId>com.google.protobuf.jruby</groupId> <groupId>com.google.protobuf.jruby</groupId>
<artifactId>protobuf-jruby</artifactId> <artifactId>protobuf-jruby</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
<name>Protocol Buffer JRuby native extension</name> <name>Protocol Buffer JRuby native extension</name>
<description> <description>
Protocol Buffers are a way of encoding structured data in an efficient yet Protocol Buffers are a way of encoding structured data in an efficient yet
@ -76,7 +76,7 @@
<dependency> <dependency>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId> <artifactId>protobuf-java-util</artifactId>
<version>3.21.5</version> <version>3.21.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jruby</groupId> <groupId>org.jruby</groupId>

@ -11,10 +11,18 @@ endif()
# //pkg:protobuf # //pkg:protobuf
set(libprotobuf_srcs set(libprotobuf_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/any.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/any.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc
@ -24,12 +32,9 @@ set(libprotobuf_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_heavy.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_heavy.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_bases.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_bases.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_reflection.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_reflection.cc
@ -58,16 +63,12 @@ set(libprotobuf_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/service.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/service.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.cc
@ -91,14 +92,21 @@ set(libprotobuf_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.cc
) )
# //pkg:protobuf # //pkg:protobuf
set(libprotobuf_hdrs set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/any.h
${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/any.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h
@ -109,15 +117,12 @@ set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.h ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.h
${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database.h ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database.h
${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.h ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.h
${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/endian.h ${protobuf_SOURCE_DIR}/src/google/protobuf/endian.h
${protobuf_SOURCE_DIR}/src/google/protobuf/explicitly_constructed.h ${protobuf_SOURCE_DIR}/src/google/protobuf/explicitly_constructed.h
${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.h ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.h
${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_inl.h ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_inl.h
${protobuf_SOURCE_DIR}/src/google/protobuf/field_access_listener.h ${protobuf_SOURCE_DIR}/src/google/protobuf/field_access_listener.h
${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_reflection.h ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_reflection.h
${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_bases.h ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_bases.h
@ -158,8 +163,6 @@ set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.h ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.h ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/service.h ${protobuf_SOURCE_DIR}/src/google/protobuf/service.h
${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h
@ -172,8 +175,6 @@ set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.h
${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h
${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.h ${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.h
${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.h ${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.h
${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.h
@ -202,7 +203,6 @@ set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util.h
${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format.h ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format.h
${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.h
) )
# //pkg:protobuf_lite # //pkg:protobuf_lite
@ -456,6 +456,7 @@ set(libprotoc_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_message_field.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_message_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_oneof.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_oneof.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_options.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.h

@ -81,6 +81,57 @@ proto_library(
strip_import_prefix = "/src", strip_import_prefix = "/src",
) )
# Generate code for the well-known types on demand.
# This needs to be done in a separate genrule because we publish protoc and the
# C++ runtime with the WKT code linked in. We need to use a stripped down
# compiler and runtime library to generate them, and cc_proto_library doesn't
# support swapping out the compiler binary (even though a custom runtime can
# be passed to proto_lang_toolchain).
#
# TODO(b/246826624) We still check in generated pb.h and pb.cc files purely to
# support CMake builds. These aren't used at all by Bazel and will be removed
# in the future once CMake can generate them too.
WELL_KNOWN_TYPES = [
"any",
"api",
"duration",
"empty",
"field_mask",
"source_context",
"struct",
"timestamp",
"type",
"wrappers",
]
genrule(
name = "gen_wkt_cc_sources",
srcs = [wkt + ".proto" for wkt in WELL_KNOWN_TYPES],
exec_tools = ["//src/google/protobuf/compiler:protoc_nowkt"],
outs =
[wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] +
[wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
cmd = """
$(execpath //src/google/protobuf/compiler:protoc_nowkt) \
--cpp_out=$(RULEDIR)/../.. \
--proto_path=$$(dirname $$(dirname $$(dirname $(location any.proto)))) \
$(SRCS)
""",
visibility = ["//visibility:private"],
)
cc_library(
name = "wkt_cc_proto",
srcs = [wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES],
hdrs = [wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES],
deps = [":protobuf_nowkt"],
copts = COPTS,
include_prefix = "google/protobuf",
linkopts = LINK_OPTS,
visibility = ["//pkg:__pkg__"],
)
# Built-in runtime types # Built-in runtime types
proto_library( proto_library(
@ -211,19 +262,14 @@ cc_library(
) )
cc_library( cc_library(
name = "protobuf", name = "protobuf_nowkt",
srcs = [ srcs = [
"any.cc", "any.cc",
"any.pb.cc",
"api.pb.cc",
"descriptor.cc", "descriptor.cc",
"descriptor.pb.cc", "descriptor.pb.cc",
"descriptor_database.cc", "descriptor_database.cc",
"duration.pb.cc",
"dynamic_message.cc", "dynamic_message.cc",
"empty.pb.cc",
"extension_set_heavy.cc", "extension_set_heavy.cc",
"field_mask.pb.cc",
"generated_message_bases.cc", "generated_message_bases.cc",
"generated_message_reflection.cc", "generated_message_reflection.cc",
"generated_message_tctable_full.cc", "generated_message_tctable_full.cc",
@ -232,26 +278,16 @@ cc_library(
"message.cc", "message.cc",
"reflection_ops.cc", "reflection_ops.cc",
"service.cc", "service.cc",
"source_context.pb.cc",
"struct.pb.cc",
"text_format.cc", "text_format.cc",
"timestamp.pb.cc",
"type.pb.cc",
"unknown_field_set.cc", "unknown_field_set.cc",
"wire_format.cc", "wire_format.cc",
"wrappers.pb.cc",
], ],
hdrs = [ hdrs = [
"any.pb.h",
"api.pb.h",
"descriptor.h", "descriptor.h",
"descriptor.pb.h", "descriptor.pb.h",
"descriptor_database.h", "descriptor_database.h",
"duration.pb.h",
"dynamic_message.h", "dynamic_message.h",
"empty.pb.h",
"field_access_listener.h", "field_access_listener.h",
"field_mask.pb.h",
"generated_enum_reflection.h", "generated_enum_reflection.h",
"generated_message_bases.h", "generated_message_bases.h",
"generated_message_reflection.h", "generated_message_reflection.h",
@ -265,25 +301,19 @@ cc_library(
"reflection_internal.h", "reflection_internal.h",
"reflection_ops.h", "reflection_ops.h",
"service.h", "service.h",
"source_context.pb.h",
"struct.pb.h",
"text_format.h", "text_format.h",
"timestamp.pb.h",
"type.pb.h",
"unknown_field_set.h", "unknown_field_set.h",
"wire_format.h", "wire_format.h",
"wrappers.pb.h",
], ],
copts = COPTS, copts = COPTS,
include_prefix = "google/protobuf", include_prefix = "google/protobuf",
linkopts = LINK_OPTS, linkopts = LINK_OPTS,
visibility = [ visibility = [
"//:__pkg__",
"//pkg:__pkg__", "//pkg:__pkg__",
"//src/google/protobuf:__subpackages__", "//src/google/protobuf:__subpackages__",
], ],
deps = [ deps = [
":protobuf_lite", ":protobuf_lite",
"//src/google/protobuf/io", "//src/google/protobuf/io",
"//src/google/protobuf/io:gzip_stream", "//src/google/protobuf/io:gzip_stream",
"//src/google/protobuf/io:printer", "//src/google/protobuf/io:printer",
@ -300,6 +330,22 @@ cc_library(
], ],
) )
cc_library(
name = "protobuf",
deps = [
":protobuf_nowkt",
":wkt_cc_proto",
],
copts = COPTS,
include_prefix = "google/protobuf",
linkopts = LINK_OPTS,
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
"//src/google/protobuf:__subpackages__",
],
)
# This provides just the header files for use in projects that need to build # This provides just the header files for use in projects that need to build
# shared libraries for dynamic loading. This target is available until Bazel # shared libraries for dynamic loading. This target is available until Bazel
# adds native support for such use cases. # adds native support for such use cases.

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update #error incompatible with your Protocol Buffer headers. Please update
#error your headers. #error your headers.
#endif #endif
#if 3021005 < PROTOBUF_MIN_PROTOC_VERSION #if 3021006 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is #error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please #error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc. #error regenerate this file with a newer version of protoc.

@ -29,7 +29,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "google/protobuf/stubs/strutil.h" #include "absl/strings/match.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/any.h" #include "google/protobuf/any.h"
#include "google/protobuf/arenastring.h" #include "google/protobuf/arenastring.h"
@ -72,7 +72,7 @@ bool AnyMetadata::InternalIs(absl::string_view type_name) const {
absl::string_view type_url = type_url_->Get(); absl::string_view type_url = type_url_->Get();
return type_url.size() >= type_name.size() + 1 && return type_url.size() >= type_name.size() + 1 &&
type_url[type_url.size() - type_name.size() - 1] == '/' && type_url[type_url.size() - type_name.size() - 1] == '/' &&
HasSuffixString(type_url, type_name); absl::EndsWith(type_url, type_name);
} }
bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix, bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix,

@ -13,7 +13,7 @@
#error incompatible with your Protocol Buffer headers. Please update #error incompatible with your Protocol Buffer headers. Please update
#error your headers. #error your headers.
#endif #endif
#if 3021005 < PROTOBUF_MIN_PROTOC_VERSION #if 3021006 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is #error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please #error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc. #error regenerate this file with a newer version of protoc.

@ -105,7 +105,7 @@ class GetDeallocator {
size_t* space_allocated_; size_t* space_allocated_;
}; };
SerialArena::SerialArena(Block* b, ThreadSafeArena& parent) SerialArena::SerialArena(ArenaBlock* b, ThreadSafeArena& parent)
: parent_(parent), space_allocated_(b->size()) { : parent_(parent), space_allocated_(b->size()) {
set_head(b); set_head(b);
set_ptr(b->Pointer(kBlockHeaderSize + ThreadSafeArena::kSerialArenaSize)); set_ptr(b->Pointer(kBlockHeaderSize + ThreadSafeArena::kSerialArenaSize));
@ -117,13 +117,13 @@ SerialArena* SerialArena::New(Memory mem, ThreadSafeArena& parent) {
ThreadSafeArenaStats::RecordAllocateStats(parent.arena_stats_.MutableStats(), ThreadSafeArenaStats::RecordAllocateStats(parent.arena_stats_.MutableStats(),
/*used=*/0, /*allocated=*/mem.size, /*used=*/0, /*allocated=*/mem.size,
/*wasted=*/0); /*wasted=*/0);
auto b = new (mem.ptr) Block{nullptr, mem.size}; auto b = new (mem.ptr) ArenaBlock{nullptr, mem.size};
return new (b->Pointer(kBlockHeaderSize)) SerialArena(b, parent); return new (b->Pointer(kBlockHeaderSize)) SerialArena(b, parent);
} }
template <typename Deallocator> template <typename Deallocator>
SerialArena::Memory SerialArena::Free(Deallocator deallocator) { SerialArena::Memory SerialArena::Free(Deallocator deallocator) {
Block* b = head(); ArenaBlock* b = head();
Memory mem = {b, b->size()}; Memory mem = {b, b->size()};
while (b->next) { while (b->next) {
b = b->next; // We must first advance before deleting this block b = b->next; // We must first advance before deleting this block
@ -179,7 +179,7 @@ void SerialArena::AllocateNewBlock(size_t n) {
ThreadSafeArenaStats::RecordAllocateStats(parent_.arena_stats_.MutableStats(), ThreadSafeArenaStats::RecordAllocateStats(parent_.arena_stats_.MutableStats(),
/*used=*/used, /*used=*/used,
/*allocated=*/mem.size, wasted); /*allocated=*/mem.size, wasted);
set_head(new (mem.ptr) Block{head(), mem.size}); set_head(new (mem.ptr) ArenaBlock{head(), mem.size});
set_ptr(head()->Pointer(kBlockHeaderSize)); set_ptr(head()->Pointer(kBlockHeaderSize));
limit_ = head()->Pointer(head()->size()); limit_ = head()->Pointer(head()->size());
@ -199,7 +199,7 @@ uint64_t SerialArena::SpaceUsed() const {
const uint64_t current_block_size = head()->size(); const uint64_t current_block_size = head()->size();
uint64_t space_used = std::min( uint64_t space_used = std::min(
static_cast<uint64_t>( static_cast<uint64_t>(
ptr() - const_cast<Block*>(head())->Pointer(kBlockHeaderSize)), ptr() - const_cast<ArenaBlock*>(head())->Pointer(kBlockHeaderSize)),
current_block_size); current_block_size);
space_used += space_used_.load(std::memory_order_relaxed); space_used += space_used_.load(std::memory_order_relaxed);
// Remove the overhead of the SerialArena itself. // Remove the overhead of the SerialArena itself.
@ -208,7 +208,7 @@ uint64_t SerialArena::SpaceUsed() const {
} }
void SerialArena::CleanupList() { void SerialArena::CleanupList() {
Block* b = head(); ArenaBlock* b = head();
b->cleanup_nodes = limit_; b->cleanup_nodes = limit_;
do { do {
char* limit = reinterpret_cast<char*>( char* limit = reinterpret_cast<char*>(

@ -252,9 +252,6 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
inline ~Arena() {} inline ~Arena() {}
// TODO(protobuf-team): Fix callers to use constructor and delete this method.
void Init(const ArenaOptions&) {}
// API to create proto2 message objects on the arena. If the arena passed in // API to create proto2 message objects on the arena. If the arena passed in
// is nullptr, then a heap allocated object is returned. Type T must be a // is nullptr, then a heap allocated object is returned. Type T must be a
// message defined in a .proto file with cc_enable_arenas set to true, // message defined in a .proto file with cc_enable_arenas set to true,

@ -90,6 +90,29 @@ inline PROTOBUF_ALWAYS_INLINE void* AlignTo(void* p, size_t a) {
} }
} }
// Arena blocks are variable length malloc-ed objects. The following structure
// describes the common header for all blocks.
struct ArenaBlock {
ArenaBlock(ArenaBlock* next, size_t size)
: next(next), cleanup_nodes(nullptr), relaxed_size(size) {
GOOGLE_DCHECK_GT(size, sizeof(ArenaBlock));
}
char* Pointer(size_t n) {
GOOGLE_DCHECK(n <= size());
return reinterpret_cast<char*>(this) + n;
}
size_t size() const { return relaxed_size.load(std::memory_order_relaxed); }
ArenaBlock* const next;
void* cleanup_nodes;
private:
const std::atomic<size_t> relaxed_size;
// data follows
};
namespace cleanup { namespace cleanup {
template <typename T> template <typename T>
@ -545,29 +568,8 @@ class PROTOBUF_EXPORT SerialArena {
template <typename Deallocator> template <typename Deallocator>
Memory Free(Deallocator deallocator); Memory Free(Deallocator deallocator);
// Blocks are variable length malloc-ed objects. The following structure
// describes the common header for all blocks.
struct Block {
Block(Block* next, size_t size)
: next(next), cleanup_nodes(nullptr), relaxed_size(size) {}
char* Pointer(size_t n) {
GOOGLE_DCHECK(n <= size());
return reinterpret_cast<char*>(this) + n;
}
size_t size() const { return relaxed_size.load(std::memory_order_relaxed); }
Block* const next;
void* cleanup_nodes;
private:
const std::atomic<size_t> relaxed_size;
// data follows
};
ThreadSafeArena& parent_; ThreadSafeArena& parent_;
std::atomic<Block*> head_; // Head of linked list of blocks. std::atomic<ArenaBlock*> head_; // Head of linked list of blocks.
std::atomic<size_t> space_used_{0}; // Necessary for metrics. std::atomic<size_t> space_used_{0}; // Necessary for metrics.
std::atomic<size_t> space_allocated_; std::atomic<size_t> space_allocated_;
@ -577,9 +579,11 @@ class PROTOBUF_EXPORT SerialArena {
std::atomic<char*> ptr_; std::atomic<char*> ptr_;
// Helper getters/setters to handle relaxed operations on atomic variables. // Helper getters/setters to handle relaxed operations on atomic variables.
Block* head() { return head_.load(std::memory_order_relaxed); } ArenaBlock* head() { return head_.load(std::memory_order_relaxed); }
const Block* head() const { return head_.load(std::memory_order_relaxed); } const ArenaBlock* head() const {
void set_head(Block* head) { return head_.load(std::memory_order_relaxed);
}
void set_head(ArenaBlock* head) {
return head_.store(head, std::memory_order_relaxed); return head_.store(head, std::memory_order_relaxed);
} }
char* ptr() { return ptr_.load(std::memory_order_relaxed); } char* ptr() { return ptr_.load(std::memory_order_relaxed); }
@ -604,7 +608,8 @@ class PROTOBUF_EXPORT SerialArena {
CachedBlock** cached_blocks_ = nullptr; CachedBlock** cached_blocks_ = nullptr;
// Constructor is private as only New() should be used. // Constructor is private as only New() should be used.
inline SerialArena(Block* b, ThreadSafeArena& parent); inline SerialArena(ArenaBlock* b, ThreadSafeArena& parent);
void* AllocateAlignedFallback(size_t n); void* AllocateAlignedFallback(size_t n);
void* AllocateAlignedWithCleanupFallback(size_t n, size_t align, void* AllocateAlignedWithCleanupFallback(size_t n, size_t align,
void (*destructor)(void*)); void (*destructor)(void*));
@ -612,7 +617,7 @@ class PROTOBUF_EXPORT SerialArena {
void AllocateNewBlock(size_t n); void AllocateNewBlock(size_t n);
public: public:
static constexpr size_t kBlockHeaderSize = AlignUpTo8(sizeof(Block)); static constexpr size_t kBlockHeaderSize = AlignUpTo8(sizeof(ArenaBlock));
}; };
// Tag type used to invoke the constructor of message-owned arena. // Tag type used to invoke the constructor of message-owned arena.

@ -11,7 +11,7 @@ load(
) )
load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_proto//proto:defs.bzl", "proto_library")
load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test") load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test")
load("//build_defs:cpp_opts.bzl", "COPTS") load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
proto_library( proto_library(
name = "plugin_proto", name = "plugin_proto",
@ -37,7 +37,7 @@ cc_library(
include_prefix = "google/protobuf/compiler", include_prefix = "google/protobuf/compiler",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//src/google/protobuf", "//src/google/protobuf:protobuf_nowkt",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
], ],
) )
@ -59,7 +59,7 @@ cc_library(
include_prefix = "google/protobuf/compiler", include_prefix = "google/protobuf/compiler",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//:protobuf", "//src/google/protobuf:protobuf_nowkt",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
], ],
) )
@ -82,26 +82,22 @@ cc_library(
deps = [ deps = [
":code_generator", ":code_generator",
":importer", ":importer",
"//:protobuf", "//src/google/protobuf:protobuf_nowkt",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
], ],
) )
cc_library( cc_library(
name = "protoc_lib", name = "protoc_lib_nowkt",
srcs = [ srcs = [
"main.cc", "main.cc",
], ],
copts = COPTS, copts = COPTS,
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
],
deps = [ deps = [
":code_generator", ":code_generator",
":command_line_interface", ":command_line_interface",
":importer", ":importer",
"//:protobuf", "//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/compiler/cpp", "//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/csharp", "//src/google/protobuf/compiler/csharp",
"//src/google/protobuf/compiler/java", "//src/google/protobuf/compiler/java",
@ -112,6 +108,29 @@ cc_library(
], ],
) )
cc_binary(
name = "protoc_nowkt",
copts = COPTS,
linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
visibility = [
"//src/google/protobuf:__pkg__",
],
deps = [":protoc_lib_nowkt"],
)
cc_library(
name = "protoc_lib",
copts = COPTS,
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
],
deps = [
"//:protobuf",
":protoc_lib_nowkt",
],
)
# Note: this is an alias for now. In the future, this rule will become the # Note: this is an alias for now. In the future, this rule will become the
# cc_binary for protoc, and //:protoc will become an alias. # cc_binary for protoc, and //:protoc will become an alias.
alias( alias(

@ -38,8 +38,8 @@
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/compiler/plugin.pb.h" #include "google/protobuf/compiler/plugin.pb.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
#include "absl/strings/strip.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {
@ -126,10 +126,10 @@ void ParseGeneratorParameter(
// Strips ".proto" or ".protodevel" from the end of a filename. // Strips ".proto" or ".protodevel" from the end of a filename.
std::string StripProto(const std::string& filename) { std::string StripProto(const std::string& filename) {
if (HasSuffixString(filename, ".protodevel")) { if (absl::EndsWith(filename, ".protodevel")) {
return StripSuffixString(filename, ".protodevel"); return std::string(absl::StripSuffix(filename, ".protodevel"));
} else { } else {
return StripSuffixString(filename, ".proto"); return std::string(absl::StripSuffix(filename, ".proto"));
} }
} }

@ -75,6 +75,7 @@
#include "google/protobuf/compiler/subprocess.h" #include "google/protobuf/compiler/subprocess.h"
#include "google/protobuf/compiler/plugin.pb.h" #include "google/protobuf/compiler/plugin.pb.h"
#include "google/protobuf/stubs/strutil.h" #include "google/protobuf/stubs/strutil.h"
#include "absl/strings/match.h"
#include "google/protobuf/stubs/stringprintf.h" #include "google/protobuf/stubs/stringprintf.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
@ -1065,9 +1066,9 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
if (mode_ == MODE_COMPILE) { if (mode_ == MODE_COMPILE) {
for (int i = 0; i < output_directives_.size(); i++) { for (int i = 0; i < output_directives_.size(); i++) {
std::string output_location = output_directives_[i].output_location; std::string output_location = output_directives_[i].output_location;
if (!HasSuffixString(output_location, ".zip") && if (!absl::EndsWith(output_location, ".zip") &&
!HasSuffixString(output_location, ".jar") && !absl::EndsWith(output_location, ".jar") &&
!HasSuffixString(output_location, ".srcjar")) { !absl::EndsWith(output_location, ".srcjar")) {
AddTrailingSlash(&output_location); AddTrailingSlash(&output_location);
} }
@ -1088,12 +1089,12 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
for (const auto& pair : output_directories) { for (const auto& pair : output_directories) {
const std::string& location = pair.first; const std::string& location = pair.first;
GeneratorContextImpl* directory = pair.second.get(); GeneratorContextImpl* directory = pair.second.get();
if (HasSuffixString(location, "/")) { if (absl::EndsWith(location, "/")) {
if (!directory->WriteAllToDisk(location)) { if (!directory->WriteAllToDisk(location)) {
return 1; return 1;
} }
} else { } else {
if (HasSuffixString(location, ".jar")) { if (absl::EndsWith(location, ".jar")) {
directory->AddJarManifest(); directory->AddJarManifest();
} }
@ -1971,7 +1972,7 @@ CommandLineInterface::InterpretArgument(const std::string& name,
// Some other flag. Look it up in the generators list. // Some other flag. Look it up in the generators list.
const GeneratorInfo* generator_info = FindGeneratorByFlag(name); const GeneratorInfo* generator_info = FindGeneratorByFlag(name);
if (generator_info == nullptr && if (generator_info == nullptr &&
(plugin_prefix_.empty() || !HasSuffixString(name, "_out"))) { (plugin_prefix_.empty() || !absl::EndsWith(name, "_out"))) {
// Check if it's a generator option flag. // Check if it's a generator option flag.
generator_info = FindGeneratorByOption(name); generator_info = FindGeneratorByOption(name);
if (generator_info != nullptr) { if (generator_info != nullptr) {
@ -1981,7 +1982,7 @@ CommandLineInterface::InterpretArgument(const std::string& name,
parameters->append(","); parameters->append(",");
} }
parameters->append(value); parameters->append(value);
} else if (HasPrefixString(name, "--") && HasSuffixString(name, "_opt")) { } else if (absl::StartsWith(name, "--") && absl::EndsWith(name, "_opt")) {
std::string* parameters = std::string* parameters =
&plugin_parameters_[PluginName(plugin_prefix_, name)]; &plugin_parameters_[PluginName(plugin_prefix_, name)];
if (!parameters->empty()) { if (!parameters->empty()) {
@ -2165,8 +2166,8 @@ bool CommandLineInterface::GenerateOutput(
std::string error; std::string error;
if (output_directive.generator == nullptr) { if (output_directive.generator == nullptr) {
// This is a plugin. // This is a plugin.
GOOGLE_CHECK(HasPrefixString(output_directive.name, "--") && GOOGLE_CHECK(absl::StartsWith(output_directive.name, "--") &&
HasSuffixString(output_directive.name, "_out")) absl::EndsWith(output_directive.name, "_out"))
<< "Bad name for plugin generator: " << output_directive.name; << "Bad name for plugin generator: " << output_directive.name;
std::string plugin_name = PluginName(plugin_prefix_, output_directive.name); std::string plugin_name = PluginName(plugin_prefix_, output_directive.name);

@ -794,6 +794,7 @@ TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport) {
"bar.proto", "Bar"); "bar.proto", "Bar");
} }
TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport_DescriptorSetIn) { TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport_DescriptorSetIn) {
// Test parsing multiple input files with an import of a separate file. // Test parsing multiple input files with an import of a separate file.
FileDescriptorSet file_descriptor_set; FileDescriptorSet file_descriptor_set;

@ -53,9 +53,10 @@ cc_library(
"//src/google/protobuf/compiler:__pkg__", "//src/google/protobuf/compiler:__pkg__",
], ],
deps = [ deps = [
"//:protobuf", "//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/container:layout", "@com_google_absl//absl/container:layout",

File diff suppressed because it is too large Load Diff

@ -36,55 +36,47 @@
#define GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__
#include <algorithm> #include <algorithm>
#include <functional>
#include <memory> #include <memory>
#include <set> #include <set>
#include <string> #include <string>
#include <vector> #include <vector>
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/compiler/scc.h"
#include "absl/container/flat_hash_set.h"
#include "google/protobuf/compiler/cpp/enum.h"
#include "google/protobuf/compiler/cpp/extension.h"
#include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/field.h"
#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/port.h" #include "google/protobuf/compiler/cpp/message.h"
#include "google/protobuf/compiler/scc.h"
#include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/compiler/cpp/options.h"
#include "google/protobuf/compiler/cpp/service.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
class FileDescriptor; // descriptor.h
namespace io {
class Printer; // printer.h
}
} // namespace protobuf
} // namespace google
namespace google { namespace google {
namespace protobuf { namespace protobuf {
namespace compiler { namespace compiler {
namespace cpp { namespace cpp {
class EnumGenerator; // enum.h
class MessageGenerator; // message.h
class ServiceGenerator; // service.h
class ExtensionGenerator; // extension.h
class FileGenerator { class FileGenerator {
public: public:
// See generator.cc for the meaning of dllexport_decl.
FileGenerator(const FileDescriptor* file, const Options& options); FileGenerator(const FileDescriptor* file, const Options& options);
FileGenerator(const FileGenerator&) = delete; FileGenerator(const FileGenerator&) = delete;
FileGenerator& operator=(const FileGenerator&) = delete; FileGenerator& operator=(const FileGenerator&) = delete;
~FileGenerator();
// Shared code between the two header generators below. ~FileGenerator() = default;
void GenerateHeader(io::Printer* printer);
// info_path, if non-empty, should be the path (relative to printer's // info_path, if non-empty, should be the path (relative to printer's
// output) to the metadata file describing this proto header. // output) to the metadata file describing this proto header.
void GenerateProtoHeader(io::Printer* printer, const std::string& info_path); void GenerateProtoHeader(io::Printer* p, absl::string_view info_path);
// info_path, if non-empty, should be the path (relative to printer's // info_path, if non-empty, should be the path (relative to printer's
// output) to the metadata file describing this PB header. // output) to the metadata file describing this PB header.
void GeneratePBHeader(io::Printer* printer, const std::string& info_path); void GeneratePBHeader(io::Printer* p, absl::string_view info_path);
void GenerateSource(io::Printer* printer); void GenerateSource(io::Printer* p);
// The following member functions are used when the lite_implicit_weak_fields // The following member functions are used when the lite_implicit_weak_fields
// option is set. In this mode the code is organized a bit differently to // option is set. In this mode the code is organized a bit differently to
@ -95,80 +87,86 @@ class FileGenerator {
int NumMessages() const { return message_generators_.size(); } int NumMessages() const { return message_generators_.size(); }
int NumExtensions() const { return extension_generators_.size(); } int NumExtensions() const { return extension_generators_.size(); }
// Generates the source file for one message. // Generates the source file for one message.
void GenerateSourceForMessage(int idx, io::Printer* printer); void GenerateSourceForMessage(int idx, io::Printer* p);
// Generates the source file for one extension. // Generates the source file for one extension.
void GenerateSourceForExtension(int idx, io::Printer* printer); void GenerateSourceForExtension(int idx, io::Printer* p);
// Generates a source file containing everything except messages and // Generates a source file containing everything except messages and
// extensions. // extensions.
void GenerateGlobalSource(io::Printer* printer); void GenerateGlobalSource(io::Printer* p);
private: private:
// Generates a file, setting up the necessary accoutrements that start and
// end the file, calling `cb` in between.
//
// This includes header guards and file-global variables.
void GenerateFile(io::Printer* p, GeneratedFileType file_type,
std::function<void()> cb);
// Shared code between the two header generators.
void GenerateSharedHeaderCode(io::Printer* p);
// Internal type used by GenerateForwardDeclarations (defined in file.cc). // Internal type used by GenerateForwardDeclarations (defined in file.cc).
class ForwardDeclarations; class ForwardDeclarations;
struct CrossFileReferences; struct CrossFileReferences;
void IncludeFile(const std::string& google3_name, io::Printer* printer) { void IncludeFile(absl::string_view google3_name, io::Printer* p) {
DoIncludeFile(google3_name, false, printer); DoIncludeFile(google3_name, false, p);
} }
void IncludeFileAndExport(const std::string& google3_name, void IncludeFileAndExport(absl::string_view google3_name, io::Printer* p) {
io::Printer* printer) { DoIncludeFile(google3_name, true, p);
DoIncludeFile(google3_name, true, printer);
} }
void DoIncludeFile(const std::string& google3_name, bool do_export, void DoIncludeFile(absl::string_view google3_name, bool do_export,
io::Printer* printer); io::Printer* p);
std::string CreateHeaderInclude(const std::string& basename, std::string CreateHeaderInclude(absl::string_view basename,
const FileDescriptor* file); const FileDescriptor* file);
void GetCrossFileReferencesForField(const FieldDescriptor* field, void GetCrossFileReferencesForField(const FieldDescriptor* field,
CrossFileReferences* refs); CrossFileReferences* refs);
void GetCrossFileReferencesForFile(const FileDescriptor* file, void GetCrossFileReferencesForFile(const FileDescriptor* file,
CrossFileReferences* refs); CrossFileReferences* refs);
void GenerateInternalForwardDeclarations(const CrossFileReferences& refs, void GenerateInternalForwardDeclarations(const CrossFileReferences& refs,
io::Printer* printer); io::Printer* p);
void GenerateSourceIncludes(io::Printer* printer); void GenerateSourceIncludes(io::Printer* p);
void GenerateSourcePrelude(io::Printer* printer); void GenerateSourcePrelude(io::Printer* p);
void GenerateSourceDefaultInstance(int idx, io::Printer* printer); void GenerateSourceDefaultInstance(int idx, io::Printer* p);
void GenerateInitForSCC(const SCC* scc, const CrossFileReferences& refs, void GenerateInitForSCC(const SCC* scc, const CrossFileReferences& refs,
io::Printer* printer); io::Printer* p);
void GenerateReflectionInitializationCode(io::Printer* printer); void GenerateReflectionInitializationCode(io::Printer* p);
// For other imports, generates their forward-declarations. // For other imports, generates their forward-declarations.
void GenerateForwardDeclarations(io::Printer* printer); void GenerateForwardDeclarations(io::Printer* p);
// Generates top or bottom of a header file. // Generates top or bottom of a header file.
void GenerateTopHeaderGuard( void GenerateTopHeaderGuard(io::Printer* p, GeneratedFileType file_type);
io::Printer* printer, google::protobuf::compiler::cpp::GeneratedFileType file_type); void GenerateBottomHeaderGuard(io::Printer* p, GeneratedFileType file_type);
void GenerateBottomHeaderGuard(
io::Printer* printer, google::protobuf::compiler::cpp::GeneratedFileType file_type);
// Generates #include directives. // Generates #include directives.
void GenerateLibraryIncludes(io::Printer* printer); void GenerateLibraryIncludes(io::Printer* p);
void GenerateDependencyIncludes(io::Printer* printer); void GenerateDependencyIncludes(io::Printer* p);
// Generate a pragma to pull in metadata using the given info_path (if // Generate a pragma to pull in metadata using the given info_path (if
// non-empty). info_path should be relative to printer's output. // non-empty). info_path should be relative to printer's output.
void GenerateMetadataPragma(io::Printer* printer, void GenerateMetadataPragma(io::Printer* p, absl::string_view info_path);
const std::string& info_path);
// Generates a couple of different pieces before definitions: // Generates a couple of different pieces before definitions:
void GenerateGlobalStateFunctionDeclarations(io::Printer* printer); void GenerateGlobalStateFunctionDeclarations(io::Printer* p);
// Generates types for classes. // Generates types for classes.
void GenerateMessageDefinitions(io::Printer* printer); void GenerateMessageDefinitions(io::Printer* p);
void GenerateEnumDefinitions(io::Printer* printer); void GenerateEnumDefinitions(io::Printer* p);
// Generates generic service definitions. // Generates generic service definitions.
void GenerateServiceDefinitions(io::Printer* printer); void GenerateServiceDefinitions(io::Printer* p);
// Generates extension identifiers. // Generates extension identifiers.
void GenerateExtensionIdentifiers(io::Printer* printer); void GenerateExtensionIdentifiers(io::Printer* p);
// Generates inline function definitions. // Generates inline function definitions.
void GenerateInlineFunctionDefinitions(io::Printer* printer); void GenerateInlineFunctionDefinitions(io::Printer* p);
void GenerateProto2NamespaceEnumSpecializations(io::Printer* printer); void GenerateProto2NamespaceEnumSpecializations(io::Printer* p);
// Sometimes the names we use in a .proto file happen to be defined as // Sometimes the names we use in a .proto file happen to be defined as
// macros on some platforms (e.g., macro/minor used in plugin.proto are // macros on some platforms (e.g., macro/minor used in plugin.proto are
@ -177,7 +175,7 @@ class FileGenerator {
// undef the macro for these few platforms, or rename the field name for all // undef the macro for these few platforms, or rename the field name for all
// platforms. Since these names are part of protobuf public API, renaming is // platforms. Since these names are part of protobuf public API, renaming is
// generally a breaking change so we prefer the #undef approach. // generally a breaking change so we prefer the #undef approach.
void GenerateMacroUndefs(io::Printer* printer); void GenerateMacroUndefs(io::Printer* p);
bool IsDepWeak(const FileDescriptor* dep) const { bool IsDepWeak(const FileDescriptor* dep) const {
if (weak_deps_.count(dep) != 0) { if (weak_deps_.count(dep) != 0) {
@ -187,13 +185,16 @@ class FileGenerator {
return false; return false;
} }
std::set<const FileDescriptor*> weak_deps_; absl::flat_hash_set<const FileDescriptor*> weak_deps_;
const FileDescriptor* file_; const FileDescriptor* file_;
const Options options_; Options options_;
MessageSCCAnalyzer scc_analyzer_; MessageSCCAnalyzer scc_analyzer_;
// This member is unused and should be deleted once all old-style variable
// maps are gone.
// TODO(b/245791219)
std::map<std::string, std::string> variables_; std::map<std::string, std::string> variables_;
// Contains the post-order walk of all the messages (and child messages) in // Contains the post-order walk of all the messages (and child messages) in

@ -70,6 +70,9 @@ absl::flat_hash_map<std::string, std::string> CommonVars(
{"uint32", "uint32_t"}, {"uint32", "uint32_t"},
{"uint64", "uint64_t"}, {"uint64", "uint64_t"},
{"hrule_thick", kThickSeparator},
{"hrule_thin", kThinSeparator},
// Warning: there is some clever naming/splitting here to avoid extract // Warning: there is some clever naming/splitting here to avoid extract
// script rewrites. The names of these variables must not be things that // script rewrites. The names of these variables must not be things that
// the extract script will rewrite. That's why we use "CHK" (for example) // the extract script will rewrite. That's why we use "CHK" (for example)

@ -43,6 +43,7 @@
#include <queue> #include <queue>
#include <set> #include <set>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
@ -1087,6 +1088,46 @@ bool IsWellKnownMessage(const FileDescriptor* file) {
return well_known_files->find(file->name()) != well_known_files->end(); return well_known_files->find(file->name()) != well_known_files->end();
} }
void NamespaceOpener::ChangeTo(absl::string_view name) {
std::vector<std::string> new_stack =
absl::StrSplit(name, "::", absl::SkipEmpty());
size_t len = std::min(name_stack_.size(), new_stack.size());
size_t common_idx = 0;
while (common_idx < len) {
if (name_stack_[common_idx] != new_stack[common_idx]) {
break;
}
++common_idx;
}
for (size_t i = name_stack_.size(); i > common_idx; i--) {
const auto& ns = name_stack_[i - 1];
if (ns == "PROTOBUF_NAMESPACE_ID") {
p_->Emit(R"cc(
PROTOBUF_NAMESPACE_CLOSE
)cc");
} else {
p_->Emit({{"ns", ns}}, R"(
} // namespace $ns$
)");
}
}
for (size_t i = common_idx; i < new_stack.size(); ++i) {
const auto& ns = new_stack[i];
if (ns == "PROTOBUF_NAMESPACE_ID") {
p_->Emit(R"cc(
PROTOBUF_NAMESPACE_OPEN
)cc");
} else {
p_->Emit({{"ns", ns}}, R"(
namespace $ns$ {
)");
}
}
name_stack_ = std::move(new_stack);
}
static void GenerateUtf8CheckCode(const FieldDescriptor* field, static void GenerateUtf8CheckCode(const FieldDescriptor* field,
const Options& options, bool for_parse, const Options& options, bool for_parse,
const char* parameters, const char* parameters,

@ -44,7 +44,7 @@
#include "google/protobuf/compiler/scc.h" #include "google/protobuf/compiler/scc.h"
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_map.h"
#include "google/protobuf/stubs/strutil.h" #include "absl/strings/match.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
#include "google/protobuf/compiler/cpp/names.h" #include "google/protobuf/compiler/cpp/names.h"
#include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/compiler/cpp/options.h"
@ -52,6 +52,7 @@
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/port.h" #include "google/protobuf/port.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
// Must be included last. // Must be included last.
@ -887,43 +888,21 @@ void PrintFieldComment(const Formatter& format, const T* field) {
class PROTOC_EXPORT NamespaceOpener { class PROTOC_EXPORT NamespaceOpener {
public: public:
explicit NamespaceOpener(const Formatter& format) explicit NamespaceOpener(io::Printer* p) : p_(p) {}
: printer_(format.printer()) {} explicit NamespaceOpener(const Formatter& format) : p_(format.printer()) {}
NamespaceOpener(const std::string& name, const Formatter& format) NamespaceOpener(absl::string_view name, const Formatter& format)
: NamespaceOpener(format) { : NamespaceOpener(format) {
ChangeTo(name); ChangeTo(name);
} }
NamespaceOpener(absl::string_view name, io::Printer* p) : NamespaceOpener(p) {
ChangeTo(name);
}
~NamespaceOpener() { ChangeTo(""); } ~NamespaceOpener() { ChangeTo(""); }
void ChangeTo(const std::string& name) { void ChangeTo(absl::string_view name);
std::vector<std::string> new_stack_ =
absl::StrSplit(name, "::", absl::SkipEmpty());
size_t len = std::min(name_stack_.size(), new_stack_.size());
size_t common_idx = 0;
while (common_idx < len) {
if (name_stack_[common_idx] != new_stack_[common_idx]) break;
common_idx++;
}
for (auto it = name_stack_.crbegin();
it != name_stack_.crend() - common_idx; ++it) {
if (*it == "PROTOBUF_NAMESPACE_ID") {
printer_->Print("PROTOBUF_NAMESPACE_CLOSE\n");
} else {
printer_->Print("} // namespace $ns$\n", "ns", *it);
}
}
name_stack_.swap(new_stack_);
for (size_t i = common_idx; i < name_stack_.size(); ++i) {
if (name_stack_[i] == "PROTOBUF_NAMESPACE_ID") {
printer_->Print("PROTOBUF_NAMESPACE_OPEN\n");
} else {
printer_->Print("namespace $ns$ {\n", "ns", name_stack_[i]);
}
}
}
private: private:
io::Printer* printer_; io::Printer* p_;
std::vector<std::string> name_stack_; std::vector<std::string> name_stack_;
}; };

@ -630,11 +630,11 @@ void ParseFunctionGenerator::GenerateFastFieldEntries(Formatter& format) {
std::string func_name = info.func_name; std::string func_name = info.func_name;
// For 1-byte tags we have a more optimized version of the varint parser // For 1-byte tags we have a more optimized version of the varint parser
// that can hardcode the offset and has bit. // that can hardcode the offset and has bit.
if (HasSuffixString(func_name, "V8S1") || if (absl::EndsWith(func_name, "V8S1") ||
HasSuffixString(func_name, "V32S1") || absl::EndsWith(func_name, "V32S1") ||
HasSuffixString(func_name, "V64S1")) { absl::EndsWith(func_name, "V64S1")) {
std::string field_type = HasSuffixString(func_name, "V8S1") ? "bool" std::string field_type = absl::EndsWith(func_name, "V8S1") ? "bool"
: HasSuffixString(func_name, "V32S1") : absl::EndsWith(func_name, "V32S1")
? "uint32_t" ? "uint32_t"
: "uint64_t"; : "uint64_t";
func_name = func_name =

@ -56,7 +56,7 @@ cc_library(
"//src/google/protobuf/compiler:__pkg__", "//src/google/protobuf/compiler:__pkg__",
], ],
deps = [ deps = [
"//:protobuf", "//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",

@ -33,9 +33,6 @@
// Sanjay Ghemawat, Jeff Dean, and others. // Sanjay Ghemawat, Jeff Dean, and others.
#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"

@ -33,22 +33,13 @@
#include <sstream> #include <sstream>
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_options.h" #include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {
@ -65,6 +56,9 @@ EnumGenerator::~EnumGenerator() {
void EnumGenerator::Generate(io::Printer* printer) { void EnumGenerator::Generate(io::Printer* printer) {
WriteEnumDocComment(printer, descriptor_); WriteEnumDocComment(printer, descriptor_);
if (descriptor_->options().deprecated()) {
printer->Print("[global::System.ObsoleteAttribute]\n");
}
printer->Print("$access_level$ enum $name$ {\n", printer->Print("$access_level$ enum $name$ {\n",
"access_level", class_access_level(), "access_level", class_access_level(),
"name", descriptor_->name()); "name", descriptor_->name());
@ -73,6 +67,9 @@ void EnumGenerator::Generate(io::Printer* printer) {
std::set<int> used_number; std::set<int> used_number;
for (int i = 0; i < descriptor_->value_count(); i++) { for (int i = 0; i < descriptor_->value_count(); i++) {
WriteEnumValueDocComment(printer, descriptor_->value(i)); WriteEnumValueDocComment(printer, descriptor_->value(i));
if (descriptor_->value(i)->options().deprecated()) {
printer->Print("[global::System.ObsoleteAttribute]\n");
}
std::string original_name = descriptor_->value(i)->name(); std::string original_name = descriptor_->value(i)->name();
std::string name = std::string name =
GetEnumValueName(descriptor_->name(), descriptor_->value(i)->name()); GetEnumValueName(descriptor_->name(), descriptor_->value(i)->name());

@ -37,21 +37,11 @@
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_names.h" #include "google/protobuf/compiler/csharp/csharp_names.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
// Must be last. // Must be last.
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"

@ -32,17 +32,13 @@
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_FIELD_BASE_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_FIELD_BASE_H__
#include <string> #include <string>
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/stubs/strutil.h" #include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/escaping.h" #include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" #include "google/protobuf/compiler/csharp/csharp_source_generator_base.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"

@ -34,16 +34,6 @@
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_names.h" #include "google/protobuf/compiler/csharp/csharp_names.h"
#include "google/protobuf/compiler/csharp/csharp_options.h" #include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/compiler/csharp/csharp_reflection_class.h" #include "google/protobuf/compiler/csharp/csharp_reflection_class.h"

@ -41,9 +41,7 @@
#include "absl/container/flat_hash_set.h" #include "absl/container/flat_hash_set.h"
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "google/protobuf/compiler/csharp/csharp_enum_field.h" #include "google/protobuf/compiler/csharp/csharp_enum_field.h"
#include "google/protobuf/compiler/csharp/csharp_field_base.h" #include "google/protobuf/compiler/csharp/csharp_field_base.h"
@ -57,8 +55,6 @@
#include "google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h" #include "google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h"
#include "google/protobuf/compiler/csharp/csharp_wrapper_field.h" #include "google/protobuf/compiler/csharp/csharp_wrapper_field.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/wire_format.h"
// Must be last. // Must be last.
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"

@ -39,11 +39,11 @@
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/port.h"
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"
#include "google/protobuf/port.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {

@ -34,20 +34,10 @@
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {

@ -35,27 +35,18 @@
#include <sstream> #include <sstream>
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/wire_format.h"
#include "google/protobuf/wire_format_lite.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h"
#include "google/protobuf/compiler/csharp/csharp_enum.h" #include "google/protobuf/compiler/csharp/csharp_enum.h"
#include "google/protobuf/compiler/csharp/csharp_field_base.h" #include "google/protobuf/compiler/csharp/csharp_field_base.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_names.h" #include "google/protobuf/compiler/csharp/csharp_names.h"
#include "google/protobuf/compiler/csharp/csharp_options.h" #include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/wire_format.h"
#include "google/protobuf/wire_format_lite.h"
// Must be last. // Must be last.
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"

@ -34,23 +34,11 @@
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/wire_format.h"
#include "google/protobuf/wire_format_lite.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_options.h" #include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {

@ -39,8 +39,6 @@
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__
#include <string> #include <string>
#include "google/protobuf/port.h"
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"

@ -33,22 +33,13 @@
#include <sstream> #include <sstream>
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "absl/strings/str_cat.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" #include "google/protobuf/compiler/csharp/csharp_doc_comment.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_options.h" #include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
namespace google { namespace google {
namespace protobuf { namespace protobuf {

@ -33,25 +33,16 @@
#include <sstream> #include <sstream>
#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/descriptor.h" #include "absl/strings/str_join.h"
#include "google/protobuf/stubs/strutil.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_split.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/compiler/csharp/csharp_enum.h" #include "google/protobuf/compiler/csharp/csharp_enum.h"
#include "google/protobuf/compiler/csharp/csharp_field_base.h" #include "google/protobuf/compiler/csharp/csharp_field_base.h"
#include "google/protobuf/compiler/csharp/csharp_helpers.h" #include "google/protobuf/compiler/csharp/csharp_helpers.h"
#include "google/protobuf/compiler/csharp/csharp_message.h" #include "google/protobuf/compiler/csharp/csharp_message.h"
#include "google/protobuf/compiler/csharp/csharp_names.h" #include "google/protobuf/compiler/csharp/csharp_names.h"
#include "google/protobuf/compiler/csharp/csharp_options.h" #include "google/protobuf/compiler/csharp/csharp_options.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
// Must be last. // Must be last.
#include "google/protobuf/port_def.inc" #include "google/protobuf/port_def.inc"

@ -48,7 +48,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "google/protobuf/stubs/strutil.h" #include "absl/strings/match.h"
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
@ -282,7 +282,7 @@ static std::string CanonicalizePath(absl::string_view path) {
// backslashes are standard. Let's avoid confusion and use only forward // backslashes are standard. Let's avoid confusion and use only forward
// slashes. // slashes.
std::string path_str; std::string path_str;
if (HasPrefixString(path, "\\\\")) { if (absl::StartsWith(path, "\\\\")) {
// Avoid converting two leading backslashes. // Avoid converting two leading backslashes.
path_str = "\\\\" + absl::StrReplaceAll(path.substr(2), {{"\\", "/"}}); path_str = "\\\\" + absl::StrReplaceAll(path.substr(2), {{"\\", "/"}});
} else { } else {
@ -306,8 +306,8 @@ static std::string CanonicalizePath(absl::string_view path) {
} }
static inline bool ContainsParentReference(absl::string_view path) { static inline bool ContainsParentReference(absl::string_view path) {
return path == ".." || HasPrefixString(path, "../") || return path == ".." || absl::StartsWith(path, "../") ||
HasSuffixString(path, "/..") || absl::StrContains(path, "/../"); absl::EndsWith(path, "/..") || absl::StrContains(path, "/../");
} }
// Maps a file from an old location to a new one. Typically, old_prefix is // Maps a file from an old location to a new one. Typically, old_prefix is
@ -336,7 +336,7 @@ static bool ApplyMapping(absl::string_view filename,
// We do not allow the file name to use "..". // We do not allow the file name to use "..".
return false; return false;
} }
if (HasPrefixString(filename, "/") || IsWindowsAbsolutePath(filename)) { if (absl::StartsWith(filename, "/") || IsWindowsAbsolutePath(filename)) {
// This is an absolute path, so it isn't matched by the empty string. // This is an absolute path, so it isn't matched by the empty string.
return false; return false;
} }
@ -344,7 +344,7 @@ static bool ApplyMapping(absl::string_view filename,
if (!result->empty()) result->push_back('/'); if (!result->empty()) result->push_back('/');
result->append(std::string(filename)); result->append(std::string(filename));
return true; return true;
} else if (HasPrefixString(filename, old_prefix)) { } else if (absl::StartsWith(filename, old_prefix)) {
// old_prefix is a prefix of the filename. Is it the whole filename? // old_prefix is a prefix of the filename. Is it the whole filename?
if (filename.size() == old_prefix.size()) { if (filename.size() == old_prefix.size()) {
// Yep, it's an exact match. // Yep, it's an exact match.

@ -81,7 +81,7 @@ cc_library(
"//src/google/protobuf/compiler:__pkg__", "//src/google/protobuf/compiler:__pkg__",
], ],
deps = [ deps = [
"//:protobuf", "//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",

@ -221,7 +221,7 @@ std::string ToCamelCase(const std::string& input, bool lower_first) {
if (i == '_') { if (i == '_') {
capitalize_next = true; capitalize_next = true;
} else if (capitalize_next) { } else if (capitalize_next) {
result.push_back(ToUpperCh(i)); result.push_back(absl::ascii_toupper(i));
capitalize_next = false; capitalize_next = false;
} else { } else {
result.push_back(i); result.push_back(i);
@ -230,20 +230,12 @@ std::string ToCamelCase(const std::string& input, bool lower_first) {
// Lower-case the first letter. // Lower-case the first letter.
if (lower_first && !result.empty()) { if (lower_first && !result.empty()) {
result[0] = ToLowerCh(result[0]); result[0] = absl::ascii_tolower(result[0]);
} }
return result; return result;
} }
char ToUpperCh(char ch) {
return (ch >= 'a' && ch <= 'z') ? (ch - 'a' + 'A') : ch;
}
char ToLowerCh(char ch) {
return (ch >= 'A' && ch <= 'Z') ? (ch - 'A' + 'a') : ch;
}
std::string UnderscoresToCamelCase(const FieldDescriptor* field) { std::string UnderscoresToCamelCase(const FieldDescriptor* field) {
return UnderscoresToCamelCase(FieldName(field), false); return UnderscoresToCamelCase(FieldName(field), false);
} }

@ -84,9 +84,6 @@ void PrintEnumVerifierLogic(io::Printer* printer,
// first letter. // first letter.
std::string ToCamelCase(const std::string& input, bool lower_first); std::string ToCamelCase(const std::string& input, bool lower_first);
char ToUpperCh(char ch);
char ToLowerCh(char ch);
// Converts a name to camel-case. If cap_first_letter is true, capitalize the // Converts a name to camel-case. If cap_first_letter is true, capitalize the
// first letter. // first letter.
std::string UnderscoresToCamelCase(const std::string& name, std::string UnderscoresToCamelCase(const std::string& name,

@ -39,19 +39,18 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "google/protobuf/stubs/strutil.h"
#include "google/protobuf/stubs/logging.h" #include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/common.h" #include "google/protobuf/stubs/common.h"
#include "google/protobuf/testing/file.h" #include "google/protobuf/testing/file.h"
#include "google/protobuf/testing/file.h" #include "google/protobuf/testing/file.h"
#include "google/protobuf/testing/file.h"
#include "google/protobuf/compiler/plugin.pb.h" #include "google/protobuf/compiler/plugin.pb.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "absl/strings/substitute.h" #include "absl/strings/substitute.h"
#include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.h"
#include "google/protobuf/io/printer.h" #include "google/protobuf/io/printer.h"
@ -208,8 +207,8 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file,
std::string* error) const { std::string* error) const {
bool annotate = false; bool annotate = false;
for (int i = 0; i < file->message_type_count(); i++) { for (int i = 0; i < file->message_type_count(); i++) {
if (HasPrefixString(file->message_type(i)->name(), "MockCodeGenerator_")) { if (absl::StartsWith(file->message_type(i)->name(), "MockCodeGenerator_")) {
std::string command = StripPrefixString( absl::string_view command = absl::StripPrefix(
file->message_type(i)->name(), "MockCodeGenerator_"); file->message_type(i)->name(), "MockCodeGenerator_");
if (command == "Error") { if (command == "Error") {
*error = "Saw message type MockCodeGenerator_Error."; *error = "Saw message type MockCodeGenerator_Error.";
@ -252,12 +251,12 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file,
} }
} }
bool insert_endlines = HasPrefixString(parameter, "insert_endlines="); bool insert_endlines = absl::StartsWith(parameter, "insert_endlines=");
if (insert_endlines || HasPrefixString(parameter, "insert=")) { if (insert_endlines || absl::StartsWith(parameter, "insert=")) {
std::vector<std::string> insert_into = absl::StrSplit( std::vector<std::string> insert_into = absl::StrSplit(
StripPrefixString( absl::StripPrefix(parameter,
parameter, insert_endlines ? "insert_endlines=" : "insert="), insert_endlines ? "insert_endlines=" : "insert="),
",", absl::SkipEmpty()); ',', absl::SkipEmpty());
for (size_t i = 0; i < insert_into.size(); i++) { for (size_t i = 0; i < insert_into.size(); i++) {
{ {
@ -265,7 +264,7 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file,
std::string content = std::string content =
GetOutputFileContent(name_, "first_insert", file, context); GetOutputFileContent(name_, "first_insert", file, context);
if (insert_endlines) { if (insert_endlines) {
GlobalReplaceSubstring(",", ",\n", &content); absl::StrReplaceAll({{",", ",\n"}}, &content);
} }
if (annotate) { if (annotate) {
auto* annotation = info.add_annotation(); auto* annotation = info.add_annotation();
@ -290,7 +289,7 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file,
std::string content = std::string content =
GetOutputFileContent(name_, "second_insert", file, context); GetOutputFileContent(name_, "second_insert", file, context);
if (insert_endlines) { if (insert_endlines) {
GlobalReplaceSubstring(",", ",\n", &content); absl::StrReplaceAll({{",", ",\n"}}, &content);
} }
if (annotate) { if (annotate) {
auto* annotation = info.add_annotation(); auto* annotation = info.add_annotation();

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

Loading…
Cancel
Save