From 896f3d8ced21cf3e37f1a90a17b7c6cf5de08008 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 16 Oct 2023 12:36:52 -0700 Subject: [PATCH 001/387] Updating version.json and repo version numbers to: 25.0-rc1 --- CMakeLists.txt | 2 +- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/README.md | 6 ++--- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/kotlin-lite/pom.xml | 2 +- java/kotlin/pom.xml | 2 +- java/lite.md | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/protoc/pom.xml | 2 +- java/util/pom.xml | 2 +- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 10 ++++----- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 ++-- src/google/protobuf/any.pb.h | 4 ++-- src/google/protobuf/api.pb.h | 4 ++-- .../protobuf/compiler/java/java_features.pb.h | 4 ++-- src/google/protobuf/compiler/plugin.pb.h | 4 ++-- src/google/protobuf/compiler/versions.h | 6 ++--- .../protobuf/compiler/versions_suffix.h | 2 +- src/google/protobuf/cpp_features.pb.h | 4 ++-- src/google/protobuf/descriptor.pb.h | 4 ++-- src/google/protobuf/duration.pb.h | 4 ++-- src/google/protobuf/empty.pb.h | 4 ++-- src/google/protobuf/field_mask.pb.h | 4 ++-- src/google/protobuf/port_def.inc | 10 ++++----- src/google/protobuf/source_context.pb.h | 4 ++-- src/google/protobuf/struct.pb.h | 4 ++-- src/google/protobuf/stubs/common.h | 10 ++++----- src/google/protobuf/timestamp.pb.h | 4 ++-- src/google/protobuf/type.pb.h | 4 ++-- src/google/protobuf/wrappers.pb.h | 4 ++-- version.json | 22 +++++++++---------- 39 files changed, 80 insertions(+), 80 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac0d03c3aa..1b4f36893d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ if (protobuf_BUILD_SHARED_LIBS) endif () # Version metadata -set(protobuf_VERSION_STRING "4.24.0") +set(protobuf_VERSION_STRING "4.25.0-rc-1") set(protobuf_DESCRIPTION "Protocol Buffers") set(protobuf_CONTACT "protobuf@googlegroups.com") diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index f472aa5f1b..29c49d02f9 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '4.24.0' + s.version = '4.25.0-rc1' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' diff --git a/Protobuf.podspec b/Protobuf.podspec index 539394e629..ef3b315579 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.24.0' + s.version = '3.25.0-rc1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 2a0cf99af8..9b1508c2f1 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.24.0 + 3.25.0-rc1 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index dede331228..447b824173 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -5,7 +5,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.24.0 + 3.25.0-rc1 10.0 Google Inc. netstandard1.1;netstandard2.0;net45;net50 diff --git a/java/README.md b/java/README.md index fb80b05f27..45e5edd18b 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.24.0 + 3.25.0-rc-1 ``` @@ -37,14 +37,14 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.24.0 + 3.25.0-rc-1 ``` ### Gradle If you are using Gradle, add the following to your `build.gradle` file's -dependencies: `implementation 'com.google.protobuf:protobuf-java:3.24.0'` Again, +dependencies: `implementation 'com.google.protobuf:protobuf-java:3.25.0-rc-1'` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 372dcdfda0..aa715919f6 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.24.0 + 3.25.0-RC1 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 84d674094e..794cfc6aac 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0-RC1 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 254eb8281b..2cfe928a4f 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0-RC1 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 354e65494c..8b2c2a82f0 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0-RC1 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index d8201e0468..d7a07b3968 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.24.0 + 3.25.0-rc-1 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 3b4ff82583..d88eff6343 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0-RC1 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 1deeca92a8..9794219de4 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0-RC1 pom Protocol Buffers [Parent] diff --git a/java/protoc/pom.xml b/java/protoc/pom.xml index eec6f636e7..b9d1f9b679 100644 --- a/java/protoc/pom.xml +++ b/java/protoc/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.24.0 + 3.25.0-RC1 pom Protobuf Compiler diff --git a/java/util/pom.xml b/java/util/pom.xml index f5c6380899..686a8b6f9e 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0-RC1 protobuf-java-util diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index d24a5328e9..81bb489a9e 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -32,7 +32,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.24.0" +#define PHP_PROTOBUF_VERSION "3.25.0RC1" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protobuf_version.bzl b/protobuf_version.bzl index e428407720..a0660c18a6 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,6 +1,6 @@ """ Contains version numbers to be used in other bzl files """ -PROTOC_VERSION = "24.0" -PROTOBUF_JAVA_VERSION = "3.24.0" -PROTOBUF_PYTHON_VERSION = "4.24.0" -PROTOBUF_PHP_VERSION = "3.24.0" -PROTOBUF_RUBY_VERSION = "3.24.0" +PROTOC_VERSION = "25.0-rc-1" +PROTOBUF_JAVA_VERSION = "3.25.0-RC1" +PROTOBUF_PYTHON_VERSION = "4.25.0rc1" +PROTOBUF_PHP_VERSION = "3.25.0RC1" +PROTOBUF_RUBY_VERSION = "3.25.0.rc.1" diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 45a6c20c59..5e1fbecb5f 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -7,4 +7,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.24.0' +__version__ = '4.25.0rc1' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 8a292af288..4eb0d5aee8 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.24.0" + s.version = "3.25.0.rc.1" 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.summary = "Protocol Buffers" diff --git a/ruby/pom.xml b/ruby/pom.xml index 2242464e23..a2bf3069c9 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.24.0 + 3.25.0-RC1 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.24.0 + 3.25.0-RC1 org.jruby diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index affeb7b6c8..69b37b6c2a 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 58eb072c74..e43a189578 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 048b5778fa..120c7e4def 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 3936fe2abe..838bb39093 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/compiler/versions.h b/src/google/protobuf/compiler/versions.h index 615944f8be..1dc25ce58a 100644 --- a/src/google/protobuf/compiler/versions.h +++ b/src/google/protobuf/compiler/versions.h @@ -46,8 +46,8 @@ // // Please avoid changing them manually, as they should be updated automatically // by Protobuf release process. -#define PROTOBUF_CPP_VERSION_STRING "4.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX -#define PROTOBUF_JAVA_VERSION_STRING "3.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX -#define PROTOBUF_PYTHON_VERSION_STRING "4.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX +#define PROTOBUF_CPP_VERSION_STRING "4.25.0" PROTOBUF_GENCODE_VERSION_SUFFIX +#define PROTOBUF_JAVA_VERSION_STRING "3.25.0" PROTOBUF_GENCODE_VERSION_SUFFIX +#define PROTOBUF_PYTHON_VERSION_STRING "4.25.0" PROTOBUF_GENCODE_VERSION_SUFFIX #endif // GOOGLE_PROTOBUF_VERSIONS_H__ diff --git a/src/google/protobuf/compiler/versions_suffix.h b/src/google/protobuf/compiler/versions_suffix.h index 5fd30faf0d..3a3638340b 100644 --- a/src/google/protobuf/compiler/versions_suffix.h +++ b/src/google/protobuf/compiler/versions_suffix.h @@ -21,6 +21,6 @@ // // Please avoid changing it manually, as they should be updated automatically by // the Protobuf release process. -#define PROTOBUF_GENCODE_VERSION_SUFFIX "-main" +#define PROTOBUF_GENCODE_VERSION_SUFFIX "-rc1" #endif // GOOGLE_PROTOBUF_COMPILER_VERSIONS_SUFFIX_H__ diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index 8169b4fb86..e157f66d30 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index dea31b5075..11cc7eba39 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index b3d14923b2..2cb6c93f87 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index f66a7258ec..1b929ecffe 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index a9c9868453..7eda512567 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index f131670a30..5e2e67b580 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -204,22 +204,22 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 4024000 +#define PROTOBUF_VERSION 4025000 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined #endif -#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 4024000 +#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 4025000 #ifdef PROTOBUF_MIN_PROTOC_VERSION #error PROTOBUF_MIN_PROTOC_VERSION was previously defined #endif -#define PROTOBUF_MIN_PROTOC_VERSION 4024000 +#define PROTOBUF_MIN_PROTOC_VERSION 4025000 #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined #endif -#define PROTOBUF_VERSION_SUFFIX "" +#define PROTOBUF_VERSION_SUFFIX "-rc1" #ifdef PROTOBUF_MINIMUM_EDITION #error PROTOBUF_MINIMUM_EDITION was previously defined @@ -406,7 +406,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 4024000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 4025000 #ifdef PROTOBUF_RTTI #error PROTOBUF_RTTI was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index e4127454df..0b8b5743bd 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 70deb30046..abcd72fcb8 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 5eb0df4c02..869a1c0d7e 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -44,23 +44,23 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 4024000 +#define GOOGLE_PROTOBUF_VERSION 4025000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. -#define GOOGLE_PROTOBUF_VERSION_SUFFIX "" +#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-rc1" // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 4024000; +static const int kMinHeaderVersionForLibrary = 4025000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 4024000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 4025000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 4024000; +static const int kMinHeaderVersionForProtoc = 4025000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index bb0b9dd972..9d8b206b8f 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index bbde59acd2..da88a5d1f0 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 122972a547..ee9a88cbde 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/version.json b/version.json index 6f7526ea3d..8b338e104d 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { - "main": { - "protoc_version": "25-dev", + "25.x": { + "protoc_version": "25.0-rc1", "lts": false, - "date": "2023-07-11", + "date": "2023-10-16", "languages": { - "cpp": "4.25-dev", - "csharp": "3.25-dev", - "java": "3.25-dev", - "javascript": "3.25-dev", - "objectivec": "3.25-dev", - "php": "3.25-dev", - "python": "4.25-dev", - "ruby": "3.25-dev" + "cpp": "4.25.0-rc1", + "csharp": "3.25.0-rc1", + "java": "3.25.0-rc1", + "javascript": "3.25.0-rc1", + "objectivec": "3.25.0-rc1", + "php": "3.25.0-rc1", + "python": "4.25.0-rc1", + "ruby": "3.25.0-rc1" } } } \ No newline at end of file From ef2228a36b8c549ff896e9ef40672377e47c540e Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 16 Oct 2023 12:36:52 -0700 Subject: [PATCH 002/387] Updating version.json to: 25.0-dev --- version.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/version.json b/version.json index 8b338e104d..5c3c0557ea 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "25.x": { - "protoc_version": "25.0-rc1", + "protoc_version": "25.0-dev", "lts": false, "date": "2023-10-16", "languages": { - "cpp": "4.25.0-rc1", - "csharp": "3.25.0-rc1", - "java": "3.25.0-rc1", - "javascript": "3.25.0-rc1", - "objectivec": "3.25.0-rc1", - "php": "3.25.0-rc1", - "python": "4.25.0-rc1", - "ruby": "3.25.0-rc1" + "cpp": "4.25.0-dev", + "csharp": "3.25.0-dev", + "java": "3.25.0-dev", + "javascript": "3.25.0-dev", + "objectivec": "3.25.0-dev", + "php": "3.25.0-dev", + "python": "4.25.0-dev", + "ruby": "3.25.0-dev" } } } \ No newline at end of file From ada0be86608dc10b3c2c46e7e2a0951015abbcc3 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 16 Oct 2023 18:43:35 -0700 Subject: [PATCH 003/387] Update stale checked-in files (#14431) This should fix the postsubmit test failures on 25.x by updating the checked-in files to match the new version number. --- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.h | 2 +- src/google/protobuf/compiler/plugin.pb.h | 2 +- src/google/protobuf/cpp_features.pb.h | 2 +- src/google/protobuf/descriptor.pb.h | 2 +- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/field_mask.pb.h | 2 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.h | 2 +- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.h | 2 +- src/google/protobuf/wrappers.pb.h | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 69b37b6c2a..02c0fd0e13 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index e43a189578..0528fd486b 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 838bb39093..793da14114 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/plugin.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index e157f66d30..cf71ba5475 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/cpp_features.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 11cc7eba39..57d3aac804 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/descriptor.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 2cb6c93f87..4fbcf72481 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 1b929ecffe..01038538ef 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 7eda512567..1219edf5b9 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 0b8b5743bd..ce751aae5c 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index abcd72fcb8..cd46e36068 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 9d8b206b8f..31b2fa99fc 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index da88a5d1f0..2dac8b88e6 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index ee9a88cbde..40c030635d 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc1 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh From db89a51e4557c40abc8845b13277a83cdf917382 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 17 Oct 2023 09:11:39 -0700 Subject: [PATCH 004/387] Set `PROTOBUF_EXPORT` on `InternalOutOfLineDeleteMessageLite()` (#14434) This function needs to be visible to generated code, so this CL ensures that it's exported on libprotobuf.so. PiperOrigin-RevId: 573980166 --- src/google/protobuf/repeated_ptr_field.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index d9d8d8fb4c..d38232462e 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -863,7 +863,7 @@ void RepeatedPtrFieldBase::MergeFrom( const RepeatedPtrFieldBase& from); -void InternalOutOfLineDeleteMessageLite(MessageLite* message); +PROTOBUF_EXPORT void InternalOutOfLineDeleteMessageLite(MessageLite* message); template class GenericTypeHandler { From b4abcef8a954383d860a9367465fb398e5992d82 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Tue, 17 Oct 2023 09:07:52 -0700 Subject: [PATCH 005/387] Bump minimum PHP to 8.0 Fixes #14436 PiperOrigin-RevId: 574168872 --- php/ext/google/protobuf/template_package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/template_package.xml b/php/ext/google/protobuf/template_package.xml index f8d6e66f6f..766a0b0d3e 100644 --- a/php/ext/google/protobuf/template_package.xml +++ b/php/ext/google/protobuf/template_package.xml @@ -30,7 +30,7 @@ - 7.0.0 + 8.0.0 1.4.0 From 3f05c099c3ad62b4af33cf4e78bc4674c32cc680 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Tue, 17 Oct 2023 13:12:51 -0400 Subject: [PATCH 006/387] update test runners --- .github/workflows/test_php_ext.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_php_ext.yml b/.github/workflows/test_php_ext.yml index ec65715119..e80afa0865 100644 --- a/.github/workflows/test_php_ext.yml +++ b/.github/workflows/test_php_ext.yml @@ -41,7 +41,7 @@ jobs: strategy: fail-fast: false # Don't cancel all jobs if one fails. matrix: - version: ["7.4", "8.1", "8.2"] + version: ["8.0", "8.1", "8.2"] name: Build ${{ matrix.version }} runs-on: ubuntu-latest steps: From ba1aab2baf19e83cc8c5532f98e5f90bd6d21fd5 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 18 Oct 2023 09:57:30 -0700 Subject: [PATCH 007/387] Updating version.json and repo version numbers to: 25.0-rc2 --- CMakeLists.txt | 2 +- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/README.md | 6 +++--- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/kotlin-lite/pom.xml | 2 +- java/kotlin/pom.xml | 2 +- java/lite.md | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/protoc/pom.xml | 2 +- java/util/pom.xml | 2 +- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 10 +++++----- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 ++-- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.h | 2 +- .../protobuf/compiler/java/java_features.pb.h | 2 +- src/google/protobuf/compiler/plugin.pb.h | 2 +- .../protobuf/compiler/versions_suffix.h | 2 +- src/google/protobuf/cpp_features.pb.h | 2 +- src/google/protobuf/descriptor.pb.h | 2 +- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/field_mask.pb.h | 2 +- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.h | 2 +- src/google/protobuf/stubs/common.h | 2 +- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.h | 2 +- src/google/protobuf/wrappers.pb.h | 2 +- version.json | 20 +++++++++---------- 38 files changed, 54 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b4f36893d..868674460e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ if (protobuf_BUILD_SHARED_LIBS) endif () # Version metadata -set(protobuf_VERSION_STRING "4.25.0-rc-1") +set(protobuf_VERSION_STRING "4.25.0-rc-2") set(protobuf_DESCRIPTION "Protocol Buffers") set(protobuf_CONTACT "protobuf@googlegroups.com") diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 29c49d02f9..4f7ce1f7ee 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '4.25.0-rc1' + s.version = '4.25.0-rc2' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' diff --git a/Protobuf.podspec b/Protobuf.podspec index ef3b315579..6852f2d265 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.25.0-rc1' + s.version = '3.25.0-rc2' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 9b1508c2f1..4cd5e49707 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.25.0-rc1 + 3.25.0-rc2 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 447b824173..1623bd1e2c 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -5,7 +5,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.25.0-rc1 + 3.25.0-rc2 10.0 Google Inc. netstandard1.1;netstandard2.0;net45;net50 diff --git a/java/README.md b/java/README.md index 45e5edd18b..acbdb00051 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.25.0-rc-1 + 3.25.0-rc-2 ``` @@ -37,14 +37,14 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.25.0-rc-1 + 3.25.0-rc-2 ``` ### Gradle If you are using Gradle, add the following to your `build.gradle` file's -dependencies: `implementation 'com.google.protobuf:protobuf-java:3.25.0-rc-1'` Again, +dependencies: `implementation 'com.google.protobuf:protobuf-java:3.25.0-rc-2'` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index aa715919f6..24a7ba1d42 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.25.0-RC1 + 3.25.0-RC2 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 794cfc6aac..8942e32b59 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC1 + 3.25.0-RC2 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 2cfe928a4f..0074e6f7fa 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC1 + 3.25.0-RC2 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 8b2c2a82f0..b7dd892c10 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC1 + 3.25.0-RC2 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index d7a07b3968..910546619b 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.25.0-rc-1 + 3.25.0-rc-2 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index d88eff6343..9d4ab79be5 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC1 + 3.25.0-RC2 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 9794219de4..44dda53871 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC1 + 3.25.0-RC2 pom Protocol Buffers [Parent] diff --git a/java/protoc/pom.xml b/java/protoc/pom.xml index b9d1f9b679..f3002179fb 100644 --- a/java/protoc/pom.xml +++ b/java/protoc/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.25.0-RC1 + 3.25.0-RC2 pom Protobuf Compiler diff --git a/java/util/pom.xml b/java/util/pom.xml index 686a8b6f9e..d374d425c9 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC1 + 3.25.0-RC2 protobuf-java-util diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 81bb489a9e..ad138218b8 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -32,7 +32,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.25.0RC1" +#define PHP_PROTOBUF_VERSION "3.25.0RC2" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protobuf_version.bzl b/protobuf_version.bzl index a0660c18a6..ed03f12247 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,6 +1,6 @@ """ Contains version numbers to be used in other bzl files """ -PROTOC_VERSION = "25.0-rc-1" -PROTOBUF_JAVA_VERSION = "3.25.0-RC1" -PROTOBUF_PYTHON_VERSION = "4.25.0rc1" -PROTOBUF_PHP_VERSION = "3.25.0RC1" -PROTOBUF_RUBY_VERSION = "3.25.0.rc.1" +PROTOC_VERSION = "25.0-rc-2" +PROTOBUF_JAVA_VERSION = "3.25.0-RC2" +PROTOBUF_PYTHON_VERSION = "4.25.0rc2" +PROTOBUF_PHP_VERSION = "3.25.0RC2" +PROTOBUF_RUBY_VERSION = "3.25.0.rc.2" diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 5e1fbecb5f..09f7a3d8b6 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -7,4 +7,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.25.0rc1' +__version__ = '4.25.0rc2' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 4eb0d5aee8..ecfa8f97c3 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.25.0.rc.1" + s.version = "3.25.0.rc.2" 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.summary = "Protocol Buffers" diff --git a/ruby/pom.xml b/ruby/pom.xml index a2bf3069c9..4f60d02c19 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.25.0-RC1 + 3.25.0-RC2 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.25.0-RC1 + 3.25.0-RC2 org.jruby diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 02c0fd0e13..89cb011789 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 0528fd486b..a778c373bd 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 120c7e4def..64297ead99 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/java/java_features.proto -// Protobuf C++ Version: 4.24.0-main +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_2epb_2eh diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 793da14114..459abfcbe8 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/plugin.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh diff --git a/src/google/protobuf/compiler/versions_suffix.h b/src/google/protobuf/compiler/versions_suffix.h index 3a3638340b..0210cb7dff 100644 --- a/src/google/protobuf/compiler/versions_suffix.h +++ b/src/google/protobuf/compiler/versions_suffix.h @@ -21,6 +21,6 @@ // // Please avoid changing it manually, as they should be updated automatically by // the Protobuf release process. -#define PROTOBUF_GENCODE_VERSION_SUFFIX "-rc1" +#define PROTOBUF_GENCODE_VERSION_SUFFIX "-rc2" #endif // GOOGLE_PROTOBUF_COMPILER_VERSIONS_SUFFIX_H__ diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index cf71ba5475..3898235022 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/cpp_features.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 57d3aac804..560e66c459 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/descriptor.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 4fbcf72481..a306db4f7a 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 01038538ef..91ef8c784b 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 1219edf5b9..bb2ca71253 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 5e2e67b580..a89add5912 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -219,7 +219,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined #endif -#define PROTOBUF_VERSION_SUFFIX "-rc1" +#define PROTOBUF_VERSION_SUFFIX "-rc2" #ifdef PROTOBUF_MINIMUM_EDITION #error PROTOBUF_MINIMUM_EDITION was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index ce751aae5c..066c0a45d6 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index cd46e36068..e50cf53b32 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 869a1c0d7e..cfd72f171c 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -47,7 +47,7 @@ namespace internal { #define GOOGLE_PROTOBUF_VERSION 4025000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. -#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-rc1" +#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-rc2" // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 31b2fa99fc..0c513a27a9 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 2dac8b88e6..362165804d 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 40c030635d..224ccd5c4a 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -// Protobuf C++ Version: 4.25.0-rc1 +// Protobuf C++ Version: 4.25.0-rc2 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh diff --git a/version.json b/version.json index 5c3c0557ea..c8a1223a46 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "25.x": { - "protoc_version": "25.0-dev", + "protoc_version": "25.0-rc2", "lts": false, - "date": "2023-10-16", + "date": "2023-10-18", "languages": { - "cpp": "4.25.0-dev", - "csharp": "3.25.0-dev", - "java": "3.25.0-dev", - "javascript": "3.25.0-dev", - "objectivec": "3.25.0-dev", - "php": "3.25.0-dev", - "python": "4.25.0-dev", - "ruby": "3.25.0-dev" + "cpp": "4.25.0-rc2", + "csharp": "3.25.0-rc2", + "java": "3.25.0-rc2", + "javascript": "3.25.0-rc2", + "objectivec": "3.25.0-rc2", + "php": "3.25.0-rc2", + "python": "4.25.0-rc2", + "ruby": "3.25.0-rc2" } } } \ No newline at end of file From 08b6c404af3cba3e054bec05221faa296584dba9 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 18 Oct 2023 09:57:30 -0700 Subject: [PATCH 008/387] Updating version.json to: 25.0-dev --- version.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/version.json b/version.json index c8a1223a46..4263fdcd3a 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "25.x": { - "protoc_version": "25.0-rc2", + "protoc_version": "25.0-dev", "lts": false, "date": "2023-10-18", "languages": { - "cpp": "4.25.0-rc2", - "csharp": "3.25.0-rc2", - "java": "3.25.0-rc2", - "javascript": "3.25.0-rc2", - "objectivec": "3.25.0-rc2", - "php": "3.25.0-rc2", - "python": "4.25.0-rc2", - "ruby": "3.25.0-rc2" + "cpp": "4.25.0-dev", + "csharp": "3.25.0-dev", + "java": "3.25.0-dev", + "javascript": "3.25.0-dev", + "objectivec": "3.25.0-dev", + "php": "3.25.0-dev", + "python": "4.25.0-dev", + "ruby": "3.25.0-dev" } } } \ No newline at end of file From c68554cc24e2d0bd35757f07bcc7f87db13bac04 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 24 Oct 2023 06:57:24 -0700 Subject: [PATCH 009/387] Optimize RepeatedPtrField constructors. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Writing zeros is faster as they are often available in the cache as well as it can be done with less instructions on common platforms. ``` BM_RepeatedPtrField_Ctor 125ns ± 3% 118ns ± 3% -5.34% (p=0.000 n=217+219) ``` PiperOrigin-RevId: 576126835 --- src/google/protobuf/repeated_ptr_field.cc | 31 ++++--- src/google/protobuf/repeated_ptr_field.h | 102 +++++++++++++--------- 2 files changed, 80 insertions(+), 53 deletions(-) diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 19b4ca59c4..734a6a7188 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -20,6 +20,7 @@ #include "absl/log/absl_check.h" #include "google/protobuf/arena.h" #include "google/protobuf/implicit_weak_message.h" +#include "google/protobuf/message_lite.h" #include "google/protobuf/port.h" #include "google/protobuf/repeated_field.h" @@ -34,10 +35,11 @@ namespace internal { void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { ABSL_DCHECK(extend_amount > 0); constexpr size_t ptr_size = sizeof(rep()->elements[0]); - int new_capacity = total_size_ + extend_amount; + int capacity = Capacity(); + int new_capacity = capacity + extend_amount; Arena* arena = GetArena(); new_capacity = internal::CalculateReserveSize( - total_size_, new_capacity); + capacity, new_capacity); ABSL_CHECK_LE( static_cast(new_capacity), static_cast( @@ -45,7 +47,6 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { << "Requested size is too large to fit into size_t."; size_t bytes = kRepHeaderSize + ptr_size * new_capacity; Rep* new_rep; - void* old_tagged_ptr = tagged_rep_or_elem_; if (arena == nullptr) { internal::SizedPtr res = internal::AllocateAtLeast(bytes); new_capacity = static_cast((res.n - kRepHeaderSize) / ptr_size); @@ -55,18 +56,17 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { } if (using_sso()) { - new_rep->allocated_size = old_tagged_ptr != nullptr ? 1 : 0; - new_rep->elements[0] = old_tagged_ptr; + new_rep->allocated_size = tagged_rep_or_elem_ != nullptr ? 1 : 0; + new_rep->elements[0] = tagged_rep_or_elem_; } else { - Rep* old_rep = - reinterpret_cast(reinterpret_cast(old_tagged_ptr) - 1); + Rep* old_rep = rep(); if (old_rep->allocated_size > 0) { memcpy(new_rep->elements, old_rep->elements, old_rep->allocated_size * ptr_size); } new_rep->allocated_size = old_rep->allocated_size; - size_t old_size = total_size_ * ptr_size + kRepHeaderSize; + size_t old_size = capacity * ptr_size + kRepHeaderSize; if (arena == nullptr) { internal::SizedDelete(old_rep, old_size); } else { @@ -76,13 +76,14 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { tagged_rep_or_elem_ = reinterpret_cast(reinterpret_cast(new_rep) + 1); - total_size_ = new_capacity; + capacity_proxy_ = new_capacity - kSSOCapacity; return &new_rep->elements[current_size_]; } void RepeatedPtrFieldBase::Reserve(int capacity) { - if (capacity > total_size_) { - InternalExtend(capacity - total_size_); + int delta = capacity - Capacity(); + if (delta > 0) { + InternalExtend(delta); } } @@ -98,7 +99,7 @@ void RepeatedPtrFieldBase::DestroyProtos() { for (int i = 0; i < n; i++) { delete static_cast(elements[i]); } - const size_t size = total_size_ * sizeof(elements[0]) + kRepHeaderSize; + const size_t size = Capacity() * sizeof(elements[0]) + kRepHeaderSize; internal::SizedDelete(r, size); } @@ -115,7 +116,9 @@ void* RepeatedPtrFieldBase::AddOutOfLineHelper(void* obj) { ExchangeCurrentSize(1); return tagged_rep_or_elem_ = obj; } - if (using_sso() || rep()->allocated_size == total_size_) { + // Not using `AllocatedSizeAtCapacity` because it's already known that + // `tagged_rep_or_elem_ != nullptr`. + if (using_sso() || rep()->allocated_size >= Capacity()) { InternalExtend(1); // Equivalent to "Reserve(total_size_ + 1)" } Rep* r = rep(); @@ -134,7 +137,7 @@ void* RepeatedPtrFieldBase::AddOutOfLineHelper(ElementFactory factory) { } else { absl::PrefetchToLocalCache(rep()); } - if (PROTOBUF_PREDICT_FALSE(current_size_ == total_size_)) { + if (PROTOBUF_PREDICT_FALSE(SizeAtCapacity())) { InternalExtend(1); } else { Rep* r = rep(); diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 5894e777e2..fe38aac865 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -177,12 +177,12 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { constexpr RepeatedPtrFieldBase() : tagged_rep_or_elem_(nullptr), current_size_(0), - total_size_(kSSOCapacity), + capacity_proxy_(0), arena_(nullptr) {} explicit RepeatedPtrFieldBase(Arena* arena) : tagged_rep_or_elem_(nullptr), current_size_(0), - total_size_(kSSOCapacity), + capacity_proxy_(0), arena_(arena) {} RepeatedPtrFieldBase(const RepeatedPtrFieldBase&) = delete; @@ -198,7 +198,13 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { bool empty() const { return current_size_ == 0; } int size() const { return current_size_; } - int Capacity() const { return total_size_; } + // Returns the size of the buffer with pointers to elements. + // + // Note: + // + // * prefer `SizeAtCapacity()` to `size() == Capacity()`; + // * prefer `AllocatedSizeAtCapacity()` to `allocated_size() == Capacity()`. + int Capacity() const { return capacity_proxy_ + kSSOCapacity; } template const Value& at(int index) const { @@ -271,7 +277,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { } if (!using_sso()) { internal::SizedDelete(rep(), - total_size_ * sizeof(elems[0]) + kRepHeaderSize); + Capacity() * sizeof(elems[0]) + kRepHeaderSize); } } @@ -417,7 +423,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { size_t allocated_bytes = using_sso() ? 0 - : static_cast(total_size_) * sizeof(void*) + kRepHeaderSize; + : static_cast(Capacity()) * sizeof(void*) + kRepHeaderSize; const int n = allocated_size(); void* const* elems = elements(); for (int i = 0; i < n; ++i) { @@ -451,11 +457,11 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { void UnsafeArenaAddAllocated(Value* value) { ABSL_DCHECK_NE(value, nullptr); // Make room for the new pointer. - if (current_size_ == total_size_) { + if (SizeAtCapacity()) { // The array is completely full with no cleared objects, so grow it. - Reserve(total_size_ + 1); + InternalExtend(1); ++rep()->allocated_size; - } else if (allocated_size() == total_size_) { + } else if (AllocatedSizeAtCapacity()) { // There is no more space in the pointer array because it contains some // cleared objects awaiting reuse. We don't want to grow the array in // this case because otherwise a loop calling AddAllocated() followed by @@ -539,41 +545,41 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { void AddAllocatedInternal(Value* value, std::true_type) { Arena* element_arena = TypeHandler::GetArena(value); Arena* arena = GetArena(); - if (arena == element_arena && allocated_size() < total_size_) { - // Fast path: underlying arena representation (tagged pointer) is equal to - // our arena pointer, and we can add to array without resizing it (at - // least one slot that is not allocated). - void** elems = elements(); - if (current_size_ < allocated_size()) { - // Make space at [current] by moving first allocated element to end of - // allocated list. - elems[allocated_size()] = elems[current_size_]; - } - elems[ExchangeCurrentSize(current_size_ + 1)] = value; - if (!using_sso()) ++rep()->allocated_size; - } else { + if (arena != element_arena || AllocatedSizeAtCapacity()) { AddAllocatedSlowWithCopy(value, element_arena, arena); + return; + } + // Fast path: underlying arena representation (tagged pointer) is equal to + // our arena pointer, and we can add to array without resizing it (at + // least one slot that is not allocated). + void** elems = elements(); + if (current_size_ < allocated_size()) { + // Make space at [current] by moving first allocated element to end of + // allocated list. + elems[allocated_size()] = elems[current_size_]; } + elems[ExchangeCurrentSize(current_size_ + 1)] = value; + if (!using_sso()) ++rep()->allocated_size; } // AddAllocated version that does not implement arena-safe copying behavior. template void AddAllocatedInternal(Value* value, std::false_type) { - if (allocated_size() < total_size_) { - // Fast path: underlying arena representation (tagged pointer) is equal to - // our arena pointer, and we can add to array without resizing it (at - // least one slot that is not allocated). - void** elems = elements(); - if (current_size_ < allocated_size()) { - // Make space at [current] by moving first allocated element to end of - // allocated list. - elems[allocated_size()] = elems[current_size_]; - } - elems[ExchangeCurrentSize(current_size_ + 1)] = value; - if (!using_sso()) ++rep()->allocated_size; - } else { + if (AllocatedSizeAtCapacity()) { UnsafeArenaAddAllocated(value); + return; } + // Fast path: underlying arena representation (tagged pointer) is equal to + // our arena pointer, and we can add to array without resizing it (at + // least one slot that is not allocated). + void** elems = elements(); + if (current_size_ < allocated_size()) { + // Make space at [current] by moving first allocated element to end of + // allocated list. + elems[allocated_size()] = elems[current_size_]; + } + elems[ExchangeCurrentSize(current_size_ + 1)] = value; + if (!using_sso()) ++rep()->allocated_size; } // Slowpath handles all cases, copying if necessary. @@ -715,6 +721,25 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { inline int ExchangeCurrentSize(int new_size) { return std::exchange(current_size_, new_size); } + inline bool SizeAtCapacity() const { + // Harden invariant size() <= allocated_size() <= Capacity(). + ABSL_DCHECK_LE(size(), allocated_size()); + ABSL_DCHECK_LE(allocated_size(), Capacity()); + // This is equivalent to `current_size_ == Capacity()`. + // Assuming `Capacity()` function is inlined, compiler is likely to optimize + // away "+ kSSOCapacity" and reduce it to "current_size_ > capacity_proxy_" + // which is an instruction less than "current_size_ == capacity_proxy_ + 1". + return current_size_ >= Capacity(); + } + inline bool AllocatedSizeAtCapacity() const { + // Harden invariant size() <= allocated_size() <= Capacity(). + ABSL_DCHECK_LE(size(), allocated_size()); + ABSL_DCHECK_LE(allocated_size(), Capacity()); + // This combines optimization mentioned in `SizeAtCapacity()` and simplifies + // `allocated_size()` in sso case. + return using_sso() ? (tagged_rep_or_elem_ != nullptr) + : rep()->allocated_size >= Capacity(); + } void* const* elements() const { return using_sso() ? &tagged_rep_or_elem_ : +rep()->elements; @@ -800,8 +825,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Ensures that capacity is big enough to store one more allocated element. inline void MaybeExtend() { - if (using_sso() ? (tagged_rep_or_elem_ != nullptr) - : (rep()->allocated_size == total_size_)) { + if (AllocatedSizeAtCapacity()) { ABSL_DCHECK_EQ(allocated_size(), Capacity()); InternalExtend(1); } else { @@ -812,11 +836,11 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Ensures that capacity is at least `n` elements. // Returns a pointer to the element directly beyond the last element. inline void** InternalReserve(int n) { - if (n <= total_size_) { + if (n <= Capacity()) { void** elements = using_sso() ? &tagged_rep_or_elem_ : rep()->elements; return elements + current_size_; } - return InternalExtend(n - total_size_); + return InternalExtend(n - Capacity()); } // Internal helper for Add: adds "obj" as the next element in the @@ -838,7 +862,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // significant performance for memory-sensitive workloads. void* tagged_rep_or_elem_; int current_size_; - int total_size_; + int capacity_proxy_; // we store `capacity - kSSOCapacity` as an optimization Arena* arena_; }; From 4d921064518ee66fb1a1a27935d5d16c3aa7e402 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 24 Oct 2023 07:06:20 -0700 Subject: [PATCH 010/387] Make SpaceUsedLong non-virtual to reduce the size of the vtable. PiperOrigin-RevId: 576128619 --- src/google/protobuf/message.cc | 8 +++++++- src/google/protobuf/message.h | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index eb81694daf..2cf07dbdf4 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -188,7 +188,13 @@ size_t Message::MaybeComputeUnknownFieldsSize( } size_t Message::SpaceUsedLong() const { - return GetReflection()->SpaceUsedLong(*this); + auto* reflection = GetReflection(); + if (PROTOBUF_PREDICT_TRUE(reflection != nullptr)) { + return reflection->SpaceUsedLong(*this); + } + // The only case that does not have reflection is RawMessage. + return internal::DownCast(*this) + .SpaceUsedLong(); } static std::string GetTypeNameImpl(const MessageLite& msg) { diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 83ba793e93..47f41b89ec 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -286,8 +286,7 @@ class PROTOBUF_EXPORT Message : public MessageLite { void DiscardUnknownFields(); // Computes (an estimate of) the total number of bytes currently used for - // storing the message in memory. The default implementation calls the - // Reflection object's SpaceUsed() method. + // storing the message in memory. // // SpaceUsed() is noticeably slower than ByteSize(), as it is implemented // using reflection (rather than the generated code implementation for @@ -297,7 +296,7 @@ class PROTOBUF_EXPORT Message : public MessageLite { // Note: The precise value of this method should never be depended on, and can // change substantially due to internal details. In debug builds, this will // include a random fuzz factor to prevent these dependencies. - virtual size_t SpaceUsedLong() const; + size_t SpaceUsedLong() const; [[deprecated("Please use SpaceUsedLong() instead")]] int SpaceUsed() const { return internal::ToIntSize(SpaceUsedLong()); @@ -1573,6 +1572,12 @@ bool SplitFieldHasExtraIndirectionStatic(const FieldDescriptor* field) { return ret; } +class RawMessageBase : public Message { + public: + using Message::Message; + virtual size_t SpaceUsedLong() const = 0; +}; + } // namespace internal template From a14f29e40aa28cd9140d19f0f063752b44f9dd29 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 24 Oct 2023 07:32:19 -0700 Subject: [PATCH 011/387] Internal change PiperOrigin-RevId: 576133829 --- rust/test/shared/BUILD | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/test/shared/BUILD b/rust/test/shared/BUILD index b2c4aaf164..73be626f76 100644 --- a/rust/test/shared/BUILD +++ b/rust/test/shared/BUILD @@ -257,11 +257,19 @@ rust_test( rust_test( name = "simple_nested_cpp_test", srcs = ["simple_nested_test.rs"], + tags = [ + # TODO: Enable testing on arm once we support sanitizers for Rust on Arm. + "not_build:arm", + ], deps = ["//rust/test:nested_cc_rust_proto"], ) rust_test( name = "simple_nested_upb_test", srcs = ["simple_nested_test.rs"], + tags = [ + # TODO: Enable testing on arm once we support sanitizers for Rust on Arm. + "not_build:arm", + ], deps = ["//rust/test:nested_upb_rust_proto"], ) From d76a6300d29d8d9feeeadddc28925ebd610b1f31 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 24 Oct 2023 10:50:34 -0700 Subject: [PATCH 012/387] Automated rollback of commit 4d921064518ee66fb1a1a27935d5d16c3aa7e402. PiperOrigin-RevId: 576194379 --- src/google/protobuf/message.cc | 8 +------- src/google/protobuf/message.h | 11 +++-------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 2cf07dbdf4..eb81694daf 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -188,13 +188,7 @@ size_t Message::MaybeComputeUnknownFieldsSize( } size_t Message::SpaceUsedLong() const { - auto* reflection = GetReflection(); - if (PROTOBUF_PREDICT_TRUE(reflection != nullptr)) { - return reflection->SpaceUsedLong(*this); - } - // The only case that does not have reflection is RawMessage. - return internal::DownCast(*this) - .SpaceUsedLong(); + return GetReflection()->SpaceUsedLong(*this); } static std::string GetTypeNameImpl(const MessageLite& msg) { diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 47f41b89ec..83ba793e93 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -286,7 +286,8 @@ class PROTOBUF_EXPORT Message : public MessageLite { void DiscardUnknownFields(); // Computes (an estimate of) the total number of bytes currently used for - // storing the message in memory. + // storing the message in memory. The default implementation calls the + // Reflection object's SpaceUsed() method. // // SpaceUsed() is noticeably slower than ByteSize(), as it is implemented // using reflection (rather than the generated code implementation for @@ -296,7 +297,7 @@ class PROTOBUF_EXPORT Message : public MessageLite { // Note: The precise value of this method should never be depended on, and can // change substantially due to internal details. In debug builds, this will // include a random fuzz factor to prevent these dependencies. - size_t SpaceUsedLong() const; + virtual size_t SpaceUsedLong() const; [[deprecated("Please use SpaceUsedLong() instead")]] int SpaceUsed() const { return internal::ToIntSize(SpaceUsedLong()); @@ -1572,12 +1573,6 @@ bool SplitFieldHasExtraIndirectionStatic(const FieldDescriptor* field) { return ret; } -class RawMessageBase : public Message { - public: - using Message::Message; - virtual size_t SpaceUsedLong() const = 0; -}; - } // namespace internal template From a286c9b56d6fd81984cb510f1db902ec96fd34c7 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Wed, 25 Oct 2023 13:40:04 -0700 Subject: [PATCH 013/387] upb: create upb/reflection/BUILD PiperOrigin-RevId: 576631037 --- .github/workflows/test_upb.yml | 2 +- upb/BUILD | 215 +++++++-------------------------- upb/reflection/BUILD | 174 ++++++++++++++++++++++++++ upb_generator/BUILD | 22 ++-- 4 files changed, 227 insertions(+), 186 deletions(-) create mode 100644 upb/reflection/BUILD diff --git a/.github/workflows/test_upb.yml b/.github/workflows/test_upb.yml index 21ec308876..f2c1cfa2e4 100644 --- a/.github/workflows/test_upb.yml +++ b/.github/workflows/test_upb.yml @@ -76,7 +76,7 @@ jobs: credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: "upb-bazel-windows" bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 //upb/... //upb_generator/... //python/... //protos/... //protos_generator/... - exclude-targets: -//python:conformance_test -//upb:def_builder_test + exclude-targets: -//python:conformance_test -//upb/reflection:def_builder_test macos: strategy: diff --git a/upb/BUILD b/upb/BUILD index 02d65bdee2..16c67b17e0 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -8,14 +8,7 @@ load("@rules_python//python:defs.bzl", "py_binary") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") -load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library") -load("//bazel:upb_proto_library.bzl", "upb_proto_reflection_library") load("//bazel:upb_proto_library_internal/copts.bzl", "upb_proto_library_copts") -load( - "//upb_generator:bootstrap_compiler.bzl", - "bootstrap_cc_library", - "bootstrap_upb_proto_library", -) # begin:google_only # load("//tools/build_defs/kotlin/native:rules.bzl", "kt_native_interop_hint") @@ -111,7 +104,7 @@ cc_library( hdrs = ["generated_code_support.h"], copts = UPB_DEFAULT_COPTS, textual_hdrs = [ - "//upb/port:inc", + ":port_inc", ], visibility = ["//visibility:public"], deps = [ @@ -133,176 +126,54 @@ cc_library( name = "generated_cpp_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", copts = UPB_DEFAULT_COPTS, textual_hdrs = [ - "//upb/port:inc", + ":port_inc", ], visibility = ["//visibility:public"], ) -cc_library( - name = "generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", - hdrs = [ - "reflection/def.h", - "reflection/internal/def_pool.h", - ], - copts = UPB_DEFAULT_COPTS, - textual_hdrs = [ - "//upb/port:inc", - ], - visibility = ["//visibility:public"], - deps = [ - ":mem", - ":mini_descriptor", - ":reflection_internal", - ], -) +# Aliases ###################################################################### +# TODO: Remove these. -bootstrap_upb_proto_library( - name = "descriptor_upb_proto", - base_dir = "reflection/", - # TODO: Export 'net/proto2/proto/descriptor.upb.h' and remove "-layering_check". - features = ["-layering_check"], - google3_src_files = ["net/proto2/proto/descriptor.proto"], - google3_src_rules = ["//net/proto2/proto:descriptor_proto_source"], - oss_src_files = ["google/protobuf/descriptor.proto"], - oss_src_rules = ["//:descriptor_proto_srcs"], - oss_strip_prefix = "third_party/protobuf/github/bootstrap/src", - proto_lib_deps = ["//:descriptor_proto"], +alias( + name = "base", + actual = "//upb/base", visibility = ["//visibility:public"], ) -upb_proto_reflection_library( - name = "descriptor_upb_proto_reflection", +alias( + name = "base_internal", + actual = "//upb/base:internal", visibility = ["//visibility:public"], - deps = ["//:descriptor_proto"], ) -upb_minitable_proto_library( - name = "descriptor_upb_minitable_proto", - visibility = [ - "//upb:__subpackages__", - # begin:github_only - "//python:__subpackages__", - # end:github_only - ], - deps = ["//:descriptor_proto"], -) - -# TODO: Once we can delete the deprecated forwarding headers -# (= everything in upb/) we can move this build target down into reflection/ -bootstrap_cc_library( - name = "reflection", - hdrs = [ - "reflection/def.h", - "reflection/def.hpp", - "reflection/message.h", - "reflection/message.hpp", - ], - bootstrap_deps = [":reflection_internal"], - copts = UPB_DEFAULT_COPTS, +alias( + name = "collections", + actual = "//upb/collections", + deprecation = "use upb:message instead", visibility = ["//visibility:public"], - deps = [ - ":base", - ":mem", - ":message", - ":message_types", - ":message_value", - ":port", - ], ) -bootstrap_cc_library( - name = "reflection_internal", - srcs = [ - "reflection/def_pool.c", - "reflection/def_type.c", - "reflection/desc_state.c", - "reflection/enum_def.c", - "reflection/enum_reserved_range.c", - "reflection/enum_value_def.c", - "reflection/extension_range.c", - "reflection/field_def.c", - "reflection/file_def.c", - "reflection/internal/def_builder.c", - "reflection/internal/def_builder.h", - "reflection/internal/strdup2.c", - "reflection/internal/strdup2.h", - "reflection/message.c", - "reflection/message_def.c", - "reflection/message_reserved_range.c", - "reflection/method_def.c", - "reflection/oneof_def.c", - "reflection/service_def.c", - ], - hdrs = [ - "reflection/common.h", - "reflection/def.h", - "reflection/def.hpp", - "reflection/def_pool.h", - "reflection/def_type.h", - "reflection/enum_def.h", - "reflection/enum_reserved_range.h", - "reflection/enum_value_def.h", - "reflection/extension_range.h", - "reflection/field_def.h", - "reflection/file_def.h", - "reflection/internal/def_pool.h", - "reflection/internal/desc_state.h", - "reflection/internal/enum_def.h", - "reflection/internal/enum_reserved_range.h", - "reflection/internal/enum_value_def.h", - "reflection/internal/extension_range.h", - "reflection/internal/field_def.h", - "reflection/internal/file_def.h", - "reflection/internal/message_def.h", - "reflection/internal/message_reserved_range.h", - "reflection/internal/method_def.h", - "reflection/internal/oneof_def.h", - "reflection/internal/service_def.h", - "reflection/message.h", - "reflection/message.hpp", - "reflection/message_def.h", - "reflection/message_reserved_range.h", - "reflection/method_def.h", - "reflection/oneof_def.h", - "reflection/service_def.h", - ], - bootstrap_deps = [":descriptor_upb_proto"], - copts = UPB_DEFAULT_COPTS, +alias( + name = "descriptor_upb_proto", + actual = "//upb/reflection:descriptor_upb_proto", visibility = ["//visibility:public"], - deps = [ - ":base", - ":hash", - ":mem", - ":message", - ":message_accessors", - ":message_types", - ":message_value", - ":mini_descriptor", - ":mini_descriptor_internal", - ":mini_table", - ":port", - ], ) -# Aliases ###################################################################### -# TODO: Remove these. - alias( - name = "base", - actual = "//upb/base", + name = "descriptor_upb_minitable_proto", + actual = "//upb/reflection:descriptor_upb_minitable_proto", visibility = ["//visibility:public"], ) alias( - name = "base_internal", - actual = "//upb/base:internal", + name = "descriptor_upb_proto_reflection", + actual = "//upb/reflection:descriptor_upb_proto_reflection", visibility = ["//visibility:public"], ) alias( - name = "collections", - actual = "//upb/collections", - deprecation = "use upb:message instead", + name = "generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", + actual = "//upb/reflection:generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", visibility = ["//visibility:public"], ) @@ -438,6 +309,24 @@ alias( visibility = ["//visibility:public"], ) +alias( + name = "port_inc", + actual = "//upb/port:inc", + visibility = ["//visibility:public"], +) + +alias( + name = "reflection", + actual = "//upb/reflection", + visibility = ["//visibility:public"], +) + +alias( + name = "reflection_internal", + actual = "//upb/reflection:internal", + visibility = ["//visibility:public"], +) + alias( name = "text", actual = "//upb/text", @@ -474,28 +363,6 @@ alias( visibility = ["//visibility:public"], ) -# Tests ######################################################################## - -cc_test( - name = "def_builder_test", - srcs = [ - "reflection/common.h", - "reflection/def_type.h", - "reflection/internal/def_builder.h", - "reflection/internal/def_builder_test.cc", - ], - deps = [ - ":descriptor_upb_proto", - ":hash", - ":mem", - ":port", - ":reflection", - ":reflection_internal", - "@com_google_googletest//:gtest_main", - "@com_google_absl//absl/strings", - ], -) - # Internal C/C++ libraries ##################################################### cc_binary( diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD new file mode 100644 index 0000000000..380ae38e51 --- /dev/null +++ b/upb/reflection/BUILD @@ -0,0 +1,174 @@ +# Copyright (c) 2009-2021, Google LLC +# All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + +load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") +load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library") +load("//bazel:upb_proto_library.bzl", "upb_proto_reflection_library") +load( + "//upb_generator:bootstrap_compiler.bzl", + "bootstrap_cc_library", + "bootstrap_upb_proto_library", +) + +bootstrap_upb_proto_library( + name = "descriptor_upb_proto", + base_dir = "", + # TODO: Export 'net/proto2/proto/descriptor.upb.h' and remove "-layering_check". + features = ["-layering_check"], + google3_src_files = ["net/proto2/proto/descriptor.proto"], + google3_src_rules = ["//net/proto2/proto:descriptor_proto_source"], + oss_src_files = ["google/protobuf/descriptor.proto"], + oss_src_rules = ["//:descriptor_proto_srcs"], + oss_strip_prefix = "third_party/protobuf/github/bootstrap/src", + proto_lib_deps = ["//:descriptor_proto"], + visibility = ["//visibility:public"], +) + +upb_proto_reflection_library( + name = "descriptor_upb_proto_reflection", + visibility = ["//visibility:public"], + deps = ["//:descriptor_proto"], +) + +upb_minitable_proto_library( + name = "descriptor_upb_minitable_proto", + visibility = ["//visibility:public"], + deps = ["//:descriptor_proto"], +) + +bootstrap_cc_library( + name = "reflection", + hdrs = [ + "def.h", + "def.hpp", + "message.h", + "message.hpp", + ], + bootstrap_deps = [":internal"], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + "//upb:base", + "//upb:mem", + "//upb:message", + "//upb:message_types", + "//upb:message_value", + "//upb:port", + ], +) + +bootstrap_cc_library( + name = "internal", + srcs = [ + "def_pool.c", + "def_type.c", + "desc_state.c", + "enum_def.c", + "enum_reserved_range.c", + "enum_value_def.c", + "extension_range.c", + "field_def.c", + "file_def.c", + "internal/def_builder.c", + "internal/def_builder.h", + "internal/strdup2.c", + "internal/strdup2.h", + "message.c", + "message_def.c", + "message_reserved_range.c", + "method_def.c", + "oneof_def.c", + "service_def.c", + ], + hdrs = [ + "common.h", + "def.h", + "def.hpp", + "def_pool.h", + "def_type.h", + "enum_def.h", + "enum_reserved_range.h", + "enum_value_def.h", + "extension_range.h", + "field_def.h", + "file_def.h", + "internal/def_pool.h", + "internal/desc_state.h", + "internal/enum_def.h", + "internal/enum_reserved_range.h", + "internal/enum_value_def.h", + "internal/extension_range.h", + "internal/field_def.h", + "internal/file_def.h", + "internal/message_def.h", + "internal/message_reserved_range.h", + "internal/method_def.h", + "internal/oneof_def.h", + "internal/service_def.h", + "message.h", + "message.hpp", + "message_def.h", + "message_reserved_range.h", + "method_def.h", + "oneof_def.h", + "service_def.h", + ], + bootstrap_deps = [":descriptor_upb_proto"], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + "//upb:base", + "//upb:hash", + "//upb:mem", + "//upb:message", + "//upb:message_accessors", + "//upb:message_types", + "//upb:message_value", + "//upb:mini_descriptor", + "//upb:mini_descriptor_internal", + "//upb:mini_table", + "//upb:port", + ], +) + +cc_library( + name = "generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", + hdrs = [ + "def.h", + "internal/def_pool.h", + ], + copts = UPB_DEFAULT_COPTS, + textual_hdrs = [ + "//upb:port_inc", + ], + visibility = ["//visibility:public"], + deps = [ + "//upb:mem", + "//upb:mini_descriptor", + "//upb:reflection_internal", + ], +) + +cc_test( + name = "def_builder_test", + srcs = [ + "common.h", + "def_type.h", + "internal/def_builder.h", + "internal/def_builder_test.cc", + ], + deps = [ + ":descriptor_upb_proto", + "@com_google_googletest//:gtest_main", + "//upb:hash", + "//upb:mem", + "//upb:port", + "//upb:reflection", + "//upb:reflection_internal", + "@com_google_absl//absl/strings", + ], +) diff --git a/upb_generator/BUILD b/upb_generator/BUILD index 79f2ac3649..723d490402 100644 --- a/upb_generator/BUILD +++ b/upb_generator/BUILD @@ -79,7 +79,7 @@ bootstrap_upb_proto_library( oss_strip_prefix = "third_party/protobuf/github/bootstrap/src", proto_lib_deps = ["//:compiler_plugin_proto"], visibility = ["//upb:friends"], - deps = ["//upb:descriptor_upb_proto"], + deps = ["//upb/reflection:descriptor_upb_proto"], ) upb_proto_reflection_library( @@ -97,7 +97,7 @@ bootstrap_cc_library( "common.h", ], bootstrap_deps = [ - "//upb:reflection", + "//upb/reflection:reflection", ], copts = UPB_DEFAULT_CPPOPTS, visibility = ["//protos_generator:__pkg__"], @@ -119,8 +119,8 @@ bootstrap_cc_library( ], bootstrap_deps = [ ":common", - "//upb:reflection", - "//upb:descriptor_upb_proto", + "//upb/reflection:reflection", + "//upb/reflection:descriptor_upb_proto", ], copts = UPB_DEFAULT_CPPOPTS, visibility = ["//visibility:public"], @@ -154,8 +154,8 @@ bootstrap_cc_library( ], bootstrap_deps = [ ":plugin_upb_proto", - "//upb:descriptor_upb_proto", - "//upb:reflection", + "//upb/reflection:descriptor_upb_proto", + "//upb/reflection:reflection", ], copts = UPB_DEFAULT_CPPOPTS, visibility = ["//protos_generator:__pkg__"], @@ -177,7 +177,7 @@ bootstrap_cc_library( "names.h", ], bootstrap_deps = [ - "//upb:reflection", + "//upb/reflection:reflection", ], copts = UPB_DEFAULT_CPPOPTS, visibility = ["//protos_generator:__pkg__"], @@ -244,8 +244,8 @@ bootstrap_cc_binary( ":names", ":plugin", ":plugin_upb_proto", - "//upb:descriptor_upb_proto", - "//upb:reflection", + "//upb/reflection:descriptor_upb_proto", + "//upb/reflection:reflection", ], copts = UPB_DEFAULT_CPPOPTS, visibility = ["//visibility:public"], @@ -283,8 +283,8 @@ bootstrap_cc_binary( ":names", ":plugin", ":plugin_upb_proto", - "//upb:descriptor_upb_proto", - "//upb:reflection", + "//upb/reflection:descriptor_upb_proto", + "//upb/reflection:reflection", ], copts = UPB_DEFAULT_CPPOPTS, visibility = ["//visibility:public"], From 6df7f0bbef9643f4fdf5c340a49988298044824d Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 25 Oct 2023 21:04:53 -0700 Subject: [PATCH 014/387] Internal changes PiperOrigin-RevId: 576731159 --- src/google/protobuf/descriptor.pb.cc | 18 +++++++++--------- src/google/protobuf/descriptor.pb.h | 10 +++++----- src/google/protobuf/descriptor.proto | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index ae02aa9a2d..88308d71f4 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1864,8 +1864,8 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] AB "SED\020\002\"V\n\025RepeatedFieldEncoding\022#\n\037REPEAT" "ED_FIELD_ENCODING_UNKNOWN\020\000\022\n\n\006PACKED\020\001\022" "\014\n\010EXPANDED\020\002\"C\n\016Utf8Validation\022\033\n\027UTF8_" - "VALIDATION_UNKNOWN\020\000\022\010\n\004NONE\020\001\022\n\n\006VERIFY" - "\020\002\"S\n\017MessageEncoding\022\034\n\030MESSAGE_ENCODIN" + "VALIDATION_UNKNOWN\020\000\022\n\n\006VERIFY\020\002\022\010\n\004NONE" + "\020\003\"S\n\017MessageEncoding\022\034\n\030MESSAGE_ENCODIN" "G_UNKNOWN\020\000\022\023\n\017LENGTH_PREFIXED\020\001\022\r\n\tDELI" "MITED\020\002\"H\n\nJsonFormat\022\027\n\023JSON_FORMAT_UNK" "NOWN\020\000\022\t\n\005ALLOW\020\001\022\026\n\022LEGACY_BEST_EFFORT\020" @@ -2260,16 +2260,16 @@ const ::google::protobuf::EnumDescriptor* FeatureSet_Utf8Validation_descriptor() return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[12]; } PROTOBUF_CONSTINIT const uint32_t FeatureSet_Utf8Validation_internal_data_[] = { - 196608u, 0u, }; + 65536u, 32u, 6u, }; bool FeatureSet_Utf8Validation_IsValid(int value) { - return 0 <= value && value <= 2; + return 0 <= value && value <= 3 && ((13u >> value) & 1) != 0; } #if (__cplusplus < 201703) && \ (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr FeatureSet_Utf8Validation FeatureSet::UTF8_VALIDATION_UNKNOWN; -constexpr FeatureSet_Utf8Validation FeatureSet::NONE; constexpr FeatureSet_Utf8Validation FeatureSet::VERIFY; +constexpr FeatureSet_Utf8Validation FeatureSet::NONE; constexpr FeatureSet_Utf8Validation FeatureSet::Utf8Validation_MIN; constexpr FeatureSet_Utf8Validation FeatureSet::Utf8Validation_MAX; constexpr int FeatureSet::Utf8Validation_ARRAYSIZE; @@ -11687,8 +11687,8 @@ constexpr ::_pbi::TcParseTable<3, 6, 6, 0, 2> FeatureSet::_table_ = { {::_pbi::TcParser::FastEr0S1, {24, 2, 2, PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.repeated_field_encoding_)}}, // optional .google.protobuf.FeatureSet.Utf8Validation utf8_validation = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { - {::_pbi::TcParser::FastEr0S1, - {32, 3, 2, PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.utf8_validation_)}}, + {::_pbi::TcParser::FastEvS1, + {32, 3, 3, PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.utf8_validation_)}}, // optional .google.protobuf.FeatureSet.MessageEncoding message_encoding = 5 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { {::_pbi::TcParser::FastEr0S1, {40, 4, 2, PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.message_encoding_)}}, @@ -11710,7 +11710,7 @@ constexpr ::_pbi::TcParseTable<3, 6, 6, 0, 2> FeatureSet::_table_ = { (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, // optional .google.protobuf.FeatureSet.Utf8Validation utf8_validation = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { {PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.utf8_validation_), _Internal::kHasBitsOffset + 3, 3, - (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, + (0 | ::_fl::kFcOptional | ::_fl::kEnum)}, // optional .google.protobuf.FeatureSet.MessageEncoding message_encoding = 5 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { {PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.message_encoding_), _Internal::kHasBitsOffset + 4, 4, (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, @@ -11721,7 +11721,7 @@ constexpr ::_pbi::TcParseTable<3, 6, 6, 0, 2> FeatureSet::_table_ = { {0, 4}, {0, 3}, {0, 3}, - {0, 3}, + {::_pbi::FieldAuxEnumData{}, ::google::protobuf::FeatureSet_Utf8Validation_internal_data_}, {0, 3}, {0, 3}, }}, {{ diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index ea38e1f3d0..fc613d584d 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -548,15 +548,15 @@ inline bool FeatureSet_RepeatedFieldEncoding_Parse(absl::string_view name, Featu } enum FeatureSet_Utf8Validation : int { FeatureSet_Utf8Validation_UTF8_VALIDATION_UNKNOWN = 0, - FeatureSet_Utf8Validation_NONE = 1, FeatureSet_Utf8Validation_VERIFY = 2, + FeatureSet_Utf8Validation_NONE = 3, }; PROTOBUF_EXPORT bool FeatureSet_Utf8Validation_IsValid(int value); PROTOBUF_EXPORT extern const uint32_t FeatureSet_Utf8Validation_internal_data_[]; constexpr FeatureSet_Utf8Validation FeatureSet_Utf8Validation_Utf8Validation_MIN = static_cast(0); -constexpr FeatureSet_Utf8Validation FeatureSet_Utf8Validation_Utf8Validation_MAX = static_cast(2); -constexpr int FeatureSet_Utf8Validation_Utf8Validation_ARRAYSIZE = 2 + 1; +constexpr FeatureSet_Utf8Validation FeatureSet_Utf8Validation_Utf8Validation_MAX = static_cast(3); +constexpr int FeatureSet_Utf8Validation_Utf8Validation_ARRAYSIZE = 3 + 1; PROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FeatureSet_Utf8Validation_descriptor(); template @@ -569,7 +569,7 @@ const std::string& FeatureSet_Utf8Validation_Name(T value) { template <> inline const std::string& FeatureSet_Utf8Validation_Name(FeatureSet_Utf8Validation value) { return ::google::protobuf::internal::NameOfDenseEnum( + 0, 3>( static_cast(value)); } inline bool FeatureSet_Utf8Validation_Parse(absl::string_view name, FeatureSet_Utf8Validation* value) { @@ -1817,8 +1817,8 @@ class PROTOBUF_EXPORT FeatureSet final : using Utf8Validation = FeatureSet_Utf8Validation; static constexpr Utf8Validation UTF8_VALIDATION_UNKNOWN = FeatureSet_Utf8Validation_UTF8_VALIDATION_UNKNOWN; - static constexpr Utf8Validation NONE = FeatureSet_Utf8Validation_NONE; static constexpr Utf8Validation VERIFY = FeatureSet_Utf8Validation_VERIFY; + static constexpr Utf8Validation NONE = FeatureSet_Utf8Validation_NONE; static inline bool Utf8Validation_IsValid(int value) { return FeatureSet_Utf8Validation_IsValid(value); } diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 474864353a..fe66e71f58 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -974,8 +974,8 @@ message FeatureSet { enum Utf8Validation { UTF8_VALIDATION_UNKNOWN = 0; - NONE = 1; VERIFY = 2; + NONE = 3; } optional Utf8Validation utf8_validation = 4 [ retention = RETENTION_RUNTIME, From 137e5984aff3e7cbc26ce4bf5923ae438cd6ecef Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Thu, 26 Oct 2023 07:23:40 -0700 Subject: [PATCH 015/387] Rollback changes to Utf8Validation PiperOrigin-RevId: 576863528 --- src/google/protobuf/descriptor.pb.cc | 18 +++++++++--------- src/google/protobuf/descriptor.pb.h | 10 +++++----- src/google/protobuf/descriptor.proto | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 88308d71f4..ae02aa9a2d 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1864,8 +1864,8 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] AB "SED\020\002\"V\n\025RepeatedFieldEncoding\022#\n\037REPEAT" "ED_FIELD_ENCODING_UNKNOWN\020\000\022\n\n\006PACKED\020\001\022" "\014\n\010EXPANDED\020\002\"C\n\016Utf8Validation\022\033\n\027UTF8_" - "VALIDATION_UNKNOWN\020\000\022\n\n\006VERIFY\020\002\022\010\n\004NONE" - "\020\003\"S\n\017MessageEncoding\022\034\n\030MESSAGE_ENCODIN" + "VALIDATION_UNKNOWN\020\000\022\010\n\004NONE\020\001\022\n\n\006VERIFY" + "\020\002\"S\n\017MessageEncoding\022\034\n\030MESSAGE_ENCODIN" "G_UNKNOWN\020\000\022\023\n\017LENGTH_PREFIXED\020\001\022\r\n\tDELI" "MITED\020\002\"H\n\nJsonFormat\022\027\n\023JSON_FORMAT_UNK" "NOWN\020\000\022\t\n\005ALLOW\020\001\022\026\n\022LEGACY_BEST_EFFORT\020" @@ -2260,16 +2260,16 @@ const ::google::protobuf::EnumDescriptor* FeatureSet_Utf8Validation_descriptor() return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[12]; } PROTOBUF_CONSTINIT const uint32_t FeatureSet_Utf8Validation_internal_data_[] = { - 65536u, 32u, 6u, }; + 196608u, 0u, }; bool FeatureSet_Utf8Validation_IsValid(int value) { - return 0 <= value && value <= 3 && ((13u >> value) & 1) != 0; + return 0 <= value && value <= 2; } #if (__cplusplus < 201703) && \ (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr FeatureSet_Utf8Validation FeatureSet::UTF8_VALIDATION_UNKNOWN; -constexpr FeatureSet_Utf8Validation FeatureSet::VERIFY; constexpr FeatureSet_Utf8Validation FeatureSet::NONE; +constexpr FeatureSet_Utf8Validation FeatureSet::VERIFY; constexpr FeatureSet_Utf8Validation FeatureSet::Utf8Validation_MIN; constexpr FeatureSet_Utf8Validation FeatureSet::Utf8Validation_MAX; constexpr int FeatureSet::Utf8Validation_ARRAYSIZE; @@ -11687,8 +11687,8 @@ constexpr ::_pbi::TcParseTable<3, 6, 6, 0, 2> FeatureSet::_table_ = { {::_pbi::TcParser::FastEr0S1, {24, 2, 2, PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.repeated_field_encoding_)}}, // optional .google.protobuf.FeatureSet.Utf8Validation utf8_validation = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { - {::_pbi::TcParser::FastEvS1, - {32, 3, 3, PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.utf8_validation_)}}, + {::_pbi::TcParser::FastEr0S1, + {32, 3, 2, PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.utf8_validation_)}}, // optional .google.protobuf.FeatureSet.MessageEncoding message_encoding = 5 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { {::_pbi::TcParser::FastEr0S1, {40, 4, 2, PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.message_encoding_)}}, @@ -11710,7 +11710,7 @@ constexpr ::_pbi::TcParseTable<3, 6, 6, 0, 2> FeatureSet::_table_ = { (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, // optional .google.protobuf.FeatureSet.Utf8Validation utf8_validation = 4 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { {PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.utf8_validation_), _Internal::kHasBitsOffset + 3, 3, - (0 | ::_fl::kFcOptional | ::_fl::kEnum)}, + (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, // optional .google.protobuf.FeatureSet.MessageEncoding message_encoding = 5 [retention = RETENTION_RUNTIME, targets = TARGET_TYPE_FIELD, targets = TARGET_TYPE_FILE, edition_defaults = { {PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_.message_encoding_), _Internal::kHasBitsOffset + 4, 4, (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, @@ -11721,7 +11721,7 @@ constexpr ::_pbi::TcParseTable<3, 6, 6, 0, 2> FeatureSet::_table_ = { {0, 4}, {0, 3}, {0, 3}, - {::_pbi::FieldAuxEnumData{}, ::google::protobuf::FeatureSet_Utf8Validation_internal_data_}, + {0, 3}, {0, 3}, {0, 3}, }}, {{ diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index fc613d584d..ea38e1f3d0 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -548,15 +548,15 @@ inline bool FeatureSet_RepeatedFieldEncoding_Parse(absl::string_view name, Featu } enum FeatureSet_Utf8Validation : int { FeatureSet_Utf8Validation_UTF8_VALIDATION_UNKNOWN = 0, + FeatureSet_Utf8Validation_NONE = 1, FeatureSet_Utf8Validation_VERIFY = 2, - FeatureSet_Utf8Validation_NONE = 3, }; PROTOBUF_EXPORT bool FeatureSet_Utf8Validation_IsValid(int value); PROTOBUF_EXPORT extern const uint32_t FeatureSet_Utf8Validation_internal_data_[]; constexpr FeatureSet_Utf8Validation FeatureSet_Utf8Validation_Utf8Validation_MIN = static_cast(0); -constexpr FeatureSet_Utf8Validation FeatureSet_Utf8Validation_Utf8Validation_MAX = static_cast(3); -constexpr int FeatureSet_Utf8Validation_Utf8Validation_ARRAYSIZE = 3 + 1; +constexpr FeatureSet_Utf8Validation FeatureSet_Utf8Validation_Utf8Validation_MAX = static_cast(2); +constexpr int FeatureSet_Utf8Validation_Utf8Validation_ARRAYSIZE = 2 + 1; PROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FeatureSet_Utf8Validation_descriptor(); template @@ -569,7 +569,7 @@ const std::string& FeatureSet_Utf8Validation_Name(T value) { template <> inline const std::string& FeatureSet_Utf8Validation_Name(FeatureSet_Utf8Validation value) { return ::google::protobuf::internal::NameOfDenseEnum( + 0, 2>( static_cast(value)); } inline bool FeatureSet_Utf8Validation_Parse(absl::string_view name, FeatureSet_Utf8Validation* value) { @@ -1817,8 +1817,8 @@ class PROTOBUF_EXPORT FeatureSet final : using Utf8Validation = FeatureSet_Utf8Validation; static constexpr Utf8Validation UTF8_VALIDATION_UNKNOWN = FeatureSet_Utf8Validation_UTF8_VALIDATION_UNKNOWN; - static constexpr Utf8Validation VERIFY = FeatureSet_Utf8Validation_VERIFY; static constexpr Utf8Validation NONE = FeatureSet_Utf8Validation_NONE; + static constexpr Utf8Validation VERIFY = FeatureSet_Utf8Validation_VERIFY; static inline bool Utf8Validation_IsValid(int value) { return FeatureSet_Utf8Validation_IsValid(value); } diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index fe66e71f58..474864353a 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -974,8 +974,8 @@ message FeatureSet { enum Utf8Validation { UTF8_VALIDATION_UNKNOWN = 0; + NONE = 1; VERIFY = 2; - NONE = 3; } optional Utf8Validation utf8_validation = 4 [ retention = RETENTION_RUNTIME, From f69f40e3f6dda0d3fc998bb00be6df35fb12bfa6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 26 Oct 2023 08:38:30 -0700 Subject: [PATCH 016/387] Internal change PiperOrigin-RevId: 576883351 --- src/google/protobuf/extension_set.cc | 3 +++ src/google/protobuf/extension_set.h | 16 +++++++++++----- .../protobuf/generated_message_reflection.cc | 5 +++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index 4b54d7a3b6..7fde2cf8de 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc @@ -11,6 +11,7 @@ #include "google/protobuf/extension_set.h" +#include #include #include #include @@ -1933,6 +1934,8 @@ LazyEagerVerifyFnType FindExtensionLazyEagerVerifyFn( return nullptr; } +std::atomic + ExtensionSet::maybe_create_lazy_extension_; } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index f45a1c858c..dd4a473ebc 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -16,6 +16,7 @@ #define GOOGLE_PROTOBUF_EXTENSION_SET_H__ #include +#include #include #include #include @@ -57,6 +58,7 @@ class FeatureSet; namespace internal { class FieldSkipper; // wire_format_lite.h class WireFormat; +void InitializeLazyExtensionSet(); } // namespace internal } // namespace protobuf } // namespace google @@ -508,6 +510,8 @@ class PROTOBUF_EXPORT ExtensionSet { friend class google::protobuf::Reflection; friend class google::protobuf::internal::WireFormat; + friend void internal::InitializeLazyExtensionSet(); + const int32_t& GetRefInt32(int number, const int32_t& default_value) const; const int64_t& GetRefInt64(int number, const int64_t& default_value) const; const uint32_t& GetRefUInt32(int number, const uint32_t& default_value) const; @@ -579,7 +583,13 @@ class PROTOBUF_EXPORT ExtensionSet { virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable. }; // Give access to function defined below to see LazyMessageExtension. - friend LazyMessageExtension* MaybeCreateLazyExtension(Arena* arena); + static LazyMessageExtension* MaybeCreateLazyExtensionImpl(Arena* arena); + static LazyMessageExtension* MaybeCreateLazyExtension(Arena* arena) { + auto* f = maybe_create_lazy_extension_.load(std::memory_order_relaxed); + return f != nullptr ? f(arena) : nullptr; + } + static std::atomic + maybe_create_lazy_extension_; struct Extension { // The order of these fields packs Extension into 24 bytes when using 8 // byte alignment. Consider this when adding or removing fields here. @@ -1529,10 +1539,6 @@ class ExtensionIdentifier { // Generated accessors -// Used to retrieve a lazy extension, may return nullptr in some environments. -extern PROTOBUF_ATTRIBUTE_WEAK ExtensionSet::LazyMessageExtension* -MaybeCreateLazyExtension(Arena* arena); - // Define a specialization of ExtensionIdentifier for bootstrapped extensions // that we need to register lazily. template <> diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 452fd5240d..84272163fe 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include "absl/base/call_once.h" #include "absl/base/casts.h" @@ -93,6 +94,9 @@ void InitializeFileDescriptorDefaultInstances() { #endif // !defined(PROTOBUF_CONSTINIT_DEFAULT_INSTANCES) } +void InitializeLazyExtensionSet() { +} + bool ParseNamedEnum(const EnumDescriptor* descriptor, absl::string_view name, int* value) { const EnumValueDescriptor* d = descriptor->FindValueByName(name); @@ -3660,6 +3664,7 @@ void AddDescriptorsImpl(const DescriptorTable* table) { // Reflection refers to the default fields so make sure they are initialized. internal::InitProtobufDefaults(); internal::InitializeFileDescriptorDefaultInstances(); + internal::InitializeLazyExtensionSet(); // Ensure all dependent descriptors are registered to the generated descriptor // pool and message factory. From c20b337221fb1c8fb02b4ea3d9363adbc2ef0ad3 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 26 Oct 2023 08:40:45 -0700 Subject: [PATCH 017/387] upb: remove redundant #includes from the foo.upbdefs.h gencode PiperOrigin-RevId: 576883852 --- upb_generator/protoc-gen-upbdefs.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/upb_generator/protoc-gen-upbdefs.cc b/upb_generator/protoc-gen-upbdefs.cc index 69682c4e78..58234150a2 100644 --- a/upb_generator/protoc-gen-upbdefs.cc +++ b/upb_generator/protoc-gen-upbdefs.cc @@ -70,17 +70,13 @@ void WriteDefHeader(upb::FileDefPtr file, Output& output) { "#define $0_UPBDEFS_H_\n\n" "#include \"upb/reflection/def.h\"\n" "#include \"upb/reflection/internal/def_pool.h\"\n" - "#include \"upb/port/def.inc\"\n" + "\n" + "#include \"upb/port/def.inc\" // Must be last.\n" "#ifdef __cplusplus\n" "extern \"C\" {\n" "#endif\n\n", ToPreproc(file.name())); - output("#include \"upb/reflection/def.h\"\n"); - output("\n"); - output("#include \"upb/port/def.inc\"\n"); - output("\n"); - output("extern _upb_DefPool_Init $0;\n", DefInitSymbol(file)); output("\n"); From 8d67a40d30553f275b28f55ab5b5dd358eacaefa Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 26 Oct 2023 10:55:23 -0700 Subject: [PATCH 018/387] upb: fix wheels build errors PiperOrigin-RevId: 576925248 --- python/dist/BUILD.bazel | 1 + upb/cmake/BUILD.bazel | 1 + upb/reflection/BUILD | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/python/dist/BUILD.bazel b/python/dist/BUILD.bazel index 4330fe1c4f..ba549acb25 100644 --- a/python/dist/BUILD.bazel +++ b/python/dist/BUILD.bazel @@ -246,6 +246,7 @@ pkg_files( "//upb/mini_descriptor:source_files", "//upb/mini_table:source_files", "//upb/port:source_files", + "//upb/reflection:source_files", "//upb/text:source_files", "//upb/util:source_files", "//upb/wire:source_files", diff --git a/upb/cmake/BUILD.bazel b/upb/cmake/BUILD.bazel index b2a5e5a7f8..3e40380e8b 100644 --- a/upb/cmake/BUILD.bazel +++ b/upb/cmake/BUILD.bazel @@ -96,6 +96,7 @@ sh_test( "//upb/mini_descriptor:source_files", "//upb/mini_table:source_files", "//upb/port:source_files", + "//upb/reflection:source_files", "//upb/text:source_files", "//upb/wire:source_files", "@utf8_range//:utf8_range_srcs", diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index 380ae38e51..0e92276c44 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -172,3 +172,21 @@ cc_test( "@com_google_absl//absl/strings", ], ) + +# begin:github_only +filegroup( + name = "source_files", + srcs = glob( + [ + "**/*.c", + "**/*.h", + "**/*.hpp", + ], + exclude = ["stage0/**"], + ), + visibility = [ + "//upb/cmake:__pkg__", + "//python/dist:__pkg__", + ] +) +# end:github_only From e9953d2155f48fbd203ea666caf352b5e5488897 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 26 Oct 2023 13:15:41 -0700 Subject: [PATCH 019/387] internal change PiperOrigin-RevId: 576966982 --- python/google/protobuf/internal/api_implementation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/google/protobuf/internal/api_implementation.py b/python/google/protobuf/internal/api_implementation.py index 65caf63f8b..09af96e67c 100755 --- a/python/google/protobuf/internal/api_implementation.py +++ b/python/google/protobuf/internal/api_implementation.py @@ -13,6 +13,8 @@ import os import sys import warnings +_GOOGLE3_PYTHON_UPB_DEFAULT = False + def _ApiVersionToImplementationType(api_version): if api_version == 2: From 37cae2d2e1320f32f64b1e9552dd3763469a1aa7 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 27 Oct 2023 02:10:28 -0700 Subject: [PATCH 020/387] Internal change PiperOrigin-RevId: 577125921 --- upb/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upb/BUILD b/upb/BUILD index 16c67b17e0..1e52a8092b 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -97,7 +97,7 @@ cc_library( # implementation, but depends on :upb and exposes a few more hdrs. # # This is public only because we have no way of visibility-limiting it to -# upb_proto_library() only. This interface is not stable and by using it you +# upb_c_proto_library() only. This interface is not stable and by using it you # give up any backward compatibility guarantees. cc_library( name = "generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", From b2efcdc1c50b204e2b612eacf5db599f74153376 Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Fri, 27 Oct 2023 12:29:24 -0700 Subject: [PATCH 021/387] Internal Code Change PiperOrigin-RevId: 577274352 --- src/google/protobuf/arenaz_sampler_test.cc | 1 + src/google/protobuf/compiler/cpp/unittest.inc | 1 - src/google/protobuf/repeated_field_unittest.cc | 6 +++--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/arenaz_sampler_test.cc b/src/google/protobuf/arenaz_sampler_test.cc index c71162467a..20a0473207 100644 --- a/src/google/protobuf/arenaz_sampler_test.cc +++ b/src/google/protobuf/arenaz_sampler_test.cc @@ -401,6 +401,7 @@ TEST(ThreadSafeArenazSamplerTest, InitialBlockReportsZeroUsedAndWasted) { for (int i = 0; i < 10; ++i) { char block[kSize]; google::protobuf::Arena arena(/*initial_block=*/block, /*initial_block_size=*/kSize); + benchmark::DoNotOptimize(&arena); sampler.Iterate([&](const ThreadSafeArenaStats& h) { const auto& histbin = h.block_histogram[ThreadSafeArenaStats::FindBin(kSize)]; diff --git a/src/google/protobuf/compiler/cpp/unittest.inc b/src/google/protobuf/compiler/cpp/unittest.inc index 169fbb6021..56109d3913 100644 --- a/src/google/protobuf/compiler/cpp/unittest.inc +++ b/src/google/protobuf/compiler/cpp/unittest.inc @@ -926,7 +926,6 @@ TEST(GENERATED_MESSAGE_TEST_NAME, TestOneofSpaceUsed) { #endif // !PROTOBUF_TEST_NO_DESCRIPTORS TEST(GENERATED_MESSAGE_TEST_NAME, FieldConstantValues) { - UNITTEST::TestRequired message; EXPECT_EQ(UNITTEST::TestAllTypes_NestedMessage::kBbFieldNumber, 1); EXPECT_EQ(UNITTEST::TestAllTypes::kOptionalInt32FieldNumber, 1); EXPECT_EQ(UNITTEST::TestAllTypes::kOptionalgroupFieldNumber, 16); diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index 529d872284..814f0c8d79 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -704,9 +704,9 @@ TEST(RepeatedField, CopyConstructIntegers) { EXPECT_EQ(2, fields1.Get(1)); RepeatedType fields2(token, nullptr, original); - ASSERT_EQ(2, fields1.size()); - EXPECT_EQ(1, fields1.Get(0)); - EXPECT_EQ(2, fields1.Get(1)); + ASSERT_EQ(2, fields2.size()); + EXPECT_EQ(1, fields2.Get(0)); + EXPECT_EQ(2, fields2.Get(1)); } TEST(RepeatedField, CopyConstructCords) { From 57bb1e55f1e439399491fe762465120fbf1c09a3 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Sat, 28 Oct 2023 12:54:21 -0700 Subject: [PATCH 022/387] Set up editions codegen tests for python These tests aren't super useful for python because of how little codegen we actually do, but the pyi ones specifically will guard against major editions regressions. PiperOrigin-RevId: 577495652 --- .../protobuf/compiler/python/generator.cc | 157 ++++++++---------- .../protobuf/compiler/python/generator.h | 6 + .../protobuf/compiler/python/pyi_generator.cc | 7 + .../protobuf/compiler/python/pyi_generator.h | 8 + 4 files changed, 86 insertions(+), 92 deletions(-) diff --git a/src/google/protobuf/compiler/python/generator.cc b/src/google/protobuf/compiler/python/generator.cc index f3cce736d6..6430459c6a 100644 --- a/src/google/protobuf/compiler/python/generator.cc +++ b/src/google/protobuf/compiler/python/generator.cc @@ -22,6 +22,8 @@ #include "google/protobuf/compiler/python/generator.h" #include +#include +#include #include #include #include @@ -35,10 +37,12 @@ #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" +#include "absl/strings/str_join.h" #include "absl/strings/str_replace.h" #include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "absl/strings/substitute.h" +#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/python/helpers.h" #include "google/protobuf/compiler/python/pyi_generator.h" #include "google/protobuf/compiler/retention.h" @@ -49,6 +53,7 @@ #include "google/protobuf/io/printer.h" #include "google/protobuf/io/strtod.h" #include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/message.h" namespace google { namespace protobuf { @@ -152,21 +157,6 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) { return ""; } -std::string StringifySyntax(FileDescriptorLegacy::Syntax syntax) { - switch (syntax) { - case FileDescriptorLegacy::Syntax::SYNTAX_PROTO2: - return "proto2"; - case FileDescriptorLegacy::Syntax::SYNTAX_PROTO3: - return "proto3"; - case FileDescriptorLegacy::Syntax::SYNTAX_UNKNOWN: - default: - ABSL_LOG(FATAL) - << "Unsupported syntax; this generator only supports proto2 " - "and proto3 syntax."; - return ""; - } -} - } // namespace Generator::Generator() : file_(nullptr) {} @@ -194,6 +184,8 @@ GeneratorOptions Generator::ParseParameter(absl::string_view parameter, options.generate_pyi = true; } else if (option.first == "annotate_code") { options.annotate_pyi = true; + } else if (option.first == "experimental_strip_nonfunctional_codegen") { + options.strip_nonfunctional_codegen = true; } else { *error = absl::StrCat("Unknown generator option: ", option.first); } @@ -211,8 +203,15 @@ bool Generator::Generate(const FileDescriptor* file, // Generate pyi typing information if (options.generate_pyi) { python::PyiGenerator pyi_generator; - std::string pyi_options = options.annotate_pyi ? "annotate_code" : ""; - if (!pyi_generator.Generate(file, pyi_options, context, error)) { + std::vector pyi_options; + if (options.annotate_pyi) { + pyi_options.push_back("annotate_code"); + } + if (options.strip_nonfunctional_codegen) { + pyi_options.push_back("experimental_strip_nonfunctional_codegen"); + } + if (!pyi_generator.Generate(file, absl::StrJoin(pyi_options, ","), context, + error)) { return false; } } @@ -423,7 +422,8 @@ void Generator::PrintFileDescriptor() const { m["descriptor_name"] = kDescriptorKey; m["name"] = file_->name(); m["package"] = file_->package(); - m["syntax"] = StringifySyntax(FileDescriptorLegacy(file_).syntax()); + m["syntax"] = std::string( + FileDescriptorLegacy::SyntaxName(FileDescriptorLegacy(file_).syntax())); m["options"] = OptionsValue( StripLocalSourceRetentionOptions(*file_).SerializeAsString()); m["serialized_descriptor"] = absl::CHexEscape(file_descriptor_serialized_); @@ -677,8 +677,7 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { "options_value", OptionsValue(options_string), "extendable", message_descriptor.extension_range_count() > 0 ? "True" : "False", "syntax", - StringifySyntax( - FileDescriptorLegacy(message_descriptor.file()).syntax())); + FileDescriptorLegacy::SyntaxName(FileDescriptorLegacy(file_).syntax())); printer_->Print(",\n"); // Extension ranges @@ -1167,7 +1166,7 @@ void Generator::PrintSerializedPbInterval( const DescriptorProtoT& descriptor_proto, absl::string_view name) const { std::string sp; descriptor_proto.SerializeToString(&sp); - int offset = file_descriptor_serialized_.find(sp); + size_t offset = file_descriptor_serialized_.find(sp); ABSL_CHECK_GE(offset, 0); printer_->Print( @@ -1177,26 +1176,34 @@ void Generator::PrintSerializedPbInterval( absl::StrCat(offset + sp.size())); } -namespace { -void PrintDescriptorOptionsFixingCode(absl::string_view descriptor, - absl::string_view options, - io::Printer* printer) { +template +bool Generator::PrintDescriptorOptionsFixingCode( + const DescriptorT& descriptor, absl::string_view descriptor_str) const { + std::string options = OptionsValue( + StripLocalSourceRetentionOptions(descriptor).SerializeAsString()); + // Reset the _options to None thus DescriptorBase.GetOptions() can // parse _options again after extensions are registered. - size_t dot_pos = descriptor.find('.'); + size_t dot_pos = descriptor_str.find('.'); std::string descriptor_name; if (dot_pos == std::string::npos) { - descriptor_name = absl::StrCat("_globals['", descriptor, "']"); + descriptor_name = absl::StrCat("_globals['", descriptor_str, "']"); } else { - descriptor_name = absl::StrCat("_globals['", descriptor.substr(0, dot_pos), - "']", descriptor.substr(dot_pos)); + descriptor_name = + absl::StrCat("_globals['", descriptor_str.substr(0, dot_pos), "']", + descriptor_str.substr(dot_pos)); + } + + if (options == "None") { + return false; } - printer->Print( + + printer_->Print( "$descriptor_name$._options = None\n" "$descriptor_name$._serialized_options = $serialized_value$\n", "descriptor_name", descriptor_name, "serialized_value", options); + return true; } -} // namespace // Generates the start and end offsets for each entity in the serialized file // descriptor. The file argument must exactly match what was serialized into @@ -1246,11 +1253,7 @@ void Generator::SetMessagePbInterval(const DescriptorProto& message_proto, // Prints expressions that set the options field of all descriptors. void Generator::FixAllDescriptorOptions() const { // Prints an expression that sets the file descriptor's options. - std::string file_options = OptionsValue( - StripLocalSourceRetentionOptions(*file_).SerializeAsString()); - if (file_options != "None") { - PrintDescriptorOptionsFixingCode(kDescriptorKey, file_options, printer_); - } else { + if (!PrintDescriptorOptionsFixingCode(*file_, kDescriptorKey)) { printer_->Print("DESCRIPTOR._options = None\n"); } // Prints expressions that set the options for all top level enums. @@ -1275,35 +1278,23 @@ void Generator::FixAllDescriptorOptions() const { } void Generator::FixOptionsForOneof(const OneofDescriptor& oneof) const { - std::string oneof_options = - OptionsValue(StripLocalSourceRetentionOptions(oneof).SerializeAsString()); - if (oneof_options != "None") { - std::string oneof_name = absl::Substitute( - "$0.$1['$2']", ModuleLevelDescriptorName(*oneof.containing_type()), - "oneofs_by_name", oneof.name()); - PrintDescriptorOptionsFixingCode(oneof_name, oneof_options, printer_); - } + std::string oneof_name = absl::Substitute( + "$0.$1['$2']", ModuleLevelDescriptorName(*oneof.containing_type()), + "oneofs_by_name", oneof.name()); + PrintDescriptorOptionsFixingCode(oneof, oneof_name); } // Prints expressions that set the options for an enum descriptor and its // value descriptors. void Generator::FixOptionsForEnum(const EnumDescriptor& enum_descriptor) const { std::string descriptor_name = ModuleLevelDescriptorName(enum_descriptor); - std::string enum_options = OptionsValue( - StripLocalSourceRetentionOptions(enum_descriptor).SerializeAsString()); - if (enum_options != "None") { - PrintDescriptorOptionsFixingCode(descriptor_name, enum_options, printer_); - } + PrintDescriptorOptionsFixingCode(enum_descriptor, descriptor_name); for (int i = 0; i < enum_descriptor.value_count(); ++i) { const EnumValueDescriptor& value_descriptor = *enum_descriptor.value(i); - std::string value_options = OptionsValue( - StripLocalSourceRetentionOptions(value_descriptor).SerializeAsString()); - if (value_options != "None") { - PrintDescriptorOptionsFixingCode( - absl::StrFormat("%s.values_by_name[\"%s\"]", descriptor_name.c_str(), - value_descriptor.name().c_str()), - value_options, printer_); - } + PrintDescriptorOptionsFixingCode( + value_descriptor, + absl::StrFormat("%s.values_by_name[\"%s\"]", descriptor_name.c_str(), + value_descriptor.name().c_str())); } } @@ -1313,46 +1304,33 @@ void Generator::FixOptionsForService( const ServiceDescriptor& service_descriptor) const { std::string descriptor_name = ModuleLevelServiceDescriptorName(service_descriptor); - std::string service_options = OptionsValue( - StripLocalSourceRetentionOptions(service_descriptor).SerializeAsString()); - if (service_options != "None") { - PrintDescriptorOptionsFixingCode(descriptor_name, service_options, - printer_); - } + PrintDescriptorOptionsFixingCode(service_descriptor, descriptor_name); for (int i = 0; i < service_descriptor.method_count(); ++i) { const MethodDescriptor* method = service_descriptor.method(i); - std::string method_options = OptionsValue( - StripLocalSourceRetentionOptions(*method).SerializeAsString()); - if (method_options != "None") { - std::string method_name = absl::StrCat( - descriptor_name, ".methods_by_name['", method->name(), "']"); - PrintDescriptorOptionsFixingCode(method_name, method_options, printer_); - } + PrintDescriptorOptionsFixingCode( + *method, absl::StrCat(descriptor_name, ".methods_by_name['", + method->name(), "']")); } } // Prints expressions that set the options for field descriptors (including // extensions). void Generator::FixOptionsForField(const FieldDescriptor& field) const { - std::string field_options = - OptionsValue(StripLocalSourceRetentionOptions(field).SerializeAsString()); - if (field_options != "None") { - std::string field_name; - if (field.is_extension()) { - if (field.extension_scope() == nullptr) { - // Top level extensions. - field_name = field.name(); - } else { - field_name = FieldReferencingExpression(field.extension_scope(), field, - "extensions_by_name"); - } + std::string field_name; + if (field.is_extension()) { + if (field.extension_scope() == nullptr) { + // Top level extensions. + field_name = field.name(); } else { - field_name = FieldReferencingExpression(field.containing_type(), field, - "fields_by_name"); + field_name = FieldReferencingExpression(field.extension_scope(), field, + "extensions_by_name"); } - PrintDescriptorOptionsFixingCode(field_name, field_options, printer_); + } else { + field_name = FieldReferencingExpression(field.containing_type(), field, + "fields_by_name"); } + PrintDescriptorOptionsFixingCode(field, field_name); } // Prints expressions that set the options for a message and all its inner @@ -1381,13 +1359,8 @@ void Generator::FixOptionsForMessage(const Descriptor& descriptor) const { FixOptionsForField(field); } // Message option for this message. - std::string message_options = OptionsValue( - StripLocalSourceRetentionOptions(descriptor).SerializeAsString()); - if (message_options != "None") { - std::string descriptor_name = ModuleLevelDescriptorName(descriptor); - PrintDescriptorOptionsFixingCode(descriptor_name, message_options, - printer_); - } + PrintDescriptorOptionsFixingCode(descriptor, + ModuleLevelDescriptorName(descriptor)); } // If a dependency forwards other files through public dependencies, let's diff --git a/src/google/protobuf/compiler/python/generator.h b/src/google/protobuf/compiler/python/generator.h index 2c73140d9c..3a4ff665ad 100644 --- a/src/google/protobuf/compiler/python/generator.h +++ b/src/google/protobuf/compiler/python/generator.h @@ -12,6 +12,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ +#include #include #include @@ -49,6 +50,7 @@ struct GeneratorOptions { bool generate_pyi = false; bool annotate_pyi = false; bool bootstrap = false; + bool strip_nonfunctional_codegen = false; }; class PROTOC_EXPORT Generator : public CodeGenerator { @@ -141,6 +143,10 @@ class PROTOC_EXPORT Generator : public CodeGenerator { void PrintSerializedPbInterval(const DescriptorProtoT& descriptor_proto, absl::string_view name) const; + template + bool PrintDescriptorOptionsFixingCode(const DescriptorT& descriptor, + absl::string_view descriptor_str) const; + void FixAllDescriptorOptions() const; void FixOptionsForField(const FieldDescriptor& field) const; void FixOptionsForOneof(const OneofDescriptor& oneof) const; diff --git a/src/google/protobuf/compiler/python/pyi_generator.cc b/src/google/protobuf/compiler/python/pyi_generator.cc index 35a4e4ec2d..7f7bfeda08 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.cc +++ b/src/google/protobuf/compiler/python/pyi_generator.cc @@ -18,6 +18,7 @@ #include "absl/strings/match.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" +#include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/python/helpers.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" @@ -169,6 +170,9 @@ void PyiGenerator::PrintImports() const { bool has_importlib = false; for (int i = 0; i < file_->dependency_count(); ++i) { const FileDescriptor* dep = file_->dependency(i); + if (strip_nonfunctional_codegen_ && IsKnownFeatureProto(dep->name())) { + continue; + } PrintImportForDescriptor(*dep, &seen_aliases, &has_importlib); for (int j = 0; j < dep->public_dependency_count(); ++j) { PrintImportForDescriptor(*dep->public_dependency(j), &seen_aliases, @@ -570,11 +574,14 @@ bool PyiGenerator::Generate(const FileDescriptor* file, std::string filename; bool annotate_code = false; + strip_nonfunctional_codegen_ = false; for (const std::pair& option : options) { if (option.first == "annotate_code") { annotate_code = true; } else if (absl::EndsWith(option.first, ".pyi")) { filename = option.first; + } else if (option.first == "experimental_strip_nonfunctional_codegen") { + strip_nonfunctional_codegen_ = true; } else { *error = absl::StrCat("Unknown generator option: ", option.first); return false; diff --git a/src/google/protobuf/compiler/python/pyi_generator.h b/src/google/protobuf/compiler/python/pyi_generator.h index 84c802bee8..495b296900 100644 --- a/src/google/protobuf/compiler/python/pyi_generator.h +++ b/src/google/protobuf/compiler/python/pyi_generator.h @@ -13,6 +13,7 @@ #define GOOGLE_PROTOBUF_COMPILER_PYTHON_PYI_GENERATOR_H__ #include +#include #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" @@ -53,6 +54,12 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera GeneratorContext* generator_context, std::string* error) const override; + Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } + Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } + std::vector GetFeatureExtensions() const override { + return {}; + } + private: void PrintImportForDescriptor(const FileDescriptor& desc, absl::flat_hash_set* seen_aliases, @@ -83,6 +90,7 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera mutable absl::Mutex mutex_; mutable const FileDescriptor* file_; // Set in Generate(). Under mutex_. mutable io::Printer* printer_; // Set in Generate(). Under mutex_. + mutable bool strip_nonfunctional_codegen_ = false; // Set in Generate(). // import_map will be a mapping from filename to module alias, e.g. // "google3/foo/bar.py" -> "_bar" mutable absl::flat_hash_map import_map_; From 63f4c503a2762abaec136209ee5b62452ecf206e Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Sat, 28 Oct 2023 12:57:37 -0700 Subject: [PATCH 023/387] Editions: Embed resolved features of descriptor.proto for pure python. Because pure python builds all descriptors at runtime via reflection, it's unable to parse options during the build of descriptor.proto (i.e. before we've built the options schemas). We always lazily parse these options to avoid this, but that still means options can't be *used* during this build. Since the current build process makes heavy use of features (which previously just relied on syntax), this poses a problem for editions. To get around this, we just embed the resolved features directly into the gencode for this one file. This will allow us to skip feature resolution for these descriptors and still consider features in their build. PiperOrigin-RevId: 577495949 --- .../protobuf/internal/descriptor_test.py | 67 ++++++++++- .../protobuf/compiler/python/generator.cc | 109 ++++++++++++++++++ .../protobuf/compiler/python/generator.h | 3 + 3 files changed, 175 insertions(+), 4 deletions(-) diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index 1adbad286e..56ca079f34 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -12,13 +12,15 @@ __author__ = 'robinson@google.com (Will Robinson)' import unittest import warnings -from google.protobuf import descriptor_pb2 -from google.protobuf.internal import api_implementation -from google.protobuf.internal import test_util from google.protobuf import descriptor +from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool from google.protobuf import symbol_database from google.protobuf import text_format +from google.protobuf.internal import api_implementation +from google.protobuf.internal import test_util + +from google.protobuf.internal import _parameterized from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_pb2 @@ -1169,7 +1171,6 @@ class MakeDescriptorTest(unittest.TestCase): self.assertEqual(result.fields[0].cpp_type, descriptor.FieldDescriptor.CPPTYPE_UINT64) - def testMakeDescriptorWithOptions(self): descriptor_proto = descriptor_pb2.DescriptorProto() aggregate_message = unittest_custom_options_pb2.AggregateMessage @@ -1214,5 +1215,63 @@ class MakeDescriptorTest(unittest.TestCase): json_names[index]) +class FeaturesTest(_parameterized.TestCase): + + # TODO Add _features for upb and C++. + @_parameterized.named_parameters([ + ('File', lambda: descriptor_pb2.DESCRIPTOR), + ('Message', lambda: descriptor_pb2.FeatureSet.DESCRIPTOR), + ( + 'Enum', + lambda: descriptor_pb2.FeatureSet.FieldPresence.DESCRIPTOR, + ), + ( + 'Field', + lambda: descriptor_pb2.FeatureSet.DESCRIPTOR.fields_by_name[ + 'enum_type' + ], + ), + ]) + @unittest.skipIf( + api_implementation.Type() != 'python', + 'Features field is only available with the pure python implementation', + ) + def testDescriptorProtoDefaultFeatures(self, desc): + self.assertEqual( + desc()._features.field_presence, + descriptor_pb2.FeatureSet.FieldPresence.EXPLICIT, + ) + self.assertEqual( + desc()._features.enum_type, + descriptor_pb2.FeatureSet.EnumType.CLOSED, + ) + self.assertEqual( + desc()._features.repeated_field_encoding, + descriptor_pb2.FeatureSet.RepeatedFieldEncoding.EXPANDED, + ) + + # TODO Add _features for upb and C++. + @unittest.skipIf( + api_implementation.Type() != 'python', + 'Features field is only available with the pure python implementation', + ) + def testDescriptorProtoOverrideFeatures(self): + desc = descriptor_pb2.SourceCodeInfo.Location.DESCRIPTOR.fields_by_name[ + 'path' + ] + self.assertEqual( + desc._features.field_presence, + descriptor_pb2.FeatureSet.FieldPresence.EXPLICIT, + ) + self.assertEqual( + desc._features.enum_type, + descriptor_pb2.FeatureSet.EnumType.CLOSED, + ) + self.assertEqual( + desc._features.repeated_field_encoding, + descriptor_pb2.FeatureSet.RepeatedFieldEncoding.PACKED, + ) + + if __name__ == '__main__': unittest.main() diff --git a/src/google/protobuf/compiler/python/generator.cc b/src/google/protobuf/compiler/python/generator.cc index 6430459c6a..3f3410e3cd 100644 --- a/src/google/protobuf/compiler/python/generator.cc +++ b/src/google/protobuf/compiler/python/generator.cc @@ -33,6 +33,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" +#include "absl/memory/memory.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" @@ -50,6 +51,8 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor_legacy.h" +#include "google/protobuf/descriptor_visitor.h" +#include "google/protobuf/dynamic_message.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/strtod.h" #include "google/protobuf/io/zero_copy_stream.h" @@ -285,6 +288,7 @@ bool Generator::Generate(const FileDescriptor* file, PrintAllEnumsInFile(); PrintMessageDescriptors(); FixForeignFieldsInDescriptors(); + PrintResolvedFeatures(); printer_->Outdent(); printer_->Print("else:\n"); printer_->Indent(); @@ -416,6 +420,111 @@ void Generator::PrintImports() const { printer_->Print("\n"); } +template +std::string Generator::GetResolvedFeatures( + const DescriptorT& descriptor) const { + if (!GeneratingDescriptorProto()) { + // Everything but descriptor.proto can handle proper feature resolution. + return "None"; + } + + // Load the resolved features from our pool. + const Descriptor* feature_set = file_->pool()->FindMessageTypeByName( + FeatureSet::GetDescriptor()->full_name()); + auto message_factory = absl::make_unique(); + auto features = + absl::WrapUnique(message_factory->GetPrototype(feature_set)->New()); + features->ParseFromString( + GetResolvedSourceFeatures(descriptor).SerializeAsString()); + + // Collect all of the resolved features. + std::vector feature_args; + const Reflection* reflection = features->GetReflection(); + std::vector fields; + reflection->ListFields(*features, &fields); + for (const auto* field : fields) { + // Assume these are all enums. If we add non-enum global features or any + // python-specific features, we will need to come back and improve this + // logic. + ABSL_CHECK(field->enum_type() != nullptr) + << "Unexpected non-enum field found!"; + if (field->options().retention() == FieldOptions::RETENTION_SOURCE) { + // Skip any source-retention features. + continue; + } + const EnumDescriptor* enm = field->enum_type(); + const EnumValueDescriptor* value = + enm->FindValueByNumber(reflection->GetEnumValue(*features, field)); + + feature_args.emplace_back(absl::StrCat( + field->name(), "=", + absl::StrFormat("%s.values_by_name[\"%s\"].number", + ModuleLevelDescriptorName(*enm), value->name()))); + } + return absl::StrCat("_ResolvedFeatures(", absl::StrJoin(feature_args, ","), + ")"); +} + +void Generator::PrintResolvedFeatures() const { + // Since features are used during the descriptor build, it's impossible to do + // feature resolution at the normal point for descriptor.proto. Instead, we do + // feature resolution here in the generator, and embed a custom object on all + // of the generated descriptors. This object should act like any other + // FeatureSet message on normal descriptors, but will never have to be + // resolved by the python runtime. + ABSL_CHECK(GeneratingDescriptorProto()); + printer_->Emit({{"resolved_features", GetResolvedFeatures(*file_)}, + {"descriptor_name", kDescriptorKey}}, + R"py( + class _ResolvedFeatures: + def __init__(self, features = None, **kwargs): + if features: + for k, v in features.FIELDS.items(): + setattr(self, k, getattr(features, k)) + else: + for k, v in kwargs.items(): + setattr(self, k, v) + $descriptor_name$._features = $resolved_features$ + )py"); + +#define MAKE_NESTED(desc, CPP_FIELD, PY_FIELD) \ + [&] { \ + for (int i = 0; i < desc.CPP_FIELD##_count(); ++i) { \ + printer_->Emit( \ + {{"resolved_subfeatures", GetResolvedFeatures(*desc.CPP_FIELD(i))}, \ + {"index", absl::StrCat(i)}, \ + {"field", PY_FIELD}}, \ + "$descriptor_name$.$field$[$index$]._features = " \ + "$resolved_subfeatures$\n"); \ + } \ + } + + internal::VisitDescriptors(*file_, [&](const Descriptor& msg) { + printer_->Emit( + {{"resolved_features", GetResolvedFeatures(msg)}, + {"descriptor_name", ModuleLevelDescriptorName(msg)}, + {"field_features", MAKE_NESTED(msg, field, "fields")}, + {"oneof_features", MAKE_NESTED(msg, oneof_decl, "oneofs")}, + {"ext_features", MAKE_NESTED(msg, extension, "extensions")}}, + R"py( + $descriptor_name$._features = $resolved_features$ + $field_features$ + $oneof_features$ + $ext_features$ + )py"); + }); + internal::VisitDescriptors(*file_, [&](const EnumDescriptor& enm) { + printer_->Emit({{"resolved_features", GetResolvedFeatures(enm)}, + {"descriptor_name", ModuleLevelDescriptorName(enm)}, + {"value_features", MAKE_NESTED(enm, value, "values")}}, + R"py( + $descriptor_name$._features = $resolved_features$ + $value_features$ + )py"); + }); +#undef MAKE_NESTED +} + // Prints the single file descriptor for this file. void Generator::PrintFileDescriptor() const { absl::flat_hash_map m; diff --git a/src/google/protobuf/compiler/python/generator.h b/src/google/protobuf/compiler/python/generator.h index 3a4ff665ad..c5beeeea35 100644 --- a/src/google/protobuf/compiler/python/generator.h +++ b/src/google/protobuf/compiler/python/generator.h @@ -75,6 +75,9 @@ class PROTOC_EXPORT Generator : public CodeGenerator { GeneratorOptions ParseParameter(absl::string_view parameter, std::string* error) const; void PrintImports() const; + template + std::string GetResolvedFeatures(const DescriptorT& descriptor) const; + void PrintResolvedFeatures() const; void PrintFileDescriptor() const; void PrintAllEnumsInFile() const; void PrintNestedEnums(const Descriptor& descriptor) const; From ebdd7e3eb6f00659014672bbb901c73cbc4c5ec2 Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Mon, 30 Oct 2023 01:02:10 -0700 Subject: [PATCH 024/387] Add private accessors for maps to be used by Rust's Map implementation. PiperOrigin-RevId: 577749942 --- upb/test/test_generated_code.cc | 15 +++++++++++ upb_generator/names.cc | 4 +++ upb_generator/names.h | 4 +++ upb_generator/protoc-gen-upb.cc | 45 ++++++++++++++++++++++++--------- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/upb/test/test_generated_code.cc b/upb/test/test_generated_code.cc index 2a2d723654..4169d5d865 100644 --- a/upb/test/test_generated_code.cc +++ b/upb/test/test_generated_code.cc @@ -706,6 +706,21 @@ TEST(GeneratedCode, Int32Map) { check_int32_map_empty(msg); + EXPECT_EQ( + _protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_upb_map( + msg), + nullptr); + + upb_Map* mut_map = + _protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_mutable_upb_map( + msg, arena); + EXPECT_NE(mut_map, nullptr); + + const upb_Map* const_map = + _protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_upb_map( + msg); + EXPECT_EQ(mut_map, const_map); + /* Set map[test_int32] = test_int32_2 */ protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_set( msg, test_int32, test_int32_2, arena); diff --git a/upb_generator/names.cc b/upb_generator/names.cc index 847c8f1b18..31f8c6457f 100644 --- a/upb_generator/names.cc +++ b/upb_generator/names.cc @@ -55,6 +55,10 @@ ABSL_CONST_INIT const absl::string_view kRepeatedFieldArrayGetterPostfix = ABSL_CONST_INIT const absl::string_view kRepeatedFieldMutableArrayGetterPostfix = "mutable_upb_array"; +ABSL_CONST_INIT const absl::string_view kMapGetterPostfix = "upb_map"; +ABSL_CONST_INIT const absl::string_view kMutableMapGetterPostfix = + "mutable_upb_map"; + // List of generated accessor prefixes to check against. // Example: // optional repeated string phase = 236; diff --git a/upb_generator/names.h b/upb_generator/names.h index 7eef159451..1694dde454 100644 --- a/upb_generator/names.h +++ b/upb_generator/names.h @@ -69,6 +69,10 @@ ABSL_CONST_INIT extern const absl::string_view kRepeatedFieldArrayGetterPostfix; ABSL_CONST_INIT extern const absl::string_view kRepeatedFieldMutableArrayGetterPostfix; +// Private getter name postfix for map fields. +ABSL_CONST_INIT extern const absl::string_view kMapGetterPostfix; +ABSL_CONST_INIT extern const absl::string_view kMutableMapGetterPostfix; + } // namespace generator } // namespace upb diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index eb839790c2..7678f99a62 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -487,6 +487,27 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools, )cc", CTypeConst(field), msg_name, resolved_name, FieldInitializer(pools, field, options)); + // Generate private getter returning a upb_Map or NULL for immutable and + // a upb_Map for mutable. + // + // Example: + // UPB_INLINE const upb_Map* _name_immutable_upb_map(Foo* msg) + // UPB_INLINE upb_Map* _name_mutable_upb_map(Foo* msg, upb_Arena* a) + output( + R"cc( + UPB_INLINE const upb_Map* _$0_$1_$2($0* msg) { + const upb_MiniTableField field = $4; + return upb_Message_GetMap(msg, &field); + } + UPB_INLINE upb_Map* _$0_$1_$3($0* msg, upb_Arena* a) { + const upb_MiniTableField field = $4; + return _upb_Message_GetOrCreateMutableMap(msg, &field, $5, $6, a); + } + )cc", + msg_name, resolved_name, kMapGetterPostfix, kMutableMapGetterPostfix, + FieldInitializer(pools, field, options), + MapKeySize(field, MapKeyCType(field)), + MapValueSize(field, MapValueCType(field))); } void GenerateMapEntryGetters(upb::FieldDefPtr field, absl::string_view msg_name, @@ -1137,17 +1158,17 @@ int main(int argc, char** argv) { upb::generator::Plugin plugin; upb::generator::Options options; if (!ParseOptions(&plugin, &options)) return 0; - plugin.GenerateFilesRaw([&](const UPB_DESC(FileDescriptorProto) * file_proto, - bool generate) { - upb::Status status; - upb::FileDefPtr file = pools.AddFile(file_proto, &status); - if (!file) { - absl::string_view name = upb::generator::ToStringView( - UPB_DESC(FileDescriptorProto_name)(file_proto)); - ABSL_LOG(FATAL) << "Couldn't add file " << name - << " to DefPool: " << status.error_message(); - } - if (generate) GenerateFile(pools, file, options, &plugin); - }); + plugin.GenerateFilesRaw( + [&](const UPB_DESC(FileDescriptorProto) * file_proto, bool generate) { + upb::Status status; + upb::FileDefPtr file = pools.AddFile(file_proto, &status); + if (!file) { + absl::string_view name = upb::generator::ToStringView( + UPB_DESC(FileDescriptorProto_name)(file_proto)); + ABSL_LOG(FATAL) << "Couldn't add file " << name + << " to DefPool: " << status.error_message(); + } + if (generate) GenerateFile(pools, file, options, &plugin); + }); return 0; } From c8d2abe43da2b63f9b5bf13f3d5cb06b1bad0dc9 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 30 Oct 2023 07:16:29 -0700 Subject: [PATCH 025/387] Automated rollback of commit d76a6300d29d8d9feeeadddc28925ebd610b1f31. PiperOrigin-RevId: 577833443 --- src/google/protobuf/message.cc | 8 +++++++- src/google/protobuf/message.h | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index eb81694daf..2cf07dbdf4 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -188,7 +188,13 @@ size_t Message::MaybeComputeUnknownFieldsSize( } size_t Message::SpaceUsedLong() const { - return GetReflection()->SpaceUsedLong(*this); + auto* reflection = GetReflection(); + if (PROTOBUF_PREDICT_TRUE(reflection != nullptr)) { + return reflection->SpaceUsedLong(*this); + } + // The only case that does not have reflection is RawMessage. + return internal::DownCast(*this) + .SpaceUsedLong(); } static std::string GetTypeNameImpl(const MessageLite& msg) { diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 83ba793e93..47f41b89ec 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -286,8 +286,7 @@ class PROTOBUF_EXPORT Message : public MessageLite { void DiscardUnknownFields(); // Computes (an estimate of) the total number of bytes currently used for - // storing the message in memory. The default implementation calls the - // Reflection object's SpaceUsed() method. + // storing the message in memory. // // SpaceUsed() is noticeably slower than ByteSize(), as it is implemented // using reflection (rather than the generated code implementation for @@ -297,7 +296,7 @@ class PROTOBUF_EXPORT Message : public MessageLite { // Note: The precise value of this method should never be depended on, and can // change substantially due to internal details. In debug builds, this will // include a random fuzz factor to prevent these dependencies. - virtual size_t SpaceUsedLong() const; + size_t SpaceUsedLong() const; [[deprecated("Please use SpaceUsedLong() instead")]] int SpaceUsed() const { return internal::ToIntSize(SpaceUsedLong()); @@ -1573,6 +1572,12 @@ bool SplitFieldHasExtraIndirectionStatic(const FieldDescriptor* field) { return ret; } +class RawMessageBase : public Message { + public: + using Message::Message; + virtual size_t SpaceUsedLong() const = 0; +}; + } // namespace internal template From c9f9d991720392c6f7a438a92c93b145417fffcf Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 30 Oct 2023 07:19:27 -0700 Subject: [PATCH 026/387] Use GetArena() instead of GetOwningArena() #6. PiperOrigin-RevId: 577833979 --- src/google/protobuf/arena.h | 43 +------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 83beb8f9b4..c4f8f5fc2c 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -389,32 +389,9 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // mutually exclusive fashion, we use implicit conversions to base classes // to force an explicit ranking for our preferences. The lowest ranked // version that compiles will be accepted. - struct Rank2 {}; - struct Rank1 : Rank2 {}; + struct Rank1 {}; struct Rank0 : Rank1 {}; - static Arena* GetOwningArena(const T* p) { - return GetOwningArena(Rank0{}, p); - } - - template - static auto GetOwningArena(Rank0, const U* p) - -> EnableIfArenaGetOwningArena())> { - return p->GetOwningArena(); - } - - // TODO: remove this function. - template - static auto GetOwningArena(Rank1, const U* p) - -> EnableIfArenaGetArena())> { - return p->GetArena(); - } - - template - static Arena* GetOwningArena(Rank2, const U*) { - return nullptr; - } - static void InternalSwap(T* a, T* b) { a->InternalSwap(b); } static Arena* GetArena(T* p) { return GetArena(Rank0{}, p); } @@ -466,28 +443,10 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { friend class TestUtil::ReflectionTester; }; - // Provides access to protected GetOwningArena to generated messages. For - // internal use only. - template - static Arena* InternalGetOwningArena(T* p) { - ABSL_DCHECK_EQ(InternalHelper::GetOwningArena(p), - InternalHelper::GetArena(p)); - return InternalHelper::GetOwningArena(p); - } - - // Wraps InternalGetArena() and will be removed soon. - // For internal use only. - template - static Arena* InternalGetArenaForAllocation(T* p) { - return InternalHelper::GetArena(p); - } - // Provides access to protected GetArena to generated messages. // For internal use only. template static Arena* InternalGetArena(T* p) { - ABSL_DCHECK_EQ(InternalHelper::GetOwningArena(p), - InternalHelper::GetArena(p)); return InternalHelper::GetArena(p); } From 6a16ab614704967b80f91b0c2b0fa886c55116e7 Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Mon, 30 Oct 2023 07:36:09 -0700 Subject: [PATCH 027/387] Check that ffi-compiler loads before using it to define tasks. (#14538) Fixes #14509 Closes #14538 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14538 from JasonLunn:fix_14509 a3f9d0bd4f1f8036253c7a794a61e8cc84b4483c PiperOrigin-RevId: 577837541 --- ruby/lib/google/tasks/ffi.rake | 82 +++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/ruby/lib/google/tasks/ffi.rake b/ruby/lib/google/tasks/ffi.rake index 00e665fee2..c7b2a8e547 100644 --- a/ruby/lib/google/tasks/ffi.rake +++ b/ruby/lib/google/tasks/ffi.rake @@ -1,5 +1,3 @@ -require "ffi-compiler/compile_task" - # # @param task [FFI::Compiler::CompileTask] task to configure def configure_common_compile_task(task) if FileUtils.pwd.include? 'ext' @@ -49,46 +47,56 @@ def with_generated_files end end -desc "Compile Protobuf library for FFI" -namespace "ffi-protobuf" do - with_generated_files do - # Compile Ruby UPB separately in order to limit use of -DUPB_BUILD_API to one - # compilation unit. - desc "Compile UPB library for FFI" - namespace "ffi-upb" do - with_generated_files do - FFI::Compiler::CompileTask.new('ruby-upb') do |c| - configure_common_compile_task c - c.add_define "UPB_BUILD_API" - c.exclude << "/glue.c" - c.exclude << "/shared_message.c" - c.exclude << "/shared_convert.c" - if RbConfig::CONFIG['target_os'] =~ /darwin|linux/ - c.cflags << "-fvisibility=hidden" +begin + require "ffi-compiler/compile_task" + + desc "Compile Protobuf library for FFI" + namespace "ffi-protobuf" do + with_generated_files do + # Compile Ruby UPB separately in order to limit use of -DUPB_BUILD_API to one + # compilation unit. + desc "Compile UPB library for FFI" + namespace "ffi-upb" do + with_generated_files do + FFI::Compiler::CompileTask.new('ruby-upb') do |c| + configure_common_compile_task c + c.add_define "UPB_BUILD_API" + c.exclude << "/glue.c" + c.exclude << "/shared_message.c" + c.exclude << "/shared_convert.c" + if RbConfig::CONFIG['target_os'] =~ /darwin|linux/ + c.cflags << "-fvisibility=hidden" + end end end end - end - FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c| - configure_common_compile_task c - # Ruby UPB was already compiled with different flags. - c.exclude << "/range2-neon.c" - c.exclude << "/range2-sse.c" - c.exclude << "/naive.c" - c.exclude << "/ruby-upb.c" - end + FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c| + configure_common_compile_task c + # Ruby UPB was already compiled with different flags. + c.exclude << "/range2-neon.c" + c.exclude << "/range2-sse.c" + c.exclude << "/naive.c" + c.exclude << "/ruby-upb.c" + end - # Setup dependencies so that the .o files generated by building ffi-upb are - # available to link here. - # TODO Can this be simplified? Can the single shared library be used - # instead of the object files? - protobuf_c_task = Rake::Task[:default] - protobuf_c_shared_lib_task = Rake::Task[protobuf_c_task.prereqs.last] - ruby_upb_shared_lib_task = Rake::Task[:"ffi-upb:default"].prereqs.first - Rake::Task[ruby_upb_shared_lib_task].prereqs.each do |dependency| - protobuf_c_shared_lib_task.prereqs.prepend dependency + # Setup dependencies so that the .o files generated by building ffi-upb are + # available to link here. + # TODO Can this be simplified? Can the single shared library be used + # instead of the object files? + protobuf_c_task = Rake::Task[:default] + protobuf_c_shared_lib_task = Rake::Task[protobuf_c_task.prereqs.last] + ruby_upb_shared_lib_task = Rake::Task[:"ffi-upb:default"].prereqs.first + Rake::Task[ruby_upb_shared_lib_task].prereqs.each do |dependency| + protobuf_c_shared_lib_task.prereqs.prepend dependency + end + end + end +rescue LoadError + desc "Compile Protobuf library for FFI" + namespace "ffi-protobuf" do + task :default do + warn "Skipping build of FFI; `gem install ffi-compiler` to enable." end end end - From e56a9099f0dad5980d1990dc6a164402abaa470c Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 30 Oct 2023 09:39:19 -0700 Subject: [PATCH 028/387] upb: minimize uses of :message_types PiperOrigin-RevId: 577872176 --- upb/mini_table/BUILD | 1 - upb/reflection/BUILD | 2 -- upb/reflection/message.h | 2 +- upb/util/BUILD | 1 - upb/util/required_fields.c | 2 +- 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index ecf2bbbb1c..f4b2ffe845 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -51,7 +51,6 @@ cc_library( "//upb:base", "//upb:hash", "//upb:mem", - "//upb:message_types", "//upb:port", ], ) diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index 0e92276c44..bf0c0e4dbe 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -55,7 +55,6 @@ bootstrap_cc_library( "//upb:base", "//upb:mem", "//upb:message", - "//upb:message_types", "//upb:message_value", "//upb:port", ], @@ -126,7 +125,6 @@ bootstrap_cc_library( "//upb:mem", "//upb:message", "//upb:message_accessors", - "//upb:message_types", "//upb:message_value", "//upb:mini_descriptor", "//upb:mini_descriptor_internal", diff --git a/upb/reflection/message.h b/upb/reflection/message.h index 9e57c1a16e..54af6f15af 100644 --- a/upb/reflection/message.h +++ b/upb/reflection/message.h @@ -12,7 +12,7 @@ #include "upb/mem/arena.h" #include "upb/message/map.h" -#include "upb/message/types.h" +#include "upb/message/message.h" #include "upb/message/value.h" // IWYU pragma: export #include "upb/reflection/common.h" diff --git a/upb/util/BUILD b/upb/util/BUILD index f15f351017..f354be10d8 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -99,7 +99,6 @@ cc_library( deps = [ "//upb:base", "//upb:message", - "//upb:message_types", "//upb:port", "//upb:reflection", ], diff --git a/upb/util/required_fields.c b/upb/util/required_fields.c index 4e66cdd9e6..c6616ecdd3 100644 --- a/upb/util/required_fields.c +++ b/upb/util/required_fields.c @@ -19,7 +19,7 @@ #include "upb/base/descriptor_constants.h" #include "upb/message/array.h" #include "upb/message/map.h" -#include "upb/message/types.h" +#include "upb/message/message.h" #include "upb/port/vsnprintf_compat.h" #include "upb/reflection/def.h" #include "upb/reflection/message.h" From 3667102d91bba05afcb777aa685b1014f521e9bc Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 30 Oct 2023 10:11:32 -0700 Subject: [PATCH 029/387] Remove `virtual` keyword. There are no overrides. PiperOrigin-RevId: 577881969 --- src/google/protobuf/message.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 47f41b89ec..6ddbaec21c 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -257,7 +257,7 @@ class PROTOBUF_EXPORT Message : public MessageLite { // messages which will be merged. Repeated fields will be concatenated. // The given message must be of the same type as this message (i.e. the // exact same class). - virtual void MergeFrom(const Message& from); + void MergeFrom(const Message& from); // Verifies that IsInitialized() returns true. ABSL_CHECK-fails otherwise, // with a nice error message. From 0a5d6d4a45880a3076681cbd7d88e0985b4ccdb7 Mon Sep 17 00:00:00 2001 From: zhangskz Date: Tue, 31 Oct 2023 12:27:44 -0400 Subject: [PATCH 030/387] Check that ffi-compiler loads before using it to define tasks. (#14538) (#14560) Fixes #14509 Closes #14538 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14538 from JasonLunn:fix_14509 a3f9d0bd4f1f8036253c7a794a61e8cc84b4483c PiperOrigin-RevId: 577837541 Co-authored-by: Jason Lunn --- ruby/lib/google/tasks/ffi.rake | 82 +++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/ruby/lib/google/tasks/ffi.rake b/ruby/lib/google/tasks/ffi.rake index 00e665fee2..c7b2a8e547 100644 --- a/ruby/lib/google/tasks/ffi.rake +++ b/ruby/lib/google/tasks/ffi.rake @@ -1,5 +1,3 @@ -require "ffi-compiler/compile_task" - # # @param task [FFI::Compiler::CompileTask] task to configure def configure_common_compile_task(task) if FileUtils.pwd.include? 'ext' @@ -49,46 +47,56 @@ def with_generated_files end end -desc "Compile Protobuf library for FFI" -namespace "ffi-protobuf" do - with_generated_files do - # Compile Ruby UPB separately in order to limit use of -DUPB_BUILD_API to one - # compilation unit. - desc "Compile UPB library for FFI" - namespace "ffi-upb" do - with_generated_files do - FFI::Compiler::CompileTask.new('ruby-upb') do |c| - configure_common_compile_task c - c.add_define "UPB_BUILD_API" - c.exclude << "/glue.c" - c.exclude << "/shared_message.c" - c.exclude << "/shared_convert.c" - if RbConfig::CONFIG['target_os'] =~ /darwin|linux/ - c.cflags << "-fvisibility=hidden" +begin + require "ffi-compiler/compile_task" + + desc "Compile Protobuf library for FFI" + namespace "ffi-protobuf" do + with_generated_files do + # Compile Ruby UPB separately in order to limit use of -DUPB_BUILD_API to one + # compilation unit. + desc "Compile UPB library for FFI" + namespace "ffi-upb" do + with_generated_files do + FFI::Compiler::CompileTask.new('ruby-upb') do |c| + configure_common_compile_task c + c.add_define "UPB_BUILD_API" + c.exclude << "/glue.c" + c.exclude << "/shared_message.c" + c.exclude << "/shared_convert.c" + if RbConfig::CONFIG['target_os'] =~ /darwin|linux/ + c.cflags << "-fvisibility=hidden" + end end end end - end - FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c| - configure_common_compile_task c - # Ruby UPB was already compiled with different flags. - c.exclude << "/range2-neon.c" - c.exclude << "/range2-sse.c" - c.exclude << "/naive.c" - c.exclude << "/ruby-upb.c" - end + FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c| + configure_common_compile_task c + # Ruby UPB was already compiled with different flags. + c.exclude << "/range2-neon.c" + c.exclude << "/range2-sse.c" + c.exclude << "/naive.c" + c.exclude << "/ruby-upb.c" + end - # Setup dependencies so that the .o files generated by building ffi-upb are - # available to link here. - # TODO Can this be simplified? Can the single shared library be used - # instead of the object files? - protobuf_c_task = Rake::Task[:default] - protobuf_c_shared_lib_task = Rake::Task[protobuf_c_task.prereqs.last] - ruby_upb_shared_lib_task = Rake::Task[:"ffi-upb:default"].prereqs.first - Rake::Task[ruby_upb_shared_lib_task].prereqs.each do |dependency| - protobuf_c_shared_lib_task.prereqs.prepend dependency + # Setup dependencies so that the .o files generated by building ffi-upb are + # available to link here. + # TODO Can this be simplified? Can the single shared library be used + # instead of the object files? + protobuf_c_task = Rake::Task[:default] + protobuf_c_shared_lib_task = Rake::Task[protobuf_c_task.prereqs.last] + ruby_upb_shared_lib_task = Rake::Task[:"ffi-upb:default"].prereqs.first + Rake::Task[ruby_upb_shared_lib_task].prereqs.each do |dependency| + protobuf_c_shared_lib_task.prereqs.prepend dependency + end + end + end +rescue LoadError + desc "Compile Protobuf library for FFI" + namespace "ffi-protobuf" do + task :default do + warn "Skipping build of FFI; `gem install ffi-compiler` to enable." end end end - From 30f157529d660bdb36ec3ed5abeaa50cec2d4e5f Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 31 Oct 2023 11:47:43 -0700 Subject: [PATCH 031/387] feat: add protons extension (#14505) Adds an extension id to the registry for use by the [protons](https://www.npmjs.com/package/protons) protobuf encoder/decoder. Closes #14505 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14505 from achingbrain:patch-1 1a80ee9b566943ff227e8a2075c6803d9562b9ae PiperOrigin-RevId: 578254102 --- docs/options.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/options.md b/docs/options.md index 18b6b410fa..aee889ecdf 100644 --- a/docs/options.md +++ b/docs/options.md @@ -486,3 +486,8 @@ with info about your project (name and website) so we can add an entry for you. * Website: https://square.github.io/wire/ * Extensions: 1185 + +1. Protons + + * Website: https://github.com/ipfs/protons + * Extensions: 1186 From 88249acbfdfd34dd24c04b032c4ae3578a481d2e Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 31 Oct 2023 13:46:24 -0700 Subject: [PATCH 032/387] Internal change PiperOrigin-RevId: 578290521 --- python/google/protobuf/internal/reflection_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 2230d0c94d..1f22b86458 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -1462,6 +1462,7 @@ class Proto2ReflectionTest(unittest.TestCase): if api_implementation.Type() != 'python': return + file = descriptor.FileDescriptor(name='foo.proto', package='') FieldDescriptor = descriptor.FieldDescriptor foo_field_descriptor = FieldDescriptor( name='foo_field', full_name='MyProto.foo_field', @@ -1470,7 +1471,7 @@ class Proto2ReflectionTest(unittest.TestCase): label=FieldDescriptor.LABEL_OPTIONAL, default_value=0, containing_type=None, message_type=None, enum_type=None, is_extension=False, extension_scope=None, - options=descriptor_pb2.FieldOptions(), + options=descriptor_pb2.FieldOptions(), file=file, # pylint: disable=protected-access create_key=descriptor._internal_create_key) mydescriptor = descriptor.Descriptor( @@ -1478,6 +1479,7 @@ class Proto2ReflectionTest(unittest.TestCase): containing_type=None, nested_types=[], enum_types=[], fields=[foo_field_descriptor], extensions=[], options=descriptor_pb2.MessageOptions(), + file=file, # pylint: disable=protected-access create_key=descriptor._internal_create_key) From 712badffb14f6f6a4a3b12d659219fe90585f9e0 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 31 Oct 2023 16:17:23 -0700 Subject: [PATCH 033/387] Include .inc files directly instead of through a filegroup gRPC auto-generates CMake and other build configs from the Bazel build graph, but the logic for doing this does not know how to handle filegroups. This change works around that problem by making the `:port` target refer directly to the `.inc` files instead of going through a filegroup. This solution is not ideal but I think it's probably the best way to unblock progress for now. PiperOrigin-RevId: 578333954 --- upb/port/BUILD | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/upb/port/BUILD b/upb/port/BUILD index dc1c343c7a..fe20c085e5 100644 --- a/upb/port/BUILD +++ b/upb/port/BUILD @@ -14,7 +14,15 @@ cc_library( "vsnprintf_compat.h", ], copts = UPB_DEFAULT_COPTS, - textual_hdrs = [":inc"], + textual_hdrs = [ + # We must list the headers explicitly here instead of relying on the + # :inc filegroup below. gRPC auto-generates various build configs from + # the Bazel graph, and this logic does not know how to handle + # filegroups. We might be able to replace these headers with just + # ":inc" after gRPC starts using upb's CMake build. + "def.inc", + "undef.inc", + ], visibility = ["//visibility:public"], ) From 8defef58f4367d3a968b44000698e308a035ab9e Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 31 Oct 2023 21:30:33 -0400 Subject: [PATCH 034/387] Include .inc files directly instead of through a filegroup (#14575) gRPC auto-generates CMake and other build configs from the Bazel build graph, but the logic for doing this does not know how to handle filegroups. This change works around that problem by making the `:port` target refer directly to the `.inc` files instead of going through a filegroup. This solution is not ideal but I think it's probably the best way to unblock progress for now. PiperOrigin-RevId: 578333954 --- upb/port/BUILD | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/upb/port/BUILD b/upb/port/BUILD index dc1c343c7a..fe20c085e5 100644 --- a/upb/port/BUILD +++ b/upb/port/BUILD @@ -14,7 +14,15 @@ cc_library( "vsnprintf_compat.h", ], copts = UPB_DEFAULT_COPTS, - textual_hdrs = [":inc"], + textual_hdrs = [ + # We must list the headers explicitly here instead of relying on the + # :inc filegroup below. gRPC auto-generates various build configs from + # the Bazel graph, and this logic does not know how to handle + # filegroups. We might be able to replace these headers with just + # ":inc" after gRPC starts using upb's CMake build. + "def.inc", + "undef.inc", + ], visibility = ["//visibility:public"], ) From abdcd6524635f71200ac5f8434680eaf10dcec2a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 1 Nov 2023 08:54:52 -0700 Subject: [PATCH 035/387] Extract field descriptor enums into descriptor_lite.h, which can be included by protobuf_lite code. PiperOrigin-RevId: 578533045 --- src/google/protobuf/BUILD.bazel | 1 + src/google/protobuf/descriptor.h | 109 ++++++++++++++------------ src/google/protobuf/descriptor_lite.h | 87 ++++++++++++++++++++ 3 files changed, 145 insertions(+), 52 deletions(-) create mode 100644 src/google/protobuf/descriptor_lite.h diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index f85e88b16c..3bb21ad0ab 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -389,6 +389,7 @@ cc_library( "arena.h", "arenastring.h", "arenaz_sampler.h", + "descriptor_lite.h", "endian.h", "explicitly_constructed.h", "extension_set.h", diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index ff178c31c9..115a1f86a5 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -49,6 +49,7 @@ #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/optional.h" +#include "google/protobuf/descriptor_lite.h" #include "google/protobuf/extension_set.h" #include "google/protobuf/port.h" @@ -731,7 +732,8 @@ PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(Descriptor, 152); // - Given a DescriptorPool, call DescriptorPool::FindExtensionByNumber() or // DescriptorPool::FindExtensionByPrintableName(). // Use DescriptorPool to construct your own descriptors. -class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { +class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase, + public internal::FieldDescriptorLite { public: typedef FieldDescriptorProto Proto; @@ -742,64 +744,67 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { // Identifies a field type. 0 is reserved for errors. The order is weird // for historical reasons. Types 12 and up are new in proto2. - enum Type { - TYPE_DOUBLE = 1, // double, exactly eight bytes on the wire. - TYPE_FLOAT = 2, // float, exactly four bytes on the wire. - TYPE_INT64 = 3, // int64, varint on the wire. Negative numbers - // take 10 bytes. Use TYPE_SINT64 if negative - // values are likely. - TYPE_UINT64 = 4, // uint64, varint on the wire. - TYPE_INT32 = 5, // int32, varint on the wire. Negative numbers - // take 10 bytes. Use TYPE_SINT32 if negative - // values are likely. - TYPE_FIXED64 = 6, // uint64, exactly eight bytes on the wire. - TYPE_FIXED32 = 7, // uint32, exactly four bytes on the wire. - TYPE_BOOL = 8, // bool, varint on the wire. - TYPE_STRING = 9, // UTF-8 text. - TYPE_GROUP = 10, // Tag-delimited message. Deprecated. - TYPE_MESSAGE = 11, // Length-delimited message. - - TYPE_BYTES = 12, // Arbitrary byte array. - TYPE_UINT32 = 13, // uint32, varint on the wire - TYPE_ENUM = 14, // Enum, varint on the wire - TYPE_SFIXED32 = 15, // int32, exactly four bytes on the wire - TYPE_SFIXED64 = 16, // int64, exactly eight bytes on the wire - TYPE_SINT32 = 17, // int32, ZigZag-encoded varint on the wire - TYPE_SINT64 = 18, // int64, ZigZag-encoded varint on the wire - - MAX_TYPE = 18, // Constant useful for defining lookup tables - // indexed by Type. - }; + // Inherited from FieldDescriptorLite: + // enum Type { + // TYPE_DOUBLE = 1, // double, exactly eight bytes on the wire. + // TYPE_FLOAT = 2, // float, exactly four bytes on the wire. + // TYPE_INT64 = 3, // int64, varint on the wire. Negative numbers + // // take 10 bytes. Use TYPE_SINT64 if negative + // // values are likely. + // TYPE_UINT64 = 4, // uint64, varint on the wire. + // TYPE_INT32 = 5, // int32, varint on the wire. Negative numbers + // // take 10 bytes. Use TYPE_SINT32 if negative + // // values are likely. + // TYPE_FIXED64 = 6, // uint64, exactly eight bytes on the wire. + // TYPE_FIXED32 = 7, // uint32, exactly four bytes on the wire. + // TYPE_BOOL = 8, // bool, varint on the wire. + // TYPE_STRING = 9, // UTF-8 text. + // TYPE_GROUP = 10, // Tag-delimited message. Deprecated. + // TYPE_MESSAGE = 11, // Length-delimited message. + + // TYPE_BYTES = 12, // Arbitrary byte array. + // TYPE_UINT32 = 13, // uint32, varint on the wire + // TYPE_ENUM = 14, // Enum, varint on the wire + // TYPE_SFIXED32 = 15, // int32, exactly four bytes on the wire + // TYPE_SFIXED64 = 16, // int64, exactly eight bytes on the wire + // TYPE_SINT32 = 17, // int32, ZigZag-encoded varint on the wire + // TYPE_SINT64 = 18, // int64, ZigZag-encoded varint on the wire + + // MAX_TYPE = 18, // Constant useful for defining lookup tables + // // indexed by Type. + // }; // Specifies the C++ data type used to represent the field. There is a // fixed mapping from Type to CppType where each Type maps to exactly one // CppType. 0 is reserved for errors. - enum CppType { - CPPTYPE_INT32 = 1, // TYPE_INT32, TYPE_SINT32, TYPE_SFIXED32 - CPPTYPE_INT64 = 2, // TYPE_INT64, TYPE_SINT64, TYPE_SFIXED64 - CPPTYPE_UINT32 = 3, // TYPE_UINT32, TYPE_FIXED32 - CPPTYPE_UINT64 = 4, // TYPE_UINT64, TYPE_FIXED64 - CPPTYPE_DOUBLE = 5, // TYPE_DOUBLE - CPPTYPE_FLOAT = 6, // TYPE_FLOAT - CPPTYPE_BOOL = 7, // TYPE_BOOL - CPPTYPE_ENUM = 8, // TYPE_ENUM - CPPTYPE_STRING = 9, // TYPE_STRING, TYPE_BYTES - CPPTYPE_MESSAGE = 10, // TYPE_MESSAGE, TYPE_GROUP - - MAX_CPPTYPE = 10, // Constant useful for defining lookup tables - // indexed by CppType. - }; + // Inherited from FieldDescriptorLite: + // enum CppType { + // CPPTYPE_INT32 = 1, // TYPE_INT32, TYPE_SINT32, TYPE_SFIXED32 + // CPPTYPE_INT64 = 2, // TYPE_INT64, TYPE_SINT64, TYPE_SFIXED64 + // CPPTYPE_UINT32 = 3, // TYPE_UINT32, TYPE_FIXED32 + // CPPTYPE_UINT64 = 4, // TYPE_UINT64, TYPE_FIXED64 + // CPPTYPE_DOUBLE = 5, // TYPE_DOUBLE + // CPPTYPE_FLOAT = 6, // TYPE_FLOAT + // CPPTYPE_BOOL = 7, // TYPE_BOOL + // CPPTYPE_ENUM = 8, // TYPE_ENUM + // CPPTYPE_STRING = 9, // TYPE_STRING, TYPE_BYTES + // CPPTYPE_MESSAGE = 10, // TYPE_MESSAGE, TYPE_GROUP + + // MAX_CPPTYPE = 10, // Constant useful for defining lookup tables + // // indexed by CppType. + // }; // Identifies whether the field is optional, required, or repeated. 0 is // reserved for errors. - enum Label { - LABEL_OPTIONAL = 1, // optional - LABEL_REQUIRED = 2, // required - LABEL_REPEATED = 3, // repeated - - MAX_LABEL = 3, // Constant useful for defining lookup tables - // indexed by Label. - }; + // Inherited from FieldDescriptorLite: + // enum Label { + // LABEL_OPTIONAL = 1, // optional + // LABEL_REQUIRED = 2, // required + // LABEL_REPEATED = 3, // repeated + + // MAX_LABEL = 3, // Constant useful for defining lookup tables + // // indexed by Label. + // }; // Valid field numbers are positive integers up to kMaxNumber. static const int kMaxNumber = (1 << 29) - 1; diff --git a/src/google/protobuf/descriptor_lite.h b/src/google/protobuf/descriptor_lite.h new file mode 100644 index 0000000000..db5805affe --- /dev/null +++ b/src/google/protobuf/descriptor_lite.h @@ -0,0 +1,87 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd +// +// This file contains definitions for the descriptors, so they can be used +// without importing descriptor.h + +#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_LITE_H__ +#define GOOGLE_PROTOBUF_DESCRIPTOR_LITE_H__ + +namespace google { +namespace protobuf { +namespace internal { + +class FieldDescriptorLite { + public: + // Identifies a field type. 0 is reserved for errors. + // The order is weird for historical reasons. + // Types 12 and up are new in proto2. + enum Type { + TYPE_DOUBLE = 1, // double, exactly eight bytes on the wire. + TYPE_FLOAT = 2, // float, exactly four bytes on the wire. + TYPE_INT64 = 3, // int64, varint on the wire. Negative numbers + // take 10 bytes. Use TYPE_SINT64 if negative + // values are likely. + TYPE_UINT64 = 4, // uint64, varint on the wire. + TYPE_INT32 = 5, // int32, varint on the wire. Negative numbers + // take 10 bytes. Use TYPE_SINT32 if negative + // values are likely. + TYPE_FIXED64 = 6, // uint64, exactly eight bytes on the wire. + TYPE_FIXED32 = 7, // uint32, exactly four bytes on the wire. + TYPE_BOOL = 8, // bool, varint on the wire. + TYPE_STRING = 9, // UTF-8 text. + TYPE_GROUP = 10, // Tag-delimited message. Deprecated. + TYPE_MESSAGE = 11, // Length-delimited message. + + TYPE_BYTES = 12, // Arbitrary byte array. + TYPE_UINT32 = 13, // uint32, varint on the wire + TYPE_ENUM = 14, // Enum, varint on the wire + TYPE_SFIXED32 = 15, // int32, exactly four bytes on the wire + TYPE_SFIXED64 = 16, // int64, exactly eight bytes on the wire + TYPE_SINT32 = 17, // int32, ZigZag-encoded varint on the wire + TYPE_SINT64 = 18, // int64, ZigZag-encoded varint on the wire + + MAX_TYPE = 18, // Constant useful for defining lookup tables + // indexed by Type. + }; + + // Specifies the C++ data type used to represent the field. There is a + // fixed mapping from Type to CppType where each Type maps to exactly one + // CppType. 0 is reserved for errors. + enum CppType { + CPPTYPE_INT32 = 1, // TYPE_INT32, TYPE_SINT32, TYPE_SFIXED32 + CPPTYPE_INT64 = 2, // TYPE_INT64, TYPE_SINT64, TYPE_SFIXED64 + CPPTYPE_UINT32 = 3, // TYPE_UINT32, TYPE_FIXED32 + CPPTYPE_UINT64 = 4, // TYPE_UINT64, TYPE_FIXED64 + CPPTYPE_DOUBLE = 5, // TYPE_DOUBLE + CPPTYPE_FLOAT = 6, // TYPE_FLOAT + CPPTYPE_BOOL = 7, // TYPE_BOOL + CPPTYPE_ENUM = 8, // TYPE_ENUM + CPPTYPE_STRING = 9, // TYPE_STRING, TYPE_BYTES + CPPTYPE_MESSAGE = 10, // TYPE_MESSAGE, TYPE_GROUP + + MAX_CPPTYPE = 10, // Constant useful for defining lookup tables + // indexed by CppType. + }; + + // Identifies whether the field is optional, required, or repeated. 0 is + // reserved for errors. + enum Label { + LABEL_OPTIONAL = 1, // optional + LABEL_REQUIRED = 2, // required + LABEL_REPEATED = 3, // repeated + + MAX_LABEL = 3, // Constant useful for defining lookup tables + // indexed by Label. + }; +}; + +} // namespace internal +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_DESCRIPTOR_LITE_H__ From f083530a0655338b5a1b8dfa0d46727cf1048dd9 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 1 Nov 2023 10:26:00 -0700 Subject: [PATCH 036/387] Allow string + bytes fields in oneofs (now that the underyling accessors match the expected shape) PiperOrigin-RevId: 578561161 --- rust/test/shared/accessors_proto3_test.rs | 5 ++--- rust/test/shared/accessors_test.rs | 5 ++--- src/google/protobuf/compiler/rust/accessors/accessors.cc | 4 ++-- src/google/protobuf/compiler/rust/oneof.cc | 7 +++++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rust/test/shared/accessors_proto3_test.rs b/rust/test/shared/accessors_proto3_test.rs index 3260c0d11d..3eb6e5df61 100644 --- a/rust/test/shared/accessors_proto3_test.rs +++ b/rust/test/shared/accessors_proto3_test.rs @@ -200,9 +200,8 @@ fn test_oneof_accessors() { assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); msg.oneof_uint32_set(Some(7)); - msg.oneof_bytes_mut().set(b""); + msg.oneof_bytes_mut().set(b"123"); assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0))); - // This should show it set to the OneofBytes but its not supported yet. - assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); + assert_that!(msg.oneof_field(), matches_pattern!(OneofBytes(eq(b"123")))); } diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index f1f55f663d..2b207ac11c 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -690,11 +690,10 @@ fn test_oneof_accessors() { assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); msg.oneof_uint32_set(Some(7)); - msg.oneof_bytes_mut().set(b""); + msg.oneof_bytes_mut().set(b"123"); assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0))); - // This should show it set to the OneofBytes but its not supported yet. - assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); + assert_that!(msg.oneof_field(), matches_pattern!(OneofBytes(eq(b"123")))); } macro_rules! generate_repeated_numeric_test { diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index fa5c876bf9..807eb478b3 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -23,8 +23,8 @@ namespace { std::unique_ptr AccessorGeneratorFor( const FieldDescriptor& desc) { - // We do not support [ctype=FOO] (used to set the field type in C++ to - // cord or string_piece) in V0 API. + // TODO: We do not support [ctype=FOO] (used to set the field + // type in C++ to cord or string_piece) in V0.6 API. if (desc.options().has_ctype()) { return std::make_unique(); } diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 2cdeeac203..41f5bb9a1c 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -92,12 +92,15 @@ std::string oneofCaseEnumName(const OneofDescriptor& desc) { // TODO: Promote up to naming.h once all types can be spelled. std::string RsTypeName(const FieldDescriptor& desc) { + // TODO: Fields with a ctype set not supported in v0.6 api. + if (desc.options().has_ctype()) { + return ""; + } + switch (desc.type()) { case FieldDescriptor::TYPE_MESSAGE: case FieldDescriptor::TYPE_ENUM: case FieldDescriptor::TYPE_GROUP: - case FieldDescriptor::TYPE_STRING: - case FieldDescriptor::TYPE_BYTES: return ""; default: return PrimitiveRsTypeName(desc); From b0eeb356b84fb7e8773c9a0dd76b354ae2e3f218 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 1 Nov 2023 10:33:11 -0700 Subject: [PATCH 037/387] Fixed Python memory leak in map lookup. Previously we were allocating memory on the message's arena every time we performed a `map[key]` or `map.get(key)` operation. This is unnecessary, as the key's data is only needed ephemerally, for the duration of the lookup, and we can therefore alias the Python object's string data instead of copying it. This required fixing a bug in the convert.c operation. Previously in the `arena==NULL` case, if the user passes a bytes object instead of a unicode string, the code would return a pointer to a temporary Python object that had already been freed, leading to use-after-free. I fixed this by referencing the bytes object's data directly, and using utf8_range to verify the UTF-8. Fixes: https://github.com/protocolbuffers/protobuf/issues/14571 PiperOrigin-RevId: 578563555 --- python/BUILD | 1 + python/convert.c | 32 ++++++++++++------- .../google/protobuf/internal/message_test.py | 1 - python/map.c | 8 ++--- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/python/BUILD b/python/BUILD index 92e9c496c5..ea1dac3160 100644 --- a/python/BUILD +++ b/python/BUILD @@ -203,5 +203,6 @@ py_extension( "//upb/util:compare", "//upb/util:def_to_proto", "//upb/util:required_fields", + "@utf8_range", ], ) diff --git a/python/convert.c b/python/convert.c index 413c42f735..0c1174ba6b 100644 --- a/python/convert.c +++ b/python/convert.c @@ -35,6 +35,7 @@ #include "upb/message/map.h" #include "upb/reflection/message.h" #include "upb/util/compare.h" +#include "utf8_range.h" // Must be last. #include "upb/port/def.inc" @@ -259,20 +260,27 @@ bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val, } case kUpb_CType_String: { Py_ssize_t size; - const char* ptr; - PyObject* unicode = NULL; if (PyBytes_Check(obj)) { - unicode = obj = PyUnicode_FromEncodedObject(obj, "utf-8", NULL); - if (!obj) return false; + // Use the object's bytes if they are valid UTF-8. + char* ptr; + if (PyBytes_AsStringAndSize(obj, &ptr, &size) < 0) return false; + if (utf8_range2((const unsigned char*)ptr, size) != 0) { + // Invalid UTF-8. Try to convert the message to a Python Unicode + // object, even though we know this will fail, just to get the + // idiomatic Python error message. + obj = PyUnicode_FromEncodedObject(obj, "utf-8", NULL); + assert(!obj); + return false; + } + *val = PyUpb_MaybeCopyString(ptr, size, arena); + return true; + } else { + const char* ptr; + ptr = PyUnicode_AsUTF8AndSize(obj, &size); + if (PyErr_Occurred()) return false; + *val = PyUpb_MaybeCopyString(ptr, size, arena); + return true; } - ptr = PyUnicode_AsUTF8AndSize(obj, &size); - if (PyErr_Occurred()) { - Py_XDECREF(unicode); - return false; - } - *val = PyUpb_MaybeCopyString(ptr, size, arena); - Py_XDECREF(unicode); - return true; } case kUpb_CType_Message: PyErr_Format(PyExc_ValueError, "Message objects may not be assigned"); diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 0bac00da02..b0f1ae784f 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -48,7 +48,6 @@ UCS2_MAXUNICODE = 65535 warnings.simplefilter('error', DeprecationWarning) - @_parameterized.named_parameters(('_proto2', unittest_pb2), ('_proto3', unittest_proto3_arena_pb2)) @testing_refleaks.TestCase diff --git a/python/map.c b/python/map.c index a1d75de9a1..6bf12af438 100644 --- a/python/map.c +++ b/python/map.c @@ -179,7 +179,7 @@ int PyUpb_MapContainer_AssignSubscript(PyObject* _self, PyObject* key, const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1); upb_Arena* arena = PyUpb_Arena_Get(self->arena); upb_MessageValue u_key, u_val; - if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return -1; + if (!PyUpb_PyToUpb(key, key_f, &u_key, NULL)) return -1; if (val) { if (!PyUpb_PyToUpb(val, val_f, &u_val, arena)) return -1; @@ -200,9 +200,8 @@ PyObject* PyUpb_MapContainer_Subscript(PyObject* _self, PyObject* key) { const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f); const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0); const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1); - upb_Arena* arena = PyUpb_Arena_Get(self->arena); upb_MessageValue u_key, u_val; - if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return NULL; + if (!PyUpb_PyToUpb(key, key_f, &u_key, NULL)) return NULL; if (!map || !upb_Map_Get(map, u_key, &u_val)) { map = PyUpb_MapContainer_EnsureReified(_self); upb_Arena* arena = PyUpb_Arena_Get(self->arena); @@ -256,9 +255,8 @@ static PyObject* PyUpb_MapContainer_Get(PyObject* _self, PyObject* args, const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f); const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0); const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1); - upb_Arena* arena = PyUpb_Arena_Get(self->arena); upb_MessageValue u_key, u_val; - if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return NULL; + if (!PyUpb_PyToUpb(key, key_f, &u_key, NULL)) return NULL; if (map && upb_Map_Get(map, u_key, &u_val)) { return PyUpb_UpbToPy(u_val, val_f, self->arena); } From 1711ebd4559313555e89d0f56294842779c7e900 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 1 Nov 2023 10:33:11 -0700 Subject: [PATCH 038/387] Fixed Python memory leak in map lookup. Previously we were allocating memory on the message's arena every time we performed a `map[key]` or `map.get(key)` operation. This is unnecessary, as the key's data is only needed ephemerally, for the duration of the lookup, and we can therefore alias the Python object's string data instead of copying it. This required fixing a bug in the convert.c operation. Previously in the `arena==NULL` case, if the user passes a bytes object instead of a unicode string, the code would return a pointer to a temporary Python object that had already been freed, leading to use-after-free. I fixed this by referencing the bytes object's data directly, and using utf8_range to verify the UTF-8. Fixes: https://github.com/protocolbuffers/protobuf/issues/14571 PiperOrigin-RevId: 578563555 --- python/BUILD | 1 + python/convert.c | 32 ++++++++++++------- .../google/protobuf/internal/message_test.py | 1 - python/map.c | 8 ++--- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/python/BUILD b/python/BUILD index 92e9c496c5..ea1dac3160 100644 --- a/python/BUILD +++ b/python/BUILD @@ -203,5 +203,6 @@ py_extension( "//upb/util:compare", "//upb/util:def_to_proto", "//upb/util:required_fields", + "@utf8_range", ], ) diff --git a/python/convert.c b/python/convert.c index 413c42f735..0c1174ba6b 100644 --- a/python/convert.c +++ b/python/convert.c @@ -35,6 +35,7 @@ #include "upb/message/map.h" #include "upb/reflection/message.h" #include "upb/util/compare.h" +#include "utf8_range.h" // Must be last. #include "upb/port/def.inc" @@ -259,20 +260,27 @@ bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val, } case kUpb_CType_String: { Py_ssize_t size; - const char* ptr; - PyObject* unicode = NULL; if (PyBytes_Check(obj)) { - unicode = obj = PyUnicode_FromEncodedObject(obj, "utf-8", NULL); - if (!obj) return false; + // Use the object's bytes if they are valid UTF-8. + char* ptr; + if (PyBytes_AsStringAndSize(obj, &ptr, &size) < 0) return false; + if (utf8_range2((const unsigned char*)ptr, size) != 0) { + // Invalid UTF-8. Try to convert the message to a Python Unicode + // object, even though we know this will fail, just to get the + // idiomatic Python error message. + obj = PyUnicode_FromEncodedObject(obj, "utf-8", NULL); + assert(!obj); + return false; + } + *val = PyUpb_MaybeCopyString(ptr, size, arena); + return true; + } else { + const char* ptr; + ptr = PyUnicode_AsUTF8AndSize(obj, &size); + if (PyErr_Occurred()) return false; + *val = PyUpb_MaybeCopyString(ptr, size, arena); + return true; } - ptr = PyUnicode_AsUTF8AndSize(obj, &size); - if (PyErr_Occurred()) { - Py_XDECREF(unicode); - return false; - } - *val = PyUpb_MaybeCopyString(ptr, size, arena); - Py_XDECREF(unicode); - return true; } case kUpb_CType_Message: PyErr_Format(PyExc_ValueError, "Message objects may not be assigned"); diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 0bac00da02..b0f1ae784f 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -48,7 +48,6 @@ UCS2_MAXUNICODE = 65535 warnings.simplefilter('error', DeprecationWarning) - @_parameterized.named_parameters(('_proto2', unittest_pb2), ('_proto3', unittest_proto3_arena_pb2)) @testing_refleaks.TestCase diff --git a/python/map.c b/python/map.c index a1d75de9a1..6bf12af438 100644 --- a/python/map.c +++ b/python/map.c @@ -179,7 +179,7 @@ int PyUpb_MapContainer_AssignSubscript(PyObject* _self, PyObject* key, const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1); upb_Arena* arena = PyUpb_Arena_Get(self->arena); upb_MessageValue u_key, u_val; - if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return -1; + if (!PyUpb_PyToUpb(key, key_f, &u_key, NULL)) return -1; if (val) { if (!PyUpb_PyToUpb(val, val_f, &u_val, arena)) return -1; @@ -200,9 +200,8 @@ PyObject* PyUpb_MapContainer_Subscript(PyObject* _self, PyObject* key) { const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f); const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0); const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1); - upb_Arena* arena = PyUpb_Arena_Get(self->arena); upb_MessageValue u_key, u_val; - if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return NULL; + if (!PyUpb_PyToUpb(key, key_f, &u_key, NULL)) return NULL; if (!map || !upb_Map_Get(map, u_key, &u_val)) { map = PyUpb_MapContainer_EnsureReified(_self); upb_Arena* arena = PyUpb_Arena_Get(self->arena); @@ -256,9 +255,8 @@ static PyObject* PyUpb_MapContainer_Get(PyObject* _self, PyObject* args, const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f); const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0); const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1); - upb_Arena* arena = PyUpb_Arena_Get(self->arena); upb_MessageValue u_key, u_val; - if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return NULL; + if (!PyUpb_PyToUpb(key, key_f, &u_key, NULL)) return NULL; if (map && upb_Map_Get(map, u_key, &u_val)) { return PyUpb_UpbToPy(u_val, val_f, self->arena); } From f2ce105a484475a5195ed6d66689fa74c90aad2d Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 1 Nov 2023 12:17:02 -0700 Subject: [PATCH 039/387] Migrate tests to windows 2022 by default. For the windows 2019 test, we need to upgrade python for the latest gcloud to work. PiperOrigin-RevId: 578600130 --- .github/workflows/test_cpp.yml | 44 ++++++++++++++++++++-------------- .github/workflows/test_upb.yml | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test_cpp.yml b/.github/workflows/test_cpp.yml index 62f8296ad5..54b28006a9 100644 --- a/.github/workflows/test_cpp.yml +++ b/.github/workflows/test_cpp.yml @@ -324,8 +324,8 @@ jobs: # for Apple Silicon to detect issues there. bazel: build --cpu=darwin_arm64 //src/... - name: Windows - os: windows-2019 - cache_key: windows-2019 + os: windows-2022 + cache_key: windows-2022 bazel: test //src/... @com_google_protobuf_examples//... --test_tag_filters=-conformance --build_tag_filters=-conformance name: ${{ matrix.name }} Bazel runs-on: ${{ matrix.os }} @@ -351,14 +351,6 @@ jobs: flags: -DCMAKE_CXX_STANDARD=14 cache-prefix: macos-cmake - name: Windows CMake - os: windows-2019 - flags: >- - -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF - -Dprotobuf_BUILD_SHARED_LIBS=OFF - -Dprotobuf_BUILD_EXAMPLES=ON - vsversion: '2019' - cache-prefix: windows-2019-cmake - - name: Windows CMake 2022 os: windows-2022 flags: >- -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF @@ -366,29 +358,38 @@ jobs: -Dprotobuf_BUILD_EXAMPLES=ON vsversion: '2022' cache-prefix: windows-2022-cmake - - name: Windows CMake 32-bit + - name: Windows CMake 2019 os: windows-2019 flags: >- -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF + -Dprotobuf_BUILD_SHARED_LIBS=OFF + -Dprotobuf_BUILD_EXAMPLES=ON vsversion: '2019' + cache-prefix: windows-2019-cmake + python-version: '3.8' + - name: Windows CMake 32-bit + os: windows-2022 + flags: >- + -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF + vsversion: '2022' windows-arch: 'win32' - cache-prefix: windows-2019-win32-cmake + cache-prefix: windows-2022-win32-cmake - name: Windows CMake Shared - os: windows-2019 + os: windows-2022 flags: >- -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_SHARED_LIBS=ON - vsversion: '2019' - cache-prefix: windows-2019-cmake + vsversion: '2022' + cache-prefix: windows-2022-cmake - name: Windows CMake Install - os: windows-2019 + os: windows-2022 install-flags: -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_TESTS=OFF flags: >- -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_REMOVE_INSTALLED_HEADERS=ON -Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF - vsversion: '2019' - cache-prefix: windows-2019-cmake + vsversion: '2022' + cache-prefix: windows-2022-cmake name: ${{ matrix.name }} runs-on: ${{ matrix.os }} steps: @@ -398,6 +399,13 @@ jobs: ref: ${{ inputs.safe-checkout }} submodules: recursive + - name: Install Python + if: ${{ matrix.python-version }} + uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 + with: + python-version: ${{ matrix.python-version }} + cache: pip + - name: Setup MSVC if: ${{ runner.os == 'Windows' }} uses: ilammy/msvc-dev-cmd@cec98b9d092141f74527d0afa6feb2af698cfe89 # v1.12.1 diff --git a/.github/workflows/test_upb.yml b/.github/workflows/test_upb.yml index f2c1cfa2e4..a8454bfe78 100644 --- a/.github/workflows/test_upb.yml +++ b/.github/workflows/test_upb.yml @@ -64,7 +64,7 @@ jobs: strategy: fail-fast: false # Don't cancel all jobs if one fails. name: Windows - runs-on: windows-2019 + runs-on: windows-2022 steps: - name: Checkout pending changes uses: protocolbuffers/protobuf-ci/checkout@v2 From 6b5d8db01fe47478e8d400f550e797e6230d464e Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 1 Nov 2023 13:03:44 -0700 Subject: [PATCH 040/387] Updating version.json and repo version numbers to: 25.0 --- CMakeLists.txt | 2 +- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/README.md | 6 +++--- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/kotlin-lite/pom.xml | 2 +- java/kotlin/pom.xml | 2 +- java/lite.md | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/protoc/pom.xml | 2 +- java/util/pom.xml | 2 +- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 10 +++++----- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 ++-- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.h | 2 +- .../protobuf/compiler/java/java_features.pb.h | 2 +- src/google/protobuf/compiler/plugin.pb.h | 2 +- .../protobuf/compiler/versions_suffix.h | 2 +- src/google/protobuf/cpp_features.pb.h | 2 +- src/google/protobuf/descriptor.pb.h | 2 +- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/field_mask.pb.h | 2 +- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.h | 2 +- src/google/protobuf/stubs/common.h | 2 +- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.h | 2 +- src/google/protobuf/wrappers.pb.h | 2 +- version.json | 20 +++++++++---------- 38 files changed, 54 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 868674460e..f78fccc27a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ if (protobuf_BUILD_SHARED_LIBS) endif () # Version metadata -set(protobuf_VERSION_STRING "4.25.0-rc-2") +set(protobuf_VERSION_STRING "4.25.0") set(protobuf_DESCRIPTION "Protocol Buffers") set(protobuf_CONTACT "protobuf@googlegroups.com") diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 4f7ce1f7ee..f2b9f35535 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '4.25.0-rc2' + s.version = '4.25.0' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' diff --git a/Protobuf.podspec b/Protobuf.podspec index 6852f2d265..0e4a664d6f 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.25.0-rc2' + s.version = '3.25.0' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 4cd5e49707..bd9a3b66db 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.25.0-rc2 + 3.25.0 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 1623bd1e2c..b5731cdebb 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -5,7 +5,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.25.0-rc2 + 3.25.0 10.0 Google Inc. netstandard1.1;netstandard2.0;net45;net50 diff --git a/java/README.md b/java/README.md index acbdb00051..f6dab2654d 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.25.0-rc-2 + 3.25.0 ``` @@ -37,14 +37,14 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.25.0-rc-2 + 3.25.0 ``` ### Gradle If you are using Gradle, add the following to your `build.gradle` file's -dependencies: `implementation 'com.google.protobuf:protobuf-java:3.25.0-rc-2'` Again, +dependencies: `implementation 'com.google.protobuf:protobuf-java:3.25.0'` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 24a7ba1d42..411c501fa7 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.25.0-RC2 + 3.25.0 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 8942e32b59..c98d168792 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC2 + 3.25.0 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 0074e6f7fa..bc4fb9ef7c 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC2 + 3.25.0 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index b7dd892c10..3d26d8a311 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC2 + 3.25.0 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index 910546619b..fbaf1c8ed4 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.25.0-rc-2 + 3.25.0 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 9d4ab79be5..3f9e3897bf 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC2 + 3.25.0 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 44dda53871..9e0a6992c0 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC2 + 3.25.0 pom Protocol Buffers [Parent] diff --git a/java/protoc/pom.xml b/java/protoc/pom.xml index f3002179fb..34f8579c8b 100644 --- a/java/protoc/pom.xml +++ b/java/protoc/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.25.0-RC2 + 3.25.0 pom Protobuf Compiler diff --git a/java/util/pom.xml b/java/util/pom.xml index d374d425c9..f25581be84 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0-RC2 + 3.25.0 protobuf-java-util diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index ad138218b8..4fab47f357 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -32,7 +32,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.25.0RC2" +#define PHP_PROTOBUF_VERSION "3.25.0" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protobuf_version.bzl b/protobuf_version.bzl index ed03f12247..a122dc377f 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,6 +1,6 @@ """ Contains version numbers to be used in other bzl files """ -PROTOC_VERSION = "25.0-rc-2" -PROTOBUF_JAVA_VERSION = "3.25.0-RC2" -PROTOBUF_PYTHON_VERSION = "4.25.0rc2" -PROTOBUF_PHP_VERSION = "3.25.0RC2" -PROTOBUF_RUBY_VERSION = "3.25.0.rc.2" +PROTOC_VERSION = "25.0" +PROTOBUF_JAVA_VERSION = "3.25.0" +PROTOBUF_PYTHON_VERSION = "4.25.0" +PROTOBUF_PHP_VERSION = "3.25.0" +PROTOBUF_RUBY_VERSION = "3.25.0" diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 09f7a3d8b6..522b7ed499 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -7,4 +7,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.25.0rc2' +__version__ = '4.25.0' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index ecfa8f97c3..e3770be416 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.25.0.rc.2" + s.version = "3.25.0" 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.summary = "Protocol Buffers" diff --git a/ruby/pom.xml b/ruby/pom.xml index 4f60d02c19..5cd8245c5a 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.25.0-RC2 + 3.25.0 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.25.0-RC2 + 3.25.0 org.jruby diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 89cb011789..13968ac3a8 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index a778c373bd..f55e3599f8 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 64297ead99..b0871acf90 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/java/java_features.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_2epb_2eh diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 459abfcbe8..574c172542 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/plugin.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh diff --git a/src/google/protobuf/compiler/versions_suffix.h b/src/google/protobuf/compiler/versions_suffix.h index 0210cb7dff..0c7a8d298a 100644 --- a/src/google/protobuf/compiler/versions_suffix.h +++ b/src/google/protobuf/compiler/versions_suffix.h @@ -21,6 +21,6 @@ // // Please avoid changing it manually, as they should be updated automatically by // the Protobuf release process. -#define PROTOBUF_GENCODE_VERSION_SUFFIX "-rc2" +#define PROTOBUF_GENCODE_VERSION_SUFFIX "" #endif // GOOGLE_PROTOBUF_COMPILER_VERSIONS_SUFFIX_H__ diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index 3898235022..8407117a38 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/cpp_features.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 560e66c459..36220fdc97 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/descriptor.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index a306db4f7a..3ed09becbb 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 91ef8c784b..f0a618d8e6 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index bb2ca71253..89c042c67b 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index a89add5912..4b1d2b46cd 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -219,7 +219,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined #endif -#define PROTOBUF_VERSION_SUFFIX "-rc2" +#define PROTOBUF_VERSION_SUFFIX "" #ifdef PROTOBUF_MINIMUM_EDITION #error PROTOBUF_MINIMUM_EDITION was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 066c0a45d6..9d35f1b2dd 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index e50cf53b32..ef2b036ff6 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index cfd72f171c..2a95199d54 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -47,7 +47,7 @@ namespace internal { #define GOOGLE_PROTOBUF_VERSION 4025000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. -#define GOOGLE_PROTOBUF_VERSION_SUFFIX "-rc2" +#define GOOGLE_PROTOBUF_VERSION_SUFFIX "" // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 0c513a27a9..9a65792520 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 362165804d..0ff5349da9 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 224ccd5c4a..b348b5d7c7 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -// Protobuf C++ Version: 4.25.0-rc2 +// Protobuf C++ Version: 4.25.0 #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh diff --git a/version.json b/version.json index 4263fdcd3a..098e086a5d 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "25.x": { - "protoc_version": "25.0-dev", + "protoc_version": "25.0", "lts": false, - "date": "2023-10-18", + "date": "2023-11-01", "languages": { - "cpp": "4.25.0-dev", - "csharp": "3.25.0-dev", - "java": "3.25.0-dev", - "javascript": "3.25.0-dev", - "objectivec": "3.25.0-dev", - "php": "3.25.0-dev", - "python": "4.25.0-dev", - "ruby": "3.25.0-dev" + "cpp": "4.25.0", + "csharp": "3.25.0", + "java": "3.25.0", + "javascript": "3.25.0", + "objectivec": "3.25.0", + "php": "3.25.0", + "python": "4.25.0", + "ruby": "3.25.0" } } } \ No newline at end of file From 7203caaae76f7a0fef892ece10aeae90959794db Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 1 Nov 2023 13:03:44 -0700 Subject: [PATCH 041/387] Updating version.json to: 25.1-dev --- version.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/version.json b/version.json index 098e086a5d..ba0cf35f44 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { "25.x": { - "protoc_version": "25.0", + "protoc_version": "25.1-dev", "lts": false, "date": "2023-11-01", "languages": { - "cpp": "4.25.0", - "csharp": "3.25.0", - "java": "3.25.0", - "javascript": "3.25.0", - "objectivec": "3.25.0", - "php": "3.25.0", - "python": "4.25.0", - "ruby": "3.25.0" + "cpp": "4.25.1-dev", + "csharp": "3.25.1-dev", + "java": "3.25.1-dev", + "javascript": "3.25.1-dev", + "objectivec": "3.25.1-dev", + "php": "3.25.1-dev", + "python": "4.25.1-dev", + "ruby": "3.25.1-dev" } } } \ No newline at end of file From b4c9546467563038a2db97ef268837cbcf110cd8 Mon Sep 17 00:00:00 2001 From: Cong Liu Date: Wed, 1 Nov 2023 15:11:35 -0700 Subject: [PATCH 042/387] Cluster non cold subtables in aux entries to the top. PiperOrigin-RevId: 578656159 --- src/google/protobuf/compiler/cpp/options.h | 1 + .../compiler/cpp/parse_function_generator.cc | 8 ++- .../protobuf/generated_message_reflection.cc | 1 + .../protobuf/generated_message_tctable_gen.cc | 50 ++++++++++++++++--- .../protobuf/generated_message_tctable_gen.h | 2 + src/google/protobuf/message_unittest.inc | 3 +- 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/options.h b/src/google/protobuf/compiler/cpp/options.h index 5ae95353fb..30be9c0bb2 100644 --- a/src/google/protobuf/compiler/cpp/options.h +++ b/src/google/protobuf/compiler/cpp/options.h @@ -54,6 +54,7 @@ struct Options { bool opensource_runtime = false; bool annotate_accessor = false; bool force_split = false; + bool profile_driven_cluster_aux_subtable = false; #ifdef PROTOBUF_STABLE_EXPERIMENTS bool force_eagerly_verified_lazy = true; bool force_inline_string = true; diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc index 6fb3aa85e3..a8074dfce7 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -116,11 +116,9 @@ ParseFunctionGenerator::ParseFunctionGenerator( if (should_generate_tctable()) { tc_table_info_.reset(new TailCallTableInfo( descriptor_, ordered_fields_, - { - /* is_lite */ GetOptimizeFor(descriptor->file(), options_) == - FileOptions::LITE_RUNTIME, - /* uses_codegen */ true, - }, + {/* is_lite */ GetOptimizeFor(descriptor->file(), options_) == + FileOptions::LITE_RUNTIME, + /* uses_codegen */ true, options_.profile_driven_cluster_aux_subtable}, GeneratedOptionProvider(this), has_bit_indices, inlined_string_indices)); } diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 84272163fe..a2e9c7cb83 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -3416,6 +3416,7 @@ const internal::TcParseTableBase* Reflection::CreateTcParseTable() const { { /* is_lite */ false, /* uses_codegen */ false, + /* should_profile_driven_cluster_aux_table */ false, }, ReflectionOptionProvider(*this), has_bit_indices, inlined_string_indices); diff --git a/src/google/protobuf/generated_message_tctable_gen.cc b/src/google/protobuf/generated_message_tctable_gen.cc index 7c1736d63e..6740e35b50 100644 --- a/src/google/protobuf/generated_message_tctable_gen.cc +++ b/src/google/protobuf/generated_message_tctable_gen.cc @@ -8,6 +8,7 @@ #include "google/protobuf/generated_message_tctable_gen.h" #include +#include #include #include #include @@ -756,6 +757,35 @@ TailCallTableInfo::TailCallTableInfo( } } + auto is_non_cold = [](PerFieldOptions options) { + return options.presence_probability >= 0.005; + }; + size_t num_non_cold_subtables = 0; + if (message_options.should_profile_driven_cluster_aux_subtable) { + // We found that clustering non-cold subtables to the top of aux_entries + // achieves the best load tests results than other strategies (e.g., + // clustering all non-cold entries). + auto is_non_cold_subtable = [&](const FieldDescriptor* field) { + auto options = option_provider.GetForField(field); + // In the following code where we assign kSubTable to aux entries, only + // the following typed fields are supported. + return (field->type() == FieldDescriptor::TYPE_MESSAGE || + field->type() == FieldDescriptor::TYPE_GROUP) && + !field->is_map() && !HasLazyRep(field, options) && + !options.is_implicitly_weak && options.use_direct_tcparser_table && + is_non_cold(options); + }; + for (const FieldDescriptor* field : ordered_fields) { + if (is_non_cold_subtable(field)) { + num_non_cold_subtables++; + } + } + } + + size_t subtable_aux_idx_begin = aux_entries.size(); + size_t subtable_aux_idx = aux_entries.size(); + aux_entries.resize(aux_entries.size() + num_non_cold_subtables); + // Fill in mini table entries. for (const FieldDescriptor* field : ordered_fields) { auto options = option_provider.GetForField(field); @@ -797,12 +827,18 @@ TailCallTableInfo::TailCallTableInfo( TcParseTableBase::FieldEntry::kNoAuxIdx; } } else { - field_entries.back().aux_idx = aux_entries.size(); - aux_entries.push_back({options.is_implicitly_weak ? kSubMessageWeak - : options.use_direct_tcparser_table - ? kSubTable - : kSubMessage, - {field}}); + AuxType type = options.is_implicitly_weak ? kSubMessageWeak + : options.use_direct_tcparser_table ? kSubTable + : kSubMessage; + if (message_options.should_profile_driven_cluster_aux_subtable && + type == kSubTable && is_non_cold(options)) { + aux_entries[subtable_aux_idx] = {type, {field}}; + field_entries.back().aux_idx = subtable_aux_idx; + ++subtable_aux_idx; + } else { + field_entries.back().aux_idx = aux_entries.size(); + aux_entries.push_back({type, {field}}); + } } } else if (field->type() == FieldDescriptor::TYPE_ENUM && !cpp::HasPreservingUnknownEnumSemantics(field)) { @@ -845,6 +881,8 @@ TailCallTableInfo::TailCallTableInfo( entry.inlined_string_idx = idx; } } + ABSL_CHECK_EQ(subtable_aux_idx - subtable_aux_idx_begin, + num_non_cold_subtables); table_size_log2 = 0; // fallback value int num_fast_fields = -1; diff --git a/src/google/protobuf/generated_message_tctable_gen.h b/src/google/protobuf/generated_message_tctable_gen.h index bf202712a4..514f590a57 100644 --- a/src/google/protobuf/generated_message_tctable_gen.h +++ b/src/google/protobuf/generated_message_tctable_gen.h @@ -38,6 +38,8 @@ struct PROTOBUF_EXPORT TailCallTableInfo { struct MessageOptions { bool is_lite; bool uses_codegen; + // TODO: remove this after A/B test is done. + bool should_profile_driven_cluster_aux_subtable; }; struct PerFieldOptions { // For presence awareness (e.g. PDProto). diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc index 4e07c69367..0dae9657fa 100644 --- a/src/google/protobuf/message_unittest.inc +++ b/src/google/protobuf/message_unittest.inc @@ -1937,9 +1937,10 @@ TEST(MESSAGE_TEST_NAME, TestRegressionInlinedStringAuxIdxMismatchOnFastParser) { if (table != nullptr && table->fast_entry(1)->target() == internal::TcParser::FastSiS1) { // optional string str1 = 1; + // The aux_idx points to the inlined_string_idx and not the actual aux_idx. EXPECT_EQ(table->fast_entry(1)->bits.aux_idx(), 1); // optional InlinedStringIdxRegressionProto sub = 2; - EXPECT_EQ(table->fast_entry(2)->bits.aux_idx(), 2); + EXPECT_EQ(table->fast_entry(2)->bits.aux_idx(), 1); // optional string str2 = 3; // The aux_idx points to the inlined_string_idx and not the actual aux_idx. EXPECT_EQ(table->fast_entry(3)->bits.aux_idx(), 2); From 769ab10e3b9f5b9ccf9a46c786091960812938c2 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 1 Nov 2023 16:18:47 -0700 Subject: [PATCH 043/387] Fix windows 2019 build. setup-gcloud doesn't honor the environment variables set by setup-python, so we need to manually set CLOUDSDK_PYTHON before running it. PiperOrigin-RevId: 578674246 --- .github/workflows/test_cpp.yml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test_cpp.yml b/.github/workflows/test_cpp.yml index 54b28006a9..55c061bc1b 100644 --- a/.github/workflows/test_cpp.yml +++ b/.github/workflows/test_cpp.yml @@ -366,6 +366,7 @@ jobs: -Dprotobuf_BUILD_EXAMPLES=ON vsversion: '2019' cache-prefix: windows-2019-cmake + # windows-2019 has python3.7 installed, which is incompatible with the latest gcloud python-version: '3.8' - name: Windows CMake 32-bit os: windows-2022 @@ -399,13 +400,6 @@ jobs: ref: ${{ inputs.safe-checkout }} submodules: recursive - - name: Install Python - if: ${{ matrix.python-version }} - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 - with: - python-version: ${{ matrix.python-version }} - cache: pip - - name: Setup MSVC if: ${{ runner.os == 'Windows' }} uses: ilammy/msvc-dev-cmd@cec98b9d092141f74527d0afa6feb2af698cfe89 # v1.12.1 @@ -413,6 +407,17 @@ jobs: arch: ${{ matrix.windows-arch || 'x64' }} vsversion: ${{ matrix.vsversion }} + # Workaround for incompatibility between gcloud and windows-2019 runners. + - name: Install Python + if: ${{ matrix.python-version }} + uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 + with: + python-version: ${{ matrix.python-version }} + - name: Use custom python for gcloud + if: ${{ matrix.python-version }} + run: echo "CLOUDSDK_PYTHON=${Python3_ROOT_DIR}\\python3" >> $GITHUB_ENV + shell: bash + - name: Setup sccache uses: protocolbuffers/protobuf-ci/sccache@v2 with: From 5f146f8dfefd136eb969ed3bb73bdd95a462c4f3 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 1 Nov 2023 22:17:29 -0700 Subject: [PATCH 044/387] Enable caching of pip dependencies PiperOrigin-RevId: 578740011 --- .github/workflows/test_python.yml | 1 + .github/workflows/test_upb.yml | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_python.yml b/.github/workflows/test_python.yml index e207ee3a92..0bec9a06c3 100644 --- a/.github/workflows/test_python.yml +++ b/.github/workflows/test_python.yml @@ -76,6 +76,7 @@ jobs: with: python-version: ${{ matrix.version }} cache: pip + cache-dependency-path: 'python/requirements.txt' - name: Validate version run: python3 --version | grep ${{ matrix.version }} || (echo "Invalid Python version - $(python3 --version)" && exit 1) diff --git a/.github/workflows/test_upb.yml b/.github/workflows/test_upb.yml index a8454bfe78..32b9ff8251 100644 --- a/.github/workflows/test_upb.yml +++ b/.github/workflows/test_upb.yml @@ -70,6 +70,10 @@ jobs: uses: protocolbuffers/protobuf-ci/checkout@v2 with: ref: ${{ inputs.safe-checkout }} + - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 + with: + cache: pip + cache-dependency-path: 'python/requirements.txt' - name: Run tests uses: protocolbuffers/protobuf-ci/bazel@v2 with: @@ -92,6 +96,10 @@ jobs: uses: protocolbuffers/protobuf-ci/checkout@v2 with: ref: ${{ inputs.safe-checkout }} + - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 + with: + cache: pip + cache-dependency-path: 'python/requirements.txt' - name: Run tests uses: protocolbuffers/protobuf-ci/bazel@v2 with: @@ -195,7 +203,7 @@ jobs: with: name: requirements path: requirements - - uses: actions/setup-python@v2 + - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 with: python-version: ${{ matrix.python-version }} architecture: ${{ matrix.architecture }} @@ -250,7 +258,7 @@ jobs: path: wheels - name: Delete Binary Wheels run: find wheels -type f | grep -v none-any | xargs rm - - uses: actions/setup-python@v2 + - uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0 with: python-version: ${{ matrix.python-version }} - name: Setup Python venv From 725b477032a9806d28cf7774d5504b7832f7c6ba Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 05:27:53 -0700 Subject: [PATCH 045/387] Adds "Editions: Feature Extension Layout" to the GitHub code repository. PiperOrigin-RevId: 578819110 --- docs/design/editions/README.md | 1 + .../editions-feature-extension-layout.md | 150 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 docs/design/editions/editions-feature-extension-layout.md diff --git a/docs/design/editions/README.md b/docs/design/editions/README.md index 483ce860c0..c551f91ab0 100644 --- a/docs/design/editions/README.md +++ b/docs/design/editions/README.md @@ -36,3 +36,4 @@ The following topics are in this repository: * [Edition Naming](edition-naming.md) * [Editions Feature Visibility](editions-feature-visibility.md) * [Legacy Syntax Editions](legacy-syntax-editions.md) +* [Editions: Feature Extension Layout](editions-feature-extension-layout.md) \ No newline at end of file diff --git a/docs/design/editions/editions-feature-extension-layout.md b/docs/design/editions/editions-feature-extension-layout.md new file mode 100644 index 0000000000..67626a4388 --- /dev/null +++ b/docs/design/editions/editions-feature-extension-layout.md @@ -0,0 +1,150 @@ +# Editions: Feature Extension Layout + +**Author:** [@mkruskal-google](https://github.com/mkruskal-google), +[@zhangskz](https://github.com/zhangskz) + +**Approved:** 2023-08-23 + +## Background + +"[What are Protobuf Editions](what-are-protobuf-editions.md)" lays out a plan +for allowing for more targeted features not owned by the protobuf team. It uses +extensions of the global features proto to implement this. One thing that was +left a bit ambiguous was *who* should own these extensions. Language, code +generator, and runtime implementations are all similar but not identical +distinctions. + +"Editions Zero Feature: utf8_validation" (not available externally, though a +later version, +"[Editions Zero: utf8_validation Without Problematic Options](editions-zero-utf8_validation.md)" +is) is a recent plan to add a new set of generator features for utf8 validation. +While the sole feature we had originally created (`legacy_closed_enum` in Java +and C++) didn't have any ambiguity here, this one did. Specifically in Python, +the current behaviors across proto2/proto3 are distinct for all 3 +implementations: pure python, Python/C++, Python/upb. + +## Overview + +In meetings, we've discussed various alternatives, captured below. The original +plan was to make feature extensions runtime implementation-specific (e.g. C++, +Java, Python, upb). There are some notable complications that came up though: + +1. **Polyglot** - it's not clear how upb or C++ runtimes should behave in + multi-language situations. Which feature sets do they consider for runtime + behaviors? *Note: this is already a serious issue today, where all proto2 + strings and many proto3 strings are completely unsafe across languages.* + +2. **Shared Implementations** - Runtimes like upb and C++ are used as backing + implementations of multiple other languages (e.g. Python, Rust, Ruby, PHP). + If we have a single set of `upb` or `cpp` features, migrating to those + shared implementations would be more difficult (since there's no independent + switches per-language). *Note: this is already the situation we're in today, + where switching the runtime implementation can cause subtle and dangerous + behavior changes.* + +Given that we only have two behaviors, and one of them is unambiguous, it seems +reasonable to punt on this decision until we have more information. We may +encounter more edge cases that require feature extensions (and give us more +information) during the rollout of edition zero. We also have a lot of freedom +to re-model features in later editions, so keeping the initial implementation as +simple as possible seems best (i.e. Alternative 2). + +## Alternatives + +### Alternative 1: Runtime Implementation Features + +Features would be per-runtime implementation as originally described in +"Editions Zero Feature: utf8_validation." For example, Protobuf Python users +would set different features depending on the backing implementation (e.g. +`features.(pb.cpp).`, `features.(pb.upb).`). + +#### Pros + +* Most consistent with range of behaviors expressible pre-Editions + +#### Cons + +* Implementation may / should not be obvious to users. +* Lack of levers specifically for language / implementation combos. For + example, there is no way to set Python-C++ behavior independently of C++ + behavior which may make migration harder from other Python implementations. + +### Alternative 2: Generator Features + +Features would be per-generator only (i.e. each protoc plugin would own one set +of features). This was the second decision we made in later discussions, and +while very similar to the above alternative, it's more inline with our goal of +making features primarily for codegen. + +For example, all Python implementations would share the same set of features +(e.g. `features.(pb.python).`). However, certain features could be +targeted to specific implementations (e.g. +`features.(pb.python).upb_utf8_validation` would only be used by Python/upb). + +#### Pros + +* Allows independent controls of shared implementations in different target + languages (e.g. Python's upb feature won't affect PHP). + +#### Cons + +* Possible complexity in upb to understand which language's features to + respect. UPB is not currently aware of what language it is being used for. +* Limits in-process sharing across languages with shared implementations (e.g. + Python upb, PHP upb) in the case of conflicting behaviors. + * Additional checks may be needed. + +### Alternative 3: Migrate to bytes + +Since this whole discussion revolves around the utf8 validation feature, one +option would be to just remove it from edition zero. Instead of adding a new +toggle for UTF8 behavior, we could simply migrate everyone who doesn't enforce +utf8 today to `bytes`. This would likely need another new *codegen* feature for +generating byte getters/setters as strings, but that wouldn't have any of the +ambiguity we're seeing today. + +Unfortunately, this doesn't seem feasible because of all the different behaviors +laid out in "Editions Zero Feature: utf8_validation." UTF8 validation isn't +really a binary on/off decision, and it can vary widely between languages. There +are many cases where UTF8 is validated in **some** languages but not others, and +there's also the C++ "hint" behavior that logs errors but allows invalid UTF8. + +**Note:** This could still be partially done in a follow-up LSC by targeting +specific combinations of the new feature that disable validation in all relevant +languages. + +#### Pros + +* Punts on the issue, we wouldn't need any upb features and C++ features would + all be code-gen only +* Simplifies the situation, avoids adding a very complicated feature in + edition zero + +#### Cons + +* Not really possible given the current complexity +* There are O(10M) proto2 string fields that would be blindly changed to bytes + +### Alternative 4: Nested Features + +Another option is to allow for shared feature set messages. For example, upb +would define a feature message, but *not* make it an extension of the global +`FeatureSet`. Instead, languages with upb implementations would have a field of +this type to allow for finer-grained controls. C++ would both extend the global +`FeatureSet` and also be allowed as a field in other languages. + +For example, python utf8 validation could be specified as: + +We could have checks during feature validation that enforce that impossible +combinations aren't specified. For example, with our current implementation +`features.(pb.python).cpp` should always be identical to `features.(pb.cpp)`, +since we don't have any mechanism for distinguishing them. + +#### Pros + +* Much more explicit than options 1 and 2 + +#### Cons + +* Maybe too explicit? Proto owners would be forced to duplicate a lot of + features From 7daa16947b01b9c82d90e7a33294a9ed0dcb4668 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 07:31:50 -0700 Subject: [PATCH 046/387] Emit a reason for why a field was unsupported. PiperOrigin-RevId: 578846947 --- .../rust/accessors/accessor_generator.h | 6 ++++++ .../compiler/rust/accessors/accessors.cc | 17 ++++++++++++----- .../rust/accessors/unsupported_field.cc | 4 ++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/accessor_generator.h b/src/google/protobuf/compiler/rust/accessors/accessor_generator.h index 3bf1dca06d..8b26d19dc8 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessor_generator.h +++ b/src/google/protobuf/compiler/rust/accessors/accessor_generator.h @@ -9,6 +9,8 @@ #define GOOGLE_PROTOBUF_COMPILER_RUST_ACCESSORS_ACCESSOR_GENERATOR_H__ #include +#include +#include #include "absl/log/absl_check.h" #include "google/protobuf/compiler/rust/context.h" @@ -96,8 +98,12 @@ class RepeatedScalar final : public AccessorGenerator { class UnsupportedField final : public AccessorGenerator { public: + explicit UnsupportedField(std::string reason) : reason_(std::move(reason)) {} ~UnsupportedField() override = default; void InMsgImpl(Context field) const override; + + private: + std::string reason_; }; } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index 807eb478b3..e963e9e075 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -9,6 +9,7 @@ #include +#include "absl/log/absl_log.h" #include "google/protobuf/compiler/rust/accessors/accessor_generator.h" #include "google/protobuf/compiler/rust/context.h" #include "google/protobuf/descriptor.h" @@ -26,7 +27,8 @@ std::unique_ptr AccessorGeneratorFor( // TODO: We do not support [ctype=FOO] (used to set the field // type in C++ to cord or string_piece) in V0.6 API. if (desc.options().has_ctype()) { - return std::make_unique(); + return std::make_unique( + "fields with ctype not supported"); } switch (desc.type()) { @@ -50,18 +52,23 @@ std::unique_ptr AccessorGeneratorFor( case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_STRING: if (desc.is_repeated()) { - return std::make_unique(); + return std::make_unique("repeated str not supported"); } return std::make_unique(); case FieldDescriptor::TYPE_MESSAGE: if (desc.is_repeated()) { - return std::make_unique(); + return std::make_unique("repeated msg not supported"); } return std::make_unique(); - default: - return std::make_unique(); + case FieldDescriptor::TYPE_ENUM: + return std::make_unique("enum not supported"); + + case FieldDescriptor::TYPE_GROUP: + return std::make_unique("group not supported"); } + + ABSL_LOG(FATAL) << "Unexpected field type: " << desc.type(); } } // namespace diff --git a/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc b/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc index ad0a98901c..e6bce02171 100644 --- a/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc +++ b/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc @@ -16,8 +16,8 @@ namespace compiler { namespace rust { void UnsupportedField::InMsgImpl(Context field) const { - field.Emit(R"rs( - // Unsupported! :( + field.Emit({{"reason", reason_}}, R"rs( + // Unsupported! :( Reason: $reason$ )rs"); field.printer().PrintRaw("\n"); } From 9a610f02f8a50395852033a5f1f28084cfa29841 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 2 Nov 2023 09:08:56 -0700 Subject: [PATCH 047/387] upb: delete unused function in the C code generator PiperOrigin-RevId: 578873644 --- upb_generator/protoc-gen-upb.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index 7678f99a62..dac5bd6383 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -835,15 +835,6 @@ void GenerateMessageInHeader(upb::MessageDefPtr message, output("\n"); } -void ForwardDeclareMiniTableInit(upb::MessageDefPtr message, - const Options& options, Output& output) { - if (options.bootstrap) { - output("extern const upb_MiniTable* $0();\n", MessageInitName(message)); - } else { - output("extern const upb_MiniTable $0;\n", MessageInitName(message)); - } -} - std::vector SortedForwardMessages( const std::vector& this_file_messages, const std::vector& this_file_exts) { From f78f9c51fa2470070e5d4b49649800971c789224 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 09:13:31 -0700 Subject: [PATCH 048/387] Workaround false positive warning in MSVC. Fixes https://github.com/protocolbuffers/protobuf/issues/14602 PiperOrigin-RevId: 578875053 --- src/google/protobuf/map_field.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index 8aa9e45fe3..8388f8a2e5 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -678,7 +678,7 @@ class MapField final : public TypeDefinedMapFieldBase { template -constexpr MapFieldBase::VTable +PROTOBUF_CONSTINIT const MapFieldBase::VTable MapField::kVTable = MapField::template MakeVTable(); From 76305620a173d1428c5a00c7c50826c8c6dbc389 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 2 Nov 2023 10:40:33 -0700 Subject: [PATCH 049/387] Add a job to the janitor GHA to annotate any issues/PRs that have been inactive for the past 90 days with the `inactive` label (which has been added to github). The job will then close an issue if it has been marked inactive for 14 days. Most of this is taken from https://github.com/carbon-language/carbon-lang/blob/trunk/.github/workflows/stale.yaml with a few adjustments, most importantly allowing the bot to auto-close issues. PiperOrigin-RevId: 578906074 --- .github/workflows/janitor.yml | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/.github/workflows/janitor.yml b/.github/workflows/janitor.yml index e6dcc06979..992d4b7113 100644 --- a/.github/workflows/janitor.yml +++ b/.github/workflows/janitor.yml @@ -28,3 +28,47 @@ jobs: echo "Closing #$pr..." gh pr close --comment "Auto-closing Copybara pull request" --delete-branch "$pr" done + + stale-others: + name: Close stale non-copybara PRs and issues + runs-on: ubuntu-latest + steps: + - uses: actions/stale@b69b346013879cedbf50c69f572cd85439a41936 + with: + stale-issue-message: > + We triage inactive PRs and issues in order to make it easier to find + active work. If this issue should remain active or becomes active + again, please add a comment. + + + This issue is labeled `inactive` because the last activity was over + 90 days ago. + close-pr-message: > + We triage inactive PRs and issues in order to make it easier to find + active work. If this issue should remain active or becomes active + again, please reopen it. + + + This issue was closed and archived because there has been no new + activity in the 14 days since the `inactive` label was added. + stale-pr-message: > + We triage inactive PRs and issues in order to make it easier to find + active work. If this PR should remain active, please add a comment. + + + This PR is labeled `inactive` because the last activity was over 90 + days ago. This PR will be closed and archived after 14 additional + days without activity. + close-pr-message: > + We triage inactive PRs and issues in order to make it easier to find + active work. If this PR should remain active or becomes active + again, please reopen it. + + + This PR was closed and archived because there has been no new + activity in the 14 days since the `inactive` label was added. + stale-issue-label: 'inactive' + stale-pr-label: 'inactive' + days-before-stale: 90 + days-before-close: 14 + operations-per-run: 100 From 520e5dde64f46fe1363383e157c8a2e63b930ad6 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 11:14:18 -0700 Subject: [PATCH 050/387] keep -main in versions_suffix.h to merge back to main --- src/google/protobuf/compiler/versions_suffix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/versions_suffix.h b/src/google/protobuf/compiler/versions_suffix.h index 0c7a8d298a..5fd30faf0d 100644 --- a/src/google/protobuf/compiler/versions_suffix.h +++ b/src/google/protobuf/compiler/versions_suffix.h @@ -21,6 +21,6 @@ // // Please avoid changing it manually, as they should be updated automatically by // the Protobuf release process. -#define PROTOBUF_GENCODE_VERSION_SUFFIX "" +#define PROTOBUF_GENCODE_VERSION_SUFFIX "-main" #endif // GOOGLE_PROTOBUF_COMPILER_VERSIONS_SUFFIX_H__ From 3718338bdcac9a609ce44c6899cdb850fcc3090b Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Thu, 2 Nov 2023 11:12:33 -0700 Subject: [PATCH 051/387] Pin python at 3.11. Github changed their mac runners to use 3.12 by default, which removed setuptools and is causing breakages in some of our tests. PiperOrigin-RevId: 578917538 --- .github/workflows/test_upb.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test_upb.yml b/.github/workflows/test_upb.yml index 32b9ff8251..aa56ce3929 100644 --- a/.github/workflows/test_upb.yml +++ b/.github/workflows/test_upb.yml @@ -100,6 +100,7 @@ jobs: with: cache: pip cache-dependency-path: 'python/requirements.txt' + python-version: '3.11' # 3.12 doesn't have setuptools - name: Run tests uses: protocolbuffers/protobuf-ci/bazel@v2 with: From 0d331fd5eaaf67217881e7c5dbac9881a00d4f00 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Thu, 2 Nov 2023 11:56:57 -0700 Subject: [PATCH 052/387] Simplify ImmutableMessageLiteGenerator::GenerateStaticVariableInitializers method which doesn't actually generate any code or do anything for Java Lite. PiperOrigin-RevId: 578933051 --- .../protobuf/compiler/java/message_lite.cc | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index 587f2ccf91..6ae00b934c 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -69,25 +69,13 @@ ImmutableMessageLiteGenerator::~ImmutableMessageLiteGenerator() {} void ImmutableMessageLiteGenerator::GenerateStaticVariables( io::Printer* printer, int* bytecode_estimate) { - // Generate static members for all nested types. - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - // TODO: Reuse MessageGenerator objects? - ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) - .GenerateStaticVariables(printer, bytecode_estimate); - } + // No-op for lite. } int ImmutableMessageLiteGenerator::GenerateStaticVariableInitializers( io::Printer* printer) { - int bytecode_estimate = 0; - // Generate static member initializers for all nested types. - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - // TODO: Reuse MessageGenerator objects? - bytecode_estimate += - ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_) - .GenerateStaticVariableInitializers(printer); - } - return bytecode_estimate; + // No-op for lite. + return 0; } // =================================================================== From 19e5c874d2a138f39c1b6839f08c98de62b039e3 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:12:25 -0700 Subject: [PATCH 053/387] Update any.pb.h --- src/google/protobuf/any.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 71713fbe8f..403d2d3881 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh From c794a49e4e7e38b8e918c03c65b17cbf3af49b27 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:12:57 -0700 Subject: [PATCH 054/387] Update api.pb.h --- src/google/protobuf/api.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 74bd6c5059..e7d0138d43 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh From dabf64631f02c50aa5d4098da0c5a0bfdb4369de Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:13:13 -0700 Subject: [PATCH 055/387] Update java_features.pb.h --- src/google/protobuf/compiler/java/java_features.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index f5f8b7d641..d20b7bc65b 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/java/java_features.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_2epb_2eh From ef724068415371c01183c3e8201672ad988d0ecb Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:13:29 -0700 Subject: [PATCH 056/387] Update plugin.pb.h --- src/google/protobuf/compiler/plugin.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 8d47638d3d..8f57f03f66 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/plugin.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh From 687e14ee5275a1ffc699756cf22b85167d596551 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:13:47 -0700 Subject: [PATCH 057/387] Update cpp_features.pb.h --- src/google/protobuf/cpp_features.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index 01d610cdf1..3d64e16a0b 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/cpp_features.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh From 9dc3e44cd4b1f1a99c02de35fe140eebe5026c55 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:14:05 -0700 Subject: [PATCH 058/387] Update descriptor.pb.h --- src/google/protobuf/descriptor.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index d69623bb21..4008b86a31 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/descriptor.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh From a85d8a28d5de172cbd48c81001ac34edcb55d5e8 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:14:19 -0700 Subject: [PATCH 059/387] Update duration.pb.h --- src/google/protobuf/duration.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 44d9a0886e..827704521d 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh From 93bdf84ccde09b4d793e6fa1ba952b1112200635 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:14:33 -0700 Subject: [PATCH 060/387] Update empty.pb.h --- src/google/protobuf/empty.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index f0a618d8e6..d3698d1416 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh From e2e8f4e58c859ac7b7573899d3ee208d24bcc70e Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:15:03 -0700 Subject: [PATCH 061/387] Update field_mask.pb.h --- src/google/protobuf/field_mask.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 2c9f72726f..d62491a9e5 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh From cbe61a4965bdcca95c07aa52182df2bbe85992da Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:15:21 -0700 Subject: [PATCH 062/387] Update source_context.pb.h --- src/google/protobuf/source_context.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index fcfd373ae9..4e924b1df1 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh From 7a04bbd3a37d917026345377f6e955e4765f28d1 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:15:37 -0700 Subject: [PATCH 063/387] Update struct.pb.h --- src/google/protobuf/struct.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 5fdf8c0578..b8f8237e6e 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh From a874b1e0d83a62d902d10aed4ad66be5b452b05e Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:15:57 -0700 Subject: [PATCH 064/387] Update timestamp.pb.h --- src/google/protobuf/timestamp.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 6c3d37a117..80e4f9dca5 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh From 08b371e89a981cc87d89f3570902a14a7e4752c6 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:16:12 -0700 Subject: [PATCH 065/387] Update type.pb.h --- src/google/protobuf/type.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index beda8737f8..c612685352 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh From ac86c5ef32da07fe624428806beabab3bcc1ea0e Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 12:16:27 -0700 Subject: [PATCH 066/387] Update wrappers.pb.h --- src/google/protobuf/wrappers.pb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 0973c4d940..405104a99e 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -// Protobuf C++ Version: 4.25.0 +// Protobuf C++ Version: 4.25.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh From 3ea774370aedab4ef132e8b6b3c59c8ade56094b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 12:34:51 -0700 Subject: [PATCH 067/387] Internal change PiperOrigin-RevId: 578944754 --- CMakeLists.txt | 2 +- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 2 +- java/README.md | 6 +++--- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/kotlin-lite/pom.xml | 2 +- java/kotlin/pom.xml | 2 +- java/lite.md | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/protoc/pom.xml | 2 +- java/util/pom.xml | 2 +- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 10 +++++----- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 ++-- src/google/protobuf/compiler/java/java_features.pb.h | 6 +++--- src/google/protobuf/compiler/plugin.pb.h | 6 +++--- src/google/protobuf/compiler/versions.h | 6 +++--- src/google/protobuf/cpp_features.pb.h | 6 +++--- src/google/protobuf/descriptor.pb.h | 6 +++--- src/google/protobuf/port_def.inc | 8 ++++---- src/google/protobuf/stubs/common.h | 8 ++++---- version.json | 2 +- 28 files changed, 51 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f78fccc27a..ac0d03c3aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ if (protobuf_BUILD_SHARED_LIBS) endif () # Version metadata -set(protobuf_VERSION_STRING "4.25.0") +set(protobuf_VERSION_STRING "4.24.0") set(protobuf_DESCRIPTION "Protocol Buffers") set(protobuf_CONTACT "protobuf@googlegroups.com") diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index f2b9f35535..f472aa5f1b 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '4.25.0' + s.version = '4.24.0' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' diff --git a/Protobuf.podspec b/Protobuf.podspec index 0e4a664d6f..539394e629 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.25.0' + s.version = '3.24.0' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index bd9a3b66db..2a0cf99af8 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.25.0 + 3.24.0 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index b5731cdebb..dede331228 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -5,7 +5,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.25.0 + 3.24.0 10.0 Google Inc. netstandard1.1;netstandard2.0;net45;net50 diff --git a/java/README.md b/java/README.md index f6dab2654d..fb80b05f27 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.25.0 + 3.24.0 ``` @@ -37,14 +37,14 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.25.0 + 3.24.0 ``` ### Gradle If you are using Gradle, add the following to your `build.gradle` file's -dependencies: `implementation 'com.google.protobuf:protobuf-java:3.25.0'` Again, +dependencies: `implementation 'com.google.protobuf:protobuf-java:3.24.0'` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 411c501fa7..372dcdfda0 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.25.0 + 3.24.0 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index c98d168792..84d674094e 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0 + 3.24.0 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index bc4fb9ef7c..254eb8281b 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0 + 3.24.0 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 3d26d8a311..354e65494c 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0 + 3.24.0 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index fbaf1c8ed4..d8201e0468 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.25.0 + 3.24.0 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 3f9e3897bf..3b4ff82583 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0 + 3.24.0 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 9e0a6992c0..1deeca92a8 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0 + 3.24.0 pom Protocol Buffers [Parent] diff --git a/java/protoc/pom.xml b/java/protoc/pom.xml index 34f8579c8b..eec6f636e7 100644 --- a/java/protoc/pom.xml +++ b/java/protoc/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.25.0 + 3.24.0 pom Protobuf Compiler diff --git a/java/util/pom.xml b/java/util/pom.xml index f25581be84..f5c6380899 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.25.0 + 3.24.0 protobuf-java-util diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 4fab47f357..d24a5328e9 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -32,7 +32,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.25.0" +#define PHP_PROTOBUF_VERSION "3.24.0" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protobuf_version.bzl b/protobuf_version.bzl index a122dc377f..e428407720 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,6 +1,6 @@ """ Contains version numbers to be used in other bzl files """ -PROTOC_VERSION = "25.0" -PROTOBUF_JAVA_VERSION = "3.25.0" -PROTOBUF_PYTHON_VERSION = "4.25.0" -PROTOBUF_PHP_VERSION = "3.25.0" -PROTOBUF_RUBY_VERSION = "3.25.0" +PROTOC_VERSION = "24.0" +PROTOBUF_JAVA_VERSION = "3.24.0" +PROTOBUF_PYTHON_VERSION = "4.24.0" +PROTOBUF_PHP_VERSION = "3.24.0" +PROTOBUF_RUBY_VERSION = "3.24.0" diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 522b7ed499..45a6c20c59 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -7,4 +7,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.25.0' +__version__ = '4.24.0' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index e3770be416..8a292af288 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.25.0" + s.version = "3.24.0" 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.summary = "Protocol Buffers" diff --git a/ruby/pom.xml b/ruby/pom.xml index 5cd8245c5a..2242464e23 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.25.0 + 3.24.0 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.25.0 + 3.24.0 org.jruby diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index d20b7bc65b..1a0c7bba2e 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/java/java_features.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 8f57f03f66..eb3da21003 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/plugin.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/compiler/versions.h b/src/google/protobuf/compiler/versions.h index 1dc25ce58a..615944f8be 100644 --- a/src/google/protobuf/compiler/versions.h +++ b/src/google/protobuf/compiler/versions.h @@ -46,8 +46,8 @@ // // Please avoid changing them manually, as they should be updated automatically // by Protobuf release process. -#define PROTOBUF_CPP_VERSION_STRING "4.25.0" PROTOBUF_GENCODE_VERSION_SUFFIX -#define PROTOBUF_JAVA_VERSION_STRING "3.25.0" PROTOBUF_GENCODE_VERSION_SUFFIX -#define PROTOBUF_PYTHON_VERSION_STRING "4.25.0" PROTOBUF_GENCODE_VERSION_SUFFIX +#define PROTOBUF_CPP_VERSION_STRING "4.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX +#define PROTOBUF_JAVA_VERSION_STRING "3.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX +#define PROTOBUF_PYTHON_VERSION_STRING "4.24.0" PROTOBUF_GENCODE_VERSION_SUFFIX #endif // GOOGLE_PROTOBUF_VERSIONS_H__ diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index 3d64e16a0b..3b470431e3 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/cpp_features.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcpp_5ffeatures_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 4008b86a31..ea38e1f3d0 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/descriptor.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 21f21bd57a..86ed3ea7d7 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -204,17 +204,17 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 4025000 +#define PROTOBUF_VERSION 4024000 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined #endif -#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 4025000 +#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 4024000 #ifdef PROTOBUF_MIN_PROTOC_VERSION #error PROTOBUF_MIN_PROTOC_VERSION was previously defined #endif -#define PROTOBUF_MIN_PROTOC_VERSION 4025000 +#define PROTOBUF_MIN_PROTOC_VERSION 4024000 #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined @@ -330,7 +330,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 4025000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 4024000 #ifdef PROTOBUF_RTTI #error PROTOBUF_RTTI was previously defined diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 2a95199d54..5eb0df4c02 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -44,7 +44,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 4025000 +#define GOOGLE_PROTOBUF_VERSION 4024000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" @@ -52,15 +52,15 @@ namespace internal { // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 4025000; +static const int kMinHeaderVersionForLibrary = 4024000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 4025000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 4024000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 4025000; +static const int kMinHeaderVersionForProtoc = 4024000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. diff --git a/version.json b/version.json index fb4e0df57b..5c98fc209d 100644 --- a/version.json +++ b/version.json @@ -2,7 +2,7 @@ "main": { "protoc_version": "26-dev", "lts": false, - "date": "2023-11-01", + "date": "2023-10-16", "languages": { "cpp": "4.26-dev", "csharp": "3.26-dev", From 9b0e9d50afb65a510df8a9e744465a822da1b5e1 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Thu, 2 Nov 2023 13:32:10 -0700 Subject: [PATCH 068/387] Automated rollback of commit 108a4a30942f81e8f8cc376e354f657141fa3594. PiperOrigin-RevId: 578962175 --- .github/workflows/staleness_check.yml | 1 + .github/workflows/staleness_refresh.yml | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/staleness_check.yml b/.github/workflows/staleness_check.yml index 2669821443..77a5e21f2c 100644 --- a/.github/workflows/staleness_check.yml +++ b/.github/workflows/staleness_check.yml @@ -54,6 +54,7 @@ jobs: credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: staleness bash: > + set -ex; if [[ -z $COMMIT_TRIGGERED_RUN || -z $MAIN_RUN ]]; then bazel query 'attr(tags, "staleness_test", //...)' | xargs bazel test $BAZEL_FLAGS || echo "Please run ./regenerate_stale_files.sh to regenerate stale files"; diff --git a/.github/workflows/staleness_refresh.yml b/.github/workflows/staleness_refresh.yml index 6f6b5ac4b5..11af94b9b6 100644 --- a/.github/workflows/staleness_refresh.yml +++ b/.github/workflows/staleness_refresh.yml @@ -30,10 +30,6 @@ jobs: # failing then you may need to generate a fresh token. token: ${{ secrets.BOT_ACCESS_TOKEN }} - name: Configure name and email address in Git - run: git config user.name "Protobuf Team Bot" && git config user.email "protobuf-team-bot@google.com" + run: cd ${{ github.workspace }} && git config user.name "Protobuf Team Bot" && git config user.email "protobuf-team-bot@google.com" - name: Commit and push update - uses: protocolbuffers/protobuf-ci/bazel@v2 - with: - credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} - bazel-cache: staleness - bash: ci/push_auto_update.sh + run: cd ${{ github.workspace }} && ./ci/push_auto_update.sh From f98f38bb20abea6a3847170697d4856f33d67e10 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 20:52:31 +0000 Subject: [PATCH 069/387] Auto-generate files after cl/578962175 --- php/ext/google/protobuf/php-upb.h | 3 +-- src/file_lists.cmake | 2 ++ src/google/protobuf/any.pb.h | 6 +++--- src/google/protobuf/api.pb.h | 6 +++--- src/google/protobuf/duration.pb.h | 6 +++--- src/google/protobuf/empty.pb.h | 6 +++--- src/google/protobuf/field_mask.pb.h | 6 +++--- src/google/protobuf/source_context.pb.h | 6 +++--- src/google/protobuf/struct.pb.h | 6 +++--- src/google/protobuf/timestamp.pb.h | 6 +++--- src/google/protobuf/type.pb.h | 6 +++--- src/google/protobuf/wrappers.pb.h | 6 +++--- upb/cmake/CMakeLists.txt | 13 ------------- 13 files changed, 33 insertions(+), 45 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index b0621443ed..53562dcd4f 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -10735,12 +10735,11 @@ bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, #endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */ + #ifdef __cplusplus extern "C" { #endif - - extern _upb_DefPool_Init google_protobuf_descriptor_proto_upbdefinit; UPB_INLINE const upb_MessageDef *google_protobuf_FileDescriptorSet_getmsgdef(upb_DefPool *s) { diff --git a/src/file_lists.cmake b/src/file_lists.cmake index e4718cf8a3..4f5b4855e0 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -117,6 +117,7 @@ set(libprotobuf_hdrs ${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_legacy.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_lite.h ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_visitor.h ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.h ${protobuf_SOURCE_DIR}/src/google/protobuf/endian.h @@ -242,6 +243,7 @@ set(libprotobuf_lite_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_cleanup.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.h ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_lite.h ${protobuf_SOURCE_DIR}/src/google/protobuf/endian.h ${protobuf_SOURCE_DIR}/src/google/protobuf/explicitly_constructed.h ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.h diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 403d2d3881..f6eecf8cd5 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index e7d0138d43..08d2f8addf 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 827704521d..3a7539d2a3 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index d3698d1416..f66a7258ec 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index d62491a9e5..e4d6dca8a2 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 4e924b1df1..ed58fe7fcf 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index b8f8237e6e..6f9c7d176e 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 80e4f9dca5..8c1d97196e 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index c612685352..489cbdd116 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 405104a99e..78d3c718f1 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -1,6 +1,6 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -// Protobuf C++ Version: 4.25.0-main +// Protobuf C++ Version: 4.24.0-main #ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh #define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 +#if PROTOBUF_VERSION < 4024000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/upb/cmake/CMakeLists.txt b/upb/cmake/CMakeLists.txt index 3ebe257806..f78faee6f8 100644 --- a/upb/cmake/CMakeLists.txt +++ b/upb/cmake/CMakeLists.txt @@ -110,17 +110,4 @@ target_include_directories(generated_cpp_support__only_for_generated_code_do_not $ ) -add_library(generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE - -) -target_include_directories(generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE - $ - $ - $ -) -target_link_libraries(generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE - mem - mini_descriptor - reflection_internal) - From da7245ca0b320205bd53bc578e3c57379e75f2a6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 13:53:44 -0700 Subject: [PATCH 070/387] Add an explicit self-reference `local_repository` To keep the build working on Bazel 7. See https://github.com/bazelbuild/bazel/issues/19973#issuecomment-1787814450 for more info. PiperOrigin-RevId: 578968403 --- WORKSPACE | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WORKSPACE b/WORKSPACE index 37994f8c06..487c9334fc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,5 +1,10 @@ workspace(name = "com_google_protobuf") +# An explicit self-reference to work around changes in Bazel 7.0 +# See https://github.com/bazelbuild/bazel/issues/19973#issuecomment-1787814450 +# buildifier: disable=duplicated-name +local_repository(name = "com_google_protobuf", path = ".") + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") local_repository( From 1c549200ffb09659354845e8c60cb686bd8949fd Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 14:39:41 -0700 Subject: [PATCH 071/387] Use Emit instead of format for extension code gen. PiperOrigin-RevId: 578983008 --- src/google/protobuf/compiler/cpp/extension.cc | 204 +++++++++++------- src/google/protobuf/compiler/cpp/extension.h | 4 +- .../compiler/java/java_features.pb.cc | 8 +- .../protobuf/compiler/java/java_features.pb.h | 7 +- src/google/protobuf/cpp_features.pb.cc | 10 +- src/google/protobuf/cpp_features.pb.h | 7 +- 6 files changed, 143 insertions(+), 97 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/extension.cc b/src/google/protobuf/compiler/cpp/extension.cc index fcb6f747d1..361d2cc5a4 100644 --- a/src/google/protobuf/compiler/cpp/extension.cc +++ b/src/google/protobuf/compiler/cpp/extension.cc @@ -11,9 +11,12 @@ #include "google/protobuf/compiler/cpp/extension.h" +#include + #include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" #include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/cpp/options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/io/printer.h" @@ -77,97 +80,134 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, variables_["scope"] = scope; variables_["scoped_name"] = ExtensionName(descriptor_); variables_["number"] = absl::StrCat(descriptor_->number()); - - bool add_verify_fn = - // Only verify msgs. - descriptor_->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && - // Options say to verify. - ShouldVerify(descriptor_->message_type(), options_, scc_analyzer_) && - ShouldVerify(descriptor_->containing_type(), options_, scc_analyzer_); - - variables_["verify_fn"] = - add_verify_fn - ? absl::StrCat("&", FieldMessageTypeName(descriptor_, options_), - "::InternalVerify") - : "nullptr"; } -ExtensionGenerator::~ExtensionGenerator() {} +ExtensionGenerator::~ExtensionGenerator() = default; bool ExtensionGenerator::IsScoped() const { return descriptor_->extension_scope() != nullptr; } -void ExtensionGenerator::GenerateDeclaration(io::Printer* printer) const { - Formatter format(printer, variables_); - - // If this is a class member, it needs to be declared "static". Otherwise, - // it needs to be "extern". In the latter case, it also needs the DLL - // export/import specifier. - std::string qualifier; - if (!IsScoped()) { - qualifier = "extern"; - if (!options_.dllexport_decl.empty()) { - qualifier = absl::StrCat(options_.dllexport_decl, " ", qualifier); - } - } else { - qualifier = "static"; - } - - format( - "static const int $constant_name$ = $number$;\n" - "$1$ ::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n" - " ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$ >\n" - " ${2$$name$$}$;\n", - qualifier, descriptor_); +void ExtensionGenerator::GenerateDeclaration(io::Printer* p) const { + auto var = p->WithVars(variables_); + auto annotate = p->WithAnnotations({{"name", descriptor_}}); + + p->Emit({{"qualifier", + // If this is a class member, it needs to be declared "static". + // Otherwise, it needs to be "extern". In the latter case, it + // also needs the DLL export/import specifier. + IsScoped() ? "static" + : options_.dllexport_decl.empty() + ? "extern" + : absl::StrCat(options_.dllexport_decl, " extern")}}, + R"cc( + static const int $constant_name$ = $number$; + $qualifier$ ::$proto_ns$::internal::ExtensionIdentifier< + $extendee$, ::$proto_ns$::internal::$type_traits$, $field_type$, + $packed$> + $name$; + )cc"); } -void ExtensionGenerator::GenerateDefinition(io::Printer* printer) { - Formatter format(printer, variables_); - std::string default_str; - // If this is a class member, it needs to be declared in its class scope. - if (descriptor_->cpp_type() == FieldDescriptor::CPPTYPE_STRING) { - // We need to declare a global string which will contain the default value. - // We cannot declare it at class scope because that would require exposing - // it in the header which would be annoying for other reasons. So we - // replace :: with _ in the name and declare it as a global. - default_str = - absl::StrReplaceAll(variables_["scoped_name"], {{"::", "_"}}) + - "_default"; - format("const std::string $1$($2$);\n", default_str, - DefaultValue(options_, descriptor_)); - } else if (descriptor_->message_type()) { - // We have to initialize the default instance for extensions at registration - // time. - default_str = absl::StrCat(FieldMessageTypeName(descriptor_, options_), - "::default_instance()"); - } else { - default_str = DefaultValue(options_, descriptor_); - } - - // Likewise, class members need to declare the field constant variable. - if (IsScoped()) { - format( - "#if !defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)\n" - "const int $scope$$constant_name$;\n" - "#endif\n"); - } - - if (IsLazilyInitializedFile(descriptor_->file()->name())) { - format( - "PROTOBUF_CONSTINIT$ dllexport_decl$ " - "PROTOBUF_ATTRIBUTE_INIT_PRIORITY2\n" - "::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n" - " ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$>\n" - " $scoped_name$($constant_name$);\n"); - } else { - format( - "$dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 " - "::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n" - " ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$>\n" - " $scoped_name$($constant_name$, $1$, $verify_fn$);\n", - default_str); - } +void ExtensionGenerator::GenerateDefinition(io::Printer* p) { + auto vars = p->WithVars(variables_); + auto generate_default_string = [&] { + if (descriptor_->cpp_type() == FieldDescriptor::CPPTYPE_STRING) { + // We need to declare a global string which will contain the default + // value. We cannot declare it at class scope because that would require + // exposing it in the header which would be annoying for other reasons. So + // we replace :: with _ in the name and declare it as a global. + return absl::StrReplaceAll(variables_["scoped_name"], {{"::", "_"}}) + + "_default"; + } else if (descriptor_->message_type()) { + // We have to initialize the default instance for extensions at + // registration time. + return absl::StrCat(FieldMessageTypeName(descriptor_, options_), + "::default_instance()"); + } else { + return DefaultValue(options_, descriptor_); + } + }; + + auto local_var = p->WithVars({ + {"default_str", generate_default_string()}, + {"default_val", DefaultValue(options_, descriptor_)}, + {"message_type", descriptor_->message_type() != nullptr + ? FieldMessageTypeName(descriptor_, options_) + : ""}, + }); + p->Emit( + { + {"declare_default_str", + [&] { + if (descriptor_->cpp_type() != FieldDescriptor::CPPTYPE_STRING) + return; + + // If this is a class member, it needs to be declared in its class + // scope. + p->Emit(R"cc( + const std::string $default_str$($default_val$); + )cc"); + }}, + {"declare_const_var", + [&] { + if (!IsScoped()) return; + // Likewise, class members need to declare the field constant + // variable. + p->Emit(R"cc( +#if !defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912) + const int $scope$$constant_name$; +#endif + )cc"); + }}, + {"define_extension_id", + [&] { + if (IsLazilyInitializedFile(descriptor_->file()->name())) { + p->Emit(R"cc( + PROTOBUF_CONSTINIT$ dllexport_decl$ + PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::$proto_ns$::internal:: + ExtensionIdentifier< + $extendee$, ::$proto_ns$::internal::$type_traits$, + $field_type$, $packed$> + $scoped_name$($constant_name$); + )cc"); + return; + } + + bool should_verify = + // Only verify msgs. + descriptor_->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && + // Options say to verify. + ShouldVerify(descriptor_->message_type(), options_, + scc_analyzer_) && + ShouldVerify(descriptor_->containing_type(), options_, + scc_analyzer_); + + if (should_verify) { + p->Emit(R"cc( + $dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 :: + $proto_ns$::internal::ExtensionIdentifier< + $extendee$, ::$proto_ns$::internal::$type_traits$, + $field_type$, $packed$> + $scoped_name$($constant_name$, $default_str$, + &$message_type$::InternalVerify); + )cc"); + } else { + p->Emit(R"cc( + $dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 :: + $proto_ns$::internal::ExtensionIdentifier< + $extendee$, ::$proto_ns$::internal::$type_traits$, + $field_type$, $packed$> + $scoped_name$($constant_name$, $default_str$, nullptr); + )cc"); + } + }}, + }, + R"cc( + $declare_default_str$; + $declare_const_var$; + $define_extension_id$; + )cc"); } } // namespace cpp diff --git a/src/google/protobuf/compiler/cpp/extension.h b/src/google/protobuf/compiler/cpp/extension.h index 406bb634bc..aab3b64b3e 100644 --- a/src/google/protobuf/compiler/cpp/extension.h +++ b/src/google/protobuf/compiler/cpp/extension.h @@ -51,10 +51,10 @@ class PROTOC_EXPORT ExtensionGenerator { ~ExtensionGenerator(); // Header stuff. - void GenerateDeclaration(io::Printer* printer) const; + void GenerateDeclaration(io::Printer* p) const; // Source file stuff. - void GenerateDefinition(io::Printer* printer); + void GenerateDefinition(io::Printer* p); bool IsScoped() const; diff --git a/src/google/protobuf/compiler/java/java_features.pb.cc b/src/google/protobuf/compiler/java/java_features.pb.cc index 309375292d..4378405e4d 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.cc +++ b/src/google/protobuf/compiler/java/java_features.pb.cc @@ -375,9 +375,11 @@ void JavaFeatures::InternalSwap(JavaFeatures* PROTOBUF_RESTRICT other) { &descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_getter, &descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_once, file_level_metadata_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto[0]); } -PROTOC_EXPORT PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FeatureSet, - ::google::protobuf::internal::MessageTypeTraits< ::pb::JavaFeatures >, 11, false> - java(kJavaFieldNumber, ::pb::JavaFeatures::default_instance(), nullptr); +PROTOC_EXPORT PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 :: + google::protobuf::internal::ExtensionIdentifier< + ::google::protobuf::FeatureSet, ::google::protobuf::internal::MessageTypeTraits< ::pb::JavaFeatures >, + 11, false> + java(kJavaFieldNumber, ::pb::JavaFeatures::default_instance(), nullptr); // @@protoc_insertion_point(namespace_scope) } // namespace pb namespace google { diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 1a0c7bba2e..88584abccd 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -318,9 +318,10 @@ class PROTOC_EXPORT JavaFeatures final : static const int kJavaFieldNumber = 1001; -PROTOC_EXPORT extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FeatureSet, - ::google::protobuf::internal::MessageTypeTraits< ::pb::JavaFeatures >, 11, false > - java; +PROTOC_EXPORT extern ::google::protobuf::internal::ExtensionIdentifier< + ::google::protobuf::FeatureSet, ::google::protobuf::internal::MessageTypeTraits< ::pb::JavaFeatures >, 11, + false> + java; // =================================================================== diff --git a/src/google/protobuf/cpp_features.pb.cc b/src/google/protobuf/cpp_features.pb.cc index b7eee1a5fa..6e5538d889 100644 --- a/src/google/protobuf/cpp_features.pb.cc +++ b/src/google/protobuf/cpp_features.pb.cc @@ -298,10 +298,12 @@ void CppFeatures::InternalSwap(CppFeatures* PROTOBUF_RESTRICT other) { &descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto_getter, &descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto_once, file_level_metadata_google_2fprotobuf_2fcpp_5ffeatures_2eproto[0]); } -PROTOBUF_CONSTINIT PROTOBUF_EXPORT PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FeatureSet, - ::google::protobuf::internal::MessageTypeTraits< ::pb::CppFeatures >, 11, false> - cpp(kCppFieldNumber); +PROTOBUF_CONSTINIT PROTOBUF_EXPORT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::google::protobuf::internal:: + ExtensionIdentifier< + ::google::protobuf::FeatureSet, ::google::protobuf::internal::MessageTypeTraits< ::pb::CppFeatures >, + 11, false> + cpp(kCppFieldNumber); // @@protoc_insertion_point(namespace_scope) } // namespace pb namespace google { diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index 3b470431e3..6e2c967dc8 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -253,9 +253,10 @@ class PROTOBUF_EXPORT CppFeatures final : static const int kCppFieldNumber = 1000; -PROTOBUF_EXPORT extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FeatureSet, - ::google::protobuf::internal::MessageTypeTraits< ::pb::CppFeatures >, 11, false > - cpp; +PROTOBUF_EXPORT extern ::google::protobuf::internal::ExtensionIdentifier< + ::google::protobuf::FeatureSet, ::google::protobuf::internal::MessageTypeTraits< ::pb::CppFeatures >, 11, + false> + cpp; // =================================================================== From 1231af10c7e55c303fc1260c4ed79f43a294adbb Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 2 Nov 2023 15:28:01 -0700 Subject: [PATCH 072/387] merge 25.x to main (#14617) Closes #14617 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14617 from anandolee:25.x ac86c5ef32da07fe624428806beabab3bcc1ea0e PiperOrigin-RevId: 578996979 --- CMakeLists.txt | 2 +- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- .../Google.Protobuf/Google.Protobuf.csproj | 2 +- java/README.md | 6 ++-- java/bom/pom.xml | 2 +- java/core/pom.xml | 2 +- java/kotlin-lite/pom.xml | 2 +- java/kotlin/pom.xml | 2 +- java/lite.md | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/protoc/pom.xml | 2 +- java/util/pom.xml | 2 +- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 10 +++---- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 +-- .../protobuf/compiler/java/java_features.pb.h | 4 +-- src/google/protobuf/compiler/plugin.pb.h | 4 +-- src/google/protobuf/cpp_features.pb.h | 4 +-- src/google/protobuf/descriptor.pb.h | 4 +-- src/google/protobuf/port_def.inc | 8 ++--- version.json | 30 +++++++++---------- 26 files changed, 54 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac0d03c3aa..f78fccc27a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ if (protobuf_BUILD_SHARED_LIBS) endif () # Version metadata -set(protobuf_VERSION_STRING "4.24.0") +set(protobuf_VERSION_STRING "4.25.0") set(protobuf_DESCRIPTION "Protocol Buffers") set(protobuf_CONTACT "protobuf@googlegroups.com") diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index f472aa5f1b..f2b9f35535 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '4.24.0' + s.version = '4.25.0' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' diff --git a/Protobuf.podspec b/Protobuf.podspec index 539394e629..0e4a664d6f 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.24.0' + s.version = '3.25.0' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 2a0cf99af8..bd9a3b66db 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.24.0 + 3.25.0 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index dede331228..b5731cdebb 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -5,7 +5,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.24.0 + 3.25.0 10.0 Google Inc. netstandard1.1;netstandard2.0;net45;net50 diff --git a/java/README.md b/java/README.md index fb80b05f27..f6dab2654d 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.24.0 + 3.25.0 ``` @@ -37,14 +37,14 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.24.0 + 3.25.0 ``` ### Gradle If you are using Gradle, add the following to your `build.gradle` file's -dependencies: `implementation 'com.google.protobuf:protobuf-java:3.24.0'` Again, +dependencies: `implementation 'com.google.protobuf:protobuf-java:3.25.0'` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index 372dcdfda0..411c501fa7 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.24.0 + 3.25.0 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 84d674094e..c98d168792 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 254eb8281b..bc4fb9ef7c 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 354e65494c..3d26d8a311 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index d8201e0468..fbaf1c8ed4 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.24.0 + 3.25.0 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 3b4ff82583..3f9e3897bf 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 1deeca92a8..9e0a6992c0 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0 pom Protocol Buffers [Parent] diff --git a/java/protoc/pom.xml b/java/protoc/pom.xml index eec6f636e7..34f8579c8b 100644 --- a/java/protoc/pom.xml +++ b/java/protoc/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.24.0 + 3.25.0 pom Protobuf Compiler diff --git a/java/util/pom.xml b/java/util/pom.xml index f5c6380899..f25581be84 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.24.0 + 3.25.0 protobuf-java-util diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index d24a5328e9..4fab47f357 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -32,7 +32,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.24.0" +#define PHP_PROTOBUF_VERSION "3.25.0" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/protobuf_version.bzl b/protobuf_version.bzl index e428407720..a122dc377f 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1,6 +1,6 @@ """ Contains version numbers to be used in other bzl files """ -PROTOC_VERSION = "24.0" -PROTOBUF_JAVA_VERSION = "3.24.0" -PROTOBUF_PYTHON_VERSION = "4.24.0" -PROTOBUF_PHP_VERSION = "3.24.0" -PROTOBUF_RUBY_VERSION = "3.24.0" +PROTOC_VERSION = "25.0" +PROTOBUF_JAVA_VERSION = "3.25.0" +PROTOBUF_PYTHON_VERSION = "4.25.0" +PROTOBUF_PHP_VERSION = "3.25.0" +PROTOBUF_RUBY_VERSION = "3.25.0" diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 45a6c20c59..522b7ed499 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -7,4 +7,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.24.0' +__version__ = '4.25.0' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 8a292af288..e3770be416 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.24.0" + s.version = "3.25.0" 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.summary = "Protocol Buffers" diff --git a/ruby/pom.xml b/ruby/pom.xml index 2242464e23..5cd8245c5a 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.24.0 + 3.25.0 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.24.0 + 3.25.0 org.jruby diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 88584abccd..675581b2fb 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index eb3da21003..79175d8f67 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index 6e2c967dc8..a39685ec5b 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index ea38e1f3d0..05856a366b 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 86ed3ea7d7..21f21bd57a 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -204,17 +204,17 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 4024000 +#define PROTOBUF_VERSION 4025000 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined #endif -#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 4024000 +#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 4025000 #ifdef PROTOBUF_MIN_PROTOC_VERSION #error PROTOBUF_MIN_PROTOC_VERSION was previously defined #endif -#define PROTOBUF_MIN_PROTOC_VERSION 4024000 +#define PROTOBUF_MIN_PROTOC_VERSION 4025000 #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined @@ -330,7 +330,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 4024000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 4025000 #ifdef PROTOBUF_RTTI #error PROTOBUF_RTTI was previously defined diff --git a/version.json b/version.json index 5c98fc209d..9deb430483 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { - "main": { - "protoc_version": "26-dev", - "lts": false, - "date": "2023-10-16", - "languages": { - "cpp": "4.26-dev", - "csharp": "3.26-dev", - "java": "3.26-dev", - "javascript": "3.26-dev", - "objectivec": "3.26-dev", - "php": "3.26-dev", - "python": "4.26-dev", - "ruby": "3.26-dev" - } + "25.x": { + "protoc_version": "25.0-dev", + "lts": false, + "date": "2023-11-01", + "languages": { + "cpp": "4.25.0-dev", + "csharp": "3.25.0-dev", + "java": "3.25.0-dev", + "javascript": "3.25.0-dev", + "objectivec": "3.25.0-dev", + "php": "3.25.0-dev", + "python": "4.25.0-dev", + "ruby": "3.25.0-dev" } -} \ No newline at end of file + } +} From be1665f92c7996d56b4d5fd8909b6e15daf07bd0 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 15:40:39 -0700 Subject: [PATCH 073/387] Do not pass verify_func for non message extensions PiperOrigin-RevId: 579000409 --- src/google/protobuf/compiler/cpp/extension.cc | 2 +- .../compiler/java/java_features.pb.cc | 2 +- src/google/protobuf/extension_set.cc | 14 ++-- src/google/protobuf/extension_set.h | 71 +++++++++++++------ 4 files changed, 58 insertions(+), 31 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/extension.cc b/src/google/protobuf/compiler/cpp/extension.cc index 361d2cc5a4..924ef4e5cb 100644 --- a/src/google/protobuf/compiler/cpp/extension.cc +++ b/src/google/protobuf/compiler/cpp/extension.cc @@ -198,7 +198,7 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* p) { $proto_ns$::internal::ExtensionIdentifier< $extendee$, ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$> - $scoped_name$($constant_name$, $default_str$, nullptr); + $scoped_name$($constant_name$, $default_str$); )cc"); } }}, diff --git a/src/google/protobuf/compiler/java/java_features.pb.cc b/src/google/protobuf/compiler/java/java_features.pb.cc index 4378405e4d..c90164e5f0 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.cc +++ b/src/google/protobuf/compiler/java/java_features.pb.cc @@ -379,7 +379,7 @@ PROTOC_EXPORT PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 :: google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FeatureSet, ::google::protobuf::internal::MessageTypeTraits< ::pb::JavaFeatures >, 11, false> - java(kJavaFieldNumber, ::pb::JavaFeatures::default_instance(), nullptr); + java(kJavaFieldNumber, ::pb::JavaFeatures::default_instance()); // @@protoc_insertion_point(namespace_scope) } // namespace pb namespace google { diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index 7fde2cf8de..538178fc4a 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc @@ -11,15 +11,19 @@ #include "google/protobuf/extension_set.h" +#include #include +#include +#include #include #include #include #include -#include "google/protobuf/stubs/common.h" #include "absl/container/flat_hash_set.h" #include "absl/hash/hash.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "google/protobuf/arena.h" #include "google/protobuf/extension_set_inl.h" #include "google/protobuf/io/coded_stream.h" @@ -107,13 +111,11 @@ bool GeneratedExtensionFinder::Find(int number, ExtensionInfo* output) { void ExtensionSet::RegisterExtension(const MessageLite* extendee, int number, FieldType type, bool is_repeated, - bool is_packed, - LazyEagerVerifyFnType verify_func) { + bool is_packed) { ABSL_CHECK_NE(type, WireFormatLite::TYPE_ENUM); ABSL_CHECK_NE(type, WireFormatLite::TYPE_MESSAGE); ABSL_CHECK_NE(type, WireFormatLite::TYPE_GROUP); - ExtensionInfo info(extendee, number, type, is_repeated, is_packed, - verify_func); + ExtensionInfo info(extendee, number, type, is_repeated, is_packed); Register(info); } @@ -135,7 +137,7 @@ void ExtensionSet::RegisterEnumExtension(const MessageLite* extendee, bool is_repeated, bool is_packed, EnumValidityFunc* is_valid) { ABSL_CHECK_EQ(type, WireFormatLite::TYPE_ENUM); - ExtensionInfo info(extendee, number, type, is_repeated, is_packed, nullptr); + ExtensionInfo info(extendee, number, type, is_repeated, is_packed); info.enum_validity_check.func = CallNoArgValidityFunc; // See comment in CallNoArgValidityFunc() about why we use a c-style cast. info.enum_validity_check.arg = (void*)is_valid; diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index dd4a473ebc..f9fb2bd94f 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include #include @@ -32,6 +34,7 @@ #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/parse_context.h" #include "google/protobuf/repeated_field.h" +#include "google/protobuf/repeated_ptr_field.h" #include "google/protobuf/wire_format_lite.h" // clang-format off @@ -90,6 +93,14 @@ typedef bool EnumValidityFuncWithArg(const void* arg, int number); // Information about a registered extension. struct ExtensionInfo { constexpr ExtensionInfo() : enum_validity_check() {} + constexpr ExtensionInfo(const MessageLite* extendee, int param_number, + FieldType type_param, bool isrepeated, bool ispacked) + : message(extendee), + number(param_number), + type(type_param), + is_repeated(isrepeated), + is_packed(ispacked), + enum_validity_check() {} constexpr ExtensionInfo(const MessageLite* extendee, int param_number, FieldType type_param, bool isrepeated, bool ispacked, LazyEagerVerifyFnType verify_func) @@ -190,8 +201,7 @@ class PROTOBUF_EXPORT ExtensionSet { // methods do. static void RegisterExtension(const MessageLite* extendee, int number, FieldType type, bool is_repeated, - bool is_packed, - LazyEagerVerifyFnType verify_func); + bool is_packed); static void RegisterEnumExtension(const MessageLite* extendee, int number, FieldType type, bool is_repeated, bool is_packed, EnumValidityFunc* is_valid); @@ -1019,10 +1029,9 @@ class PrimitiveTypeTraits { static inline void Set(int number, FieldType field_type, ConstType value, ExtensionSet* set); template - static void Register(int number, FieldType type, bool is_packed, - LazyEagerVerifyFnType verify_func) { + static void Register(int number, FieldType type, bool is_packed) { ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number, - type, false, is_packed, verify_func); + type, false, is_packed); } }; @@ -1054,10 +1063,9 @@ class RepeatedPrimitiveTypeTraits { static const RepeatedFieldType* GetDefaultRepeatedField(); template - static void Register(int number, FieldType type, bool is_packed, - LazyEagerVerifyFnType verify_func) { + static void Register(int number, FieldType type, bool is_packed) { ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number, - type, true, is_packed, verify_func); + type, true, is_packed); } }; @@ -1178,10 +1186,9 @@ class PROTOBUF_EXPORT StringTypeTraits { return set->MutableString(number, field_type, nullptr); } template - static void Register(int number, FieldType type, bool is_packed, - LazyEagerVerifyFnType verify_func) { + static void Register(int number, FieldType type, bool is_packed) { ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number, - type, false, is_packed, verify_func); + type, false, is_packed); } }; @@ -1236,10 +1243,9 @@ class PROTOBUF_EXPORT RepeatedStringTypeTraits { static const RepeatedFieldType* GetDefaultRepeatedField(); template - static void Register(int number, FieldType type, bool is_packed, - LazyEagerVerifyFnType fn) { + static void Register(int number, FieldType type, bool is_packed) { ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number, - type, true, is_packed, fn); + type, true, is_packed); } private: @@ -1275,10 +1281,7 @@ class EnumTypeTraits { set->SetEnum(number, field_type, value, nullptr); } template - static void Register(int number, FieldType type, bool is_packed, - LazyEagerVerifyFnType fn) { - // Avoid -Wunused-parameter - (void)fn; + static void Register(int number, FieldType type, bool is_packed) { ExtensionSet::RegisterEnumExtension(&ExtendeeT::default_instance(), number, type, false, is_packed, IsValid); } @@ -1344,10 +1347,7 @@ class RepeatedEnumTypeTraits { RepeatedPrimitiveTypeTraits::GetDefaultRepeatedField()); } template - static void Register(int number, FieldType type, bool is_packed, - LazyEagerVerifyFnType fn) { - // Avoid -Wunused-parameter - (void)fn; + static void Register(int number, FieldType type, bool is_packed) { ExtensionSet::RegisterEnumExtension(&ExtendeeT::default_instance(), number, type, true, is_packed, IsValid); } @@ -1402,6 +1402,14 @@ class MessageTypeTraits { return static_cast( set->UnsafeArenaReleaseMessage(number, Type::default_instance())); } + // Some messages won't (can't) be verified; e.g. lite. + template + static void Register(int number, FieldType type, bool is_packed) { + ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(), + number, type, false, is_packed, + &Type::default_instance(), nullptr); + } + template static void Register(int number, FieldType type, bool is_packed, LazyEagerVerifyFnType fn) { @@ -1469,6 +1477,15 @@ class RepeatedMessageTypeTraits { } static const RepeatedFieldType* GetDefaultRepeatedField(); + + // Some messages won't (can't) be verified; e.g. lite. + template + static void Register(int number, FieldType type, bool is_packed) { + ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(), + number, type, true, is_packed, + &Type::default_instance(), nullptr); + } + template static void Register(int number, FieldType type, bool is_packed, LazyEagerVerifyFnType fn) { @@ -1511,8 +1528,12 @@ class ExtensionIdentifier { typedef TypeTraitsType TypeTraits; typedef ExtendeeType Extendee; + ExtensionIdentifier(int number, typename TypeTraits::ConstType default_value) + : number_(number), default_value_(default_value) { + Register(number); + } ExtensionIdentifier(int number, typename TypeTraits::ConstType default_value, - LazyEagerVerifyFnType verify_func = nullptr) + LazyEagerVerifyFnType verify_func) : number_(number), default_value_(default_value) { Register(number, verify_func); } @@ -1521,6 +1542,10 @@ class ExtensionIdentifier { return default_value_; } + static void Register(int number) { + TypeTraits::template Register(number, field_type, is_packed); + } + static void Register(int number, LazyEagerVerifyFnType verify_func) { TypeTraits::template Register(number, field_type, is_packed, verify_func); From 2e5e2783cc8e41bf84263de11b147dcd36cedb83 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 22:46:19 +0000 Subject: [PATCH 074/387] Auto-generate files after PR #14617 --- src/google/protobuf/any.pb.h | 4 ++-- src/google/protobuf/api.pb.h | 4 ++-- src/google/protobuf/duration.pb.h | 4 ++-- src/google/protobuf/empty.pb.h | 4 ++-- src/google/protobuf/field_mask.pb.h | 4 ++-- src/google/protobuf/source_context.pb.h | 4 ++-- src/google/protobuf/struct.pb.h | 4 ++-- src/google/protobuf/timestamp.pb.h | 4 ++-- src/google/protobuf/type.pb.h | 4 ++-- src/google/protobuf/wrappers.pb.h | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index f6eecf8cd5..10a84ba8af 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 08d2f8addf..88d9ccc34f 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 3a7539d2a3..346b58d9f1 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index f66a7258ec..1b929ecffe 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index e4d6dca8a2..4e8f3946ca 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index ed58fe7fcf..0e3e2c96fd 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 6f9c7d176e..61a923efc0 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 8c1d97196e..0d58d1e036 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 489cbdd116..b9bb7f6336 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 78d3c718f1..564ba0c2c2 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -11,13 +11,13 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4024000 +#if PROTOBUF_VERSION < 4025000 #error "This file was generated by a newer version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please update" #error "your headers." #endif // PROTOBUF_VERSION -#if 4024000 < PROTOBUF_MIN_PROTOC_VERSION +#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION #error "This file was generated by an older version of protoc which is" #error "incompatible with your Protocol Buffer headers. Please" #error "regenerate this file with a newer version of protoc." From 0d5cb3a6a6cfb95b41974dd64162a554b30b4d3c Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Thu, 2 Nov 2023 18:19:24 -0700 Subject: [PATCH 075/387] Fix file missing in merge from 25.x PiperOrigin-RevId: 579036296 --- src/google/protobuf/stubs/common.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 5eb0df4c02..2a95199d54 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -44,7 +44,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 4024000 +#define GOOGLE_PROTOBUF_VERSION 4025000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" @@ -52,15 +52,15 @@ namespace internal { // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 4024000; +static const int kMinHeaderVersionForLibrary = 4025000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 4024000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 4025000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 4024000; +static const int kMinHeaderVersionForProtoc = 4025000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. From e682ab6bc378ede1d98735b39bcc0d426d4f5ffb Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 2 Nov 2023 23:13:55 -0700 Subject: [PATCH 076/387] Annotate message field builder getters with Semantic::kSet As an analog to the C++ mutable_foo() member functions, uses of Java builders should appear as writes in Code Search. They should be marked with the kSet semantic. Note that the get*OrBuilder[List] methods should *not* be marked with kSet as they do not return a mutable object. PiperOrigin-RevId: 579079084 --- src/google/protobuf/compiler/java/message_field.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index 56c06c0fcd..f982bf9f1b 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -342,7 +342,7 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " $on_changed$\n" " return get$capitalized_name$FieldBuilder().getBuilder();\n" "}\n"); - printer->Annotate("{", "}", descriptor_); + printer->Annotate("{", "}", descriptor_, Semantic::kSet); // FieldOrBuilder getFieldOrBuilder() WriteFieldDocComment(printer, descriptor_, context_->options()); @@ -692,7 +692,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( "${$get$capitalized_name$Builder$}$() {\n" " return get$capitalized_name$FieldBuilder().getBuilder();\n" "}\n"); - printer->Annotate("{", "}", descriptor_); + printer->Annotate("{", "}", descriptor_, Semantic::kSet); WriteFieldDocComment(printer, descriptor_, context_->options()); printer->Print( variables_, @@ -730,7 +730,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( " $on_changed$\n" " return $name$Builder_;\n" "}\n"); - printer->Annotate("{", "}", descriptor_); + printer->Annotate("{", "}", descriptor_, Semantic::kSet); } void ImmutableMessageOneofFieldGenerator::GenerateBuilderClearCode( @@ -1148,7 +1148,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " int index) {\n" " return get$capitalized_name$FieldBuilder().getBuilder(index);\n" "}\n"); - printer->Annotate("{", "}", descriptor_); + printer->Annotate("{", "}", descriptor_, Semantic::kSet); // FieldOrBuilder getRepeatedFieldOrBuilder(int index) WriteFieldDocComment(printer, descriptor_, context_->options()); @@ -1222,7 +1222,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " }\n" " return $name$Builder_;\n" "}\n"); - printer->Annotate("{", "}", descriptor_); + printer->Annotate("{", "}", descriptor_, Semantic::kSet); } void RepeatedImmutableMessageFieldGenerator:: From 4721f6a5e91de847d106877633296981c97cfa8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Sad=C5=82ocha?= Date: Fri, 3 Nov 2023 06:50:57 -0700 Subject: [PATCH 077/387] Update a comment in oneofs PiperOrigin-RevId: 579168059 --- src/google/protobuf/compiler/rust/oneof.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 41f5bb9a1c..33836a02f9 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -246,8 +246,7 @@ void GenerateOneofAccessors(Context oneof) { if (rs_type.empty()) { continue; } - // TODO: Uncomment this to allow mut once - // _mut() on singular fields with presence is implemented. + // TODO: Allow mut. /*oneof.Emit({ {"case", ToCamelCase(field->name())}, {"rs_getter", field->name() + "_mut"}, From 6ee7a322d3556b56d79b67e1ba44e81310f50448 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 3 Nov 2023 07:24:10 -0700 Subject: [PATCH 078/387] Clarify same-crate-import vs different-crate-import message fields (latter unsupported). PiperOrigin-RevId: 579175657 --- .../compiler/rust/accessors/accessors.cc | 15 +++++-- .../rust/accessors/singular_message.cc | 9 +--- src/google/protobuf/compiler/rust/context.h | 43 ++++++++++++++++--- .../protobuf/compiler/rust/generator.cc | 23 +++++----- 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index e963e9e075..f3664229ca 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -23,7 +23,8 @@ namespace rust { namespace { std::unique_ptr AccessorGeneratorFor( - const FieldDescriptor& desc) { + Context field) { + const FieldDescriptor& desc = field.desc(); // TODO: We do not support [ctype=FOO] (used to set the field // type in C++ to cord or string_piece) in V0.6 API. if (desc.options().has_ctype()) { @@ -59,6 +60,12 @@ std::unique_ptr AccessorGeneratorFor( if (desc.is_repeated()) { return std::make_unique("repeated msg not supported"); } + if (!field.generator_context().is_file_in_current_crate( + desc.message_type()->file())) { + return std::make_unique( + "message fields that are imported from another proto_library" + " (defined in a separate Rust crate) are not supported"); + } return std::make_unique(); case FieldDescriptor::TYPE_ENUM: @@ -74,15 +81,15 @@ std::unique_ptr AccessorGeneratorFor( } // namespace void GenerateAccessorMsgImpl(Context field) { - AccessorGeneratorFor(field.desc())->GenerateMsgImpl(field); + AccessorGeneratorFor(field)->GenerateMsgImpl(field); } void GenerateAccessorExternC(Context field) { - AccessorGeneratorFor(field.desc())->GenerateExternC(field); + AccessorGeneratorFor(field)->GenerateExternC(field); } void GenerateAccessorThunkCc(Context field) { - AccessorGeneratorFor(field.desc())->GenerateThunkCc(field); + AccessorGeneratorFor(field)->GenerateThunkCc(field); } } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/singular_message.cc b/src/google/protobuf/compiler/rust/accessors/singular_message.cc index 2978631faf..26f3358b75 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_message.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_message.cc @@ -5,7 +5,6 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "absl/strings/match.h" #include "absl/strings/string_view.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/rust/accessors/accessor_generator.h" @@ -20,13 +19,9 @@ namespace rust { void SingularMessage::InMsgImpl(Context field) const { Context d = field.WithDesc(field.desc().message_type()); + auto prefix = "crate::" + GetCrateRelativeQualifiedPath(d); - // here we defer unit tests with messages that have import inside their - // pkg name e.g. unittest_import.proto - if (absl::StrContains(prefix, "import")) { - // TODO: Handle imports correctly, default to $Msg$View for now - prefix = field.desc().containing_type()->name(); - } + if (field.is_cpp()) { field.Emit({{"prefix", prefix}, {"field", field.desc().name()}, diff --git a/src/google/protobuf/compiler/rust/context.h b/src/google/protobuf/compiler/rust/context.h index 1158fbd795..ac31e99d68 100644 --- a/src/google/protobuf/compiler/rust/context.h +++ b/src/google/protobuf/compiler/rust/context.h @@ -8,10 +8,14 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_RUST_CONTEXT_H__ #define GOOGLE_PROTOBUF_COMPILER_RUST_CONTEXT_H__ +#include +#include + #include "absl/log/absl_log.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" +#include "google/protobuf/descriptor.h" #include "google/protobuf/io/printer.h" namespace google { @@ -43,6 +47,26 @@ struct Options { static absl::StatusOr Parse(absl::string_view param); }; +class RustGeneratorContext { + public: + explicit RustGeneratorContext( + const std::vector* files_in_current_crate) + : files_in_current_crate_(*files_in_current_crate) {} + + const FileDescriptor* primary_file() const { + return files_in_current_crate_.front(); + } + + bool is_file_in_current_crate(const FileDescriptor* f) const { + return std::find(files_in_current_crate_.begin(), + files_in_current_crate_.end(), + f) != files_in_current_crate_.end(); + } + + private: + const std::vector& files_in_current_crate_; +}; + // A context for generating a particular kind of definition. // This type acts as an options struct (as in go/totw/173) for most of the // generator. @@ -52,14 +76,22 @@ struct Options { template class Context { public: - Context(const Options* opts, const Descriptor* desc, io::Printer* printer) - : opts_(opts), desc_(desc), printer_(printer) {} + Context(const Options* opts, const Descriptor* desc, + const RustGeneratorContext* rust_generator_context, + io::Printer* printer) + : opts_(opts), + desc_(desc), + rust_generator_context_(rust_generator_context), + printer_(printer) {} Context(const Context&) = default; Context& operator=(const Context&) = default; const Descriptor& desc() const { return *desc_; } const Options& opts() const { return *opts_; } + const RustGeneratorContext& generator_context() const { + return *rust_generator_context_; + } bool is_cpp() const { return opts_->kernel == Kernel::kCpp; } bool is_upb() const { return opts_->kernel == Kernel::kUpb; } @@ -70,16 +102,16 @@ class Context { // Creates a new context over a different descriptor. template Context WithDesc(const D& desc) const { - return Context(opts_, &desc, printer_); + return Context(opts_, &desc, rust_generator_context_, printer_); } template Context WithDesc(const D* desc) const { - return Context(opts_, desc, printer_); + return Context(opts_, desc, rust_generator_context_, printer_); } Context WithPrinter(io::Printer* printer) const { - return Context(opts_, desc_, printer); + return Context(opts_, desc_, rust_generator_context_, printer); } // Forwards to Emit(), which will likely be called all the time. @@ -97,6 +129,7 @@ class Context { private: const Options* opts_; const Descriptor* desc_; + const RustGeneratorContext* rust_generator_context_; io::Printer* printer_; }; } // namespace rust diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index 4027376102..585b7aae83 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -123,11 +123,7 @@ void EmitPubUseForImportedMessages(Context& primary_file, } // Emits all public imports of the current file -void EmitPublicImports( - Context& primary_file, - const std::vector& files_in_current_crate) { - absl::flat_hash_set files( - files_in_current_crate.begin(), files_in_current_crate.end()); +void EmitPublicImports(Context& primary_file) { for (int i = 0; i < primary_file.desc().public_dependency_count(); ++i) { auto dep_file = primary_file.desc().public_dependency(i); // If the publicly imported file is a src of the current `proto_library` @@ -137,7 +133,8 @@ void EmitPublicImports( // TODO: Handle the case where a non-primary src with the same // declared package as the primary src publicly imports a file that the // primary doesn't. - if (files.contains(dep_file)) continue; + if (primary_file.generator_context().is_file_in_current_crate(dep_file)) + continue; auto dep = primary_file.WithDesc(dep_file); EmitPubUseForImportedMessages(primary_file, dep); } @@ -206,7 +203,13 @@ bool RustGenerator::Generate(const FileDescriptor* file_desc, return false; } - Context file(&*opts, file_desc, nullptr); + std::vector files_in_current_crate; + generator_context->ListParsedFiles(&files_in_current_crate); + + RustGeneratorContext rust_generator_context(&files_in_current_crate); + + Context file(&*opts, file_desc, &rust_generator_context, + nullptr); auto outfile = absl::WrapUnique(generator_context->Open(GetRsFile(file))); io::Printer printer(outfile.get()); @@ -228,15 +231,13 @@ bool RustGenerator::Generate(const FileDescriptor* file_desc, )rs"); - std::vector files_in_current_crate; - generator_context->ListParsedFiles(&files_in_current_crate); std::vector> file_contexts; for (const FileDescriptor* f : files_in_current_crate) { file_contexts.push_back(file.WithDesc(*f)); } // Generating the primary file? - if (file_desc == files_in_current_crate.front()) { + if (file_desc == rust_generator_context.primary_file()) { auto non_primary_srcs = absl::MakeConstSpan(file_contexts).subspan(1); DeclareSubmodulesForNonPrimarySrcs(file, non_primary_srcs); @@ -252,7 +253,7 @@ bool RustGenerator::Generate(const FileDescriptor* file_desc, } } - EmitPublicImports(file, files_in_current_crate); + EmitPublicImports(file); std::unique_ptr thunks_cc; std::unique_ptr thunks_printer; From b0d4b2c1fe5a759b4e0459a0c2efd7dd690d97fe Mon Sep 17 00:00:00 2001 From: "Michael Vorburger.ch" Date: Fri, 3 Nov 2023 08:40:44 -0700 Subject: [PATCH 079/387] Separate Build / IDE / Documentation from Other on Third Party doc PiperOrigin-RevId: 579193733 --- docs/third_party.md | 47 +++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/third_party.md b/docs/third_party.md index a3763a974e..b339c4f196 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -169,9 +169,7 @@ Inactive: * https://github.com/thesamet/rpcz (C++/Python, based on ZeroMQ) * https://github.com/w359405949/libmaid (C++, Python) -## Other Utilities - -There are miscellaneous other things you may find useful as a Protocol Buffers developer. +## Build * [Bazel Build](https://bazel.build) * [rules_closure](https://github.com/bazelbuild/rules_closure) @@ -179,17 +177,6 @@ There are miscellaneous other things you may find useful as a Protocol Buffers d * [rules_go](https://github.com/bazelbuild/rules_go) `go` * [rules_protobuf](https://github.com/pubref/rules_protobuf) `java` `c++` `c#` `go` `js-closure` `js-node` `python` `ruby` -* [NetBeans IDE plugin](https://code.google.com/p/protobuf-netbeans-plugin/) -* [Wireshark/Ethereal packet sniffer plugin](https://code.google.com/p/protobuf-wireshark/) -* [Alternate encodings (JSON, XML, HTML) for Java protobufs](https://code.google.com/p/protobuf-java-format/) -* [Another JSON encoder/decoder for Java](https://github.com/sijuv/protobuf-codec) -* [Editor for serialized protobufs](https://code.google.com/p/protobufeditor/) -* [IntelliJ IDEA plugin](http://github.com/jvolkman/intellij-protobuf-editor) -* [IntelliJ Protobuf Plugin](https://github.com/devkanro/intellij-protobuf-plugin) -* [TextMate syntax highlighting](http://github.com/michaeledgar/protobuf-tmbundle) -* [Oracle PL SQL plugin](https://code.google.com/p/protocol-buffer-plsql/) -* [Eclipse editor for protobuf (from Google)](https://code.google.com/p/protobuf-dt/) -* [C++ Builder compatible protobuf](https://github.com/saadware/protobuf-cppbuilder) * Maven Protobuf Compiler Plugin * By xolstice.org ([Documentation](https://www.xolstice.org/protobuf-maven-plugin/)) @@ -197,21 +184,43 @@ There are miscellaneous other things you may find useful as a Protocol Buffers d [![Maven Central](https://img.shields.io/maven-central/v/org.xolstice.maven.plugins/protobuf-maven-plugin.svg)](https://repo1.maven.org/maven2/org/xolstice/maven/plugins/protobuf-maven-plugin/) * https://code.google.com/p/maven-protoc-plugin/ * https://github.com/os72/protoc-jar-maven-plugin +* [Protobuf Plugin for Gradle](https://github.com/google/protobuf-gradle-plugin) +* [Sbt plugin for Protocol Buffers](https://github.com/Atry/sbt-cppp) + +## IDE + +* [Visual Studio Code Support for Protocol Buffers](https://marketplace.visualstudio.com/items?itemName=zxh404.vscode-proto3) +* [Visual Studio Language Service support for Protocol Buffers](http://visualstudiogallery.msdn.microsoft.com/4bc0f38c-b058-4e05-ae38-155e053c19c5) +* [IntelliJ IDEA plugin](http://github.com/jvolkman/intellij-protobuf-editor) +* [IntelliJ Protobuf Plugin](https://github.com/devkanro/intellij-protobuf-plugin) +* [TextMate syntax highlighting](http://github.com/michaeledgar/protobuf-tmbundle) +* [Notepad++ Syntax Highlighting for .proto files](https://github.com/chai2010/notepadplus-protobuf) +* [Eclipse editor for protobuf (from Google)](https://code.google.com/p/protobuf-dt/) +* [NetBeans IDE plugin](https://code.google.com/p/protobuf-netbeans-plugin/) +* [Editor for serialized protobufs](https://code.google.com/p/protobufeditor/) + +## Documentation + * [Documentation generator plugin (Markdown/HTML/DocBook/...)](https://github.com/pseudomuto/protoc-gen-doc) * [DocBook generator for .proto files](https://code.google.com/p/protoc-gen-docbook/) + +## Other Utilities + +There are miscellaneous other things you may find useful as a Protocol Buffers developer. + +* [Wireshark/Ethereal packet sniffer plugin](https://code.google.com/p/protobuf-wireshark/) +* [Alternate encodings (JSON, XML, HTML) for Java protobufs](https://code.google.com/p/protobuf-java-format/) +* [Another JSON encoder/decoder for Java](https://github.com/sijuv/protobuf-codec) +* [Oracle PL SQL plugin](https://code.google.com/p/protocol-buffer-plsql/) +* [C++ Builder compatible protobuf](https://github.com/saadware/protobuf-cppbuilder) * [Protobuf for nginx module](https://github.com/dbcode/protobuf-nginx/) * [RSpec matchers and Cucumber step defs for testing Protocol Buffers](https://github.com/connamara/protobuf_spec) -* [Sbt plugin for Protocol Buffers](https://github.com/Atry/sbt-cppp) -* [Protobuf Plugin for Gradle](https://github.com/google/protobuf-gradle-plugin) * [Multi-platform executable JAR and Java API for protoc](https://github.com/os72/protoc-jar) * [Python scripts to convert between Protocol Buffers and JSON](https://github.com/NextTuesday/py-pb-converters) -* [Visual Studio Language Service support for Protocol Buffers](http://visualstudiogallery.msdn.microsoft.com/4bc0f38c-b058-4e05-ae38-155e053c19c5) -* [Visual Studio Code Support for Protocol Buffers](https://marketplace.visualstudio.com/items?itemName=zxh404.vscode-proto3) * [C++ library for serialization/de-serialization between Protocol Buffers and JSON.](https://github.com/yinqiwen/pbjson) * [ProtoBuf with Java EE7 Expression Language 3.0; pure Java ProtoBuf Parser and Builder.](https://github.com/protobufel/protobuf-el) -* [Notepad++ Syntax Highlighting for .proto files](https://github.com/chai2010/notepadplus-protobuf) * [Linter for .proto files](https://github.com/ckaznocha/protoc-gen-lint) * [Protocol Buffers Dynamic Schema - create protobuf schemas programmatically (Java)](https://github.com/os72/protobuf-dynamic) From a3e45d27eeb211f15f05376a7f070634489c9b75 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 3 Nov 2023 09:11:36 -0700 Subject: [PATCH 080/387] Dedup `RepeatedPtrField::Add` methods to all use common implementation. As a result, `AddMessage` get the same perf boost as main `Add` method from 1df8ea4. PiperOrigin-RevId: 579201689 --- .../generated_message_tctable_lite.cc | 9 ++--- src/google/protobuf/repeated_ptr_field.cc | 23 ++++++++++--- src/google/protobuf/repeated_ptr_field.h | 33 +++++++++++-------- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index bf5a97b7a5..104a22a857 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -470,8 +470,7 @@ inline PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedParseMessageAuxImpl( aux_is_table ? aux.table->default_instance : aux.message_default(); do { ptr += sizeof(TagType); - MessageLite* submsg = - field.Add>(default_instance); + MessageLite* submsg = field.AddMessage(default_instance); if (aux_is_table) { if (group_coding) { ptr = ctx->ParseGroup(submsg, ptr, @@ -2426,8 +2425,7 @@ const char* TcParser::MpRepeatedMessageOrGroup(PROTOBUF_TC_PARAM_DECL) { const char* ptr2 = ptr; uint32_t next_tag; do { - MessageLite* value = - field.template Add>(default_instance); + MessageLite* value = field.AddMessage(default_instance); ptr = is_group ? ctx->ParseGroup(value, ptr2, decoded_tag, inner_table) : ctx->ParseMessage(value, ptr2, inner_table); @@ -2448,8 +2446,7 @@ const char* TcParser::MpRepeatedMessageOrGroup(PROTOBUF_TC_PARAM_DECL) { const char* ptr2 = ptr; uint32_t next_tag; do { - MessageLite* value = - field.template Add>(default_instance); + MessageLite* value = field.AddMessage(default_instance); ptr = is_group ? ctx->ParseGroup(value, ptr2, decoded_tag) : ctx->ParseMessage(value, ptr2); if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) goto error; diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 734a6a7188..82205b1715 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -126,14 +126,18 @@ void* RepeatedPtrFieldBase::AddOutOfLineHelper(void* obj) { return r->elements[ExchangeCurrentSize(current_size_ + 1)] = obj; } -void* RepeatedPtrFieldBase::AddOutOfLineHelper(ElementFactory factory) { +template +auto* RepeatedPtrFieldBase::AddInternal(F factory) { + using Result = decltype(factory(GetArena())); if (tagged_rep_or_elem_ == nullptr) { ExchangeCurrentSize(1); tagged_rep_or_elem_ = factory(GetArena()); - return tagged_rep_or_elem_; + return static_cast(tagged_rep_or_elem_); } if (using_sso()) { - if (ExchangeCurrentSize(1) == 0) return tagged_rep_or_elem_; + if (ExchangeCurrentSize(1) == 0) { + return static_cast(tagged_rep_or_elem_); + } } else { absl::PrefetchToLocalCache(rep()); } @@ -142,14 +146,19 @@ void* RepeatedPtrFieldBase::AddOutOfLineHelper(ElementFactory factory) { } else { Rep* r = rep(); if (current_size_ != r->allocated_size) { - return r->elements[ExchangeCurrentSize(current_size_ + 1)]; + return static_cast( + r->elements[ExchangeCurrentSize(current_size_ + 1)]); } } Rep* r = rep(); ++r->allocated_size; void*& result = r->elements[ExchangeCurrentSize(current_size_ + 1)]; result = factory(GetArena()); - return result; + return static_cast(result); +} + +void* RepeatedPtrFieldBase::AddOutOfLineHelper(ElementFactory factory) { + return AddInternal(factory); } void RepeatedPtrFieldBase::CloseGap(int start, int num) { @@ -167,6 +176,10 @@ void RepeatedPtrFieldBase::CloseGap(int start, int num) { ExchangeCurrentSize(current_size_ - num); } +MessageLite* RepeatedPtrFieldBase::AddMessage(const MessageLite* prototype) { + return AddInternal([prototype](Arena* a) { return prototype->New(a); }); +} + MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) { if (current_size_ < allocated_size()) { return reinterpret_cast( diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index fe38aac865..57a86a87c5 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -232,16 +232,6 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return cast(AddOutOfLineHelper(NewT>)); } - template - Value* Add(const Value* prototype) { - if (current_size_ < allocated_size()) { - return cast( - element_at(ExchangeCurrentSize(current_size_ + 1))); - } - auto* result = TypeHandler::NewFromPrototype(prototype, arena_); - return cast(AddOutOfLineHelper(result)); - } - template < typename TypeHandler, typename std::enable_if::type* = nullptr> @@ -299,9 +289,14 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { } // Creates and adds an element using the given prototype, without introducing - // a link-time dependency on the concrete message type. This method is used to - // implement implicit weak fields. The prototype may be nullptr, in which case - // an ImplicitWeakMessage will be used as a placeholder. + // a link-time dependency on the concrete message type. + // + // Pre-condition: prototype must not be nullptr. + MessageLite* AddMessage(const MessageLite* prototype); + + // This method is similar to `AddMessage` except that prototype may be nullptr + // in which case an ImplicitWeakMessage will be used as a placeholder. It is + // used to implement implicit weak fields. MessageLite* AddWeak(const MessageLite* prototype); template @@ -847,8 +842,20 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // array, including potentially resizing the array with Reserve if // needed void* AddOutOfLineHelper(void* obj); + // Internal helper for Add that keeps definition out-of-line. void* AddOutOfLineHelper(ElementFactory factory); + // Common implementation used by various Add* methods. `factory` is an object + // used to construct a new element unless there are spare cleared elements + // ready for reuse. Returns pointer to the new element. + // + // Note: avoid inlining this function in methods such as `Add()` as this would + // drastically increase binary size due to template instantiation and implicit + // inlining. Instead, use wrapper functions with out-of-line definition + // similar to `AddOutOfLineHelper`. + template + auto* AddInternal(F factory); + // A few notes on internal representation: // // We use an indirected approach, with struct Rep, to keep From 25f28ee6caf7f83921cb238fba8a787b91576c2e Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 3 Nov 2023 09:50:55 -0700 Subject: [PATCH 081/387] Fix typo with janitor GHA, close-pr-message was accidentally defined twice. PiperOrigin-RevId: 579213119 --- .github/workflows/janitor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/janitor.yml b/.github/workflows/janitor.yml index 992d4b7113..5c052a4f12 100644 --- a/.github/workflows/janitor.yml +++ b/.github/workflows/janitor.yml @@ -43,7 +43,7 @@ jobs: This issue is labeled `inactive` because the last activity was over 90 days ago. - close-pr-message: > + close-issue-message: > We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it. From af75cb31f42a56753ffda2d4dcb758c8ab18d44f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 3 Nov 2023 11:18:02 -0700 Subject: [PATCH 082/387] Small clean up Rust crate-relative naming logic PiperOrigin-RevId: 579243379 --- rust/test/nested.proto | 12 ++++ rust/test/shared/simple_nested_test.rs | 10 ++++ src/google/protobuf/compiler/rust/naming.cc | 61 +++++++++++++++------ 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/rust/test/nested.proto b/rust/test/nested.proto index 1b5b149e0c..80b0c615aa 100644 --- a/rust/test/nested.proto +++ b/rust/test/nested.proto @@ -13,6 +13,18 @@ message Outer { message Inner { optional int32 num = 1; optional bool boolean = 2; + + message SuperInner { + message DuperInner { + message EvenMoreInner { + message CantBelieveItsSoInner { + optional int32 num = 99; + } + } + } + } } optional Inner inner = 1; + optional .nest.Outer.Inner.SuperInner.DuperInner.EvenMoreInner + .CantBelieveItsSoInner deep = 2; } diff --git a/rust/test/shared/simple_nested_test.rs b/rust/test/shared/simple_nested_test.rs index 2f9dad50b4..daa654c7da 100644 --- a/rust/test/shared/simple_nested_test.rs +++ b/rust/test/shared/simple_nested_test.rs @@ -13,3 +13,13 @@ fn test_simple_nested_proto() { assert_eq!(outer_msg.inner().num(), 0); assert!(!outer_msg.inner().boolean()); } + +#[test] +fn test_deeply_nested_definition() { + let deep = nested_proto::nest::Outer_::Inner_::SuperInner_::DuperInner_::EvenMoreInner_ + ::CantBelieveItsSoInner::new(); + assert_eq!(deep.num(), 0); + + let outer_msg = Outer::new(); + assert_eq!(outer_msg.deep().num(), 0); +} diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index bb1c35a3e2..e9e24c40b0 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -8,13 +8,14 @@ #include "google/protobuf/compiler/rust/naming.h" #include +#include #include "absl/log/absl_log.h" -#include "absl/strings/match.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_join.h" #include "absl/strings/str_replace.h" +#include "absl/strings/str_split.h" #include "absl/strings/string_view.h" -#include "absl/strings/strip.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/rust/context.h" @@ -166,10 +167,46 @@ std::string PrimitiveRsTypeName(const FieldDescriptor& desc) { return ""; } +// Constructs a string of the Rust modules which will contain the message. +// +// Example: Given a message 'NestedMessage' which is defined in package 'x.y' +// which is inside 'ParentMessage', the message will be placed in the +// x::y::ParentMessage_ Rust module, so this function will return the string +// "x::y::ParentMessage_::". +// +// If the message has no package and no containing messages then this returns +// empty string. std::string RustModule(Context msg) { - absl::string_view package = msg.desc().file()->package(); - if (package.empty()) return ""; - return absl::StrCat("", absl::StrReplaceAll(package, {{".", "::"}})); + const Descriptor& desc = msg.desc(); + + std::vector modules; + + std::vector package_modules = + absl::StrSplit(desc.file()->package(), '.', absl::SkipEmpty()); + + modules.insert(modules.begin(), package_modules.begin(), + package_modules.end()); + + // Innermost to outermost order. + std::vector modules_from_containing_types; + const Descriptor* parent = desc.containing_type(); + while (parent != nullptr) { + modules_from_containing_types.push_back(absl::StrCat(parent->name(), "_")); + parent = parent->containing_type(); + } + + // Add the modules from containing messages (rbegin/rend to get them in outer + // to inner order). + modules.insert(modules.end(), modules_from_containing_types.rbegin(), + modules_from_containing_types.rend()); + + // If there is any modules at all, push an empty string on the end so that + // we get the trailing :: + if (!modules.empty()) { + modules.push_back(""); + } + + return absl::StrJoin(modules, "::"); } std::string RustInternalModuleName(Context file) { @@ -179,19 +216,7 @@ std::string RustInternalModuleName(Context file) { } std::string GetCrateRelativeQualifiedPath(Context msg) { - std::string name = msg.desc().full_name(); - if (msg.desc().file()->package().empty()) { - return name; - } - // when computing the relative path, we don't want the package name, so we - // strip that out - name = - std::string(absl::StripPrefix(name, msg.desc().file()->package() + ".")); - // proto nesting is marked with periods in .proto files -- this gets - // translated to delimiting via _:: in terra rust - absl::StrReplaceAll({{".", "_::"}}, &name); - - return absl::StrCat(RustModule(msg), "::", name); + return absl::StrCat(RustModule(msg), msg.desc().name()); } std::string FieldInfoComment(Context field) { From 70cc55aeb229c8bf3e8962ace8cafee2d9abff59 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 3 Nov 2023 12:31:48 -0700 Subject: [PATCH 083/387] Reduce stack usage on recursion by making all error generation lazy on out-of-line functions. This avoids local std::string temporaries and alike. It also speeds up code because we delay constructing the errors via StrCat until an error has actually occurred. PiperOrigin-RevId: 579269516 --- src/google/protobuf/compiler/parser.cc | 123 ++++++++++++++----------- src/google/protobuf/compiler/parser.h | 62 ++++++++++--- 2 files changed, 117 insertions(+), 68 deletions(-) diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index a402701268..44ecc5d49b 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -201,7 +201,7 @@ bool Parser::TryConsume(absl::string_view text) { } } -bool Parser::Consume(absl::string_view text, absl::string_view error) { +bool Parser::Consume(absl::string_view text, ErrorMaker error) { if (TryConsume(text)) { return true; } else { @@ -211,10 +211,11 @@ bool Parser::Consume(absl::string_view text, absl::string_view error) { } bool Parser::Consume(absl::string_view text) { - return Consume(text, absl::StrCat("Expected \"", text, "\".")); + return Consume(text, + [&] { return absl::StrCat("Expected \"", text, "\"."); }); } -bool Parser::ConsumeIdentifier(std::string* output, absl::string_view error) { +bool Parser::ConsumeIdentifier(std::string* output, ErrorMaker error) { if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) { *output = input_->current().text; input_->Next(); @@ -225,7 +226,7 @@ bool Parser::ConsumeIdentifier(std::string* output, absl::string_view error) { } } -bool Parser::ConsumeInteger(int* output, absl::string_view error) { +bool Parser::ConsumeInteger(int* output, ErrorMaker error) { if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { uint64_t value = 0; if (!io::Tokenizer::ParseInteger(input_->current().text, @@ -243,7 +244,7 @@ bool Parser::ConsumeInteger(int* output, absl::string_view error) { } } -bool Parser::ConsumeSignedInteger(int* output, absl::string_view error) { +bool Parser::ConsumeSignedInteger(int* output, ErrorMaker error) { bool is_negative = false; uint64_t max_value = std::numeric_limits::max(); if (TryConsume("-")) { @@ -258,7 +259,7 @@ bool Parser::ConsumeSignedInteger(int* output, absl::string_view error) { } bool Parser::ConsumeInteger64(uint64_t max_value, uint64_t* output, - absl::string_view error) { + ErrorMaker error) { if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { if (!io::Tokenizer::ParseInteger(input_->current().text, max_value, output)) { @@ -283,7 +284,7 @@ bool Parser::TryConsumeInteger64(uint64_t max_value, uint64_t* output) { return false; } -bool Parser::ConsumeNumber(double* output, absl::string_view error) { +bool Parser::ConsumeNumber(double* output, ErrorMaker error) { if (LookingAtType(io::Tokenizer::TYPE_FLOAT)) { *output = io::Tokenizer::ParseFloat(input_->current().text); input_->Next(); @@ -320,7 +321,7 @@ bool Parser::ConsumeNumber(double* output, absl::string_view error) { } } -bool Parser::ConsumeString(std::string* output, absl::string_view error) { +bool Parser::ConsumeString(std::string* output, ErrorMaker error) { if (LookingAtType(io::Tokenizer::TYPE_STRING)) { io::Tokenizer::ParseString(input_->current().text, output); input_->Next(); @@ -372,32 +373,34 @@ bool Parser::ConsumeEndOfDeclaration(absl::string_view text, if (TryConsumeEndOfDeclaration(text, location)) { return true; } else { - RecordError(absl::StrCat("Expected \"", text, "\".")); + RecordError([&] { return absl::StrCat("Expected \"", text, "\"."); }); return false; } } // ------------------------------------------------------------------- -void Parser::RecordError(int line, int column, absl::string_view error) { +void Parser::RecordError(int line, int column, ErrorMaker error) { if (error_collector_ != nullptr) { - error_collector_->RecordError(line, column, error); + error_collector_->RecordError(line, column, error.get()); } had_errors_ = true; } -void Parser::RecordError(absl::string_view error) { +void Parser::RecordError(ErrorMaker error) { RecordError(input_->current().line, input_->current().column, error); } -void Parser::RecordWarning(int line, int column, absl::string_view warning) { +void Parser::RecordWarning(int line, int column, ErrorMaker error) { if (error_collector_ != nullptr) { - error_collector_->RecordWarning(line, column, warning); + error_collector_->RecordWarning(line, column, error.get()); } } -void Parser::RecordWarning(absl::string_view warning) { - RecordWarning(input_->current().line, input_->current().column, warning); +// Invokes error_collector_->RecordWarning() with the line and column number +// of the current token. +void Parser::RecordWarning(ErrorMaker error) { + RecordWarning(input_->current().line, input_->current().column, error); } // ------------------------------------------------------------------- @@ -590,12 +593,13 @@ bool Parser::ValidateEnum(const EnumDescriptorProto* proto) { } if (has_allow_alias && !allow_alias) { - std::string error = absl::StrCat( - "\"", proto->name(), - "\" declares 'option allow_alias = false;' which has no effect. " - "Please remove the declaration."); // This needlessly clutters declarations with nops. - RecordError(error); + RecordError([=] { + return absl::StrCat( + "\"", proto->name(), + "\" declares 'option allow_alias = false;' which has no effect. " + "Please remove the declaration."); + }); return false; } @@ -611,14 +615,15 @@ bool Parser::ValidateEnum(const EnumDescriptorProto* proto) { } } if (allow_alias && !has_duplicates) { - std::string error = absl::StrCat( - "\"", proto->name(), - "\" declares support for enum aliases but no enum values share field " - "numbers. Please remove the unnecessary 'option allow_alias = true;' " - "declaration."); // Generate an error if an enum declares support for duplicate enum values // and does not use it protect future authors. - RecordError(error); + RecordError([=] { + return absl::StrCat( + "\"", proto->name(), + "\" declares support for enum aliases but no enum values share field " + "numbers. Please remove the unnecessary 'option allow_alias = true;' " + "declaration."); + }); return false; } @@ -627,9 +632,13 @@ bool Parser::ValidateEnum(const EnumDescriptorProto* proto) { if (!allow_alias) { for (const auto& enum_value : proto->value()) { if (!IsUpperUnderscore(enum_value.name())) { - RecordWarning(absl::StrCat( - "Enum constant should be in UPPER_CASE. Found: ", enum_value.name(), - ". See https://developers.google.com/protocol-buffers/docs/style")); + RecordWarning([&] { + return absl::StrCat( + "Enum constant should be in UPPER_CASE. Found: ", + enum_value.name(), + ". See " + "https://developers.google.com/protocol-buffers/docs/style"); + }); } } } @@ -732,8 +741,9 @@ bool Parser::ParseSyntaxIdentifier(const FileDescriptorProto* file, if (has_edition) { if (!Edition_Parse(absl::StrCat("EDITION_", syntax), &edition_) || edition_ < Edition::EDITION_2023) { - RecordError(syntax_token.line, syntax_token.column, - absl::StrCat("Unknown edition \"", syntax, "\".")); + RecordError(syntax_token.line, syntax_token.column, [&] { + return absl::StrCat("Unknown edition \"", syntax, "\"."); + }); return false; } syntax_identifier_ = "editions"; @@ -743,10 +753,11 @@ bool Parser::ParseSyntaxIdentifier(const FileDescriptorProto* file, syntax_identifier_ = syntax; if (syntax != "proto2" && syntax != "proto3" && !stop_after_syntax_identifier_) { - RecordError(syntax_token.line, syntax_token.column, - absl::StrCat("Unrecognized syntax identifier \"", syntax, - "\". This parser " - "only recognizes \"proto2\" and \"proto3\".")); + RecordError(syntax_token.line, syntax_token.column, [&] { + return absl::StrCat("Unrecognized syntax identifier \"", syntax, + "\". This parser " + "only recognizes \"proto2\" and \"proto3\"."); + }); return false; } @@ -847,9 +858,12 @@ bool Parser::ParseMessageDefinition( DescriptorPool::ErrorCollector::NAME); DO(ConsumeIdentifier(message->mutable_name(), "Expected message name.")); if (!IsUpperCamelCase(message->name())) { - RecordWarning(absl::StrCat( - "Message name should be in UpperCamelCase. Found: ", message->name(), - ". See https://developers.google.com/protocol-buffers/docs/style")); + RecordWarning([=] { + return absl::StrCat( + "Message name should be in UpperCamelCase. Found: ", + message->name(), + ". See https://developers.google.com/protocol-buffers/docs/style"); + }); } } DO(ParseMessageBlock(message, message_location, containing_file)); @@ -1080,15 +1094,19 @@ bool Parser::ParseMessageFieldNoLabel( DO(ConsumeIdentifier(field->mutable_name(), "Expected field name.")); if (!IsLowerUnderscore(field->name())) { - RecordWarning(absl::StrCat( - "Field name should be lowercase. Found: ", field->name(), - ". See: https://developers.google.com/protocol-buffers/docs/style")); + RecordWarning([=] { + return absl::StrCat( + "Field name should be lowercase. Found: ", field->name(), + ". See: https://developers.google.com/protocol-buffers/docs/style"); + }); } if (IsNumberFollowUnderscore(field->name())) { - RecordWarning(absl::StrCat( - "Number should not come right after an underscore. Found: ", - field->name(), - ". See: https://developers.google.com/protocol-buffers/docs/style")); + RecordWarning([=] { + return absl::StrCat( + "Number should not come right after an underscore. Found: ", + field->name(), + ". See: https://developers.google.com/protocol-buffers/docs/style"); + }); } } DO(Consume("=", "Missing field number.")); @@ -1819,18 +1837,17 @@ bool Parser::ParseReserved(DescriptorProto* message, } } -bool Parser::ParseReservedName(std::string* name, - absl::string_view error_message) { +bool Parser::ParseReservedName(std::string* name, ErrorMaker error_message) { // Capture the position of the token, in case we have to report an // error after it is consumed. int line = input_->current().line; int col = input_->current().column; DO(ConsumeString(name, error_message)); if (!io::Tokenizer::IsIdentifier(*name)) { - RecordWarning( - line, col, - absl::StrFormat("Reserved name \"%s\" is not a valid identifier.", - *name)); + RecordWarning(line, col, [=] { + return absl::StrFormat("Reserved name \"%s\" is not a valid identifier.", + *name); + }); } return true; } @@ -1847,7 +1864,7 @@ bool Parser::ParseReservedNames(DescriptorProto* message, } bool Parser::ParseReservedIdentifier(std::string* name, - absl::string_view error_message) { + ErrorMaker error_message) { DO(ConsumeIdentifier(name, error_message)); return true; } diff --git a/src/google/protobuf/compiler/parser.h b/src/google/protobuf/compiler/parser.h index f3e6460a7e..7ed020f7dc 100644 --- a/src/google/protobuf/compiler/parser.h +++ b/src/google/protobuf/compiler/parser.h @@ -16,6 +16,7 @@ #include #include +#include #include #include "absl/container/flat_hash_map.h" @@ -139,33 +140,65 @@ class PROTOBUF_EXPORT Parser { // true. Otherwise, return false without logging an error. bool TryConsume(absl::string_view text); + // In the following functions the error is passed as a lazily evaluated + // callable to reduce stack usage and delay the actual execution of the error + // statement. + // Super simple type erasure interface. Similar to absl::FunctionRef but takes + // the callable by value. Optimized for lambdas with at most a single pointer + // as payload. + class ErrorMaker { + using StorageT = void*; + + public: + template ()())>::value>> + ErrorMaker(F f) { + static_assert(sizeof(F) <= sizeof(StorageT), ""); + static_assert(alignof(F) <= alignof(StorageT), ""); + static_assert(std::is_trivially_destructible::value, ""); + ::new (static_cast(storage_)) F(f); + func_ = [](const void* p) { return (*reinterpret_cast(p))(); }; + } + // This overload helps callers that just want to pass a literal string. + ErrorMaker(const char* error) : error_(error), func_(nullptr) {} + + std::string get() const { return func_ ? func_(storage_) : error_; } + + private: + union { + alignas(StorageT) char storage_[sizeof(StorageT)]; + const char* error_; + }; + std::string (*func_)(const void*); + }; + // These attempt to read some kind of token from the input. If successful, // they return true. Otherwise they return false and add the given error // to the error list. // Consume a token with the exact text given. - bool Consume(absl::string_view text, absl::string_view error); + bool Consume(absl::string_view text, ErrorMaker error); // Same as above, but automatically generates the error "Expected \"text\".", // where "text" is the expected token text. bool Consume(absl::string_view text); // Consume a token of type IDENTIFIER and store its text in "output". - bool ConsumeIdentifier(std::string* output, absl::string_view error); + bool ConsumeIdentifier(std::string* output, ErrorMaker error); // Consume an integer and store its value in "output". - bool ConsumeInteger(int* output, absl::string_view error); + bool ConsumeInteger(int* output, ErrorMaker error); // Consume a signed integer and store its value in "output". - bool ConsumeSignedInteger(int* output, absl::string_view error); + bool ConsumeSignedInteger(int* output, ErrorMaker error); // Consume a 64-bit integer and store its value in "output". If the value // is greater than max_value, an error will be reported. - bool ConsumeInteger64(uint64_t max_value, uint64_t* output, - absl::string_view error); + bool ConsumeInteger64(uint64_t max_value, uint64_t* output, ErrorMaker error); // Try to consume a 64-bit integer and store its value in "output". No // error is reported on failure, allowing caller to consume token another way. bool TryConsumeInteger64(uint64_t max_value, uint64_t* output); // Consume a number and store its value in "output". This will accept // tokens of either INTEGER or FLOAT type. - bool ConsumeNumber(double* output, absl::string_view error); + bool ConsumeNumber(double* output, ErrorMaker error); // Consume a string literal and store its (unescaped) value in "output". - bool ConsumeString(std::string* output, absl::string_view error); + bool ConsumeString(std::string* output, ErrorMaker error); // Consume a token representing the end of the statement. Comments between // this token and the next will be harvested for documentation. The given @@ -188,18 +221,18 @@ class PROTOBUF_EXPORT Parser { // Error logging helpers // Invokes error_collector_->RecordError(), if error_collector_ is not NULL. - void RecordError(int line, int column, absl::string_view error); + PROTOBUF_NOINLINE void RecordError(int line, int column, ErrorMaker error); // Invokes error_collector_->RecordError() with the line and column number // of the current token. - void RecordError(absl::string_view error); + PROTOBUF_NOINLINE void RecordError(ErrorMaker error); // Invokes error_collector_->RecordWarning(), if error_collector_ is not NULL. - void RecordWarning(int line, int column, absl::string_view warning); + PROTOBUF_NOINLINE void RecordWarning(int line, int column, ErrorMaker error); // Invokes error_collector_->RecordWarning() with the line and column number // of the current token. - void RecordWarning(absl::string_view warning); + PROTOBUF_NOINLINE void RecordWarning(ErrorMaker error); // Records a location in the SourceCodeInfo.location table (see // descriptor.proto). We use RAII to ensure that the start and end locations @@ -379,11 +412,10 @@ class PROTOBUF_EXPORT Parser { const LocationRecorder& message_location); bool ParseReservedNames(DescriptorProto* message, const LocationRecorder& parent_location); - bool ParseReservedName(std::string* name, absl::string_view error_message); + bool ParseReservedName(std::string* name, ErrorMaker error_message); bool ParseReservedIdentifiers(DescriptorProto* message, const LocationRecorder& parent_location); - bool ParseReservedIdentifier(std::string* name, - absl::string_view error_message); + bool ParseReservedIdentifier(std::string* name, ErrorMaker error_message); bool ParseReservedNumbers(DescriptorProto* message, const LocationRecorder& parent_location); bool ParseReserved(EnumDescriptorProto* message, From c1e0853f7047494af39388f72d80cfe14336bf27 Mon Sep 17 00:00:00 2001 From: marner2 Date: Fri, 3 Nov 2023 14:57:25 -0700 Subject: [PATCH 084/387] Fix csharp fieldmasktree merge null checking (#12737) Fixes #12685 for CSharp, but the Java equivalent probably has the same bug. Closes #12737 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/12737 from marner2:fix_csharp_fieldmasktree_merge_null_checking 78c7812ac37d5e31b889a725459a726a7e121058 PiperOrigin-RevId: 579314424 --- csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs | 6 ++++++ csharp/src/Google.Protobuf/FieldMaskTree.cs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs b/csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs index 380ef72d37..d477cb35b1 100644 --- a/csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs +++ b/csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs @@ -406,6 +406,12 @@ namespace Google.Protobuf Merge(new FieldMaskTree().AddFieldPath("payload.single_int32"), sourceWithPayloadInt32Unset, destination, options, useDynamicMessage); Assert.IsNotNull(destination.Payload); + + // Clear unset primitive fields even if source payload is cleared + destination = source.Clone(); + Merge(new FieldMaskTree().AddFieldPath("payload.single_int32"), + clearedSource, destination, options, useDynamicMessage); + Assert.AreEqual(0, destination.Payload.SingleInt32); } [Test] diff --git a/csharp/src/Google.Protobuf/FieldMaskTree.cs b/csharp/src/Google.Protobuf/FieldMaskTree.cs index aaa780ba92..b8a8fff586 100644 --- a/csharp/src/Google.Protobuf/FieldMaskTree.cs +++ b/csharp/src/Google.Protobuf/FieldMaskTree.cs @@ -270,6 +270,13 @@ namespace Google.Protobuf field.Accessor.SetValue(destination, destinationField); } + if (sourceField == null) + { + // If the message field is not present in the source but is in the destination, create an empty one + // so we can properly handle child entries + sourceField = field.MessageType.Parser.CreateTemplate(); + } + var childPath = path.Length == 0 ? entry.Key : path + "." + entry.Key; Merge(entry.Value, childPath, (IMessage)sourceField, (IMessage)destinationField, options); continue; From c69dd68fb1d1bbb8bb8d2ec03019e18c12b9e5d7 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 3 Nov 2023 15:24:57 -0700 Subject: [PATCH 085/387] Implement feature inheritance and legacy editions for upb. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This switches upb to using legacy editions for all proto2/proto3 logic. This does not yet enable code generation for editions protos (ie. we do not yet turn on `FEATURE_SUPPORTS_EDITIONS`), but with feature inheritance in place, this will be a much smaller follow-on change. There is a ~10% increase in allocations, but only a ~1% increase in peak memory. There are some <5% increases in instructions and cycles, but apparently no increase in time: ``` name old cpu/op new cpu/op delta BM_ArenaOneAlloc 17.8ns ±11% 16.9ns ±17% ~ (p=0.310 n=5+5) BM_ArenaInitialBlockOneAlloc 5.99ns ±13% 5.35ns ± 2% ~ (p=0.421 n=5+5) BM_ArenaFuseUnbalanced/2 71.4ns ±11% 63.1ns ± 3% ~ (p=0.095 n=5+5) BM_ArenaFuseUnbalanced/8 509ns ± 2% 532ns ±15% ~ (p=0.421 n=5+5) BM_ArenaFuseUnbalanced/64 4.73µs ±20% 4.43µs ±10% ~ (p=0.841 n=5+5) BM_ArenaFuseUnbalanced/128 9.77µs ±12% 8.64µs ± 4% ~ (p=0.095 n=5+5) BM_ArenaFuseBalanced/2 67.5ns ±13% 62.6ns ± 3% ~ (p=0.841 n=5+5) BM_ArenaFuseBalanced/8 552ns ±23% 496ns ±25% ~ (p=0.222 n=5+5) BM_ArenaFuseBalanced/64 4.76µs ±14% 4.24µs ± 4% ~ (p=0.421 n=5+5) BM_ArenaFuseBalanced/128 10.2µs ±14% 8.6µs ± 4% -15.61% (p=0.016 n=5+5) BM_LoadAdsDescriptor_Upb 6.20ms ±12% 6.18ms ±16% ~ (p=0.421 n=5+5) BM_LoadAdsDescriptor_Upb 6.91ms ±12% 6.63ms ± 3% ~ (p=0.690 n=5+5) BM_LoadAdsDescriptor_Proto2 15.0ms ±12% 13.7ms ± 3% ~ (p=0.421 n=5+5) BM_LoadAdsDescriptor_Proto2 15.1ms ±13% 13.8ms ± 3% ~ (p=0.548 n=5+5) BM_Parse_Upb_FileDesc 14.4µs ±13% 13.2µs ± 3% ~ (p=0.548 n=5+5) BM_Parse_Upb_FileDesc 12.8µs ±12% 11.8µs ± 3% ~ (p=0.222 n=5+5) BM_Parse_Upb_FileDesc 13.7µs ±12% 12.9µs ± 3% ~ (p=1.000 n=5+5) BM_Parse_Upb_FileDesc 13.1µs ±11% 11.6µs ± 3% ~ (p=0.056 n=5+5) BM_Parse_Proto2 24.7µs ±12% 22.6µs ± 8% ~ (p=0.310 n=5+5) BM_Parse_Proto2 11.6µs ±13% 10.9µs ± 2% ~ (p=1.000 n=5+5) BM_Parse_Proto2 11.7µs ±10% 10.6µs ± 3% ~ (p=0.310 n=5+5) BM_Parse_Proto2 13.4µs ±12% 12.3µs ± 4% ~ (p=0.310 n=5+5) BM_SerializeDescriptor_Proto2 6.62µs ±13% 6.00µs ± 6% ~ (p=0.056 n=5+5) BM_SerializeDescriptor_Upb 11.1µs ±13% 10.3µs ± 3% ~ (p=1.000 n=5+5) name old time/op new time/op delta BM_ArenaOneAlloc 17.9ns ±12% 17.0ns ±17% ~ (p=0.310 n=5+5) BM_ArenaInitialBlockOneAlloc 6.03ns ±14% 5.36ns ± 2% ~ (p=0.421 n=5+5) BM_ArenaFuseUnbalanced/2 71.9ns ±12% 63.3ns ± 3% ~ (p=0.095 n=5+5) BM_ArenaFuseUnbalanced/8 511ns ± 2% 533ns ±15% ~ (p=0.421 n=5+5) BM_ArenaFuseUnbalanced/64 4.75µs ±20% 4.44µs ±10% ~ (p=0.841 n=5+5) BM_ArenaFuseUnbalanced/128 9.83µs ±12% 8.66µs ± 4% ~ (p=0.151 n=5+5) BM_ArenaFuseBalanced/2 67.8ns ±13% 62.7ns ± 3% ~ (p=0.841 n=5+5) BM_ArenaFuseBalanced/8 555ns ±24% 497ns ±26% ~ (p=0.222 n=5+5) BM_ArenaFuseBalanced/64 4.79µs ±14% 4.25µs ± 4% ~ (p=0.310 n=5+5) BM_ArenaFuseBalanced/128 10.3µs ±14% 8.6µs ± 4% -15.93% (p=0.016 n=5+5) BM_LoadAdsDescriptor_Upb 6.25ms ±12% 6.20ms ±16% ~ (p=0.421 n=5+5) BM_LoadAdsDescriptor_Upb 6.96ms ±13% 6.65ms ± 3% ~ (p=0.690 n=5+5) BM_LoadAdsDescriptor_Proto2 15.2ms ±12% 13.7ms ± 3% ~ (p=0.421 n=5+5) BM_LoadAdsDescriptor_Proto2 15.3ms ±14% 13.8ms ± 3% ~ (p=0.548 n=5+5) BM_Parse_Upb_FileDesc 14.5µs ±14% 13.2µs ± 3% ~ (p=0.690 n=5+5) BM_Parse_Upb_FileDesc 12.8µs ±12% 11.8µs ± 3% ~ (p=0.222 n=5+5) BM_Parse_Upb_FileDesc 13.8µs ±13% 13.0µs ± 3% ~ (p=1.000 n=5+5) BM_Parse_Upb_FileDesc 13.2µs ±12% 11.6µs ± 3% ~ (p=0.056 n=5+5) BM_Parse_Proto2 24.9µs ±12% 22.6µs ± 8% ~ (p=0.310 n=5+5) BM_Parse_Proto2 11.7µs ±14% 10.9µs ± 2% ~ (p=1.000 n=5+5) BM_Parse_Proto2 11.7µs ±11% 10.7µs ± 3% ~ (p=0.222 n=5+5) BM_Parse_Proto2 13.5µs ±12% 12.3µs ± 4% ~ (p=0.310 n=5+5) BM_SerializeDescriptor_Proto2 6.65µs ±13% 6.01µs ± 6% ~ (p=0.056 n=5+5) BM_SerializeDescriptor_Upb 11.2µs ±13% 10.3µs ± 3% ~ (p=1.000 n=5+5) name old INSTRUCTIONS/op new INSTRUCTIONS/op delta BM_ArenaOneAlloc 189 ± 0% 189 ± 0% ~ (p=0.881 n=5+5) BM_ArenaInitialBlockOneAlloc 69.0 ± 0% 69.0 ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/2 458 ± 0% 458 ± 0% ~ (p=1.000 n=5+5) BM_ArenaFuseUnbalanced/8 3.28k ±15% 3.60k ± 0% ~ (p=0.286 n=5+4) BM_ArenaFuseUnbalanced/64 28.6k ± 2% 29.2k ± 0% +2.17% (p=0.032 n=5+4) BM_ArenaFuseUnbalanced/128 57.9k ± 1% 57.9k ± 1% ~ (p=1.000 n=5+5) BM_ArenaFuseBalanced/2 482 ± 0% 482 ± 0% ~ (p=0.421 n=5+5) BM_ArenaFuseBalanced/8 3.35k ±14% 3.35k ±14% ~ (p=0.841 n=5+5) BM_ArenaFuseBalanced/64 29.2k ± 2% 29.3k ± 1% ~ (p=0.421 n=5+5) BM_ArenaFuseBalanced/128 59.2k ± 1% 59.3k ± 1% ~ (p=0.556 n=4+5) BM_LoadAdsDescriptor_Upb 37.3M ± 0% 38.2M ± 0% +2.39% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Upb 40.9M ± 0% 41.7M ± 0% +2.02% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Proto2 87.2M ± 0% 88.3M ± 1% +1.25% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Proto2 88.0M ± 0% 88.9M ± 1% +1.13% (p=0.016 n=5+5) BM_Parse_Upb_FileDesc 154k ± 0% 154k ± 0% ~ (p=1.000 n=5+5) BM_Parse_Upb_FileDesc 143k ± 0% 143k ± 0% ~ (p=0.310 n=5+5) BM_Parse_Upb_FileDesc 153k ± 0% 153k ± 0% ~ (p=1.016 n=5+4) BM_Parse_Upb_FileDesc 142k ± 0% 142k ± 0% ~ (p=0.127 n=5+5) BM_Parse_Proto2 213k ± 1% 217k ± 5% ~ (p=1.000 n=5+5) BM_Parse_Proto2 122k ± 0% 123k ± 0% +0.86% (p=0.008 n=5+5) BM_Parse_Proto2 120k ± 0% 120k ± 0% ~ (p=0.421 n=5+5) BM_Parse_Proto2 124k ± 0% 124k ± 0% ~ (p=0.587 n=5+5) BM_SerializeDescriptor_Proto2 63.5k ± 0% 63.5k ± 0% ~ (p=0.278 n=5+5) BM_SerializeDescriptor_Upb 111k ± 0% 111k ± 0% ~ (p=1.000 n=5+5) name old CYCLES/op new CYCLES/op delta BM_ArenaOneAlloc 53.5 ± 0% 53.4 ± 0% ~ (p=0.095 n=5+5) BM_ArenaInitialBlockOneAlloc 17.5 ± 1% 17.4 ± 0% ~ (p=0.087 n=5+5) BM_ArenaFuseUnbalanced/2 206 ± 0% 206 ± 0% ~ (p=0.548 n=5+5) BM_ArenaFuseUnbalanced/8 1.55k ±12% 1.67k ± 1% ~ (p=0.548 n=5+5) BM_ArenaFuseUnbalanced/64 14.1k ± 8% 14.1k ± 1% ~ (p=0.222 n=5+5) BM_ArenaFuseUnbalanced/128 28.2k ± 1% 28.3k ± 1% ~ (p=0.548 n=5+5) BM_ArenaFuseBalanced/2 205 ± 0% 204 ± 0% ~ (p=0.548 n=5+5) BM_ArenaFuseBalanced/8 1.57k ±12% 1.56k ±12% ~ (p=0.421 n=5+5) BM_ArenaFuseBalanced/64 13.9k ± 2% 13.9k ± 1% ~ (p=1.000 n=5+5) BM_ArenaFuseBalanced/128 28.1k ± 1% 28.2k ± 1% ~ (p=0.730 n=4+5) BM_LoadAdsDescriptor_Upb 18.7M ± 0% 19.3M ± 1% +3.38% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Upb 20.9M ± 0% 21.6M ± 0% +3.09% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Proto2 43.4M ± 0% 44.4M ± 1% +2.33% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Proto2 44.0M ± 0% 44.9M ± 2% +1.92% (p=0.016 n=5+5) BM_Parse_Upb_FileDesc 42.0k ± 1% 43.0k ± 1% +2.32% (p=0.008 n=5+5) BM_Parse_Upb_FileDesc 38.2k ± 1% 38.4k ± 0% +0.74% (p=0.032 n=5+5) BM_Parse_Upb_FileDesc 41.6k ± 0% 42.6k ± 1% +2.51% (p=0.008 n=5+5) BM_Parse_Upb_FileDesc 37.6k ± 0% 38.1k ± 0% +1.34% (p=0.008 n=5+5) BM_Parse_Proto2 71.9k ± 1% 74.1k ± 6% ~ (p=1.000 n=5+5) BM_Parse_Proto2 35.4k ± 1% 35.8k ± 0% +1.10% (p=0.008 n=5+5) BM_Parse_Proto2 34.6k ± 1% 34.9k ± 1% ~ (p=0.095 n=5+5) BM_Parse_Proto2 40.5k ± 0% 40.0k ± 1% -1.36% (p=0.008 n=5+5) BM_SerializeDescriptor_Proto2 20.1k ± 1% 19.7k ± 4% ~ (p=0.421 n=5+5) BM_SerializeDescriptor_Upb 33.7k ± 0% 33.7k ± 0% ~ (p=0.222 n=5+5) name old allocs/op new allocs/op delta BM_ArenaOneAlloc 1.00 ± 0% 1.00 ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/2 2.00 ± 0% 2.00 ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/8 8.00 ± 0% 8.00 ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/64 64.0 ± 0% 64.0 ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/128 128 ± 0% 128 ± 0% ~ (all samples are equal) BM_ArenaFuseBalanced/2 2.00 ± 0% 2.00 ± 0% ~ (all samples are equal) BM_ArenaFuseBalanced/8 8.00 ± 0% 8.00 ± 0% ~ (all samples are equal) BM_ArenaFuseBalanced/64 64.0 ± 0% 64.0 ± 0% ~ (all samples are equal) BM_ArenaFuseBalanced/128 128 ± 0% 128 ± 0% ~ (all samples are equal) BM_LoadAdsDescriptor_Upb 6.21k ± 0% 6.93k ± 0% +11.54% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Upb 6.54k ± 0% 6.96k ± 0% +6.34% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Proto2 124k ± 0% 124k ± 0% +0.00% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Proto2 126k ± 0% 126k ± 0% +0.00% (p=0.008 n=5+5) BM_Parse_Upb_FileDesc 7.00 ± 0% 7.00 ± 0% ~ (all samples are equal) BM_Parse_Upb_FileDesc 7.00 ± 0% 7.00 ± 0% ~ (all samples are equal) BM_Parse_Proto2 709 ± 0% 709 ± 0% ~ (all samples are equal) BM_Parse_Proto2 8.00 ± 0% 8.00 ± 0% ~ (all samples are equal) name old peak-mem(Bytes)/op new peak-mem(Bytes)/op delta BM_ArenaOneAlloc 328 ± 0% 328 ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/2 656 ± 0% 656 ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/8 2.62k ± 0% 2.62k ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/64 21.0k ± 0% 21.0k ± 0% ~ (all samples are equal) BM_ArenaFuseUnbalanced/128 42.0k ± 0% 42.0k ± 0% ~ (all samples are equal) BM_ArenaFuseBalanced/2 656 ± 0% 656 ± 0% ~ (all samples are equal) BM_ArenaFuseBalanced/8 2.62k ± 0% 2.62k ± 0% ~ (all samples are equal) BM_ArenaFuseBalanced/64 21.0k ± 0% 21.0k ± 0% ~ (all samples are equal) BM_ArenaFuseBalanced/128 42.0k ± 0% 42.0k ± 0% ~ (all samples are equal) BM_LoadAdsDescriptor_Upb 10.2M ± 0% 10.4M ± 0% +1.15% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Upb 10.5M ± 0% 10.5M ± 0% +0.11% (p=0.008 n=5+5) BM_LoadAdsDescriptor_Proto2 7.14M ± 0% 7.14M ± 0% ~ (p=0.317 n=4+5) BM_LoadAdsDescriptor_Proto2 7.18M ± 0% 7.18M ± 0% ~ (p=0.159 n=5+4) BM_Parse_Upb_FileDesc 36.5k ± 0% 36.5k ± 0% ~ (all samples are equal) BM_Parse_Upb_FileDesc 36.5k ± 0% 36.5k ± 0% ~ (all samples are equal) BM_Parse_Proto2 35.4k ± 0% 35.4k ± 0% ~ (all samples are equal) BM_Parse_Proto2 65.3k ± 0% 65.3k ± 0% ~ (all samples are equal) name old items/s new items/s delta BM_ArenaFuseUnbalanced/2 28.2M ±12% 31.7M ± 3% ~ (p=0.095 n=5+5) BM_ArenaFuseUnbalanced/8 15.7M ± 2% 15.1M ±14% ~ (p=0.421 n=5+5) BM_ArenaFuseUnbalanced/64 13.7M ±18% 14.5M ± 9% ~ (p=0.841 n=5+5) BM_ArenaFuseUnbalanced/128 13.2M ±12% 14.8M ± 5% ~ (p=0.095 n=5+5) BM_ArenaFuseBalanced/2 29.9M ±12% 32.0M ± 3% ~ (p=0.841 n=5+5) BM_ArenaFuseBalanced/8 14.8M ±28% 16.5M ±22% ~ (p=0.222 n=5+5) BM_ArenaFuseBalanced/64 13.6M ±15% 15.1M ± 4% ~ (p=0.421 n=5+5) BM_ArenaFuseBalanced/128 12.6M ±15% 14.9M ± 4% +17.88% (p=0.016 n=5+5) name old speed new speed delta BM_LoadAdsDescriptor_Upb 128MB/s ±11% 128MB/s ±14% ~ (p=0.421 n=5+5) BM_LoadAdsDescriptor_Upb 115MB/s ±12% 119MB/s ± 3% ~ (p=0.690 n=5+5) BM_LoadAdsDescriptor_Proto2 52.9MB/s ±12% 57.6MB/s ± 3% ~ (p=0.421 n=5+5) BM_LoadAdsDescriptor_Proto2 52.6MB/s ±14% 57.2MB/s ± 2% ~ (p=0.548 n=5+5) BM_Parse_Upb_FileDesc 527MB/s ±14% 571MB/s ± 3% ~ (p=0.548 n=5+5) BM_Parse_Upb_FileDesc 595MB/s ±11% 640MB/s ± 3% ~ (p=0.222 n=5+5) BM_Parse_Upb_FileDesc 553MB/s ±12% 582MB/s ± 3% ~ (p=1.000 n=5+5) BM_Parse_Upb_FileDesc 576MB/s ±12% 649MB/s ± 3% ~ (p=0.056 n=5+5) BM_Parse_Proto2 307MB/s ±13% 334MB/s ± 8% ~ (p=0.310 n=5+5) BM_Parse_Proto2 653MB/s ±13% 689MB/s ± 2% ~ (p=1.000 n=5+5) BM_Parse_Proto2 650MB/s ±10% 708MB/s ± 3% ~ (p=0.310 n=5+5) BM_Parse_Proto2 564MB/s ±12% 614MB/s ± 4% ~ (p=0.310 n=5+5) BM_SerializeDescriptor_Proto2 1.15GB/s ±12% 1.25GB/s ± 5% ~ (p=0.056 n=5+5) BM_SerializeDescriptor_Upb 684MB/s ±12% 730MB/s ± 3% ~ (p=1.000 n=5+5) ``` This adds about 5Ki of code size. Some of this likely comes from the fact that we now link in `message/copy.c` to perform a deep copy of a FeatureSet proto. ``` $ /google/bin/releases/protobuf-team/bloaty/bloaty-google3-diff --blaze-build-opts="-c opt" third_party/upb/upb/conformance/conformance_upb FILE SIZE VM SIZE -------------- -------------- +0.5% +4.19Ki +0.5% +4.19Ki .text +0.4% +656 +0.4% +656 .rodata +0.1% +504 [ = ] 0 .strtab +0.2% +384 [ = ] 0 .symtab +0.2% +280 +0.2% +280 .eh_frame +0.2% +216 +0.2% +216 .rela.dyn +0.3% +96 +0.3% +96 .data.rel.ro +0.2% +64 +0.2% +64 .eh_frame_hdr +1.1% +16 [ = ] 0 .got.plt +0.2% +8 +0.2% +8 .rela.plt -4.6% -8 -4.6% -8 [LOAD #2 [RX]] -50.0% -48 [ = ] 0 [Unmapped] [ = ] 0 -81.7% -1.47Ki .relro_padding +0.1% +6.30Ki +0.0% +4.00Ki TOTAL ``` PiperOrigin-RevId: 579321454 --- src/google/protobuf/compiler/BUILD.bazel | 1 + upb/BUILD | 3 + upb/port/def.inc | 5 + upb/port/undef.inc | 1 + upb/reflection/BUILD | 36 ++++ upb/reflection/def_pool.c | 21 +- upb/reflection/def_pool.h | 3 + upb/reflection/enum_def.c | 40 ++-- upb/reflection/enum_def.h | 1 + upb/reflection/enum_value_def.c | 52 +++-- upb/reflection/enum_value_def.h | 2 + upb/reflection/extension_range.c | 18 +- upb/reflection/extension_range.h | 2 + upb/reflection/field_def.c | 184 +++++++++++------- upb/reflection/field_def.h | 2 + upb/reflection/file_def.c | 62 +++++- upb/reflection/file_def.h | 1 + upb/reflection/internal/def_builder.c | 74 +++++++ upb/reflection/internal/def_builder.h | 23 +++ upb/reflection/internal/enum_def.h | 9 +- upb/reflection/internal/enum_reserved_range.h | 2 +- upb/reflection/internal/enum_value_def.h | 3 +- upb/reflection/internal/extension_range.h | 4 +- upb/reflection/internal/field_def.h | 19 +- upb/reflection/internal/message_def.h | 9 +- upb/reflection/internal/method_def.h | 8 +- upb/reflection/internal/oneof_def.h | 8 +- upb/reflection/internal/service_def.h | 8 +- .../internal/upb_edition_defaults.h | 20 ++ .../internal/upb_edition_defaults.h.template | 20 ++ upb/reflection/message_def.c | 53 +++-- upb/reflection/message_def.h | 2 + upb/reflection/method_def.c | 24 ++- upb/reflection/method_def.h | 2 + upb/reflection/oneof_def.c | 26 +-- upb/reflection/oneof_def.h | 4 +- upb/reflection/service_def.c | 33 ++-- upb/reflection/service_def.h | 2 + upb/util/required_fields.c | 2 +- 39 files changed, 593 insertions(+), 196 deletions(-) create mode 100644 upb/reflection/internal/upb_edition_defaults.h create mode 100644 upb/reflection/internal/upb_edition_defaults.h.template diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index f98c31785b..45afef2a93 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -164,6 +164,7 @@ cc_binary( copts = COPTS, visibility = [ "//src/google/protobuf:__subpackages__", + "//upb:__subpackages__", ], deps = [ ":command_line_interface", diff --git a/upb/BUILD b/upb/BUILD index 1e52a8092b..ff5d6defc7 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -406,6 +406,7 @@ upb_amalgamation( ":mem_internal", ":message", ":message_accessors", + ":message_copy", ":message_internal", ":message_internal_types", ":message_tagged_ptr", @@ -456,6 +457,7 @@ upb_amalgamation( ":mem_internal", ":message", ":message_accessors", + ":message_copy", ":message_internal", ":message_internal_types", ":message_tagged_ptr", @@ -506,6 +508,7 @@ upb_amalgamation( ":mem_internal", ":message", ":message_accessors", + ":message_copy", ":message_internal", ":message_internal_types", ":message_tagged_ptr", diff --git a/upb/port/def.inc b/upb/port/def.inc index f320821384..aa335c8c86 100644 --- a/upb/port/def.inc +++ b/upb/port/def.inc @@ -323,6 +323,11 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #if defined(UPB_IS_GOOGLE3) && !defined(UPB_BOOTSTRAP_STAGE0) #define UPB_DESC(sym) proto2_##sym +#define UPB_DESC_MINITABLE(sym) &proto2__##sym##_msg_init +#elif defined(UPB_BOOTSTRAP_STAGE0) +#define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) google__protobuf__##sym##_msg_init() #else #define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) &google__protobuf__##sym##_msg_init #endif diff --git a/upb/port/undef.inc b/upb/port/undef.inc index eb0e1654f8..5a1429e34c 100644 --- a/upb/port/undef.inc +++ b/upb/port/undef.inc @@ -49,6 +49,7 @@ #undef UPB_GNUC_MIN #undef UPB_DESCRIPTOR_UPB_H_FILENAME #undef UPB_DESC +#undef UPB_DESC_MINITABLE #undef UPB_IS_GOOGLE3 #undef UPB_ATOMIC #undef UPB_USE_C11_ATOMICS diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index bf0c0e4dbe..f6ea369d06 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -5,6 +5,15 @@ # license that can be found in the LICENSE file or at # https://developers.google.com/open-source/licenses/bsd +load( + "//upb/cmake:build_defs.bzl", + "staleness_test", +) +load( + "//src/google/protobuf/editions:defaults.bzl", + "compile_edition_defaults", + "embed_edition_defaults", +) load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library") load("//bazel:upb_proto_library.bzl", "upb_proto_reflection_library") @@ -108,6 +117,7 @@ bootstrap_cc_library( "internal/method_def.h", "internal/oneof_def.h", "internal/service_def.h", + "internal/upb_edition_defaults.h", "message.h", "message.hpp", "message_def.h", @@ -125,11 +135,13 @@ bootstrap_cc_library( "//upb:mem", "//upb:message", "//upb:message_accessors", + "//upb:message_copy", "//upb:message_value", "//upb:mini_descriptor", "//upb:mini_descriptor_internal", "//upb:mini_table", "//upb:port", + "//upb/base:internal", ], ) @@ -171,6 +183,30 @@ cc_test( ], ) +compile_edition_defaults( + name = "upb_edition_defaults", + srcs = [ + "//:descriptor_proto", + ], + maximum_edition = "2023", + minimum_edition = "PROTO2", +) + +embed_edition_defaults( + name = "embedded_upb_edition_defaults_generate", + defaults = "upb_edition_defaults", + output = "generated/internal/upb_edition_defaults.h", + placeholder = "DEFAULTS_VALUE", + template = "internal/upb_edition_defaults.h.template", +) + +staleness_test( + name = "bootstrap_upb_defaults_staleness_test", + outs = ["internal/upb_edition_defaults.h"], + generated_pattern = "generated/%s", + target_files = ["internal/upb_edition_defaults.h"], +) + # begin:github_only filegroup( name = "source_files", diff --git a/upb/reflection/def_pool.c b/upb/reflection/def_pool.c index 90d3beadf5..88e42ded15 100644 --- a/upb/reflection/def_pool.c +++ b/upb/reflection/def_pool.c @@ -17,6 +17,7 @@ #include "upb/reflection/internal/file_def.h" #include "upb/reflection/internal/message_def.h" #include "upb/reflection/internal/service_def.h" +#include "upb/reflection/internal/upb_edition_defaults.h" // Must be last. #include "upb/port/def.inc" @@ -27,6 +28,7 @@ struct upb_DefPool { upb_strtable files; // file_name -> (upb_FileDef*) upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) upb_ExtensionRegistry* extreg; + const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; upb_MiniTablePlatform platform; void* scratch_data; size_t scratch_size; @@ -39,6 +41,8 @@ void upb_DefPool_Free(upb_DefPool* s) { upb_gfree(s); } +static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; + upb_DefPool* upb_DefPool_New(void) { upb_DefPool* s = upb_gmalloc(sizeof(*s)); if (!s) return NULL; @@ -58,6 +62,10 @@ upb_DefPool* upb_DefPool_New(void) { if (!s->extreg) goto err; s->platform = kUpb_MiniTablePlatform_Native; + s->feature_set_defaults = UPB_DESC(FeatureSetDefaults_parse)( + serialized_defaults, sizeof(serialized_defaults) - 1, s->arena); + + if (!s->feature_set_defaults) goto err; return s; @@ -66,6 +74,11 @@ err: return NULL; } +const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { + return s->feature_set_defaults; +} + bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, const upb_FieldDef* f) { return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), @@ -279,7 +292,11 @@ static const upb_FileDef* upb_DefBuilder_AddFileToPool( remove_filedef(s, builder->file); builder->file = NULL; } - } else if (!builder->arena || !builder->tmp_arena) { + } else if (!builder->arena || !builder->tmp_arena || + !upb_strtable_init(&builder->feature_cache, 16, + builder->tmp_arena) || + !(builder->legacy_features = + UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { _upb_DefBuilder_OomErr(builder); } else { _upb_FileDef_Create(builder, file_proto); @@ -312,6 +329,8 @@ static const upb_FileDef* _upb_DefPool_AddFile( upb_DefBuilder ctx = { .symtab = s, + .tmp_buf = NULL, + .tmp_buf_size = 0, .layout = layout, .platform = s->platform, .msg_count = 0, diff --git a/upb/reflection/def_pool.h b/upb/reflection/def_pool.h index f21a0dbd2d..63cce8a080 100644 --- a/upb/reflection/def_pool.h +++ b/upb/reflection/def_pool.h @@ -26,6 +26,9 @@ UPB_API void upb_DefPool_Free(upb_DefPool* s); UPB_API upb_DefPool* upb_DefPool_New(void); +UPB_API const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s); + UPB_API const upb_MessageDef* upb_DefPool_FindMessageByName( const upb_DefPool* s, const char* sym); diff --git a/upb/reflection/enum_def.c b/upb/reflection/enum_def.c index 97fc63e9ac..8ba894f21d 100644 --- a/upb/reflection/enum_def.c +++ b/upb/reflection/enum_def.c @@ -23,7 +23,8 @@ #include "upb/port/def.inc" struct upb_EnumDef { - const UPB_DESC(EnumOptions) * opts; + const UPB_DESC(EnumOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MiniTableEnum* layout; // Only for proto2. const upb_FileDef* file; const upb_MessageDef* containing_type; // Could be merged with "file". @@ -37,8 +38,10 @@ struct upb_EnumDef { int res_range_count; int res_name_count; int32_t defaultval; - bool is_closed; bool is_sorted; // Whether all of the values are defined in ascending order. +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { @@ -140,7 +143,11 @@ const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { return _upb_EnumValueDef_At(e->values, i); } -bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { return e->is_closed; } +bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; + return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) == + UPB_DESC(FeatureSet_CLOSED); +} bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, upb_StringView* out) { @@ -209,6 +216,7 @@ static upb_StringView* _upb_EnumReservedNames_New( static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, const UPB_DESC(EnumDescriptorProto) * enum_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e) { const UPB_DESC(EnumValueDescriptorProto)* const* values; const UPB_DESC(EnumDescriptorProto_EnumReservedRange)* const* res_ranges; @@ -216,6 +224,10 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, upb_StringView name; size_t n_value, n_res_range, n_res_name; + UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); + e->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumOptions_features)(e->opts)); + // Must happen before _upb_DefBuilder_Add() e->file = _upb_DefBuilder_File(ctx); @@ -225,9 +237,6 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, _upb_DefBuilder_Add(ctx, e->full_name, _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - e->is_closed = (!UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) && - (upb_FileDef_Syntax(e->file) == kUpb_Syntax_Proto2); - values = UPB_DESC(EnumDescriptorProto_value)(enum_proto, &n_value); bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); @@ -238,8 +247,8 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, e->defaultval = 0; e->value_count = n_value; - e->values = - _upb_EnumValueDefs_New(ctx, prefix, n_value, values, e, &e->is_sorted); + e->values = _upb_EnumValueDefs_New(ctx, prefix, n_value, values, + e->resolved_features, e, &e->is_sorted); if (n_value == 0) { _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", @@ -256,11 +265,9 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, e->res_name_count = n_res_name; e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); - UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - upb_inttable_compact(&e->iton, ctx->arena); - if (e->is_closed) { + if (upb_EnumDef_IsClosed(e)) { if (ctx->layout) { UPB_ASSERT(ctx->enum_count < ctx->layout->enum_count); e->layout = ctx->layout->enums[ctx->enum_count++]; @@ -272,10 +279,11 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, } } -upb_EnumDef* _upb_EnumDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto) * const* protos, - const upb_MessageDef* containing_type) { +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type) { _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); // If a containing type is defined then get the full name from that. @@ -285,7 +293,7 @@ upb_EnumDef* _upb_EnumDefs_New( upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); for (int i = 0; i < n; i++) { - create_enumdef(ctx, name, protos[i], &e[i]); + create_enumdef(ctx, name, protos[i], parent_features, &e[i]); e[i].containing_type = containing_type; } return e; diff --git a/upb/reflection/enum_def.h b/upb/reflection/enum_def.h index 6f406f54bb..a81ce5fd11 100644 --- a/upb/reflection/enum_def.h +++ b/upb/reflection/enum_def.h @@ -40,6 +40,7 @@ bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, const char* upb_EnumDef_Name(const upb_EnumDef* e); const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e); +const UPB_DESC(FeatureSet) * upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e); upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i); int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e); diff --git a/upb/reflection/enum_value_def.c b/upb/reflection/enum_value_def.c index d06c933107..d250daade6 100644 --- a/upb/reflection/enum_value_def.c +++ b/upb/reflection/enum_value_def.c @@ -7,19 +7,27 @@ #include "upb/reflection/internal/enum_value_def.h" +#include + #include "upb/reflection/def_type.h" +#include "upb/reflection/enum_def.h" +#include "upb/reflection/enum_value_def.h" +#include "upb/reflection/file_def.h" #include "upb/reflection/internal/def_builder.h" #include "upb/reflection/internal/enum_def.h" -#include "upb/reflection/internal/file_def.h" // Must be last. #include "upb/port/def.inc" struct upb_EnumValueDef { - const UPB_DESC(EnumValueOptions) * opts; + const UPB_DESC(EnumValueOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_EnumDef* parent; const char* full_name; int32_t number; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { @@ -76,9 +84,15 @@ uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { } static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(EnumValueDescriptorProto) * + const UPB_DESC(EnumValueDescriptorProto*) val_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, upb_EnumValueDef* v) { + UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, + val_proto); + v->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumValueOptions_features)(v->opts)); + upb_StringView name = UPB_DESC(EnumValueDescriptorProto_name)(val_proto); v->parent = e; // Must happen prior to _upb_DefBuilder_Add() @@ -87,17 +101,32 @@ static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, _upb_DefBuilder_Add(ctx, v->full_name, _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, - val_proto); - bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); } +static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx, + const upb_EnumDef* e, + const upb_EnumValueDef* v, int n) { + if (upb_EnumDef_IsClosed(e) || n == 0 || v[0].number == 0) return; + + // When the special UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 is enabled, we have to + // exempt proto2 enums from this check, even when we are treating them as + // open. + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 && + upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) { + return; + } + + _upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)", + upb_EnumDef_FullName(e)); +} + // Allocate and initialize an array of |n| enum value defs owned by |e|. upb_EnumValueDef* _upb_EnumValueDefs_New( upb_DefBuilder* ctx, const char* prefix, int n, - const UPB_DESC(EnumValueDescriptorProto) * const* protos, upb_EnumDef* e, + const UPB_DESC(EnumValueDescriptorProto*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, bool* is_sorted) { _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); @@ -107,19 +136,14 @@ upb_EnumValueDef* _upb_EnumValueDefs_New( *is_sorted = true; uint32_t previous = 0; for (int i = 0; i < n; i++) { - create_enumvaldef(ctx, prefix, protos[i], e, &v[i]); + create_enumvaldef(ctx, prefix, protos[i], parent_features, e, &v[i]); const uint32_t current = v[i].number; if (previous > current) *is_sorted = false; previous = current; } - if (upb_FileDef_Syntax(ctx->file) == kUpb_Syntax_Proto3 && n > 0 && - v[0].number != 0) { - _upb_DefBuilder_Errf(ctx, - "for proto3, the first enum value must be zero (%s)", - upb_EnumDef_FullName(e)); - } + _upb_EnumValueDef_CheckZeroValue(ctx, e, v, n); return v; } diff --git a/upb/reflection/enum_value_def.h b/upb/reflection/enum_value_def.h index e95232847a..4fbbade19d 100644 --- a/upb/reflection/enum_value_def.h +++ b/upb/reflection/enum_value_def.h @@ -27,6 +27,8 @@ UPB_API const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v); UPB_API int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v); const UPB_DESC(EnumValueOptions) * upb_EnumValueDef_Options(const upb_EnumValueDef* v); +const UPB_DESC(FeatureSet) * + upb_EnumValueDef_ResolvedFeatures(const upb_EnumValueDef* e); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/extension_range.c b/upb/reflection/extension_range.c index b088ba92ed..83382de356 100644 --- a/upb/reflection/extension_range.c +++ b/upb/reflection/extension_range.c @@ -7,6 +7,9 @@ #include "upb/reflection/internal/extension_range.h" +#include + +#include "upb/reflection/extension_range.h" #include "upb/reflection/field_def.h" #include "upb/reflection/internal/def_builder.h" #include "upb/reflection/message_def.h" @@ -15,7 +18,8 @@ #include "upb/port/def.inc" struct upb_ExtensionRange { - const UPB_DESC(ExtensionRangeOptions) * opts; + const UPB_DESC(ExtensionRangeOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; int32_t start; int32_t end; }; @@ -41,12 +45,18 @@ int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ExtensionRange) * const* protos, - const upb_MessageDef* m) { + const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m) { upb_ExtensionRange* r = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); for (int i = 0; i < n; i++) { + UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, + ExtensionRangeOptions, protos[i]); + r[i].resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, + UPB_DESC(ExtensionRangeOptions_features)(r[i].opts)); + const int32_t start = UPB_DESC(DescriptorProto_ExtensionRange_start)(protos[i]); const int32_t end = UPB_DESC(DescriptorProto_ExtensionRange_end)(protos[i]); @@ -66,8 +76,6 @@ upb_ExtensionRange* _upb_ExtensionRanges_New( r[i].start = start; r[i].end = end; - UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, - ExtensionRangeOptions, protos[i]); } return r; diff --git a/upb/reflection/extension_range.h b/upb/reflection/extension_range.h index 7c3e19f005..3ddd5340e7 100644 --- a/upb/reflection/extension_range.h +++ b/upb/reflection/extension_range.h @@ -25,6 +25,8 @@ int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); const UPB_DESC(ExtensionRangeOptions) * upb_ExtensionRange_Options(const upb_ExtensionRange* r); +const UPB_DESC(FeatureSet) * + upb_ExtensionRange_ResolvedFeatures(const upb_ExtensionRange* e); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/field_def.c b/upb/reflection/field_def.c index 537d05ef85..5b67e209cc 100644 --- a/upb/reflection/field_def.c +++ b/upb/reflection/field_def.c @@ -12,6 +12,7 @@ #include #include "upb/base/descriptor_constants.h" +#include "upb/message/accessors.h" #include "upb/mini_descriptor/decode.h" #include "upb/mini_descriptor/internal/modifiers.h" #include "upb/reflection/def.h" @@ -35,7 +36,8 @@ typedef struct { } str_t; struct upb_FieldDef { - const UPB_DESC(FieldOptions) * opts; + const UPB_DESC(FieldOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_FileDef* file; const upb_MessageDef* msgdef; const char* full_name; @@ -65,13 +67,9 @@ struct upb_FieldDef { bool has_json_name; bool has_presence; bool is_extension; - bool is_packed; bool is_proto3_optional; upb_FieldType type_; upb_Label label_; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif }; upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { @@ -140,7 +138,9 @@ bool _upb_FieldDef_IsPackable(const upb_FieldDef* f) { } bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { - return _upb_FieldDef_IsPackable(f) && f->is_packed; + return _upb_FieldDef_IsPackable(f) && + UPB_DESC(FeatureSet_repeated_field_encoding(f->resolved_features)) == + UPB_DESC(FeatureSet_PACKED); } const char* upb_FieldDef_Name(const upb_FieldDef* f) { @@ -253,44 +253,21 @@ bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } -// begin:google_only -// static bool _upb_FieldDef_EnforceUtf8Option(const upb_FieldDef* f) { -// #if defined(UPB_BOOTSTRAP_STAGE0) -// return true; -// #else -// return UPB_DESC(FieldOptions_enforce_utf8)(f->opts); -// #endif -// } -// end:google_only - -// begin:github_only -static bool _upb_FieldDef_EnforceUtf8Option(const upb_FieldDef* f) { - return true; -} -// end:github_only - bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) { if (upb_FieldDef_Type(f) != kUpb_FieldType_String) return false; - return upb_FileDef_Syntax(upb_FieldDef_File(f)) == kUpb_Syntax_Proto3 - ? _upb_FieldDef_EnforceUtf8Option(f) - : false; + return UPB_DESC(FeatureSet_utf8_validation(f->resolved_features)) == + UPB_DESC(FeatureSet_VERIFY); } uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0; - switch (f->label_) { - case kUpb_Label_Optional: - if (!upb_FieldDef_HasPresence(f)) { - out |= kUpb_FieldModifier_IsProto3Singular; - } - break; - case kUpb_Label_Repeated: - out |= kUpb_FieldModifier_IsRepeated; - break; - case kUpb_Label_Required: - out |= kUpb_FieldModifier_IsRequired; - break; + if (upb_FieldDef_IsRepeated(f)) { + out |= kUpb_FieldModifier_IsRepeated; + } else if (upb_FieldDef_IsRequired(f)) { + out |= kUpb_FieldModifier_IsRequired; + } else if (!upb_FieldDef_HasPresence(f)) { + out |= kUpb_FieldModifier_IsProto3Singular; } if (_upb_FieldDef_IsClosedEnum(f)) { @@ -330,7 +307,8 @@ bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { } bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Required; + return UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED); } bool upb_FieldDef_IsString(const upb_FieldDef* f) { @@ -554,19 +532,63 @@ static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { } } +static bool _upb_FieldDef_InferLegacyFeatures( + upb_DefBuilder* ctx, upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto*) proto, + const UPB_DESC(FieldOptions*) options, upb_Syntax syntax, + UPB_DESC(FeatureSet*) features) { + bool ret = false; + + if (UPB_DESC(FieldDescriptorProto_label)(proto) == kUpb_Label_Required) { + if (syntax == kUpb_Syntax_Proto3) { + _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", + f->full_name); + } + int val = UPB_DESC(FeatureSet_LEGACY_REQUIRED); + UPB_DESC(FeatureSet_set_field_presence(features, val)); + ret = true; + } + + if (UPB_DESC(FieldDescriptorProto_type)(proto) == kUpb_FieldType_Group) { + int val = UPB_DESC(FeatureSet_DELIMITED); + UPB_DESC(FeatureSet_set_message_encoding(features, val)); + ret = true; + } + + if (UPB_DESC(FieldOptions_has_packed)(options)) { + int val = UPB_DESC(FieldOptions_packed)(options) + ? UPB_DESC(FeatureSet_PACKED) + : UPB_DESC(FeatureSet_EXPANDED); + UPB_DESC(FeatureSet_set_repeated_field_encoding(features, val)); + ret = true; + } + +// begin:google_only +// #ifndef UPB_BOOTSTRAP_STAGE0 +// if (syntax == kUpb_Syntax_Proto3 && +// UPB_DESC(FieldOptions_has_enforce_utf8)(options) && +// !UPB_DESC(FieldOptions_enforce_utf8)(options)) { +// int val = UPB_DESC(FeatureSet_UNVERIFIED); +// UPB_DESC(FeatureSet_set_utf8_validation(features, val)); +// ret = true; +// } +// #endif +// // clang-format off +// end:google_only + // clang-format on + + return ret; +} + static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { // Must happen before _upb_DefBuilder_Add() f->file = _upb_DefBuilder_File(ctx); - if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "field has no name"); - } - const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto); - f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto); f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto); @@ -575,6 +597,29 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, f->msgdef = m; f->scope.oneof = NULL; + UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); + + upb_Syntax syntax = upb_FileDef_Syntax(f->file); + const UPB_DESC(FeatureSet*) unresolved_features = + UPB_DESC(FieldOptions_features)(f->opts); + bool implicit = false; + + if (syntax != kUpb_Syntax_Editions) { + upb_Message_Clear(ctx->legacy_features, UPB_DESC_MINITABLE(FeatureSet)); + if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, + ctx->legacy_features)) { + implicit = true; + unresolved_features = ctx->legacy_features; + } + } + + f->resolved_features = _upb_DefBuilder_DoResolveFeatures( + ctx, parent_features, unresolved_features, implicit); + + if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "field has no name"); + } + f->has_json_name = UPB_DESC(FieldDescriptorProto_has_json_name)(field_proto); if (f->has_json_name) { const upb_StringView sv = @@ -630,12 +675,6 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, * to the field_proto until later when we can properly resolve it. */ f->sub.unresolved = field_proto; - if (f->label_ == kUpb_Label_Required && - upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", - f->full_name); - } - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); @@ -659,27 +698,21 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); } - UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); - - if (UPB_DESC(FieldOptions_has_packed)(f->opts)) { - f->is_packed = UPB_DESC(FieldOptions_packed)(f->opts); - } else { - f->is_packed = upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3; - } - f->has_presence = (!upb_FieldDef_IsRepeated(f)) && (f->type_ == kUpb_FieldType_Message || f->type_ == kUpb_FieldType_Group || upb_FieldDef_ContainingOneof(f) || - (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto2)); + UPB_DESC(FeatureSet_field_presence)(f->resolved_features) != + UPB_DESC(FeatureSet_IMPLICIT)); } static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { f->is_extension = true; - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", @@ -696,11 +729,13 @@ static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, } static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) + parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { f->is_extension = false; - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); if (!UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { if (f->is_proto3_optional) { @@ -714,10 +749,11 @@ static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, _upb_MessageDef_InsertField(ctx, m, f); } -upb_FieldDef* _upb_Extensions_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m) { +upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m) { _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); upb_FieldDef* defs = (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); @@ -725,17 +761,19 @@ upb_FieldDef* _upb_Extensions_New( for (int i = 0; i < n; i++) { upb_FieldDef* f = &defs[i]; - _upb_FieldDef_CreateExt(ctx, prefix, protos[i], m, f); + _upb_FieldDef_CreateExt(ctx, prefix, parent_features, protos[i], m, f); f->index_ = i; } return defs; } -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted) { +upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m, + bool* is_sorted) { _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); upb_FieldDef* defs = (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); @@ -744,7 +782,7 @@ upb_FieldDef* _upb_FieldDefs_New( for (int i = 0; i < n; i++) { upb_FieldDef* f = &defs[i]; - _upb_FieldDef_CreateNotExt(ctx, prefix, protos[i], m, f); + _upb_FieldDef_CreateNotExt(ctx, prefix, parent_features, protos[i], m, f); f->index_ = i; if (!ctx->layout) { // Speculate that the def fields are sorted. We will always sort the diff --git a/upb/reflection/field_def.h b/upb/reflection/field_def.h index b3305bc1f2..35c3e702ed 100644 --- a/upb/reflection/field_def.h +++ b/upb/reflection/field_def.h @@ -61,6 +61,8 @@ const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f); UPB_API const char* upb_FieldDef_Name(const upb_FieldDef* f); UPB_API uint32_t upb_FieldDef_Number(const upb_FieldDef* f); const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f); +const UPB_DESC(FeatureSet) * + upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f); UPB_API const upb_OneofDef* upb_FieldDef_RealContainingOneof( const upb_FieldDef* f); UPB_API upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); diff --git a/upb/reflection/file_def.c b/upb/reflection/file_def.c index bd4b254cac..abdbd3523e 100644 --- a/upb/reflection/file_def.c +++ b/upb/reflection/file_def.c @@ -7,6 +7,8 @@ #include "upb/reflection/internal/file_def.h" +#include + #include "upb/reflection/def_pool.h" #include "upb/reflection/internal/def_builder.h" #include "upb/reflection/internal/enum_def.h" @@ -19,7 +21,8 @@ #include "upb/port/def.inc" struct upb_FileDef { - const UPB_DESC(FileOptions) * opts; + const UPB_DESC(FileOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const char* name; const char* package; UPB_DESC(Edition) edition; @@ -49,6 +52,11 @@ const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { return f->opts; } +const UPB_DESC(FeatureSet) * + upb_FileDef_ResolvedFeatures(const upb_FileDef* f) { + return f->resolved_features; +} + bool upb_FileDef_HasOptions(const upb_FileDef* f) { return f->opts != (void*)kUpbDefOptDefault; } @@ -165,6 +173,34 @@ static int count_exts_in_msg(const UPB_DESC(DescriptorProto) * msg_proto) { return ext_count; } +const UPB_DESC(FeatureSet*) + _upb_FileDef_FindEdition(upb_DefBuilder* ctx, int edition) { + const UPB_DESC(FeatureSetDefaults)* defaults = + upb_DefPool_FeatureSetDefaults(ctx->symtab); + + int min = UPB_DESC(FeatureSetDefaults_minimum_edition)(defaults); + int max = UPB_DESC(FeatureSetDefaults_maximum_edition)(defaults); + if (edition < min || edition > max) { + _upb_DefBuilder_Errf(ctx, + "Edition %d is outside the supported range [%d, %d] " + "given in the defaults", + edition, min, max); + } + + size_t n; + const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d = + UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n); + const UPB_DESC(FeatureSet)* ret = NULL; + for (size_t i = 0; i < n; i++) { + if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) > + edition) { + break; + } + ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]); + } + return ret; +} + // Allocate and initialize one file def, and add it to the context object. void _upb_FileDef_Create(upb_DefBuilder* ctx, const UPB_DESC(FileDescriptorProto) * file_proto) { @@ -233,21 +269,33 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, if (streql_view(syntax, "proto2")) { file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); } else if (streql_view(syntax, "proto3")) { file->syntax = kUpb_Syntax_Proto3; + file->edition = UPB_DESC(EDITION_PROTO3); } else if (streql_view(syntax, "editions")) { file->syntax = kUpb_Syntax_Editions; + file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); } else { _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", UPB_STRINGVIEW_ARGS(syntax)); } } else { file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); } // Read options. UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); + // Resolve features. + const UPB_DESC(FeatureSet*) edition_defaults = + _upb_FileDef_FindEdition(ctx, file->edition); + const UPB_DESC(FeatureSet*) unresolved = + UPB_DESC(FileOptions_features)(file->opts); + file->resolved_features = + _upb_DefBuilder_ResolveFeatures(ctx, edition_defaults, unresolved); + // Verify dependencies. strs = UPB_DESC(FileDescriptorProto_dependency)(file_proto, &n); file->dep_count = n; @@ -293,22 +341,26 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, // Create enums. enums = UPB_DESC(FileDescriptorProto_enum_type)(file_proto, &n); file->top_lvl_enum_count = n; - file->top_lvl_enums = _upb_EnumDefs_New(ctx, n, enums, NULL); + file->top_lvl_enums = + _upb_EnumDefs_New(ctx, n, enums, file->resolved_features, NULL); // Create extensions. exts = UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); file->top_lvl_ext_count = n; - file->top_lvl_exts = _upb_Extensions_New(ctx, n, exts, file->package, NULL); + file->top_lvl_exts = _upb_Extensions_New( + ctx, n, exts, file->resolved_features, file->package, NULL); // Create messages. msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); file->top_lvl_msg_count = n; - file->top_lvl_msgs = _upb_MessageDefs_New(ctx, n, msgs, NULL); + file->top_lvl_msgs = + _upb_MessageDefs_New(ctx, n, msgs, file->resolved_features, NULL); // Create services. services = UPB_DESC(FileDescriptorProto_service)(file_proto, &n); file->service_count = n; - file->services = _upb_ServiceDefs_New(ctx, n, services); + file->services = + _upb_ServiceDefs_New(ctx, n, services, file->resolved_features); // Now that all names are in the table, build layouts and resolve refs. diff --git a/upb/reflection/file_def.h b/upb/reflection/file_def.h index f338c25f92..912d0081d9 100644 --- a/upb/reflection/file_def.h +++ b/upb/reflection/file_def.h @@ -24,6 +24,7 @@ int upb_FileDef_DependencyCount(const upb_FileDef* f); bool upb_FileDef_HasOptions(const upb_FileDef* f); UPB_API const char* upb_FileDef_Name(const upb_FileDef* f); const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f); +const UPB_DESC(FeatureSet) * upb_FileDef_ResolvedFeatures(const upb_FileDef* f); const char* upb_FileDef_Package(const upb_FileDef* f); UPB_DESC(Edition) upb_FileDef_Edition(const upb_FileDef* f); UPB_API const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); diff --git a/upb/reflection/internal/def_builder.c b/upb/reflection/internal/def_builder.c index 2ab16f27de..d6737982ca 100644 --- a/upb/reflection/internal/def_builder.c +++ b/upb/reflection/internal/def_builder.c @@ -9,9 +9,12 @@ #include +#include "upb/base/internal/log2.h" +#include "upb/message/copy.h" #include "upb/reflection/def_pool.h" #include "upb/reflection/def_type.h" #include "upb/reflection/field_def.h" +#include "upb/reflection/file_def.h" #include "upb/reflection/internal/strdup2.h" // Must be last. @@ -337,3 +340,74 @@ void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, // We should never reach this point. UPB_ASSERT(false); } + +upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key) { + size_t need = key.size + sizeof(void*); + if (ctx->tmp_buf_size < need) { + ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need)); + ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size); + if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx); + } + + memcpy(ctx->tmp_buf, &parent, sizeof(void*)); + memcpy(ctx->tmp_buf + sizeof(void*), key.data, key.size); + return upb_StringView_FromDataAndSize(ctx->tmp_buf, need); +} + +bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key, + UPB_DESC(FeatureSet**) set) { + upb_StringView k = _upb_DefBuilder_MakeKey(ctx, parent, key); + upb_value v; + if (upb_strtable_lookup2(&ctx->feature_cache, k.data, k.size, &v)) { + *set = upb_value_getptr(v); + return false; + } + + *set = + upb_Message_DeepClone(parent, UPB_DESC_MINITABLE(FeatureSet), ctx->arena); + if (!*set) _upb_DefBuilder_OomErr(ctx); + + v = upb_value_ptr(*set); + if (!upb_strtable_insert(&ctx->feature_cache, k.data, k.size, v, + ctx->tmp_arena)) { + _upb_DefBuilder_OomErr(ctx); + } + + return true; +} + +const UPB_DESC(FeatureSet*) + _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child, + bool is_implicit) { + assert(parent); + if (!child) return parent; + + if (child && !is_implicit && + upb_FileDef_Syntax(ctx->file) != kUpb_Syntax_Editions) { + _upb_DefBuilder_Errf(ctx, "Features can only be specified for editions"); + } + + UPB_DESC(FeatureSet*) resolved; + size_t child_size; + const char* child_bytes = + UPB_DESC(FeatureSet_serialize)(child, ctx->tmp_arena, &child_size); + if (!child_bytes) _upb_DefBuilder_OomErr(ctx); + + upb_StringView key = upb_StringView_FromDataAndSize(child_bytes, child_size); + if (!_upb_DefBuilder_GetOrCreateFeatureSet(ctx, parent, key, &resolved)) { + return resolved; + } + + upb_DecodeStatus dec_status = + upb_Decode(child_bytes, child_size, resolved, + UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); + if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); + + return resolved; +} diff --git a/upb/reflection/internal/def_builder.h b/upb/reflection/internal/def_builder.h index 584553214d..b9a0bff5f8 100644 --- a/upb/reflection/internal/def_builder.h +++ b/upb/reflection/internal/def_builder.h @@ -36,6 +36,10 @@ extern "C" { struct upb_DefBuilder { upb_DefPool* symtab; + upb_strtable feature_cache; // Caches features by identity. + UPB_DESC(FeatureSet*) legacy_features; // For computing legacy features. + char* tmp_buf; // Temporary buffer in tmp_arena. + size_t tmp_buf_size; // Size of temporary buffer. upb_FileDef* file; // File we are building. upb_Arena* arena; // Allocate defs here. upb_Arena* tmp_arena; // For temporary allocations. @@ -128,6 +132,25 @@ UPB_INLINE void _upb_DefBuilder_CheckIdentFull(upb_DefBuilder* ctx, if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, true); } +// Returns true if the returned feature set is new and must be populated. +bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key, + UPB_DESC(FeatureSet**) set); + +const UPB_DESC(FeatureSet*) + _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child, + bool is_implicit); + +UPB_INLINE const UPB_DESC(FeatureSet*) + _upb_DefBuilder_ResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child) { + return _upb_DefBuilder_DoResolveFeatures(ctx, parent, child, false); +} + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/upb/reflection/internal/enum_def.h b/upb/reflection/internal/enum_def.h index 8f6b220112..d8912a08c4 100644 --- a/upb/reflection/internal/enum_def.h +++ b/upb/reflection/internal/enum_def.h @@ -22,10 +22,11 @@ bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); // Allocate and initialize an array of |n| enum defs. -upb_EnumDef* _upb_EnumDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto) * const* protos, - const upb_MessageDef* containing_type); +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/internal/enum_reserved_range.h b/upb/reflection/internal/enum_reserved_range.h index fe30604a1a..6b988ee245 100644 --- a/upb/reflection/internal/enum_reserved_range.h +++ b/upb/reflection/internal/enum_reserved_range.h @@ -23,7 +23,7 @@ upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, // Allocate and initialize an array of |n| reserved ranges owned by |e|. upb_EnumReservedRange* _upb_EnumReservedRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, + const UPB_DESC(EnumDescriptorProto_EnumReservedRange*) const* protos, const upb_EnumDef* e); #ifdef __cplusplus diff --git a/upb/reflection/internal/enum_value_def.h b/upb/reflection/internal/enum_value_def.h index 2484567feb..e75e48a6e2 100644 --- a/upb/reflection/internal/enum_value_def.h +++ b/upb/reflection/internal/enum_value_def.h @@ -22,7 +22,8 @@ upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); // Allocate and initialize an array of |n| enum value defs owned by |e|. upb_EnumValueDef* _upb_EnumValueDefs_New( upb_DefBuilder* ctx, const char* prefix, int n, - const UPB_DESC(EnumValueDescriptorProto) * const* protos, upb_EnumDef* e, + const UPB_DESC(EnumValueDescriptorProto*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, bool* is_sorted); const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, diff --git a/upb/reflection/internal/extension_range.h b/upb/reflection/internal/extension_range.h index 09901b41ff..2432701c5f 100644 --- a/upb/reflection/internal/extension_range.h +++ b/upb/reflection/internal/extension_range.h @@ -22,8 +22,8 @@ upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); // Allocate and initialize an array of |n| extension ranges owned by |m|. upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ExtensionRange) * const* protos, - const upb_MessageDef* m); + const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/internal/field_def.h b/upb/reflection/internal/field_def.h index 838f3b6070..f41a8226a6 100644 --- a/upb/reflection/internal/field_def.h +++ b/upb/reflection/internal/field_def.h @@ -31,16 +31,19 @@ void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, const upb_FieldDef* f); // Allocate and initialize an array of |n| extensions (field defs). -upb_FieldDef* _upb_Extensions_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m); +upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m); // Allocate and initialize an array of |n| field defs. -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted); +upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m, + bool* is_sorted); // Allocate and return a list of pointers to the |n| field defs in |ff|, // sorted by field number. diff --git a/upb/reflection/internal/message_def.h b/upb/reflection/internal/message_def.h index 6cc9686a74..a8bcec244f 100644 --- a/upb/reflection/internal/message_def.h +++ b/upb/reflection/internal/message_def.h @@ -30,9 +30,12 @@ void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); // Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const UPB_DESC(DescriptorProto) * const* protos, - const upb_MessageDef* containing_type); +upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features, + const upb_MessageDef* containing_type); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/internal/method_def.h b/upb/reflection/internal/method_def.h index a7e8ef8a37..b2b628d642 100644 --- a/upb/reflection/internal/method_def.h +++ b/upb/reflection/internal/method_def.h @@ -20,9 +20,11 @@ extern "C" { upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); // Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto) * const* protos, upb_ServiceDef* s); +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/internal/oneof_def.h b/upb/reflection/internal/oneof_def.h index 9cd6713efd..7d803d592c 100644 --- a/upb/reflection/internal/oneof_def.h +++ b/upb/reflection/internal/oneof_def.h @@ -22,9 +22,11 @@ void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, const upb_FieldDef* f, const char* name, size_t size); // Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto) * const* protos, upb_MessageDef* m); +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m); size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); diff --git a/upb/reflection/internal/service_def.h b/upb/reflection/internal/service_def.h index 2845b87907..b95b53b842 100644 --- a/upb/reflection/internal/service_def.h +++ b/upb/reflection/internal/service_def.h @@ -20,9 +20,11 @@ extern "C" { upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); // Allocate and initialize an array of |n| service defs. -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(ServiceDescriptorProto) * const* protos); +upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(ServiceDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/internal/upb_edition_defaults.h b/upb/reflection/internal/upb_edition_defaults.h new file mode 100644 index 0000000000..587d3b13d1 --- /dev/null +++ b/upb/reflection/internal/upb_edition_defaults.h @@ -0,0 +1,20 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ +#define UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ + +// This file contains the serialized FeatureSetDefaults object for +// language-independent features and (possibly at some point) for upb-specific +// features. This is used for feature resolution under Editions. +// NOLINTBEGIN +// clang-format off +#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "\n\021\022\014\010\001\020\002\030\002 \001(\0010\002\030\346\007\n\021\022\014\010\002\020\001\030\001 \002(\0010\001\030\347\007\n\021\022\014\010\001\020\001\030\001 \002(\0010\001\030\350\007 \346\007(\350\007" +// clang-format on +// NOLINTEND + +#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ diff --git a/upb/reflection/internal/upb_edition_defaults.h.template b/upb/reflection/internal/upb_edition_defaults.h.template new file mode 100644 index 0000000000..58ff7f1eb3 --- /dev/null +++ b/upb/reflection/internal/upb_edition_defaults.h.template @@ -0,0 +1,20 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ +#define UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ + +// This file contains the serialized FeatureSetDefaults object for +// language-independent features and (possibly at some point) for upb-specific +// features. This is used for feature resolution under Editions. +// NOLINTBEGIN +// clang-format off +#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "DEFAULTS_VALUE" +// clang-format on +// NOLINTEND + +#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ diff --git a/upb/reflection/message_def.c b/upb/reflection/message_def.c index 9e55d612a4..96037d1863 100644 --- a/upb/reflection/message_def.c +++ b/upb/reflection/message_def.c @@ -28,7 +28,8 @@ #include "upb/port/def.inc" struct upb_MessageDef { - const UPB_DESC(MessageOptions) * opts; + const UPB_DESC(MessageOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MiniTable* layout; const upb_FileDef* file; const upb_MessageDef* containing_type; @@ -66,6 +67,9 @@ struct upb_MessageDef { bool in_message_set; bool is_sorted; upb_WellKnown well_known_type; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; static void assign_msg_wellknowntype(upb_MessageDef* m) { @@ -397,10 +401,9 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); - // TODO: Once editions is supported this should turn into a - // check on LEGACY_BEST_EFFORT if (strcmp(shortname, json_name) != 0 && - upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3 && + UPB_DESC(FeatureSet_json_format)(m->resolved_features) == + UPB_DESC(FeatureSet_ALLOW) && upb_strtable_lookup(&m->ntof, json_name, &v)) { _upb_DefBuilder_Errf( ctx, "duplicate json_name for (%s) with original field name (%s)", @@ -517,7 +520,8 @@ static bool _upb_MessageDef_ValidateUtf8(const upb_MessageDef* m) { static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { uint64_t out = 0; - if (upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3) { + if (UPB_DESC(FeatureSet_repeated_field_encoding(m->resolved_features)) == + UPB_DESC(FeatureSet_PACKED)) { out |= kUpb_MessageModifier_DefaultIsPacked; } @@ -631,7 +635,8 @@ static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, } static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(DescriptorProto) * msg_proto, + const UPB_DESC(DescriptorProto*) msg_proto, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* containing_type, upb_MessageDef* m) { const UPB_DESC(OneofDescriptorProto)* const* oneofs; @@ -643,6 +648,10 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, size_t n_ext_range, n_res_range, n_res_name; upb_StringView name; + UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MessageOptions_features)(m->opts)); + // Must happen before _upb_DefBuilder_Add() m->file = _upb_DefBuilder_File(ctx); @@ -671,14 +680,12 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); - UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); - m->oneof_count = n_oneof; - m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m); + m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m->resolved_features, m); m->field_count = n_field; - m->fields = - _upb_FieldDefs_New(ctx, n_field, fields, m->full_name, m, &m->is_sorted); + m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->resolved_features, + m->full_name, m, &m->is_sorted); // Message Sets may not contain fields. if (UPB_UNLIKELY(UPB_DESC(MessageOptions_message_set_wire_format)(m->opts))) { @@ -688,7 +695,8 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, } m->ext_range_count = n_ext_range; - m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, m); + m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, + m->resolved_features, m); m->res_range_count = n_res_range; m->res_ranges = @@ -706,23 +714,29 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, const UPB_DESC(EnumDescriptorProto)* const* enums = UPB_DESC(DescriptorProto_enum_type)(msg_proto, &n_enum); m->nested_enum_count = n_enum; - m->nested_enums = _upb_EnumDefs_New(ctx, n_enum, enums, m); + m->nested_enums = + _upb_EnumDefs_New(ctx, n_enum, enums, m->resolved_features, m); const UPB_DESC(FieldDescriptorProto)* const* exts = UPB_DESC(DescriptorProto_extension)(msg_proto, &n_ext); m->nested_ext_count = n_ext; - m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->full_name, m); + m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->resolved_features, + m->full_name, m); const UPB_DESC(DescriptorProto)* const* msgs = UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n_msg); m->nested_msg_count = n_msg; - m->nested_msgs = _upb_MessageDefs_New(ctx, n_msg, msgs, m); + m->nested_msgs = + _upb_MessageDefs_New(ctx, n_msg, msgs, m->resolved_features, m); } // Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const UPB_DESC(DescriptorProto) * const* protos, - const upb_MessageDef* containing_type) { +upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features, + const upb_MessageDef* containing_type) { _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); const char* name = containing_type ? containing_type->full_name @@ -730,7 +744,8 @@ upb_MessageDef* _upb_MessageDefs_New( upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); for (int i = 0; i < n; i++) { - create_msgdef(ctx, name, protos[i], containing_type, &m[i]); + create_msgdef(ctx, name, protos[i], parent_features, containing_type, + &m[i]); } return m; } diff --git a/upb/reflection/message_def.h b/upb/reflection/message_def.h index a5c85efe23..1a92ed4349 100644 --- a/upb/reflection/message_def.h +++ b/upb/reflection/message_def.h @@ -136,6 +136,8 @@ int upb_MessageDef_RealOneofCount(const upb_MessageDef* m); const UPB_DESC(MessageOptions) * upb_MessageDef_Options(const upb_MessageDef* m); +const UPB_DESC(FeatureSet) * + upb_MessageDef_ResolvedFeatures(const upb_MessageDef* m); upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i); int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m); diff --git a/upb/reflection/method_def.c b/upb/reflection/method_def.c index 049ef4a81d..ee4e06efff 100644 --- a/upb/reflection/method_def.c +++ b/upb/reflection/method_def.c @@ -15,7 +15,8 @@ #include "upb/port/def.inc" struct upb_MethodDef { - const UPB_DESC(MethodOptions) * opts; + const UPB_DESC(MethodOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; upb_ServiceDef* service; const char* full_name; const upb_MessageDef* input_type; @@ -68,8 +69,14 @@ bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { } static void create_method(upb_DefBuilder* ctx, - const UPB_DESC(MethodDescriptorProto) * method_proto, + const UPB_DESC(MethodDescriptorProto*) method_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_ServiceDef* s, upb_MethodDef* m) { + UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, + method_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MethodOptions_features)(m->opts)); + upb_StringView name = UPB_DESC(MethodDescriptorProto_name)(method_proto); m->service = s; @@ -87,18 +94,17 @@ static void create_method(upb_DefBuilder* ctx, ctx, m->full_name, m->full_name, UPB_DESC(MethodDescriptorProto_output_type)(method_proto), UPB_DEFTYPE_MSG); - - UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, - method_proto); } // Allocate and initialize an array of |n| method defs belonging to |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto) * const* protos, upb_ServiceDef* s) { +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s) { upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); for (int i = 0; i < n; i++) { - create_method(ctx, protos[i], s, &m[i]); + create_method(ctx, protos[i], parent_features, s, &m[i]); m[i].index = i; } return m; diff --git a/upb/reflection/method_def.h b/upb/reflection/method_def.h index 64b88a6683..4abfb69e0f 100644 --- a/upb/reflection/method_def.h +++ b/upb/reflection/method_def.h @@ -26,6 +26,8 @@ int upb_MethodDef_Index(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); const char* upb_MethodDef_Name(const upb_MethodDef* m); const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m); +const UPB_DESC(FeatureSet) * + upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); diff --git a/upb/reflection/oneof_def.c b/upb/reflection/oneof_def.c index 869ca16b96..8f639df284 100644 --- a/upb/reflection/oneof_def.c +++ b/upb/reflection/oneof_def.c @@ -22,7 +22,8 @@ #include "upb/port/def.inc" struct upb_OneofDef { - const UPB_DESC(OneofOptions) * opts; + const UPB_DESC(OneofOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MessageDef* parent; const char* full_name; int field_count; @@ -30,9 +31,6 @@ struct upb_OneofDef { const upb_FieldDef** fields; upb_strtable ntof; // lookup a field by name upb_inttable itof; // lookup a field by number (index) -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif }; upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { @@ -166,9 +164,15 @@ size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { } static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const UPB_DESC(OneofDescriptorProto) * oneof_proto, + const UPB_DESC(OneofDescriptorProto*) oneof_proto, + const UPB_DESC(FeatureSet*) parent_features, const upb_OneofDef* _o) { upb_OneofDef* o = (upb_OneofDef*)_o; + + UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + o->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(OneofOptions_features)(o->opts)); + upb_StringView name = UPB_DESC(OneofDescriptorProto_name)(oneof_proto); o->parent = m; @@ -177,8 +181,6 @@ static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, o->field_count = 0; o->synthetic = false; - UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); - if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); } @@ -195,14 +197,16 @@ static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, } // Allocate and initialize an array of |n| oneof defs. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto) * const* protos, upb_MessageDef* m) { +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m) { _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); for (int i = 0; i < n; i++) { - create_oneofdef(ctx, m, protos[i], &o[i]); + create_oneofdef(ctx, m, protos[i], parent_features, &o[i]); } return o; } diff --git a/upb/reflection/oneof_def.h b/upb/reflection/oneof_def.h index 38c7a7002f..1a62f3dc8b 100644 --- a/upb/reflection/oneof_def.h +++ b/upb/reflection/oneof_def.h @@ -36,7 +36,9 @@ const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, uint32_t num); UPB_API const char* upb_OneofDef_Name(const upb_OneofDef* o); int upb_OneofDef_numfields(const upb_OneofDef* o); -const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o); +const UPB_DESC(OneofOptions*) upb_OneofDef_Options(const upb_OneofDef* o); +const UPB_DESC(FeatureSet*) + upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/reflection/service_def.c b/upb/reflection/service_def.c index 7a0cbc7a09..34ea9c9ca5 100644 --- a/upb/reflection/service_def.c +++ b/upb/reflection/service_def.c @@ -16,12 +16,16 @@ #include "upb/port/def.inc" struct upb_ServiceDef { - const UPB_DESC(ServiceOptions) * opts; + const UPB_DESC(ServiceOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_FileDef* file; const char* full_name; upb_MethodDef* methods; int method_count; int index; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { @@ -72,37 +76,40 @@ const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, } static void create_service(upb_DefBuilder* ctx, - const UPB_DESC(ServiceDescriptorProto) * svc_proto, + const UPB_DESC(ServiceDescriptorProto*) svc_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_ServiceDef* s) { - upb_StringView name; - size_t n; + UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, + svc_proto); + s->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(ServiceOptions_features)(s->opts)); // Must happen before _upb_DefBuilder_Add() s->file = _upb_DefBuilder_File(ctx); - name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); + upb_StringView name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); const char* package = _upb_FileDef_RawPackage(s->file); s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); _upb_DefBuilder_Add(ctx, s->full_name, _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); + size_t n; const UPB_DESC(MethodDescriptorProto)* const* methods = UPB_DESC(ServiceDescriptorProto_method)(svc_proto, &n); s->method_count = n; - s->methods = _upb_MethodDefs_New(ctx, n, methods, s); - - UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, - svc_proto); + s->methods = _upb_MethodDefs_New(ctx, n, methods, s->resolved_features, s); } -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(ServiceDescriptorProto) * const* protos) { +upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(ServiceDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features) { _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); for (int i = 0; i < n; i++) { - create_service(ctx, protos[i], &s[i]); + create_service(ctx, protos[i], parent_features, &s[i]); s[i].index = i; } return s; diff --git a/upb/reflection/service_def.h b/upb/reflection/service_def.h index 98cd993b4d..781932e176 100644 --- a/upb/reflection/service_def.h +++ b/upb/reflection/service_def.h @@ -30,6 +30,8 @@ int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); const char* upb_ServiceDef_Name(const upb_ServiceDef* s); const UPB_DESC(ServiceOptions) * upb_ServiceDef_Options(const upb_ServiceDef* s); +const UPB_DESC(FeatureSet) * + upb_ServiceDef_ResolvedFeatures(const upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/util/required_fields.c b/upb/util/required_fields.c index c6616ecdd3..b93adc0d99 100644 --- a/upb/util/required_fields.c +++ b/upb/util/required_fields.c @@ -196,7 +196,7 @@ static void upb_util_FindUnsetInMessage(upb_FindContext* ctx, // Iterate over all fields to see if any required fields are missing. for (int i = 0, n = upb_MessageDef_FieldCount(m); i < n; i++) { const upb_FieldDef* f = upb_MessageDef_Field(m, i); - if (upb_FieldDef_Label(f) != kUpb_Label_Required) continue; + if (!upb_FieldDef_IsRequired(f)) continue; if (!msg || !upb_Message_HasFieldByDef(msg, f)) { // A required field is missing. From ce9dcc24559a367c42fa2ec8d32f399e681ada1b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 3 Nov 2023 22:38:26 +0000 Subject: [PATCH 086/387] Auto-generate files after cl/579321454 --- php/ext/google/protobuf/php-upb.c | 866 +++++++++++++++++++++----- php/ext/google/protobuf/php-upb.h | 170 ++++- ruby/ext/google/protobuf_c/ruby-upb.c | 866 +++++++++++++++++++++----- ruby/ext/google/protobuf_c/ruby-upb.h | 170 ++++- 4 files changed, 1684 insertions(+), 388 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index f999768b48..f20fc800d8 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -319,8 +319,13 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #if defined(UPB_IS_GOOGLE3) && !defined(UPB_BOOTSTRAP_STAGE0) #define UPB_DESC(sym) proto2_##sym +#define UPB_DESC_MINITABLE(sym) &proto2__##sym##_msg_init +#elif defined(UPB_BOOTSTRAP_STAGE0) +#define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) google__protobuf__##sym##_msg_init() #else #define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) &google__protobuf__##sym##_msg_init #endif @@ -5880,6 +5885,289 @@ bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, } +#include +#include + + +// Must be last. + +static bool upb_MessageField_IsMap(const upb_MiniTableField* field) { + return upb_FieldMode_Get(field) == kUpb_FieldMode_Map; +} + +static upb_StringView upb_Clone_StringView(upb_StringView str, + upb_Arena* arena) { + if (str.size == 0) { + return upb_StringView_FromDataAndSize(NULL, 0); + } + void* cloned_data = upb_Arena_Malloc(arena, str.size); + upb_StringView cloned_str = + upb_StringView_FromDataAndSize(cloned_data, str.size); + memcpy(cloned_data, str.data, str.size); + return cloned_str; +} + +static bool upb_Clone_MessageValue(void* value, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + switch (value_type) { + case kUpb_CType_Bool: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return true; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView source = *(upb_StringView*)value; + int size = source.size; + void* cloned_data = upb_Arena_Malloc(arena, size); + if (cloned_data == NULL) { + return false; + } + *(upb_StringView*)value = + upb_StringView_FromDataAndSize(cloned_data, size); + memcpy(cloned_data, source.data, size); + return true; + } break; + case kUpb_CType_Message: { + const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; + bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); + if (is_empty) sub = &_kUpb_MiniTable_Empty; + UPB_ASSERT(source); + upb_Message* clone = upb_Message_DeepClone( + _upb_TaggedMessagePtr_GetMessage(source), sub, arena); + *(upb_TaggedMessagePtr*)value = + _upb_TaggedMessagePtr_Pack(clone, is_empty); + return clone != NULL; + } break; + } + UPB_UNREACHABLE(); +} + +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena) { + upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); + if (cloned_map == NULL) { + return NULL; + } + upb_MessageValue key, val; + size_t iter = kUpb_Map_Begin; + while (upb_Map_Next(map, &key, &val, &iter)) { + const upb_MiniTableField* value_field = &map_entry_table->fields[1]; + const upb_MiniTable* value_sub = + (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) + ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) + : NULL; + upb_CType value_field_type = upb_MiniTableField_CType(value_field); + if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { + return NULL; + } + if (upb_Map_Insert(cloned_map, key, val, arena) == + kUpb_MapInsertStatus_OutOfMemory) { + return NULL; + } + } + return cloned_map; +} + +static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, + const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* clone, + upb_Arena* arena) { + const upb_MiniTable* map_entry_table = + mini_table->subs[field->UPB_PRIVATE(submsg_index)].submsg; + UPB_ASSERT(map_entry_table); + + const upb_MiniTableField* key_field = &map_entry_table->fields[0]; + const upb_MiniTableField* value_field = &map_entry_table->fields[1]; + + upb_Map* cloned_map = upb_Map_DeepClone( + map, upb_MiniTableField_CType(key_field), + upb_MiniTableField_CType(value_field), map_entry_table, arena); + if (!cloned_map) { + return NULL; + } + _upb_Message_SetNonExtensionField(clone, field, &cloned_map); + return cloned_map; +} + +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + size_t size = array->size; + upb_Array* cloned_array = + _upb_Array_New(arena, size, _upb_Array_CTypeSizeLg2(value_type)); + if (!cloned_array) { + return NULL; + } + if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { + return NULL; + } + for (size_t i = 0; i < size; ++i) { + upb_MessageValue val = upb_Array_Get(array, i); + if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { + return false; + } + upb_Array_Set(cloned_array, i, val); + } + return cloned_array; +} + +static bool upb_Message_Array_DeepClone(const upb_Array* array, + const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* clone, upb_Arena* arena) { + _upb_MiniTableField_CheckIsArray(field); + upb_Array* cloned_array = upb_Array_DeepClone( + array, upb_MiniTableField_CType(field), + upb_MiniTableField_CType(field) == kUpb_CType_Message && + field->UPB_PRIVATE(submsg_index) != kUpb_NoSub + ? upb_MiniTable_GetSubMessageTable(mini_table, field) + : NULL, + arena); + + // Clear out upb_Array* due to parent memcpy. + _upb_Message_SetNonExtensionField(clone, field, &cloned_array); + return true; +} + +static bool upb_Clone_ExtensionValue( + const upb_MiniTableExtension* mini_table_ext, + const upb_Message_Extension* source, upb_Message_Extension* dest, + upb_Arena* arena) { + dest->data = source->data; + return upb_Clone_MessageValue( + &dest->data, upb_MiniTableField_CType(&mini_table_ext->field), + mini_table_ext->sub.submsg, arena); +} + +upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, + upb_Arena* arena) { + upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); + // Only copy message area skipping upb_Message_Internal. + memcpy(dst, src, mini_table->size); + for (size_t i = 0; i < mini_table->field_count; ++i) { + const upb_MiniTableField* field = &mini_table->fields[i]; + if (!upb_IsRepeatedOrMap(field)) { + switch (upb_MiniTableField_CType(field)) { + case kUpb_CType_Message: { + upb_TaggedMessagePtr tagged = + upb_Message_GetTaggedMessagePtr(src, field, NULL); + const upb_Message* sub_message = + _upb_TaggedMessagePtr_GetMessage(tagged); + if (sub_message != NULL) { + // If the message is currently in an unlinked, "empty" state we keep + // it that way, because we don't want to deal with decode options, + // decode status, or possible parse failure here. + bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); + const upb_MiniTable* sub_message_table = + is_empty ? &_kUpb_MiniTable_Empty + : upb_MiniTable_GetSubMessageTable(mini_table, field); + upb_Message* dst_sub_message = + upb_Message_DeepClone(sub_message, sub_message_table, arena); + if (dst_sub_message == NULL) { + return NULL; + } + _upb_Message_SetTaggedMessagePtr( + dst, mini_table, field, + _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); + } + } break; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView str = upb_Message_GetString(src, field, empty_string); + if (str.size != 0) { + if (!upb_Message_SetString( + dst, field, upb_Clone_StringView(str, arena), arena)) { + return NULL; + } + } + } break; + default: + // Scalar, already copied. + break; + } + } else { + if (upb_MessageField_IsMap(field)) { + const upb_Map* map = upb_Message_GetMap(src, field); + if (map != NULL) { + if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { + return NULL; + } + } + } else { + const upb_Array* array = upb_Message_GetArray(src, field); + if (array != NULL) { + if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, + arena)) { + return NULL; + } + } + } + } + } + // Clone extensions. + size_t ext_count; + const upb_Message_Extension* ext = _upb_Message_Getexts(src, &ext_count); + for (size_t i = 0; i < ext_count; ++i) { + const upb_Message_Extension* msg_ext = &ext[i]; + const upb_MiniTableField* field = &msg_ext->ext->field; + upb_Message_Extension* dst_ext = + _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); + if (!dst_ext) return NULL; + if (!upb_IsRepeatedOrMap(field)) { + if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { + return NULL; + } + } else { + upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; + UPB_ASSERT(msg_array); + upb_Array* cloned_array = + upb_Array_DeepClone(msg_array, upb_MiniTableField_CType(field), + msg_ext->ext->sub.submsg, arena); + if (!cloned_array) { + return NULL; + } + dst_ext->data.ptr = (void*)cloned_array; + } + } + + // Clone unknowns. + size_t unknown_size = 0; + const char* ptr = upb_Message_GetUnknown(src, &unknown_size); + if (unknown_size != 0) { + UPB_ASSERT(ptr); + // Make a copy into destination arena. + if (!_upb_Message_AddUnknown(dst, ptr, unknown_size, arena)) { + return NULL; + } + } + return dst; +} + +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, upb_Arena* arena) { + upb_Message_Clear(dst, mini_table); + return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; +} + +// Deep clones a message using the provided target arena. +// +// Returns NULL on failure. +upb_Message* upb_Message_DeepClone(const upb_Message* message, + const upb_MiniTable* mini_table, + upb_Arena* arena) { + upb_Message* clone = upb_Message_New(mini_table, arena); + return _upb_Message_Copy(clone, message, mini_table, arena); +} + + #include // Must be last. @@ -7968,6 +8256,7 @@ struct upb_DefPool { upb_strtable files; // file_name -> (upb_FileDef*) upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) upb_ExtensionRegistry* extreg; + const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; upb_MiniTablePlatform platform; void* scratch_data; size_t scratch_size; @@ -7980,6 +8269,8 @@ void upb_DefPool_Free(upb_DefPool* s) { upb_gfree(s); } +static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; + upb_DefPool* upb_DefPool_New(void) { upb_DefPool* s = upb_gmalloc(sizeof(*s)); if (!s) return NULL; @@ -7999,6 +8290,10 @@ upb_DefPool* upb_DefPool_New(void) { if (!s->extreg) goto err; s->platform = kUpb_MiniTablePlatform_Native; + s->feature_set_defaults = UPB_DESC(FeatureSetDefaults_parse)( + serialized_defaults, sizeof(serialized_defaults) - 1, s->arena); + + if (!s->feature_set_defaults) goto err; return s; @@ -8007,6 +8302,11 @@ err: return NULL; } +const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { + return s->feature_set_defaults; +} + bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, const upb_FieldDef* f) { return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), @@ -8220,7 +8520,11 @@ static const upb_FileDef* upb_DefBuilder_AddFileToPool( remove_filedef(s, builder->file); builder->file = NULL; } - } else if (!builder->arena || !builder->tmp_arena) { + } else if (!builder->arena || !builder->tmp_arena || + !upb_strtable_init(&builder->feature_cache, 16, + builder->tmp_arena) || + !(builder->legacy_features = + UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { _upb_DefBuilder_OomErr(builder); } else { _upb_FileDef_Create(builder, file_proto); @@ -8253,6 +8557,8 @@ static const upb_FileDef* _upb_DefPool_AddFile( upb_DefBuilder ctx = { .symtab = s, + .tmp_buf = NULL, + .tmp_buf_size = 0, .layout = layout, .platform = s->platform, .msg_count = 0, @@ -8435,7 +8741,8 @@ bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { // Must be last. struct upb_EnumDef { - const UPB_DESC(EnumOptions) * opts; + const UPB_DESC(EnumOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MiniTableEnum* layout; // Only for proto2. const upb_FileDef* file; const upb_MessageDef* containing_type; // Could be merged with "file". @@ -8449,8 +8756,10 @@ struct upb_EnumDef { int res_range_count; int res_name_count; int32_t defaultval; - bool is_closed; bool is_sorted; // Whether all of the values are defined in ascending order. +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { @@ -8552,7 +8861,11 @@ const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { return _upb_EnumValueDef_At(e->values, i); } -bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { return e->is_closed; } +bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; + return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) == + UPB_DESC(FeatureSet_CLOSED); +} bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, upb_StringView* out) { @@ -8621,6 +8934,7 @@ static upb_StringView* _upb_EnumReservedNames_New( static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, const UPB_DESC(EnumDescriptorProto) * enum_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e) { const UPB_DESC(EnumValueDescriptorProto)* const* values; const UPB_DESC(EnumDescriptorProto_EnumReservedRange)* const* res_ranges; @@ -8628,6 +8942,10 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, upb_StringView name; size_t n_value, n_res_range, n_res_name; + UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); + e->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumOptions_features)(e->opts)); + // Must happen before _upb_DefBuilder_Add() e->file = _upb_DefBuilder_File(ctx); @@ -8637,9 +8955,6 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, _upb_DefBuilder_Add(ctx, e->full_name, _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - e->is_closed = (!UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) && - (upb_FileDef_Syntax(e->file) == kUpb_Syntax_Proto2); - values = UPB_DESC(EnumDescriptorProto_value)(enum_proto, &n_value); bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); @@ -8650,8 +8965,8 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, e->defaultval = 0; e->value_count = n_value; - e->values = - _upb_EnumValueDefs_New(ctx, prefix, n_value, values, e, &e->is_sorted); + e->values = _upb_EnumValueDefs_New(ctx, prefix, n_value, values, + e->resolved_features, e, &e->is_sorted); if (n_value == 0) { _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", @@ -8668,11 +8983,9 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, e->res_name_count = n_res_name; e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); - UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - upb_inttable_compact(&e->iton, ctx->arena); - if (e->is_closed) { + if (upb_EnumDef_IsClosed(e)) { if (ctx->layout) { UPB_ASSERT(ctx->enum_count < ctx->layout->enum_count); e->layout = ctx->layout->enums[ctx->enum_count++]; @@ -8684,10 +8997,11 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, } } -upb_EnumDef* _upb_EnumDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto) * const* protos, - const upb_MessageDef* containing_type) { +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type) { _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); // If a containing type is defined then get the full name from that. @@ -8697,7 +9011,7 @@ upb_EnumDef* _upb_EnumDefs_New( upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); for (int i = 0; i < n; i++) { - create_enumdef(ctx, name, protos[i], &e[i]); + create_enumdef(ctx, name, protos[i], parent_features, &e[i]); e[i].containing_type = containing_type; } return e; @@ -8756,14 +9070,20 @@ upb_EnumReservedRange* _upb_EnumReservedRanges_New( } +#include + // Must be last. struct upb_EnumValueDef { - const UPB_DESC(EnumValueOptions) * opts; + const UPB_DESC(EnumValueOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_EnumDef* parent; const char* full_name; int32_t number; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { @@ -8820,9 +9140,15 @@ uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { } static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(EnumValueDescriptorProto) * + const UPB_DESC(EnumValueDescriptorProto*) val_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, upb_EnumValueDef* v) { + UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, + val_proto); + v->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumValueOptions_features)(v->opts)); + upb_StringView name = UPB_DESC(EnumValueDescriptorProto_name)(val_proto); v->parent = e; // Must happen prior to _upb_DefBuilder_Add() @@ -8831,17 +9157,32 @@ static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, _upb_DefBuilder_Add(ctx, v->full_name, _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, - val_proto); - bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); } +static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx, + const upb_EnumDef* e, + const upb_EnumValueDef* v, int n) { + if (upb_EnumDef_IsClosed(e) || n == 0 || v[0].number == 0) return; + + // When the special UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 is enabled, we have to + // exempt proto2 enums from this check, even when we are treating them as + // open. + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 && + upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) { + return; + } + + _upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)", + upb_EnumDef_FullName(e)); +} + // Allocate and initialize an array of |n| enum value defs owned by |e|. upb_EnumValueDef* _upb_EnumValueDefs_New( upb_DefBuilder* ctx, const char* prefix, int n, - const UPB_DESC(EnumValueDescriptorProto) * const* protos, upb_EnumDef* e, + const UPB_DESC(EnumValueDescriptorProto*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, bool* is_sorted) { _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); @@ -8851,29 +9192,27 @@ upb_EnumValueDef* _upb_EnumValueDefs_New( *is_sorted = true; uint32_t previous = 0; for (int i = 0; i < n; i++) { - create_enumvaldef(ctx, prefix, protos[i], e, &v[i]); + create_enumvaldef(ctx, prefix, protos[i], parent_features, e, &v[i]); const uint32_t current = v[i].number; if (previous > current) *is_sorted = false; previous = current; } - if (upb_FileDef_Syntax(ctx->file) == kUpb_Syntax_Proto3 && n > 0 && - v[0].number != 0) { - _upb_DefBuilder_Errf(ctx, - "for proto3, the first enum value must be zero (%s)", - upb_EnumDef_FullName(e)); - } + _upb_EnumValueDef_CheckZeroValue(ctx, e, v, n); return v; } +#include + // Must be last. struct upb_ExtensionRange { - const UPB_DESC(ExtensionRangeOptions) * opts; + const UPB_DESC(ExtensionRangeOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; int32_t start; int32_t end; }; @@ -8899,12 +9238,18 @@ int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ExtensionRange) * const* protos, - const upb_MessageDef* m) { + const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m) { upb_ExtensionRange* r = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); for (int i = 0; i < n; i++) { + UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, + ExtensionRangeOptions, protos[i]); + r[i].resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, + UPB_DESC(ExtensionRangeOptions_features)(r[i].opts)); + const int32_t start = UPB_DESC(DescriptorProto_ExtensionRange_start)(protos[i]); const int32_t end = UPB_DESC(DescriptorProto_ExtensionRange_end)(protos[i]); @@ -8924,8 +9269,6 @@ upb_ExtensionRange* _upb_ExtensionRanges_New( r[i].start = start; r[i].end = end; - UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, - ExtensionRangeOptions, protos[i]); } return r; @@ -8947,7 +9290,8 @@ typedef struct { } str_t; struct upb_FieldDef { - const UPB_DESC(FieldOptions) * opts; + const UPB_DESC(FieldOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_FileDef* file; const upb_MessageDef* msgdef; const char* full_name; @@ -8977,13 +9321,9 @@ struct upb_FieldDef { bool has_json_name; bool has_presence; bool is_extension; - bool is_packed; bool is_proto3_optional; upb_FieldType type_; upb_Label label_; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif }; upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { @@ -9052,7 +9392,9 @@ bool _upb_FieldDef_IsPackable(const upb_FieldDef* f) { } bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { - return _upb_FieldDef_IsPackable(f) && f->is_packed; + return _upb_FieldDef_IsPackable(f) && + UPB_DESC(FeatureSet_repeated_field_encoding(f->resolved_features)) == + UPB_DESC(FeatureSet_PACKED); } const char* upb_FieldDef_Name(const upb_FieldDef* f) { @@ -9165,44 +9507,21 @@ bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } -// begin:google_only -// static bool _upb_FieldDef_EnforceUtf8Option(const upb_FieldDef* f) { -// #if defined(UPB_BOOTSTRAP_STAGE0) -// return true; -// #else -// return UPB_DESC(FieldOptions_enforce_utf8)(f->opts); -// #endif -// } -// end:google_only - -// begin:github_only -static bool _upb_FieldDef_EnforceUtf8Option(const upb_FieldDef* f) { - return true; -} -// end:github_only - bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) { if (upb_FieldDef_Type(f) != kUpb_FieldType_String) return false; - return upb_FileDef_Syntax(upb_FieldDef_File(f)) == kUpb_Syntax_Proto3 - ? _upb_FieldDef_EnforceUtf8Option(f) - : false; + return UPB_DESC(FeatureSet_utf8_validation(f->resolved_features)) == + UPB_DESC(FeatureSet_VERIFY); } uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0; - switch (f->label_) { - case kUpb_Label_Optional: - if (!upb_FieldDef_HasPresence(f)) { - out |= kUpb_FieldModifier_IsProto3Singular; - } - break; - case kUpb_Label_Repeated: - out |= kUpb_FieldModifier_IsRepeated; - break; - case kUpb_Label_Required: - out |= kUpb_FieldModifier_IsRequired; - break; + if (upb_FieldDef_IsRepeated(f)) { + out |= kUpb_FieldModifier_IsRepeated; + } else if (upb_FieldDef_IsRequired(f)) { + out |= kUpb_FieldModifier_IsRequired; + } else if (!upb_FieldDef_HasPresence(f)) { + out |= kUpb_FieldModifier_IsProto3Singular; } if (_upb_FieldDef_IsClosedEnum(f)) { @@ -9242,7 +9561,8 @@ bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { } bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Required; + return UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED); } bool upb_FieldDef_IsString(const upb_FieldDef* f) { @@ -9466,19 +9786,63 @@ static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { } } +static bool _upb_FieldDef_InferLegacyFeatures( + upb_DefBuilder* ctx, upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto*) proto, + const UPB_DESC(FieldOptions*) options, upb_Syntax syntax, + UPB_DESC(FeatureSet*) features) { + bool ret = false; + + if (UPB_DESC(FieldDescriptorProto_label)(proto) == kUpb_Label_Required) { + if (syntax == kUpb_Syntax_Proto3) { + _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", + f->full_name); + } + int val = UPB_DESC(FeatureSet_LEGACY_REQUIRED); + UPB_DESC(FeatureSet_set_field_presence(features, val)); + ret = true; + } + + if (UPB_DESC(FieldDescriptorProto_type)(proto) == kUpb_FieldType_Group) { + int val = UPB_DESC(FeatureSet_DELIMITED); + UPB_DESC(FeatureSet_set_message_encoding(features, val)); + ret = true; + } + + if (UPB_DESC(FieldOptions_has_packed)(options)) { + int val = UPB_DESC(FieldOptions_packed)(options) + ? UPB_DESC(FeatureSet_PACKED) + : UPB_DESC(FeatureSet_EXPANDED); + UPB_DESC(FeatureSet_set_repeated_field_encoding(features, val)); + ret = true; + } + +// begin:google_only +// #ifndef UPB_BOOTSTRAP_STAGE0 +// if (syntax == kUpb_Syntax_Proto3 && +// UPB_DESC(FieldOptions_has_enforce_utf8)(options) && +// !UPB_DESC(FieldOptions_enforce_utf8)(options)) { +// int val = UPB_DESC(FeatureSet_UNVERIFIED); +// UPB_DESC(FeatureSet_set_utf8_validation(features, val)); +// ret = true; +// } +// #endif +// // clang-format off +// end:google_only + // clang-format on + + return ret; +} + static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { // Must happen before _upb_DefBuilder_Add() f->file = _upb_DefBuilder_File(ctx); - if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "field has no name"); - } - const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto); - f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto); f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto); @@ -9487,6 +9851,29 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, f->msgdef = m; f->scope.oneof = NULL; + UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); + + upb_Syntax syntax = upb_FileDef_Syntax(f->file); + const UPB_DESC(FeatureSet*) unresolved_features = + UPB_DESC(FieldOptions_features)(f->opts); + bool implicit = false; + + if (syntax != kUpb_Syntax_Editions) { + upb_Message_Clear(ctx->legacy_features, UPB_DESC_MINITABLE(FeatureSet)); + if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, + ctx->legacy_features)) { + implicit = true; + unresolved_features = ctx->legacy_features; + } + } + + f->resolved_features = _upb_DefBuilder_DoResolveFeatures( + ctx, parent_features, unresolved_features, implicit); + + if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "field has no name"); + } + f->has_json_name = UPB_DESC(FieldDescriptorProto_has_json_name)(field_proto); if (f->has_json_name) { const upb_StringView sv = @@ -9542,12 +9929,6 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, * to the field_proto until later when we can properly resolve it. */ f->sub.unresolved = field_proto; - if (f->label_ == kUpb_Label_Required && - upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", - f->full_name); - } - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); @@ -9571,27 +9952,21 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); } - UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); - - if (UPB_DESC(FieldOptions_has_packed)(f->opts)) { - f->is_packed = UPB_DESC(FieldOptions_packed)(f->opts); - } else { - f->is_packed = upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3; - } - f->has_presence = (!upb_FieldDef_IsRepeated(f)) && (f->type_ == kUpb_FieldType_Message || f->type_ == kUpb_FieldType_Group || upb_FieldDef_ContainingOneof(f) || - (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto2)); + UPB_DESC(FeatureSet_field_presence)(f->resolved_features) != + UPB_DESC(FeatureSet_IMPLICIT)); } static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { f->is_extension = true; - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", @@ -9608,11 +9983,13 @@ static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, } static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) + parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { f->is_extension = false; - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); if (!UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { if (f->is_proto3_optional) { @@ -9626,10 +10003,11 @@ static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, _upb_MessageDef_InsertField(ctx, m, f); } -upb_FieldDef* _upb_Extensions_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m) { +upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m) { _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); upb_FieldDef* defs = (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); @@ -9637,17 +10015,19 @@ upb_FieldDef* _upb_Extensions_New( for (int i = 0; i < n; i++) { upb_FieldDef* f = &defs[i]; - _upb_FieldDef_CreateExt(ctx, prefix, protos[i], m, f); + _upb_FieldDef_CreateExt(ctx, prefix, parent_features, protos[i], m, f); f->index_ = i; } return defs; } -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted) { +upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m, + bool* is_sorted) { _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); upb_FieldDef* defs = (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); @@ -9656,7 +10036,7 @@ upb_FieldDef* _upb_FieldDefs_New( for (int i = 0; i < n; i++) { upb_FieldDef* f = &defs[i]; - _upb_FieldDef_CreateNotExt(ctx, prefix, protos[i], m, f); + _upb_FieldDef_CreateNotExt(ctx, prefix, parent_features, protos[i], m, f); f->index_ = i; if (!ctx->layout) { // Speculate that the def fields are sorted. We will always sort the @@ -9860,11 +10240,14 @@ void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, } +#include + // Must be last. struct upb_FileDef { - const UPB_DESC(FileOptions) * opts; + const UPB_DESC(FileOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const char* name; const char* package; UPB_DESC(Edition) edition; @@ -9894,6 +10277,11 @@ const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { return f->opts; } +const UPB_DESC(FeatureSet) * + upb_FileDef_ResolvedFeatures(const upb_FileDef* f) { + return f->resolved_features; +} + bool upb_FileDef_HasOptions(const upb_FileDef* f) { return f->opts != (void*)kUpbDefOptDefault; } @@ -10010,6 +10398,34 @@ static int count_exts_in_msg(const UPB_DESC(DescriptorProto) * msg_proto) { return ext_count; } +const UPB_DESC(FeatureSet*) + _upb_FileDef_FindEdition(upb_DefBuilder* ctx, int edition) { + const UPB_DESC(FeatureSetDefaults)* defaults = + upb_DefPool_FeatureSetDefaults(ctx->symtab); + + int min = UPB_DESC(FeatureSetDefaults_minimum_edition)(defaults); + int max = UPB_DESC(FeatureSetDefaults_maximum_edition)(defaults); + if (edition < min || edition > max) { + _upb_DefBuilder_Errf(ctx, + "Edition %d is outside the supported range [%d, %d] " + "given in the defaults", + edition, min, max); + } + + size_t n; + const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d = + UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n); + const UPB_DESC(FeatureSet)* ret = NULL; + for (size_t i = 0; i < n; i++) { + if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) > + edition) { + break; + } + ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]); + } + return ret; +} + // Allocate and initialize one file def, and add it to the context object. void _upb_FileDef_Create(upb_DefBuilder* ctx, const UPB_DESC(FileDescriptorProto) * file_proto) { @@ -10078,21 +10494,33 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, if (streql_view(syntax, "proto2")) { file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); } else if (streql_view(syntax, "proto3")) { file->syntax = kUpb_Syntax_Proto3; + file->edition = UPB_DESC(EDITION_PROTO3); } else if (streql_view(syntax, "editions")) { file->syntax = kUpb_Syntax_Editions; + file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); } else { _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", UPB_STRINGVIEW_ARGS(syntax)); } } else { file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); } // Read options. UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); + // Resolve features. + const UPB_DESC(FeatureSet*) edition_defaults = + _upb_FileDef_FindEdition(ctx, file->edition); + const UPB_DESC(FeatureSet*) unresolved = + UPB_DESC(FileOptions_features)(file->opts); + file->resolved_features = + _upb_DefBuilder_ResolveFeatures(ctx, edition_defaults, unresolved); + // Verify dependencies. strs = UPB_DESC(FileDescriptorProto_dependency)(file_proto, &n); file->dep_count = n; @@ -10138,22 +10566,26 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, // Create enums. enums = UPB_DESC(FileDescriptorProto_enum_type)(file_proto, &n); file->top_lvl_enum_count = n; - file->top_lvl_enums = _upb_EnumDefs_New(ctx, n, enums, NULL); + file->top_lvl_enums = + _upb_EnumDefs_New(ctx, n, enums, file->resolved_features, NULL); // Create extensions. exts = UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); file->top_lvl_ext_count = n; - file->top_lvl_exts = _upb_Extensions_New(ctx, n, exts, file->package, NULL); + file->top_lvl_exts = _upb_Extensions_New( + ctx, n, exts, file->resolved_features, file->package, NULL); // Create messages. msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); file->top_lvl_msg_count = n; - file->top_lvl_msgs = _upb_MessageDefs_New(ctx, n, msgs, NULL); + file->top_lvl_msgs = + _upb_MessageDefs_New(ctx, n, msgs, file->resolved_features, NULL); // Create services. services = UPB_DESC(FileDescriptorProto_service)(file_proto, &n); file->service_count = n; - file->services = _upb_ServiceDefs_New(ctx, n, services); + file->services = + _upb_ServiceDefs_New(ctx, n, services, file->resolved_features); // Now that all names are in the table, build layouts and resolve refs. @@ -10516,6 +10948,77 @@ void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, UPB_ASSERT(false); } +upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key) { + size_t need = key.size + sizeof(void*); + if (ctx->tmp_buf_size < need) { + ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need)); + ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size); + if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx); + } + + memcpy(ctx->tmp_buf, &parent, sizeof(void*)); + memcpy(ctx->tmp_buf + sizeof(void*), key.data, key.size); + return upb_StringView_FromDataAndSize(ctx->tmp_buf, need); +} + +bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key, + UPB_DESC(FeatureSet**) set) { + upb_StringView k = _upb_DefBuilder_MakeKey(ctx, parent, key); + upb_value v; + if (upb_strtable_lookup2(&ctx->feature_cache, k.data, k.size, &v)) { + *set = upb_value_getptr(v); + return false; + } + + *set = + upb_Message_DeepClone(parent, UPB_DESC_MINITABLE(FeatureSet), ctx->arena); + if (!*set) _upb_DefBuilder_OomErr(ctx); + + v = upb_value_ptr(*set); + if (!upb_strtable_insert(&ctx->feature_cache, k.data, k.size, v, + ctx->tmp_arena)) { + _upb_DefBuilder_OomErr(ctx); + } + + return true; +} + +const UPB_DESC(FeatureSet*) + _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child, + bool is_implicit) { + assert(parent); + if (!child) return parent; + + if (child && !is_implicit && + upb_FileDef_Syntax(ctx->file) != kUpb_Syntax_Editions) { + _upb_DefBuilder_Errf(ctx, "Features can only be specified for editions"); + } + + UPB_DESC(FeatureSet*) resolved; + size_t child_size; + const char* child_bytes = + UPB_DESC(FeatureSet_serialize)(child, ctx->tmp_arena, &child_size); + if (!child_bytes) _upb_DefBuilder_OomErr(ctx); + + upb_StringView key = upb_StringView_FromDataAndSize(child_bytes, child_size); + if (!_upb_DefBuilder_GetOrCreateFeatureSet(ctx, parent, key, &resolved)) { + return resolved; + } + + upb_DecodeStatus dec_status = + upb_Decode(child_bytes, child_size, resolved, + UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); + if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); + + return resolved; +} + #include @@ -10739,7 +11242,8 @@ bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, // Must be last. struct upb_MessageDef { - const UPB_DESC(MessageOptions) * opts; + const UPB_DESC(MessageOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MiniTable* layout; const upb_FileDef* file; const upb_MessageDef* containing_type; @@ -10777,6 +11281,9 @@ struct upb_MessageDef { bool in_message_set; bool is_sorted; upb_WellKnown well_known_type; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; static void assign_msg_wellknowntype(upb_MessageDef* m) { @@ -11108,10 +11615,9 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); - // TODO: Once editions is supported this should turn into a - // check on LEGACY_BEST_EFFORT if (strcmp(shortname, json_name) != 0 && - upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3 && + UPB_DESC(FeatureSet_json_format)(m->resolved_features) == + UPB_DESC(FeatureSet_ALLOW) && upb_strtable_lookup(&m->ntof, json_name, &v)) { _upb_DefBuilder_Errf( ctx, "duplicate json_name for (%s) with original field name (%s)", @@ -11228,7 +11734,8 @@ static bool _upb_MessageDef_ValidateUtf8(const upb_MessageDef* m) { static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { uint64_t out = 0; - if (upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3) { + if (UPB_DESC(FeatureSet_repeated_field_encoding(m->resolved_features)) == + UPB_DESC(FeatureSet_PACKED)) { out |= kUpb_MessageModifier_DefaultIsPacked; } @@ -11342,7 +11849,8 @@ static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, } static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(DescriptorProto) * msg_proto, + const UPB_DESC(DescriptorProto*) msg_proto, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* containing_type, upb_MessageDef* m) { const UPB_DESC(OneofDescriptorProto)* const* oneofs; @@ -11354,6 +11862,10 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, size_t n_ext_range, n_res_range, n_res_name; upb_StringView name; + UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MessageOptions_features)(m->opts)); + // Must happen before _upb_DefBuilder_Add() m->file = _upb_DefBuilder_File(ctx); @@ -11382,14 +11894,12 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); - UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); - m->oneof_count = n_oneof; - m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m); + m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m->resolved_features, m); m->field_count = n_field; - m->fields = - _upb_FieldDefs_New(ctx, n_field, fields, m->full_name, m, &m->is_sorted); + m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->resolved_features, + m->full_name, m, &m->is_sorted); // Message Sets may not contain fields. if (UPB_UNLIKELY(UPB_DESC(MessageOptions_message_set_wire_format)(m->opts))) { @@ -11399,7 +11909,8 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, } m->ext_range_count = n_ext_range; - m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, m); + m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, + m->resolved_features, m); m->res_range_count = n_res_range; m->res_ranges = @@ -11417,23 +11928,29 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, const UPB_DESC(EnumDescriptorProto)* const* enums = UPB_DESC(DescriptorProto_enum_type)(msg_proto, &n_enum); m->nested_enum_count = n_enum; - m->nested_enums = _upb_EnumDefs_New(ctx, n_enum, enums, m); + m->nested_enums = + _upb_EnumDefs_New(ctx, n_enum, enums, m->resolved_features, m); const UPB_DESC(FieldDescriptorProto)* const* exts = UPB_DESC(DescriptorProto_extension)(msg_proto, &n_ext); m->nested_ext_count = n_ext; - m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->full_name, m); + m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->resolved_features, + m->full_name, m); const UPB_DESC(DescriptorProto)* const* msgs = UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n_msg); m->nested_msg_count = n_msg; - m->nested_msgs = _upb_MessageDefs_New(ctx, n_msg, msgs, m); + m->nested_msgs = + _upb_MessageDefs_New(ctx, n_msg, msgs, m->resolved_features, m); } // Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const UPB_DESC(DescriptorProto) * const* protos, - const upb_MessageDef* containing_type) { +upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features, + const upb_MessageDef* containing_type) { _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); const char* name = containing_type ? containing_type->full_name @@ -11441,7 +11958,8 @@ upb_MessageDef* _upb_MessageDefs_New( upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); for (int i = 0; i < n; i++) { - create_msgdef(ctx, name, protos[i], containing_type, &m[i]); + create_msgdef(ctx, name, protos[i], parent_features, containing_type, + &m[i]); } return m; } @@ -11500,7 +12018,8 @@ upb_MessageReservedRange* _upb_MessageReservedRanges_New( // Must be last. struct upb_MethodDef { - const UPB_DESC(MethodOptions) * opts; + const UPB_DESC(MethodOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; upb_ServiceDef* service; const char* full_name; const upb_MessageDef* input_type; @@ -11553,8 +12072,14 @@ bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { } static void create_method(upb_DefBuilder* ctx, - const UPB_DESC(MethodDescriptorProto) * method_proto, + const UPB_DESC(MethodDescriptorProto*) method_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_ServiceDef* s, upb_MethodDef* m) { + UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, + method_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MethodOptions_features)(m->opts)); + upb_StringView name = UPB_DESC(MethodDescriptorProto_name)(method_proto); m->service = s; @@ -11572,18 +12097,17 @@ static void create_method(upb_DefBuilder* ctx, ctx, m->full_name, m->full_name, UPB_DESC(MethodDescriptorProto_output_type)(method_proto), UPB_DEFTYPE_MSG); - - UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, - method_proto); } // Allocate and initialize an array of |n| method defs belonging to |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto) * const* protos, upb_ServiceDef* s) { +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s) { upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); for (int i = 0; i < n; i++) { - create_method(ctx, protos[i], s, &m[i]); + create_method(ctx, protos[i], parent_features, s, &m[i]); m[i].index = i; } return m; @@ -11598,7 +12122,8 @@ upb_MethodDef* _upb_MethodDefs_New( // Must be last. struct upb_OneofDef { - const UPB_DESC(OneofOptions) * opts; + const UPB_DESC(OneofOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MessageDef* parent; const char* full_name; int field_count; @@ -11606,9 +12131,6 @@ struct upb_OneofDef { const upb_FieldDef** fields; upb_strtable ntof; // lookup a field by name upb_inttable itof; // lookup a field by number (index) -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif }; upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { @@ -11742,9 +12264,15 @@ size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { } static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const UPB_DESC(OneofDescriptorProto) * oneof_proto, + const UPB_DESC(OneofDescriptorProto*) oneof_proto, + const UPB_DESC(FeatureSet*) parent_features, const upb_OneofDef* _o) { upb_OneofDef* o = (upb_OneofDef*)_o; + + UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + o->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(OneofOptions_features)(o->opts)); + upb_StringView name = UPB_DESC(OneofDescriptorProto_name)(oneof_proto); o->parent = m; @@ -11753,8 +12281,6 @@ static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, o->field_count = 0; o->synthetic = false; - UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); - if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); } @@ -11771,14 +12297,16 @@ static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, } // Allocate and initialize an array of |n| oneof defs. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto) * const* protos, upb_MessageDef* m) { +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m) { _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); for (int i = 0; i < n; i++) { - create_oneofdef(ctx, m, protos[i], &o[i]); + create_oneofdef(ctx, m, protos[i], parent_features, &o[i]); } return o; } @@ -11788,12 +12316,16 @@ upb_OneofDef* _upb_OneofDefs_New( // Must be last. struct upb_ServiceDef { - const UPB_DESC(ServiceOptions) * opts; + const UPB_DESC(ServiceOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_FileDef* file; const char* full_name; upb_MethodDef* methods; int method_count; int index; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { @@ -11844,37 +12376,40 @@ const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, } static void create_service(upb_DefBuilder* ctx, - const UPB_DESC(ServiceDescriptorProto) * svc_proto, + const UPB_DESC(ServiceDescriptorProto*) svc_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_ServiceDef* s) { - upb_StringView name; - size_t n; + UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, + svc_proto); + s->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(ServiceOptions_features)(s->opts)); // Must happen before _upb_DefBuilder_Add() s->file = _upb_DefBuilder_File(ctx); - name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); + upb_StringView name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); const char* package = _upb_FileDef_RawPackage(s->file); s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); _upb_DefBuilder_Add(ctx, s->full_name, _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); + size_t n; const UPB_DESC(MethodDescriptorProto)* const* methods = UPB_DESC(ServiceDescriptorProto_method)(svc_proto, &n); s->method_count = n; - s->methods = _upb_MethodDefs_New(ctx, n, methods, s); - - UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, - svc_proto); + s->methods = _upb_MethodDefs_New(ctx, n, methods, s->resolved_features, s); } -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(ServiceDescriptorProto) * const* protos) { +upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(ServiceDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features) { _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); for (int i = 0; i < n; i++) { - create_service(ctx, protos[i], &s[i]); + create_service(ctx, protos[i], parent_features, &s[i]); s[i].index = i; } return s; @@ -14895,6 +15430,7 @@ const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, #undef UPB_GNUC_MIN #undef UPB_DESCRIPTOR_UPB_H_FILENAME #undef UPB_DESC +#undef UPB_DESC_MINITABLE #undef UPB_IS_GOOGLE3 #undef UPB_ATOMIC #undef UPB_USE_C11_ATOMICS diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 53562dcd4f..88b8b2206d 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -318,8 +318,13 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #if defined(UPB_IS_GOOGLE3) && !defined(UPB_BOOTSTRAP_STAGE0) #define UPB_DESC(sym) proto2_##sym +#define UPB_DESC_MINITABLE(sym) &proto2__##sym##_msg_init +#elif defined(UPB_BOOTSTRAP_STAGE0) +#define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) google__protobuf__##sym##_msg_init() #else #define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) &google__protobuf__##sym##_msg_init #endif #ifndef UPB_BASE_STATUS_H_ @@ -10156,6 +10161,9 @@ UPB_API void upb_DefPool_Free(upb_DefPool* s); UPB_API upb_DefPool* upb_DefPool_New(void); +UPB_API const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s); + UPB_API const upb_MessageDef* upb_DefPool_FindMessageByName( const upb_DefPool* s, const char* sym); @@ -10247,6 +10255,7 @@ bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, const char* upb_EnumDef_Name(const upb_EnumDef* e); const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e); +const UPB_DESC(FeatureSet) * upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e); upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i); int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e); @@ -10285,6 +10294,8 @@ UPB_API const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v); UPB_API int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v); const UPB_DESC(EnumValueOptions) * upb_EnumValueDef_Options(const upb_EnumValueDef* v); +const UPB_DESC(FeatureSet) * + upb_EnumValueDef_ResolvedFeatures(const upb_EnumValueDef* e); #ifdef __cplusplus } /* extern "C" */ @@ -10311,6 +10322,8 @@ int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); const UPB_DESC(ExtensionRangeOptions) * upb_ExtensionRange_Options(const upb_ExtensionRange* r); +const UPB_DESC(FeatureSet) * + upb_ExtensionRange_ResolvedFeatures(const upb_ExtensionRange* e); #ifdef __cplusplus } /* extern "C" */ @@ -10372,6 +10385,8 @@ const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f); UPB_API const char* upb_FieldDef_Name(const upb_FieldDef* f); UPB_API uint32_t upb_FieldDef_Number(const upb_FieldDef* f); const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f); +const UPB_DESC(FeatureSet) * + upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f); UPB_API const upb_OneofDef* upb_FieldDef_RealContainingOneof( const upb_FieldDef* f); UPB_API upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); @@ -10400,6 +10415,7 @@ int upb_FileDef_DependencyCount(const upb_FileDef* f); bool upb_FileDef_HasOptions(const upb_FileDef* f); UPB_API const char* upb_FileDef_Name(const upb_FileDef* f); const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f); +const UPB_DESC(FeatureSet) * upb_FileDef_ResolvedFeatures(const upb_FileDef* f); const char* upb_FileDef_Package(const upb_FileDef* f); UPB_DESC(Edition) upb_FileDef_Edition(const upb_FileDef* f); UPB_API const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); @@ -10559,6 +10575,8 @@ int upb_MessageDef_RealOneofCount(const upb_MessageDef* m); const UPB_DESC(MessageOptions) * upb_MessageDef_Options(const upb_MessageDef* m); +const UPB_DESC(FeatureSet) * + upb_MessageDef_ResolvedFeatures(const upb_MessageDef* m); upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i); int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m); @@ -10596,6 +10614,8 @@ int upb_MethodDef_Index(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); const char* upb_MethodDef_Name(const upb_MethodDef* m); const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m); +const UPB_DESC(FeatureSet) * + upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); @@ -10636,7 +10656,9 @@ const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, uint32_t num); UPB_API const char* upb_OneofDef_Name(const upb_OneofDef* o); int upb_OneofDef_numfields(const upb_OneofDef* o); -const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o); +const UPB_DESC(OneofOptions*) upb_OneofDef_Options(const upb_OneofDef* o); +const UPB_DESC(FeatureSet*) + upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o); #ifdef __cplusplus } /* extern "C" */ @@ -10668,6 +10690,8 @@ int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); const char* upb_ServiceDef_Name(const upb_ServiceDef* s); const UPB_DESC(ServiceOptions) * upb_ServiceDef_Options(const upb_ServiceDef* s); +const UPB_DESC(FeatureSet) * + upb_ServiceDef_ResolvedFeatures(const upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ @@ -12100,6 +12124,42 @@ UPB_INLINE const char* upb_WireReader_SkipValue( #endif // UPB_WIRE_READER_H_ +#ifndef UPB_MESSAGE_COPY_H_ +#define UPB_MESSAGE_COPY_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Deep clones a message using the provided target arena. +upb_Message* upb_Message_DeepClone(const upb_Message* message, + const upb_MiniTable* mini_table, + upb_Arena* arena); + +// Deep clones array contents. +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena); + +// Deep clones map contents. +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena); + +// Deep copies the message from src to dst. +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, upb_Arena* arena); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_MESSAGE_COPY_H_ + // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// #ifndef UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ @@ -12506,6 +12566,10 @@ extern "C" { struct upb_DefBuilder { upb_DefPool* symtab; + upb_strtable feature_cache; // Caches features by identity. + UPB_DESC(FeatureSet*) legacy_features; // For computing legacy features. + char* tmp_buf; // Temporary buffer in tmp_arena. + size_t tmp_buf_size; // Size of temporary buffer. upb_FileDef* file; // File we are building. upb_Arena* arena; // Allocate defs here. upb_Arena* tmp_arena; // For temporary allocations. @@ -12598,6 +12662,25 @@ UPB_INLINE void _upb_DefBuilder_CheckIdentFull(upb_DefBuilder* ctx, if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, true); } +// Returns true if the returned feature set is new and must be populated. +bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key, + UPB_DESC(FeatureSet**) set); + +const UPB_DESC(FeatureSet*) + _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child, + bool is_implicit); + +UPB_INLINE const UPB_DESC(FeatureSet*) + _upb_DefBuilder_ResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child) { + return _upb_DefBuilder_DoResolveFeatures(ctx, parent, child, false); +} + #ifdef __cplusplus } /* extern "C" */ #endif @@ -12620,10 +12703,11 @@ bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); // Allocate and initialize an array of |n| enum defs. -upb_EnumDef* _upb_EnumDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto) * const* protos, - const upb_MessageDef* containing_type); +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type); #ifdef __cplusplus } /* extern "C" */ @@ -12647,7 +12731,8 @@ upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); // Allocate and initialize an array of |n| enum value defs owned by |e|. upb_EnumValueDef* _upb_EnumValueDefs_New( upb_DefBuilder* ctx, const char* prefix, int n, - const UPB_DESC(EnumValueDescriptorProto) * const* protos, upb_EnumDef* e, + const UPB_DESC(EnumValueDescriptorProto*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, bool* is_sorted); const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, @@ -12684,16 +12769,19 @@ void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, const upb_FieldDef* f); // Allocate and initialize an array of |n| extensions (field defs). -upb_FieldDef* _upb_Extensions_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m); +upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m); // Allocate and initialize an array of |n| field defs. -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted); +upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m, + bool* is_sorted); // Allocate and return a list of pointers to the |n| field defs in |ff|, // sorted by field number. @@ -12758,9 +12846,12 @@ void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); // Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const UPB_DESC(DescriptorProto) * const* protos, - const upb_MessageDef* containing_type); +upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features, + const upb_MessageDef* containing_type); #ifdef __cplusplus } /* extern "C" */ @@ -12782,9 +12873,11 @@ extern "C" { upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); // Allocate and initialize an array of |n| service defs. -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(ServiceDescriptorProto) * const* protos); +upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(ServiceDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features); #ifdef __cplusplus } /* extern "C" */ @@ -12793,6 +12886,20 @@ upb_ServiceDef* _upb_ServiceDefs_New( #endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */ +#ifndef UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ +#define UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ + +// This file contains the serialized FeatureSetDefaults object for +// language-independent features and (possibly at some point) for upb-specific +// features. This is used for feature resolution under Editions. +// NOLINTBEGIN +// clang-format off +#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "\n\021\022\014\010\001\020\002\030\002 \001(\0010\002\030\346\007\n\021\022\014\010\002\020\001\030\001 \002(\0010\001\030\347\007\n\021\022\014\010\001\020\001\030\001 \002(\0010\001\030\350\007 \346\007(\350\007" +// clang-format on +// NOLINTEND + +#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ + #ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ #define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ @@ -12865,7 +12972,7 @@ upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, // Allocate and initialize an array of |n| reserved ranges owned by |e|. upb_EnumReservedRange* _upb_EnumReservedRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, + const UPB_DESC(EnumDescriptorProto_EnumReservedRange*) const* protos, const upb_EnumDef* e); #ifdef __cplusplus @@ -12913,8 +13020,8 @@ upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); // Allocate and initialize an array of |n| extension ranges owned by |m|. upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ExtensionRange) * const* protos, - const upb_MessageDef* m); + const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m); #ifdef __cplusplus } /* extern "C" */ @@ -12938,9 +13045,11 @@ void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, const upb_FieldDef* f, const char* name, size_t size); // Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto) * const* protos, upb_MessageDef* m); +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m); size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); @@ -13012,9 +13121,11 @@ extern "C" { upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); // Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto) * const* protos, upb_ServiceDef* s); +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ @@ -13219,6 +13330,7 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #undef UPB_GNUC_MIN #undef UPB_DESCRIPTOR_UPB_H_FILENAME #undef UPB_DESC +#undef UPB_DESC_MINITABLE #undef UPB_IS_GOOGLE3 #undef UPB_ATOMIC #undef UPB_USE_C11_ATOMICS diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 8790a0e32d..332aaea4e5 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -319,8 +319,13 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #if defined(UPB_IS_GOOGLE3) && !defined(UPB_BOOTSTRAP_STAGE0) #define UPB_DESC(sym) proto2_##sym +#define UPB_DESC_MINITABLE(sym) &proto2__##sym##_msg_init +#elif defined(UPB_BOOTSTRAP_STAGE0) +#define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) google__protobuf__##sym##_msg_init() #else #define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) &google__protobuf__##sym##_msg_init #endif @@ -5395,6 +5400,289 @@ bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, } +#include +#include + + +// Must be last. + +static bool upb_MessageField_IsMap(const upb_MiniTableField* field) { + return upb_FieldMode_Get(field) == kUpb_FieldMode_Map; +} + +static upb_StringView upb_Clone_StringView(upb_StringView str, + upb_Arena* arena) { + if (str.size == 0) { + return upb_StringView_FromDataAndSize(NULL, 0); + } + void* cloned_data = upb_Arena_Malloc(arena, str.size); + upb_StringView cloned_str = + upb_StringView_FromDataAndSize(cloned_data, str.size); + memcpy(cloned_data, str.data, str.size); + return cloned_str; +} + +static bool upb_Clone_MessageValue(void* value, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + switch (value_type) { + case kUpb_CType_Bool: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return true; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView source = *(upb_StringView*)value; + int size = source.size; + void* cloned_data = upb_Arena_Malloc(arena, size); + if (cloned_data == NULL) { + return false; + } + *(upb_StringView*)value = + upb_StringView_FromDataAndSize(cloned_data, size); + memcpy(cloned_data, source.data, size); + return true; + } break; + case kUpb_CType_Message: { + const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; + bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); + if (is_empty) sub = &_kUpb_MiniTable_Empty; + UPB_ASSERT(source); + upb_Message* clone = upb_Message_DeepClone( + _upb_TaggedMessagePtr_GetMessage(source), sub, arena); + *(upb_TaggedMessagePtr*)value = + _upb_TaggedMessagePtr_Pack(clone, is_empty); + return clone != NULL; + } break; + } + UPB_UNREACHABLE(); +} + +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena) { + upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); + if (cloned_map == NULL) { + return NULL; + } + upb_MessageValue key, val; + size_t iter = kUpb_Map_Begin; + while (upb_Map_Next(map, &key, &val, &iter)) { + const upb_MiniTableField* value_field = &map_entry_table->fields[1]; + const upb_MiniTable* value_sub = + (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) + ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) + : NULL; + upb_CType value_field_type = upb_MiniTableField_CType(value_field); + if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { + return NULL; + } + if (upb_Map_Insert(cloned_map, key, val, arena) == + kUpb_MapInsertStatus_OutOfMemory) { + return NULL; + } + } + return cloned_map; +} + +static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, + const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* clone, + upb_Arena* arena) { + const upb_MiniTable* map_entry_table = + mini_table->subs[field->UPB_PRIVATE(submsg_index)].submsg; + UPB_ASSERT(map_entry_table); + + const upb_MiniTableField* key_field = &map_entry_table->fields[0]; + const upb_MiniTableField* value_field = &map_entry_table->fields[1]; + + upb_Map* cloned_map = upb_Map_DeepClone( + map, upb_MiniTableField_CType(key_field), + upb_MiniTableField_CType(value_field), map_entry_table, arena); + if (!cloned_map) { + return NULL; + } + _upb_Message_SetNonExtensionField(clone, field, &cloned_map); + return cloned_map; +} + +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + size_t size = array->size; + upb_Array* cloned_array = + _upb_Array_New(arena, size, _upb_Array_CTypeSizeLg2(value_type)); + if (!cloned_array) { + return NULL; + } + if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { + return NULL; + } + for (size_t i = 0; i < size; ++i) { + upb_MessageValue val = upb_Array_Get(array, i); + if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { + return false; + } + upb_Array_Set(cloned_array, i, val); + } + return cloned_array; +} + +static bool upb_Message_Array_DeepClone(const upb_Array* array, + const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* clone, upb_Arena* arena) { + _upb_MiniTableField_CheckIsArray(field); + upb_Array* cloned_array = upb_Array_DeepClone( + array, upb_MiniTableField_CType(field), + upb_MiniTableField_CType(field) == kUpb_CType_Message && + field->UPB_PRIVATE(submsg_index) != kUpb_NoSub + ? upb_MiniTable_GetSubMessageTable(mini_table, field) + : NULL, + arena); + + // Clear out upb_Array* due to parent memcpy. + _upb_Message_SetNonExtensionField(clone, field, &cloned_array); + return true; +} + +static bool upb_Clone_ExtensionValue( + const upb_MiniTableExtension* mini_table_ext, + const upb_Message_Extension* source, upb_Message_Extension* dest, + upb_Arena* arena) { + dest->data = source->data; + return upb_Clone_MessageValue( + &dest->data, upb_MiniTableField_CType(&mini_table_ext->field), + mini_table_ext->sub.submsg, arena); +} + +upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, + upb_Arena* arena) { + upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); + // Only copy message area skipping upb_Message_Internal. + memcpy(dst, src, mini_table->size); + for (size_t i = 0; i < mini_table->field_count; ++i) { + const upb_MiniTableField* field = &mini_table->fields[i]; + if (!upb_IsRepeatedOrMap(field)) { + switch (upb_MiniTableField_CType(field)) { + case kUpb_CType_Message: { + upb_TaggedMessagePtr tagged = + upb_Message_GetTaggedMessagePtr(src, field, NULL); + const upb_Message* sub_message = + _upb_TaggedMessagePtr_GetMessage(tagged); + if (sub_message != NULL) { + // If the message is currently in an unlinked, "empty" state we keep + // it that way, because we don't want to deal with decode options, + // decode status, or possible parse failure here. + bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); + const upb_MiniTable* sub_message_table = + is_empty ? &_kUpb_MiniTable_Empty + : upb_MiniTable_GetSubMessageTable(mini_table, field); + upb_Message* dst_sub_message = + upb_Message_DeepClone(sub_message, sub_message_table, arena); + if (dst_sub_message == NULL) { + return NULL; + } + _upb_Message_SetTaggedMessagePtr( + dst, mini_table, field, + _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); + } + } break; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView str = upb_Message_GetString(src, field, empty_string); + if (str.size != 0) { + if (!upb_Message_SetString( + dst, field, upb_Clone_StringView(str, arena), arena)) { + return NULL; + } + } + } break; + default: + // Scalar, already copied. + break; + } + } else { + if (upb_MessageField_IsMap(field)) { + const upb_Map* map = upb_Message_GetMap(src, field); + if (map != NULL) { + if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { + return NULL; + } + } + } else { + const upb_Array* array = upb_Message_GetArray(src, field); + if (array != NULL) { + if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, + arena)) { + return NULL; + } + } + } + } + } + // Clone extensions. + size_t ext_count; + const upb_Message_Extension* ext = _upb_Message_Getexts(src, &ext_count); + for (size_t i = 0; i < ext_count; ++i) { + const upb_Message_Extension* msg_ext = &ext[i]; + const upb_MiniTableField* field = &msg_ext->ext->field; + upb_Message_Extension* dst_ext = + _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); + if (!dst_ext) return NULL; + if (!upb_IsRepeatedOrMap(field)) { + if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { + return NULL; + } + } else { + upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; + UPB_ASSERT(msg_array); + upb_Array* cloned_array = + upb_Array_DeepClone(msg_array, upb_MiniTableField_CType(field), + msg_ext->ext->sub.submsg, arena); + if (!cloned_array) { + return NULL; + } + dst_ext->data.ptr = (void*)cloned_array; + } + } + + // Clone unknowns. + size_t unknown_size = 0; + const char* ptr = upb_Message_GetUnknown(src, &unknown_size); + if (unknown_size != 0) { + UPB_ASSERT(ptr); + // Make a copy into destination arena. + if (!_upb_Message_AddUnknown(dst, ptr, unknown_size, arena)) { + return NULL; + } + } + return dst; +} + +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, upb_Arena* arena) { + upb_Message_Clear(dst, mini_table); + return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; +} + +// Deep clones a message using the provided target arena. +// +// Returns NULL on failure. +upb_Message* upb_Message_DeepClone(const upb_Message* message, + const upb_MiniTable* mini_table, + upb_Arena* arena) { + upb_Message* clone = upb_Message_New(mini_table, arena); + return _upb_Message_Copy(clone, message, mini_table, arena); +} + + #include // Must be last. @@ -7483,6 +7771,7 @@ struct upb_DefPool { upb_strtable files; // file_name -> (upb_FileDef*) upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) upb_ExtensionRegistry* extreg; + const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; upb_MiniTablePlatform platform; void* scratch_data; size_t scratch_size; @@ -7495,6 +7784,8 @@ void upb_DefPool_Free(upb_DefPool* s) { upb_gfree(s); } +static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; + upb_DefPool* upb_DefPool_New(void) { upb_DefPool* s = upb_gmalloc(sizeof(*s)); if (!s) return NULL; @@ -7514,6 +7805,10 @@ upb_DefPool* upb_DefPool_New(void) { if (!s->extreg) goto err; s->platform = kUpb_MiniTablePlatform_Native; + s->feature_set_defaults = UPB_DESC(FeatureSetDefaults_parse)( + serialized_defaults, sizeof(serialized_defaults) - 1, s->arena); + + if (!s->feature_set_defaults) goto err; return s; @@ -7522,6 +7817,11 @@ err: return NULL; } +const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { + return s->feature_set_defaults; +} + bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, const upb_FieldDef* f) { return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), @@ -7735,7 +8035,11 @@ static const upb_FileDef* upb_DefBuilder_AddFileToPool( remove_filedef(s, builder->file); builder->file = NULL; } - } else if (!builder->arena || !builder->tmp_arena) { + } else if (!builder->arena || !builder->tmp_arena || + !upb_strtable_init(&builder->feature_cache, 16, + builder->tmp_arena) || + !(builder->legacy_features = + UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { _upb_DefBuilder_OomErr(builder); } else { _upb_FileDef_Create(builder, file_proto); @@ -7768,6 +8072,8 @@ static const upb_FileDef* _upb_DefPool_AddFile( upb_DefBuilder ctx = { .symtab = s, + .tmp_buf = NULL, + .tmp_buf_size = 0, .layout = layout, .platform = s->platform, .msg_count = 0, @@ -7950,7 +8256,8 @@ bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { // Must be last. struct upb_EnumDef { - const UPB_DESC(EnumOptions) * opts; + const UPB_DESC(EnumOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MiniTableEnum* layout; // Only for proto2. const upb_FileDef* file; const upb_MessageDef* containing_type; // Could be merged with "file". @@ -7964,8 +8271,10 @@ struct upb_EnumDef { int res_range_count; int res_name_count; int32_t defaultval; - bool is_closed; bool is_sorted; // Whether all of the values are defined in ascending order. +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { @@ -8067,7 +8376,11 @@ const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { return _upb_EnumValueDef_At(e->values, i); } -bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { return e->is_closed; } +bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; + return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) == + UPB_DESC(FeatureSet_CLOSED); +} bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, upb_StringView* out) { @@ -8136,6 +8449,7 @@ static upb_StringView* _upb_EnumReservedNames_New( static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, const UPB_DESC(EnumDescriptorProto) * enum_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e) { const UPB_DESC(EnumValueDescriptorProto)* const* values; const UPB_DESC(EnumDescriptorProto_EnumReservedRange)* const* res_ranges; @@ -8143,6 +8457,10 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, upb_StringView name; size_t n_value, n_res_range, n_res_name; + UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); + e->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumOptions_features)(e->opts)); + // Must happen before _upb_DefBuilder_Add() e->file = _upb_DefBuilder_File(ctx); @@ -8152,9 +8470,6 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, _upb_DefBuilder_Add(ctx, e->full_name, _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - e->is_closed = (!UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) && - (upb_FileDef_Syntax(e->file) == kUpb_Syntax_Proto2); - values = UPB_DESC(EnumDescriptorProto_value)(enum_proto, &n_value); bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); @@ -8165,8 +8480,8 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, e->defaultval = 0; e->value_count = n_value; - e->values = - _upb_EnumValueDefs_New(ctx, prefix, n_value, values, e, &e->is_sorted); + e->values = _upb_EnumValueDefs_New(ctx, prefix, n_value, values, + e->resolved_features, e, &e->is_sorted); if (n_value == 0) { _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", @@ -8183,11 +8498,9 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, e->res_name_count = n_res_name; e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); - UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - upb_inttable_compact(&e->iton, ctx->arena); - if (e->is_closed) { + if (upb_EnumDef_IsClosed(e)) { if (ctx->layout) { UPB_ASSERT(ctx->enum_count < ctx->layout->enum_count); e->layout = ctx->layout->enums[ctx->enum_count++]; @@ -8199,10 +8512,11 @@ static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, } } -upb_EnumDef* _upb_EnumDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto) * const* protos, - const upb_MessageDef* containing_type) { +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type) { _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); // If a containing type is defined then get the full name from that. @@ -8212,7 +8526,7 @@ upb_EnumDef* _upb_EnumDefs_New( upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); for (int i = 0; i < n; i++) { - create_enumdef(ctx, name, protos[i], &e[i]); + create_enumdef(ctx, name, protos[i], parent_features, &e[i]); e[i].containing_type = containing_type; } return e; @@ -8271,14 +8585,20 @@ upb_EnumReservedRange* _upb_EnumReservedRanges_New( } +#include + // Must be last. struct upb_EnumValueDef { - const UPB_DESC(EnumValueOptions) * opts; + const UPB_DESC(EnumValueOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_EnumDef* parent; const char* full_name; int32_t number; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { @@ -8335,9 +8655,15 @@ uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { } static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(EnumValueDescriptorProto) * + const UPB_DESC(EnumValueDescriptorProto*) val_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, upb_EnumValueDef* v) { + UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, + val_proto); + v->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumValueOptions_features)(v->opts)); + upb_StringView name = UPB_DESC(EnumValueDescriptorProto_name)(val_proto); v->parent = e; // Must happen prior to _upb_DefBuilder_Add() @@ -8346,17 +8672,32 @@ static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, _upb_DefBuilder_Add(ctx, v->full_name, _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, - val_proto); - bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); } +static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx, + const upb_EnumDef* e, + const upb_EnumValueDef* v, int n) { + if (upb_EnumDef_IsClosed(e) || n == 0 || v[0].number == 0) return; + + // When the special UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 is enabled, we have to + // exempt proto2 enums from this check, even when we are treating them as + // open. + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 && + upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) { + return; + } + + _upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)", + upb_EnumDef_FullName(e)); +} + // Allocate and initialize an array of |n| enum value defs owned by |e|. upb_EnumValueDef* _upb_EnumValueDefs_New( upb_DefBuilder* ctx, const char* prefix, int n, - const UPB_DESC(EnumValueDescriptorProto) * const* protos, upb_EnumDef* e, + const UPB_DESC(EnumValueDescriptorProto*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, bool* is_sorted) { _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); @@ -8366,29 +8707,27 @@ upb_EnumValueDef* _upb_EnumValueDefs_New( *is_sorted = true; uint32_t previous = 0; for (int i = 0; i < n; i++) { - create_enumvaldef(ctx, prefix, protos[i], e, &v[i]); + create_enumvaldef(ctx, prefix, protos[i], parent_features, e, &v[i]); const uint32_t current = v[i].number; if (previous > current) *is_sorted = false; previous = current; } - if (upb_FileDef_Syntax(ctx->file) == kUpb_Syntax_Proto3 && n > 0 && - v[0].number != 0) { - _upb_DefBuilder_Errf(ctx, - "for proto3, the first enum value must be zero (%s)", - upb_EnumDef_FullName(e)); - } + _upb_EnumValueDef_CheckZeroValue(ctx, e, v, n); return v; } +#include + // Must be last. struct upb_ExtensionRange { - const UPB_DESC(ExtensionRangeOptions) * opts; + const UPB_DESC(ExtensionRangeOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; int32_t start; int32_t end; }; @@ -8414,12 +8753,18 @@ int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ExtensionRange) * const* protos, - const upb_MessageDef* m) { + const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m) { upb_ExtensionRange* r = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); for (int i = 0; i < n; i++) { + UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, + ExtensionRangeOptions, protos[i]); + r[i].resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, + UPB_DESC(ExtensionRangeOptions_features)(r[i].opts)); + const int32_t start = UPB_DESC(DescriptorProto_ExtensionRange_start)(protos[i]); const int32_t end = UPB_DESC(DescriptorProto_ExtensionRange_end)(protos[i]); @@ -8439,8 +8784,6 @@ upb_ExtensionRange* _upb_ExtensionRanges_New( r[i].start = start; r[i].end = end; - UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, - ExtensionRangeOptions, protos[i]); } return r; @@ -8462,7 +8805,8 @@ typedef struct { } str_t; struct upb_FieldDef { - const UPB_DESC(FieldOptions) * opts; + const UPB_DESC(FieldOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_FileDef* file; const upb_MessageDef* msgdef; const char* full_name; @@ -8492,13 +8836,9 @@ struct upb_FieldDef { bool has_json_name; bool has_presence; bool is_extension; - bool is_packed; bool is_proto3_optional; upb_FieldType type_; upb_Label label_; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif }; upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { @@ -8567,7 +8907,9 @@ bool _upb_FieldDef_IsPackable(const upb_FieldDef* f) { } bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { - return _upb_FieldDef_IsPackable(f) && f->is_packed; + return _upb_FieldDef_IsPackable(f) && + UPB_DESC(FeatureSet_repeated_field_encoding(f->resolved_features)) == + UPB_DESC(FeatureSet_PACKED); } const char* upb_FieldDef_Name(const upb_FieldDef* f) { @@ -8680,44 +9022,21 @@ bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } -// begin:google_only -// static bool _upb_FieldDef_EnforceUtf8Option(const upb_FieldDef* f) { -// #if defined(UPB_BOOTSTRAP_STAGE0) -// return true; -// #else -// return UPB_DESC(FieldOptions_enforce_utf8)(f->opts); -// #endif -// } -// end:google_only - -// begin:github_only -static bool _upb_FieldDef_EnforceUtf8Option(const upb_FieldDef* f) { - return true; -} -// end:github_only - bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) { if (upb_FieldDef_Type(f) != kUpb_FieldType_String) return false; - return upb_FileDef_Syntax(upb_FieldDef_File(f)) == kUpb_Syntax_Proto3 - ? _upb_FieldDef_EnforceUtf8Option(f) - : false; + return UPB_DESC(FeatureSet_utf8_validation(f->resolved_features)) == + UPB_DESC(FeatureSet_VERIFY); } uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0; - switch (f->label_) { - case kUpb_Label_Optional: - if (!upb_FieldDef_HasPresence(f)) { - out |= kUpb_FieldModifier_IsProto3Singular; - } - break; - case kUpb_Label_Repeated: - out |= kUpb_FieldModifier_IsRepeated; - break; - case kUpb_Label_Required: - out |= kUpb_FieldModifier_IsRequired; - break; + if (upb_FieldDef_IsRepeated(f)) { + out |= kUpb_FieldModifier_IsRepeated; + } else if (upb_FieldDef_IsRequired(f)) { + out |= kUpb_FieldModifier_IsRequired; + } else if (!upb_FieldDef_HasPresence(f)) { + out |= kUpb_FieldModifier_IsProto3Singular; } if (_upb_FieldDef_IsClosedEnum(f)) { @@ -8757,7 +9076,8 @@ bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { } bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Required; + return UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED); } bool upb_FieldDef_IsString(const upb_FieldDef* f) { @@ -8981,19 +9301,63 @@ static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { } } +static bool _upb_FieldDef_InferLegacyFeatures( + upb_DefBuilder* ctx, upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto*) proto, + const UPB_DESC(FieldOptions*) options, upb_Syntax syntax, + UPB_DESC(FeatureSet*) features) { + bool ret = false; + + if (UPB_DESC(FieldDescriptorProto_label)(proto) == kUpb_Label_Required) { + if (syntax == kUpb_Syntax_Proto3) { + _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", + f->full_name); + } + int val = UPB_DESC(FeatureSet_LEGACY_REQUIRED); + UPB_DESC(FeatureSet_set_field_presence(features, val)); + ret = true; + } + + if (UPB_DESC(FieldDescriptorProto_type)(proto) == kUpb_FieldType_Group) { + int val = UPB_DESC(FeatureSet_DELIMITED); + UPB_DESC(FeatureSet_set_message_encoding(features, val)); + ret = true; + } + + if (UPB_DESC(FieldOptions_has_packed)(options)) { + int val = UPB_DESC(FieldOptions_packed)(options) + ? UPB_DESC(FeatureSet_PACKED) + : UPB_DESC(FeatureSet_EXPANDED); + UPB_DESC(FeatureSet_set_repeated_field_encoding(features, val)); + ret = true; + } + +// begin:google_only +// #ifndef UPB_BOOTSTRAP_STAGE0 +// if (syntax == kUpb_Syntax_Proto3 && +// UPB_DESC(FieldOptions_has_enforce_utf8)(options) && +// !UPB_DESC(FieldOptions_enforce_utf8)(options)) { +// int val = UPB_DESC(FeatureSet_UNVERIFIED); +// UPB_DESC(FeatureSet_set_utf8_validation(features, val)); +// ret = true; +// } +// #endif +// // clang-format off +// end:google_only + // clang-format on + + return ret; +} + static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { // Must happen before _upb_DefBuilder_Add() f->file = _upb_DefBuilder_File(ctx); - if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "field has no name"); - } - const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto); - f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto); f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto); @@ -9002,6 +9366,29 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, f->msgdef = m; f->scope.oneof = NULL; + UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); + + upb_Syntax syntax = upb_FileDef_Syntax(f->file); + const UPB_DESC(FeatureSet*) unresolved_features = + UPB_DESC(FieldOptions_features)(f->opts); + bool implicit = false; + + if (syntax != kUpb_Syntax_Editions) { + upb_Message_Clear(ctx->legacy_features, UPB_DESC_MINITABLE(FeatureSet)); + if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, + ctx->legacy_features)) { + implicit = true; + unresolved_features = ctx->legacy_features; + } + } + + f->resolved_features = _upb_DefBuilder_DoResolveFeatures( + ctx, parent_features, unresolved_features, implicit); + + if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "field has no name"); + } + f->has_json_name = UPB_DESC(FieldDescriptorProto_has_json_name)(field_proto); if (f->has_json_name) { const upb_StringView sv = @@ -9057,12 +9444,6 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, * to the field_proto until later when we can properly resolve it. */ f->sub.unresolved = field_proto; - if (f->label_ == kUpb_Label_Required && - upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", - f->full_name); - } - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); @@ -9086,27 +9467,21 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); } - UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); - - if (UPB_DESC(FieldOptions_has_packed)(f->opts)) { - f->is_packed = UPB_DESC(FieldOptions_packed)(f->opts); - } else { - f->is_packed = upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3; - } - f->has_presence = (!upb_FieldDef_IsRepeated(f)) && (f->type_ == kUpb_FieldType_Message || f->type_ == kUpb_FieldType_Group || upb_FieldDef_ContainingOneof(f) || - (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto2)); + UPB_DESC(FeatureSet_field_presence)(f->resolved_features) != + UPB_DESC(FeatureSet_IMPLICIT)); } static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { f->is_extension = true; - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", @@ -9123,11 +9498,13 @@ static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, } static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FieldDescriptorProto) * + const UPB_DESC(FeatureSet*) + parent_features, + const UPB_DESC(FieldDescriptorProto*) field_proto, upb_MessageDef* m, upb_FieldDef* f) { f->is_extension = false; - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); if (!UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { if (f->is_proto3_optional) { @@ -9141,10 +9518,11 @@ static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, _upb_MessageDef_InsertField(ctx, m, f); } -upb_FieldDef* _upb_Extensions_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m) { +upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m) { _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); upb_FieldDef* defs = (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); @@ -9152,17 +9530,19 @@ upb_FieldDef* _upb_Extensions_New( for (int i = 0; i < n; i++) { upb_FieldDef* f = &defs[i]; - _upb_FieldDef_CreateExt(ctx, prefix, protos[i], m, f); + _upb_FieldDef_CreateExt(ctx, prefix, parent_features, protos[i], m, f); f->index_ = i; } return defs; } -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted) { +upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m, + bool* is_sorted) { _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); upb_FieldDef* defs = (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); @@ -9171,7 +9551,7 @@ upb_FieldDef* _upb_FieldDefs_New( for (int i = 0; i < n; i++) { upb_FieldDef* f = &defs[i]; - _upb_FieldDef_CreateNotExt(ctx, prefix, protos[i], m, f); + _upb_FieldDef_CreateNotExt(ctx, prefix, parent_features, protos[i], m, f); f->index_ = i; if (!ctx->layout) { // Speculate that the def fields are sorted. We will always sort the @@ -9375,11 +9755,14 @@ void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, } +#include + // Must be last. struct upb_FileDef { - const UPB_DESC(FileOptions) * opts; + const UPB_DESC(FileOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const char* name; const char* package; UPB_DESC(Edition) edition; @@ -9409,6 +9792,11 @@ const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { return f->opts; } +const UPB_DESC(FeatureSet) * + upb_FileDef_ResolvedFeatures(const upb_FileDef* f) { + return f->resolved_features; +} + bool upb_FileDef_HasOptions(const upb_FileDef* f) { return f->opts != (void*)kUpbDefOptDefault; } @@ -9525,6 +9913,34 @@ static int count_exts_in_msg(const UPB_DESC(DescriptorProto) * msg_proto) { return ext_count; } +const UPB_DESC(FeatureSet*) + _upb_FileDef_FindEdition(upb_DefBuilder* ctx, int edition) { + const UPB_DESC(FeatureSetDefaults)* defaults = + upb_DefPool_FeatureSetDefaults(ctx->symtab); + + int min = UPB_DESC(FeatureSetDefaults_minimum_edition)(defaults); + int max = UPB_DESC(FeatureSetDefaults_maximum_edition)(defaults); + if (edition < min || edition > max) { + _upb_DefBuilder_Errf(ctx, + "Edition %d is outside the supported range [%d, %d] " + "given in the defaults", + edition, min, max); + } + + size_t n; + const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d = + UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n); + const UPB_DESC(FeatureSet)* ret = NULL; + for (size_t i = 0; i < n; i++) { + if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) > + edition) { + break; + } + ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]); + } + return ret; +} + // Allocate and initialize one file def, and add it to the context object. void _upb_FileDef_Create(upb_DefBuilder* ctx, const UPB_DESC(FileDescriptorProto) * file_proto) { @@ -9593,21 +10009,33 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, if (streql_view(syntax, "proto2")) { file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); } else if (streql_view(syntax, "proto3")) { file->syntax = kUpb_Syntax_Proto3; + file->edition = UPB_DESC(EDITION_PROTO3); } else if (streql_view(syntax, "editions")) { file->syntax = kUpb_Syntax_Editions; + file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); } else { _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", UPB_STRINGVIEW_ARGS(syntax)); } } else { file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); } // Read options. UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); + // Resolve features. + const UPB_DESC(FeatureSet*) edition_defaults = + _upb_FileDef_FindEdition(ctx, file->edition); + const UPB_DESC(FeatureSet*) unresolved = + UPB_DESC(FileOptions_features)(file->opts); + file->resolved_features = + _upb_DefBuilder_ResolveFeatures(ctx, edition_defaults, unresolved); + // Verify dependencies. strs = UPB_DESC(FileDescriptorProto_dependency)(file_proto, &n); file->dep_count = n; @@ -9653,22 +10081,26 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, // Create enums. enums = UPB_DESC(FileDescriptorProto_enum_type)(file_proto, &n); file->top_lvl_enum_count = n; - file->top_lvl_enums = _upb_EnumDefs_New(ctx, n, enums, NULL); + file->top_lvl_enums = + _upb_EnumDefs_New(ctx, n, enums, file->resolved_features, NULL); // Create extensions. exts = UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); file->top_lvl_ext_count = n; - file->top_lvl_exts = _upb_Extensions_New(ctx, n, exts, file->package, NULL); + file->top_lvl_exts = _upb_Extensions_New( + ctx, n, exts, file->resolved_features, file->package, NULL); // Create messages. msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); file->top_lvl_msg_count = n; - file->top_lvl_msgs = _upb_MessageDefs_New(ctx, n, msgs, NULL); + file->top_lvl_msgs = + _upb_MessageDefs_New(ctx, n, msgs, file->resolved_features, NULL); // Create services. services = UPB_DESC(FileDescriptorProto_service)(file_proto, &n); file->service_count = n; - file->services = _upb_ServiceDefs_New(ctx, n, services); + file->services = + _upb_ServiceDefs_New(ctx, n, services, file->resolved_features); // Now that all names are in the table, build layouts and resolve refs. @@ -10031,6 +10463,77 @@ void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, UPB_ASSERT(false); } +upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key) { + size_t need = key.size + sizeof(void*); + if (ctx->tmp_buf_size < need) { + ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need)); + ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size); + if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx); + } + + memcpy(ctx->tmp_buf, &parent, sizeof(void*)); + memcpy(ctx->tmp_buf + sizeof(void*), key.data, key.size); + return upb_StringView_FromDataAndSize(ctx->tmp_buf, need); +} + +bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key, + UPB_DESC(FeatureSet**) set) { + upb_StringView k = _upb_DefBuilder_MakeKey(ctx, parent, key); + upb_value v; + if (upb_strtable_lookup2(&ctx->feature_cache, k.data, k.size, &v)) { + *set = upb_value_getptr(v); + return false; + } + + *set = + upb_Message_DeepClone(parent, UPB_DESC_MINITABLE(FeatureSet), ctx->arena); + if (!*set) _upb_DefBuilder_OomErr(ctx); + + v = upb_value_ptr(*set); + if (!upb_strtable_insert(&ctx->feature_cache, k.data, k.size, v, + ctx->tmp_arena)) { + _upb_DefBuilder_OomErr(ctx); + } + + return true; +} + +const UPB_DESC(FeatureSet*) + _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child, + bool is_implicit) { + assert(parent); + if (!child) return parent; + + if (child && !is_implicit && + upb_FileDef_Syntax(ctx->file) != kUpb_Syntax_Editions) { + _upb_DefBuilder_Errf(ctx, "Features can only be specified for editions"); + } + + UPB_DESC(FeatureSet*) resolved; + size_t child_size; + const char* child_bytes = + UPB_DESC(FeatureSet_serialize)(child, ctx->tmp_arena, &child_size); + if (!child_bytes) _upb_DefBuilder_OomErr(ctx); + + upb_StringView key = upb_StringView_FromDataAndSize(child_bytes, child_size); + if (!_upb_DefBuilder_GetOrCreateFeatureSet(ctx, parent, key, &resolved)) { + return resolved; + } + + upb_DecodeStatus dec_status = + upb_Decode(child_bytes, child_size, resolved, + UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); + if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); + + return resolved; +} + #include @@ -10254,7 +10757,8 @@ bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, // Must be last. struct upb_MessageDef { - const UPB_DESC(MessageOptions) * opts; + const UPB_DESC(MessageOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MiniTable* layout; const upb_FileDef* file; const upb_MessageDef* containing_type; @@ -10292,6 +10796,9 @@ struct upb_MessageDef { bool in_message_set; bool is_sorted; upb_WellKnown well_known_type; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; static void assign_msg_wellknowntype(upb_MessageDef* m) { @@ -10623,10 +11130,9 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); - // TODO: Once editions is supported this should turn into a - // check on LEGACY_BEST_EFFORT if (strcmp(shortname, json_name) != 0 && - upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3 && + UPB_DESC(FeatureSet_json_format)(m->resolved_features) == + UPB_DESC(FeatureSet_ALLOW) && upb_strtable_lookup(&m->ntof, json_name, &v)) { _upb_DefBuilder_Errf( ctx, "duplicate json_name for (%s) with original field name (%s)", @@ -10743,7 +11249,8 @@ static bool _upb_MessageDef_ValidateUtf8(const upb_MessageDef* m) { static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { uint64_t out = 0; - if (upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3) { + if (UPB_DESC(FeatureSet_repeated_field_encoding(m->resolved_features)) == + UPB_DESC(FeatureSet_PACKED)) { out |= kUpb_MessageModifier_DefaultIsPacked; } @@ -10857,7 +11364,8 @@ static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, } static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(DescriptorProto) * msg_proto, + const UPB_DESC(DescriptorProto*) msg_proto, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* containing_type, upb_MessageDef* m) { const UPB_DESC(OneofDescriptorProto)* const* oneofs; @@ -10869,6 +11377,10 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, size_t n_ext_range, n_res_range, n_res_name; upb_StringView name; + UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MessageOptions_features)(m->opts)); + // Must happen before _upb_DefBuilder_Add() m->file = _upb_DefBuilder_File(ctx); @@ -10897,14 +11409,12 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); - UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); - m->oneof_count = n_oneof; - m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m); + m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m->resolved_features, m); m->field_count = n_field; - m->fields = - _upb_FieldDefs_New(ctx, n_field, fields, m->full_name, m, &m->is_sorted); + m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->resolved_features, + m->full_name, m, &m->is_sorted); // Message Sets may not contain fields. if (UPB_UNLIKELY(UPB_DESC(MessageOptions_message_set_wire_format)(m->opts))) { @@ -10914,7 +11424,8 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, } m->ext_range_count = n_ext_range; - m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, m); + m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, + m->resolved_features, m); m->res_range_count = n_res_range; m->res_ranges = @@ -10932,23 +11443,29 @@ static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, const UPB_DESC(EnumDescriptorProto)* const* enums = UPB_DESC(DescriptorProto_enum_type)(msg_proto, &n_enum); m->nested_enum_count = n_enum; - m->nested_enums = _upb_EnumDefs_New(ctx, n_enum, enums, m); + m->nested_enums = + _upb_EnumDefs_New(ctx, n_enum, enums, m->resolved_features, m); const UPB_DESC(FieldDescriptorProto)* const* exts = UPB_DESC(DescriptorProto_extension)(msg_proto, &n_ext); m->nested_ext_count = n_ext; - m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->full_name, m); + m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->resolved_features, + m->full_name, m); const UPB_DESC(DescriptorProto)* const* msgs = UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n_msg); m->nested_msg_count = n_msg; - m->nested_msgs = _upb_MessageDefs_New(ctx, n_msg, msgs, m); + m->nested_msgs = + _upb_MessageDefs_New(ctx, n_msg, msgs, m->resolved_features, m); } // Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const UPB_DESC(DescriptorProto) * const* protos, - const upb_MessageDef* containing_type) { +upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features, + const upb_MessageDef* containing_type) { _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); const char* name = containing_type ? containing_type->full_name @@ -10956,7 +11473,8 @@ upb_MessageDef* _upb_MessageDefs_New( upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); for (int i = 0; i < n; i++) { - create_msgdef(ctx, name, protos[i], containing_type, &m[i]); + create_msgdef(ctx, name, protos[i], parent_features, containing_type, + &m[i]); } return m; } @@ -11015,7 +11533,8 @@ upb_MessageReservedRange* _upb_MessageReservedRanges_New( // Must be last. struct upb_MethodDef { - const UPB_DESC(MethodOptions) * opts; + const UPB_DESC(MethodOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; upb_ServiceDef* service; const char* full_name; const upb_MessageDef* input_type; @@ -11068,8 +11587,14 @@ bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { } static void create_method(upb_DefBuilder* ctx, - const UPB_DESC(MethodDescriptorProto) * method_proto, + const UPB_DESC(MethodDescriptorProto*) method_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_ServiceDef* s, upb_MethodDef* m) { + UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, + method_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MethodOptions_features)(m->opts)); + upb_StringView name = UPB_DESC(MethodDescriptorProto_name)(method_proto); m->service = s; @@ -11087,18 +11612,17 @@ static void create_method(upb_DefBuilder* ctx, ctx, m->full_name, m->full_name, UPB_DESC(MethodDescriptorProto_output_type)(method_proto), UPB_DEFTYPE_MSG); - - UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, - method_proto); } // Allocate and initialize an array of |n| method defs belonging to |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto) * const* protos, upb_ServiceDef* s) { +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s) { upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); for (int i = 0; i < n; i++) { - create_method(ctx, protos[i], s, &m[i]); + create_method(ctx, protos[i], parent_features, s, &m[i]); m[i].index = i; } return m; @@ -11113,7 +11637,8 @@ upb_MethodDef* _upb_MethodDefs_New( // Must be last. struct upb_OneofDef { - const UPB_DESC(OneofOptions) * opts; + const UPB_DESC(OneofOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_MessageDef* parent; const char* full_name; int field_count; @@ -11121,9 +11646,6 @@ struct upb_OneofDef { const upb_FieldDef** fields; upb_strtable ntof; // lookup a field by name upb_inttable itof; // lookup a field by number (index) -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif }; upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { @@ -11257,9 +11779,15 @@ size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { } static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const UPB_DESC(OneofDescriptorProto) * oneof_proto, + const UPB_DESC(OneofDescriptorProto*) oneof_proto, + const UPB_DESC(FeatureSet*) parent_features, const upb_OneofDef* _o) { upb_OneofDef* o = (upb_OneofDef*)_o; + + UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + o->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(OneofOptions_features)(o->opts)); + upb_StringView name = UPB_DESC(OneofDescriptorProto_name)(oneof_proto); o->parent = m; @@ -11268,8 +11796,6 @@ static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, o->field_count = 0; o->synthetic = false; - UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); - if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); } @@ -11286,14 +11812,16 @@ static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, } // Allocate and initialize an array of |n| oneof defs. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto) * const* protos, upb_MessageDef* m) { +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m) { _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); for (int i = 0; i < n; i++) { - create_oneofdef(ctx, m, protos[i], &o[i]); + create_oneofdef(ctx, m, protos[i], parent_features, &o[i]); } return o; } @@ -11303,12 +11831,16 @@ upb_OneofDef* _upb_OneofDefs_New( // Must be last. struct upb_ServiceDef { - const UPB_DESC(ServiceOptions) * opts; + const UPB_DESC(ServiceOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; const upb_FileDef* file; const char* full_name; upb_MethodDef* methods; int method_count; int index; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif }; upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { @@ -11359,37 +11891,40 @@ const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, } static void create_service(upb_DefBuilder* ctx, - const UPB_DESC(ServiceDescriptorProto) * svc_proto, + const UPB_DESC(ServiceDescriptorProto*) svc_proto, + const UPB_DESC(FeatureSet*) parent_features, upb_ServiceDef* s) { - upb_StringView name; - size_t n; + UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, + svc_proto); + s->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(ServiceOptions_features)(s->opts)); // Must happen before _upb_DefBuilder_Add() s->file = _upb_DefBuilder_File(ctx); - name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); + upb_StringView name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); const char* package = _upb_FileDef_RawPackage(s->file); s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); _upb_DefBuilder_Add(ctx, s->full_name, _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); + size_t n; const UPB_DESC(MethodDescriptorProto)* const* methods = UPB_DESC(ServiceDescriptorProto_method)(svc_proto, &n); s->method_count = n; - s->methods = _upb_MethodDefs_New(ctx, n, methods, s); - - UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, - svc_proto); + s->methods = _upb_MethodDefs_New(ctx, n, methods, s->resolved_features, s); } -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(ServiceDescriptorProto) * const* protos) { +upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(ServiceDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features) { _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); for (int i = 0; i < n; i++) { - create_service(ctx, protos[i], &s[i]); + create_service(ctx, protos[i], parent_features, &s[i]); s[i].index = i; } return s; @@ -14410,6 +14945,7 @@ const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, #undef UPB_GNUC_MIN #undef UPB_DESCRIPTOR_UPB_H_FILENAME #undef UPB_DESC +#undef UPB_DESC_MINITABLE #undef UPB_IS_GOOGLE3 #undef UPB_ATOMIC #undef UPB_USE_C11_ATOMICS diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 9393812f7e..ba67dfa2ea 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -320,8 +320,13 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #if defined(UPB_IS_GOOGLE3) && !defined(UPB_BOOTSTRAP_STAGE0) #define UPB_DESC(sym) proto2_##sym +#define UPB_DESC_MINITABLE(sym) &proto2__##sym##_msg_init +#elif defined(UPB_BOOTSTRAP_STAGE0) +#define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) google__protobuf__##sym##_msg_init() #else #define UPB_DESC(sym) google_protobuf_##sym +#define UPB_DESC_MINITABLE(sym) &google__protobuf__##sym##_msg_init #endif #ifndef UPB_BASE_STATUS_H_ @@ -10660,6 +10665,9 @@ UPB_API void upb_DefPool_Free(upb_DefPool* s); UPB_API upb_DefPool* upb_DefPool_New(void); +UPB_API const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s); + UPB_API const upb_MessageDef* upb_DefPool_FindMessageByName( const upb_DefPool* s, const char* sym); @@ -10751,6 +10759,7 @@ bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, const char* upb_EnumDef_Name(const upb_EnumDef* e); const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e); +const UPB_DESC(FeatureSet) * upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e); upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i); int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e); @@ -10789,6 +10798,8 @@ UPB_API const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v); UPB_API int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v); const UPB_DESC(EnumValueOptions) * upb_EnumValueDef_Options(const upb_EnumValueDef* v); +const UPB_DESC(FeatureSet) * + upb_EnumValueDef_ResolvedFeatures(const upb_EnumValueDef* e); #ifdef __cplusplus } /* extern "C" */ @@ -10815,6 +10826,8 @@ int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); const UPB_DESC(ExtensionRangeOptions) * upb_ExtensionRange_Options(const upb_ExtensionRange* r); +const UPB_DESC(FeatureSet) * + upb_ExtensionRange_ResolvedFeatures(const upb_ExtensionRange* e); #ifdef __cplusplus } /* extern "C" */ @@ -10876,6 +10889,8 @@ const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f); UPB_API const char* upb_FieldDef_Name(const upb_FieldDef* f); UPB_API uint32_t upb_FieldDef_Number(const upb_FieldDef* f); const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f); +const UPB_DESC(FeatureSet) * + upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f); UPB_API const upb_OneofDef* upb_FieldDef_RealContainingOneof( const upb_FieldDef* f); UPB_API upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); @@ -10904,6 +10919,7 @@ int upb_FileDef_DependencyCount(const upb_FileDef* f); bool upb_FileDef_HasOptions(const upb_FileDef* f); UPB_API const char* upb_FileDef_Name(const upb_FileDef* f); const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f); +const UPB_DESC(FeatureSet) * upb_FileDef_ResolvedFeatures(const upb_FileDef* f); const char* upb_FileDef_Package(const upb_FileDef* f); UPB_DESC(Edition) upb_FileDef_Edition(const upb_FileDef* f); UPB_API const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); @@ -11063,6 +11079,8 @@ int upb_MessageDef_RealOneofCount(const upb_MessageDef* m); const UPB_DESC(MessageOptions) * upb_MessageDef_Options(const upb_MessageDef* m); +const UPB_DESC(FeatureSet) * + upb_MessageDef_ResolvedFeatures(const upb_MessageDef* m); upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i); int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m); @@ -11100,6 +11118,8 @@ int upb_MethodDef_Index(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); const char* upb_MethodDef_Name(const upb_MethodDef* m); const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m); +const UPB_DESC(FeatureSet) * + upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m); const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); @@ -11140,7 +11160,9 @@ const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, uint32_t num); UPB_API const char* upb_OneofDef_Name(const upb_OneofDef* o); int upb_OneofDef_numfields(const upb_OneofDef* o); -const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o); +const UPB_DESC(OneofOptions*) upb_OneofDef_Options(const upb_OneofDef* o); +const UPB_DESC(FeatureSet*) + upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o); #ifdef __cplusplus } /* extern "C" */ @@ -11172,6 +11194,8 @@ int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); const char* upb_ServiceDef_Name(const upb_ServiceDef* s); const UPB_DESC(ServiceOptions) * upb_ServiceDef_Options(const upb_ServiceDef* s); +const UPB_DESC(FeatureSet) * + upb_ServiceDef_ResolvedFeatures(const upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ @@ -11872,6 +11896,42 @@ UPB_INLINE const char* upb_WireReader_SkipValue( #endif // UPB_WIRE_READER_H_ +#ifndef UPB_MESSAGE_COPY_H_ +#define UPB_MESSAGE_COPY_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Deep clones a message using the provided target arena. +upb_Message* upb_Message_DeepClone(const upb_Message* message, + const upb_MiniTable* mini_table, + upb_Arena* arena); + +// Deep clones array contents. +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena); + +// Deep clones map contents. +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena); + +// Deep copies the message from src to dst. +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, upb_Arena* arena); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_MESSAGE_COPY_H_ + // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// #ifndef UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ @@ -12325,6 +12385,10 @@ extern "C" { struct upb_DefBuilder { upb_DefPool* symtab; + upb_strtable feature_cache; // Caches features by identity. + UPB_DESC(FeatureSet*) legacy_features; // For computing legacy features. + char* tmp_buf; // Temporary buffer in tmp_arena. + size_t tmp_buf_size; // Size of temporary buffer. upb_FileDef* file; // File we are building. upb_Arena* arena; // Allocate defs here. upb_Arena* tmp_arena; // For temporary allocations. @@ -12417,6 +12481,25 @@ UPB_INLINE void _upb_DefBuilder_CheckIdentFull(upb_DefBuilder* ctx, if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, true); } +// Returns true if the returned feature set is new and must be populated. +bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key, + UPB_DESC(FeatureSet**) set); + +const UPB_DESC(FeatureSet*) + _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child, + bool is_implicit); + +UPB_INLINE const UPB_DESC(FeatureSet*) + _upb_DefBuilder_ResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child) { + return _upb_DefBuilder_DoResolveFeatures(ctx, parent, child, false); +} + #ifdef __cplusplus } /* extern "C" */ #endif @@ -12439,10 +12522,11 @@ bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); // Allocate and initialize an array of |n| enum defs. -upb_EnumDef* _upb_EnumDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto) * const* protos, - const upb_MessageDef* containing_type); +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type); #ifdef __cplusplus } /* extern "C" */ @@ -12466,7 +12550,8 @@ upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); // Allocate and initialize an array of |n| enum value defs owned by |e|. upb_EnumValueDef* _upb_EnumValueDefs_New( upb_DefBuilder* ctx, const char* prefix, int n, - const UPB_DESC(EnumValueDescriptorProto) * const* protos, upb_EnumDef* e, + const UPB_DESC(EnumValueDescriptorProto*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, bool* is_sorted); const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, @@ -12503,16 +12588,19 @@ void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, const upb_FieldDef* f); // Allocate and initialize an array of |n| extensions (field defs). -upb_FieldDef* _upb_Extensions_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m); +upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m); // Allocate and initialize an array of |n| field defs. -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto) * const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted); +upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m, + bool* is_sorted); // Allocate and return a list of pointers to the |n| field defs in |ff|, // sorted by field number. @@ -12577,9 +12665,12 @@ void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); // Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const UPB_DESC(DescriptorProto) * const* protos, - const upb_MessageDef* containing_type); +upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features, + const upb_MessageDef* containing_type); #ifdef __cplusplus } /* extern "C" */ @@ -12601,9 +12692,11 @@ extern "C" { upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); // Allocate and initialize an array of |n| service defs. -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(ServiceDescriptorProto) * const* protos); +upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(ServiceDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features); #ifdef __cplusplus } /* extern "C" */ @@ -12612,6 +12705,20 @@ upb_ServiceDef* _upb_ServiceDefs_New( #endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */ +#ifndef UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ +#define UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ + +// This file contains the serialized FeatureSetDefaults object for +// language-independent features and (possibly at some point) for upb-specific +// features. This is used for feature resolution under Editions. +// NOLINTBEGIN +// clang-format off +#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "\n\021\022\014\010\001\020\002\030\002 \001(\0010\002\030\346\007\n\021\022\014\010\002\020\001\030\001 \002(\0010\001\030\347\007\n\021\022\014\010\001\020\001\030\001 \002(\0010\001\030\350\007 \346\007(\350\007" +// clang-format on +// NOLINTEND + +#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ + #ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ #define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ @@ -12684,7 +12791,7 @@ upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, // Allocate and initialize an array of |n| reserved ranges owned by |e|. upb_EnumReservedRange* _upb_EnumReservedRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, + const UPB_DESC(EnumDescriptorProto_EnumReservedRange*) const* protos, const upb_EnumDef* e); #ifdef __cplusplus @@ -12732,8 +12839,8 @@ upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); // Allocate and initialize an array of |n| extension ranges owned by |m|. upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ExtensionRange) * const* protos, - const upb_MessageDef* m); + const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m); #ifdef __cplusplus } /* extern "C" */ @@ -12757,9 +12864,11 @@ void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, const upb_FieldDef* f, const char* name, size_t size); // Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto) * const* protos, upb_MessageDef* m); +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m); size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); @@ -12831,9 +12940,11 @@ extern "C" { upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); // Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto) * const* protos, upb_ServiceDef* s); +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ @@ -13038,6 +13149,7 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #undef UPB_GNUC_MIN #undef UPB_DESCRIPTOR_UPB_H_FILENAME #undef UPB_DESC +#undef UPB_DESC_MINITABLE #undef UPB_IS_GOOGLE3 #undef UPB_ATOMIC #undef UPB_USE_C11_ATOMICS From 722ddce3340349b60e857a5afaab207ab6ec579d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 3 Nov 2023 17:07:05 -0700 Subject: [PATCH 087/387] pass explicit lazy annotation for messages PiperOrigin-RevId: 579343301 --- src/google/protobuf/compiler/cpp/extension.cc | 49 ++++++++++------ .../compiler/java/java_features.pb.cc | 7 +-- src/google/protobuf/cpp_features.pb.cc | 7 +-- src/google/protobuf/extension_set.cc | 5 +- src/google/protobuf/extension_set.h | 56 ++++++++++++------- src/google/protobuf/extension_set_heavy.cc | 5 ++ src/google/protobuf/extension_set_unittest.cc | 5 ++ 7 files changed, 85 insertions(+), 49 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/extension.cc b/src/google/protobuf/compiler/cpp/extension.cc index 924ef4e5cb..a13aae2d4f 100644 --- a/src/google/protobuf/compiler/cpp/extension.cc +++ b/src/google/protobuf/compiler/cpp/extension.cc @@ -165,10 +165,9 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* p) { if (IsLazilyInitializedFile(descriptor_->file()->name())) { p->Emit(R"cc( PROTOBUF_CONSTINIT$ dllexport_decl$ - PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::$proto_ns$::internal:: - ExtensionIdentifier< - $extendee$, ::$proto_ns$::internal::$type_traits$, - $field_type$, $packed$> + PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::_pbi:: + ExtensionIdentifier<$extendee$, ::_pbi::$type_traits$, + $field_type$, $packed$> $scoped_name$($constant_name$); )cc"); return; @@ -183,23 +182,37 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* p) { ShouldVerify(descriptor_->containing_type(), options_, scc_analyzer_); - if (should_verify) { + if (!should_verify) { p->Emit(R"cc( - $dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 :: - $proto_ns$::internal::ExtensionIdentifier< - $extendee$, ::$proto_ns$::internal::$type_traits$, - $field_type$, $packed$> - $scoped_name$($constant_name$, $default_str$, - &$message_type$::InternalVerify); - )cc"); - } else { - p->Emit(R"cc( - $dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 :: - $proto_ns$::internal::ExtensionIdentifier< - $extendee$, ::$proto_ns$::internal::$type_traits$, - $field_type$, $packed$> + $dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::_pbi:: + ExtensionIdentifier<$extendee$, ::_pbi::$type_traits$, + $field_type$, $packed$> $scoped_name$($constant_name$, $default_str$); )cc"); + return; + } + + const auto& options = descriptor_->options(); + if (options.has_lazy()) { + p->Emit( + {{"is_lazy", options.lazy() ? "kLazy" : "kEager"}}, + R"cc( + $dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::_pbi:: + ExtensionIdentifier<$extendee$, ::_pbi::$type_traits$, + $field_type$, $packed$> + $scoped_name$($constant_name$, $default_str$, + &$message_type$::InternalVerify, + ::_pbi::LazyAnnotation::$is_lazy$); + )cc"); + } else { + p->Emit( + R"cc( + $dllexport_decl $PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::_pbi:: + ExtensionIdentifier<$extendee$, ::_pbi::$type_traits$, + $field_type$, $packed$> + $scoped_name$($constant_name$, $default_str$, + &$message_type$::InternalVerify); + )cc"); } }}, }, diff --git a/src/google/protobuf/compiler/java/java_features.pb.cc b/src/google/protobuf/compiler/java/java_features.pb.cc index c90164e5f0..1b02dbef59 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.cc +++ b/src/google/protobuf/compiler/java/java_features.pb.cc @@ -375,10 +375,9 @@ void JavaFeatures::InternalSwap(JavaFeatures* PROTOBUF_RESTRICT other) { &descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_getter, &descriptor_table_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto_once, file_level_metadata_google_2fprotobuf_2fcompiler_2fjava_2fjava_5ffeatures_2eproto[0]); } -PROTOC_EXPORT PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 :: - google::protobuf::internal::ExtensionIdentifier< - ::google::protobuf::FeatureSet, ::google::protobuf::internal::MessageTypeTraits< ::pb::JavaFeatures >, - 11, false> +PROTOC_EXPORT PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::_pbi:: + ExtensionIdentifier<::google::protobuf::FeatureSet, ::_pbi::MessageTypeTraits< ::pb::JavaFeatures >, + 11, false> java(kJavaFieldNumber, ::pb::JavaFeatures::default_instance()); // @@protoc_insertion_point(namespace_scope) } // namespace pb diff --git a/src/google/protobuf/cpp_features.pb.cc b/src/google/protobuf/cpp_features.pb.cc index 6e5538d889..55c1864695 100644 --- a/src/google/protobuf/cpp_features.pb.cc +++ b/src/google/protobuf/cpp_features.pb.cc @@ -299,10 +299,9 @@ void CppFeatures::InternalSwap(CppFeatures* PROTOBUF_RESTRICT other) { file_level_metadata_google_2fprotobuf_2fcpp_5ffeatures_2eproto[0]); } PROTOBUF_CONSTINIT PROTOBUF_EXPORT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::google::protobuf::internal:: - ExtensionIdentifier< - ::google::protobuf::FeatureSet, ::google::protobuf::internal::MessageTypeTraits< ::pb::CppFeatures >, - 11, false> + PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 ::_pbi:: + ExtensionIdentifier<::google::protobuf::FeatureSet, ::_pbi::MessageTypeTraits< ::pb::CppFeatures >, + 11, false> cpp(kCppFieldNumber); // @@protoc_insertion_point(namespace_scope) } // namespace pb diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index 538178fc4a..32528d4cb2 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc @@ -148,11 +148,12 @@ void ExtensionSet::RegisterMessageExtension(const MessageLite* extendee, int number, FieldType type, bool is_repeated, bool is_packed, const MessageLite* prototype, - LazyEagerVerifyFnType verify_func) { + LazyEagerVerifyFnType verify_func, + LazyAnnotation is_lazy) { ABSL_CHECK(type == WireFormatLite::TYPE_MESSAGE || type == WireFormatLite::TYPE_GROUP); ExtensionInfo info(extendee, number, type, is_repeated, is_packed, - verify_func); + verify_func, is_lazy); info.message_info = {prototype}; Register(info); } diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index f9fb2bd94f..74a316eee3 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -32,6 +32,7 @@ #include "google/protobuf/internal_visibility.h" #include "google/protobuf/port.h" #include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/message_lite.h" #include "google/protobuf/parse_context.h" #include "google/protobuf/repeated_field.h" #include "google/protobuf/repeated_ptr_field.h" @@ -90,6 +91,12 @@ typedef bool EnumValidityFunc(int number); // extensions that are not compiled in. typedef bool EnumValidityFuncWithArg(const void* arg, int number); +enum class LazyAnnotation : int8_t { + kUndefined = 0, + kLazy = 1, + kEager = 2, +}; + // Information about a registered extension. struct ExtensionInfo { constexpr ExtensionInfo() : enum_validity_check() {} @@ -103,12 +110,14 @@ struct ExtensionInfo { enum_validity_check() {} constexpr ExtensionInfo(const MessageLite* extendee, int param_number, FieldType type_param, bool isrepeated, bool ispacked, - LazyEagerVerifyFnType verify_func) + LazyEagerVerifyFnType verify_func, + LazyAnnotation islazy = LazyAnnotation::kUndefined) : message(extendee), number(param_number), type(type_param), is_repeated(isrepeated), is_packed(ispacked), + is_lazy(islazy), enum_validity_check(), lazy_eager_verify_func(verify_func) {} @@ -118,6 +127,7 @@ struct ExtensionInfo { FieldType type = 0; bool is_repeated = false; bool is_packed = false; + LazyAnnotation is_lazy = LazyAnnotation::kUndefined; struct EnumValidityCheck { EnumValidityFuncWithArg* func; @@ -144,6 +154,7 @@ struct ExtensionInfo { LazyEagerVerifyFnType lazy_eager_verify_func = nullptr; }; + // An ExtensionFinder is an object which looks up extension definitions. It // must implement this method: // @@ -209,7 +220,8 @@ class PROTOBUF_EXPORT ExtensionSet { FieldType type, bool is_repeated, bool is_packed, const MessageLite* prototype, - LazyEagerVerifyFnType verify_func); + LazyEagerVerifyFnType verify_func, + LazyAnnotation is_lazy); // ================================================================= @@ -1405,17 +1417,17 @@ class MessageTypeTraits { // Some messages won't (can't) be verified; e.g. lite. template static void Register(int number, FieldType type, bool is_packed) { - ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(), - number, type, false, is_packed, - &Type::default_instance(), nullptr); + ExtensionSet::RegisterMessageExtension( + &ExtendeeT::default_instance(), number, type, false, is_packed, + &Type::default_instance(), nullptr, LazyAnnotation::kUndefined); } template static void Register(int number, FieldType type, bool is_packed, - LazyEagerVerifyFnType fn) { - ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(), - number, type, false, is_packed, - &Type::default_instance(), fn); + LazyEagerVerifyFnType fn, LazyAnnotation is_lazy) { + ExtensionSet::RegisterMessageExtension( + &ExtendeeT::default_instance(), number, type, false, is_packed, + &Type::default_instance(), fn, is_lazy); } }; @@ -1481,17 +1493,17 @@ class RepeatedMessageTypeTraits { // Some messages won't (can't) be verified; e.g. lite. template static void Register(int number, FieldType type, bool is_packed) { - ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(), - number, type, true, is_packed, - &Type::default_instance(), nullptr); + ExtensionSet::RegisterMessageExtension( + &ExtendeeT::default_instance(), number, type, true, is_packed, + &Type::default_instance(), nullptr, LazyAnnotation::kUndefined); } template static void Register(int number, FieldType type, bool is_packed, - LazyEagerVerifyFnType fn) { - ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(), - number, type, true, is_packed, - &Type::default_instance(), fn); + LazyEagerVerifyFnType fn, LazyAnnotation is_lazy) { + ExtensionSet::RegisterMessageExtension( + &ExtendeeT::default_instance(), number, type, true, is_packed, + &Type::default_instance(), fn, is_lazy); } }; @@ -1533,9 +1545,10 @@ class ExtensionIdentifier { Register(number); } ExtensionIdentifier(int number, typename TypeTraits::ConstType default_value, - LazyEagerVerifyFnType verify_func) + LazyEagerVerifyFnType verify_func, + LazyAnnotation is_lazy = LazyAnnotation::kUndefined) : number_(number), default_value_(default_value) { - Register(number, verify_func); + Register(number, verify_func, is_lazy); } inline int number() const { return number_; } typename TypeTraits::ConstType default_value() const { @@ -1546,9 +1559,10 @@ class ExtensionIdentifier { TypeTraits::template Register(number, field_type, is_packed); } - static void Register(int number, LazyEagerVerifyFnType verify_func) { + static void Register(int number, LazyEagerVerifyFnType verify_func, + LazyAnnotation is_lazy) { TypeTraits::template Register(number, field_type, is_packed, - verify_func); + verify_func, is_lazy); } typename TypeTraits::ConstType const& default_value_ref() const { @@ -1586,7 +1600,7 @@ class ExtensionIdentifier, 11, absl::call_once(once_, [&] { default_value_ = &default_instance; MessageTypeTraits::template Register( - number_, 11, false, verify_func); + number_, 11, false, verify_func, LazyAnnotation::kUndefined); }); } diff --git a/src/google/protobuf/extension_set_heavy.cc b/src/google/protobuf/extension_set_heavy.cc index 20530c14dc..79d7977ab0 100644 --- a/src/google/protobuf/extension_set_heavy.cc +++ b/src/google/protobuf/extension_set_heavy.cc @@ -271,6 +271,11 @@ bool DescriptorPoolExtensionFinder::Find(int number, ExtensionInfo* output) { ABSL_CHECK(output->message_info.prototype != nullptr) << "Extension factory's GetPrototype() returned nullptr; extension: " << extension->full_name(); + + if (extension->options().has_lazy()) { + output->is_lazy = extension->options().lazy() ? LazyAnnotation::kLazy + : LazyAnnotation::kEager; + } } else if (extension->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { output->enum_validity_check.func = ValidateEnumUsingDescriptor; output->enum_validity_check.arg = extension->enum_type(); diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index c65ebd96d1..df926e7a20 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -11,6 +11,8 @@ #include "google/protobuf/extension_set.h" +#include + #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/testing/googletest.h" #include @@ -27,6 +29,7 @@ #include "google/protobuf/test_util2.h" #include "google/protobuf/text_format.h" #include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_mset.pb.h" #include "google/protobuf/wire_format.h" #include "google/protobuf/wire_format_lite.h" @@ -37,6 +40,8 @@ namespace google { namespace protobuf { + + namespace internal { namespace { From c508a40f40c0b4f1e562ef917cd5606d66d9601c Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Fri, 3 Nov 2023 17:15:12 -0700 Subject: [PATCH 088/387] Raise warnings for python syntax usages PiperOrigin-RevId: 579344748 --- python/descriptor.c | 10 ++++++++ python/google/protobuf/descriptor.py | 28 ++++++++++++++++++---- python/google/protobuf/pyext/descriptor.cc | 10 ++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/python/descriptor.c b/python/descriptor.c index be1a839ac2..023e943605 100644 --- a/python/descriptor.c +++ b/python/descriptor.c @@ -620,6 +620,11 @@ static PyObject* PyUpb_Descriptor_GetOneofsByName(PyObject* _self, } static PyObject* PyUpb_Descriptor_GetSyntax(PyObject* self, void* closure) { + PyErr_WarnEx(NULL, + "descriptor.syntax is deprecated. It will be removed soon. " + "Most usages are checking field descriptors. Consider to use " + "has_presence, is_packed on field descriptors.", + 1); const upb_MessageDef* msgdef = PyUpb_Descriptor_GetDef(self); const char* syntax = upb_MessageDef_Syntax(msgdef) == kUpb_Syntax_Proto2 ? "proto2" : "proto3"; @@ -1309,6 +1314,11 @@ static PyObject* PyUpb_FileDescriptor_GetPublicDependencies(PyObject* _self, static PyObject* PyUpb_FileDescriptor_GetSyntax(PyObject* _self, void* closure) { + PyErr_WarnEx(NULL, + "descriptor.syntax is deprecated. It will be removed soon. " + "Most usages are checking field descriptors. Consider to use " + "has_presence, is_packed on field descriptors.", + 1); PyUpb_DescriptorBase* self = (void*)_self; const char* syntax = upb_FileDef_Syntax(self->def) == kUpb_Syntax_Proto2 ? "proto2" : "proto3"; diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index f8b12ff132..5b32e5e154 100755 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py @@ -353,9 +353,18 @@ class Descriptor(_NestedDescriptorBase): self.oneofs_by_name = dict((o.name, o) for o in self.oneofs) for oneof in self.oneofs: oneof.containing_type = self - self.syntax = syntax or "proto2" + self._deprecated_syntax = syntax or "proto2" self._is_map_entry = is_map_entry + @property + def syntax(self): + warnings.warn( + 'descriptor.syntax is deprecated. It will be removed' + ' soon. Most usages are checking field descriptors. Consider to use' + ' has_presence, is_packed on field descriptors.' + ) + return self._deprecated_syntax + @property def fields_by_camelcase_name(self): """Same FieldDescriptor objects as in :attr:`fields`, but indexed by @@ -621,7 +630,7 @@ class FieldDescriptor(DescriptorBase): # compatibility. FieldDescriptor.file was added in cl/153110619 # Some old/generated code didn't link file to FieldDescriptor. # TODO: remove syntax usage b/240619313 - return self.containing_type.syntax == 'proto2' + return self.containing_type._deprecated_syntax == 'proto2' @property def is_packed(self): @@ -634,7 +643,7 @@ class FieldDescriptor(DescriptorBase): field_type == FieldDescriptor.TYPE_MESSAGE or field_type == FieldDescriptor.TYPE_BYTES): return False - if self.containing_type.syntax == 'proto2': + if self.containing_type._deprecated_syntax == 'proto2': return self.has_options and self.GetOptions().packed else: return (not self.has_options or @@ -743,7 +752,7 @@ class EnumDescriptor(_NestedDescriptorBase): Care should be taken when using this function to respect the target runtime's enum handling quirks. """ - return self.file.syntax == 'proto2' + return self.file._deprecated_syntax == 'proto2' def CopyToProto(self, proto): """Copies this to a descriptor_pb2.EnumDescriptorProto. @@ -1083,7 +1092,7 @@ class FileDescriptor(DescriptorBase): self.message_types_by_name = {} self.name = name self.package = package - self.syntax = syntax or "proto2" + self._deprecated_syntax = syntax or "proto2" self.serialized_pb = serialized_pb self.enum_types_by_name = {} @@ -1092,6 +1101,15 @@ class FileDescriptor(DescriptorBase): self.dependencies = (dependencies or []) self.public_dependencies = (public_dependencies or []) + @property + def syntax(self): + warnings.warn( + 'descriptor.syntax is deprecated. It will be removed' + ' soon. Most usages are checking field descriptors. Consider to use' + ' has_presence, is_packed on field descriptors.' + ) + return self._deprecated_syntax + def CopyToProto(self, proto): """Copies this to a descriptor_pb2.FileDescriptorProto. diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 44d9e45177..734aea66aa 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -672,6 +672,11 @@ static PyObject* EnumValueName(PyBaseDescriptor *self, PyObject *args) { } static PyObject* GetSyntax(PyBaseDescriptor *self, void *closure) { + PyErr_WarnEx(nullptr, + "descriptor.syntax is deprecated. It will be removed soon. " + "Most usages are checking field descriptors. Consider to use " + "has_presence, is_packed on field descriptors.", + 1); std::string syntax(FileDescriptorLegacy::SyntaxName( FileDescriptorLegacy(_GetDescriptor(self)->file()).syntax())); return PyUnicode_InternFromString(syntax.c_str()); @@ -1493,6 +1498,11 @@ static int SetSerializedOptions(PyFileDescriptor *self, PyObject *value, } static PyObject* GetSyntax(PyFileDescriptor *self, void *closure) { + PyErr_WarnEx(nullptr, + "descriptor.syntax is deprecated. It will be removed soon. " + "Most usages are checking field descriptors. Consider to use " + "has_presence, is_packed on field descriptors.", + 1); std::string syntax(FileDescriptorLegacy::SyntaxName( FileDescriptorLegacy(_GetDescriptor(self)).syntax())); return PyUnicode_InternFromString(syntax.c_str()); From 0a2fe573a292325600d1d99619a1a711a349d314 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Sat, 4 Nov 2023 06:26:13 -0700 Subject: [PATCH 089/387] upb: remove unused code from message/promote_test PiperOrigin-RevId: 579453773 --- upb/message/promote_test.cc | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/upb/message/promote_test.cc b/upb/message/promote_test.cc index 1bfbb15fcd..0d279d44f3 100644 --- a/upb/message/promote_test.cc +++ b/upb/message/promote_test.cc @@ -654,12 +654,6 @@ upb_MiniTable* CreateMiniTableWithEmptySubTablesOld(upb_Arena* arena) { upb_MiniTable* table = upb_MiniTable_Build(e.data().data(), e.data().size(), arena, &status); EXPECT_EQ(status.ok, true); - // Initialize sub table to null. Not using upb_MiniTable_SetSubMessage - // since it checks ->ext on parameter. - upb_MiniTableSub* sub = const_cast( - &table->subs[table->fields[1].UPB_PRIVATE(submsg_index)]); - sub = const_cast( - &table->subs[table->fields[2].UPB_PRIVATE(submsg_index)]); return table; } @@ -677,12 +671,6 @@ upb_MiniTable* CreateMiniTableWithEmptySubTablesForMapsOld(upb_Arena* arena) { upb_MiniTable* table = upb_MiniTable_Build(e.data().data(), e.data().size(), arena, &status); EXPECT_EQ(status.ok, true); - // Initialize sub table to null. Not using upb_MiniTable_SetSubMessage - // since it checks ->ext on parameter. - upb_MiniTableSub* sub = const_cast( - &table->subs[table->fields[1].UPB_PRIVATE(submsg_index)]); - sub = const_cast( - &table->subs[table->fields[2].UPB_PRIVATE(submsg_index)]); return table; } From d580fde63aa8ea5c6f4619396e68aaf017fc9d61 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Mon, 6 Nov 2023 00:22:39 -0800 Subject: [PATCH 090/387] Add Automatic-Module-Name (#14562) Adds Automatic-Module-Name after it was lost during the maven-bazel migration (and subsequent re-addition of osgi bundle support). Updates OsgiWrapper to support adding the Automatic-Module-Name header to the list of properties supported by the `osgi_java_library` rule. Fixes #12639 Closes #14562 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14562 from Sineaggi:add-automatic-module-name a27b3e6695acb4f1f253422fd2d324bb1b3f6669 PiperOrigin-RevId: 579748655 --- build_defs/java_opts.bzl | 5 +++++ java/core/BUILD.bazel | 2 ++ java/osgi/OsgiWrapper.java | 6 ++++++ java/osgi/osgi.bzl | 4 ++++ java/util/BUILD.bazel | 1 + 5 files changed, 18 insertions(+) diff --git a/build_defs/java_opts.bzl b/build_defs/java_opts.bzl index e9c04074ee..2da4e5f6d4 100644 --- a/build_defs/java_opts.bzl +++ b/build_defs/java_opts.bzl @@ -27,6 +27,7 @@ def protobuf_java_library(**kwargs): ) def protobuf_versioned_java_library( + automatic_module_name, bundle_description, bundle_name, bundle_symbolic_name, @@ -44,6 +45,9 @@ def protobuf_versioned_java_library( Args: bundle_description: (required) The Bundle-Description header defines a short description of this bundle. + automatic_module_name: (required) The Automatic-Module-Name header that represents + the name of the module when this bundle is used as an automatic + module. bundle_name: (required) The Bundle-Name header defines a readable name for this bundle. This should be a short, human-readable name that can contain spaces. @@ -65,6 +69,7 @@ def protobuf_versioned_java_library( """ osgi_java_library( javacopts = JAVA_OPTS, + automatic_module_name = automatic_module_name, bundle_doc_url = BUNDLE_DOC_URL, bundle_license = BUNDLE_LICENSE, bundle_version = PROTOBUF_JAVA_VERSION, diff --git a/java/core/BUILD.bazel b/java/core/BUILD.bazel index 70fe8faa25..b896c426b9 100644 --- a/java/core/BUILD.bazel +++ b/java/core/BUILD.bazel @@ -136,6 +136,7 @@ protobuf_versioned_java_library( srcs = LITE_SRCS + [ ":gen_well_known_protos_javalite", ], + automatic_module_name = "com.google.protobuf", bundle_description = "Lite version of Protocol Buffers library. This " + "version is optimized for code size, but does not " + "guarantee API/ABI stability.", @@ -217,6 +218,7 @@ protobuf_versioned_java_library( ) + [ ":gen_well_known_protos_java", ], + automatic_module_name = "com.google.protobuf", bundle_description = "Core Protocol Buffers library. Protocol Buffers " + "are a way of encoding structured data in an " + "efficient yet extensible format.", diff --git a/java/osgi/OsgiWrapper.java b/java/osgi/OsgiWrapper.java index e917ae60f3..c0690eb944 100644 --- a/java/osgi/OsgiWrapper.java +++ b/java/osgi/OsgiWrapper.java @@ -55,6 +55,11 @@ public final class OsgiWrapper implements Callable { description = "The classpath that contains dependencies of the input jar, separated with :") private String classpath; + @Option( + names = {"--automatic_module_name"}, + description = "The automatic module name of the bundle") + private String automaticModuleName; + @Option( names = {"--bundle_copyright"}, description = "Copyright string for the bundle") @@ -106,6 +111,7 @@ public final class OsgiWrapper implements Callable { Analyzer analyzer = new Analyzer(); analyzer.setJar(bin); + analyzer.setProperty(Analyzer.AUTOMATIC_MODULE_NAME, automaticModuleName); analyzer.setProperty(Analyzer.BUNDLE_NAME, bundleName); analyzer.setProperty(Analyzer.BUNDLE_SYMBOLICNAME, bundleSymbolicName); analyzer.setProperty(Analyzer.BUNDLE_VERSION, bundleVersion); diff --git a/java/osgi/osgi.bzl b/java/osgi/osgi.bzl index 40ee0842a5..68600b5d7b 100644 --- a/java/osgi/osgi.bzl +++ b/java/osgi/osgi.bzl @@ -23,6 +23,7 @@ load("@rules_java//java:defs.bzl", "java_library") # which is probably sub-optimal. def osgi_java_library( name, + automatic_module_name, bundle_description, bundle_doc_url, bundle_license, @@ -119,6 +120,7 @@ def osgi_java_library( # Repackage the jar with an OSGI manifest _osgi_jar( name = name, + automatic_module_name = automatic_module_name, bundle_description = bundle_description, bundle_doc_url = bundle_doc_url, bundle_license = bundle_license, @@ -141,6 +143,7 @@ def _run_osgi_wrapper(ctx, input_jar, classpath_jars, output_jar): args.add_joined("--classpath", classpath_jars, join_with = ":") args.add("--input_jar", input_jar.path) args.add("--output_jar", output_jar.path) + args.add("--automatic_module_name", ctx.attr.automatic_module_name) args.add("--bundle_copyright", ctx.attr.bundle_copyright) args.add("--bundle_description", ctx.attr.bundle_description) args.add("--bundle_doc_url", ctx.attr.bundle_doc_url) @@ -215,6 +218,7 @@ _osgi_jar = rule( "output_jar": "lib%{name}.jar", }, attrs = { + "automatic_module_name": attr.string(), "bundle_copyright": attr.string(), "bundle_description": attr.string(), "bundle_doc_url": attr.string(), diff --git a/java/util/BUILD.bazel b/java/util/BUILD.bazel index c6ab799a5d..c8b9e76697 100644 --- a/java/util/BUILD.bazel +++ b/java/util/BUILD.bazel @@ -26,6 +26,7 @@ protobuf_versioned_java_library( srcs = glob([ "src/main/java/com/google/protobuf/util/*.java", ]), + automatic_module_name = "com.google.protobuf.util", bundle_description = "Utilities for Protocol Buffers", bundle_name = "Protocol Buffers [Util]", bundle_symbolic_name = "com.google.protobuf.util", From e32d0948e7b2799037be0e4364816249119acc3f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 6 Nov 2023 06:43:06 -0800 Subject: [PATCH 091/387] Properly untrack Python GC objects during deallocation. Add PyObject_GC_UnTrack() in deallocation functions for Python types that have PyTPFLAGS_HAVE_GC set, either explicitly or by inheriting from a type with GC set. Not untracking before clearing instance data introduces potential race conditions (if GC happens to run between the partial clearing and the actual deallocation) and produces a warning under Python 3.11. (The warning then triggered an assertion failure, which only showed up when building in Py_DEBUG mode; this therefor also fixes that assertion failure.) PiperOrigin-RevId: 579827001 --- python/descriptor.c | 29 ++++++++++++++++++++++++----- python/descriptor_pool.c | 1 + python/message.c | 12 +++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/python/descriptor.c b/python/descriptor.c index 023e943605..42e4bfea1e 100644 --- a/python/descriptor.c +++ b/python/descriptor.c @@ -197,10 +197,25 @@ static PyObject* PyUpb_DescriptorBase_CopyToProto(PyObject* _self, } static void PyUpb_DescriptorBase_Dealloc(PyUpb_DescriptorBase* base) { + // This deallocator can be called on different types (which, despite + // 'Base' in the name of one of them, do not inherit from each other). + // Some of these types are GC types (they have Py_TPFLAGS_HAVE_GC set), + // which means Python's GC can visit them (via tp_visit and/or tp_clear + // methods) at any time. This also means we *must* stop GC from tracking + // instances of them before we start destructing the object. In Python + // 3.11, failing to do so would raise a runtime warning. + if (PyType_HasFeature(Py_TYPE(base), Py_TPFLAGS_HAVE_GC)) { + PyObject_GC_UnTrack(base); + } PyUpb_ObjCache_Delete(base->def); - Py_XDECREF(base->message_meta); - Py_DECREF(base->pool); - Py_XDECREF(base->options); + // In addition to being visited by GC, instances can also (potentially) be + // accessed whenever arbitrary code is executed. Destructors can execute + // arbitrary code, so any struct members we DECREF should be set to NULL + // or a new value *before* calling Py_DECREF on them. The Py_CLEAR macro + // (and Py_SETREF in Python 3.8+) takes care to do this safely. + Py_CLEAR(base->message_meta); + Py_CLEAR(base->pool); + Py_CLEAR(base->options); PyUpb_Dealloc(base); } @@ -256,9 +271,13 @@ err: void PyUpb_Descriptor_SetClass(PyObject* py_descriptor, PyObject* meta) { PyUpb_DescriptorBase* base = (PyUpb_DescriptorBase*)py_descriptor; - Py_XDECREF(base->message_meta); - base->message_meta = meta; Py_INCREF(meta); + // Py_SETREF replaces strong references without an intermediate invalid + // object state, which code executed by base->message_meta's destructor + // might see, but it's Python 3.8+. + PyObject* tmp = base->message_meta; + base->message_meta = meta; + Py_XDECREF(tmp); } // The LookupNested*() functions provide name lookup for entities nested inside diff --git a/python/descriptor_pool.c b/python/descriptor_pool.c index ee4167754c..00612f8bdc 100644 --- a/python/descriptor_pool.c +++ b/python/descriptor_pool.c @@ -99,6 +99,7 @@ PyObject* PyUpb_DescriptorPool_Get(const upb_DefPool* symtab) { } static void PyUpb_DescriptorPool_Dealloc(PyUpb_DescriptorPool* self) { + PyObject_GC_UnTrack(self); PyUpb_DescriptorPool_Clear(self); upb_DefPool_Free(self->symtab); PyUpb_ObjCache_Delete(self->symtab); diff --git a/python/message.c b/python/message.c index 0777e7ed5f..3ed6514fe6 100644 --- a/python/message.c +++ b/python/message.c @@ -1850,7 +1850,15 @@ static PyObject* PyUpb_MessageMeta_New(PyTypeObject* type, PyObject* args, static void PyUpb_MessageMeta_Dealloc(PyObject* self) { PyUpb_MessageMeta* meta = PyUpb_GetMessageMeta(self); PyUpb_ObjCache_Delete(meta->layout); - Py_DECREF(meta->py_message_descriptor); + // The MessageMeta type is a GC type, which means we should untrack the + // object before invalidating internal state (so that code executed by the + // GC doesn't see the invalid state). Unfortunately since we're calling + // cpython_bits.type_dealloc, which also untracks the object, we can't. + // Instead just make sure the internal state remains reasonable by using + // Py_CLEAR(), which sets the struct member to NULL. The tp_traverse and + // tp_clear methods, which are called by Python's GC, already allow for it + // to be NULL. + Py_CLEAR(meta->py_message_descriptor); PyTypeObject* tp = Py_TYPE(self); cpython_bits.type_dealloc(self); Py_DECREF(tp); @@ -1948,6 +1956,8 @@ static int PyUpb_MessageMeta_Traverse(PyObject* self, visitproc visit, } static int PyUpb_MessageMeta_Clear(PyObject* self, visitproc visit, void* arg) { + PyUpb_MessageMeta* meta = PyUpb_GetMessageMeta(self); + Py_CLEAR(meta->py_message_descriptor); return cpython_bits.type_clear(self); } From 08ec050c44c3ffe3074f0e14a4a47095d14dd855 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 6 Nov 2023 06:59:39 -0800 Subject: [PATCH 092/387] Delete obsolete function. `WeakRepeatedPtrField::AddWeak` is not used anywhere, hence deleting it and related code in `RepeatedPtrField`. PiperOrigin-RevId: 579830701 --- src/google/protobuf/implicit_weak_message.h | 3 --- src/google/protobuf/repeated_ptr_field.cc | 29 --------------------- src/google/protobuf/repeated_ptr_field.h | 9 ------- 3 files changed, 41 deletions(-) diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index 0428d9eb32..61bfbbb58e 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -187,9 +187,6 @@ struct WeakRepeatedPtrField { return const_pointer_iterator(base().raw_data() + base().size()); } - MessageLite* AddWeak(const MessageLite* prototype) { - return base().AddWeak(prototype); - } T* Add() { return weak.Add(); } void Clear() { base().template Clear(); } void MergeFrom(const WeakRepeatedPtrField& other) { diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 82205b1715..4ac05d642f 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -108,24 +108,6 @@ void RepeatedPtrFieldBase::DestroyProtos() { tagged_rep_or_elem_ = nullptr; } -void* RepeatedPtrFieldBase::AddOutOfLineHelper(void* obj) { - if (tagged_rep_or_elem_ == nullptr) { - ABSL_DCHECK_EQ(current_size_, 0); - ABSL_DCHECK(using_sso()); - ABSL_DCHECK_EQ(allocated_size(), 0); - ExchangeCurrentSize(1); - return tagged_rep_or_elem_ = obj; - } - // Not using `AllocatedSizeAtCapacity` because it's already known that - // `tagged_rep_or_elem_ != nullptr`. - if (using_sso() || rep()->allocated_size >= Capacity()) { - InternalExtend(1); // Equivalent to "Reserve(total_size_ + 1)" - } - Rep* r = rep(); - ++r->allocated_size; - return r->elements[ExchangeCurrentSize(current_size_ + 1)] = obj; -} - template auto* RepeatedPtrFieldBase::AddInternal(F factory) { using Result = decltype(factory(GetArena())); @@ -180,17 +162,6 @@ MessageLite* RepeatedPtrFieldBase::AddMessage(const MessageLite* prototype) { return AddInternal([prototype](Arena* a) { return prototype->New(a); }); } -MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) { - if (current_size_ < allocated_size()) { - return reinterpret_cast( - element_at(ExchangeCurrentSize(current_size_ + 1))); - } - MessageLite* result = prototype - ? prototype->New(arena_) - : Arena::CreateMessage(arena_); - return static_cast(AddOutOfLineHelper(result)); -} - void InternalOutOfLineDeleteMessageLite(MessageLite* message) { delete message; } diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 57a86a87c5..02661f6725 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -294,11 +294,6 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Pre-condition: prototype must not be nullptr. MessageLite* AddMessage(const MessageLite* prototype); - // This method is similar to `AddMessage` except that prototype may be nullptr - // in which case an ImplicitWeakMessage will be used as a placeholder. It is - // used to implement implicit weak fields. - MessageLite* AddWeak(const MessageLite* prototype); - template void Clear() { const int n = current_size_; @@ -838,10 +833,6 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return InternalExtend(n - Capacity()); } - // Internal helper for Add: adds "obj" as the next element in the - // array, including potentially resizing the array with Reserve if - // needed - void* AddOutOfLineHelper(void* obj); // Internal helper for Add that keeps definition out-of-line. void* AddOutOfLineHelper(ElementFactory factory); From f9fb51ff67c19d99723693e49943e505941f5512 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 6 Nov 2023 08:48:15 -0800 Subject: [PATCH 093/387] Move cached size access into the ClassData object as a 32-bit offset. This removes a virtual function from MessageLite. To support this, we now make sure that all derived types provide a ClassData instance tailored for them. All special classes now also contain a CachedSize member to make it a requirement instead of optional. The ClassData instanaces are still not unique because all MapEntry instantiations share one. PiperOrigin-RevId: 579856691 --- src/google/protobuf/compiler/cpp/message.cc | 18 +- .../compiler/java/java_features.pb.cc | 8 +- .../protobuf/compiler/java/java_features.pb.h | 1 - src/google/protobuf/compiler/plugin.pb.cc | 32 +-- src/google/protobuf/compiler/plugin.pb.h | 4 - src/google/protobuf/cpp_features.pb.cc | 8 +- src/google/protobuf/cpp_features.pb.h | 1 - src/google/protobuf/descriptor.pb.cc | 256 +++++++----------- src/google/protobuf/descriptor.pb.h | 32 --- src/google/protobuf/dynamic_message.cc | 10 +- .../protobuf/generated_message_bases.cc | 5 +- src/google/protobuf/generated_message_bases.h | 4 - src/google/protobuf/implicit_weak_message.h | 14 +- src/google/protobuf/map_entry.h | 33 ++- src/google/protobuf/message.cc | 18 +- src/google/protobuf/message.h | 4 - src/google/protobuf/message_lite.cc | 14 +- src/google/protobuf/message_lite.h | 19 +- 18 files changed, 190 insertions(+), 291 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index b5f89a9da2..59d7c1e8f9 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -1554,7 +1554,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { int GetCachedSize() const { return $cached_size$.Get(); } private: - $pbi$::CachedSize* AccessCachedSize() const final; void SharedCtor(::$proto_ns$::Arena* arena); void SharedDtor(); void InternalSwap($classname$* other); @@ -2088,14 +2087,6 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) { DefaultInstanceName(descriptor_, options_, /*split=*/false)); } - if (!HasSimpleBaseClass(descriptor_, options_)) { - p->Emit(R"cc( - ::_pbi::CachedSize* $classname$::AccessCachedSize() const { - return &$cached_size$; - } - )cc"); - } - GenerateVerify(p); GenerateSwap(p); @@ -3440,6 +3431,7 @@ void MessageGenerator::GenerateClassData(io::Printer* p) { }, R"cc( $merge_impl$, $on_demand_register_arena_dtor$, $descriptor_methods$, + PROTOBUF_FIELD_OFFSET($classname$, $cached_size$), )cc"); }; @@ -3450,10 +3442,10 @@ void MessageGenerator::GenerateClassData(io::Printer* p) { const ::$proto_ns$::MessageLite::ClassData* $classname$::GetClassData() const { PROTOBUF_CONSTINIT static const ::$proto_ns$::MessageLite::ClassData - data = { + _data_ = { $class_data_members$, }; - return &data; + return &_data_; } )cc"); } else { @@ -3469,14 +3461,14 @@ void MessageGenerator::GenerateClassData(io::Printer* p) { ::$proto_ns$::MessageLite::ClassData header; char type_name[$type_size$]; }; - PROTOBUF_CONSTINIT static const ClassData_ data = { + PROTOBUF_CONSTINIT static const ClassData_ _data_ = { { $class_data_members$, }, "$full_name$", }; - return &data.header; + return &_data_.header; } )cc"); } diff --git a/src/google/protobuf/compiler/java/java_features.pb.cc b/src/google/protobuf/compiler/java/java_features.pb.cc index 1b02dbef59..df3c83a3b3 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.cc +++ b/src/google/protobuf/compiler/java/java_features.pb.cc @@ -199,12 +199,13 @@ inline void JavaFeatures::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* JavaFeatures::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { JavaFeatures::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void JavaFeatures::Clear() { // @@protoc_insertion_point(message_clear_start:pb.JavaFeatures) @@ -355,9 +356,6 @@ PROTOBUF_NOINLINE bool JavaFeatures::IsInitialized() const { return true; } -::_pbi::CachedSize* JavaFeatures::AccessCachedSize() const { - return &_impl_._cached_size_; -} void JavaFeatures::InternalSwap(JavaFeatures* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 675581b2fb..e4b0a514fe 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -211,7 +211,6 @@ class PROTOC_EXPORT JavaFeatures final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(JavaFeatures* other); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 06e403cc6e..d16ebb9888 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -384,12 +384,13 @@ inline void Version::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Version::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Version::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Version, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Version::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.Version) @@ -592,9 +593,6 @@ PROTOBUF_NOINLINE bool Version::IsInitialized() const { return true; } -::_pbi::CachedSize* Version::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Version::InternalSwap(Version* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -701,12 +699,13 @@ inline void CodeGeneratorRequest::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* CodeGeneratorRequest::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { CodeGeneratorRequest::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(CodeGeneratorRequest, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void CodeGeneratorRequest::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorRequest) @@ -942,9 +941,6 @@ PROTOBUF_NOINLINE bool CodeGeneratorRequest::IsInitialized() const { return true; } -::_pbi::CachedSize* CodeGeneratorRequest::AccessCachedSize() const { - return &_impl_._cached_size_; -} void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -1052,12 +1048,13 @@ inline void CodeGeneratorResponse_File::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* CodeGeneratorResponse_File::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { CodeGeneratorResponse_File::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(CodeGeneratorResponse_File, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void CodeGeneratorResponse_File::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse.File) @@ -1271,9 +1268,6 @@ PROTOBUF_NOINLINE bool CodeGeneratorResponse_File::IsInitialized() const { return true; } -::_pbi::CachedSize* CodeGeneratorResponse_File::AccessCachedSize() const { - return &_impl_._cached_size_; -} void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -1357,12 +1351,13 @@ inline void CodeGeneratorResponse::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* CodeGeneratorResponse::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { CodeGeneratorResponse::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(CodeGeneratorResponse, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void CodeGeneratorResponse::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse) @@ -1541,9 +1536,6 @@ PROTOBUF_NOINLINE bool CodeGeneratorResponse::IsInitialized() const { return true; } -::_pbi::CachedSize* CodeGeneratorResponse::AccessCachedSize() const { - return &_impl_._cached_size_; -} void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 79175d8f67..d4d3613920 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -228,7 +228,6 @@ class PROTOC_EXPORT Version final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Version* other); @@ -448,7 +447,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(CodeGeneratorResponse_File* other); @@ -684,7 +682,6 @@ class PROTOC_EXPORT CodeGeneratorResponse final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(CodeGeneratorResponse* other); @@ -921,7 +918,6 @@ class PROTOC_EXPORT CodeGeneratorRequest final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(CodeGeneratorRequest* other); diff --git a/src/google/protobuf/cpp_features.pb.cc b/src/google/protobuf/cpp_features.pb.cc index 55c1864695..e4f9fc81f9 100644 --- a/src/google/protobuf/cpp_features.pb.cc +++ b/src/google/protobuf/cpp_features.pb.cc @@ -160,12 +160,13 @@ inline void CppFeatures::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* CppFeatures::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { CppFeatures::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void CppFeatures::Clear() { // @@protoc_insertion_point(message_clear_start:pb.CppFeatures) @@ -283,9 +284,6 @@ PROTOBUF_NOINLINE bool CppFeatures::IsInitialized() const { return true; } -::_pbi::CachedSize* CppFeatures::AccessCachedSize() const { - return &_impl_._cached_size_; -} void CppFeatures::InternalSwap(CppFeatures* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index a39685ec5b..c06083ecad 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -180,7 +180,6 @@ class PROTOBUF_EXPORT CppFeatures final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(CppFeatures* other); diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index ae02aa9a2d..e690ce6cad 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -2399,12 +2399,13 @@ inline void FileDescriptorSet::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FileDescriptorSet::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FileDescriptorSet::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FileDescriptorSet, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FileDescriptorSet::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FileDescriptorSet) @@ -2521,9 +2522,6 @@ PROTOBUF_NOINLINE bool FileDescriptorSet::IsInitialized() const { return true; } -::_pbi::CachedSize* FileDescriptorSet::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FileDescriptorSet::InternalSwap(FileDescriptorSet* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -2653,12 +2651,13 @@ inline void FileDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FileDescriptorProto::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FileDescriptorProto::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FileDescriptorProto, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FileDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FileDescriptorProto) @@ -3107,9 +3106,6 @@ PROTOBUF_NOINLINE bool FileDescriptorProto::IsInitialized() const { return true; } -::_pbi::CachedSize* FileDescriptorProto::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FileDescriptorProto::InternalSwap(FileDescriptorProto* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -3223,12 +3219,13 @@ inline void DescriptorProto_ExtensionRange::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* DescriptorProto_ExtensionRange::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { DescriptorProto_ExtensionRange::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(DescriptorProto_ExtensionRange, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void DescriptorProto_ExtensionRange::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto.ExtensionRange) @@ -3410,9 +3407,6 @@ PROTOBUF_NOINLINE bool DescriptorProto_ExtensionRange::IsInitialized() const { return true; } -::_pbi::CachedSize* DescriptorProto_ExtensionRange::AccessCachedSize() const { - return &_impl_._cached_size_; -} void DescriptorProto_ExtensionRange::InternalSwap(DescriptorProto_ExtensionRange* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -3482,12 +3476,13 @@ inline void DescriptorProto_ReservedRange::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* DescriptorProto_ReservedRange::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { DescriptorProto_ReservedRange::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(DescriptorProto_ReservedRange, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void DescriptorProto_ReservedRange::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto.ReservedRange) @@ -3638,9 +3633,6 @@ PROTOBUF_NOINLINE bool DescriptorProto_ReservedRange::IsInitialized() const { return true; } -::_pbi::CachedSize* DescriptorProto_ReservedRange::AccessCachedSize() const { - return &_impl_._cached_size_; -} void DescriptorProto_ReservedRange::InternalSwap(DescriptorProto_ReservedRange* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -3746,12 +3738,13 @@ inline void DescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* DescriptorProto::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { DescriptorProto::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(DescriptorProto, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void DescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto) @@ -4122,9 +4115,6 @@ PROTOBUF_NOINLINE bool DescriptorProto::IsInitialized() const { return true; } -::_pbi::CachedSize* DescriptorProto::AccessCachedSize() const { - return &_impl_._cached_size_; -} void DescriptorProto::InternalSwap(DescriptorProto* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -4235,12 +4225,13 @@ inline void ExtensionRangeOptions_Declaration::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ExtensionRangeOptions_Declaration::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { ExtensionRangeOptions_Declaration::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(ExtensionRangeOptions_Declaration, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void ExtensionRangeOptions_Declaration::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ExtensionRangeOptions.Declaration) @@ -4472,9 +4463,6 @@ PROTOBUF_NOINLINE bool ExtensionRangeOptions_Declaration::IsInitialized() const return true; } -::_pbi::CachedSize* ExtensionRangeOptions_Declaration::AccessCachedSize() const { - return &_impl_._cached_size_; -} void ExtensionRangeOptions_Declaration::InternalSwap(ExtensionRangeOptions_Declaration* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -4574,12 +4562,13 @@ inline void ExtensionRangeOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ExtensionRangeOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { ExtensionRangeOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(ExtensionRangeOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void ExtensionRangeOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ExtensionRangeOptions) @@ -4802,9 +4791,6 @@ PROTOBUF_NOINLINE bool ExtensionRangeOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* ExtensionRangeOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void ExtensionRangeOptions::InternalSwap(ExtensionRangeOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -4950,12 +4936,13 @@ inline void FieldDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FieldDescriptorProto::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FieldDescriptorProto::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FieldDescriptorProto, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FieldDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldDescriptorProto) @@ -5355,9 +5342,6 @@ PROTOBUF_NOINLINE bool FieldDescriptorProto::IsInitialized() const { return true; } -::_pbi::CachedSize* FieldDescriptorProto::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -5454,12 +5438,13 @@ inline void OneofDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* OneofDescriptorProto::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { OneofDescriptorProto::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(OneofDescriptorProto, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void OneofDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.OneofDescriptorProto) @@ -5621,9 +5606,6 @@ PROTOBUF_NOINLINE bool OneofDescriptorProto::IsInitialized() const { return true; } -::_pbi::CachedSize* OneofDescriptorProto::AccessCachedSize() const { - return &_impl_._cached_size_; -} void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -5691,12 +5673,13 @@ inline void EnumDescriptorProto_EnumReservedRange::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumDescriptorProto_EnumReservedRange::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { EnumDescriptorProto_EnumReservedRange::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(EnumDescriptorProto_EnumReservedRange, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void EnumDescriptorProto_EnumReservedRange::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumDescriptorProto.EnumReservedRange) @@ -5847,9 +5830,6 @@ PROTOBUF_NOINLINE bool EnumDescriptorProto_EnumReservedRange::IsInitialized() co return true; } -::_pbi::CachedSize* EnumDescriptorProto_EnumReservedRange::AccessCachedSize() const { - return &_impl_._cached_size_; -} void EnumDescriptorProto_EnumReservedRange::InternalSwap(EnumDescriptorProto_EnumReservedRange* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -5945,12 +5925,13 @@ inline void EnumDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumDescriptorProto::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { EnumDescriptorProto::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(EnumDescriptorProto, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void EnumDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumDescriptorProto) @@ -6188,9 +6169,6 @@ PROTOBUF_NOINLINE bool EnumDescriptorProto::IsInitialized() const { return true; } -::_pbi::CachedSize* EnumDescriptorProto::AccessCachedSize() const { - return &_impl_._cached_size_; -} void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -6290,12 +6268,13 @@ inline void EnumValueDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumValueDescriptorProto::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { EnumValueDescriptorProto::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(EnumValueDescriptorProto, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void EnumValueDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValueDescriptorProto) @@ -6482,9 +6461,6 @@ PROTOBUF_NOINLINE bool EnumValueDescriptorProto::IsInitialized() const { return true; } -::_pbi::CachedSize* EnumValueDescriptorProto::AccessCachedSize() const { - return &_impl_._cached_size_; -} void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -6579,12 +6555,13 @@ inline void ServiceDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ServiceDescriptorProto::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { ServiceDescriptorProto::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(ServiceDescriptorProto, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void ServiceDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ServiceDescriptorProto) @@ -6773,9 +6750,6 @@ PROTOBUF_NOINLINE bool ServiceDescriptorProto::IsInitialized() const { return true; } -::_pbi::CachedSize* ServiceDescriptorProto::AccessCachedSize() const { - return &_impl_._cached_size_; -} void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -6894,12 +6868,13 @@ inline void MethodDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* MethodDescriptorProto::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { MethodDescriptorProto::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(MethodDescriptorProto, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void MethodDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.MethodDescriptorProto) @@ -7163,9 +7138,6 @@ PROTOBUF_NOINLINE bool MethodDescriptorProto::IsInitialized() const { return true; } -::_pbi::CachedSize* MethodDescriptorProto::AccessCachedSize() const { - return &_impl_._cached_size_; -} void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -7363,12 +7335,13 @@ inline void FileOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FileOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FileOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FileOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FileOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FileOptions) @@ -8050,9 +8023,6 @@ PROTOBUF_NOINLINE bool FileOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* FileOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FileOptions::InternalSwap(FileOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -8182,12 +8152,13 @@ inline void MessageOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* MessageOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { MessageOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(MessageOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void MessageOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.MessageOptions) @@ -8464,9 +8435,6 @@ PROTOBUF_NOINLINE bool MessageOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* MessageOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void MessageOptions::InternalSwap(MessageOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -8550,12 +8518,13 @@ inline void FieldOptions_EditionDefault::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FieldOptions_EditionDefault::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FieldOptions_EditionDefault::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FieldOptions_EditionDefault, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FieldOptions_EditionDefault::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldOptions.EditionDefault) @@ -8709,9 +8678,6 @@ PROTOBUF_NOINLINE bool FieldOptions_EditionDefault::IsInitialized() const { return true; } -::_pbi::CachedSize* FieldOptions_EditionDefault::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FieldOptions_EditionDefault::InternalSwap(FieldOptions_EditionDefault* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -8841,12 +8807,13 @@ inline void FieldOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FieldOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FieldOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FieldOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FieldOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldOptions) @@ -9276,9 +9243,6 @@ PROTOBUF_NOINLINE bool FieldOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* FieldOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FieldOptions::InternalSwap(FieldOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -9371,12 +9335,13 @@ inline void OneofOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* OneofOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { OneofOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(OneofOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void OneofOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.OneofOptions) @@ -9542,9 +9507,6 @@ PROTOBUF_NOINLINE bool OneofOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* OneofOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void OneofOptions::InternalSwap(OneofOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -9651,12 +9613,13 @@ inline void EnumOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { EnumOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(EnumOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void EnumOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumOptions) @@ -9893,9 +9856,6 @@ PROTOBUF_NOINLINE bool EnumOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* EnumOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void EnumOptions::InternalSwap(EnumOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -10004,12 +9964,13 @@ inline void EnumValueOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumValueOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { EnumValueOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(EnumValueOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void EnumValueOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValueOptions) @@ -10228,9 +10189,6 @@ PROTOBUF_NOINLINE bool EnumValueOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* EnumValueOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void EnumValueOptions::InternalSwap(EnumValueOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -10330,12 +10288,13 @@ inline void ServiceOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ServiceOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { ServiceOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(ServiceOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void ServiceOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ServiceOptions) @@ -10529,9 +10488,6 @@ PROTOBUF_NOINLINE bool ServiceOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* ServiceOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void ServiceOptions::InternalSwap(ServiceOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -10640,12 +10596,13 @@ inline void MethodOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* MethodOptions::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { MethodOptions::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(MethodOptions, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void MethodOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.MethodOptions) @@ -10869,9 +10826,6 @@ PROTOBUF_NOINLINE bool MethodOptions::IsInitialized() const { return true; } -::_pbi::CachedSize* MethodOptions::AccessCachedSize() const { - return &_impl_._cached_size_; -} void MethodOptions::InternalSwap(MethodOptions* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -10958,12 +10912,13 @@ inline void UninterpretedOption_NamePart::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* UninterpretedOption_NamePart::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { UninterpretedOption_NamePart::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(UninterpretedOption_NamePart, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void UninterpretedOption_NamePart::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UninterpretedOption.NamePart) @@ -11119,9 +11074,6 @@ PROTOBUF_NOINLINE bool UninterpretedOption_NamePart::IsInitialized() const { return true; } -::_pbi::CachedSize* UninterpretedOption_NamePart::AccessCachedSize() const { - return &_impl_._cached_size_; -} void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -11232,12 +11184,13 @@ inline void UninterpretedOption::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* UninterpretedOption::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { UninterpretedOption::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(UninterpretedOption, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void UninterpretedOption::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UninterpretedOption) @@ -11517,9 +11470,6 @@ PROTOBUF_NOINLINE bool UninterpretedOption::IsInitialized() const { return true; } -::_pbi::CachedSize* UninterpretedOption::AccessCachedSize() const { - return &_impl_._cached_size_; -} void UninterpretedOption::InternalSwap(UninterpretedOption* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -11630,12 +11580,13 @@ inline void FeatureSet::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FeatureSet::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FeatureSet::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FeatureSet::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FeatureSet) @@ -11891,9 +11842,6 @@ PROTOBUF_NOINLINE bool FeatureSet::IsInitialized() const { return true; } -::_pbi::CachedSize* FeatureSet::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FeatureSet::InternalSwap(FeatureSet* PROTOBUF_RESTRICT other) { using std::swap; _impl_._extensions_.InternalSwap(&other->_impl_._extensions_); @@ -11987,12 +11935,13 @@ inline void FeatureSetDefaults_FeatureSetEditionDefault::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FeatureSetDefaults_FeatureSetEditionDefault::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FeatureSetDefaults_FeatureSetEditionDefault, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FeatureSetDefaults_FeatureSetEditionDefault::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault) @@ -12148,9 +12097,6 @@ PROTOBUF_NOINLINE bool FeatureSetDefaults_FeatureSetEditionDefault::IsInitialize return true; } -::_pbi::CachedSize* FeatureSetDefaults_FeatureSetEditionDefault::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FeatureSetDefaults_FeatureSetEditionDefault::InternalSwap(FeatureSetDefaults_FeatureSetEditionDefault* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -12242,12 +12188,13 @@ inline void FeatureSetDefaults::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FeatureSetDefaults::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FeatureSetDefaults::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FeatureSetDefaults, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FeatureSetDefaults::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FeatureSetDefaults) @@ -12422,9 +12369,6 @@ PROTOBUF_NOINLINE bool FeatureSetDefaults::IsInitialized() const { return true; } -::_pbi::CachedSize* FeatureSetDefaults::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FeatureSetDefaults::InternalSwap(FeatureSetDefaults* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -12518,12 +12462,13 @@ inline void SourceCodeInfo_Location::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* SourceCodeInfo_Location::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { SourceCodeInfo_Location::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(SourceCodeInfo_Location, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void SourceCodeInfo_Location::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.SourceCodeInfo.Location) @@ -12768,9 +12713,6 @@ PROTOBUF_NOINLINE bool SourceCodeInfo_Location::IsInitialized() const { return true; } -::_pbi::CachedSize* SourceCodeInfo_Location::AccessCachedSize() const { - return &_impl_._cached_size_; -} void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -12840,12 +12782,13 @@ inline void SourceCodeInfo::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* SourceCodeInfo::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { SourceCodeInfo::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(SourceCodeInfo, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void SourceCodeInfo::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.SourceCodeInfo) @@ -12960,9 +12903,6 @@ PROTOBUF_NOINLINE bool SourceCodeInfo::IsInitialized() const { return true; } -::_pbi::CachedSize* SourceCodeInfo::AccessCachedSize() const { - return &_impl_._cached_size_; -} void SourceCodeInfo::InternalSwap(SourceCodeInfo* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -13059,12 +12999,13 @@ inline void GeneratedCodeInfo_Annotation::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* GeneratedCodeInfo_Annotation::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { GeneratedCodeInfo_Annotation::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void GeneratedCodeInfo_Annotation::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.GeneratedCodeInfo.Annotation) @@ -13299,9 +13240,6 @@ PROTOBUF_NOINLINE bool GeneratedCodeInfo_Annotation::IsInitialized() const { return true; } -::_pbi::CachedSize* GeneratedCodeInfo_Annotation::AccessCachedSize() const { - return &_impl_._cached_size_; -} void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -13374,12 +13312,13 @@ inline void GeneratedCodeInfo::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* GeneratedCodeInfo::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { GeneratedCodeInfo::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void GeneratedCodeInfo::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.GeneratedCodeInfo) @@ -13494,9 +13433,6 @@ PROTOBUF_NOINLINE bool GeneratedCodeInfo::IsInitialized() const { return true; } -::_pbi::CachedSize* GeneratedCodeInfo::AccessCachedSize() const { - return &_impl_._cached_size_; -} void GeneratedCodeInfo::InternalSwap(GeneratedCodeInfo* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 05856a366b..5a0ab746b2 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -809,7 +809,6 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(UninterpretedOption_NamePart* other); @@ -1003,7 +1002,6 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(SourceCodeInfo_Location* other); @@ -1275,7 +1273,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(GeneratedCodeInfo_Annotation* other); @@ -1537,7 +1534,6 @@ class PROTOBUF_EXPORT FieldOptions_EditionDefault final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FieldOptions_EditionDefault* other); @@ -1731,7 +1727,6 @@ class PROTOBUF_EXPORT FeatureSet final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FeatureSet* other); @@ -2277,7 +2272,6 @@ class PROTOBUF_EXPORT ExtensionRangeOptions_Declaration final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(ExtensionRangeOptions_Declaration* other); @@ -2516,7 +2510,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(EnumDescriptorProto_EnumReservedRange* other); @@ -2704,7 +2697,6 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(DescriptorProto_ReservedRange* other); @@ -2892,7 +2884,6 @@ class PROTOBUF_EXPORT UninterpretedOption final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(UninterpretedOption* other); @@ -3172,7 +3163,6 @@ class PROTOBUF_EXPORT SourceCodeInfo final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(SourceCodeInfo* other); @@ -3355,7 +3345,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(GeneratedCodeInfo* other); @@ -3538,7 +3527,6 @@ class PROTOBUF_EXPORT FeatureSetDefaults_FeatureSetEditionDefault final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FeatureSetDefaults_FeatureSetEditionDefault* other); @@ -3730,7 +3718,6 @@ class PROTOBUF_EXPORT ServiceOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(ServiceOptions* other); @@ -4121,7 +4108,6 @@ class PROTOBUF_EXPORT OneofOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(OneofOptions* other); @@ -4499,7 +4485,6 @@ class PROTOBUF_EXPORT MethodOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(MethodOptions* other); @@ -4924,7 +4909,6 @@ class PROTOBUF_EXPORT MessageOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(MessageOptions* other); @@ -5367,7 +5351,6 @@ class PROTOBUF_EXPORT FileOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FileOptions* other); @@ -6086,7 +6069,6 @@ class PROTOBUF_EXPORT FieldOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FieldOptions* other); @@ -6715,7 +6697,6 @@ class PROTOBUF_EXPORT FeatureSetDefaults final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FeatureSetDefaults* other); @@ -6925,7 +6906,6 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(ExtensionRangeOptions* other); @@ -7358,7 +7338,6 @@ class PROTOBUF_EXPORT EnumValueOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(EnumValueOptions* other); @@ -7762,7 +7741,6 @@ class PROTOBUF_EXPORT EnumOptions final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(EnumOptions* other); @@ -8179,7 +8157,6 @@ class PROTOBUF_EXPORT OneofDescriptorProto final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(OneofDescriptorProto* other); @@ -8377,7 +8354,6 @@ class PROTOBUF_EXPORT MethodDescriptorProto final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(MethodDescriptorProto* other); @@ -8639,7 +8615,6 @@ class PROTOBUF_EXPORT FieldDescriptorProto final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FieldDescriptorProto* other); @@ -9035,7 +9010,6 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(EnumValueDescriptorProto* other); @@ -9246,7 +9220,6 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(DescriptorProto_ExtensionRange* other); @@ -9451,7 +9424,6 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(ServiceDescriptorProto* other); @@ -9669,7 +9641,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(EnumDescriptorProto* other); @@ -9939,7 +9910,6 @@ class PROTOBUF_EXPORT DescriptorProto final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(DescriptorProto* other); @@ -10310,7 +10280,6 @@ class PROTOBUF_EXPORT FileDescriptorProto final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FileDescriptorProto* other); @@ -10726,7 +10695,6 @@ class PROTOBUF_EXPORT FileDescriptorSet final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FileDescriptorSet* other); diff --git a/src/google/protobuf/dynamic_message.cc b/src/google/protobuf/dynamic_message.cc index 64427553cc..94d7e45bd0 100644 --- a/src/google/protobuf/dynamic_message.cc +++ b/src/google/protobuf/dynamic_message.cc @@ -204,8 +204,14 @@ class DynamicMessage final : public Message { Message* New(Arena* arena) const override; - internal::CachedSize* AccessCachedSize() const final { - return &cached_byte_size_; + const ClassData* GetClassData() const final { + ABSL_CONST_INIT static const ClassData data = { + &MergeImpl, + nullptr, // on_demand_register_arena_dtor + &kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(DynamicMessage, cached_byte_size_), + }; + return &data; } Metadata GetMetadata() const override; diff --git a/src/google/protobuf/generated_message_bases.cc b/src/google/protobuf/generated_message_bases.cc index 5821ac6157..45bdf0ceba 100644 --- a/src/google/protobuf/generated_message_bases.cc +++ b/src/google/protobuf/generated_message_bases.cc @@ -96,10 +96,11 @@ void ZeroFieldsBase::InternalSwap(ZeroFieldsBase* other) { } const Message::ClassData* ZeroFieldsBase::GetClassData() const { - static constexpr ClassData data = { + ABSL_CONST_INIT static const ClassData data = { &MergeImpl, - nullptr, + nullptr, // on_demand_register_arena_dtor &kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(ZeroFieldsBase, _cached_size_), }; return &data; } diff --git a/src/google/protobuf/generated_message_bases.h b/src/google/protobuf/generated_message_bases.h index 0f5e398a53..4cd97577e0 100644 --- a/src/google/protobuf/generated_message_bases.h +++ b/src/google/protobuf/generated_message_bases.h @@ -39,10 +39,6 @@ class PROTOBUF_EXPORT ZeroFieldsBase : public Message { io::EpsCopyOutputStream* stream) const final; protected: - internal::CachedSize* AccessCachedSize() const final { - return &_cached_size_; - } - constexpr ZeroFieldsBase() {} explicit ZeroFieldsBase(Arena* arena) : Message(arena) {} ZeroFieldsBase(const ZeroFieldsBase&) = delete; diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index 61bfbbb58e..7c94d394f3 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -61,7 +61,14 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { ClassData header; char name[1]; }; - static constexpr Data data = {{}, ""}; + static constexpr Data data = { + { + nullptr, // merge_impl + nullptr, // on_demand_register_arena_dtor + nullptr, // descriptor_methods + PROTOBUF_FIELD_OFFSET(ImplicitWeakMessage, cached_size_), + }, + ""}; return &data.header; } @@ -84,7 +91,9 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { const char* _InternalParse(const char* ptr, ParseContext* ctx) final; size_t ByteSizeLong() const override { - return data_ == nullptr ? 0 : data_->size(); + size_t size = data_ == nullptr ? 0 : data_->size(); + cached_size_.Set(internal::ToCachedSize(size)); + return size; } uint8_t* _InternalSerialize(uint8_t* target, @@ -103,6 +112,7 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { // the default instance can be constant-initialized. In the const methods, we // have to handle the possibility of data_ being null. std::string* data_; + mutable google::protobuf::internal::CachedSize cached_size_{}; }; struct ImplicitWeakMessageDefaultType; diff --git a/src/google/protobuf/map_entry.h b/src/google/protobuf/map_entry.h index 2163383aed..1bc1fc3c8b 100644 --- a/src/google/protobuf/map_entry.h +++ b/src/google/protobuf/map_entry.h @@ -44,6 +44,25 @@ namespace google { namespace protobuf { namespace internal { +// Base class to keep common fields and virtual function overrides. +class MapEntryBase : public Message { + protected: + using Message::Message; + + const ClassData* GetClassData() const final { + ABSL_CONST_INIT static const ClassData data = { + &MergeImpl, + nullptr, // on_demand_register_arena_dtor + &kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(MapEntryBase, _cached_size_), + }; + return &data; + } + + HasBits<1> _has_bits_{}; + mutable CachedSize _cached_size_{}; +}; + // MapEntry is the returned google::protobuf::Message when calling AddMessage of // google::protobuf::Reflection. In order to let it work with generated message // reflection, its in-memory type is the same as generated message with the same @@ -73,7 +92,7 @@ namespace internal { template -class MapEntry : public Message { +class MapEntry : public MapEntryBase { // Provide utilities to parse/serialize key/value. Provide utilities to // manipulate internal stored type. using KeyTypeHandler = MapTypeHandler; @@ -98,14 +117,12 @@ class MapEntry : public Message { public: constexpr MapEntry() : key_(KeyTypeHandler::Constinit()), - value_(ValueTypeHandler::Constinit()), - _has_bits_{} {} + value_(ValueTypeHandler::Constinit()) {} explicit MapEntry(Arena* arena) - : Message(arena), + : MapEntryBase(arena), key_(KeyTypeHandler::Constinit()), - value_(ValueTypeHandler::Constinit()), - _has_bits_{} {} + value_(ValueTypeHandler::Constinit()) {} MapEntry(const MapEntry&) = delete; MapEntry& operator=(const MapEntry&) = delete; @@ -190,8 +207,6 @@ class MapEntry : public Message { return Arena::CreateMessage(arena); } - CachedSize* AccessCachedSize() const final { return &_cached_size_; } - protected: friend class google::protobuf::Arena; template _has_bits_; - mutable CachedSize _cached_size_; }; } // namespace internal diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 2cf07dbdf4..200ba1e6a2 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -74,15 +74,6 @@ void Message::MergeFrom(const Message& from) { merge_to_from(*this, from); } -const MessageLite::ClassData* Message::GetClassData() const { - static constexpr ClassData data = { - &MergeImpl, - nullptr, - &kDescriptorMethods, - }; - return &data; -} - void Message::CheckTypeAndMergeFrom(const MessageLite& other) { MergeFrom(*DownCast(&other)); } @@ -158,14 +149,7 @@ uint8_t* Message::_InternalSerialize(uint8_t* target, size_t Message::ByteSizeLong() const { size_t size = WireFormat::ByteSize(*this); - - auto* cached_size = AccessCachedSize(); - ABSL_CHECK(cached_size != nullptr) - << "Message class \"" << GetDescriptor()->full_name() - << "\" implements neither AccessCachedSize() nor ByteSizeLong(). " - "Must implement one or the other."; - cached_size->Set(internal::ToCachedSize(size)); - + AccessCachedSize().Set(internal::ToCachedSize(size)); return size; } diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 6ddbaec21c..8630cdc369 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -373,10 +373,6 @@ class PROTOBUF_EXPORT Message : public MessageLite { static const DescriptorMethods kDescriptorMethods; - // Default implementation using reflection. Avoids bloat in MapEntry. - // Generated types will make their own. - const ClassData* GetClassData() const override; - }; namespace internal { diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 12ee82f4ca..36e8597c47 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -83,13 +83,15 @@ std::string MessageLite::DebugString() const { return absl::StrCat("MessageLite at 0x", absl::Hex(this)); } -int MessageLite::GetCachedSize() const { - auto* cached_size = AccessCachedSize(); - if (PROTOBUF_PREDICT_FALSE(cached_size == nullptr)) return ByteSize(); - return cached_size->Get(); -} +int MessageLite::GetCachedSize() const { return AccessCachedSize().Get(); } -internal::CachedSize* MessageLite::AccessCachedSize() const { return nullptr; } +internal::CachedSize& MessageLite::AccessCachedSize() const { + auto* data = GetClassData(); + ABSL_DCHECK(data != nullptr); + ABSL_DCHECK(data->cached_size_offset != 0); + return *reinterpret_cast(const_cast( + reinterpret_cast(this) + data->cached_size_offset)); +} namespace { diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index cbece7c799..74f6be8612 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -532,6 +532,19 @@ class PROTOBUF_EXPORT MessageLite { // LITE objects (ie !descriptor_methods) collocate their name as a // char[] just beyond the ClassData. const DescriptorMethods* descriptor_methods; + + // Offset of the CachedSize member. + uint32_t cached_size_offset; + + constexpr ClassData(void (*merge_to_from)(Message& to, const Message&), + void (*on_demand_register_arena_dtor)(MessageLite&, + Arena&), + const DescriptorMethods* descriptor_methods, + uint32_t cached_size_offset) + : merge_to_from(merge_to_from), + on_demand_register_arena_dtor(on_demand_register_arena_dtor), + descriptor_methods(descriptor_methods), + cached_size_offset(cached_size_offset) {} }; // GetClassData() returns a pointer to a ClassData struct which @@ -545,9 +558,9 @@ class PROTOBUF_EXPORT MessageLite { internal::InternalMetadata _internal_metadata_; - // The default implementation means there is no cached size and ByteSize - // should be called instead. - virtual internal::CachedSize* AccessCachedSize() const; + // Return the cached size object as described by + // ClassData::cached_size_offset. + internal::CachedSize& AccessCachedSize() const; public: enum ParseFlags { From 7e0e8ef385538b074a895a8d824075f7e96c20d9 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 6 Nov 2023 08:58:37 -0800 Subject: [PATCH 094/387] Move python/BUILD to python/BUILD.bazel This should address the issue in #14600 by avoiding a conflict on with the `build` directory created by setup.py on a case-insensitive filesystem. Closes #14600. PiperOrigin-RevId: 579859556 --- python/{BUILD => BUILD.bazel} | 0 python/build_targets.bzl | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename python/{BUILD => BUILD.bazel} (100%) diff --git a/python/BUILD b/python/BUILD.bazel similarity index 100% rename from python/BUILD rename to python/BUILD.bazel diff --git a/python/build_targets.bzl b/python/build_targets.bzl index 91c8dfb37e..fff32b4a5b 100644 --- a/python/build_targets.bzl +++ b/python/build_targets.bzl @@ -456,7 +456,7 @@ def build_targets(name): "google/protobuf/pyext/*.cc", "google/protobuf/pyext/*.h", ]) + [ - "BUILD", + "BUILD.bazel", "MANIFEST.in", "README.md", "build_targets.bzl", From 160697003a10db5e3b56e0fec5846d274e82e317 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 6 Nov 2023 17:01:54 +0000 Subject: [PATCH 095/387] Auto-generate files after cl/579856691 --- src/google/protobuf/any.pb.cc | 8 +-- src/google/protobuf/any.pb.h | 1 - src/google/protobuf/api.pb.cc | 24 +++----- src/google/protobuf/api.pb.h | 3 - src/google/protobuf/duration.pb.cc | 8 +-- src/google/protobuf/duration.pb.h | 1 - src/google/protobuf/field_mask.pb.cc | 8 +-- src/google/protobuf/field_mask.pb.h | 1 - src/google/protobuf/source_context.pb.cc | 8 +-- src/google/protobuf/source_context.pb.h | 1 - src/google/protobuf/struct.pb.cc | 24 +++----- src/google/protobuf/struct.pb.h | 3 - src/google/protobuf/timestamp.pb.cc | 8 +-- src/google/protobuf/timestamp.pb.h | 1 - src/google/protobuf/type.pb.cc | 40 +++++-------- src/google/protobuf/type.pb.h | 5 -- src/google/protobuf/wrappers.pb.cc | 72 +++++++++--------------- src/google/protobuf/wrappers.pb.h | 9 --- 18 files changed, 75 insertions(+), 150 deletions(-) diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 429b41c6f8..889e5d2ed9 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -198,12 +198,13 @@ inline void Any::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Any::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Any::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Any, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Any::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Any) @@ -345,9 +346,6 @@ PROTOBUF_NOINLINE bool Any::IsInitialized() const { return true; } -::_pbi::CachedSize* Any::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Any::InternalSwap(Any* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 10a84ba8af..9ce9e6f2a9 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -213,7 +213,6 @@ class PROTOBUF_EXPORT Any final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Any* other); diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 773786a15b..afcad3de14 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -335,12 +335,13 @@ inline void Api::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Api::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Api::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Api, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Api::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Api) @@ -612,9 +613,6 @@ PROTOBUF_NOINLINE bool Api::IsInitialized() const { return true; } -::_pbi::CachedSize* Api::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Api::InternalSwap(Api* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -716,12 +714,13 @@ inline void Method::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Method::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Method::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Method, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Method::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Method) @@ -982,9 +981,6 @@ PROTOBUF_NOINLINE bool Method::IsInitialized() const { return true; } -::_pbi::CachedSize* Method::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Method::InternalSwap(Method* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -1062,12 +1058,13 @@ inline void Mixin::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Mixin::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Mixin::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Mixin, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Mixin::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Mixin) @@ -1212,9 +1209,6 @@ PROTOBUF_NOINLINE bool Mixin::IsInitialized() const { return true; } -::_pbi::CachedSize* Mixin::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Mixin::InternalSwap(Mixin* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 88d9ccc34f..2252373551 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -186,7 +186,6 @@ class PROTOBUF_EXPORT Mixin final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Mixin* other); @@ -383,7 +382,6 @@ class PROTOBUF_EXPORT Method final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Method* other); @@ -654,7 +652,6 @@ class PROTOBUF_EXPORT Api final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Api* other); diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index a3838bdfa3..4024586011 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -162,12 +162,13 @@ inline void Duration::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Duration::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Duration::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Duration, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Duration::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Duration) @@ -307,9 +308,6 @@ PROTOBUF_NOINLINE bool Duration::IsInitialized() const { return true; } -::_pbi::CachedSize* Duration::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Duration::InternalSwap(Duration* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 346b58d9f1..c165b574b7 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -178,7 +178,6 @@ class PROTOBUF_EXPORT Duration final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Duration* other); diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index 2c6c5badc2..6c6ddd0a6c 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -168,12 +168,13 @@ inline void FieldMask::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FieldMask::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FieldMask::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FieldMask, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FieldMask::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldMask) @@ -291,9 +292,6 @@ PROTOBUF_NOINLINE bool FieldMask::IsInitialized() const { return true; } -::_pbi::CachedSize* FieldMask::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FieldMask::InternalSwap(FieldMask* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 4e8f3946ca..123d28d102 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -178,7 +178,6 @@ class PROTOBUF_EXPORT FieldMask final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FieldMask* other); diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index b93bf206fa..f1b6d8ad1c 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -171,12 +171,13 @@ inline void SourceContext::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* SourceContext::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { SourceContext::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(SourceContext, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void SourceContext::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.SourceContext) @@ -296,9 +297,6 @@ PROTOBUF_NOINLINE bool SourceContext::IsInitialized() const { return true; } -::_pbi::CachedSize* SourceContext::AccessCachedSize() const { - return &_impl_._cached_size_; -} void SourceContext::InternalSwap(SourceContext* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 0e3e2c96fd..1504fe9015 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -178,7 +178,6 @@ class PROTOBUF_EXPORT SourceContext final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(SourceContext* other); diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index cb8e5c9736..4d1b6255ae 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -289,12 +289,13 @@ inline void Struct::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Struct::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Struct::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Struct, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Struct::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Struct) @@ -434,9 +435,6 @@ PROTOBUF_NOINLINE bool Struct::IsInitialized() const { return true; } -::_pbi::CachedSize* Struct::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Struct::InternalSwap(Struct* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -602,12 +600,13 @@ void Value::clear_kind() { const ::google::protobuf::MessageLite::ClassData* Value::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Value::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Value, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Value) @@ -835,9 +834,6 @@ PROTOBUF_NOINLINE bool Value::IsInitialized() const { return true; } -::_pbi::CachedSize* Value::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Value::InternalSwap(Value* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -901,12 +897,13 @@ inline void ListValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ListValue::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { ListValue::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(ListValue, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void ListValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ListValue) @@ -1022,9 +1019,6 @@ PROTOBUF_NOINLINE bool ListValue::IsInitialized() const { return true; } -::_pbi::CachedSize* ListValue::AccessCachedSize() const { - return &_impl_._cached_size_; -} void ListValue::InternalSwap(ListValue* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 61a923efc0..6f5d3e968b 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -223,7 +223,6 @@ class PROTOBUF_EXPORT ListValue final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(ListValue* other); @@ -404,7 +403,6 @@ class PROTOBUF_EXPORT Struct final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Struct* other); @@ -624,7 +622,6 @@ class PROTOBUF_EXPORT Value final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Value* other); diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index e048cb8c30..42a487730a 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -162,12 +162,13 @@ inline void Timestamp::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Timestamp::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Timestamp::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Timestamp, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Timestamp::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Timestamp) @@ -307,9 +308,6 @@ PROTOBUF_NOINLINE bool Timestamp::IsInitialized() const { return true; } -::_pbi::CachedSize* Timestamp::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Timestamp::InternalSwap(Timestamp* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 0d58d1e036..6a6b310aac 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -178,7 +178,6 @@ class PROTOBUF_EXPORT Timestamp final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Timestamp* other); diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 29884227e7..18a1f3946e 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -515,12 +515,13 @@ inline void Type::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Type::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Type::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Type, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Type::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Type) @@ -791,9 +792,6 @@ PROTOBUF_NOINLINE bool Type::IsInitialized() const { return true; } -::_pbi::CachedSize* Type::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Type::InternalSwap(Type* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -894,12 +892,13 @@ inline void Field::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Field::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Field::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Field, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Field::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Field) @@ -1235,9 +1234,6 @@ PROTOBUF_NOINLINE bool Field::IsInitialized() const { return true; } -::_pbi::CachedSize* Field::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Field::InternalSwap(Field* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -1348,12 +1344,13 @@ inline void Enum::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Enum::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Enum::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Enum, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Enum::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Enum) @@ -1602,9 +1599,6 @@ PROTOBUF_NOINLINE bool Enum::IsInitialized() const { return true; } -::_pbi::CachedSize* Enum::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Enum::InternalSwap(Enum* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -1684,12 +1678,13 @@ inline void EnumValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumValue::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { EnumValue::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(EnumValue, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void EnumValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValue) @@ -1856,9 +1851,6 @@ PROTOBUF_NOINLINE bool EnumValue::IsInitialized() const { return true; } -::_pbi::CachedSize* EnumValue::AccessCachedSize() const { - return &_impl_._cached_size_; -} void EnumValue::InternalSwap(EnumValue* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -1948,12 +1940,13 @@ inline void Option::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Option::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Option::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Option, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Option::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Option) @@ -2104,9 +2097,6 @@ PROTOBUF_NOINLINE bool Option::IsInitialized() const { return true; } -::_pbi::CachedSize* Option::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Option::InternalSwap(Option* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index b9bb7f6336..f15c09249d 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -312,7 +312,6 @@ class PROTOBUF_EXPORT Option final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Option* other); @@ -509,7 +508,6 @@ class PROTOBUF_EXPORT Field final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Field* other); @@ -881,7 +879,6 @@ class PROTOBUF_EXPORT EnumValue final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(EnumValue* other); @@ -1092,7 +1089,6 @@ class PROTOBUF_EXPORT Type final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Type* other); @@ -1389,7 +1385,6 @@ class PROTOBUF_EXPORT Enum final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Enum* other); diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index cf7efbb562..895975fdd6 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -405,12 +405,13 @@ inline void DoubleValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* DoubleValue::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { DoubleValue::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(DoubleValue, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void DoubleValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DoubleValue) @@ -540,9 +541,6 @@ PROTOBUF_NOINLINE bool DoubleValue::IsInitialized() const { return true; } -::_pbi::CachedSize* DoubleValue::AccessCachedSize() const { - return &_impl_._cached_size_; -} void DoubleValue::InternalSwap(DoubleValue* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -592,12 +590,13 @@ inline void FloatValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FloatValue::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { FloatValue::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(FloatValue, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void FloatValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FloatValue) @@ -727,9 +726,6 @@ PROTOBUF_NOINLINE bool FloatValue::IsInitialized() const { return true; } -::_pbi::CachedSize* FloatValue::AccessCachedSize() const { - return &_impl_._cached_size_; -} void FloatValue::InternalSwap(FloatValue* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -779,12 +775,13 @@ inline void Int64Value::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Int64Value::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Int64Value::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Int64Value, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Int64Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Int64Value) @@ -900,9 +897,6 @@ PROTOBUF_NOINLINE bool Int64Value::IsInitialized() const { return true; } -::_pbi::CachedSize* Int64Value::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Int64Value::InternalSwap(Int64Value* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -952,12 +946,13 @@ inline void UInt64Value::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* UInt64Value::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { UInt64Value::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(UInt64Value, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void UInt64Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UInt64Value) @@ -1073,9 +1068,6 @@ PROTOBUF_NOINLINE bool UInt64Value::IsInitialized() const { return true; } -::_pbi::CachedSize* UInt64Value::AccessCachedSize() const { - return &_impl_._cached_size_; -} void UInt64Value::InternalSwap(UInt64Value* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -1125,12 +1117,13 @@ inline void Int32Value::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Int32Value::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { Int32Value::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(Int32Value, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void Int32Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Int32Value) @@ -1246,9 +1239,6 @@ PROTOBUF_NOINLINE bool Int32Value::IsInitialized() const { return true; } -::_pbi::CachedSize* Int32Value::AccessCachedSize() const { - return &_impl_._cached_size_; -} void Int32Value::InternalSwap(Int32Value* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -1298,12 +1288,13 @@ inline void UInt32Value::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* UInt32Value::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { UInt32Value::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(UInt32Value, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void UInt32Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UInt32Value) @@ -1419,9 +1410,6 @@ PROTOBUF_NOINLINE bool UInt32Value::IsInitialized() const { return true; } -::_pbi::CachedSize* UInt32Value::AccessCachedSize() const { - return &_impl_._cached_size_; -} void UInt32Value::InternalSwap(UInt32Value* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -1471,12 +1459,13 @@ inline void BoolValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* BoolValue::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { BoolValue::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(BoolValue, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void BoolValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.BoolValue) @@ -1591,9 +1580,6 @@ PROTOBUF_NOINLINE bool BoolValue::IsInitialized() const { return true; } -::_pbi::CachedSize* BoolValue::AccessCachedSize() const { - return &_impl_._cached_size_; -} void BoolValue::InternalSwap(BoolValue* PROTOBUF_RESTRICT other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); @@ -1657,12 +1643,13 @@ inline void StringValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* StringValue::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { StringValue::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(StringValue, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void StringValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.StringValue) @@ -1782,9 +1769,6 @@ PROTOBUF_NOINLINE bool StringValue::IsInitialized() const { return true; } -::_pbi::CachedSize* StringValue::AccessCachedSize() const { - return &_impl_._cached_size_; -} void StringValue::InternalSwap(StringValue* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); @@ -1850,12 +1834,13 @@ inline void BytesValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* BytesValue::GetClassData() const { PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - data = { + _data_ = { BytesValue::MergeImpl, nullptr, // OnDemandRegisterArenaDtor &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_FIELD_OFFSET(BytesValue, _impl_._cached_size_), }; - return &data; + return &_data_; } PROTOBUF_NOINLINE void BytesValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.BytesValue) @@ -1970,9 +1955,6 @@ PROTOBUF_NOINLINE bool BytesValue::IsInitialized() const { return true; } -::_pbi::CachedSize* BytesValue::AccessCachedSize() const { - return &_impl_._cached_size_; -} void BytesValue::InternalSwap(BytesValue* PROTOBUF_RESTRICT other) { using std::swap; auto* arena = GetArena(); diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 564ba0c2c2..3aeffa20c9 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -202,7 +202,6 @@ class PROTOBUF_EXPORT UInt64Value final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(UInt64Value* other); @@ -375,7 +374,6 @@ class PROTOBUF_EXPORT UInt32Value final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(UInt32Value* other); @@ -548,7 +546,6 @@ class PROTOBUF_EXPORT StringValue final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(StringValue* other); @@ -727,7 +724,6 @@ class PROTOBUF_EXPORT Int64Value final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Int64Value* other); @@ -900,7 +896,6 @@ class PROTOBUF_EXPORT Int32Value final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(Int32Value* other); @@ -1073,7 +1068,6 @@ class PROTOBUF_EXPORT FloatValue final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(FloatValue* other); @@ -1246,7 +1240,6 @@ class PROTOBUF_EXPORT DoubleValue final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(DoubleValue* other); @@ -1419,7 +1412,6 @@ class PROTOBUF_EXPORT BytesValue final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(BytesValue* other); @@ -1598,7 +1590,6 @@ class PROTOBUF_EXPORT BoolValue final : int GetCachedSize() const { return _impl_._cached_size_.Get(); } private: - ::google::protobuf::internal::CachedSize* AccessCachedSize() const final; void SharedCtor(::google::protobuf::Arena* arena); void SharedDtor(); void InternalSwap(BoolValue* other); From d702651e5d1ac0929e8bbece2c7310333989b01f Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 6 Nov 2023 09:19:30 -0800 Subject: [PATCH 096/387] [ObjC] Ensure collecting delimitedData always return zero length on failure. There was the potential for if the serialization failed, the final release of the CodedOutputStream could flush some data back into the return result; instead insure a zero length data is always returned for that error case. PiperOrigin-RevId: 579865501 --- objectivec/GPBMessage.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index 64c22dd840..6124b70814 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -1369,6 +1369,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { GPBCodedOutputStream *stream = [[GPBCodedOutputStream alloc] initWithData:data]; @try { [self writeDelimitedToCodedOutputStream:stream]; + [stream flush]; } @catch (NSException *exception) { // This really shouldn't happen. Normally, this could mean there was a bug in the library and it // failed to match between computing the size and writing out the bytes. However, the more @@ -1380,8 +1381,9 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { NSLog(@"%@: Internal exception while building message delimitedData: %@", [self class], exception); #endif - // If it happens, truncate. - data.length = 0; + // If it happens, return an empty data. + [stream release]; + return [NSData data]; } [stream release]; return data; From 349122f777a3d6029e9a189729720b0842072a71 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 6 Nov 2023 11:46:37 -0800 Subject: [PATCH 097/387] Move the declarations in SerialArena to more closely match the style guide. Roughly, this means: types, static constants, constructors, other functions, data members. Also, remove a redundant `private:`. PiperOrigin-RevId: 579911543 --- src/google/protobuf/serial_arena.h | 88 +++++++++++++++--------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/google/protobuf/serial_arena.h b/src/google/protobuf/serial_arena.h index 743965f787..311c1dd3bb 100644 --- a/src/google/protobuf/serial_arena.h +++ b/src/google/protobuf/serial_arena.h @@ -88,6 +88,9 @@ struct FirstSerialArena { // used. class PROTOBUF_EXPORT SerialArena { public: + static constexpr size_t kBlockHeaderSize = + ArenaAlignDefault::Ceil(sizeof(ArenaBlock)); + void CleanupList(); size_t FreeStringBlocks() { // On the active block delete all strings skipping the unused instances. @@ -273,6 +276,24 @@ class PROTOBUF_EXPORT SerialArena { std::vector PeekCleanupListForTesting(); private: + friend class ThreadSafeArena; + + // See comments for cached_blocks_. + struct CachedBlock { + // Simple linked list. + CachedBlock* next; + }; + + static constexpr ptrdiff_t kPrefetchForwardsDegree = ABSL_CACHELINE_SIZE * 16; + static constexpr ptrdiff_t kPrefetchBackwardsDegree = ABSL_CACHELINE_SIZE * 6; + + // Constructor is private as only New() should be used. + inline SerialArena(ArenaBlock* b, ThreadSafeArena& parent); + + // Constructors to handle the first SerialArena. + inline explicit SerialArena(ThreadSafeArena& parent); + inline SerialArena(FirstSerialArena, ArenaBlock* b, ThreadSafeArena& parent); + bool MaybeAllocateString(void*& p); ABSL_ATTRIBUTE_RETURNS_NONNULL void* AllocateFromStringBlockFallback(); @@ -288,9 +309,6 @@ class PROTOBUF_EXPORT SerialArena { cleanup::CreateNode(tag, limit_, elem, destructor); } - static constexpr ptrdiff_t kPrefetchForwardsDegree = ABSL_CACHELINE_SIZE * 16; - static constexpr ptrdiff_t kPrefetchBackwardsDegree = ABSL_CACHELINE_SIZE * 6; - // Prefetch the next kPrefetchForwardsDegree bytes after `prefetch_ptr_` and // up to `prefetch_limit_`, if `next` is within kPrefetchForwardsDegree bytes // of `prefetch_ptr_`. @@ -335,9 +353,6 @@ class PROTOBUF_EXPORT SerialArena { } } - private: - friend class ThreadSafeArena; - // Creates a new SerialArena inside mem using the remaining memory as for // future allocations. // The `parent` arena must outlive the serial arena, which is guaranteed @@ -362,6 +377,29 @@ class PROTOBUF_EXPORT SerialArena { std::memory_order_relaxed); } + // Helper getters/setters to handle relaxed operations on atomic variables. + ArenaBlock* head() { return head_.load(std::memory_order_relaxed); } + const ArenaBlock* head() const { + return head_.load(std::memory_order_relaxed); + } + + char* ptr() { return ptr_.load(std::memory_order_relaxed); } + const char* ptr() const { return ptr_.load(std::memory_order_relaxed); } + void set_ptr(char* ptr) { return ptr_.store(ptr, std::memory_order_relaxed); } + PROTOBUF_ALWAYS_INLINE void set_range(char* ptr, char* limit) { + set_ptr(ptr); + prefetch_ptr_ = ptr; + limit_ = limit; + prefetch_limit_ = limit; + } + + void* AllocateAlignedFallback(size_t n); + void* AllocateAlignedWithCleanupFallback(size_t n, size_t align, + void (*destructor)(void*)); + void AddCleanupFallback(void* elem, void (*destructor)(void*)); + inline void AllocateNewBlock(size_t n); + inline void Init(ArenaBlock* b, size_t offset); + // Members are declared here to track sizeof(SerialArena) and hotness // centrally. They are (roughly) laid out in descending order of hotness. @@ -397,46 +435,8 @@ class PROTOBUF_EXPORT SerialArena { // this free list. // `cached_blocks_[i]` points to the free list for blocks of size `8+2^(i+3)`. // The array of freelists is grown when needed in `ReturnArrayMemory()`. - struct CachedBlock { - // Simple linked list. - CachedBlock* next; - }; uint8_t cached_block_length_ = 0; CachedBlock** cached_blocks_ = nullptr; - - // Helper getters/setters to handle relaxed operations on atomic variables. - ArenaBlock* head() { return head_.load(std::memory_order_relaxed); } - const ArenaBlock* head() const { - return head_.load(std::memory_order_relaxed); - } - - char* ptr() { return ptr_.load(std::memory_order_relaxed); } - const char* ptr() const { return ptr_.load(std::memory_order_relaxed); } - void set_ptr(char* ptr) { return ptr_.store(ptr, std::memory_order_relaxed); } - PROTOBUF_ALWAYS_INLINE void set_range(char* ptr, char* limit) { - set_ptr(ptr); - prefetch_ptr_ = ptr; - limit_ = limit; - prefetch_limit_ = limit; - } - - // Constructor is private as only New() should be used. - inline SerialArena(ArenaBlock* b, ThreadSafeArena& parent); - - // Constructors to handle the first SerialArena. - inline explicit SerialArena(ThreadSafeArena& parent); - inline SerialArena(FirstSerialArena, ArenaBlock* b, ThreadSafeArena& parent); - - void* AllocateAlignedFallback(size_t n); - void* AllocateAlignedWithCleanupFallback(size_t n, size_t align, - void (*destructor)(void*)); - void AddCleanupFallback(void* elem, void (*destructor)(void*)); - inline void AllocateNewBlock(size_t n); - inline void Init(ArenaBlock* b, size_t offset); - - public: - static constexpr size_t kBlockHeaderSize = - ArenaAlignDefault::Ceil(sizeof(ArenaBlock)); }; inline PROTOBUF_ALWAYS_INLINE bool SerialArena::MaybeAllocateString(void*& p) { From a2815fa13fee316ab9ed764391a4311fe25d1d4a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 6 Nov 2023 12:02:18 -0800 Subject: [PATCH 098/387] [ObjC] Ensure -[GPBCodedOutputStream dealloc] cannot throw exceptions If `-[GPBCodedOutputStream flush]` failed (e.g., because the filesystem was out of space), then `-[GPBCodedOutputStream dealloc]` would throw an exception. `-dealloc` cannot fail, so the only thing to do in this case is to silently swallow the exception. PiperOrigin-RevId: 579916429 --- objectivec/GPBCodedOutputStream.m | 9 +++++++- objectivec/Tests/GPBCodedOutputStreamTests.m | 23 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/objectivec/GPBCodedOutputStream.m b/objectivec/GPBCodedOutputStream.m index 0eec4556d6..7f81821413 100644 --- a/objectivec/GPBCodedOutputStream.m +++ b/objectivec/GPBCodedOutputStream.m @@ -160,7 +160,14 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } - (void)dealloc { - [self flush]; + @try { + [self flush]; + } @catch (NSException *exception) { + // -dealloc methods cannot fail, so swallow any exceptions from flushing. +#if defined(DEBUG) && DEBUG + NSLog(@"GPBCodedOutputStream: Exception while flushing in dealloc: %@", exception); +#endif + } [state_.output close]; [state_.output release]; [buffer_ release]; diff --git a/objectivec/Tests/GPBCodedOutputStreamTests.m b/objectivec/Tests/GPBCodedOutputStreamTests.m index e781c25c71..550864995f 100644 --- a/objectivec/Tests/GPBCodedOutputStreamTests.m +++ b/objectivec/Tests/GPBCodedOutputStreamTests.m @@ -393,4 +393,27 @@ NSException, GPBCodedOutputStreamException_WriteFailed); } +- (void)testThatDeallocNeverThrows { + uint8_t buffer[1] = {0}; + + // Output stream which can write precisely 1 byte of data before it's full. + NSOutputStream* output = [[[NSOutputStream alloc] initToBuffer:buffer + capacity:sizeof(buffer)] autorelease]; + + NSMutableData* outputBuffer = [NSMutableData data]; + GPBCodedOutputStream* codedOutput = + [[GPBCodedOutputStream alloc] initWithOutputStream:output data:outputBuffer]; + + [codedOutput writeRawByte:0x23]; + [codedOutput flush]; + + // Put one more byte in the output buffer. + [codedOutput writeRawByte:0x42]; + XCTAssertThrowsSpecificNamed([codedOutput flush], NSException, + GPBCodedOutputStreamException_WriteFailed); + + // -dealloc must not throw when it flushes, even if a previous flush failed. + XCTAssertNoThrow([codedOutput release]); +} + @end From 5c4d643a2d8b28700b94c599020a4c7f5b0bee29 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 6 Nov 2023 14:57:28 -0800 Subject: [PATCH 099/387] Move type card printing to standalone function for reuse. PiperOrigin-RevId: 579966858 --- .../compiler/cpp/parse_function_generator.cc | 139 +----------------- .../protobuf/generated_message_tctable_decl.h | 4 + .../protobuf/generated_message_tctable_impl.h | 4 + .../generated_message_tctable_lite.cc | 133 +++++++++++++++++ .../generated_message_tctable_lite_test.cc | 2 + 5 files changed, 146 insertions(+), 136 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc index a8074dfce7..25bfbbed03 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -621,141 +621,6 @@ void ParseFunctionGenerator::GenerateFastFieldEntries(Formatter& format) { } } -static void FormatFieldKind(Formatter& format, - const TailCallTableInfo::FieldEntryInfo& entry) { - // In here we convert the runtime value of entry.type_card back into a - // sequence of literal enum labels. We use the mnenonic labels for nicer - // codegen. - namespace fl = internal::field_layout; - const uint16_t type_card = entry.type_card; - const int rep_index = (type_card & fl::kRepMask) >> fl::kRepShift; - const int tv_index = (type_card & fl::kTvMask) >> fl::kTvShift; - - // Use `0|` prefix to eagerly convert the enums to int to avoid enum-enum - // operations. They are deprecated in C++20. - format("(0 | "); - static constexpr const char* kFieldCardNames[] = {"Singular", "Optional", - "Repeated", "Oneof"}; - static_assert((fl::kFcSingular >> fl::kFcShift) == 0, ""); - static_assert((fl::kFcOptional >> fl::kFcShift) == 1, ""); - static_assert((fl::kFcRepeated >> fl::kFcShift) == 2, ""); - static_assert((fl::kFcOneof >> fl::kFcShift) == 3, ""); - - format("::_fl::kFc$1$", - kFieldCardNames[(type_card & fl::kFcMask) >> fl::kFcShift]); - -#define PROTOBUF_INTERNAL_TYPE_CARD_CASE(x) \ - case fl::k##x: \ - format(" | ::_fl::k" #x); \ - break - - switch (type_card & fl::kFkMask) { - case fl::kFkString: { - switch (type_card & ~fl::kFcMask & ~fl::kRepMask & ~fl::kSplitMask) { - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Bytes); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(RawString); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Utf8String); - default: - ABSL_LOG(FATAL) << "Unknown type_card: 0x" << type_card; - } - - static constexpr const char* kRepNames[] = {"AString", "IString", "Cord", - "SPiece", "SString"}; - static_assert((fl::kRepAString >> fl::kRepShift) == 0, ""); - static_assert((fl::kRepIString >> fl::kRepShift) == 1, ""); - static_assert((fl::kRepCord >> fl::kRepShift) == 2, ""); - static_assert((fl::kRepSPiece >> fl::kRepShift) == 3, ""); - static_assert((fl::kRepSString >> fl::kRepShift) == 4, ""); - - format(" | ::_fl::kRep$1$", kRepNames[rep_index]); - break; - } - - case fl::kFkMessage: { - format(" | ::_fl::kMessage"); - - static constexpr const char* kRepNames[] = {nullptr, "Group", "Lazy"}; - static_assert((fl::kRepGroup >> fl::kRepShift) == 1, ""); - static_assert((fl::kRepLazy >> fl::kRepShift) == 2, ""); - - if (auto* rep = kRepNames[rep_index]) { - format(" | ::_fl::kRep$1$", rep); - } - - static constexpr const char* kXFormNames[2][4] = { - {nullptr, "Default", "Table", "WeakPtr"}, {nullptr, "Eager", "Lazy"}}; - - static_assert((fl::kTvDefault >> fl::kTvShift) == 1, ""); - static_assert((fl::kTvTable >> fl::kTvShift) == 2, ""); - static_assert((fl::kTvWeakPtr >> fl::kTvShift) == 3, ""); - static_assert((fl::kTvEager >> fl::kTvShift) == 1, ""); - static_assert((fl::kTvLazy >> fl::kTvShift) == 2, ""); - - if (auto* xform = kXFormNames[rep_index == 2][tv_index]) { - format(" | ::_fl::kTv$1$", xform); - } - break; - } - - case fl::kFkMap: - format(" | ::_fl::kMap"); - break; - - case fl::kFkNone: - break; - - case fl::kFkVarint: - case fl::kFkPackedVarint: - case fl::kFkFixed: - case fl::kFkPackedFixed: { - switch (type_card & ~fl::kFcMask & ~fl::kSplitMask) { - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Bool); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Fixed32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(UInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(SFixed32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Int32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(SInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Float); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Enum); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(EnumRange); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(OpenEnum); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Fixed64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(UInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(SFixed64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Int64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(SInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Double); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedBool); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFixed32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedUInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSFixed32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFloat); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedEnum); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedEnumRange); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedOpenEnum); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFixed64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedUInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSFixed64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedDouble); - default: - ABSL_LOG(FATAL) << "Unknown type_card: 0x" << type_card; - } - } - } - - if (type_card & fl::kSplitMask) { - format(" | ::_fl::kSplitTrue"); - } - -#undef PROTOBUF_INTERNAL_TYPE_CARD_CASE - - format(")"); -} - void ParseFunctionGenerator::GenerateFieldEntries(Formatter& format) { for (const auto& entry : tc_table_info_->field_entries) { const FieldDescriptor* field = entry.field; @@ -787,7 +652,9 @@ void ParseFunctionGenerator::GenerateFieldEntries(Formatter& format) { format("0, "); } format("$1$,\n ", entry.aux_idx); - FormatFieldKind(format, entry); + // Use `0|` prefix to eagerly convert the enums to int to avoid enum-enum + // operations. They are deprecated in C++20. + format("(0 | $1$)", internal::TypeCardToString(entry.type_card)); } format("},\n"); } diff --git a/src/google/protobuf/generated_message_tctable_decl.h b/src/google/protobuf/generated_message_tctable_decl.h index 629cfb7293..22aa54b681 100644 --- a/src/google/protobuf/generated_message_tctable_decl.h +++ b/src/google/protobuf/generated_message_tctable_decl.h @@ -18,6 +18,7 @@ #include #include +#include "absl/types/span.h" #include "google/protobuf/message_lite.h" #include "google/protobuf/parse_context.h" @@ -375,6 +376,9 @@ struct alignas(uint64_t) TcParseTableBase { return reinterpret_cast( reinterpret_cast(this) + field_entries_offset); } + absl::Span field_entries() const { + return {field_entries_begin(), num_field_entries}; + } FieldEntry* field_entries_begin() { return reinterpret_cast(reinterpret_cast(this) + field_entries_offset); diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h index 42a56084b3..fb111e34fe 100644 --- a/src/google/protobuf/generated_message_tctable_impl.h +++ b/src/google/protobuf/generated_message_tctable_impl.h @@ -943,6 +943,10 @@ inline PROTOBUF_ALWAYS_INLINE const char* TcParser::ToParseLoop( return ptr; } +// Prints the type card as or of labels, using known higher level labels. +// Used for code generation, but also useful for debugging. +PROTOBUF_EXPORT std::string TypeCardToString(uint16_t type_card); + } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index 104a22a857..e37a208372 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -18,6 +18,7 @@ #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/numeric/bits.h" +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "google/protobuf/generated_message_tctable_decl.h" #include "google/protobuf/generated_message_tctable_impl.h" @@ -2800,6 +2801,138 @@ PROTOBUF_NOINLINE const char* TcParser::MpMap(PROTOBUF_TC_PARAM_DECL) { PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_NO_DATA_PASS); } +std::string TypeCardToString(uint16_t type_card) { + // In here we convert the runtime value of entry.type_card back into a + // sequence of literal enum labels. We use the mnenonic labels for nicer + // codegen. + namespace fl = internal::field_layout; + const int rep_index = (type_card & fl::kRepMask) >> fl::kRepShift; + const int tv_index = (type_card & fl::kTvMask) >> fl::kTvShift; + + static constexpr const char* kFieldCardNames[] = {"Singular", "Optional", + "Repeated", "Oneof"}; + static_assert((fl::kFcSingular >> fl::kFcShift) == 0, ""); + static_assert((fl::kFcOptional >> fl::kFcShift) == 1, ""); + static_assert((fl::kFcRepeated >> fl::kFcShift) == 2, ""); + static_assert((fl::kFcOneof >> fl::kFcShift) == 3, ""); + + std::string out; + + absl::StrAppend(&out, "::_fl::kFc", + kFieldCardNames[(type_card & fl::kFcMask) >> fl::kFcShift]); + +#define PROTOBUF_INTERNAL_TYPE_CARD_CASE(x) \ + case fl::k##x: \ + absl::StrAppend(&out, " | ::_fl::k" #x); \ + break + + switch (type_card & fl::kFkMask) { + case fl::kFkString: { + switch (type_card & ~fl::kFcMask & ~fl::kRepMask & ~fl::kSplitMask) { + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Bytes); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(RawString); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Utf8String); + default: + ABSL_LOG(FATAL) << "Unknown type_card: 0x" << type_card; + } + + static constexpr const char* kRepNames[] = {"AString", "IString", "Cord", + "SPiece", "SString"}; + static_assert((fl::kRepAString >> fl::kRepShift) == 0, ""); + static_assert((fl::kRepIString >> fl::kRepShift) == 1, ""); + static_assert((fl::kRepCord >> fl::kRepShift) == 2, ""); + static_assert((fl::kRepSPiece >> fl::kRepShift) == 3, ""); + static_assert((fl::kRepSString >> fl::kRepShift) == 4, ""); + + absl::StrAppend(&out, " | ::_fl::kRep", kRepNames[rep_index]); + break; + } + + case fl::kFkMessage: { + absl::StrAppend(&out, " | ::_fl::kMessage"); + + static constexpr const char* kRepNames[] = {nullptr, "Group", "Lazy"}; + static_assert((fl::kRepGroup >> fl::kRepShift) == 1, ""); + static_assert((fl::kRepLazy >> fl::kRepShift) == 2, ""); + + if (auto* rep = kRepNames[rep_index]) { + absl::StrAppend(&out, " | ::_fl::kRep", rep); + } + + static constexpr const char* kXFormNames[2][4] = { + {nullptr, "Default", "Table", "WeakPtr"}, {nullptr, "Eager", "Lazy"}}; + + static_assert((fl::kTvDefault >> fl::kTvShift) == 1, ""); + static_assert((fl::kTvTable >> fl::kTvShift) == 2, ""); + static_assert((fl::kTvWeakPtr >> fl::kTvShift) == 3, ""); + static_assert((fl::kTvEager >> fl::kTvShift) == 1, ""); + static_assert((fl::kTvLazy >> fl::kTvShift) == 2, ""); + + if (auto* xform = kXFormNames[rep_index == 2][tv_index]) { + absl::StrAppend(&out, " | ::_fl::kTv", xform); + } + break; + } + + case fl::kFkMap: + absl::StrAppend(&out, " | ::_fl::kMap"); + break; + + case fl::kFkNone: + break; + + case fl::kFkVarint: + case fl::kFkPackedVarint: + case fl::kFkFixed: + case fl::kFkPackedFixed: { + switch (type_card & ~fl::kFcMask & ~fl::kSplitMask) { + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Bool); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Fixed32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(UInt32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(SFixed32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Int32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(SInt32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Float); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Enum); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(EnumRange); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(OpenEnum); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Fixed64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(UInt64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(SFixed64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Int64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(SInt64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(Double); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedBool); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFixed32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedUInt32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSFixed32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedInt32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSInt32); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFloat); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedEnum); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedEnumRange); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedOpenEnum); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFixed64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedUInt64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSFixed64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedInt64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSInt64); + PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedDouble); + default: + ABSL_LOG(FATAL) << "Unknown type_card: 0x" << type_card; + } + } + } + + if (type_card & fl::kSplitMask) { + absl::StrAppend(&out, " | ::_fl::kSplitTrue"); + } + +#undef PROTOBUF_INTERNAL_TYPE_CARD_CASE + + return out; +} + } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/generated_message_tctable_lite_test.cc b/src/google/protobuf/generated_message_tctable_lite_test.cc index d037852b3d..8648712446 100644 --- a/src/google/protobuf/generated_message_tctable_lite_test.cc +++ b/src/google/protobuf/generated_message_tctable_lite_test.cc @@ -20,6 +20,7 @@ namespace internal { namespace { +using ::testing::ElementsAreArray; using ::testing::Eq; using ::testing::Not; using ::testing::Optional; @@ -899,6 +900,7 @@ TEST(GeneratedMessageTctableLiteTest, EXPECT_LE(proto.vals().Capacity(), 2048); } + } // namespace internal } // namespace protobuf } // namespace google From 0f1ab75dbef64ec7508425af59c9ddd584e6aa75 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Mon, 6 Nov 2023 15:51:28 -0800 Subject: [PATCH 100/387] Add empty feature resolution method for FileDescriptor to Java runtime. PiperOrigin-RevId: 579981476 --- .../src/main/java/com/google/protobuf/Descriptors.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java index fb9b661bb0..330cbf3592 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -605,6 +605,15 @@ public final class Descriptors { pool.addSymbol(message); } + /** + * This method is to be called by generated code only. It resolves features for the descriptor + * and all of its children. + * + *

TODO Implement and use this method in gencode once users using prebuilt jars + * with stale runtimes updated. + */ + public void resolveAllFeatures() {} + /** Look up and cross-link all field types, etc. */ private void crossLink() throws DescriptorValidationException { for (final Descriptor messageType : messageTypes) { From f247630a1011db0858be08c4859d83bc65a9f153 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 6 Nov 2023 16:10:42 -0800 Subject: [PATCH 101/387] Add CI coverage for utf8_range We will soon be moving utf8_range into the protobuf repo, not as a subtree anymore but as the real source of truth. This change adds CI coverage in advance so that there will not be a lapse in coverage. I also upgraded our pinned versions of rules_fuzzing and rules_python, to fix some errors that came up with Bazel 6 and Python 3.12. I had to patch rules_fuzzing but I am working on upstreaming the fixes. PiperOrigin-RevId: 579987379 --- .github/workflows/test_cpp.yml | 12 ++++++------ WORKSPACE | 20 +++++++++++++++++--- protobuf_deps.bzl | 12 ++++++------ third_party/BUILD.bazel | 1 + third_party/rules_fuzzing.patch | 25 +++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 third_party/rules_fuzzing.patch diff --git a/.github/workflows/test_cpp.yml b/.github/workflows/test_cpp.yml index 55c061bc1b..58ffdc1916 100644 --- a/.github/workflows/test_cpp.yml +++ b/.github/workflows/test_cpp.yml @@ -27,14 +27,14 @@ jobs: include: # Set defaults - image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:04cd765285bc52cbbf51d66c8c66d8603579cf0f19cc42df26b09d2c270541fb - - targets: //pkg/... //src/... @com_google_protobuf_examples//... + - targets: //pkg/... //src/... @com_google_protobuf_examples//... @utf8_range//... # Override cases with custom images - config: { name: "TCMalloc" } image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/tcmalloc@sha256:bd39119d74b8a3fad4ae335d4cf5294e70384676331b7e19949459fc7a8d8328" - targets: "//src/..." + targets: "//src/... @utf8_range//..." - config: { name: "aarch64" } - targets: "//src/... //src/google/protobuf/compiler:protoc_aarch64_test" + targets: "//src/... //src/google/protobuf/compiler:protoc_aarch64_test @utf8_range//..." image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-63dd26c0c7a808d92673a3e52e848189d4ab0f17" name: Linux ${{ matrix.config.name }} runs-on: ${{ matrix.config.runner || 'ubuntu-latest' }} @@ -69,7 +69,7 @@ jobs: image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:${{ matrix.version }}-6.3.0-63dd26c0c7a808d92673a3e52e848189d4ab0f17 credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: cpp_linux/gcc-${{ matrix.version }} - bazel: test //pkg/... //src/... @com_google_protobuf_examples//... + bazel: test //pkg/... //src/... @com_google_protobuf_examples//... @utf8_range//... linux-release: strategy: @@ -316,13 +316,13 @@ jobs: - name: MacOS os: macos-12 cache_key: macos-12 - bazel: test //src/... + bazel: test //src/... @utf8_range//... - name: MacOS Apple Silicon (build only) os: macos-12 cache_key: macos-12-arm # Current github runners are all Intel based, so just build/compile # for Apple Silicon to detect issues there. - bazel: build --cpu=darwin_arm64 //src/... + bazel: build --cpu=darwin_arm64 //src/... @utf8_range//... - name: Windows os: windows-2022 cache_key: windows-2022 diff --git a/WORKSPACE b/WORKSPACE index 487c9334fc..4dd69d25d2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,6 +17,10 @@ load("//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps") protobuf_deps() +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + # Bazel platform rules. http_archive( name = "platforms", @@ -163,15 +167,25 @@ utf8_range_deps() http_archive( name = "rules_fuzzing", - sha256 = "d9002dd3cd6437017f08593124fdd1b13b3473c7b929ceb0e60d317cb9346118", - strip_prefix = "rules_fuzzing-0.3.2", - urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.3.2.zip"], + sha256 = "ff52ef4845ab00e95d29c02a9e32e9eff4e0a4c9c8a6bcf8407a2f19eb3f9190", + strip_prefix = "rules_fuzzing-0.4.1", + urls = ["https://github.com/bazelbuild/rules_fuzzing/releases/download/v0.4.1/rules_fuzzing-0.4.1.zip"], + patches = ["//third_party:rules_fuzzing.patch"], + patch_args = ["-p1"], ) load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") rules_fuzzing_dependencies() +load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init") + +rules_fuzzing_init() + +load("@fuzzing_py_deps//:requirements.bzl", fuzzing_py_deps_install_deps = "install_deps") + +fuzzing_py_deps_install_deps() + bind( name = "python_headers", actual = "@system_python//:python_headers", diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index d055eed8c6..ed0d73bbbc 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -72,8 +72,8 @@ def protobuf_deps(): _github_archive( name = "utf8_range", repo = "https://github.com/protocolbuffers/utf8_range", - commit = "d863bc33e15cba6d873c878dcca9e6fe52b2f8cb", - sha256 = "568988b5f7261ca181468dba38849fabf59dd9200fb2ed4b2823da187ef84d8c", + commit = "0e378bdb224cc8d4653b0db963b474839c2bb43c", + sha256 = "9b8db33325e5b6105c04369cd04dbbd9186e0577141543714243e66b8f045664", ) if not native.existing_rule("rules_cc"): @@ -102,11 +102,11 @@ def protobuf_deps(): ) if not native.existing_rule("rules_python"): - _github_archive( + http_archive( name = "rules_python", - repo = "https://github.com/bazelbuild/rules_python", - commit = "02b521fce3c7b36b05813aa986d72777cc3ee328", # 0.24.0 - sha256 = "f9e4f6acf82449324d56669bda4bdb28b48688ad2990d8b39fa5b93ed39c9ad1", + sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b", + strip_prefix = "rules_python-0.26.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.26.0/rules_python-0.26.0.tar.gz", ) if not native.existing_rule("rules_ruby"): diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel index d12b3e37f7..35da5c30f8 100644 --- a/third_party/BUILD.bazel +++ b/third_party/BUILD.bazel @@ -1,4 +1,5 @@ exports_files([ "BUILD.bazel", + "rules_fuzzing.patch", "zlib.BUILD", ]) diff --git a/third_party/rules_fuzzing.patch b/third_party/rules_fuzzing.patch new file mode 100644 index 0000000000..b522abb73f --- /dev/null +++ b/third_party/rules_fuzzing.patch @@ -0,0 +1,25 @@ +diff --git a/fuzzing/tools/validate_dict.py b/fuzzing/tools/validate_dict.py +index d561e68..52cbcb8 100644 +--- a/fuzzing/tools/validate_dict.py ++++ b/fuzzing/tools/validate_dict.py +@@ -19,7 +19,7 @@ Validates and merges a set of fuzzing dictionary files into a single output. + + from absl import app + from absl import flags +-from dict_validation import validate_line ++from fuzzing.tools.dict_validation import validate_line + from sys import stderr + + FLAGS = flags.FLAGS +diff --git a/fuzzing/requirements.txt b/fuzzing/requirements.txt +index 01482d4..4b36f4f 100644 +--- a/fuzzing/requirements.txt ++++ b/fuzzing/requirements.txt +@@ -1,5 +1,5 @@ + # Python requirements for the tools supporting the fuzzing rules. These are + # installed automatically through the WORKSPACE configuration. + +-absl-py==0.11.0 --hash=sha256:b3d9eb5119ff6e0a0125f6dabf2f9fae02f8acae7be70576002fac27235611c5 +-six==1.15.0 --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced ++absl-py==2.0.0 --hash=sha256:9a28abb62774ae4e8edbe2dd4c49ffcd45a6a848952a5eccc6a49f3f0fc1e2f3 ++six==1.15.0 From d63a145c7e8721f0de4954323a8c207c5f0c8b1c Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 6 Nov 2023 16:16:33 -0800 Subject: [PATCH 102/387] Allow users to force eager parsing via CodedInputStream::ForceEagerParsing(). PiperOrigin-RevId: 579989063 --- src/google/protobuf/extension_set_heavy.cc | 2 ++ src/google/protobuf/extension_set_unittest.cc | 1 + src/google/protobuf/io/coded_stream.h | 6 ++++++ src/google/protobuf/message_lite.cc | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/extension_set_heavy.cc b/src/google/protobuf/extension_set_heavy.cc index 79d7977ab0..ef3a794809 100644 --- a/src/google/protobuf/extension_set_heavy.cc +++ b/src/google/protobuf/extension_set_heavy.cc @@ -12,6 +12,8 @@ // Contains methods defined in extension_set.h which cannot be part of the // lite library because they use descriptors or reflection. +#include +#include #include #include "absl/log/absl_check.h" diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index df926e7a20..cb969896a5 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -11,6 +11,7 @@ #include "google/protobuf/extension_set.h" +#include #include #include "google/protobuf/descriptor.pb.h" diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index ecb0f2ec57..97d62e4900 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -91,6 +91,7 @@ #include #include #include +#include #include #include #include @@ -522,6 +523,9 @@ class PROTOBUF_EXPORT CodedInputStream { // See EnableAliasing(). bool aliasing_enabled_; + // If true, set eager parsing mode to override lazy fields. + bool force_eager_parsing_; + // Limits Limit current_limit_; // if position = -1, no limit is applied @@ -1553,6 +1557,7 @@ inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input) last_tag_(0), legitimate_message_end_(false), aliasing_enabled_(false), + force_eager_parsing_(false), current_limit_(std::numeric_limits::max()), buffer_size_after_limit_(0), total_bytes_limit_(kDefaultTotalBytesLimit), @@ -1573,6 +1578,7 @@ inline CodedInputStream::CodedInputStream(const uint8_t* buffer, int size) last_tag_(0), legitimate_message_end_(false), aliasing_enabled_(false), + force_eager_parsing_(false), current_limit_(size), buffer_size_after_limit_(0), total_bytes_limit_(kDefaultTotalBytesLimit), diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 36e8597c47..d6a473e0be 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -251,7 +251,7 @@ bool MessageLite::MergeFromImpl(io::CodedInputStream* input, if (PROTOBUF_PREDICT_FALSE(!ptr)) return false; ctx.BackUp(ptr); if (!ctx.EndedAtEndOfStream()) { - ABSL_DCHECK_NE(ctx.LastTag(), 1); // We can't end on a pushed limit. + ABSL_DCHECK_NE(ctx.LastTag(), 1u); // We can't end on a pushed limit. if (ctx.IsExceedingLimit(ptr)) return false; input->SetLastTag(ctx.LastTag()); } else { From a2eda0427b79501ac68cf4629acc4359bc4b7358 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 05:16:25 -0800 Subject: [PATCH 103/387] Enable the mutable oneof accessor. PiperOrigin-RevId: 580142622 --- rust/test/shared/accessors_proto3_test.rs | 34 ++++++++++++++++++++++ rust/test/shared/accessors_test.rs | 34 ++++++++++++++++++++++ src/google/protobuf/compiler/rust/oneof.cc | 21 +++++++++---- 3 files changed, 84 insertions(+), 5 deletions(-) diff --git a/rust/test/shared/accessors_proto3_test.rs b/rust/test/shared/accessors_proto3_test.rs index 3eb6e5df61..8800a097a9 100644 --- a/rust/test/shared/accessors_proto3_test.rs +++ b/rust/test/shared/accessors_proto3_test.rs @@ -205,3 +205,37 @@ fn test_oneof_accessors() { assert_that!(msg.oneof_field(), matches_pattern!(OneofBytes(eq(b"123")))); } + +#[test] +fn test_oneof_mut_accessors() { + use TestAllTypes_::OneofFieldMut::*; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.oneof_field_mut(), matches_pattern!(not_set(_))); + + msg.oneof_uint32_set(Some(7)); + + match msg.oneof_field_mut() { + OneofUint32(mut v) => { + assert_eq!(v.get(), 7); + v.set(8); + assert_eq!(v.get(), 8); + } + f => panic!("unexpected field_mut type! {:?}", f), + } + + // Confirm that the mut write above applies to both the field accessor and the + // oneof view accessor. + assert_that!(msg.oneof_uint32_opt(), eq(Optional::Set(8))); + assert_that!( + msg.oneof_field(), + matches_pattern!(TestAllTypes_::OneofField::OneofUint32(eq(8))) + ); + + msg.oneof_uint32_set(None); + assert_that!(msg.oneof_field_mut(), matches_pattern!(not_set(_))); + + msg.oneof_uint32_set(Some(7)); + msg.oneof_bytes_mut().set(b"123"); + assert_that!(msg.oneof_field_mut(), matches_pattern!(OneofBytes(_))); +} diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 2b207ac11c..e5949fffab 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -696,6 +696,40 @@ fn test_oneof_accessors() { assert_that!(msg.oneof_field(), matches_pattern!(OneofBytes(eq(b"123")))); } +#[test] +fn test_oneof_mut_accessors() { + use TestAllTypes_::OneofFieldMut::*; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.oneof_field_mut(), matches_pattern!(not_set(_))); + + msg.oneof_uint32_set(Some(7)); + + match msg.oneof_field_mut() { + OneofUint32(mut v) => { + assert_eq!(v.get(), 7); + v.set(8); + assert_eq!(v.get(), 8); + } + f => panic!("unexpected field_mut type! {:?}", f), + } + + // Confirm that the mut write above applies to both the field accessor and the + // oneof view accessor. + assert_that!(msg.oneof_uint32_opt(), eq(Optional::Set(8))); + assert_that!( + msg.oneof_field(), + matches_pattern!(TestAllTypes_::OneofField::OneofUint32(eq(8))) + ); + + msg.oneof_uint32_set(None); + assert_that!(msg.oneof_field_mut(), matches_pattern!(not_set(_))); + + msg.oneof_uint32_set(Some(7)); + msg.oneof_bytes_mut().set(b"123"); + assert_that!(msg.oneof_field_mut(), matches_pattern!(OneofBytes(_))); +} + macro_rules! generate_repeated_numeric_test { ($(($t: ty, $field: ident)),*) => { paste! { $( diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 33836a02f9..7f2671d7ea 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -246,15 +246,26 @@ void GenerateOneofAccessors(Context oneof) { if (rs_type.empty()) { continue; } - // TODO: Allow mut. - /*oneof.Emit({ + oneof.Emit( + { {"case", ToCamelCase(field->name())}, - {"rs_getter", field->name() + "_mut"}, + {"rs_mut_getter", field->name() + "_mut"}, {"type", rs_type}, }, + + // The flow here is: + // 1) First find out which oneof field is already set (if any) + // 2) If a field is set, call the corresponding field's _mut() + // and wrap that Mut<> in the SomeOneofMut eum. + // During step 2 this code uses try_into_mut().unwrap() instead + // of .or_default() so that it will panic if step 1 says that + // the field is set, but then the _mut() accessor for the + // corresponding field shows as unset; if that happened it would + // imply a severe error in protobuf code; .or_default() would + // silently continue and cause the field to become set on the + // message, which is not the intended behavior. R"rs($Msg$_::$case_enum_name$::$case$ => - $Msg$_::$mut_enum_name$::$case$(self.$rs_getter$()), )rs"); - */ + $Msg$_::$mut_enum_name$::$case$(self.$rs_mut_getter$().try_into_mut().unwrap()), )rs"); } }}, {"case_thunk", Thunk(oneof, "case")}}, From 66ee906904a330c9d70fb6c2c0e8bad78760baea Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 06:25:32 -0800 Subject: [PATCH 104/387] Add initial fuzz test to upb's json encode/decode. Unlike the wire fuzz test this only fuzzes json against a fixed message; in a subsequent improvement it can additionally fuzz over the message def itself. PiperOrigin-RevId: 580158012 --- upb/json/BUILD | 24 +++++++++++++++++ upb/json/decode.c | 35 ++++++++++++++++++++++--- upb/json/fuzz_test.cc | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 upb/json/fuzz_test.cc diff --git a/upb/json/BUILD b/upb/json/BUILD index b560854f50..29ce7ae538 100644 --- a/upb/json/BUILD +++ b/upb/json/BUILD @@ -20,8 +20,12 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + "//upb:base", "//upb:lex", + "//upb:mem", "//upb:message", + "//upb:message_types", + "//upb:mini_table", "//upb:port", "//upb:reflection", "//upb:wire", @@ -82,3 +86,23 @@ upb_c_proto_library( testonly = 1, deps = ["//:struct_proto"], ) + +# begin:google_only +# cc_test( +# name = "fuzz_test", +# srcs = ["fuzz_test.cc"], +# deps = [ +# ":json", +# ":test_upb_proto", +# ":test_upb_proto_reflection", +# "@com_google_googletest//:gtest_main", +# "//testing/fuzzing:fuzztest", +# "//upb:base", +# "//upb:mem", +# "//upb:message", +# "//upb:message_types", +# "//upb:mini_table", +# "//upb:reflection", +# ], +# ) +# end:google_only diff --git a/upb/json/decode.c b/upb/json/decode.c index 5b7fc3d9f4..683a721a50 100644 --- a/upb/json/decode.c +++ b/upb/json/decode.c @@ -35,12 +35,25 @@ #include #include #include +#include +#include +#include +#include #include #include +#include "upb/base/descriptor_constants.h" +#include "upb/base/status.h" +#include "upb/base/string_view.h" #include "upb/lex/atoi.h" #include "upb/lex/unicode.h" +#include "upb/mem/arena.h" +#include "upb/message/array.h" #include "upb/message/map.h" +#include "upb/message/message.h" +#include "upb/message/types.h" +#include "upb/mini_table/message.h" +#include "upb/reflection/def.h" #include "upb/reflection/message.h" #include "upb/wire/encode.h" @@ -157,6 +170,10 @@ static void jsondec_entrysep(jsondec* d) { } static int jsondec_rawpeek(jsondec* d) { + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); + } + switch (*d->ptr) { case '{': return JD_OBJECT; @@ -272,7 +289,7 @@ static void jsondec_skipdigits(jsondec* d) { static double jsondec_number(jsondec* d) { const char* start = d->ptr; - assert(jsondec_rawpeek(d) == JD_NUMBER); + UPB_ASSERT(jsondec_rawpeek(d) == JD_NUMBER); /* Skip over the syntax of a number, as specified by JSON. */ if (*d->ptr == '-') d->ptr++; @@ -307,9 +324,19 @@ parse: * (strtod() accepts a superset of JSON syntax). */ errno = 0; { + // Copy the number into a null-terminated scratch buffer since strtod + // expects a null-terminated string. + char nullz[64]; + ptrdiff_t len = d->ptr - start; + if (len > (ptrdiff_t)(sizeof(nullz) - 1)) { + jsondec_err(d, "excessively long number"); + } + memcpy(nullz, start, len); + nullz[len] = '\0'; + char* end; - double val = strtod(start, &end); - assert(end == d->ptr); + double val = strtod(nullz, &end); + UPB_ASSERT(end - nullz == len); /* Currently the min/max-val conformance tests fail if we check this. Does * this mean the conformance tests are wrong or strtod() is wrong, or @@ -450,7 +477,7 @@ static upb_StringView jsondec_string(jsondec* d) { } break; default: - if ((unsigned char)*d->ptr < 0x20) { + if ((unsigned char)ch < 0x20) { jsondec_err(d, "Invalid char in JSON string"); } *end++ = ch; diff --git a/upb/json/fuzz_test.cc b/upb/json/fuzz_test.cc new file mode 100644 index 0000000000..381c8ebad3 --- /dev/null +++ b/upb/json/fuzz_test.cc @@ -0,0 +1,61 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#include +#include +#include + +#include +#include "testing/fuzzing/fuzztest.h" +#include "upb/base/status.hpp" +#include "upb/json/decode.h" +#include "upb/json/encode.h" +#include "upb/json/test.upb.h" +#include "upb/json/test.upbdefs.h" +#include "upb/mem/arena.h" +#include "upb/mem/arena.hpp" +#include "upb/reflection/def.hpp" + +namespace { + +void DecodeEncodeArbitraryJson(std::string_view json) { + upb::Arena arena; + upb::Status status; + + // Copy the input string to the heap. This helps asan reproduce issues that + // don't reproduce when passing static memory pointers. See b/309107518. + auto* json_heap = new char[json.size()]; + memcpy(json_heap, json.data(), json.size()); + + upb::DefPool defpool; + upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr())); + EXPECT_TRUE(m.ptr() != nullptr); + + upb_test_Box* box = upb_test_Box_new(arena.ptr()); + int options = 0; + bool ok = upb_JsonDecode(json_heap, json.size(), box, m.ptr(), defpool.ptr(), + options, arena.ptr(), status.ptr()); + delete[] json_heap; + if (!ok) return; + + size_t size = upb_JsonEncode(box, m.ptr(), defpool.ptr(), options, nullptr, 0, + status.ptr()); + char* json_buf = (char*)upb_Arena_Malloc(arena.ptr(), size + 1); + + size_t written = upb_JsonEncode(box, m.ptr(), defpool.ptr(), options, + json_buf, size + 1, status.ptr()); + EXPECT_EQ(written, size); +} +FUZZ_TEST(FuzzTest, DecodeEncodeArbitraryJson); + +TEST(FuzzTest, UnclosedObjectKey) { DecodeEncodeArbitraryJson("{\" "); } + +TEST(FuzzTest, MalformedExponent) { + DecodeEncodeArbitraryJson(R"({"val":0XE$})"); +} + +} // namespace From 75b9030c797e4b10199842c298f80368d585c0b8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 14:38:26 +0000 Subject: [PATCH 105/387] Auto-generate files after cl/580158012 --- php/ext/google/protobuf/php-upb.c | 26 ++++++++++++++++++++++---- ruby/ext/google/protobuf_c/ruby-upb.c | 26 ++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index f20fc800d8..4225aa3a7d 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -3064,6 +3064,10 @@ void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v) { #include #include #include +#include +#include +#include +#include #include #include @@ -3180,6 +3184,10 @@ static void jsondec_entrysep(jsondec* d) { } static int jsondec_rawpeek(jsondec* d) { + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); + } + switch (*d->ptr) { case '{': return JD_OBJECT; @@ -3295,7 +3303,7 @@ static void jsondec_skipdigits(jsondec* d) { static double jsondec_number(jsondec* d) { const char* start = d->ptr; - assert(jsondec_rawpeek(d) == JD_NUMBER); + UPB_ASSERT(jsondec_rawpeek(d) == JD_NUMBER); /* Skip over the syntax of a number, as specified by JSON. */ if (*d->ptr == '-') d->ptr++; @@ -3330,9 +3338,19 @@ parse: * (strtod() accepts a superset of JSON syntax). */ errno = 0; { + // Copy the number into a null-terminated scratch buffer since strtod + // expects a null-terminated string. + char nullz[64]; + ptrdiff_t len = d->ptr - start; + if (len > (ptrdiff_t)(sizeof(nullz) - 1)) { + jsondec_err(d, "excessively long number"); + } + memcpy(nullz, start, len); + nullz[len] = '\0'; + char* end; - double val = strtod(start, &end); - assert(end == d->ptr); + double val = strtod(nullz, &end); + UPB_ASSERT(end - nullz == len); /* Currently the min/max-val conformance tests fail if we check this. Does * this mean the conformance tests are wrong or strtod() is wrong, or @@ -3473,7 +3491,7 @@ static upb_StringView jsondec_string(jsondec* d) { } break; default: - if ((unsigned char)*d->ptr < 0x20) { + if ((unsigned char)ch < 0x20) { jsondec_err(d, "Invalid char in JSON string"); } *end++ = ch; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 332aaea4e5..998f4c0891 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -2579,6 +2579,10 @@ void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v) { #include #include #include +#include +#include +#include +#include #include #include @@ -2695,6 +2699,10 @@ static void jsondec_entrysep(jsondec* d) { } static int jsondec_rawpeek(jsondec* d) { + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); + } + switch (*d->ptr) { case '{': return JD_OBJECT; @@ -2810,7 +2818,7 @@ static void jsondec_skipdigits(jsondec* d) { static double jsondec_number(jsondec* d) { const char* start = d->ptr; - assert(jsondec_rawpeek(d) == JD_NUMBER); + UPB_ASSERT(jsondec_rawpeek(d) == JD_NUMBER); /* Skip over the syntax of a number, as specified by JSON. */ if (*d->ptr == '-') d->ptr++; @@ -2845,9 +2853,19 @@ parse: * (strtod() accepts a superset of JSON syntax). */ errno = 0; { + // Copy the number into a null-terminated scratch buffer since strtod + // expects a null-terminated string. + char nullz[64]; + ptrdiff_t len = d->ptr - start; + if (len > (ptrdiff_t)(sizeof(nullz) - 1)) { + jsondec_err(d, "excessively long number"); + } + memcpy(nullz, start, len); + nullz[len] = '\0'; + char* end; - double val = strtod(start, &end); - assert(end == d->ptr); + double val = strtod(nullz, &end); + UPB_ASSERT(end - nullz == len); /* Currently the min/max-val conformance tests fail if we check this. Does * this mean the conformance tests are wrong or strtod() is wrong, or @@ -2988,7 +3006,7 @@ static upb_StringView jsondec_string(jsondec* d) { } break; default: - if ((unsigned char)*d->ptr < 0x20) { + if ((unsigned char)ch < 0x20) { jsondec_err(d, "Invalid char in JSON string"); } *end++ = ch; From 6404e55d6dc0cb601a095ab5b305d55f23fa35fb Mon Sep 17 00:00:00 2001 From: Martijn Vels Date: Tue, 7 Nov 2023 07:14:54 -0800 Subject: [PATCH 106/387] Automated rollback of commit 022d223488c0807e11d1c2509123901f5cc6b0b6. PiperOrigin-RevId: 580169349 --- src/google/protobuf/compiler/cpp/field.cc | 4 + src/google/protobuf/compiler/cpp/field.h | 16 ++ .../cpp/field_generators/message_field.cc | 27 ++- src/google/protobuf/compiler/cpp/message.cc | 14 ++ src/google/protobuf/compiler/cpp/message.h | 5 + src/google/protobuf/compiler/plugin.pb.cc | 20 +- src/google/protobuf/descriptor.pb.cc | 199 ++++++++++++++---- 7 files changed, 240 insertions(+), 45 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index e9ccf46bbd..d2fee868e1 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -263,6 +263,7 @@ void HasBitVars(const FieldDescriptor* field, const Options& opts, absl::optional idx, std::vector& vars) { if (!idx.has_value()) { vars.emplace_back("set_hasbit", ""); + vars.emplace_back("this_set_hasbit", ""); vars.emplace_back("clear_hasbit", ""); return; } @@ -283,6 +284,9 @@ void HasBitVars(const FieldDescriptor* field, const Options& opts, vars.emplace_back("has_hasbit", has); vars.emplace_back(Sub("set_hasbit", set).WithSuffix(";")); vars.emplace_back(Sub("clear_hasbit", clr).WithSuffix(";")); + + set = absl::StrFormat("_this->%s[%d] |= %s;", has_bits, index, mask); + vars.emplace_back(Sub("this_set_hasbit", set).WithSuffix(";")); } void InlinedStringVars(const FieldDescriptor* field, const Options& opts, diff --git a/src/google/protobuf/compiler/cpp/field.h b/src/google/protobuf/compiler/cpp/field.h index 1bba5f27b5..d24d816d81 100644 --- a/src/google/protobuf/compiler/cpp/field.h +++ b/src/google/protobuf/compiler/cpp/field.h @@ -39,6 +39,11 @@ namespace cpp { // matter of clean composability. class FieldGeneratorBase { public: + // `GeneratorFunction` defines a subset of generator functions that may have + // additional optimizations or requirements such as 'uses a local `arena` + // variable instead of calling GetArena()' + enum class GeneratorFunction { kMergeFrom }; + FieldGeneratorBase(const FieldDescriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer); @@ -100,6 +105,10 @@ class FieldGeneratorBase { return has_default_constexpr_constructor_; } + // Returns true if this generator requires an 'arena' parameter on the + // given generator function. + virtual bool RequiresArena(GeneratorFunction) const { return false; } + virtual std::vector MakeVars() const { return {}; } virtual void GeneratePrivateMembers(io::Printer* p) const = 0; @@ -230,6 +239,8 @@ class FieldGenerator { } public: + using GeneratorFunction = FieldGeneratorBase::GeneratorFunction; + FieldGenerator(const FieldGenerator&) = delete; FieldGenerator& operator=(const FieldGenerator&) = delete; FieldGenerator(FieldGenerator&&) = default; @@ -256,6 +267,11 @@ class FieldGenerator { return impl_->has_default_constexpr_constructor(); } + // Requirements: see FieldGeneratorBase for documentation + bool RequiresArena(GeneratorFunction function) const { + return impl_->RequiresArena(function); + } + // Prints private members needed to represent this field. // // These are placed inside the class definition. diff --git a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc index 34c7733eac..83d2a21637 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc @@ -102,6 +102,8 @@ class SingularMessage : public FieldGeneratorBase { )cc"); } + bool RequiresArena(GeneratorFunction function) const override; + void GenerateNonInlineAccessorDefinitions(io::Printer* p) const override {} void GenerateAccessorDeclarations(io::Printer* p) const override; @@ -415,15 +417,38 @@ void SingularMessage::GenerateMessageClearingCode(io::Printer* p) const { } } +bool SingularMessage::RequiresArena(GeneratorFunction function) const { + switch (function) { + case GeneratorFunction::kMergeFrom: + return !(is_weak() || is_oneof() || should_split()); + } + return false; +} + void SingularMessage::GenerateMergingCode(io::Printer* p) const { if (is_weak()) { p->Emit( "_Internal::mutable_$name$(_this)->CheckTypeAndMergeFrom(\n" " _Internal::$name$(&from));\n"); - } else { + } else if (is_oneof() || should_split()) { p->Emit( "_this->_internal_mutable_$name$()->$Submsg$::MergeFrom(\n" " from._internal_$name$());\n"); + } else { + // Important: we set `hasbits` after we copied the field. There are cases + // where people assign root values to child values or vice versa which + // are not always checked, so we delay this change becoming 'visibile' + // until after we copied the message. + // TODO enforces this as undefined behavior in debug builds. + p->Emit(R"cc( + $DCHK$(from.$field_$ != nullptr); + if (_this->$field_$ == nullptr) { + _this->$field_$ = CreateMaybeMessage<$Submsg$>(arena, *from.$field_$); + } else { + _this->$field_$->MergeFrom(*from.$field_$); + } + $this_set_hasbit$; + )cc"); } } diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 59d7c1e8f9..8dfff78caa 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -3488,6 +3488,15 @@ void MessageGenerator::GenerateMergeFrom(io::Printer* p) { } } +bool MessageGenerator::RequiresArena(GeneratorFunction function) const { + for (const FieldDescriptor* field : FieldRange(descriptor_)) { + if (field_generators_.get(field).RequiresArena(function)) { + return true; + } + } + return false; +} + void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { if (HasSimpleBaseClass(descriptor_, options_)) return; // Generate the class-specific MergeFrom, which avoids the ABSL_CHECK and @@ -3507,6 +3516,11 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { " auto& from = static_cast(from_msg);\n"); } format.Indent(); + if (RequiresArena(GeneratorFunction::kMergeFrom)) { + p->Emit(R"cc( + ::$proto_ns$::Arena* arena = _this->GetArena(); + )cc"); + } format( "$annotate_mergefrom$" "// @@protoc_insertion_point(class_specific_merge_from_start:" diff --git a/src/google/protobuf/compiler/cpp/message.h b/src/google/protobuf/compiler/cpp/message.h index 4c404adcb9..e62bce2797 100644 --- a/src/google/protobuf/compiler/cpp/message.h +++ b/src/google/protobuf/compiler/cpp/message.h @@ -80,6 +80,7 @@ class MessageGenerator { const Descriptor* descriptor() const { return descriptor_; } private: + using GeneratorFunction = FieldGeneratorBase::GeneratorFunction; enum class InitType { kConstexpr, kArena, kArenaCopy }; // Generate declarations and definitions of accessors for fields. @@ -148,6 +149,10 @@ class MessageGenerator { void GenerateFieldClear(const FieldDescriptor* field, bool is_inline, io::Printer* p); + // Returns true if any of the fields needs an `arena` variable containing + // the current message's arena, reducing `GetArena()` call churn. + bool RequiresArena(GeneratorFunction function) const; + // Returns whether impl_ has a copy ctor. bool ImplHasCopyCtor() const; diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index d16ebb9888..dc37bd6e68 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -903,6 +903,7 @@ const ::_pbi::TcParseTable<3, 5, 3, 79, 2> CodeGeneratorRequest::_table_ = { void CodeGeneratorRequest::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -919,8 +920,13 @@ void CodeGeneratorRequest::MergeImpl(::google::protobuf::Message& to_msg, const _this->_internal_set_parameter(from._internal_parameter()); } if (cached_has_bits & 0x00000002u) { - _this->_internal_mutable_compiler_version()->::google::protobuf::compiler::Version::MergeFrom( - from._internal_compiler_version()); + ABSL_DCHECK(from._impl_.compiler_version_ != nullptr); + if (_this->_impl_.compiler_version_ == nullptr) { + _this->_impl_.compiler_version_ = CreateMaybeMessage<::google::protobuf::compiler::Version>(arena, *from._impl_.compiler_version_); + } else { + _this->_impl_.compiler_version_->MergeFrom(*from._impl_.compiler_version_); + } + _this->_impl_._has_bits_[0] |= 0x00000002u; } } _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); @@ -1233,6 +1239,7 @@ const ::_pbi::TcParseTable<2, 4, 1, 86, 2> CodeGeneratorResponse_File::_table_ = void CodeGeneratorResponse_File::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -1250,8 +1257,13 @@ void CodeGeneratorResponse_File::MergeImpl(::google::protobuf::Message& to_msg, _this->_internal_set_content(from._internal_content()); } if (cached_has_bits & 0x00000008u) { - _this->_internal_mutable_generated_code_info()->::google::protobuf::GeneratedCodeInfo::MergeFrom( - from._internal_generated_code_info()); + ABSL_DCHECK(from._impl_.generated_code_info_ != nullptr); + if (_this->_impl_.generated_code_info_ == nullptr) { + _this->_impl_.generated_code_info_ = CreateMaybeMessage<::google::protobuf::GeneratedCodeInfo>(arena, *from._impl_.generated_code_info_); + } else { + _this->_impl_.generated_code_info_->MergeFrom(*from._impl_.generated_code_info_); + } + _this->_impl_._has_bits_[0] |= 0x00000008u; } } _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index e690ce6cad..a9006879bf 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -3041,6 +3041,7 @@ constexpr ::_pbi::TcParseTable<4, 13, 7, 79, 2> FileDescriptorProto::_table_ = { void FileDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorProto) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -3069,12 +3070,22 @@ void FileDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const : _this->_internal_set_syntax(from._internal_syntax()); } if (cached_has_bits & 0x00000008u) { - _this->_internal_mutable_options()->::google::protobuf::FileOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::FileOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000008u; } if (cached_has_bits & 0x00000010u) { - _this->_internal_mutable_source_code_info()->::google::protobuf::SourceCodeInfo::MergeFrom( - from._internal_source_code_info()); + ABSL_DCHECK(from._impl_.source_code_info_ != nullptr); + if (_this->_impl_.source_code_info_ == nullptr) { + _this->_impl_.source_code_info_ = CreateMaybeMessage<::google::protobuf::SourceCodeInfo>(arena, *from._impl_.source_code_info_); + } else { + _this->_impl_.source_code_info_->MergeFrom(*from._impl_.source_code_info_); + } + _this->_impl_._has_bits_[0] |= 0x00000010u; } if (cached_has_bits & 0x00000020u) { _this->_impl_.edition_ = from._impl_.edition_; @@ -3371,6 +3382,7 @@ constexpr ::_pbi::TcParseTable<2, 3, 1, 0, 2> DescriptorProto_ExtensionRange::_t void DescriptorProto_ExtensionRange::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -3379,8 +3391,13 @@ void DescriptorProto_ExtensionRange::MergeImpl(::google::protobuf::Message& to_m cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000007u) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_options()->::google::protobuf::ExtensionRangeOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::ExtensionRangeOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.start_ = from._impl_.start_; @@ -4056,6 +4073,7 @@ constexpr ::_pbi::TcParseTable<4, 10, 8, 65, 2> DescriptorProto::_table_ = { void DescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -4082,8 +4100,13 @@ void DescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::goo _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _this->_internal_mutable_options()->::google::protobuf::MessageOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::MessageOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000002u; } } _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); @@ -4748,6 +4771,7 @@ constexpr ::_pbi::TcParseTable<3, 4, 4, 0, 12> ExtensionRangeOptions::_table_ = void ExtensionRangeOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ExtensionRangeOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -4760,8 +4784,13 @@ void ExtensionRangeOptions::MergeImpl(::google::protobuf::Message& to_msg, const cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.verification_ = from._impl_.verification_; @@ -5279,6 +5308,7 @@ constexpr ::_pbi::TcParseTable<4, 11, 3, 96, 2> FieldDescriptorProto::_table_ = void FieldDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldDescriptorProto) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -5302,8 +5332,13 @@ void FieldDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const _this->_internal_set_json_name(from._internal_json_name()); } if (cached_has_bits & 0x00000020u) { - _this->_internal_mutable_options()->::google::protobuf::FieldOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::FieldOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000020u; } if (cached_has_bits & 0x00000040u) { _this->_impl_.number_ = from._impl_.number_; @@ -5574,6 +5609,7 @@ constexpr ::_pbi::TcParseTable<1, 2, 1, 49, 2> OneofDescriptorProto::_table_ = { void OneofDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofDescriptorProto) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -5585,8 +5621,13 @@ void OneofDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _this->_internal_mutable_options()->::google::protobuf::OneofOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::OneofOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000002u; } } _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); @@ -6130,6 +6171,7 @@ constexpr ::_pbi::TcParseTable<3, 5, 3, 61, 2> EnumDescriptorProto::_table_ = { void EnumDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -6146,8 +6188,13 @@ void EnumDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const : _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _this->_internal_mutable_options()->::google::protobuf::EnumOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::EnumOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000002u; } } _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); @@ -6425,6 +6472,7 @@ constexpr ::_pbi::TcParseTable<2, 3, 1, 53, 2> EnumValueDescriptorProto::_table_ void EnumValueDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueDescriptorProto) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -6436,8 +6484,13 @@ void EnumValueDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, co _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _this->_internal_mutable_options()->::google::protobuf::EnumValueOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::EnumValueOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000002u; } if (cached_has_bits & 0x00000004u) { _this->_impl_.number_ = from._impl_.number_; @@ -6714,6 +6767,7 @@ constexpr ::_pbi::TcParseTable<2, 3, 2, 51, 2> ServiceDescriptorProto::_table_ = void ServiceDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceDescriptorProto) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -6727,8 +6781,13 @@ void ServiceDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, cons _this->_internal_set_name(from._internal_name()); } if (cached_has_bits & 0x00000002u) { - _this->_internal_mutable_options()->::google::protobuf::ServiceOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::ServiceOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000002u; } } _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); @@ -7093,6 +7152,7 @@ constexpr ::_pbi::TcParseTable<3, 6, 1, 71, 2> MethodDescriptorProto::_table_ = void MethodDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodDescriptorProto) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -7110,8 +7170,13 @@ void MethodDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const _this->_internal_set_output_type(from._internal_output_type()); } if (cached_has_bits & 0x00000008u) { - _this->_internal_mutable_options()->::google::protobuf::MethodOptions::MergeFrom( - from._internal_options()); + ABSL_DCHECK(from._impl_.options_ != nullptr); + if (_this->_impl_.options_ == nullptr) { + _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::MethodOptions>(arena, *from._impl_.options_); + } else { + _this->_impl_.options_->MergeFrom(*from._impl_.options_); + } + _this->_impl_._has_bits_[0] |= 0x00000008u; } if (cached_has_bits & 0x00000010u) { _this->_impl_.client_streaming_ = from._impl_.client_streaming_; @@ -7920,6 +7985,7 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { void FileOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -7962,8 +8028,13 @@ void FileOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google: _this->_internal_set_ruby_package(from._internal_ruby_package()); } if (cached_has_bits & 0x00000400u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000400u; } if (cached_has_bits & 0x00000800u) { _this->_impl_.java_multiple_files_ = from._impl_.java_multiple_files_; @@ -8382,6 +8453,7 @@ constexpr ::_pbi::TcParseTable<3, 7, 2, 0, 7> MessageOptions::_table_ = { void MessageOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MessageOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -8392,8 +8464,13 @@ void MessageOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::goog cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000003fu) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.message_set_wire_format_ = from._impl_.message_set_wire_format_; @@ -9172,6 +9249,7 @@ constexpr ::_pbi::TcParseTable<4, 13, 7, 0, 7> FieldOptions::_table_ = { void FieldOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -9185,8 +9263,13 @@ void FieldOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x000000ffu) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.ctype_ = from._impl_.ctype_; @@ -9473,6 +9556,7 @@ constexpr ::_pbi::TcParseTable<2, 2, 2, 0, 7> OneofOptions::_table_ = { void OneofOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -9481,8 +9565,13 @@ void OneofOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google _this->_internal_mutable_uninterpreted_option()->MergeFrom( from._internal_uninterpreted_option()); if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } _this->_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_); _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); @@ -9809,6 +9898,7 @@ constexpr ::_pbi::TcParseTable<3, 5, 2, 0, 7> EnumOptions::_table_ = { void EnumOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -9819,8 +9909,13 @@ void EnumOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google: cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x0000000fu) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.allow_alias_ = from._impl_.allow_alias_; @@ -10145,6 +10240,7 @@ constexpr ::_pbi::TcParseTable<3, 4, 2, 0, 7> EnumValueOptions::_table_ = { void EnumValueOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -10155,8 +10251,13 @@ void EnumValueOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::go cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000007u) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.deprecated_ = from._impl_.deprecated_; @@ -10447,6 +10548,7 @@ constexpr ::_pbi::TcParseTable<2, 3, 2, 0, 12> ServiceOptions::_table_ = { void ServiceOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -10457,8 +10559,13 @@ void ServiceOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::goog cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.deprecated_ = from._impl_.deprecated_; @@ -10782,6 +10889,7 @@ constexpr ::_pbi::TcParseTable<3, 4, 3, 0, 12> MethodOptions::_table_ = { void MethodOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodOptions) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -10792,8 +10900,13 @@ void MethodOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::googl cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000007u) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.deprecated_ = from._impl_.deprecated_; @@ -12064,6 +12177,7 @@ constexpr ::_pbi::TcParseTable<1, 2, 2, 0, 2> FeatureSetDefaults_FeatureSetEditi void FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -12072,8 +12186,13 @@ void FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl(::google::protobuf:: cached_has_bits = from._impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { if (cached_has_bits & 0x00000001u) { - _this->_internal_mutable_features()->::google::protobuf::FeatureSet::MergeFrom( - from._internal_features()); + ABSL_DCHECK(from._impl_.features_ != nullptr); + if (_this->_impl_.features_ == nullptr) { + _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + } else { + _this->_impl_.features_->MergeFrom(*from._impl_.features_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (cached_has_bits & 0x00000002u) { _this->_impl_.edition_ = from._impl_.edition_; From 9118b9084aeac6a5a00c341e0493d3a6d09cc36e Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 15:28:54 +0000 Subject: [PATCH 107/387] Auto-generate files after cl/580169349 --- src/google/protobuf/api.pb.cc | 10 ++++++++-- src/google/protobuf/type.pb.cc | 30 ++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index afcad3de14..a38ddbaa58 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -575,6 +575,7 @@ const ::_pbi::TcParseTable<3, 7, 4, 39, 2> Api::_table_ = { void Api::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -593,8 +594,13 @@ void Api::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobu _this->_internal_set_version(from._internal_version()); } if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { - _this->_internal_mutable_source_context()->::google::protobuf::SourceContext::MergeFrom( - from._internal_source_context()); + ABSL_DCHECK(from._impl_.source_context_ != nullptr); + if (_this->_impl_.source_context_ == nullptr) { + _this->_impl_.source_context_ = CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); + } else { + _this->_impl_.source_context_->MergeFrom(*from._impl_.source_context_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (from._internal_syntax() != 0) { _this->_internal_set_syntax(from._internal_syntax()); diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 18a1f3946e..4ae35c5542 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -755,6 +755,7 @@ const ::_pbi::TcParseTable<3, 7, 3, 46, 2> Type::_table_ = { void Type::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -772,8 +773,13 @@ void Type::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protob _this->_internal_set_edition(from._internal_edition()); } if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { - _this->_internal_mutable_source_context()->::google::protobuf::SourceContext::MergeFrom( - from._internal_source_context()); + ABSL_DCHECK(from._impl_.source_context_ != nullptr); + if (_this->_impl_.source_context_ == nullptr) { + _this->_impl_.source_context_ = CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); + } else { + _this->_impl_.source_context_->MergeFrom(*from._impl_.source_context_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (from._internal_syntax() != 0) { _this->_internal_set_syntax(from._internal_syntax()); @@ -1563,6 +1569,7 @@ const ::_pbi::TcParseTable<3, 6, 3, 40, 2> Enum::_table_ = { void Enum::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -1579,8 +1586,13 @@ void Enum::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protob _this->_internal_set_edition(from._internal_edition()); } if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { - _this->_internal_mutable_source_context()->::google::protobuf::SourceContext::MergeFrom( - from._internal_source_context()); + ABSL_DCHECK(from._impl_.source_context_ != nullptr); + if (_this->_impl_.source_context_ == nullptr) { + _this->_impl_.source_context_ = CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); + } else { + _this->_impl_.source_context_->MergeFrom(*from._impl_.source_context_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } if (from._internal_syntax() != 0) { _this->_internal_set_syntax(from._internal_syntax()); @@ -2071,6 +2083,7 @@ const ::_pbi::TcParseTable<1, 2, 1, 35, 2> Option::_table_ = { void Option::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); + ::google::protobuf::Arena* arena = _this->GetArena(); // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Option) ABSL_DCHECK_NE(&from, _this); ::uint32_t cached_has_bits = 0; @@ -2080,8 +2093,13 @@ void Option::MergeImpl(::google::protobuf::Message& to_msg, const ::google::prot _this->_internal_set_name(from._internal_name()); } if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { - _this->_internal_mutable_value()->::google::protobuf::Any::MergeFrom( - from._internal_value()); + ABSL_DCHECK(from._impl_.value_ != nullptr); + if (_this->_impl_.value_ == nullptr) { + _this->_impl_.value_ = CreateMaybeMessage<::google::protobuf::Any>(arena, *from._impl_.value_); + } else { + _this->_impl_.value_->MergeFrom(*from._impl_.value_); + } + _this->_impl_._has_bits_[0] |= 0x00000001u; } _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); } From 9ac3548fa9adc3cbc6861d91f09d9913ec7facce Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Tue, 7 Nov 2023 09:05:28 -0800 Subject: [PATCH 108/387] Clean up trailing whitespace in defs.bzl PiperOrigin-RevId: 580198718 --- rust/defs.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/defs.bzl b/rust/defs.bzl index c542760056..d51829bb83 100644 --- a/rust/defs.bzl +++ b/rust/defs.bzl @@ -18,7 +18,7 @@ visibility([ ]) def rust_proto_library(name, deps, visibility = [], **args): - """Declares all the boilerplate needed to use Rust protobufs conveniently. + """Declares all the boilerplate needed to use Rust protobufs conveniently. Hopefully no user will ever need to read this code. From 1e0338b2ba720243766cbda76b27bcf010aa1fa7 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 09:31:49 -0800 Subject: [PATCH 109/387] [ObjC] Ensure `-[GPBMessage writeToOutputStream:]` still throws exception on flush failure This restores the behavior of `-[GPBMessage writeToOutputStream:]` throwing an exception if the underlying `GPBCodedOutputStream` failed to flush. `GPBDictionary` and `GPBUnknownFieldSet` could also have theoretically thrown exceptions from just about any method (although not for disk I/O reasons), so this also restores that functionality by explicitly flushing before deallocating the `GPBCodedOutputStream`. PiperOrigin-RevId: 580207004 --- objectivec/GPBDictionary.m | 7 +++++++ objectivec/GPBMessage.m | 3 +++ objectivec/GPBUnknownFieldSet.m | 1 + objectivec/Tests/GPBMessageTests.m | 13 +++++++++++++ 4 files changed, 24 insertions(+) diff --git a/objectivec/GPBDictionary.m b/objectivec/GPBDictionary.m index 4d7c08c1ee..a07a419f8b 100644 --- a/objectivec/GPBDictionary.m +++ b/objectivec/GPBDictionary.m @@ -1044,6 +1044,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, //% GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; //% WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType); //% WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); +//% [outputStream flush]; //% [outputStream release]; //% return data; //%} @@ -2788,6 +2789,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType); WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); + [outputStream flush]; [outputStream release]; return data; } @@ -4518,6 +4520,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType); WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); + [outputStream flush]; [outputStream release]; return data; } @@ -6248,6 +6251,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType); WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); + [outputStream flush]; [outputStream release]; return data; } @@ -7978,6 +7982,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType); WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); + [outputStream flush]; [outputStream release]; return data; } @@ -9768,6 +9773,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType); WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); + [outputStream flush]; [outputStream release]; return data; } @@ -11741,6 +11747,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType); WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); + [outputStream flush]; [outputStream release]; return data; } diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index 6124b70814..e2436a226a 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -1343,6 +1343,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { GPBCodedOutputStream *stream = [[GPBCodedOutputStream alloc] initWithData:data]; @try { [self writeToCodedOutputStream:stream]; + [stream flush]; } @catch (NSException *exception) { // This really shouldn't happen. Normally, this could mean there was a bug in the library and it // failed to match between computing the size and writing out the bytes. However, the more @@ -1393,6 +1394,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { GPBCodedOutputStream *stream = [[GPBCodedOutputStream alloc] initWithOutputStream:output]; @try { [self writeToCodedOutputStream:stream]; + [stream flush]; size_t bytesWritten = [stream bytesWritten]; if (bytesWritten > kMaximumMessageSize) { [NSException raise:GPBMessageExceptionMessageTooLarge @@ -1436,6 +1438,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { GPBCodedOutputStream *codedOutput = [[GPBCodedOutputStream alloc] initWithOutputStream:output]; @try { [self writeDelimitedToCodedOutputStream:codedOutput]; + [codedOutput flush]; } @finally { [codedOutput release]; } diff --git a/objectivec/GPBUnknownFieldSet.m b/objectivec/GPBUnknownFieldSet.m index a68b62c841..768734070d 100644 --- a/objectivec/GPBUnknownFieldSet.m +++ b/objectivec/GPBUnknownFieldSet.m @@ -207,6 +207,7 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke NSMutableData *data = [NSMutableData dataWithLength:self.serializedSize]; GPBCodedOutputStream *output = [[GPBCodedOutputStream alloc] initWithData:data]; [self writeToCodedOutputStream:output]; + [output flush]; [output release]; return data; } diff --git a/objectivec/Tests/GPBMessageTests.m b/objectivec/Tests/GPBMessageTests.m index d5a085c83d..d598a48b60 100644 --- a/objectivec/Tests/GPBMessageTests.m +++ b/objectivec/Tests/GPBMessageTests.m @@ -2225,4 +2225,17 @@ XCTAssertNil(shouldGetAPrefixMessage); } +- (void)testWriteToFullOutputStreamShouldThrow { + uint8_t buffer[1] = {0}; + + // Output stream which can write precisely 1 byte of data before it's full. + NSOutputStream *output = [[[NSOutputStream alloc] initToBuffer:buffer + capacity:sizeof(buffer)] autorelease]; + + TestAllTypes *message = [TestAllTypes message]; + [message setOptionalInt32:1]; + XCTAssertThrowsSpecificNamed([message writeToOutputStream:output], NSException, + GPBCodedOutputStreamException_WriteFailed); +} + @end From 7463878e35ed49f57594256524d265c9cfaeb3a4 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 7 Nov 2023 09:40:13 -0800 Subject: [PATCH 110/387] Give protobuf janitor access to edit prs/issues and exempt issues with the 'help wanted' tag. The initial job ran and found stale PRs/issues, but lacked the permission to comment on them, add labels, or close issues/PRs. Any issues with 'help wanted' shouldn't be auto-closed as we want them to be able to sit inactive. PiperOrigin-RevId: 580209299 --- .github/workflows/janitor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/janitor.yml b/.github/workflows/janitor.yml index 5c052a4f12..4aa88bae5f 100644 --- a/.github/workflows/janitor.yml +++ b/.github/workflows/janitor.yml @@ -32,6 +32,9 @@ jobs: stale-others: name: Close stale non-copybara PRs and issues runs-on: ubuntu-latest + permissions: + issues: write # allow the action to comment on, add labels to, and close issues + pull-requests: write # allow the action to comment on, add labels to, and close PRs steps: - uses: actions/stale@b69b346013879cedbf50c69f572cd85439a41936 with: @@ -69,6 +72,7 @@ jobs: activity in the 14 days since the `inactive` label was added. stale-issue-label: 'inactive' stale-pr-label: 'inactive' + exempt-issue-labels: 'help wanted' days-before-stale: 90 days-before-close: 14 operations-per-run: 100 From 62f48888247587eeee4f13ff0cc464d78b8e2d04 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 7 Nov 2023 11:27:13 -0800 Subject: [PATCH 111/387] Bump mac PHP version to 8.2 to fix non-hermetic breakages. This was likely either a change in macos or the github runners PiperOrigin-RevId: 580245853 --- .github/workflows/test_php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_php.yml b/.github/workflows/test_php.yml index 954aa4be8d..391442d8a2 100644 --- a/.github/workflows/test_php.yml +++ b/.github/workflows/test_php.yml @@ -150,7 +150,7 @@ jobs: strategy: fail-fast: false # Don't cancel all jobs if one fails. matrix: - version: ['8.0'] + version: ['8.2'] name: MacOS PHP ${{ matrix.version }} runs-on: macos-12 From bb40d9199c6e476d7eac490743825dae603884fc Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 12:09:20 -0800 Subject: [PATCH 112/387] Update main/version.json to 26-dev PiperOrigin-RevId: 580259174 --- version.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/version.json b/version.json index 9deb430483..735b320f9f 100644 --- a/version.json +++ b/version.json @@ -1,17 +1,17 @@ { - "25.x": { - "protoc_version": "25.0-dev", + "main": { + "protoc_version": "26-dev", "lts": false, "date": "2023-11-01", "languages": { - "cpp": "4.25.0-dev", - "csharp": "3.25.0-dev", - "java": "3.25.0-dev", - "javascript": "3.25.0-dev", - "objectivec": "3.25.0-dev", - "php": "3.25.0-dev", - "python": "4.25.0-dev", - "ruby": "3.25.0-dev" + "cpp": "4.26-dev", + "csharp": "3.26-dev", + "java": "3.26-dev", + "javascript": "3.26-dev", + "objectivec": "3.26-dev", + "php": "3.26-dev", + "python": "4.26-dev", + "ruby": "3.26-dev" } } } From cf3a6f5868222d31021e3835e5e7890a847f3d01 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 7 Nov 2023 12:22:10 -0800 Subject: [PATCH 113/387] Enabled editions support for upb generated code. This required enabling the feature in the code generator and fixing a few edge cases around label and type. Also added tests to verify the special cases, and to verify that required fields work as expected. PiperOrigin-RevId: 580263087 --- .../protobuf/compiler/allowlists/editions.cc | 1 + upb/reflection/field_def.c | 19 +++- upb/test/BUILD | 32 ++++++ upb/test/editions_test.cc | 62 +++++++++++ upb/test/editions_test.proto | 26 +++++ upb/util/BUILD | 6 +- upb/util/def_to_proto.c | 2 + upb/util/required_fields_editions_test.proto | 28 +++++ upb/util/required_fields_test.cc | 103 ++++++++++++------ upb_generator/file_layout.cc | 22 +++- upb_generator/file_layout.h | 8 +- upb_generator/plugin.h | 7 +- upb_generator/protoc-gen-upb.cc | 4 +- upb_generator/protoc-gen-upb_minitable.cc | 14 +-- 14 files changed, 277 insertions(+), 57 deletions(-) create mode 100644 upb/test/editions_test.cc create mode 100644 upb/test/editions_test.proto create mode 100644 upb/util/required_fields_editions_test.proto diff --git a/src/google/protobuf/compiler/allowlists/editions.cc b/src/google/protobuf/compiler/allowlists/editions.cc index 6ab81c0646..f883ece02a 100644 --- a/src/google/protobuf/compiler/allowlists/editions.cc +++ b/src/google/protobuf/compiler/allowlists/editions.cc @@ -20,6 +20,7 @@ static constexpr auto kEarlyEditionsFile = internal::MakeAllowlist( { // Intentionally left blank. "google/protobuf/", + "upb/", }, internal::AllowlistFlags::kMatchPrefix); diff --git a/upb/reflection/field_def.c b/upb/reflection/field_def.c index 5b67e209cc..0a4ae254eb 100644 --- a/upb/reflection/field_def.c +++ b/upb/reflection/field_def.c @@ -123,11 +123,26 @@ upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { UPB_UNREACHABLE(); } -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; } +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_FieldType_Group. + if (f->type_ == kUpb_FieldType_Message && + UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) == + UPB_DESC(FeatureSet_DELIMITED)) { + return kUpb_FieldType_Group; + } + return f->type_; +} uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } -upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; } +upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_Label_Required. + if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED)) { + return kUpb_Label_Required; + } + return f->label_; +} uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } diff --git a/upb/test/BUILD b/upb/test/BUILD index 6ae451d029..b101237ddf 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -84,6 +84,24 @@ upb_c_proto_library( deps = [":test_proto"], ) +proto_library( + name = "editions_test_proto", + testonly = 1, + srcs = ["editions_test.proto"], +) + +upb_c_proto_library( + name = "editions_test_upb_c_proto", + testonly = 1, + deps = [":editions_test_proto"], +) + +upb_proto_reflection_library( + name = "editions_test_upb_proto_reflection", + testonly = 1, + deps = [":editions_test_proto"], +) + proto_library( name = "test_cpp_proto", srcs = ["test_cpp.proto"], @@ -166,6 +184,20 @@ cc_test( ], ) +cc_test( + name = "editions_test", + srcs = ["editions_test.cc"], + copts = UPB_DEFAULT_CPPOPTS, + deps = [ + ":editions_test_upb_c_proto", + ":editions_test_upb_proto_reflection", + "@com_google_googletest//:gtest_main", + "//upb:base", + "//upb:mem", + "//upb:reflection", + ], +) + cc_test( name = "test_cpp", srcs = ["test_cpp.cc"], diff --git a/upb/test/editions_test.cc b/upb/test/editions_test.cc new file mode 100644 index 0000000000..92f9922ebd --- /dev/null +++ b/upb/test/editions_test.cc @@ -0,0 +1,62 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#include +#include "upb/base/descriptor_constants.h" +#include "upb/mem/arena.hpp" +#include "upb/reflection/def.hpp" +#include "upb/test/editions_test.upb.h" +#include "upb/test/editions_test.upbdefs.h" + +TEST(EditionsTest, PlainField) { + upb::DefPool defpool; + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); + upb::FieldDefPtr f(md.FindFieldByName("plain_field")); + EXPECT_TRUE(f.has_presence()); +} + +TEST(EditionsTest, ImplicitPresenceField) { + upb::DefPool defpool; + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); + upb::FieldDefPtr f(md.FindFieldByName("implicit_presence_field")); + EXPECT_FALSE(f.has_presence()); +} + +TEST(EditionsTest, DelimitedField) { + upb::DefPool defpool; + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); + upb::FieldDefPtr f(md.FindFieldByName("delimited_field")); + EXPECT_EQ(kUpb_FieldType_Group, f.type()); +} + +TEST(EditionsTest, RequiredField) { + upb::DefPool defpool; + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); + upb::FieldDefPtr f(md.FindFieldByName("required_field")); + EXPECT_EQ(kUpb_Label_Required, f.label()); +} + +TEST(EditionsTest, ClosedEnum) { + upb::DefPool defpool; + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); + upb::FieldDefPtr f(md.FindFieldByName("enum_field")); + ASSERT_TRUE(f.enum_subdef().is_closed()); +} + +TEST(EditionsTest, PackedField) { + upb::DefPool defpool; + upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr())); + upb::FieldDefPtr f(md.FindFieldByName("unpacked_field")); + ASSERT_FALSE(f.packed()); +} + +TEST(EditionsTest, ConstructProto) { + // Doesn't do anything except construct the proto. This just verifies that + // the generated code compiles successfully. + upb::Arena arena; + upb_test_2023_EditionsMessage_new(arena.ptr()); +} diff --git a/upb/test/editions_test.proto b/upb/test/editions_test.proto new file mode 100644 index 0000000000..aeb2440c0d --- /dev/null +++ b/upb/test/editions_test.proto @@ -0,0 +1,26 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +edition = "2023"; + +package upb.test_2023; + +message EditionsMessage { + int32 plain_field = 1; + int32 implicit_presence_field = 2 [features.field_presence = IMPLICIT]; + int32 required_field = 3 [features.field_presence = LEGACY_REQUIRED]; + EditionsMessage delimited_field = 4 [features.message_encoding = DELIMITED]; + EditionsEnum enum_field = 5; + repeated int32 unpacked_field = 6 + [features.repeated_field_encoding = EXPANDED]; +} + +enum EditionsEnum { + option features.enum_type = CLOSED; + + ONE = 1; +} diff --git a/upb/util/BUILD b/upb/util/BUILD index f354be10d8..8efb0b1f68 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -106,7 +106,10 @@ cc_library( proto_library( name = "required_fields_test_proto", - srcs = ["required_fields_test.proto"], + srcs = [ + "required_fields_editions_test.proto", + "required_fields_test.proto", + ], ) upb_c_proto_library( @@ -131,6 +134,7 @@ cc_test( "//upb:json", "//upb:mem", "//upb:reflection", + "//upb:reflection_internal", "@com_google_absl//absl/strings", ], ) diff --git a/upb/util/def_to_proto.c b/upb/util/def_to_proto.c index 29331d59bb..2c0ecbe484 100644 --- a/upb/util/def_to_proto.c +++ b/upb/util/def_to_proto.c @@ -511,6 +511,8 @@ static google_protobuf_FileDescriptorProto* filedef_toproto(upb_ToProto_Context* if (upb_FileDef_Syntax(f) == kUpb_Syntax_Proto3) { google_protobuf_FileDescriptorProto_set_syntax(proto, strviewdup(ctx, "proto3")); + } else if (upb_FileDef_Syntax(f) == kUpb_Syntax_Editions) { + google_protobuf_FileDescriptorProto_set_syntax(proto, strviewdup(ctx, "editions")); } size_t n; diff --git a/upb/util/required_fields_editions_test.proto b/upb/util/required_fields_editions_test.proto new file mode 100644 index 0000000000..b0f41008da --- /dev/null +++ b/upb/util/required_fields_editions_test.proto @@ -0,0 +1,28 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +edition = "2023"; + +package upb_util_2023_test; + +message EmptyMessage {} + +message HasRequiredField { + int32 required_int32 = 1 [features.field_presence = LEGACY_REQUIRED]; +} + +message TestRequiredFields { + EmptyMessage required_message = 1 [features.field_presence = LEGACY_REQUIRED]; + TestRequiredFields optional_message = 2; + repeated HasRequiredField repeated_message = 3; + map map_int32_message = 4; + map map_int64_message = 5; + map map_uint32_message = 6; + map map_uint64_message = 7; + map map_bool_message = 8; + map map_string_message = 9; +} diff --git a/upb/util/required_fields_test.cc b/upb/util/required_fields_test.cc index 167fa7e71c..70f0a95bf6 100644 --- a/upb/util/required_fields_test.cc +++ b/upb/util/required_fields_test.cc @@ -9,13 +9,16 @@ #include -#include #include #include "absl/strings/string_view.h" #include "upb/base/status.hpp" #include "upb/json/decode.h" +#include "upb/mem/arena.h" #include "upb/mem/arena.hpp" +#include "upb/reflection/common.h" #include "upb/reflection/def.hpp" +#include "upb/util/required_fields_editions_test.upb.h" +#include "upb/util/required_fields_editions_test.upbdefs.h" #include "upb/util/required_fields_test.upb.h" #include "upb/util/required_fields_test.upbdefs.h" @@ -40,31 +43,61 @@ std::vector PathsToText(upb_FieldPathEntry* entry) { return ret; } -void CheckRequired(absl::string_view json, - const std::vector& missing) { - upb::Arena arena; - upb::DefPool defpool; - upb_util_test_TestRequiredFields* test_msg = - upb_util_test_TestRequiredFields_new(arena.ptr()); - upb::MessageDefPtr m( - upb_util_test_TestRequiredFields_getmsgdef(defpool.ptr())); - upb::Status status; - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), test_msg, m.ptr(), - defpool.ptr(), 0, arena.ptr(), status.ptr())) - << status.error_message(); - upb_FieldPathEntry* entries = nullptr; - EXPECT_EQ(!missing.empty(), upb_util_HasUnsetRequired( - test_msg, m.ptr(), defpool.ptr(), &entries)); - if (entries) { - EXPECT_EQ(missing, PathsToText(entries)); - free(entries); +template +class RequiredFieldsTest : public testing::Test { + public: + void CheckRequired(absl::string_view json, + const std::vector& missing) { + upb::Arena arena; + upb::DefPool defpool; + auto* test_msg = T::NewMessage(arena.ptr()); + upb::MessageDefPtr m = T::GetMessageDef(defpool.ptr()); + upb::Status status; + EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), test_msg, m.ptr(), + defpool.ptr(), 0, arena.ptr(), status.ptr())) + << status.error_message(); + upb_FieldPathEntry* entries = nullptr; + EXPECT_EQ( + !missing.empty(), + upb_util_HasUnsetRequired(test_msg, m.ptr(), defpool.ptr(), &entries)); + if (entries) { + EXPECT_EQ(missing, PathsToText(entries)); + free(entries); + } + + // Verify that we can pass a NULL pointer to entries when we don't care + // about them. + EXPECT_EQ(!missing.empty(), upb_util_HasUnsetRequired( + test_msg, m.ptr(), defpool.ptr(), nullptr)); } +}; - // Verify that we can pass a NULL pointer to entries when we don't care about - // them. - EXPECT_EQ(!missing.empty(), upb_util_HasUnsetRequired( - test_msg, m.ptr(), defpool.ptr(), nullptr)); -} +class Proto2Type { + public: + using MessageType = upb_util_test_TestRequiredFields; + static MessageType* NewMessage(upb_Arena* arena) { + return upb_util_test_TestRequiredFields_new(arena); + } + static upb::MessageDefPtr GetMessageDef(upb_DefPool* defpool) { + return upb::MessageDefPtr( + upb_util_test_TestRequiredFields_getmsgdef(defpool)); + } +}; + +class Edition2023Type { + public: + using MessageType = upb_util_2023_test_TestRequiredFields; + static MessageType* NewMessage(upb_Arena* arena) { + return upb_util_2023_test_TestRequiredFields_new(arena); + } + static upb::MessageDefPtr GetMessageDef(upb_DefPool* defpool) { + return upb::MessageDefPtr( + upb_util_2023_test_TestRequiredFields_getmsgdef(defpool)); + } +}; + +using MyTypes = ::testing::Types; +TYPED_TEST_SUITE(RequiredFieldsTest, MyTypes); // message HasRequiredField { // required int32 required_int32 = 1; @@ -76,10 +109,10 @@ void CheckRequired(absl::string_view json, // repeated HasRequiredField repeated_message = 3; // map map_int32_message = 4; // } -TEST(RequiredFieldsTest, TestRequired) { - CheckRequired(R"json({})json", {"required_message"}); - CheckRequired(R"json({"required_message": {}}")json", {}); - CheckRequired( +TYPED_TEST(RequiredFieldsTest, TestRequired) { + TestFixture::CheckRequired(R"json({})json", {"required_message"}); + TestFixture::CheckRequired(R"json({"required_message": {}}")json", {}); + TestFixture::CheckRequired( R"json( { "optional_message": {} @@ -88,7 +121,7 @@ TEST(RequiredFieldsTest, TestRequired) { {"required_message", "optional_message.required_message"}); // Repeated field. - CheckRequired( + TestFixture::CheckRequired( R"json( { "optional_message": { @@ -104,7 +137,7 @@ TEST(RequiredFieldsTest, TestRequired) { "optional_message.repeated_message[1].required_int32"}); // Int32 map key. - CheckRequired( + TestFixture::CheckRequired( R"json( { "required_message": {}, @@ -118,7 +151,7 @@ TEST(RequiredFieldsTest, TestRequired) { {"map_int32_message[5].required_int32"}); // Int64 map key. - CheckRequired( + TestFixture::CheckRequired( R"json( { "required_message": {}, @@ -132,7 +165,7 @@ TEST(RequiredFieldsTest, TestRequired) { {"map_int64_message[5].required_int32"}); // Uint32 map key. - CheckRequired( + TestFixture::CheckRequired( R"json( { "required_message": {}, @@ -146,7 +179,7 @@ TEST(RequiredFieldsTest, TestRequired) { {"map_uint32_message[5].required_int32"}); // Uint64 map key. - CheckRequired( + TestFixture::CheckRequired( R"json( { "required_message": {}, @@ -160,7 +193,7 @@ TEST(RequiredFieldsTest, TestRequired) { {"map_uint64_message[5].required_int32"}); // Bool map key. - CheckRequired( + TestFixture::CheckRequired( R"json( { "required_message": {}, @@ -173,7 +206,7 @@ TEST(RequiredFieldsTest, TestRequired) { {"map_bool_message[true].required_int32"}); // String map key. - CheckRequired( + TestFixture::CheckRequired( R"json( { "required_message": {}, diff --git a/upb_generator/file_layout.cc b/upb_generator/file_layout.cc index 9fa03d2635..56067c5818 100644 --- a/upb_generator/file_layout.cc +++ b/upb_generator/file_layout.cc @@ -32,8 +32,10 @@ #include #include +#include #include "upb/mini_table/internal/extension.h" +#include "upb/reflection/def.hpp" #include "upb_generator/common.h" namespace upb { @@ -43,24 +45,32 @@ const char* kEnumsInit = "enums_layout"; const char* kExtensionsInit = "extensions_layout"; const char* kMessagesInit = "messages_layout"; -void AddEnums(upb::MessageDefPtr message, std::vector* enums) { +void AddEnums(upb::MessageDefPtr message, std::vector* enums, + WhichEnums which) { enums->reserve(enums->size() + message.enum_type_count()); for (int i = 0; i < message.enum_type_count(); i++) { - enums->push_back(message.enum_type(i)); + upb::EnumDefPtr enum_type = message.enum_type(i); + if (which == kAllEnums || enum_type.is_closed()) { + enums->push_back(message.enum_type(i)); + } } for (int i = 0; i < message.nested_message_count(); i++) { - AddEnums(message.nested_message(i), enums); + AddEnums(message.nested_message(i), enums, which); } } -std::vector SortedEnums(upb::FileDefPtr file) { +std::vector SortedEnums(upb::FileDefPtr file, + WhichEnums which) { std::vector enums; enums.reserve(file.toplevel_enum_count()); for (int i = 0; i < file.toplevel_enum_count(); i++) { - enums.push_back(file.toplevel_enum(i)); + upb::EnumDefPtr top_level_enum = file.toplevel_enum(i); + if (which == kAllEnums || top_level_enum.is_closed()) { + enums.push_back(file.toplevel_enum(i)); + } } for (int i = 0; i < file.toplevel_message_count(); i++) { - AddEnums(file.toplevel_message(i), &enums); + AddEnums(file.toplevel_message(i), &enums, which); } std::sort(enums.begin(), enums.end(), [](upb::EnumDefPtr a, upb::EnumDefPtr b) { diff --git a/upb_generator/file_layout.h b/upb_generator/file_layout.h index a5b9416a7d..d428674098 100644 --- a/upb_generator/file_layout.h +++ b/upb_generator/file_layout.h @@ -57,7 +57,13 @@ namespace upb { namespace generator { -std::vector SortedEnums(upb::FileDefPtr file); +enum WhichEnums { + kAllEnums = 0, + kClosedEnums = 1, +}; + +std::vector SortedEnums(upb::FileDefPtr file, + WhichEnums which); // Ordering must match upb/def.c! // diff --git a/upb_generator/plugin.h b/upb_generator/plugin.h index 1500d4097c..50ff5498bf 100644 --- a/upb_generator/plugin.h +++ b/upb_generator/plugin.h @@ -187,9 +187,12 @@ class Plugin { ABSL_LOG(FATAL) << "Failed to parse CodeGeneratorRequest"; } response_ = UPB_DESC(compiler_CodeGeneratorResponse_new)(arena_.ptr()); + + int features = + UPB_DESC(compiler_CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) | + UPB_DESC(compiler_CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS); UPB_DESC(compiler_CodeGeneratorResponse_set_supported_features) - (response_, - UPB_DESC(compiler_CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)); + (response_, features); } void WriteResponse() { diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index dac5bd6383..1e97a78370 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -868,7 +868,7 @@ void WriteHeader(const DefPoolPair& pools, upb::FileDefPtr file, const std::vector this_file_messages = SortedMessages(file); const std::vector this_file_exts = SortedExtensions(file); - std::vector this_file_enums = SortedEnums(file); + std::vector this_file_enums = SortedEnums(file, kAllEnums); std::vector forward_messages = SortedForwardMessages(this_file_messages, this_file_exts); @@ -1097,7 +1097,7 @@ void WriteMiniDescriptorSource(const DefPoolPair& pools, upb::FileDefPtr file, WriteMessageMiniDescriptorInitializer(msg, options, output); } - for (const auto msg : SortedEnums(file)) { + for (const auto msg : SortedEnums(file, kClosedEnums)) { WriteEnumMiniDescriptorInitializer(msg, options, output); } } diff --git a/upb_generator/protoc-gen-upb_minitable.cc b/upb_generator/protoc-gen-upb_minitable.cc index e3064adadc..7a1d1d6dfb 100644 --- a/upb_generator/protoc-gen-upb_minitable.cc +++ b/upb_generator/protoc-gen-upb_minitable.cc @@ -145,12 +145,11 @@ void WriteHeader(const DefPoolPair& pools, upb::FileDefPtr file, output("\n"); - std::vector this_file_enums = SortedEnums(file); + std::vector this_file_enums = + SortedEnums(file, kClosedEnums); - if (file.syntax() == kUpb_Syntax_Proto2) { - for (const auto enumdesc : this_file_enums) { - output("extern const upb_MiniTableEnum $0;\n", EnumInit(enumdesc)); - } + for (const auto enumdesc : this_file_enums) { + output("extern const upb_MiniTableEnum $0;\n", EnumInit(enumdesc)); } output("extern const upb_MiniTableFile $0;\n\n", FileLayoutName(file)); @@ -536,9 +535,8 @@ void WriteEnum(upb::EnumDefPtr e, Output& output) { } int WriteEnums(const DefPoolPair& pools, upb::FileDefPtr file, Output& output) { - if (file.syntax() != kUpb_Syntax_Proto2) return 0; - - std::vector this_file_enums = SortedEnums(file); + std::vector this_file_enums = + SortedEnums(file, kClosedEnums); for (const auto e : this_file_enums) { WriteEnum(e, output); From ebef52ec2fb8675c4a2e7946c40bd2715768f7c1 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 20:35:14 +0000 Subject: [PATCH 114/387] Auto-generate files after cl/580263087 --- php/ext/google/protobuf/php-upb.c | 19 +++++++++++++++++-- ruby/ext/google/protobuf_c/ruby-upb.c | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 4225aa3a7d..cdd27ede87 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -9395,11 +9395,26 @@ upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { UPB_UNREACHABLE(); } -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; } +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_FieldType_Group. + if (f->type_ == kUpb_FieldType_Message && + UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) == + UPB_DESC(FeatureSet_DELIMITED)) { + return kUpb_FieldType_Group; + } + return f->type_; +} uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } -upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; } +upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_Label_Required. + if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED)) { + return kUpb_Label_Required; + } + return f->label_; +} uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 998f4c0891..63627d4b83 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -8910,11 +8910,26 @@ upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { UPB_UNREACHABLE(); } -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; } +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_FieldType_Group. + if (f->type_ == kUpb_FieldType_Message && + UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) == + UPB_DESC(FeatureSet_DELIMITED)) { + return kUpb_FieldType_Group; + } + return f->type_; +} uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } -upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; } +upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_Label_Required. + if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED)) { + return kUpb_Label_Required; + } + return f->label_; +} uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } From b837d17d2c35a01eebd223d90c3dfa0a0e5a9dbd Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Tue, 7 Nov 2023 13:24:59 -0800 Subject: [PATCH 115/387] Update to shortened headers in upb_generator PiperOrigin-RevId: 580281151 --- upb_generator/code_generator_request.c | 29 +++------------------- upb_generator/code_generator_request.h | 29 +++------------------- upb_generator/code_generator_request.proto | 29 +++------------------- upb_generator/common.cc | 29 +++------------------- upb_generator/common.h | 29 +++------------------- upb_generator/file_layout.cc | 29 +++------------------- upb_generator/file_layout.h | 29 +++------------------- upb_generator/get_used_fields.c | 29 +++------------------- upb_generator/get_used_fields.h | 29 +++------------------- upb_generator/keywords.cc | 29 +++------------------- upb_generator/keywords.h | 29 +++------------------- upb_generator/names.cc | 29 +++------------------- upb_generator/names.h | 29 +++------------------- upb_generator/plugin.h | 29 +++------------------- upb_generator/protoc-gen-upb.cc | 29 +++------------------- upb_generator/protoc-gen-upb_minitable.cc | 29 +++------------------- upb_generator/protoc-gen-upbdefs.cc | 29 +++------------------- upb_generator/protoc-gen-upbdev.cc | 29 +++------------------- upb_generator/subprocess.cc | 29 +++------------------- upb_generator/subprocess.h | 29 +++------------------- upb_generator/upb_generator_so.c | 29 +++------------------- upb_generator/upbdev.c | 29 +++------------------- upb_generator/upbdev.h | 29 +++------------------- 23 files changed, 69 insertions(+), 598 deletions(-) diff --git a/upb_generator/code_generator_request.c b/upb_generator/code_generator_request.c index 1c9bcd3ae3..f5c87c0e74 100644 --- a/upb_generator/code_generator_request.c +++ b/upb_generator/code_generator_request.c @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include "upb_generator/code_generator_request.h" diff --git a/upb_generator/code_generator_request.h b/upb_generator/code_generator_request.h index ddd9131a51..fb2af9d7f5 100644 --- a/upb_generator/code_generator_request.h +++ b/upb_generator/code_generator_request.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #ifndef UPB_GENERATOR_CODE_GENERATOR_REQUEST_H_ #define UPB_GENERATOR_CODE_GENERATOR_REQUEST_H_ diff --git a/upb_generator/code_generator_request.proto b/upb_generator/code_generator_request.proto index 63501cf4da..e0033e0bf0 100644 --- a/upb_generator/code_generator_request.proto +++ b/upb_generator/code_generator_request.proto @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd syntax = "proto2"; diff --git a/upb_generator/common.cc b/upb_generator/common.cc index ecd0da6124..b1bfbc3723 100644 --- a/upb_generator/common.cc +++ b/upb_generator/common.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include "upb_generator/common.h" diff --git a/upb_generator/common.h b/upb_generator/common.h index bf4fd7c8f0..42bad45cfe 100644 --- a/upb_generator/common.h +++ b/upb_generator/common.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #ifndef UPB_GENERATOR_COMMON_H #define UPB_GENERATOR_COMMON_H diff --git a/upb_generator/file_layout.cc b/upb_generator/file_layout.cc index 56067c5818..e2660e9d50 100644 --- a/upb_generator/file_layout.cc +++ b/upb_generator/file_layout.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include "upb_generator/file_layout.h" diff --git a/upb_generator/file_layout.h b/upb_generator/file_layout.h index d428674098..a2aad3339a 100644 --- a/upb_generator/file_layout.h +++ b/upb_generator/file_layout.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #ifndef UPB_GENERATOR_FILE_LAYOUT_H #define UPB_GENERATOR_FILE_LAYOUT_H diff --git a/upb_generator/get_used_fields.c b/upb_generator/get_used_fields.c index 55a4ff4b00..1478df7d23 100644 --- a/upb_generator/get_used_fields.c +++ b/upb_generator/get_used_fields.c @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include "upb_generator/get_used_fields.h" diff --git a/upb_generator/get_used_fields.h b/upb_generator/get_used_fields.h index 428c654892..a6c96002b3 100644 --- a/upb_generator/get_used_fields.h +++ b/upb_generator/get_used_fields.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #ifndef UPB_GENERATOR_GET_USED_FIELDS #define UPB_GENERATOR_GET_USED_FIELDS diff --git a/upb_generator/keywords.cc b/upb_generator/keywords.cc index eb6af3a313..beaf7dfc4a 100644 --- a/upb_generator/keywords.cc +++ b/upb_generator/keywords.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include "upb_generator/keywords.h" diff --git a/upb_generator/keywords.h b/upb_generator/keywords.h index 51564a21f3..d4b6ed34bb 100644 --- a/upb_generator/keywords.h +++ b/upb_generator/keywords.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #ifndef UPB_PROTOS_GENERATOR_KEYWORDS_H #define UPB_PROTOS_GENERATOR_KEYWORDS_H diff --git a/upb_generator/names.cc b/upb_generator/names.cc index 31f8c6457f..16ffa43043 100644 --- a/upb_generator/names.cc +++ b/upb_generator/names.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include "upb_generator/names.h" diff --git a/upb_generator/names.h b/upb_generator/names.h index 1694dde454..7830190c19 100644 --- a/upb_generator/names.h +++ b/upb_generator/names.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #ifndef UPB_PROTOS_GENERATOR_NAMES_H #define UPB_PROTOS_GENERATOR_NAMES_H diff --git a/upb_generator/plugin.h b/upb_generator/plugin.h index 50ff5498bf..a4ff00fba7 100644 --- a/upb_generator/plugin.h +++ b/upb_generator/plugin.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #ifndef UPB_UPB_GENERATOR_PLUGIN_H_ #define UPB_UPB_GENERATOR_PLUGIN_H_ diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index 1e97a78370..ae5f1fe0e0 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include #include diff --git a/upb_generator/protoc-gen-upb_minitable.cc b/upb_generator/protoc-gen-upb_minitable.cc index 7a1d1d6dfb..08dfcdc5ad 100644 --- a/upb_generator/protoc-gen-upb_minitable.cc +++ b/upb_generator/protoc-gen-upb_minitable.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include #include diff --git a/upb_generator/protoc-gen-upbdefs.cc b/upb_generator/protoc-gen-upbdefs.cc index 58234150a2..6ee6bafe9b 100644 --- a/upb_generator/protoc-gen-upbdefs.cc +++ b/upb_generator/protoc-gen-upbdefs.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include diff --git a/upb_generator/protoc-gen-upbdev.cc b/upb_generator/protoc-gen-upbdev.cc index ce3bc69283..801a2c8438 100644 --- a/upb_generator/protoc-gen-upbdev.cc +++ b/upb_generator/protoc-gen-upbdev.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include #include diff --git a/upb_generator/subprocess.cc b/upb_generator/subprocess.cc index 5280dc0fba..6831f656b7 100644 --- a/upb_generator/subprocess.cc +++ b/upb_generator/subprocess.cc @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd // Shamelessly copied from the protobuf compiler's subprocess.cc // except this version passes strings instead of Messages. diff --git a/upb_generator/subprocess.h b/upb_generator/subprocess.h index 5465ccdd80..731969083f 100644 --- a/upb_generator/subprocess.h +++ b/upb_generator/subprocess.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd // Shamelessly copied from the protobuf compiler's subprocess.h // except this version passes strings instead of Messages. diff --git a/upb_generator/upb_generator_so.c b/upb_generator/upb_generator_so.c index 30b800f9ed..2edb694d9f 100644 --- a/upb_generator/upb_generator_so.c +++ b/upb_generator/upb_generator_so.c @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd // These headers form a spanning tree for the upbc defs needed by FFI layers. diff --git a/upb_generator/upbdev.c b/upb_generator/upbdev.c index 837b459702..3de46e5c27 100644 --- a/upb_generator/upbdev.c +++ b/upb_generator/upbdev.c @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #include "upb_generator/upbdev.h" diff --git a/upb_generator/upbdev.h b/upb_generator/upbdev.h index 1814b52452..ee5b0a8aa9 100644 --- a/upb_generator/upbdev.h +++ b/upb_generator/upbdev.h @@ -1,32 +1,9 @@ // Protocol Buffers - Google's data interchange format // Copyright 2023 Google LLC. All rights reserved. -// https://developers.google.com/protocol-buffers/ // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google LLC nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd #ifndef UPB_GENERATOR_UPBDEV_H_ #define UPB_GENERATOR_UPBDEV_H_ From e6ea44c9119b0f5976ea7b335395753833fc382d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 13:38:16 -0800 Subject: [PATCH 116/387] Fix upb_MiniTable_GetOneof(miniTable, field) to work correctly if `field` is the very first field in the proto. PiperOrigin-RevId: 580285127 --- upb/mini_table/message.c | 2 +- upb/test/BUILD | 1 + upb/test/proto3_test.proto | 10 ++++++++++ upb/test/test_mini_table_oneof.cc | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/upb/mini_table/message.c b/upb/mini_table/message.c index 56f23014a3..28635cdb0a 100644 --- a/upb/mini_table/message.c +++ b/upb/mini_table/message.c @@ -55,7 +55,7 @@ const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, } const upb_MiniTableField* ptr = &m->fields[0]; const upb_MiniTableField* end = &m->fields[m->field_count]; - while (++ptr < end) { + for (; ptr < end; ptr++) { if (ptr->presence == (*f).presence) { return ptr; } diff --git a/upb/test/BUILD b/upb/test/BUILD index b101237ddf..93661f452e 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -239,6 +239,7 @@ cc_test( ], deps = [ ":empty_upb_proto_reflection", + ":proto3_test_upb_proto", ":test_messages_proto2_upb_minitable", ":test_upb_proto", "@com_google_googletest//:gtest_main", diff --git a/upb/test/proto3_test.proto b/upb/test/proto3_test.proto index 28bc4d347d..774538f42b 100644 --- a/upb/test/proto3_test.proto +++ b/upb/test/proto3_test.proto @@ -27,3 +27,13 @@ message TestMessage3 { optional TestMessage3 msg = 5; repeated TestMessage3 r_msg = 6; } + +// See the InitialFieldOneOf test in test_mini_table_oneof.cc. +message TestOneOfInitialField { + oneof oneof_field { + int32 a = 1; + uint32 b = 2; + } + + float c = 3; +} diff --git a/upb/test/test_mini_table_oneof.cc b/upb/test/test_mini_table_oneof.cc index 3c0ecae0f5..850d57186e 100644 --- a/upb/test/test_mini_table_oneof.cc +++ b/upb/test/test_mini_table_oneof.cc @@ -9,6 +9,7 @@ #include "google/protobuf/test_messages_proto2.upb_minitable.h" #include "upb/mini_table/field.h" #include "upb/mini_table/message.h" +#include "upb/test/proto3_test.upb.h" // Must be last. #include "upb/port/def.inc" @@ -29,6 +30,15 @@ TEST(MiniTableOneofTest, OneOfIteratorProto2) { } while (upb_MiniTable_NextOneofField(google_protobuf_table, &ptr)); } +TEST(MiniTableOneofTest, InitialFieldOneOf) { + const upb_MiniTable* table = &upb__test__TestOneOfInitialField_msg_init; + const upb_MiniTableField* field = upb_MiniTable_FindFieldByNumber(table, 1); + ASSERT_TRUE(field != nullptr); + + const upb_MiniTableField* ptr = upb_MiniTable_GetOneof(table, field); + EXPECT_TRUE(ptr == field); +} + TEST(MiniTableOneofTest, InitialFieldNotOneOf) { constexpr int test_field_number = 1; // optional int that is not a oneof const upb_MiniTable* google_protobuf_table = From f82d198ba52ccfbc1f0c8e0bb57c66be9a9a0519 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 21:50:17 +0000 Subject: [PATCH 117/387] Auto-generate files after cl/580285127 --- php/ext/google/protobuf/php-upb.c | 2 +- ruby/ext/google/protobuf_c/ruby-upb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index cdd27ede87..d375f0f5df 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -8231,7 +8231,7 @@ const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, } const upb_MiniTableField* ptr = &m->fields[0]; const upb_MiniTableField* end = &m->fields[m->field_count]; - while (++ptr < end) { + for (; ptr < end; ptr++) { if (ptr->presence == (*f).presence) { return ptr; } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 63627d4b83..cdcbf4a1db 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -7746,7 +7746,7 @@ const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, } const upb_MiniTableField* ptr = &m->fields[0]; const upb_MiniTableField* end = &m->fields[m->field_count]; - while (++ptr < end) { + for (; ptr < end; ptr++) { if (ptr->presence == (*f).presence) { return ptr; } From fc456aeb39fe5e45726b48f6e512310a86291f5c Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Nov 2023 13:54:33 -0800 Subject: [PATCH 118/387] Change bytes accessors to expose only unmodifiable List, making Bytes as a type an internal implementation detail. PiperOrigin-RevId: 580290313 --- conformance/conformance_dart.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/conformance/conformance_dart.dart b/conformance/conformance_dart.dart index 8491fa0827..386e63ec67 100644 --- a/conformance/conformance_dart.dart +++ b/conformance/conformance_dart.dart @@ -1,6 +1,5 @@ import 'dart:io'; -import 'package:pb_runtime/ffi/bytes.dart'; import 'package:pb_runtime/pb_runtime.dart' as pb; import 'package:third_party.protobuf/test_messages_proto2.upb.dart'; import 'package:third_party.protobuf/test_messages_proto3.upb.dart'; @@ -50,8 +49,8 @@ ConformanceResponse doTest(ConformanceRequest request) { case ConformanceRequest_payload.protobufPayload: try { testMessage = isProto3 - ? TestAllTypesProto3.fromBinary(request.protobufPayload.data) - : TestAllTypesProto2.fromBinary(request.protobufPayload.data); + ? TestAllTypesProto3.fromBinary(request.protobufPayload) + : TestAllTypesProto2.fromBinary(request.protobufPayload); } catch (e) { final parseErrorResponse = ConformanceResponse(); parseErrorResponse.parseError = '$e'; @@ -66,8 +65,7 @@ ConformanceResponse doTest(ConformanceRequest request) { switch (request.requestedOutputFormat) { case WireFormat.PROTOBUF: try { - response.protobufPayload = - Bytes(pb.GeneratedMessage.toBinary(testMessage)); + response.protobufPayload = pb.GeneratedMessage.toBinary(testMessage); } catch (e) { response.serializeError = '$e'; } From 15eccf3ec4636cab20a16b7570d3967d79ecfa95 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 7 Nov 2023 14:37:40 -0800 Subject: [PATCH 119/387] Implement Editions in Pure Python. This change only covers pure python, and follow-up changes will handle C++/upb variants and actually enable editions support. The C++ one works (as evident from the conformance tests), but needs some APIs added to allow for testing. PiperOrigin-RevId: 580304039 --- conformance/BUILD.bazel | 3 +- conformance/conformance_python.py | 22 +- conformance/failure_list_python.txt | 3 + conformance/failure_list_python_cpp.txt | 3 + .../text_format_failure_list_python.txt | 6 + .../text_format_failure_list_python_cpp.txt | 4 + python/build_targets.bzl | 70 ++- python/google/protobuf/descriptor.py | 422 ++++++++++++++---- python/google/protobuf/descriptor_pool.py | 116 ++++- .../protobuf/internal/descriptor_pool_test.py | 203 ++++++++- .../protobuf/internal/descriptor_test.py | 369 ++++++++++++++- .../protobuf/internal/legacy_features.proto | 18 + .../python_edition_defaults.py.template | 5 + src/google/protobuf/compiler/BUILD.bazel | 3 +- .../protobuf/compiler/python/generator.cc | 193 ++++---- .../protobuf/compiler/python/generator.h | 59 ++- src/google/protobuf/editions/BUILD | 26 ++ 17 files changed, 1242 insertions(+), 283 deletions(-) create mode 100644 python/google/protobuf/internal/legacy_features.proto create mode 100644 python/google/protobuf/internal/python_edition_defaults.py.template diff --git a/conformance/BUILD.bazel b/conformance/BUILD.bazel index e54eab02d2..d0640dc9a9 100644 --- a/conformance/BUILD.bazel +++ b/conformance/BUILD.bazel @@ -261,8 +261,7 @@ py_binary( deps = [ ":conformance_py_proto", "//:protobuf_python", - "//python:test_messages_proto2_py_proto", - "//python:test_messages_proto3_py_proto", + "//python:conformance_test_py_proto", ], ) diff --git a/conformance/conformance_python.py b/conformance/conformance_python.py index 5e2a99af82..1709457a37 100755 --- a/conformance/conformance_python.py +++ b/conformance/conformance_python.py @@ -19,6 +19,8 @@ from google.protobuf import text_format from google.protobuf import test_messages_proto2_pb2 from google.protobuf import test_messages_proto3_pb2 from conformance import conformance_pb2 +from google.protobuf.editions.golden import test_messages_proto2_editions_pb2 +from google.protobuf.editions.golden import test_messages_proto3_editions_pb2 test_count = 0 verbose = False @@ -28,6 +30,18 @@ class ProtocolError(Exception): pass +def _create_test_message(type): + if type == "protobuf_test_messages.proto2.TestAllTypesProto2": + return test_messages_proto2_pb2.TestAllTypesProto2() + if type == "protobuf_test_messages.proto3.TestAllTypesProto3": + return test_messages_proto3_pb2.TestAllTypesProto3() + if type == "protobuf_test_messages.editions.proto2.TestAllTypesProto2": + return test_messages_proto2_editions_pb2.TestAllTypesProto2() + if type == "protobuf_test_messages.editions.proto3.TestAllTypesProto3": + return test_messages_proto3_editions_pb2.TestAllTypesProto3() + return None + + def do_test(request): response = conformance_pb2.ConformanceResponse() @@ -85,16 +99,12 @@ def do_test(request): response.protobuf_payload = failure_set.SerializeToString() return response - isProto3 = (request.message_type == "protobuf_test_messages.proto3.TestAllTypesProto3") isJson = (request.WhichOneof('payload') == 'json_payload') - isProto2 = (request.message_type == "protobuf_test_messages.proto2.TestAllTypesProto2") + test_message = _create_test_message(request.message_type) - if (not isProto3) and (not isJson) and (not isProto2): + if (not isJson) and (test_message is None): raise ProtocolError("Protobuf request doesn't have specific payload type") - test_message = test_messages_proto2_pb2.TestAllTypesProto2() if isProto2 else \ - test_messages_proto3_pb2.TestAllTypesProto3() - try: if request.WhichOneof('payload') == 'protobuf_payload': try: diff --git a/conformance/failure_list_python.txt b/conformance/failure_list_python.txt index 8bbf094293..b278006bcc 100644 --- a/conformance/failure_list_python.txt +++ b/conformance/failure_list_python.txt @@ -1,3 +1,6 @@ Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput +Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput +Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput diff --git a/conformance/failure_list_python_cpp.txt b/conformance/failure_list_python_cpp.txt index a49939327b..9b0dea6864 100644 --- a/conformance/failure_list_python_cpp.txt +++ b/conformance/failure_list_python_cpp.txt @@ -9,3 +9,6 @@ Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput +Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput +Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput diff --git a/conformance/text_format_failure_list_python.txt b/conformance/text_format_failure_list_python.txt index 2f7f22471c..6754aa4c4b 100644 --- a/conformance/text_format_failure_list_python.txt +++ b/conformance/text_format_failure_list_python.txt @@ -7,3 +7,9 @@ Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput +Required.Editions_Proto3.TextFormatInput.FloatFieldMaxValue.ProtobufOutput +Required.Editions_Proto3.TextFormatInput.FloatFieldMaxValue.TextFormatOutput +Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput +Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput +Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput +Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput diff --git a/conformance/text_format_failure_list_python_cpp.txt b/conformance/text_format_failure_list_python_cpp.txt index b9da32dab8..037ca00e13 100644 --- a/conformance/text_format_failure_list_python_cpp.txt +++ b/conformance/text_format_failure_list_python_cpp.txt @@ -2,3 +2,7 @@ Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput +Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput +Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput +Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput +Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput diff --git a/python/build_targets.bzl b/python/build_targets.bzl index fff32b4a5b..56ed77b4dd 100644 --- a/python/build_targets.bzl +++ b/python/build_targets.bzl @@ -12,6 +12,7 @@ load("//:protobuf.bzl", "internal_py_proto_library") load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test") load("//build_defs:cpp_opts.bzl", "COPTS") load("//conformance:defs.bzl", "conformance_test") +load("//src/google/protobuf/editions:defaults.bzl", "compile_edition_defaults", "embed_edition_defaults") load(":internal.bzl", "internal_copy_files", "internal_py_test") def build_targets(name): @@ -143,8 +144,23 @@ def build_targets(name): ], ) - py_library( - name = "python_srcs", + compile_edition_defaults( + name = "python_edition_defaults", + srcs = ["//:descriptor_proto"], + maximum_edition = "2023", + minimum_edition = "PROTO2", + ) + + embed_edition_defaults( + name = "embedded_python_edition_defaults_generate", + defaults = "python_edition_defaults", + output = "google/protobuf/internal/python_edition_defaults.py", + placeholder = "DEFAULTS_VALUE", + template = "google/protobuf/internal/python_edition_defaults.py.template", + ) + + native.filegroup( + name = "python_src_files", srcs = native.glob( [ "google/protobuf/**/*.py", @@ -154,7 +170,12 @@ def build_targets(name): "google/protobuf/internal/test_util.py", "google/protobuf/internal/import_test_package/__init__.py", ], - ), + ) + ["google/protobuf/internal/python_edition_defaults.py"], + ) + + py_library( + name = "python_srcs", + srcs = [":python_src_files"], imports = ["python"], srcs_version = "PY2AND3", visibility = [ @@ -196,19 +217,13 @@ def build_targets(name): ) internal_copy_files( - name = "copied_test_messages_proto2_files", + name = "copied_conformance_test_files", testonly = 1, srcs = [ "//src/google/protobuf:test_messages_proto2.proto", - ], - strip_prefix = "src", - ) - - internal_copy_files( - name = "copied_test_messages_proto3_files", - testonly = 1, - srcs = [ "//src/google/protobuf:test_messages_proto3.proto", + "//src/google/protobuf/editions:golden/test_messages_proto2_editions.proto", + "//src/google/protobuf/editions:golden/test_messages_proto3_editions.proto", ], strip_prefix = "src", ) @@ -241,22 +256,9 @@ def build_targets(name): ) internal_py_proto_library( - name = "test_messages_proto2_py_proto", - testonly = 1, - srcs = [":copied_test_messages_proto2_files"], - include = ".", - default_runtime = "//:protobuf_python", - protoc = "//:protoc", - visibility = [ - "//conformance:__pkg__", - "//python:__subpackages__", - ], - ) - - internal_py_proto_library( - name = "test_messages_proto3_py_proto", + name = "conformance_test_py_proto", testonly = 1, - srcs = [":copied_test_messages_proto3_files"], + srcs = [":copied_conformance_test_files"], include = ".", default_runtime = "//:protobuf_python", protoc = "//:protoc", @@ -404,6 +406,7 @@ def build_targets(name): ":use_fast_cpp_protos": ["@platforms//:incompatible"], "//conditions:default": [], }), + maximum_edition = "2023", testee = "//conformance:conformance_python", text_format_failure_list = "//conformance:text_format_failure_list_python.txt", ) @@ -418,6 +421,7 @@ def build_targets(name): ":use_fast_cpp_protos": [], "//conditions:default": ["@platforms//:incompatible"], }), + maximum_edition = "2023", testee = "//conformance:conformance_python", text_format_failure_list = "//conformance:text_format_failure_list_python_cpp.txt", ) @@ -428,16 +432,8 @@ def build_targets(name): pkg_files( name = "python_source_files", - srcs = native.glob( - [ - "google/protobuf/**/*.py", - ], - exclude = [ - "google/protobuf/internal/*_test.py", - "google/protobuf/internal/test_util.py", - "google/protobuf/internal/import_test_package/__init__.py", - ], - ) + [ + srcs = [ + ":python_src_files", "README.md", "google/__init__.py", "setup.cfg", diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index 5b32e5e154..fb16bb4fe9 100755 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py @@ -11,6 +11,9 @@ file, in types that make this information accessible in Python. __author__ = 'robinson@google.com (Will Robinson)' +import abc +import binascii +import os import threading import warnings @@ -18,9 +21,6 @@ from google.protobuf.internal import api_implementation _USE_C_DESCRIPTORS = False if api_implementation.Type() != 'python': - # Used by MakeDescriptor in cpp mode - import binascii - import os # pylint: disable=protected-access _message = api_implementation._c_module # TODO: Remove this import after fix api_implementation @@ -52,7 +52,7 @@ if _USE_C_DESCRIPTORS: return False else: # The standard metaclass; nothing changes. - DescriptorMetaclass = type + DescriptorMetaclass = abc.ABCMeta class _Lock(object): @@ -83,6 +83,14 @@ def _Deprecated(name): % name, category=DeprecationWarning, stacklevel=3) +# These must match the values in descriptor.proto, but we can't use them +# directly because we sometimes need to reference them in feature helpers +# below *during* the build of descriptor.proto. +_FEATURESET_MESSAGE_ENCODING_DELIMITED = 2 +_FEATURESET_FIELD_PRESENCE_IMPLICIT = 2 +_FEATURESET_FIELD_PRESENCE_LEGACY_REQUIRED = 3 +_FEATURESET_REPEATED_FIELD_ENCODING_PACKED = 1 +_FEATURESET_ENUM_TYPE_CLOSED = 2 # Deprecated warnings will print 100 times at most which should be enough for # users to notice and do not cause timeout. @@ -118,8 +126,10 @@ class DescriptorBase(metaclass=DescriptorMetaclass): class of the options message. The name of the class is required in case the options message is None and has to be created. """ + self._features = None self.file = file self._options = options + self._loaded_options = None self._options_class_name = options_class_name self._serialized_options = serialized_options @@ -128,44 +138,106 @@ class DescriptorBase(metaclass=DescriptorMetaclass): self._serialized_options is not None ) - def _SetOptions(self, options, options_class_name): - """Sets the descriptor's options + @property + @abc.abstractmethod + def _parent(self): + pass + + def _InferLegacyFeatures(self, edition, options, features): + """Infers features from proto2/proto3 syntax so that editions logic can be used everywhere. - This function is used in generated proto2 files to update descriptor - options. It must not be used outside proto2. + Args: + edition: The edition to infer features for. + options: The options for this descriptor that are being processed. + features: The feature set object to modify with inferred features. """ - self._options = options - self._options_class_name = options_class_name + pass - # Does this descriptor have non-default options? - self.has_options = options is not None + def _GetFeatures(self): + if not self._features: + self._LazyLoadOptions() + return self._features - def GetOptions(self): - """Retrieves descriptor options. + def _ResolveFeatures(self, edition, raw_options): + """Resolves features from the raw options of this descriptor. - This method returns the options set or creates the default options for the - descriptor. + Args: + edition: The edition to use for feature defaults. + raw_options: The options for this descriptor that are being processed. + + Returns: + A fully resolved feature set for making runtime decisions. """ - if self._options: - return self._options + # pylint: disable=g-import-not-at-top + from google.protobuf import descriptor_pb2 + + if self._parent: + features = descriptor_pb2.FeatureSet() + features.CopyFrom(self._parent._GetFeatures()) + else: + features = self.file.pool._CreateDefaultFeatures(edition) + unresolved = descriptor_pb2.FeatureSet() + unresolved.CopyFrom(raw_options.features) + self._InferLegacyFeatures(edition, raw_options, unresolved) + features.MergeFrom(unresolved) + + # Use the feature cache to reduce memory bloat. + return self.file.pool._InternFeatures(features) + + def _LazyLoadOptions(self): + """Lazily initializes descriptor options towards the end of the build.""" + if self._loaded_options: + return + # pylint: disable=g-import-not-at-top from google.protobuf import descriptor_pb2 - try: - options_class = getattr(descriptor_pb2, - self._options_class_name) - except AttributeError: - raise RuntimeError('Unknown options class name %s!' % - (self._options_class_name)) - if self._serialized_options is None: + if not hasattr(descriptor_pb2, self._options_class_name): + raise RuntimeError( + 'Unknown options class name %s!' % self._options_class_name + ) + options_class = getattr(descriptor_pb2, self._options_class_name) + features = None + edition = self.file._edition + + if not self.has_options: + if not self._features: + features = self._ResolveFeatures( + descriptor_pb2.Edition.Value(edition), options_class() + ) with _lock: - self._options = options_class() + self._loaded_options = options_class() + if not self._features: + self._features = features else: - options = _ParseOptions(options_class(), self._serialized_options) + if not self._serialized_options: + options = self._options + else: + options = _ParseOptions(options_class(), self._serialized_options) + + if not self._features: + features = self._ResolveFeatures( + descriptor_pb2.Edition.Value(edition), options + ) with _lock: - self._options = options + self._loaded_options = options + if not self._features: + self._features = features + if options.HasField('features'): + options.ClearField('features') + if not options.SerializeToString(): + self._loaded_options = options_class() + self.has_options = False + + def GetOptions(self): + """Retrieves descriptor options. - return self._options + Returns: + The options set on this descriptor. + """ + if not self._loaded_options: + self._LazyLoadOptions() + return self._loaded_options class _NestedDescriptorBase(DescriptorBase): @@ -327,6 +399,7 @@ class Descriptor(_NestedDescriptorBase): self.fields = fields for field in self.fields: field.containing_type = self + field.file = file self.fields_by_number = dict((f.number, f) for f in fields) self.fields_by_name = dict((f.name, f) for f in fields) self._fields_by_camelcase_name = None @@ -353,17 +426,12 @@ class Descriptor(_NestedDescriptorBase): self.oneofs_by_name = dict((o.name, o) for o in self.oneofs) for oneof in self.oneofs: oneof.containing_type = self - self._deprecated_syntax = syntax or "proto2" + oneof.file = file self._is_map_entry = is_map_entry @property - def syntax(self): - warnings.warn( - 'descriptor.syntax is deprecated. It will be removed' - ' soon. Most usages are checking field descriptors. Consider to use' - ' has_presence, is_packed on field descriptors.' - ) - return self._deprecated_syntax + def _parent(self): + return self.containing_type or self.file @property def fields_by_camelcase_name(self): @@ -584,9 +652,9 @@ class FieldDescriptor(DescriptorBase): self.json_name = json_name self.index = index self.number = number - self.type = type + self._type = type self.cpp_type = cpp_type - self.label = label + self._label = label self.has_default_value = has_default_value self.default_value = default_value self.containing_type = containing_type @@ -603,6 +671,60 @@ class FieldDescriptor(DescriptorBase): else: self._cdescriptor = _message.default_pool.FindFieldByName(full_name) + @property + def _parent(self): + if self.containing_oneof: + return self.containing_oneof + if self.is_extension: + return self.extension_scope or self.file + return self.containing_type + + def _InferLegacyFeatures(self, edition, options, features): + # pylint: disable=g-import-not-at-top + from google.protobuf import descriptor_pb2 + + if edition >= descriptor_pb2.Edition.EDITION_2023: + return + + if self._label == FieldDescriptor.LABEL_REQUIRED: + features.field_presence = ( + descriptor_pb2.FeatureSet.FieldPresence.LEGACY_REQUIRED + ) + + if self._type == FieldDescriptor.TYPE_GROUP: + features.message_encoding = ( + descriptor_pb2.FeatureSet.MessageEncoding.DELIMITED + ) + + if options.HasField('packed'): + features.repeated_field_encoding = ( + descriptor_pb2.FeatureSet.RepeatedFieldEncoding.PACKED + if options.packed + else descriptor_pb2.FeatureSet.RepeatedFieldEncoding.EXPANDED + ) + + @property + def type(self): + if ( + self._GetFeatures().message_encoding + == _FEATURESET_MESSAGE_ENCODING_DELIMITED + ): + return FieldDescriptor.TYPE_GROUP + return self._type + + @type.setter + def type(self, val): + self._type = val + + @property + def label(self): + if ( + self._GetFeatures().field_presence + == _FEATURESET_FIELD_PRESENCE_LEGACY_REQUIRED + ): + return FieldDescriptor.LABEL_REQUIRED + return self._label + @property def camelcase_name(self): """Camelcase name of this field. @@ -626,11 +748,11 @@ class FieldDescriptor(DescriptorBase): if (self.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE or self.containing_oneof): return True - # self.containing_type is used here instead of self.file for legacy - # compatibility. FieldDescriptor.file was added in cl/153110619 - # Some old/generated code didn't link file to FieldDescriptor. - # TODO: remove syntax usage b/240619313 - return self.containing_type._deprecated_syntax == 'proto2' + + return ( + self._GetFeatures().field_presence + != _FEATURESET_FIELD_PRESENCE_IMPLICIT + ) @property def is_packed(self): @@ -643,12 +765,11 @@ class FieldDescriptor(DescriptorBase): field_type == FieldDescriptor.TYPE_MESSAGE or field_type == FieldDescriptor.TYPE_BYTES): return False - if self.containing_type._deprecated_syntax == 'proto2': - return self.has_options and self.GetOptions().packed - else: - return (not self.has_options or - not self.GetOptions().HasField('packed') or - self.GetOptions().packed) + + return ( + self._GetFeatures().repeated_field_encoding + == _FEATURESET_REPEATED_FIELD_ENCODING_PACKED + ) @staticmethod def ProtoTypeToCppProtoType(proto_type): @@ -730,6 +851,10 @@ class EnumDescriptor(_NestedDescriptorBase): # Values are reversed to ensure that the first alias is retained. self.values_by_number = dict((v.number, v) for v in reversed(values)) + @property + def _parent(self): + return self.containing_type or self.file + @property def is_closed(self): """Returns true whether this is a "closed" enum. @@ -752,7 +877,7 @@ class EnumDescriptor(_NestedDescriptorBase): Care should be taken when using this function to respect the target runtime's enum handling quirks. """ - return self.file._deprecated_syntax == 'proto2' + return self._GetFeatures().enum_type == _FEATURESET_ENUM_TYPE_CLOSED def CopyToProto(self, proto): """Copies this to a descriptor_pb2.EnumDescriptorProto. @@ -811,6 +936,10 @@ class EnumValueDescriptor(DescriptorBase): self.number = number self.type = type + @property + def _parent(self): + return self.type + class OneofDescriptor(DescriptorBase): """Descriptor for a oneof field. @@ -855,6 +984,10 @@ class OneofDescriptor(DescriptorBase): self.containing_type = containing_type self.fields = fields + @property + def _parent(self): + return self.containing_type + class ServiceDescriptor(_NestedDescriptorBase): @@ -911,6 +1044,10 @@ class ServiceDescriptor(_NestedDescriptorBase): method.file = self.file method.containing_service = self + @property + def _parent(self): + return self.file + def FindMethodByName(self, name): """Searches for the specified method, and returns its descriptor. @@ -1008,6 +1145,10 @@ class MethodDescriptor(DescriptorBase): self.client_streaming = client_streaming self.server_streaming = server_streaming + @property + def _parent(self): + return self.containing_service + def CopyToProto(self, proto): """Copies this to a descriptor_pb2.MethodDescriptorProto. @@ -1061,10 +1202,20 @@ class FileDescriptor(DescriptorBase): if _USE_C_DESCRIPTORS: _C_DESCRIPTOR_CLASS = _message.FileDescriptor - def __new__(cls, name, package, options=None, - serialized_options=None, serialized_pb=None, - dependencies=None, public_dependencies=None, - syntax=None, pool=None, create_key=None): + def __new__( + cls, + name, + package, + options=None, + serialized_options=None, + serialized_pb=None, + dependencies=None, + public_dependencies=None, + syntax=None, + edition=None, + pool=None, + create_key=None, + ): # FileDescriptor() is called from various places, not only from generated # files, to register dynamic proto files and messages. # pylint: disable=g-explicit-bool-comparison @@ -1073,18 +1224,35 @@ class FileDescriptor(DescriptorBase): else: return super(FileDescriptor, cls).__new__(cls) - def __init__(self, name, package, options=None, - serialized_options=None, serialized_pb=None, - dependencies=None, public_dependencies=None, - syntax=None, pool=None, create_key=None): + def __init__( + self, + name, + package, + options=None, + serialized_options=None, + serialized_pb=None, + dependencies=None, + public_dependencies=None, + syntax=None, + edition=None, + pool=None, + create_key=None, + ): """Constructor.""" if create_key is not _internal_create_key: _Deprecated('FileDescriptor') super(FileDescriptor, self).__init__( - None, options, serialized_options, 'FileOptions' + self, options, serialized_options, 'FileOptions' ) + if edition and edition != 'EDITION_UNKNOWN': + self._edition = edition + elif syntax == 'proto3': + self._edition = 'EDITION_PROTO3' + else: + self._edition = 'EDITION_PROTO2' + if pool is None: from google.protobuf import descriptor_pool pool = descriptor_pool.Default() @@ -1118,6 +1286,10 @@ class FileDescriptor(DescriptorBase): """ proto.ParseFromString(self.serialized_pb) + @property + def _parent(self): + return None + def _ParseOptions(message, string): """Parses serialized options. @@ -1175,8 +1347,14 @@ def _ToJsonName(name): return ''.join(result) -def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, - syntax=None): +def MakeDescriptor( + desc_proto, + package='', + build_file_if_cpp=True, + syntax=None, + edition=None, + file_desc=None, +): """Make a protobuf Descriptor given a DescriptorProto protobuf. Handles nested descriptors. Note that this is limited to the scope of defining @@ -1186,34 +1364,41 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, Args: desc_proto: The descriptor_pb2.DescriptorProto protobuf message. package: Optional package name for the new message Descriptor (string). - build_file_if_cpp: Update the C++ descriptor pool if api matches. - Set to False on recursion, so no duplicates are created. + build_file_if_cpp: Update the C++ descriptor pool if api matches. Set to + False on recursion, so no duplicates are created. syntax: The syntax/semantics that should be used. Set to "proto3" to get - proto3 field presence semantics. + proto3 field presence semantics. + edition: The edition that should be used if syntax is "edition". + file_desc: A FileDescriptor to place this descriptor into. + Returns: A Descriptor for protobuf messages. """ + # pylint: disable=g-import-not-at-top + from google.protobuf import descriptor_pb2 + + # Generate a random name for this proto file to prevent conflicts with any + # imported ones. We need to specify a file name so the descriptor pool + # accepts our FileDescriptorProto, but it is not important what that file + # name is actually set to. + proto_name = binascii.hexlify(os.urandom(16)).decode('ascii') + + if package: + file_name = os.path.join(package.replace('.', '/'), proto_name + '.proto') + else: + file_name = proto_name + '.proto' + if api_implementation.Type() != 'python' and build_file_if_cpp: # The C++ implementation requires all descriptors to be backed by the same # definition in the C++ descriptor pool. To do this, we build a # FileDescriptorProto with the same definition as this descriptor and build # it into the pool. - from google.protobuf import descriptor_pb2 file_descriptor_proto = descriptor_pb2.FileDescriptorProto() file_descriptor_proto.message_type.add().MergeFrom(desc_proto) - # Generate a random name for this proto file to prevent conflicts with any - # imported ones. We need to specify a file name so the descriptor pool - # accepts our FileDescriptorProto, but it is not important what that file - # name is actually set to. - proto_name = binascii.hexlify(os.urandom(16)).decode('ascii') - if package: - file_descriptor_proto.name = os.path.join(package.replace('.', '/'), - proto_name + '.proto') file_descriptor_proto.package = package - else: - file_descriptor_proto.name = proto_name + '.proto' + file_descriptor_proto.name = file_name _message.default_pool.Add(file_descriptor_proto) result = _message.default_pool.FindFileByName(file_descriptor_proto.name) @@ -1221,6 +1406,19 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, if _USE_C_DESCRIPTORS: return result.message_types_by_name[desc_proto.name] + if file_desc is None: + file_desc = FileDescriptor( + pool=None, + name=file_name, + package=package, + syntax=syntax, + edition=edition, + options=None, + serialized_pb='', + dependencies=[], + public_dependencies=[], + create_key=_internal_create_key, + ) full_message_name = [desc_proto.name] if package: full_message_name.insert(0, package) @@ -1229,11 +1427,21 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, for enum_proto in desc_proto.enum_type: full_name = '.'.join(full_message_name + [enum_proto.name]) enum_desc = EnumDescriptor( - enum_proto.name, full_name, None, [ - EnumValueDescriptor(enum_val.name, ii, enum_val.number, - create_key=_internal_create_key) - for ii, enum_val in enumerate(enum_proto.value)], - create_key=_internal_create_key) + enum_proto.name, + full_name, + None, + [ + EnumValueDescriptor( + enum_val.name, + ii, + enum_val.number, + create_key=_internal_create_key, + ) + for ii, enum_val in enumerate(enum_proto.value) + ], + file=file_desc, + create_key=_internal_create_key, + ) enum_types[full_name] = enum_desc # Create Descriptors for nested types @@ -1242,10 +1450,14 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, full_name = '.'.join(full_message_name + [nested_proto.name]) # Nested types are just those defined inside of the message, not all types # used by fields in the message, so no loops are possible here. - nested_desc = MakeDescriptor(nested_proto, - package='.'.join(full_message_name), - build_file_if_cpp=False, - syntax=syntax) + nested_desc = MakeDescriptor( + nested_proto, + package='.'.join(full_message_name), + build_file_if_cpp=False, + syntax=syntax, + edition=edition, + file_desc=file_desc, + ) nested_types[full_name] = nested_desc fields = [] @@ -1267,16 +1479,38 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, enum_desc = enum_types[full_type_name] # Else type_name references a non-local type, which isn't implemented field = FieldDescriptor( - field_proto.name, full_name, field_proto.number - 1, - field_proto.number, field_proto.type, + field_proto.name, + full_name, + field_proto.number - 1, + field_proto.number, + field_proto.type, FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), - field_proto.label, None, nested_desc, enum_desc, None, False, None, - options=_OptionsOrNone(field_proto), has_default_value=False, - json_name=json_name, create_key=_internal_create_key) + field_proto.label, + None, + nested_desc, + enum_desc, + None, + False, + None, + options=_OptionsOrNone(field_proto), + has_default_value=False, + json_name=json_name, + file=file_desc, + create_key=_internal_create_key, + ) fields.append(field) desc_name = '.'.join(full_message_name) - return Descriptor(desc_proto.name, desc_name, None, None, fields, - list(nested_types.values()), list(enum_types.values()), [], - options=_OptionsOrNone(desc_proto), - create_key=_internal_create_key) + return Descriptor( + desc_proto.name, + desc_name, + None, + None, + fields, + list(nested_types.values()), + list(enum_types.values()), + [], + options=_OptionsOrNone(desc_proto), + file=file_desc, + create_key=_internal_create_key, + ) diff --git a/python/google/protobuf/descriptor_pool.py b/python/google/protobuf/descriptor_pool.py index c2fe59fdcd..10ad72d3d2 100644 --- a/python/google/protobuf/descriptor_pool.py +++ b/python/google/protobuf/descriptor_pool.py @@ -35,11 +35,13 @@ directly instead of this class. __author__ = 'matthewtoia@google.com (Matt Toia)' import collections +import threading import warnings from google.protobuf import descriptor from google.protobuf import descriptor_database from google.protobuf import text_encoding +from google.protobuf.internal import python_edition_defaults from google.protobuf.internal import python_message _USE_C_DESCRIPTORS = descriptor._USE_C_DESCRIPTORS # pylint: disable=protected-access @@ -91,6 +93,8 @@ def _IsMessageSetExtension(field): field.type == descriptor.FieldDescriptor.TYPE_MESSAGE and field.label == descriptor.FieldDescriptor.LABEL_OPTIONAL) +_edition_defaults_lock = threading.Lock() + class DescriptorPool(object): """A collection of protobufs dynamically constructed by descriptor protos.""" @@ -131,6 +135,11 @@ class DescriptorPool(object): # full name or its tag number. self._extensions_by_name = collections.defaultdict(dict) self._extensions_by_number = collections.defaultdict(dict) + self._serialized_edition_defaults = ( + python_edition_defaults._PROTOBUF_INTERNAL_PYTHON_EDITION_DEFAULTS + ) + self._edition_defaults = None + self._feature_cache = dict() def _CheckConflictRegister(self, desc, desc_name, file_name): """Check if the descriptor name conflicts with another of the same name. @@ -679,6 +688,102 @@ class DescriptorPool(object): service_descriptor = self.FindServiceByName(service_name) return service_descriptor.methods_by_name[method_name] + def SetFeatureSetDefaults(self, defaults): + """Sets the default feature mappings used during the build. + + Args: + defaults: a FeatureSetDefaults message containing the new mappings. + """ + if self._edition_defaults is not None: + raise ValueError( + "Feature set defaults can't be changed once the pool has started" + ' building!' + ) + + # pylint: disable=g-import-not-at-top + from google.protobuf import descriptor_pb2 + + if defaults.minimum_edition > defaults.maximum_edition: + raise ValueError( + 'Invalid edition range %s to %s' + % ( + descriptor_pb2.Edition.Name(defaults.minimum_edition), + descriptor_pb2.Edition.Name(defaults.maximum_edition), + ) + ) + + prev_edition = descriptor_pb2.Edition.EDITION_UNKNOWN + for d in defaults.defaults: + if d.edition == descriptor_pb2.Edition.EDITION_UNKNOWN: + raise ValueError('Invalid edition EDITION_UNKNOWN specified') + if prev_edition >= d.edition: + raise ValueError('Feature set defaults are not strictly increasing') + prev_edition = d.edition + self._edition_defaults = defaults + + def _CreateDefaultFeatures(self, edition): + """Creates a FeatureSet message with defaults for a specific edition. + + Args: + edition: the edition to generate defaults for. + + Returns: + A FeatureSet message with defaults for a specific edition. + """ + # pylint: disable=g-import-not-at-top + from google.protobuf import descriptor_pb2 + + with _edition_defaults_lock: + if not self._edition_defaults: + self._edition_defaults = descriptor_pb2.FeatureSetDefaults() + self._edition_defaults.ParseFromString( + self._serialized_edition_defaults + ) + + if edition < self._edition_defaults.minimum_edition: + raise TypeError( + 'Edition %s is earlier than the minimum supported edition %s!' + % ( + descriptor_pb2.Edition.Name(edition), + descriptor_pb2.Edition.Name( + self._edition_defaults.minimum_edition + ), + ) + ) + if edition > self._edition_defaults.maximum_edition: + raise TypeError( + 'Edition %s is later than the maximum supported edition %s!' + % ( + descriptor_pb2.Edition.Name(edition), + descriptor_pb2.Edition.Name( + self._edition_defaults.maximum_edition + ), + ) + ) + found = None + for d in self._edition_defaults.defaults: + if d.edition > edition: + break + found = d.features + if found is None: + raise TypeError( + 'No valid default found for edition %s!' + % descriptor_pb2.Edition.Name(edition) + ) + + defaults = descriptor_pb2.FeatureSet() + defaults.CopyFrom(found) + return defaults + + def _InternFeatures(self, features): + serialized = features.SerializeToString() + with _edition_defaults_lock: + cached = self._feature_cache.get(serialized) + if cached is None: + self._feature_cache[serialized] = features + cached = features + return cached + def _FindFileContainingSymbolInDb(self, symbol): """Finds the file in descriptor DB containing the specified symbol. @@ -719,17 +824,22 @@ class DescriptorPool(object): direct_deps = [self.FindFileByName(n) for n in file_proto.dependency] public_deps = [direct_deps[i] for i in file_proto.public_dependency] + # pylint: disable=g-import-not-at-top + from google.protobuf import descriptor_pb2 + file_descriptor = descriptor.FileDescriptor( pool=self, name=file_proto.name, package=file_proto.package, syntax=file_proto.syntax, + edition=descriptor_pb2.Edition.Name(file_proto.edition), options=_OptionsOrNone(file_proto), serialized_pb=file_proto.SerializeToString(), dependencies=direct_deps, public_dependencies=public_deps, # pylint: disable=protected-access - create_key=descriptor._internal_create_key) + create_key=descriptor._internal_create_key, + ) scope = {} # This loop extracts all the message and enum types from all the @@ -876,10 +986,10 @@ class DescriptorPool(object): file=file_desc, serialized_start=None, serialized_end=None, - syntax=syntax, is_map_entry=desc_proto.options.map_entry, # pylint: disable=protected-access - create_key=descriptor._internal_create_key) + create_key=descriptor._internal_create_key, + ) for nested in desc.nested_types: nested.containing_type = desc for enum in desc.enum_types: diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index dd2dc32423..69fab8fd99 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -13,7 +13,12 @@ import copy import unittest import warnings +from google.protobuf import descriptor +from google.protobuf import descriptor_database from google.protobuf import descriptor_pb2 +from google.protobuf import descriptor_pool +from google.protobuf import message_factory +from google.protobuf import symbol_database from google.protobuf.internal import api_implementation from google.protobuf.internal import descriptor_pool_test1_pb2 from google.protobuf.internal import descriptor_pool_test2_pb2 @@ -23,15 +28,15 @@ from google.protobuf.internal import file_options_test_pb2 from google.protobuf.internal import more_messages_pb2 from google.protobuf.internal import no_package_pb2 from google.protobuf.internal import testing_refleaks -from google.protobuf import descriptor -from google.protobuf import descriptor_database -from google.protobuf import descriptor_pool -from google.protobuf import message_factory -from google.protobuf import symbol_database + +from google.protobuf import unittest_features_pb2 from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_import_public_pb2 from google.protobuf import unittest_pb2 +# pyformat: disable +# pyformat: enable + warnings.simplefilter('error', DeprecationWarning) @@ -1070,6 +1075,194 @@ class AddDescriptorTest(unittest.TestCase): pool._AddFileDescriptor(0) +# TODO Expand these tests to upb and C++ once the DescriptorPool +# API is unified. +@unittest.skipIf( + api_implementation.Type() != 'python', + 'Only pure python allows SetFeatureSetDefaults()', +) +@testing_refleaks.TestCase +class FeatureSetDefaults(unittest.TestCase): + + def testDefault(self): + pool = descriptor_pool.DescriptorPool() + file_desc = descriptor_pb2.FileDescriptorProto(name='some/file.proto') + file = pool.AddSerializedFile(file_desc.SerializeToString()) + self.assertFalse( + file._GetFeatures().HasExtension(unittest_features_pb2.test) + ) + + def testOverride(self): + pool = descriptor_pool.DescriptorPool() + defaults = descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO2, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ) + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + maximum_edition=descriptor_pb2.Edition.EDITION_2023, + ) + defaults.defaults[0].features.Extensions[ + unittest_features_pb2.test + ].int_file_feature = 9 + pool.SetFeatureSetDefaults(defaults) + file_desc = descriptor_pb2.FileDescriptorProto(name='some/file.proto') + file = pool.AddSerializedFile(file_desc.SerializeToString()) + self.assertTrue( + file._GetFeatures().HasExtension(unittest_features_pb2.test) + ) + + def testInvalidEditionRange(self): + pool = descriptor_pool.DescriptorPool() + with self.assertRaisesRegex(ValueError, 'Invalid edition range'): + pool.SetFeatureSetDefaults( + descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO2, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ) + ], + minimum_edition=descriptor_pb2.Edition.EDITION_2023, + maximum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + ) + ) + file_desc = descriptor_pb2.FileDescriptorProto(name='some/file.proto') + file = pool.AddSerializedFile(file_desc.SerializeToString()) + + def testNotStrictlyIncreasing(self): + pool = descriptor_pool.DescriptorPool() + with self.assertRaisesRegex(ValueError, 'not strictly increasing'): + pool.SetFeatureSetDefaults( + descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO3, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ), + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO2, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ), + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + maximum_edition=descriptor_pb2.Edition.EDITION_2023, + ) + ) + + def testUnknownEdition(self): + pool = descriptor_pool.DescriptorPool() + with self.assertRaisesRegex(ValueError, 'Invalid edition'): + pool.SetFeatureSetDefaults( + descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_UNKNOWN, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ), + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO2, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ), + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + maximum_edition=descriptor_pb2.Edition.EDITION_2023, + ) + ) + + def testChangeAfterBuild(self): + pool = descriptor_pool.DescriptorPool() + file_desc = descriptor_pb2.FileDescriptorProto(name='some/file.proto') + file = pool.AddSerializedFile(file_desc.SerializeToString()) + file._GetFeatures() + defaults = descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO2, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ) + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + maximum_edition=descriptor_pb2.Edition.EDITION_2023, + ) + with self.assertRaisesRegex(ValueError, "defaults can't be changed"): + pool.SetFeatureSetDefaults(defaults) + + def testChangeDefaultPool(self): + defaults = descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO2, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ) + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + maximum_edition=descriptor_pb2.Edition.EDITION_2023, + ) + with self.assertRaisesRegex(ValueError, "defaults can't be changed"): + descriptor_pool.Default().SetFeatureSetDefaults(defaults) + + def testNoValidFeatures(self): + pool = descriptor_pool.DescriptorPool() + defaults = descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_2023, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ) + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + maximum_edition=descriptor_pb2.Edition.EDITION_2023, + ) + pool.SetFeatureSetDefaults(defaults) + file_desc = descriptor_pb2.FileDescriptorProto(name='some/file.proto') + with self.assertRaisesRegex(TypeError, 'No valid default found'): + file = pool.AddSerializedFile(file_desc.SerializeToString()) + file._GetFeatures() + + def testBelowMinimum(self): + pool = descriptor_pool.DescriptorPool() + defaults = descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO3, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ) + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO3, + maximum_edition=descriptor_pb2.Edition.EDITION_2023, + ) + pool.SetFeatureSetDefaults(defaults) + file_desc = descriptor_pb2.FileDescriptorProto(name='some/file.proto') + with self.assertRaisesRegex(TypeError, 'earlier than the minimum'): + file = pool.AddSerializedFile(file_desc.SerializeToString()) + file._GetFeatures() + + def testAboveMaximum(self): + pool = descriptor_pool.DescriptorPool() + defaults = descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO2, + features=unittest_features_pb2.DESCRIPTOR._GetFeatures(), + ) + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + maximum_edition=descriptor_pb2.Edition.EDITION_PROTO3, + ) + pool.SetFeatureSetDefaults(defaults) + file_desc = descriptor_pb2.FileDescriptorProto( + name='some/file.proto', + syntax='editions', + edition=descriptor_pb2.Edition.EDITION_2023, + ) + with self.assertRaisesRegex(TypeError, 'later than the maximum'): + file = pool.AddSerializedFile(file_desc.SerializeToString()) + file._GetFeatures() + + TEST1_FILE = ProtoFile( 'google/protobuf/internal/descriptor_pool_test1.proto', 'google.protobuf.python.internal', diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index 56ca079f34..2e90f0f51d 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -18,12 +18,15 @@ from google.protobuf import descriptor_pool from google.protobuf import symbol_database from google.protobuf import text_format from google.protobuf.internal import api_implementation +from google.protobuf.internal import legacy_features_pb2 from google.protobuf.internal import test_util from google.protobuf.internal import _parameterized from google.protobuf import unittest_custom_options_pb2 +from google.protobuf import unittest_features_pb2 from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_pb2 +from google.protobuf import unittest_proto3_pb2 TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII = """ @@ -1215,9 +1218,13 @@ class MakeDescriptorTest(unittest.TestCase): json_names[index]) +# TODO Add _GetFeatures for upb and C++. +@unittest.skipIf( + api_implementation.Type() != 'python', + 'Features field is only available with the pure python implementation', +) class FeaturesTest(_parameterized.TestCase): - # TODO Add _features for upb and C++. @_parameterized.named_parameters([ ('File', lambda: descriptor_pb2.DESCRIPTOR), ('Message', lambda: descriptor_pb2.FeatureSet.DESCRIPTOR), @@ -1232,46 +1239,376 @@ class FeaturesTest(_parameterized.TestCase): ], ), ]) - @unittest.skipIf( - api_implementation.Type() != 'python', - 'Features field is only available with the pure python implementation', - ) def testDescriptorProtoDefaultFeatures(self, desc): self.assertEqual( - desc()._features.field_presence, + desc()._GetFeatures().field_presence, descriptor_pb2.FeatureSet.FieldPresence.EXPLICIT, ) self.assertEqual( - desc()._features.enum_type, + desc()._GetFeatures().enum_type, descriptor_pb2.FeatureSet.EnumType.CLOSED, ) self.assertEqual( - desc()._features.repeated_field_encoding, + desc()._GetFeatures().repeated_field_encoding, descriptor_pb2.FeatureSet.RepeatedFieldEncoding.EXPANDED, ) - # TODO Add _features for upb and C++. - @unittest.skipIf( - api_implementation.Type() != 'python', - 'Features field is only available with the pure python implementation', - ) def testDescriptorProtoOverrideFeatures(self): desc = descriptor_pb2.SourceCodeInfo.Location.DESCRIPTOR.fields_by_name[ 'path' ] self.assertEqual( - desc._features.field_presence, + desc._GetFeatures().field_presence, descriptor_pb2.FeatureSet.FieldPresence.EXPLICIT, ) self.assertEqual( - desc._features.enum_type, + desc._GetFeatures().enum_type, descriptor_pb2.FeatureSet.EnumType.CLOSED, ) self.assertEqual( - desc._features.repeated_field_encoding, + desc._GetFeatures().repeated_field_encoding, + descriptor_pb2.FeatureSet.RepeatedFieldEncoding.PACKED, + ) + + def testFeaturesStripped(self): + desc = legacy_features_pb2.TestEditionsMessage.DESCRIPTOR.fields_by_name[ + 'required_field' + ] + self.assertFalse(desc.GetOptions().HasField('features')) + + def testLegacyRequiredTransform(self): + desc = legacy_features_pb2.TestEditionsMessage.DESCRIPTOR + self.assertEqual( + desc.fields_by_name['required_field'].label, + descriptor.FieldDescriptor.LABEL_REQUIRED, + ) + + def testLegacyGroupTransform(self): + desc = legacy_features_pb2.TestEditionsMessage.DESCRIPTOR + self.assertEqual( + desc.fields_by_name['delimited_field'].type, + descriptor.FieldDescriptor.TYPE_GROUP, + ) + + def testLegacyInferRequired(self): + desc = unittest_pb2.TestRequired.DESCRIPTOR.fields_by_name['a'] + self.assertEqual( + desc._GetFeatures().field_presence, + descriptor_pb2.FeatureSet.FieldPresence.LEGACY_REQUIRED, + ) + + def testLegacyInferGroup(self): + desc = unittest_pb2.TestAllTypes.DESCRIPTOR.fields_by_name['optionalgroup'] + self.assertEqual( + desc._GetFeatures().message_encoding, + descriptor_pb2.FeatureSet.MessageEncoding.DELIMITED, + ) + + def testLegacyInferProto2Packed(self): + desc = unittest_pb2.TestPackedTypes.DESCRIPTOR.fields_by_name[ + 'packed_int32' + ] + self.assertEqual( + desc._GetFeatures().repeated_field_encoding, descriptor_pb2.FeatureSet.RepeatedFieldEncoding.PACKED, ) + def testLegacyInferProto3Expanded(self): + desc = unittest_proto3_pb2.TestUnpackedTypes.DESCRIPTOR.fields_by_name[ + 'repeated_int32' + ] + self.assertEqual( + desc._GetFeatures().repeated_field_encoding, + descriptor_pb2.FeatureSet.RepeatedFieldEncoding.EXPANDED, + ) + + def testProto2Defaults(self): + features = unittest_pb2.TestAllTypes.DESCRIPTOR.fields_by_name[ + 'optional_int32' + ]._GetFeatures() + fs = descriptor_pb2.FeatureSet + self.assertEqual(features.field_presence, fs.FieldPresence.EXPLICIT) + self.assertEqual(features.enum_type, fs.EnumType.CLOSED) + self.assertEqual( + features.repeated_field_encoding, fs.RepeatedFieldEncoding.EXPANDED + ) + self.assertEqual(features.utf8_validation, fs.Utf8Validation.NONE) + self.assertEqual( + features.message_encoding, fs.MessageEncoding.LENGTH_PREFIXED + ) + self.assertEqual(features.json_format, fs.JsonFormat.LEGACY_BEST_EFFORT) + + def testProto3Defaults(self): + features = unittest_proto3_pb2.TestAllTypes.DESCRIPTOR.fields_by_name[ + 'optional_int32' + ]._GetFeatures() + fs = descriptor_pb2.FeatureSet + self.assertEqual(features.field_presence, fs.FieldPresence.IMPLICIT) + self.assertEqual(features.enum_type, fs.EnumType.OPEN) + self.assertEqual( + features.repeated_field_encoding, fs.RepeatedFieldEncoding.PACKED + ) + self.assertEqual(features.utf8_validation, fs.Utf8Validation.VERIFY) + self.assertEqual( + features.message_encoding, fs.MessageEncoding.LENGTH_PREFIXED + ) + self.assertEqual(features.json_format, fs.JsonFormat.ALLOW) + + +def GetTestFeature(desc): + return ( + desc._GetFeatures() + .Extensions[unittest_features_pb2.test] + .int_multiple_feature + ) + + +def SetTestFeature(proto, value): + proto.options.features.Extensions[ + unittest_features_pb2.test + ].int_multiple_feature = value + + +# TODO Add _GetFeatures for upb and C++. +@unittest.skipIf( + api_implementation.Type() != 'python', + 'Features field is only available with the pure python implementation', +) +class FeatureInheritanceTest(unittest.TestCase): + + def setUp(self): + super().setUp() + self.file_proto = descriptor_pb2.FileDescriptorProto( + name='some/filename/some.proto', + package='protobuf_unittest', + edition=descriptor_pb2.Edition.EDITION_2023, + syntax='editions', + ) + self.top_extension_proto = self.file_proto.extension.add( + name='top_extension', + number=10, + type=descriptor_pb2.FieldDescriptorProto.TYPE_INT32, + label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL, + extendee='.protobuf_unittest.TopMessage', + ) + self.top_enum_proto = self.file_proto.enum_type.add(name='TopEnum') + self.enum_value_proto = self.top_enum_proto.value.add( + name='TOP_VALUE', number=0 + ) + self.top_message_proto = self.file_proto.message_type.add(name='TopMessage') + self.field_proto = self.top_message_proto.field.add( + name='field', + number=1, + type=descriptor_pb2.FieldDescriptorProto.TYPE_INT32, + label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL, + ) + self.top_message_proto.extension_range.add(start=10, end=20) + self.nested_extension_proto = self.top_message_proto.extension.add( + name='nested_extension', + number=11, + type=descriptor_pb2.FieldDescriptorProto.TYPE_INT32, + label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL, + extendee='.protobuf_unittest.TopMessage', + ) + self.nested_message_proto = self.top_message_proto.nested_type.add( + name='NestedMessage' + ) + self.nested_enum_proto = self.top_message_proto.enum_type.add( + name='NestedEnum' + ) + self.nested_enum_proto.value.add(name='NESTED_VALUE', number=0) + self.oneof_proto = self.top_message_proto.oneof_decl.add(name='Oneof') + self.oneof_field_proto = self.top_message_proto.field.add( + name='oneof_field', + number=2, + type=descriptor_pb2.FieldDescriptorProto.TYPE_INT32, + label=descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL, + oneof_index=0, + ) + + self.service_proto = self.file_proto.service.add(name='TestService') + self.method_proto = self.service_proto.method.add( + name='CallMethod', + input_type='.protobuf_unittest.TopMessage', + output_type='.protobuf_unittest.TopMessage', + ) + + def BuildPool(self): + pool = descriptor_pool.DescriptorPool() + defaults = descriptor_pb2.FeatureSetDefaults( + defaults=[ + descriptor_pb2.FeatureSetDefaults.FeatureSetEditionDefault( + edition=descriptor_pb2.Edition.EDITION_PROTO2, + features=unittest_pb2.TestAllTypes.DESCRIPTOR._GetFeatures(), + ) + ], + minimum_edition=descriptor_pb2.Edition.EDITION_PROTO2, + maximum_edition=descriptor_pb2.Edition.EDITION_2023, + ) + defaults.defaults[0].features.Extensions[ + unittest_features_pb2.test + ].int_multiple_feature = 1 + pool.SetFeatureSetDefaults(defaults) + + self.file = pool.AddSerializedFile(self.file_proto.SerializeToString()) + self.top_message = pool.FindMessageTypeByName('protobuf_unittest.TopMessage') + self.top_enum = pool.FindEnumTypeByName('protobuf_unittest.TopEnum') + self.top_extension = pool.FindExtensionByName( + 'protobuf_unittest.top_extension' + ) + self.nested_message = self.top_message.nested_types_by_name['NestedMessage'] + self.nested_enum = self.top_message.enum_types_by_name['NestedEnum'] + self.nested_extension = self.top_message.extensions_by_name[ + 'nested_extension' + ] + self.field = self.top_message.fields_by_name['field'] + self.oneof = self.top_message.oneofs_by_name['Oneof'] + self.oneof_field = self.top_message.fields_by_name['oneof_field'] + self.enum_value = self.top_enum.values_by_name['TOP_VALUE'] + self.service = pool.FindServiceByName('protobuf_unittest.TestService') + self.method = self.service.methods_by_name['CallMethod'] + + def testFileDefaults(self): + self.BuildPool() + self.assertEqual(GetTestFeature(self.file), 1) + + def testFileOverride(self): + SetTestFeature(self.file_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.file), 3) + + def testFileMessageInherit(self): + SetTestFeature(self.file_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.top_message), 3) + + def testFileMessageOverride(self): + SetTestFeature(self.file_proto, 3) + SetTestFeature(self.top_message_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.top_message), 5) + + def testFileEnumInherit(self): + SetTestFeature(self.file_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.top_enum), 3) + + def testFileEnumOverride(self): + SetTestFeature(self.file_proto, 3) + SetTestFeature(self.top_enum_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.top_enum), 5) + + def testFileExtensionInherit(self): + SetTestFeature(self.file_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.top_extension), 3) + + def testFileExtensionOverride(self): + SetTestFeature(self.file_proto, 3) + SetTestFeature(self.top_extension_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.top_extension), 5) + + def testFileServiceInherit(self): + SetTestFeature(self.file_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.service), 3) + + def testFileServiceOverride(self): + SetTestFeature(self.file_proto, 3) + SetTestFeature(self.service_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.service), 5) + + def testMessageFieldInherit(self): + SetTestFeature(self.top_message_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.field), 3) + + def testMessageFieldOverride(self): + SetTestFeature(self.top_message_proto, 3) + SetTestFeature(self.field_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.field), 5) + + def testMessageEnumInherit(self): + SetTestFeature(self.top_message_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.nested_enum), 3) + + def testMessageEnumOverride(self): + SetTestFeature(self.top_message_proto, 3) + SetTestFeature(self.nested_enum_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.nested_enum), 5) + + def testMessageMessageInherit(self): + SetTestFeature(self.top_message_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.nested_message), 3) + + def testMessageMessageOverride(self): + SetTestFeature(self.top_message_proto, 3) + SetTestFeature(self.nested_message_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.nested_message), 5) + + def testMessageExtensionInherit(self): + SetTestFeature(self.top_message_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.nested_extension), 3) + + def testMessageExtensionOverride(self): + SetTestFeature(self.top_message_proto, 3) + SetTestFeature(self.nested_extension_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.nested_extension), 5) + + def testMessageOneofInherit(self): + SetTestFeature(self.top_message_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.oneof), 3) + + def testMessageOneofOverride(self): + SetTestFeature(self.top_message_proto, 3) + SetTestFeature(self.oneof_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.oneof), 5) + + def testOneofFieldInherit(self): + SetTestFeature(self.oneof_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.oneof_field), 3) + + def testOneofFieldOverride(self): + SetTestFeature(self.oneof_proto, 3) + SetTestFeature(self.oneof_field_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.oneof_field), 5) + + def testEnumValueInherit(self): + SetTestFeature(self.top_enum_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.enum_value), 3) + + def testEnumValueOverride(self): + SetTestFeature(self.top_enum_proto, 3) + SetTestFeature(self.enum_value_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.enum_value), 5) + + def testServiceMethodInherit(self): + SetTestFeature(self.service_proto, 3) + self.BuildPool() + self.assertEqual(GetTestFeature(self.method), 3) + + def testServiceMethodOverride(self): + SetTestFeature(self.service_proto, 3) + SetTestFeature(self.method_proto, 5) + self.BuildPool() + self.assertEqual(GetTestFeature(self.method), 5) + if __name__ == '__main__': unittest.main() diff --git a/python/google/protobuf/internal/legacy_features.proto b/python/google/protobuf/internal/legacy_features.proto new file mode 100644 index 0000000000..ef803ddbad --- /dev/null +++ b/python/google/protobuf/internal/legacy_features.proto @@ -0,0 +1,18 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +// Test that features with legacy descriptor helpers get properly converted. + +edition = "2023"; + +package google.protobuf.internal; + +message TestEditionsMessage { + int32 required_field = 1 [features.field_presence = LEGACY_REQUIRED]; + TestEditionsMessage delimited_field = 2 + [features.message_encoding = DELIMITED]; +} diff --git a/python/google/protobuf/internal/python_edition_defaults.py.template b/python/google/protobuf/internal/python_edition_defaults.py.template new file mode 100644 index 0000000000..56bdf042e6 --- /dev/null +++ b/python/google/protobuf/internal/python_edition_defaults.py.template @@ -0,0 +1,5 @@ +""" +This file contains the serialized FeatureSetDefaults object corresponding to +the Pure Python runtime. This is used for feature resolution under Editions. +""" +_PROTOBUF_INTERNAL_PYTHON_EDITION_DEFAULTS = b"DEFAULTS_VALUE" diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index 45afef2a93..a03b8171c4 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -163,8 +163,7 @@ cc_binary( ], copts = COPTS, visibility = [ - "//src/google/protobuf:__subpackages__", - "//upb:__subpackages__", + "//:__subpackages__", ], deps = [ ":command_line_interface", diff --git a/src/google/protobuf/compiler/python/generator.cc b/src/google/protobuf/compiler/python/generator.cc index 3f3410e3cd..e34a7be015 100644 --- a/src/google/protobuf/compiler/python/generator.cc +++ b/src/google/protobuf/compiler/python/generator.cc @@ -21,9 +21,7 @@ #include "google/protobuf/compiler/python/generator.h" -#include #include -#include #include #include #include @@ -160,16 +158,21 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) { return ""; } +// Returns a CEscaped string of serialized_options. +std::string OptionsValue(absl::string_view serialized_options) { + if (serialized_options.empty()) { + return "None"; + } else { + return absl::StrCat("b'", absl::CEscape(serialized_options), "'"); + } +} + } // namespace Generator::Generator() : file_(nullptr) {} Generator::~Generator() {} -uint64_t Generator::GetSupportedFeatures() const { - return CodeGenerator::Feature::FEATURE_PROTO3_OPTIONAL; -} - GeneratorOptions Generator::ParseParameter(absl::string_view parameter, std::string* error) const { GeneratorOptions options; @@ -231,8 +234,8 @@ bool Generator::Generate(const FileDescriptor* file, std::string filename = GetFileName(file, ".py"); - FileDescriptorProto fdp = StripSourceRetentionOptions(*file_); - fdp.SerializeToString(&file_descriptor_serialized_); + proto_ = StripSourceRetentionOptions(*file_); + proto_.SerializeToString(&file_descriptor_serialized_); if (!opensource_runtime_ && GeneratingDescriptorProto()) { std::string bootstrap_filename = @@ -320,7 +323,7 @@ bool Generator::Generate(const FileDescriptor* file, FixAllDescriptorOptions(); // Set serialized_start and serialized_end. - SetSerializedPbInterval(fdp); + SetSerializedPbInterval(proto_); printer_->Outdent(); if (HasGenericServices(file)) { @@ -533,8 +536,8 @@ void Generator::PrintFileDescriptor() const { m["package"] = file_->package(); m["syntax"] = std::string( FileDescriptorLegacy::SyntaxName(FileDescriptorLegacy(file_).syntax())); - m["options"] = OptionsValue( - StripLocalSourceRetentionOptions(*file_).SerializeAsString()); + m["edition"] = Edition_Name(file_->edition()); + m["options"] = OptionsValue(proto_.options().SerializeAsString()); m["serialized_descriptor"] = absl::CHexEscape(file_descriptor_serialized_); if (GeneratingDescriptorProto()) { printer_->Print("if _descriptor._USE_C_DESCRIPTORS == False:\n"); @@ -547,6 +550,7 @@ void Generator::PrintFileDescriptor() const { " name='$name$',\n" " package='$package$',\n" " syntax='$syntax$',\n" + " edition='$edition$',\n" " serialized_options=$options$,\n" " create_key=_descriptor._internal_create_key,\n"; printer_->Print(m, file_descriptor_template); @@ -596,17 +600,18 @@ void Generator::PrintFileDescriptor() const { // Prints all enums contained in all message types in |file|. void Generator::PrintAllEnumsInFile() const { for (int i = 0; i < file_->enum_type_count(); ++i) { - PrintEnum(*file_->enum_type(i)); + PrintEnum(*file_->enum_type(i), proto_.enum_type(i)); } for (int i = 0; i < file_->message_type_count(); ++i) { - PrintNestedEnums(*file_->message_type(i)); + PrintNestedEnums(*file_->message_type(i), proto_.message_type(i)); } } // Prints a Python statement assigning the appropriate module-level // enum name to a Python EnumDescriptor object equivalent to // enum_descriptor. -void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const { +void Generator::PrintEnum(const EnumDescriptor& enum_descriptor, + const EnumDescriptorProto& proto) const { absl::flat_hash_map m; std::string module_level_descriptor_name = ModuleLevelDescriptorName(enum_descriptor); @@ -623,14 +628,13 @@ void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const { " create_key=_descriptor._internal_create_key,\n" " values=[\n"; std::string options_string; - StripLocalSourceRetentionOptions(enum_descriptor) - .SerializeToString(&options_string); + proto.options().SerializeToString(&options_string); printer_->Print(m, enum_descriptor_template); printer_->Indent(); printer_->Indent(); for (int i = 0; i < enum_descriptor.value_count(); ++i) { - PrintEnumValueDescriptor(*enum_descriptor.value(i)); + PrintEnumValueDescriptor(*enum_descriptor.value(i), proto.value(i)); printer_->Print(",\n"); } @@ -649,20 +653,21 @@ void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const { // Recursively prints enums in nested types within descriptor, then // prints enums contained at the top level in descriptor. -void Generator::PrintNestedEnums(const Descriptor& descriptor) const { +void Generator::PrintNestedEnums(const Descriptor& descriptor, + const DescriptorProto& proto) const { for (int i = 0; i < descriptor.nested_type_count(); ++i) { - PrintNestedEnums(*descriptor.nested_type(i)); + PrintNestedEnums(*descriptor.nested_type(i), proto.nested_type(i)); } for (int i = 0; i < descriptor.enum_type_count(); ++i) { - PrintEnum(*descriptor.enum_type(i)); + PrintEnum(*descriptor.enum_type(i), proto.enum_type(i)); } } // Prints Python equivalents of all Descriptors in |file|. void Generator::PrintMessageDescriptors() const { for (int i = 0; i < file_->message_type_count(); ++i) { - PrintDescriptor(*file_->message_type(i)); + PrintDescriptor(*file_->message_type(i), proto_.message_type(i)); printer_->Print("\n"); } } @@ -732,13 +737,14 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { // to a Python Descriptor object for message_descriptor. // // Mutually recursive with PrintNestedDescriptors(). -void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { +void Generator::PrintDescriptor(const Descriptor& message_descriptor, + const DescriptorProto& proto) const { absl::flat_hash_map m; m["name"] = message_descriptor.name(); m["full_name"] = message_descriptor.full_name(); m["file"] = kDescriptorKey; - PrintNestedDescriptors(message_descriptor); + PrintNestedDescriptors(message_descriptor, proto); printer_->Print("\n"); printer_->Print("$descriptor_name$ = _descriptor.Descriptor(\n", @@ -753,8 +759,8 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { "containing_type=None,\n" "create_key=_descriptor._internal_create_key,\n"; printer_->Print(m, required_function_arguments); - PrintFieldsInDescriptor(message_descriptor); - PrintExtensionsInDescriptor(message_descriptor); + PrintFieldsInDescriptor(message_descriptor, proto); + PrintExtensionsInDescriptor(message_descriptor, proto); // Nested types printer_->Print("nested_types=["); @@ -777,16 +783,12 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { printer_->Outdent(); printer_->Print("],\n"); std::string options_string; - StripLocalSourceRetentionOptions(message_descriptor) - .SerializeToString(&options_string); + proto.options().SerializeToString(&options_string); printer_->Print( "serialized_options=$options_value$,\n" - "is_extendable=$extendable$,\n" - "syntax='$syntax$'", + "is_extendable=$extendable$", "options_value", OptionsValue(options_string), "extendable", - message_descriptor.extension_range_count() > 0 ? "True" : "False", - "syntax", - FileDescriptorLegacy::SyntaxName(FileDescriptorLegacy(file_).syntax())); + message_descriptor.extension_range_count() > 0 ? "True" : "False"); printer_->Print(",\n"); // Extension ranges @@ -807,8 +809,8 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { m["name"] = desc->name(); m["full_name"] = desc->full_name(); m["index"] = absl::StrCat(desc->index()); - options_string = OptionsValue( - StripLocalSourceRetentionOptions(*desc).SerializeAsString()); + options_string = + OptionsValue(proto.oneof_decl(i).options().SerializeAsString()); if (options_string == "None") { m["serialized_options"] = ""; } else { @@ -833,10 +835,11 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { // message_descriptor. // // Mutually recursive with PrintDescriptor(). -void Generator::PrintNestedDescriptors( - const Descriptor& containing_descriptor) const { +void Generator::PrintNestedDescriptors(const Descriptor& containing_descriptor, + const DescriptorProto& proto) const { for (int i = 0; i < containing_descriptor.nested_type_count(); ++i) { - PrintDescriptor(*containing_descriptor.nested_type(i)); + PrintDescriptor(*containing_descriptor.nested_type(i), + proto.nested_type(i)); } } @@ -1103,12 +1106,12 @@ void Generator::FixForeignFieldsInDescriptors() const { // Returns a Python expression that instantiates a Python EnumValueDescriptor // object for the given C++ descriptor. void Generator::PrintEnumValueDescriptor( - const EnumValueDescriptor& descriptor) const { + const EnumValueDescriptor& descriptor, + const EnumValueDescriptorProto& proto) const { // TODO: Fix up EnumValueDescriptor "type" fields. // More circular references. ::sigh:: std::string options_string; - StripLocalSourceRetentionOptions(descriptor) - .SerializeToString(&options_string); + proto.options().SerializeToString(&options_string); absl::flat_hash_map m; m["name"] = descriptor.name(); m["index"] = absl::StrCat(descriptor.index()); @@ -1122,21 +1125,11 @@ void Generator::PrintEnumValueDescriptor( " create_key=_descriptor._internal_create_key)"); } -// Returns a CEscaped string of serialized_options. -std::string Generator::OptionsValue( - absl::string_view serialized_options) const { - if (serialized_options.length() == 0) { - return "None"; - } else { - return absl::StrCat("b'", absl::CEscape(serialized_options), "'"); - } -} - // Prints an expression for a Python FieldDescriptor for |field|. void Generator::PrintFieldDescriptor(const FieldDescriptor& field, - bool is_extension) const { + const FieldDescriptorProto& proto) const { std::string options_string; - StripLocalSourceRetentionOptions(field).SerializeToString(&options_string); + proto.options().SerializeToString(&options_string); absl::flat_hash_map m; m["name"] = field.name(); m["full_name"] = field.full_name(); @@ -1147,7 +1140,7 @@ void Generator::PrintFieldDescriptor(const FieldDescriptor& field, m["label"] = absl::StrCat(field.label()); m["has_default_value"] = field.has_default_value() ? "True" : "False"; m["default_value"] = StringifyDefaultValue(field); - m["is_extension"] = is_extension ? "True" : "False"; + m["is_extension"] = field.is_extension() ? "True" : "False"; m["serialized_options"] = OptionsValue(options_string); m["json_name"] = field.has_json_name() ? absl::StrCat(", json_name='", field.json_name(), "'") @@ -1170,13 +1163,16 @@ void Generator::PrintFieldDescriptor(const FieldDescriptor& field, // Helper for Print{Fields,Extensions}InDescriptor(). void Generator::PrintFieldDescriptorsInDescriptor( - const Descriptor& message_descriptor, bool is_extension, - absl::string_view list_variable_name, int (Descriptor::*CountFn)() const, - const FieldDescriptor* (Descriptor::*GetterFn)(int) const) const { + const Descriptor& message_descriptor, const DescriptorProto& proto, + bool is_extension, absl::string_view list_variable_name) const { printer_->Print("$list$=[\n", "list", list_variable_name); printer_->Indent(); - for (int i = 0; i < (message_descriptor.*CountFn)(); ++i) { - PrintFieldDescriptor(*(message_descriptor.*GetterFn)(i), is_extension); + int count = is_extension ? message_descriptor.extension_count() + : message_descriptor.field_count(); + for (int i = 0; i < count; ++i) { + PrintFieldDescriptor(is_extension ? *message_descriptor.extension(i) + : *message_descriptor.field(i), + is_extension ? proto.extension(i) : proto.field(i)); printer_->Print(",\n"); } printer_->Outdent(); @@ -1185,22 +1181,20 @@ void Generator::PrintFieldDescriptorsInDescriptor( // Prints a statement assigning "fields" to a list of Python FieldDescriptors, // one for each field present in message_descriptor. -void Generator::PrintFieldsInDescriptor( - const Descriptor& message_descriptor) const { +void Generator::PrintFieldsInDescriptor(const Descriptor& message_descriptor, + const DescriptorProto& proto) const { const bool is_extension = false; - PrintFieldDescriptorsInDescriptor(message_descriptor, is_extension, "fields", - &Descriptor::field_count, - &Descriptor::field); + PrintFieldDescriptorsInDescriptor(message_descriptor, proto, is_extension, + "fields"); } // Prints a statement assigning "extensions" to a list of Python // FieldDescriptors, one for each extension present in message_descriptor. void Generator::PrintExtensionsInDescriptor( - const Descriptor& message_descriptor) const { + const Descriptor& message_descriptor, const DescriptorProto& proto) const { const bool is_extension = true; - PrintFieldDescriptorsInDescriptor(message_descriptor, is_extension, - "extensions", &Descriptor::extension_count, - &Descriptor::extension); + PrintFieldDescriptorsInDescriptor(message_descriptor, proto, is_extension, + "extensions"); } bool Generator::GeneratingDescriptorProto() const { @@ -1287,9 +1281,9 @@ void Generator::PrintSerializedPbInterval( template bool Generator::PrintDescriptorOptionsFixingCode( - const DescriptorT& descriptor, absl::string_view descriptor_str) const { - std::string options = OptionsValue( - StripLocalSourceRetentionOptions(descriptor).SerializeAsString()); + const DescriptorT& descriptor, const typename DescriptorT::Proto& proto, + absl::string_view descriptor_str) const { + std::string options = OptionsValue(proto.options().SerializeAsString()); // Reset the _options to None thus DescriptorBase.GetOptions() can // parse _options again after extensions are registered. @@ -1308,7 +1302,7 @@ bool Generator::PrintDescriptorOptionsFixingCode( } printer_->Print( - "$descriptor_name$._options = None\n" + "$descriptor_name$._loaded_options = None\n" "$descriptor_name$._serialized_options = $serialized_value$\n", "descriptor_name", descriptor_name, "serialized_value", options); return true; @@ -1362,46 +1356,46 @@ void Generator::SetMessagePbInterval(const DescriptorProto& message_proto, // Prints expressions that set the options field of all descriptors. void Generator::FixAllDescriptorOptions() const { // Prints an expression that sets the file descriptor's options. - if (!PrintDescriptorOptionsFixingCode(*file_, kDescriptorKey)) { - printer_->Print("DESCRIPTOR._options = None\n"); + if (!PrintDescriptorOptionsFixingCode(*file_, proto_, kDescriptorKey)) { + printer_->Print("DESCRIPTOR._loaded_options = None\n"); } // Prints expressions that set the options for all top level enums. for (int i = 0; i < file_->enum_type_count(); ++i) { - const EnumDescriptor& enum_descriptor = *file_->enum_type(i); - FixOptionsForEnum(enum_descriptor); + FixOptionsForEnum(*file_->enum_type(i), proto_.enum_type(i)); } // Prints expressions that set the options for all top level extensions. for (int i = 0; i < file_->extension_count(); ++i) { - const FieldDescriptor& field = *file_->extension(i); - FixOptionsForField(field); + FixOptionsForField(*file_->extension(i), proto_.extension(i)); } // Prints expressions that set the options for all messages, nested enums, // nested extensions and message fields. for (int i = 0; i < file_->message_type_count(); ++i) { - FixOptionsForMessage(*file_->message_type(i)); + FixOptionsForMessage(*file_->message_type(i), proto_.message_type(i)); } for (int i = 0; i < file_->service_count(); ++i) { - FixOptionsForService(*file_->service(i)); + FixOptionsForService(*file_->service(i), proto_.service(i)); } } -void Generator::FixOptionsForOneof(const OneofDescriptor& oneof) const { +void Generator::FixOptionsForOneof(const OneofDescriptor& oneof, + const OneofDescriptorProto& proto) const { std::string oneof_name = absl::Substitute( "$0.$1['$2']", ModuleLevelDescriptorName(*oneof.containing_type()), "oneofs_by_name", oneof.name()); - PrintDescriptorOptionsFixingCode(oneof, oneof_name); + PrintDescriptorOptionsFixingCode(oneof, proto, oneof_name); } // Prints expressions that set the options for an enum descriptor and its // value descriptors. -void Generator::FixOptionsForEnum(const EnumDescriptor& enum_descriptor) const { +void Generator::FixOptionsForEnum(const EnumDescriptor& enum_descriptor, + const EnumDescriptorProto& proto) const { std::string descriptor_name = ModuleLevelDescriptorName(enum_descriptor); - PrintDescriptorOptionsFixingCode(enum_descriptor, descriptor_name); + PrintDescriptorOptionsFixingCode(enum_descriptor, proto, descriptor_name); for (int i = 0; i < enum_descriptor.value_count(); ++i) { const EnumValueDescriptor& value_descriptor = *enum_descriptor.value(i); PrintDescriptorOptionsFixingCode( - value_descriptor, + value_descriptor, proto.value(i), absl::StrFormat("%s.values_by_name[\"%s\"]", descriptor_name.c_str(), value_descriptor.name().c_str())); } @@ -1410,22 +1404,24 @@ void Generator::FixOptionsForEnum(const EnumDescriptor& enum_descriptor) const { // Prints expressions that set the options for an service descriptor and its // value descriptors. void Generator::FixOptionsForService( - const ServiceDescriptor& service_descriptor) const { + const ServiceDescriptor& service_descriptor, + const ServiceDescriptorProto& proto) const { std::string descriptor_name = ModuleLevelServiceDescriptorName(service_descriptor); - PrintDescriptorOptionsFixingCode(service_descriptor, descriptor_name); + PrintDescriptorOptionsFixingCode(service_descriptor, proto, descriptor_name); for (int i = 0; i < service_descriptor.method_count(); ++i) { const MethodDescriptor* method = service_descriptor.method(i); - PrintDescriptorOptionsFixingCode( - *method, absl::StrCat(descriptor_name, ".methods_by_name['", - method->name(), "']")); + std::string method_name = absl::StrCat( + descriptor_name, ".methods_by_name['", method->name(), "']"); + PrintDescriptorOptionsFixingCode(*method, proto.method(i), method_name); } } // Prints expressions that set the options for field descriptors (including // extensions). -void Generator::FixOptionsForField(const FieldDescriptor& field) const { +void Generator::FixOptionsForField(const FieldDescriptor& field, + const FieldDescriptorProto& proto) const { std::string field_name; if (field.is_extension()) { if (field.extension_scope() == nullptr) { @@ -1439,36 +1435,37 @@ void Generator::FixOptionsForField(const FieldDescriptor& field) const { field_name = FieldReferencingExpression(field.containing_type(), field, "fields_by_name"); } - PrintDescriptorOptionsFixingCode(field, field_name); + PrintDescriptorOptionsFixingCode(field, proto, field_name); } // Prints expressions that set the options for a message and all its inner // types (nested messages, nested enums, extensions, fields). -void Generator::FixOptionsForMessage(const Descriptor& descriptor) const { +void Generator::FixOptionsForMessage(const Descriptor& descriptor, + const DescriptorProto& proto) const { // Nested messages. for (int i = 0; i < descriptor.nested_type_count(); ++i) { - FixOptionsForMessage(*descriptor.nested_type(i)); + FixOptionsForMessage(*descriptor.nested_type(i), proto.nested_type(i)); } // Oneofs. for (int i = 0; i < descriptor.oneof_decl_count(); ++i) { - FixOptionsForOneof(*descriptor.oneof_decl(i)); + FixOptionsForOneof(*descriptor.oneof_decl(i), proto.oneof_decl(i)); } // Enums. for (int i = 0; i < descriptor.enum_type_count(); ++i) { - FixOptionsForEnum(*descriptor.enum_type(i)); + FixOptionsForEnum(*descriptor.enum_type(i), proto.enum_type(i)); } // Fields. for (int i = 0; i < descriptor.field_count(); ++i) { const FieldDescriptor& field = *descriptor.field(i); - FixOptionsForField(field); + FixOptionsForField(field, proto.field(i)); } // Extensions. for (int i = 0; i < descriptor.extension_count(); ++i) { const FieldDescriptor& field = *descriptor.extension(i); - FixOptionsForField(field); + FixOptionsForField(field, proto.extension(i)); } // Message option for this message. - PrintDescriptorOptionsFixingCode(descriptor, + PrintDescriptorOptionsFixingCode(descriptor, proto, ModuleLevelDescriptorName(descriptor)); } diff --git a/src/google/protobuf/compiler/python/generator.h b/src/google/protobuf/compiler/python/generator.h index c5beeeea35..531c44a349 100644 --- a/src/google/protobuf/compiler/python/generator.h +++ b/src/google/protobuf/compiler/python/generator.h @@ -65,7 +65,14 @@ class PROTOC_EXPORT Generator : public CodeGenerator { GeneratorContext* generator_context, std::string* error) const override; - uint64_t GetSupportedFeatures() const override; + uint64_t GetSupportedFeatures() const override { + return Feature::FEATURE_PROTO3_OPTIONAL; + } + Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; } + Edition GetMaximumEdition() const override { return Edition::EDITION_2023; } + std::vector GetFeatureExtensions() const override { + return {}; + } void set_opensource_runtime(bool opensource) { opensource_runtime_ = opensource; @@ -80,20 +87,25 @@ class PROTOC_EXPORT Generator : public CodeGenerator { void PrintResolvedFeatures() const; void PrintFileDescriptor() const; void PrintAllEnumsInFile() const; - void PrintNestedEnums(const Descriptor& descriptor) const; - void PrintEnum(const EnumDescriptor& enum_descriptor) const; + void PrintNestedEnums(const Descriptor& descriptor, + const DescriptorProto& proto) const; + void PrintEnum(const EnumDescriptor& enum_descriptor, + const EnumDescriptorProto& proto) const; void PrintFieldDescriptor(const FieldDescriptor& field, - bool is_extension) const; + const FieldDescriptorProto& proto) const; void PrintFieldDescriptorsInDescriptor( - const Descriptor& message_descriptor, bool is_extension, - absl::string_view list_variable_name, int (Descriptor::*CountFn)() const, - const FieldDescriptor* (Descriptor::*GetterFn)(int) const) const; - void PrintFieldsInDescriptor(const Descriptor& message_descriptor) const; - void PrintExtensionsInDescriptor(const Descriptor& message_descriptor) const; + const Descriptor& message_descriptor, const DescriptorProto& proto, + bool is_extension, absl::string_view list_variable_name) const; + void PrintFieldsInDescriptor(const Descriptor& message_descriptor, + const DescriptorProto& proto) const; + void PrintExtensionsInDescriptor(const Descriptor& message_descriptor, + const DescriptorProto& proto) const; void PrintMessageDescriptors() const; - void PrintDescriptor(const Descriptor& message_descriptor) const; - void PrintNestedDescriptors(const Descriptor& containing_descriptor) const; + void PrintDescriptor(const Descriptor& message_descriptor, + const DescriptorProto& proto) const; + void PrintNestedDescriptors(const Descriptor& containing_descriptor, + const DescriptorProto& proto) const; void PrintMessages() const; void PrintMessage(const Descriptor& message_descriptor, @@ -132,8 +144,8 @@ class PROTOC_EXPORT Generator : public CodeGenerator { void PrintDescriptorKeyAndModuleName( const ServiceDescriptor& descriptor) const; - void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; - std::string OptionsValue(absl::string_view serialized_options) const; + void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor, + const EnumValueDescriptorProto& proto) const; bool GeneratingDescriptorProto() const; template @@ -147,15 +159,21 @@ class PROTOC_EXPORT Generator : public CodeGenerator { absl::string_view name) const; template - bool PrintDescriptorOptionsFixingCode(const DescriptorT& descriptor, - absl::string_view descriptor_str) const; + bool PrintDescriptorOptionsFixingCode( + const DescriptorT& descriptor, const typename DescriptorT::Proto& proto, + absl::string_view descriptor_str) const; void FixAllDescriptorOptions() const; - void FixOptionsForField(const FieldDescriptor& field) const; - void FixOptionsForOneof(const OneofDescriptor& oneof) const; - void FixOptionsForEnum(const EnumDescriptor& descriptor) const; - void FixOptionsForService(const ServiceDescriptor& descriptor) const; - void FixOptionsForMessage(const Descriptor& descriptor) const; + void FixOptionsForField(const FieldDescriptor& field, + const FieldDescriptorProto& proto) const; + void FixOptionsForOneof(const OneofDescriptor& oneof, + const OneofDescriptorProto& proto) const; + void FixOptionsForEnum(const EnumDescriptor& descriptor, + const EnumDescriptorProto& proto) const; + void FixOptionsForService(const ServiceDescriptor& descriptor, + const ServiceDescriptorProto& proto) const; + void FixOptionsForMessage(const Descriptor& descriptor, + const DescriptorProto& proto) const; void SetSerializedPbInterval(const FileDescriptorProto& file) const; void SetMessagePbInterval(const DescriptorProto& message_proto, @@ -168,6 +186,7 @@ class PROTOC_EXPORT Generator : public CodeGenerator { // Guards file_, printer_ and file_descriptor_serialized_. mutable absl::Mutex mutex_; mutable const FileDescriptor* file_; // Set in Generate(). Under mutex_. + mutable FileDescriptorProto proto_; // Set in Generate(). Under mutex_. mutable std::string file_descriptor_serialized_; mutable io::Printer* printer_; // Set in Generate(). Under mutex_. diff --git a/src/google/protobuf/editions/BUILD b/src/google/protobuf/editions/BUILD index 4489ffdbf8..cba63638a0 100644 --- a/src/google/protobuf/editions/BUILD +++ b/src/google/protobuf/editions/BUILD @@ -1,3 +1,4 @@ +load("@rules_python//python:proto.bzl", "py_proto_library") load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults") @@ -98,6 +99,13 @@ cc_proto_library( deps = [":test_messages_proto2_editions_proto"], ) +py_proto_library( + name = "test_messages_proto2_editions_py_pb2", + testonly = True, + visibility = ["//conformance:__pkg__"], + deps = [":test_messages_proto2_editions_proto"], +) + proto_library( name = "test_messages_proto3_editions_proto", testonly = True, @@ -120,6 +128,24 @@ cc_proto_library( deps = [":test_messages_proto3_editions_proto"], ) +py_proto_library( + name = "test_messages_proto3_editions_py_pb2", + testonly = True, + visibility = ["//conformance:__pkg__"], + deps = [":test_messages_proto3_editions_proto"], +) + +# Export these for conformance tests until we support py_proto_library. +exports_files( + [ + "golden/test_messages_proto2_editions.proto", + "golden/test_messages_proto3_editions.proto", + ], + visibility = [ + "//python:__pkg__", + ], +) + proto_library( name = "test_editions_default_features_proto", testonly = True, From ac3f553073c56b96bad2e8d3101bbdb899d2148d Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Wed, 8 Nov 2023 02:13:42 -0800 Subject: [PATCH 120/387] This CL implements msg.() and msg.() accessors for maps with primitive-typed keys and values for the UPB kernel only. Support for the CPP runtime and non-scalar value types will be implemented in follow up CLs. PiperOrigin-RevId: 580453646 --- rust/BUILD | 8 +- rust/internal.rs | 14 + rust/map.rs | 77 ++++++ rust/shared.rs | 4 + rust/test/BUILD | 11 +- rust/test/shared/BUILD | 36 ++- rust/test/shared/accessors_map_test.rs | 43 +++ rust/upb.rs | 246 +++++++++++++++++- rust/upb_kernel/upb_api.c | 1 + src/google/protobuf/compiler/rust/BUILD.bazel | 1 + .../rust/accessors/accessor_generator.h | 7 + .../compiler/rust/accessors/accessors.cc | 13 + .../protobuf/compiler/rust/accessors/map.cc | 82 ++++++ src/google/protobuf/compiler/rust/naming.cc | 13 +- 14 files changed, 533 insertions(+), 23 deletions(-) create mode 100644 rust/map.rs create mode 100644 rust/test/shared/accessors_map_test.rs create mode 100644 src/google/protobuf/compiler/rust/accessors/map.cc diff --git a/rust/BUILD b/rust/BUILD index 3e0ca71ed6..61f8236f46 100644 --- a/rust/BUILD +++ b/rust/BUILD @@ -65,7 +65,10 @@ PROTOBUF_SHARED = [ # setting. rust_library( name = "protobuf_upb", - srcs = PROTOBUF_SHARED + ["upb.rs"], + srcs = PROTOBUF_SHARED + [ + "map.rs", + "upb.rs", + ], crate_root = "shared.rs", rustc_flags = ["--cfg=upb_kernel"], visibility = [ @@ -82,6 +85,9 @@ rust_test( name = "protobuf_upb_test", crate = ":protobuf_upb", rustc_flags = ["--cfg=upb_kernel"], + deps = [ + "@crate_index//:googletest", + ], ) # The Rust Protobuf runtime using the cpp kernel. diff --git a/rust/internal.rs b/rust/internal.rs index d7ea96baaf..be9ddb2203 100644 --- a/rust/internal.rs +++ b/rust/internal.rs @@ -62,6 +62,17 @@ mod _opaque_pointees { _data: [u8; 0], _marker: std::marker::PhantomData<(*mut u8, ::std::marker::PhantomPinned)>, } + + /// Opaque pointee for [`RawMap`] + /// + /// This type is not meant to be dereferenced in Rust code. + /// It is only meant to provide type safety for raw pointers + /// which are manipulated behind FFI. + #[repr(C)] + pub struct RawMapData { + _data: [u8; 0], + _marker: std::marker::PhantomData<(*mut u8, ::std::marker::PhantomPinned)>, + } } /// A raw pointer to the underlying message for this runtime. @@ -73,6 +84,9 @@ pub type RawArena = NonNull<_opaque_pointees::RawArenaData>; /// A raw pointer to the underlying repeated field container for this runtime. pub type RawRepeatedField = NonNull<_opaque_pointees::RawRepeatedFieldData>; +/// A raw pointer to the underlying arena for this runtime. +pub type RawMap = NonNull<_opaque_pointees::RawMapData>; + /// Represents an ABI-stable version of `NonNull<[u8]>`/`string_view` (a /// borrowed slice of bytes) for FFI use only. /// diff --git a/rust/map.rs b/rust/map.rs new file mode 100644 index 0000000000..450b854f31 --- /dev/null +++ b/rust/map.rs @@ -0,0 +1,77 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +use crate::{ + __internal::Private, + __runtime::{Map, MapInner, MapValueType}, +}; + +#[derive(Clone, Copy)] +#[repr(transparent)] +pub struct MapView<'a, K: ?Sized, V: ?Sized> { + inner: Map<'a, K, V>, +} + +#[derive(Clone, Copy)] +#[repr(transparent)] +pub struct MapMut<'a, K: ?Sized, V: ?Sized> { + inner: Map<'a, K, V>, +} + +impl<'a, K: ?Sized, V: ?Sized> MapView<'a, K, V> { + pub fn from_inner(_private: Private, inner: MapInner<'a>) -> Self { + Self { inner: Map::<'a, K, V>::from_inner(_private, inner) } + } + + pub fn len(&self) -> usize { + self.inner.len() + } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } +} + +impl<'a, K: ?Sized, V: ?Sized> MapMut<'a, K, V> { + pub fn from_inner(_private: Private, inner: MapInner<'a>) -> Self { + Self { inner: Map::<'a, K, V>::from_inner(_private, inner) } + } +} + +macro_rules! impl_scalar_map_keys { + ($(key_type $type:ty;)*) => { + $( + impl<'a, V: MapValueType> MapView<'a, $type, V> { + pub fn get(&self, key: $type) -> Option { + self.inner.get(key) + } + } + + impl<'a, V: MapValueType> MapMut<'a, $type, V> { + pub fn insert(&mut self, key: $type, value: V) -> bool { + self.inner.insert(key, value) + } + + pub fn remove(&mut self, key: $type) -> Option { + self.inner.remove(key) + } + + pub fn clear(&mut self) { + self.inner.clear() + } + } + )* + }; +} + +impl_scalar_map_keys!( + key_type i32; + key_type u32; + key_type i64; + key_type u64; + key_type bool; +); diff --git a/rust/shared.rs b/rust/shared.rs index 7c3a3d163d..5aa054c0eb 100644 --- a/rust/shared.rs +++ b/rust/shared.rs @@ -17,6 +17,8 @@ use std::fmt; /// These are the items protobuf users can access directly. #[doc(hidden)] pub mod __public { + #[cfg(upb_kernel)] + pub use crate::map::{MapMut, MapView}; pub use crate::optional::{AbsentField, FieldEntry, Optional, PresentField}; pub use crate::primitive::{PrimitiveMut, SingularPrimitiveMut}; pub use crate::proxied::{ @@ -44,6 +46,8 @@ pub mod __runtime; pub mod __runtime; mod macros; +#[cfg(upb_kernel)] +mod map; mod optional; mod primitive; mod proxied; diff --git a/rust/test/BUILD b/rust/test/BUILD index 94167810fd..1c8255cc15 100644 --- a/rust/test/BUILD +++ b/rust/test/BUILD @@ -1,10 +1,10 @@ -load("@rules_cc//cc:defs.bzl", "cc_proto_library") load( "//rust:defs.bzl", "rust_cc_proto_library", "rust_proto_library", "rust_upb_proto_library", ) +load("@rules_cc//cc:defs.bzl", "cc_proto_library") UNITTEST_PROTO_TARGET = "//src/google/protobuf:test_protos" UNITTEST_CC_PROTO_TARGET = "//src/google/protobuf:cc_test_protos" @@ -330,3 +330,12 @@ rust_upb_proto_library( ], deps = [":nested_proto"], ) + +rust_upb_proto_library( + name = "map_unittest_upb_rust_proto", + testonly = True, + visibility = [ + "//rust/test/shared:__subpackages__", + ], + deps = ["//src/google/protobuf:map_unittest_proto"], +) diff --git a/rust/test/shared/BUILD b/rust/test/shared/BUILD index 73be626f76..b5864a3acc 100644 --- a/rust/test/shared/BUILD +++ b/rust/test/shared/BUILD @@ -23,7 +23,7 @@ rust_library( "//rust:protobuf_upb": "protobuf", }, deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust:protobuf_upb", ], ) @@ -35,7 +35,7 @@ rust_library( "//rust:protobuf_cpp": "protobuf", }, deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust:protobuf_cpp", ], ) @@ -48,7 +48,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust/test:child_upb_rust_proto", "//rust/test:parent_upb_rust_proto", ], @@ -62,7 +62,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust/test:child_cc_rust_proto", "//rust/test:parent_cc_rust_proto", ], @@ -104,7 +104,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust/test:reserved_cc_rust_proto", "//rust/test:unittest_cc_rust_proto", ], @@ -118,7 +118,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust/test:reserved_upb_rust_proto", "//rust/test:unittest_upb_rust_proto", ], @@ -159,7 +159,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:unittest_cc_rust_proto", "//rust/test/shared:matchers_cpp", @@ -181,7 +181,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust:protobuf_upb", "//rust/test:unittest_upb_rust_proto", "//rust/test/shared:matchers_upb", @@ -200,7 +200,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:unittest_proto3_cc_rust_proto", "//rust/test:unittest_proto3_optional_cc_rust_proto", @@ -220,7 +220,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust:protobuf_upb", "//rust/test:unittest_proto3_optional_upb_rust_proto", "//rust/test:unittest_proto3_upb_rust_proto", @@ -236,7 +236,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust/test:unittest_upb_rust_proto", ], ) @@ -249,7 +249,7 @@ rust_test( "not_build:arm", ], deps = [ - "//third_party/gtest_rust/googletest", + "@crate_index//:googletest", "//rust/test:unittest_cc_rust_proto", ], ) @@ -273,3 +273,15 @@ rust_test( ], deps = ["//rust/test:nested_upb_rust_proto"], ) + +rust_test( + name = "accessors_map_upb_test", + srcs = ["accessors_map_test.rs"], + proc_macro_deps = [ + "@crate_index//:paste", + ], + deps = [ + "@crate_index//:googletest", + "//rust/test:map_unittest_upb_rust_proto", + ], +) diff --git a/rust/test/shared/accessors_map_test.rs b/rust/test/shared/accessors_map_test.rs new file mode 100644 index 0000000000..a401d946a0 --- /dev/null +++ b/rust/test/shared/accessors_map_test.rs @@ -0,0 +1,43 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +use googletest::prelude::*; +use map_unittest_proto::proto2_unittest::TestMap; +use paste::paste; + +macro_rules! generate_map_primitives_tests { + ( + $(($k_type:ty, $v_type:ty, $k_field:ident, $v_field:ident)),* + ) => { + paste! { $( + #[test] + fn [< test_map_ $k_field _ $v_field >]() { + let mut msg = TestMap::new(); + let k: $k_type = Default::default(); + let v: $v_type = Default::default(); + assert_that!(msg.[< map_ $k_field _ $v_field _mut>]().insert(k, v), eq(true)); + assert_that!(msg.[< map_ $k_field _ $v_field >]().len(), eq(1)); + } + )* } + }; +} + +generate_map_primitives_tests!( + (i32, i32, int32, int32), + (i64, i64, int64, int64), + (u32, u32, uint32, uint32), + (u64, u64, uint64, uint64), + (i32, i32, sint32, sint32), + (i64, i64, sint64, sint64), + (u32, u32, fixed32, fixed32), + (u64, u64, fixed64, fixed64), + (i32, i32, sfixed32, sfixed32), + (i64, i64, sfixed64, sfixed64), + (i32, f32, int32, float), + (i32, f64, int32, double), + (bool, bool, bool, bool) +); diff --git a/rust/upb.rs b/rust/upb.rs index b6fd7b322a..bab1a9b4aa 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -7,7 +7,7 @@ //! UPB FFI wrapper code for use by Rust Protobuf. -use crate::__internal::{Private, PtrAndLen, RawArena, RawMessage, RawRepeatedField}; +use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; use std::alloc; use std::alloc::Layout; use std::cell::UnsafeCell; @@ -324,7 +324,7 @@ impl<'msg, T: ?Sized> RepeatedField<'msg, T> { // Transcribed from google3/third_party/upb/upb/message/value.h #[repr(C)] #[derive(Clone, Copy)] -union upb_MessageValue { +pub union upb_MessageValue { bool_val: bool, float_val: std::ffi::c_float, double_val: std::ffi::c_double, @@ -341,7 +341,7 @@ union upb_MessageValue { // Transcribed from google3/third_party/upb/upb/base/descriptor_constants.h #[repr(C)] #[allow(dead_code)] -enum UpbCType { +pub enum UpbCType { Bool = 1, Float = 2, Int32 = 3, @@ -435,6 +435,8 @@ impl_repeated_primitives!( /// RepeatedView. /// /// # Safety +/// The returned array must never be mutated. +/// /// TODO: Split RepeatedFieldInner into mut and const variants to /// enforce safety. The returned array must never be mutated. pub unsafe fn empty_array() -> RepeatedFieldInner<'static> { @@ -451,9 +453,205 @@ pub unsafe fn empty_array() -> RepeatedFieldInner<'static> { REPEATED_FIELD.with(|inner| *inner) } +/// Returns a static thread-local empty MapInner for use in a +/// MapView. +/// +/// # Safety +/// The returned map must never be mutated. +/// +/// TODO: Split MapInner into mut and const variants to +/// enforce safety. The returned array must never be mutated. +pub unsafe fn empty_map() -> MapInner<'static> { + fn new_map_inner() -> MapInner<'static> { + // TODO: Consider creating empty map in C. + let arena = Box::leak::<'static>(Box::new(Arena::new())); + // Provide `i32` as a placeholder type. + Map::<'static, i32, i32>::new(arena).inner + } + thread_local! { + static MAP: MapInner<'static> = new_map_inner(); + } + + MAP.with(|inner| *inner) +} + +#[derive(Clone, Copy, Debug)] +pub struct MapInner<'msg> { + pub raw: RawMap, + pub arena: &'msg Arena, +} + +#[derive(Debug)] +pub struct Map<'msg, K: ?Sized, V: ?Sized> { + inner: MapInner<'msg>, + _phantom_key: PhantomData<&'msg mut K>, + _phantom_value: PhantomData<&'msg mut V>, +} + +// These use manual impls instead of derives to avoid unnecessary bounds on `K` +// and `V`. This problem is referred to as "perfect derive". +// https://smallcultfollowing.com/babysteps/blog/2022/04/12/implied-bounds-and-perfect-derive/ +impl<'msg, K: ?Sized, V: ?Sized> Copy for Map<'msg, K, V> {} +impl<'msg, K: ?Sized, V: ?Sized> Clone for Map<'msg, K, V> { + fn clone(&self) -> Map<'msg, K, V> { + *self + } +} + +impl<'msg, K: ?Sized, V: ?Sized> Map<'msg, K, V> { + pub fn len(&self) -> usize { + unsafe { upb_Map_Size(self.inner.raw) } + } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + + pub fn from_inner(_private: Private, inner: MapInner<'msg>) -> Self { + Map { inner, _phantom_key: PhantomData, _phantom_value: PhantomData } + } + + pub fn clear(&mut self) { + unsafe { upb_Map_Clear(self.inner.raw) } + } +} + +/// # Safety +/// Implementers of this trait must ensure that `pack_message_value` returns +/// a `upb_MessageValue` with the active variant indicated by `Self`. +pub unsafe trait MapType { + /// # Safety + /// The active variant of `outer` must be the `type PrimitiveValue` + unsafe fn unpack_message_value(_private: Private, outer: upb_MessageValue) -> Self; + + fn pack_message_value(_private: Private, inner: Self) -> upb_MessageValue; + + fn upb_ctype(_private: Private) -> UpbCType; + + fn zero_value(_private: Private) -> Self; +} + +/// Types implementing this trait can be used as map keys. +pub trait MapKeyType: MapType {} + +/// Types implementing this trait can be used as map values. +pub trait MapValueType: MapType {} + +macro_rules! impl_scalar_map_value_types { + ($($type:ty, $union_field:ident, $upb_tag:expr, $zero_val:literal;)*) => { + $( + unsafe impl MapType for $type { + unsafe fn unpack_message_value(_private: Private, outer: upb_MessageValue) -> Self { + unsafe { outer.$union_field } + } + + fn pack_message_value(_private: Private, inner: Self) -> upb_MessageValue { + upb_MessageValue { $union_field: inner } + } + + fn upb_ctype(_private: Private) -> UpbCType { + $upb_tag + } + + fn zero_value(_private: Private) -> Self { + $zero_val + } + } + + impl MapValueType for $type {} + )* + }; +} + +impl_scalar_map_value_types!( + f32, float_val, UpbCType::Float, 0f32; + f64, double_val, UpbCType::Double, 0f64; + i32, int32_val, UpbCType::Int32, 0i32; + u32, uint32_val, UpbCType::UInt32, 0u32; + i64, int64_val, UpbCType::Int64, 0i64; + u64, uint64_val, UpbCType::UInt64, 0u64; + bool, bool_val, UpbCType::Bool, false; +); + +macro_rules! impl_scalar_map_key_types { + ($($type:ty;)*) => { + $( + impl MapKeyType for $type {} + )* + }; +} + +impl_scalar_map_key_types!( + i32; u32; i64; u64; bool; +); + +impl<'msg, K: MapKeyType, V: MapValueType> Map<'msg, K, V> { + pub fn new(arena: &'msg Arena) -> Self { + unsafe { + let raw_map = upb_Map_New(arena.raw(), K::upb_ctype(Private), V::upb_ctype(Private)); + Map { + inner: MapInner { raw: raw_map, arena }, + _phantom_key: PhantomData, + _phantom_value: PhantomData, + } + } + } + + pub fn get(&self, key: K) -> Option { + let mut val = V::pack_message_value(Private, V::zero_value(Private)); + let found = + unsafe { upb_Map_Get(self.inner.raw, K::pack_message_value(Private, key), &mut val) }; + if !found { + return None; + } + Some(unsafe { V::unpack_message_value(Private, val) }) + } + + pub fn insert(&mut self, key: K, value: V) -> bool { + unsafe { + upb_Map_Set( + self.inner.raw, + K::pack_message_value(Private, key), + V::pack_message_value(Private, value), + self.inner.arena.raw(), + ) + } + } + + pub fn remove(&mut self, key: K) -> Option { + let mut val = V::pack_message_value(Private, V::zero_value(Private)); + let removed = unsafe { + upb_Map_Delete(self.inner.raw, K::pack_message_value(Private, key), &mut val) + }; + if !removed { + return None; + } + Some(unsafe { V::unpack_message_value(Private, val) }) + } +} + +extern "C" { + fn upb_Map_New(arena: RawArena, key_type: UpbCType, value_type: UpbCType) -> RawMap; + fn upb_Map_Size(map: RawMap) -> usize; + fn upb_Map_Set( + map: RawMap, + key: upb_MessageValue, + value: upb_MessageValue, + arena: RawArena, + ) -> bool; + fn upb_Map_Get(map: RawMap, key: upb_MessageValue, value: *mut upb_MessageValue) -> bool; + fn upb_Map_Delete( + map: RawMap, + key: upb_MessageValue, + removed_value: *mut upb_MessageValue, + ) -> bool; + fn upb_Map_Clear(map: RawMap); +} + #[cfg(test)] mod tests { use super::*; + use googletest::prelude::*; #[test] fn test_arena_new_and_free() { @@ -507,4 +705,46 @@ mod tests { assert_eq!(arr.get(arr.len() - 1), Some(i)); } } + + #[test] + fn i32_i32_map() { + let arena = Arena::new(); + let mut map = Map::<'_, i32, i32>::new(&arena); + assert_that!(map.len(), eq(0)); + + assert_that!(map.insert(1, 2), eq(true)); + assert_that!(map.get(1), eq(Some(2))); + assert_that!(map.get(3), eq(None)); + assert_that!(map.len(), eq(1)); + + assert_that!(map.remove(1), eq(Some(2))); + assert_that!(map.len(), eq(0)); + assert_that!(map.remove(1), eq(None)); + + assert_that!(map.insert(4, 5), eq(true)); + assert_that!(map.insert(6, 7), eq(true)); + map.clear(); + assert_that!(map.len(), eq(0)); + } + + #[test] + fn i64_f64_map() { + let arena = Arena::new(); + let mut map = Map::<'_, i64, f64>::new(&arena); + assert_that!(map.len(), eq(0)); + + assert_that!(map.insert(1, 2.5), eq(true)); + assert_that!(map.get(1), eq(Some(2.5))); + assert_that!(map.get(3), eq(None)); + assert_that!(map.len(), eq(1)); + + assert_that!(map.remove(1), eq(Some(2.5))); + assert_that!(map.len(), eq(0)); + assert_that!(map.remove(1), eq(None)); + + assert_that!(map.insert(4, 5.1), eq(true)); + assert_that!(map.insert(6, 7.2), eq(true)); + map.clear(); + assert_that!(map.len(), eq(0)); + } } diff --git a/rust/upb_kernel/upb_api.c b/rust/upb_kernel/upb_api.c index a30b4dd9bb..e2a67ebb86 100644 --- a/rust/upb_kernel/upb_api.c +++ b/rust/upb_kernel/upb_api.c @@ -8,5 +8,6 @@ #define UPB_BUILD_API +#include "upb/collections/map.h" // IWYU pragma: keep #include "upb/collections/array.h" // IWYU pragma: keep #include "upb/mem/arena.h" // IWYU pragma: keep diff --git a/src/google/protobuf/compiler/rust/BUILD.bazel b/src/google/protobuf/compiler/rust/BUILD.bazel index 9939c2ca21..5d84df3229 100644 --- a/src/google/protobuf/compiler/rust/BUILD.bazel +++ b/src/google/protobuf/compiler/rust/BUILD.bazel @@ -51,6 +51,7 @@ cc_library( name = "accessors", srcs = [ "accessors/accessors.cc", + "accessors/map.cc", "accessors/repeated_scalar.cc", "accessors/singular_message.cc", "accessors/singular_scalar.cc", diff --git a/src/google/protobuf/compiler/rust/accessors/accessor_generator.h b/src/google/protobuf/compiler/rust/accessors/accessor_generator.h index 8b26d19dc8..dcefbe8ae4 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessor_generator.h +++ b/src/google/protobuf/compiler/rust/accessors/accessor_generator.h @@ -106,6 +106,13 @@ class UnsupportedField final : public AccessorGenerator { std::string reason_; }; +class Map final : public AccessorGenerator { + public: + ~Map() override = default; + void InMsgImpl(Context field) const override; + void InExternC(Context field) const override; +}; + } // namespace rust } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index f3664229ca..2f08da5694 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -57,6 +57,19 @@ std::unique_ptr AccessorGeneratorFor( } return std::make_unique(); case FieldDescriptor::TYPE_MESSAGE: + if (desc.is_map()) { + // This switch statement will be removed as we support all map + // value types. + switch (desc.message_type()->map_value()->type()) { + case FieldDescriptor::TYPE_STRING: + case FieldDescriptor::TYPE_ENUM: + case FieldDescriptor::TYPE_MESSAGE: + return std::make_unique( + "message types in maps are not supported"); + default: + return std::make_unique(); + } + } if (desc.is_repeated()) { return std::make_unique("repeated msg not supported"); } diff --git a/src/google/protobuf/compiler/rust/accessors/map.cc b/src/google/protobuf/compiler/rust/accessors/map.cc new file mode 100644 index 0000000000..f7eda845c4 --- /dev/null +++ b/src/google/protobuf/compiler/rust/accessors/map.cc @@ -0,0 +1,82 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#include "google/protobuf/compiler/rust/accessors/accessor_generator.h" +#include "google/protobuf/compiler/rust/context.h" +#include "google/protobuf/compiler/rust/naming.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" + +namespace google { +namespace protobuf { +namespace compiler { +namespace rust { + +void Map::InMsgImpl(Context field) const { + auto& key_type = *field.desc().message_type()->map_key(); + auto& value_type = *field.desc().message_type()->map_value(); + + field.Emit({{"field", field.desc().name()}, + {"Key", PrimitiveRsTypeName(key_type)}, + {"Value", PrimitiveRsTypeName(value_type)}, + {"getter_thunk", Thunk(field, "get")}, + {"getter_thunk_mut", Thunk(field, "get_mut")}, + {"getter", + [&] { + if (field.is_upb()) { + field.Emit({}, R"rs( + pub fn r#$field$(&self) -> $pb$::MapView<'_, $Key$, $Value$> { + let inner = unsafe { + $getter_thunk$(self.inner.msg) + }.map_or_else(|| unsafe {$pbr$::empty_map()}, |raw| { + $pbr$::MapInner{ raw, arena: &self.inner.arena } + }); + $pb$::MapView::from_inner($pbi$::Private, inner) + } + + pub fn r#$field$_mut(&mut self) + -> $pb$::MapMut<'_, $Key$, $Value$> { + let raw = unsafe { + $getter_thunk_mut$(self.inner.msg, self.inner.arena.raw()) + }; + let inner = $pbr$::MapInner{ raw, arena: &self.inner.arena }; + $pb$::MapMut::from_inner($pbi$::Private, inner) + } + )rs"); + } + }}}, + R"rs( + $getter$ + )rs"); +} + +void Map::InExternC(Context field) const { + field.Emit( + { + {"getter_thunk", Thunk(field, "get")}, + {"getter_thunk_mut", Thunk(field, "get_mut")}, + {"getter", + [&] { + if (field.is_upb()) { + field.Emit({}, R"rs( + fn $getter_thunk$(raw_msg: $pbi$::RawMessage) + -> Option<$pbi$::RawMap>; + fn $getter_thunk_mut$(raw_msg: $pbi$::RawMessage, + arena: $pbi$::RawArena) -> $pbi$::RawMap; + )rs"); + } + }}, + }, + R"rs( + $getter$ + )rs"); +} + +} // namespace rust +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index e9e24c40b0..198fbd16e4 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -96,8 +96,8 @@ std::string Thunk(Context field, absl::string_view op) { return thunk; } -std::string ThunkRepeated(Context field, - absl::string_view op) { +std::string ThunkMapOrRepeated(Context field, + absl::string_view op) { if (!field.is_upb()) { return Thunk(field, op); } @@ -105,9 +105,10 @@ std::string ThunkRepeated(Context field, std::string thunk = absl::StrCat("_", FieldPrefix(field)); absl::string_view format; if (op == "get") { - format = "_$1_upb_array"; + format = field.desc().is_map() ? "_$1_upb_map" : "_$1_upb_array"; } else if (op == "get_mut") { - format = "_$1_mutable_upb_array"; + format = + field.desc().is_map() ? "_$1_mutable_upb_map" : "_$1_mutable_upb_array"; } else { return Thunk(field, op); } @@ -119,8 +120,8 @@ std::string ThunkRepeated(Context field, } // namespace std::string Thunk(Context field, absl::string_view op) { - if (field.desc().is_repeated()) { - return ThunkRepeated(field, op); + if (field.desc().is_map() || field.desc().is_repeated()) { + return ThunkMapOrRepeated(field, op); } return Thunk(field, op); } From e9d1a70426ccfc63e814fe0261ad7a6c8425834a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 8 Nov 2023 10:38:20 +0000 Subject: [PATCH 121/387] Auto-generate files after cl/580453646 --- src/file_lists.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/src/file_lists.cmake b/src/file_lists.cmake index 4f5b4855e0..7b18692443 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -385,6 +385,7 @@ set(libprotoc_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/retention.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/accessors.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/map.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/singular_message.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc From 90aa298406fa8333be23924195fe2e92c137bb08 Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Wed, 8 Nov 2023 03:12:13 -0800 Subject: [PATCH 122/387] Migrate upb.rs to googletest PiperOrigin-RevId: 580469265 --- rust/upb.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/upb.rs b/rust/upb.rs index bab1a9b4aa..dff07dfc06 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -672,37 +672,37 @@ mod tests { len, ) }; - assert_eq!(&*serialized_data, b"Hello world"); + assert_that!(&*serialized_data, eq(b"Hello world")); } #[test] fn i32_array() { let arena = Arena::new(); let mut arr = RepeatedField::::new(&arena); - assert_eq!(arr.len(), 0); + assert_that!(arr.len(), eq(0)); arr.push(1); - assert_eq!(arr.get(0), Some(1)); - assert_eq!(arr.len(), 1); + assert_that!(arr.get(0), eq(Some(1))); + assert_that!(arr.len(), eq(1)); arr.set(0, 3); - assert_eq!(arr.get(0), Some(3)); + assert_that!(arr.get(0), eq(Some(3))); for i in 0..2048 { arr.push(i); - assert_eq!(arr.get(arr.len() - 1), Some(i)); + assert_that!(arr.get(arr.len() - 1), eq(Some(i))); } } #[test] fn u32_array() { let mut arena = Arena::new(); let mut arr = RepeatedField::::new(&mut arena); - assert_eq!(arr.len(), 0); + assert_that!(arr.len(), eq(0)); arr.push(1); - assert_eq!(arr.get(0), Some(1)); - assert_eq!(arr.len(), 1); + assert_that!(arr.get(0), eq(Some(1))); + assert_that!(arr.len(), eq(1)); arr.set(0, 3); - assert_eq!(arr.get(0), Some(3)); + assert_that!(arr.get(0), eq(Some(3))); for i in 0..2048 { arr.push(i); - assert_eq!(arr.get(arr.len() - 1), Some(i)); + assert_that!(arr.get(arr.len() - 1), eq(Some(i))); } } From 2ec703fcc16c0afbd3e2644c84ad750260b215ed Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 8 Nov 2023 04:58:29 -0800 Subject: [PATCH 123/387] Preserve lazy fields when merging FieldSets. In particular, when calling toBuilder() on a MessageSet with lazily-parsed extensions, don't eagerly parse all extensions. PiperOrigin-RevId: 580492290 --- .../java/com/google/protobuf/FieldSet.java | 40 ++++++++-- .../com/google/protobuf/WireFormatTest.java | 76 +++++++++++++++++++ 2 files changed, 108 insertions(+), 8 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/FieldSet.java b/java/core/src/main/java/com/google/protobuf/FieldSet.java index d2a5d48fb8..bb3eea993d 100644 --- a/java/core/src/main/java/com/google/protobuf/FieldSet.java +++ b/java/core/src/main/java/com/google/protobuf/FieldSet.java @@ -500,11 +500,12 @@ final class FieldSet> { private void mergeFromField(final Map.Entry entry) { final T descriptor = entry.getKey(); Object otherValue = entry.getValue(); - if (otherValue instanceof LazyField) { - otherValue = ((LazyField) otherValue).getValue(); - } + boolean isLazyField = otherValue instanceof LazyField; if (descriptor.isRepeated()) { + if (isLazyField) { + throw new IllegalStateException("Lazy fields can not be repeated"); + } Object value = getField(descriptor); if (value == null) { value = new ArrayList<>(); @@ -516,9 +517,17 @@ final class FieldSet> { } else if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) { Object value = getField(descriptor); if (value == null) { + // New field. fields.put(descriptor, cloneIfMutable(otherValue)); + if (isLazyField) { + hasLazyField = true; + } } else { - // Merge the messages. + // There is an existing field. Need to merge the messages. + if (otherValue instanceof LazyField) { + // Extract the actual value for lazy fields. + otherValue = ((LazyField) otherValue).getValue(); + } value = descriptor .internalMergeFrom(((MessageLite) value).toBuilder(), (MessageLite) otherValue) @@ -526,6 +535,9 @@ final class FieldSet> { fields.put(descriptor, value); } } else { + if (isLazyField) { + throw new IllegalStateException("Lazy fields must be message-valued"); + } fields.put(descriptor, cloneIfMutable(otherValue)); } } @@ -1274,11 +1286,12 @@ final class FieldSet> { private void mergeFromField(final Map.Entry entry) { final T descriptor = entry.getKey(); Object otherValue = entry.getValue(); - if (otherValue instanceof LazyField) { - otherValue = ((LazyField) otherValue).getValue(); - } + boolean isLazyField = otherValue instanceof LazyField; if (descriptor.isRepeated()) { + if (isLazyField) { + throw new IllegalStateException("Lazy fields can not be repeated"); + } List value = (List) getFieldAllowBuilders(descriptor); if (value == null) { value = new ArrayList<>(); @@ -1290,9 +1303,17 @@ final class FieldSet> { } else if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) { Object value = getFieldAllowBuilders(descriptor); if (value == null) { + // New field. fields.put(descriptor, FieldSet.cloneIfMutable(otherValue)); + if (isLazyField) { + hasLazyField = true; + } } else { - // Merge the messages. + // There is an existing field. Need to merge the messages. + if (otherValue instanceof LazyField) { + // Extract the actual value for lazy fields. + otherValue = ((LazyField) otherValue).getValue(); + } if (value instanceof MessageLite.Builder) { descriptor.internalMergeFrom((MessageLite.Builder) value, (MessageLite) otherValue); } else { @@ -1304,6 +1325,9 @@ final class FieldSet> { } } } else { + if (isLazyField) { + throw new IllegalStateException("Lazy fields must be message-valued"); + } fields.put(descriptor, cloneIfMutable(otherValue)); } } diff --git a/java/core/src/test/java/com/google/protobuf/WireFormatTest.java b/java/core/src/test/java/com/google/protobuf/WireFormatTest.java index 020409e9cf..4afeff8f17 100644 --- a/java/core/src/test/java/com/google/protobuf/WireFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/WireFormatTest.java @@ -12,6 +12,7 @@ import static com.google.common.truth.Truth.assertThat; import protobuf_unittest.UnittestMset.RawMessageSet; import protobuf_unittest.UnittestMset.TestMessageSetExtension1; import protobuf_unittest.UnittestMset.TestMessageSetExtension2; +import protobuf_unittest.UnittestMset.TestMessageSetExtension3; import protobuf_unittest.UnittestProto; import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestAllTypes; @@ -25,6 +26,7 @@ import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.List; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -39,6 +41,13 @@ public class WireFormatTest { TestMessageSetExtension2.getDescriptor().getExtensions().get(0).getNumber(); private static final int UNKNOWN_TYPE_ID = 1550055; + @After + public void tearDown() { + // Whether to parse message sets eagerly is stored in a global static. Since some tests modify + // the value, make sure to reset it between test runs. + ExtensionRegistryLite.setEagerlyParseMessageSets(false); + } + @Test public void testSerialization() throws Exception { TestAllTypes message = TestUtil.getAllSet(); @@ -497,6 +506,73 @@ public class WireFormatTest { .isEqualTo(123); } + @Test + public void testParseAndUpdateMessageSetExtensionEagerly() throws Exception { + testParseAndUpdateMessageSetExtensionEagerlyWithFlag(true); + } + + @Test + public void testParseAndUpdateMessageSetExtensionNotEagerly() throws Exception { + testParseAndUpdateMessageSetExtensionEagerlyWithFlag(false); + } + + private void testParseAndUpdateMessageSetExtensionEagerlyWithFlag(boolean eagerParsing) + throws Exception { + ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing); + ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance(); + extensionRegistry.add(TestMessageSetExtension1.messageSetExtension); + extensionRegistry.add(TestMessageSetExtension2.messageSetExtension); + extensionRegistry.add(TestMessageSetExtension3.messageSetExtension); + + // Set up a RawMessageSet with 2 extensions + RawMessageSet raw = + RawMessageSet.newBuilder() + .addItem( + RawMessageSet.Item.newBuilder() + .setTypeId(TYPE_ID_1) + .setMessage( + TestMessageSetExtension1.newBuilder().setI(123).build().toByteString()) + .build()) + .addItem( + RawMessageSet.Item.newBuilder() + .setTypeId(TYPE_ID_2) + .setMessage( + TestMessageSetExtension2.newBuilder().setStr("foo").build().toByteString()) + .build()) + .build(); + + ByteString data = raw.toByteString(); + + // Parse as a TestMessageSet. + TestMessageSet messageSet = TestMessageSet.parseFrom(data, extensionRegistry); + + // Update one extension and add a new one. + TestMessageSet.Builder builder = messageSet.toBuilder(); + builder.setExtension( + TestMessageSetExtension2.messageSetExtension, + TestMessageSetExtension2.newBuilder().setStr("bar").build()); + builder.setExtension( + TestMessageSetExtension3.messageSetExtension, + TestMessageSetExtension3.newBuilder().setRequiredInt(666).build()); + + TestMessageSet updatedMessageSet = builder.build(); + // Check all 3 extensions + assertThat(updatedMessageSet.getExtension(TestMessageSetExtension1.messageSetExtension).getI()) + .isEqualTo(123); + assertThat( + updatedMessageSet.getExtension(TestMessageSetExtension2.messageSetExtension).getStr()) + .isEqualTo("bar"); + assertThat( + updatedMessageSet + .getExtension(TestMessageSetExtension3.messageSetExtension) + .getRequiredInt()) + .isEqualTo(666); + + // Serialize and re-parse, and make sure we get the same message back + assertThat(TestMessageSet.parseFrom(updatedMessageSet.toByteString(), extensionRegistry)) + .isEqualTo(updatedMessageSet); + } + // ================================================================ // oneof @Test From fa15c2160eaeb8d11ed71ba956da0c27d268ec6d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 8 Nov 2023 05:01:04 -0800 Subject: [PATCH 124/387] Fix upb's json decoder ignoring trailing characters after a successfully parsed object. This is a breaking change since the JSON parser will now correctly reject certain bad inputs that it previously silently accepted (for example: json="{}x" was accepted). PiperOrigin-RevId: 580493003 --- upb/json/BUILD | 1 + upb/json/decode.c | 33 ++++++++++++++++++++++++++++---- upb/json/decode_test.cc | 19 ++++++++++++++++++ upb/util/required_fields_test.cc | 2 +- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/upb/json/BUILD b/upb/json/BUILD index 29ce7ae538..91c7dc1658 100644 --- a/upb/json/BUILD +++ b/upb/json/BUILD @@ -41,6 +41,7 @@ cc_test( ":test_upb_proto", ":test_upb_proto_reflection", "@com_google_googletest//:gtest_main", + "//upb:base", "//upb:mem", "//upb:reflection", ], diff --git a/upb/json/decode.c b/upb/json/decode.c index 683a721a50..ce48948634 100644 --- a/upb/json/decode.c +++ b/upb/json/decode.c @@ -102,9 +102,13 @@ static bool jsondec_isvalue(const upb_FieldDef* f) { jsondec_isnullvalue(f); } -UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { +static void jsondec_seterrmsg(jsondec* d, const char* msg) { upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, (int)(d->ptr - d->line_begin), msg); +} + +UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { + jsondec_seterrmsg(d, msg); UPB_LONGJMP(d->err, 1); } @@ -119,7 +123,9 @@ UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { UPB_LONGJMP(d->err, 1); } -static void jsondec_skipws(jsondec* d) { +// Advances d->ptr until the next non-whitespace character or to the end of +// the buffer. +static void jsondec_consumews(jsondec* d) { while (d->ptr != d->end) { switch (*d->ptr) { case '\n': @@ -135,7 +141,16 @@ static void jsondec_skipws(jsondec* d) { return; } } - jsondec_err(d, "Unexpected EOF"); +} + +// Advances d->ptr until the next non-whitespace character. Postcondition that +// d->ptr is pointing at a valid non-whitespace character (will err if end of +// buffer is reached). +static void jsondec_skipws(jsondec* d) { + jsondec_consumews(d); + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); + } } static bool jsondec_tryparsech(jsondec* d, char ch) { @@ -1481,7 +1496,17 @@ static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, if (UPB_SETJMP(d->err)) return false; jsondec_tomsg(d, msg, m); - return true; + + // Consume any trailing whitespace before checking if we read the entire + // input. + jsondec_consumews(d); + + if (d->ptr == d->end) { + return true; + } else { + jsondec_seterrmsg(d, "unexpected trailing characters"); + return false; + } } bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, diff --git a/upb/json/decode_test.cc b/upb/json/decode_test.cc index 9d40b02b74..b196bf95a5 100644 --- a/upb/json/decode_test.cc +++ b/upb/json/decode_test.cc @@ -30,10 +30,15 @@ #include "upb/json/decode.h" +#include +#include + #include "google/protobuf/struct.upb.h" #include +#include "upb/base/status.hpp" #include "upb/json/test.upb.h" #include "upb/json/test.upbdefs.h" +#include "upb/mem/arena.h" #include "upb/mem/arena.hpp" #include "upb/reflection/def.hpp" @@ -100,3 +105,17 @@ TEST(JsonTest, DecodeConflictJsonName) { EXPECT_EQ(2, upb_test_Box_new_value(box)); EXPECT_EQ(0, upb_test_Box_value(box)); } + +TEST(JsonTest, RejectsBadTrailingCharacters) { + upb::Arena a; + std::string json_string = R"({}abc)"; + upb_test_Box* box = JsonDecode(json_string.c_str(), a.ptr()); + EXPECT_EQ(box, nullptr); +} + +TEST(JsonTest, AcceptsTrailingWhitespace) { + upb::Arena a; + std::string json_string = "{} \n \r\n \t\t"; + upb_test_Box* box = JsonDecode(json_string.c_str(), a.ptr()); + EXPECT_NE(box, nullptr); +} diff --git a/upb/util/required_fields_test.cc b/upb/util/required_fields_test.cc index 70f0a95bf6..396c3aa997 100644 --- a/upb/util/required_fields_test.cc +++ b/upb/util/required_fields_test.cc @@ -111,7 +111,7 @@ TYPED_TEST_SUITE(RequiredFieldsTest, MyTypes); // } TYPED_TEST(RequiredFieldsTest, TestRequired) { TestFixture::CheckRequired(R"json({})json", {"required_message"}); - TestFixture::CheckRequired(R"json({"required_message": {}}")json", {}); + TestFixture::CheckRequired(R"json({"required_message": {}})json", {}); TestFixture::CheckRequired( R"json( { From a9b11dd7bdb197f861d3e20c3e447e831d587c80 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 8 Nov 2023 13:28:44 +0000 Subject: [PATCH 125/387] Auto-generate files after cl/580493003 --- php/ext/google/protobuf/php-upb.c | 33 +++++++++++++++++++++++---- ruby/ext/google/protobuf_c/ruby-upb.c | 33 +++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index d375f0f5df..7ec2c579dd 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -3116,9 +3116,13 @@ static bool jsondec_isvalue(const upb_FieldDef* f) { jsondec_isnullvalue(f); } -UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { +static void jsondec_seterrmsg(jsondec* d, const char* msg) { upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, (int)(d->ptr - d->line_begin), msg); +} + +UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { + jsondec_seterrmsg(d, msg); UPB_LONGJMP(d->err, 1); } @@ -3133,7 +3137,9 @@ UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { UPB_LONGJMP(d->err, 1); } -static void jsondec_skipws(jsondec* d) { +// Advances d->ptr until the next non-whitespace character or to the end of +// the buffer. +static void jsondec_consumews(jsondec* d) { while (d->ptr != d->end) { switch (*d->ptr) { case '\n': @@ -3149,7 +3155,16 @@ static void jsondec_skipws(jsondec* d) { return; } } - jsondec_err(d, "Unexpected EOF"); +} + +// Advances d->ptr until the next non-whitespace character. Postcondition that +// d->ptr is pointing at a valid non-whitespace character (will err if end of +// buffer is reached). +static void jsondec_skipws(jsondec* d) { + jsondec_consumews(d); + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); + } } static bool jsondec_tryparsech(jsondec* d, char ch) { @@ -4495,7 +4510,17 @@ static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, if (UPB_SETJMP(d->err)) return false; jsondec_tomsg(d, msg, m); - return true; + + // Consume any trailing whitespace before checking if we read the entire + // input. + jsondec_consumews(d); + + if (d->ptr == d->end) { + return true; + } else { + jsondec_seterrmsg(d, "unexpected trailing characters"); + return false; + } } bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index cdcbf4a1db..888f507043 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -2631,9 +2631,13 @@ static bool jsondec_isvalue(const upb_FieldDef* f) { jsondec_isnullvalue(f); } -UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { +static void jsondec_seterrmsg(jsondec* d, const char* msg) { upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, (int)(d->ptr - d->line_begin), msg); +} + +UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { + jsondec_seterrmsg(d, msg); UPB_LONGJMP(d->err, 1); } @@ -2648,7 +2652,9 @@ UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { UPB_LONGJMP(d->err, 1); } -static void jsondec_skipws(jsondec* d) { +// Advances d->ptr until the next non-whitespace character or to the end of +// the buffer. +static void jsondec_consumews(jsondec* d) { while (d->ptr != d->end) { switch (*d->ptr) { case '\n': @@ -2664,7 +2670,16 @@ static void jsondec_skipws(jsondec* d) { return; } } - jsondec_err(d, "Unexpected EOF"); +} + +// Advances d->ptr until the next non-whitespace character. Postcondition that +// d->ptr is pointing at a valid non-whitespace character (will err if end of +// buffer is reached). +static void jsondec_skipws(jsondec* d) { + jsondec_consumews(d); + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); + } } static bool jsondec_tryparsech(jsondec* d, char ch) { @@ -4010,7 +4025,17 @@ static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, if (UPB_SETJMP(d->err)) return false; jsondec_tomsg(d, msg, m); - return true; + + // Consume any trailing whitespace before checking if we read the entire + // input. + jsondec_consumews(d); + + if (d->ptr == d->end) { + return true; + } else { + jsondec_seterrmsg(d, "unexpected trailing characters"); + return false; + } } bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, From e4196b144338caedba24c8f8b7cea31fa71f982c Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 8 Nov 2023 07:38:24 -0800 Subject: [PATCH 126/387] Replace CreateMaybeMessage hooks with a `void*` based signature to allow reusing the functions in more generic contexts. Reuse these new functions in the implementation of RepeatedPtrField. PiperOrigin-RevId: 580530262 --- src/google/protobuf/arena.h | 110 ++++++++--- src/google/protobuf/arena_test_util.h | 5 + src/google/protobuf/arena_unittest.cc | 77 ++++++++ .../cpp/field_generators/message_field.cc | 24 ++- src/google/protobuf/compiler/cpp/file.cc | 8 +- src/google/protobuf/compiler/cpp/message.cc | 30 +-- .../protobuf/compiler/java/java_features.pb.h | 2 +- src/google/protobuf/compiler/plugin.pb.cc | 18 +- src/google/protobuf/compiler/plugin.pb.h | 12 +- src/google/protobuf/cpp_features.pb.h | 2 +- src/google/protobuf/descriptor.pb.cc | 180 ++++++++++-------- src/google/protobuf/descriptor.pb.h | 104 +++++----- src/google/protobuf/message_lite.cc | 5 - src/google/protobuf/message_lite.h | 8 +- src/google/protobuf/repeated_ptr_field.cc | 10 +- src/google/protobuf/repeated_ptr_field.h | 48 ++--- 16 files changed, 381 insertions(+), 262 deletions(-) diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index c4f8f5fc2c..4370990277 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -223,13 +223,23 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // allocation protocol, documented above. template PROTOBUF_ALWAYS_INLINE static T* CreateMessage(Arena* arena, Args&&... args) { + using Type = std::remove_const_t; static_assert( - is_arena_constructable::value, + is_arena_constructable::value, "CreateMessage can only construct types that are ArenaConstructable"); - // We must delegate to CreateMaybeMessage() and NOT CreateMessageInternal() - // because protobuf generated classes specialize CreateMaybeMessage() and we - // need to use that specialization for code size reasons. - return Arena::CreateMaybeMessage(arena, static_cast(args)...); +#ifdef __cpp_if_constexpr + constexpr auto construct_type = GetConstructType(); + // We delegate to DefaultConstruct/CopyConstruct where appropriate + // because protobuf generated classes have external templates for these + // functions for code size reasons. + // When `if constexpr` is not available always use the fallback. + if constexpr (construct_type == ConstructType::kDefault) { + return static_cast(DefaultConstruct(arena)); + } else if constexpr (construct_type == ConstructType::kCopy) { + return static_cast(CopyConstruct(arena, &args...)); + } +#endif + return CreateMessageInternal(arena, std::forward(args)...); } // API to create any objects on the arena. Note that only the object will @@ -471,6 +481,36 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { private: internal::ThreadSafeArena impl_; + enum class ConstructType { kUnknown, kDefault, kCopy, kMove }; + // Overload set to detect which kind of construction is going to happen for a + // specific set of input arguments. This is used to dispatch to different + // helper functions. + template + static auto ProbeConstructType() + -> std::integral_constant; + template + static auto ProbeConstructType(const T&) + -> std::integral_constant; + template + static auto ProbeConstructType(T&) + -> std::integral_constant; + template + static auto ProbeConstructType(const T&&) + -> std::integral_constant; + template + static auto ProbeConstructType(T&&) + -> std::integral_constant; + template + static auto ProbeConstructType(U&&...) + -> std::integral_constant; + + template + static constexpr auto GetConstructType() { + return std::is_base_of::value + ? decltype(ProbeConstructType(std::declval()...))::value + : ConstructType::kUnknown; + } + void ReturnArrayMemory(void* p, size_t size) { impl_.ReturnArrayMemory(p, size); } @@ -517,31 +557,21 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { } } - // CreateMessage requires that T supports arenas, but this private method - // works whether or not T supports arenas. These are not exposed to user code - // as it can cause confusing API usages, and end up having double free in - // user code. These are used only internally from LazyField and Repeated - // fields, since they are designed to work in all mode combinations. - template - PROTOBUF_ALWAYS_INLINE static Msg* DoCreateMaybeMessage(Arena* arena, - std::true_type, - Args&&... args) { - return CreateMessageInternal(arena, std::forward(args)...); - } - - template - PROTOBUF_ALWAYS_INLINE static T* DoCreateMaybeMessage(Arena* arena, - std::false_type, - Args&&... args) { - return Create(arena, std::forward(args)...); - } - - template - PROTOBUF_ALWAYS_INLINE static T* CreateMaybeMessage(Arena* arena, - Args&&... args) { - return DoCreateMaybeMessage(arena, is_arena_constructable(), - std::forward(args)...); - } + // DefaultConstruct/CopyConstruct: + // + // Functions with a generic signature to support taking the address in generic + // contexts, like RepeatedPtrField, etc. + // These are also used as a hook for `extern template` instantiations where + // codegen can offload the instantiations to the respective .pb.cc files. This + // has two benefits: + // - It reduces the library bloat as callers don't have to instantiate the + // function. + // - It allows the optimizer to see the constructors called to + // further optimize the instantiation. + template + static void* DefaultConstruct(Arena* arena); + template + static void* CopyConstruct(Arena* arena, const void* from); template PROTOBUF_NDEBUG_INLINE T* DoCreateMessage(Args&&... args) { @@ -620,7 +650,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { template friend class internal::GenericTypeHandler; friend class internal::InternalMetadata; // For user_arena(). - friend class internal::LazyField; // For CreateMaybeMessage. + friend class internal::LazyField; // For DefaultConstruct. friend class internal::EpsCopyInputStream; // For parser performance friend class internal::TcParser; // For parser performance friend class MessageLite; @@ -632,6 +662,24 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { friend struct internal::ArenaTestPeer; }; +// DefaultConstruct/CopyConstruct +// +// IMPORTANT: These have to be defined out of line and without an `inline` +// keyword to make sure the `extern template` suppresses instantiations. +template +PROTOBUF_NOINLINE void* Arena::DefaultConstruct(Arena* arena) { + void* mem = arena != nullptr ? arena->AllocateAligned(sizeof(T)) + : ::operator new(sizeof(T)); + return new (mem) T(arena); +} + +template +PROTOBUF_NOINLINE void* Arena::CopyConstruct(Arena* arena, const void* from) { + void* mem = arena != nullptr ? arena->AllocateAligned(sizeof(T)) + : ::operator new(sizeof(T)); + return new (mem) T(arena, *static_cast(from)); +} + template <> inline void* Arena::AllocateInternal() { return impl_.AllocateFromStringBlock(); diff --git a/src/google/protobuf/arena_test_util.h b/src/google/protobuf/arena_test_util.h index e2144a8660..40b44c18f4 100644 --- a/src/google/protobuf/arena_test_util.h +++ b/src/google/protobuf/arena_test_util.h @@ -62,6 +62,11 @@ struct ArenaTestPeer { static auto PeekCleanupListForTesting(Arena* arena) { return arena->PeekCleanupListForTesting(); } + template + static constexpr auto GetConstructType() { + return Arena::GetConstructType(); + } + using ConstructType = Arena::ConstructType; }; struct CleanupGrowthInfo { diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index 21041129fb..673e3e6695 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -17,11 +17,13 @@ #include #include #include +#include #include #include #include #include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/string_view.h" #include "absl/synchronization/barrier.h" #include "google/protobuf/arena_test_util.h" @@ -324,6 +326,81 @@ TEST(ArenaTest, ArenaOnlyTypesCanBeConstructed) { Arena::CreateMessage(&arena); } +TEST(ArenaTest, GetConstructTypeWorks) { + using T = TestAllTypes; + using Peer = internal::ArenaTestPeer; + using CT = typename Peer::ConstructType; + EXPECT_EQ(CT::kDefault, (Peer::GetConstructType())); + EXPECT_EQ(CT::kCopy, (Peer::GetConstructType())); + EXPECT_EQ(CT::kCopy, (Peer::GetConstructType())); + EXPECT_EQ(CT::kCopy, (Peer::GetConstructType())); + EXPECT_EQ(CT::kMove, (Peer::GetConstructType())); + EXPECT_EQ(CT::kUnknown, (Peer::GetConstructType())); + EXPECT_EQ(CT::kUnknown, (Peer::GetConstructType())); + + // For non-protos, it's always unknown + EXPECT_EQ(CT::kUnknown, (Peer::GetConstructType())); +} + +#ifdef __cpp_if_constexpr +class DispatcherTestProto : public Message { + public: + using InternalArenaConstructable_ = void; + // For the test below to construct. + explicit DispatcherTestProto(absl::in_place_t) {} + explicit DispatcherTestProto(Arena*) { ABSL_LOG(FATAL); } + DispatcherTestProto(Arena*, const DispatcherTestProto&) { ABSL_LOG(FATAL); } + DispatcherTestProto* New(Arena*) const final { ABSL_LOG(FATAL); } + Metadata GetMetadata() const final { ABSL_LOG(FATAL); } + const ClassData* GetClassData() const final { ABSL_LOG(FATAL); } +}; +// We use a specialization to inject behavior for the test. +// This test is very intrusive and will have to be fixed if we change the +// implementation of CreateMessage. +absl::string_view hook_called; +template <> +void* Arena::DefaultConstruct(Arena*) { + hook_called = "default"; + return nullptr; +} +template <> +void* Arena::CopyConstruct(Arena*, const void*) { + hook_called = "copy"; + return nullptr; +} +template <> +DispatcherTestProto* Arena::CreateMessageInternal( + Arena*, int&&) { + hook_called = "fallback"; + return nullptr; +} + +TEST(ArenaTest, CreateMessageDispatchesToSpecialFunctions) { + hook_called = ""; + Arena::CreateMessage(nullptr); + EXPECT_EQ(hook_called, "default"); + + DispatcherTestProto ref(absl::in_place); + const DispatcherTestProto& cref = ref; + + hook_called = ""; + Arena::CreateMessage(nullptr); + EXPECT_EQ(hook_called, "default"); + + hook_called = ""; + Arena::CreateMessage(nullptr, ref); + EXPECT_EQ(hook_called, "copy"); + + hook_called = ""; + Arena::CreateMessage(nullptr, cref); + EXPECT_EQ(hook_called, "copy"); + + hook_called = ""; + Arena::CreateMessage(nullptr, 1); + EXPECT_EQ(hook_called, "fallback"); +} +#endif // __cpp_if_constexpr + TEST(ArenaTest, Parsing) { TestAllTypes original; TestUtil::SetAllFields(&original); diff --git a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc index 83d2a21637..e5ac613080 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc @@ -133,12 +133,13 @@ class SingularMessage : public FieldGeneratorBase { } void GenerateMemberCopyConstructor(io::Printer* p) const override { - p->Emit("$name$_{CreateMaybeMessage<$Submsg$>(arena, *from.$name$_)}"); + p->Emit( + "$name$_{$superclass$::CopyConstruct<$Submsg$>(arena, *from.$name$_)}"); } void GenerateOneofCopyConstruct(io::Printer* p) const override { p->Emit(R"cc( - $field$ = CreateMaybeMessage<$Submsg$>(arena, *from.$field$); + $field$ = $superclass$::CopyConstruct<$Submsg$>(arena, *from.$field$); )cc"); } @@ -262,7 +263,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { $StrongRef$; $set_hasbit$; if ($field_$ == nullptr) { - auto* p = CreateMaybeMessage<$Submsg$>(GetArena()); + auto* p = $superclass$::DefaultConstruct<$Submsg$>(GetArena()); $field_$ = reinterpret_cast<$MemberType$*>(p); } return $cast_field_$; @@ -443,7 +444,8 @@ void SingularMessage::GenerateMergingCode(io::Printer* p) const { p->Emit(R"cc( $DCHK$(from.$field_$ != nullptr); if (_this->$field_$ == nullptr) { - _this->$field_$ = CreateMaybeMessage<$Submsg$>(arena, *from.$field_$); + _this->$field_$ = + $superclass$::CopyConstruct<$Submsg$>(arena, *from.$field_$); } else { _this->$field_$->MergeFrom(*from.$field_$); } @@ -474,13 +476,15 @@ void SingularMessage::GenerateCopyConstructorCode(io::Printer* p) const { if (has_hasbit_) { p->Emit(R"cc( if ((from.$has_hasbit$) != 0) { - _this->$field_$ = CreateMaybeMessage<$Submsg$>(arena, *from.$field_$); + _this->$field_$ = + $superclass$::CopyConstruct<$Submsg$>(arena, *from.$field_$); } )cc"); } else { p->Emit(R"cc( if (from._internal_has_$name$()) { - _this->$field_$ = CreateMaybeMessage<$Submsg$>(arena, *from.$field_$); + _this->$field_$ = + $superclass$::CopyConstruct<$Submsg$>(arena, *from.$field_$); } )cc"); } @@ -661,7 +665,8 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { if ($not_has_field$) { clear_$oneof_name$(); set_has_$name$(); - $field_$ = $weak_cast$(CreateMaybeMessage<$Submsg$>(GetArena())); + $field_$ = + $weak_cast$($superclass$::DefaultConstruct<$Submsg$>(GetArena())); } return $cast_field_$; } @@ -855,9 +860,8 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { $TsanDetectConcurrentRead$; $PrepareSplitMessageForWrite$; if ($field_$.IsDefault()) { - $field_$.Set( - CreateMaybeMessage<$pb$::$Weak$RepeatedPtrField<$Submsg$>>( - GetArena())); + $field_$.Set($superclass$::DefaultConstruct< + $pb$::$Weak$RepeatedPtrField<$Submsg$>>(GetArena())); } return $field_$.Get(); } diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 1c88b8a226..a70ea0bfd8 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -1405,14 +1405,12 @@ class FileGenerator::ForwardDeclarations { // However, it increases the size of the pb.cc translation units so it // is a tradeoff. p->Emit({{"class", QualifiedClassName(c.second, options)}}, R"cc( - template <> - $dllexport_decl $$class$* Arena::CreateMaybeMessage<$class$>(Arena*); + extern template void* Arena::DefaultConstruct<$class$>(Arena*); )cc"); if (!IsMapEntryMessage(c.second)) { p->Emit({{"class", QualifiedClassName(c.second, options)}}, R"cc( - template <> - $dllexport_decl $$class$* Arena::CreateMaybeMessage<$class$>( - Arena*, const $class$&); + extern template void* Arena::CopyConstruct<$class$>(Arena*, + const void*); )cc"); } } diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 8dfff78caa..0c41a5ed3c 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -1477,7 +1477,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { "// implements Message ----------------------------------------------\n" "\n" "$classname$* New(::$proto_ns$::Arena* arena = nullptr) const final {\n" - " return CreateMaybeMessage<$classname$>(arena);\n" + " return $superclass$::DefaultConstruct<$classname$>(arena);\n" "}\n"); // For instances that derive from Message (rather than MessageLite), some @@ -2739,9 +2739,9 @@ void MessageGenerator::GenerateCopyInitFields(io::Printer* p) const { p->Emit({{"has_msg", [&] { has_message(field); }}, {"submsg", FieldMessageTypeName(field, options_)}}, R"cc( - $field$ = ($has_msg$) - ? CreateMaybeMessage<$submsg$>(arena, *from.$field$) - : nullptr; + $field$ = ($has_msg$) ? $superclass$::CopyConstruct<$submsg$>( + arena, *from.$field$) + : nullptr; )cc"); }; @@ -3000,26 +3000,12 @@ void MessageGenerator::GenerateSourceInProto2Namespace(io::Printer* p) { Formatter format(p); if (ShouldGenerateExternSpecializations(options_) && ShouldGenerateClass(descriptor_, options_)) { - format(R"cc( - template <> - PROTOBUF_NOINLINE $classtype$* Arena::CreateMaybeMessage<$classtype$>( - Arena* arena) { - using T = $classtype$; - void* mem = arena != nullptr ? arena->AllocateAligned(sizeof(T)) - : ::operator new(sizeof(T)); - return new (mem) T(arena); - } + p->Emit(R"cc( + template void* Arena::DefaultConstruct<$classtype$>(Arena*); )cc"); if (!IsMapEntryMessage(descriptor_)) { - format(R"cc( - template <> - PROTOBUF_NOINLINE $classtype$* Arena::CreateMaybeMessage<$classtype$>( - Arena* arena, const $classtype$& from) { - using T = $classtype$; - void* mem = arena != nullptr ? arena->AllocateAligned(sizeof(T)) - : ::operator new(sizeof(T)); - return new (mem) T(arena, from); - } + p->Emit(R"cc( + template void* Arena::CopyConstruct<$classtype$>(Arena*, const void*); )cc"); } } diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index e4b0a514fe..e57275a2dc 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -190,7 +190,7 @@ class PROTOC_EXPORT JavaFeatures final : // implements Message ---------------------------------------------- JavaFeatures* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const JavaFeatures& from); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index dc37bd6e68..17247abad6 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -665,9 +665,9 @@ CodeGeneratorRequest::CodeGeneratorRequest( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.compiler_version_ = (cached_has_bits & 0x00000002u) - ? CreateMaybeMessage<::google::protobuf::compiler::Version>(arena, *from._impl_.compiler_version_) - : nullptr; + _impl_.compiler_version_ = (cached_has_bits & 0x00000002u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::compiler::Version>( + arena, *from._impl_.compiler_version_) + : nullptr; // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorRequest) } @@ -922,7 +922,8 @@ void CodeGeneratorRequest::MergeImpl(::google::protobuf::Message& to_msg, const if (cached_has_bits & 0x00000002u) { ABSL_DCHECK(from._impl_.compiler_version_ != nullptr); if (_this->_impl_.compiler_version_ == nullptr) { - _this->_impl_.compiler_version_ = CreateMaybeMessage<::google::protobuf::compiler::Version>(arena, *from._impl_.compiler_version_); + _this->_impl_.compiler_version_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::compiler::Version>(arena, *from._impl_.compiler_version_); } else { _this->_impl_.compiler_version_->MergeFrom(*from._impl_.compiler_version_); } @@ -1019,9 +1020,9 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.generated_code_info_ = (cached_has_bits & 0x00000008u) - ? CreateMaybeMessage<::google::protobuf::GeneratedCodeInfo>(arena, *from._impl_.generated_code_info_) - : nullptr; + _impl_.generated_code_info_ = (cached_has_bits & 0x00000008u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::GeneratedCodeInfo>( + arena, *from._impl_.generated_code_info_) + : nullptr; // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorResponse.File) } @@ -1259,7 +1260,8 @@ void CodeGeneratorResponse_File::MergeImpl(::google::protobuf::Message& to_msg, if (cached_has_bits & 0x00000008u) { ABSL_DCHECK(from._impl_.generated_code_info_ != nullptr); if (_this->_impl_.generated_code_info_ == nullptr) { - _this->_impl_.generated_code_info_ = CreateMaybeMessage<::google::protobuf::GeneratedCodeInfo>(arena, *from._impl_.generated_code_info_); + _this->_impl_.generated_code_info_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::GeneratedCodeInfo>(arena, *from._impl_.generated_code_info_); } else { _this->_impl_.generated_code_info_->MergeFrom(*from._impl_.generated_code_info_); } diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index d4d3613920..e48dbb6d06 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -207,7 +207,7 @@ class PROTOC_EXPORT Version final : // implements Message ---------------------------------------------- Version* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Version& from); @@ -426,7 +426,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final : // implements Message ---------------------------------------------- CodeGeneratorResponse_File* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const CodeGeneratorResponse_File& from); @@ -661,7 +661,7 @@ class PROTOC_EXPORT CodeGeneratorResponse final : // implements Message ---------------------------------------------- CodeGeneratorResponse* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const CodeGeneratorResponse& from); @@ -897,7 +897,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final : // implements Message ---------------------------------------------- CodeGeneratorRequest* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const CodeGeneratorRequest& from); @@ -1580,7 +1580,7 @@ inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::_internal_mu PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000002u; if (_impl_.compiler_version_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::compiler::Version>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::compiler::Version>(GetArena()); _impl_.compiler_version_ = reinterpret_cast<::google::protobuf::compiler::Version*>(p); } return _impl_.compiler_version_; @@ -1888,7 +1888,7 @@ inline ::google::protobuf::GeneratedCodeInfo* CodeGeneratorResponse_File::_inter PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000008u; if (_impl_.generated_code_info_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::GeneratedCodeInfo>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::GeneratedCodeInfo>(GetArena()); _impl_.generated_code_info_ = reinterpret_cast<::google::protobuf::GeneratedCodeInfo*>(p); } return _impl_.generated_code_info_; diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index c06083ecad..cab376f695 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -159,7 +159,7 @@ class PROTOBUF_EXPORT CppFeatures final : // implements Message ---------------------------------------------- CppFeatures* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const CppFeatures& from); diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index a9006879bf..0a33adfd84 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -2599,12 +2599,12 @@ FileDescriptorProto::FileDescriptorProto( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000008u) - ? CreateMaybeMessage<::google::protobuf::FileOptions>(arena, *from._impl_.options_) - : nullptr; - _impl_.source_code_info_ = (cached_has_bits & 0x00000010u) - ? CreateMaybeMessage<::google::protobuf::SourceCodeInfo>(arena, *from._impl_.source_code_info_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000008u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FileOptions>( + arena, *from._impl_.options_) + : nullptr; + _impl_.source_code_info_ = (cached_has_bits & 0x00000010u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::SourceCodeInfo>( + arena, *from._impl_.source_code_info_) + : nullptr; _impl_.edition_ = from._impl_.edition_; // @@protoc_insertion_point(copy_constructor:google.protobuf.FileDescriptorProto) @@ -3072,7 +3072,8 @@ void FileDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const : if (cached_has_bits & 0x00000008u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::FileOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FileOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -3081,7 +3082,8 @@ void FileDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const : if (cached_has_bits & 0x00000010u) { ABSL_DCHECK(from._impl_.source_code_info_ != nullptr); if (_this->_impl_.source_code_info_ == nullptr) { - _this->_impl_.source_code_info_ = CreateMaybeMessage<::google::protobuf::SourceCodeInfo>(arena, *from._impl_.source_code_info_); + _this->_impl_.source_code_info_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::SourceCodeInfo>(arena, *from._impl_.source_code_info_); } else { _this->_impl_.source_code_info_->MergeFrom(*from._impl_.source_code_info_); } @@ -3189,9 +3191,9 @@ DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::ExtensionRangeOptions>(arena, *from._impl_.options_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::ExtensionRangeOptions>( + arena, *from._impl_.options_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, start_), reinterpret_cast(&from._impl_) + @@ -3393,7 +3395,8 @@ void DescriptorProto_ExtensionRange::MergeImpl(::google::protobuf::Message& to_m if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::ExtensionRangeOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::ExtensionRangeOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -3716,9 +3719,9 @@ DescriptorProto::DescriptorProto( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000002u) - ? CreateMaybeMessage<::google::protobuf::MessageOptions>(arena, *from._impl_.options_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000002u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::MessageOptions>( + arena, *from._impl_.options_) + : nullptr; // @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto) } @@ -4102,7 +4105,8 @@ void DescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const ::goo if (cached_has_bits & 0x00000002u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::MessageOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::MessageOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -4551,9 +4555,9 @@ ExtensionRangeOptions::ExtensionRangeOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; _impl_.verification_ = from._impl_.verification_; // @@protoc_insertion_point(copy_constructor:google.protobuf.ExtensionRangeOptions) @@ -4786,7 +4790,8 @@ void ExtensionRangeOptions::MergeImpl(::google::protobuf::Message& to_msg, const if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -4912,9 +4917,9 @@ FieldDescriptorProto::FieldDescriptorProto( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000020u) - ? CreateMaybeMessage<::google::protobuf::FieldOptions>(arena, *from._impl_.options_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000020u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FieldOptions>( + arena, *from._impl_.options_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, number_), reinterpret_cast(&from._impl_) + @@ -5334,7 +5339,8 @@ void FieldDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const if (cached_has_bits & 0x00000020u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::FieldOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FieldOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -5442,9 +5448,9 @@ OneofDescriptorProto::OneofDescriptorProto( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000002u) - ? CreateMaybeMessage<::google::protobuf::OneofOptions>(arena, *from._impl_.options_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000002u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::OneofOptions>( + arena, *from._impl_.options_) + : nullptr; // @@protoc_insertion_point(copy_constructor:google.protobuf.OneofDescriptorProto) } @@ -5623,7 +5629,8 @@ void OneofDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const if (cached_has_bits & 0x00000002u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::OneofOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::OneofOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -5932,9 +5939,9 @@ EnumDescriptorProto::EnumDescriptorProto( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000002u) - ? CreateMaybeMessage<::google::protobuf::EnumOptions>(arena, *from._impl_.options_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000002u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::EnumOptions>( + arena, *from._impl_.options_) + : nullptr; // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumDescriptorProto) } @@ -6190,7 +6197,8 @@ void EnumDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const : if (cached_has_bits & 0x00000002u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::EnumOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::EnumOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -6278,9 +6286,9 @@ EnumValueDescriptorProto::EnumValueDescriptorProto( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000002u) - ? CreateMaybeMessage<::google::protobuf::EnumValueOptions>(arena, *from._impl_.options_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000002u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::EnumValueOptions>( + arena, *from._impl_.options_) + : nullptr; _impl_.number_ = from._impl_.number_; // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValueDescriptorProto) @@ -6486,7 +6494,8 @@ void EnumValueDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, co if (cached_has_bits & 0x00000002u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::EnumValueOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::EnumValueOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -6576,9 +6585,9 @@ ServiceDescriptorProto::ServiceDescriptorProto( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000002u) - ? CreateMaybeMessage<::google::protobuf::ServiceOptions>(arena, *from._impl_.options_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000002u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::ServiceOptions>( + arena, *from._impl_.options_) + : nullptr; // @@protoc_insertion_point(copy_constructor:google.protobuf.ServiceDescriptorProto) } @@ -6783,7 +6792,8 @@ void ServiceDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, cons if (cached_has_bits & 0x00000002u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::ServiceOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::ServiceOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -6880,9 +6890,9 @@ MethodDescriptorProto::MethodDescriptorProto( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.options_ = (cached_has_bits & 0x00000008u) - ? CreateMaybeMessage<::google::protobuf::MethodOptions>(arena, *from._impl_.options_) - : nullptr; + _impl_.options_ = (cached_has_bits & 0x00000008u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::MethodOptions>( + arena, *from._impl_.options_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, client_streaming_), reinterpret_cast(&from._impl_) + @@ -7172,7 +7182,8 @@ void MethodDescriptorProto::MergeImpl(::google::protobuf::Message& to_msg, const if (cached_has_bits & 0x00000008u) { ABSL_DCHECK(from._impl_.options_ != nullptr); if (_this->_impl_.options_ == nullptr) { - _this->_impl_.options_ = CreateMaybeMessage<::google::protobuf::MethodOptions>(arena, *from._impl_.options_); + _this->_impl_.options_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::MethodOptions>(arena, *from._impl_.options_); } else { _this->_impl_.options_->MergeFrom(*from._impl_.options_); } @@ -7335,9 +7346,9 @@ FileOptions::FileOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000400u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000400u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, java_multiple_files_), reinterpret_cast(&from._impl_) + @@ -8030,7 +8041,8 @@ void FileOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google: if (cached_has_bits & 0x00000400u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -8180,9 +8192,9 @@ MessageOptions::MessageOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, message_set_wire_format_), reinterpret_cast(&from._impl_) + @@ -8466,7 +8478,8 @@ void MessageOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::goog if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -8839,9 +8852,9 @@ FieldOptions::FieldOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, ctype_), reinterpret_cast(&from._impl_) + @@ -9265,7 +9278,8 @@ void FieldOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -9387,9 +9401,9 @@ OneofOptions::OneofOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; // @@protoc_insertion_point(copy_constructor:google.protobuf.OneofOptions) } @@ -9567,7 +9581,8 @@ void OneofOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -9659,9 +9674,9 @@ EnumOptions::EnumOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, allow_alias_), reinterpret_cast(&from._impl_) + @@ -9911,7 +9926,8 @@ void EnumOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::google: if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -10016,9 +10032,9 @@ EnumValueOptions::EnumValueOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, deprecated_), reinterpret_cast(&from._impl_) + @@ -10253,7 +10269,8 @@ void EnumValueOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::go if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -10352,9 +10369,9 @@ ServiceOptions::ServiceOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; _impl_.deprecated_ = from._impl_.deprecated_; // @@protoc_insertion_point(copy_constructor:google.protobuf.ServiceOptions) @@ -10561,7 +10578,8 @@ void ServiceOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::goog if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -10660,9 +10678,9 @@ MethodOptions::MethodOptions( new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); _impl_._extensions_.MergeFrom(this, from._impl_._extensions_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; ::memcpy(reinterpret_cast(&_impl_) + offsetof(Impl_, deprecated_), reinterpret_cast(&from._impl_) + @@ -10902,7 +10920,8 @@ void MethodOptions::MergeImpl(::google::protobuf::Message& to_msg, const ::googl if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } @@ -12013,9 +12032,9 @@ FeatureSetDefaults_FeatureSetEditionDefault::FeatureSetDefaults_FeatureSetEditio from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.features_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_) - : nullptr; + _impl_.features_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>( + arena, *from._impl_.features_) + : nullptr; _impl_.edition_ = from._impl_.edition_; // @@protoc_insertion_point(copy_constructor:google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault) @@ -12188,7 +12207,8 @@ void FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl(::google::protobuf:: if (cached_has_bits & 0x00000001u) { ABSL_DCHECK(from._impl_.features_ != nullptr); if (_this->_impl_.features_ == nullptr) { - _this->_impl_.features_ = CreateMaybeMessage<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); + _this->_impl_.features_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::FeatureSet>(arena, *from._impl_.features_); } else { _this->_impl_.features_->MergeFrom(*from._impl_.features_); } diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 5a0ab746b2..658988ebc0 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -788,7 +788,7 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final : // implements Message ---------------------------------------------- UninterpretedOption_NamePart* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const UninterpretedOption_NamePart& from); @@ -981,7 +981,7 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final : // implements Message ---------------------------------------------- SourceCodeInfo_Location* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const SourceCodeInfo_Location& from); @@ -1252,7 +1252,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : // implements Message ---------------------------------------------- GeneratedCodeInfo_Annotation* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const GeneratedCodeInfo_Annotation& from); @@ -1513,7 +1513,7 @@ class PROTOBUF_EXPORT FieldOptions_EditionDefault final : // implements Message ---------------------------------------------- FieldOptions_EditionDefault* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FieldOptions_EditionDefault& from); @@ -1706,7 +1706,7 @@ class PROTOBUF_EXPORT FeatureSet final : // implements Message ---------------------------------------------- FeatureSet* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FeatureSet& from); @@ -2251,7 +2251,7 @@ class PROTOBUF_EXPORT ExtensionRangeOptions_Declaration final : // implements Message ---------------------------------------------- ExtensionRangeOptions_Declaration* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const ExtensionRangeOptions_Declaration& from); @@ -2489,7 +2489,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : // implements Message ---------------------------------------------- EnumDescriptorProto_EnumReservedRange* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const EnumDescriptorProto_EnumReservedRange& from); @@ -2676,7 +2676,7 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : // implements Message ---------------------------------------------- DescriptorProto_ReservedRange* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const DescriptorProto_ReservedRange& from); @@ -2863,7 +2863,7 @@ class PROTOBUF_EXPORT UninterpretedOption final : // implements Message ---------------------------------------------- UninterpretedOption* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const UninterpretedOption& from); @@ -3142,7 +3142,7 @@ class PROTOBUF_EXPORT SourceCodeInfo final : // implements Message ---------------------------------------------- SourceCodeInfo* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const SourceCodeInfo& from); @@ -3324,7 +3324,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final : // implements Message ---------------------------------------------- GeneratedCodeInfo* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const GeneratedCodeInfo& from); @@ -3506,7 +3506,7 @@ class PROTOBUF_EXPORT FeatureSetDefaults_FeatureSetEditionDefault final : // implements Message ---------------------------------------------- FeatureSetDefaults_FeatureSetEditionDefault* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FeatureSetDefaults_FeatureSetEditionDefault& from); @@ -3697,7 +3697,7 @@ class PROTOBUF_EXPORT ServiceOptions final : // implements Message ---------------------------------------------- ServiceOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const ServiceOptions& from); @@ -4087,7 +4087,7 @@ class PROTOBUF_EXPORT OneofOptions final : // implements Message ---------------------------------------------- OneofOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const OneofOptions& from); @@ -4464,7 +4464,7 @@ class PROTOBUF_EXPORT MethodOptions final : // implements Message ---------------------------------------------- MethodOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const MethodOptions& from); @@ -4888,7 +4888,7 @@ class PROTOBUF_EXPORT MessageOptions final : // implements Message ---------------------------------------------- MessageOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const MessageOptions& from); @@ -5330,7 +5330,7 @@ class PROTOBUF_EXPORT FileOptions final : // implements Message ---------------------------------------------- FileOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FileOptions& from); @@ -6048,7 +6048,7 @@ class PROTOBUF_EXPORT FieldOptions final : // implements Message ---------------------------------------------- FieldOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FieldOptions& from); @@ -6676,7 +6676,7 @@ class PROTOBUF_EXPORT FeatureSetDefaults final : // implements Message ---------------------------------------------- FeatureSetDefaults* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FeatureSetDefaults& from); @@ -6885,7 +6885,7 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final : // implements Message ---------------------------------------------- ExtensionRangeOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const ExtensionRangeOptions& from); @@ -7317,7 +7317,7 @@ class PROTOBUF_EXPORT EnumValueOptions final : // implements Message ---------------------------------------------- EnumValueOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const EnumValueOptions& from); @@ -7720,7 +7720,7 @@ class PROTOBUF_EXPORT EnumOptions final : // implements Message ---------------------------------------------- EnumOptions* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const EnumOptions& from); @@ -8136,7 +8136,7 @@ class PROTOBUF_EXPORT OneofDescriptorProto final : // implements Message ---------------------------------------------- OneofDescriptorProto* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const OneofDescriptorProto& from); @@ -8333,7 +8333,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto final : // implements Message ---------------------------------------------- MethodDescriptorProto* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const MethodDescriptorProto& from); @@ -8594,7 +8594,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final : // implements Message ---------------------------------------------- FieldDescriptorProto* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FieldDescriptorProto& from); @@ -8989,7 +8989,7 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final : // implements Message ---------------------------------------------- EnumValueDescriptorProto* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const EnumValueDescriptorProto& from); @@ -9199,7 +9199,7 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : // implements Message ---------------------------------------------- DescriptorProto_ExtensionRange* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const DescriptorProto_ExtensionRange& from); @@ -9403,7 +9403,7 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final : // implements Message ---------------------------------------------- ServiceDescriptorProto* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const ServiceDescriptorProto& from); @@ -9620,7 +9620,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto final : // implements Message ---------------------------------------------- EnumDescriptorProto* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const EnumDescriptorProto& from); @@ -9889,7 +9889,7 @@ class PROTOBUF_EXPORT DescriptorProto final : // implements Message ---------------------------------------------- DescriptorProto* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const DescriptorProto& from); @@ -10259,7 +10259,7 @@ class PROTOBUF_EXPORT FileDescriptorProto final : // implements Message ---------------------------------------------- FileDescriptorProto* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FileDescriptorProto& from); @@ -10674,7 +10674,7 @@ class PROTOBUF_EXPORT FileDescriptorSet final : // implements Message ---------------------------------------------- FileDescriptorSet* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FileDescriptorSet& from); @@ -11431,7 +11431,7 @@ inline ::google::protobuf::FileOptions* FileDescriptorProto::_internal_mutable_o PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000008u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FileOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FileOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::FileOptions*>(p); } return _impl_.options_; @@ -11527,7 +11527,7 @@ inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::_internal_mutabl PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000010u; if (_impl_.source_code_info_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::SourceCodeInfo>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::SourceCodeInfo>(GetArena()); _impl_.source_code_info_ = reinterpret_cast<::google::protobuf::SourceCodeInfo*>(p); } return _impl_.source_code_info_; @@ -11783,7 +11783,7 @@ inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::ExtensionRangeOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::ExtensionRangeOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::ExtensionRangeOptions*>(p); } return _impl_.options_; @@ -12308,7 +12308,7 @@ inline ::google::protobuf::MessageOptions* DescriptorProto::_internal_mutable_op PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000002u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::MessageOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::MessageOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::MessageOptions*>(p); } return _impl_.options_; @@ -12886,7 +12886,7 @@ inline ::google::protobuf::FeatureSet* ExtensionRangeOptions::_internal_mutable_ PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -13484,7 +13484,7 @@ inline ::google::protobuf::FieldOptions* FieldDescriptorProto::_internal_mutable PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000020u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FieldOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FieldOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::FieldOptions*>(p); } return _impl_.options_; @@ -13683,7 +13683,7 @@ inline ::google::protobuf::OneofOptions* OneofDescriptorProto::_internal_mutable PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000002u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::OneofOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::OneofOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::OneofOptions*>(p); } return _impl_.options_; @@ -13963,7 +13963,7 @@ inline ::google::protobuf::EnumOptions* EnumDescriptorProto::_internal_mutable_o PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000002u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::EnumOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::EnumOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::EnumOptions*>(p); } return _impl_.options_; @@ -14312,7 +14312,7 @@ inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::_internal PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000002u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::EnumValueOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::EnumValueOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::EnumValueOptions*>(p); } return _impl_.options_; @@ -14532,7 +14532,7 @@ inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::_internal_mut PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000002u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::ServiceOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::ServiceOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::ServiceOptions*>(p); } return _impl_.options_; @@ -14845,7 +14845,7 @@ inline ::google::protobuf::MethodOptions* MethodDescriptorProto::_internal_mutab PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000008u; if (_impl_.options_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::MethodOptions>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::MethodOptions>(GetArena()); _impl_.options_ = reinterpret_cast<::google::protobuf::MethodOptions*>(p); } return _impl_.options_; @@ -15992,7 +15992,7 @@ inline ::google::protobuf::FeatureSet* FileOptions::_internal_mutable_features() PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000400u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -16281,7 +16281,7 @@ inline ::google::protobuf::FeatureSet* MessageOptions::_internal_mutable_feature PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -16884,7 +16884,7 @@ inline ::google::protobuf::FeatureSet* FieldOptions::_internal_mutable_features( PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -17033,7 +17033,7 @@ inline ::google::protobuf::FeatureSet* OneofOptions::_internal_mutable_features( PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -17266,7 +17266,7 @@ inline ::google::protobuf::FeatureSet* EnumOptions::_internal_mutable_features() PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -17443,7 +17443,7 @@ inline ::google::protobuf::FeatureSet* EnumValueOptions::_internal_mutable_featu PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -17620,7 +17620,7 @@ inline ::google::protobuf::FeatureSet* ServiceOptions::_internal_mutable_feature PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -17854,7 +17854,7 @@ inline ::google::protobuf::FeatureSet* MethodOptions::_internal_mutable_features PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; @@ -18663,7 +18663,7 @@ inline ::google::protobuf::FeatureSet* FeatureSetDefaults_FeatureSetEditionDefau PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.features_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::FeatureSet>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::FeatureSet>(GetArena()); _impl_.features_ = reinterpret_cast<::google::protobuf::FeatureSet*>(p); } return _impl_.features_; diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index d6a473e0be..8b5e83c32a 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -651,11 +651,6 @@ void GenericTypeHandler::Merge(const MessageLite& from, MessageLite* to) { to->CheckTypeAndMergeFrom(from); } -template <> -void GenericTypeHandler::Merge(const std::string& from, - std::string* to) { - *to = from; -} // Non-inline variants of std::string specializations for // various InternalMetadata routines. diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 74f6be8612..58d44eb43e 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -505,13 +505,13 @@ class PROTOBUF_EXPORT MessageLite { } template - static T* CreateMaybeMessage(Arena* arena) { - return Arena::CreateMaybeMessage(arena); + PROTOBUF_ALWAYS_INLINE static T* DefaultConstruct(Arena* arena) { + return static_cast(Arena::DefaultConstruct(arena)); } template - static T* CreateMaybeMessage(Arena* arena, const T& from) { - return Arena::CreateMaybeMessage(arena, from); + PROTOBUF_ALWAYS_INLINE static T* CopyConstruct(Arena* arena, const T& from) { + return static_cast(Arena::CopyConstruct(arena, &from)); } inline explicit MessageLite(Arena* arena) : _internal_metadata_(arena) {} diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 4ac05d642f..2a98da24d4 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -219,8 +219,8 @@ void RepeatedPtrFieldBase::MergeFromConcreteMessage( const RepeatedPtrFieldBase& from, CopyFn copy_fn) { ABSL_DCHECK_NE(&from, this); int new_size = current_size_ + from.current_size_; - auto dst = reinterpret_cast(InternalReserve(new_size)); - auto src = reinterpret_cast(from.elements()); + void** dst = InternalReserve(new_size); + const void* const* src = from.elements(); auto end = src + from.current_size_; if (PROTOBUF_PREDICT_FALSE(ClearedCount() > 0)) { int recycled = MergeIntoClearedMessages(from); @@ -229,7 +229,7 @@ void RepeatedPtrFieldBase::MergeFromConcreteMessage( } Arena* arena = GetArena(); for (; src < end; ++src, ++dst) { - *dst = copy_fn(arena, **src); + *dst = copy_fn(arena, *src); } ExchangeCurrentSize(new_size); if (new_size > allocated_size()) { @@ -270,6 +270,10 @@ void RepeatedPtrFieldBase::MergeFrom( } } +void* NewStringElement(Arena* arena) { + return Arena::Create(arena); +} + } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 02661f6725..11ddd154ec 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -72,11 +72,6 @@ class RepeatedPtrOverPtrsIterator; namespace internal { -template -inline void* NewT(Arena* a) { - return GenericTypeHandler::New(a); -} - // Swaps two non-overlapping blocks of memory of size `N` template inline void memswap(char* PROTOBUF_RESTRICT a, char* PROTOBUF_RESTRICT b) { @@ -229,7 +224,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template Value* Add() { - return cast(AddOutOfLineHelper(NewT>)); + return cast(AddOutOfLineHelper(Handler::GetNewFunc())); } template < @@ -304,17 +299,11 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { } } - // Message creating functor: used in MergeFrom() - template - static MessageLite* CopyMessage(Arena* arena, const MessageLite& src) { - return Arena::CreateMaybeMessage(arena, static_cast(src)); - } - // Appends all message values from `from` to this instance. template void MergeFrom(const RepeatedPtrFieldBase& from) { static_assert(std::is_base_of::value, ""); - MergeFromConcreteMessage(from, CopyMessage); + MergeFromConcreteMessage(from, Arena::CopyConstruct); } inline void InternalSwap(RepeatedPtrFieldBase* PROTOBUF_RESTRICT rhs) { @@ -693,7 +682,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // This follows the `Arena::CreateMaybeMessage` signature so that the compiler // can have the inlined call into the out of line copy function(s) simply pass // the address of `Arena::CreateMaybeMessage` 'as is'. - using CopyFn = MessageLite* (*)(Arena*, const MessageLite&); + using CopyFn = void* (*)(Arena*, const void*); struct Rep { int allocated_size; @@ -891,8 +880,10 @@ class GenericTypeHandler { typedef GenericType Type; using Movable = IsMovable; + static constexpr auto GetNewFunc() { return Arena::DefaultConstruct; } + static inline GenericType* New(Arena* arena) { - return Arena::CreateMaybeMessage(arena); + return static_cast(Arena::DefaultConstruct(arena)); } static inline GenericType* New(Arena* arena, GenericType&& value) { return Arena::Create(arena, std::move(value)); @@ -951,14 +942,6 @@ template <> PROTOBUF_EXPORT void GenericTypeHandler::Merge( const MessageLite& from, MessageLite* to); -template <> -inline void GenericTypeHandler::Clear(std::string* value) { - value->clear(); -} -template <> -void GenericTypeHandler::Merge(const std::string& from, - std::string* to); - // Message specialization bodies defined in message.cc. This split is necessary // to allow proto2-lite (which includes this header) to be independent of // Message. @@ -968,11 +951,16 @@ PROTOBUF_EXPORT Message* GenericTypeHandler::NewFromPrototype( template <> PROTOBUF_EXPORT Arena* GenericTypeHandler::GetArena(Message* value); -class StringTypeHandler { +PROTOBUF_EXPORT void* NewStringElement(Arena* arena); + +template <> +class GenericTypeHandler { public: typedef std::string Type; using Movable = IsMovable; + static constexpr auto GetNewFunc() { return NewStringElement; } + static PROTOBUF_NOINLINE std::string* New(Arena* arena) { return Arena::Create(arena); } @@ -1333,7 +1321,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { friend struct WeakRepeatedPtrField; // Note: RepeatedPtrField SHOULD NOT be subclassed by users. - class TypeHandler; + using TypeHandler = internal::GenericTypeHandler; RepeatedPtrField(Arena* arena, const RepeatedPtrField& rhs); @@ -1354,14 +1342,6 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { // ------------------------------------------------------------------- -template -class RepeatedPtrField::TypeHandler - : public internal::GenericTypeHandler {}; - -template <> -class RepeatedPtrField::TypeHandler - : public internal::StringTypeHandler {}; - template constexpr RepeatedPtrField::RepeatedPtrField() : RepeatedPtrFieldBase() { @@ -1373,7 +1353,7 @@ inline RepeatedPtrField::RepeatedPtrField(Arena* arena) : RepeatedPtrFieldBase(arena) { // We can't have StaticValidityCheck here because that requires Element to be // a complete type, and in split repeated fields cases, we call - // CreateMaybeMessage> for incomplete Ts. + // CreateMessage> for incomplete Ts. } template From 01292502fa8363e548ecfb8d6ce900a39f4076a4 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 8 Nov 2023 07:50:44 -0800 Subject: [PATCH 127/387] Squashed 'third_party/utf8_range/' changes from d863bc33e..0e378bdb2 (#14679) 0e378bdb2 Add missing `` include to utf8_validity_fuzzer.cc git-subtree-dir: third_party/utf8_range git-subtree-split: 0e378bdb224cc8d4653b0db963b474839c2bb43c --- .../.github/workflows/bazel_tests.yml | 2 +- third_party/utf8_range/BUILD.bazel | 5 +++- third_party/utf8_range/WORKSPACE | 23 ++++++++++++++--- .../utf8_range/fuzz/utf8_validity_fuzzer.cc | 2 ++ third_party/utf8_range/rules_fuzzing.patch | 25 +++++++++++++++++++ 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 third_party/utf8_range/rules_fuzzing.patch diff --git a/third_party/utf8_range/.github/workflows/bazel_tests.yml b/third_party/utf8_range/.github/workflows/bazel_tests.yml index adf711859a..97ade8dbd9 100644 --- a/third_party/utf8_range/.github/workflows/bazel_tests.yml +++ b/third_party/utf8_range/.github/workflows/bazel_tests.yml @@ -32,7 +32,7 @@ jobs: - name: Setup Bazel run: | echo "BAZEL=bazel" >> $GITHUB_ENV - echo "USE_BAZEL_VERSION=5.1.1" >> $GITHUB_ENV + echo "USE_BAZEL_VERSION=6.4.0" >> $GITHUB_ENV - name: Setup Bazel (macOS) if: runner.os == 'macOS' run: echo "BAZEL=bazelisk" >> $GITHUB_ENV diff --git a/third_party/utf8_range/BUILD.bazel b/third_party/utf8_range/BUILD.bazel index b9ba04e17c..1e2992fc25 100644 --- a/third_party/utf8_range/BUILD.bazel +++ b/third_party/utf8_range/BUILD.bazel @@ -14,7 +14,10 @@ package(default_visibility = ["//visibility:public"]) licenses(["notice"]) -exports_files(["LICENSE"]) +exports_files([ + "LICENSE", + "rules_fuzzing.patch", +]) # TODO(b/252876197) Remove this once callers have been Bazelified. filegroup( diff --git a/third_party/utf8_range/WORKSPACE b/third_party/utf8_range/WORKSPACE index 42708aff82..84634cb7e2 100644 --- a/third_party/utf8_range/WORKSPACE +++ b/third_party/utf8_range/WORKSPACE @@ -5,6 +5,17 @@ load("//:workspace_deps.bzl", "utf8_range_deps") utf8_range_deps() +http_archive( + name = "rules_python", + sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b", + strip_prefix = "rules_python-0.26.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.26.0/rules_python-0.26.0.tar.gz", +) + +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + http_archive( name = "com_google_googletest", sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2", @@ -17,9 +28,11 @@ http_archive( http_archive( name = "rules_fuzzing", - sha256 = "d9002dd3cd6437017f08593124fdd1b13b3473c7b929ceb0e60d317cb9346118", - strip_prefix = "rules_fuzzing-0.3.2", - urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.3.2.zip"], + sha256 = "ff52ef4845ab00e95d29c02a9e32e9eff4e0a4c9c8a6bcf8407a2f19eb3f9190", + strip_prefix = "rules_fuzzing-0.4.1", + urls = ["https://github.com/bazelbuild/rules_fuzzing/releases/download/v0.4.1/rules_fuzzing-0.4.1.zip"], + patches = ["//:rules_fuzzing.patch"], + patch_args = ["-p1"], ) load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") @@ -29,3 +42,7 @@ rules_fuzzing_dependencies() load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init") rules_fuzzing_init() + +load("@fuzzing_py_deps//:requirements.bzl", "install_deps") + +install_deps() diff --git a/third_party/utf8_range/fuzz/utf8_validity_fuzzer.cc b/third_party/utf8_range/fuzz/utf8_validity_fuzzer.cc index 4578600d05..c596823abe 100644 --- a/third_party/utf8_range/fuzz/utf8_validity_fuzzer.cc +++ b/third_party/utf8_range/fuzz/utf8_validity_fuzzer.cc @@ -4,6 +4,8 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +#include + #include "utf8_validity.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { diff --git a/third_party/utf8_range/rules_fuzzing.patch b/third_party/utf8_range/rules_fuzzing.patch new file mode 100644 index 0000000000..b522abb73f --- /dev/null +++ b/third_party/utf8_range/rules_fuzzing.patch @@ -0,0 +1,25 @@ +diff --git a/fuzzing/tools/validate_dict.py b/fuzzing/tools/validate_dict.py +index d561e68..52cbcb8 100644 +--- a/fuzzing/tools/validate_dict.py ++++ b/fuzzing/tools/validate_dict.py +@@ -19,7 +19,7 @@ Validates and merges a set of fuzzing dictionary files into a single output. + + from absl import app + from absl import flags +-from dict_validation import validate_line ++from fuzzing.tools.dict_validation import validate_line + from sys import stderr + + FLAGS = flags.FLAGS +diff --git a/fuzzing/requirements.txt b/fuzzing/requirements.txt +index 01482d4..4b36f4f 100644 +--- a/fuzzing/requirements.txt ++++ b/fuzzing/requirements.txt +@@ -1,5 +1,5 @@ + # Python requirements for the tools supporting the fuzzing rules. These are + # installed automatically through the WORKSPACE configuration. + +-absl-py==0.11.0 --hash=sha256:b3d9eb5119ff6e0a0125f6dabf2f9fae02f8acae7be70576002fac27235611c5 +-six==1.15.0 --hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced ++absl-py==2.0.0 --hash=sha256:9a28abb62774ae4e8edbe2dd4c49ffcd45a6a848952a5eccc6a49f3f0fc1e2f3 ++six==1.15.0 From 5c7b41a76974bf1af0b605090fed27ce63fcd36b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 8 Nov 2023 15:52:01 +0000 Subject: [PATCH 128/387] Auto-generate files after cl/580530262 --- src/google/protobuf/any.pb.h | 2 +- src/google/protobuf/api.pb.cc | 9 +++++---- src/google/protobuf/api.pb.h | 8 ++++---- src/google/protobuf/duration.pb.h | 2 +- src/google/protobuf/empty.pb.h | 2 +- src/google/protobuf/field_mask.pb.h | 2 +- src/google/protobuf/source_context.pb.h | 2 +- src/google/protobuf/struct.pb.cc | 4 ++-- src/google/protobuf/struct.pb.h | 12 ++++++----- src/google/protobuf/timestamp.pb.h | 2 +- src/google/protobuf/type.pb.cc | 27 ++++++++++++++----------- src/google/protobuf/type.pb.h | 16 +++++++-------- src/google/protobuf/wrappers.pb.h | 18 ++++++++--------- 13 files changed, 56 insertions(+), 50 deletions(-) diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 9ce9e6f2a9..c1ecb27c2d 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -192,7 +192,7 @@ class PROTOBUF_EXPORT Any final : // implements Message ---------------------------------------------- Any* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Any& from); diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index a38ddbaa58..1de9fd8223 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -293,9 +293,9 @@ Api::Api( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.source_context_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_) - : nullptr; + _impl_.source_context_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::SourceContext>( + arena, *from._impl_.source_context_) + : nullptr; _impl_.syntax_ = from._impl_.syntax_; // @@protoc_insertion_point(copy_constructor:google.protobuf.Api) @@ -596,7 +596,8 @@ void Api::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobu if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { ABSL_DCHECK(from._impl_.source_context_ != nullptr); if (_this->_impl_.source_context_ == nullptr) { - _this->_impl_.source_context_ = CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); + _this->_impl_.source_context_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); } else { _this->_impl_.source_context_->MergeFrom(*from._impl_.source_context_); } diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 2252373551..efec0866d4 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -165,7 +165,7 @@ class PROTOBUF_EXPORT Mixin final : // implements Message ---------------------------------------------- Mixin* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Mixin& from); @@ -361,7 +361,7 @@ class PROTOBUF_EXPORT Method final : // implements Message ---------------------------------------------- Method* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Method& from); @@ -631,7 +631,7 @@ class PROTOBUF_EXPORT Api final : // implements Message ---------------------------------------------- Api* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Api& from); @@ -1107,7 +1107,7 @@ inline ::google::protobuf::SourceContext* Api::_internal_mutable_source_context( PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_._has_bits_[0] |= 0x00000001u; if (_impl_.source_context_ == nullptr) { - auto* p = CreateMaybeMessage<::google::protobuf::SourceContext>(GetArena()); + auto* p = ::google::protobuf::Message::DefaultConstruct<::google::protobuf::SourceContext>(GetArena()); _impl_.source_context_ = reinterpret_cast<::google::protobuf::SourceContext*>(p); } return _impl_.source_context_; diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index c165b574b7..df3f7fbcfc 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -157,7 +157,7 @@ class PROTOBUF_EXPORT Duration final : // implements Message ---------------------------------------------- Duration* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Duration& from); diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 1b929ecffe..903b06159c 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -157,7 +157,7 @@ class PROTOBUF_EXPORT Empty final : // implements Message ---------------------------------------------- Empty* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::internal::ZeroFieldsBase::DefaultConstruct(arena); } using ::google::protobuf::internal::ZeroFieldsBase::CopyFrom; inline void CopyFrom(const Empty& from) { diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 123d28d102..bf0902728e 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -157,7 +157,7 @@ class PROTOBUF_EXPORT FieldMask final : // implements Message ---------------------------------------------- FieldMask* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const FieldMask& from); diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 1504fe9015..af0a1f566e 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -157,7 +157,7 @@ class PROTOBUF_EXPORT SourceContext final : // implements Message ---------------------------------------------- SourceContext* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const SourceContext& from); diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 4d1b6255ae..e72e157147 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -525,10 +525,10 @@ Value::Value( _impl_.kind_.bool_value_ = from._impl_.kind_.bool_value_; break; case kStructValue: - _impl_.kind_.struct_value_ = CreateMaybeMessage<::google::protobuf::Struct>(arena, *from._impl_.kind_.struct_value_); + _impl_.kind_.struct_value_ = ::google::protobuf::Message::CopyConstruct<::google::protobuf::Struct>(arena, *from._impl_.kind_.struct_value_); break; case kListValue: - _impl_.kind_.list_value_ = CreateMaybeMessage<::google::protobuf::ListValue>(arena, *from._impl_.kind_.list_value_); + _impl_.kind_.list_value_ = ::google::protobuf::Message::CopyConstruct<::google::protobuf::ListValue>(arena, *from._impl_.kind_.list_value_); break; } diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 6f5d3e968b..643e6399cb 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -202,7 +202,7 @@ class PROTOBUF_EXPORT ListValue final : // implements Message ---------------------------------------------- ListValue* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const ListValue& from); @@ -382,7 +382,7 @@ class PROTOBUF_EXPORT Struct final : // implements Message ---------------------------------------------- Struct* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Struct& from); @@ -601,7 +601,7 @@ class PROTOBUF_EXPORT Value final : // implements Message ---------------------------------------------- Value* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Value& from); @@ -1101,7 +1101,8 @@ inline ::google::protobuf::Struct* Value::_internal_mutable_struct_value() { if (kind_case() != kStructValue) { clear_kind(); set_has_struct_value(); - _impl_.kind_.struct_value_ = CreateMaybeMessage<::google::protobuf::Struct>(GetArena()); + _impl_.kind_.struct_value_ = + ::google::protobuf::Message::DefaultConstruct<::google::protobuf::Struct>(GetArena()); } return _impl_.kind_.struct_value_; } @@ -1177,7 +1178,8 @@ inline ::google::protobuf::ListValue* Value::_internal_mutable_list_value() { if (kind_case() != kListValue) { clear_kind(); set_has_list_value(); - _impl_.kind_.list_value_ = CreateMaybeMessage<::google::protobuf::ListValue>(GetArena()); + _impl_.kind_.list_value_ = + ::google::protobuf::Message::DefaultConstruct<::google::protobuf::ListValue>(GetArena()); } return _impl_.kind_.list_value_; } diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 6a6b310aac..0009e3f121 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -157,7 +157,7 @@ class PROTOBUF_EXPORT Timestamp final : // implements Message ---------------------------------------------- Timestamp* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage(arena); + return ::google::protobuf::Message::DefaultConstruct(arena); } using ::google::protobuf::Message::CopyFrom; void CopyFrom(const Timestamp& from); diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 4ae35c5542..a0cd02ea87 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -473,9 +473,9 @@ Type::Type( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.source_context_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_) - : nullptr; + _impl_.source_context_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::SourceContext>( + arena, *from._impl_.source_context_) + : nullptr; _impl_.syntax_ = from._impl_.syntax_; // @@protoc_insertion_point(copy_constructor:google.protobuf.Type) @@ -775,7 +775,8 @@ void Type::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protob if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { ABSL_DCHECK(from._impl_.source_context_ != nullptr); if (_this->_impl_.source_context_ == nullptr) { - _this->_impl_.source_context_ = CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); + _this->_impl_.source_context_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); } else { _this->_impl_.source_context_->MergeFrom(*from._impl_.source_context_); } @@ -1309,9 +1310,9 @@ Enum::Enum( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.source_context_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_) - : nullptr; + _impl_.source_context_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::SourceContext>( + arena, *from._impl_.source_context_) + : nullptr; _impl_.syntax_ = from._impl_.syntax_; // @@protoc_insertion_point(copy_constructor:google.protobuf.Enum) @@ -1588,7 +1589,8 @@ void Enum::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protob if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { ABSL_DCHECK(from._impl_.source_context_ != nullptr); if (_this->_impl_.source_context_ == nullptr) { - _this->_impl_.source_context_ = CreateMaybeMessage<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); + _this->_impl_.source_context_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::SourceContext>(arena, *from._impl_.source_context_); } else { _this->_impl_.source_context_->MergeFrom(*from._impl_.source_context_); } @@ -1921,9 +1923,9 @@ Option::Option( from._internal_metadata_); new (&_impl_) Impl_(internal_visibility(), arena, from._impl_); ::uint32_t cached_has_bits = _impl_._has_bits_[0]; - _impl_.value_ = (cached_has_bits & 0x00000001u) - ? CreateMaybeMessage<::google::protobuf::Any>(arena, *from._impl_.value_) - : nullptr; + _impl_.value_ = (cached_has_bits & 0x00000001u) ? ::google::protobuf::Message::CopyConstruct<::google::protobuf::Any>( + arena, *from._impl_.value_) + : nullptr; // @@protoc_insertion_point(copy_constructor:google.protobuf.Option) } @@ -2095,7 +2097,8 @@ void Option::MergeImpl(::google::protobuf::Message& to_msg, const ::google::prot if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) { ABSL_DCHECK(from._impl_.value_ != nullptr); if (_this->_impl_.value_ == nullptr) { - _this->_impl_.value_ = CreateMaybeMessage<::google::protobuf::Any>(arena, *from._impl_.value_); + _this->_impl_.value_ = + ::google::protobuf::Message::CopyConstruct<::google::protobuf::Any>(arena, *from._impl_.value_); } else { _this->_impl_.value_->MergeFrom(*from._impl_.value_); } diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index f15c09249d..12c26544e4 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -291,7 +291,7 @@ class PROTOBUF_EXPORT Option final : // implements Message ---------------------------------------------- Option* New(::google::protobuf::Arena* arena = nullptr) const final { - return CreateMaybeMessage