From ef70acbc03e8dbcf4370ee82b5371f01a4952e39 Mon Sep 17 00:00:00 2001 From: Joel Courtney Date: Wed, 3 Feb 2021 12:34:52 +1100 Subject: [PATCH 001/207] Improvement: better ruby from_* support in well_known_types.rb * Added capability to support from_* requests properly by adding class methods and returning self for instance methods * `Timestamp.from_time` * `Value.from_ruby` --- ruby/lib/google/protobuf/well_known_types.rb | 36 +++++++++++++++++++- ruby/tests/well_known_types_test.rb | 14 ++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/ruby/lib/google/protobuf/well_known_types.rb b/ruby/lib/google/protobuf/well_known_types.rb index 37f8d5b675..942782026c 100755 --- a/ruby/lib/google/protobuf/well_known_types.rb +++ b/ruby/lib/google/protobuf/well_known_types.rb @@ -82,9 +82,14 @@ module Google end end + def self.from_time(time) + Timestamp.new(seconds: time.to_i, nanos: time.nsec) + end + def from_time(time) self.seconds = time.to_i self.nanos = time.nsec + self end def to_i @@ -131,6 +136,34 @@ module Google raise UnexpectedStructType end end + + def self.from_ruby(value) + ret = Value.new + case value + when NilClass + ret.null_value = 0 + when Numeric + ret.number_value = value + when String + ret.string_value = value + when TrueClass + ret.bool_value = true + when FalseClass + ret.bool_value = false + when Struct + ret.struct_value = value + when Hash + ret.struct_value = Struct.from_hash(value) + when ListValue + ret.list_value = value + when Array + ret.list_value = ListValue.from_a(value) + else + raise UnexpectedStructType + end + + ret + end def from_ruby(value) case value @@ -155,6 +188,8 @@ module Google else raise UnexpectedStructType end + + self end end @@ -225,6 +260,5 @@ module Google ret end end - end end diff --git a/ruby/tests/well_known_types_test.rb b/ruby/tests/well_known_types_test.rb index 3eafe095ad..9949795250 100755 --- a/ruby/tests/well_known_types_test.rb +++ b/ruby/tests/well_known_types_test.rb @@ -15,16 +15,26 @@ class TestWellKnownTypes < Test::Unit::TestCase # millisecond accuracy time = Time.at(123456, 654321) - ts.from_time(time) + resp = ts.from_time(time) assert_equal 123456, ts.seconds assert_equal 654321000, ts.nanos assert_equal time, ts.to_time + assert_equal resp, ts # nanosecond accuracy time = Time.at(123456, Rational(654321321, 1000)) - ts.from_time(time) + resp = ts.from_time(time) + assert_equal 123456, ts.seconds assert_equal 654321321, ts.nanos assert_equal time, ts.to_time + assert_equal resp, ts + + # Class based initialisation using from_time + time = Time.at(123456, Rational(654321321, 1000)) + ts = Google::Protobuf::Timestamp.from_time(time) + assert_equal 123456, ts.seconds + assert_equal 654321000, ts.nanos + assert_equal time, ts.to_time end def test_duration From 519340d662379feae6a50973e43220d5f1e252f0 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 15 Oct 2021 14:33:06 -0700 Subject: [PATCH 002/207] Update protobuf version (#9106) --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 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/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 27 ++++++++++++++----- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 +-- src/Makefile.am | 2 +- src/google/protobuf/any.pb.h | 4 +-- src/google/protobuf/api.pb.h | 4 +-- src/google/protobuf/compiler/plugin.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 +-- 37 files changed, 80 insertions(+), 65 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 9b8fae51a7..6e0c840d45 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.18.1' + s.version = '3.19.0-rc1' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 4a5f7dd9c1..83981c66ea 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.18.1' + s.version = '3.19.0-rc1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index b7466c28b5..a45db7dec5 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.18.1],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.19.0-rc-1],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 8e5786fdbd..607ff258a8 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.18.1 + 3.19.0-rc1 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index f6d6069102..e4bb99d96e 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.18.1 + 3.19.0-rc1 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 849f9b0bb0..3b129aa97e 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.18.0 + 3.19.0-rc-1 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.18.0 + 3.19.0-rc-1 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.18.0' + implementation 'com.google.protobuf:protobuf-java:3.19.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 c4ec685537..ac7a69cd82 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.18.1 + 3.19.0-rc-1 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 3b56150e1c..778b8af5a5 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.18.1 + 3.19.0-rc-1 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 57416d3ed8..89e0d2011a 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.18.1 + 3.19.0-rc-1 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 40394eb77d..c21e7d561c 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.18.1 + 3.19.0-rc-1 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index 603609f676..fb1a8e3f11 100644 --- a/java/lite.md +++ b/java/lite.md @@ -30,7 +30,7 @@ protobuf Java runtime. If you are using Maven, use the following: com.google.protobuf protobuf-javalite - 3.18.1 + 3.19.0-rc-1 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index ac4f25c25d..d8d19c20ea 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.18.1 + 3.19.0-rc-1 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index e39536f920..8d05f91a5b 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.18.1 + 3.19.0-rc-1 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 3c955789ed..0fa2edbe09 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.18.1 + 3.19.0-rc-1 protobuf-java-util diff --git a/js/package.json b/js/package.json index 33f3009255..820cef75f9 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.18.1", + "version": "3.19.0-rc.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index f083785bb1..850563e1c1 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,15 +10,15 @@ protobuf-opensource@google.com yes - 2021-10-04 - + 2021-10-15 + - 3.18.1 - 3.18.1 + 3.19.0RC1 + 3.19.0 - stable - stable + beta + beta 3-Clause BSD License @@ -1098,5 +1098,20 @@ G A release. + + + 3.19.0RC1 + 3.19.0 + + + beta + beta + + 2021-10-15 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 8b5c8aa857..c3d74e1fb4 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -91,7 +91,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.18.1" +#define PHP_PROTOBUF_VERSION "3.19.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 7f6d71460c..72a807dc51 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1 @@ -PROTOBUF_VERSION = '3.18.1' +PROTOBUF_VERSION = '3.19.0-rc-1' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index c3aa37771f..e3f1051a3c 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.18.1 + 3.19.0-rc-1 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index b8122e82ae..a305bc2027 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.18.1' +__version__ = '3.19.0rc1' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index b4ae37bb3c..1388de2933 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.18.1" + s.version = "3.19.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 0b13996d82..16890fec85 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.18.1 + 3.19.0-rc-1 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.18.1 + 3.19.0-rc-1 org.jruby diff --git a/src/Makefile.am b/src/Makefile.am index 232955f904..f78c46c579 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 28:3:0 +PROTOBUF_VERSION = 30:0:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 60308ffbaf..e90d198cbc 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 e614f07a32..a2fa75a931 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 76c3da1de7..f3e28605bb 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 cf425ff7e4..4bc09d8e28 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 292c170750..8cd8cd1fe2 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 000c3dfaad..509443c96b 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 b0fb89254e..d2cd9d6a37 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 afa38b5617..a79e9cb8e1 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -153,22 +153,22 @@ #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 3018001 +#define PROTOBUF_VERSION 3019000 #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 3018000 +#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3019000 #ifdef PROTOBUF_MIN_PROTOC_VERSION #error PROTOBUF_MIN_PROTOC_VERSION was previously defined #endif -#define PROTOBUF_MIN_PROTOC_VERSION 3018000 +#define PROTOBUF_MIN_PROTOC_VERSION 3019000 #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined #endif -#define PROTOBUF_VERSION_SUFFIX "" +#define PROTOBUF_VERSION_SUFFIX "-rc1" #if defined(PROTOBUF_NAMESPACE) || defined(PROTOBUF_NAMESPACE_ID) #error PROTOBUF_NAMESPACE or PROTOBUF_NAMESPACE_ID was previously defined @@ -356,7 +356,7 @@ // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3018000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3019000 #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 d6bc1daef0..a703bb5316 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 83a9d90824..570303e2e7 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 1d25852264..238d5e8bb7 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -82,23 +82,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 3018001 +#define GOOGLE_PROTOBUF_VERSION 3019000 // 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 = 3018000; +static const int kMinHeaderVersionForLibrary = 3019000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3018000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3019000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 3018000; +static const int kMinHeaderVersionForProtoc = 3019000; // 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 66535fec6d..54604acf0d 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 027982829f..ae8c144449 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 e03527ad75..83d258b031 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3018000 +#if PROTOBUF_VERSION < 3019000 #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 -#if 3018001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019000 < 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 d1c6620347f9f2e1e5522168ba4a5e66fe56666e Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 15 Oct 2021 15:14:12 -0700 Subject: [PATCH 003/207] Update CHANGES.txt for 3.19.0 --- CHANGES.txt | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 66f1bc0f4c..ce3ec9f6b0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,20 +1,48 @@ -Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) - - Python - * Proto2 DecodeError now includes message name in error message +2021-10-15 version 3.19.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) C++ * Make proto2::Message::DiscardUnknownFields() non-virtual * Separate RepeatedPtrField into its own header file * For default floating point values of 0, consider all bits significant + * cmake: support `MSVC_RUNTIME_LIBRARY` property (#8851) + * Fix shadowing warnings (#8926) + * Fix for issue #8484, constant initialization doesn't compile in msvc clang-cl environment (#8993) + * Fix build on AIX and SunOS (#8373) (#9065) + * Add Android stlport and default toolchains to BUILD. (#8290) Java + * This release drops support for Java 7. Use 3.18.x if you still need Java 7 support. * For default floating point values of 0, consider all bits significant * Annotate `//java/com/google/protobuf/util/...` with nullness annotations + * Use ArrayList copy constructor (#7853) Kotlin * Switch Kotlin proto DSLs to be implemented with inline value classes + Python + * Proto2 DecodeError now includes message name in error message + * Make MessageToDict convert map keys to strings (#8122) + * Add python-requires in setup.py (#8989) + * Add python 3.10 (#9034) + + JavaScript + * Skip exports if not available by CommonJS (#8856) + * JS: Comply with CSP no-unsafe-eval. (#8864) + + PHP + * Added "object" as a reserved name for PHP (#8962) + + Ruby + * Override Map.clone to use Map's dup method (#7938) + * Ruby: build extensions for arm64-darwin (#8232) + * Add class method Timestamp.from_time to ruby well known types (#8562) + * Adopt pure ruby DSL implementation for JRuby (#9047) + * Add size to Map class (#8068) + + C# + * Correctly set ExtensionRegistry when parsing with MessageParser, but using an already existing CodedInputStream (#7246) + * [C#] Make FieldDescriptor propertyName public (#7642) + 2021-10-04 version 3.18.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Python From 53a1d66d9d7fa0efa4547308bca8e1f750ea6010 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 15 Oct 2021 15:35:27 -0700 Subject: [PATCH 004/207] Update PHP release notes for 3.19.0 (#9110) --- php/ext/google/protobuf/package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 850563e1c1..33b694f9ed 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -22,7 +22,7 @@ 3-Clause BSD License - * No new changes in 3.18.1 + * Added "object" as a reserved name (#8962) From 454778d011919601635b6f5070402918a6cf352e Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 15 Oct 2021 19:00:04 -0700 Subject: [PATCH 005/207] Python: fix usages of deprecated assertRaisesRegxp (#9098) assertRaisesRegexp has been deprecated in favor of the slightly different spelling assertRaisesRegex. Let's fix this just to clean up a bunch of deprecation warnings in the tests. --- .../internal/descriptor_database_test.py | 2 +- .../protobuf/internal/descriptor_pool_test.py | 4 +- .../protobuf/internal/json_format_test.py | 46 +++++++++---------- .../google/protobuf/internal/message_test.py | 4 +- .../protobuf/internal/reflection_test.py | 2 +- .../internal/well_known_types_test.py | 38 +++++++-------- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/python/google/protobuf/internal/descriptor_database_test.py b/python/google/protobuf/internal/descriptor_database_test.py index ad3ca645f9..3c086b9247 100644 --- a/python/google/protobuf/internal/descriptor_database_test.py +++ b/python/google/protobuf/internal/descriptor_database_test.py @@ -100,7 +100,7 @@ class DescriptorDatabaseTest(unittest.TestCase): self.assertEqual(file_desc_proto2, db.FindFileContainingSymbol( 'protobuf_unittest.TestAllTypes.none_field')) - with self.assertRaisesRegexp(KeyError, r'\'protobuf_unittest\.NoneMessage\''): + with self.assertRaisesRegex(KeyError, r'\'protobuf_unittest\.NoneMessage\''): db.FindFileContainingSymbol('protobuf_unittest.NoneMessage') def testConflictRegister(self): diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index e59cf9b97e..9727692a26 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -648,10 +648,10 @@ class SecondaryDescriptorFromDescriptorDB(DescriptorPoolTestBase, enum_value.number = 0 self.db.Add(file_proto) - self.assertRaisesRegexp(KeyError, 'SubMessage', + self.assertRaisesRegex(KeyError, 'SubMessage', self.pool.FindMessageTypeByName, 'collector.ErrorMessage') - self.assertRaisesRegexp(KeyError, 'SubMessage', + self.assertRaisesRegex(KeyError, 'SubMessage', self.pool.FindFileByName, 'error_file') with self.assertRaises(KeyError) as exc: self.pool.FindFileByName('none_file') diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index af3713fcb5..092dfdb1fa 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -100,7 +100,7 @@ class JsonFormatBase(unittest.TestCase): def CheckError(self, text, error_message): message = json_format_proto3_pb2.TestMessage() - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, error_message, json_format.Parse, text, message) @@ -813,7 +813,7 @@ class JsonFormatTest(JsonFormatBase): json_format.Parse('{"messageValue": {}}', parsed_message) self.assertTrue(parsed_message.HasField('message_value')) # Null is not allowed to be used as an element in repeated field. - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to parse repeatedInt32Value field: ' 'null is not allowed to be used as an element in a repeated field.', @@ -901,7 +901,7 @@ class JsonFormatTest(JsonFormatBase): json_format.Parse(text, message) # Proto2 does not accept unknown enums. message = unittest_pb2.TestAllTypes() - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to parse optionalNestedEnum field: Invalid enum value 12345 ' 'for enum type protobuf_unittest.TestAllTypes.NestedEnum.', @@ -1015,28 +1015,28 @@ class JsonFormatTest(JsonFormatBase): def testInvalidMap(self): message = json_format_proto3_pb2.TestMap() text = '{"int32Map": {"null": 2, "2": 3}}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to parse int32Map field: invalid literal', json_format.Parse, text, message) text = '{"int32Map": {1: 2, "2": 3}}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, (r'Failed to load JSON: Expecting property name' r'( enclosed in double quotes)?: line 1'), json_format.Parse, text, message) text = '{"boolMap": {"null": 1}}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to parse boolMap field: Expected "true" or "false", not null.', json_format.Parse, text, message) text = r'{"stringMap": {"a": 3, "\u0061": 2}}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to load JSON: duplicate key a', json_format.Parse, text, message) text = r'{"stringMap": 0}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to parse stringMap field: Map field string_map must be ' 'in a dict which is 0.', @@ -1045,31 +1045,31 @@ class JsonFormatTest(JsonFormatBase): def testInvalidTimestamp(self): message = json_format_proto3_pb2.TestTimestamp() text = '{"value": "10000-01-01T00:00:00.00Z"}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to parse value field: ' 'time data \'10000-01-01T00:00:00\' does not match' ' format \'%Y-%m-%dT%H:%M:%S\'.', json_format.Parse, text, message) text = '{"value": "1970-01-01T00:00:00.0123456789012Z"}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'nanos 0123456789012 more than 9 fractional digits.', json_format.Parse, text, message) text = '{"value": "1972-01-01T01:00:00.01+08"}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, (r'Invalid timezone offset value: \+08.'), json_format.Parse, text, message) # Time smaller than minimum time. text = '{"value": "0000-01-01T00:00:00Z"}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to parse value field: year (0 )?is out of range.', json_format.Parse, text, message) # Time bigger than maximum time. message.value.seconds = 253402300800 - self.assertRaisesRegexp( + self.assertRaisesRegex( OverflowError, 'date value out of range', json_format.MessageToJson, message) @@ -1086,7 +1086,7 @@ class JsonFormatTest(JsonFormatBase): def testInvalidOneof(self): message = json_format_proto3_pb2.TestOneof() text = '{"oneofInt32Value": 1, "oneofStringValue": "2"}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Message type "proto3.TestOneof"' ' should not have multiple "oneof_value" oneof fields.', @@ -1095,7 +1095,7 @@ class JsonFormatTest(JsonFormatBase): def testInvalidListValue(self): message = json_format_proto3_pb2.TestListValue() text = '{"value": 1234}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, r'Failed to parse value field: ListValue must be in \[\] which is 1234', json_format.Parse, text, message) @@ -1103,7 +1103,7 @@ class JsonFormatTest(JsonFormatBase): def testInvalidStruct(self): message = json_format_proto3_pb2.TestStruct() text = '{"value": 1234}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, 'Failed to parse value field: Struct must be in a dict which is 1234', json_format.Parse, text, message) @@ -1111,7 +1111,7 @@ class JsonFormatTest(JsonFormatBase): def testTimestampInvalidStringValue(self): message = json_format_proto3_pb2.TestTimestamp() text = '{"value": {"foo": 123}}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, r"Timestamp JSON value not a string: {u?'foo': 123}", json_format.Parse, text, message) @@ -1119,7 +1119,7 @@ class JsonFormatTest(JsonFormatBase): def testDurationInvalidStringValue(self): message = json_format_proto3_pb2.TestDuration() text = '{"value": {"foo": 123}}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, r"Duration JSON value not a string: {u?'foo': 123}", json_format.Parse, text, message) @@ -1127,7 +1127,7 @@ class JsonFormatTest(JsonFormatBase): def testFieldMaskInvalidStringValue(self): message = json_format_proto3_pb2.TestFieldMask() text = '{"value": {"foo": 123}}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, r"FieldMask JSON value not a string: {u?'foo': 123}", json_format.Parse, text, message) @@ -1135,17 +1135,17 @@ class JsonFormatTest(JsonFormatBase): def testInvalidAny(self): message = any_pb2.Any() text = '{"@type": "type.googleapis.com/google.protobuf.Int32Value"}' - self.assertRaisesRegexp( + self.assertRaisesRegex( KeyError, 'value', json_format.Parse, text, message) text = '{"value": 1234}' - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, '@type is missing when parsing any message.', json_format.Parse, text, message) text = '{"@type": "type.googleapis.com/MessageNotExist", "value": 1234}' - self.assertRaisesRegexp( + self.assertRaisesRegex( TypeError, 'Can not find message descriptor by type_url: ' 'type.googleapis.com/MessageNotExist.', @@ -1233,7 +1233,7 @@ class JsonFormatTest(JsonFormatBase): def __repr__(self): return 'v' message = json_format_proto3_pb2.TestValue() - self.assertRaisesRegexp( + self.assertRaisesRegex( json_format.ParseError, r"Value v has unexpected type .", json_format.ParseDict, diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 6ed1f20ef5..dea5d82b79 100644 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -2033,7 +2033,7 @@ class Proto3Test(unittest.TestCase): def testMergeFromBadType(self): msg = map_unittest_pb2.TestMap() - with self.assertRaisesRegexp( + with self.assertRaisesRegex( TypeError, r'Parameter to MergeFrom\(\) must be instance of same class: expected ' r'.+TestMap got int\.'): @@ -2041,7 +2041,7 @@ class Proto3Test(unittest.TestCase): def testCopyFromBadType(self): msg = map_unittest_pb2.TestMap() - with self.assertRaisesRegexp( + with self.assertRaisesRegex( TypeError, r'Parameter to [A-Za-z]*From\(\) must be instance of same class: ' r'expected .+TestMap got int\.'): diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 9343389ed5..035ef6d614 100644 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -427,7 +427,7 @@ class ReflectionTest(unittest.TestCase): pb.optional_uint64 = '2' # The exact error should propagate with a poorly written custom integer. - with self.assertRaisesRegexp(RuntimeError, 'my_error'): + with self.assertRaisesRegex(RuntimeError, 'my_error'): pb.optional_uint64 = test_util.NonStandardInteger(5, 'my_error') def assetIntegerBoundsChecking(self, integer_fn, message_module): diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index d2632f9cea..796886c52c 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -295,82 +295,82 @@ class TimeUtilTest(TimeUtilTestBase): def testInvalidTimestamp(self): message = timestamp_pb2.Timestamp() - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Failed to parse timestamp: missing valid timezone offset.', message.FromJsonString, '') - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Failed to parse timestamp: invalid trailing data ' '1970-01-01T00:00:01Ztrail.', message.FromJsonString, '1970-01-01T00:00:01Ztrail') - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'time data \'10000-01-01T00:00:00\' does not match' ' format \'%Y-%m-%dT%H:%M:%S\'', message.FromJsonString, '10000-01-01T00:00:00.00Z') - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'nanos 0123456789012 more than 9 fractional digits.', message.FromJsonString, '1970-01-01T00:00:00.0123456789012Z') - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, (r'Invalid timezone offset value: \+08.'), message.FromJsonString, '1972-01-01T01:00:00.01+08',) - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'year (0 )?is out of range', message.FromJsonString, '0000-01-01T00:00:00Z') message.seconds = 253402300800 - self.assertRaisesRegexp( + self.assertRaisesRegex( OverflowError, 'date value out of range', message.ToJsonString) def testInvalidDuration(self): message = duration_pb2.Duration() - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Duration must end with letter "s": 1.', message.FromJsonString, '1') - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Couldn\'t parse duration: 1...2s.', message.FromJsonString, '1...2s') text = '-315576000001.000000000s' - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, r'Duration is not valid\: Seconds -315576000001 must be in range' r' \[-315576000000\, 315576000000\].', message.FromJsonString, text) text = '315576000001.000000000s' - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, r'Duration is not valid\: Seconds 315576000001 must be in range' r' \[-315576000000\, 315576000000\].', message.FromJsonString, text) message.seconds = -315576000001 message.nanos = 0 - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, r'Duration is not valid\: Seconds -315576000001 must be in range' r' \[-315576000000\, 315576000000\].', message.ToJsonString) message.seconds = 0 message.nanos = 999999999 + 1 - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, r'Duration is not valid\: Nanos 1000000000 must be in range' r' \[-999999999\, 999999999\].', message.ToJsonString) message.seconds = -1 message.nanos = 1 - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, r'Duration is not valid\: Sign mismatch.', message.ToJsonString) @@ -695,7 +695,7 @@ class FieldMaskTest(unittest.TestCase): well_known_types._SnakeCaseToCamelCase('foo3_bar')) # No uppercase letter is allowed. - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Fail to print FieldMask to Json string: Path name Foo must ' 'not contain uppercase letters.', @@ -705,19 +705,19 @@ class FieldMaskTest(unittest.TestCase): # 1. "_" cannot be followed by another "_". # 2. "_" cannot be followed by a digit. # 3. "_" cannot appear as the last character. - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Fail to print FieldMask to Json string: The character after a ' '"_" must be a lowercase letter in path name foo__bar.', well_known_types._SnakeCaseToCamelCase, 'foo__bar') - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Fail to print FieldMask to Json string: The character after a ' '"_" must be a lowercase letter in path name foo_3bar.', well_known_types._SnakeCaseToCamelCase, 'foo_3bar') - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Fail to print FieldMask to Json string: Trailing "_" in path ' 'name foo_bar_.', @@ -731,7 +731,7 @@ class FieldMaskTest(unittest.TestCase): well_known_types._CamelCaseToSnakeCase('FooBar')) self.assertEqual('foo3_bar', well_known_types._CamelCaseToSnakeCase('foo3Bar')) - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, 'Fail to parse FieldMask: Path name foo_bar must not contain "_"s.', well_known_types._CamelCaseToSnakeCase, From 62d59d7d4caa08df86fa74b2e8f66a744e3194f9 Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Fri, 15 Oct 2021 23:02:36 -0400 Subject: [PATCH 006/207] Update maven-surefire-plugin to 3.0.0-M5. (#7830) This avoids https://issues.apache.org/jira/browse/SUREFIRE-1439, which I hit while investigating https://github.com/protocolbuffers/protobuf/issues/7827 --- java/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/java/pom.xml b/java/pom.xml index e39536f920..faaf586b7d 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -181,6 +181,10 @@ + + maven-surefire-plugin + 3.0.0-M5 + From d08bc71c96d3dfcea12de3d4efacfbad5d473e44 Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Sat, 16 Oct 2021 12:11:59 +0900 Subject: [PATCH 007/207] Suppress dot-delimiter warning if ruby_package consists of a single component (#7276) --- src/google/protobuf/compiler/ruby/ruby_generator.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index c1a5c67d2a..f4c6729eed 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -421,7 +421,7 @@ int GeneratePackageModules(const FileDescriptor* file, io::Printer* printer) { // -> A.B.C if (package_name.find("::") != std::string::npos) { need_change_to_module = false; - } else { + } else if (package_name.find(".") != std::string::npos) { GOOGLE_LOG(WARNING) << "ruby_package option should be in the form of:" << " 'A::B::C' and not 'A.B.C'"; } From 21478b371e0e71ead9fc1c357c261be7a168b1be Mon Sep 17 00:00:00 2001 From: Joel Courtney Date: Tue, 19 Oct 2021 12:25:21 +1100 Subject: [PATCH 008/207] Update well_known_types_test.rb --- ruby/tests/well_known_types_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby/tests/well_known_types_test.rb b/ruby/tests/well_known_types_test.rb index 5fcc3dbabe..996dbc30a5 100755 --- a/ruby/tests/well_known_types_test.rb +++ b/ruby/tests/well_known_types_test.rb @@ -33,13 +33,13 @@ class TestWellKnownTypes < Test::Unit::TestCase time = Time.at(123456, Rational(654321321, 1000)) ts = Google::Protobuf::Timestamp.from_time(time) assert_equal 123456, ts.seconds - assert_equal 654321000, ts.nanos + assert_equal 654321321, ts.nanos assert_equal time, ts.to_time # Instance method returns the same value as class method assert_equal Google::Protobuf::Timestamp.new.from_time(time), Google::Protobuf::Timestamp.from_time(time) -end + end def test_duration duration = Google::Protobuf::Duration.new(seconds: 123, nanos: 456) From 3f3e6f47c6d71e755faf6abb3f49b89dce8c5182 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 19 Oct 2021 09:01:57 -0700 Subject: [PATCH 009/207] Update version to 3.19.0-rc2 and fix changelog about Java 7 (#9116) * Update protobuf version * Update CHANGES.txt to reflect that we're not yet dropping Java 7 --- CHANGES.txt | 1 - Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 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/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 23 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 ++-- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/stubs/common.h | 2 +- 25 files changed, 45 insertions(+), 31 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ce3ec9f6b0..db6194529d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -11,7 +11,6 @@ * Add Android stlport and default toolchains to BUILD. (#8290) Java - * This release drops support for Java 7. Use 3.18.x if you still need Java 7 support. * For default floating point values of 0, consider all bits significant * Annotate `//java/com/google/protobuf/util/...` with nullness annotations * Use ArrayList copy constructor (#7853) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 6e0c840d45..841e74edcd 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.19.0-rc1' + s.version = '3.19.0-rc2' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 83981c66ea..37d32b3976 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.19.0-rc1' + s.version = '3.19.0-rc2' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index a45db7dec5..7fbc58ec0b 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.19.0-rc-1],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.19.0-rc-2],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 607ff258a8..5edce1a5c6 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.19.0-rc1 + 3.19.0-rc2 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index e4bb99d96e..648d98e3c2 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.19.0-rc1 + 3.19.0-rc2 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 3b129aa97e..02238b23b9 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.19.0-rc-1 + 3.19.0-rc-2 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.19.0-rc-1 + 3.19.0-rc-2 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.19.0-rc-1' + implementation 'com.google.protobuf:protobuf-java:3.19.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 ac7a69cd82..62c68e2ac8 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.19.0-rc-1 + 3.19.0-rc-2 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 778b8af5a5..d4f5d626a6 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-1 + 3.19.0-rc-2 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 89e0d2011a..12e00d53ff 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-1 + 3.19.0-rc-2 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index c21e7d561c..a6929ce913 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-1 + 3.19.0-rc-2 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index fb1a8e3f11..9c416aabaa 100644 --- a/java/lite.md +++ b/java/lite.md @@ -30,7 +30,7 @@ protobuf Java runtime. If you are using Maven, use the following: com.google.protobuf protobuf-javalite - 3.19.0-rc-1 + 3.19.0-rc-2 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index d8d19c20ea..552c1803d8 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-1 + 3.19.0-rc-2 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 8d05f91a5b..cf5650e9db 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-1 + 3.19.0-rc-2 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 0fa2edbe09..4c97a151f8 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-1 + 3.19.0-rc-2 protobuf-java-util diff --git a/js/package.json b/js/package.json index 820cef75f9..bdda3ad311 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.19.0-rc.1", + "version": "3.19.0-rc.2", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 33b694f9ed..cac79d5bf8 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,10 +10,10 @@ protobuf-opensource@google.com yes - 2021-10-15 - + 2021-10-18 + - 3.19.0RC1 + 3.19.0RC2 3.19.0 @@ -22,7 +22,7 @@ 3-Clause BSD License - * Added "object" as a reserved name (#8962) + * Added "object" as a reserved name (#8962) @@ -1113,5 +1113,20 @@ G A release. + + + 3.19.0RC2 + 3.19.0 + + + beta + beta + + 2021-10-18 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index c3d74e1fb4..311525203b 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -91,7 +91,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.19.0RC1" +#define PHP_PROTOBUF_VERSION "3.19.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 72a807dc51..b893092b68 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1 @@ -PROTOBUF_VERSION = '3.19.0-rc-1' +PROTOBUF_VERSION = '3.19.0-rc-2' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index e3f1051a3c..f231e194d3 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.19.0-rc-1 + 3.19.0-rc-2 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index a305bc2027..64916c5f9b 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.19.0rc1' +__version__ = '3.19.0rc2' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 1388de2933..ef05598bfc 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.19.0.rc.1" + s.version = "3.19.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 16890fec85..c2c3824594 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.19.0-rc-1 + 3.19.0-rc-2 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.19.0-rc-1 + 3.19.0-rc-2 org.jruby diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index a79e9cb8e1..9f78385228 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -168,7 +168,7 @@ #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined #endif -#define PROTOBUF_VERSION_SUFFIX "-rc1" +#define PROTOBUF_VERSION_SUFFIX "-rc2" #if defined(PROTOBUF_NAMESPACE) || defined(PROTOBUF_NAMESPACE_ID) #error PROTOBUF_NAMESPACE or PROTOBUF_NAMESPACE_ID was previously defined diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 238d5e8bb7..5dc79fd871 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -85,7 +85,7 @@ namespace internal { #define GOOGLE_PROTOBUF_VERSION 3019000 // 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 From 33113ce9f9ef6d4240c4326564bb528087efcc94 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 19 Oct 2021 21:34:32 +0000 Subject: [PATCH 010/207] Fixing inlining and deprecation for repeated string fields in kotlin --- .../compiler/java/java_string_field.cc | 35 +++++++++---------- .../compiler/java/java_string_field_lite.cc | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index 28164c7633..cd6308b7f6 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -1,5 +1,4 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. +// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without @@ -968,16 +967,14 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // property for List WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print( - variables_, - "public val $kt_name$: " - "com.google.protobuf.kotlin.DslList" - "\n" - " @kotlin.OptIn" - "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - " get() = com.google.protobuf.kotlin.DslList(\n" - " $kt_dsl_builder$.${$get$capitalized_name$List$}$()\n" - " )\n"); + printer->Print(variables_, + "$kt_deprecation$public val $kt_name$: " + "com.google.protobuf.kotlin.DslList" + "\n" + " @kotlin.jvm.JvmSynthetic\n" + " get() = com.google.protobuf.kotlin.DslList(\n" + " $kt_dsl_builder$.${$get$capitalized_name$List$}$()\n" + " )\n"); // List.add(String) WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, @@ -994,13 +991,14 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List += String WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, /* builder */ false); - printer->Print(variables_, + printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" - "public operator fun com.google.protobuf.kotlin.DslList" + "@Suppress(\"NOTHING_TO_INLINE\")\n" + "public inline operator fun com.google.protobuf.kotlin.DslList" "." "plusAssign(value: kotlin.String) {\n" - " $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n" + " add(value)\n" "}\n"); // List.addAll(Iterable) @@ -1019,14 +1017,15 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List += Iterable WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ false); - printer->Print( + printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" - "public operator fun com.google.protobuf.kotlin.DslList" + "@Suppress(\"NOTHING_TO_INLINE\")\n" + "public inline operator fun com.google.protobuf.kotlin.DslList" "." "plusAssign(values: kotlin.collections.Iterable) {\n" - " $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n" + " addAll(values)\n" "}\n"); // List[Int] = String diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.cc b/src/google/protobuf/compiler/java/java_string_field_lite.cc index 57cd43677c..1833903316 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_string_field_lite.cc @@ -755,7 +755,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print( variables_, - "public val $kt_name$: " + "$kt_deprecation$public val $kt_name$: " "com.google.protobuf.kotlin.DslList" "\n" " @kotlin.OptIn" From ad9eb238cc5293de5cc5c2607f9ccfb2f31e913c Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 19 Oct 2021 21:36:30 +0000 Subject: [PATCH 011/207] Fixing formatting --- src/google/protobuf/compiler/java/java_string_field.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index cd6308b7f6..1a0959e408 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -1,4 +1,5 @@ -// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without @@ -1017,7 +1018,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List += Iterable WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, /* builder */ false); - printer->Print( + printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n" From 4c445b18038b843588a2298b423d27b0d97cef1e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 19 Oct 2021 14:51:52 -0700 Subject: [PATCH 012/207] Fix for descriptor_pb.rb: google/protobuf should be required first. --- src/google/protobuf/compiler/ruby/ruby_generator.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index c1a5c67d2a..6f718cfd5a 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -467,8 +467,6 @@ void EndPackageModules(int levels, io::Printer* printer) { bool GenerateDslDescriptor(const FileDescriptor* file, io::Printer* printer, std::string* error) { - printer->Print( - "require 'google/protobuf'\n\n"); printer->Print("Google::Protobuf::DescriptorPool.generated_pool.build do\n"); printer->Indent(); printer->Print("add_file(\"$filename$\", :syntax => :$syntax$) do\n", @@ -509,6 +507,9 @@ bool GenerateFile(const FileDescriptor* file, io::Printer* printer, "\n", "filename", file->name()); + printer->Print( + "require 'google/protobuf'\n\n"); + for (int i = 0; i < file->dependency_count(); i++) { printer->Print("require '$name$'\n", "name", GetRequireName(file->dependency(i)->name())); } From bb5a2684de8b53cd23199965bdd193a80168eb44 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 19 Oct 2021 16:21:24 -0700 Subject: [PATCH 013/207] Minor whitespace fixes and test fixups. --- .../protobuf/compiler/ruby/ruby_generated_code_pb.rb | 3 ++- .../compiler/ruby/ruby_generated_code_proto2_pb.rb | 3 ++- src/google/protobuf/compiler/ruby/ruby_generator.cc | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb b/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb index 4cf4866cfa..256ac7c153 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb @@ -1,9 +1,10 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: ruby_generated_code.proto -require 'ruby_generated_code_proto2_import_pb' require 'google/protobuf' +require 'ruby_generated_code_proto2_import_pb' + Google::Protobuf::DescriptorPool.generated_pool.build do add_file("ruby_generated_code.proto", :syntax => :proto3) do add_message "A.B.C.TestMessage" do diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb b/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb index e331e9b2b3..44d31969ec 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb @@ -1,9 +1,10 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: ruby_generated_code_proto2.proto -require 'ruby_generated_code_proto2_import_pb' require 'google/protobuf' +require 'ruby_generated_code_proto2_import_pb' + Google::Protobuf::DescriptorPool.generated_pool.build do add_file("ruby_generated_code_proto2.proto", :syntax => :proto2) do add_message "A.B.C.TestMessage" do diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index 6f718cfd5a..46e60f5874 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -507,11 +507,13 @@ bool GenerateFile(const FileDescriptor* file, io::Printer* printer, "\n", "filename", file->name()); - printer->Print( - "require 'google/protobuf'\n\n"); + printer->Print("require 'google/protobuf'\n\n"); - for (int i = 0; i < file->dependency_count(); i++) { - printer->Print("require '$name$'\n", "name", GetRequireName(file->dependency(i)->name())); + if (file->dependency_count() != 0) { + for (int i = 0; i < file->dependency_count(); i++) { + printer->Print("require '$name$'\n", "name", GetRequireName(file->dependency(i)->name())); + } + printer->Print("\n"); } // TODO: Remove this when ruby supports extensions for proto2 syntax. From 17b30e96476be70b8773b2b807bab857fd3ceb39 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 20 Oct 2021 10:14:02 -0700 Subject: [PATCH 014/207] Update protobuf version (#9119) --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 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/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 25 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 +-- src/google/protobuf/port_def.inc | 2 +- src/google/protobuf/stubs/common.h | 2 +- 24 files changed, 46 insertions(+), 31 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 841e74edcd..01c890de4a 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.19.0-rc2' + s.version = '3.19.0' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 37d32b3976..b1a959478c 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.19.0-rc2' + s.version = '3.19.0' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 7fbc58ec0b..d076062f22 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.19.0-rc-2],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.19.0],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 5edce1a5c6..93b8ab40c4 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.19.0-rc2 + 3.19.0 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 648d98e3c2..4b3a9bb7e1 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.19.0-rc2 + 3.19.0 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 02238b23b9..1cfff6afd0 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.19.0-rc-2 + 3.19.0 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.19.0-rc-2 + 3.19.0 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.19.0-rc-2' + implementation 'com.google.protobuf:protobuf-java:3.19.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 62c68e2ac8..d0a93a35ce 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.19.0-rc-2 + 3.19.0 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index d4f5d626a6..4c75eb40cd 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-2 + 3.19.0 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 12e00d53ff..47e2ab4af5 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-2 + 3.19.0 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index a6929ce913..d5b4d2e0d9 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-2 + 3.19.0 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index 9c416aabaa..9929f19ae2 100644 --- a/java/lite.md +++ b/java/lite.md @@ -30,7 +30,7 @@ protobuf Java runtime. If you are using Maven, use the following: com.google.protobuf protobuf-javalite - 3.19.0-rc-2 + 3.19.0 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 552c1803d8..a473948b9f 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-2 + 3.19.0 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index cf5650e9db..6642131f66 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-2 + 3.19.0 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 4c97a151f8..63b53f3df1 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0-rc-2 + 3.19.0 protobuf-java-util diff --git a/js/package.json b/js/package.json index bdda3ad311..43ae2d70b7 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.19.0-rc.2", + "version": "3.19.0", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index cac79d5bf8..76d601f8df 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,15 +10,15 @@ protobuf-opensource@google.com yes - 2021-10-18 - + 2021-10-19 + - 3.19.0RC2 + 3.19.0 3.19.0 - beta - beta + stable + stable 3-Clause BSD License @@ -1128,5 +1128,20 @@ G A release. + + + 3.19.0 + 3.19.0 + + + stable + stable + + 2021-10-19 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 311525203b..d5eb4faaa2 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -91,7 +91,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.19.0RC2" +#define PHP_PROTOBUF_VERSION "3.19.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 b893092b68..bf0d52b18a 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1 @@ -PROTOBUF_VERSION = '3.19.0-rc-2' +PROTOBUF_VERSION = '3.19.0' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index f231e194d3..9f44f5f43f 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.19.0-rc-2 + 3.19.0 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 64916c5f9b..68087e5501 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.19.0rc2' +__version__ = '3.19.0' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index ef05598bfc..c034f3743b 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.19.0.rc.2" + s.version = "3.19.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 c2c3824594..a38d395b73 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.19.0-rc-2 + 3.19.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.19.0-rc-2 + 3.19.0 org.jruby diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 9f78385228..003f75ac7d 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -168,7 +168,7 @@ #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined #endif -#define PROTOBUF_VERSION_SUFFIX "-rc2" +#define PROTOBUF_VERSION_SUFFIX "" #if defined(PROTOBUF_NAMESPACE) || defined(PROTOBUF_NAMESPACE_ID) #error PROTOBUF_NAMESPACE or PROTOBUF_NAMESPACE_ID was previously defined diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 5dc79fd871..d9524d2b5f 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -85,7 +85,7 @@ namespace internal { #define GOOGLE_PROTOBUF_VERSION 3019000 // 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 From 63f952b987bd848ac278c714c81c47250214adc7 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 20 Oct 2021 14:51:07 -0700 Subject: [PATCH 015/207] Fix Python 3.10 C++ tests (#9128) The first change is to make sure we always define PY_SSIZE_T_CLEAN before including Python.h. Starting from Python 3.10 this is required. Otherwise we get errors like this: SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats The second change is to update reflection_test.py to account for the fact that with Python 3.10, we get a TypeError even with the C++ implementation when trying to assign a float to a bool field. I'm not sure why this changed with Python 3.10, but it seems like a good thing since this is the desired behavior anyway. --- python/google/protobuf/internal/api_implementation.cc | 1 + python/google/protobuf/internal/reflection_test.py | 4 +++- python/google/protobuf/proto_api.h | 1 + python/google/protobuf/pyext/descriptor.cc | 1 + python/google/protobuf/pyext/descriptor.h | 1 + python/google/protobuf/pyext/descriptor_containers.cc | 1 + python/google/protobuf/pyext/descriptor_containers.h | 1 + python/google/protobuf/pyext/descriptor_database.h | 1 + python/google/protobuf/pyext/descriptor_pool.cc | 1 + python/google/protobuf/pyext/descriptor_pool.h | 1 + python/google/protobuf/pyext/extension_dict.h | 1 + python/google/protobuf/pyext/field.h | 1 + python/google/protobuf/pyext/map_container.h | 1 + python/google/protobuf/pyext/message.h | 1 + python/google/protobuf/pyext/message_factory.cc | 1 + python/google/protobuf/pyext/message_factory.h | 1 + python/google/protobuf/pyext/message_module.cc | 1 + python/google/protobuf/pyext/repeated_composite_container.h | 1 + python/google/protobuf/pyext/repeated_scalar_container.h | 1 + python/google/protobuf/pyext/scoped_pyobject_ptr.h | 1 + python/google/protobuf/pyext/unknown_fields.cc | 1 + python/google/protobuf/pyext/unknown_fields.h | 1 + python/google/protobuf/python_protobuf.h | 1 + 23 files changed, 25 insertions(+), 1 deletion(-) diff --git a/python/google/protobuf/internal/api_implementation.cc b/python/google/protobuf/internal/api_implementation.cc index 6532a81405..802322424e 100644 --- a/python/google/protobuf/internal/api_implementation.cc +++ b/python/google/protobuf/internal/api_implementation.cc @@ -28,6 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#define PY_SSIZE_T_CLEAN #include namespace google { diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 035ef6d614..66dd0c710a 100644 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -37,6 +37,7 @@ import copy import gc import operator import struct +import sys import warnings import unittest @@ -376,7 +377,8 @@ class ReflectionTest(unittest.TestCase): self.assertRaises(TypeError, setattr, proto, 'optional_float', 'foo') self.assertRaises(TypeError, setattr, proto, 'optional_double', 'foo') # TODO(jieluo): Fix type checking difference for python and c extension - if api_implementation.Type() == 'python': + if (api_implementation.Type() == 'python' or + (sys.version_info.major, sys.version_info.minor) >= (3, 10)): self.assertRaises(TypeError, setattr, proto, 'optional_bool', 1.1) else: proto.optional_bool = 1.1 diff --git a/python/google/protobuf/proto_api.h b/python/google/protobuf/proto_api.h index 2e2156a56e..9969a91f44 100644 --- a/python/google/protobuf/proto_api.h +++ b/python/google/protobuf/proto_api.h @@ -45,6 +45,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__ #define GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index bc49e91b92..2101c2982e 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -32,6 +32,7 @@ #include +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor.h b/python/google/protobuf/pyext/descriptor.h index b99209dd19..d97e2f8103 100644 --- a/python/google/protobuf/pyext/descriptor.h +++ b/python/google/protobuf/pyext/descriptor.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor_containers.cc b/python/google/protobuf/pyext/descriptor_containers.cc index b084f5b812..4caff6941a 100644 --- a/python/google/protobuf/pyext/descriptor_containers.cc +++ b/python/google/protobuf/pyext/descriptor_containers.cc @@ -49,6 +49,7 @@ // because the Python API is based on C, and does not play well with C++ // inheritance. +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor_containers.h b/python/google/protobuf/pyext/descriptor_containers.h index 4e05c58e2b..cf2cf4ad0b 100644 --- a/python/google/protobuf/pyext/descriptor_containers.h +++ b/python/google/protobuf/pyext/descriptor_containers.h @@ -34,6 +34,7 @@ // Mappings and Sequences of descriptors. // They implement containers like fields_by_name, EnumDescriptor.values... // See descriptor_containers.cc for more description. +#define PY_SSIZE_T_CLEAN #include namespace google { diff --git a/python/google/protobuf/pyext/descriptor_database.h b/python/google/protobuf/pyext/descriptor_database.h index d2d9f8e506..3bc99e7dbc 100644 --- a/python/google/protobuf/pyext/descriptor_database.h +++ b/python/google/protobuf/pyext/descriptor_database.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_DATABASE_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_DATABASE_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index 5ec6269cd4..f6bdb6e4c8 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -32,6 +32,7 @@ #include +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor_pool.h b/python/google/protobuf/pyext/descriptor_pool.h index 48658d3e88..5d3c3a95cc 100644 --- a/python/google/protobuf/pyext/descriptor_pool.h +++ b/python/google/protobuf/pyext/descriptor_pool.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/extension_dict.h b/python/google/protobuf/pyext/extension_dict.h index c9da443161..a0581941bd 100644 --- a/python/google/protobuf/pyext/extension_dict.h +++ b/python/google/protobuf/pyext/extension_dict.h @@ -34,6 +34,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/field.h b/python/google/protobuf/pyext/field.h index 7b4660cab5..f9f94c4983 100644 --- a/python/google/protobuf/pyext/field.h +++ b/python/google/protobuf/pyext/field.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__ +#define PY_SSIZE_T_CLEAN #include namespace google { diff --git a/python/google/protobuf/pyext/map_container.h b/python/google/protobuf/pyext/map_container.h index 842602e79f..e14136efab 100644 --- a/python/google/protobuf/pyext/map_container.h +++ b/python/google/protobuf/pyext/map_container.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index 29af255154..b17daa5806 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -34,6 +34,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/message_factory.cc b/python/google/protobuf/pyext/message_factory.cc index 30dfab88dc..5098379f35 100644 --- a/python/google/protobuf/pyext/message_factory.cc +++ b/python/google/protobuf/pyext/message_factory.cc @@ -30,6 +30,7 @@ #include +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/message_factory.h b/python/google/protobuf/pyext/message_factory.h index 515c29cdb8..7dfe425dd5 100644 --- a/python/google/protobuf/pyext/message_factory.h +++ b/python/google/protobuf/pyext/message_factory.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/message_module.cc b/python/google/protobuf/pyext/message_module.cc index 971d2bad70..a0806a3160 100644 --- a/python/google/protobuf/pyext/message_module.cc +++ b/python/google/protobuf/pyext/message_module.cc @@ -28,6 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/repeated_composite_container.h b/python/google/protobuf/pyext/repeated_composite_container.h index e241827ef5..30536eabd4 100644 --- a/python/google/protobuf/pyext/repeated_composite_container.h +++ b/python/google/protobuf/pyext/repeated_composite_container.h @@ -34,6 +34,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_COMPOSITE_CONTAINER_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_COMPOSITE_CONTAINER_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/repeated_scalar_container.h b/python/google/protobuf/pyext/repeated_scalar_container.h index f9f0ea8f31..372b6f0a35 100644 --- a/python/google/protobuf/pyext/repeated_scalar_container.h +++ b/python/google/protobuf/pyext/repeated_scalar_container.h @@ -34,6 +34,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_SCALAR_CONTAINER_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_SCALAR_CONTAINER_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/scoped_pyobject_ptr.h b/python/google/protobuf/pyext/scoped_pyobject_ptr.h index 6f7fc29813..985df2c3bb 100644 --- a/python/google/protobuf/pyext/scoped_pyobject_ptr.h +++ b/python/google/protobuf/pyext/scoped_pyobject_ptr.h @@ -35,6 +35,7 @@ #include +#define PY_SSIZE_T_CLEAN #include namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/unknown_fields.cc b/python/google/protobuf/pyext/unknown_fields.cc index 5dbcd88568..31926c8554 100644 --- a/python/google/protobuf/pyext/unknown_fields.cc +++ b/python/google/protobuf/pyext/unknown_fields.cc @@ -30,6 +30,7 @@ #include +#define PY_SSIZE_T_CLEAN #include #include #include diff --git a/python/google/protobuf/pyext/unknown_fields.h b/python/google/protobuf/pyext/unknown_fields.h index 94d55e148d..e7b0b35c41 100644 --- a/python/google/protobuf/pyext/unknown_fields.h +++ b/python/google/protobuf/pyext/unknown_fields.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/python_protobuf.h b/python/google/protobuf/python_protobuf.h index 8db1ffb750..4fcf065404 100644 --- a/python/google/protobuf/python_protobuf.h +++ b/python/google/protobuf/python_protobuf.h @@ -36,6 +36,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ #define GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ +#define PY_SSIZE_T_CLEAN #include namespace google { From 67c2a92f82b16331199cb89062b832e15aeb0c1f Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 21 Oct 2021 06:47:17 -0700 Subject: [PATCH 016/207] Ensure that release archives contain everything needed for Bazel (#9131) This change adds some files to EXTRA_DIST in Makefile.am so that our published tar and zip files will have everything needed for Bazel builds. I also added a basic test for this so that next time we should find out sooner if we're missing any important files. This should fix #9129. --- Makefile.am | 2 ++ kokoro/linux/bazel/build.sh | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index f37ae9fdae..178c124b5e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1424,8 +1424,10 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ examples/list_people.py \ examples/list_people_test.go \ examples/pubspec.yaml \ + maven_install.json \ protobuf.bzl \ protobuf_deps.bzl \ + protobuf_version.bzl \ third_party/zlib.BUILD \ util/python/BUILD \ internal.bzl diff --git a/kokoro/linux/bazel/build.sh b/kokoro/linux/bazel/build.sh index 5ec92ce7e5..d0d4b3ef4d 100755 --- a/kokoro/linux/bazel/build.sh +++ b/kokoro/linux/bazel/build.sh @@ -35,5 +35,13 @@ bazel test -k --copt=-Werror --host_copt=-Werror \ @com_google_protobuf//:cc_proto_blacklist_test trap - EXIT -cd examples +pushd examples bazel build //... +popd + +# Verify that we can build successfully from generated tar files. +./autogen.sh && ./configure && make -j$(nproc) dist +DIST=`ls *.tar.gz` +tar -xf $DIST +cd ${DIST//.tar.gz} +bazel build //:protobuf //:protobuf_java From 1e1c1cd8849965e19a06b69a87ffca272425bb9c Mon Sep 17 00:00:00 2001 From: Upils <5464641+upils@users.noreply.github.com> Date: Thu, 21 Oct 2021 17:24:38 +0200 Subject: [PATCH 017/207] Reserve extension id range for protoc-gen-checker (#9133) --- docs/options.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/options.md b/docs/options.md index 159951ac3c..6608bedba8 100644 --- a/docs/options.md +++ b/docs/options.md @@ -292,3 +292,7 @@ with info about your project (name and website) so we can add an entry for you. 1. Protoc-gen-jsonschema * Website: https://github.com/chrusty/protoc-gen-jsonschema * Extension: 1125-1129 + +1. Protoc-gen-checker + * Website: https://github.com/Intrinsec/protoc-gen-checker + * Extension: 1130-1139 From 42db8a3f966cad1b2c96dc586e10f79a8d88d053 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 21 Oct 2021 11:47:05 -0700 Subject: [PATCH 018/207] Make IsDescriptor* helpers lenient about descriptor name (#9127) Our internal version of the codebase has a different path and package name for descriptor.proto, so this change updates IsDescriptorProto() and IsDescriptorOptionMessage() to be able to handle both the internal and external descriptor types. --- .../csharp/csharp_generator_unittest.cc | 13 ++++++++++++ .../protobuf/compiler/csharp/csharp_helpers.h | 21 ++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc index 5755fee00b..75acda026c 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc @@ -30,8 +30,10 @@ #include +#include #include #include +#include #include #include @@ -63,6 +65,17 @@ TEST(CSharpEnumValue, PascalCasedPrefixStripping) { EXPECT_EQ("_2", GetEnumValueName("Foo", "FOO___2")); } +TEST(DescriptorProtoHelpers, IsDescriptorProto) { + EXPECT_TRUE(IsDescriptorProto(DescriptorProto::descriptor()->file())); + EXPECT_FALSE(IsDescriptorProto(Any::descriptor()->file())); +} + +TEST(DescriptorProtoHelpers, IsDescriptorOptionMessage) { + EXPECT_TRUE(IsDescriptorOptionMessage(FileOptions::descriptor())); + EXPECT_FALSE(IsDescriptorOptionMessage(Any::descriptor())); + EXPECT_FALSE(IsDescriptorOptionMessage(DescriptorProto::descriptor())); +} + } // namespace } // namespace csharp } // namespace compiler diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index a6009c8b1e..619e7dba3a 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -130,7 +130,8 @@ uint GetGroupEndTag(const Descriptor* descriptor); // descriptors etc, for use in the runtime. This is the only type which is // allowed to use proto2 syntax, and it generates internal classes. inline bool IsDescriptorProto(const FileDescriptor* descriptor) { - return descriptor->name() == "google/protobuf/descriptor.proto"; + return descriptor->name() == "google/protobuf/descriptor.proto" || + descriptor->name() == "net/proto2/proto/descriptor.proto"; } // Determines whether the given message is an options message within descriptor.proto. @@ -138,15 +139,15 @@ inline bool IsDescriptorOptionMessage(const Descriptor* descriptor) { if (!IsDescriptorProto(descriptor->file())) { return false; } - const std::string name = descriptor->full_name(); - return name == "google.protobuf.FileOptions" || - name == "google.protobuf.MessageOptions" || - name == "google.protobuf.FieldOptions" || - name == "google.protobuf.OneofOptions" || - name == "google.protobuf.EnumOptions" || - name == "google.protobuf.EnumValueOptions" || - name == "google.protobuf.ServiceOptions" || - name == "google.protobuf.MethodOptions"; + const std::string name = descriptor->name(); + return name == "FileOptions" || + name == "MessageOptions" || + name == "FieldOptions" || + name == "OneofOptions" || + name == "EnumOptions" || + name == "EnumValueOptions" || + name == "ServiceOptions" || + name == "MethodOptions"; } inline bool IsWrapperType(const FieldDescriptor* descriptor) { From c8dfe32b5ac190cecd8750db438c4151ab07a3da Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Thu, 21 Oct 2021 13:27:40 -0700 Subject: [PATCH 019/207] examples: update Go example (#7217) Update the Go example to use Go modules: Move the example into a directory containing a go.mod file, change the installation instructions to use "go install". Update the go_package option in addressbook.proto to an actual module path. Update examples to use the google.golang.org/protobuf/proto module. --- examples/Makefile | 29 ++++++++----------- examples/README.md | 22 ++++++-------- examples/addressbook.proto | 2 +- .../{ => go/cmd/add_person}/add_person.go | 4 +-- .../cmd/add_person}/add_person_test.go | 6 ++-- .../{ => go/cmd/list_people}/list_people.go | 4 +-- .../cmd/list_people}/list_people_test.go | 2 +- examples/go/go.mod | 5 ++++ examples/go/go.sum | 6 ++++ 9 files changed, 41 insertions(+), 39 deletions(-) rename examples/{ => go/cmd/add_person}/add_person.go (96%) rename examples/{ => go/cmd/add_person}/add_person_test.go (88%) rename examples/{ => go/cmd/list_people}/list_people.go (92%) rename examples/{ => go/cmd/list_people}/list_people_test.go (97%) create mode 100644 examples/go/go.mod create mode 100644 examples/go/go.sum diff --git a/examples/Makefile b/examples/Makefile index 8ed2492cd8..1c7ec8d632 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -16,7 +16,7 @@ clean: rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/*.class rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/AddressBookProtos.java rm -f *.pyc - rm -f protoc_middleman_go tutorial/*.pb.go add_person_go list_people_go go.mod go.sum + rm -f go/tutorialpb/*.pb.go add_person_go list_people_go rm -f protoc_middleman_dart dart_tutorial/*.pb*.dart rmdir dart_tutorial 2>/dev/null || true rmdir tutorial 2>/dev/null || true @@ -28,10 +28,9 @@ protoc_middleman: addressbook.proto protoc $$PROTO_PATH --cpp_out=. --java_out=. --python_out=. addressbook.proto @touch protoc_middleman -protoc_middleman_go: addressbook.proto - mkdir -p tutorial # make directory for go package - protoc $$PROTO_PATH --go_out=tutorial addressbook.proto - @touch protoc_middleman_go +go/tutorialpb/addressbook.pb.go: addressbook.proto + mkdir -p go/tutorialpb # make directory for go package + protoc $$PROTO_PATH --go_opt=paths=source_relative --go_out=go/tutorialpb addressbook.proto protoc_middleman_dart: addressbook.proto mkdir -p dart_tutorial # make directory for the dart package @@ -51,21 +50,17 @@ add_person_dart: add_person.dart protoc_middleman_dart list_people_dart: list_people.dart protoc_middleman_dart -go_mod: - go mod init github.com/protocolbuffers/protobuf/examples - go mod tidy +add_person_go: go/cmd/add_person/add_person.go go/tutorialpb/addressbook.pb.go + cd go && go build -o ../add_person_go ./cmd/add_person -add_person_go: add_person.go protoc_middleman_go go_mod - go build -o add_person_go add_person.go +add_person_gotest: go/tutorialpb/addressbook.pb.go + cd go && go test ./cmd/add_person -add_person_gotest: add_person_test.go add_person_go go_mod - go test add_person.go add_person_test.go +list_people_go: go/cmd/list_people/list_people.go go/tutorialpb/addressbook.pb.go + cd go && go build -o ../list_people_go ./cmd/list_people -list_people_go: list_people.go protoc_middleman_go go_mod - go build -o list_people_go list_people.go - -list_people_gotest: list_people.go list_people_go go_mod - go test list_people.go list_people_test.go +list_people_gotest: go/tutorialpb/addressbook.pb.go + cd go && go test ./cmd/list_people javac_middleman: AddPerson.java ListPeople.java protoc_middleman javac -cp $$CLASSPATH AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java diff --git a/examples/README.md b/examples/README.md index 4bf7c17ccc..a99883e066 100644 --- a/examples/README.md +++ b/examples/README.md @@ -91,22 +91,18 @@ scripts) and can be used to create/display an address book data file. ### Go -The Go example requires a plugin to the protocol buffer compiler, so it is not -build with all the other examples. See: +Follow instructions in [../README.md](../README.md) to install protoc. Then +install the Go protoc plugin (protoc-gen-go): - https://github.com/golang/protobuf + $ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest -for more information about Go protocol buffer support. +The "go install" command will install protoc-gen-go into the GOBIN +directory. You can set the $GOBIN environment variable before +running "go install" to change the install location. Make sure the +install directory is in your shell $PATH. -First, install the Protocol Buffers compiler (protoc). - -Then, install the Go Protocol Buffers plugin ($GOPATH/bin must be in your $PATH -for protoc to find it): - - go get github.com/golang/protobuf/protoc-gen-go - -Build the Go samples in this directory with "make go". This creates the -following executable files in the current directory: +Build the Go samples with "make go". This creates the following +executable files in the current directory: add_person_go list_people_go diff --git a/examples/addressbook.proto b/examples/addressbook.proto index 5bb35772d5..1bff4ad3bd 100644 --- a/examples/addressbook.proto +++ b/examples/addressbook.proto @@ -24,7 +24,7 @@ option csharp_namespace = "Google.Protobuf.Examples.AddressBook"; // [END csharp_declaration] // [START go_declaration] -option go_package = "../tutorial"; +option go_package = "github.com/protocolbuffers/protobuf/examples/go/tutorialpb"; // [END go_declaration] // [START messages] diff --git a/examples/add_person.go b/examples/go/cmd/add_person/add_person.go similarity index 96% rename from examples/add_person.go rename to examples/go/cmd/add_person/add_person.go index 7ffb0ab095..5d2f21c1f3 100644 --- a/examples/add_person.go +++ b/examples/go/cmd/add_person/add_person.go @@ -9,8 +9,8 @@ import ( "os" "strings" - "github.com/golang/protobuf/proto" - pb "github.com/protocolbuffers/protobuf/examples/tutorial" + pb "github.com/protocolbuffers/protobuf/examples/go/tutorialpb" + "google.golang.org/protobuf/proto" ) func promptForAddress(r io.Reader) (*pb.Person, error) { diff --git a/examples/add_person_test.go b/examples/go/cmd/add_person/add_person_test.go similarity index 88% rename from examples/add_person_test.go rename to examples/go/cmd/add_person/add_person_test.go index d35f10ece9..f10c355a68 100644 --- a/examples/add_person_test.go +++ b/examples/go/cmd/add_person/add_person_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" - "github.com/golang/protobuf/proto" - pb "github.com/protocolbuffers/protobuf/examples/tutorial" + pb "github.com/protocolbuffers/protobuf/examples/go/tutorialpb" + "google.golang.org/protobuf/proto" ) func TestPromptForAddressReturnsAddress(t *testing.T) { @@ -51,7 +51,7 @@ unknown } for i := 0; i < phones; i++ { if !proto.Equal(got.Phones[i], want[i]) { - t.Errorf("want phone %q, got %q", *want[i], *got.Phones[i]) + t.Errorf("want phone %q, got %q", want[i], got.Phones[i]) } } diff --git a/examples/list_people.go b/examples/go/cmd/list_people/list_people.go similarity index 92% rename from examples/list_people.go rename to examples/go/cmd/list_people/list_people.go index 6c2c34ac33..5ca0dcf31b 100644 --- a/examples/list_people.go +++ b/examples/go/cmd/list_people/list_people.go @@ -7,8 +7,8 @@ import ( "log" "os" - "github.com/golang/protobuf/proto" - pb "github.com/protocolbuffers/protobuf/examples/tutorial" + pb "github.com/protocolbuffers/protobuf/examples/go/tutorialpb" + "google.golang.org/protobuf/proto" ) func writePerson(w io.Writer, p *pb.Person) { diff --git a/examples/list_people_test.go b/examples/go/cmd/list_people/list_people_test.go similarity index 97% rename from examples/list_people_test.go rename to examples/go/cmd/list_people/list_people_test.go index aceabd4a61..b116c16a95 100644 --- a/examples/list_people_test.go +++ b/examples/go/cmd/list_people/list_people_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - pb "github.com/protocolbuffers/protobuf/examples/tutorial" + pb "github.com/protocolbuffers/protobuf/examples/go/tutorialpb" ) func TestWritePersonWritesPerson(t *testing.T) { diff --git a/examples/go/go.mod b/examples/go/go.mod new file mode 100644 index 0000000000..ed43328d78 --- /dev/null +++ b/examples/go/go.mod @@ -0,0 +1,5 @@ +module github.com/protocolbuffers/protobuf/examples/go + +go 1.14 + +require google.golang.org/protobuf v1.27.1 diff --git a/examples/go/go.sum b/examples/go/go.sum new file mode 100644 index 0000000000..9f8c064398 --- /dev/null +++ b/examples/go/go.sum @@ -0,0 +1,6 @@ +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= From f4af0bc931bf731c4a356e26cc33c73ce5a835bf Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 21 Oct 2021 14:15:54 -0700 Subject: [PATCH 020/207] Fix distcheck test by updating example Go file paths (#9137) --- Makefile.am | 120 ++++++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/Makefile.am b/Makefile.am index 178c124b5e..8e9f1bfdc7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1371,65 +1371,67 @@ js_EXTRA_DIST= \ all_EXTRA_DIST=$(csharp_EXTRA_DIST) $(java_EXTRA_DIST) $(objectivec_EXTRA_DIST) $(php_EXTRA_DIST) $(python_EXTRA_DIST) $(ruby_EXTRA_DIST) $(js_EXTRA_DIST) -EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ - autogen.sh \ - generate_descriptor_proto.sh \ - README.md \ - LICENSE \ - CONTRIBUTORS.txt \ - CHANGES.txt \ - update_file_lists.sh \ - BUILD \ - WORKSPACE \ - cmake/CMakeLists.txt \ - cmake/README.md \ - cmake/conformance.cmake \ - cmake/examples.cmake \ - cmake/extract_includes.bat.in \ - cmake/install.cmake \ - cmake/libprotobuf.cmake \ - cmake/libprotobuf-lite.cmake \ - cmake/libprotoc.cmake \ - cmake/protobuf-config-version.cmake.in \ - cmake/protobuf-config.cmake.in \ - cmake/protobuf-lite.pc.cmake \ - cmake/protobuf-module.cmake.in \ - cmake/protobuf-options.cmake \ - cmake/protobuf.pc.cmake \ - cmake/protoc.cmake \ - cmake/tests.cmake \ - cmake/version.rc.in \ - compiler_config_setting.bzl \ - build_files_updated_unittest.sh \ - cc_proto_blacklist_test.bzl \ - editors/README.txt \ - editors/proto.vim \ - editors/protobuf-mode.el \ - examples/AddPerson.java \ - examples/BUILD \ - examples/CMakeLists.txt \ - examples/ListPeople.java \ - examples/Makefile \ - examples/README.md \ - examples/WORKSPACE \ - examples/add_person.cc \ - examples/add_person.dart \ - examples/add_person.go \ - examples/add_person.py \ - examples/add_person_test.go \ - examples/addressbook.proto \ - examples/list_people.cc \ - examples/list_people.dart \ - examples/list_people.go \ - examples/list_people.py \ - examples/list_people_test.go \ - examples/pubspec.yaml \ - maven_install.json \ - protobuf.bzl \ - protobuf_deps.bzl \ - protobuf_version.bzl \ - third_party/zlib.BUILD \ - util/python/BUILD \ +EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ + autogen.sh \ + generate_descriptor_proto.sh \ + README.md \ + LICENSE \ + CONTRIBUTORS.txt \ + CHANGES.txt \ + update_file_lists.sh \ + BUILD \ + WORKSPACE \ + cmake/CMakeLists.txt \ + cmake/README.md \ + cmake/conformance.cmake \ + cmake/examples.cmake \ + cmake/extract_includes.bat.in \ + cmake/install.cmake \ + cmake/libprotobuf.cmake \ + cmake/libprotobuf-lite.cmake \ + cmake/libprotoc.cmake \ + cmake/protobuf-config-version.cmake.in \ + cmake/protobuf-config.cmake.in \ + cmake/protobuf-lite.pc.cmake \ + cmake/protobuf-module.cmake.in \ + cmake/protobuf-options.cmake \ + cmake/protobuf.pc.cmake \ + cmake/protoc.cmake \ + cmake/tests.cmake \ + cmake/version.rc.in \ + compiler_config_setting.bzl \ + build_files_updated_unittest.sh \ + cc_proto_blacklist_test.bzl \ + editors/README.txt \ + editors/proto.vim \ + editors/protobuf-mode.el \ + examples/AddPerson.java \ + examples/BUILD \ + examples/CMakeLists.txt \ + examples/ListPeople.java \ + examples/Makefile \ + examples/README.md \ + examples/WORKSPACE \ + examples/add_person.cc \ + examples/add_person.dart \ + examples/add_person.py \ + examples/addressbook.proto \ + examples/go/cmd/add_person/add_person.go \ + examples/go/cmd/add_person/add_person_test.go \ + examples/go/cmd/list_people/list_people.go \ + examples/go/cmd/list_people/list_people_test.go \ + examples/go/go.sum \ + examples/go/go.mod \ + examples/list_people.cc \ + examples/list_people.dart \ + examples/list_people.py \ + examples/pubspec.yaml \ + maven_install.json \ + protobuf.bzl \ + protobuf_deps.bzl \ + protobuf_version.bzl \ + third_party/zlib.BUILD \ + util/python/BUILD \ internal.bzl From adc1f931e328f7b7462ffaed07b79e66fcc69c00 Mon Sep 17 00:00:00 2001 From: Derek Perez Date: Thu, 21 Oct 2021 21:17:20 +0000 Subject: [PATCH 021/207] Fix wkt dupes (#8942) * properly ignore WKTs in lang_proto_toolchain for java We already pre-compile the well known types into the runtimes so they shouldn't be re-compiled. #8925 * remove accidental proto addition. --- java/core/BUILD | 15 +++++++++++++++ java/lite/BUILD | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/java/core/BUILD b/java/core/BUILD index c65f10a4e1..530d516886 100644 --- a/java/core/BUILD +++ b/java/core/BUILD @@ -176,6 +176,21 @@ proto_lang_toolchain( command_line = "--java_out=$(OUT)", runtime = ":core", visibility = ["//visibility:public"], + # keep this in sync w/ WELL_KNOWN_PROTO_MAP in //:BUILD + blacklisted_protos = [ + "//:any_proto", + "//:api_proto", + "//:compiler_plugin_proto", + "//:descriptor_proto", + "//:duration_proto", + "//:empty_proto", + "//:field_mask_proto", + "//:source_context_proto", + "//:struct_proto", + "//:timestamp_proto", + "//:type_proto", + "//:wrappers_proto", + ], ) proto_library( diff --git a/java/lite/BUILD b/java/lite/BUILD index 7089f958b0..520d22d591 100644 --- a/java/lite/BUILD +++ b/java/lite/BUILD @@ -17,6 +17,19 @@ proto_lang_toolchain( command_line = "--java_out=lite:$(OUT)", runtime = ":lite", visibility = ["//visibility:public"], + # keep this in sync w/ LITE_WELL_KNOWN_PROTO_MAP in //:BUILD + blacklisted_protos = [ + "//:any_proto", + "//:api_proto", + "//:duration_proto", + "//:empty_proto", + "//:field_mask_proto", + "//:source_context_proto", + "//:struct_proto", + "//:timestamp_proto", + "//:type_proto", + "//:wrappers_proto", + ], ) test_suite( From 0707f2e7f556c8396d6027d0533ec3a56d1061db Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Thu, 21 Oct 2021 15:09:41 -0700 Subject: [PATCH 022/207] Provide a type alias field ValueType on EnumTypeWrapper (#8182) This should provide a runtime alias, which can be used in mypy stubs to provide better typing for enum values Fixes #8175 --- python/google/protobuf/internal/enum_type_wrapper.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/google/protobuf/internal/enum_type_wrapper.py b/python/google/protobuf/internal/enum_type_wrapper.py index 9a53999a43..65d2c7a5c0 100644 --- a/python/google/protobuf/internal/enum_type_wrapper.py +++ b/python/google/protobuf/internal/enum_type_wrapper.py @@ -43,6 +43,15 @@ class EnumTypeWrapper(object): DESCRIPTOR = None + # This is a type alias, which mypy typing stubs can type as + # a genericized parameter constrained to an int, allowing subclasses + # to be typed with more constraint in .pyi stubs + # Eg. + # def MyGeneratedEnum(Message): + # ValueType = NewType('ValueType', int) + # def Name(self, number: MyGeneratedEnum.ValueType) -> str + ValueType = int + def __init__(self, enum_type): """Inits EnumTypeWrapper with an EnumDescriptor.""" self._enum_type = enum_type From 02d2e5fdd71a798f221ab3098019eaf51ecc5533 Mon Sep 17 00:00:00 2001 From: appledragon Date: Mon, 25 Oct 2021 15:31:06 +0800 Subject: [PATCH 023/207] Update stl_util.h --- src/google/protobuf/stubs/stl_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/stubs/stl_util.h b/src/google/protobuf/stubs/stl_util.h index 3bc1dbf002..45d28904f9 100644 --- a/src/google/protobuf/stubs/stl_util.h +++ b/src/google/protobuf/stubs/stl_util.h @@ -57,7 +57,7 @@ inline void STLStringResizeUninitializedAmortized(std::string* s, const size_t cap = s->capacity(); if (new_size > cap) { // Make sure to always grow by at least a factor of 2x. - s->reserve(std::max(new_size, 2 * cap)); + s->reserve(std::max(new_size, 2 * cap)); } STLStringResizeUninitialized(s, new_size); } From 3370cc4456deaeb97ca6ae4aa10b0be1f2610c7f Mon Sep 17 00:00:00 2001 From: David Mollitor Date: Mon, 25 Oct 2021 13:46:34 -0400 Subject: [PATCH 024/207] Transition to NIO StandardCharsets --- .../java/com/google/protobuf/ArrayDecoders.java | 11 ++++++----- .../java/com/google/protobuf/BinaryReader.java | 3 ++- .../java/com/google/protobuf/ByteString.java | 5 +++-- .../com/google/protobuf/CodedInputStream.java | 3 ++- .../com/google/protobuf/CodedOutputStream.java | 6 +++--- .../java/com/google/protobuf/Descriptors.java | 5 +++-- .../main/java/com/google/protobuf/Internal.java | 16 ++++++---------- .../java/com/google/protobuf/MessageSchema.java | 3 ++- .../src/main/java/com/google/protobuf/Utf8.java | 3 ++- .../google/protobuf/BoundedByteStringTest.java | 8 +++++--- .../com/google/protobuf/ByteStringTest.java | 9 +++++---- .../google/protobuf/CodedOutputStreamTest.java | 7 ++++--- .../com/google/protobuf/DecodeUtf8Test.java | 17 +++++++++-------- .../com/google/protobuf/DescriptorsTest.java | 4 +++- .../google/protobuf/IsValidUtf8TestUtil.java | 5 +++-- .../google/protobuf/LiteralByteStringTest.java | 11 ++++++----- .../com/google/protobuf/NioByteStringTest.java | 3 ++- .../protobuf/RopeByteStringSubstringTest.java | 3 ++- .../com/google/protobuf/RopeByteStringTest.java | 7 ++++--- .../com/google/protobuf/TextFormatTest.java | 3 ++- .../test/java/com/google/protobuf/Utf8Test.java | 3 ++- .../protobuf/WrappersLiteOfMethodTest.java | 4 +++- .../google/protobuf/WrappersOfMethodTest.java | 4 +++- .../test/java/com/google/protobuf/LiteTest.java | 3 ++- 24 files changed, 84 insertions(+), 62 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java b/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java index 1217e112e0..0471afaf1f 100644 --- a/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java +++ b/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java @@ -34,6 +34,7 @@ import static com.google.protobuf.MessageSchema.getMutableUnknownFields; import com.google.protobuf.Internal.ProtobufList; import java.io.IOException; +import java.nio.charset.StandardCharsets; /** * Helper functions to decode protobuf wire format from a byte array. @@ -191,7 +192,7 @@ final class ArrayDecoders { registers.object1 = ""; return position; } else { - registers.object1 = new String(data, position, length, Internal.UTF_8); + registers.object1 = new String(data, position, length, StandardCharsets.UTF_8); return position + length; } } @@ -577,7 +578,7 @@ final class ArrayDecoders { } else if (length == 0) { output.add(""); } else { - String value = new String(data, position, length, Internal.UTF_8); + String value = new String(data, position, length, StandardCharsets.UTF_8); output.add(value); position += length; } @@ -593,7 +594,7 @@ final class ArrayDecoders { } else if (nextLength == 0) { output.add(""); } else { - String value = new String(data, position, nextLength, Internal.UTF_8); + String value = new String(data, position, nextLength, StandardCharsets.UTF_8); output.add(value); position += nextLength; } @@ -619,7 +620,7 @@ final class ArrayDecoders { if (!Utf8.isValidUtf8(data, position, position + length)) { throw InvalidProtocolBufferException.invalidUtf8(); } - String value = new String(data, position, length, Internal.UTF_8); + String value = new String(data, position, length, StandardCharsets.UTF_8); output.add(value); position += length; } @@ -638,7 +639,7 @@ final class ArrayDecoders { if (!Utf8.isValidUtf8(data, position, position + nextLength)) { throw InvalidProtocolBufferException.invalidUtf8(); } - String value = new String(data, position, nextLength, Internal.UTF_8); + String value = new String(data, position, nextLength, StandardCharsets.UTF_8); output.add(value); position += nextLength; } diff --git a/java/core/src/main/java/com/google/protobuf/BinaryReader.java b/java/core/src/main/java/com/google/protobuf/BinaryReader.java index d64574c2a5..547e78c014 100644 --- a/java/core/src/main/java/com/google/protobuf/BinaryReader.java +++ b/java/core/src/main/java/com/google/protobuf/BinaryReader.java @@ -41,6 +41,7 @@ import static com.google.protobuf.WireFormat.WIRETYPE_VARINT; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; @@ -226,7 +227,7 @@ abstract class BinaryReader implements Reader { if (requireUtf8 && !Utf8.isValidUtf8(buffer, pos, pos + size)) { throw InvalidProtocolBufferException.invalidUtf8(); } - String result = new String(buffer, pos, size, Internal.UTF_8); + String result = new String(buffer, pos, size, StandardCharsets.UTF_8); pos += size; return result; } diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index a4beaeb4cf..c42b28c4f2 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -45,6 +45,7 @@ import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Arrays; @@ -460,7 +461,7 @@ public abstract class ByteString implements Iterable, Serializable { * @return new {@code ByteString} */ public static ByteString copyFromUtf8(String text) { - return new LiteralByteString(text.getBytes(Internal.UTF_8)); + return new LiteralByteString(text.getBytes(StandardCharsets.UTF_8)); } // ================================================================= @@ -833,7 +834,7 @@ public abstract class ByteString implements Iterable, Serializable { * @return new string using UTF-8 encoding */ public final String toStringUtf8() { - return toString(Internal.UTF_8); + return toString(StandardCharsets.UTF_8); } /** diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index 6e9c0f6209..ad87d4e05c 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -32,12 +32,13 @@ package com.google.protobuf; import static com.google.protobuf.Internal.EMPTY_BYTE_ARRAY; import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; -import static com.google.protobuf.Internal.UTF_8; import static com.google.protobuf.Internal.checkNotNull; import static com.google.protobuf.WireFormat.FIXED32_SIZE; import static com.google.protobuf.WireFormat.FIXED64_SIZE; import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index 12f2097a8f..65ea627044 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -42,6 +42,7 @@ import java.io.OutputStream; import java.nio.BufferOverflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; @@ -842,7 +843,7 @@ public abstract class CodedOutputStream extends ByteOutput { length = Utf8.encodedLength(value); } catch (UnpairedSurrogateException e) { // TODO(dweis): Consider using nio Charset methods instead. - final byte[] bytes = value.getBytes(Internal.UTF_8); + final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); length = bytes.length; } @@ -989,8 +990,7 @@ public abstract class CodedOutputStream extends ByteOutput { // Unfortunately there does not appear to be any way to tell Java to encode // UTF-8 directly into our buffer, so we have to let it create its own byte // array and then copy. - // TODO(dweis): Consider using nio Charset methods instead. - final byte[] bytes = value.getBytes(Internal.UTF_8); + final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); try { writeUInt32NoTag(bytes.length); writeLazy(bytes, 0, bytes.length); 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 f36d033327..c3b6dc09e0 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -51,6 +51,7 @@ import com.google.protobuf.DescriptorProtos.ServiceOptions; import com.google.protobuf.Descriptors.FileDescriptor.Syntax; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -333,13 +334,13 @@ public final class Descriptors { // should get the original bytes that we want. // Literal strings are limited to 64k, so it may be split into multiple strings. if (strings.length == 1) { - return strings[0].getBytes(Internal.ISO_8859_1); + return strings[0].getBytes(StandardCharsets.ISO_8859_1); } StringBuilder descriptorData = new StringBuilder(); for (String part : strings) { descriptorData.append(part); } - return descriptorData.toString().getBytes(Internal.ISO_8859_1); + return descriptorData.toString().getBytes(StandardCharsets.ISO_8859_1); } private static FileDescriptor[] findDescriptors( diff --git a/java/core/src/main/java/com/google/protobuf/Internal.java b/java/core/src/main/java/com/google/protobuf/Internal.java index 07e8dd1322..1c7e7049ea 100644 --- a/java/core/src/main/java/com/google/protobuf/Internal.java +++ b/java/core/src/main/java/com/google/protobuf/Internal.java @@ -32,7 +32,7 @@ package com.google.protobuf; import java.lang.reflect.Method; import java.nio.ByteBuffer; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.AbstractList; import java.util.AbstractMap; import java.util.AbstractSet; @@ -54,10 +54,6 @@ public final class Internal { private Internal() {} - static final Charset US_ASCII = Charset.forName("US-ASCII"); - static final Charset UTF_8 = Charset.forName("UTF-8"); - static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); - /** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */ static T checkNotNull(T obj) { if (obj == null) { @@ -97,7 +93,7 @@ public final class Internal { * actually want. The generated code calls this automatically. */ public static String stringDefaultValue(String bytes) { - return new String(bytes.getBytes(ISO_8859_1), UTF_8); + return new String(bytes.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); } /** @@ -108,7 +104,7 @@ public final class Internal { * ISO-8859-1 encoding. */ public static ByteString bytesDefaultValue(String bytes) { - return ByteString.copyFrom(bytes.getBytes(ISO_8859_1)); + return ByteString.copyFrom(bytes.getBytes(StandardCharsets.ISO_8859_1)); } /** * Helper called by generated code to construct default values for bytes fields. @@ -116,7 +112,7 @@ public final class Internal { *

This is like {@link #bytesDefaultValue}, but returns a byte array. */ public static byte[] byteArrayDefaultValue(String bytes) { - return bytes.getBytes(ISO_8859_1); + return bytes.getBytes(StandardCharsets.ISO_8859_1); } /** @@ -183,12 +179,12 @@ public final class Internal { /** Helper method to get the UTF-8 bytes of a string. */ public static byte[] toByteArray(String value) { - return value.getBytes(UTF_8); + return value.getBytes(StandardCharsets.UTF_8); } /** Helper method to convert a byte array to a string using UTF-8 encoding. */ public static String toStringUtf8(byte[] bytes) { - return new String(bytes, UTF_8); + return new String(bytes, StandardCharsets.UTF_8); } /** diff --git a/java/core/src/main/java/com/google/protobuf/MessageSchema.java b/java/core/src/main/java/com/google/protobuf/MessageSchema.java index 4170f4fbe4..518f647e3e 100644 --- a/java/core/src/main/java/com/google/protobuf/MessageSchema.java +++ b/java/core/src/main/java/com/google/protobuf/MessageSchema.java @@ -76,6 +76,7 @@ import com.google.protobuf.Internal.ProtobufList; import com.google.protobuf.MapEntryLite.Metadata; import java.io.IOException; import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -4765,7 +4766,7 @@ final class MessageSchema implements Schema { && !Utf8.isValidUtf8(data, position, position + length)) { throw InvalidProtocolBufferException.invalidUtf8(); } - final String value = new String(data, position, length, Internal.UTF_8); + final String value = new String(data, position, length, StandardCharsets.UTF_8); unsafe.putObject(message, fieldOffset, value); position += length; } diff --git a/java/core/src/main/java/com/google/protobuf/Utf8.java b/java/core/src/main/java/com/google/protobuf/Utf8.java index 7c9133e16b..2a6023ccc0 100644 --- a/java/core/src/main/java/com/google/protobuf/Utf8.java +++ b/java/core/src/main/java/com/google/protobuf/Utf8.java @@ -42,6 +42,7 @@ import static java.lang.Character.isSurrogatePair; import static java.lang.Character.toCodePoint; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; /** * A set of low-level, high-performance static utility methods related to the UTF-8 character @@ -1386,7 +1387,7 @@ final class Utf8 { if (offset == limit) { // The entire byte sequence is ASCII. Don't bother copying to a char[], JVMs using // compact strings will just turn it back into the same byte[]. - return new String(bytes, index, size, Internal.US_ASCII); + return new String(bytes, index, size, StandardCharsets.US_ASCII); } // It's not all ASCII, at this point. This may over-allocate, but we will truncate in the diff --git a/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java b/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java index 656d2c3ab6..210134f0f0 100644 --- a/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java @@ -38,6 +38,8 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -68,7 +70,7 @@ public class BoundedByteStringTest extends LiteralByteStringTest { @Test public void testToString() throws UnsupportedEncodingException { String testString = "I love unicode \u1234\u5678 characters"; - ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(StandardCharsets.UTF_8)); ByteString chopped = unicode.substring(2, unicode.size() - 6); assertWithMessage("%s.substring() must have the expected type", classUnderTest) .that(classUnderTest) @@ -84,13 +86,13 @@ public class BoundedByteStringTest extends LiteralByteStringTest { @Test public void testCharsetToString() { String testString = "I love unicode \u1234\u5678 characters"; - ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(StandardCharsets.UTF_8)); ByteString chopped = unicode.substring(2, unicode.size() - 6); assertWithMessage("%s.substring() must have the expected type", classUnderTest) .that(classUnderTest) .isEqualTo(getActualClassName(chopped)); - String roundTripString = chopped.toString(Internal.UTF_8); + String roundTripString = chopped.toString(StandardCharsets.UTF_8); assertWithMessage("%s unicode bytes must match", classUnderTest) .that(testString.substring(2, testString.length() - 6)) .isEqualTo(roundTripString); diff --git a/java/core/src/test/java/com/google/protobuf/ByteStringTest.java b/java/core/src/test/java/com/google/protobuf/ByteStringTest.java index 3f97e3174f..5d1028a2e6 100644 --- a/java/core/src/test/java/com/google/protobuf/ByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/ByteStringTest.java @@ -42,6 +42,7 @@ import java.io.OutputStream; import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -198,7 +199,7 @@ public class ByteStringTest { public void testCopyFrom_Utf8() { String testString = "I love unicode \u1234\u5678 characters"; ByteString byteString = ByteString.copyFromUtf8(testString); - byte[] testBytes = testString.getBytes(Internal.UTF_8); + byte[] testBytes = testString.getBytes(StandardCharsets.UTF_8); assertWithMessage("copyFromUtf8 string must respect the charset") .that(isArrayRange(byteString.toByteArray(), testBytes, 0, testBytes.length)) .isTrue(); @@ -516,7 +517,7 @@ public class ByteStringTest { @Test public void testToStringUtf8() { String testString = "I love unicode \u1234\u5678 characters"; - byte[] testBytes = testString.getBytes(Internal.UTF_8); + byte[] testBytes = testString.getBytes(StandardCharsets.UTF_8); ByteString byteString = ByteString.copyFrom(testBytes); assertWithMessage("copyToStringUtf8 must respect the charset") .that(testString) @@ -526,7 +527,7 @@ public class ByteStringTest { @Test public void testToString() { String toString = - ByteString.copyFrom("Here are some bytes: \t\u00a1".getBytes(Internal.UTF_8)).toString(); + ByteString.copyFrom("Here are some bytes: \t\u00a1".getBytes(StandardCharsets.UTF_8)).toString(); assertWithMessage(toString).that(toString.contains("size=24")).isTrue(); assertWithMessage(toString) .that(toString.contains("contents=\"Here are some bytes: \\t\\302\\241\"")) @@ -538,7 +539,7 @@ public class ByteStringTest { String toString = ByteString.copyFrom( "123456789012345678901234567890123456789012345678901234567890" - .getBytes(Internal.UTF_8)) + .getBytes(StandardCharsets.UTF_8)) .toString(); assertWithMessage(toString).that(toString.contains("size=60")).isTrue(); assertWithMessage(toString) diff --git a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java index 9934ca19ff..5bc514f342 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java @@ -41,6 +41,7 @@ import protobuf_unittest.UnittestProto.TestSparseEnum; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -417,7 +418,7 @@ public class CodedOutputStreamTest { // Write some some bytes (more than the buffer can hold) and verify that totalWritten // is correct. - byte[] value = "abcde".getBytes(Internal.UTF_8); + byte[] value = "abcde".getBytes(StandardCharsets.UTF_8); for (int i = 0; i < 1024; ++i) { coder.stream().writeRawBytes(value, 0, value.length); } @@ -500,7 +501,7 @@ public class CodedOutputStreamTest { @Test public void testWriteByteBuffer() throws Exception { - byte[] value = "abcde".getBytes(Internal.UTF_8); + byte[] value = "abcde".getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); CodedOutputStream codedStream = CodedOutputStream.newInstance(outputStream); ByteBuffer byteBuffer = ByteBuffer.wrap(value, 0, 1); @@ -543,7 +544,7 @@ public class CodedOutputStreamTest { for (int pos = 0; pos < source.length(); pos += 2) { String substr = source.substring(pos, pos + 2); expectedBytesStream.write(2); - expectedBytesStream.write(substr.getBytes(Internal.UTF_8)); + expectedBytesStream.write(substr.getBytes(StandardCharsets.UTF_8)); } final byte[] expectedBytes = expectedBytesStream.toByteArray(); diff --git a/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java b/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java index 5a345aa173..690d130ed9 100644 --- a/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java +++ b/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java @@ -34,6 +34,7 @@ import com.google.protobuf.Utf8.Processor; import com.google.protobuf.Utf8.SafeProcessor; import com.google.protobuf.Utf8.UnsafeProcessor; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; @@ -196,7 +197,7 @@ public class DecodeUtf8Test extends TestCase { } public void testInvalidBufferSlice() throws Exception { - byte[] bytes = "The quick brown fox jumps over the lazy dog".getBytes(Internal.UTF_8); + byte[] bytes = "The quick brown fox jumps over the lazy dog".getBytes(StandardCharsets.UTF_8); assertInvalidSlice(bytes, bytes.length - 3, 4); assertInvalidSlice(bytes, bytes.length, 1); assertInvalidSlice(bytes, bytes.length + 1, 0); @@ -301,35 +302,35 @@ public class DecodeUtf8Test extends TestCase { } private void assertRoundTrips(String str, int index, int size) throws Exception { - byte[] bytes = str.getBytes(Internal.UTF_8); + byte[] bytes = str.getBytes(StandardCharsets.UTF_8); if (size == -1) { size = bytes.length; } assertDecode( - new String(bytes, index, size, Internal.UTF_8), + new String(bytes, index, size, StandardCharsets.UTF_8), UNSAFE_PROCESSOR.decodeUtf8(bytes, index, size)); assertDecode( - new String(bytes, index, size, Internal.UTF_8), + new String(bytes, index, size, StandardCharsets.UTF_8), SAFE_PROCESSOR.decodeUtf8(bytes, index, size)); ByteBuffer direct = ByteBuffer.allocateDirect(bytes.length); direct.put(bytes); direct.flip(); assertDecode( - new String(bytes, index, size, Internal.UTF_8), + new String(bytes, index, size, StandardCharsets.UTF_8), UNSAFE_PROCESSOR.decodeUtf8(direct, index, size)); assertDecode( - new String(bytes, index, size, Internal.UTF_8), + new String(bytes, index, size, StandardCharsets.UTF_8), SAFE_PROCESSOR.decodeUtf8(direct, index, size)); ByteBuffer heap = ByteBuffer.allocate(bytes.length); heap.put(bytes); heap.flip(); assertDecode( - new String(bytes, index, size, Internal.UTF_8), + new String(bytes, index, size, StandardCharsets.UTF_8), UNSAFE_PROCESSOR.decodeUtf8(heap, index, size)); assertDecode( - new String(bytes, index, size, Internal.UTF_8), + new String(bytes, index, size, StandardCharsets.UTF_8), SAFE_PROCESSOR.decodeUtf8(heap, index, size)); } diff --git a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java index 6cb0baebed..9e93b9f86c 100644 --- a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java +++ b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java @@ -63,6 +63,8 @@ import protobuf_unittest.UnittestProto.TestMultipleExtensionRanges; import protobuf_unittest.UnittestProto.TestRequired; import protobuf_unittest.UnittestProto.TestReservedFields; import protobuf_unittest.UnittestProto.TestService; + +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import org.junit.Test; @@ -281,7 +283,7 @@ public class DescriptorsTest { assertThat(d.findFieldByName("escaped_bytes").getDefaultValue()) .isEqualTo( ByteString.copyFrom( - "\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes(Internal.ISO_8859_1))); + "\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes(StandardCharsets.ISO_8859_1))); assertThat(d.findFieldByName("large_uint32").getDefaultValue()).isEqualTo(-1); assertThat(d.findFieldByName("large_uint64").getDefaultValue()).isEqualTo(-1L); } diff --git a/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java b/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java index f1a671164d..0c24207fcd 100644 --- a/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java +++ b/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java @@ -35,6 +35,7 @@ import static com.google.common.truth.Truth.assertWithMessage; import java.lang.ref.SoftReference; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -276,8 +277,8 @@ final class IsValidUtf8TestUtil { } ByteString bs = factory.newByteString(bytes); boolean isRoundTrippable = bs.isValidUtf8(); - String s = new String(bytes, Internal.UTF_8); - byte[] bytesReencoded = s.getBytes(Internal.UTF_8); + String s = new String(bytes, StandardCharsets.UTF_8); + byte[] bytesReencoded = s.getBytes(StandardCharsets.UTF_8); boolean bytesEqual = Arrays.equals(bytes, bytesReencoded); if (bytesEqual != isRoundTrippable) { diff --git a/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java b/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java index 5ec4a937bb..573af2f016 100644 --- a/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java @@ -43,6 +43,7 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; @@ -468,7 +469,7 @@ public class LiteralByteStringTest { @Test public void testToString() throws UnsupportedEncodingException { String testString = "I love unicode \u1234\u5678 characters"; - ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(StandardCharsets.UTF_8)); String roundTripString = unicode.toString(UTF_8); assertWithMessage("%s unicode must match", classUnderTest) .that(testString) @@ -478,8 +479,8 @@ public class LiteralByteStringTest { @Test public void testCharsetToString() { String testString = "I love unicode \u1234\u5678 characters"; - ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); - String roundTripString = unicode.toString(Internal.UTF_8); + ByteString unicode = ByteString.wrap(testString.getBytes(StandardCharsets.UTF_8)); + String roundTripString = unicode.toString(StandardCharsets.UTF_8); assertWithMessage("%s unicode must match", classUnderTest) .that(testString) .isEqualTo(roundTripString); @@ -488,8 +489,8 @@ public class LiteralByteStringTest { @Test public void testToString_returnsCanonicalEmptyString() { assertWithMessage("%s must be the same string references", classUnderTest) - .that(ByteString.EMPTY.toString(Internal.UTF_8)) - .isSameInstanceAs(ByteString.wrap(new byte[] {}).toString(Internal.UTF_8)); + .that(ByteString.EMPTY.toString(StandardCharsets.UTF_8)) + .isSameInstanceAs(ByteString.wrap(new byte[] {}).toString(StandardCharsets.UTF_8)); } @Test diff --git a/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java b/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java index 1f1427142b..d645b89359 100644 --- a/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java @@ -32,7 +32,8 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; -import static com.google.protobuf.Internal.UTF_8; + +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java b/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java index 0bfc0beaa3..445dbe229d 100644 --- a/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +++ b/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java @@ -33,6 +33,7 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertWithMessage; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Iterator; import org.junit.Before; import org.junit.Test; @@ -132,7 +133,7 @@ public class RopeByteStringSubstringTest extends LiteralByteStringTest { assertWithMessage("%s from string must have the expected type", classUnderTest) .that(classUnderTest) .isEqualTo(getActualClassName(unicode)); - String roundTripString = unicode.toString(Internal.UTF_8); + String roundTripString = unicode.toString(StandardCharsets.UTF_8); assertWithMessage("%s unicode bytes must match", classUnderTest) .that(testString) .isEqualTo(roundTripString); diff --git a/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java index bdb8132020..000c374556 100644 --- a/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java @@ -39,6 +39,7 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Iterator; import org.junit.Before; @@ -175,7 +176,7 @@ public class RopeByteStringTest extends LiteralByteStringTest { assertWithMessage("%s from string must have the expected type", classUnderTest) .that(classUnderTest) .isEqualTo(getActualClassName(unicode)); - String roundTripString = unicode.toString(Internal.UTF_8); + String roundTripString = unicode.toString(StandardCharsets.UTF_8); assertWithMessage("%s unicode bytes must match", classUnderTest) .that(testString) .isEqualTo(roundTripString); @@ -194,8 +195,8 @@ public class RopeByteStringTest extends LiteralByteStringTest { RopeByteString ropeByteString = RopeByteString.newInstanceForTest(ByteString.EMPTY, ByteString.EMPTY); assertWithMessage("%s must be the same string references", classUnderTest) - .that(ByteString.EMPTY.toString(Internal.UTF_8)) - .isSameInstanceAs(ropeByteString.toString(Internal.UTF_8)); + .that(ByteString.EMPTY.toString(StandardCharsets.UTF_8)) + .isSameInstanceAs(ropeByteString.toString(StandardCharsets.UTF_8)); } @Override diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index f9b7da46b7..c4fb591676 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -59,6 +59,7 @@ import protobuf_unittest.UnittestProto.TestOneof2; import protobuf_unittest.UnittestProto.TestRequired; import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.logging.Logger; @@ -277,7 +278,7 @@ public class TextFormatTest { * are converted directly to bytes, *not* encoded using UTF-8. */ private ByteString bytes(String str) { - return ByteString.copyFrom(str.getBytes(Internal.ISO_8859_1)); + return ByteString.copyFrom(str.getBytes(StandardCharsets.ISO_8859_1)); } /** diff --git a/java/core/src/test/java/com/google/protobuf/Utf8Test.java b/java/core/src/test/java/com/google/protobuf/Utf8Test.java index 89f080ef36..5fdc61b5e5 100644 --- a/java/core/src/test/java/com/google/protobuf/Utf8Test.java +++ b/java/core/src/test/java/com/google/protobuf/Utf8Test.java @@ -34,6 +34,7 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Random; import org.junit.Test; import org.junit.runner.RunWith; @@ -133,7 +134,7 @@ public class Utf8Test { } private static void assertEncoding(String message) { - byte[] expected = message.getBytes(Internal.UTF_8); + byte[] expected = message.getBytes(StandardCharsets.UTF_8); byte[] output = encodeToByteArray(message, expected.length, safeProcessor); assertWithMessage("encodeUtf8[ARRAY]") .that(output).isEqualTo(expected); diff --git a/java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java b/java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java index fc1e09f10e..3f416263f9 100644 --- a/java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java +++ b/java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java @@ -32,6 +32,8 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertThat; +import java.nio.charset.StandardCharsets; + import com.google.protobuf.wrapperstest.WrappersTestProto.TopLevelMessage; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,7 +53,7 @@ public class WrappersLiteOfMethodTest { builder.setFieldUint64(UInt64Value.of(23333333333333L)); builder.setFieldBool(BoolValue.of(true)); builder.setFieldString(StringValue.of("23333")); - builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8)))); + builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(StandardCharsets.UTF_8)))); TopLevelMessage message = builder.build(); assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333); diff --git a/java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java b/java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java index 44c4ad6e6e..0106987215 100644 --- a/java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java +++ b/java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java @@ -32,6 +32,8 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertThat; +import java.nio.charset.StandardCharsets; + import com.google.protobuf.wrapperstest.WrappersTestProto.TopLevelMessage; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,7 +53,7 @@ public class WrappersOfMethodTest { builder.setFieldUint64(UInt64Value.of(23333333333333L)); builder.setFieldBool(BoolValue.of(true)); builder.setFieldString(StringValue.of("23333")); - builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8)))); + builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(StandardCharsets.UTF_8)))); TopLevelMessage message = builder.build(); assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333); diff --git a/java/lite/src/test/java/com/google/protobuf/LiteTest.java b/java/lite/src/test/java/com/google/protobuf/LiteTest.java index b0972111ac..a42ab31c27 100644 --- a/java/lite/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/lite/src/test/java/com/google/protobuf/LiteTest.java @@ -68,6 +68,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Field; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -1720,7 +1721,7 @@ public class LiteTest { public void testMergeFromStream_invalidBytes() throws Exception { TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder().setDefaultBool(true); try { - builder.mergeFrom(CodedInputStream.newInstance("Invalid bytes".getBytes(Internal.UTF_8))); + builder.mergeFrom(CodedInputStream.newInstance("Invalid bytes".getBytes(StandardCharsets.UTF_8))); assertWithMessage("expected exception").fail(); } catch (InvalidProtocolBufferException expected) { } From 3a18299cc0643e7bf73653e8ff9a1d615f295407 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 25 Oct 2021 15:41:19 -0400 Subject: [PATCH 025/207] Fix memory leak in MessageClass.encode If the line above raises an exception, the upb_arena is lost and memory is leaked. --- ruby/ext/google/protobuf_c/message.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 59602cf089..d07eba760d 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1012,7 +1012,6 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { */ static VALUE Message_encode(VALUE klass, VALUE msg_rb) { Message* msg = ruby_to_Message(msg_rb); - upb_arena *arena = upb_arena_new(); const char *data; size_t size; @@ -1020,6 +1019,8 @@ static VALUE Message_encode(VALUE klass, VALUE msg_rb) { rb_raise(rb_eArgError, "Message of wrong type."); } + upb_arena *arena = upb_arena_new(); + data = upb_encode(msg->msg, upb_msgdef_layout(msg->msgdef), arena, &size); From 84c2e1e5027ccce38cf7d79136471410d7d0fe93 Mon Sep 17 00:00:00 2001 From: Taufiq Rahman Date: Tue, 26 Oct 2021 02:09:13 +0600 Subject: [PATCH 026/207] Fix grammatical error in comments #7603 --- src/google/protobuf/descriptor.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 156e410ae1..f307be7e0a 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -803,7 +803,7 @@ message SourceCodeInfo { // location. // // Each element is a field number or an index. They form a path from - // the root FileDescriptorProto to the place where the definition. For + // the root FileDescriptorProto to the place where the definition occurs. For // example, this path: // [ 4, 3, 2, 7, 1 ] // refers to: From 947a51a464ec9ecd3aa7098fe3abfcc4822c1fe5 Mon Sep 17 00:00:00 2001 From: Joel Courtney Date: Tue, 26 Oct 2021 12:43:57 +1100 Subject: [PATCH 027/207] Test coverage: .from_ruby / #from_ruby --- ruby/lib/google/protobuf/well_known_types.rb | 4 +-- ruby/tests/well_known_types_test.rb | 29 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ruby/lib/google/protobuf/well_known_types.rb b/ruby/lib/google/protobuf/well_known_types.rb index b58e815670..f86fe28b77 100755 --- a/ruby/lib/google/protobuf/well_known_types.rb +++ b/ruby/lib/google/protobuf/well_known_types.rb @@ -136,7 +136,7 @@ module Google raise UnexpectedStructType end end - + def self.from_ruby(value) Value.new.from_ruby(value) end @@ -164,7 +164,7 @@ module Google else raise UnexpectedStructType end - + self end end diff --git a/ruby/tests/well_known_types_test.rb b/ruby/tests/well_known_types_test.rb index 996dbc30a5..3e94ca01f3 100755 --- a/ruby/tests/well_known_types_test.rb +++ b/ruby/tests/well_known_types_test.rb @@ -215,4 +215,33 @@ class TestWellKnownTypes < Test::Unit::TestCase ) assert_equal '[]', value_field.get(proto).inspect end + + def test_from_ruby + pb = Google::Protobuf::Value.from_ruby(nil) + assert_equal pb.null_value, 0 + + pb = Google::Protobuf::Value.from_ruby(1.23) + assert_equal pb.number_value, 1.23 + + pb = Google::Protobuf::Value.from_ruby('1.23') + assert_equal pb.string_value, '1.23' + + pb = Google::Protobuf::Value.from_ruby(true) + assert_equal pb.bool_value, true + + pb = Google::Protobuf::Value.from_ruby(false) + assert_equal pb.bool_value, false + + pb = Google::Protobuf::Value.from_ruby(Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] })) + assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] }) + + pb = Google::Protobuf::Value.from_ruby({ a: 1, b: '2', c: [1, 2, 3] }) + assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] }) + + pb = Google::Protobuf::Value.from_ruby(Google::Protobuf::ListValue.from_a([1, 2, 3])) + assert_equal pb.struct_value, Google::Protobuf::ListValue.from_a([1, 2, 3]) + + pb = Google::Protobuf::Value.from_ruby([1, 2, 3]) + assert_equal pb.struct_value, Google::Protobuf::ListValue.from_a([1, 2, 3]) + end end From e350ef8c20da29e1769e8adbe664e6d153c6e0f4 Mon Sep 17 00:00:00 2001 From: Marnix Bouhuis Date: Tue, 26 Oct 2021 18:48:47 +0200 Subject: [PATCH 028/207] JS: Fixed `ReferenceError: window is not defined` when getting the global object (#9156) --- src/google/protobuf/compiler/js/js_generator.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 5542256f38..d2dac2f606 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -3634,7 +3634,14 @@ void Generator::GenerateFile(const GeneratorOptions& options, // - self: defined inside Web Workers (WorkerGlobalScope) // - Function('return this')(): this will work on most platforms, but it may be blocked by things like CSP. // Function('') is almost the same as eval('') - printer->Print("var global = (function() { return this || window || global || self || Function('return this')(); }).call(null);\n\n"); + printer->Print( + "var global = (function() {\n" + " if (this) { return this; }\n" + " if (typeof window !== 'undefined') { return window; }\n" + " if (typeof global !== 'undefined') { return global; }\n" + " if (typeof self !== 'undefined') { return self; }\n" + " return Function('return this')();\n" + "}.call(null));\n\n"); } for (int i = 0; i < file->dependency_count(); i++) { From 9c3af64ae45b9c423093f934f42ac48a3de674ed Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 26 Oct 2021 14:31:46 -0700 Subject: [PATCH 029/207] Update checked-in C# generated code (#9158) This change fixes the test that verifies that the checked-in generated code for descriptor.proto is up to date. --- csharp/src/AddressBook/Addressbook.cs | 7 ++++--- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 343012 -> 343019 bytes .../Google.Protobuf/Reflection/Descriptor.cs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs index 2e88db9a18..484a2296a7 100644 --- a/csharp/src/AddressBook/Addressbook.cs +++ b/csharp/src/AddressBook/Addressbook.cs @@ -32,9 +32,10 @@ namespace Google.Protobuf.Examples.AddressBook { "Eg4KBm51bWJlchgBIAEoCRIoCgR0eXBlGAIgASgOMhoudHV0b3JpYWwuUGVy", "c29uLlBob25lVHlwZSIrCglQaG9uZVR5cGUSCgoGTU9CSUxFEAASCAoESE9N", "RRABEggKBFdPUksQAiIvCgtBZGRyZXNzQm9vaxIgCgZwZW9wbGUYASADKAsy", - "EC50dXRvcmlhbC5QZXJzb25CZgobY29tLmV4YW1wbGUudHV0b3JpYWwucHJv", - "dG9zQhFBZGRyZXNzQm9va1Byb3Rvc1ABWgsuLi90dXRvcmlhbKoCJEdvb2ds", - "ZS5Qcm90b2J1Zi5FeGFtcGxlcy5BZGRyZXNzQm9va2IGcHJvdG8z")); + "EC50dXRvcmlhbC5QZXJzb25ClQEKG2NvbS5leGFtcGxlLnR1dG9yaWFsLnBy", + "b3Rvc0IRQWRkcmVzc0Jvb2tQcm90b3NQAVo6Z2l0aHViLmNvbS9wcm90b2Nv", + "bGJ1ZmZlcnMvcHJvdG9idWYvZXhhbXBsZXMvZ28vdHV0b3JpYWxwYqoCJEdv", + "b2dsZS5Qcm90b2J1Zi5FeGFtcGxlcy5BZGRyZXNzQm9va2IGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index f1f44f1c54670ac40082de74041ae06fd0461a19..20ac953288fc6528fd0222cde29d9e8c64dd659d 100644 GIT binary patch delta 81 zcmaFzUF7w5kqt+Vv0P|n=9+%ClTmT=%VUdV89O)kJmHuu)Wy!l#v;tjz{DWLvV)C9 kN9yPFW#x?5*cI}VlS_+=+iNNqftU%1nYY(euw)zt0B6b{b^rhX delta 73 zcmaF;UF6Akkqt+Vv7BsW=9)g=g;{a)%VUdV8JjluJmHuu)XdJs#v;tjz{DWLvV)C9 cN9xn`W#x?5+M6pFftU%1nYTAruw)zt0A#crPXGV_ diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 5cae6ac9b2..8d398560de 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -10101,7 +10101,7 @@ namespace Google.Protobuf.Reflection { /// location. /// /// Each element is a field number or an index. They form a path from - /// the root FileDescriptorProto to the place where the definition. For + /// the root FileDescriptorProto to the place where the definition occurs. For /// example, this path: /// [ 4, 3, 2, 7, 1 ] /// refers to: From 4d94a7cd935a28f2161fcc43b00545bb16021d42 Mon Sep 17 00:00:00 2001 From: Joel Courtney Date: Wed, 27 Oct 2021 22:20:45 +1100 Subject: [PATCH 030/207] Fixed: incorrect tests --- ruby/lib/google/protobuf/well_known_types.rb | 4 ++-- ruby/tests/well_known_types_test.rb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ruby/lib/google/protobuf/well_known_types.rb b/ruby/lib/google/protobuf/well_known_types.rb index f86fe28b77..2d06ca2742 100755 --- a/ruby/lib/google/protobuf/well_known_types.rb +++ b/ruby/lib/google/protobuf/well_known_types.rb @@ -138,13 +138,13 @@ module Google end def self.from_ruby(value) - Value.new.from_ruby(value) + self.new.from_ruby(value) end def from_ruby(value) case value when NilClass - self.null_value = 0 + self.null_value = :NULL_VALUE when Numeric self.number_value = value when String diff --git a/ruby/tests/well_known_types_test.rb b/ruby/tests/well_known_types_test.rb index 3e94ca01f3..2f345cd017 100755 --- a/ruby/tests/well_known_types_test.rb +++ b/ruby/tests/well_known_types_test.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby require 'test/unit' -require 'google/protobuf/well_known_types' +require 'lib/google/protobuf/well_known_types' class TestWellKnownTypes < Test::Unit::TestCase def test_timestamp @@ -218,7 +218,7 @@ class TestWellKnownTypes < Test::Unit::TestCase def test_from_ruby pb = Google::Protobuf::Value.from_ruby(nil) - assert_equal pb.null_value, 0 + assert_equal pb.null_value, :NULL_VALUE pb = Google::Protobuf::Value.from_ruby(1.23) assert_equal pb.number_value, 1.23 @@ -232,16 +232,16 @@ class TestWellKnownTypes < Test::Unit::TestCase pb = Google::Protobuf::Value.from_ruby(false) assert_equal pb.bool_value, false - pb = Google::Protobuf::Value.from_ruby(Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] })) - assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] }) + pb = Google::Protobuf::Value.from_ruby(Google::Protobuf::Struct.from_hash({ 'a' => 1, 'b' => '2', 'c' => [1, 2, 3], 'd' => nil, 'e' => true })) + assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ 'a' => 1, 'b' => '2', 'c' => [1, 2, 3], 'd' => nil, 'e' => true }) - pb = Google::Protobuf::Value.from_ruby({ a: 1, b: '2', c: [1, 2, 3] }) - assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ a: 1, b: '2', c: [1, 2, 3] }) + pb = Google::Protobuf::Value.from_ruby({ 'a' => 1, 'b' => '2', 'c' => [1, 2, 3], 'd' => nil, 'e' => true }) + assert_equal pb.struct_value, Google::Protobuf::Struct.from_hash({ 'a' => 1, 'b' => '2', 'c' => [1, 2, 3], 'd' => nil, 'e' => true }) pb = Google::Protobuf::Value.from_ruby(Google::Protobuf::ListValue.from_a([1, 2, 3])) - assert_equal pb.struct_value, Google::Protobuf::ListValue.from_a([1, 2, 3]) + assert_equal pb.list_value, Google::Protobuf::ListValue.from_a([1, 2, 3]) pb = Google::Protobuf::Value.from_ruby([1, 2, 3]) - assert_equal pb.struct_value, Google::Protobuf::ListValue.from_a([1, 2, 3]) + assert_equal pb.list_value, Google::Protobuf::ListValue.from_a([1, 2, 3]) end end From 935d099ad9f6692e727406764bb3226d935e899d Mon Sep 17 00:00:00 2001 From: David Mollitor Date: Wed, 27 Oct 2021 11:08:33 -0400 Subject: [PATCH 031/207] Standardize on Array copyOf --- .../java/com/google/protobuf/BooleanArrayList.java | 13 +++---------- .../java/com/google/protobuf/DoubleArrayList.java | 13 +++---------- .../java/com/google/protobuf/FloatArrayList.java | 13 +++---------- .../main/java/com/google/protobuf/IntArrayList.java | 13 +++---------- .../java/com/google/protobuf/LongArrayList.java | 13 +++---------- .../java/com/google/protobuf/ProtobufArrayList.java | 4 +--- 6 files changed, 16 insertions(+), 53 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java index 451fce1e84..35c9240780 100644 --- a/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java @@ -197,10 +197,7 @@ final class BooleanArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - boolean[] newArray = new boolean[length]; - - System.arraycopy(array, 0, newArray, 0, size); - array = newArray; + array = Arrays.copyOf(array, length); } array[size++] = element; @@ -219,14 +216,10 @@ final class BooleanArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - boolean[] newArray = new boolean[length]; - - // Copy the first part directly - System.arraycopy(array, 0, newArray, 0, index); + array = Arrays.copyOf(array, length); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, newArray, index + 1, size - index); - array = newArray; + System.arraycopy(array, index, array, index + 1, size - index); } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java index 4085653437..ec4a416781 100644 --- a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java @@ -197,10 +197,7 @@ final class DoubleArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - double[] newArray = new double[length]; - - System.arraycopy(array, 0, newArray, 0, size); - array = newArray; + array = Arrays.copyOf(array, length); } array[size++] = element; @@ -219,14 +216,10 @@ final class DoubleArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - double[] newArray = new double[length]; - - // Copy the first part directly - System.arraycopy(array, 0, newArray, 0, index); + array = Arrays.copyOf(array, length); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, newArray, index + 1, size - index); - array = newArray; + System.arraycopy(array, index, array, index + 1, size - index); } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/FloatArrayList.java b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java index e6feba8a35..4d42b7c495 100644 --- a/java/core/src/main/java/com/google/protobuf/FloatArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java @@ -196,10 +196,7 @@ final class FloatArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - float[] newArray = new float[length]; - - System.arraycopy(array, 0, newArray, 0, size); - array = newArray; + array = Arrays.copyOf(array, length); } array[size++] = element; @@ -218,14 +215,10 @@ final class FloatArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - float[] newArray = new float[length]; - - // Copy the first part directly - System.arraycopy(array, 0, newArray, 0, index); + array = Arrays.copyOf(array, length); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, newArray, index + 1, size - index); - array = newArray; + System.arraycopy(array, index, array, index + 1, size - index); } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/IntArrayList.java b/java/core/src/main/java/com/google/protobuf/IntArrayList.java index 9daeebed99..5392e0e408 100644 --- a/java/core/src/main/java/com/google/protobuf/IntArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/IntArrayList.java @@ -196,10 +196,7 @@ final class IntArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - int[] newArray = new int[length]; - - System.arraycopy(array, 0, newArray, 0, size); - array = newArray; + array = Arrays.copyOf(array, length); } array[size++] = element; @@ -218,14 +215,10 @@ final class IntArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - int[] newArray = new int[length]; - - // Copy the first part directly - System.arraycopy(array, 0, newArray, 0, index); + array = Arrays.copyOf(array, length); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, newArray, index + 1, size - index); - array = newArray; + System.arraycopy(array, index, array, index + 1, size - index); } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/LongArrayList.java b/java/core/src/main/java/com/google/protobuf/LongArrayList.java index bda43a41bb..c971b5a995 100644 --- a/java/core/src/main/java/com/google/protobuf/LongArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/LongArrayList.java @@ -196,10 +196,7 @@ final class LongArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - long[] newArray = new long[length]; - - System.arraycopy(array, 0, newArray, 0, size); - array = newArray; + array = Arrays.copyOf(array, length); } array[size++] = element; @@ -218,14 +215,10 @@ final class LongArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - long[] newArray = new long[length]; - - // Copy the first part directly - System.arraycopy(array, 0, newArray, 0, index); + array = Arrays.copyOf(array, length); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, newArray, index + 1, size - index); - array = newArray; + System.arraycopy(array, index, array, index + 1, size - index); } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java index 33e4bd5e35..fd82233fcf 100644 --- a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java @@ -80,9 +80,7 @@ final class ProtobufArrayList extends AbstractProtobufList implements Rand if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - E[] newArray = Arrays.copyOf(array, length); - - array = newArray; + array = Arrays.copyOf(array, length); } array[size++] = element; From 1d2e8d93027d988f497a4690eb47ece1fe47d665 Mon Sep 17 00:00:00 2001 From: appledragon Date: Thu, 28 Oct 2021 00:45:42 +0800 Subject: [PATCH 032/207] for old clang build issue, related with https://reviews.llvm.org/D12375 (#9159) This seems wrong: given [[foo]] [[bar]], we'll now parse the second one as an MS attribute in a context where both are allowed. --- src/google/protobuf/parse_context.h | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 62e25dc768..80d5b0195c 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -787,7 +787,7 @@ inline bool VerifyUTF8(const std::string* s, const char* field_name) { } // All the string parsers with or without UTF checking and for all CTypes. -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* InlineGreedyStringParser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* InlineGreedyStringParser( std::string* s, const char* ptr, ParseContext* ctx); @@ -859,19 +859,19 @@ PROTOBUF_NODISCARD const char* WireFormatParser(T& field_parser, // corresponding field // These are packed varints -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedInt32Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedInt32Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedUInt32Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedUInt32Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedInt64Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedInt64Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedUInt64Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedUInt64Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedSInt32Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedSInt32Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedSInt64Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedSInt64Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedEnumParser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedEnumParser( void* object, const char* ptr, ParseContext* ctx); template @@ -905,28 +905,28 @@ PROTOBUF_NODISCARD const char* PackedEnumParserArg( }); } -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedBoolParser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedBoolParser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedFixed32Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedFixed32Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedSFixed32Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedSFixed32Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedFixed64Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedFixed64Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedSFixed64Parser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedSFixed64Parser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedFloatParser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedFloatParser( void* object, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* PackedDoubleParser( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* PackedDoubleParser( void* object, const char* ptr, ParseContext* ctx); // This is the only recursive parser. -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* UnknownGroupLiteParse( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* UnknownGroupLiteParse( std::string* unknown, const char* ptr, ParseContext* ctx); // This is a helper to for the UnknownGroupLiteParse but is actually also // useful in the generated code. It uses overload on std::string* vs // UnknownFieldSet* to make the generated code isomorphic between full and lite. -PROTOBUF_EXPORT PROTOBUF_NODISCARD const char* UnknownFieldParse( +PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* UnknownFieldParse( uint32_t tag, std::string* unknown, const char* ptr, ParseContext* ctx); } // namespace internal From 65852d6e9cdb3d6e1120ef6af044968cbbaff733 Mon Sep 17 00:00:00 2001 From: Chris Bainbridge Date: Wed, 27 Oct 2021 19:28:21 +0100 Subject: [PATCH 033/207] Fix comment syntax in any.proto (#8792) * Fix comment syntax in any.proto Remove extra spaces which cause incorrect indentation in godoc. Remove the "====" style title which is not rendered by godoc. * Run ./generate_descriptor_proto.sh --- csharp/src/Google.Protobuf/WellKnownTypes/Any.cs | 6 +++--- objectivec/GPBAny.pbobjc.h | 6 +++--- php/src/Google/Protobuf/Any.php | 5 ++--- src/google/protobuf/any.proto | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs index 7b5019a8ac..13066da3fe 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs @@ -65,7 +65,7 @@ namespace Google.Protobuf.WellKnownTypes { /// foo = any.unpack(Foo.class); /// } /// - /// Example 3: Pack and unpack a message in Python. + /// Example 3: Pack and unpack a message in Python. /// /// foo = Foo(...) /// any = Any() @@ -75,7 +75,7 @@ namespace Google.Protobuf.WellKnownTypes { /// any.Unpack(foo) /// ... /// - /// Example 4: Pack and unpack a message in Go + /// Example 4: Pack and unpack a message in Go /// /// foo := &pb.Foo{...} /// any, err := anypb.New(foo) @@ -95,7 +95,7 @@ namespace Google.Protobuf.WellKnownTypes { /// name "y.z". /// /// JSON - /// ==== + /// /// The JSON representation of an `Any` value uses the regular /// representation of the deserialized, embedded message, with an /// additional field `@type` which contains the type URL. Example: diff --git a/objectivec/GPBAny.pbobjc.h b/objectivec/GPBAny.pbobjc.h index 21b7dcf4af..5ed3f2ee68 100644 --- a/objectivec/GPBAny.pbobjc.h +++ b/objectivec/GPBAny.pbobjc.h @@ -81,7 +81,7 @@ typedef GPB_ENUM(GPBAny_FieldNumber) { * foo = any.unpack(Foo.class); * } * - * Example 3: Pack and unpack a message in Python. + * Example 3: Pack and unpack a message in Python. * * foo = Foo(...) * any = Any() @@ -91,7 +91,7 @@ typedef GPB_ENUM(GPBAny_FieldNumber) { * any.Unpack(foo) * ... * - * Example 4: Pack and unpack a message in Go + * Example 4: Pack and unpack a message in Go * * foo := &pb.Foo{...} * any, err := anypb.New(foo) @@ -112,7 +112,7 @@ typedef GPB_ENUM(GPBAny_FieldNumber) { * * * JSON - * ==== + * * The JSON representation of an `Any` value uses the regular * representation of the deserialized, embedded message, with an * additional field `\@type` which contains the type URL. Example: diff --git a/php/src/Google/Protobuf/Any.php b/php/src/Google/Protobuf/Any.php index 8fdc3c483d..cc64bad3db 100644 --- a/php/src/Google/Protobuf/Any.php +++ b/php/src/Google/Protobuf/Any.php @@ -28,7 +28,7 @@ use Google\Protobuf\Internal\GPBUtil; * if (any.is(Foo.class)) { * foo = any.unpack(Foo.class); * } - * Example 3: Pack and unpack a message in Python. + * Example 3: Pack and unpack a message in Python. * foo = Foo(...) * any = Any() * any.Pack(foo) @@ -36,7 +36,7 @@ use Google\Protobuf\Internal\GPBUtil; * if any.Is(Foo.DESCRIPTOR): * any.Unpack(foo) * ... - * Example 4: Pack and unpack a message in Go + * Example 4: Pack and unpack a message in Go * foo := &pb.Foo{...} * any, err := anypb.New(foo) * if err != nil { @@ -53,7 +53,6 @@ use Google\Protobuf\Internal\GPBUtil; * in the type URL, for example "foo.bar.com/x/y.z" will yield type * name "y.z". * JSON - * ==== * The JSON representation of an `Any` value uses the regular * representation of the deserialized, embedded message, with an * additional field `@type` which contains the type URL. Example: diff --git a/src/google/protobuf/any.proto b/src/google/protobuf/any.proto index 6ed8a23cf5..e2c2042fdc 100644 --- a/src/google/protobuf/any.proto +++ b/src/google/protobuf/any.proto @@ -64,7 +64,7 @@ option objc_class_prefix = "GPB"; // foo = any.unpack(Foo.class); // } // -// Example 3: Pack and unpack a message in Python. +// Example 3: Pack and unpack a message in Python. // // foo = Foo(...) // any = Any() @@ -74,7 +74,7 @@ option objc_class_prefix = "GPB"; // any.Unpack(foo) // ... // -// Example 4: Pack and unpack a message in Go +// Example 4: Pack and unpack a message in Go // // foo := &pb.Foo{...} // any, err := anypb.New(foo) @@ -95,7 +95,7 @@ option objc_class_prefix = "GPB"; // // // JSON -// ==== +// // The JSON representation of an `Any` value uses the regular // representation of the deserialized, embedded message, with an // additional field `@type` which contains the type URL. Example: From bbdcea8547e43b2cf2a1851fec6c50c272dcc212 Mon Sep 17 00:00:00 2001 From: Joel Courtney Date: Thu, 28 Oct 2021 07:09:11 +1100 Subject: [PATCH 034/207] Remove lib from require --- ruby/tests/well_known_types_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/tests/well_known_types_test.rb b/ruby/tests/well_known_types_test.rb index 2f345cd017..fbdee38a29 100755 --- a/ruby/tests/well_known_types_test.rb +++ b/ruby/tests/well_known_types_test.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby require 'test/unit' -require 'lib/google/protobuf/well_known_types' +require 'google/protobuf/well_known_types' class TestWellKnownTypes < Test::Unit::TestCase def test_timestamp From c7dfd0d6b92f825a4b9e986b3e948a5ab61c7438 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 28 Oct 2021 10:34:54 -0700 Subject: [PATCH 035/207] Align dependency handling with Bazel best practices (#9165) This commit removes the use of bind() since that function goes against Bazel best practices: https://docs.bazel.build/versions/main/external.html#repository-rules-1 The bind() function basically maps a dependency into //external, but there is no good reason to do this. By mapping dependencies into //external and relying on this in our own BUILD files, we're forcing projects that depend on us to do the same. The one bind() call that I did leave in place was //:python_headers. This one seems to be doing something complicated I don't fully understand, and I don't want to risk breaking it. This change also moves our list of required Maven artifacts into a constant in protobuf_deps.bzl. This way, projects that depend on us can refer to this list when they invoke maven_install() and automatically pull in all the necesary dependencies. This fixes #9132. --- WORKSPACE | 63 +++++------------------------------- java/core/BUILD | 81 +++++++++++++++++++++++++---------------------- java/lite/BUILD | 21 ++++++++---- java/util/BUILD | 29 +++++++++-------- protobuf_deps.bzl | 13 +++++++- 5 files changed, 92 insertions(+), 115 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index c88d242db2..e500967fe4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,7 +27,7 @@ http_archive( ) # Load common dependencies. -load("//:protobuf_deps.bzl", "protobuf_deps") +load("//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps") protobuf_deps() bind( @@ -36,70 +36,23 @@ bind( ) load("@rules_jvm_external//:defs.bzl", "maven_install") -maven_install( - artifacts = [ - "com.google.code.findbugs:jsr305:3.0.2", - "com.google.code.gson:gson:2.8.6", - "com.google.errorprone:error_prone_annotations:2.3.2", - "com.google.j2objc:j2objc-annotations:1.3", - "com.google.guava:guava:30.1.1-jre", - "com.google.truth:truth:1.1.2", - "junit:junit:4.12", - "org.easymock:easymock:3.2", - ], +maven_install( + artifacts = PROTOBUF_MAVEN_ARTIFACTS, + # For updating instructions, see: + # https://github.com/bazelbuild/rules_jvm_external#updating-maven_installjson + maven_install_json = "//:maven_install.json", repositories = [ "https://repo1.maven.org/maven2", "https://repo.maven.apache.org/maven2", ], - # For updating instructions, see: - # https://github.com/bazelbuild/rules_jvm_external#updating-maven_installjson - maven_install_json = "//:maven_install.json", ) load("@maven//:defs.bzl", "pinned_maven_install") -pinned_maven_install() - -bind( - name = "guava", - actual = "@maven//:com_google_guava_guava", -) - -bind( - name = "gson", - actual = "@maven//:com_google_code_gson_gson", -) - -bind( - name = "error_prone_annotations", - actual = "@maven//:com_google_errorprone_error_prone_annotations", -) -bind( - name = "j2objc_annotations", - actual = "@maven//:com_google_j2objc_j2objc_annotations", -) - -bind( - name = "jsr305", - actual = "@maven//:com_google_code_findbugs_jsr305", -) - -bind( - name = "junit", - actual = "@maven//:junit_junit", -) - -bind( - name = "easymock", - actual = "@maven//:org_easymock_easymock", -) - -bind( - name = "truth", - actual = "@maven//:com_google_truth_truth", -) +pinned_maven_install() # For `cc_proto_blacklist_test` and `build_test`. load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + bazel_skylib_workspace() diff --git a/java/core/BUILD b/java/core/BUILD index c65f10a4e1..1a37b4e820 100644 --- a/java/core/BUILD +++ b/java/core/BUILD @@ -1,5 +1,5 @@ load("@bazel_skylib//rules:build_test.bzl", "build_test") -load("@rules_java//java:defs.bzl", "java_library", "java_proto_library", "java_lite_proto_library") +load("@rules_java//java:defs.bzl", "java_library", "java_lite_proto_library", "java_proto_library") load("@rules_jvm_external//:defs.bzl", "java_export") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") load("//:internal.bzl", "conformance_test") @@ -103,7 +103,7 @@ LITE_SRCS = [ java_library( name = "lite", srcs = LITE_SRCS + [ - "//:gen_well_known_protos_javalite" + "//:gen_well_known_protos_javalite", ], visibility = [ "//java/lite:__pkg__", @@ -115,10 +115,10 @@ java_export( name = "lite_mvn", maven_coordinates = "com.google.protobuf:protobuf-javalite:%s" % PROTOBUF_VERSION, pom_template = "//java/lite:pom_template.xml", - runtime_deps = [":lite"], resources = [ "//:lite_well_known_protos", ], + runtime_deps = [":lite"], ) java_library( @@ -150,25 +150,25 @@ java_export( name = "core_mvn", maven_coordinates = "com.google.protobuf:protobuf-java:%s" % PROTOBUF_VERSION, pom_template = "pom_template.xml", - runtime_deps = [":core"], resources = [ "//:well_known_protos", ], + runtime_deps = [":core"], ) filegroup( name = "release", - visibility = ["//java:__pkg__"], srcs = [ - ":core_mvn-pom", - ":core_mvn-maven-source", ":core_mvn-docs", + ":core_mvn-maven-source", + ":core_mvn-pom", ":core_mvn-project", - ":lite_mvn-pom", - ":lite_mvn-maven-source", ":lite_mvn-docs", + ":lite_mvn-maven-source", + ":lite_mvn-pom", ":lite_mvn-project", - ] + ], + visibility = ["//java:__pkg__"], ) proto_lang_toolchain( @@ -207,22 +207,22 @@ java_library( name = "test_util", srcs = [ "src/test/java/com/google/protobuf/TestUtil.java", - "src/test/java/com/google/protobuf/TestUtilLite.java" + "src/test/java/com/google/protobuf/TestUtilLite.java", ], deps = [ ":core", ":generic_test_protos_java_proto", ":java_test_protos_java_proto", - "//external:guava", - "//external:junit", + "@maven//:com_google_guava_guava", + "@maven//:junit_junit", ], ) test_suite( name = "tests", tests = [ - "core_build_test", "conformance_test", + "core_build_test", "core_tests", ], ) @@ -236,29 +236,32 @@ build_test( conformance_test( name = "conformance_test", - testee = "//:conformance_java", failure_list = "//:conformance/failure_list_java.txt", + testee = "//:conformance_java", text_format_failure_list = "//:conformance/text_format_failure_list_java.txt", ) junit_tests( name = "core_tests", - srcs = glob(["src/test/java/**/*.java"], exclude = [ - "src/test/java/com/google/protobuf/TestUtil.java", - "src/test/java/com/google/protobuf/TestUtilLite.java", - ]), - data = ["//:testdata"], size = "large", + srcs = glob( + ["src/test/java/**/*.java"], + exclude = [ + "src/test/java/com/google/protobuf/TestUtil.java", + "src/test/java/com/google/protobuf/TestUtilLite.java", + ], + ), + data = ["//:testdata"], deps = [ ":core", ":generic_test_protos_java_proto", ":java_test_protos_java_proto", ":test_util", - "//external:easymock", - "//external:guava", - "//external:junit", - "//external:truth", - ] + "@maven//:com_google_guava_guava", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + "@maven//:org_easymock_easymock", + ], ) java_lite_proto_library( @@ -281,17 +284,17 @@ genrule( name = "rewrite_javalite_test_util", srcs = [ "//java/lite:lite.awk", - "src/test/java/com/google/protobuf/TestUtil.java" + "src/test/java/com/google/protobuf/TestUtil.java", ], outs = ["TestUtil.java"], - cmd = "awk -f $(location //java/lite:lite.awk) $(location src/test/java/com/google/protobuf/TestUtil.java) > $@" + cmd = "awk -f $(location //java/lite:lite.awk) $(location src/test/java/com/google/protobuf/TestUtil.java) > $@", ) java_library( name = "test_util_lite", srcs = [ + "src/test/java/com/google/protobuf/TestUtilLite.java", ":rewrite_javalite_test_util", - "src/test/java/com/google/protobuf/TestUtilLite.java" ], visibility = [ "//java/lite:__pkg__", @@ -300,8 +303,8 @@ java_library( ":generic_test_protos_java_proto_lite", ":java_test_protos_java_proto_lite", ":lite_runtime_only", - "//external:guava", - "//external:junit", + "@maven//:com_google_guava_guava", + "@maven//:junit_junit", ], ) @@ -350,18 +353,20 @@ LITE_TEST_EXCLUSIONS = [ junit_tests( name = "lite_tests", - srcs = glob(["src/test/java/**/*.java"], exclude = LITE_TEST_EXCLUSIONS), + size = "large", + srcs = glob( + ["src/test/java/**/*.java"], + exclude = LITE_TEST_EXCLUSIONS, + ), data = ["//:testdata"], test_prefix = "Lite", - size = "large", deps = [ - ":lite", ":generic_test_protos_java_proto_lite", ":java_test_protos_java_proto_lite", + ":lite", ":test_util_lite", - "//external:easymock", - "//external:junit", - "//external:truth", - ] + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + "@maven//:org_easymock_easymock", + ], ) - diff --git a/java/lite/BUILD b/java/lite/BUILD index 7089f958b0..17e9667e6a 100644 --- a/java/lite/BUILD +++ b/java/lite/BUILD @@ -3,8 +3,15 @@ load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") load("//:internal.bzl", "conformance_test") load("//java/internal:testing.bzl", "junit_tests") -exports_files(["lite.awk"], visibility = ["//java/core:__pkg__"]) -exports_files(["pom_template.xml"], visibility = ["//java/core:__pkg__"]) +exports_files( + ["lite.awk"], + visibility = ["//java/core:__pkg__"], +) + +exports_files( + ["pom_template.xml"], + visibility = ["//java/core:__pkg__"], +) alias( name = "lite", @@ -22,8 +29,8 @@ proto_lang_toolchain( test_suite( name = "tests", tests = [ - "lite_build_test", "conformance_test", + "lite_build_test", "lite_tests", "//java/core:lite_tests", ], @@ -38,21 +45,21 @@ build_test( conformance_test( name = "conformance_test", - testee = "//:conformance_java_lite", failure_list = "//:conformance/failure_list_java_lite.txt", + testee = "//:conformance_java_lite", text_format_failure_list = "//:conformance/text_format_failure_list_java_lite.txt", ) junit_tests( name = "lite_tests", - srcs = glob(["src/test/**/*.java"]), size = "small", + srcs = glob(["src/test/**/*.java"]), deps = [ ":lite", - "//external:junit", - "//external:truth", "//java/core:generic_test_protos_java_proto_lite", "//java/core:java_test_protos_java_proto_lite", "//java/core:test_util_lite", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", ], ) diff --git a/java/util/BUILD b/java/util/BUILD index 3855da96f0..ee6ddeaf19 100644 --- a/java/util/BUILD +++ b/java/util/BUILD @@ -11,33 +11,34 @@ java_library( ]), visibility = ["//visibility:public"], deps = [ - "//external:error_prone_annotations", - "//external:j2objc_annotations", - "//external:gson", - "//external:jsr305", - "//external:guava", "//java/core", "//java/lite", + "@maven//:com_google_code_findbugs_jsr305", + "@maven//:com_google_code_gson_gson", + "@maven//:com_google_errorprone_error_prone_annotations", + "@maven//:com_google_guava_guava", + "@maven//:com_google_j2objc_j2objc_annotations", ], ) + # Bazel users, don't depend on this target, use :util. java_export( name = "util_mvn", maven_coordinates = "com.google.protobuf:protobuf-java-util:%s" % PROTOBUF_VERSION, pom_template = "pom_template.xml", - runtime_deps = [":util"], visibility = ["//java:__pkg__"], + runtime_deps = [":util"], ) filegroup( name = "release", - visibility = ["//java:__pkg__"], srcs = [ - ":util_mvn-pom", - ":util_mvn-maven-source", ":util_mvn-docs", + ":util_mvn-maven-source", + ":util_mvn-pom", ":util_mvn-project", - ] + ], + visibility = ["//java:__pkg__"], ) proto_library( @@ -60,15 +61,15 @@ java_proto_library( junit_tests( name = "tests", - srcs = glob(["src/test/java/**/*.java"]), package_name = "com.google.protobuf.util", + srcs = glob(["src/test/java/**/*.java"]), deps = [ ":test_protos_java_proto", ":util", - "//external:guava", - "//external:junit", - "//external:truth", "//java/core", "//java/core:generic_test_protos_java_proto", + "@maven//:com_google_guava_guava", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", ], ) diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 7420bc1fd7..32f38ebb6e 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -2,6 +2,17 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +PROTOBUF_MAVEN_ARTIFACTS = [ + "com.google.code.findbugs:jsr305:3.0.2", + "com.google.code.gson:gson:2.8.6", + "com.google.errorprone:error_prone_annotations:2.3.2", + "com.google.j2objc:j2objc-annotations:1.3", + "com.google.guava:guava:30.1.1-jre", + "com.google.truth:truth:1.1.2", + "junit:junit:4.12", + "org.easymock:easymock:3.2", +] + def protobuf_deps(): """Loads common dependencies needed to compile the protobuf library.""" @@ -56,7 +67,7 @@ def protobuf_deps(): ) if not native.existing_rule("rules_jvm_external"): - http_archive( + http_archive( name = "rules_jvm_external", sha256 = "f36441aa876c4f6427bfb2d1f2d723b48e9d930b62662bf723ddfb8fc80f0140", strip_prefix = "rules_jvm_external-4.1", From e58469bdbedf514988efa86af9e8e7b5b1fa272f Mon Sep 17 00:00:00 2001 From: Marnix Bouhuis Date: Tue, 26 Oct 2021 18:48:47 +0200 Subject: [PATCH 036/207] JS: Fixed `ReferenceError: window is not defined` when getting the global object (#9156) --- src/google/protobuf/compiler/js/js_generator.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 5542256f38..d2dac2f606 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -3634,7 +3634,14 @@ void Generator::GenerateFile(const GeneratorOptions& options, // - self: defined inside Web Workers (WorkerGlobalScope) // - Function('return this')(): this will work on most platforms, but it may be blocked by things like CSP. // Function('') is almost the same as eval('') - printer->Print("var global = (function() { return this || window || global || self || Function('return this')(); }).call(null);\n\n"); + printer->Print( + "var global = (function() {\n" + " if (this) { return this; }\n" + " if (typeof window !== 'undefined') { return window; }\n" + " if (typeof global !== 'undefined') { return global; }\n" + " if (typeof self !== 'undefined') { return self; }\n" + " return Function('return this')();\n" + "}.call(null));\n\n"); } for (int i = 0; i < file->dependency_count(); i++) { From b2ac7ced50ed160985ba79bbbdea8bad8f28b039 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 25 Oct 2021 15:41:19 -0400 Subject: [PATCH 037/207] Fix memory leak in MessageClass.encode If the line above raises an exception, the upb_arena is lost and memory is leaked. --- ruby/ext/google/protobuf_c/message.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 59602cf089..d07eba760d 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -1012,7 +1012,6 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { */ static VALUE Message_encode(VALUE klass, VALUE msg_rb) { Message* msg = ruby_to_Message(msg_rb); - upb_arena *arena = upb_arena_new(); const char *data; size_t size; @@ -1020,6 +1019,8 @@ static VALUE Message_encode(VALUE klass, VALUE msg_rb) { rb_raise(rb_eArgError, "Message of wrong type."); } + upb_arena *arena = upb_arena_new(); + data = upb_encode(msg->msg, upb_msgdef_layout(msg->msgdef), arena, &size); From 1c8ae2459567388085f5da4b5ef2af7863a003fb Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 28 Oct 2021 18:02:41 +0000 Subject: [PATCH 038/207] Update changelog for 3.19.1 I also updated CHANGES.txt to include a couple things I forgot to add for 3.19.0. --- CHANGES.txt | 14 ++++++++++++++ php/ext/google/protobuf/package.xml | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index db6194529d..926eff72da 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,15 @@ +2021-10-28 version 3.19.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Bazel + * Ensure that release archives contain everything needed for Bazel (#9131) + * Align dependency handling with Bazel best practices (#9165) + + JavaScript + * Fix `ReferenceError: window is not defined` when getting the global object (#9156) + + Ruby + * Fix memory leak in MessageClass.encode (#9150) + 2021-10-15 version 3.19.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) C++ @@ -17,6 +29,7 @@ Kotlin * Switch Kotlin proto DSLs to be implemented with inline value classes + * Fix inlining and deprecation for repeated string fields in kotlin (#9120) Python * Proto2 DecodeError now includes message name in error message @@ -37,6 +50,7 @@ * Add class method Timestamp.from_time to ruby well known types (#8562) * Adopt pure ruby DSL implementation for JRuby (#9047) * Add size to Map class (#8068) + * Fix for descriptor_pb.rb: google/protobuf should be required first (#9121) C# * Correctly set ExtensionRegistry when parsing with MessageParser, but using an already existing CodedInputStream (#7246) diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 76d601f8df..db45943ba1 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -22,7 +22,7 @@ 3-Clause BSD License - * Added "object" as a reserved name (#8962) + * No new changes in 3.19.1

From 7c40b2df1fdf6f414c1c18c789715a9c948a0725 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 28 Oct 2021 14:07:53 -0700 Subject: [PATCH 039/207] Update protobuf version (#9167) --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 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/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 25 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 +-- src/Makefile.am | 2 +- 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/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 +- 37 files changed, 59 insertions(+), 44 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index 01c890de4a..c6f5511cdb 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.19.0' + s.version = '3.19.1' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index b1a959478c..ee63ffcb07 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.19.0' + s.version = '3.19.1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index d076062f22..fb5f9d09f3 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.19.0],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.19.1],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 93b8ab40c4..b2d1417b6c 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.19.0 + 3.19.1 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 4b3a9bb7e1..ad6f57999b 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.19.0 + 3.19.1 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 1cfff6afd0..456ba1c976 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.19.0 + 3.19.1 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.19.0 + 3.19.1 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.19.0' + implementation 'com.google.protobuf:protobuf-java:3.19.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 d0a93a35ce..348ea57fcc 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.19.0 + 3.19.1 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 4c75eb40cd..9c020f98dc 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0 + 3.19.1 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 47e2ab4af5..23dfc77cc3 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0 + 3.19.1 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index d5b4d2e0d9..0455d114ed 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0 + 3.19.1 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index 9929f19ae2..8f3ef1e49b 100644 --- a/java/lite.md +++ b/java/lite.md @@ -30,7 +30,7 @@ protobuf Java runtime. If you are using Maven, use the following: com.google.protobuf protobuf-javalite - 3.19.0 + 3.19.1 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index a473948b9f..cfd5707f9b 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0 + 3.19.1 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 6642131f66..127fa6287f 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0 + 3.19.1 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 63b53f3df1..c9ada55804 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.0 + 3.19.1 protobuf-java-util diff --git a/js/package.json b/js/package.json index 43ae2d70b7..edccba6097 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.19.0", + "version": "3.19.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index db45943ba1..12c899ef85 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -1,5 +1,5 @@ - + protobuf pecl.php.net Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2021-10-19 - + 2021-10-28 + - 3.19.0 - 3.19.0 + 3.19.1 + 3.19.1 stable @@ -1143,5 +1143,20 @@ G A release. + + + 3.19.1 + 3.19.1 + + + stable + stable + + 2021-10-28 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index d5eb4faaa2..7cbad84861 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -91,7 +91,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.19.0" +#define PHP_PROTOBUF_VERSION "3.19.1" // 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 bf0d52b18a..31ce2e3bac 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1 @@ -PROTOBUF_VERSION = '3.19.0' +PROTOBUF_VERSION = '3.19.1' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 9f44f5f43f..7e5eca83ed 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.19.0 + 3.19.1 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 68087e5501..52101b6fe4 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.19.0' +__version__ = '3.19.1' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index c034f3743b..7e2dd14aae 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.19.0" + s.version = "3.19.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 a38d395b73..f4c8f66d1e 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.19.0 + 3.19.1 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.19.0 + 3.19.1 org.jruby diff --git a/src/Makefile.am b/src/Makefile.am index f78c46c579..2d6034a0de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 30:0:0 +PROTOBUF_VERSION = 30:1:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index e90d198cbc..ab07cc70d2 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 a2fa75a931..26e1946f85 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 f3e28605bb..569bb30a69 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 4bc09d8e28..66d7e264d6 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 8cd8cd1fe2..6440e9d331 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 509443c96b..ba97255ed0 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 d2cd9d6a37..4114740bbe 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 003f75ac7d..71325c3872 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -153,7 +153,7 @@ #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 3019000 +#define PROTOBUF_VERSION 3019001 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index a703bb5316..5f91f3eb8d 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 570303e2e7..6e54bee65b 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 d9524d2b5f..c32503a6de 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -82,7 +82,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 3019000 +#define GOOGLE_PROTOBUF_VERSION 3019001 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 54604acf0d..95036fdea6 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 ae8c144449..b91ab7ce58 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 83d258b031..42ffda2eeb 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019000 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019001 < 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 26603a14666c0f30883bc4508591522586ba51f8 Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Sat, 30 Oct 2021 20:56:40 +0200 Subject: [PATCH 040/207] Remove unittest2 imports (#9171) They were only needed for python versions <= 2.6 Related: #6658 --- python/google/protobuf/internal/_parameterized.py | 5 +---- python/google/protobuf/internal/generator_test.py | 5 +---- python/google/protobuf/internal/proto_builder_test.py | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/python/google/protobuf/internal/_parameterized.py b/python/google/protobuf/internal/_parameterized.py index 2229671ed6..deafab324e 100755 --- a/python/google/protobuf/internal/_parameterized.py +++ b/python/google/protobuf/internal/_parameterized.py @@ -148,10 +148,7 @@ __author__ = 'tmarek@google.com (Torsten Marek)' import functools import re import types -try: - import unittest2 as unittest -except ImportError: - import unittest +import unittest import uuid try: diff --git a/python/google/protobuf/internal/generator_test.py b/python/google/protobuf/internal/generator_test.py index 0c4299a3d1..9883fce31e 100644 --- a/python/google/protobuf/internal/generator_test.py +++ b/python/google/protobuf/internal/generator_test.py @@ -39,10 +39,7 @@ further ensures that we can use Python protocol message objects as we expect. __author__ = 'robinson@google.com (Will Robinson)' -try: - import unittest2 as unittest #PY26 -except ImportError: - import unittest +import unittest from google.protobuf.internal import test_bad_identifiers_pb2 from google.protobuf import unittest_custom_options_pb2 diff --git a/python/google/protobuf/internal/proto_builder_test.py b/python/google/protobuf/internal/proto_builder_test.py index 8e2afaf98c..48077b0a4b 100644 --- a/python/google/protobuf/internal/proto_builder_test.py +++ b/python/google/protobuf/internal/proto_builder_test.py @@ -31,10 +31,7 @@ """Tests for google.protobuf.proto_builder.""" import collections -try: - import unittest2 as unittest -except ImportError: - import unittest +import unittest from google.protobuf import descriptor_pb2 # pylint: disable=g-import-not-at-top from google.protobuf import descriptor From 6a9cf18cbadd7f4dde659c89fa02f7459e0c7a1c Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 1 Nov 2021 09:00:31 -0700 Subject: [PATCH 041/207] Fix benchmark by making sure we use Python 3 (#9170) The benchmark runs have been failing since we started requiring Python 3, so this changes fixes the benchmarks by ensuring we always use Python 3. --- benchmarks/Makefile.am | 8 +++---- .../python/python_benchmark_messages.cc | 23 +++++++++++-------- benchmarks/util/result_parser.py | 12 +++++----- kokoro/linux/benchmark/run.sh | 8 ++++--- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/benchmarks/Makefile.am b/benchmarks/Makefile.am index 2b2204d082..3ab35e37ca 100644 --- a/benchmarks/Makefile.am +++ b/benchmarks/Makefile.am @@ -165,7 +165,7 @@ python_add_init: protoc_middleman protoc_middleman2 done \ done -python_cpp_pkg_flags = `pkg-config --cflags --libs python` +python_cpp_pkg_flags = `pkg-config --cflags --libs python3` lib_LTLIBRARIES = libbenchmark_messages.la libbenchmark_messages_la_SOURCES = python/python_benchmark_messages.cc @@ -186,7 +186,7 @@ python-pure-python-benchmark: python_add_init @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-pure-python-benchmark @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'python\' >> python-pure-python-benchmark @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-pure-python-benchmark - @echo python tmp/py_benchmark.py '$$@' >> python-pure-python-benchmark + @echo python3 tmp/py_benchmark.py '$$@' >> python-pure-python-benchmark @chmod +x python-pure-python-benchmark python-cpp-reflection-benchmark: python_add_init @@ -196,7 +196,7 @@ python-cpp-reflection-benchmark: python_add_init @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-cpp-reflection-benchmark @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'cpp\' >> python-cpp-reflection-benchmark @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-cpp-reflection-benchmark - @echo python tmp/py_benchmark.py '$$@' >> python-cpp-reflection-benchmark + @echo python3 tmp/py_benchmark.py '$$@' >> python-cpp-reflection-benchmark @chmod +x python-cpp-reflection-benchmark python-cpp-generated-code-benchmark: python_add_init libbenchmark_messages.la @@ -206,7 +206,7 @@ python-cpp-generated-code-benchmark: python_add_init libbenchmark_messages.la @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-cpp-generated-code-benchmark @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'cpp\' >> python-cpp-generated-code-benchmark @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-cpp-generated-code-benchmark - @echo python tmp/py_benchmark.py --cpp_generated '$$@' >> python-cpp-generated-code-benchmark + @echo python3 tmp/py_benchmark.py --cpp_generated '$$@' >> python-cpp-generated-code-benchmark @chmod +x python-cpp-generated-code-benchmark python-pure-python: python-pure-python-benchmark diff --git a/benchmarks/python/python_benchmark_messages.cc b/benchmarks/python/python_benchmark_messages.cc index ded16fe96e..ef7e8a2e95 100644 --- a/benchmarks/python/python_benchmark_messages.cc +++ b/benchmarks/python/python_benchmark_messages.cc @@ -7,13 +7,19 @@ #include "datasets/google_message3/benchmark_message3.pb.h" #include "datasets/google_message4/benchmark_message4.pb.h" -static PyMethodDef python_benchmark_methods[] = { - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - +static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT, + "libbenchmark_messages", + "Benchmark messages Python module", + -1, + NULL, + NULL, + NULL, + NULL, + NULL}; +extern "C" { PyMODINIT_FUNC -initlibbenchmark_messages() { +PyInit_libbenchmark_messages() { benchmarks::BenchmarkDataset().descriptor(); benchmarks::proto3::GoogleMessage1().descriptor(); benchmarks::proto2::GoogleMessage1().descriptor(); @@ -21,9 +27,6 @@ initlibbenchmark_messages() { benchmarks::google_message3::GoogleMessage3().descriptor(); benchmarks::google_message4::GoogleMessage4().descriptor(); - PyObject *m; - - m = Py_InitModule("libbenchmark_messages", python_benchmark_methods); - if (m == NULL) - return; + return PyModule_Create(&_module); +} } diff --git a/benchmarks/util/result_parser.py b/benchmarks/util/result_parser.py index bdf3a9980a..d3251a8b26 100644 --- a/benchmarks/util/result_parser.py +++ b/benchmarks/util/result_parser.py @@ -61,7 +61,7 @@ def __parse_cpp_result(filename): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results = json.loads(f.read()) for benchmark in results["benchmarks"]: data_filename = "".join( @@ -96,7 +96,7 @@ def __parse_synthetic_result(filename): return if filename[0] != "/": filename = os.path.dirname(os.path.abspath(__file__)) + "/" + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results = json.loads(f.read()) for benchmark in results["benchmarks"]: __results.append({ @@ -126,7 +126,7 @@ def __parse_python_result(filename): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results_list = json.loads(f.read()) for results in results_list: for result in results: @@ -176,7 +176,7 @@ def __parse_java_result(filename): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results = json.loads(f.read()) for result in results: total_weight = 0 @@ -212,7 +212,7 @@ def __parse_go_result(filename): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: for line in f: result_list = re.split(r"[\ \t]+", line) if result_list[0][:9] != "Benchmark": @@ -252,7 +252,7 @@ def __parse_custom_result(filename, language): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results = json.loads(f.read()) for result in results: _, avg_size = __get_data_size(result["filename"]) diff --git a/kokoro/linux/benchmark/run.sh b/kokoro/linux/benchmark/run.sh index 502f436536..acd8737077 100755 --- a/kokoro/linux/benchmark/run.sh +++ b/kokoro/linux/benchmark/run.sh @@ -23,8 +23,10 @@ popd ./configure CXXFLAGS="-fPIC -O2" make -j8 pushd python -python setup.py build --cpp_implementation -pip install . --user +virtualenv -p python3 env +source env/bin/activate +python3 setup.py build --cpp_implementation +pip3 install --install-option="--cpp_implementation" . popd # build and run Python benchmark @@ -91,7 +93,7 @@ cat tmp/python_result.json # print the postprocessed results to the build job log # TODO(jtattermusch): re-enable uploading results to bigquery (it is currently broken) make python_add_init -env LD_LIBRARY_PATH="${repo_root}/src/.libs" python -m util.result_parser \ +env LD_LIBRARY_PATH="${repo_root}/src/.libs" python3 -m util.result_parser \ -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -python="../tmp/python_result.json" popd From 31dd7b71cc5ff697e7cc37156b083a1eb5fd4d9b Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 1 Nov 2021 11:44:58 -0700 Subject: [PATCH 042/207] Fix benchmark by making sure we use Python 3 (#9170) (#9176) The benchmark runs have been failing since we started requiring Python 3, so this changes fixes the benchmarks by ensuring we always use Python 3. --- benchmarks/Makefile.am | 8 +++---- .../python/python_benchmark_messages.cc | 23 +++++++++++-------- benchmarks/util/result_parser.py | 12 +++++----- kokoro/linux/benchmark/run.sh | 8 ++++--- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/benchmarks/Makefile.am b/benchmarks/Makefile.am index 2b2204d082..3ab35e37ca 100644 --- a/benchmarks/Makefile.am +++ b/benchmarks/Makefile.am @@ -165,7 +165,7 @@ python_add_init: protoc_middleman protoc_middleman2 done \ done -python_cpp_pkg_flags = `pkg-config --cflags --libs python` +python_cpp_pkg_flags = `pkg-config --cflags --libs python3` lib_LTLIBRARIES = libbenchmark_messages.la libbenchmark_messages_la_SOURCES = python/python_benchmark_messages.cc @@ -186,7 +186,7 @@ python-pure-python-benchmark: python_add_init @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-pure-python-benchmark @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'python\' >> python-pure-python-benchmark @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-pure-python-benchmark - @echo python tmp/py_benchmark.py '$$@' >> python-pure-python-benchmark + @echo python3 tmp/py_benchmark.py '$$@' >> python-pure-python-benchmark @chmod +x python-pure-python-benchmark python-cpp-reflection-benchmark: python_add_init @@ -196,7 +196,7 @@ python-cpp-reflection-benchmark: python_add_init @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-cpp-reflection-benchmark @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'cpp\' >> python-cpp-reflection-benchmark @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-cpp-reflection-benchmark - @echo python tmp/py_benchmark.py '$$@' >> python-cpp-reflection-benchmark + @echo python3 tmp/py_benchmark.py '$$@' >> python-cpp-reflection-benchmark @chmod +x python-cpp-reflection-benchmark python-cpp-generated-code-benchmark: python_add_init libbenchmark_messages.la @@ -206,7 +206,7 @@ python-cpp-generated-code-benchmark: python_add_init libbenchmark_messages.la @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-cpp-generated-code-benchmark @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'cpp\' >> python-cpp-generated-code-benchmark @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-cpp-generated-code-benchmark - @echo python tmp/py_benchmark.py --cpp_generated '$$@' >> python-cpp-generated-code-benchmark + @echo python3 tmp/py_benchmark.py --cpp_generated '$$@' >> python-cpp-generated-code-benchmark @chmod +x python-cpp-generated-code-benchmark python-pure-python: python-pure-python-benchmark diff --git a/benchmarks/python/python_benchmark_messages.cc b/benchmarks/python/python_benchmark_messages.cc index ded16fe96e..ef7e8a2e95 100644 --- a/benchmarks/python/python_benchmark_messages.cc +++ b/benchmarks/python/python_benchmark_messages.cc @@ -7,13 +7,19 @@ #include "datasets/google_message3/benchmark_message3.pb.h" #include "datasets/google_message4/benchmark_message4.pb.h" -static PyMethodDef python_benchmark_methods[] = { - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - +static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT, + "libbenchmark_messages", + "Benchmark messages Python module", + -1, + NULL, + NULL, + NULL, + NULL, + NULL}; +extern "C" { PyMODINIT_FUNC -initlibbenchmark_messages() { +PyInit_libbenchmark_messages() { benchmarks::BenchmarkDataset().descriptor(); benchmarks::proto3::GoogleMessage1().descriptor(); benchmarks::proto2::GoogleMessage1().descriptor(); @@ -21,9 +27,6 @@ initlibbenchmark_messages() { benchmarks::google_message3::GoogleMessage3().descriptor(); benchmarks::google_message4::GoogleMessage4().descriptor(); - PyObject *m; - - m = Py_InitModule("libbenchmark_messages", python_benchmark_methods); - if (m == NULL) - return; + return PyModule_Create(&_module); +} } diff --git a/benchmarks/util/result_parser.py b/benchmarks/util/result_parser.py index bdf3a9980a..d3251a8b26 100644 --- a/benchmarks/util/result_parser.py +++ b/benchmarks/util/result_parser.py @@ -61,7 +61,7 @@ def __parse_cpp_result(filename): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results = json.loads(f.read()) for benchmark in results["benchmarks"]: data_filename = "".join( @@ -96,7 +96,7 @@ def __parse_synthetic_result(filename): return if filename[0] != "/": filename = os.path.dirname(os.path.abspath(__file__)) + "/" + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results = json.loads(f.read()) for benchmark in results["benchmarks"]: __results.append({ @@ -126,7 +126,7 @@ def __parse_python_result(filename): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results_list = json.loads(f.read()) for results in results_list: for result in results: @@ -176,7 +176,7 @@ def __parse_java_result(filename): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results = json.loads(f.read()) for result in results: total_weight = 0 @@ -212,7 +212,7 @@ def __parse_go_result(filename): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: for line in f: result_list = re.split(r"[\ \t]+", line) if result_list[0][:9] != "Benchmark": @@ -252,7 +252,7 @@ def __parse_custom_result(filename, language): return if filename[0] != '/': filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename - with open(filename, "rb") as f: + with open(filename, encoding="utf-8") as f: results = json.loads(f.read()) for result in results: _, avg_size = __get_data_size(result["filename"]) diff --git a/kokoro/linux/benchmark/run.sh b/kokoro/linux/benchmark/run.sh index 502f436536..acd8737077 100755 --- a/kokoro/linux/benchmark/run.sh +++ b/kokoro/linux/benchmark/run.sh @@ -23,8 +23,10 @@ popd ./configure CXXFLAGS="-fPIC -O2" make -j8 pushd python -python setup.py build --cpp_implementation -pip install . --user +virtualenv -p python3 env +source env/bin/activate +python3 setup.py build --cpp_implementation +pip3 install --install-option="--cpp_implementation" . popd # build and run Python benchmark @@ -91,7 +93,7 @@ cat tmp/python_result.json # print the postprocessed results to the build job log # TODO(jtattermusch): re-enable uploading results to bigquery (it is currently broken) make python_add_init -env LD_LIBRARY_PATH="${repo_root}/src/.libs" python -m util.result_parser \ +env LD_LIBRARY_PATH="${repo_root}/src/.libs" python3 -m util.result_parser \ -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -python="../tmp/python_result.json" popd From c4c7e2b8f932ab8be9b84b6ea8c26355546d2a38 Mon Sep 17 00:00:00 2001 From: JongChan Choi Date: Mon, 1 Nov 2021 13:53:04 -0700 Subject: [PATCH 043/207] Add pbkit to third_party.md (#9177) --- docs/third_party.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/third_party.md b/docs/third_party.md index 645ada81f4..ca15aaae2e 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -108,6 +108,7 @@ These are projects we know about implementing Protocol Buffers for other program * Swift: https://github.com/alexeyxo/protobuf-swift * Swift: https://github.com/apple/swift-protobuf/ * Typescript: https://github.com/thesayyn/protoc-gen-ts +* Typescript: https://github.com/pbkit/pbkit * Vala: https://launchpad.net/protobuf-vala * Visual Basic: http://code.google.com/p/protobuf-net/ @@ -130,6 +131,7 @@ GRPC (http://www.grpc.io/) is Google's RPC implementation for Protocol Buffers. * https://github.com/awakesecurity/gRPC-haskell (Haskell) * https://github.com/Yeolar/raster (C++) * https://github.com/jnordberg/wsrpc (JavaScript Node.js/Browser) +* https://github.com/pbkit/npm-packages/blob/main/frpc-test/src/index.spec.ts (TypeScript Node.js/Browser) * https://github.com/ppissias/xsrpcj (Java) * https://github.com/twitchtv/twirp (Multiple languages) From d88c8d5d4b7c458b3c0f894ad46700aa4fca7b39 Mon Sep 17 00:00:00 2001 From: Kent Ross Date: Thu, 4 Nov 2021 07:16:02 -0700 Subject: [PATCH 044/207] Implement unambiguous comparisons for RepeatedPtrIterator in C++20 (#9139) --- src/google/protobuf/repeated_ptr_field.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 7d635e3bb5..3c813a9f0a 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -1617,6 +1617,8 @@ class RepeatedPtrIterator { using iterator = RepeatedPtrIterator; using iterator_category = std::random_access_iterator_tag; using value_type = typename std::remove_const::type; + using const_iterator = RepeatedPtrIterator; + using nonconst_iterator = RepeatedPtrIterator; using difference_type = std::ptrdiff_t; using pointer = Element*; using reference = Element&; @@ -1652,14 +1654,20 @@ class RepeatedPtrIterator { iterator operator--(int) { return iterator(it_--); } // equality_comparable - bool operator==(const iterator& x) const { return it_ == x.it_; } - bool operator!=(const iterator& x) const { return it_ != x.it_; } + bool operator==(const nonconst_iterator& x) const { return it_ == x.it_; } + bool operator==(const const_iterator& x) const { return it_ == x.it_; } + bool operator!=(const nonconst_iterator& x) const { return it_ != x.it_; } + bool operator!=(const const_iterator& x) const { return it_ != x.it_; } // less_than_comparable - bool operator<(const iterator& x) const { return it_ < x.it_; } - bool operator<=(const iterator& x) const { return it_ <= x.it_; } - bool operator>(const iterator& x) const { return it_ > x.it_; } - bool operator>=(const iterator& x) const { return it_ >= x.it_; } + bool operator<(const nonconst_iterator& x) const { return it_ < x.it_; } + bool operator<(const const_iterator& x) const { return it_ < x.it_; } + bool operator<=(const nonconst_iterator& x) const { return it_ <= x.it_; } + bool operator<=(const const_iterator& x) const { return it_ <= x.it_; } + bool operator>(const nonconst_iterator& x) const { return it_ > x.it_; } + bool operator>(const const_iterator& x) const { return it_ > x.it_; } + bool operator>=(const nonconst_iterator& x) const { return it_ >= x.it_; } + bool operator>=(const const_iterator& x) const { return it_ >= x.it_; } // addable, subtractable iterator& operator+=(difference_type d) { From 11de748d66a0b358b01c2ca1a03b6455b33f808b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?X=C3=B9d=C5=8Dng=20Y=C3=A1ng?= Date: Fri, 5 Nov 2021 01:56:32 +1100 Subject: [PATCH 045/207] Use repo-relative labels wherever possible (#9187) * Use repo-relative labels wherever possible The label `@com_google_protobuf//:foo` within the protobuf repo is often synonymous with just `//:foo`. We should prefer the latter as it allows us to use a shorter name for the module in the Bazel Central Registry (so just "protobuf" instead of "com_google_protobuf"). Note that the semantics can be subtle: in a macro, plain strings are anchored to the *calling* repo, so if we just use `//:foo` as the default value of a macro argument, it will be resolved to `@myrepo//:foo` if the macro is called from the repo `@myrepo`. In this case, it's necessary to directly call the `Label()` constructor to anchor the string label to the repo where the .bzl file lives. See https://github.com/bazelbuild/bazel-central-registry/pull/28#issuecomment-954741081 for a bit more context. * fix protobuf_deps.bzl --- protobuf.bzl | 10 +++++----- protobuf_deps.bzl | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/protobuf.bzl b/protobuf.bzl index 9716128121..26b6625327 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -259,9 +259,9 @@ def cc_proto_library( deps = [], cc_libs = [], include = None, - protoc = "@com_google_protobuf//:protoc", + protoc = Label("//:protoc"), use_grpc_plugin = False, - default_runtime = "@com_google_protobuf//:protobuf", + default_runtime = Label("//:protobuf"), **kargs): """Bazel rule to create a C++ protobuf library from proto source files @@ -379,7 +379,7 @@ internal_gen_well_known_protos_java = rule( "_protoc": attr.label( executable = True, cfg = "exec", - default = "@com_google_protobuf//:protoc", + default = "//:protoc", ), }, ) @@ -422,8 +422,8 @@ def py_proto_library( py_libs = [], py_extra_srcs = [], include = None, - default_runtime = "@com_google_protobuf//:protobuf_python", - protoc = "@com_google_protobuf//:protoc", + default_runtime = Label("//:protobuf_python"), + protoc = Label("//:protoc"), use_grpc_plugin = False, **kargs): """Bazel rule to create a Python protobuf library from proto source files diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 32f38ebb6e..45e413d94b 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -29,7 +29,7 @@ def protobuf_deps(): if not native.existing_rule("zlib"): http_archive( name = "zlib", - build_file = "@com_google_protobuf//:third_party/zlib.BUILD", + build_file = Label("//:third_party/zlib.BUILD"), sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff", strip_prefix = "zlib-1.2.11", urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"], From 3a4d9316aa9e3f0afec58e83ed744b0be4d337fa Mon Sep 17 00:00:00 2001 From: Derek Perez Date: Thu, 4 Nov 2021 22:57:29 +0000 Subject: [PATCH 046/207] Creates a protoc release zip (#9188) * Creates a protoc release zip Mimics what we're doing manually today but powered by Bazel. * don't special case this. * Addressing feedback. * adding comment about _cc_toolchain --- BUILD | 67 ++++++++++++++++++++++++++++++- Makefile.am | 1 + WORKSPACE | 3 ++ protobuf_deps.bzl | 10 +++++ protobuf_release.bzl | 28 +++++++++++++ toolchain/cc_toolchain_config.bzl | 1 - 6 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 protobuf_release.bzl diff --git a/BUILD b/BUILD index 1690d42198..87bd219c07 100644 --- a/BUILD +++ b/BUILD @@ -2,11 +2,13 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library") +load("@rules_pkg//:pkg.bzl", "pkg_zip") +load("@rules_pkg//:mappings.bzl", "pkg_files") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") load("@rules_python//python:defs.bzl", "py_library") load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library") load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test") - +load(":protobuf_release.bzl", "package_naming") licenses(["notice"]) exports_files(["LICENSE"]) @@ -518,6 +520,69 @@ cc_binary( deps = [":protoc_lib"], ) + +################################################################################ +# Generates protoc release artifacts. +################################################################################ + +genrule( + name = "protoc_readme", + visibility = ["//visibility:private"], + cmd = """ +echo "Protocol Buffers - Google's data interchange format +Copyright 2008 Google Inc. +https://developers.google.com/protocol-buffers/ +This package contains a precompiled binary version of the protocol buffer +compiler (protoc). This binary is intended for users who want to use Protocol +Buffers in languages other than C++ but do not want to compile protoc +themselves. To install, simply place this binary somewhere in your PATH. +If you intend to use the included well known types then don't forget to +copy the contents of the 'include' directory somewhere as well, for example +into '/usr/local/include/'. +Please refer to our official github site for more installation instructions: + https://github.com/protocolbuffers/protobuf" > $@ + """, + outs = ["readme.txt"], +) + +# plugin.proto is excluded from this list because it belongs in a nested folder (protobuf/compiler/plugin.proto) +pkg_files( + name = "wkt_protos_files", + srcs = [value[0] for value in WELL_KNOWN_PROTO_MAP.values() if not value[0].endswith("plugin.proto")], + visibility = ["//visibility:private"], + prefix = "include/google/protobuf", +) + +pkg_files( + name = "compiler_plugin_protos_files", + srcs = ["src/google/protobuf/compiler/plugin.proto"], + visibility = ["//visibility:private"], + prefix = "include/google/protobuf/compiler", +) + +pkg_files( + name = "protoc_files", + srcs = [":protoc"], + visibility = ["//visibility:private"], + prefix = "bin/", +) + +package_naming( + name = "protoc_pkg_naming", +) + +pkg_zip( + name = "protoc_release", + package_file_name = "protoc-{version}-{cpu}.zip", + package_variables = ":protoc_pkg_naming", + srcs = [ + ":protoc_files", + ":wkt_protos_files", + ":compiler_plugin_protos_files", + "readme.txt", + ], +) + ################################################################################ # Tests ################################################################################ diff --git a/Makefile.am b/Makefile.am index 8e9f1bfdc7..ae86b8f05d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1429,6 +1429,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ maven_install.json \ protobuf.bzl \ protobuf_deps.bzl \ + protobuf_release.bzl \ protobuf_version.bzl \ third_party/zlib.BUILD \ util/python/BUILD \ diff --git a/WORKSPACE b/WORKSPACE index e500967fe4..8104dccaf1 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -56,3 +56,6 @@ pinned_maven_install() load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") bazel_skylib_workspace() + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") +rules_pkg_dependencies() diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 45e413d94b..2e628868e6 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -73,3 +73,13 @@ def protobuf_deps(): strip_prefix = "rules_jvm_external-4.1", urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/4.1.zip"], ) + + if not native.existing_rule("rules_pkg"): + http_archive( + name = "rules_pkg", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz", + "https://github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz", + ], + sha256 = "a89e203d3cf264e564fcb96b6e06dd70bc0557356eb48400ce4b5d97c2c3720d", + ) diff --git a/protobuf_release.bzl b/protobuf_release.bzl new file mode 100644 index 0000000000..e007e004d7 --- /dev/null +++ b/protobuf_release.bzl @@ -0,0 +1,28 @@ +""" +Generates package naming variables for use with rules_pkg. +""" + +load("@rules_pkg//:providers.bzl", "PackageVariablesInfo") +load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") +load(":protobuf_version.bzl", "PROTOBUF_VERSION") + +def _package_naming_impl(ctx): + values = {} + values["version"] = PROTOBUF_VERSION + + # infer from the current cpp toolchain. + toolchain = find_cpp_toolchain(ctx) + values["cpu"] = toolchain.cpu + + return PackageVariablesInfo(values = values) + + +package_naming = rule( + implementation = _package_naming_impl, + attrs = { + # Necessary data dependency for find_cpp_toolchain. + "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), + }, + toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], + incompatible_use_toolchain_transition = True, +) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 4478a11416..568b056c70 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -4,7 +4,6 @@ load( "feature", "flag_group", "flag_set", - "tool", "tool_path", ) From 13d559beb6967033a467a7517c35d8ad970f8afb Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 8 Nov 2021 13:40:52 -0800 Subject: [PATCH 047/207] Update our build script to publish Mac aarch_64 binaries (#9203) These are still x86-64 binaries at the moment (see #8557), but should be usable on M1 Macs in the Rosetta compatibility mode. Let's start publishing them on our GitHub release page and then eventually we can make them into true aarch_64 binaries. This fixes #9200. --- protoc-artifacts/build-zip.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/protoc-artifacts/build-zip.sh b/protoc-artifacts/build-zip.sh index 7d1923e6e6..1d977259f3 100755 --- a/protoc-artifacts/build-zip.sh +++ b/protoc-artifacts/build-zip.sh @@ -16,6 +16,7 @@ release page. If the target is protoc, well-known type .proto files will also be included. Each invocation will create 8 zip packages: dist/--win32.zip dist/--win64.zip + dist/--osx-aarch_64.zip dist/--osx-x86_64.zip dist/--linux-x86_32.zip dist/--linux-x86_64.zip @@ -33,6 +34,7 @@ VERSION_NUMBER=$2 declare -a FILE_NAMES=( \ win32.zip windows-x86_32.exe \ win64.zip windows-x86_64.exe \ + osx-aarch_64.zip osx-aarch_64.exe \ osx-x86_64.zip osx-x86_64.exe \ linux-x86_32.zip linux-x86_32.exe \ linux-x86_64.zip linux-x86_64.exe \ From d37dcf9e34809a7def529e591860eb6faa653f29 Mon Sep 17 00:00:00 2001 From: Oliver Eikemeier Date: Tue, 9 Nov 2021 14:20:11 +0100 Subject: [PATCH 048/207] remove unnecessary dependency (#9195) Signed-off-by: Oliver Eikemeier --- java/util/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/java/util/BUILD b/java/util/BUILD index ee6ddeaf19..2714917e41 100644 --- a/java/util/BUILD +++ b/java/util/BUILD @@ -12,7 +12,6 @@ java_library( visibility = ["//visibility:public"], deps = [ "//java/core", - "//java/lite", "@maven//:com_google_code_findbugs_jsr305", "@maven//:com_google_code_gson_gson", "@maven//:com_google_errorprone_error_prone_annotations", From aa15931050990b568110f44117ee10a1fae58e8d Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 10 Nov 2021 08:49:53 +1300 Subject: [PATCH 049/207] Update .NET SDKs to LTS versions --- appveyor.bat | 2 +- conformance/Makefile.am | 2 +- csharp/buildall.sh | 4 ++-- .../src/Google.Protobuf.Test/Google.Protobuf.Test.csproj | 2 +- csharp/compatibility_tests/v3.0.0/test.sh | 2 +- csharp/install_dotnet_sdk.ps1 | 4 ++-- csharp/src/AddressBook/AddressBook.csproj | 2 +- csharp/src/Google.Protobuf.Benchmarks/Program.cs | 2 +- .../Google.Protobuf.Conformance.csproj | 2 +- .../Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj | 2 +- .../src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs | 2 +- csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 4 ++-- global.json | 2 +- kokoro/linux/aarch64/test_csharp_aarch64.sh | 4 ++-- kokoro/linux/dockerfile/test/csharp/Dockerfile | 4 ++-- 16 files changed, 21 insertions(+), 21 deletions(-) diff --git a/appveyor.bat b/appveyor.bat index 7a35ceb4d6..005fb11f89 100644 --- a/appveyor.bat +++ b/appveyor.bat @@ -38,7 +38,7 @@ dotnet restore dotnet build -c %configuration% || goto error echo Testing C# -dotnet test -c %configuration% -f netcoreapp2.1 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error +dotnet test -c %configuration% -f netcoreapp3.1 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error dotnet test -c %configuration% -f net451 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error goto :EOF diff --git a/conformance/Makefile.am b/conformance/Makefile.am index ac6f9e1b2b..940c0a2668 100644 --- a/conformance/Makefile.am +++ b/conformance/Makefile.am @@ -316,7 +316,7 @@ conformance-java-lite: javac_middleman_lite conformance-csharp: $(other_language_protoc_outputs) @echo "Writing shortcut script conformance-csharp..." @echo '#! /bin/sh' > conformance-csharp - @echo 'dotnet ../csharp/src/Google.Protobuf.Conformance/bin/Release/netcoreapp2.1/Google.Protobuf.Conformance.dll "$$@"' >> conformance-csharp + @echo 'dotnet ../csharp/src/Google.Protobuf.Conformance/bin/Release/netcoreapp3.1/Google.Protobuf.Conformance.dll "$$@"' >> conformance-csharp @chmod +x conformance-csharp conformance-php: diff --git a/csharp/buildall.sh b/csharp/buildall.sh index 43b5ac3ffb..ab1a6c425a 100755 --- a/csharp/buildall.sh +++ b/csharp/buildall.sh @@ -10,8 +10,8 @@ dotnet restore $SRC/Google.Protobuf.sln dotnet build -c $CONFIG $SRC/Google.Protobuf.sln echo Running tests. -# Only test netcoreapp2.1, which uses the .NET Core runtime. +# Only test netcoreapp3.1, which uses the .NET Core runtime. # If we want to test the .NET 4.5 version separately, we could # run Mono explicitly. However, we don't have any differences between # the .NET 4.5 and netstandard2.1 assemblies. -dotnet test -c $CONFIG -f netcoreapp2.1 $SRC/Google.Protobuf.Test/Google.Protobuf.Test.csproj +dotnet test -c $CONFIG -f netcoreapp3.1 $SRC/Google.Protobuf.Test/Google.Protobuf.Test.csproj diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index cbb6fee5f7..0ecdf37abb 100644 --- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -2,7 +2,7 @@ Exe - net451;netcoreapp2.1 + net451;netcoreapp3.1 ../../keys/Google.Protobuf.snk true False diff --git a/csharp/compatibility_tests/v3.0.0/test.sh b/csharp/compatibility_tests/v3.0.0/test.sh index f893d64aba..459c079879 100755 --- a/csharp/compatibility_tests/v3.0.0/test.sh +++ b/csharp/compatibility_tests/v3.0.0/test.sh @@ -22,7 +22,7 @@ function run_test() { dotnet restore src/Google.Protobuf.Test/Google.Protobuf.Test.csproj dotnet build -c Release src/Google.Protobuf/Google.Protobuf.csproj dotnet build -c Release src/Google.Protobuf.Test/Google.Protobuf.Test.csproj - dotnet run -c Release -f netcoreapp2.1 -p src/Google.Protobuf.Test/Google.Protobuf.Test.csproj + dotnet run -c Release -f netcoreapp3.1 -p src/Google.Protobuf.Test/Google.Protobuf.Test.csproj } set -ex diff --git a/csharp/install_dotnet_sdk.ps1 b/csharp/install_dotnet_sdk.ps1 index c78655cc02..f9dc0d9d7a 100755 --- a/csharp/install_dotnet_sdk.ps1 +++ b/csharp/install_dotnet_sdk.ps1 @@ -16,5 +16,5 @@ Invoke-WebRequest -Uri $InstallScriptUrl -OutFile $InstallScriptPath # The SDK versions to install should be kept in sync with versions # installed by kokoro/linux/dockerfile/test/csharp/Dockerfile -&$InstallScriptPath -Version 2.1.802 -&$InstallScriptPath -Version 5.0.102 +&$InstallScriptPath -Version 3.1.415 +&$InstallScriptPath -Version 6.0.100 diff --git a/csharp/src/AddressBook/AddressBook.csproj b/csharp/src/AddressBook/AddressBook.csproj index f3268c0acf..9a527874ce 100644 --- a/csharp/src/AddressBook/AddressBook.csproj +++ b/csharp/src/AddressBook/AddressBook.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.1 Exe Google.Protobuf.Examples.AddressBook.Program False diff --git a/csharp/src/Google.Protobuf.Benchmarks/Program.cs b/csharp/src/Google.Protobuf.Benchmarks/Program.cs index 1f77a26135..037752f6b7 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/Program.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/Program.cs @@ -36,7 +36,7 @@ namespace Google.Protobuf.Benchmarks { class Program { - // typical usage: dotnet run -c Release -f netcoreapp2.1 + // typical usage: dotnet run -c Release -f netcoreapp3.1 // (this can profile both .net core and .net framework; for some reason // if you start from "-f net461", it goes horribly wrong) public static void Main(string[] args) diff --git a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj index ec8fb91389..6277e6898a 100644 --- a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj +++ b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.1 Exe False diff --git a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj index fee35be991..b2c4272628 100644 --- a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj +++ b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.1 Exe False diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index 61453e5ab2..ff8f5cc6b1 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -840,7 +840,7 @@ namespace Google.Protobuf.Collections var list2 = new RepeatedField { SampleNaNs.Regular, SampleNaNs.PayloadFlipped }; var list3 = new RepeatedField { SampleNaNs.Regular, SampleNaNs.SignallingFlipped }; - // All SampleNaNs have the same hashcode under certain targets (e.g. netcoreapp2.1) + // All SampleNaNs have the same hashcode under certain targets (e.g. netcoreapp3.1) EqualityTester.AssertInequality(list1, list2, checkHashcode: false); EqualityTester.AssertEquality(list1, list3); Assert.True(list1.Contains(SampleNaNs.SignallingFlipped)); diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index cdfa98e098..2665cc3d35 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -1,7 +1,7 @@  - net451;netcoreapp2.1;net50 + net451;netcoreapp3.1;net60 ../../keys/Google.Protobuf.snk true False diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index ad6f57999b..7e9e33a302 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -1,4 +1,4 @@ - + C# runtime library for Protocol Buffers - Google's data interchange format. @@ -43,7 +43,7 @@ - + diff --git a/global.json b/global.json index d29e29a3ea..ade0252834 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "5.0.102", + "version": "6.0.100", "rollForward": "latestMinor" } } diff --git a/kokoro/linux/aarch64/test_csharp_aarch64.sh b/kokoro/linux/aarch64/test_csharp_aarch64.sh index 450bb1e04d..6cbd2438b3 100755 --- a/kokoro/linux/aarch64/test_csharp_aarch64.sh +++ b/kokoro/linux/aarch64/test_csharp_aarch64.sh @@ -15,7 +15,7 @@ fi # First, build protobuf C# tests under x86_64 docker image # Tests are built "dotnet publish" because we want all the dependencies to the copied to the destination directory # (we want to avoid references to ~/.nuget that won't be available in the subsequent docker run) -CSHARP_BUILD_COMMAND="dotnet publish -c Release -f net50 csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj" +CSHARP_BUILD_COMMAND="dotnet publish -c Release -f net60 csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj" docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "DOTNET_CLI_TELEMETRY_OPTOUT=true" -e "DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work mcr.microsoft.com/dotnet/sdk:5.0.202-buster-slim bash -c "$CSHARP_BUILD_COMMAND" # Use an actual aarch64 docker image to run protobuf C# tests with an emulator. "dotnet vstest" allows @@ -25,5 +25,5 @@ docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake- # running under current user's UID and GID. To be able to do that, we need to provide a home directory for the user # otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity, # we just run map the user's home to a throwaway temporary directory -CSHARP_TEST_COMMAND="dotnet vstest csharp/src/Google.Protobuf.Test/bin/Release/net50/publish/Google.Protobuf.Test.dll" +CSHARP_TEST_COMMAND="dotnet vstest csharp/src/Google.Protobuf.Test/bin/Release/net60/publish/Google.Protobuf.Test.dll" docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "DOTNET_CLI_TELEMETRY_OPTOUT=true" -e "DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work mcr.microsoft.com/dotnet/sdk:5.0.202-buster-slim-arm64v8 bash -c "$CSHARP_TEST_COMMAND" diff --git a/kokoro/linux/dockerfile/test/csharp/Dockerfile b/kokoro/linux/dockerfile/test/csharp/Dockerfile index 37edbfda99..c07fcbcef1 100644 --- a/kokoro/linux/dockerfile/test/csharp/Dockerfile +++ b/kokoro/linux/dockerfile/test/csharp/Dockerfile @@ -32,8 +32,8 @@ RUN apt-get update && apt-get install -y libunwind8 libicu63 && apt-get clean # Install dotnet SDK via install script RUN wget -q https://dot.net/v1/dotnet-install.sh && \ chmod u+x dotnet-install.sh && \ - ./dotnet-install.sh --version 2.1.802 && \ - ./dotnet-install.sh --version 5.0.102 && \ + ./dotnet-install.sh --version 3.1.415 && \ + ./dotnet-install.sh --version 6.0.100 && \ ln -s /root/.dotnet/dotnet /usr/local/bin RUN wget -q www.nuget.org/NuGet.exe -O /usr/local/bin/nuget.exe From 0f33dc4380accab1a2d814c7da561e224c13a699 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 10 Nov 2021 09:02:28 +1300 Subject: [PATCH 050/207] Fix tests --- csharp/src/Google.Protobuf.Test/JsonParserTest.cs | 2 +- csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index 69c9eb6e99..8462c83994 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -553,7 +553,7 @@ namespace Google.Protobuf [Test] // Skip these test cases in .NET 5 because floating point parsing supports bigger values. // These big values won't throw an error in the test. -#if !NET5_0 +#if !NETCOREAPP3_1_OR_GREATER [TestCase("1.7977e308")] [TestCase("-1.7977e308")] [TestCase("1e309")] diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index 0cbc0a4ff8..7cc5c6bcfb 100644 --- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -201,7 +201,7 @@ namespace Google.Protobuf [TestCase("--1")] // Skip these test cases in .NET 5 because floating point parsing supports bigger values. // These big values won't throw an error in the test. -#if !NET5_0 +#if !NETCOREAPP3_1_OR_GREATER [TestCase("-1.7977e308")] [TestCase("1.7977e308")] #endif From a5fa4fb0192c09cc60b37fb4d118c62b5e5d6769 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 10 Nov 2021 21:12:44 +0000 Subject: [PATCH 051/207] Creating bazel toolchains to compile for macOS. --- toolchain/BUILD | 55 +++++++++++++++++++++++++++---- toolchain/cc_toolchain_config.bzl | 55 +++++++++++++++++++++++++------ toolchain/toolchains.bazelrc | 2 ++ 3 files changed, 96 insertions(+), 16 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index f5c38531bf..384115f54b 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -4,7 +4,9 @@ package(default_visibility = ["//visibility:public"]) filegroup(name = "empty") -LINUX_TOOLCHAINS = { +TOOLCHAINS = { + "darwin-x86_64": "cc-compiler-osx-x86_64", + "darwin-aarch_64": "cc-compiler-osx-aarch_64", "linux-aarch_64": "cc-compiler-linux-aarch_64", "linux-ppcle_64": "cc-compiler-linux-ppcle_64", "linux-s390_64": "cc-compiler-linux-s390_64", @@ -14,7 +16,7 @@ LINUX_TOOLCHAINS = { cc_toolchain_suite( name = "clang_suite", - toolchains = LINUX_TOOLCHAINS + toolchains = TOOLCHAINS ) [ @@ -32,13 +34,16 @@ cc_toolchain_suite( toolchain_config = ":" + cpu + "-config", toolchain_identifier = toolchain, ) - for cpu, toolchain in LINUX_TOOLCHAINS.items() + for cpu, toolchain in TOOLCHAINS.items() ] cc_toolchain_config( name = "linux-aarch_64-config", bit_flag = "-m64", - include_flag = "-I/usr/aarch64-linux-gnu/include/c++/8/aarch64-linux-gnu/", + cpp_flag = "-lstdc++", + include_flag = ["-I/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/", + "-I/usr/aarch64-linux-gnu/include/c++/10"], + linker_path = "/usr/bin/ld", target_cpu = "aarch64", target_full_name = "aarch64-linux-gnu", toolchain_dir = "/usr/aarch64-linux-gnu/include", @@ -48,7 +53,10 @@ cc_toolchain_config( cc_toolchain_config( name = "linux-ppcle_64-config", bit_flag = "-m64", - include_flag = "-I/usr/powerpc64le-linux-gnu/include/c++/8/powerpc64le-linux-gnu/", + cpp_flag = "-lstdc++", + include_flag = ["-I/usr/powerpc64le-linux-gnu/include/c++/10/powerpc64le-linux-gnu/", + "-I/usr/powerpc64le-linux-gnu/include/c++/10/"], + linker_path = "/usr/bin/ld", target_cpu = "ppc64", target_full_name = "powerpc64le-linux-gnu", toolchain_dir = "/usr/powerpc64le-linux-gnu/include", @@ -58,7 +66,10 @@ cc_toolchain_config( cc_toolchain_config( name = "linux-s390_64-config", bit_flag = "-m64", - include_flag = "-I/usr/s390x-linux-gnu/include/c++/8/s390x-linux-gnu/", + cpp_flag = "-lstdc++", + include_flag = ["-I/usr/s390x-linux-gnu/include/c++/10/s390x-linux-gnu/", + "-I/usr/s390x-linux-gnu/include/c++/10/"], + linker_path = "/usr/bin/ld", target_cpu = "systemz", target_full_name = "s390x-linux-gnu", toolchain_dir = "/usr/s390x-linux-gnu/include", @@ -68,6 +79,8 @@ cc_toolchain_config( cc_toolchain_config( name = "linux-x86_32-config", bit_flag = "-m32", + cpp_flag = "-lstdc++", + linker_path = "/usr/bin/ld", target_cpu = "x86_32", target_full_name = "i386-linux-gnu", toolchain_dir = "/usr/include/i386-linux-gnu", @@ -77,8 +90,38 @@ cc_toolchain_config( cc_toolchain_config( name = "linux-x86_64-config", bit_flag = "-m64", + cpp_flag = "-lstdc++", + linker_path = "/usr/bin/ld", target_cpu = "x86_64", target_full_name = "x86_64-linux-gnu", toolchain_dir = "/usr/include/x86_64-linux-gnu", toolchain_name = "linux_x86_64", ) + +cc_toolchain_config( + name = "darwin-aarch_64-config", + bit_flag = "-m64", + cpp_flag = "-lc++", + include_flag = ["-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", + "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include"], + linker_path = "/tools", + sysroot = "/tools/apple_sdks/xcode_13_0/macosx", + target_cpu = "aarch64", + target_full_name = "aarch64-apple-macosx11.3", + toolchain_dir = "/tools/apple_sdks/xcode_13_0/macosx", + toolchain_name = "darwin_aarch_64", +) + +cc_toolchain_config( + name = "darwin-x86_64-config", + bit_flag = "-m64", + cpp_flag = "-lc++", + include_flag = ["-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", + "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include"], + linker_path = "/tools", + sysroot = "/tools/apple_sdks/xcode_13_0/macosx", + target_cpu = "x86_64", + target_full_name = "x86_64-apple-macosx11.3", + toolchain_dir = "/tools/apple_sdks/xcode_13_0/macosx", + toolchain_name = "darwin_x86_64", +) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 4478a11416..7d027ef26a 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -35,15 +35,15 @@ def _impl(ctx): ), tool_path( name = "ld", - path = "/usr/bin/ld", + path = ctx.attr.linker_path, ), tool_path( name = "ar", - path = "/usr/bin/ar", + path = "/usr/bin/llvm-ar", ), tool_path( name = "compat-ld", - path = "/usr/bin/ld", + path = ctx.attr.linker_path, ), tool_path( name = "cpp", @@ -84,7 +84,8 @@ def _impl(ctx): flag_groups = [ flag_group( flags = [ - "-lstdc++", + "-B" + ctx.attr.linker_path, + ctx.attr.cpp_flag, "--target=" + ctx.attr.target_full_name, ], ), @@ -92,6 +93,36 @@ def _impl(ctx): ), ], ) + + sysroot_flags = feature( + name = "sysroot_flags", + #Only enable this if a sysroot was specified + enabled = (ctx.attr.sysroot != ""), + flag_sets = [ + flag_set( + actions = all_link_actions, + flag_groups = [ + flag_group( + flags = [ + "--sysroot", + ctx.attr.sysroot, + ], + ), + ], + ), + flag_set( + actions = all_compile_actions, + flag_groups = [ + flag_group( + flags = [ + "-isysroot" + ctx.attr.sysroot, + ], + ), + ], + ), + ], + ) + compiler_flags = feature( name = "default_compile_flags", enabled = True, @@ -107,8 +138,8 @@ def _impl(ctx): "--target=" + ctx.attr.target_full_name, "-isystem", ctx.attr.toolchain_dir, - ctx.attr.include_flag, - ], + "-fvisibility=hidden", + ] + ctx.attr.include_flag, ), ], ), @@ -116,8 +147,8 @@ def _impl(ctx): ) return cc_common.create_cc_toolchain_config_info( - abi_libc_version = ctx.attr.target_cpu, - abi_version = ctx.attr.target_cpu, + abi_libc_version = ctx.attr.abi_version, + abi_version = ctx.attr.abi_version, ctx = ctx, compiler = "clang", cxx_builtin_include_directories = [ @@ -125,7 +156,7 @@ def _impl(ctx): "/usr/include", "/usr/local/lib/clang", ], - features = [linker_flags, compiler_flags], + features = [linker_flags, compiler_flags, sysroot_flags], host_system_name = "local", target_cpu = ctx.attr.target_cpu, target_libc = ctx.attr.target_cpu, @@ -137,8 +168,12 @@ def _impl(ctx): cc_toolchain_config = rule( implementation = _impl, attrs = { + "abi_version": attr.string(default = "local"), "bit_flag": attr.string(mandatory = True, values = ["-m32", "-m64"]), - "include_flag": attr.string(mandatory = False), + "cpp_flag": attr.string(mandatory = True), + "include_flag": attr.string_list(), + "linker_path": attr.string(mandatory = True), + "sysroot": attr.string(mandatory = False), "target_cpu": attr.string(mandatory = True, values = ["aarch64", "ppc64", "systemz", "x86_32", "x86_64"]), "target_full_name": attr.string(mandatory = True), "toolchain_dir": attr.string(mandatory = True), diff --git a/toolchain/toolchains.bazelrc b/toolchain/toolchains.bazelrc index f56e4cee3b..60fb6a4ea3 100644 --- a/toolchain/toolchains.bazelrc +++ b/toolchain/toolchains.bazelrc @@ -6,3 +6,5 @@ build:linux-ppcle_64 --config=cross_config --cpu=linux-ppcle_64 build:linux-s390_64 --config=cross_config --cpu=linux-s390_64 build:linux-x86_32 --config=cross_config --cpu=linux-x86_32 build:linux-x86_64 --config=cross_config --cpu=linux-x86_64 +build:osx-aarch_64 --config=cross_config --cpu=darwin-aarch_64 +build:osx-x86_64 --config=cross_config --cpu=darwin-x86_64 From 97c901cfb6f2db6ed84e31875331b850fd9126d1 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 10 Nov 2021 21:27:20 +0000 Subject: [PATCH 052/207] Fixing formatting --- toolchain/BUILD | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 384115f54b..d56cf9bdfa 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -41,8 +41,10 @@ cc_toolchain_config( name = "linux-aarch_64-config", bit_flag = "-m64", cpp_flag = "-lstdc++", - include_flag = ["-I/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/", - "-I/usr/aarch64-linux-gnu/include/c++/10"], + include_flag = [ + "-I/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/", + "-I/usr/aarch64-linux-gnu/include/c++/10" + ], linker_path = "/usr/bin/ld", target_cpu = "aarch64", target_full_name = "aarch64-linux-gnu", @@ -54,8 +56,10 @@ cc_toolchain_config( name = "linux-ppcle_64-config", bit_flag = "-m64", cpp_flag = "-lstdc++", - include_flag = ["-I/usr/powerpc64le-linux-gnu/include/c++/10/powerpc64le-linux-gnu/", - "-I/usr/powerpc64le-linux-gnu/include/c++/10/"], + include_flag = [ + "-I/usr/powerpc64le-linux-gnu/include/c++/10/powerpc64le-linux-gnu/", + "-I/usr/powerpc64le-linux-gnu/include/c++/10/" + ], linker_path = "/usr/bin/ld", target_cpu = "ppc64", target_full_name = "powerpc64le-linux-gnu", @@ -67,8 +71,10 @@ cc_toolchain_config( name = "linux-s390_64-config", bit_flag = "-m64", cpp_flag = "-lstdc++", - include_flag = ["-I/usr/s390x-linux-gnu/include/c++/10/s390x-linux-gnu/", - "-I/usr/s390x-linux-gnu/include/c++/10/"], + include_flag = [ + "-I/usr/s390x-linux-gnu/include/c++/10/s390x-linux-gnu/", + "-I/usr/s390x-linux-gnu/include/c++/10/" + ], linker_path = "/usr/bin/ld", target_cpu = "systemz", target_full_name = "s390x-linux-gnu", @@ -102,8 +108,10 @@ cc_toolchain_config( name = "darwin-aarch_64-config", bit_flag = "-m64", cpp_flag = "-lc++", - include_flag = ["-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", - "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include"], + include_flag = [ + "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", + "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include" + ], linker_path = "/tools", sysroot = "/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "aarch64", @@ -116,8 +124,10 @@ cc_toolchain_config( name = "darwin-x86_64-config", bit_flag = "-m64", cpp_flag = "-lc++", - include_flag = ["-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", - "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include"], + include_flag = [ + "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", + "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include" + ], linker_path = "/tools", sysroot = "/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "x86_64", From ef1c9fd9077440acacf4fec112153dda4a2c9d44 Mon Sep 17 00:00:00 2001 From: Rose <91555155+rpvela@users.noreply.github.com> Date: Thu, 11 Nov 2021 00:37:03 +0000 Subject: [PATCH 053/207] [C++] Fix missing #ifdef for undefined identifiers (#9201) * Fix #if for undefined identifiers * port_undef.inc --- src/google/protobuf/inlined_string_field.h | 2 +- src/google/protobuf/port_def.inc | 4 ++-- src/google/protobuf/port_undef.inc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/inlined_string_field.h b/src/google/protobuf/inlined_string_field.h index 1fe639f065..e4ab35972a 100644 --- a/src/google/protobuf/inlined_string_field.h +++ b/src/google/protobuf/inlined_string_field.h @@ -347,7 +347,7 @@ inline void InlinedStringField::Swap( InlinedStringField* from, const std::string* /*default_value*/, Arena* arena, bool donated, bool from_donated, uint32_t* donating_states, uint32_t* from_donating_states, uint32_t mask) { -#if GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE +#ifdef GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE // If one is donated and the other is not, undonate the donated one. if (donated && !from_donated) { MutableSlow(arena, donated, donating_states, mask); diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 71325c3872..67b67e949e 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -617,7 +617,7 @@ #ifdef PROTOBUF_PRAGMA_INIT_SEG #error PROTOBUF_PRAGMA_INIT_SEG was previously defined #endif -#if _MSC_VER +#ifdef _MSC_VER #define PROTOBUF_PRAGMA_INIT_SEG __pragma(init_seg(lib)) #else #define PROTOBUF_PRAGMA_INIT_SEG @@ -784,7 +784,7 @@ #endif // Silence some MSVC warnings in all our code. -#if _MSC_VER +#ifdef _MSC_VER #pragma warning(push) // For non-trivial unions #pragma warning(disable : 4582) diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index 579eb419d0..ccc5daf564 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -140,6 +140,6 @@ #endif // Pop the warning(push) from port_def.inc -#if _MSC_VER +#ifdef _MSC_VER #pragma warning(pop) #endif From 47e05427e3341c9b18fff047e7d9f79af0dafe9b Mon Sep 17 00:00:00 2001 From: tomerv Date: Thu, 11 Nov 2021 03:03:55 +0200 Subject: [PATCH 054/207] Fix typo in docstring (#9208) --- python/google/protobuf/descriptor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index 61c242f9df..7e98293475 100644 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py @@ -647,7 +647,7 @@ class EnumDescriptor(_NestedDescriptorBase): full_name (str): Full name of the type, including package name and any enclosing type(s). - values (list[EnumValueDescriptors]): List of the values + values (list[EnumValueDescriptor]): List of the values in this enum. values_by_name (dict(str, EnumValueDescriptor)): Same as :attr:`values`, but indexed by the "name" field of each EnumValueDescriptor. From 627bb4b60e42f8fac1dc0bdb790d50cba6f74f30 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 11 Nov 2021 19:30:49 +0000 Subject: [PATCH 055/207] Changing cpp version back to 8 --- toolchain/BUILD | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index d56cf9bdfa..25a3cda96c 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -42,8 +42,8 @@ cc_toolchain_config( bit_flag = "-m64", cpp_flag = "-lstdc++", include_flag = [ - "-I/usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/", - "-I/usr/aarch64-linux-gnu/include/c++/10" + "-I/usr/aarch64-linux-gnu/include/c++/8/aarch64-linux-gnu/", + "-I/usr/aarch64-linux-gnu/include/c++/8" ], linker_path = "/usr/bin/ld", target_cpu = "aarch64", @@ -57,8 +57,8 @@ cc_toolchain_config( bit_flag = "-m64", cpp_flag = "-lstdc++", include_flag = [ - "-I/usr/powerpc64le-linux-gnu/include/c++/10/powerpc64le-linux-gnu/", - "-I/usr/powerpc64le-linux-gnu/include/c++/10/" + "-I/usr/powerpc64le-linux-gnu/include/c++/8/powerpc64le-linux-gnu/", + "-I/usr/powerpc64le-linux-gnu/include/c++/8/" ], linker_path = "/usr/bin/ld", target_cpu = "ppc64", @@ -72,8 +72,8 @@ cc_toolchain_config( bit_flag = "-m64", cpp_flag = "-lstdc++", include_flag = [ - "-I/usr/s390x-linux-gnu/include/c++/10/s390x-linux-gnu/", - "-I/usr/s390x-linux-gnu/include/c++/10/" + "-I/usr/s390x-linux-gnu/include/c++/8/s390x-linux-gnu/", + "-I/usr/s390x-linux-gnu/include/c++/8/" ], linker_path = "/usr/bin/ld", target_cpu = "systemz", From 90afe0cfc6288deb84025c518134bcbf70fa3b96 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 12 Nov 2021 12:38:05 +1300 Subject: [PATCH 056/207] Add nuget.config --- csharp/NuGet.Config | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 csharp/NuGet.Config diff --git a/csharp/NuGet.Config b/csharp/NuGet.Config new file mode 100644 index 0000000000..b04b00689f --- /dev/null +++ b/csharp/NuGet.Config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file From c685d79368a50293d8cbd53540cf52ab33e8265b Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 12 Nov 2021 12:57:47 +1300 Subject: [PATCH 057/207] Fix test --- csharp/src/Google.Protobuf.Test/JsonParserTest.cs | 4 ---- csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs | 4 ---- csharp/src/Google.Protobuf/JsonTokenizer.cs | 11 ++++++++++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index 8462c83994..e170fcc5a0 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -551,13 +551,9 @@ namespace Google.Protobuf } [Test] - // Skip these test cases in .NET 5 because floating point parsing supports bigger values. - // These big values won't throw an error in the test. -#if !NETCOREAPP3_1_OR_GREATER [TestCase("1.7977e308")] [TestCase("-1.7977e308")] [TestCase("1e309")] -#endif [TestCase("1,0")] [TestCase("1.0.0")] [TestCase("+1")] diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index 7cc5c6bcfb..df43effd4f 100644 --- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -199,12 +199,8 @@ namespace Google.Protobuf [TestCase("1e-")] [TestCase("--")] [TestCase("--1")] - // Skip these test cases in .NET 5 because floating point parsing supports bigger values. - // These big values won't throw an error in the test. -#if !NETCOREAPP3_1_OR_GREATER [TestCase("-1.7977e308")] [TestCase("1.7977e308")] -#endif public void InvalidNumberValue(string json) { AssertThrowsAfter(json); diff --git a/csharp/src/Google.Protobuf/JsonTokenizer.cs b/csharp/src/Google.Protobuf/JsonTokenizer.cs index 4725e7cc51..13a12c05dd 100644 --- a/csharp/src/Google.Protobuf/JsonTokenizer.cs +++ b/csharp/src/Google.Protobuf/JsonTokenizer.cs @@ -471,9 +471,18 @@ namespace Google.Protobuf // TODO: What exception should we throw if the value can't be represented as a double? try { - return double.Parse(builder.ToString(), + double result = double.Parse(builder.ToString(), NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, CultureInfo.InvariantCulture); + + // .NET Core 3.0 and later returns infinity if the number is too large or small to be represented. + // For compatibility with other Protobuf implementations the tokenizer should still throw. + if (double.IsInfinity(result)) + { + throw reader.CreateException("Numeric value out of range: " + builder); + } + + return result; } catch (OverflowException) { From 7569df0f58209b33ebc4a4ac5c36e1b3b7d8781c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 12 Nov 2021 11:22:19 +0100 Subject: [PATCH 058/207] add NuGet.config to Makefile.am --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index ae86b8f05d..a83f9aaf41 100644 --- a/Makefile.am +++ b/Makefile.am @@ -54,6 +54,7 @@ csharp_EXTRA_DIST= \ csharp/CHANGES.txt \ csharp/Google.Protobuf.Tools.targets \ csharp/Google.Protobuf.Tools.nuspec \ + csharp/NuGet.Config \ csharp/README.md \ csharp/build_packages.bat \ csharp/build_tools.sh \ From 4c09e43f7419e3c194273f2f9dd67f03eb20e5ea Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 8 Apr 2021 13:21:53 +1200 Subject: [PATCH 059/207] Fix .NET SourceLink and warnings in NuGet package --- csharp/build_packages.bat | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/csharp/build_packages.bat b/csharp/build_packages.bat index d7205659f1..9e68229037 100644 --- a/csharp/build_packages.bat +++ b/csharp/build_packages.bat @@ -1,7 +1,7 @@ @rem Builds Google.Protobuf NuGet packages dotnet restore src/Google.Protobuf.sln -dotnet pack -c Release src/Google.Protobuf.sln || goto :error +dotnet pack -c Release src/Google.Protobuf.sln -p:ContinuousIntegrationBuild=true || goto :error goto :EOF diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 7e9e33a302..f40e444de9 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -15,10 +15,11 @@ Protocol;Buffers;Binary;Serialization;Format;Google;proto;proto3 C# proto3 support https://github.com/protocolbuffers/protobuf - https://github.com/protocolbuffers/protobuf/blob/master/LICENSE + BSD-3-Clause git https://github.com/protocolbuffers/protobuf.git - True + true + true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb From 76f57fd6df9513588b7b2f0a9e4b8cc6db2633d1 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Fri, 12 Nov 2021 16:06:54 -0800 Subject: [PATCH 060/207] Update BUILD paths Prefix all tools paths with /root/ --- toolchain/BUILD | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 25a3cda96c..83864a937a 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -109,14 +109,14 @@ cc_toolchain_config( bit_flag = "-m64", cpp_flag = "-lc++", include_flag = [ - "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", - "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include" + "-I/root/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", + "-I/root/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], - linker_path = "/tools", - sysroot = "/tools/apple_sdks/xcode_13_0/macosx", + linker_path = "/root/tools", + sysroot = "/root/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "aarch64", target_full_name = "aarch64-apple-macosx11.3", - toolchain_dir = "/tools/apple_sdks/xcode_13_0/macosx", + toolchain_dir = "/root/tools/apple_sdks/xcode_13_0/macosx", toolchain_name = "darwin_aarch_64", ) @@ -125,13 +125,13 @@ cc_toolchain_config( bit_flag = "-m64", cpp_flag = "-lc++", include_flag = [ - "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", - "-I/tools/apple_sdks/xcode_13_0/macosx/usr/include" + "-I/root/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", + "-I/root/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], - linker_path = "/tools", - sysroot = "/tools/apple_sdks/xcode_13_0/macosx", + linker_path = "/root/tools", + sysroot = "/root/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "x86_64", target_full_name = "x86_64-apple-macosx11.3", - toolchain_dir = "/tools/apple_sdks/xcode_13_0/macosx", + toolchain_dir = "/root/tools/apple_sdks/xcode_13_0/macosx", toolchain_name = "darwin_x86_64", ) From 845db63cede55426cc19e2ea228f013c14caf068 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 16 Nov 2021 18:26:30 +0100 Subject: [PATCH 061/207] Fix dotnet aarch64 (#9222) * fix C# aarch64 test after .NET SDK upgrade * simplify C# aarch64 tests (net60 can build under emulator) * Revert "simplify C# aarch64 tests (net60 can build under emulator)" This reverts commit 6b2aa5f0061e8a7e82c85a4ba810e196eaf63eec. --- kokoro/linux/aarch64/test_csharp_aarch64.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kokoro/linux/aarch64/test_csharp_aarch64.sh b/kokoro/linux/aarch64/test_csharp_aarch64.sh index 6cbd2438b3..cc3bffe04d 100755 --- a/kokoro/linux/aarch64/test_csharp_aarch64.sh +++ b/kokoro/linux/aarch64/test_csharp_aarch64.sh @@ -16,7 +16,7 @@ fi # Tests are built "dotnet publish" because we want all the dependencies to the copied to the destination directory # (we want to avoid references to ~/.nuget that won't be available in the subsequent docker run) CSHARP_BUILD_COMMAND="dotnet publish -c Release -f net60 csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj" -docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "DOTNET_CLI_TELEMETRY_OPTOUT=true" -e "DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work mcr.microsoft.com/dotnet/sdk:5.0.202-buster-slim bash -c "$CSHARP_BUILD_COMMAND" +docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "DOTNET_CLI_TELEMETRY_OPTOUT=true" -e "DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work mcr.microsoft.com/dotnet/sdk:6.0.100-bullseye-slim bash -c "$CSHARP_BUILD_COMMAND" # Use an actual aarch64 docker image to run protobuf C# tests with an emulator. "dotnet vstest" allows # running tests from a pre-built project. @@ -26,4 +26,4 @@ docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake- # otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity, # we just run map the user's home to a throwaway temporary directory CSHARP_TEST_COMMAND="dotnet vstest csharp/src/Google.Protobuf.Test/bin/Release/net60/publish/Google.Protobuf.Test.dll" -docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "DOTNET_CLI_TELEMETRY_OPTOUT=true" -e "DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work mcr.microsoft.com/dotnet/sdk:5.0.202-buster-slim-arm64v8 bash -c "$CSHARP_TEST_COMMAND" +docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "DOTNET_CLI_TELEMETRY_OPTOUT=true" -e "DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work mcr.microsoft.com/dotnet/sdk:6.0.100-bullseye-slim-arm64v8 bash -c "$CSHARP_TEST_COMMAND" From a16227351545246bb42c48198469e13d1fb1f256 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Tue, 16 Nov 2021 11:38:16 -0800 Subject: [PATCH 062/207] Update BUILD paths Update paths for apple sdks --- toolchain/BUILD | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 83864a937a..2b0a815091 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -109,14 +109,14 @@ cc_toolchain_config( bit_flag = "-m64", cpp_flag = "-lc++", include_flag = [ - "-I/root/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", - "-I/root/tools/apple_sdks/xcode_13_0/macosx/usr/include" + "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", + "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], - linker_path = "/root/tools", - sysroot = "/root/tools/apple_sdks/xcode_13_0/macosx", + linker_path = "/usr/tools", + sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "aarch64", target_full_name = "aarch64-apple-macosx11.3", - toolchain_dir = "/root/tools/apple_sdks/xcode_13_0/macosx", + toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", toolchain_name = "darwin_aarch_64", ) @@ -125,13 +125,13 @@ cc_toolchain_config( bit_flag = "-m64", cpp_flag = "-lc++", include_flag = [ - "-I/root/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", - "-I/root/tools/apple_sdks/xcode_13_0/macosx/usr/include" + "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", + "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], - linker_path = "/root/tools", - sysroot = "/root/tools/apple_sdks/xcode_13_0/macosx", + linker_path = "/usr/tools", + sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "x86_64", target_full_name = "x86_64-apple-macosx11.3", - toolchain_dir = "/root/tools/apple_sdks/xcode_13_0/macosx", + toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", toolchain_name = "darwin_x86_64", ) From 25c818e3f1c90d86723d99052b1de21b58a8d584 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Tue, 16 Nov 2021 15:15:46 -0800 Subject: [PATCH 063/207] Update BUILD Change sysroot to be specific to the folder where all the include files are. --- toolchain/BUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 2b0a815091..a33603a5f7 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -113,7 +113,7 @@ cc_toolchain_config( "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], linker_path = "/usr/tools", - sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", + sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include", target_cpu = "aarch64", target_full_name = "aarch64-apple-macosx11.3", toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", @@ -129,7 +129,7 @@ cc_toolchain_config( "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], linker_path = "/usr/tools", - sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", + sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include", target_cpu = "x86_64", target_full_name = "x86_64-apple-macosx11.3", toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", From 6cc68c5c595f4db7a0507853e217e8aac501da61 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Tue, 16 Nov 2021 16:01:15 -0800 Subject: [PATCH 064/207] Update include directories Add /usr/local/include to cpp builtin include directories. --- toolchain/cc_toolchain_config.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 107822f993..27185c7a63 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -153,6 +153,7 @@ def _impl(ctx): cxx_builtin_include_directories = [ ctx.attr.toolchain_dir, "/usr/include", + "/usr/local/include", "/usr/local/lib/clang", ], features = [linker_flags, compiler_flags, sysroot_flags], From 22462b0c529b444d065679885a6aaf5cb2514e05 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 3 Nov 2021 10:50:09 +1300 Subject: [PATCH 065/207] Fix trim warnings --- Makefile.am | 4 + .../Google.Protobuf.Test.TestProtos.csproj | 4 +- .../Google.Protobuf.Test.csproj | 2 +- .../Google.Protobuf.Test/JsonParserTest.cs | 132 +++++++++++++++++- .../DynamicallyAccessedMemberTypes.cs | 127 +++++++++++++++++ .../DynamicallyAccessedMembersAttribute.cs | 83 +++++++++++ .../RequiresUnreferencedCodeAttribute.cs | 72 ++++++++++ .../Compatibility/TypeExtensions.cs | 13 +- .../UnconditionalSuppressMessageAttribute.cs | 117 ++++++++++++++++ .../Google.Protobuf/Google.Protobuf.csproj | 1 + csharp/src/Google.Protobuf/JsonFormatter.cs | 27 ++-- .../Reflection/CustomOptions.cs | 20 +++ .../Reflection/FieldDescriptor.cs | 2 +- .../Reflection/GeneratedClrTypeInfo.cs | 22 ++- .../Reflection/MessageDescriptor.cs | 2 + .../Reflection/ReflectionUtil.cs | 14 +- .../Reflection/SingleFieldAccessor.cs | 54 +++++-- .../WellKnownTypes/FieldMaskPartial.cs | 13 +- 18 files changed, 660 insertions(+), 49 deletions(-) create mode 100644 csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMemberTypes.cs create mode 100644 csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMembersAttribute.cs create mode 100644 csharp/src/Google.Protobuf/Compatibility/RequiresUnreferencedCodeAttribute.cs create mode 100644 csharp/src/Google.Protobuf/Compatibility/UnconditionalSuppressMessageAttribute.cs diff --git a/Makefile.am b/Makefile.am index a83f9aaf41..23022f7cad 100644 --- a/Makefile.am +++ b/Makefile.am @@ -182,10 +182,14 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/Collections/ProtobufEqualityComparers.cs \ csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs \ csharp/src/Google.Protobuf/Collections/RepeatedField.cs \ + csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMembersAttribute.cs \ + csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMemberTypes.cs \ csharp/src/Google.Protobuf/Compatibility/MethodInfoExtensions.cs \ csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs \ + csharp/src/Google.Protobuf/Compatibility/RequiresUnreferencedCodeAttribute.cs \ csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs \ csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs \ + csharp/src/Google.Protobuf/Compatibility/UnconditionalSuppressMessageAttribute.cs \ csharp/src/Google.Protobuf/Extension.cs \ csharp/src/Google.Protobuf/ExtensionRegistry.cs \ csharp/src/Google.Protobuf/ExtensionSet.cs \ diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj b/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj index 9f2ba6b0de..5030043d76 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj +++ b/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj @@ -1,4 +1,4 @@ - + - + diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index 2665cc3d35..deb17e9f52 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -21,7 +21,7 @@ - + diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index e170fcc5a0..eb8996e620 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -35,6 +35,7 @@ using Google.Protobuf.TestProtos; using Google.Protobuf.WellKnownTypes; using NUnit.Framework; using ProtobufTestMessages.Proto2; +using ProtobufTestMessages.Proto3; using System; using UnitTest.Issues.TestProtos; @@ -918,10 +919,10 @@ namespace Google.Protobuf } [Test] - [TestCase("\"FOREIGN_BAR\"", ForeignEnum.ForeignBar)] - [TestCase("5", ForeignEnum.ForeignBar)] - [TestCase("100", (ForeignEnum)100)] - public void EnumValid(string value, ForeignEnum expectedValue) + [TestCase("\"FOREIGN_BAR\"", TestProtos.ForeignEnum.ForeignBar)] + [TestCase("5", TestProtos.ForeignEnum.ForeignBar)] + [TestCase("100", (TestProtos.ForeignEnum)100)] + public void EnumValid(string value, TestProtos.ForeignEnum expectedValue) { string json = "{ \"singleForeignEnum\": " + value + " }"; var parsed = TestAllTypes.Parser.ParseJson(json); @@ -1021,5 +1022,128 @@ namespace Google.Protobuf { return '"' + text + '"'; } + + [Test] + public void ParseAllNullValues() + { + string json = @"{ + ""optionalInt32"": null, + ""optionalInt64"": null, + ""optionalUint32"": null, + ""optionalUint64"": null, + ""optionalSint32"": null, + ""optionalSint64"": null, + ""optionalFixed32"": null, + ""optionalFixed64"": null, + ""optionalSfixed32"": null, + ""optionalSfixed64"": null, + ""optionalFloat"": null, + ""optionalDouble"": null, + ""optionalBool"": null, + ""optionalString"": null, + ""optionalBytes"": null, + ""optionalNestedEnum"": null, + ""optionalNestedMessage"": null, + ""repeatedInt32"": null, + ""repeatedInt64"": null, + ""repeatedUint32"": null, + ""repeatedUint64"": null, + ""repeatedSint32"": null, + ""repeatedSint64"": null, + ""repeatedFixed32"": null, + ""repeatedFixed64"": null, + ""repeatedSfixed32"": null, + ""repeatedSfixed64"": null, + ""repeatedFloat"": null, + ""repeatedDouble"": null, + ""repeatedBool"": null, + ""repeatedString"": null, + ""repeatedBytes"": null, + ""repeatedNestedEnum"": null, + ""repeatedNestedMessage"": null, + ""mapInt32Int32"": null, + ""mapBoolBool"": null, + ""mapStringNestedMessage"": null +}"; + + TestAllTypesProto3 message = new TestAllTypesProto3(); + + message.OptionalInt32 = 1; + message.OptionalInt64 = 1; + message.OptionalUint32 = 1; + message.OptionalUint64 = 1; + message.OptionalSint32 = 1; + message.OptionalSint64 = 1; + message.OptionalFixed32 = 1; + message.OptionalFixed64 = 1; + message.OptionalSfixed32 = 1; + message.OptionalSfixed64 = 1; + message.OptionalFloat = 1; + message.OptionalDouble = 1; + message.OptionalBool = true; + message.OptionalString = "1"; + message.OptionalBytes = ByteString.CopyFrom(new byte[] { 1 }); + message.OptionalNestedEnum = TestAllTypesProto3.Types.NestedEnum.Bar; + message.OptionalNestedMessage = new TestAllTypesProto3.Types.NestedMessage(); + message.RepeatedInt32.Add(1); + message.RepeatedInt64.Add(1); + message.RepeatedUint32.Add(1); + message.RepeatedUint64.Add(1); + message.RepeatedSint32.Add(1); + message.RepeatedSint64.Add(1); + message.RepeatedFixed32.Add(1); + message.RepeatedFixed64.Add(1); + message.RepeatedSfixed32.Add(1); + message.RepeatedSfixed64.Add(1); + message.RepeatedFloat.Add(1); + message.RepeatedDouble.Add(1); + message.RepeatedBool.Add(true); + message.RepeatedString.Add("1"); + message.RepeatedBytes.Add(ByteString.CopyFrom(new byte[] { 1 })); + message.RepeatedNestedEnum.Add(TestAllTypesProto3.Types.NestedEnum.Bar); + message.RepeatedNestedMessage.Add(new TestAllTypesProto3.Types.NestedMessage()); + message.MapInt32Int32.Add(1, 1); + message.MapBoolBool.Add(true, true); + message.MapStringNestedMessage.Add(" ", new TestAllTypesProto3.Types.NestedMessage()); + + JsonParser.Default.Merge(message, json); + + Assert.AreEqual(0, message.OptionalInt32); + Assert.AreEqual(0, message.OptionalInt64); + Assert.AreEqual(0, message.OptionalUint32); + Assert.AreEqual(0, message.OptionalUint64); + Assert.AreEqual(0, message.OptionalSint32); + Assert.AreEqual(0, message.OptionalSint64); + Assert.AreEqual(0, message.OptionalFixed32); + Assert.AreEqual(0, message.OptionalFixed64); + Assert.AreEqual(0, message.OptionalSfixed32); + Assert.AreEqual(0, message.OptionalSfixed64); + Assert.AreEqual(0, message.OptionalFloat); + Assert.AreEqual(0, message.OptionalDouble); + Assert.AreEqual(false, message.OptionalBool); + Assert.AreEqual("", message.OptionalString); + Assert.AreEqual(ByteString.Empty, message.OptionalBytes); + Assert.AreEqual(TestAllTypesProto3.Types.NestedEnum.Foo, message.OptionalNestedEnum); + Assert.AreEqual(null, message.OptionalNestedMessage); + Assert.AreEqual(0, message.RepeatedInt32.Count); + Assert.AreEqual(0, message.RepeatedInt64.Count); + Assert.AreEqual(0, message.RepeatedUint32.Count); + Assert.AreEqual(0, message.RepeatedUint64.Count); + Assert.AreEqual(0, message.RepeatedSint32.Count); + Assert.AreEqual(0, message.RepeatedSint64.Count); + Assert.AreEqual(0, message.RepeatedFixed32.Count); + Assert.AreEqual(0, message.RepeatedFixed64.Count); + Assert.AreEqual(0, message.RepeatedSfixed32.Count); + Assert.AreEqual(0, message.RepeatedFloat.Count); + Assert.AreEqual(0, message.RepeatedDouble.Count); + Assert.AreEqual(0, message.RepeatedBool.Count); + Assert.AreEqual(0, message.RepeatedString.Count); + Assert.AreEqual(0, message.RepeatedBytes.Count); + Assert.AreEqual(0, message.RepeatedNestedEnum.Count); + Assert.AreEqual(0, message.RepeatedNestedMessage.Count); + Assert.AreEqual(0, message.MapInt32Int32.Count); + Assert.AreEqual(0, message.MapBoolBool.Count); + Assert.AreEqual(0, message.MapStringNestedMessage.Count); + } } } \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMemberTypes.cs b/csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMemberTypes.cs new file mode 100644 index 0000000000..a4d739d802 --- /dev/null +++ b/csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMemberTypes.cs @@ -0,0 +1,127 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if !NET5_0_OR_GREATER +// Copied with permission from https://github.com/dotnet/runtime/tree/8fbf206d0e518b45ca855832e8bfb391afa85972/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis +namespace System.Diagnostics.CodeAnalysis +{ + /// + /// Specifies the types of members that are dynamically accessed. + /// + /// This enumeration has a attribute that allows a + /// bitwise combination of its member values. + /// + [Flags] + internal enum DynamicallyAccessedMemberTypes + { + /// + /// Specifies no members. + /// + None = 0, + + /// + /// Specifies the default, parameterless public constructor. + /// + PublicParameterlessConstructor = 0x0001, + + /// + /// Specifies all public constructors. + /// + PublicConstructors = 0x0002 | PublicParameterlessConstructor, + + /// + /// Specifies all non-public constructors. + /// + NonPublicConstructors = 0x0004, + + /// + /// Specifies all public methods. + /// + PublicMethods = 0x0008, + + /// + /// Specifies all non-public methods. + /// + NonPublicMethods = 0x0010, + + /// + /// Specifies all public fields. + /// + PublicFields = 0x0020, + + /// + /// Specifies all non-public fields. + /// + NonPublicFields = 0x0040, + + /// + /// Specifies all public nested types. + /// + PublicNestedTypes = 0x0080, + + /// + /// Specifies all non-public nested types. + /// + NonPublicNestedTypes = 0x0100, + + /// + /// Specifies all public properties. + /// + PublicProperties = 0x0200, + + /// + /// Specifies all non-public properties. + /// + NonPublicProperties = 0x0400, + + /// + /// Specifies all public events. + /// + PublicEvents = 0x0800, + + /// + /// Specifies all non-public events. + /// + NonPublicEvents = 0x1000, + + /// + /// Specifies all interfaces implemented by the type. + /// + Interfaces = 0x2000, + + /// + /// Specifies all members. + /// + All = ~None + } +} +#endif diff --git a/csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMembersAttribute.cs b/csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMembersAttribute.cs new file mode 100644 index 0000000000..ae09276234 --- /dev/null +++ b/csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMembersAttribute.cs @@ -0,0 +1,83 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if !NET5_0_OR_GREATER +// Copied with permission from https://github.com/dotnet/runtime/tree/8fbf206d0e518b45ca855832e8bfb391afa85972/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis +namespace System.Diagnostics.CodeAnalysis +{ + /// + /// Indicates that certain members on a specified are accessed dynamically, + /// for example through . + /// + /// + /// This allows tools to understand which members are being accessed during the execution + /// of a program. + /// + /// This attribute is valid on members whose type is or . + /// + /// When this attribute is applied to a location of type , the assumption is + /// that the string represents a fully qualified type name. + /// + /// When this attribute is applied to a class, interface, or struct, the members specified + /// can be accessed dynamically on instances returned from calling + /// on instances of that class, interface, or struct. + /// + /// If the attribute is applied to a method it's treated as a special case and it implies + /// the attribute should be applied to the "this" parameter of the method. As such the attribute + /// should only be used on instance methods of types assignable to System.Type (or string, but no methods + /// will use it there). + /// + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | + AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method | + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct, + Inherited = false)] + internal sealed class DynamicallyAccessedMembersAttribute : Attribute + { + /// + /// Initializes a new instance of the class + /// with the specified member types. + /// + /// The types of members dynamically accessed. + public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes) + { + MemberTypes = memberTypes; + } + + /// + /// Gets the which specifies the type + /// of members dynamically accessed. + /// + public DynamicallyAccessedMemberTypes MemberTypes { get; } + } +} +#endif diff --git a/csharp/src/Google.Protobuf/Compatibility/RequiresUnreferencedCodeAttribute.cs b/csharp/src/Google.Protobuf/Compatibility/RequiresUnreferencedCodeAttribute.cs new file mode 100644 index 0000000000..1fc8e66d49 --- /dev/null +++ b/csharp/src/Google.Protobuf/Compatibility/RequiresUnreferencedCodeAttribute.cs @@ -0,0 +1,72 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if !NET5_0_OR_GREATER +// Copied with permission from https://github.com/dotnet/runtime/tree/8fbf206d0e518b45ca855832e8bfb391afa85972/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis +namespace System.Diagnostics.CodeAnalysis +{ + /// + /// Indicates that the specified method requires dynamic access to code that is not referenced + /// statically, for example through . + /// + /// + /// This allows tools to understand which methods are unsafe to call when removing unreferenced + /// code from an application. + /// + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class, Inherited = false)] + internal sealed class RequiresUnreferencedCodeAttribute : Attribute + { + /// + /// Initializes a new instance of the class + /// with the specified message. + /// + /// + /// A message that contains information about the usage of unreferenced code. + /// + public RequiresUnreferencedCodeAttribute(string message) + { + Message = message; + } + + /// + /// Gets a message that contains information about the usage of unreferenced code. + /// + public string Message { get; } + + /// + /// Gets or sets an optional URL that contains more information about the method, + /// why it requires unreferenced code, and what options a consumer has to deal with it. + /// + public string Url { get; set; } + } +} +#endif diff --git a/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs b/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs index 2f23713819..b3acda2da7 100644 --- a/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs +++ b/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs @@ -31,6 +31,7 @@ #endregion using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; #if !NET35 @@ -59,7 +60,11 @@ namespace Google.Protobuf.Compatibility /// including inherited properties or null if there is no such public property. /// Here, "public property" means a property where either the getter, or the setter, or both, is public. /// - internal static PropertyInfo GetProperty(this Type target, string name) + [UnconditionalSuppressMessage("Trimming", "IL2072", + Justification = "The BaseType of the target will have all properties because of the annotation.")] + internal static PropertyInfo GetProperty( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] + this Type target, string name) { // GetDeclaredProperty only returns properties declared in the given type, so we need to recurse. while (target != null) @@ -86,7 +91,11 @@ namespace Google.Protobuf.Compatibility /// class Child : Base declares public void Foo(long)). /// /// One type in the hierarchy declared more than one method with the same name - internal static MethodInfo GetMethod(this Type target, string name) + [UnconditionalSuppressMessage("Trimming", "IL2072", + Justification = "The BaseType of the target will have all properties because of the annotation.")] + internal static MethodInfo GetMethod( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] + this Type target, string name) { // GetDeclaredMethod only returns methods declared in the given type, so we need to recurse. while (target != null) diff --git a/csharp/src/Google.Protobuf/Compatibility/UnconditionalSuppressMessageAttribute.cs b/csharp/src/Google.Protobuf/Compatibility/UnconditionalSuppressMessageAttribute.cs new file mode 100644 index 0000000000..a02a1453eb --- /dev/null +++ b/csharp/src/Google.Protobuf/Compatibility/UnconditionalSuppressMessageAttribute.cs @@ -0,0 +1,117 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if !NET5_0_OR_GREATER +// Copied with permission from https://github.com/dotnet/runtime/tree/8fbf206d0e518b45ca855832e8bfb391afa85972/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis +namespace System.Diagnostics.CodeAnalysis +{ + /// + /// Suppresses reporting of a specific rule violation, allowing multiple suppressions on a + /// single code artifact. + /// + /// + /// is different than + /// in that it doesn't have a + /// . So it is always preserved in the compiled assembly. + /// + [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] + internal sealed class UnconditionalSuppressMessageAttribute : Attribute + { + /// + /// Initializes a new instance of the + /// class, specifying the category of the tool and the identifier for an analysis rule. + /// + /// The category for the attribute. + /// The identifier of the analysis rule the attribute applies to. + public UnconditionalSuppressMessageAttribute(string category, string checkId) + { + Category = category; + CheckId = checkId; + } + + /// + /// Gets the category identifying the classification of the attribute. + /// + /// + /// The property describes the tool or tool analysis category + /// for which a message suppression attribute applies. + /// + public string Category { get; } + + /// + /// Gets the identifier of the analysis tool rule to be suppressed. + /// + /// + /// Concatenated together, the and + /// properties form a unique check identifier. + /// + public string CheckId { get; } + + /// + /// Gets or sets the scope of the code that is relevant for the attribute. + /// + /// + /// The Scope property is an optional argument that specifies the metadata scope for which + /// the attribute is relevant. + /// + public string Scope { get; set; } + + /// + /// Gets or sets a fully qualified path that represents the target of the attribute. + /// + /// + /// The property is an optional argument identifying the analysis target + /// of the attribute. An example value is "System.IO.Stream.ctor():System.Void". + /// Because it is fully qualified, it can be long, particularly for targets such as parameters. + /// The analysis tool user interface should be capable of automatically formatting the parameter. + /// + public string Target { get; set; } + + /// + /// Gets or sets an optional argument expanding on exclusion criteria. + /// + /// + /// The property is an optional argument that specifies additional + /// exclusion where the literal metadata target is not sufficiently precise. For example, + /// the cannot be applied within a method, + /// and it may be desirable to suppress a violation against a statement in the method that will + /// give a rule violation, but not against all statements in the method. + /// + public string MessageId { get; set; } + + /// + /// Gets or sets the justification for suppressing the code analysis message. + /// + public string Justification { get; set; } + } +} +#endif diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index f40e444de9..9289150856 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -22,6 +22,7 @@ true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index 4bffd58c1f..17fdc7f738 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -40,6 +40,7 @@ using System.IO; using System.Linq; using System.Collections.Generic; using System.Reflection; +using System.Diagnostics.CodeAnalysis; namespace Google.Protobuf { @@ -879,6 +880,8 @@ namespace Google.Protobuf private static readonly Dictionary> dictionaries = new Dictionary>(); + [UnconditionalSuppressMessage("Trimming", "IL2072", + Justification = "The field for the value must still be present. It will be returned by reflection, will be in this collection, and its name can be resolved.")] internal static string GetOriginalName(object value) { var enumType = value.GetType(); @@ -898,21 +901,13 @@ namespace Google.Protobuf return originalName; } -#if NET35 - // TODO: Consider adding functionality to TypeExtensions to avoid this difference. - private static Dictionary GetNameMapping(System.Type enumType) => - enumType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static) - .Where(f => (f.GetCustomAttributes(typeof(OriginalNameAttribute), false) - .FirstOrDefault() as OriginalNameAttribute) - ?.PreferredAlias ?? true) - .ToDictionary(f => f.GetValue(null), - f => (f.GetCustomAttributes(typeof(OriginalNameAttribute), false) - .FirstOrDefault() as OriginalNameAttribute) - // If the attribute hasn't been applied, fall back to the name of the field. - ?.Name ?? f.Name); -#else - private static Dictionary GetNameMapping(System.Type enumType) => - enumType.GetTypeInfo().DeclaredFields + private static Dictionary GetNameMapping( + [DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields)] + System.Type enumType) + { + return enumType.GetTypeInfo().DeclaredFields .Where(f => f.IsStatic) .Where(f => f.GetCustomAttributes() .FirstOrDefault()?.PreferredAlias ?? true) @@ -921,7 +916,7 @@ namespace Google.Protobuf .FirstOrDefault() // If the attribute hasn't been applied, fall back to the name of the field. ?.Name ?? f.Name); -#endif + } } } } diff --git a/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs b/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs index 9fc3766889..f6fa1522ba 100644 --- a/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs +++ b/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs @@ -34,6 +34,7 @@ using Google.Protobuf.Collections; using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; @@ -63,6 +64,8 @@ namespace Google.Protobuf.Reflection /// public sealed class CustomOptions { + private const string UnreferencedCodeMessage = "CustomOptions is incompatible with trimming."; + private static readonly object[] EmptyParameters = new object[0]; private readonly IDictionary values; @@ -77,6 +80,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetBool(int field, out bool value) => TryGetPrimitiveValue(field, out value); /// @@ -85,6 +89,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetInt32(int field, out int value) => TryGetPrimitiveValue(field, out value); /// @@ -93,6 +98,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetInt64(int field, out long value) => TryGetPrimitiveValue(field, out value); /// @@ -102,6 +108,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetFixed32(int field, out uint value) => TryGetUInt32(field, out value); /// @@ -111,6 +118,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetFixed64(int field, out ulong value) => TryGetUInt64(field, out value); /// @@ -120,6 +128,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetSFixed32(int field, out int value) => TryGetInt32(field, out value); /// @@ -129,6 +138,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetSFixed64(int field, out long value) => TryGetInt64(field, out value); /// @@ -138,6 +148,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetSInt32(int field, out int value) => TryGetPrimitiveValue(field, out value); /// @@ -147,6 +158,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetSInt64(int field, out long value) => TryGetPrimitiveValue(field, out value); /// @@ -155,6 +167,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetUInt32(int field, out uint value) => TryGetPrimitiveValue(field, out value); /// @@ -163,6 +176,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetUInt64(int field, out ulong value) => TryGetPrimitiveValue(field, out value); /// @@ -171,6 +185,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetFloat(int field, out float value) => TryGetPrimitiveValue(field, out value); /// @@ -179,6 +194,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetDouble(int field, out double value) => TryGetPrimitiveValue(field, out value); /// @@ -187,6 +203,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetString(int field, out string value) => TryGetPrimitiveValue(field, out value); /// @@ -195,6 +212,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetBytes(int field, out ByteString value) => TryGetPrimitiveValue(field, out value); /// @@ -203,6 +221,7 @@ namespace Google.Protobuf.Reflection /// The field to fetch the value for. /// The output variable to populate. /// true if a suitable value for the field was found; false otherwise. + [RequiresUnreferencedCode(UnreferencedCodeMessage)] public bool TryGetMessage(int field, out T value) where T : class, IMessage, new() { if (values == null) @@ -240,6 +259,7 @@ namespace Google.Protobuf.Reflection return false; } + [RequiresUnreferencedCode(UnreferencedCodeMessage)] private bool TryGetPrimitiveValue(int field, out T value) { if (values == null) diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 0ba16cf96f..f9b90619ad 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -452,7 +452,7 @@ namespace Google.Protobuf.Reflection } return IsMap ? new MapFieldAccessor(property, this) : IsRepeated ? new RepeatedFieldAccessor(property, this) - : (IFieldAccessor) new SingleFieldAccessor(property, this); + : (IFieldAccessor) new SingleFieldAccessor(ContainingType.ClrType, property, this); } } } diff --git a/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs b/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs index 479e177130..d0a495b851 100644 --- a/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs +++ b/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs @@ -30,6 +30,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion using System; +using System.Diagnostics.CodeAnalysis; namespace Google.Protobuf.Reflection { @@ -43,10 +44,19 @@ namespace Google.Protobuf.Reflection private static readonly string[] EmptyNames = new string[0]; private static readonly GeneratedClrTypeInfo[] EmptyCodeInfo = new GeneratedClrTypeInfo[0]; private static readonly Extension[] EmptyExtensions = new Extension[0]; + internal const DynamicallyAccessedMemberTypes MessageAccessibility = + // Creating types + DynamicallyAccessedMemberTypes.PublicConstructors | + // Getting and setting properties + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties | + // Calling presence methods + DynamicallyAccessedMemberTypes.PublicMethods; /// /// Irrelevant for file descriptors; the CLR type for the message for message descriptors. /// + [DynamicallyAccessedMembers(MessageAccessibility)] public Type ClrType { get; private set; } /// @@ -88,7 +98,11 @@ namespace Google.Protobuf.Reflection /// Each array parameter may be null, to indicate a lack of values. /// The parameter order is designed to make it feasible to format the generated code readably. /// - public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, Extension[] extensions, GeneratedClrTypeInfo[] nestedTypes) + public GeneratedClrTypeInfo( + // Preserve all public members on message types when trimming is enabled. + // This ensures that members used by reflection, e.g. JSON serialization, are preserved. + [DynamicallyAccessedMembers(MessageAccessibility)] + Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, Extension[] extensions, GeneratedClrTypeInfo[] nestedTypes) { NestedTypes = nestedTypes ?? EmptyCodeInfo; NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes; @@ -104,7 +118,11 @@ namespace Google.Protobuf.Reflection /// Each array parameter may be null, to indicate a lack of values. /// The parameter order is designed to make it feasible to format the generated code readably. /// - public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes) + public GeneratedClrTypeInfo( + // Preserve all public members on message types when trimming is enabled. + // This ensures that members used by reflection, e.g. JSON serialization, are preserved. + [DynamicallyAccessedMembers(MessageAccessibility)] + Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes) : this(clrType, parser, propertyNames, oneofNames, nestedEnums, null, nestedTypes) { } diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index 7b5ab2fb48..f56dd893b8 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -33,6 +33,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; #if NET35 @@ -182,6 +183,7 @@ namespace Google.Protobuf.Reflection /// a wrapper type, and handle the result appropriately. /// /// + [DynamicallyAccessedMembers(GeneratedClrTypeInfo.MessageAccessibility)] public Type ClrType { get; } /// diff --git a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs index fd1ad4e3e0..73efcc2566 100644 --- a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs +++ b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs @@ -32,6 +32,7 @@ using Google.Protobuf.Compatibility; using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; namespace Google.Protobuf.Reflection @@ -115,13 +116,15 @@ namespace Google.Protobuf.Reflection internal static Func CreateFuncIMessageBool(MethodInfo method) => GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageBool(method); - internal static Func CreateIsInitializedCaller(Type msg) => + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] + internal static Func CreateIsInitializedCaller([DynamicallyAccessedMembers(GeneratedClrTypeInfo.MessageAccessibility)]Type msg) => ((IExtensionSetReflector)Activator.CreateInstance(typeof(ExtensionSetReflector<>).MakeGenericType(msg))).CreateIsInitializedCaller(); /// /// Creates a delegate which will execute the given method after casting the first argument to /// the type that declares the method, and the second argument to the first parameter type of the method. /// + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] internal static IExtensionReflectionHelper CreateExtensionHelper(Extension extension) => (IExtensionReflectionHelper)Activator.CreateInstance(typeof(ExtensionReflectionHelper<,>).MakeGenericType(extension.TargetType, extension.GetType().GenericTypeArguments[1]), extension); @@ -131,6 +134,7 @@ namespace Google.Protobuf.Reflection /// they can be garbage collected. We could cache them by type if that proves to be important, but creating /// an object is pretty cheap. /// + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] private static IReflectionHelper GetReflectionHelper(Type t1, Type t2) => (IReflectionHelper) Activator.CreateInstance(typeof(ReflectionHelper<,>).MakeGenericType(t1, t2)); @@ -308,16 +312,14 @@ namespace Google.Protobuf.Reflection } } - private class ExtensionSetReflector : IExtensionSetReflector where T1 : IExtendableMessage + private class ExtensionSetReflector< + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] + T1> : IExtensionSetReflector where T1 : IExtendableMessage { public Func CreateIsInitializedCaller() { var prop = typeof(T1).GetTypeInfo().GetDeclaredProperty("_Extensions"); -#if NET35 - var getFunc = (Func>)prop.GetGetMethod(true).CreateDelegate(typeof(Func>)); -#else var getFunc = (Func>)prop.GetMethod.CreateDelegate(typeof(Func>)); -#endif var initializedFunc = (Func, bool>) typeof(ExtensionSet) .GetTypeInfo() diff --git a/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs b/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs index 07d84d7fb9..ac35e729f7 100644 --- a/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs +++ b/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs @@ -31,6 +31,8 @@ #endregion using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using Google.Protobuf.Compatibility; @@ -50,7 +52,9 @@ namespace Google.Protobuf.Reflection private readonly Action clearDelegate; private readonly Func hasDelegate; - internal SingleFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor) + internal SingleFieldAccessor( + [DynamicallyAccessedMembers(GeneratedClrTypeInfo.MessageAccessibility)] + Type messageType, PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor) { if (!property.CanWrite) { @@ -87,13 +91,13 @@ namespace Google.Protobuf.Reflection // Primitive fields always support presence in proto2, and support presence in proto3 for optional fields. else if (descriptor.File.Syntax == Syntax.Proto2 || descriptor.Proto.Proto3Optional) { - MethodInfo hasMethod = property.DeclaringType.GetRuntimeProperty("Has" + property.Name).GetMethod; + MethodInfo hasMethod = messageType.GetRuntimeProperty("Has" + property.Name).GetMethod; if (hasMethod == null) { throw new ArgumentException("Not all required properties/methods are available"); } hasDelegate = ReflectionUtil.CreateFuncIMessageBool(hasMethod); - MethodInfo clearMethod = property.DeclaringType.GetRuntimeMethod("Clear" + property.Name, ReflectionUtil.EmptyTypes); + MethodInfo clearMethod = messageType.GetRuntimeMethod("Clear" + property.Name, ReflectionUtil.EmptyTypes); if (clearMethod == null) { throw new ArgumentException("Not all required properties/methods are available"); @@ -107,16 +111,48 @@ namespace Google.Protobuf.Reflection hasDelegate = message => { throw new InvalidOperationException("Presence is not implemented for this field"); }; // While presence isn't supported, clearing still is; it's just setting to a default value. - var clrType = property.PropertyType; - - object defaultValue = - clrType == typeof(string) ? "" - : clrType == typeof(ByteString) ? ByteString.Empty - : Activator.CreateInstance(clrType); + object defaultValue = GetDefaultValue(descriptor); clearDelegate = message => SetValue(message, defaultValue); } } + private static object GetDefaultValue(FieldDescriptor descriptor) + { + switch (descriptor.FieldType) + { + case FieldType.Bool: + return false; + case FieldType.Bytes: + return ByteString.Empty; + case FieldType.String: + return ""; + case FieldType.Double: + return 0.0; + case FieldType.SInt32: + case FieldType.Int32: + case FieldType.SFixed32: + case FieldType.Enum: + return 0; + case FieldType.Fixed32: + case FieldType.UInt32: + return (uint)0; + case FieldType.Fixed64: + case FieldType.UInt64: + return 0UL; + case FieldType.SFixed64: + case FieldType.Int64: + case FieldType.SInt64: + return 0L; + case FieldType.Float: + return 0f; + case FieldType.Message: + case FieldType.Group: // Never expect to get this, but... + return null; + default: + throw new ArgumentException("Invalid field type"); + } + } + public override void Clear(IMessage message) => clearDelegate(message); public override bool HasValue(IMessage message) => hasDelegate(message); public override void SetValue(IMessage message, object value) => setValueDelegate(message, value); diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs index 91d2ee9094..58a33cb6d4 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs @@ -33,6 +33,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using Google.Protobuf.Reflection; @@ -115,7 +116,7 @@ namespace Google.Protobuf.WellKnownTypes /// Parses from a string to a FieldMask and validates all field paths. /// /// The type to validate the field paths against. - public static FieldMask FromString(string value) where T : IMessage + public static FieldMask FromString<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(string value) where T : IMessage { return FromStringEnumerable(new List(value.Split(FIELD_PATH_SEPARATOR))); } @@ -124,7 +125,7 @@ namespace Google.Protobuf.WellKnownTypes /// Constructs a FieldMask for a list of field paths in a certain type. /// /// The type to validate the field paths against. - public static FieldMask FromStringEnumerable(IEnumerable paths) where T : IMessage + public static FieldMask FromStringEnumerable<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(IEnumerable paths) where T : IMessage { var mask = new FieldMask(); foreach (var path in paths) @@ -151,7 +152,7 @@ namespace Google.Protobuf.WellKnownTypes /// Constructs a FieldMask from the passed field numbers. /// /// The type to validate the field paths against. - public static FieldMask FromFieldNumbers(params int[] fieldNumbers) where T : IMessage + public static FieldMask FromFieldNumbers<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(params int[] fieldNumbers) where T : IMessage { return FromFieldNumbers((IEnumerable)fieldNumbers); } @@ -160,7 +161,7 @@ namespace Google.Protobuf.WellKnownTypes /// Constructs a FieldMask from the passed field numbers. /// /// The type to validate the field paths against. - public static FieldMask FromFieldNumbers(IEnumerable fieldNumbers) where T : IMessage + public static FieldMask FromFieldNumbers<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(IEnumerable fieldNumbers) where T : IMessage { var descriptor = Activator.CreateInstance().Descriptor; @@ -208,7 +209,7 @@ namespace Google.Protobuf.WellKnownTypes /// Checks whether paths in a given fields mask are valid. /// /// The type to validate the field paths against. - public static bool IsValid(FieldMask fieldMask) where T : IMessage + public static bool IsValid<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(FieldMask fieldMask) where T : IMessage { var descriptor = Activator.CreateInstance().Descriptor; @@ -235,7 +236,7 @@ namespace Google.Protobuf.WellKnownTypes /// Checks whether a given field path is valid. /// /// The type to validate the field paths against. - public static bool IsValid(string path) where T : IMessage + public static bool IsValid<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(string path) where T : IMessage { var descriptor = Activator.CreateInstance().Descriptor; From 8608ee97dae0537ee407b007b44f395a3351af83 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 19 Nov 2021 22:56:15 +0000 Subject: [PATCH 066/207] Change sysroot flags --- toolchain/BUILD | 4 ++-- toolchain/cc_toolchain_config.bzl | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index a33603a5f7..2b0a815091 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -113,7 +113,7 @@ cc_toolchain_config( "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], linker_path = "/usr/tools", - sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include", + sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "aarch64", target_full_name = "aarch64-apple-macosx11.3", toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", @@ -129,7 +129,7 @@ cc_toolchain_config( "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], linker_path = "/usr/tools", - sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include", + sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "x86_64", target_full_name = "x86_64-apple-macosx11.3", toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 27185c7a63..1c0e33025d 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -109,16 +109,6 @@ def _impl(ctx): ), ], ), - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = [ - "-isysroot" + ctx.attr.sysroot, - ], - ), - ], - ), ], ) From f7a58bb060cd06d7f0d9d0810e7b151dbc391fb5 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Fri, 19 Nov 2021 15:34:25 -0500 Subject: [PATCH 067/207] Add a envvar to provide a prefix on all proto package prefixed symbols. While at it, fix a header comment. --- .../compiler/objectivec/objectivec_helpers.cc | 18 +++++++++++++++--- .../compiler/objectivec/objectivec_helpers.h | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 5f4b7f60fa..74943cb0a8 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -102,9 +102,14 @@ class PrefixModeStorage { bool is_package_exempted(const std::string& package); + // When using a proto package as the prefix, this should be added as the + // prefix in front of it. + const std::string& forced_package_prefix() const { return forced_prefix_; } + private: bool use_package_name_; std::string exception_path_; + std::string forced_prefix_; std::unordered_set exceptions_; }; @@ -120,6 +125,13 @@ PrefixModeStorage::PrefixModeStorage() { if (exception_path) { exception_path_ = exception_path; } + + // This one is a not expected to be common, so it doesn't get a generation + // option, just the env var. + const char* prefix = getenv("GPB_OBJC_USE_PACKAGE_AS_PREFIX_PREFIX"); + if (prefix) { + forced_prefix_ = prefix; + } } bool PrefixModeStorage::is_package_exempted(const std::string& package) { @@ -510,8 +522,8 @@ std::string FileClassPrefix(const FileDescriptor* file) { return file->options().objc_class_prefix(); } - // If package prefix isn't enabled or no package, done. - if (!g_prefix_mode.use_package_name() || file->package().empty()) { + // If package prefix isn't enabled, done. + if (!g_prefix_mode.use_package_name()) { return ""; } @@ -538,7 +550,7 @@ std::string FileClassPrefix(const FileDescriptor* file) { if (!result.empty()) { result.append("_"); } - return result; + return g_prefix_mode.forced_package_prefix() + result; } std::string FilePath(const FileDescriptor* file) { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 13a1052406..f4b71ced8e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -54,8 +54,8 @@ namespace objectivec { bool PROTOC_EXPORT UseProtoPackageAsDefaultPrefix(); void PROTOC_EXPORT SetUseProtoPackageAsDefaultPrefix(bool on_or_off); // Get/Set the path to a file to load as exceptions when -// `UseProtoPackageAsDefaultPrefixUseProtoPackageAsDefaultPrefix()` is `true`. -// And empty string means there should be no exceptions loaded. +// `UseProtoPackageAsDefaultPrefix()` is `true`. An empty string means there +// should be no exceptions. std::string PROTOC_EXPORT GetProtoPackagePrefixExceptionList(); void PROTOC_EXPORT SetProtoPackagePrefixExceptionList( const std::string& file_path); From ef9b7036e7a0b0317c51ea0a8c9619c8cf7022c8 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Fri, 19 Nov 2021 17:32:06 -0500 Subject: [PATCH 068/207] Support no_package:FILE in the expected prefixes file. When a file doesn't have a proto package, allow validation to still be supported via entries with that consist of 'no_package:FILE'. This allows someone using an expected prefixes file to also list these exceptional cases, and allows them to becomes error cases with requiring all prefixes to be registered. --- .../objectivec/objectivec_generator.cc | 3 + .../compiler/objectivec/objectivec_helpers.cc | 84 +++++++++---------- 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index a03b8604fc..713f93ef1b 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -110,6 +110,9 @@ bool ObjectiveCGenerator::GenerateAll( // - Comments start with "#". // - A comment can go on a line after a expected package/prefix pair. // (i.e. - "package=prefix # comment") + // - For files that do NOT have a proto package (not recommended), an + // entry can be made as "no_package:PATH=prefix", where PATH is the + // path for the .proto file. // // There is no validation that the prefixes are good prefixes, it is // assumed that they are when you create the file. diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 5f4b7f60fa..85f18a9234 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -352,9 +352,9 @@ bool IsReservedCIdentifier(const std::string& input) { } std::string SanitizeNameForObjC(const std::string& prefix, - const std::string& input, - const std::string& extension, - std::string* out_suffix_added) { + const std::string& input, + const std::string& extension, + std::string* out_suffix_added) { static const std::unordered_set kReservedWords = MakeWordsMap(kReservedWordList, GOOGLE_ARRAYSIZE(kReservedWordList)); static const std::unordered_set kNSObjectMethods = @@ -1240,6 +1240,11 @@ bool ValidateObjCClassPrefix( const std::string prefix = file->options().objc_class_prefix(); const std::string package = file->package(); + // For files without packages, the can be registered as "no_package:PATH", + // allowing the expected prefixes file. + static const std::string no_package_prefix("no_package:"); + const std::string lookup_key = + package.empty() ? no_package_prefix + file->name() : package; // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for warnings. @@ -1247,7 +1252,7 @@ bool ValidateObjCClassPrefix( // Check: Error - See if there was an expected prefix for the package and // report if it doesn't match (wrong or missing). std::map::const_iterator package_match = - expected_package_prefixes.find(package); + expected_package_prefixes.find(lookup_key); if (package_match != expected_package_prefixes.end()) { // There was an entry, and... if (has_prefix && package_match->second == prefix) { @@ -1256,8 +1261,11 @@ bool ValidateObjCClassPrefix( } else { // ...it didn't match! *out_error = "error: Expected 'option objc_class_prefix = \"" + - package_match->second + "\";' for package '" + package + - "' in '" + file->name() + "'"; + package_match->second + "\";'"; + if (!package.empty()) { + *out_error += " for package '" + package + "'"; + } + *out_error += " in '" + file->name() + "'"; if (has_prefix) { *out_error += "; but found '" + prefix + "' instead"; } @@ -1286,35 +1294,12 @@ bool ValidateObjCClassPrefix( i != expected_package_prefixes.end(); ++i) { if (i->second == prefix) { other_package_for_prefix = i->first; - break; - } - } - - // Check: Warning - If the file does not have a package, check whether the - // prefix was declared is being used by another package or not. This is - // a special case for empty packages. - if (package.empty()) { - // The file does not have a package and ... - if (other_package_for_prefix.empty()) { - // ... no other package has declared that prefix. - std::cerr - << "protoc:0: warning: File '" << file->name() << "' has no " - << "package. Consider adding a new package to the proto and adding '" - << "new.package = " << prefix << "' to the expected prefixes file (" - << expected_prefixes_path << ")." << std::endl; - std::cerr.flush(); - } else { - // ... another package has declared the same prefix. - std::cerr - << "protoc:0: warning: File '" << file->name() << "' has no package " - << "and package '" << other_package_for_prefix << "' already uses '" - << prefix << "' as its prefix. Consider either adding a new package " - << "to the proto, or reusing one of the packages already using this " - << "prefix in the expected prefixes file (" - << expected_prefixes_path << ")." << std::endl; - std::cerr.flush(); + // Stop on the first real package listing, if it was a no_package file + // specific entry, keep looking to try and find a package one. + if (!HasPrefixString(other_package_for_prefix, no_package_prefix)) { + break; + } } - return true; } // Check: Error - Make sure the prefix wasn't expected for a different @@ -1323,14 +1308,20 @@ bool ValidateObjCClassPrefix( if (!other_package_for_prefix.empty()) { *out_error = "error: Found 'option objc_class_prefix = \"" + prefix + - "\";' in '" + file->name() + - "'; that prefix is already used for 'package " + - other_package_for_prefix + ";'. It can only be reused by listing " + - "it in the expected file (" + - expected_prefixes_path + ")."; + "\";' in '" + file->name() + "'; that prefix is already used for "; + if (HasPrefixString(other_package_for_prefix, no_package_prefix)) { + *out_error += "file '" + + StripPrefixString(other_package_for_prefix, no_package_prefix) + + "'."; + } else { + *out_error += "'package " + other_package_for_prefix + ";'."; + } + *out_error += + "It can only be reused by adding '" + lookup_key + " = " + prefix + + "' to the expected prefixes file (" + expected_prefixes_path + ")."; return false; // Only report first usage of the prefix. } - } // !prefix.empty() + } // !prefix.empty() && have_expected_prefix_file // Check: Warning - Make sure the prefix is is a reasonable value according // to Apple's rules (the checks above implicitly whitelist anything that @@ -1359,17 +1350,18 @@ bool ValidateObjCClassPrefix( if (prefixes_must_be_registered) { *out_error = "error: '" + file->name() + "' has 'option objc_class_prefix = \"" + - prefix + "\";', but it is not registered; add it to the expected " + - "prefixes file (" + expected_prefixes_path + ") for the package '" + - package + "'."; + prefix + "\";', but it is not registered. Add '" + lookup_key + " = " + + (prefix.empty() ? "\"\"" : prefix) + + "' to the expected prefixes file (" + expected_prefixes_path + ")."; return false; } std::cerr << "protoc:0: warning: Found unexpected 'option objc_class_prefix = \"" - << prefix << "\";' in '" << file->name() << "';" - << " consider adding it to the expected prefixes file (" - << expected_prefixes_path << ")." << std::endl; + << prefix << "\";' in '" << file->name() << "'; consider adding '" + << lookup_key << " = " << (prefix.empty() ? "\"\"" : prefix) + << "' to the expected prefixes file (" << expected_prefixes_path + << ")." << std::endl; std::cerr.flush(); } From a49dbd73d6f7ef87789ed640d532039a69f87a03 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Mon, 22 Nov 2021 10:14:26 -0800 Subject: [PATCH 069/207] Update BUILD Change all the instances of "darwin" to "osx" to be consistent. --- toolchain/BUILD | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 2b0a815091..9bd5dcdea2 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -105,7 +105,7 @@ cc_toolchain_config( ) cc_toolchain_config( - name = "darwin-aarch_64-config", + name = "osx-aarch_64-config", bit_flag = "-m64", cpp_flag = "-lc++", include_flag = [ @@ -117,11 +117,11 @@ cc_toolchain_config( target_cpu = "aarch64", target_full_name = "aarch64-apple-macosx11.3", toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", - toolchain_name = "darwin_aarch_64", + toolchain_name = "osx_aarch_64", ) cc_toolchain_config( - name = "darwin-x86_64-config", + name = "osx-x86_64-config", bit_flag = "-m64", cpp_flag = "-lc++", include_flag = [ @@ -133,5 +133,5 @@ cc_toolchain_config( target_cpu = "x86_64", target_full_name = "x86_64-apple-macosx11.3", toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", - toolchain_name = "darwin_x86_64", + toolchain_name = "osx_x86_64", ) From 3ad04bd4d9076799993e4d7941866c1bbd96a287 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Mon, 22 Nov 2021 10:40:37 -0800 Subject: [PATCH 070/207] Update BUILD Change darwin to osx in two more places. --- toolchain/BUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 9bd5dcdea2..fd4799ceec 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -5,8 +5,8 @@ package(default_visibility = ["//visibility:public"]) filegroup(name = "empty") TOOLCHAINS = { - "darwin-x86_64": "cc-compiler-osx-x86_64", - "darwin-aarch_64": "cc-compiler-osx-aarch_64", + "osx-x86_64": "cc-compiler-osx-x86_64", + "osx-aarch_64": "cc-compiler-osx-aarch_64", "linux-aarch_64": "cc-compiler-linux-aarch_64", "linux-ppcle_64": "cc-compiler-linux-ppcle_64", "linux-s390_64": "cc-compiler-linux-s390_64", From 221169d2acd4ee3f3cba688a5b79270908831912 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Mon, 22 Nov 2021 11:10:44 -0800 Subject: [PATCH 071/207] Update toolchains.bazelrc One more darwin->osx rewrite. --- toolchain/toolchains.bazelrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/toolchains.bazelrc b/toolchain/toolchains.bazelrc index 60fb6a4ea3..ba6c2237e8 100644 --- a/toolchain/toolchains.bazelrc +++ b/toolchain/toolchains.bazelrc @@ -6,5 +6,5 @@ build:linux-ppcle_64 --config=cross_config --cpu=linux-ppcle_64 build:linux-s390_64 --config=cross_config --cpu=linux-s390_64 build:linux-x86_32 --config=cross_config --cpu=linux-x86_32 build:linux-x86_64 --config=cross_config --cpu=linux-x86_64 -build:osx-aarch_64 --config=cross_config --cpu=darwin-aarch_64 -build:osx-x86_64 --config=cross_config --cpu=darwin-x86_64 +build:osx-aarch_64 --config=cross_config --cpu=osx-aarch_64 +build:osx-x86_64 --config=cross_config --cpu=osx-x86_64 From 73c57034aa14fcd3fcea58a64db7ae6dad6af08e Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 24 Nov 2021 19:48:16 +0000 Subject: [PATCH 072/207] Adding windows toolchains --- toolchain/BUILD | 38 +++++++++++++++++++++++++++++++ toolchain/cc_toolchain_config.bzl | 4 ++++ toolchain/toolchains.bazelrc | 2 ++ 3 files changed, 44 insertions(+) diff --git a/toolchain/BUILD b/toolchain/BUILD index 2b0a815091..46e0348f6e 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -12,6 +12,8 @@ TOOLCHAINS = { "linux-s390_64": "cc-compiler-linux-s390_64", "linux-x86_32": "cc-compiler-linux-x86_32", "linux-x86_64": "cc-compiler-linux-x86_64", + "win32": "cc-compiler-windows-x86_32", + "win64": "cc-compiler-windows-x86_64", } cc_toolchain_suite( @@ -135,3 +137,39 @@ cc_toolchain_config( toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", toolchain_name = "darwin_x86_64", ) + +cc_toolchain_config( + name = "win32-config", + bit_flag = "-m32", + cpp_flag = "-lstdc++", + extra_include = "/usr/lib/gcc/i686-w64-mingw32/10-posix/include", + extra_linker_flag = "-L/usr/lib/gcc/i686-w64-mingw32/10-posix", + include_flag = [ + "-I/usr/lib/gcc/i686-w64-mingw32/10-posix/include/c++", + "-I/usr/lib/gcc/i686-w64-mingw32/10-posix/include/c++/i686-w64-mingw32", + "-I/usr/i686-w64-mingw32/include" + ], + linker_path = "/usr/bin/ld", + target_cpu = "x86_32", + target_full_name = "i686-w64-mingw32", + toolchain_dir = "/usr/i686-w64-mingw32/include", + toolchain_name = "i686-w64-mingw32", +) + +cc_toolchain_config( + name = "win64-config", + bit_flag = "-m64", + cpp_flag = "-lstdc++", + extra_include = "/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include", + extra_linker_flag = "-L/usr/lib/gcc/x86_64-w64-mingw32/10-posix", + include_flag = [ + "-I/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/", + "-I/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/x86_64-w64-mingw32", + "-I/usr/x86_64-w64-mingw32/include" + ], + linker_path = "/usr/bin/ld", + target_cpu = "x86_64", + target_full_name = "x86_64-w64-mingw32", + toolchain_dir = "/usr/x86_64-w64-mingw32/include", + toolchain_name = "x86_64-w64-mingw32", +) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 1c0e33025d..f9b92675a4 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -86,6 +86,7 @@ def _impl(ctx): "-B" + ctx.attr.linker_path, ctx.attr.cpp_flag, "--target=" + ctx.attr.target_full_name, + ctx.attr.extra_linker_flag, ], ), ], @@ -142,6 +143,7 @@ def _impl(ctx): compiler = "clang", cxx_builtin_include_directories = [ ctx.attr.toolchain_dir, + ctx.attr.extra_include, "/usr/include", "/usr/local/include", "/usr/local/lib/clang", @@ -161,6 +163,8 @@ cc_toolchain_config = rule( "abi_version": attr.string(default = "local"), "bit_flag": attr.string(mandatory = True, values = ["-m32", "-m64"]), "cpp_flag": attr.string(mandatory = True), + "extra_include": attr.string(mandatory = False), + "extra_linker_flag": attr.string(mandatory = False), "include_flag": attr.string_list(), "linker_path": attr.string(mandatory = True), "sysroot": attr.string(mandatory = False), diff --git a/toolchain/toolchains.bazelrc b/toolchain/toolchains.bazelrc index 60fb6a4ea3..e28aa8051d 100644 --- a/toolchain/toolchains.bazelrc +++ b/toolchain/toolchains.bazelrc @@ -8,3 +8,5 @@ build:linux-x86_32 --config=cross_config --cpu=linux-x86_32 build:linux-x86_64 --config=cross_config --cpu=linux-x86_64 build:osx-aarch_64 --config=cross_config --cpu=darwin-aarch_64 build:osx-x86_64 --config=cross_config --cpu=darwin-x86_64 +build:win32 --config=cross_config --cpu=win32 +build:win64 --config=cross_config --cpu=win64 From e4e26dfdf7c8bb82f29debcb7929fe517c848e39 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 24 Nov 2021 21:27:54 +0000 Subject: [PATCH 073/207] Name protoc artifacts by their cpu and os --- BUILD | 2 +- protobuf_release.bzl | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/BUILD b/BUILD index 87bd219c07..81f550b946 100644 --- a/BUILD +++ b/BUILD @@ -573,7 +573,7 @@ package_naming( pkg_zip( name = "protoc_release", - package_file_name = "protoc-{version}-{cpu}.zip", + package_file_name = "protoc-{version}-{platform}.zip", package_variables = ":protoc_pkg_naming", srcs = [ ":protoc_files", diff --git a/protobuf_release.bzl b/protobuf_release.bzl index e007e004d7..cac0a0c52a 100644 --- a/protobuf_release.bzl +++ b/protobuf_release.bzl @@ -12,8 +12,28 @@ def _package_naming_impl(ctx): # infer from the current cpp toolchain. toolchain = find_cpp_toolchain(ctx) - values["cpu"] = toolchain.cpu - + cpu = toolchain.cpu + system_name = toolchain.target_gnu_system_name + + # rename cpus to match what we want artifacts to be + if cpu == "systemz": + cpu = "s390_64" + elif cpu == "aarch64": + cpu = "aarch_64" + + # use the system name to determine the os and then create platform names + if "apple" in system_name: + values["platform"] = "osx-" + cpu + elif "linux" in system_name: + values["platform"] = "linux-" + cpu + elif "mingw" in system_name: + if "cpu" == "x86_64": + values["platform"] = "win64" + else: + values["platform"] = "win32" + else: + values["platform"] = "unknown" + return PackageVariablesInfo(values = values) From bf481851d8d37ee0c78be419431e55a6f64098e8 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 24 Nov 2021 14:00:20 -0800 Subject: [PATCH 074/207] Remove unused includes from unit tests (#9251) --- .../protobuf/compiler/csharp/csharp_generator_unittest.cc | 2 -- .../protobuf/compiler/objectivec/objectivec_helpers_unittest.cc | 1 - 2 files changed, 3 deletions(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc index 75acda026c..ae975baa02 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc @@ -37,9 +37,7 @@ #include #include -#include #include -#include namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc index 3c5eda2265..9410056284 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc @@ -30,7 +30,6 @@ #include #include -#include #include namespace google { From 1ced82f8fdd3c5541543bff6876d75b888e36101 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 24 Nov 2021 14:59:57 -0800 Subject: [PATCH 075/207] Use C++11 integer types and fully qualify std::string (#9253) --- src/google/protobuf/compiler/command_line_interface.cc | 4 +++- .../protobuf/compiler/csharp/csharp_bootstrap_unittest.cc | 2 +- src/google/protobuf/compiler/csharp/csharp_field_base.cc | 2 +- src/google/protobuf/compiler/csharp/csharp_message.cc | 2 +- .../compiler/objectivec/objectivec_helpers_unittest.cc | 4 ++-- src/google/protobuf/compiler/php/php_generator.cc | 6 +++--- .../protobuf/compiler/ruby/ruby_generator_unittest.cc | 2 +- src/google/protobuf/stubs/common.h | 4 ---- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index bfc6b0552d..6cd17ea558 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -1675,7 +1675,9 @@ CommandLineInterface::InterpretArgument(const std::string& name, // file names (e.g. foo\*.proto), so we do it ourselves. switch (google::protobuf::io::win32::ExpandWildcards( value, - [this](const string& path) { this->input_files_.push_back(path); })) { + [this](const std::string& path) { + this->input_files_.push_back(path); + })) { case google::protobuf::io::win32::ExpandWildcardsResult::kSuccess: break; case google::protobuf::io::win32::ExpandWildcardsResult:: diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index 86bacf8103..44ecfdedbe 100644 --- a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc @@ -116,7 +116,7 @@ class GenerateAndTest { &context_, &error_)); context_.ExpectFileMatches(file1, file2); } - void SetParameter(string parameter) { + void SetParameter(std::string parameter) { parameter_ = parameter; } diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index 477b49e5f6..146ca9e5bd 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -61,7 +61,7 @@ void FieldGeneratorBase::SetCommonFieldVariables( part_tag_size /= 2; } uint tag = internal::WireFormat::MakeTag(descriptor_); - uint8 tag_array[5]; + uint8_t tag_array[5]; io::CodedOutputStream::WriteTagToArray(tag, tag_array); std::string tag_bytes = StrCat(tag_array[0]); for (int i = 1; i < part_tag_size; i++) { diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 998087492e..9dbce03c02 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -717,7 +717,7 @@ void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_pars const FieldDescriptor* field = fields_by_number()[i]; internal::WireFormatLite::WireType wt = internal::WireFormat::WireTypeForFieldType(field->type()); - uint32 tag = internal::WireFormatLite::MakeTag(field->number(), wt); + uint32_t tag = internal::WireFormatLite::MakeTag(field->number(), wt); // Handle both packed and unpacked repeated fields with the same Read*Array call; // the two generated cases are the packed and unpacked tags. // TODO(jonskeet): Check that is_packable is equivalent to diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc index 9410056284..7ae6a9275f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc @@ -153,7 +153,7 @@ TEST(ObjCHelper, TextFormatDecodeData_RawStrings) { EXPECT_EQ(4, decode_data.num_entries()); - uint8 expected_data[] = { + uint8_t expected_data[] = { 0x4, 0x1, 0x0, 'z', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 'J', 0x0, 0x3, 0x0, 'a', 'b', 'c', 'd', 'e', 'z', 'g', 'h', 'I', 'J', 0x0, @@ -178,7 +178,7 @@ TEST(ObjCHelper, TextFormatDecodeData_ByteCodes) { EXPECT_EQ(5, decode_data.num_entries()); - uint8 expected_data[] = { + uint8_t expected_data[] = { 0x5, // All as is (00 op) 0x1, 0x0A, 0x0, diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 4b7fda91d4..6b8ee524aa 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -83,14 +83,14 @@ struct Options { bool is_descriptor = false; bool aggregate_metadata = false; bool gen_c_wkt = false; - std::set aggregate_metadata_prefixes; + std::set aggregate_metadata_prefixes; }; namespace { // Forward decls. std::string PhpName(const std::string& full_name, const Options& options); -std::string IntToString(int32 value); +std::string IntToString(int32_t value); std::string FilenameToClassname(const std::string& filename); std::string GeneratedMetadataFileName(const FileDescriptor* file, const Options& options); @@ -430,7 +430,7 @@ std::string GeneratedServiceFileName(const ServiceDescriptor* service, return result + ".php"; } -std::string IntToString(int32 value) { +std::string IntToString(int32_t value) { std::ostringstream os; os << value; return os.str(); diff --git a/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc b/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc index 040b6c981c..c3ce1d3684 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc @@ -57,7 +57,7 @@ std::string FindRubyTestDir() { // Some day, we may integrate build systems between protoc and the language // extensions to the point where we can do this test in a more automated way. -void RubyTest(string proto_file, string import_proto_file = "") { +void RubyTest(std::string proto_file, std::string import_proto_file = "") { std::string ruby_tests = FindRubyTestDir(); google::protobuf::compiler::CommandLineInterface cli; diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index c32503a6de..c8f238b474 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -189,10 +189,6 @@ class FatalException : public std::exception { }; #endif -// This is at the end of the file instead of the beginning to work around a bug -// in some versions of MSVC. -using std::string; - } // namespace protobuf } // namespace google From 7d9c9ebd5dff4b52162b80f2b4ad75bdb571b77b Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 24 Nov 2021 22:59:57 +0000 Subject: [PATCH 076/207] Add error throwing --- protobuf_release.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf_release.bzl b/protobuf_release.bzl index cac0a0c52a..7ed3cc7c8e 100644 --- a/protobuf_release.bzl +++ b/protobuf_release.bzl @@ -32,7 +32,7 @@ def _package_naming_impl(ctx): else: values["platform"] = "win32" else: - values["platform"] = "unknown" + fail("Unrecognized platform") return PackageVariablesInfo(values = values) From 19eaec02e1cdb2d8747c4d34fa0ee8f555d9d560 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 29 Nov 2021 12:31:46 -0500 Subject: [PATCH 077/207] delete unused files (#9262) * delete unused files * update Makefile --- Makefile.am | 2 - .../protobuf/Proto2MessageInfoFactory.java | 892 ------------------ .../protobuf/Proto3MessageInfoFactory.java | 506 ---------- 3 files changed, 1400 deletions(-) delete mode 100644 java/core/src/test/java/com/google/protobuf/Proto2MessageInfoFactory.java delete mode 100644 java/core/src/test/java/com/google/protobuf/Proto3MessageInfoFactory.java diff --git a/Makefile.am b/Makefile.am index a83f9aaf41..712f5ae397 100644 --- a/Makefile.am +++ b/Makefile.am @@ -465,13 +465,11 @@ java_EXTRA_DIST= java/core/src/test/java/com/google/protobuf/Proto2ExtensionLookupSchemaTest.java \ java/core/src/test/java/com/google/protobuf/Proto2LiteSchemaTest.java \ java/core/src/test/java/com/google/protobuf/Proto2MessageFactory.java \ - java/core/src/test/java/com/google/protobuf/Proto2MessageInfoFactory.java \ java/core/src/test/java/com/google/protobuf/Proto2MessageLiteFactory.java \ java/core/src/test/java/com/google/protobuf/Proto2SchemaTest.java \ java/core/src/test/java/com/google/protobuf/Proto2UnknownEnumValueTest.java \ java/core/src/test/java/com/google/protobuf/Proto3LiteSchemaTest.java \ java/core/src/test/java/com/google/protobuf/Proto3MessageFactory.java \ - java/core/src/test/java/com/google/protobuf/Proto3MessageInfoFactory.java \ java/core/src/test/java/com/google/protobuf/Proto3MessageLiteFactory.java \ java/core/src/test/java/com/google/protobuf/Proto3MessageLiteInfoFactory.java \ java/core/src/test/java/com/google/protobuf/Proto3SchemaTest.java \ diff --git a/java/core/src/test/java/com/google/protobuf/Proto2MessageInfoFactory.java b/java/core/src/test/java/com/google/protobuf/Proto2MessageInfoFactory.java deleted file mode 100644 index af671b22e4..0000000000 --- a/java/core/src/test/java/com/google/protobuf/Proto2MessageInfoFactory.java +++ /dev/null @@ -1,892 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package com.google.protobuf; - -import static com.google.protobuf.FieldInfo.forField; -import static com.google.protobuf.FieldInfo.forFieldWithEnumVerifier; -import static com.google.protobuf.FieldInfo.forMapField; -import static com.google.protobuf.FieldInfo.forOneofMemberField; -import static com.google.protobuf.FieldInfo.forProto2OptionalField; -import static com.google.protobuf.FieldInfo.forProto2RequiredField; -import static com.google.protobuf.FieldInfo.forRepeatedMessageField; - -import com.google.protobuf.testing.Proto2Testing; -import com.google.protobuf.testing.Proto2Testing.Proto2Empty; -import com.google.protobuf.testing.Proto2Testing.Proto2Message; -import com.google.protobuf.testing.Proto2Testing.Proto2Message.FieldGroup49; -import com.google.protobuf.testing.Proto2Testing.Proto2Message.FieldGroup69; -import com.google.protobuf.testing.Proto2Testing.Proto2Message.FieldGroupList51; -import com.google.protobuf.testing.Proto2Testing.Proto2Message.FieldRequiredGroup88; -import com.google.protobuf.testing.Proto2Testing.Proto2Message.RequiredNestedMessage; -import com.google.protobuf.testing.Proto2Testing.Proto2Message.TestEnum; -import com.google.protobuf.testing.Proto2Testing.Proto2MessageWithExtensions; -import com.google.protobuf.testing.Proto2Testing.Proto2MessageWithMaps; -import java.lang.reflect.Field; - -/** A factory that generates a hard-coded message info for {@link Proto2Message}. */ -public final class Proto2MessageInfoFactory implements MessageInfoFactory { - private static final Proto2MessageInfoFactory INSTANCE = new Proto2MessageInfoFactory(); - - private Proto2MessageInfoFactory() {} - - public static Proto2MessageInfoFactory getInstance() { - return INSTANCE; - } - - @Override - public boolean isSupported(Class clazz) { - return true; - } - - @Override - public MessageInfo messageInfoFor(Class clazz) { - if (Proto2Message.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto2Message(); - } else if (FieldGroup49.class.isAssignableFrom(clazz)) { - return newMessageInfoForFieldGroup49(); - } else if (FieldGroupList51.class.isAssignableFrom(clazz)) { - return newMessageInfoForFieldGroupList51(); - } else if (FieldGroup69.class.isAssignableFrom(clazz)) { - return newMessageInfoForFieldGroup69(); - } else if (FieldRequiredGroup88.class.isAssignableFrom(clazz)) { - return newMessageInfoForFieldRequiredGroup88(); - } else if (RequiredNestedMessage.class.isAssignableFrom(clazz)) { - return newMessageInfoForRequiredNestedMessage(); - } else if (Proto2Empty.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto2Empty(); - } else if (Proto2MessageWithExtensions.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto2MessageWithExtensions(); - } else if (Proto2Testing.FieldGroup49.class.isAssignableFrom(clazz)) { - return newMessageInfoForExtensionFieldGroup49(); - } else if (Proto2Testing.FieldGroupList51.class.isAssignableFrom(clazz)) { - return newMessageInfoForExtensionFieldGroupList51(); - } else if (Proto2Testing.Proto2MessageWithMaps.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto2MessageWithMaps(); - } else { - throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); - } - } - - /** - * Creates a new hard-coded info for {@link Proto2Message}. Each time this is called, we manually - * go through the entire process of what a message would do if it self-registered its own info, - * including looking up each field by name. This is done for benchmarking purposes, so that we get - * a more accurate representation of the time it takes to perform this process. - */ - private static StructuralMessageInfo newMessageInfoForProto2Message() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(50); - builder.withCheckInitialized( - new int[] { - 10, 27, 62, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, - }); - lookupFieldsByName(builder); - return builder.build(); - } - - private static void lookupFieldsByName(StructuralMessageInfo.Builder builder) { - Field bitField0 = field("bitField0_"); - - builder.withDefaultInstance(Proto2Message.getDefaultInstance()); - builder.withSyntax(ProtoSyntax.PROTO2); - builder.withField( - forProto2OptionalField( - field("fieldDouble1_"), 1, FieldType.DOUBLE, bitField0, 0x00000001, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldFloat2_"), 2, FieldType.FLOAT, bitField0, 0x00000002, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldInt643_"), 3, FieldType.INT64, bitField0, 0x00000004, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldUint644_"), 4, FieldType.UINT64, bitField0, 0x00000008, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldInt325_"), 5, FieldType.INT32, bitField0, 0x00000010, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldFixed646_"), 6, FieldType.FIXED64, bitField0, 0x00000020, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldFixed327_"), 7, FieldType.FIXED32, bitField0, 0x00000040, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldBool8_"), 8, FieldType.BOOL, bitField0, 0x00000080, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldString9_"), 9, FieldType.STRING, bitField0, 0x00000100, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldMessage10_"), 10, FieldType.MESSAGE, bitField0, 0x00000200, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldBytes11_"), 11, FieldType.BYTES, bitField0, 0x00000400, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldUint3212_"), 12, FieldType.UINT32, bitField0, 0x00000800, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldEnum13_"), - 13, - FieldType.ENUM, - bitField0, - 0x00001000, - false, - asVerifier(TestEnum.internalGetValueMap()))); - builder.withField( - forProto2OptionalField( - field("fieldSfixed3214_"), 14, FieldType.SFIXED32, bitField0, 0x00002000, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldSfixed6415_"), 15, FieldType.SFIXED64, bitField0, 0x00004000, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldSint3216_"), 16, FieldType.SINT32, bitField0, 0x00008000, false, null)); - builder.withField( - forProto2OptionalField( - field("fieldSint6417_"), 17, FieldType.SINT64, bitField0, 0x00010000, false, null)); - builder.withField(forField(field("fieldDoubleList18_"), 18, FieldType.DOUBLE_LIST, false)); - builder.withField(forField(field("fieldFloatList19_"), 19, FieldType.FLOAT_LIST, false)); - builder.withField(forField(field("fieldInt64List20_"), 20, FieldType.INT64_LIST, false)); - builder.withField(forField(field("fieldUint64List21_"), 21, FieldType.UINT64_LIST, false)); - builder.withField(forField(field("fieldInt32List22_"), 22, FieldType.INT32_LIST, false)); - builder.withField(forField(field("fieldFixed64List23_"), 23, FieldType.FIXED64_LIST, false)); - builder.withField(forField(field("fieldFixed32List24_"), 24, FieldType.FIXED32_LIST, false)); - builder.withField(forField(field("fieldBoolList25_"), 25, FieldType.BOOL_LIST, false)); - builder.withField(forField(field("fieldStringList26_"), 26, FieldType.STRING_LIST, false)); - builder.withField( - forRepeatedMessageField( - field("fieldMessageList27_"), 27, FieldType.MESSAGE_LIST, Proto2Message.class)); - builder.withField(forField(field("fieldBytesList28_"), 28, FieldType.BYTES_LIST, false)); - builder.withField(forField(field("fieldUint32List29_"), 29, FieldType.UINT32_LIST, false)); - builder.withField( - forFieldWithEnumVerifier( - field("fieldEnumList30_"), - 30, - FieldType.ENUM_LIST, - asVerifier(TestEnum.internalGetValueMap()))); - builder.withField(forField(field("fieldSfixed32List31_"), 31, FieldType.SFIXED32_LIST, false)); - builder.withField(forField(field("fieldSfixed64List32_"), 32, FieldType.SFIXED64_LIST, false)); - builder.withField(forField(field("fieldSint32List33_"), 33, FieldType.SINT32_LIST, false)); - builder.withField(forField(field("fieldSint64List34_"), 34, FieldType.SINT64_LIST, false)); - builder.withField( - forField(field("fieldDoubleListPacked35_"), 35, FieldType.DOUBLE_LIST_PACKED, false)); - builder.withField( - forField(field("fieldFloatListPacked36_"), 36, FieldType.FLOAT_LIST_PACKED, false)); - builder.withField( - forField(field("fieldInt64ListPacked37_"), 37, FieldType.INT64_LIST_PACKED, false)); - builder.withField( - forField(field("fieldUint64ListPacked38_"), 38, FieldType.UINT64_LIST_PACKED, false)); - builder.withField( - forField(field("fieldInt32ListPacked39_"), 39, FieldType.INT32_LIST_PACKED, false)); - builder.withField( - forField(field("fieldFixed64ListPacked40_"), 40, FieldType.FIXED64_LIST_PACKED, false)); - builder.withField( - forField(field("fieldFixed32ListPacked41_"), 41, FieldType.FIXED32_LIST_PACKED, false)); - builder.withField( - forField(field("fieldBoolListPacked42_"), 42, FieldType.BOOL_LIST_PACKED, false)); - builder.withField( - forField(field("fieldUint32ListPacked43_"), 43, FieldType.UINT32_LIST_PACKED, false)); - builder.withField( - forFieldWithEnumVerifier( - field("fieldEnumListPacked44_"), - 44, - FieldType.ENUM_LIST_PACKED, - asVerifier(TestEnum.internalGetValueMap()))); - builder.withField( - forField(field("fieldSfixed32ListPacked45_"), 45, FieldType.SFIXED32_LIST_PACKED, false)); - builder.withField( - forField(field("fieldSfixed64ListPacked46_"), 46, FieldType.SFIXED64_LIST_PACKED, false)); - builder.withField( - forField(field("fieldSint32ListPacked47_"), 47, FieldType.SINT32_LIST_PACKED, false)); - builder.withField( - forField(field("fieldSint64ListPacked48_"), 48, FieldType.SINT64_LIST_PACKED, false)); - - builder.withField( - forProto2OptionalField( - field("fieldGroup49_"), 49, FieldType.GROUP, bitField0, 0x00020000, false, null)); - builder.withField( - forRepeatedMessageField( - field("fieldGroupList51_"), - 51, - FieldType.GROUP_LIST, - Proto2Message.FieldGroupList51.class)); - - OneofInfo oneof = new OneofInfo(0, field("testOneofCase_"), field("testOneof_")); - builder.withField(forOneofMemberField(53, FieldType.DOUBLE, oneof, Double.class, false, null)); - builder.withField(forOneofMemberField(54, FieldType.FLOAT, oneof, Float.class, false, null)); - builder.withField(forOneofMemberField(55, FieldType.INT64, oneof, Long.class, false, null)); - builder.withField(forOneofMemberField(56, FieldType.UINT64, oneof, Long.class, false, null)); - builder.withField(forOneofMemberField(57, FieldType.INT32, oneof, Integer.class, false, null)); - builder.withField(forOneofMemberField(58, FieldType.FIXED64, oneof, Long.class, false, null)); - builder.withField( - forOneofMemberField(59, FieldType.FIXED32, oneof, Integer.class, false, null)); - builder.withField(forOneofMemberField(60, FieldType.BOOL, oneof, Boolean.class, false, null)); - builder.withField(forOneofMemberField(61, FieldType.STRING, oneof, String.class, false, null)); - builder.withField( - forOneofMemberField(62, FieldType.MESSAGE, oneof, Proto2Message.class, false, null)); - builder.withField( - forOneofMemberField(63, FieldType.BYTES, oneof, ByteString.class, false, null)); - builder.withField(forOneofMemberField(64, FieldType.UINT32, oneof, Integer.class, false, null)); - builder.withField( - forOneofMemberField(65, FieldType.SFIXED32, oneof, Integer.class, false, null)); - builder.withField(forOneofMemberField(66, FieldType.SFIXED64, oneof, Long.class, false, null)); - builder.withField(forOneofMemberField(67, FieldType.SINT32, oneof, Integer.class, false, null)); - builder.withField(forOneofMemberField(68, FieldType.SINT64, oneof, Long.class, false, null)); - builder.withField( - forOneofMemberField( - 69, FieldType.GROUP, oneof, Proto2Message.FieldGroup69.class, false, null)); - - Field bitField1 = field("bitField1_"); - builder.withField( - forProto2RequiredField( - field("fieldRequiredDouble71_"), - 71, - FieldType.DOUBLE, - bitField1, - 0x00000008, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredFloat72_"), - 72, - FieldType.FLOAT, - bitField1, - 0x00000010, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredInt6473_"), - 73, - FieldType.INT64, - bitField1, - 0x00000020, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredUint6474_"), - 74, - FieldType.UINT64, - bitField1, - 0x00000040, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredInt3275_"), - 75, - FieldType.INT32, - bitField1, - 0x00000080, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredFixed6476_"), - 76, - FieldType.FIXED64, - bitField1, - 0x00000100, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredFixed3277_"), - 77, - FieldType.FIXED32, - bitField1, - 0x00000200, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredBool78_"), 78, FieldType.BOOL, bitField1, 0x00000400, false, null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredString79_"), - 79, - FieldType.STRING, - bitField1, - 0x00000800, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredMessage80_"), - 80, - FieldType.MESSAGE, - bitField1, - 0x00001000, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredBytes81_"), - 81, - FieldType.BYTES, - bitField1, - 0x00002000, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredUint3282_"), - 82, - FieldType.UINT32, - bitField1, - 0x00004000, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredEnum83_"), - 83, - FieldType.ENUM, - bitField1, - 0x00008000, - false, - asVerifier(TestEnum.internalGetValueMap()))); - builder.withField( - forProto2RequiredField( - field("fieldRequiredSfixed3284_"), - 84, - FieldType.SFIXED32, - bitField1, - 0x00010000, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredSfixed6485_"), - 85, - FieldType.SFIXED64, - bitField1, - 0x00020000, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredSint3286_"), - 86, - FieldType.SINT32, - bitField1, - 0x00040000, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredSint6487_"), - 87, - FieldType.SINT64, - bitField1, - 0x00080000, - false, - null)); - builder.withField( - forProto2RequiredField( - field("fieldRequiredGroup88_"), - 88, - FieldType.GROUP, - bitField1, - 0x00100000, - false, - null)); - } - - private static StructuralMessageInfo newMessageInfoForFieldGroup49() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(FieldGroup49.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(FieldGroup49.class, "fieldInt3250_"), - 50, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForFieldGroupList51() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(FieldGroupList51.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(FieldGroupList51.class, "fieldInt3252_"), - 52, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForFieldGroup69() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(FieldGroup69.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(FieldGroup69.class, "fieldInt3270_"), - 70, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForRequiredNestedMessage() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(RequiredNestedMessage.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(RequiredNestedMessage.class, "value_"), - 1, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForFieldRequiredGroup88() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(FieldRequiredGroup88.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(FieldRequiredGroup88.class, "fieldInt3289_"), - 89, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForProto2Empty() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForProto2MessageWithExtensions() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(0); - builder.withSyntax(ProtoSyntax.PROTO2); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForExtensionFieldGroup49() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(Proto2Testing.FieldGroup49.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(Proto2Testing.FieldGroup49.class, "fieldInt3250_"), - 50, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForExtensionFieldGroupList51() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(Proto2Testing.FieldGroupList51.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(Proto2Testing.FieldGroupList51.class, "fieldInt3252_"), - 52, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForProto2MessageWithMaps() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(); - builder.withCheckInitialized( - new int[] { - 10, 27, 44, 61, 78, 95, 112, 129, 146, 163, 180, 197, - }); - builder.withSyntax(ProtoSyntax.PROTO2); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_bool_1", 1)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_bytes_2", 2)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_double_3", 3)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_enum_4", 4)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_fixed32_5", 5)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_fixed64_6", 6)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_float_7", 7)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_int32_8", 8)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_int64_9", 9)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_message_10", 10)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_sfixed32_11", 11)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_sfixed64_12", 12)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_sint32_13", 13)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_sint64_14", 14)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_string_15", 15)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_uint32_16", 16)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_bool_uint64_17", 17)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_bool_18", 18)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_bytes_19", 19)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_double_20", 20)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_enum_21", 21)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_fixed32_22", 22)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_fixed64_23", 23)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_float_24", 24)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_int32_25", 25)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_int64_26", 26)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_message_27", 27)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_sfixed32_28", 28)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_sfixed64_29", 29)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_sint32_30", 30)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_sint64_31", 31)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_string_32", 32)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_uint32_33", 33)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed32_uint64_34", 34)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_bool_35", 35)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_bytes_36", 36)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_double_37", 37)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_enum_38", 38)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_fixed32_39", 39)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_fixed64_40", 40)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_float_41", 41)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_int32_42", 42)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_int64_43", 43)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_message_44", 44)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_sfixed32_45", 45)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_sfixed64_46", 46)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_sint32_47", 47)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_sint64_48", 48)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_string_49", 49)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_uint32_50", 50)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_fixed64_uint64_51", 51)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_bool_52", 52)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_bytes_53", 53)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_double_54", 54)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_enum_55", 55)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_fixed32_56", 56)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_fixed64_57", 57)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_float_58", 58)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_int32_59", 59)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_int64_60", 60)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_message_61", 61)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_sfixed32_62", 62)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_sfixed64_63", 63)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_sint32_64", 64)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_sint64_65", 65)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_string_66", 66)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_uint32_67", 67)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int32_uint64_68", 68)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_bool_69", 69)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_bytes_70", 70)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_double_71", 71)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_enum_72", 72)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_fixed32_73", 73)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_fixed64_74", 74)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_float_75", 75)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_int32_76", 76)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_int64_77", 77)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_message_78", 78)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_sfixed32_79", 79)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_sfixed64_80", 80)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_sint32_81", 81)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_sint64_82", 82)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_string_83", 83)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_uint32_84", 84)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_int64_uint64_85", 85)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_bool_86", 86)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_bytes_87", 87)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_double_88", 88)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_enum_89", 89)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_fixed32_90", 90)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_fixed64_91", 91)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_float_92", 92)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_int32_93", 93)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_int64_94", 94)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_message_95", 95)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_sfixed32_96", 96)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_sfixed64_97", 97)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_sint32_98", 98)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_sint64_99", 99)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_string_100", 100)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_uint32_101", 101)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed32_uint64_102", 102)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_bool_103", 103)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_bytes_104", 104)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_double_105", 105)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_enum_106", 106)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_fixed32_107", 107)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_fixed64_108", 108)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_float_109", 109)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_int32_110", 110)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_int64_111", 111)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_message_112", 112)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_sfixed32_113", 113)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_sfixed64_114", 114)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_sint32_115", 115)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_sint64_116", 116)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_string_117", 117)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_uint32_118", 118)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sfixed64_uint64_119", 119)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_bool_120", 120)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_bytes_121", 121)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_double_122", 122)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_enum_123", 123)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_fixed32_124", 124)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_fixed64_125", 125)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_float_126", 126)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_int32_127", 127)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_int64_128", 128)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_message_129", 129)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_sfixed32_130", 130)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_sfixed64_131", 131)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_sint32_132", 132)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_sint64_133", 133)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_string_134", 134)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_uint32_135", 135)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint32_uint64_136", 136)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_bool_137", 137)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_bytes_138", 138)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_double_139", 139)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_enum_140", 140)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_fixed32_141", 141)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_fixed64_142", 142)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_float_143", 143)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_int32_144", 144)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_int64_145", 145)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_message_146", 146)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_sfixed32_147", 147)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_sfixed64_148", 148)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_sint32_149", 149)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_sint64_150", 150)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_string_151", 151)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_uint32_152", 152)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_sint64_uint64_153", 153)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_bool_154", 154)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_bytes_155", 155)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_double_156", 156)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_enum_157", 157)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_fixed32_158", 158)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_fixed64_159", 159)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_float_160", 160)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_int32_161", 161)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_int64_162", 162)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_message_163", 163)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_sfixed32_164", 164)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_sfixed64_165", 165)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_sint32_166", 166)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_sint64_167", 167)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_string_168", 168)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_uint32_169", 169)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_string_uint64_170", 170)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_bool_171", 171)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_bytes_172", 172)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_double_173", 173)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_enum_174", 174)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_fixed32_175", 175)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_fixed64_176", 176)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_float_177", 177)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_int32_178", 178)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_int64_179", 179)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_message_180", 180)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_sfixed32_181", 181)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_sfixed64_182", 182)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_sint32_183", 183)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_sint64_184", 184)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_string_185", 185)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_uint32_186", 186)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint32_uint64_187", 187)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_bool_188", 188)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_bytes_189", 189)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_double_190", 190)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_enum_191", 191)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_fixed32_192", 192)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_fixed64_193", 193)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_float_194", 194)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_int32_195", 195)); - builder.withField(mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_int64_196", 196)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_message_197", 197)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_sfixed32_198", 198)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_sfixed64_199", 199)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_sint32_200", 200)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_sint64_201", 201)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_string_202", 202)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_uint32_203", 203)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_uint64_204", 204)); - - return builder.build(); - } - - private static FieldInfo mapFieldInfo(Class clazz, String fieldName, int fieldNumber) { - try { - return forMapField( - field(clazz, SchemaUtil.toCamelCase(fieldName, false) + "_"), - fieldNumber, - SchemaUtil.getMapDefaultEntry(clazz, fieldName), - fieldName.contains("_enum_") ? asVerifier(TestEnum.internalGetValueMap()) : null); - } catch (Throwable t) { - throw new RuntimeException(t); - } - } - - - private static Field field(String name) { - return field(Proto2Message.class, name); - } - - private static Field field(Class clazz, String name) { - try { - return clazz.getDeclaredField(name); - } catch (NoSuchFieldException | SecurityException e) { - throw new RuntimeException(e); - } - } - - private static Internal.EnumVerifier asVerifier(final Internal.EnumLiteMap map) { - return new Internal.EnumVerifier() { - @Override - public boolean isInRange(int number) { - return map.findValueByNumber(number) != null; - } - }; - } -} diff --git a/java/core/src/test/java/com/google/protobuf/Proto3MessageInfoFactory.java b/java/core/src/test/java/com/google/protobuf/Proto3MessageInfoFactory.java deleted file mode 100644 index 364071b35d..0000000000 --- a/java/core/src/test/java/com/google/protobuf/Proto3MessageInfoFactory.java +++ /dev/null @@ -1,506 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package com.google.protobuf; - -import static com.google.protobuf.FieldInfo.forField; -import static com.google.protobuf.FieldInfo.forMapField; -import static com.google.protobuf.FieldInfo.forOneofMemberField; -import static com.google.protobuf.FieldInfo.forRepeatedMessageField; - -import com.google.protobuf.testing.Proto2Testing.Proto2MessageWithMaps; -import com.google.protobuf.testing.Proto3Testing.Proto3Empty; -import com.google.protobuf.testing.Proto3Testing.Proto3Message; -import com.google.protobuf.testing.Proto3Testing.Proto3MessageWithMaps; -import java.lang.reflect.Field; - -/** A factory that generates a hard-coded info for {@link Proto3Message}. */ -public final class Proto3MessageInfoFactory implements MessageInfoFactory { - private static final Proto3MessageInfoFactory INSTANCE = new Proto3MessageInfoFactory(); - - private Proto3MessageInfoFactory() {} - - public static Proto3MessageInfoFactory getInstance() { - return INSTANCE; - } - - @Override - public boolean isSupported(Class clazz) { - return true; - } - - @Override - public MessageInfo messageInfoFor(Class clazz) { - if (Proto3Message.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto3Message(); - } else if (Proto3Empty.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto3Empty(); - } else if (Proto3MessageWithMaps.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto3MessageWithMaps(); - } else { - throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); - } - } - - /** - * Creates a new hard-coded info for {@link Proto3Message}. Each time this is called, we manually - * go through the entire process of what a message would do if it self-registered its own info, - * including looking up each field by name. This is done for benchmarking purposes, so that we get - * a more accurate representation of the time it takes to perform this process. - */ - private static StructuralMessageInfo newMessageInfoForProto3Message() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(48); - lookupFieldsByName(builder); - return builder.build(); - } - - private static void lookupFieldsByName(StructuralMessageInfo.Builder builder) { - builder.withDefaultInstance(Proto3Message.getDefaultInstance()); - builder.withSyntax(ProtoSyntax.PROTO3); - builder.withField(forField(field("fieldDouble1_"), 1, FieldType.DOUBLE, true)); - builder.withField(forField(field("fieldFloat2_"), 2, FieldType.FLOAT, true)); - builder.withField(forField(field("fieldInt643_"), 3, FieldType.INT64, true)); - builder.withField(forField(field("fieldUint644_"), 4, FieldType.UINT64, true)); - builder.withField(forField(field("fieldInt325_"), 5, FieldType.INT32, true)); - builder.withField(forField(field("fieldFixed646_"), 6, FieldType.FIXED64, true)); - builder.withField(forField(field("fieldFixed327_"), 7, FieldType.FIXED32, true)); - builder.withField(forField(field("fieldBool8_"), 8, FieldType.BOOL, true)); - builder.withField(forField(field("fieldString9_"), 9, FieldType.STRING, true)); - builder.withField(forField(field("fieldMessage10_"), 10, FieldType.MESSAGE, true)); - builder.withField(forField(field("fieldBytes11_"), 11, FieldType.BYTES, true)); - builder.withField(forField(field("fieldUint3212_"), 12, FieldType.UINT32, true)); - builder.withField(forField(field("fieldEnum13_"), 13, FieldType.ENUM, true)); - builder.withField(forField(field("fieldSfixed3214_"), 14, FieldType.SFIXED32, true)); - builder.withField(forField(field("fieldSfixed6415_"), 15, FieldType.SFIXED64, true)); - builder.withField(forField(field("fieldSint3216_"), 16, FieldType.SINT32, true)); - builder.withField(forField(field("fieldSint6417_"), 17, FieldType.SINT64, true)); - builder.withField(forField(field("fieldDoubleList18_"), 18, FieldType.DOUBLE_LIST, true)); - builder.withField(forField(field("fieldFloatList19_"), 19, FieldType.FLOAT_LIST, true)); - builder.withField(forField(field("fieldInt64List20_"), 20, FieldType.INT64_LIST, true)); - builder.withField(forField(field("fieldUint64List21_"), 21, FieldType.UINT64_LIST, true)); - builder.withField(forField(field("fieldInt32List22_"), 22, FieldType.INT32_LIST, true)); - builder.withField(forField(field("fieldFixed64List23_"), 23, FieldType.FIXED64_LIST, true)); - builder.withField(forField(field("fieldFixed32List24_"), 24, FieldType.FIXED32_LIST, true)); - builder.withField(forField(field("fieldBoolList25_"), 25, FieldType.BOOL_LIST, true)); - builder.withField(forField(field("fieldStringList26_"), 26, FieldType.STRING_LIST, true)); - builder.withField( - forRepeatedMessageField( - field("fieldMessageList27_"), 27, FieldType.MESSAGE_LIST, Proto3Message.class)); - builder.withField(forField(field("fieldBytesList28_"), 28, FieldType.BYTES_LIST, true)); - builder.withField(forField(field("fieldUint32List29_"), 29, FieldType.UINT32_LIST, true)); - builder.withField(forField(field("fieldEnumList30_"), 30, FieldType.ENUM_LIST, true)); - builder.withField(forField(field("fieldSfixed32List31_"), 31, FieldType.SFIXED32_LIST, true)); - builder.withField(forField(field("fieldSfixed64List32_"), 32, FieldType.SFIXED64_LIST, true)); - builder.withField(forField(field("fieldSint32List33_"), 33, FieldType.SINT32_LIST, true)); - builder.withField(forField(field("fieldSint64List34_"), 34, FieldType.SINT64_LIST, true)); - builder.withField( - forField(field("fieldDoubleListPacked35_"), 35, FieldType.DOUBLE_LIST_PACKED, true)); - builder.withField( - forField(field("fieldFloatListPacked36_"), 36, FieldType.FLOAT_LIST_PACKED, true)); - builder.withField( - forField(field("fieldInt64ListPacked37_"), 37, FieldType.INT64_LIST_PACKED, true)); - builder.withField( - forField(field("fieldUint64ListPacked38_"), 38, FieldType.UINT64_LIST_PACKED, true)); - builder.withField( - forField(field("fieldInt32ListPacked39_"), 39, FieldType.INT32_LIST_PACKED, true)); - builder.withField( - forField(field("fieldFixed64ListPacked40_"), 40, FieldType.FIXED64_LIST_PACKED, true)); - builder.withField( - forField(field("fieldFixed32ListPacked41_"), 41, FieldType.FIXED32_LIST_PACKED, true)); - builder.withField( - forField(field("fieldBoolListPacked42_"), 42, FieldType.BOOL_LIST_PACKED, true)); - builder.withField( - forField(field("fieldUint32ListPacked43_"), 43, FieldType.UINT32_LIST_PACKED, true)); - builder.withField( - forField(field("fieldEnumListPacked44_"), 44, FieldType.ENUM_LIST_PACKED, true)); - builder.withField( - forField(field("fieldSfixed32ListPacked45_"), 45, FieldType.SFIXED32_LIST_PACKED, true)); - builder.withField( - forField(field("fieldSfixed64ListPacked46_"), 46, FieldType.SFIXED64_LIST_PACKED, true)); - builder.withField( - forField(field("fieldSint32ListPacked47_"), 47, FieldType.SINT32_LIST_PACKED, true)); - builder.withField( - forField(field("fieldSint64ListPacked48_"), 48, FieldType.SINT64_LIST_PACKED, true)); - - OneofInfo oneof = new OneofInfo(0, field("testOneofCase_"), field("testOneof_")); - builder.withField(forOneofMemberField(53, FieldType.DOUBLE, oneof, Double.class, true, null)); - builder.withField(forOneofMemberField(54, FieldType.FLOAT, oneof, Float.class, true, null)); - builder.withField(forOneofMemberField(55, FieldType.INT64, oneof, Long.class, true, null)); - builder.withField(forOneofMemberField(56, FieldType.UINT64, oneof, Long.class, true, null)); - builder.withField(forOneofMemberField(57, FieldType.INT32, oneof, Integer.class, true, null)); - builder.withField(forOneofMemberField(58, FieldType.FIXED64, oneof, Long.class, true, null)); - builder.withField(forOneofMemberField(59, FieldType.FIXED32, oneof, Integer.class, true, null)); - builder.withField(forOneofMemberField(60, FieldType.BOOL, oneof, Boolean.class, true, null)); - builder.withField(forOneofMemberField(61, FieldType.STRING, oneof, String.class, true, null)); - builder.withField( - forOneofMemberField(62, FieldType.MESSAGE, oneof, Proto3Message.class, true, null)); - builder.withField( - forOneofMemberField(63, FieldType.BYTES, oneof, ByteString.class, true, null)); - builder.withField(forOneofMemberField(64, FieldType.UINT32, oneof, Integer.class, true, null)); - builder.withField( - forOneofMemberField(65, FieldType.SFIXED32, oneof, Integer.class, true, null)); - builder.withField(forOneofMemberField(66, FieldType.SFIXED64, oneof, Long.class, true, null)); - builder.withField(forOneofMemberField(67, FieldType.SINT32, oneof, Integer.class, true, null)); - builder.withField(forOneofMemberField(68, FieldType.SINT64, oneof, Long.class, true, null)); - } - - private StructuralMessageInfo newMessageInfoForProto3Empty() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO3); - return builder.build(); - } - - private StructuralMessageInfo newMessageInfoForProto3MessageWithMaps() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(); - builder.withSyntax(ProtoSyntax.PROTO3); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_bool_1", 1)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_bytes_2", 2)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_double_3", 3)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_enum_4", 4)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_fixed32_5", 5)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_fixed64_6", 6)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_float_7", 7)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_int32_8", 8)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_int64_9", 9)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_message_10", 10)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_sfixed32_11", 11)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_sfixed64_12", 12)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_sint32_13", 13)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_sint64_14", 14)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_string_15", 15)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_uint32_16", 16)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_bool_uint64_17", 17)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_bool_18", 18)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_bytes_19", 19)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_double_20", 20)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_enum_21", 21)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_fixed32_22", 22)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_fixed64_23", 23)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_float_24", 24)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_int32_25", 25)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_int64_26", 26)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_message_27", 27)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_sfixed32_28", 28)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_sfixed64_29", 29)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_sint32_30", 30)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_sint64_31", 31)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_string_32", 32)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_uint32_33", 33)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed32_uint64_34", 34)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_bool_35", 35)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_bytes_36", 36)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_double_37", 37)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_enum_38", 38)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_fixed32_39", 39)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_fixed64_40", 40)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_float_41", 41)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_int32_42", 42)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_int64_43", 43)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_message_44", 44)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_sfixed32_45", 45)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_sfixed64_46", 46)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_sint32_47", 47)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_sint64_48", 48)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_string_49", 49)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_uint32_50", 50)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_fixed64_uint64_51", 51)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_bool_52", 52)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_bytes_53", 53)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_double_54", 54)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_enum_55", 55)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_fixed32_56", 56)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_fixed64_57", 57)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_float_58", 58)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_int32_59", 59)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_int64_60", 60)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_message_61", 61)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_sfixed32_62", 62)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_sfixed64_63", 63)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_sint32_64", 64)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_sint64_65", 65)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_string_66", 66)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_uint32_67", 67)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int32_uint64_68", 68)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_bool_69", 69)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_bytes_70", 70)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_double_71", 71)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_enum_72", 72)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_fixed32_73", 73)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_fixed64_74", 74)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_float_75", 75)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_int32_76", 76)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_int64_77", 77)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_message_78", 78)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_sfixed32_79", 79)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_sfixed64_80", 80)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_sint32_81", 81)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_sint64_82", 82)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_string_83", 83)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_uint32_84", 84)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_int64_uint64_85", 85)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_bool_86", 86)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_bytes_87", 87)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_double_88", 88)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_enum_89", 89)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_fixed32_90", 90)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_fixed64_91", 91)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_float_92", 92)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_int32_93", 93)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_int64_94", 94)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_message_95", 95)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_sfixed32_96", 96)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_sfixed64_97", 97)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_sint32_98", 98)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_sint64_99", 99)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_string_100", 100)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_uint32_101", 101)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed32_uint64_102", 102)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_bool_103", 103)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_bytes_104", 104)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_double_105", 105)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_enum_106", 106)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_fixed32_107", 107)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_fixed64_108", 108)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_float_109", 109)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_int32_110", 110)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_int64_111", 111)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_message_112", 112)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_sfixed32_113", 113)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_sfixed64_114", 114)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_sint32_115", 115)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_sint64_116", 116)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_string_117", 117)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_uint32_118", 118)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sfixed64_uint64_119", 119)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_bool_120", 120)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_bytes_121", 121)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_double_122", 122)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_enum_123", 123)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_fixed32_124", 124)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_fixed64_125", 125)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_float_126", 126)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_int32_127", 127)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_int64_128", 128)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_message_129", 129)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_sfixed32_130", 130)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_sfixed64_131", 131)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_sint32_132", 132)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_sint64_133", 133)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_string_134", 134)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_uint32_135", 135)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint32_uint64_136", 136)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_bool_137", 137)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_bytes_138", 138)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_double_139", 139)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_enum_140", 140)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_fixed32_141", 141)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_fixed64_142", 142)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_float_143", 143)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_int32_144", 144)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_int64_145", 145)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_message_146", 146)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_sfixed32_147", 147)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_sfixed64_148", 148)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_sint32_149", 149)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_sint64_150", 150)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_string_151", 151)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_uint32_152", 152)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_sint64_uint64_153", 153)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_bool_154", 154)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_bytes_155", 155)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_double_156", 156)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_enum_157", 157)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_fixed32_158", 158)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_fixed64_159", 159)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_float_160", 160)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_int32_161", 161)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_int64_162", 162)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_message_163", 163)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_sfixed32_164", 164)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_sfixed64_165", 165)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_sint32_166", 166)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_sint64_167", 167)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_string_168", 168)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_uint32_169", 169)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_string_uint64_170", 170)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_bool_171", 171)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_bytes_172", 172)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_double_173", 173)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_enum_174", 174)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_fixed32_175", 175)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_fixed64_176", 176)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_float_177", 177)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_int32_178", 178)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_int64_179", 179)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_message_180", 180)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_sfixed32_181", 181)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_sfixed64_182", 182)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_sint32_183", 183)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_sint64_184", 184)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_string_185", 185)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_uint32_186", 186)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint32_uint64_187", 187)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_bool_188", 188)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_bytes_189", 189)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_double_190", 190)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_enum_191", 191)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_fixed32_192", 192)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_fixed64_193", 193)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_float_194", 194)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_int32_195", 195)); - builder.withField(mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_int64_196", 196)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_message_197", 197)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_sfixed32_198", 198)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_sfixed64_199", 199)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_sint32_200", 200)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_sint64_201", 201)); - builder.withField( - mapFieldInfo(Proto3MessageWithMaps.class, "field_map_uint64_string_202", 202)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_uint32_203", 203)); - builder.withField( - mapFieldInfo(Proto2MessageWithMaps.class, "field_map_uint64_uint64_204", 204)); - return builder.build(); - } - - private static Field field(String name) { - return field(Proto3Message.class, name); - } - - private static Field field(Class clazz, String name) { - try { - return clazz.getDeclaredField(name); - } catch (NoSuchFieldException | SecurityException e) { - throw new RuntimeException(e); - } - } - - private static FieldInfo mapFieldInfo(Class clazz, String fieldName, int fieldNumber) { - try { - return forMapField( - field(clazz, SchemaUtil.toCamelCase(fieldName, false) + "_"), - fieldNumber, - SchemaUtil.getMapDefaultEntry(clazz, fieldName), - null); - } catch (Throwable t) { - throw new RuntimeException(t); - } - } -} From 278dfb24964ff12702dc21dc9d49e20f0a4345b4 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 29 Nov 2021 16:07:20 -0500 Subject: [PATCH 078/207] remove UTF8Utils class that hasn't been needed since Java 6 --- Makefile.am | 1 - .../java/com/google/protobuf/Utf8Test.java | 2 +- .../java/com/google/protobuf/Utf8Utils.java | 192 ------------------ 3 files changed, 1 insertion(+), 194 deletions(-) delete mode 100644 java/core/src/test/java/com/google/protobuf/Utf8Utils.java diff --git a/Makefile.am b/Makefile.am index 712f5ae397..7e21cc0a61 100644 --- a/Makefile.am +++ b/Makefile.am @@ -494,7 +494,6 @@ java_EXTRA_DIST= java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java \ java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java \ java/core/src/test/java/com/google/protobuf/Utf8Test.java \ - java/core/src/test/java/com/google/protobuf/Utf8Utils.java \ java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java \ java/core/src/test/java/com/google/protobuf/WireFormatLiteTest.java \ java/core/src/test/java/com/google/protobuf/WireFormatTest.java \ diff --git a/java/core/src/test/java/com/google/protobuf/Utf8Test.java b/java/core/src/test/java/com/google/protobuf/Utf8Test.java index 5fdc61b5e5..787cb11cb9 100644 --- a/java/core/src/test/java/com/google/protobuf/Utf8Test.java +++ b/java/core/src/test/java/com/google/protobuf/Utf8Test.java @@ -102,7 +102,7 @@ public class Utf8Test { int codePoint; do { codePoint = rnd.nextInt(maxCodePoint); - } while (Utf8Utils.isSurrogate(codePoint)); + } while (Character.isSurrogate((char) codePoint)); sb.appendCodePoint(codePoint); } return sb.toString(); diff --git a/java/core/src/test/java/com/google/protobuf/Utf8Utils.java b/java/core/src/test/java/com/google/protobuf/Utf8Utils.java deleted file mode 100644 index 6b031867a3..0000000000 --- a/java/core/src/test/java/com/google/protobuf/Utf8Utils.java +++ /dev/null @@ -1,192 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package com.google.protobuf; - -import static java.lang.Character.MIN_HIGH_SURROGATE; -import static java.lang.Character.MIN_LOW_SURROGATE; -import static java.lang.Character.MIN_SURROGATE; - -import java.util.Random; - -/** Utilities for benchmarking UTF-8. */ -final class Utf8Utils { - private Utf8Utils() {} - - static class MaxCodePoint { - final int value; - - /** - * Convert the input string to a code point. Accepts regular decimal numerals, hex strings, and - * some symbolic names meaningful to humans. - */ - private static int decode(String userFriendly) { - try { - return Integer.decode(userFriendly); - } catch (NumberFormatException ignored) { - if (userFriendly.matches("(?i)(?:American|English|ASCII)")) { - // 1-byte UTF-8 sequences - "American" ASCII text - return 0x80; - } else if (userFriendly.matches("(?i)(?:Danish|Latin|Western.*European)")) { - // Mostly 1-byte UTF-8 sequences, mixed with occasional 2-byte - // sequences - "Western European" text - return 0x90; - } else if (userFriendly.matches("(?i)(?:Greek|Cyrillic|European|ISO.?8859)")) { - // Mostly 2-byte UTF-8 sequences - "European" text - return 0x800; - } else if (userFriendly.matches("(?i)(?:Chinese|Han|Asian|BMP)")) { - // Mostly 3-byte UTF-8 sequences - "Asian" text - return Character.MIN_SUPPLEMENTARY_CODE_POINT; - } else if (userFriendly.matches("(?i)(?:Cuneiform|rare|exotic|supplementary.*)")) { - // Mostly 4-byte UTF-8 sequences - "rare exotic" text - return Character.MAX_CODE_POINT; - } else { - throw new IllegalArgumentException("Can't decode codepoint " + userFriendly); - } - } - } - - public static MaxCodePoint valueOf(String userFriendly) { - return new MaxCodePoint(userFriendly); - } - - public MaxCodePoint(String userFriendly) { - value = decode(userFriendly); - } - } - - /** - * The Utf8 distribution of real data. The distribution is an array with length 4. - * "distribution[i]" means the total number of characters who are encoded with (i + 1) bytes. - * - *

GMM_UTF8_DISTRIBUTION is the distribution of gmm data set. GSR_UTF8_DISTRIBUTION is the - * distribution of gsreq/gsresp data set - */ - public enum Utf8Distribution { - GMM_UTF8_DISTRIBUTION { - @Override - public int[] getDistribution() { - return new int[] {53059, 104, 0, 0}; - } - }, - GSR_UTF8_DISTRIBUTION { - @Override - public int[] getDistribution() { - return new int[] {119458, 74, 2706, 0}; - } - }; - - public abstract int[] getDistribution(); - } - - /** - * Creates an array of random strings. - * - * @param stringCount the number of strings to be created. - * @param charCount the number of characters per string. - * @param maxCodePoint the maximum code point for the characters in the strings. - * @return an array of random strings. - */ - static String[] randomStrings(int stringCount, int charCount, MaxCodePoint maxCodePoint) { - final long seed = 99; - final Random rnd = new Random(seed); - String[] strings = new String[stringCount]; - for (int i = 0; i < stringCount; i++) { - strings[i] = randomString(rnd, charCount, maxCodePoint); - } - return strings; - } - - /** - * Creates a random string - * - * @param rnd the random generator. - * @param charCount the number of characters per string. - * @param maxCodePoint the maximum code point for the characters in the strings. - */ - static String randomString(Random rnd, int charCount, MaxCodePoint maxCodePoint) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < charCount; i++) { - int codePoint; - do { - codePoint = rnd.nextInt(maxCodePoint.value); - } while (Utf8Utils.isSurrogate(codePoint)); - sb.appendCodePoint(codePoint); - } - return sb.toString(); - } - - /** Character.isSurrogate was added in Java SE 7. */ - static boolean isSurrogate(int c) { - return Character.MIN_HIGH_SURROGATE <= c && c <= Character.MAX_LOW_SURROGATE; - } - - /** - * Creates an array of random strings according to UTF8 distribution. - * - * @param stringCount the number of strings to be created. - * @param charCount the number of characters per string. - */ - static String[] randomStringsWithDistribution( - int stringCount, int charCount, Utf8Distribution utf8Distribution) { - final int[] distribution = utf8Distribution.getDistribution(); - for (int i = 0; i < 3; i++) { - distribution[i + 1] += distribution[i]; - } - final long seed = 99; - final Random rnd = new Random(seed); - String[] strings = new String[stringCount]; - for (int i = 0; i < stringCount; i++) { - StringBuilder sb = new StringBuilder(); - for (int j = 0; j < charCount; j++) { - int codePoint; - do { - codePoint = rnd.nextInt(distribution[3]); - if (codePoint < distribution[0]) { - // 1 bytes - sb.append((char) 0x7F); - } else if (codePoint < distribution[1]) { - // 2 bytes - sb.append((char) 0x7FF); - } else if (codePoint < distribution[2]) { - // 3 bytes - sb.append((char) (MIN_SURROGATE - 1)); - } else { - // 4 bytes - sb.append(MIN_HIGH_SURROGATE); - sb.append(MIN_LOW_SURROGATE); - } - } while (Utf8Utils.isSurrogate(codePoint)); - } - strings[i] = sb.toString(); - } - return strings; - } -} From 667d5e9e9f1a9ebc15cfcddb5f272a301d0f16b6 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Mon, 29 Nov 2021 23:54:09 +0000 Subject: [PATCH 079/207] No error throwing for unknown OS --- protobuf_release.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf_release.bzl b/protobuf_release.bzl index 7ed3cc7c8e..cac0a0c52a 100644 --- a/protobuf_release.bzl +++ b/protobuf_release.bzl @@ -32,7 +32,7 @@ def _package_naming_impl(ctx): else: values["platform"] = "win32" else: - fail("Unrecognized platform") + values["platform"] = "unknown" return PackageVariablesInfo(values = values) From 9a1d5dfa4bfcddac7e7db71c899aa0b832161bcc Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 30 Nov 2021 11:24:50 -0800 Subject: [PATCH 080/207] Small tweaks to C# unit tests (#9271) This change includes just a couple small tweaks: - Keep line lengths under 80 characters - Fully qualify google::protobuf::Any so that the code still compiles internally where we use a different namespace. --- .../protobuf/compiler/csharp/csharp_bootstrap_unittest.cc | 3 ++- .../protobuf/compiler/csharp/csharp_generator_unittest.cc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index 44ecfdedbe..84aacca57e 100644 --- a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc @@ -110,7 +110,8 @@ class MockGeneratorContext : public GeneratorContext { class GenerateAndTest { public: GenerateAndTest() {} - void Run(const FileDescriptor* proto_file, std::string file1, std::string file2) { + void Run(const FileDescriptor* proto_file, std::string file1, + std::string file2) { ASSERT_TRUE(proto_file != NULL) << TestSourceDir(); ASSERT_TRUE(generator_.Generate(proto_file, parameter_, &context_, &error_)); diff --git a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc index ae975baa02..e21eff17ba 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc @@ -65,12 +65,12 @@ TEST(CSharpEnumValue, PascalCasedPrefixStripping) { TEST(DescriptorProtoHelpers, IsDescriptorProto) { EXPECT_TRUE(IsDescriptorProto(DescriptorProto::descriptor()->file())); - EXPECT_FALSE(IsDescriptorProto(Any::descriptor()->file())); + EXPECT_FALSE(IsDescriptorProto(google::protobuf::Any::descriptor()->file())); } TEST(DescriptorProtoHelpers, IsDescriptorOptionMessage) { EXPECT_TRUE(IsDescriptorOptionMessage(FileOptions::descriptor())); - EXPECT_FALSE(IsDescriptorOptionMessage(Any::descriptor())); + EXPECT_FALSE(IsDescriptorOptionMessage(google::protobuf::Any::descriptor())); EXPECT_FALSE(IsDescriptorOptionMessage(DescriptorProto::descriptor())); } From a863972644eccb4fab941a84334364fbfe732dc8 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 3 Dec 2021 18:34:37 +0000 Subject: [PATCH 081/207] Fixing windows builds --- toolchain/BUILD | 38 ++++++++++++++++++------------- toolchain/cc_toolchain_config.bzl | 19 ++++++++++++---- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 394269272d..d995de56a8 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -43,7 +43,7 @@ cc_toolchain_config( name = "linux-aarch_64-config", bit_flag = "-m64", cpp_flag = "-lstdc++", - include_flag = [ + extra_compiler_flags = [ "-I/usr/aarch64-linux-gnu/include/c++/8/aarch64-linux-gnu/", "-I/usr/aarch64-linux-gnu/include/c++/8" ], @@ -58,7 +58,7 @@ cc_toolchain_config( name = "linux-ppcle_64-config", bit_flag = "-m64", cpp_flag = "-lstdc++", - include_flag = [ + extra_compiler_flags = [ "-I/usr/powerpc64le-linux-gnu/include/c++/8/powerpc64le-linux-gnu/", "-I/usr/powerpc64le-linux-gnu/include/c++/8/" ], @@ -73,7 +73,7 @@ cc_toolchain_config( name = "linux-s390_64-config", bit_flag = "-m64", cpp_flag = "-lstdc++", - include_flag = [ + extra_compiler_flags = [ "-I/usr/s390x-linux-gnu/include/c++/8/s390x-linux-gnu/", "-I/usr/s390x-linux-gnu/include/c++/8/" ], @@ -110,7 +110,7 @@ cc_toolchain_config( name = "osx-aarch_64-config", bit_flag = "-m64", cpp_flag = "-lc++", - include_flag = [ + extra_compiler_flags = [ "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], @@ -126,7 +126,7 @@ cc_toolchain_config( name = "osx-x86_64-config", bit_flag = "-m64", cpp_flag = "-lc++", - include_flag = [ + extra_compiler_flags = [ "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], @@ -142,12 +142,16 @@ cc_toolchain_config( name = "win32-config", bit_flag = "-m32", cpp_flag = "-lstdc++", - extra_include = "/usr/lib/gcc/i686-w64-mingw32/10-posix/include", - extra_linker_flag = "-L/usr/lib/gcc/i686-w64-mingw32/10-posix", - include_flag = [ - "-I/usr/lib/gcc/i686-w64-mingw32/10-posix/include/c++", - "-I/usr/lib/gcc/i686-w64-mingw32/10-posix/include/c++/i686-w64-mingw32", - "-I/usr/i686-w64-mingw32/include" + extra_compiler_flags = [ + "-I/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++", + "-I/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++/i686-w64-mingw32", + "-I/usr/i686-w64-mingw32/include", + "-fsjlj-exceptions", + ], + extra_include = "/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include", + extra_linker_flags = [ + "-L/usr/lib/gcc/i686-w64-mingw32/8.3-posix", + "-pthread", ], linker_path = "/usr/bin/ld", target_cpu = "x86_32", @@ -160,13 +164,15 @@ cc_toolchain_config( name = "win64-config", bit_flag = "-m64", cpp_flag = "-lstdc++", - extra_include = "/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include", - extra_linker_flag = "-L/usr/lib/gcc/x86_64-w64-mingw32/10-posix", - include_flag = [ - "-I/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/", - "-I/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/x86_64-w64-mingw32", + extra_compiler_flags = [ + "-I/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/", + "-I/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/x86_64-w64-mingw32", "-I/usr/x86_64-w64-mingw32/include" ], + extra_include = "/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include", + extra_linker_flags = [ + "-L/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix", + ], linker_path = "/usr/bin/ld", target_cpu = "x86_64", target_full_name = "x86_64-w64-mingw32", diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index f9b92675a4..7cf982d531 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -1,6 +1,7 @@ load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") load( "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "artifact_name_pattern", "feature", "flag_group", "flag_set", @@ -27,6 +28,14 @@ all_compile_actions = [ ] def _impl(ctx): + artifact_name_patterns = [ + artifact_name_pattern( + category_name = "executable", + prefix = "", + extension = ".exe", + ), + ] + tool_paths = [ tool_path( name = "gcc", @@ -86,8 +95,7 @@ def _impl(ctx): "-B" + ctx.attr.linker_path, ctx.attr.cpp_flag, "--target=" + ctx.attr.target_full_name, - ctx.attr.extra_linker_flag, - ], + ] + ctx.attr.extra_linker_flags, ), ], ), @@ -129,7 +137,7 @@ def _impl(ctx): "-isystem", ctx.attr.toolchain_dir, "-fvisibility=hidden", - ] + ctx.attr.include_flag, + ] + ctx.attr.extra_compiler_flags, ), ], ), @@ -139,6 +147,7 @@ def _impl(ctx): return cc_common.create_cc_toolchain_config_info( abi_libc_version = ctx.attr.abi_version, abi_version = ctx.attr.abi_version, + artifact_name_patterns = artifact_name_patterns, ctx = ctx, compiler = "clang", cxx_builtin_include_directories = [ @@ -163,9 +172,9 @@ cc_toolchain_config = rule( "abi_version": attr.string(default = "local"), "bit_flag": attr.string(mandatory = True, values = ["-m32", "-m64"]), "cpp_flag": attr.string(mandatory = True), + "extra_compiler_flags": attr.string_list(), "extra_include": attr.string(mandatory = False), - "extra_linker_flag": attr.string(mandatory = False), - "include_flag": attr.string_list(), + "extra_linker_flags": attr.string_list(), "linker_path": attr.string(mandatory = True), "sysroot": attr.string(mandatory = False), "target_cpu": attr.string(mandatory = True, values = ["aarch64", "ppc64", "systemz", "x86_32", "x86_64"]), From 88076658f1279494fc414db0e605bb80d2bebf19 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 3 Dec 2021 23:25:36 +0000 Subject: [PATCH 082/207] Change includes --- toolchain/BUILD | 7 +++++++ toolchain/cc_toolchain_config.bzl | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index d995de56a8..2fab64457f 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -47,6 +47,7 @@ cc_toolchain_config( "-I/usr/aarch64-linux-gnu/include/c++/8/aarch64-linux-gnu/", "-I/usr/aarch64-linux-gnu/include/c++/8" ], + extra_include = "/usr/include", linker_path = "/usr/bin/ld", target_cpu = "aarch64", target_full_name = "aarch64-linux-gnu", @@ -62,6 +63,7 @@ cc_toolchain_config( "-I/usr/powerpc64le-linux-gnu/include/c++/8/powerpc64le-linux-gnu/", "-I/usr/powerpc64le-linux-gnu/include/c++/8/" ], + extra_include = "/usr/include" linker_path = "/usr/bin/ld", target_cpu = "ppc64", target_full_name = "powerpc64le-linux-gnu", @@ -77,6 +79,7 @@ cc_toolchain_config( "-I/usr/s390x-linux-gnu/include/c++/8/s390x-linux-gnu/", "-I/usr/s390x-linux-gnu/include/c++/8/" ], + extra_include = "/usr/include", linker_path = "/usr/bin/ld", target_cpu = "systemz", target_full_name = "s390x-linux-gnu", @@ -88,6 +91,7 @@ cc_toolchain_config( name = "linux-x86_32-config", bit_flag = "-m32", cpp_flag = "-lstdc++", + extra_include = "/usr/include", linker_path = "/usr/bin/ld", target_cpu = "x86_32", target_full_name = "i386-linux-gnu", @@ -99,6 +103,7 @@ cc_toolchain_config( name = "linux-x86_64-config", bit_flag = "-m64", cpp_flag = "-lstdc++", + extra_include = "/usr/include", linker_path = "/usr/bin/ld", target_cpu = "x86_64", target_full_name = "x86_64-linux-gnu", @@ -114,6 +119,7 @@ cc_toolchain_config( "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], + extra_include = "/usr/include", linker_path = "/usr/tools", sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "aarch64", @@ -130,6 +136,7 @@ cc_toolchain_config( "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1", "-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include" ], + extra_include = "/usr/include", linker_path = "/usr/tools", sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx", target_cpu = "x86_64", diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 7cf982d531..b86c39611f 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -153,7 +153,6 @@ def _impl(ctx): cxx_builtin_include_directories = [ ctx.attr.toolchain_dir, ctx.attr.extra_include, - "/usr/include", "/usr/local/include", "/usr/local/lib/clang", ], From 0fba541a69bc889f41976cc26799e8decb4680fa Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Sat, 4 Dec 2021 00:33:05 +0000 Subject: [PATCH 083/207] Add comma --- toolchain/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 2fab64457f..44f24a0185 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -63,7 +63,7 @@ cc_toolchain_config( "-I/usr/powerpc64le-linux-gnu/include/c++/8/powerpc64le-linux-gnu/", "-I/usr/powerpc64le-linux-gnu/include/c++/8/" ], - extra_include = "/usr/include" + extra_include = "/usr/include", linker_path = "/usr/bin/ld", target_cpu = "ppc64", target_full_name = "powerpc64le-linux-gnu", From 29b3d01572d50c0e5bc0ab2eea32f9779c7576f4 Mon Sep 17 00:00:00 2001 From: Dane Harrigan <72265290+dane@users.noreply.github.com> Date: Tue, 7 Dec 2021 16:47:05 -0800 Subject: [PATCH 084/207] Add protoc-gen-go-svc to options.md (#9280) --- docs/options.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/options.md b/docs/options.md index 6608bedba8..e4ca729c0a 100644 --- a/docs/options.md +++ b/docs/options.md @@ -296,3 +296,7 @@ with info about your project (name and website) so we can add an entry for you. 1. Protoc-gen-checker * Website: https://github.com/Intrinsec/protoc-gen-checker * Extension: 1130-1139 + +1. Protoc-gen-go-svc + * Website: https://github.com/dane/protoc-gen-go-svc + * Extension: 1140 From 9e896e2e92d545b4330bda4de82b2d49c7c5886d Mon Sep 17 00:00:00 2001 From: owentou Date: Tue, 14 Dec 2021 22:34:07 +0800 Subject: [PATCH 085/207] [CMAKE] `protobuf::libprotoc` and `protobuf::protoc` should be optional in legacy `protobuf-module.cmake` when crossing compiling. --- cmake/protobuf-module.cmake.in | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/cmake/protobuf-module.cmake.in b/cmake/protobuf-module.cmake.in index 09b9d29c22..0bb05e38fa 100644 --- a/cmake/protobuf-module.cmake.in +++ b/cmake/protobuf-module.cmake.in @@ -94,7 +94,7 @@ function(_protobuf_find_libraries name filename) elseif(${name}_LIBRARY) # Honor cache entry used by CMake 3.5 and lower. set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE) - else() + elseif(TARGET protobuf::lib${filename}) get_target_property(${name}_LIBRARY_RELEASE protobuf::lib${filename} LOCATION_RELEASE) get_target_property(${name}_LIBRARY_RELWITHDEBINFO protobuf::lib${filename} @@ -134,23 +134,25 @@ get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES) # Set the protoc Executable -get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc - IMPORTED_LOCATION_RELEASE) -if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") +if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc) get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc - IMPORTED_LOCATION_RELWITHDEBINFO) -endif() -if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") - get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc - IMPORTED_LOCATION_MINSIZEREL) -endif() -if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") - get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc - IMPORTED_LOCATION_DEBUG) -endif() -if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") - get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc - IMPORTED_LOCATION_NOCONFIG) + IMPORTED_LOCATION_RELEASE) + if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc + IMPORTED_LOCATION_RELWITHDEBINFO) + endif() + if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc + IMPORTED_LOCATION_MINSIZEREL) + endif() + if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc + IMPORTED_LOCATION_DEBUG) + endif() + if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}") + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc + IMPORTED_LOCATION_NOCONFIG) + endif() endif() # Version info variable From 8c29dc2c4d55bb620bfe15ca6b74f8097cbb006d Mon Sep 17 00:00:00 2001 From: Alisa Date: Wed, 15 Dec 2021 00:45:13 +0800 Subject: [PATCH 086/207] Fix broken max macro on Windows (#9273) --- src/google/protobuf/arena.h | 3 --- src/google/protobuf/stubs/stl_util.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 6dd6467f58..785f2730cf 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -37,9 +37,6 @@ #include #include #include -#ifdef max -#undef max // Visual Studio defines this macro -#endif #if defined(_MSC_VER) && !defined(_LIBCPP_STD_VER) && !_HAS_EXCEPTIONS // Work around bugs in MSVC header when _HAS_EXCEPTIONS=0. #include diff --git a/src/google/protobuf/stubs/stl_util.h b/src/google/protobuf/stubs/stl_util.h index 45d28904f9..ef66305650 100644 --- a/src/google/protobuf/stubs/stl_util.h +++ b/src/google/protobuf/stubs/stl_util.h @@ -37,6 +37,8 @@ #include +#include + namespace google { namespace protobuf { @@ -82,4 +84,6 @@ inline char* string_as_array(std::string* str) { } // namespace protobuf } // namespace google +#include + #endif // GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ From 5711cab189e468b2f11dd307141c08f636f25632 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Tue, 14 Dec 2021 23:40:36 +0000 Subject: [PATCH 087/207] show less log junk from Maven @perezd turn off de bugging messages such as ``` [DEBUG] Imported: org.codehaus.plexus.configuration < plexus.core ``` --- tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.sh b/tests.sh index 176bc5f2bc..290f110a8c 100755 --- a/tests.sh +++ b/tests.sh @@ -204,7 +204,7 @@ use_java() { esac MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository - MVN="$MVN -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY" + MVN="$MVN -e --quiet -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY" which java java -version From 214180c5a237c17f41e520ddde63bc1279782245 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 14 Dec 2021 16:33:16 -0800 Subject: [PATCH 088/207] Dropped Ruby 2.4 support for CI and releases. --- kokoro/linux/dockerfile/test/ruby/Dockerfile | 2 -- kokoro/release/ruby/macos/ruby/ruby_build_environment.sh | 2 +- ruby/Gemfile | 2 -- ruby/Rakefile | 4 ++-- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/kokoro/linux/dockerfile/test/ruby/Dockerfile b/kokoro/linux/dockerfile/test/ruby/Dockerfile index 2affd14196..4fe2bfdc75 100644 --- a/kokoro/linux/dockerfile/test/ruby/Dockerfile +++ b/kokoro/linux/dockerfile/test/ruby/Dockerfile @@ -31,8 +31,6 @@ RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys \ 7D2BAF1CF37B13E2069D6956105BD0E739499BDB RUN \curl -sSL https://get.rvm.io | bash -s master -RUN /bin/bash -l -c "rvm install 2.3.8" -RUN /bin/bash -l -c "rvm install 2.4.5" RUN /bin/bash -l -c "rvm install 2.5.1" RUN /bin/bash -l -c "rvm install 2.6.0" RUN /bin/bash -l -c "rvm install 2.7.0" diff --git a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh index 9954fb0c2f..98270d1383 100755 --- a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh +++ b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh @@ -67,7 +67,7 @@ set +x rvm use 2.5.0 set -x ruby --version | grep 'ruby 2.5.0' -for v in 2.6.0 2.5.1 2.4.0 2.3.0; do +for v in 2.6.0 2.5.1; do ccache -c rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=x86_64-darwin MAKE="$MAKE" rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=aarch64-darwin MAKE="$MAKE" diff --git a/ruby/Gemfile b/ruby/Gemfile index 76b23ad91d..fa75df1563 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -1,5 +1,3 @@ source 'https://rubygems.org' gemspec - -gem "irb", "~> 1.1", "< 1.2.0" if RUBY_VERSION < "2.5" diff --git a/ruby/Rakefile b/ruby/Rakefile index a3367039c1..89b9ca5bfc 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -117,7 +117,7 @@ else ['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat| RakeCompilerDock.sh <<-"EOT", platform: plat bundle && \ - IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.0:2.4.0:2.3.0 + IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.0 EOT end end @@ -125,7 +125,7 @@ else if RUBY_PLATFORM =~ /darwin/ task 'gem:native' do system "rake genproto" - system "rake cross native gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.1:2.4.0:2.3.0" + system "rake cross native gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.1" end else task 'gem:native' => [:genproto, 'gem:windows', 'gem:java'] From a7089254d1f3192a9d550381c4103c10709a7bbf Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 15 Dec 2021 16:48:01 -0800 Subject: [PATCH 089/207] Removed Kokoro configs for old Ruby versions. --- kokoro/linux/ruby23/build.sh | 18 ------------------ kokoro/linux/ruby23/continuous.cfg | 11 ----------- kokoro/linux/ruby23/presubmit.cfg | 11 ----------- kokoro/linux/ruby24/build.sh | 18 ------------------ kokoro/linux/ruby24/continuous.cfg | 11 ----------- kokoro/linux/ruby24/presubmit.cfg | 11 ----------- kokoro/macos/ruby23/build.sh | 12 ------------ kokoro/macos/ruby23/continuous.cfg | 5 ----- kokoro/macos/ruby23/presubmit.cfg | 5 ----- kokoro/macos/ruby24/build.sh | 12 ------------ kokoro/macos/ruby24/continuous.cfg | 5 ----- kokoro/macos/ruby24/presubmit.cfg | 5 ----- 12 files changed, 124 deletions(-) delete mode 100755 kokoro/linux/ruby23/build.sh delete mode 100644 kokoro/linux/ruby23/continuous.cfg delete mode 100644 kokoro/linux/ruby23/presubmit.cfg delete mode 100755 kokoro/linux/ruby24/build.sh delete mode 100644 kokoro/linux/ruby24/continuous.cfg delete mode 100644 kokoro/linux/ruby24/presubmit.cfg delete mode 100755 kokoro/macos/ruby23/build.sh delete mode 100644 kokoro/macos/ruby23/continuous.cfg delete mode 100644 kokoro/macos/ruby23/presubmit.cfg delete mode 100755 kokoro/macos/ruby24/build.sh delete mode 100644 kokoro/macos/ruby24/continuous.cfg delete mode 100644 kokoro/macos/ruby24/presubmit.cfg diff --git a/kokoro/linux/ruby23/build.sh b/kokoro/linux/ruby23/build.sh deleted file mode 100755 index 503a320de2..0000000000 --- a/kokoro/linux/ruby23/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERHUB_ORGANIZATION=protobuftesting -export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="ruby23" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/ruby23/continuous.cfg b/kokoro/linux/ruby23/continuous.cfg deleted file mode 100644 index f5c64988bf..0000000000 --- a/kokoro/linux/ruby23/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby23/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/ruby23/presubmit.cfg b/kokoro/linux/ruby23/presubmit.cfg deleted file mode 100644 index f5c64988bf..0000000000 --- a/kokoro/linux/ruby23/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby23/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/ruby24/build.sh b/kokoro/linux/ruby24/build.sh deleted file mode 100755 index 68585aabc0..0000000000 --- a/kokoro/linux/ruby24/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERHUB_ORGANIZATION=protobuftesting -export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="ruby24" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/ruby24/continuous.cfg b/kokoro/linux/ruby24/continuous.cfg deleted file mode 100644 index a1ccfc0b8b..0000000000 --- a/kokoro/linux/ruby24/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby24/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/ruby24/presubmit.cfg b/kokoro/linux/ruby24/presubmit.cfg deleted file mode 100644 index a1ccfc0b8b..0000000000 --- a/kokoro/linux/ruby24/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby24/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/macos/ruby23/build.sh b/kokoro/macos/ruby23/build.sh deleted file mode 100755 index 5a29a997fc..0000000000 --- a/kokoro/macos/ruby23/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests - -# Change to repo root -cd $(dirname $0)/../../.. - -# Prepare worker environment to run tests -KOKORO_INSTALL_RVM=yes -source kokoro/macos/prepare_build_macos_rc - -./tests.sh ruby23 diff --git a/kokoro/macos/ruby23/continuous.cfg b/kokoro/macos/ruby23/continuous.cfg deleted file mode 100644 index c9b1f61284..0000000000 --- a/kokoro/macos/ruby23/continuous.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby23/build.sh" -timeout_mins: 1440 diff --git a/kokoro/macos/ruby23/presubmit.cfg b/kokoro/macos/ruby23/presubmit.cfg deleted file mode 100644 index c9b1f61284..0000000000 --- a/kokoro/macos/ruby23/presubmit.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby23/build.sh" -timeout_mins: 1440 diff --git a/kokoro/macos/ruby24/build.sh b/kokoro/macos/ruby24/build.sh deleted file mode 100755 index 10ac85f7a4..0000000000 --- a/kokoro/macos/ruby24/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests - -# Change to repo root -cd $(dirname $0)/../../.. - -# Prepare worker environment to run tests -KOKORO_INSTALL_RVM=yes -source kokoro/macos/prepare_build_macos_rc - -./tests.sh ruby24 diff --git a/kokoro/macos/ruby24/continuous.cfg b/kokoro/macos/ruby24/continuous.cfg deleted file mode 100644 index fada028fc5..0000000000 --- a/kokoro/macos/ruby24/continuous.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby24/build.sh" -timeout_mins: 1440 diff --git a/kokoro/macos/ruby24/presubmit.cfg b/kokoro/macos/ruby24/presubmit.cfg deleted file mode 100644 index fada028fc5..0000000000 --- a/kokoro/macos/ruby24/presubmit.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby24/build.sh" -timeout_mins: 1440 From a35c973b7f067f0dd390a850cdc8213a7866a485 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 16 Dec 2021 16:50:40 +0000 Subject: [PATCH 090/207] remove unused test proto (#9298) * remove unused test proto --- Makefile.am | 1 - java/core/generate-test-sources-build.xml | 1 - .../message_lite_extension_util_test.proto | 48 ------------------- java/lite/generate-test-sources-build.xml | 1 - 4 files changed, 51 deletions(-) delete mode 100644 java/core/src/test/proto/com/google/protobuf/message_lite_extension_util_test.proto diff --git a/Makefile.am b/Makefile.am index 1dfb99ebfa..9534b42ee5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -514,7 +514,6 @@ java_EXTRA_DIST= java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto \ java/core/src/test/proto/com/google/protobuf/map_lite_test.proto \ java/core/src/test/proto/com/google/protobuf/map_test.proto \ - java/core/src/test/proto/com/google/protobuf/message_lite_extension_util_test.proto\ java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto \ java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto \ java/core/src/test/proto/com/google/protobuf/nested_extension.proto \ diff --git a/java/core/generate-test-sources-build.xml b/java/core/generate-test-sources-build.xml index 71a88d07b3..db44a15ab2 100644 --- a/java/core/generate-test-sources-build.xml +++ b/java/core/generate-test-sources-build.xml @@ -30,7 +30,6 @@ - diff --git a/java/core/src/test/proto/com/google/protobuf/message_lite_extension_util_test.proto b/java/core/src/test/proto/com/google/protobuf/message_lite_extension_util_test.proto deleted file mode 100644 index 9baf948d2e..0000000000 --- a/java/core/src/test/proto/com/google/protobuf/message_lite_extension_util_test.proto +++ /dev/null @@ -1,48 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Proto definitions used to test MessageLiteExtensionUtil -syntax = "proto2"; - -package protobuf_unittest; - -option java_outer_classname = "MessageLiteExtensionTestProtos"; - -message Car { - optional string make = 1; - extensions 1000 to max; -} - -extend Car { - optional bool turbo = 1001; - optional bool self_driving = 1002; - optional bool flies = 1003; - optional string plate = 9999; -} diff --git a/java/lite/generate-test-sources-build.xml b/java/lite/generate-test-sources-build.xml index 65e62ce4fb..365194e1db 100644 --- a/java/lite/generate-test-sources-build.xml +++ b/java/lite/generate-test-sources-build.xml @@ -29,7 +29,6 @@ - From 41606730da4b41704f12cbfdd70d24a0e69eedb8 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 16 Dec 2021 15:07:56 -0500 Subject: [PATCH 091/207] Add space to fix error message formatting. --- src/google/protobuf/compiler/objectivec/objectivec_helpers.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index bb56b20e4e..58f54bd6af 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -1329,7 +1329,7 @@ bool ValidateObjCClassPrefix( *out_error += "'package " + other_package_for_prefix + ";'."; } *out_error += - "It can only be reused by adding '" + lookup_key + " = " + prefix + + " It can only be reused by adding '" + lookup_key + " = " + prefix + "' to the expected prefixes file (" + expected_prefixes_path + ")."; return false; // Only report first usage of the prefix. } From a16629667a0da31ae3659f34e01ca42fb5bc0f96 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 16 Dec 2021 21:16:08 +0000 Subject: [PATCH 092/207] Removing -I include to ensure there's only one system include --- toolchain/BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index 44f24a0185..d94003e96f 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -152,7 +152,6 @@ cc_toolchain_config( extra_compiler_flags = [ "-I/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++", "-I/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++/i686-w64-mingw32", - "-I/usr/i686-w64-mingw32/include", "-fsjlj-exceptions", ], extra_include = "/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include", @@ -174,7 +173,6 @@ cc_toolchain_config( extra_compiler_flags = [ "-I/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/", "-I/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/x86_64-w64-mingw32", - "-I/usr/x86_64-w64-mingw32/include" ], extra_include = "/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include", extra_linker_flags = [ From 911c940569c3ec7601f171abb1529d7329507ca9 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 16 Dec 2021 14:14:45 -0800 Subject: [PATCH 093/207] Fix python 10 install error --- kokoro/release/python/windows/install_python_interpreters.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kokoro/release/python/windows/install_python_interpreters.ps1 b/kokoro/release/python/windows/install_python_interpreters.ps1 index f193eedeb0..ff13bdd842 100644 --- a/kokoro/release/python/windows/install_python_interpreters.ps1 +++ b/kokoro/release/python/windows/install_python_interpreters.ps1 @@ -97,7 +97,7 @@ $Python39x64Config = @{ Install-Python @Python39x64Config # Python 3.10 -$Python39x86Config = @{ +$Python310x86Config = @{ PythonVersion = "3.10.0" PythonInstaller = "python-3.10.0" PythonInstallPath = "C:\python310_32bit" @@ -105,7 +105,7 @@ $Python39x86Config = @{ } Install-Python @Python310x86Config -$Python39x64Config = @{ +$Python310x64Config = @{ PythonVersion = "3.10.0" PythonInstaller = "python-3.10.0-amd64" PythonInstallPath = "C:\python310" From b360b9e388351aaed97f2ead98dd951fb5f1951e Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Thu, 16 Dec 2021 15:07:05 -0800 Subject: [PATCH 094/207] Change toolchain includes (#9318) This fixes path resolution failures when following `#include_next` directives in headers found from paths in `extra_compiler_flags`. --- toolchain/BUILD | 8 ++++---- toolchain/cc_toolchain_config.bzl | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/toolchain/BUILD b/toolchain/BUILD index d94003e96f..467d1a5df7 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -150,8 +150,8 @@ cc_toolchain_config( bit_flag = "-m32", cpp_flag = "-lstdc++", extra_compiler_flags = [ - "-I/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++", - "-I/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++/i686-w64-mingw32", + "-isystem/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++", + "-isystem/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++/i686-w64-mingw32", "-fsjlj-exceptions", ], extra_include = "/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include", @@ -171,8 +171,8 @@ cc_toolchain_config( bit_flag = "-m64", cpp_flag = "-lstdc++", extra_compiler_flags = [ - "-I/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/", - "-I/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/x86_64-w64-mingw32", + "-isystem/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/", + "-isystem/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/x86_64-w64-mingw32", ], extra_include = "/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include", extra_linker_flags = [ diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index b86c39611f..6310c69762 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -134,10 +134,11 @@ def _impl(ctx): "-Wall", "-no-canonical-prefixes", "--target=" + ctx.attr.target_full_name, + "-fvisibility=hidden", + ] + ctx.attr.extra_compiler_flags + [ "-isystem", ctx.attr.toolchain_dir, - "-fvisibility=hidden", - ] + ctx.attr.extra_compiler_flags, + ], ), ], ), From bb5094881c6a496a458cb5d1c939ac4d0e822964 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 16 Dec 2021 21:38:42 -0800 Subject: [PATCH 095/207] Update python 3.10 install MD5 Sum (#9322) https://www.python.org/downloads/release/python-3100/ --- kokoro/release/python/windows/install_python_interpreters.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kokoro/release/python/windows/install_python_interpreters.ps1 b/kokoro/release/python/windows/install_python_interpreters.ps1 index f193eedeb0..e541fc2cf1 100644 --- a/kokoro/release/python/windows/install_python_interpreters.ps1 +++ b/kokoro/release/python/windows/install_python_interpreters.ps1 @@ -101,7 +101,7 @@ $Python39x86Config = @{ PythonVersion = "3.10.0" PythonInstaller = "python-3.10.0" PythonInstallPath = "C:\python310_32bit" - PythonInstallerHash = "6de353f2f7422aa030d4ccc788ffa75e" + PythonInstallerHash = "133aa48145032e341ad2a000cd3bff50" } Install-Python @Python310x86Config @@ -109,6 +109,6 @@ $Python39x64Config = @{ PythonVersion = "3.10.0" PythonInstaller = "python-3.10.0-amd64" PythonInstallPath = "C:\python310" - PythonInstallerHash = "39135519b044757f0a3b09d63612b0da" + PythonInstallerHash = "c3917c08a7fe85db7203da6dcaa99a70" } Install-Python @Python310x64Config From cb1f49ae73cf26dd61368f8bd1297e11c62a5f03 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Fri, 17 Dec 2021 10:50:45 -0800 Subject: [PATCH 096/207] Cherry-pick Python 3.10 fix to 3.19.x (#9323) --- kokoro/release/python/windows/install_python_interpreters.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kokoro/release/python/windows/install_python_interpreters.ps1 b/kokoro/release/python/windows/install_python_interpreters.ps1 index e541fc2cf1..3f8db95b7a 100644 --- a/kokoro/release/python/windows/install_python_interpreters.ps1 +++ b/kokoro/release/python/windows/install_python_interpreters.ps1 @@ -97,7 +97,7 @@ $Python39x64Config = @{ Install-Python @Python39x64Config # Python 3.10 -$Python39x86Config = @{ +$Python310x86Config = @{ PythonVersion = "3.10.0" PythonInstaller = "python-3.10.0" PythonInstallPath = "C:\python310_32bit" @@ -105,7 +105,7 @@ $Python39x86Config = @{ } Install-Python @Python310x86Config -$Python39x64Config = @{ +$Python310x64Config = @{ PythonVersion = "3.10.0" PythonInstaller = "python-3.10.0-amd64" PythonInstallPath = "C:\python310" From 8f6c3c6824c669e1df46cd04204524825ac05139 Mon Sep 17 00:00:00 2001 From: Protobuf Team Date: Wed, 22 Dec 2021 08:03:49 -0800 Subject: [PATCH 097/207] Project import generated by Copybara PiperOrigin-RevId: 417821950 --- .../code_size/apps_jspb/all_types_proto2.js | 10 +++---- .../code_size/apps_jspb/all_types_proto3.js | 10 +++---- js/experimental/runtime/kernel/kernel_test.js | 28 +++++++++---------- js/experimental/runtime/kernel/tag_test.js | 4 +-- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/js/experimental/benchmarks/code_size/apps_jspb/all_types_proto2.js b/js/experimental/benchmarks/code_size/apps_jspb/all_types_proto2.js index 252520f71c..94c2598a8c 100644 --- a/js/experimental/benchmarks/code_size/apps_jspb/all_types_proto2.js +++ b/js/experimental/benchmarks/code_size/apps_jspb/all_types_proto2.js @@ -119,7 +119,7 @@ function accessAllTypes() { arrayVal[0] = true; msgAllTypes.setRepeatedBoolList(arrayVal); msgAllTypes.setRepeatedBytesList(['']); - arrayVal = msgAllTypes.getRepeatedBytesList(); + arrayVal = msgAllTypes.getRepeatedBytesList_asB64(); arrayVal[0] = ''; msgAllTypes.setRepeatedBytesList(arrayVal); msgPackedTypes.setPackedDoubleList([1.0]); @@ -233,8 +233,7 @@ function accessAllTypes() { let s = ''; s += msgAllTypes.getOptionalBool() || false; - s += msgAllTypes.getOptionalBytes() || ''; - // s += msgAllTypes.getOptionalBytes_asB64() || ""; + s += msgAllTypes.getOptionalBytes_asB64() || ''; // s += msgAllTypes.getOptionalBytes_asU8() || new Uint8Array([]); s += msgAllTypes.getOptionalDouble() || 0.0; s += msgAllTypes.getOptionalFixed32() || 0; @@ -254,10 +253,9 @@ function accessAllTypes() { s += msgAllTypes.getRepeatedBoolList(); s += msgAllTypes.getRepeatedBoolList()[0]; s += msgAllTypes.getRepeatedBoolList().length; - s += msgAllTypes.getRepeatedBytesList(); - s += msgAllTypes.getRepeatedBytesList()[0]; - s += msgAllTypes.getRepeatedBytesList().length; s += msgAllTypes.getRepeatedBytesList_asB64(); + s += msgAllTypes.getRepeatedBytesList_asB64()[0]; + s += msgAllTypes.getRepeatedBytesList_asB64().length; s += msgAllTypes.getRepeatedBytesList_asU8(); s += msgAllTypes.getRepeatedDoubleList(); s += msgAllTypes.getRepeatedDoubleList()[0]; diff --git a/js/experimental/benchmarks/code_size/apps_jspb/all_types_proto3.js b/js/experimental/benchmarks/code_size/apps_jspb/all_types_proto3.js index 3637df612f..9eb8126a88 100644 --- a/js/experimental/benchmarks/code_size/apps_jspb/all_types_proto3.js +++ b/js/experimental/benchmarks/code_size/apps_jspb/all_types_proto3.js @@ -119,7 +119,7 @@ function accessAllTypes() { arrayVal[0] = true; msgAllTypes.setRepeatedBoolList(arrayVal); msgAllTypes.setRepeatedBytesList(['']); - arrayVal = msgAllTypes.getRepeatedBytesList(); + arrayVal = msgAllTypes.getRepeatedBytesList_asB64(); arrayVal[0] = ''; msgAllTypes.setRepeatedBytesList(arrayVal); msgPackedTypes.setPackedDoubleList([1.0]); @@ -233,8 +233,7 @@ function accessAllTypes() { let s = ''; s += msgAllTypes.getOptionalBool() || false; - s += msgAllTypes.getOptionalBytes() || ''; - // s += msgAllTypes.getOptionalBytes_asB64() || ""; + s += msgAllTypes.getOptionalBytes_asB64() || ''; // s += msgAllTypes.getOptionalBytes_asU8() || new Uint8Array([]); s += msgAllTypes.getOptionalDouble() || 0.0; s += msgAllTypes.getOptionalFixed32() || 0; @@ -254,10 +253,9 @@ function accessAllTypes() { s += msgAllTypes.getRepeatedBoolList(); s += msgAllTypes.getRepeatedBoolList()[0]; s += msgAllTypes.getRepeatedBoolList().length; - s += msgAllTypes.getRepeatedBytesList(); - s += msgAllTypes.getRepeatedBytesList()[0]; - s += msgAllTypes.getRepeatedBytesList().length; s += msgAllTypes.getRepeatedBytesList_asB64(); + s += msgAllTypes.getRepeatedBytesList_asB64()[0]; + s += msgAllTypes.getRepeatedBytesList_asB64().length; s += msgAllTypes.getRepeatedBytesList_asU8(); s += msgAllTypes.getRepeatedDoubleList(); s += msgAllTypes.getRepeatedDoubleList()[0]; diff --git a/js/experimental/runtime/kernel/kernel_test.js b/js/experimental/runtime/kernel/kernel_test.js index eba7c4a55a..e72be4f3b6 100644 --- a/js/experimental/runtime/kernel/kernel_test.js +++ b/js/experimental/runtime/kernel/kernel_test.js @@ -699,7 +699,7 @@ describe('Bytes access', () => { expect(accessor.getBytesWithDefault(1)).toEqual(simpleByteString); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer( createArrayBuffer(0x0A, 0x01, 0x00, 0x0A, 0x01, 0x01)); expect(accessor.getBytesWithDefault(1)).toEqual(simpleByteString); @@ -801,7 +801,7 @@ describe('Fixed32 access', () => { expect(accessor.getFixed32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x0D, 0x01, 0x00, 0x80, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00)); expect(accessor.getFixed32WithDefault(1)).toEqual(2); @@ -909,7 +909,7 @@ describe('Fixed64 access', () => { expect(accessor.getFixed64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)); @@ -1008,7 +1008,7 @@ describe('Float access', () => { expect(accessor.getFloatWithDefault(1)).toEqual(1); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x0D, 0x00, 0x00, 0x80, 0x3F, 0x0D, 0x00, 0x00, 0x80, 0xBF)); expect(accessor.getFloatWithDefault(1)).toEqual(-1); @@ -1110,7 +1110,7 @@ describe('Int32 access', () => { expect(accessor.getInt32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getInt32WithDefault(1)).toEqual(2); @@ -1207,7 +1207,7 @@ describe('Int64 access', () => { expect(accessor.getInt64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getInt64WithDefault(1)).toEqual(Int64.fromInt(2)); @@ -1306,7 +1306,7 @@ describe('Sfixed32 access', () => { expect(accessor.getSfixed32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x0D, 0x01, 0x00, 0x80, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00)); expect(accessor.getSfixed32WithDefault(1)).toEqual(2); @@ -1404,7 +1404,7 @@ describe('Sfixed64 access', () => { expect(accessor.getSfixed64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)); @@ -1502,7 +1502,7 @@ describe('Sint32 access', () => { expect(accessor.getSint32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x03, 0x08, 0x02)); expect(accessor.getSint32WithDefault(1)).toEqual(1); @@ -1599,7 +1599,7 @@ describe('SInt64 access', () => { expect(accessor.getSint64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getSint64WithDefault(1)).toEqual(Int64.fromInt(1)); @@ -1698,7 +1698,7 @@ describe('String access', () => { expect(accessor.getStringWithDefault(1)).toEqual('a'); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer( createArrayBuffer(0x0A, 0x01, 0x60, 0x0A, 0x01, 0x61)); expect(accessor.getStringWithDefault(1)).toEqual('a'); @@ -1789,7 +1789,7 @@ describe('Uint32 access', () => { expect(accessor.getUint32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getUint32WithDefault(1)).toEqual(2); @@ -1896,7 +1896,7 @@ describe('Uint64 access', () => { expect(accessor.getUint64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getUint64WithDefault(1)).toEqual(Int64.fromInt(2)); @@ -1996,7 +1996,7 @@ describe('Double access', () => { }); - it('decodes value from wire with multiple values being present', () => { + it('decodes value from wire with multple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF)); diff --git a/js/experimental/runtime/kernel/tag_test.js b/js/experimental/runtime/kernel/tag_test.js index 35137bb247..04a6cb6668 100644 --- a/js/experimental/runtime/kernel/tag_test.js +++ b/js/experimental/runtime/kernel/tag_test.js @@ -95,12 +95,12 @@ describe('skipField', () => { it('skips group in group', () => { const buffer = createArrayBuffer( - 0x0B, // start outer + 0x0B, // start outter 0x10, 0x01, // field: 2, value: 1 0x0B, // start inner group 0x10, 0x01, // payload inner group 0x0C, // stop inner group - 0x0C // end outer + 0x0C // end outter ); const bufferDecoder = BufferDecoder.fromArrayBuffer(buffer); bufferDecoder.setCursor(1); From b79dbb7db02ece81e004b91175f2299ad08678d9 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 21 Dec 2021 08:05:17 -0800 Subject: [PATCH 098/207] Project import generated by Copybara PiperOrigin-RevId: 417622470 --- js/experimental/runtime/kernel/reader.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/js/experimental/runtime/kernel/reader.js b/js/experimental/runtime/kernel/reader.js index 2b80e15bff..44708b5aec 100644 --- a/js/experimental/runtime/kernel/reader.js +++ b/js/experimental/runtime/kernel/reader.js @@ -97,19 +97,6 @@ function readSfixed64(bufferDecoder, start) { return Int64.fromBits(lowBits, highBits); } -/** - * Reads a sint32 value from the binary bytes encoded as varint. - * @param {!BufferDecoder} bufferDecoder Binary format encoded bytes. - * @param {number} start Start of the data. - * @return {number} - * @package - */ -function readSint32(bufferDecoder, start) { - const bits = bufferDecoder.getUnsignedVarint32At(start); - // Truncate upper bits and convert from zig zag to signd int - return (bits >>> 1) ^ -(bits & 0x01); -} - /** * Reads a sint64 value from the binary bytes encoded as varint. * @param {!BufferDecoder} bufferDecoder Binary format encoded bytes. @@ -125,6 +112,17 @@ function readSint64(bufferDecoder, start) { return Int64.fromBits(decodedLowerBits, decodedUpperBits); } +/** + * Reads a sint32 value from the binary bytes encoded as varint. + * @param {!BufferDecoder} bufferDecoder Binary format encoded bytes. + * @param {number} start Start of the data. + * @return {number} + * @package + */ +function readSint32(bufferDecoder, start) { + return readSint64(bufferDecoder, start).getLowBits(); +} + /** * Read a subarray of bytes representing a length delimited field. * @param {!BufferDecoder} bufferDecoder Binary format encoded bytes. From 1fe07f9ce2e98ca66a403b989d78a060f3153d5b Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 22 Dec 2021 15:01:34 -0800 Subject: [PATCH 099/207] Cherry-pick fix from #9311 into 3.18.x (#9320) * Dropped Ruby 2.4 support for CI and releases. * Removed Kokoro configs for old Ruby versions. * Update Dockerfile to allow it to be rebuilt Co-authored-by: Joshua Haberman --- kokoro/linux/dockerfile/test/ruby/Dockerfile | 6 ++---- kokoro/linux/ruby23/build.sh | 18 ------------------ kokoro/linux/ruby23/continuous.cfg | 11 ----------- kokoro/linux/ruby23/presubmit.cfg | 11 ----------- kokoro/linux/ruby24/build.sh | 18 ------------------ kokoro/linux/ruby24/continuous.cfg | 11 ----------- kokoro/linux/ruby24/presubmit.cfg | 11 ----------- kokoro/macos/ruby23/build.sh | 12 ------------ kokoro/macos/ruby23/continuous.cfg | 5 ----- kokoro/macos/ruby23/presubmit.cfg | 5 ----- kokoro/macos/ruby24/build.sh | 12 ------------ kokoro/macos/ruby24/continuous.cfg | 5 ----- kokoro/macos/ruby24/presubmit.cfg | 5 ----- .../ruby/macos/ruby/ruby_build_environment.sh | 2 +- ruby/Gemfile | 2 -- ruby/Rakefile | 4 ++-- 16 files changed, 5 insertions(+), 133 deletions(-) delete mode 100755 kokoro/linux/ruby23/build.sh delete mode 100644 kokoro/linux/ruby23/continuous.cfg delete mode 100644 kokoro/linux/ruby23/presubmit.cfg delete mode 100755 kokoro/linux/ruby24/build.sh delete mode 100644 kokoro/linux/ruby24/continuous.cfg delete mode 100644 kokoro/linux/ruby24/presubmit.cfg delete mode 100755 kokoro/macos/ruby23/build.sh delete mode 100644 kokoro/macos/ruby23/continuous.cfg delete mode 100644 kokoro/macos/ruby23/presubmit.cfg delete mode 100755 kokoro/macos/ruby24/build.sh delete mode 100644 kokoro/macos/ruby24/continuous.cfg delete mode 100644 kokoro/macos/ruby24/presubmit.cfg diff --git a/kokoro/linux/dockerfile/test/ruby/Dockerfile b/kokoro/linux/dockerfile/test/ruby/Dockerfile index b73bf84095..e8a70d5fee 100644 --- a/kokoro/linux/dockerfile/test/ruby/Dockerfile +++ b/kokoro/linux/dockerfile/test/ruby/Dockerfile @@ -23,13 +23,11 @@ RUN apt-get update && apt-get install -y \ && apt-get clean # Install rvm -RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys \ +RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys \ 409B6B1796C275462A1703113804BB82D39DC0E3 \ 7D2BAF1CF37B13E2069D6956105BD0E739499BDB -RUN \curl -sSL https://get.rvm.io | bash -s master +RUN \curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s master -RUN /bin/bash -l -c "rvm install 2.3.8" -RUN /bin/bash -l -c "rvm install 2.4.5" RUN /bin/bash -l -c "rvm install 2.5.1" RUN /bin/bash -l -c "rvm install 2.6.0" RUN /bin/bash -l -c "rvm install 2.7.0" diff --git a/kokoro/linux/ruby23/build.sh b/kokoro/linux/ruby23/build.sh deleted file mode 100755 index 503a320de2..0000000000 --- a/kokoro/linux/ruby23/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERHUB_ORGANIZATION=protobuftesting -export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="ruby23" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/ruby23/continuous.cfg b/kokoro/linux/ruby23/continuous.cfg deleted file mode 100644 index f5c64988bf..0000000000 --- a/kokoro/linux/ruby23/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby23/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/ruby23/presubmit.cfg b/kokoro/linux/ruby23/presubmit.cfg deleted file mode 100644 index f5c64988bf..0000000000 --- a/kokoro/linux/ruby23/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby23/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/ruby24/build.sh b/kokoro/linux/ruby24/build.sh deleted file mode 100755 index 68585aabc0..0000000000 --- a/kokoro/linux/ruby24/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERHUB_ORGANIZATION=protobuftesting -export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="ruby24" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/ruby24/continuous.cfg b/kokoro/linux/ruby24/continuous.cfg deleted file mode 100644 index a1ccfc0b8b..0000000000 --- a/kokoro/linux/ruby24/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby24/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/ruby24/presubmit.cfg b/kokoro/linux/ruby24/presubmit.cfg deleted file mode 100644 index a1ccfc0b8b..0000000000 --- a/kokoro/linux/ruby24/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby24/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/macos/ruby23/build.sh b/kokoro/macos/ruby23/build.sh deleted file mode 100755 index 5a29a997fc..0000000000 --- a/kokoro/macos/ruby23/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests - -# Change to repo root -cd $(dirname $0)/../../.. - -# Prepare worker environment to run tests -KOKORO_INSTALL_RVM=yes -source kokoro/macos/prepare_build_macos_rc - -./tests.sh ruby23 diff --git a/kokoro/macos/ruby23/continuous.cfg b/kokoro/macos/ruby23/continuous.cfg deleted file mode 100644 index c9b1f61284..0000000000 --- a/kokoro/macos/ruby23/continuous.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby23/build.sh" -timeout_mins: 1440 diff --git a/kokoro/macos/ruby23/presubmit.cfg b/kokoro/macos/ruby23/presubmit.cfg deleted file mode 100644 index c9b1f61284..0000000000 --- a/kokoro/macos/ruby23/presubmit.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby23/build.sh" -timeout_mins: 1440 diff --git a/kokoro/macos/ruby24/build.sh b/kokoro/macos/ruby24/build.sh deleted file mode 100755 index 10ac85f7a4..0000000000 --- a/kokoro/macos/ruby24/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests - -# Change to repo root -cd $(dirname $0)/../../.. - -# Prepare worker environment to run tests -KOKORO_INSTALL_RVM=yes -source kokoro/macos/prepare_build_macos_rc - -./tests.sh ruby24 diff --git a/kokoro/macos/ruby24/continuous.cfg b/kokoro/macos/ruby24/continuous.cfg deleted file mode 100644 index fada028fc5..0000000000 --- a/kokoro/macos/ruby24/continuous.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby24/build.sh" -timeout_mins: 1440 diff --git a/kokoro/macos/ruby24/presubmit.cfg b/kokoro/macos/ruby24/presubmit.cfg deleted file mode 100644 index fada028fc5..0000000000 --- a/kokoro/macos/ruby24/presubmit.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby24/build.sh" -timeout_mins: 1440 diff --git a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh index 046b604b40..8d9308d57d 100755 --- a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh +++ b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh @@ -66,7 +66,7 @@ set +x rvm use 2.5.0 set -x ruby --version | grep 'ruby 2.5.0' -for v in 2.6.0 2.5.1 2.4.0 2.3.0; do +for v in 2.6.0 2.5.1; do ccache -c rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=x86_64-darwin11 MAKE="$MAKE" done diff --git a/ruby/Gemfile b/ruby/Gemfile index 76b23ad91d..fa75df1563 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -1,5 +1,3 @@ source 'https://rubygems.org' gemspec - -gem "irb", "~> 1.1", "< 1.2.0" if RUBY_VERSION < "2.5" diff --git a/ruby/Rakefile b/ruby/Rakefile index c7187a6a89..5e788c7810 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -100,7 +100,7 @@ else ['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat| RakeCompilerDock.sh <<-"EOT", platform: plat bundle && \ - IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.0:2.4.0:2.3.0 + IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.0 EOT end end @@ -108,7 +108,7 @@ else if RUBY_PLATFORM =~ /darwin/ task 'gem:native' do system "rake genproto" - system "rake cross native gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.1:2.4.0:2.3.0" + system "rake cross native gem RUBY_CC_VERSION=3.0.0:2.7.0:2.6.0:2.5.1" end else task 'gem:native' => [:genproto, 'gem:windows'] From 0906af98708ebd8d6cb059111abcb524209c9ff1 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 12 Nov 2021 10:35:03 +0100 Subject: [PATCH 100/207] pin multibuild scripts to get manylinux1 wheels back --- kokoro/release/python/linux/build_artifacts.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kokoro/release/python/linux/build_artifacts.sh b/kokoro/release/python/linux/build_artifacts.sh index 31da562814..363af70937 100755 --- a/kokoro/release/python/linux/build_artifacts.sh +++ b/kokoro/release/python/linux/build_artifacts.sh @@ -25,7 +25,13 @@ rm -rf multibuild/ mkdir artifacts export ARTIFACT_DIR=$(pwd)/artifacts +# Pin multibuild script to a version just before the default +# manylinux image has switched from manylinux1 to manylinux2014. +# Also, pinning version avoid potentially unwanted future changes from +# silently creeping in. +# See https://github.com/protocolbuffers/protobuf/issues/9180 git clone https://github.com/matthew-brett/multibuild.git +(cd multibuild; git checkout 13a01725b0f0aa551ab34aa2311cdc1c77be4337) cp kokoro/release/python/linux/config.sh config.sh build_artifact_version() { From 7857b15afcf21a409b0cf991a8b30e16f9522ab2 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 16 Nov 2021 11:54:09 +0100 Subject: [PATCH 101/207] pin multibuild, set MB_ML_VER explicitly --- .../release/python/linux/build_artifacts.sh | 34 +++++++++++++------ .../release/python/macos/build_artifacts.sh | 9 ++++- .../python/windows/build_artifacts.bat | 9 +++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/kokoro/release/python/linux/build_artifacts.sh b/kokoro/release/python/linux/build_artifacts.sh index 363af70937..e1fe98c778 100755 --- a/kokoro/release/python/linux/build_artifacts.sh +++ b/kokoro/release/python/linux/build_artifacts.sh @@ -25,13 +25,14 @@ rm -rf multibuild/ mkdir artifacts export ARTIFACT_DIR=$(pwd)/artifacts -# Pin multibuild script to a version just before the default -# manylinux image has switched from manylinux1 to manylinux2014. -# Also, pinning version avoid potentially unwanted future changes from -# silently creeping in. -# See https://github.com/protocolbuffers/protobuf/issues/9180 git clone https://github.com/matthew-brett/multibuild.git -(cd multibuild; git checkout 13a01725b0f0aa551ab34aa2311cdc1c77be4337) +# Pin multibuild scripts at a known commit to avoid potentially unwanted future changes from +# silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). +# IMPORTANT: always pin multibuild at the same commit for: +# - linux/build_artifacts.sh +# - linux/build_artifacts.sh +# - windows/build_artifacts.bat +(cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313) cp kokoro/release/python/linux/config.sh config.sh build_artifact_version() { @@ -53,9 +54,20 @@ build_artifact_version() { sudo rm -rf $REPO_DIR } +build_x86_64_artifact_version() { + # Explicitly request building manylinux1 wheels, which is no longer the default. + # https://github.com/protocolbuffers/protobuf/issues/9180 + MB_ML_VER=1 + + # TODO(jtatermusch): currently when crosscompiling, "auditwheel repair" will be disabled + # since auditwheel doesn't work for crosscomiled wheels. + build_artifact_version $@ +} + build_crosscompiled_aarch64_artifact_version() { # crosscompilation is only supported with the dockcross manylinux2014 image DOCKER_IMAGE=dockcross/manylinux2014-aarch64:20210706-65bf2dd + MB_ML_VER=2014 PLAT=aarch64 # TODO(jtatermusch): currently when crosscompiling, "auditwheel repair" will be disabled @@ -63,11 +75,11 @@ build_crosscompiled_aarch64_artifact_version() { build_artifact_version $@ } -build_artifact_version 3.6 -build_artifact_version 3.7 -build_artifact_version 3.8 -build_artifact_version 3.9 -build_artifact_version 3.10 +build_x86_64_artifact_version 3.6 +build_x86_64_artifact_version 3.7 +build_x86_64_artifact_version 3.8 +build_x86_64_artifact_version 3.9 +build_x86_64_artifact_version 3.10 build_crosscompiled_aarch64_artifact_version 3.7 build_crosscompiled_aarch64_artifact_version 3.8 diff --git a/kokoro/release/python/macos/build_artifacts.sh b/kokoro/release/python/macos/build_artifacts.sh index 75644539fa..5b6d035431 100755 --- a/kokoro/release/python/macos/build_artifacts.sh +++ b/kokoro/release/python/macos/build_artifacts.sh @@ -25,7 +25,14 @@ rm -rf multibuild/ mkdir artifacts export ARTIFACT_DIR=$(pwd)/artifacts -git clone https://github.com/matthew-brett/multibuild.git +git clone https://github.com/matthew-brett/ +# Pin multibuild scripts at a known commit to avoid potentially unwanted future changes from +# silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). +# IMPORTANT: always pin multibuild at the same commit for: +# - linux/build_artifacts.sh +# - linux/build_artifacts.sh +# - windows/build_artifacts.bat +(cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313) cp kokoro/release/python/macos/config.sh config.sh OLD_PATH=$PATH diff --git a/kokoro/release/python/windows/build_artifacts.bat b/kokoro/release/python/windows/build_artifacts.bat index ac466a901d..a8f8f78314 100644 --- a/kokoro/release/python/windows/build_artifacts.bat +++ b/kokoro/release/python/windows/build_artifacts.bat @@ -14,6 +14,15 @@ set OLD_PATH=C:\Program Files (x86)\MSBuild\14.0\bin\;%PATH% REM Fetch multibuild git clone https://github.com/matthew-brett/multibuild.git +REM Pin multibuild scripts at a known commit to avoid potentially unwanted future changes from +REM silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). +REM IMPORTANT: always pin multibuild at the same commit for: +REM - linux/build_artifacts.sh +REM - linux/build_artifacts.sh +REM - windows/build_artifacts.bat +cd multibuild +git checkout b89bb903e94308be79abefa4f436bf123ebb1313 +cd .. REM Install zlib mkdir zlib From ea60c9cb08bb6f7c967d0ace9714aed311fda255 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 3 Jan 2022 10:54:28 +0100 Subject: [PATCH 102/207] use manylinux2010 for python3.10 wheel on x86_64 --- .../release/python/linux/build_artifacts.sh | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/kokoro/release/python/linux/build_artifacts.sh b/kokoro/release/python/linux/build_artifacts.sh index e1fe98c778..9a3fc5841f 100755 --- a/kokoro/release/python/linux/build_artifacts.sh +++ b/kokoro/release/python/linux/build_artifacts.sh @@ -54,17 +54,20 @@ build_artifact_version() { sudo rm -rf $REPO_DIR } -build_x86_64_artifact_version() { +build_x86_64_manylinux1_artifact_version() { # Explicitly request building manylinux1 wheels, which is no longer the default. # https://github.com/protocolbuffers/protobuf/issues/9180 MB_ML_VER=1 + build_artifact_version $@ +} - # TODO(jtatermusch): currently when crosscompiling, "auditwheel repair" will be disabled - # since auditwheel doesn't work for crosscomiled wheels. +build_x86_64_manylinux2010_artifact_version() { + # Explicitly request building manylinux2010 wheels + MB_ML_VER=2010 build_artifact_version $@ } -build_crosscompiled_aarch64_artifact_version() { +build_crosscompiled_aarch64_manylinux2014_artifact_version() { # crosscompilation is only supported with the dockcross manylinux2014 image DOCKER_IMAGE=dockcross/manylinux2014-aarch64:20210706-65bf2dd MB_ML_VER=2014 @@ -75,13 +78,13 @@ build_crosscompiled_aarch64_artifact_version() { build_artifact_version $@ } -build_x86_64_artifact_version 3.6 -build_x86_64_artifact_version 3.7 -build_x86_64_artifact_version 3.8 -build_x86_64_artifact_version 3.9 -build_x86_64_artifact_version 3.10 +build_x86_64_manylinux1_artifact_version 3.6 +build_x86_64_manylinux1_artifact_version 3.7 +build_x86_64_manylinux1_artifact_version 3.8 +build_x86_64_manylinux1_artifact_version 3.9 +build_x86_64_manylinux2010_artifact_version 3.10 -build_crosscompiled_aarch64_artifact_version 3.7 -build_crosscompiled_aarch64_artifact_version 3.8 -build_crosscompiled_aarch64_artifact_version 3.9 -build_crosscompiled_aarch64_artifact_version 3.10 +build_crosscompiled_aarch64_manylinux2014_artifact_version 3.7 +build_crosscompiled_aarch64_manylinux2014_artifact_version 3.8 +build_crosscompiled_aarch64_manylinux2014_artifact_version 3.9 +build_crosscompiled_aarch64_manylinux2014_artifact_version 3.10 From 6f8d82c2b1f2d391033d7babf20bb2b8857ef688 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 3 Jan 2022 14:59:51 +0100 Subject: [PATCH 103/207] fixup linux python artifact build --- kokoro/release/python/macos/build_artifacts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kokoro/release/python/macos/build_artifacts.sh b/kokoro/release/python/macos/build_artifacts.sh index 5b6d035431..aeb4242a6b 100755 --- a/kokoro/release/python/macos/build_artifacts.sh +++ b/kokoro/release/python/macos/build_artifacts.sh @@ -25,7 +25,7 @@ rm -rf multibuild/ mkdir artifacts export ARTIFACT_DIR=$(pwd)/artifacts -git clone https://github.com/matthew-brett/ +git clone https://github.com/matthew-brett/multibuild.git # Pin multibuild scripts at a known commit to avoid potentially unwanted future changes from # silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). # IMPORTANT: always pin multibuild at the same commit for: From b17c8ca979c40987a6947be2fa7090e6c5bac895 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Tue, 4 Jan 2022 21:50:47 +0000 Subject: [PATCH 104/207] fix spelling errors (#9368) * fix spelling errors * outter --> outer --- js/experimental/runtime/kernel/kernel_test.js | 28 +++++++++---------- js/experimental/runtime/kernel/tag_test.js | 4 +-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/js/experimental/runtime/kernel/kernel_test.js b/js/experimental/runtime/kernel/kernel_test.js index e72be4f3b6..eba7c4a55a 100644 --- a/js/experimental/runtime/kernel/kernel_test.js +++ b/js/experimental/runtime/kernel/kernel_test.js @@ -699,7 +699,7 @@ describe('Bytes access', () => { expect(accessor.getBytesWithDefault(1)).toEqual(simpleByteString); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer( createArrayBuffer(0x0A, 0x01, 0x00, 0x0A, 0x01, 0x01)); expect(accessor.getBytesWithDefault(1)).toEqual(simpleByteString); @@ -801,7 +801,7 @@ describe('Fixed32 access', () => { expect(accessor.getFixed32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x0D, 0x01, 0x00, 0x80, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00)); expect(accessor.getFixed32WithDefault(1)).toEqual(2); @@ -909,7 +909,7 @@ describe('Fixed64 access', () => { expect(accessor.getFixed64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)); @@ -1008,7 +1008,7 @@ describe('Float access', () => { expect(accessor.getFloatWithDefault(1)).toEqual(1); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x0D, 0x00, 0x00, 0x80, 0x3F, 0x0D, 0x00, 0x00, 0x80, 0xBF)); expect(accessor.getFloatWithDefault(1)).toEqual(-1); @@ -1110,7 +1110,7 @@ describe('Int32 access', () => { expect(accessor.getInt32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getInt32WithDefault(1)).toEqual(2); @@ -1207,7 +1207,7 @@ describe('Int64 access', () => { expect(accessor.getInt64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getInt64WithDefault(1)).toEqual(Int64.fromInt(2)); @@ -1306,7 +1306,7 @@ describe('Sfixed32 access', () => { expect(accessor.getSfixed32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x0D, 0x01, 0x00, 0x80, 0x00, 0x0D, 0x02, 0x00, 0x00, 0x00)); expect(accessor.getSfixed32WithDefault(1)).toEqual(2); @@ -1404,7 +1404,7 @@ describe('Sfixed64 access', () => { expect(accessor.getSfixed64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)); @@ -1502,7 +1502,7 @@ describe('Sint32 access', () => { expect(accessor.getSint32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x03, 0x08, 0x02)); expect(accessor.getSint32WithDefault(1)).toEqual(1); @@ -1599,7 +1599,7 @@ describe('SInt64 access', () => { expect(accessor.getSint64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getSint64WithDefault(1)).toEqual(Int64.fromInt(1)); @@ -1698,7 +1698,7 @@ describe('String access', () => { expect(accessor.getStringWithDefault(1)).toEqual('a'); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer( createArrayBuffer(0x0A, 0x01, 0x60, 0x0A, 0x01, 0x61)); expect(accessor.getStringWithDefault(1)).toEqual('a'); @@ -1789,7 +1789,7 @@ describe('Uint32 access', () => { expect(accessor.getUint32WithDefault(1)).toEqual(1); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getUint32WithDefault(1)).toEqual(2); @@ -1896,7 +1896,7 @@ describe('Uint64 access', () => { expect(accessor.getUint64WithDefault(1)).toEqual(Int64.fromInt(1)); }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer(0x08, 0x01, 0x08, 0x02)); expect(accessor.getUint64WithDefault(1)).toEqual(Int64.fromInt(2)); @@ -1996,7 +1996,7 @@ describe('Double access', () => { }); - it('decodes value from wire with multple values being present', () => { + it('decodes value from wire with multiple values being present', () => { const accessor = Kernel.fromArrayBuffer(createArrayBuffer( 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF)); diff --git a/js/experimental/runtime/kernel/tag_test.js b/js/experimental/runtime/kernel/tag_test.js index 04a6cb6668..35137bb247 100644 --- a/js/experimental/runtime/kernel/tag_test.js +++ b/js/experimental/runtime/kernel/tag_test.js @@ -95,12 +95,12 @@ describe('skipField', () => { it('skips group in group', () => { const buffer = createArrayBuffer( - 0x0B, // start outter + 0x0B, // start outer 0x10, 0x01, // field: 2, value: 1 0x0B, // start inner group 0x10, 0x01, // payload inner group 0x0C, // stop inner group - 0x0C // end outter + 0x0C // end outer ); const bufferDecoder = BufferDecoder.fromArrayBuffer(buffer); bufferDecoder.setCursor(1); From c26b1c87d7ad6a36c4f1f0763b107f3a8b3257eb Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Wed, 5 Jan 2022 16:06:40 +1100 Subject: [PATCH 105/207] fixing php 8.1 deprecation warnings php 8.1 is more strict, and raises some deprecation notices with existing protobuf code. Not all of the deprecations can be fixed without dropping support for php7.x (eg, the 'mixed' type doesn't appear until 8.1, and union types until 8.0, but as an interim solution the 'ReturnTypeWillChange' attribute can be used to suppress the notices. In passing, also be explicit about a cast from float to int in 'zigZagEncode64' which 8.1 also complains about when running tests. --- php/src/Google/Protobuf/Internal/GPBWire.php | 2 +- php/src/Google/Protobuf/Internal/MapField.php | 13 ++++++++----- php/src/Google/Protobuf/Internal/MapFieldIter.php | 12 +++++++----- php/src/Google/Protobuf/Internal/RepeatedField.php | 12 +++++++----- .../Google/Protobuf/Internal/RepeatedFieldIter.php | 8 +++++--- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/php/src/Google/Protobuf/Internal/GPBWire.php b/php/src/Google/Protobuf/Internal/GPBWire.php index 29569530fd..034f5df92e 100644 --- a/php/src/Google/Protobuf/Internal/GPBWire.php +++ b/php/src/Google/Protobuf/Internal/GPBWire.php @@ -146,7 +146,7 @@ class GPBWire return bcsub(bcmul(bcsub(0, $int64), 2), 1); } } else { - return ($int64 << 1) ^ ($int64 >> 63); + return ((int)$int64 << 1) ^ ((int)$int64 >> 63); } } diff --git a/php/src/Google/Protobuf/Internal/MapField.php b/php/src/Google/Protobuf/Internal/MapField.php index 719fb350bd..20ac6c2d66 100644 --- a/php/src/Google/Protobuf/Internal/MapField.php +++ b/php/src/Google/Protobuf/Internal/MapField.php @@ -37,6 +37,8 @@ namespace Google\Protobuf\Internal; +use Traversable; + /** * MapField is used by generated protocol message classes to manipulate map * fields. It can be used like native PHP array. @@ -134,6 +136,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Invalid type for index. * @throws \ErrorException Non-existing index. */ + #[\ReturnTypeWillChange] public function offsetGet($key) { return $this->container[$key]; @@ -151,7 +154,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Invalid type for value. * @throws \ErrorException Non-existing key. */ - public function offsetSet($key, $value) + public function offsetSet($key, $value): void { $this->checkKey($this->key_type, $key); @@ -209,7 +212,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @return void * @throws \ErrorException Invalid type for key. */ - public function offsetUnset($key) + public function offsetUnset($key): void { $this->checkKey($this->key_type, $key); unset($this->container[$key]); @@ -224,7 +227,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @return bool True if the element at the given key exists. * @throws \ErrorException Invalid type for key. */ - public function offsetExists($key) + public function offsetExists($key): bool { $this->checkKey($this->key_type, $key); return isset($this->container[$key]); @@ -233,7 +236,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable /** * @ignore */ - public function getIterator() + public function getIterator(): Traversable { return new MapFieldIter($this->container, $this->key_type); } @@ -245,7 +248,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * * @return integer The number of stored elements. */ - public function count() + public function count(): int { return count($this->container); } diff --git a/php/src/Google/Protobuf/Internal/MapFieldIter.php b/php/src/Google/Protobuf/Internal/MapFieldIter.php index 4e18005ea8..8370787876 100644 --- a/php/src/Google/Protobuf/Internal/MapFieldIter.php +++ b/php/src/Google/Protobuf/Internal/MapFieldIter.php @@ -68,9 +68,9 @@ class MapFieldIter implements \Iterator * * @return void */ - public function rewind() + public function rewind(): void { - return reset($this->container); + reset($this->container); } /** @@ -78,6 +78,7 @@ class MapFieldIter implements \Iterator * * @return object The element at the current position. */ + #[\ReturnTypeWillChange] public function current() { return current($this->container); @@ -88,6 +89,7 @@ class MapFieldIter implements \Iterator * * @return object The current key. */ + #[\ReturnTypeWillChange] public function key() { $key = key($this->container); @@ -117,9 +119,9 @@ class MapFieldIter implements \Iterator * * @return void */ - public function next() + public function next(): void { - return next($this->container); + next($this->container); } /** @@ -127,7 +129,7 @@ class MapFieldIter implements \Iterator * * @return bool True if there are more elements to iterate. */ - public function valid() + public function valid(): bool { return key($this->container) !== null; } diff --git a/php/src/Google/Protobuf/Internal/RepeatedField.php b/php/src/Google/Protobuf/Internal/RepeatedField.php index c0331ff38e..e589b644fe 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -39,6 +39,7 @@ namespace Google\Protobuf\Internal; use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBUtil; +use Traversable; /** * RepeatedField is used by generated protocol message classes to manipulate @@ -121,6 +122,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Invalid type for index. * @throws \ErrorException Non-existing index. */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->container[$offset]; @@ -138,7 +140,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Non-existing index. * @throws \ErrorException Incorrect type of the element. */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { switch ($this->type) { case GPBType::SFIXED32: @@ -209,7 +211,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException The element to be removed is not at the end of the * RepeatedField. */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { $count = count($this->container); if (!is_numeric($offset) || $count === 0 || $offset !== $count - 1) { @@ -230,7 +232,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @return bool True if the element at the given offset exists. * @throws \ErrorException Invalid type for index. */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->container[$offset]); } @@ -238,7 +240,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable /** * @ignore */ - public function getIterator() + public function getIterator(): Traversable { return new RepeatedFieldIter($this->container); } @@ -250,7 +252,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * @return integer The number of stored elements. */ - public function count() + public function count(): int { return count($this->container); } diff --git a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php index 2b6f82309b..ad86f95f94 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php +++ b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php @@ -71,7 +71,7 @@ class RepeatedFieldIter implements \Iterator * * @return void */ - public function rewind() + public function rewind(): void { $this->position = 0; } @@ -81,6 +81,7 @@ class RepeatedFieldIter implements \Iterator * * @return object The element at the current position. */ + #[\ReturnTypeWillChange] public function current() { return $this->container[$this->position]; @@ -91,6 +92,7 @@ class RepeatedFieldIter implements \Iterator * * @return integer The current position. */ + #[\ReturnTypeWillChange] public function key() { return $this->position; @@ -101,7 +103,7 @@ class RepeatedFieldIter implements \Iterator * * @return void */ - public function next() + public function next(): void { ++$this->position; } @@ -111,7 +113,7 @@ class RepeatedFieldIter implements \Iterator * * @return bool True if there are more elements to iterate. */ - public function valid() + public function valid(): bool { return isset($this->container[$this->position]); } From f681c8d9e6880d9f5e06ec67328e46e3ce562283 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 5 Jan 2022 08:26:20 -0800 Subject: [PATCH 106/207] Fix Ruby release build by pinning rake-compiler-dock version (#9372) Our Ruby release build broke at some point in the past day or so, and I strongly suspect it is due to a new version (1.2.0) of rake-compiler-dock. This commit pins the version to 1.1.0 as a temporary fix. --- ruby/google-protobuf.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 7e2dd14aae..810c6fff88 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| else s.files += Dir.glob('ext/**/*') s.extensions= ["ext/google/protobuf_c/extconf.rb"] - s.add_development_dependency "rake-compiler-dock", ">= 1.1.0", "< 2.0" + s.add_development_dependency "rake-compiler-dock", "= 1.1.0" end s.test_files = ["tests/basic.rb", "tests/stress.rb", From c555c3dd14feb25d6283cbbd4903fe8108667c72 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 5 Jan 2022 08:50:29 -0800 Subject: [PATCH 107/207] Improve performance of parsing unknown fields in Java (#9371) Credit should go to @elharo for most of these Java changes--I am just cherry-picking them from our internal codebase. The one thing I did change was to give the UTF-8 validation tests their own Bazel test target. This makes it possible to give the other tests a shorter timeout, which is important for UnknownFieldSetPerformanceTest in particular. --- Makefile.am | 1 + java/core/BUILD | 24 +- .../com/google/protobuf/UnknownFieldSet.java | 427 +++++++++--------- .../UnknownFieldSetPerformanceTest.java | 78 ++++ .../google/protobuf/UnknownFieldSetTest.java | 182 +++++++- java/lite/pom.xml | 1 + 6 files changed, 499 insertions(+), 214 deletions(-) create mode 100644 java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java diff --git a/Makefile.am b/Makefile.am index 9534b42ee5..43a6bffe56 100644 --- a/Makefile.am +++ b/Makefile.am @@ -496,6 +496,7 @@ java_EXTRA_DIST= java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java \ java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java \ java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java \ + java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java \ java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java \ java/core/src/test/java/com/google/protobuf/Utf8Test.java \ java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java \ diff --git a/java/core/BUILD b/java/core/BUILD index 20bf589906..aa7ba62155 100644 --- a/java/core/BUILD +++ b/java/core/BUILD @@ -239,6 +239,7 @@ test_suite( "conformance_test", "core_build_test", "core_tests", + "utf8_tests", ], ) @@ -258,10 +259,12 @@ conformance_test( junit_tests( name = "core_tests", - size = "large", + size = "small", srcs = glob( ["src/test/java/**/*.java"], exclude = [ + "src/test/java/com/google/protobuf/DecodeUtf8Test.java", + "src/test/java/com/google/protobuf/IsValidUtf8Test.java", "src/test/java/com/google/protobuf/TestUtil.java", "src/test/java/com/google/protobuf/TestUtilLite.java", ], @@ -279,6 +282,24 @@ junit_tests( ], ) +# The UTF-8 validation tests are much slower than the other tests, so they get +# their own test target with a longer timeout. +junit_tests( + name = "utf8_tests", + size = "large", + srcs = [ + "src/test/java/com/google/protobuf/DecodeUtf8Test.java", + "src/test/java/com/google/protobuf/IsValidUtf8Test.java", + "src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java", + ], + deps = [ + ":core", + "@maven//:com_google_guava_guava", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], +) + java_lite_proto_library( name = "generic_test_protos_java_proto_lite", visibility = [ @@ -361,6 +382,7 @@ LITE_TEST_EXCLUSIONS = [ "src/test/java/com/google/protobuf/TypeRegistryTest.java", "src/test/java/com/google/protobuf/UnknownEnumValueTest.java", "src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java", + "src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java", "src/test/java/com/google/protobuf/UnknownFieldSetTest.java", "src/test/java/com/google/protobuf/WellKnownTypesTest.java", "src/test/java/com/google/protobuf/WireFormatTest.java", diff --git a/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java index ba2f9df08e..5c482d62da 100644 --- a/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java @@ -43,13 +43,13 @@ import java.util.Map; import java.util.TreeMap; /** - * {@code UnknownFieldSet} is used to keep track of fields which were seen when parsing a protocol + * {@code UnknownFieldSet} keeps track of fields which were seen when parsing a protocol * message but whose field numbers or types are unrecognized. This most frequently occurs when new * fields are added to a message type and then messages containing those fields are read by old * software that was compiled before the new types were added. * *

Every {@link Message} contains an {@code UnknownFieldSet} (and every {@link Message.Builder} - * contains an {@link Builder}). + * contains a {@link Builder}). * *

Most users will never need to use this class. * @@ -57,9 +57,13 @@ import java.util.TreeMap; */ public final class UnknownFieldSet implements MessageLite { - private UnknownFieldSet() { - fields = null; - fieldsDescending = null; + private final TreeMap fields; + + /** + * Construct an {@code UnknownFieldSet} around the given map. + */ + UnknownFieldSet(TreeMap fields) { + this.fields = fields; } /** Create a new {@link Builder}. */ @@ -68,7 +72,7 @@ public final class UnknownFieldSet implements MessageLite { } /** Create a new {@link Builder} and initialize it to be a copy of {@code copyFrom}. */ - public static Builder newBuilder(final UnknownFieldSet copyFrom) { + public static Builder newBuilder(UnknownFieldSet copyFrom) { return newBuilder().mergeFrom(copyFrom); } @@ -83,25 +87,11 @@ public final class UnknownFieldSet implements MessageLite { } private static final UnknownFieldSet defaultInstance = - new UnknownFieldSet( - Collections.emptyMap(), Collections.emptyMap()); - - /** - * Construct an {@code UnknownFieldSet} around the given map. The map is expected to be immutable. - */ - UnknownFieldSet(final Map fields, final Map fieldsDescending) { - this.fields = fields; - this.fieldsDescending = fieldsDescending; - } - - private final Map fields; - - /** A copy of {@link #fields} who's iterator order is reversed. */ - private final Map fieldsDescending; + new UnknownFieldSet(new TreeMap()); @Override - public boolean equals(final Object other) { + public boolean equals(Object other) { if (this == other) { return true; } @@ -110,29 +100,33 @@ public final class UnknownFieldSet implements MessageLite { @Override public int hashCode() { + if (fields.isEmpty()) { // avoid allocation of iterator. + // This optimization may not be helpful but it is needed for the allocation tests to pass. + return 0; + } return fields.hashCode(); } /** Get a map of fields in the set by number. */ public Map asMap() { - return fields; + return (Map) fields.clone(); } /** Check if the given field number is present in the set. */ - public boolean hasField(final int number) { + public boolean hasField(int number) { return fields.containsKey(number); } /** Get a field by number. Returns an empty field if not present. Never returns {@code null}. */ - public Field getField(final int number) { - final Field result = fields.get(number); + public Field getField(int number) { + Field result = fields.get(number); return (result == null) ? Field.getDefaultInstance() : result; } /** Serializes the set and writes it to {@code output}. */ @Override - public void writeTo(final CodedOutputStream output) throws IOException { - for (final Map.Entry entry : fields.entrySet()) { + public void writeTo(CodedOutputStream output) throws IOException { + for (Map.Entry entry : fields.entrySet()) { Field field = entry.getValue(); field.writeTo(entry.getKey(), output); } @@ -154,10 +148,10 @@ public final class UnknownFieldSet implements MessageLite { @Override public ByteString toByteString() { try { - final ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize()); + ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize()); writeTo(out.getCodedOutput()); return out.build(); - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException( "Serializing to a ByteString threw an IOException (should never happen).", e); } @@ -170,12 +164,12 @@ public final class UnknownFieldSet implements MessageLite { @Override public byte[] toByteArray() { try { - final byte[] result = new byte[getSerializedSize()]; - final CodedOutputStream output = CodedOutputStream.newInstance(result); + byte[] result = new byte[getSerializedSize()]; + CodedOutputStream output = CodedOutputStream.newInstance(result); writeTo(output); output.checkNoSpaceLeft(); return result; - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException( "Serializing to a byte array threw an IOException (should never happen).", e); } @@ -186,16 +180,16 @@ public final class UnknownFieldSet implements MessageLite { * {@link #writeTo(CodedOutputStream)}. */ @Override - public void writeTo(final OutputStream output) throws IOException { - final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); + public void writeTo(OutputStream output) throws IOException { + CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); writeTo(codedOutput); codedOutput.flush(); } @Override public void writeDelimitedTo(OutputStream output) throws IOException { - final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); - codedOutput.writeRawVarint32(getSerializedSize()); + CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); + codedOutput.writeUInt32NoTag(getSerializedSize()); writeTo(codedOutput); codedOutput.flush(); } @@ -204,15 +198,17 @@ public final class UnknownFieldSet implements MessageLite { @Override public int getSerializedSize() { int result = 0; - for (final Map.Entry entry : fields.entrySet()) { - result += entry.getValue().getSerializedSize(entry.getKey()); + if (!fields.isEmpty()) { + for (Map.Entry entry : fields.entrySet()) { + result += entry.getValue().getSerializedSize(entry.getKey()); + } } return result; } /** Serializes the set and writes it to {@code output} using {@code MessageSet} wire format. */ - public void writeAsMessageSetTo(final CodedOutputStream output) throws IOException { - for (final Map.Entry entry : fields.entrySet()) { + public void writeAsMessageSetTo(CodedOutputStream output) throws IOException { + for (Map.Entry entry : fields.entrySet()) { entry.getValue().writeAsMessageSetExtensionTo(entry.getKey(), output); } } @@ -221,7 +217,7 @@ public final class UnknownFieldSet implements MessageLite { void writeTo(Writer writer) throws IOException { if (writer.fieldOrder() == Writer.FieldOrder.DESCENDING) { // Write fields in descending order. - for (Map.Entry entry : fieldsDescending.entrySet()) { + for (Map.Entry entry : fields.descendingMap().entrySet()) { entry.getValue().writeTo(entry.getKey(), writer); } } else { @@ -233,15 +229,15 @@ public final class UnknownFieldSet implements MessageLite { } /** Serializes the set and writes it to {@code writer} using {@code MessageSet} wire format. */ - void writeAsMessageSetTo(final Writer writer) throws IOException { + void writeAsMessageSetTo(Writer writer) throws IOException { if (writer.fieldOrder() == Writer.FieldOrder.DESCENDING) { // Write fields in descending order. - for (final Map.Entry entry : fieldsDescending.entrySet()) { + for (Map.Entry entry : fields.descendingMap().entrySet()) { entry.getValue().writeAsMessageSetExtensionTo(entry.getKey(), writer); } } else { // Write fields in ascending order. - for (final Map.Entry entry : fields.entrySet()) { + for (Map.Entry entry : fields.entrySet()) { entry.getValue().writeAsMessageSetExtensionTo(entry.getKey(), writer); } } @@ -250,7 +246,7 @@ public final class UnknownFieldSet implements MessageLite { /** Get the number of bytes required to encode this set using {@code MessageSet} wire format. */ public int getSerializedSizeAsMessageSet() { int result = 0; - for (final Map.Entry entry : fields.entrySet()) { + for (Map.Entry entry : fields.entrySet()) { result += entry.getValue().getSerializedSizeAsMessageSetExtension(entry.getKey()); } return result; @@ -264,23 +260,23 @@ public final class UnknownFieldSet implements MessageLite { } /** Parse an {@code UnknownFieldSet} from the given input stream. */ - public static UnknownFieldSet parseFrom(final CodedInputStream input) throws IOException { + public static UnknownFieldSet parseFrom(CodedInputStream input) throws IOException { return newBuilder().mergeFrom(input).build(); } /** Parse {@code data} as an {@code UnknownFieldSet} and return it. */ - public static UnknownFieldSet parseFrom(final ByteString data) + public static UnknownFieldSet parseFrom(ByteString data) throws InvalidProtocolBufferException { return newBuilder().mergeFrom(data).build(); } /** Parse {@code data} as an {@code UnknownFieldSet} and return it. */ - public static UnknownFieldSet parseFrom(final byte[] data) throws InvalidProtocolBufferException { + public static UnknownFieldSet parseFrom(byte[] data) throws InvalidProtocolBufferException { return newBuilder().mergeFrom(data).build(); } /** Parse an {@code UnknownFieldSet} from {@code input} and return it. */ - public static UnknownFieldSet parseFrom(final InputStream input) throws IOException { + public static UnknownFieldSet parseFrom(InputStream input) throws IOException { return newBuilder().mergeFrom(input).build(); } @@ -309,64 +305,43 @@ public final class UnknownFieldSet implements MessageLite { // This constructor should never be called directly (except from 'create'). private Builder() {} - private Map fields; - - // Optimization: We keep around a builder for the last field that was - // modified so that we can efficiently add to it multiple times in a - // row (important when parsing an unknown repeated field). - private int lastFieldNumber; - private Field.Builder lastField; + private TreeMap fieldBuilders = new TreeMap<>(); private static Builder create() { - Builder builder = new Builder(); - builder.reinitialize(); - return builder; + return new Builder(); } /** * Get a field builder for the given field number which includes any values that already exist. */ - private Field.Builder getFieldBuilder(final int number) { - if (lastField != null) { - if (number == lastFieldNumber) { - return lastField; - } - // Note: addField() will reset lastField and lastFieldNumber. - addField(lastFieldNumber, lastField.build()); - } + private Field.Builder getFieldBuilder(int number) { if (number == 0) { return null; } else { - final Field existing = fields.get(number); - lastFieldNumber = number; - lastField = Field.newBuilder(); - if (existing != null) { - lastField.mergeFrom(existing); + Field.Builder builder = fieldBuilders.get(number); + if (builder == null) { + builder = Field.newBuilder(); + fieldBuilders.put(number, builder); } - return lastField; + return builder; } } /** * Build the {@link UnknownFieldSet} and return it. - * - *

Once {@code build()} has been called, the {@code Builder} will no longer be usable. - * Calling any method after {@code build()} will result in undefined behavior and can cause a - * {@code NullPointerException} to be thrown. */ @Override public UnknownFieldSet build() { - getFieldBuilder(0); // Force lastField to be built. - final UnknownFieldSet result; - if (fields.isEmpty()) { + UnknownFieldSet result; + if (fieldBuilders.isEmpty()) { result = getDefaultInstance(); } else { - Map descendingFields = null; - descendingFields = - Collections.unmodifiableMap(((TreeMap) fields).descendingMap()); - result = new UnknownFieldSet(Collections.unmodifiableMap(fields), descendingFields); + TreeMap fields = new TreeMap<>(); + for (Map.Entry entry : fieldBuilders.entrySet()) { + fields.put(entry.getKey(), entry.getValue().build()); + } + result = new UnknownFieldSet(fields); } - fields = null; return result; } @@ -378,11 +353,13 @@ public final class UnknownFieldSet implements MessageLite { @Override public Builder clone() { - getFieldBuilder(0); // Force lastField to be built. - Map descendingFields = null; - descendingFields = - Collections.unmodifiableMap(((TreeMap) fields).descendingMap()); - return UnknownFieldSet.newBuilder().mergeFrom(new UnknownFieldSet(fields, descendingFields)); + Builder clone = UnknownFieldSet.newBuilder(); + for (Map.Entry entry : fieldBuilders.entrySet()) { + Integer key = entry.getKey(); + Field.Builder value = entry.getValue(); + clone.fieldBuilders.put(key, value.clone()); + } + return clone; } @Override @@ -390,31 +367,24 @@ public final class UnknownFieldSet implements MessageLite { return UnknownFieldSet.getDefaultInstance(); } - private void reinitialize() { - fields = Collections.emptyMap(); - lastFieldNumber = 0; - lastField = null; - } - /** Reset the builder to an empty set. */ @Override public Builder clear() { - reinitialize(); + fieldBuilders = new TreeMap<>(); return this; } - /** Clear fields from the set with a given field number. */ - public Builder clearField(final int number) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); - } - if (lastField != null && lastFieldNumber == number) { - // Discard this. - lastField = null; - lastFieldNumber = 0; + /** + * Clear fields from the set with a given field number. + * + * @throws IllegalArgumentException if number is not positive + */ + public Builder clearField(int number) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } - if (fields.containsKey(number)) { - fields.remove(number); + if (fieldBuilders.containsKey(number)) { + fieldBuilders.remove(number); } return this; } @@ -423,9 +393,9 @@ public final class UnknownFieldSet implements MessageLite { * Merge the fields from {@code other} into this set. If a field number exists in both sets, * {@code other}'s values for that field will be appended to the values in this set. */ - public Builder mergeFrom(final UnknownFieldSet other) { + public Builder mergeFrom(UnknownFieldSet other) { if (other != getDefaultInstance()) { - for (final Map.Entry entry : other.fields.entrySet()) { + for (Map.Entry entry : other.fields.entrySet()) { mergeField(entry.getKey(), entry.getValue()); } } @@ -435,10 +405,12 @@ public final class UnknownFieldSet implements MessageLite { /** * Add a field to the {@code UnknownFieldSet}. If a field with the same number already exists, * the two are merged. + * + * @throws IllegalArgumentException if number is not positive */ - public Builder mergeField(final int number, final Field field) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); + public Builder mergeField(int number, final Field field) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } if (hasField(number)) { getFieldBuilder(number).mergeFrom(field); @@ -454,10 +426,12 @@ public final class UnknownFieldSet implements MessageLite { /** * Convenience method for merging a new field containing a single varint value. This is used in * particular when an unknown enum value is encountered. + * + * @throws IllegalArgumentException if number is not positive */ - public Builder mergeVarintField(final int number, final int value) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); + public Builder mergeVarintField(int number, int value) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } getFieldBuilder(number).addVarint(value); return this; @@ -467,40 +441,33 @@ public final class UnknownFieldSet implements MessageLite { * Convenience method for merging a length-delimited field. * *

For use by generated code only. + * + * @throws IllegalArgumentException if number is not positive */ - public Builder mergeLengthDelimitedField(final int number, final ByteString value) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); + public Builder mergeLengthDelimitedField(int number, ByteString value) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } getFieldBuilder(number).addLengthDelimited(value); return this; } /** Check if the given field number is present in the set. */ - public boolean hasField(final int number) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); - } - return number == lastFieldNumber || fields.containsKey(number); + public boolean hasField(int number) { + return fieldBuilders.containsKey(number); } /** * Add a field to the {@code UnknownFieldSet}. If a field with the same number already exists, * it is removed. + * + * @throws IllegalArgumentException if number is not positive */ - public Builder addField(final int number, final Field field) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); - } - if (lastField != null && lastFieldNumber == number) { - // Discard this. - lastField = null; - lastFieldNumber = 0; + public Builder addField(int number, Field field) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } - if (fields.isEmpty()) { - fields = new TreeMap(); - } - fields.put(number, field); + fieldBuilders.put(number, Field.newBuilder(field)); return this; } @@ -509,15 +476,18 @@ public final class UnknownFieldSet implements MessageLite { * changes may or may not be reflected in this map. */ public Map asMap() { - getFieldBuilder(0); // Force lastField to be built. + TreeMap fields = new TreeMap<>(); + for (Map.Entry entry : fieldBuilders.entrySet()) { + fields.put(entry.getKey(), entry.getValue().build()); + } return Collections.unmodifiableMap(fields); } /** Parse an entire message from {@code input} and merge its fields into this set. */ @Override - public Builder mergeFrom(final CodedInputStream input) throws IOException { + public Builder mergeFrom(CodedInputStream input) throws IOException { while (true) { - final int tag = input.readTag(); + int tag = input.readTag(); if (tag == 0 || !mergeFieldFrom(tag, input)) { break; } @@ -531,8 +501,8 @@ public final class UnknownFieldSet implements MessageLite { * @param tag The field's tag number, which was already parsed. * @return {@code false} if the tag is an end group tag. */ - public boolean mergeFieldFrom(final int tag, final CodedInputStream input) throws IOException { - final int number = WireFormat.getTagFieldNumber(tag); + public boolean mergeFieldFrom(int tag, CodedInputStream input) throws IOException { + int number = WireFormat.getTagFieldNumber(tag); switch (WireFormat.getTagWireType(tag)) { case WireFormat.WIRETYPE_VARINT: getFieldBuilder(number).addVarint(input.readInt64()); @@ -544,7 +514,7 @@ public final class UnknownFieldSet implements MessageLite { getFieldBuilder(number).addLengthDelimited(input.readBytes()); return true; case WireFormat.WIRETYPE_START_GROUP: - final Builder subBuilder = newBuilder(); + Builder subBuilder = newBuilder(); input.readGroup(number, subBuilder, ExtensionRegistry.getEmptyRegistry()); getFieldBuilder(number).addGroup(subBuilder.build()); return true; @@ -563,15 +533,15 @@ public final class UnknownFieldSet implements MessageLite { * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. */ @Override - public Builder mergeFrom(final ByteString data) throws InvalidProtocolBufferException { + public Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException { try { - final CodedInputStream input = data.newCodedInput(); + CodedInputStream input = data.newCodedInput(); mergeFrom(input); input.checkLastTagWas(0); return this; - } catch (final InvalidProtocolBufferException e) { + } catch (InvalidProtocolBufferException e) { throw e; - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException( "Reading from a ByteString threw an IOException (should never happen).", e); } @@ -582,15 +552,15 @@ public final class UnknownFieldSet implements MessageLite { * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. */ @Override - public Builder mergeFrom(final byte[] data) throws InvalidProtocolBufferException { + public Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException { try { - final CodedInputStream input = CodedInputStream.newInstance(data); + CodedInputStream input = CodedInputStream.newInstance(data); mergeFrom(input); input.checkLastTagWas(0); return this; - } catch (final InvalidProtocolBufferException e) { + } catch (InvalidProtocolBufferException e) { throw e; - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException( "Reading from a byte array threw an IOException (should never happen).", e); } @@ -601,8 +571,8 @@ public final class UnknownFieldSet implements MessageLite { * This is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. */ @Override - public Builder mergeFrom(final InputStream input) throws IOException { - final CodedInputStream codedInput = CodedInputStream.newInstance(input); + public Builder mergeFrom(InputStream input) throws IOException { + CodedInputStream codedInput = CodedInputStream.newInstance(input); mergeFrom(codedInput); codedInput.checkLastTagWas(0); return this; @@ -610,12 +580,12 @@ public final class UnknownFieldSet implements MessageLite { @Override public boolean mergeDelimitedFrom(InputStream input) throws IOException { - final int firstByte = input.read(); + int firstByte = input.read(); if (firstByte == -1) { return false; } - final int size = CodedInputStream.readRawVarint32(firstByte, input); - final InputStream limitedInput = new LimitedInputStream(input, size); + int size = CodedInputStream.readRawVarint32(firstByte, input); + InputStream limitedInput = new LimitedInputStream(input, size); mergeFrom(limitedInput); return true; } @@ -644,7 +614,7 @@ public final class UnknownFieldSet implements MessageLite { @Override public Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException { try { - final CodedInputStream input = CodedInputStream.newInstance(data, off, len); + CodedInputStream input = CodedInputStream.newInstance(data, off, len); mergeFrom(input); input.checkLastTagWas(0); return this; @@ -718,7 +688,7 @@ public final class UnknownFieldSet implements MessageLite { } /** Construct a new {@link Builder} and initialize it to a copy of {@code copyFrom}. */ - public static Builder newBuilder(final Field copyFrom) { + public static Builder newBuilder(Field copyFrom) { return newBuilder().mergeFrom(copyFrom); } @@ -758,7 +728,7 @@ public final class UnknownFieldSet implements MessageLite { } @Override - public boolean equals(final Object other) { + public boolean equals(Object other) { if (this == other) { return true; } @@ -785,7 +755,7 @@ public final class UnknownFieldSet implements MessageLite { public ByteString toByteString(int fieldNumber) { try { // TODO(lukes): consider caching serialized size in a volatile long - final ByteString.CodedBuilder out = + ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize(fieldNumber)); writeTo(fieldNumber, out.getCodedOutput()); return out.build(); @@ -796,40 +766,40 @@ public final class UnknownFieldSet implements MessageLite { } /** Serializes the field, including field number, and writes it to {@code output}. */ - public void writeTo(final int fieldNumber, final CodedOutputStream output) throws IOException { - for (final long value : varint) { + public void writeTo(int fieldNumber, CodedOutputStream output) throws IOException { + for (long value : varint) { output.writeUInt64(fieldNumber, value); } - for (final int value : fixed32) { + for (int value : fixed32) { output.writeFixed32(fieldNumber, value); } - for (final long value : fixed64) { + for (long value : fixed64) { output.writeFixed64(fieldNumber, value); } - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { output.writeBytes(fieldNumber, value); } - for (final UnknownFieldSet value : group) { + for (UnknownFieldSet value : group) { output.writeGroup(fieldNumber, value); } } /** Get the number of bytes required to encode this field, including field number. */ - public int getSerializedSize(final int fieldNumber) { + public int getSerializedSize(int fieldNumber) { int result = 0; - for (final long value : varint) { + for (long value : varint) { result += CodedOutputStream.computeUInt64Size(fieldNumber, value); } - for (final int value : fixed32) { + for (int value : fixed32) { result += CodedOutputStream.computeFixed32Size(fieldNumber, value); } - for (final long value : fixed64) { + for (long value : fixed64) { result += CodedOutputStream.computeFixed64Size(fieldNumber, value); } - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { result += CodedOutputStream.computeBytesSize(fieldNumber, value); } - for (final UnknownFieldSet value : group) { + for (UnknownFieldSet value : group) { result += CodedOutputStream.computeGroupSize(fieldNumber, value); } return result; @@ -839,15 +809,15 @@ public final class UnknownFieldSet implements MessageLite { * Serializes the field, including field number, and writes it to {@code output}, using {@code * MessageSet} wire format. */ - public void writeAsMessageSetExtensionTo(final int fieldNumber, final CodedOutputStream output) + public void writeAsMessageSetExtensionTo(int fieldNumber, CodedOutputStream output) throws IOException { - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { output.writeRawMessageSetExtension(fieldNumber, value); } } /** Serializes the field, including field number, and writes it to {@code writer}. */ - void writeTo(final int fieldNumber, final Writer writer) throws IOException { + void writeTo(int fieldNumber, Writer writer) throws IOException { writer.writeInt64List(fieldNumber, varint, false); writer.writeFixed32List(fieldNumber, fixed32, false); writer.writeFixed64List(fieldNumber, fixed64, false); @@ -872,7 +842,7 @@ public final class UnknownFieldSet implements MessageLite { * Serializes the field, including field number, and writes it to {@code writer}, using {@code * MessageSet} wire format. */ - private void writeAsMessageSetExtensionTo(final int fieldNumber, final Writer writer) + private void writeAsMessageSetExtensionTo(int fieldNumber, Writer writer) throws IOException { if (writer.fieldOrder() == Writer.FieldOrder.DESCENDING) { // Write in descending field order. @@ -882,7 +852,7 @@ public final class UnknownFieldSet implements MessageLite { } } else { // Write in ascending field order. - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { writer.writeMessageSetItem(fieldNumber, value); } } @@ -892,9 +862,9 @@ public final class UnknownFieldSet implements MessageLite { * Get the number of bytes required to encode this field, including field number, using {@code * MessageSet} wire format. */ - public int getSerializedSizeAsMessageSetExtension(final int fieldNumber) { + public int getSerializedSizeAsMessageSetExtension(int fieldNumber) { int result = 0; - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { result += CodedOutputStream.computeRawMessageSetExtensionSize(fieldNumber, value); } return result; @@ -912,52 +882,85 @@ public final class UnknownFieldSet implements MessageLite { *

Use {@link Field#newBuilder()} to construct a {@code Builder}. */ public static final class Builder { - // This constructor should never be called directly (except from 'create'). - private Builder() {} + // This constructor should only be called directly from 'create' and 'clone'. + private Builder() { + result = new Field(); + } private static Builder create() { Builder builder = new Builder(); - builder.result = new Field(); return builder; } private Field result; + @Override + public Builder clone() { + Field copy = new Field(); + if (result.varint == null) { + copy.varint = null; + } else { + copy.varint = new ArrayList<>(result.varint); + } + if (result.fixed32 == null) { + copy.fixed32 = null; + } else { + copy.fixed32 = new ArrayList<>(result.fixed32); + } + if (result.fixed64 == null) { + copy.fixed64 = null; + } else { + copy.fixed64 = new ArrayList<>(result.fixed64); + } + if (result.lengthDelimited == null) { + copy.lengthDelimited = null; + } else { + copy.lengthDelimited = new ArrayList<>(result.lengthDelimited); + } + if (result.group == null) { + copy.group = null; + } else { + copy.group = new ArrayList<>(result.group); + } + + Builder clone = new Builder(); + clone.result = copy; + return clone; + } + /** - * Build the field. After {@code build()} has been called, the {@code Builder} is no longer - * usable. Calling any other method will result in undefined behavior and can cause a {@code - * NullPointerException} to be thrown. + * Build the field. */ public Field build() { + Field built = new Field(); if (result.varint == null) { - result.varint = Collections.emptyList(); + built.varint = Collections.emptyList(); } else { - result.varint = Collections.unmodifiableList(result.varint); + built.varint = Collections.unmodifiableList(new ArrayList<>(result.varint)); } if (result.fixed32 == null) { - result.fixed32 = Collections.emptyList(); + built.fixed32 = Collections.emptyList(); } else { - result.fixed32 = Collections.unmodifiableList(result.fixed32); + built.fixed32 = Collections.unmodifiableList(new ArrayList<>(result.fixed32)); } if (result.fixed64 == null) { - result.fixed64 = Collections.emptyList(); + built.fixed64 = Collections.emptyList(); } else { - result.fixed64 = Collections.unmodifiableList(result.fixed64); + built.fixed64 = Collections.unmodifiableList(new ArrayList<>(result.fixed64)); } if (result.lengthDelimited == null) { - result.lengthDelimited = Collections.emptyList(); + built.lengthDelimited = Collections.emptyList(); } else { - result.lengthDelimited = Collections.unmodifiableList(result.lengthDelimited); + built.lengthDelimited = Collections.unmodifiableList( + new ArrayList<>(result.lengthDelimited)); } if (result.group == null) { - result.group = Collections.emptyList(); + built.group = Collections.emptyList(); } else { - result.group = Collections.unmodifiableList(result.group); + built.group = Collections.unmodifiableList(new ArrayList<>(result.group)); } - final Field returnMe = result; - result = null; - return returnMe; + return built; } /** Discard the field's contents. */ @@ -970,7 +973,7 @@ public final class UnknownFieldSet implements MessageLite { * Merge the values in {@code other} into this field. For each list of values, {@code other}'s * values are append to the ones in this field. */ - public Builder mergeFrom(final Field other) { + public Builder mergeFrom(Field other) { if (!other.varint.isEmpty()) { if (result.varint == null) { result.varint = new ArrayList(); @@ -985,19 +988,19 @@ public final class UnknownFieldSet implements MessageLite { } if (!other.fixed64.isEmpty()) { if (result.fixed64 == null) { - result.fixed64 = new ArrayList(); + result.fixed64 = new ArrayList<>(); } result.fixed64.addAll(other.fixed64); } if (!other.lengthDelimited.isEmpty()) { if (result.lengthDelimited == null) { - result.lengthDelimited = new ArrayList(); + result.lengthDelimited = new ArrayList<>(); } result.lengthDelimited.addAll(other.lengthDelimited); } if (!other.group.isEmpty()) { if (result.group == null) { - result.group = new ArrayList(); + result.group = new ArrayList<>(); } result.group.addAll(other.group); } @@ -1005,45 +1008,45 @@ public final class UnknownFieldSet implements MessageLite { } /** Add a varint value. */ - public Builder addVarint(final long value) { + public Builder addVarint(long value) { if (result.varint == null) { - result.varint = new ArrayList(); + result.varint = new ArrayList<>(); } result.varint.add(value); return this; } /** Add a fixed32 value. */ - public Builder addFixed32(final int value) { + public Builder addFixed32(int value) { if (result.fixed32 == null) { - result.fixed32 = new ArrayList(); + result.fixed32 = new ArrayList<>(); } result.fixed32.add(value); return this; } /** Add a fixed64 value. */ - public Builder addFixed64(final long value) { + public Builder addFixed64(long value) { if (result.fixed64 == null) { - result.fixed64 = new ArrayList(); + result.fixed64 = new ArrayList<>(); } result.fixed64.add(value); return this; } /** Add a length-delimited value. */ - public Builder addLengthDelimited(final ByteString value) { + public Builder addLengthDelimited(ByteString value) { if (result.lengthDelimited == null) { - result.lengthDelimited = new ArrayList(); + result.lengthDelimited = new ArrayList<>(); } result.lengthDelimited.add(value); return this; } /** Add an embedded group. */ - public Builder addGroup(final UnknownFieldSet value) { + public Builder addGroup(UnknownFieldSet value) { if (result.group == null) { - result.group = new ArrayList(); + result.group = new ArrayList<>(); } result.group.add(value); return this; diff --git a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java new file mode 100644 index 0000000000..6ce0fc7e34 --- /dev/null +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java @@ -0,0 +1,78 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class UnknownFieldSetPerformanceTest { + + private static byte[] generateBytes(int length) { + assertThat(length % 4).isEqualTo(0); + byte[] input = new byte[length]; + for (int i = 0; i < length; i += 4) { + input[i] = (byte) 0x08; // field 1, wiretype 0 + input[i + 1] = (byte) 0x08; // field 1, payload 8 + input[i + 2] = (byte) 0x20; // field 4, wiretype 0 + input[i + 3] = (byte) 0x20; // field 4, payload 32 + } + return input; + } + + @Test + // This is a performance test. Failure here is a timeout. + public void testAlternatingFieldNumbers() throws IOException { + byte[] input = generateBytes(800000); + InputStream in = new ByteArrayInputStream(input); + UnknownFieldSet.Builder builder = UnknownFieldSet.newBuilder(); + CodedInputStream codedInput = CodedInputStream.newInstance(in); + builder.mergeFrom(codedInput); + } + + @Test + // This is a performance test. Failure here is a timeout. + public void testAddField() { + UnknownFieldSet.Builder builder = UnknownFieldSet.newBuilder(); + for (int i = 1; i <= 100000; i++) { + UnknownFieldSet.Field field = UnknownFieldSet.Field.newBuilder().addFixed32(i).build(); + builder.addField(i, field); + } + UnknownFieldSet fieldSet = builder.build(); + assertThat(fieldSet.getField(100000).getFixed32List().get(0)).isEqualTo(100000); + } +} diff --git a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java index 1e5bc9649a..fbc3bb8fcf 100644 --- a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java @@ -42,7 +42,9 @@ import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions; import protobuf_unittest.UnittestProto.TestPackedExtensions; import protobuf_unittest.UnittestProto.TestPackedTypes; import proto3_unittest.UnittestProto3; +import java.util.List; import java.util.Map; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,7 +63,7 @@ public class UnknownFieldSetTest { unknownFields = emptyMessage.getUnknownFields(); } - UnknownFieldSet.Field getField(String name) { + private UnknownFieldSet.Field getField(String name) { Descriptors.FieldDescriptor field = descriptor.findFieldByName(name); assertThat(field).isNotNull(); return unknownFields.getField(field.getNumber()); @@ -100,6 +102,174 @@ public class UnknownFieldSetTest { // ================================================================= + @Test + public void testFieldBuildersAreReusable() { + UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder(); + fieldBuilder.addFixed32(10); + UnknownFieldSet.Field first = fieldBuilder.build(); + UnknownFieldSet.Field second = fieldBuilder.build(); + fieldBuilder.addFixed32(11); + UnknownFieldSet.Field third = fieldBuilder.build(); + + assertThat(first).isEqualTo(second); + assertThat(first).isNotEqualTo(third); + } + + @Test + public void testClone() { + UnknownFieldSet.Builder unknownSetBuilder = UnknownFieldSet.newBuilder(); + UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder(); + fieldBuilder.addFixed32(10); + unknownSetBuilder.addField(8, fieldBuilder.build()); + // necessary to call clone twice to expose the bug + UnknownFieldSet.Builder clone1 = unknownSetBuilder.clone(); + UnknownFieldSet.Builder clone2 = unknownSetBuilder.clone(); // failure is a NullPointerException + assertThat(clone1).isNotSameInstanceAs(clone2); + } + + @Test + public void testClone_lengthDelimited() { + UnknownFieldSet.Builder destUnknownFieldSet = + UnknownFieldSet.newBuilder() + .addField(997, UnknownFieldSet.Field.newBuilder().addVarint(99).build()) + .addField( + 999, + UnknownFieldSet.Field.newBuilder() + .addLengthDelimited(ByteString.copyFromUtf8("some data")) + .addLengthDelimited(ByteString.copyFromUtf8("some more data")) + .build()); + UnknownFieldSet clone = destUnknownFieldSet.clone().build(); + assertThat(clone.getField(997)).isNotNull(); + UnknownFieldSet.Field field999 = clone.getField(999); + List lengthDelimited = field999.getLengthDelimitedList(); + assertThat(lengthDelimited.get(0).toStringUtf8()).isEqualTo("some data"); + assertThat(lengthDelimited.get(1).toStringUtf8()).isEqualTo("some more data"); + + UnknownFieldSet clone2 = destUnknownFieldSet.clone().build(); + assertThat(clone2.getField(997)).isNotNull(); + UnknownFieldSet.Field secondField = clone2.getField(999); + List lengthDelimited2 = secondField.getLengthDelimitedList(); + assertThat(lengthDelimited2.get(0).toStringUtf8()).isEqualTo("some data"); + assertThat(lengthDelimited2.get(1).toStringUtf8()).isEqualTo("some more data"); + } + + @Test + public void testReuse() { + UnknownFieldSet.Builder builder = + UnknownFieldSet.newBuilder() + .addField(997, UnknownFieldSet.Field.newBuilder().addVarint(99).build()) + .addField( + 999, + UnknownFieldSet.Field.newBuilder() + .addLengthDelimited(ByteString.copyFromUtf8("some data")) + .addLengthDelimited(ByteString.copyFromUtf8("some more data")) + .build()); + + UnknownFieldSet fieldSet1 = builder.build(); + UnknownFieldSet fieldSet2 = builder.build(); + builder.addField(1000, UnknownFieldSet.Field.newBuilder().addVarint(-90).build()); + UnknownFieldSet fieldSet3 = builder.build(); + + assertThat(fieldSet1).isEqualTo(fieldSet2); + assertThat(fieldSet1).isNotEqualTo(fieldSet3); + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testAddField_zero() { + UnknownFieldSet.Field field = getField("optional_int32"); + try { + UnknownFieldSet.newBuilder().addField(0, field); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("0 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testAddField_negative() { + UnknownFieldSet.Field field = getField("optional_int32"); + try { + UnknownFieldSet.newBuilder().addField(-2, field); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-2 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testClearField_negative() { + try { + UnknownFieldSet.newBuilder().clearField(-28); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-28 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testMergeField_negative() { + UnknownFieldSet.Field field = getField("optional_int32"); + try { + UnknownFieldSet.newBuilder().mergeField(-2, field); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-2 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testMergeVarintField_negative() { + try { + UnknownFieldSet.newBuilder().mergeVarintField(-2, 78); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-2 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testHasField_negative() { + assertThat(UnknownFieldSet.newBuilder().hasField(-2)).isFalse(); + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testMergeLengthDelimitedField_negative() { + ByteString byteString = ByteString.copyFromUtf8("some data"); + try { + UnknownFieldSet.newBuilder().mergeLengthDelimitedField(-2, byteString); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-2 is not a valid field number."); + } + } + + @Test + public void testAddField() { + UnknownFieldSet.Field field = getField("optional_int32"); + UnknownFieldSet fieldSet = UnknownFieldSet.newBuilder().addField(1, field).build(); + assertThat(fieldSet.getField(1)).isEqualTo(field); + } + + @Test + public void testAddField_withReplacement() { + UnknownFieldSet.Field first = UnknownFieldSet.Field.newBuilder().addFixed32(56).build(); + UnknownFieldSet.Field second = UnknownFieldSet.Field.newBuilder().addFixed32(25).build(); + UnknownFieldSet fieldSet = UnknownFieldSet.newBuilder() + .addField(1, first) + .addField(1, second) + .build(); + List list = fieldSet.getField(1).getFixed32List(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isEqualTo(25); + } + @Test public void testVarint() throws Exception { UnknownFieldSet.Field field = getField("optional_int32"); @@ -185,6 +355,16 @@ public class UnknownFieldSetTest { assertThat(destination.toString()).isEqualTo("1: 1\n2: 2\n3: 3\n3: 4\n"); } + @Test + public void testAsMap() throws Exception { + UnknownFieldSet.Builder builder = UnknownFieldSet.newBuilder().mergeFrom(unknownFields); + Map mapFromBuilder = builder.asMap(); + assertThat(mapFromBuilder).isNotEmpty(); + UnknownFieldSet fields = builder.build(); + Map mapFromFieldSet = fields.asMap(); + assertThat(mapFromFieldSet).containsExactlyEntriesIn(mapFromBuilder); + } + @Test public void testClear() throws Exception { UnknownFieldSet fields = UnknownFieldSet.newBuilder().mergeFrom(unknownFields).clear().build(); diff --git a/java/lite/pom.xml b/java/lite/pom.xml index cfd5707f9b..6f7f53afa1 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -232,6 +232,7 @@ TypeRegistryTest.java UnknownEnumValueTest.java UnknownFieldSetLiteTest.java + UnknownFieldSetPerformanceTest.java UnknownFieldSetTest.java WellKnownTypesTest.java WireFormatTest.java From 0e02f95b876c40ecb04a76e729dd3f0d9185431e Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 5 Jan 2022 08:26:20 -0800 Subject: [PATCH 108/207] Fix Ruby release build by pinning rake-compiler-dock version (#9372) Our Ruby release build broke at some point in the past day or so, and I strongly suspect it is due to a new version (1.2.0) of rake-compiler-dock. This commit pins the version to 1.1.0 as a temporary fix. --- ruby/google-protobuf.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 7e2dd14aae..810c6fff88 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| else s.files += Dir.glob('ext/**/*') s.extensions= ["ext/google/protobuf_c/extconf.rb"] - s.add_development_dependency "rake-compiler-dock", ">= 1.1.0", "< 2.0" + s.add_development_dependency "rake-compiler-dock", "= 1.1.0" end s.test_files = ["tests/basic.rb", "tests/stress.rb", From 9638a5e5315bf73f5e7148c16181676372321892 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 5 Jan 2022 08:50:29 -0800 Subject: [PATCH 109/207] Improve performance of parsing unknown fields in Java (#9371) Credit should go to @elharo for most of these Java changes--I am just cherry-picking them from our internal codebase. The one thing I did change was to give the UTF-8 validation tests their own Bazel test target. This makes it possible to give the other tests a shorter timeout, which is important for UnknownFieldSetPerformanceTest in particular. --- Makefile.am | 1 + java/core/BUILD | 24 +- .../com/google/protobuf/UnknownFieldSet.java | 427 +++++++++--------- .../UnknownFieldSetPerformanceTest.java | 78 ++++ .../google/protobuf/UnknownFieldSetTest.java | 182 +++++++- java/lite/pom.xml | 1 + 6 files changed, 499 insertions(+), 214 deletions(-) create mode 100644 java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java diff --git a/Makefile.am b/Makefile.am index 178c124b5e..41d4061a98 100644 --- a/Makefile.am +++ b/Makefile.am @@ -493,6 +493,7 @@ java_EXTRA_DIST= java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java \ java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java \ java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java \ + java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java \ java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java \ java/core/src/test/java/com/google/protobuf/Utf8Test.java \ java/core/src/test/java/com/google/protobuf/Utf8Utils.java \ diff --git a/java/core/BUILD b/java/core/BUILD index 1a37b4e820..419eafb58a 100644 --- a/java/core/BUILD +++ b/java/core/BUILD @@ -224,6 +224,7 @@ test_suite( "conformance_test", "core_build_test", "core_tests", + "utf8_tests", ], ) @@ -243,10 +244,12 @@ conformance_test( junit_tests( name = "core_tests", - size = "large", + size = "small", srcs = glob( ["src/test/java/**/*.java"], exclude = [ + "src/test/java/com/google/protobuf/DecodeUtf8Test.java", + "src/test/java/com/google/protobuf/IsValidUtf8Test.java", "src/test/java/com/google/protobuf/TestUtil.java", "src/test/java/com/google/protobuf/TestUtilLite.java", ], @@ -264,6 +267,24 @@ junit_tests( ], ) +# The UTF-8 validation tests are much slower than the other tests, so they get +# their own test target with a longer timeout. +junit_tests( + name = "utf8_tests", + size = "large", + srcs = [ + "src/test/java/com/google/protobuf/DecodeUtf8Test.java", + "src/test/java/com/google/protobuf/IsValidUtf8Test.java", + "src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java", + ], + deps = [ + ":core", + "@maven//:com_google_guava_guava", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], +) + java_lite_proto_library( name = "generic_test_protos_java_proto_lite", visibility = [ @@ -346,6 +367,7 @@ LITE_TEST_EXCLUSIONS = [ "src/test/java/com/google/protobuf/TypeRegistryTest.java", "src/test/java/com/google/protobuf/UnknownEnumValueTest.java", "src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java", + "src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java", "src/test/java/com/google/protobuf/UnknownFieldSetTest.java", "src/test/java/com/google/protobuf/WellKnownTypesTest.java", "src/test/java/com/google/protobuf/WireFormatTest.java", diff --git a/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java index ba2f9df08e..5c482d62da 100644 --- a/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java @@ -43,13 +43,13 @@ import java.util.Map; import java.util.TreeMap; /** - * {@code UnknownFieldSet} is used to keep track of fields which were seen when parsing a protocol + * {@code UnknownFieldSet} keeps track of fields which were seen when parsing a protocol * message but whose field numbers or types are unrecognized. This most frequently occurs when new * fields are added to a message type and then messages containing those fields are read by old * software that was compiled before the new types were added. * *

Every {@link Message} contains an {@code UnknownFieldSet} (and every {@link Message.Builder} - * contains an {@link Builder}). + * contains a {@link Builder}). * *

Most users will never need to use this class. * @@ -57,9 +57,13 @@ import java.util.TreeMap; */ public final class UnknownFieldSet implements MessageLite { - private UnknownFieldSet() { - fields = null; - fieldsDescending = null; + private final TreeMap fields; + + /** + * Construct an {@code UnknownFieldSet} around the given map. + */ + UnknownFieldSet(TreeMap fields) { + this.fields = fields; } /** Create a new {@link Builder}. */ @@ -68,7 +72,7 @@ public final class UnknownFieldSet implements MessageLite { } /** Create a new {@link Builder} and initialize it to be a copy of {@code copyFrom}. */ - public static Builder newBuilder(final UnknownFieldSet copyFrom) { + public static Builder newBuilder(UnknownFieldSet copyFrom) { return newBuilder().mergeFrom(copyFrom); } @@ -83,25 +87,11 @@ public final class UnknownFieldSet implements MessageLite { } private static final UnknownFieldSet defaultInstance = - new UnknownFieldSet( - Collections.emptyMap(), Collections.emptyMap()); - - /** - * Construct an {@code UnknownFieldSet} around the given map. The map is expected to be immutable. - */ - UnknownFieldSet(final Map fields, final Map fieldsDescending) { - this.fields = fields; - this.fieldsDescending = fieldsDescending; - } - - private final Map fields; - - /** A copy of {@link #fields} who's iterator order is reversed. */ - private final Map fieldsDescending; + new UnknownFieldSet(new TreeMap()); @Override - public boolean equals(final Object other) { + public boolean equals(Object other) { if (this == other) { return true; } @@ -110,29 +100,33 @@ public final class UnknownFieldSet implements MessageLite { @Override public int hashCode() { + if (fields.isEmpty()) { // avoid allocation of iterator. + // This optimization may not be helpful but it is needed for the allocation tests to pass. + return 0; + } return fields.hashCode(); } /** Get a map of fields in the set by number. */ public Map asMap() { - return fields; + return (Map) fields.clone(); } /** Check if the given field number is present in the set. */ - public boolean hasField(final int number) { + public boolean hasField(int number) { return fields.containsKey(number); } /** Get a field by number. Returns an empty field if not present. Never returns {@code null}. */ - public Field getField(final int number) { - final Field result = fields.get(number); + public Field getField(int number) { + Field result = fields.get(number); return (result == null) ? Field.getDefaultInstance() : result; } /** Serializes the set and writes it to {@code output}. */ @Override - public void writeTo(final CodedOutputStream output) throws IOException { - for (final Map.Entry entry : fields.entrySet()) { + public void writeTo(CodedOutputStream output) throws IOException { + for (Map.Entry entry : fields.entrySet()) { Field field = entry.getValue(); field.writeTo(entry.getKey(), output); } @@ -154,10 +148,10 @@ public final class UnknownFieldSet implements MessageLite { @Override public ByteString toByteString() { try { - final ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize()); + ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize()); writeTo(out.getCodedOutput()); return out.build(); - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException( "Serializing to a ByteString threw an IOException (should never happen).", e); } @@ -170,12 +164,12 @@ public final class UnknownFieldSet implements MessageLite { @Override public byte[] toByteArray() { try { - final byte[] result = new byte[getSerializedSize()]; - final CodedOutputStream output = CodedOutputStream.newInstance(result); + byte[] result = new byte[getSerializedSize()]; + CodedOutputStream output = CodedOutputStream.newInstance(result); writeTo(output); output.checkNoSpaceLeft(); return result; - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException( "Serializing to a byte array threw an IOException (should never happen).", e); } @@ -186,16 +180,16 @@ public final class UnknownFieldSet implements MessageLite { * {@link #writeTo(CodedOutputStream)}. */ @Override - public void writeTo(final OutputStream output) throws IOException { - final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); + public void writeTo(OutputStream output) throws IOException { + CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); writeTo(codedOutput); codedOutput.flush(); } @Override public void writeDelimitedTo(OutputStream output) throws IOException { - final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); - codedOutput.writeRawVarint32(getSerializedSize()); + CodedOutputStream codedOutput = CodedOutputStream.newInstance(output); + codedOutput.writeUInt32NoTag(getSerializedSize()); writeTo(codedOutput); codedOutput.flush(); } @@ -204,15 +198,17 @@ public final class UnknownFieldSet implements MessageLite { @Override public int getSerializedSize() { int result = 0; - for (final Map.Entry entry : fields.entrySet()) { - result += entry.getValue().getSerializedSize(entry.getKey()); + if (!fields.isEmpty()) { + for (Map.Entry entry : fields.entrySet()) { + result += entry.getValue().getSerializedSize(entry.getKey()); + } } return result; } /** Serializes the set and writes it to {@code output} using {@code MessageSet} wire format. */ - public void writeAsMessageSetTo(final CodedOutputStream output) throws IOException { - for (final Map.Entry entry : fields.entrySet()) { + public void writeAsMessageSetTo(CodedOutputStream output) throws IOException { + for (Map.Entry entry : fields.entrySet()) { entry.getValue().writeAsMessageSetExtensionTo(entry.getKey(), output); } } @@ -221,7 +217,7 @@ public final class UnknownFieldSet implements MessageLite { void writeTo(Writer writer) throws IOException { if (writer.fieldOrder() == Writer.FieldOrder.DESCENDING) { // Write fields in descending order. - for (Map.Entry entry : fieldsDescending.entrySet()) { + for (Map.Entry entry : fields.descendingMap().entrySet()) { entry.getValue().writeTo(entry.getKey(), writer); } } else { @@ -233,15 +229,15 @@ public final class UnknownFieldSet implements MessageLite { } /** Serializes the set and writes it to {@code writer} using {@code MessageSet} wire format. */ - void writeAsMessageSetTo(final Writer writer) throws IOException { + void writeAsMessageSetTo(Writer writer) throws IOException { if (writer.fieldOrder() == Writer.FieldOrder.DESCENDING) { // Write fields in descending order. - for (final Map.Entry entry : fieldsDescending.entrySet()) { + for (Map.Entry entry : fields.descendingMap().entrySet()) { entry.getValue().writeAsMessageSetExtensionTo(entry.getKey(), writer); } } else { // Write fields in ascending order. - for (final Map.Entry entry : fields.entrySet()) { + for (Map.Entry entry : fields.entrySet()) { entry.getValue().writeAsMessageSetExtensionTo(entry.getKey(), writer); } } @@ -250,7 +246,7 @@ public final class UnknownFieldSet implements MessageLite { /** Get the number of bytes required to encode this set using {@code MessageSet} wire format. */ public int getSerializedSizeAsMessageSet() { int result = 0; - for (final Map.Entry entry : fields.entrySet()) { + for (Map.Entry entry : fields.entrySet()) { result += entry.getValue().getSerializedSizeAsMessageSetExtension(entry.getKey()); } return result; @@ -264,23 +260,23 @@ public final class UnknownFieldSet implements MessageLite { } /** Parse an {@code UnknownFieldSet} from the given input stream. */ - public static UnknownFieldSet parseFrom(final CodedInputStream input) throws IOException { + public static UnknownFieldSet parseFrom(CodedInputStream input) throws IOException { return newBuilder().mergeFrom(input).build(); } /** Parse {@code data} as an {@code UnknownFieldSet} and return it. */ - public static UnknownFieldSet parseFrom(final ByteString data) + public static UnknownFieldSet parseFrom(ByteString data) throws InvalidProtocolBufferException { return newBuilder().mergeFrom(data).build(); } /** Parse {@code data} as an {@code UnknownFieldSet} and return it. */ - public static UnknownFieldSet parseFrom(final byte[] data) throws InvalidProtocolBufferException { + public static UnknownFieldSet parseFrom(byte[] data) throws InvalidProtocolBufferException { return newBuilder().mergeFrom(data).build(); } /** Parse an {@code UnknownFieldSet} from {@code input} and return it. */ - public static UnknownFieldSet parseFrom(final InputStream input) throws IOException { + public static UnknownFieldSet parseFrom(InputStream input) throws IOException { return newBuilder().mergeFrom(input).build(); } @@ -309,64 +305,43 @@ public final class UnknownFieldSet implements MessageLite { // This constructor should never be called directly (except from 'create'). private Builder() {} - private Map fields; - - // Optimization: We keep around a builder for the last field that was - // modified so that we can efficiently add to it multiple times in a - // row (important when parsing an unknown repeated field). - private int lastFieldNumber; - private Field.Builder lastField; + private TreeMap fieldBuilders = new TreeMap<>(); private static Builder create() { - Builder builder = new Builder(); - builder.reinitialize(); - return builder; + return new Builder(); } /** * Get a field builder for the given field number which includes any values that already exist. */ - private Field.Builder getFieldBuilder(final int number) { - if (lastField != null) { - if (number == lastFieldNumber) { - return lastField; - } - // Note: addField() will reset lastField and lastFieldNumber. - addField(lastFieldNumber, lastField.build()); - } + private Field.Builder getFieldBuilder(int number) { if (number == 0) { return null; } else { - final Field existing = fields.get(number); - lastFieldNumber = number; - lastField = Field.newBuilder(); - if (existing != null) { - lastField.mergeFrom(existing); + Field.Builder builder = fieldBuilders.get(number); + if (builder == null) { + builder = Field.newBuilder(); + fieldBuilders.put(number, builder); } - return lastField; + return builder; } } /** * Build the {@link UnknownFieldSet} and return it. - * - *

Once {@code build()} has been called, the {@code Builder} will no longer be usable. - * Calling any method after {@code build()} will result in undefined behavior and can cause a - * {@code NullPointerException} to be thrown. */ @Override public UnknownFieldSet build() { - getFieldBuilder(0); // Force lastField to be built. - final UnknownFieldSet result; - if (fields.isEmpty()) { + UnknownFieldSet result; + if (fieldBuilders.isEmpty()) { result = getDefaultInstance(); } else { - Map descendingFields = null; - descendingFields = - Collections.unmodifiableMap(((TreeMap) fields).descendingMap()); - result = new UnknownFieldSet(Collections.unmodifiableMap(fields), descendingFields); + TreeMap fields = new TreeMap<>(); + for (Map.Entry entry : fieldBuilders.entrySet()) { + fields.put(entry.getKey(), entry.getValue().build()); + } + result = new UnknownFieldSet(fields); } - fields = null; return result; } @@ -378,11 +353,13 @@ public final class UnknownFieldSet implements MessageLite { @Override public Builder clone() { - getFieldBuilder(0); // Force lastField to be built. - Map descendingFields = null; - descendingFields = - Collections.unmodifiableMap(((TreeMap) fields).descendingMap()); - return UnknownFieldSet.newBuilder().mergeFrom(new UnknownFieldSet(fields, descendingFields)); + Builder clone = UnknownFieldSet.newBuilder(); + for (Map.Entry entry : fieldBuilders.entrySet()) { + Integer key = entry.getKey(); + Field.Builder value = entry.getValue(); + clone.fieldBuilders.put(key, value.clone()); + } + return clone; } @Override @@ -390,31 +367,24 @@ public final class UnknownFieldSet implements MessageLite { return UnknownFieldSet.getDefaultInstance(); } - private void reinitialize() { - fields = Collections.emptyMap(); - lastFieldNumber = 0; - lastField = null; - } - /** Reset the builder to an empty set. */ @Override public Builder clear() { - reinitialize(); + fieldBuilders = new TreeMap<>(); return this; } - /** Clear fields from the set with a given field number. */ - public Builder clearField(final int number) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); - } - if (lastField != null && lastFieldNumber == number) { - // Discard this. - lastField = null; - lastFieldNumber = 0; + /** + * Clear fields from the set with a given field number. + * + * @throws IllegalArgumentException if number is not positive + */ + public Builder clearField(int number) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } - if (fields.containsKey(number)) { - fields.remove(number); + if (fieldBuilders.containsKey(number)) { + fieldBuilders.remove(number); } return this; } @@ -423,9 +393,9 @@ public final class UnknownFieldSet implements MessageLite { * Merge the fields from {@code other} into this set. If a field number exists in both sets, * {@code other}'s values for that field will be appended to the values in this set. */ - public Builder mergeFrom(final UnknownFieldSet other) { + public Builder mergeFrom(UnknownFieldSet other) { if (other != getDefaultInstance()) { - for (final Map.Entry entry : other.fields.entrySet()) { + for (Map.Entry entry : other.fields.entrySet()) { mergeField(entry.getKey(), entry.getValue()); } } @@ -435,10 +405,12 @@ public final class UnknownFieldSet implements MessageLite { /** * Add a field to the {@code UnknownFieldSet}. If a field with the same number already exists, * the two are merged. + * + * @throws IllegalArgumentException if number is not positive */ - public Builder mergeField(final int number, final Field field) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); + public Builder mergeField(int number, final Field field) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } if (hasField(number)) { getFieldBuilder(number).mergeFrom(field); @@ -454,10 +426,12 @@ public final class UnknownFieldSet implements MessageLite { /** * Convenience method for merging a new field containing a single varint value. This is used in * particular when an unknown enum value is encountered. + * + * @throws IllegalArgumentException if number is not positive */ - public Builder mergeVarintField(final int number, final int value) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); + public Builder mergeVarintField(int number, int value) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } getFieldBuilder(number).addVarint(value); return this; @@ -467,40 +441,33 @@ public final class UnknownFieldSet implements MessageLite { * Convenience method for merging a length-delimited field. * *

For use by generated code only. + * + * @throws IllegalArgumentException if number is not positive */ - public Builder mergeLengthDelimitedField(final int number, final ByteString value) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); + public Builder mergeLengthDelimitedField(int number, ByteString value) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } getFieldBuilder(number).addLengthDelimited(value); return this; } /** Check if the given field number is present in the set. */ - public boolean hasField(final int number) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); - } - return number == lastFieldNumber || fields.containsKey(number); + public boolean hasField(int number) { + return fieldBuilders.containsKey(number); } /** * Add a field to the {@code UnknownFieldSet}. If a field with the same number already exists, * it is removed. + * + * @throws IllegalArgumentException if number is not positive */ - public Builder addField(final int number, final Field field) { - if (number == 0) { - throw new IllegalArgumentException("Zero is not a valid field number."); - } - if (lastField != null && lastFieldNumber == number) { - // Discard this. - lastField = null; - lastFieldNumber = 0; + public Builder addField(int number, Field field) { + if (number <= 0) { + throw new IllegalArgumentException(number + " is not a valid field number."); } - if (fields.isEmpty()) { - fields = new TreeMap(); - } - fields.put(number, field); + fieldBuilders.put(number, Field.newBuilder(field)); return this; } @@ -509,15 +476,18 @@ public final class UnknownFieldSet implements MessageLite { * changes may or may not be reflected in this map. */ public Map asMap() { - getFieldBuilder(0); // Force lastField to be built. + TreeMap fields = new TreeMap<>(); + for (Map.Entry entry : fieldBuilders.entrySet()) { + fields.put(entry.getKey(), entry.getValue().build()); + } return Collections.unmodifiableMap(fields); } /** Parse an entire message from {@code input} and merge its fields into this set. */ @Override - public Builder mergeFrom(final CodedInputStream input) throws IOException { + public Builder mergeFrom(CodedInputStream input) throws IOException { while (true) { - final int tag = input.readTag(); + int tag = input.readTag(); if (tag == 0 || !mergeFieldFrom(tag, input)) { break; } @@ -531,8 +501,8 @@ public final class UnknownFieldSet implements MessageLite { * @param tag The field's tag number, which was already parsed. * @return {@code false} if the tag is an end group tag. */ - public boolean mergeFieldFrom(final int tag, final CodedInputStream input) throws IOException { - final int number = WireFormat.getTagFieldNumber(tag); + public boolean mergeFieldFrom(int tag, CodedInputStream input) throws IOException { + int number = WireFormat.getTagFieldNumber(tag); switch (WireFormat.getTagWireType(tag)) { case WireFormat.WIRETYPE_VARINT: getFieldBuilder(number).addVarint(input.readInt64()); @@ -544,7 +514,7 @@ public final class UnknownFieldSet implements MessageLite { getFieldBuilder(number).addLengthDelimited(input.readBytes()); return true; case WireFormat.WIRETYPE_START_GROUP: - final Builder subBuilder = newBuilder(); + Builder subBuilder = newBuilder(); input.readGroup(number, subBuilder, ExtensionRegistry.getEmptyRegistry()); getFieldBuilder(number).addGroup(subBuilder.build()); return true; @@ -563,15 +533,15 @@ public final class UnknownFieldSet implements MessageLite { * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. */ @Override - public Builder mergeFrom(final ByteString data) throws InvalidProtocolBufferException { + public Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException { try { - final CodedInputStream input = data.newCodedInput(); + CodedInputStream input = data.newCodedInput(); mergeFrom(input); input.checkLastTagWas(0); return this; - } catch (final InvalidProtocolBufferException e) { + } catch (InvalidProtocolBufferException e) { throw e; - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException( "Reading from a ByteString threw an IOException (should never happen).", e); } @@ -582,15 +552,15 @@ public final class UnknownFieldSet implements MessageLite { * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. */ @Override - public Builder mergeFrom(final byte[] data) throws InvalidProtocolBufferException { + public Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException { try { - final CodedInputStream input = CodedInputStream.newInstance(data); + CodedInputStream input = CodedInputStream.newInstance(data); mergeFrom(input); input.checkLastTagWas(0); return this; - } catch (final InvalidProtocolBufferException e) { + } catch (InvalidProtocolBufferException e) { throw e; - } catch (final IOException e) { + } catch (IOException e) { throw new RuntimeException( "Reading from a byte array threw an IOException (should never happen).", e); } @@ -601,8 +571,8 @@ public final class UnknownFieldSet implements MessageLite { * This is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. */ @Override - public Builder mergeFrom(final InputStream input) throws IOException { - final CodedInputStream codedInput = CodedInputStream.newInstance(input); + public Builder mergeFrom(InputStream input) throws IOException { + CodedInputStream codedInput = CodedInputStream.newInstance(input); mergeFrom(codedInput); codedInput.checkLastTagWas(0); return this; @@ -610,12 +580,12 @@ public final class UnknownFieldSet implements MessageLite { @Override public boolean mergeDelimitedFrom(InputStream input) throws IOException { - final int firstByte = input.read(); + int firstByte = input.read(); if (firstByte == -1) { return false; } - final int size = CodedInputStream.readRawVarint32(firstByte, input); - final InputStream limitedInput = new LimitedInputStream(input, size); + int size = CodedInputStream.readRawVarint32(firstByte, input); + InputStream limitedInput = new LimitedInputStream(input, size); mergeFrom(limitedInput); return true; } @@ -644,7 +614,7 @@ public final class UnknownFieldSet implements MessageLite { @Override public Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException { try { - final CodedInputStream input = CodedInputStream.newInstance(data, off, len); + CodedInputStream input = CodedInputStream.newInstance(data, off, len); mergeFrom(input); input.checkLastTagWas(0); return this; @@ -718,7 +688,7 @@ public final class UnknownFieldSet implements MessageLite { } /** Construct a new {@link Builder} and initialize it to a copy of {@code copyFrom}. */ - public static Builder newBuilder(final Field copyFrom) { + public static Builder newBuilder(Field copyFrom) { return newBuilder().mergeFrom(copyFrom); } @@ -758,7 +728,7 @@ public final class UnknownFieldSet implements MessageLite { } @Override - public boolean equals(final Object other) { + public boolean equals(Object other) { if (this == other) { return true; } @@ -785,7 +755,7 @@ public final class UnknownFieldSet implements MessageLite { public ByteString toByteString(int fieldNumber) { try { // TODO(lukes): consider caching serialized size in a volatile long - final ByteString.CodedBuilder out = + ByteString.CodedBuilder out = ByteString.newCodedBuilder(getSerializedSize(fieldNumber)); writeTo(fieldNumber, out.getCodedOutput()); return out.build(); @@ -796,40 +766,40 @@ public final class UnknownFieldSet implements MessageLite { } /** Serializes the field, including field number, and writes it to {@code output}. */ - public void writeTo(final int fieldNumber, final CodedOutputStream output) throws IOException { - for (final long value : varint) { + public void writeTo(int fieldNumber, CodedOutputStream output) throws IOException { + for (long value : varint) { output.writeUInt64(fieldNumber, value); } - for (final int value : fixed32) { + for (int value : fixed32) { output.writeFixed32(fieldNumber, value); } - for (final long value : fixed64) { + for (long value : fixed64) { output.writeFixed64(fieldNumber, value); } - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { output.writeBytes(fieldNumber, value); } - for (final UnknownFieldSet value : group) { + for (UnknownFieldSet value : group) { output.writeGroup(fieldNumber, value); } } /** Get the number of bytes required to encode this field, including field number. */ - public int getSerializedSize(final int fieldNumber) { + public int getSerializedSize(int fieldNumber) { int result = 0; - for (final long value : varint) { + for (long value : varint) { result += CodedOutputStream.computeUInt64Size(fieldNumber, value); } - for (final int value : fixed32) { + for (int value : fixed32) { result += CodedOutputStream.computeFixed32Size(fieldNumber, value); } - for (final long value : fixed64) { + for (long value : fixed64) { result += CodedOutputStream.computeFixed64Size(fieldNumber, value); } - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { result += CodedOutputStream.computeBytesSize(fieldNumber, value); } - for (final UnknownFieldSet value : group) { + for (UnknownFieldSet value : group) { result += CodedOutputStream.computeGroupSize(fieldNumber, value); } return result; @@ -839,15 +809,15 @@ public final class UnknownFieldSet implements MessageLite { * Serializes the field, including field number, and writes it to {@code output}, using {@code * MessageSet} wire format. */ - public void writeAsMessageSetExtensionTo(final int fieldNumber, final CodedOutputStream output) + public void writeAsMessageSetExtensionTo(int fieldNumber, CodedOutputStream output) throws IOException { - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { output.writeRawMessageSetExtension(fieldNumber, value); } } /** Serializes the field, including field number, and writes it to {@code writer}. */ - void writeTo(final int fieldNumber, final Writer writer) throws IOException { + void writeTo(int fieldNumber, Writer writer) throws IOException { writer.writeInt64List(fieldNumber, varint, false); writer.writeFixed32List(fieldNumber, fixed32, false); writer.writeFixed64List(fieldNumber, fixed64, false); @@ -872,7 +842,7 @@ public final class UnknownFieldSet implements MessageLite { * Serializes the field, including field number, and writes it to {@code writer}, using {@code * MessageSet} wire format. */ - private void writeAsMessageSetExtensionTo(final int fieldNumber, final Writer writer) + private void writeAsMessageSetExtensionTo(int fieldNumber, Writer writer) throws IOException { if (writer.fieldOrder() == Writer.FieldOrder.DESCENDING) { // Write in descending field order. @@ -882,7 +852,7 @@ public final class UnknownFieldSet implements MessageLite { } } else { // Write in ascending field order. - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { writer.writeMessageSetItem(fieldNumber, value); } } @@ -892,9 +862,9 @@ public final class UnknownFieldSet implements MessageLite { * Get the number of bytes required to encode this field, including field number, using {@code * MessageSet} wire format. */ - public int getSerializedSizeAsMessageSetExtension(final int fieldNumber) { + public int getSerializedSizeAsMessageSetExtension(int fieldNumber) { int result = 0; - for (final ByteString value : lengthDelimited) { + for (ByteString value : lengthDelimited) { result += CodedOutputStream.computeRawMessageSetExtensionSize(fieldNumber, value); } return result; @@ -912,52 +882,85 @@ public final class UnknownFieldSet implements MessageLite { *

Use {@link Field#newBuilder()} to construct a {@code Builder}. */ public static final class Builder { - // This constructor should never be called directly (except from 'create'). - private Builder() {} + // This constructor should only be called directly from 'create' and 'clone'. + private Builder() { + result = new Field(); + } private static Builder create() { Builder builder = new Builder(); - builder.result = new Field(); return builder; } private Field result; + @Override + public Builder clone() { + Field copy = new Field(); + if (result.varint == null) { + copy.varint = null; + } else { + copy.varint = new ArrayList<>(result.varint); + } + if (result.fixed32 == null) { + copy.fixed32 = null; + } else { + copy.fixed32 = new ArrayList<>(result.fixed32); + } + if (result.fixed64 == null) { + copy.fixed64 = null; + } else { + copy.fixed64 = new ArrayList<>(result.fixed64); + } + if (result.lengthDelimited == null) { + copy.lengthDelimited = null; + } else { + copy.lengthDelimited = new ArrayList<>(result.lengthDelimited); + } + if (result.group == null) { + copy.group = null; + } else { + copy.group = new ArrayList<>(result.group); + } + + Builder clone = new Builder(); + clone.result = copy; + return clone; + } + /** - * Build the field. After {@code build()} has been called, the {@code Builder} is no longer - * usable. Calling any other method will result in undefined behavior and can cause a {@code - * NullPointerException} to be thrown. + * Build the field. */ public Field build() { + Field built = new Field(); if (result.varint == null) { - result.varint = Collections.emptyList(); + built.varint = Collections.emptyList(); } else { - result.varint = Collections.unmodifiableList(result.varint); + built.varint = Collections.unmodifiableList(new ArrayList<>(result.varint)); } if (result.fixed32 == null) { - result.fixed32 = Collections.emptyList(); + built.fixed32 = Collections.emptyList(); } else { - result.fixed32 = Collections.unmodifiableList(result.fixed32); + built.fixed32 = Collections.unmodifiableList(new ArrayList<>(result.fixed32)); } if (result.fixed64 == null) { - result.fixed64 = Collections.emptyList(); + built.fixed64 = Collections.emptyList(); } else { - result.fixed64 = Collections.unmodifiableList(result.fixed64); + built.fixed64 = Collections.unmodifiableList(new ArrayList<>(result.fixed64)); } if (result.lengthDelimited == null) { - result.lengthDelimited = Collections.emptyList(); + built.lengthDelimited = Collections.emptyList(); } else { - result.lengthDelimited = Collections.unmodifiableList(result.lengthDelimited); + built.lengthDelimited = Collections.unmodifiableList( + new ArrayList<>(result.lengthDelimited)); } if (result.group == null) { - result.group = Collections.emptyList(); + built.group = Collections.emptyList(); } else { - result.group = Collections.unmodifiableList(result.group); + built.group = Collections.unmodifiableList(new ArrayList<>(result.group)); } - final Field returnMe = result; - result = null; - return returnMe; + return built; } /** Discard the field's contents. */ @@ -970,7 +973,7 @@ public final class UnknownFieldSet implements MessageLite { * Merge the values in {@code other} into this field. For each list of values, {@code other}'s * values are append to the ones in this field. */ - public Builder mergeFrom(final Field other) { + public Builder mergeFrom(Field other) { if (!other.varint.isEmpty()) { if (result.varint == null) { result.varint = new ArrayList(); @@ -985,19 +988,19 @@ public final class UnknownFieldSet implements MessageLite { } if (!other.fixed64.isEmpty()) { if (result.fixed64 == null) { - result.fixed64 = new ArrayList(); + result.fixed64 = new ArrayList<>(); } result.fixed64.addAll(other.fixed64); } if (!other.lengthDelimited.isEmpty()) { if (result.lengthDelimited == null) { - result.lengthDelimited = new ArrayList(); + result.lengthDelimited = new ArrayList<>(); } result.lengthDelimited.addAll(other.lengthDelimited); } if (!other.group.isEmpty()) { if (result.group == null) { - result.group = new ArrayList(); + result.group = new ArrayList<>(); } result.group.addAll(other.group); } @@ -1005,45 +1008,45 @@ public final class UnknownFieldSet implements MessageLite { } /** Add a varint value. */ - public Builder addVarint(final long value) { + public Builder addVarint(long value) { if (result.varint == null) { - result.varint = new ArrayList(); + result.varint = new ArrayList<>(); } result.varint.add(value); return this; } /** Add a fixed32 value. */ - public Builder addFixed32(final int value) { + public Builder addFixed32(int value) { if (result.fixed32 == null) { - result.fixed32 = new ArrayList(); + result.fixed32 = new ArrayList<>(); } result.fixed32.add(value); return this; } /** Add a fixed64 value. */ - public Builder addFixed64(final long value) { + public Builder addFixed64(long value) { if (result.fixed64 == null) { - result.fixed64 = new ArrayList(); + result.fixed64 = new ArrayList<>(); } result.fixed64.add(value); return this; } /** Add a length-delimited value. */ - public Builder addLengthDelimited(final ByteString value) { + public Builder addLengthDelimited(ByteString value) { if (result.lengthDelimited == null) { - result.lengthDelimited = new ArrayList(); + result.lengthDelimited = new ArrayList<>(); } result.lengthDelimited.add(value); return this; } /** Add an embedded group. */ - public Builder addGroup(final UnknownFieldSet value) { + public Builder addGroup(UnknownFieldSet value) { if (result.group == null) { - result.group = new ArrayList(); + result.group = new ArrayList<>(); } result.group.add(value); return this; diff --git a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java new file mode 100644 index 0000000000..6ce0fc7e34 --- /dev/null +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java @@ -0,0 +1,78 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf; + +import static com.google.common.truth.Truth.assertThat; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class UnknownFieldSetPerformanceTest { + + private static byte[] generateBytes(int length) { + assertThat(length % 4).isEqualTo(0); + byte[] input = new byte[length]; + for (int i = 0; i < length; i += 4) { + input[i] = (byte) 0x08; // field 1, wiretype 0 + input[i + 1] = (byte) 0x08; // field 1, payload 8 + input[i + 2] = (byte) 0x20; // field 4, wiretype 0 + input[i + 3] = (byte) 0x20; // field 4, payload 32 + } + return input; + } + + @Test + // This is a performance test. Failure here is a timeout. + public void testAlternatingFieldNumbers() throws IOException { + byte[] input = generateBytes(800000); + InputStream in = new ByteArrayInputStream(input); + UnknownFieldSet.Builder builder = UnknownFieldSet.newBuilder(); + CodedInputStream codedInput = CodedInputStream.newInstance(in); + builder.mergeFrom(codedInput); + } + + @Test + // This is a performance test. Failure here is a timeout. + public void testAddField() { + UnknownFieldSet.Builder builder = UnknownFieldSet.newBuilder(); + for (int i = 1; i <= 100000; i++) { + UnknownFieldSet.Field field = UnknownFieldSet.Field.newBuilder().addFixed32(i).build(); + builder.addField(i, field); + } + UnknownFieldSet fieldSet = builder.build(); + assertThat(fieldSet.getField(100000).getFixed32List().get(0)).isEqualTo(100000); + } +} diff --git a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java index 1e5bc9649a..fbc3bb8fcf 100644 --- a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java @@ -42,7 +42,9 @@ import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions; import protobuf_unittest.UnittestProto.TestPackedExtensions; import protobuf_unittest.UnittestProto.TestPackedTypes; import proto3_unittest.UnittestProto3; +import java.util.List; import java.util.Map; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,7 +63,7 @@ public class UnknownFieldSetTest { unknownFields = emptyMessage.getUnknownFields(); } - UnknownFieldSet.Field getField(String name) { + private UnknownFieldSet.Field getField(String name) { Descriptors.FieldDescriptor field = descriptor.findFieldByName(name); assertThat(field).isNotNull(); return unknownFields.getField(field.getNumber()); @@ -100,6 +102,174 @@ public class UnknownFieldSetTest { // ================================================================= + @Test + public void testFieldBuildersAreReusable() { + UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder(); + fieldBuilder.addFixed32(10); + UnknownFieldSet.Field first = fieldBuilder.build(); + UnknownFieldSet.Field second = fieldBuilder.build(); + fieldBuilder.addFixed32(11); + UnknownFieldSet.Field third = fieldBuilder.build(); + + assertThat(first).isEqualTo(second); + assertThat(first).isNotEqualTo(third); + } + + @Test + public void testClone() { + UnknownFieldSet.Builder unknownSetBuilder = UnknownFieldSet.newBuilder(); + UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder(); + fieldBuilder.addFixed32(10); + unknownSetBuilder.addField(8, fieldBuilder.build()); + // necessary to call clone twice to expose the bug + UnknownFieldSet.Builder clone1 = unknownSetBuilder.clone(); + UnknownFieldSet.Builder clone2 = unknownSetBuilder.clone(); // failure is a NullPointerException + assertThat(clone1).isNotSameInstanceAs(clone2); + } + + @Test + public void testClone_lengthDelimited() { + UnknownFieldSet.Builder destUnknownFieldSet = + UnknownFieldSet.newBuilder() + .addField(997, UnknownFieldSet.Field.newBuilder().addVarint(99).build()) + .addField( + 999, + UnknownFieldSet.Field.newBuilder() + .addLengthDelimited(ByteString.copyFromUtf8("some data")) + .addLengthDelimited(ByteString.copyFromUtf8("some more data")) + .build()); + UnknownFieldSet clone = destUnknownFieldSet.clone().build(); + assertThat(clone.getField(997)).isNotNull(); + UnknownFieldSet.Field field999 = clone.getField(999); + List lengthDelimited = field999.getLengthDelimitedList(); + assertThat(lengthDelimited.get(0).toStringUtf8()).isEqualTo("some data"); + assertThat(lengthDelimited.get(1).toStringUtf8()).isEqualTo("some more data"); + + UnknownFieldSet clone2 = destUnknownFieldSet.clone().build(); + assertThat(clone2.getField(997)).isNotNull(); + UnknownFieldSet.Field secondField = clone2.getField(999); + List lengthDelimited2 = secondField.getLengthDelimitedList(); + assertThat(lengthDelimited2.get(0).toStringUtf8()).isEqualTo("some data"); + assertThat(lengthDelimited2.get(1).toStringUtf8()).isEqualTo("some more data"); + } + + @Test + public void testReuse() { + UnknownFieldSet.Builder builder = + UnknownFieldSet.newBuilder() + .addField(997, UnknownFieldSet.Field.newBuilder().addVarint(99).build()) + .addField( + 999, + UnknownFieldSet.Field.newBuilder() + .addLengthDelimited(ByteString.copyFromUtf8("some data")) + .addLengthDelimited(ByteString.copyFromUtf8("some more data")) + .build()); + + UnknownFieldSet fieldSet1 = builder.build(); + UnknownFieldSet fieldSet2 = builder.build(); + builder.addField(1000, UnknownFieldSet.Field.newBuilder().addVarint(-90).build()); + UnknownFieldSet fieldSet3 = builder.build(); + + assertThat(fieldSet1).isEqualTo(fieldSet2); + assertThat(fieldSet1).isNotEqualTo(fieldSet3); + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testAddField_zero() { + UnknownFieldSet.Field field = getField("optional_int32"); + try { + UnknownFieldSet.newBuilder().addField(0, field); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("0 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testAddField_negative() { + UnknownFieldSet.Field field = getField("optional_int32"); + try { + UnknownFieldSet.newBuilder().addField(-2, field); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-2 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testClearField_negative() { + try { + UnknownFieldSet.newBuilder().clearField(-28); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-28 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testMergeField_negative() { + UnknownFieldSet.Field field = getField("optional_int32"); + try { + UnknownFieldSet.newBuilder().mergeField(-2, field); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-2 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testMergeVarintField_negative() { + try { + UnknownFieldSet.newBuilder().mergeVarintField(-2, 78); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-2 is not a valid field number."); + } + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testHasField_negative() { + assertThat(UnknownFieldSet.newBuilder().hasField(-2)).isFalse(); + } + + @Test + @SuppressWarnings("ModifiedButNotUsed") + public void testMergeLengthDelimitedField_negative() { + ByteString byteString = ByteString.copyFromUtf8("some data"); + try { + UnknownFieldSet.newBuilder().mergeLengthDelimitedField(-2, byteString); + Assert.fail(); + } catch (IllegalArgumentException expected) { + assertThat(expected).hasMessageThat().isEqualTo("-2 is not a valid field number."); + } + } + + @Test + public void testAddField() { + UnknownFieldSet.Field field = getField("optional_int32"); + UnknownFieldSet fieldSet = UnknownFieldSet.newBuilder().addField(1, field).build(); + assertThat(fieldSet.getField(1)).isEqualTo(field); + } + + @Test + public void testAddField_withReplacement() { + UnknownFieldSet.Field first = UnknownFieldSet.Field.newBuilder().addFixed32(56).build(); + UnknownFieldSet.Field second = UnknownFieldSet.Field.newBuilder().addFixed32(25).build(); + UnknownFieldSet fieldSet = UnknownFieldSet.newBuilder() + .addField(1, first) + .addField(1, second) + .build(); + List list = fieldSet.getField(1).getFixed32List(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isEqualTo(25); + } + @Test public void testVarint() throws Exception { UnknownFieldSet.Field field = getField("optional_int32"); @@ -185,6 +355,16 @@ public class UnknownFieldSetTest { assertThat(destination.toString()).isEqualTo("1: 1\n2: 2\n3: 3\n3: 4\n"); } + @Test + public void testAsMap() throws Exception { + UnknownFieldSet.Builder builder = UnknownFieldSet.newBuilder().mergeFrom(unknownFields); + Map mapFromBuilder = builder.asMap(); + assertThat(mapFromBuilder).isNotEmpty(); + UnknownFieldSet fields = builder.build(); + Map mapFromFieldSet = fields.asMap(); + assertThat(mapFromFieldSet).containsExactlyEntriesIn(mapFromBuilder); + } + @Test public void testClear() throws Exception { UnknownFieldSet fields = UnknownFieldSet.newBuilder().mergeFrom(unknownFields).clear().build(); diff --git a/java/lite/pom.xml b/java/lite/pom.xml index cfd5707f9b..6f7f53afa1 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -232,6 +232,7 @@ TypeRegistryTest.java UnknownEnumValueTest.java UnknownFieldSetLiteTest.java + UnknownFieldSetPerformanceTest.java UnknownFieldSetTest.java WellKnownTypesTest.java WireFormatTest.java From ea9a01a0f5c259e9597c199e447d99eaab19930b Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 5 Jan 2022 16:24:38 +0000 Subject: [PATCH 110/207] Update CHANGES.txt for 3.19.2 release --- CHANGES.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 926eff72da..00e1b92bcb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,11 @@ +2022-01-05 version 3.19.2 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Python + * Fix missing Windows wheel for Python 3.10 on PyPI + + Java + * Change implementation of UnknownFieldSet (#9371) + 2021-10-28 version 3.19.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Bazel From eb94f17a8b8babc4851fb9bb27f9fb1919fe9cfc Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 5 Jan 2022 17:05:38 +0000 Subject: [PATCH 111/207] Update protobuf version --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 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/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 27 ++++++++++++++----- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 +-- src/Makefile.am | 2 +- 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/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 +- 37 files changed, 60 insertions(+), 45 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index c6f5511cdb..d6f2c00f07 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.19.1' + s.version = '3.19.2' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index ee63ffcb07..f8c8c65b83 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.19.1' + s.version = '3.19.2' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index fb5f9d09f3..6bec81022d 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.19.1],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.19.2],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index b2d1417b6c..b653766268 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.19.1 + 3.19.2 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index ad6f57999b..68c14bf58a 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.19.1 + 3.19.2 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 456ba1c976..c1c3614063 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.19.1 + 3.19.2 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.19.1 + 3.19.2 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.19.1' + implementation 'com.google.protobuf:protobuf-java:3.19.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 348ea57fcc..68aded500c 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.19.1 + 3.19.2 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index 9c020f98dc..b77a5c422d 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.1 + 3.19.2 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 23dfc77cc3..4be6c73a91 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.1 + 3.19.2 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 0455d114ed..90d12f6a0d 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.1 + 3.19.2 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index 8f3ef1e49b..bb22fb9f91 100644 --- a/java/lite.md +++ b/java/lite.md @@ -30,7 +30,7 @@ protobuf Java runtime. If you are using Maven, use the following: com.google.protobuf protobuf-javalite - 3.19.1 + 3.19.2 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 6f7f53afa1..a8ae75cc3b 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.1 + 3.19.2 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 127fa6287f..1932c9e89f 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.1 + 3.19.2 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index c9ada55804..e5a4b412c2 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.1 + 3.19.2 protobuf-java-util diff --git a/js/package.json b/js/package.json index edccba6097..2c9ac58721 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.19.1", + "version": "3.19.2", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 12c899ef85..dc35b7d593 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -1,5 +1,5 @@ - + protobuf pecl.php.net Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2021-10-28 - + 2022-01-05 + - 3.19.1 - 3.19.1 + 3.19.2 + 3.19.2 stable @@ -22,7 +22,7 @@ 3-Clause BSD License - * No new changes in 3.19.1 + * No new changes in 3.19.2 @@ -1158,5 +1158,20 @@ G A release. + + + 3.19.2 + 3.19.2 + + + stable + stable + + 2022-01-05 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 7cbad84861..87aeeea59d 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -91,7 +91,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.19.1" +#define PHP_PROTOBUF_VERSION "3.19.2" // 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 31ce2e3bac..436086e0da 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1 @@ -PROTOBUF_VERSION = '3.19.1' +PROTOBUF_VERSION = '3.19.2' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 7e5eca83ed..7bb58f6dfc 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.19.1 + 3.19.2 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 52101b6fe4..fc8d7ae1d9 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.19.1' +__version__ = '3.19.2' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 810c6fff88..6a82dc1b41 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.19.1" + s.version = "3.19.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 f4c8f66d1e..395b957696 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.19.1 + 3.19.2 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.19.1 + 3.19.2 org.jruby diff --git a/src/Makefile.am b/src/Makefile.am index 2d6034a0de..e897cc8eed 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 30:1:0 +PROTOBUF_VERSION = 30:2:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index ab07cc70d2..9e04bfb296 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 26e1946f85..69d4cad776 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 569bb30a69..320011e98a 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 66d7e264d6..a0a96821af 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 6440e9d331..d1962b736c 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 ba97255ed0..eaee816b33 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 4114740bbe..103dfa377b 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 71325c3872..631b143623 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -153,7 +153,7 @@ #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 3019001 +#define PROTOBUF_VERSION 3019002 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 5f91f3eb8d..589f4de006 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 6e54bee65b..b6429e6083 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 c32503a6de..d3b32c381f 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -82,7 +82,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 3019001 +#define GOOGLE_PROTOBUF_VERSION 3019002 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 95036fdea6..ea0cb201fe 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 b91ab7ce58..ce17016ba9 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 42ffda2eeb..9e32a6609f 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019001 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019002 < 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 cb46755e6405e083b45481f5ea4754b180705529 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 5 Jan 2022 18:03:53 +0000 Subject: [PATCH 112/207] Tweak wording of CHANGES.txt --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 00e1b92bcb..19720f972a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,7 +4,7 @@ * Fix missing Windows wheel for Python 3.10 on PyPI Java - * Change implementation of UnknownFieldSet (#9371) + * Improve performance characteristics of UnknownFieldSet parsing (#9371) 2021-10-28 version 3.19.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) From c997582f7c5b4c04247588e873733e130068246b Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Wed, 5 Jan 2022 14:47:58 -0500 Subject: [PATCH 113/207] Default two more of the options from env variables. For build systems that don't allow someone to easily add in generator args, support env variables for the values. Most the bool env var support to a helper since it is used in three places now. --- .../compiler/objectivec/objectivec_helpers.cc | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 58f54bd6af..cf926071fc 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -73,6 +73,14 @@ using ::open; namespace { +bool BoolFromEnvVar(const char* env_var, bool default_value) { + const char* value = getenv(env_var); + if (value) { + return std::string("YES") == ToUpper(value); + } + return default_value; +} + class SimpleLineCollector : public LineConsumer { public: SimpleLineCollector(std::unordered_set* inout_set) @@ -117,9 +125,7 @@ PrefixModeStorage::PrefixModeStorage() { // Even thought there are generation options, have an env back door since some // of these helpers could be used in other plugins. - const char* use_package_cstr = getenv("GPB_OBJC_USE_PACKAGE_AS_PREFIX"); - use_package_name_ = - (use_package_cstr && (std::string("YES") == ToUpper(use_package_cstr))); + use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false); const char* exception_path = getenv("GPB_OBJC_PACKAGE_PREFIX_EXCEPTIONS_PATH"); if (exception_path) { @@ -180,7 +186,9 @@ void SetProtoPackagePrefixExceptionList(const std::string& file_path) { } Options::Options() { - // Default is the value of the env for the package prefixes. + // While there are generator options, also support env variables to help with + // build systems where it isn't as easy to hook in for add the generation + // options when invoking protoc. const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES"); if (file_path) { expected_prefixes_path = file_path; @@ -190,8 +198,9 @@ Options::Options() { expected_prefixes_suppressions = Split(suppressions, ";", true); } - prefixes_must_be_registered = false; - require_prefixes = false; + prefixes_must_be_registered = + BoolFromEnvVar("GPB_OBJC_PREFIXES_MUST_BE_REGISTERED", false); + require_prefixes = BoolFromEnvVar("GPB_OBJC_REQUIRE_PREFIXES", false); } namespace { From b73f78d32cc6d1013986de76789481dcaec2d064 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 5 Jan 2022 21:23:54 +0000 Subject: [PATCH 114/207] update GSON to 2.8.9 (#9367) --- java/util/pom.xml | 2 +- maven_install.json | 16 ++++++++-------- protobuf_deps.bzl | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/java/util/pom.xml b/java/util/pom.xml index c9ada55804..e870bff04c 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -45,7 +45,7 @@ com.google.code.gson gson - 2.8.6 + 2.8.9 junit diff --git a/maven_install.json b/maven_install.json index 6168aa4af2..3919de3e79 100644 --- a/maven_install.json +++ b/maven_install.json @@ -1,8 +1,8 @@ { "dependency_tree": { "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", - "__INPUT_ARTIFACTS_HASH": 1907885757, - "__RESOLVED_ARTIFACTS_HASH": 375457873, + "__INPUT_ARTIFACTS_HASH": -1650978854, + "__RESOLVED_ARTIFACTS_HASH": -718494898, "conflict_resolution": { "com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.5.1", "junit:junit:4.12": "junit:junit:4.13.1" @@ -45,16 +45,16 @@ "url": "https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" }, { - "coord": "com.google.code.gson:gson:2.8.6", + "coord": "com.google.code.gson:gson:2.8.9", "dependencies": [], "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar", + "file": "v1/https/repo1.maven.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar", "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar", - "https://repo.maven.apache.org/maven2/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar" + "https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar", + "https://repo.maven.apache.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar" ], - "sha256": "c8fb4839054d280b3033f800d1f5a97de2f028eb8ba2eb458ad287e536f3f25f", - "url": "https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar" + "sha256": "d3999291855de495c94c743761b8ab5176cfeabe281a5ab0d8e8d45326fd703e", + "url": "https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar" }, { "coord": "com.google.errorprone:error_prone_annotations:2.5.1", diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 2e628868e6..f78006862a 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -4,7 +4,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") PROTOBUF_MAVEN_ARTIFACTS = [ "com.google.code.findbugs:jsr305:3.0.2", - "com.google.code.gson:gson:2.8.6", + "com.google.code.gson:gson:2.8.9", "com.google.errorprone:error_prone_annotations:2.3.2", "com.google.j2objc:j2objc-annotations:1.3", "com.google.guava:guava:30.1.1-jre", From 50b0bed121031774f03866e3913a227a31049a73 Mon Sep 17 00:00:00 2001 From: LINKIWI Date: Thu, 6 Jan 2022 17:22:31 -0800 Subject: [PATCH 115/207] Set protoc binary file mode to 0555 in release archive (#9354) --- BUILD | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 81f550b946..45a64abc9a 100644 --- a/BUILD +++ b/BUILD @@ -3,7 +3,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library") load("@rules_pkg//:pkg.bzl", "pkg_zip") -load("@rules_pkg//:mappings.bzl", "pkg_files") +load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") load("@rules_python//python:defs.bzl", "py_library") load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library") @@ -563,6 +563,7 @@ pkg_files( pkg_files( name = "protoc_files", srcs = [":protoc"], + attributes = pkg_attributes(mode = "0555"), visibility = ["//visibility:private"], prefix = "bin/", ) From fabe73db6f0632ef76faf1629e07c12f80f80c50 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 7 Jan 2022 23:12:46 +1100 Subject: [PATCH 116/207] adding return type hints to php ext --- php/ext/google/protobuf/array.c | 68 ++++++++++++++++++++++----------- php/ext/google/protobuf/map.c | 65 +++++++++++++++++++++---------- 2 files changed, 90 insertions(+), 43 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index 2c9a7108b9..a8ad9292a1 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -287,7 +287,7 @@ PHP_METHOD(RepeatedField, append) { } /** - * RepeatedField::offsetExists() + * RepeatedField::offsetExists(): bool * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -341,7 +341,7 @@ PHP_METHOD(RepeatedField, offsetGet) { } /** - * RepeatedField::offsetSet() + * RepeatedField::offsetSet(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -386,7 +386,7 @@ PHP_METHOD(RepeatedField, offsetSet) { } /** - * RepeatedField::offsetUnset() + * RepeatedField::offsetUnset(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -416,7 +416,7 @@ PHP_METHOD(RepeatedField, offsetUnset) { } /** - * RepeatedField::count() + * RepeatedField::count(): int * * Implements the Countable interface. Invoked when PHP code calls: * @@ -436,7 +436,7 @@ PHP_METHOD(RepeatedField, count) { } /** - * RepeatedField::getIterator() + * RepeatedField::getIterator(): Traversable * * Implements the IteratorAggregate interface. Invoked when PHP code calls: * @@ -463,20 +463,35 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() + + static zend_function_entry repeated_field_methods[] = { - PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, count, arginfo_count, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -550,7 +565,7 @@ static void RepeatedFieldIter_make(zval *val, zval *repeated_field) { */ /** - * RepeatedFieldIter::rewind() + * RepeatedFieldIter::rewind(): void * * Implements the Iterator interface. Sets the iterator to the first element. */ @@ -593,7 +608,7 @@ PHP_METHOD(RepeatedFieldIter, key) { } /** - * RepeatedFieldIter::next() + * RepeatedFieldIter::next(): void * * Implements the Iterator interface. Advances to the next element. */ @@ -603,7 +618,7 @@ PHP_METHOD(RepeatedFieldIter, next) { } /** - * RepeatedFieldIter::valid() + * RepeatedFieldIter::valid(): bool * * Implements the Iterator interface. Returns true if this is a valid element. */ @@ -613,12 +628,21 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + static zend_function_entry repeated_field_iter_methods[] = { - PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index bbdfe29c5d..b908fd586f 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -305,7 +305,7 @@ PHP_METHOD(MapField, __construct) { } /** - * MapField::offsetExists() + * MapField::offsetExists(): bool * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -361,7 +361,7 @@ PHP_METHOD(MapField, offsetGet) { } /** - * MapField::offsetSet() + * MapField::offsetSet(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -389,7 +389,7 @@ PHP_METHOD(MapField, offsetSet) { } /** - * MapField::offsetUnset() + * MapField::offsetUnset(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -413,7 +413,7 @@ PHP_METHOD(MapField, offsetUnset) { } /** - * MapField::count() + * MapField::count(): int * * Implements the Countable interface. Invoked when PHP code calls: * @@ -433,7 +433,7 @@ PHP_METHOD(MapField, count) { } /** - * MapField::getIterator() + * MapField::getIterator(): Traversable * * Implements the IteratorAggregate interface. Invoked when PHP code calls: * @@ -457,19 +457,33 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + static zend_function_entry MapField_methods[] = { - PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC) + PHP_ME(MapField, count, arginfo_count, ZEND_ACC_PUBLIC) + PHP_ME(MapField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -547,7 +561,7 @@ static void MapFieldIter_make(zval *val, zval *map_field) { */ /** - * MapFieldIter::rewind() + * MapFieldIter::rewind(): void * * Implements the Iterator interface. Sets the iterator to the first element. */ @@ -587,7 +601,7 @@ PHP_METHOD(MapFieldIter, key) { } /** - * MapFieldIter::next() + * MapFieldIter::next(): void * * Implements the Iterator interface. Advances to the next element. */ @@ -598,7 +612,7 @@ PHP_METHOD(MapFieldIter, next) { } /** - * MapFieldIter::valid() + * MapFieldIter::valid(): bool * * Implements the Iterator interface. Returns true if this is a valid element. */ @@ -609,12 +623,21 @@ PHP_METHOD(MapFieldIter, valid) { RETURN_BOOL(!done); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + static zend_function_entry map_field_iter_methods[] = { - PHP_ME(MapFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; From ee648b76a701434990b499455f175e7f7941b499 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 7 Jan 2022 13:42:27 +0000 Subject: [PATCH 117/207] Update, fix, or delete an assortment of broken links (#9381) * fix a few broken links and remove some dead ones * new github repo --- docs/third_party.md | 66 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/docs/third_party.md b/docs/third_party.md index ca15aaae2e..8448b57829 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -2,28 +2,29 @@ This page lists code related to Protocol Buffers which is developed and maintained by third parties. You may find this code useful, but note that **these projects are not affiliated with or endorsed by Google (unless explicitly marked)**; try them at your own risk. Also note that many projects here are in the early stages of development and not production-ready. -If you have a project that should be listed here, please [send us a pull request](https://github.com/google/protobuf/pulls) to update this page. +If you have a project that should be listed here, please +[send us a pull request](https://github.com/protocolbuffers/protobuf/pulls) to update this page. ## Programming Languages These are projects we know about implementing Protocol Buffers for other programming languages: -* Action Script: http://code.google.com/p/protobuf-actionscript3/ +* Action Script: https://code.google.com/p/protobuf-actionscript3/ * Action Script: https://code.google.com/p/protoc-gen-as3/ * Action Script: https://github.com/matrix3d/JProtoc * Action Script: https://github.com/zhongfq/protobuf-as3/ * Ada: https://github.com/reznikmm/protobuf * C: https://github.com/protobuf-c/protobuf-c -* C: http://koti.kapsi.fi/jpa/nanopb/ +* C: https://koti.kapsi.fi/jpa/nanopb/ * C: https://github.com/cloudwu/pbc/ * C: https://github.com/haberman/upb/wiki * C: https://github.com/squidfunk/protobluff * C: https://github.com/eerimoq/pbtools -* C++: https://github.com/google/protobuf (Google-official implementation) +* C++: https://github.com/protocolbuffers/protobuf (Google-official implementation) * C++: https://EmbeddedProto.com * C/C++: http://spbc.sf.net/ -* C#: http://code.google.com/p/protobuf-csharp-port +* C#: https://code.google.com/p/protobuf-csharp-port * C#: https://silentorbit.com/protobuf/ -* C#/.NET/WCF/VB: http://code.google.com/p/protobuf-net/ +* C#/.NET/WCF/VB: https://code.google.com/p/protobuf-net/ * Clojure: http://github.com/ninjudd/clojure-protobuf * Clojure: https://github.com/clojusc/protobuf * Clojure: https://protojure.github.io @@ -48,21 +49,20 @@ These are projects we know about implementing Protocol Buffers for other program * Go: https://github.com/akunspy/gopbuf * Go: https://github.com/gogo/protobuf * GopherJS: https://github.com/johanbrandhorst/protobuf -* Haskell: http://hackage.haskell.org/package/hprotoc +* Haskell: https://hackage.haskell.org/package/hprotoc * Haskell: https://github.com/google/proto-lens (Google-unofficial implementation) * Haskell: https://github.com/awakesecurity/proto3-suite (code generator) https://github.com/awakesecurity/proto3-wire (binary serializer/deserializer) * Haxe: https://github.com/Atry/protoc-gen-haxe -* Java: https://github.com/google/protobuf (Google-official implementation) +* Java: https://github.com/protocolbuffers/protobuf (Google-official implementation) * Java/Android: https://github.com/square/wire * Java: https://github.com/HebiRobotics/QuickBuffers/ -* Java ME: http://code.google.com/p/protobuf-javame/ +* Java ME: https://code.google.com/p/protobuf-javame/ * Java ME: http://swingme.sourceforge.net/encode.shtml -* Java ME: http://code.google.com/p/protobuf-j2me/ -* Javascript: http://code.google.com/p/protobuf-js/ +* Javascript: https://code.google.com/p/protobuf-js/ * Javascript: http://github.com/sirikata/protojs * Javascript: https://github.com/dcodeIO/ProtoBuf.js -* Javascript: http://code.google.com/p/protobuf-for-node/ -* Javascript: http://code.google.com/p/protostuff/ +* Javascript: https://code.google.com/p/protobuf-for-node/ +* Javascript: https://code.google.com/p/protostuff/ * Javascript: https://github.com/seishun/node-protoc-plugin (Node.js port of plugin.h) * Javascript: https://github.com/seishun/node-protoc-gen-javascript (Node.js port of the Google-official implementation) * Javascript: https://github.com/ButterCam/sisyphus-js @@ -71,29 +71,28 @@ These are projects we know about implementing Protocol Buffers for other program * Kotlin: https://github.com/Kotlin/kotlinx.serialization * Kotlin: https://github.com/ButterCam/sisyphus * Kotlin: https://github.com/open-toast/protokt -* Lua: http://code.google.com/p/protoc-gen-lua/ +* Lua: https://code.google.com/p/protoc-gen-lua/ * Lua: http://github.com/indygreg/lua-protobuf * Lua: https://github.com/Neopallium/lua-pb -* Matlab: http://code.google.com/p/protobuf-matlab/ -* Mercury: http://code.google.com/p/protobuf-mercury/ -* Objective C: http://code.google.com/p/protobuf-objc/ +* Matlab: https://code.google.com/p/protobuf-matlab/ +* Mercury: https://code.google.com/p/protobuf-mercury/ +* Objective C: https://code.google.com/p/protobuf-objc/ * Objective C: https://github.com/alexeyxo/protobuf-objc * OCaml: http://piqi.org/ * Perl: http://groups.google.com/group/protobuf-perl -* Perl: http://search.cpan.org/perldoc?Google::ProtocolBuffers +* Perl: https://metacpan.org/pod/Google::ProtocolBuffers * Perl: https://metacpan.org/pod/Google::ProtocolBuffers::Dynamic -* Perl/XS: http://code.google.com/p/protobuf-perlxs/ -* PHP: http://code.google.com/p/pb4php/ +* Perl/XS: https://code.google.com/p/protobuf-perlxs/ +* PHP: https://code.google.com/p/pb4php/ * PHP: https://github.com/allegro/php-protobuf/ * PHP: https://github.com/chobie/php-protocolbuffers -* PHP: http://drslump.github.com/Protobuf-PHP * Prolog: http://www.swi-prolog.org/pldoc/package/protobufs.html * Purescript: https://github.com/xc-jp/purescript-protobuf -* Python: https://github.com/google/protobuf (Google-official implementation) +* Python: https://github.com/protocolbuffers/protobuf (Google-official implementation) * Python: https://github.com/eigenein/protobuf * Python: https://github.com/danielgtaylor/python-betterproto * R: http://cran.r-project.org/package=RProtoBuf -* Ruby: http://code.google.com/p/ruby-protobuf/ +* Ruby: https://code.google.com/p/ruby-protobuf/ * Ruby: http://github.com/mozy/ruby-protocol-buffers * Ruby: https://github.com/bmizerany/beefcake/tree/master/lib/beefcake * Ruby: https://github.com/localshred/protobuf @@ -101,7 +100,7 @@ These are projects we know about implementing Protocol Buffers for other program * Rust: https://github.com/stepancheg/rust-protobuf/ * Rust: https://github.com/tafia/quick-protobuf * Scala: http://github.com/jeffplaisance/scala-protobuf -* Scala: http://code.google.com/p/protobuf-scala +* Scala: https://code.google.com/p/protobuf-scala * Scala: https://github.com/SandroGrzicic/ScalaBuff * Scala: https://scalapb.github.io * Solidity: https://github.com/celer-network/pb3-gen-sol @@ -110,7 +109,7 @@ These are projects we know about implementing Protocol Buffers for other program * Typescript: https://github.com/thesayyn/protoc-gen-ts * Typescript: https://github.com/pbkit/pbkit * Vala: https://launchpad.net/protobuf-vala -* Visual Basic: http://code.google.com/p/protobuf-net/ +* Visual Basic: https://code.google.com/p/protobuf-net/ ## RPC Implementations @@ -161,24 +160,23 @@ There are miscellaneous other things you may find useful as a Protocol Buffers d * [rules_closure](https://github.com/bazelbuild/rules_closure) `js-closure` * [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](http://code.google.com/p/protobuf-netbeans-plugin/) -* [Wireshark/Ethereal packet sniffer plugin](http://code.google.com/p/protobuf-wireshark/) -* [Alternate encodings (JSON, XML, HTML) for Java protobufs](http://code.google.com/p/protobuf-java-format/) +* [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](http://code.google.com/p/protobufeditor/) +* [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](http://code.google.com/p/protocol-buffer-plsql/) -* [Eclipse editor for protobuf (from Google)](http://code.google.com/p/protobuf-dt/) +* [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/)) ([Source](https://github.com/xolstice/protobuf-maven-plugin/)) [![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/) - * http://igor-petruk.github.com/protobuf-maven-plugin/ - * http://code.google.com/p/maven-protoc-plugin/ + * https://code.google.com/p/maven-protoc-plugin/ * https://github.com/os72/protoc-jar-maven-plugin * [Documentation generator plugin (Markdown/HTML/DocBook/...)](https://github.com/pseudomuto/protoc-gen-doc) -* [DocBook generator for .proto files](http://code.google.com/p/protoc-gen-docbook/) +* [DocBook generator for .proto files](https://code.google.com/p/protoc-gen-docbook/) * [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) From d8ccfbf00541eb0705bbba640d65e3df814b3d2a Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 7 Jan 2022 18:19:51 +0000 Subject: [PATCH 118/207] Revert "Transition to NIO StandardCharsets" (#9382) --- .../java/com/google/protobuf/ArrayDecoders.java | 11 +++++------ .../java/com/google/protobuf/BinaryReader.java | 3 +-- .../java/com/google/protobuf/ByteString.java | 5 ++--- .../com/google/protobuf/CodedInputStream.java | 3 +-- .../com/google/protobuf/CodedOutputStream.java | 6 +++--- .../java/com/google/protobuf/Descriptors.java | 5 ++--- .../main/java/com/google/protobuf/Internal.java | 16 ++++++++++------ .../java/com/google/protobuf/MessageSchema.java | 3 +-- .../src/main/java/com/google/protobuf/Utf8.java | 3 +-- .../google/protobuf/BoundedByteStringTest.java | 8 +++----- .../com/google/protobuf/ByteStringTest.java | 9 ++++----- .../google/protobuf/CodedOutputStreamTest.java | 7 +++---- .../com/google/protobuf/DecodeUtf8Test.java | 17 ++++++++--------- .../com/google/protobuf/DescriptorsTest.java | 4 +--- .../google/protobuf/IsValidUtf8TestUtil.java | 5 ++--- .../google/protobuf/LiteralByteStringTest.java | 11 +++++------ .../com/google/protobuf/NioByteStringTest.java | 3 +-- .../protobuf/RopeByteStringSubstringTest.java | 3 +-- .../com/google/protobuf/RopeByteStringTest.java | 7 +++---- .../com/google/protobuf/TextFormatTest.java | 3 +-- .../test/java/com/google/protobuf/Utf8Test.java | 3 +-- .../protobuf/WrappersLiteOfMethodTest.java | 4 +--- .../google/protobuf/WrappersOfMethodTest.java | 4 +--- .../test/java/com/google/protobuf/LiteTest.java | 3 +-- 24 files changed, 62 insertions(+), 84 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java b/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java index 0471afaf1f..1217e112e0 100644 --- a/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java +++ b/java/core/src/main/java/com/google/protobuf/ArrayDecoders.java @@ -34,7 +34,6 @@ import static com.google.protobuf.MessageSchema.getMutableUnknownFields; import com.google.protobuf.Internal.ProtobufList; import java.io.IOException; -import java.nio.charset.StandardCharsets; /** * Helper functions to decode protobuf wire format from a byte array. @@ -192,7 +191,7 @@ final class ArrayDecoders { registers.object1 = ""; return position; } else { - registers.object1 = new String(data, position, length, StandardCharsets.UTF_8); + registers.object1 = new String(data, position, length, Internal.UTF_8); return position + length; } } @@ -578,7 +577,7 @@ final class ArrayDecoders { } else if (length == 0) { output.add(""); } else { - String value = new String(data, position, length, StandardCharsets.UTF_8); + String value = new String(data, position, length, Internal.UTF_8); output.add(value); position += length; } @@ -594,7 +593,7 @@ final class ArrayDecoders { } else if (nextLength == 0) { output.add(""); } else { - String value = new String(data, position, nextLength, StandardCharsets.UTF_8); + String value = new String(data, position, nextLength, Internal.UTF_8); output.add(value); position += nextLength; } @@ -620,7 +619,7 @@ final class ArrayDecoders { if (!Utf8.isValidUtf8(data, position, position + length)) { throw InvalidProtocolBufferException.invalidUtf8(); } - String value = new String(data, position, length, StandardCharsets.UTF_8); + String value = new String(data, position, length, Internal.UTF_8); output.add(value); position += length; } @@ -639,7 +638,7 @@ final class ArrayDecoders { if (!Utf8.isValidUtf8(data, position, position + nextLength)) { throw InvalidProtocolBufferException.invalidUtf8(); } - String value = new String(data, position, nextLength, StandardCharsets.UTF_8); + String value = new String(data, position, nextLength, Internal.UTF_8); output.add(value); position += nextLength; } diff --git a/java/core/src/main/java/com/google/protobuf/BinaryReader.java b/java/core/src/main/java/com/google/protobuf/BinaryReader.java index 547e78c014..d64574c2a5 100644 --- a/java/core/src/main/java/com/google/protobuf/BinaryReader.java +++ b/java/core/src/main/java/com/google/protobuf/BinaryReader.java @@ -41,7 +41,6 @@ import static com.google.protobuf.WireFormat.WIRETYPE_VARINT; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; @@ -227,7 +226,7 @@ abstract class BinaryReader implements Reader { if (requireUtf8 && !Utf8.isValidUtf8(buffer, pos, pos + size)) { throw InvalidProtocolBufferException.invalidUtf8(); } - String result = new String(buffer, pos, size, StandardCharsets.UTF_8); + String result = new String(buffer, pos, size, Internal.UTF_8); pos += size; return result; } diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index c42b28c4f2..a4beaeb4cf 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -45,7 +45,6 @@ import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.util.ArrayList; import java.util.Arrays; @@ -461,7 +460,7 @@ public abstract class ByteString implements Iterable, Serializable { * @return new {@code ByteString} */ public static ByteString copyFromUtf8(String text) { - return new LiteralByteString(text.getBytes(StandardCharsets.UTF_8)); + return new LiteralByteString(text.getBytes(Internal.UTF_8)); } // ================================================================= @@ -834,7 +833,7 @@ public abstract class ByteString implements Iterable, Serializable { * @return new string using UTF-8 encoding */ public final String toStringUtf8() { - return toString(StandardCharsets.UTF_8); + return toString(Internal.UTF_8); } /** diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index ad87d4e05c..6e9c0f6209 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -32,13 +32,12 @@ package com.google.protobuf; import static com.google.protobuf.Internal.EMPTY_BYTE_ARRAY; import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; +import static com.google.protobuf.Internal.UTF_8; import static com.google.protobuf.Internal.checkNotNull; import static com.google.protobuf.WireFormat.FIXED32_SIZE; import static com.google.protobuf.WireFormat.FIXED64_SIZE; import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; -import static java.nio.charset.StandardCharsets.UTF_8; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index 65ea627044..12f2097a8f 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -42,7 +42,6 @@ import java.io.OutputStream; import java.nio.BufferOverflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; @@ -843,7 +842,7 @@ public abstract class CodedOutputStream extends ByteOutput { length = Utf8.encodedLength(value); } catch (UnpairedSurrogateException e) { // TODO(dweis): Consider using nio Charset methods instead. - final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); + final byte[] bytes = value.getBytes(Internal.UTF_8); length = bytes.length; } @@ -990,7 +989,8 @@ public abstract class CodedOutputStream extends ByteOutput { // Unfortunately there does not appear to be any way to tell Java to encode // UTF-8 directly into our buffer, so we have to let it create its own byte // array and then copy. - final byte[] bytes = value.getBytes(StandardCharsets.UTF_8); + // TODO(dweis): Consider using nio Charset methods instead. + final byte[] bytes = value.getBytes(Internal.UTF_8); try { writeUInt32NoTag(bytes.length); writeLazy(bytes, 0, bytes.length); 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 c3b6dc09e0..f36d033327 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -51,7 +51,6 @@ import com.google.protobuf.DescriptorProtos.ServiceOptions; import com.google.protobuf.Descriptors.FileDescriptor.Syntax; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -334,13 +333,13 @@ public final class Descriptors { // should get the original bytes that we want. // Literal strings are limited to 64k, so it may be split into multiple strings. if (strings.length == 1) { - return strings[0].getBytes(StandardCharsets.ISO_8859_1); + return strings[0].getBytes(Internal.ISO_8859_1); } StringBuilder descriptorData = new StringBuilder(); for (String part : strings) { descriptorData.append(part); } - return descriptorData.toString().getBytes(StandardCharsets.ISO_8859_1); + return descriptorData.toString().getBytes(Internal.ISO_8859_1); } private static FileDescriptor[] findDescriptors( diff --git a/java/core/src/main/java/com/google/protobuf/Internal.java b/java/core/src/main/java/com/google/protobuf/Internal.java index 1c7e7049ea..07e8dd1322 100644 --- a/java/core/src/main/java/com/google/protobuf/Internal.java +++ b/java/core/src/main/java/com/google/protobuf/Internal.java @@ -32,7 +32,7 @@ package com.google.protobuf; import java.lang.reflect.Method; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; +import java.nio.charset.Charset; import java.util.AbstractList; import java.util.AbstractMap; import java.util.AbstractSet; @@ -54,6 +54,10 @@ public final class Internal { private Internal() {} + static final Charset US_ASCII = Charset.forName("US-ASCII"); + static final Charset UTF_8 = Charset.forName("UTF-8"); + static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); + /** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */ static T checkNotNull(T obj) { if (obj == null) { @@ -93,7 +97,7 @@ public final class Internal { * actually want. The generated code calls this automatically. */ public static String stringDefaultValue(String bytes) { - return new String(bytes.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); + return new String(bytes.getBytes(ISO_8859_1), UTF_8); } /** @@ -104,7 +108,7 @@ public final class Internal { * ISO-8859-1 encoding. */ public static ByteString bytesDefaultValue(String bytes) { - return ByteString.copyFrom(bytes.getBytes(StandardCharsets.ISO_8859_1)); + return ByteString.copyFrom(bytes.getBytes(ISO_8859_1)); } /** * Helper called by generated code to construct default values for bytes fields. @@ -112,7 +116,7 @@ public final class Internal { *

This is like {@link #bytesDefaultValue}, but returns a byte array. */ public static byte[] byteArrayDefaultValue(String bytes) { - return bytes.getBytes(StandardCharsets.ISO_8859_1); + return bytes.getBytes(ISO_8859_1); } /** @@ -179,12 +183,12 @@ public final class Internal { /** Helper method to get the UTF-8 bytes of a string. */ public static byte[] toByteArray(String value) { - return value.getBytes(StandardCharsets.UTF_8); + return value.getBytes(UTF_8); } /** Helper method to convert a byte array to a string using UTF-8 encoding. */ public static String toStringUtf8(byte[] bytes) { - return new String(bytes, StandardCharsets.UTF_8); + return new String(bytes, UTF_8); } /** diff --git a/java/core/src/main/java/com/google/protobuf/MessageSchema.java b/java/core/src/main/java/com/google/protobuf/MessageSchema.java index 518f647e3e..4170f4fbe4 100644 --- a/java/core/src/main/java/com/google/protobuf/MessageSchema.java +++ b/java/core/src/main/java/com/google/protobuf/MessageSchema.java @@ -76,7 +76,6 @@ import com.google.protobuf.Internal.ProtobufList; import com.google.protobuf.MapEntryLite.Metadata; import java.io.IOException; import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -4766,7 +4765,7 @@ final class MessageSchema implements Schema { && !Utf8.isValidUtf8(data, position, position + length)) { throw InvalidProtocolBufferException.invalidUtf8(); } - final String value = new String(data, position, length, StandardCharsets.UTF_8); + final String value = new String(data, position, length, Internal.UTF_8); unsafe.putObject(message, fieldOffset, value); position += length; } diff --git a/java/core/src/main/java/com/google/protobuf/Utf8.java b/java/core/src/main/java/com/google/protobuf/Utf8.java index 2a6023ccc0..7c9133e16b 100644 --- a/java/core/src/main/java/com/google/protobuf/Utf8.java +++ b/java/core/src/main/java/com/google/protobuf/Utf8.java @@ -42,7 +42,6 @@ import static java.lang.Character.isSurrogatePair; import static java.lang.Character.toCodePoint; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; /** * A set of low-level, high-performance static utility methods related to the UTF-8 character @@ -1387,7 +1386,7 @@ final class Utf8 { if (offset == limit) { // The entire byte sequence is ASCII. Don't bother copying to a char[], JVMs using // compact strings will just turn it back into the same byte[]. - return new String(bytes, index, size, StandardCharsets.US_ASCII); + return new String(bytes, index, size, Internal.US_ASCII); } // It's not all ASCII, at this point. This may over-allocate, but we will truncate in the diff --git a/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java b/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java index 210134f0f0..656d2c3ab6 100644 --- a/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java @@ -38,8 +38,6 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -70,7 +68,7 @@ public class BoundedByteStringTest extends LiteralByteStringTest { @Test public void testToString() throws UnsupportedEncodingException { String testString = "I love unicode \u1234\u5678 characters"; - ByteString unicode = ByteString.wrap(testString.getBytes(StandardCharsets.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); ByteString chopped = unicode.substring(2, unicode.size() - 6); assertWithMessage("%s.substring() must have the expected type", classUnderTest) .that(classUnderTest) @@ -86,13 +84,13 @@ public class BoundedByteStringTest extends LiteralByteStringTest { @Test public void testCharsetToString() { String testString = "I love unicode \u1234\u5678 characters"; - ByteString unicode = ByteString.wrap(testString.getBytes(StandardCharsets.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); ByteString chopped = unicode.substring(2, unicode.size() - 6); assertWithMessage("%s.substring() must have the expected type", classUnderTest) .that(classUnderTest) .isEqualTo(getActualClassName(chopped)); - String roundTripString = chopped.toString(StandardCharsets.UTF_8); + String roundTripString = chopped.toString(Internal.UTF_8); assertWithMessage("%s unicode bytes must match", classUnderTest) .that(testString.substring(2, testString.length() - 6)) .isEqualTo(roundTripString); diff --git a/java/core/src/test/java/com/google/protobuf/ByteStringTest.java b/java/core/src/test/java/com/google/protobuf/ByteStringTest.java index 5d1028a2e6..3f97e3174f 100644 --- a/java/core/src/test/java/com/google/protobuf/ByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/ByteStringTest.java @@ -42,7 +42,6 @@ import java.io.OutputStream; import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -199,7 +198,7 @@ public class ByteStringTest { public void testCopyFrom_Utf8() { String testString = "I love unicode \u1234\u5678 characters"; ByteString byteString = ByteString.copyFromUtf8(testString); - byte[] testBytes = testString.getBytes(StandardCharsets.UTF_8); + byte[] testBytes = testString.getBytes(Internal.UTF_8); assertWithMessage("copyFromUtf8 string must respect the charset") .that(isArrayRange(byteString.toByteArray(), testBytes, 0, testBytes.length)) .isTrue(); @@ -517,7 +516,7 @@ public class ByteStringTest { @Test public void testToStringUtf8() { String testString = "I love unicode \u1234\u5678 characters"; - byte[] testBytes = testString.getBytes(StandardCharsets.UTF_8); + byte[] testBytes = testString.getBytes(Internal.UTF_8); ByteString byteString = ByteString.copyFrom(testBytes); assertWithMessage("copyToStringUtf8 must respect the charset") .that(testString) @@ -527,7 +526,7 @@ public class ByteStringTest { @Test public void testToString() { String toString = - ByteString.copyFrom("Here are some bytes: \t\u00a1".getBytes(StandardCharsets.UTF_8)).toString(); + ByteString.copyFrom("Here are some bytes: \t\u00a1".getBytes(Internal.UTF_8)).toString(); assertWithMessage(toString).that(toString.contains("size=24")).isTrue(); assertWithMessage(toString) .that(toString.contains("contents=\"Here are some bytes: \\t\\302\\241\"")) @@ -539,7 +538,7 @@ public class ByteStringTest { String toString = ByteString.copyFrom( "123456789012345678901234567890123456789012345678901234567890" - .getBytes(StandardCharsets.UTF_8)) + .getBytes(Internal.UTF_8)) .toString(); assertWithMessage(toString).that(toString.contains("size=60")).isTrue(); assertWithMessage(toString) diff --git a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java index 5bc514f342..9934ca19ff 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java @@ -41,7 +41,6 @@ import protobuf_unittest.UnittestProto.TestSparseEnum; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -418,7 +417,7 @@ public class CodedOutputStreamTest { // Write some some bytes (more than the buffer can hold) and verify that totalWritten // is correct. - byte[] value = "abcde".getBytes(StandardCharsets.UTF_8); + byte[] value = "abcde".getBytes(Internal.UTF_8); for (int i = 0; i < 1024; ++i) { coder.stream().writeRawBytes(value, 0, value.length); } @@ -501,7 +500,7 @@ public class CodedOutputStreamTest { @Test public void testWriteByteBuffer() throws Exception { - byte[] value = "abcde".getBytes(StandardCharsets.UTF_8); + byte[] value = "abcde".getBytes(Internal.UTF_8); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); CodedOutputStream codedStream = CodedOutputStream.newInstance(outputStream); ByteBuffer byteBuffer = ByteBuffer.wrap(value, 0, 1); @@ -544,7 +543,7 @@ public class CodedOutputStreamTest { for (int pos = 0; pos < source.length(); pos += 2) { String substr = source.substring(pos, pos + 2); expectedBytesStream.write(2); - expectedBytesStream.write(substr.getBytes(StandardCharsets.UTF_8)); + expectedBytesStream.write(substr.getBytes(Internal.UTF_8)); } final byte[] expectedBytes = expectedBytesStream.toByteArray(); diff --git a/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java b/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java index 690d130ed9..5a345aa173 100644 --- a/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java +++ b/java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java @@ -34,7 +34,6 @@ import com.google.protobuf.Utf8.Processor; import com.google.protobuf.Utf8.SafeProcessor; import com.google.protobuf.Utf8.UnsafeProcessor; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; @@ -197,7 +196,7 @@ public class DecodeUtf8Test extends TestCase { } public void testInvalidBufferSlice() throws Exception { - byte[] bytes = "The quick brown fox jumps over the lazy dog".getBytes(StandardCharsets.UTF_8); + byte[] bytes = "The quick brown fox jumps over the lazy dog".getBytes(Internal.UTF_8); assertInvalidSlice(bytes, bytes.length - 3, 4); assertInvalidSlice(bytes, bytes.length, 1); assertInvalidSlice(bytes, bytes.length + 1, 0); @@ -302,35 +301,35 @@ public class DecodeUtf8Test extends TestCase { } private void assertRoundTrips(String str, int index, int size) throws Exception { - byte[] bytes = str.getBytes(StandardCharsets.UTF_8); + byte[] bytes = str.getBytes(Internal.UTF_8); if (size == -1) { size = bytes.length; } assertDecode( - new String(bytes, index, size, StandardCharsets.UTF_8), + new String(bytes, index, size, Internal.UTF_8), UNSAFE_PROCESSOR.decodeUtf8(bytes, index, size)); assertDecode( - new String(bytes, index, size, StandardCharsets.UTF_8), + new String(bytes, index, size, Internal.UTF_8), SAFE_PROCESSOR.decodeUtf8(bytes, index, size)); ByteBuffer direct = ByteBuffer.allocateDirect(bytes.length); direct.put(bytes); direct.flip(); assertDecode( - new String(bytes, index, size, StandardCharsets.UTF_8), + new String(bytes, index, size, Internal.UTF_8), UNSAFE_PROCESSOR.decodeUtf8(direct, index, size)); assertDecode( - new String(bytes, index, size, StandardCharsets.UTF_8), + new String(bytes, index, size, Internal.UTF_8), SAFE_PROCESSOR.decodeUtf8(direct, index, size)); ByteBuffer heap = ByteBuffer.allocate(bytes.length); heap.put(bytes); heap.flip(); assertDecode( - new String(bytes, index, size, StandardCharsets.UTF_8), + new String(bytes, index, size, Internal.UTF_8), UNSAFE_PROCESSOR.decodeUtf8(heap, index, size)); assertDecode( - new String(bytes, index, size, StandardCharsets.UTF_8), + new String(bytes, index, size, Internal.UTF_8), SAFE_PROCESSOR.decodeUtf8(heap, index, size)); } diff --git a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java index 9e93b9f86c..6cb0baebed 100644 --- a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java +++ b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java @@ -63,8 +63,6 @@ import protobuf_unittest.UnittestProto.TestMultipleExtensionRanges; import protobuf_unittest.UnittestProto.TestRequired; import protobuf_unittest.UnittestProto.TestReservedFields; import protobuf_unittest.UnittestProto.TestService; - -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import org.junit.Test; @@ -283,7 +281,7 @@ public class DescriptorsTest { assertThat(d.findFieldByName("escaped_bytes").getDefaultValue()) .isEqualTo( ByteString.copyFrom( - "\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes(StandardCharsets.ISO_8859_1))); + "\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes(Internal.ISO_8859_1))); assertThat(d.findFieldByName("large_uint32").getDefaultValue()).isEqualTo(-1); assertThat(d.findFieldByName("large_uint64").getDefaultValue()).isEqualTo(-1L); } diff --git a/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java b/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java index 0c24207fcd..f1a671164d 100644 --- a/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java +++ b/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java @@ -35,7 +35,6 @@ import static com.google.common.truth.Truth.assertWithMessage; import java.lang.ref.SoftReference; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -277,8 +276,8 @@ final class IsValidUtf8TestUtil { } ByteString bs = factory.newByteString(bytes); boolean isRoundTrippable = bs.isValidUtf8(); - String s = new String(bytes, StandardCharsets.UTF_8); - byte[] bytesReencoded = s.getBytes(StandardCharsets.UTF_8); + String s = new String(bytes, Internal.UTF_8); + byte[] bytesReencoded = s.getBytes(Internal.UTF_8); boolean bytesEqual = Arrays.equals(bytes, bytesReencoded); if (bytesEqual != isRoundTrippable) { diff --git a/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java b/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java index 573af2f016..5ec4a937bb 100644 --- a/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java @@ -43,7 +43,6 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; @@ -469,7 +468,7 @@ public class LiteralByteStringTest { @Test public void testToString() throws UnsupportedEncodingException { String testString = "I love unicode \u1234\u5678 characters"; - ByteString unicode = ByteString.wrap(testString.getBytes(StandardCharsets.UTF_8)); + ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); String roundTripString = unicode.toString(UTF_8); assertWithMessage("%s unicode must match", classUnderTest) .that(testString) @@ -479,8 +478,8 @@ public class LiteralByteStringTest { @Test public void testCharsetToString() { String testString = "I love unicode \u1234\u5678 characters"; - ByteString unicode = ByteString.wrap(testString.getBytes(StandardCharsets.UTF_8)); - String roundTripString = unicode.toString(StandardCharsets.UTF_8); + ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8)); + String roundTripString = unicode.toString(Internal.UTF_8); assertWithMessage("%s unicode must match", classUnderTest) .that(testString) .isEqualTo(roundTripString); @@ -489,8 +488,8 @@ public class LiteralByteStringTest { @Test public void testToString_returnsCanonicalEmptyString() { assertWithMessage("%s must be the same string references", classUnderTest) - .that(ByteString.EMPTY.toString(StandardCharsets.UTF_8)) - .isSameInstanceAs(ByteString.wrap(new byte[] {}).toString(StandardCharsets.UTF_8)); + .that(ByteString.EMPTY.toString(Internal.UTF_8)) + .isSameInstanceAs(ByteString.wrap(new byte[] {}).toString(Internal.UTF_8)); } @Test diff --git a/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java b/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java index d645b89359..1f1427142b 100644 --- a/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java @@ -32,8 +32,7 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; - -import static java.nio.charset.StandardCharsets.UTF_8; +import static com.google.protobuf.Internal.UTF_8; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java b/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java index 445dbe229d..0bfc0beaa3 100644 --- a/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +++ b/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java @@ -33,7 +33,6 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertWithMessage; import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; import java.util.Iterator; import org.junit.Before; import org.junit.Test; @@ -133,7 +132,7 @@ public class RopeByteStringSubstringTest extends LiteralByteStringTest { assertWithMessage("%s from string must have the expected type", classUnderTest) .that(classUnderTest) .isEqualTo(getActualClassName(unicode)); - String roundTripString = unicode.toString(StandardCharsets.UTF_8); + String roundTripString = unicode.toString(Internal.UTF_8); assertWithMessage("%s unicode bytes must match", classUnderTest) .that(testString) .isEqualTo(roundTripString); diff --git a/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java index 000c374556..bdb8132020 100644 --- a/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java @@ -39,7 +39,6 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Iterator; import org.junit.Before; @@ -176,7 +175,7 @@ public class RopeByteStringTest extends LiteralByteStringTest { assertWithMessage("%s from string must have the expected type", classUnderTest) .that(classUnderTest) .isEqualTo(getActualClassName(unicode)); - String roundTripString = unicode.toString(StandardCharsets.UTF_8); + String roundTripString = unicode.toString(Internal.UTF_8); assertWithMessage("%s unicode bytes must match", classUnderTest) .that(testString) .isEqualTo(roundTripString); @@ -195,8 +194,8 @@ public class RopeByteStringTest extends LiteralByteStringTest { RopeByteString ropeByteString = RopeByteString.newInstanceForTest(ByteString.EMPTY, ByteString.EMPTY); assertWithMessage("%s must be the same string references", classUnderTest) - .that(ByteString.EMPTY.toString(StandardCharsets.UTF_8)) - .isSameInstanceAs(ropeByteString.toString(StandardCharsets.UTF_8)); + .that(ByteString.EMPTY.toString(Internal.UTF_8)) + .isSameInstanceAs(ropeByteString.toString(Internal.UTF_8)); } @Override diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index c4fb591676..f9b7da46b7 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -59,7 +59,6 @@ import protobuf_unittest.UnittestProto.TestOneof2; import protobuf_unittest.UnittestProto.TestRequired; import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet; import java.io.StringReader; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.logging.Logger; @@ -278,7 +277,7 @@ public class TextFormatTest { * are converted directly to bytes, *not* encoded using UTF-8. */ private ByteString bytes(String str) { - return ByteString.copyFrom(str.getBytes(StandardCharsets.ISO_8859_1)); + return ByteString.copyFrom(str.getBytes(Internal.ISO_8859_1)); } /** diff --git a/java/core/src/test/java/com/google/protobuf/Utf8Test.java b/java/core/src/test/java/com/google/protobuf/Utf8Test.java index 787cb11cb9..44f7cf136d 100644 --- a/java/core/src/test/java/com/google/protobuf/Utf8Test.java +++ b/java/core/src/test/java/com/google/protobuf/Utf8Test.java @@ -34,7 +34,6 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.Random; import org.junit.Test; import org.junit.runner.RunWith; @@ -134,7 +133,7 @@ public class Utf8Test { } private static void assertEncoding(String message) { - byte[] expected = message.getBytes(StandardCharsets.UTF_8); + byte[] expected = message.getBytes(Internal.UTF_8); byte[] output = encodeToByteArray(message, expected.length, safeProcessor); assertWithMessage("encodeUtf8[ARRAY]") .that(output).isEqualTo(expected); diff --git a/java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java b/java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java index 3f416263f9..fc1e09f10e 100644 --- a/java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java +++ b/java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java @@ -32,8 +32,6 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertThat; -import java.nio.charset.StandardCharsets; - import com.google.protobuf.wrapperstest.WrappersTestProto.TopLevelMessage; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,7 +51,7 @@ public class WrappersLiteOfMethodTest { builder.setFieldUint64(UInt64Value.of(23333333333333L)); builder.setFieldBool(BoolValue.of(true)); builder.setFieldString(StringValue.of("23333")); - builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(StandardCharsets.UTF_8)))); + builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8)))); TopLevelMessage message = builder.build(); assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333); diff --git a/java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java b/java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java index 0106987215..44c4ad6e6e 100644 --- a/java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java +++ b/java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java @@ -32,8 +32,6 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertThat; -import java.nio.charset.StandardCharsets; - import com.google.protobuf.wrapperstest.WrappersTestProto.TopLevelMessage; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,7 +51,7 @@ public class WrappersOfMethodTest { builder.setFieldUint64(UInt64Value.of(23333333333333L)); builder.setFieldBool(BoolValue.of(true)); builder.setFieldString(StringValue.of("23333")); - builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(StandardCharsets.UTF_8)))); + builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8)))); TopLevelMessage message = builder.build(); assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333); diff --git a/java/lite/src/test/java/com/google/protobuf/LiteTest.java b/java/lite/src/test/java/com/google/protobuf/LiteTest.java index a42ab31c27..b0972111ac 100644 --- a/java/lite/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/lite/src/test/java/com/google/protobuf/LiteTest.java @@ -68,7 +68,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Field; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -1721,7 +1720,7 @@ public class LiteTest { public void testMergeFromStream_invalidBytes() throws Exception { TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder().setDefaultBool(true); try { - builder.mergeFrom(CodedInputStream.newInstance("Invalid bytes".getBytes(StandardCharsets.UTF_8))); + builder.mergeFrom(CodedInputStream.newInstance("Invalid bytes".getBytes(Internal.UTF_8))); assertWithMessage("expected exception").fail(); } catch (InvalidProtocolBufferException expected) { } From 864aa49c6d09cec3eaed6205cd279a7460ed71f6 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 7 Jan 2022 20:08:45 +0000 Subject: [PATCH 119/207] restore Android API level 14 compatibility (#9386) --- .../src/main/java/com/google/protobuf/ByteString.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index a4beaeb4cf..b46df5a376 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -268,22 +268,19 @@ public abstract class ByteString implements Iterable, Serializable { ByteIterator latterBytes = latter.iterator(); while (formerBytes.hasNext() && latterBytes.hasNext()) { - // Note: This code was copied from com.google.common.primitives.UnsignedBytes#compare, - // as Guava libraries cannot be used in the {@code com.google.protobuf} package. - int result = - Integer.compare(toInt(formerBytes.nextByte()), toInt(latterBytes.nextByte())); + int result = Integer.valueOf(toInt(formerBytes.nextByte())) + .compareTo(toInt(latterBytes.nextByte())); if (result != 0) { return result; } } - - return Integer.compare(former.size(), latter.size()); + return Integer.valueOf(former.size()).compareTo(Integer.valueOf(latter.size())); } }; /** * Returns a {@link Comparator} which compares {@link ByteString}-s lexicographically - * as sequences of unsigned bytes (i.e. values between 0 and 255, inclusive). + * as sequences of unsigned byte values between 0 and 255, inclusive. * *

For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because it * is interpreted as an unsigned value, {@code 255}: From c7808a87fa136385b60bd339eca95d942bd86273 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 7 Jan 2022 21:27:07 +0000 Subject: [PATCH 120/207] restore even more Android API level 14 compatibility (#9388) --- .../java/com/google/protobuf/Descriptors.java | 2 +- .../main/java/com/google/protobuf/TextFormat.java | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) 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 f36d033327..0c10774dde 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -1941,7 +1941,7 @@ public final class Descriptors { new Comparator() { @Override public int compare(EnumValueDescriptor o1, EnumValueDescriptor o2) { - return Integer.compare(o1.getNumber(), o2.getNumber()); + return Integer.valueOf(o1.getNumber()).compareTo(o2.getNumber()); } }; diff --git a/java/core/src/main/java/com/google/protobuf/TextFormat.java b/java/core/src/main/java/com/google/protobuf/TextFormat.java index 21f1ff09d4..eff10afa70 100644 --- a/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -30,8 +30,6 @@ package com.google.protobuf; -import static java.nio.charset.StandardCharsets.UTF_8; - import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.EnumDescriptor; import com.google.protobuf.Descriptors.EnumValueDescriptor; @@ -491,11 +489,11 @@ public final class TextFormat { } switch (fieldType) { case BOOLEAN: - return Boolean.compare((boolean) getKey(), (boolean) b.getKey()); + return Boolean.valueOf((boolean) getKey()).compareTo((boolean) b.getKey()); case LONG: - return Long.compare((long) getKey(), (long) b.getKey()); + return Long.valueOf((long) getKey()).compareTo((long) b.getKey()); case INT: - return Integer.compare((int) getKey(), (int) b.getKey()); + return Integer.valueOf((int) getKey()).compareTo((int) b.getKey()); case STRING: String aString = (String) getKey(); String bString = (String) b.getKey(); @@ -2393,11 +2391,12 @@ public final class TextFormat { | digitValue(input.byteAt(i + 1)) << 8 | digitValue(input.byteAt(i + 2)) << 4 | digitValue(input.byteAt(i + 3))); - if (Character.isSurrogate(ch)) { + + if (ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE) { throw new InvalidEscapeSequenceException( "Invalid escape sequence: '\\u' refers to a surrogate"); } - byte[] chUtf8 = Character.toString(ch).getBytes(UTF_8); + byte[] chUtf8 = Character.toString(ch).getBytes(Internal.UTF_8); System.arraycopy(chUtf8, 0, result, pos, chUtf8.length); pos += chUtf8.length; i += 3; @@ -2440,7 +2439,7 @@ public final class TextFormat { } int[] codepoints = new int[1]; codepoints[0] = codepoint; - byte[] chUtf8 = new String(codepoints, 0, 1).getBytes(UTF_8); + byte[] chUtf8 = new String(codepoints, 0, 1).getBytes(Internal.UTF_8); System.arraycopy(chUtf8, 0, result, pos, chUtf8.length); pos += chUtf8.length; i += 7; From 0ac74b8126b76498075f43c37603d67a15d8d205 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 7 Jan 2022 23:45:21 +0000 Subject: [PATCH 121/207] turn on animal-sniffer (#9383) * turn on animal-sniffer * allow API level 19 for util package --- java/pom.xml | 50 ++++++++++++++++++++++++++++------------------- java/util/pom.xml | 22 ++++++++++++++++++++- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index 5dd0b925b8..e0f4f26431 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -160,33 +160,43 @@ maven-antrun-plugin 3.0.0 + + maven-surefire-plugin + 3.0.0-M5 + org.codehaus.mojo animal-sniffer-maven-plugin 1.20 - - - net.sf.androidscents.signature - android-api-level-14 - 4.0_r4 - - - - - android - test - - check - - - - - - maven-surefire-plugin - 3.0.0-M5 + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + net.sf.androidscents.signature + android-api-level-14 + 4.0_r4 + + + sun.misc.Unsafe + + + + + android + test + + check + + + + + diff --git a/java/util/pom.xml b/java/util/pom.xml index e870bff04c..5e7e891de7 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -117,7 +117,27 @@ - + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + net.sf.androidscents.signature + android-api-level-19 + 4.4.2_r4 + + + + + android + test + + check + + + + org.apache.felix From 3d995aaf98ed73ddcbbf0ed88d82bbbf80ec8cf9 Mon Sep 17 00:00:00 2001 From: Gregory Haskins Date: Sun, 9 Jan 2022 10:14:18 -0500 Subject: [PATCH 122/207] Update protojure link (#9389) --- docs/third_party.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/third_party.md b/docs/third_party.md index 8448b57829..1bf36a8a9f 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -27,7 +27,7 @@ These are projects we know about implementing Protocol Buffers for other program * C#/.NET/WCF/VB: https://code.google.com/p/protobuf-net/ * Clojure: http://github.com/ninjudd/clojure-protobuf * Clojure: https://github.com/clojusc/protobuf -* Clojure: https://protojure.github.io +* Clojure: https://protojure.readthedocs.io * Common Lisp: http://github.com/brown/protobuf * Common Lisp: http://github.com/qitab/cl-protobuf * D: https://github.com/dcarp/protobuf-d From 558d128fc7caddc6d5f087dfd979fa4b2dc040b1 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 10 Jan 2022 11:28:45 +1100 Subject: [PATCH 123/207] require bcmath bcmath (specifically, the bccomp function) is internally required, and tests fail if it's not available --- php/composer.json | 3 ++- php/src/Google/Protobuf/Internal/GPBUtil.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/php/composer.json b/php/composer.json index f712f0ebb9..d0d50ce713 100644 --- a/php/composer.json +++ b/php/composer.json @@ -6,7 +6,8 @@ "homepage": "https://developers.google.com/protocol-buffers/", "license": "BSD-3-Clause", "require": { - "php": ">=7.0.0" + "php": ">=7.1.0", + "ext-bcmath": "*" }, "require-dev": { "phpunit/phpunit": ">=5.0.0" diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 1dd6645bcd..b71246e81d 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -37,6 +37,7 @@ use Google\Protobuf\FieldMask; use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\MapField; +use function bccomp; function camel2underscore($input) { preg_match_all( From 922a7ec18926aa2612d14a2b4abb8689477e97a4 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 20 Oct 2021 14:51:07 -0700 Subject: [PATCH 124/207] Fix Python 3.10 C++ tests (#9128) The first change is to make sure we always define PY_SSIZE_T_CLEAN before including Python.h. Starting from Python 3.10 this is required. Otherwise we get errors like this: SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats The second change is to update reflection_test.py to account for the fact that with Python 3.10, we get a TypeError even with the C++ implementation when trying to assign a float to a bool field. I'm not sure why this changed with Python 3.10, but it seems like a good thing since this is the desired behavior anyway. --- python/google/protobuf/internal/api_implementation.cc | 1 + python/google/protobuf/internal/reflection_test.py | 4 +++- python/google/protobuf/proto_api.h | 1 + python/google/protobuf/pyext/descriptor.cc | 1 + python/google/protobuf/pyext/descriptor.h | 1 + python/google/protobuf/pyext/descriptor_containers.cc | 1 + python/google/protobuf/pyext/descriptor_containers.h | 1 + python/google/protobuf/pyext/descriptor_database.h | 1 + python/google/protobuf/pyext/descriptor_pool.cc | 1 + python/google/protobuf/pyext/descriptor_pool.h | 1 + python/google/protobuf/pyext/extension_dict.h | 1 + python/google/protobuf/pyext/field.h | 1 + python/google/protobuf/pyext/map_container.h | 1 + python/google/protobuf/pyext/message.h | 1 + python/google/protobuf/pyext/message_factory.cc | 1 + python/google/protobuf/pyext/message_factory.h | 1 + python/google/protobuf/pyext/message_module.cc | 1 + python/google/protobuf/pyext/repeated_composite_container.h | 1 + python/google/protobuf/pyext/repeated_scalar_container.h | 1 + python/google/protobuf/pyext/scoped_pyobject_ptr.h | 1 + python/google/protobuf/pyext/unknown_fields.cc | 1 + python/google/protobuf/pyext/unknown_fields.h | 1 + python/google/protobuf/python_protobuf.h | 1 + 23 files changed, 25 insertions(+), 1 deletion(-) diff --git a/python/google/protobuf/internal/api_implementation.cc b/python/google/protobuf/internal/api_implementation.cc index 6532a81405..802322424e 100644 --- a/python/google/protobuf/internal/api_implementation.cc +++ b/python/google/protobuf/internal/api_implementation.cc @@ -28,6 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#define PY_SSIZE_T_CLEAN #include namespace google { diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 9343389ed5..d1d595625d 100644 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -37,6 +37,7 @@ import copy import gc import operator import struct +import sys import warnings import unittest @@ -376,7 +377,8 @@ class ReflectionTest(unittest.TestCase): self.assertRaises(TypeError, setattr, proto, 'optional_float', 'foo') self.assertRaises(TypeError, setattr, proto, 'optional_double', 'foo') # TODO(jieluo): Fix type checking difference for python and c extension - if api_implementation.Type() == 'python': + if (api_implementation.Type() == 'python' or + (sys.version_info.major, sys.version_info.minor) >= (3, 10)): self.assertRaises(TypeError, setattr, proto, 'optional_bool', 1.1) else: proto.optional_bool = 1.1 diff --git a/python/google/protobuf/proto_api.h b/python/google/protobuf/proto_api.h index 2e2156a56e..9969a91f44 100644 --- a/python/google/protobuf/proto_api.h +++ b/python/google/protobuf/proto_api.h @@ -45,6 +45,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__ #define GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 9708b84013..a2993d908b 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -32,6 +32,7 @@ #include +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor.h b/python/google/protobuf/pyext/descriptor.h index b99209dd19..d97e2f8103 100644 --- a/python/google/protobuf/pyext/descriptor.h +++ b/python/google/protobuf/pyext/descriptor.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor_containers.cc b/python/google/protobuf/pyext/descriptor_containers.cc index b084f5b812..4caff6941a 100644 --- a/python/google/protobuf/pyext/descriptor_containers.cc +++ b/python/google/protobuf/pyext/descriptor_containers.cc @@ -49,6 +49,7 @@ // because the Python API is based on C, and does not play well with C++ // inheritance. +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor_containers.h b/python/google/protobuf/pyext/descriptor_containers.h index 4e05c58e2b..cf2cf4ad0b 100644 --- a/python/google/protobuf/pyext/descriptor_containers.h +++ b/python/google/protobuf/pyext/descriptor_containers.h @@ -34,6 +34,7 @@ // Mappings and Sequences of descriptors. // They implement containers like fields_by_name, EnumDescriptor.values... // See descriptor_containers.cc for more description. +#define PY_SSIZE_T_CLEAN #include namespace google { diff --git a/python/google/protobuf/pyext/descriptor_database.h b/python/google/protobuf/pyext/descriptor_database.h index d2d9f8e506..3bc99e7dbc 100644 --- a/python/google/protobuf/pyext/descriptor_database.h +++ b/python/google/protobuf/pyext/descriptor_database.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_DATABASE_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_DATABASE_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index 5ec6269cd4..f6bdb6e4c8 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -32,6 +32,7 @@ #include +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/descriptor_pool.h b/python/google/protobuf/pyext/descriptor_pool.h index 48658d3e88..5d3c3a95cc 100644 --- a/python/google/protobuf/pyext/descriptor_pool.h +++ b/python/google/protobuf/pyext/descriptor_pool.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/extension_dict.h b/python/google/protobuf/pyext/extension_dict.h index c9da443161..a0581941bd 100644 --- a/python/google/protobuf/pyext/extension_dict.h +++ b/python/google/protobuf/pyext/extension_dict.h @@ -34,6 +34,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/field.h b/python/google/protobuf/pyext/field.h index 7b4660cab5..f9f94c4983 100644 --- a/python/google/protobuf/pyext/field.h +++ b/python/google/protobuf/pyext/field.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__ +#define PY_SSIZE_T_CLEAN #include namespace google { diff --git a/python/google/protobuf/pyext/map_container.h b/python/google/protobuf/pyext/map_container.h index 842602e79f..e14136efab 100644 --- a/python/google/protobuf/pyext/map_container.h +++ b/python/google/protobuf/pyext/map_container.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index 29af255154..b17daa5806 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -34,6 +34,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/message_factory.cc b/python/google/protobuf/pyext/message_factory.cc index 30dfab88dc..5098379f35 100644 --- a/python/google/protobuf/pyext/message_factory.cc +++ b/python/google/protobuf/pyext/message_factory.cc @@ -30,6 +30,7 @@ #include +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/message_factory.h b/python/google/protobuf/pyext/message_factory.h index 515c29cdb8..7dfe425dd5 100644 --- a/python/google/protobuf/pyext/message_factory.h +++ b/python/google/protobuf/pyext/message_factory.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/message_module.cc b/python/google/protobuf/pyext/message_module.cc index 971d2bad70..a0806a3160 100644 --- a/python/google/protobuf/pyext/message_module.cc +++ b/python/google/protobuf/pyext/message_module.cc @@ -28,6 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/repeated_composite_container.h b/python/google/protobuf/pyext/repeated_composite_container.h index e241827ef5..30536eabd4 100644 --- a/python/google/protobuf/pyext/repeated_composite_container.h +++ b/python/google/protobuf/pyext/repeated_composite_container.h @@ -34,6 +34,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_COMPOSITE_CONTAINER_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_COMPOSITE_CONTAINER_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/repeated_scalar_container.h b/python/google/protobuf/pyext/repeated_scalar_container.h index f9f0ea8f31..372b6f0a35 100644 --- a/python/google/protobuf/pyext/repeated_scalar_container.h +++ b/python/google/protobuf/pyext/repeated_scalar_container.h @@ -34,6 +34,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_SCALAR_CONTAINER_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_SCALAR_CONTAINER_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/pyext/scoped_pyobject_ptr.h b/python/google/protobuf/pyext/scoped_pyobject_ptr.h index 6f7fc29813..985df2c3bb 100644 --- a/python/google/protobuf/pyext/scoped_pyobject_ptr.h +++ b/python/google/protobuf/pyext/scoped_pyobject_ptr.h @@ -35,6 +35,7 @@ #include +#define PY_SSIZE_T_CLEAN #include namespace google { namespace protobuf { diff --git a/python/google/protobuf/pyext/unknown_fields.cc b/python/google/protobuf/pyext/unknown_fields.cc index 7f4fb23edf..b9ca6ad3b0 100644 --- a/python/google/protobuf/pyext/unknown_fields.cc +++ b/python/google/protobuf/pyext/unknown_fields.cc @@ -30,6 +30,7 @@ #include +#define PY_SSIZE_T_CLEAN #include #include #include diff --git a/python/google/protobuf/pyext/unknown_fields.h b/python/google/protobuf/pyext/unknown_fields.h index 94d55e148d..e7b0b35c41 100644 --- a/python/google/protobuf/pyext/unknown_fields.h +++ b/python/google/protobuf/pyext/unknown_fields.h @@ -31,6 +31,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__ +#define PY_SSIZE_T_CLEAN #include #include diff --git a/python/google/protobuf/python_protobuf.h b/python/google/protobuf/python_protobuf.h index 8db1ffb750..4fcf065404 100644 --- a/python/google/protobuf/python_protobuf.h +++ b/python/google/protobuf/python_protobuf.h @@ -36,6 +36,7 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ #define GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ +#define PY_SSIZE_T_CLEAN #include namespace google { From 203c593b9681d98e7e05f3d8f862aa183f5d9c91 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Mon, 10 Jan 2022 21:40:56 +0000 Subject: [PATCH 125/207] Fix build error with Python 3.10 build on Windows The Windows build for Python 3.10 is giving us an error about ssize_t being undefined, so this commit fixes the problem by replacing it with Py_ssize_t, which is consistent with what we do elsewhere in the file. --- python/google/protobuf/pyext/unknown_fields.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/google/protobuf/pyext/unknown_fields.cc b/python/google/protobuf/pyext/unknown_fields.cc index b9ca6ad3b0..6d919b361a 100644 --- a/python/google/protobuf/pyext/unknown_fields.cc +++ b/python/google/protobuf/pyext/unknown_fields.cc @@ -219,7 +219,7 @@ const UnknownField* GetUnknownField(PyUnknownFieldRef* self) { "The parent message might be cleared."); return NULL; } - ssize_t total_size = fields->field_count(); + Py_ssize_t total_size = fields->field_count(); if (self->index >= total_size) { PyErr_Format(PyExc_ValueError, "UnknownField does not exist. " From ee432e55b808a57e44115178e41cd5ceae91b205 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 11 Jan 2022 01:05:54 +0000 Subject: [PATCH 126/207] Update CHANGES.txt for 3.19.3 The 3.19.2 release was supposed to fix the missing Python 3.10 wheel for Windows, but this turned out to need some more fixes. This commit updates CHANGES.txt to reflect that this fix will happen in 3.19.3 instead of 3.19.2. --- CHANGES.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 19720f972a..92d220f35b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,8 +1,10 @@ -2022-01-05 version 3.19.2 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) +2022-01-10 version 3.19.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Python * Fix missing Windows wheel for Python 3.10 on PyPI +2022-01-05 version 3.19.2 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + Java * Improve performance characteristics of UnknownFieldSet parsing (#9371) From cc7b1b53234cd7a8f50d90ac3933b240dcf4cd97 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 11 Jan 2022 01:02:49 +0000 Subject: [PATCH 127/207] Update protobuf version --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 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/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 25 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 +-- src/Makefile.am | 2 +- 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/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 +- 37 files changed, 59 insertions(+), 44 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index d6f2c00f07..ab241b9432 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.19.2' + s.version = '3.19.3' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index f8c8c65b83..39f83393fa 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.19.2' + s.version = '3.19.3' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 6bec81022d..02085ca809 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.19.2],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.19.3],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index b653766268..b57bab299a 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.19.2 + 3.19.3 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 68c14bf58a..1caa7de93c 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.19.2 + 3.19.3 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index c1c3614063..46b3f563d4 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.19.2 + 3.19.3 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.19.2 + 3.19.3 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.19.2' + implementation 'com.google.protobuf:protobuf-java:3.19.3' ``` 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 68aded500c..cb0fad22c3 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.19.2 + 3.19.3 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index b77a5c422d..f288746711 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.2 + 3.19.3 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 4be6c73a91..0348bddf20 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.2 + 3.19.3 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index 90d12f6a0d..a275f24bd9 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.2 + 3.19.3 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index bb22fb9f91..cbb5960793 100644 --- a/java/lite.md +++ b/java/lite.md @@ -30,7 +30,7 @@ protobuf Java runtime. If you are using Maven, use the following: com.google.protobuf protobuf-javalite - 3.19.2 + 3.19.3 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index a8ae75cc3b..ee8c73ca51 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.2 + 3.19.3 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 1932c9e89f..16df630384 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.2 + 3.19.3 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index e5a4b412c2..606c445321 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.2 + 3.19.3 protobuf-java-util diff --git a/js/package.json b/js/package.json index 2c9ac58721..aecbbc1c84 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.19.2", + "version": "3.19.3", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index dc35b7d593..2986347904 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2022-01-05 - + 2022-01-11 + - 3.19.2 - 3.19.2 + 3.19.3 + 3.19.3 stable @@ -22,7 +22,7 @@ 3-Clause BSD License - * No new changes in 3.19.2 + * No new changes in 3.19.3 @@ -1173,5 +1173,20 @@ G A release. + + + 3.19.3 + 3.19.3 + + + stable + stable + + 2022-01-11 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 87aeeea59d..df52892111 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -91,7 +91,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.19.2" +#define PHP_PROTOBUF_VERSION "3.19.3" // 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 436086e0da..3a5a72dec6 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1 @@ -PROTOBUF_VERSION = '3.19.2' +PROTOBUF_VERSION = '3.19.3' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 7bb58f6dfc..8c2948c586 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.19.2 + 3.19.3 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index fc8d7ae1d9..07a4d94fd2 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.19.2' +__version__ = '3.19.3' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 6a82dc1b41..1c151a5983 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.19.2" + s.version = "3.19.3" 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 395b957696..255d840bb9 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.19.2 + 3.19.3 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.19.2 + 3.19.3 org.jruby diff --git a/src/Makefile.am b/src/Makefile.am index e897cc8eed..3312e5db33 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 30:2:0 +PROTOBUF_VERSION = 30:3:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 9e04bfb296..a04547b453 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 69d4cad776..c13eaab1ea 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 320011e98a..3e9d7c5b6e 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 a0a96821af..71b018eb83 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 d1962b736c..4f04a0b83a 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 eaee816b33..658ceea0f6 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 103dfa377b..c641a4acc2 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 631b143623..2c71f9b5e5 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -153,7 +153,7 @@ #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 3019002 +#define PROTOBUF_VERSION 3019003 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 589f4de006..58b1cb8f62 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 b6429e6083..f2beaef09c 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 d3b32c381f..44d680a197 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -82,7 +82,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 3019002 +#define GOOGLE_PROTOBUF_VERSION 3019003 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index ea0cb201fe..671961edd5 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 ce17016ba9..d3c198a3e3 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 9e32a6609f..a4ac2896bc 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019003 < 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 49b184b163a830518f1f2d6e4396a71791bdb90c Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 11 Jan 2022 08:47:10 -0800 Subject: [PATCH 128/207] Revert "Standardize on Array copyOf" (#9400) This reverts commit 935d099ad9f6692e727406764bb3226d935e899d from PR #9162. While the original commit was a nice simplification, I learned from another Googler that there is unfortunately a performance cost to this (or at least there was last time this change was attempted). Even if it turns out to be fast on modern Java runtimes, we still care about the performance on old Android devices. --- .../java/com/google/protobuf/BooleanArrayList.java | 13 ++++++++++--- .../java/com/google/protobuf/DoubleArrayList.java | 13 ++++++++++--- .../java/com/google/protobuf/FloatArrayList.java | 13 ++++++++++--- .../main/java/com/google/protobuf/IntArrayList.java | 13 ++++++++++--- .../java/com/google/protobuf/LongArrayList.java | 13 ++++++++++--- .../java/com/google/protobuf/ProtobufArrayList.java | 4 +++- 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java index 35c9240780..451fce1e84 100644 --- a/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java @@ -197,7 +197,10 @@ final class BooleanArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + boolean[] newArray = new boolean[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; } array[size++] = element; @@ -216,10 +219,14 @@ final class BooleanArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + boolean[] newArray = new boolean[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, array, index + 1, size - index); + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java index ec4a416781..4085653437 100644 --- a/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java @@ -197,7 +197,10 @@ final class DoubleArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + double[] newArray = new double[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; } array[size++] = element; @@ -216,10 +219,14 @@ final class DoubleArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + double[] newArray = new double[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, array, index + 1, size - index); + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/FloatArrayList.java b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java index 4d42b7c495..e6feba8a35 100644 --- a/java/core/src/main/java/com/google/protobuf/FloatArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/FloatArrayList.java @@ -196,7 +196,10 @@ final class FloatArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + float[] newArray = new float[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; } array[size++] = element; @@ -215,10 +218,14 @@ final class FloatArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + float[] newArray = new float[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, array, index + 1, size - index); + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/IntArrayList.java b/java/core/src/main/java/com/google/protobuf/IntArrayList.java index 5392e0e408..9daeebed99 100644 --- a/java/core/src/main/java/com/google/protobuf/IntArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/IntArrayList.java @@ -196,7 +196,10 @@ final class IntArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + int[] newArray = new int[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; } array[size++] = element; @@ -215,10 +218,14 @@ final class IntArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + int[] newArray = new int[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, array, index + 1, size - index); + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/LongArrayList.java b/java/core/src/main/java/com/google/protobuf/LongArrayList.java index c971b5a995..bda43a41bb 100644 --- a/java/core/src/main/java/com/google/protobuf/LongArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/LongArrayList.java @@ -196,7 +196,10 @@ final class LongArrayList extends AbstractProtobufList if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + long[] newArray = new long[length]; + + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; } array[size++] = element; @@ -215,10 +218,14 @@ final class LongArrayList extends AbstractProtobufList } else { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + long[] newArray = new long[length]; + + // Copy the first part directly + System.arraycopy(array, 0, newArray, 0, index); // Copy the rest shifted over by one to make room - System.arraycopy(array, index, array, index + 1, size - index); + System.arraycopy(array, index, newArray, index + 1, size - index); + array = newArray; } array[index] = element; diff --git a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java index fd82233fcf..33e4bd5e35 100644 --- a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java @@ -80,7 +80,9 @@ final class ProtobufArrayList extends AbstractProtobufList implements Rand if (size == array.length) { // Resize to 1.5x the size int length = ((size * 3) / 2) + 1; - array = Arrays.copyOf(array, length); + E[] newArray = Arrays.copyOf(array, length); + + array = newArray; } array[size++] = element; From b3093dce58bc9d3042f085666d83c8ef1f51fe7b Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 11 Jan 2022 15:36:56 -0800 Subject: [PATCH 129/207] Update CHANGES.txt to include recent Java security advisory (#9403) --- CHANGES.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 92d220f35b..d919ae1b6a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,22 @@ Java * Improve performance characteristics of UnknownFieldSet parsing (#9371) + * This release addresses a Security Advisory for Java users + (https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-wrvw-hg22-4m67) + +2022-01-05 version 3.18.2 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Java + * Improve performance characteristics of UnknownFieldSet parsing (#9371) + * This release addresses a Security Advisory for Java users + (https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-wrvw-hg22-4m67) + +2022-01-05 version 3.16.1 (Java) + + Java + * Improve performance characteristics of UnknownFieldSet parsing (#9371) + * This release addresses a Security Advisory for Java users + (https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-wrvw-hg22-4m67) 2021-10-28 version 3.19.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) From f96050a05d417fbeb989d412e4d2ad5da3d20b96 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Wed, 12 Jan 2022 23:43:13 +0330 Subject: [PATCH 130/207] Add $(nproc) to make documentation (#9360) --- src/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/README.md b/src/README.md index 9db40fdde4..80e8668d99 100644 --- a/src/README.md +++ b/src/README.md @@ -48,7 +48,7 @@ Buffer compiler (protoc) execute the following: ./configure - make + make -j$(nproc) # $(nproc) ensures it uses all cores for compilation make check sudo make install sudo ldconfig # refresh shared library cache. From c160ae52a91ca4c76936531d68cc846f8230dbb1 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 12 Jan 2022 15:31:20 -0500 Subject: [PATCH 131/207] remove Proto2MessageLiteInfoFactory and Proto3MessageLiteInfoFactory (#9407) * remove Proto2MessageLiteInfoFactory.java= * remove Proto3MessageLiteInfoFactory.java --- Makefile.am | 2 - .../Proto3MessageLiteInfoFactory.java | 816 ---------- .../Proto2MessageLiteInfoFactory.java | 1332 ----------------- 3 files changed, 2150 deletions(-) delete mode 100644 java/core/src/test/java/com/google/protobuf/Proto3MessageLiteInfoFactory.java delete mode 100644 java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java diff --git a/Makefile.am b/Makefile.am index 43a6bffe56..ecfab8cda9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -475,7 +475,6 @@ java_EXTRA_DIST= java/core/src/test/java/com/google/protobuf/Proto3LiteSchemaTest.java \ java/core/src/test/java/com/google/protobuf/Proto3MessageFactory.java \ java/core/src/test/java/com/google/protobuf/Proto3MessageLiteFactory.java \ - java/core/src/test/java/com/google/protobuf/Proto3MessageLiteInfoFactory.java \ java/core/src/test/java/com/google/protobuf/Proto3SchemaTest.java \ java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java \ java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java \ @@ -577,7 +576,6 @@ java_EXTRA_DIST= java/lite/pom_template.xml \ java/lite/process-lite-sources-build.xml \ java/lite/src/test/java/com/google/protobuf/LiteTest.java \ - java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java \ java/BUILD \ java/pom.xml \ java/util/BUILD \ diff --git a/java/core/src/test/java/com/google/protobuf/Proto3MessageLiteInfoFactory.java b/java/core/src/test/java/com/google/protobuf/Proto3MessageLiteInfoFactory.java deleted file mode 100644 index 3c0c629c20..0000000000 --- a/java/core/src/test/java/com/google/protobuf/Proto3MessageLiteInfoFactory.java +++ /dev/null @@ -1,816 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package com.google.protobuf; - -import static com.google.protobuf.FieldInfo.forField; -import static com.google.protobuf.FieldInfo.forMapField; -import static com.google.protobuf.FieldInfo.forOneofMemberField; -import static com.google.protobuf.FieldInfo.forRepeatedMessageField; - -import com.google.protobuf.testing.Proto3TestingLite.Proto3EmptyLite; -import com.google.protobuf.testing.Proto3TestingLite.Proto3MessageLite; -import com.google.protobuf.testing.Proto3TestingLite.Proto3MessageLiteWithMaps; -import java.lang.reflect.Field; - -/** A factory that generates a hard-coded info for {@link Proto3MessageLite}. */ -public final class Proto3MessageLiteInfoFactory implements MessageInfoFactory { - private static final Proto3MessageLiteInfoFactory instanceForRawMessageInfo = - new Proto3MessageLiteInfoFactory(true); - private static final Proto3MessageLiteInfoFactory instanceForStructuralMessageInfo = - new Proto3MessageLiteInfoFactory(false); - - public static Proto3MessageLiteInfoFactory getInstanceForRawMessageInfo() { - return instanceForRawMessageInfo; - } - - public static Proto3MessageLiteInfoFactory getInstanceForStructuralMessageInfo() { - return instanceForStructuralMessageInfo; - } - - private final boolean produceRawMessageInfo; - - private Proto3MessageLiteInfoFactory(boolean produceRawMessageInfo) { - this.produceRawMessageInfo = produceRawMessageInfo; - } - - @Override - public boolean isSupported(Class clazz) { - return true; - } - - @Override - public MessageInfo messageInfoFor(Class clazz) { - return produceRawMessageInfo ? rawMessageInfoFor(clazz) : structuralMessageInfoFor(clazz); - } - - private MessageInfo rawMessageInfoFor(Class clazz) { - if (Proto3MessageLite.class.isAssignableFrom(clazz)) { - return newRawMessageInfoForProto3MessageLite(); - } else { - throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); - } - } - - private MessageInfo newRawMessageInfoForProto3MessageLite() { - java.lang.Object[] objects = - new java.lang.Object[] { - "testOneof_", - "testOneofCase_", - "fieldDouble1_", - "fieldFloat2_", - "fieldInt643_", - "fieldUint644_", - "fieldInt325_", - "fieldFixed646_", - "fieldFixed327_", - "fieldBool8_", - "fieldString9_", - "fieldMessage10_", - "fieldBytes11_", - "fieldUint3212_", - "fieldEnum13_", - "fieldSfixed3214_", - "fieldSfixed6415_", - "fieldSint3216_", - "fieldSint6417_", - "fieldDoubleList18_", - "fieldFloatList19_", - "fieldInt64List20_", - "fieldUint64List21_", - "fieldInt32List22_", - "fieldFixed64List23_", - "fieldFixed32List24_", - "fieldBoolList25_", - "fieldStringList26_", - "fieldMessageList27_", - Proto3MessageLite.class, - "fieldBytesList28_", - "fieldUint32List29_", - "fieldEnumList30_", - "fieldSfixed32List31_", - "fieldSfixed64List32_", - "fieldSint32List33_", - "fieldSint64List34_", - "fieldDoubleListPacked35_", - "fieldFloatListPacked36_", - "fieldInt64ListPacked37_", - "fieldUint64ListPacked38_", - "fieldInt32ListPacked39_", - "fieldFixed64ListPacked40_", - "fieldFixed32ListPacked41_", - "fieldBoolListPacked42_", - "fieldUint32ListPacked43_", - "fieldEnumListPacked44_", - "fieldSfixed32ListPacked45_", - "fieldSfixed64ListPacked46_", - "fieldSint32ListPacked47_", - "fieldSint64ListPacked48_", - Proto3MessageLite.class, - }; - // To update this after a proto change, run protoc on proto3_message_lite.proto and copy over - // the content of the generated buildMessageInfo() method here. - java.lang.String info = - "\u0000@\u0001\u0000\u0001D@\u0000\u001f\u0000\u0001\u0000\u0002\u0001\u0003\u0002" - + "\u0004\u0003\u0005\u0004\u0006\u0005\u0007\u0006\b\u0007\t\u0208\n\t\u000b\n\f\u000b" - + "\r\f\u000e\r\u000f\u000e\u0010\u000f\u0011\u0010\u0012\u0012\u0013\u0013\u0014\u0014" - + "\u0015\u0015\u0016\u0016\u0017\u0017\u0018\u0018\u0019\u0019\u001a\u021a\u001b\u001b" - + "\u001c\u001c\u001d\u001d\u001e\u001e\u001f\u001f !!\"\"##$$%%&&\'\'(())**++,,--" - + "..//0053\u000064\u000075\u000086\u000097\u0000:8\u0000;9\u0000<:\u0000=\u023b\u0000" - + "><\u0000?=\u0000@>\u0000A@\u0000BA\u0000CB\u0000DC\u0000"; - return new RawMessageInfo(Proto3MessageLite.getDefaultInstance(), info, objects); - } - - private MessageInfo structuralMessageInfoFor(Class clazz) { - if (Proto3MessageLite.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto3MessageLite(); - } else if (Proto3EmptyLite.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto3EmptyLite(); - } else if (Proto3MessageLiteWithMaps.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto3MessageLiteWithMaps(); - } else { - throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); - } - } - - /** - * Creates a new hard-coded info for {@link Proto3MessageLite}. Each time this is called, we - * manually go through the entire process of what a message would do if it self-registered its own - * info, including looking up each field by name. This is done for benchmarking purposes, so that - * we get a more accurate representation of the time it takes to perform this process. - */ - private static StructuralMessageInfo newMessageInfoForProto3MessageLite() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(48); - lookupFieldsByName(builder); - return builder.build(); - } - - private static void lookupFieldsByName(StructuralMessageInfo.Builder builder) { - builder.withDefaultInstance(Proto3MessageLite.getDefaultInstance()); - builder.withSyntax(ProtoSyntax.PROTO3); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldDouble1_"), 1, FieldType.DOUBLE, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldFloat2_"), 2, FieldType.FLOAT, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldInt643_"), 3, FieldType.INT64, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldUint644_"), 4, FieldType.UINT64, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldInt325_"), 5, FieldType.INT32, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldFixed646_"), 6, FieldType.FIXED64, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldFixed327_"), 7, FieldType.FIXED32, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldBool8_"), 8, FieldType.BOOL, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldString9_"), 9, FieldType.STRING, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldMessage10_"), 10, FieldType.MESSAGE, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldBytes11_"), 11, FieldType.BYTES, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldUint3212_"), 12, FieldType.UINT32, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldEnum13_"), 13, FieldType.ENUM, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldSfixed3214_"), 14, FieldType.SFIXED32, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldSfixed6415_"), 15, FieldType.SFIXED64, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldSint3216_"), 16, FieldType.SINT32, true)); - builder.withField( - forField(field(Proto3MessageLite.class, "fieldSint6417_"), 17, FieldType.SINT64, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldDoubleList18_"), 18, FieldType.DOUBLE_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldFloatList19_"), 19, FieldType.FLOAT_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldInt64List20_"), 20, FieldType.INT64_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldUint64List21_"), 21, FieldType.UINT64_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldInt32List22_"), 22, FieldType.INT32_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldFixed64List23_"), - 23, - FieldType.FIXED64_LIST, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldFixed32List24_"), - 24, - FieldType.FIXED32_LIST, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldBoolList25_"), 25, FieldType.BOOL_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldStringList26_"), 26, FieldType.STRING_LIST, true)); - builder.withField( - forRepeatedMessageField( - field(Proto3MessageLite.class, "fieldMessageList27_"), - 27, - FieldType.MESSAGE_LIST, - Proto3MessageLite.class)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldBytesList28_"), 28, FieldType.BYTES_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldUint32List29_"), 29, FieldType.UINT32_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldEnumList30_"), 30, FieldType.ENUM_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldSfixed32List31_"), - 31, - FieldType.SFIXED32_LIST, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldSfixed64List32_"), - 32, - FieldType.SFIXED64_LIST, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldSint32List33_"), 33, FieldType.SINT32_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldSint64List34_"), 34, FieldType.SINT64_LIST, true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldDoubleListPacked35_"), - 35, - FieldType.DOUBLE_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldFloatListPacked36_"), - 36, - FieldType.FLOAT_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldInt64ListPacked37_"), - 37, - FieldType.INT64_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldUint64ListPacked38_"), - 38, - FieldType.UINT64_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldInt32ListPacked39_"), - 39, - FieldType.INT32_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldFixed64ListPacked40_"), - 40, - FieldType.FIXED64_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldFixed32ListPacked41_"), - 41, - FieldType.FIXED32_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldBoolListPacked42_"), - 42, - FieldType.BOOL_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldUint32ListPacked43_"), - 43, - FieldType.UINT32_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldEnumListPacked44_"), - 44, - FieldType.ENUM_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldSfixed32ListPacked45_"), - 45, - FieldType.SFIXED32_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldSfixed64ListPacked46_"), - 46, - FieldType.SFIXED64_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldSint32ListPacked47_"), - 47, - FieldType.SINT32_LIST_PACKED, - true)); - builder.withField( - forField( - field(Proto3MessageLite.class, "fieldSint64ListPacked48_"), - 48, - FieldType.SINT64_LIST_PACKED, - true)); - - OneofInfo oneof = - new OneofInfo( - 0, - field(Proto3MessageLite.class, "testOneofCase_"), - field(Proto3MessageLite.class, "testOneof_")); - builder.withField(forOneofMemberField(53, FieldType.DOUBLE, oneof, Double.class, true, null)); - builder.withField(forOneofMemberField(54, FieldType.FLOAT, oneof, Float.class, true, null)); - builder.withField(forOneofMemberField(55, FieldType.INT64, oneof, Long.class, true, null)); - builder.withField(forOneofMemberField(56, FieldType.UINT64, oneof, Long.class, true, null)); - builder.withField(forOneofMemberField(57, FieldType.INT32, oneof, Integer.class, true, null)); - builder.withField(forOneofMemberField(58, FieldType.FIXED64, oneof, Long.class, true, null)); - builder.withField(forOneofMemberField(59, FieldType.FIXED32, oneof, Integer.class, true, null)); - builder.withField(forOneofMemberField(60, FieldType.BOOL, oneof, Boolean.class, true, null)); - builder.withField(forOneofMemberField(61, FieldType.STRING, oneof, String.class, true, null)); - builder.withField( - forOneofMemberField(62, FieldType.MESSAGE, oneof, Proto3MessageLite.class, true, null)); - builder.withField( - forOneofMemberField(63, FieldType.BYTES, oneof, ByteString.class, true, null)); - builder.withField(forOneofMemberField(64, FieldType.UINT32, oneof, Integer.class, true, null)); - builder.withField( - forOneofMemberField(65, FieldType.SFIXED32, oneof, Integer.class, true, null)); - builder.withField(forOneofMemberField(66, FieldType.SFIXED64, oneof, Long.class, true, null)); - builder.withField(forOneofMemberField(67, FieldType.SINT32, oneof, Integer.class, true, null)); - builder.withField(forOneofMemberField(68, FieldType.SINT64, oneof, Long.class, true, null)); - } - - private StructuralMessageInfo newMessageInfoForProto3EmptyLite() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO3); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForProto3MessageLiteWithMaps() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(); - builder.withSyntax(ProtoSyntax.PROTO2); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_bool_1", 1)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_bytes_2", 2)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_double_3", 3)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_enum_4", 4)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_fixed32_5", 5)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_fixed64_6", 6)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_float_7", 7)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_int32_8", 8)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_int64_9", 9)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_message_10", 10)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_sfixed32_11", 11)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_sfixed64_12", 12)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_sint32_13", 13)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_sint64_14", 14)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_string_15", 15)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_uint32_16", 16)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_bool_uint64_17", 17)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_bool_18", 18)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_bytes_19", 19)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_double_20", 20)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_enum_21", 21)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_fixed32_22", 22)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_fixed64_23", 23)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_float_24", 24)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_int32_25", 25)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_int64_26", 26)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_message_27", 27)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_sfixed32_28", 28)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_sfixed64_29", 29)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_sint32_30", 30)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_sint64_31", 31)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_string_32", 32)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_uint32_33", 33)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed32_uint64_34", 34)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_bool_35", 35)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_bytes_36", 36)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_double_37", 37)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_enum_38", 38)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_fixed32_39", 39)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_fixed64_40", 40)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_float_41", 41)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_int32_42", 42)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_int64_43", 43)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_message_44", 44)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_sfixed32_45", 45)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_sfixed64_46", 46)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_sint32_47", 47)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_sint64_48", 48)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_string_49", 49)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_uint32_50", 50)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_fixed64_uint64_51", 51)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_bool_52", 52)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_bytes_53", 53)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_double_54", 54)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_enum_55", 55)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_fixed32_56", 56)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_fixed64_57", 57)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_float_58", 58)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_int32_59", 59)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_int64_60", 60)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_message_61", 61)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_sfixed32_62", 62)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_sfixed64_63", 63)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_sint32_64", 64)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_sint64_65", 65)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_string_66", 66)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_uint32_67", 67)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int32_uint64_68", 68)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_bool_69", 69)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_bytes_70", 70)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_double_71", 71)); - builder.withField(mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_enum_72", 72)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_fixed32_73", 73)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_fixed64_74", 74)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_float_75", 75)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_int32_76", 76)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_int64_77", 77)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_message_78", 78)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_sfixed32_79", 79)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_sfixed64_80", 80)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_sint32_81", 81)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_sint64_82", 82)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_string_83", 83)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_uint32_84", 84)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_int64_uint64_85", 85)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_bool_86", 86)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_bytes_87", 87)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_double_88", 88)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_enum_89", 89)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_fixed32_90", 90)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_fixed64_91", 91)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_float_92", 92)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_int32_93", 93)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_int64_94", 94)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_message_95", 95)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_sfixed32_96", 96)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_sfixed64_97", 97)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_sint32_98", 98)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_sint64_99", 99)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_string_100", 100)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_uint32_101", 101)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed32_uint64_102", 102)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_bool_103", 103)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_bytes_104", 104)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_double_105", 105)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_enum_106", 106)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_fixed32_107", 107)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_fixed64_108", 108)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_float_109", 109)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_int32_110", 110)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_int64_111", 111)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_message_112", 112)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_sfixed32_113", 113)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_sfixed64_114", 114)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_sint32_115", 115)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_sint64_116", 116)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_string_117", 117)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_uint32_118", 118)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sfixed64_uint64_119", 119)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_bool_120", 120)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_bytes_121", 121)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_double_122", 122)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_enum_123", 123)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_fixed32_124", 124)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_fixed64_125", 125)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_float_126", 126)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_int32_127", 127)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_int64_128", 128)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_message_129", 129)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_sfixed32_130", 130)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_sfixed64_131", 131)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_sint32_132", 132)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_sint64_133", 133)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_string_134", 134)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_uint32_135", 135)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint32_uint64_136", 136)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_bool_137", 137)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_bytes_138", 138)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_double_139", 139)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_enum_140", 140)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_fixed32_141", 141)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_fixed64_142", 142)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_float_143", 143)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_int32_144", 144)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_int64_145", 145)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_message_146", 146)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_sfixed32_147", 147)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_sfixed64_148", 148)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_sint32_149", 149)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_sint64_150", 150)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_string_151", 151)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_uint32_152", 152)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_sint64_uint64_153", 153)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_bool_154", 154)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_bytes_155", 155)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_double_156", 156)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_enum_157", 157)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_fixed32_158", 158)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_fixed64_159", 159)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_float_160", 160)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_int32_161", 161)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_int64_162", 162)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_message_163", 163)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_sfixed32_164", 164)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_sfixed64_165", 165)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_sint32_166", 166)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_sint64_167", 167)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_string_168", 168)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_uint32_169", 169)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_string_uint64_170", 170)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_bool_171", 171)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_bytes_172", 172)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_double_173", 173)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_enum_174", 174)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_fixed32_175", 175)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_fixed64_176", 176)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_float_177", 177)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_int32_178", 178)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_int64_179", 179)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_message_180", 180)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_sfixed32_181", 181)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_sfixed64_182", 182)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_sint32_183", 183)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_sint64_184", 184)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_string_185", 185)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_uint32_186", 186)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint32_uint64_187", 187)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_bool_188", 188)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_bytes_189", 189)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_double_190", 190)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_enum_191", 191)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_fixed32_192", 192)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_fixed64_193", 193)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_float_194", 194)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_int32_195", 195)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_int64_196", 196)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_message_197", 197)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_sfixed32_198", 198)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_sfixed64_199", 199)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_sint32_200", 200)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_sint64_201", 201)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_string_202", 202)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_uint32_203", 203)); - builder.withField( - mapFieldInfo(Proto3MessageLiteWithMaps.class, "field_map_uint64_uint64_204", 204)); - - return builder.build(); - } - - private static Field field(Class clazz, String name) { - try { - return clazz.getDeclaredField(name); - } catch (NoSuchFieldException | SecurityException e) { - throw new RuntimeException(e); - } - } - - private static FieldInfo mapFieldInfo(Class clazz, String fieldName, int fieldNumber) { - try { - return forMapField( - field(clazz, SchemaUtil.toCamelCase(fieldName, false) + "_"), - fieldNumber, - SchemaUtil.getMapDefaultEntry(clazz, fieldName), - null); - } catch (Throwable t) { - throw new RuntimeException(t); - } - } -} diff --git a/java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java b/java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java deleted file mode 100644 index a17dda5c1f..0000000000 --- a/java/lite/src/test/java/com/google/protobuf/Proto2MessageLiteInfoFactory.java +++ /dev/null @@ -1,1332 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package com.google.protobuf; - -import static com.google.protobuf.FieldInfo.forField; -import static com.google.protobuf.FieldInfo.forFieldWithEnumVerifier; -import static com.google.protobuf.FieldInfo.forMapField; -import static com.google.protobuf.FieldInfo.forOneofMemberField; -import static com.google.protobuf.FieldInfo.forProto2OptionalField; -import static com.google.protobuf.FieldInfo.forProto2RequiredField; -import static com.google.protobuf.FieldInfo.forRepeatedMessageField; - -import com.google.protobuf.testing.Proto2TestingLite; -import com.google.protobuf.testing.Proto2TestingLite.Proto2EmptyLite; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLite; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLite.FieldGroup49; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLite.FieldGroup69; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLite.FieldGroupList51; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLite.FieldRequiredGroup88; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLite.RequiredNestedMessage; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLite.TestEnum; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLiteWithExtensions; -import com.google.protobuf.testing.Proto2TestingLite.Proto2MessageLiteWithMaps; -import java.lang.reflect.Field; - -/** A factory that generates a hard-coded info for {@link Proto2MessageLite}. */ -public final class Proto2MessageLiteInfoFactory implements MessageInfoFactory { - private static final Proto2MessageLiteInfoFactory instanceForRawMessageInfo = - new Proto2MessageLiteInfoFactory(true); - private static final Proto2MessageLiteInfoFactory instanceForStructuralMessageInfo = - new Proto2MessageLiteInfoFactory(false); - - public static Proto2MessageLiteInfoFactory getInstanceForRawMessageInfo() { - return instanceForRawMessageInfo; - } - - public static Proto2MessageLiteInfoFactory getInstanceForStructuralMessageInfo() { - return instanceForStructuralMessageInfo; - } - - private final boolean produceRawMessageInfo; - - private Proto2MessageLiteInfoFactory(boolean produceRawMessageInfo) { - this.produceRawMessageInfo = produceRawMessageInfo; - } - - @Override - public boolean isSupported(Class clazz) { - return true; - } - - @Override - public MessageInfo messageInfoFor(Class clazz) { - return produceRawMessageInfo ? rawMessageInfoFor(clazz) : structuralMessageInfoFor(clazz); - } - - private MessageInfo rawMessageInfoFor(Class clazz) { - if (Proto2MessageLite.class.isAssignableFrom(clazz)) { - return newRawMessageInfoForProto2MessageLite(); - } else { - throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); - } - } - - private MessageInfo newRawMessageInfoForProto2MessageLite() { - java.lang.Object[] objects = - new java.lang.Object[] { - "testOneof_", - "testOneofCase_", - "bitField0_", - "bitField1_", - "fieldDouble1_", - "fieldFloat2_", - "fieldInt643_", - "fieldUint644_", - "fieldInt325_", - "fieldFixed646_", - "fieldFixed327_", - "fieldBool8_", - "fieldString9_", - "fieldMessage10_", - "fieldBytes11_", - "fieldUint3212_", - "fieldEnum13_", - Proto2MessageLite.TestEnum.internalGetVerifier(), - "fieldSfixed3214_", - "fieldSfixed6415_", - "fieldSint3216_", - "fieldSint6417_", - "fieldDoubleList18_", - "fieldFloatList19_", - "fieldInt64List20_", - "fieldUint64List21_", - "fieldInt32List22_", - "fieldFixed64List23_", - "fieldFixed32List24_", - "fieldBoolList25_", - "fieldStringList26_", - "fieldMessageList27_", - Proto2MessageLite.class, - "fieldBytesList28_", - "fieldUint32List29_", - "fieldEnumList30_", - Proto2MessageLite.TestEnum.internalGetVerifier(), - "fieldSfixed32List31_", - "fieldSfixed64List32_", - "fieldSint32List33_", - "fieldSint64List34_", - "fieldDoubleListPacked35_", - "fieldFloatListPacked36_", - "fieldInt64ListPacked37_", - "fieldUint64ListPacked38_", - "fieldInt32ListPacked39_", - "fieldFixed64ListPacked40_", - "fieldFixed32ListPacked41_", - "fieldBoolListPacked42_", - "fieldUint32ListPacked43_", - "fieldEnumListPacked44_", - Proto2MessageLite.TestEnum.internalGetVerifier(), - "fieldSfixed32ListPacked45_", - "fieldSfixed64ListPacked46_", - "fieldSint32ListPacked47_", - "fieldSint64ListPacked48_", - "fieldGroup49_", - "fieldGroupList51_", - Proto2MessageLite.FieldGroupList51.class, - Proto2MessageLite.class, - Proto2MessageLite.FieldGroup69.class, - "fieldRequiredDouble71_", - "fieldRequiredFloat72_", - "fieldRequiredInt6473_", - "fieldRequiredUint6474_", - "fieldRequiredInt3275_", - "fieldRequiredFixed6476_", - "fieldRequiredFixed3277_", - "fieldRequiredBool78_", - "fieldRequiredString79_", - "fieldRequiredMessage80_", - "fieldRequiredBytes81_", - "fieldRequiredUint3282_", - "fieldRequiredEnum83_", - Proto2MessageLite.TestEnum.internalGetVerifier(), - "fieldRequiredSfixed3284_", - "fieldRequiredSfixed6485_", - "fieldRequiredSint3286_", - "fieldRequiredSint6487_", - "fieldRequiredGroup88_", - }; - // To update this after a proto change, run blaze build on proto2_message_lite.proto and copy - // over the String info from the proto2_message_lite_proto-lite-src.jar file in the - // blaze-genfiles directory. - java.lang.String info = - "\u0001U\u0001\u0002\u0001XU\u0000 \u0015\u0001\u1000\u0000\u0002\u1001\u0001\u0003" - + "\u1002\u0002\u0004\u1003\u0003\u0005\u1004\u0004\u0006\u1005\u0005\u0007\u1006\u0006\b\u1007\u0007" - + "\t\u1008\b\n" - + "\u1409\t\u000b\u100a\n" - + "\f\u100b\u000b\r" - + "\u100c\f\u000e\u100d\r" - + "\u000f\u100e\u000e\u0010\u100f\u000f\u0011\u1010\u0010\u0012\u0012\u0013\u0013" - + "\u0014\u0014\u0015\u0015\u0016\u0016\u0017\u0017\u0018\u0018\u0019\u0019\u001a\u001a\u001b\u041b\u001c\u001c\u001d\u001d\u001e\u001e\u001f\u001f" - + " !!\"\"##$$%%&&\'\'" - + "(())**++,,--..//001\u1011\u0011315\u1033\u00006\u1034\u00007\u1035\u00008\u1036\u0000" - + "9\u1037\u0000:\u1038\u0000;\u1039\u0000<\u103a\u0000=\u103b\u0000>\u143c\u0000?\u103d" - + "\u0000@\u103e\u0000A\u1040\u0000B\u1041\u0000C\u1042\u0000D\u1043\u0000E\u1044\u0000" - + "G\u1500#H\u1501$I\u1502%J\u1503&K\u1504\'L\u1505(M\u1506)N\u1507*O\u1508+P\u1509" - + ",Q\u150a-R\u150b.S\u150c/T\u150d0U\u150e1V\u150f2W\u15103X\u15114"; - return new RawMessageInfo(Proto2MessageLite.getDefaultInstance(), info, objects); - } - - private MessageInfo structuralMessageInfoFor(Class clazz) { - if (Proto2MessageLite.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto2MessageLite(); - } else if (FieldGroup49.class.isAssignableFrom(clazz)) { - return newMessageInfoForFieldGroup49(); - } else if (FieldGroupList51.class.isAssignableFrom(clazz)) { - return newMessageInfoForFieldGroupList51(); - } else if (FieldGroup69.class.isAssignableFrom(clazz)) { - return newMessageInfoForFieldGroup69(); - } else if (FieldRequiredGroup88.class.isAssignableFrom(clazz)) { - return newMessageInfoForFieldRequiredGroup88(); - } else if (RequiredNestedMessage.class.isAssignableFrom(clazz)) { - return newMessageInfoForRequiredNestedMessage(); - } else if (Proto2EmptyLite.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto2EmptyLite(); - } else if (Proto2MessageLiteWithExtensions.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto2MessageLiteWithExtensions(); - } else if (Proto2TestingLite.FieldGroup49.class.isAssignableFrom(clazz)) { - return newMessageInfoForExtensionFieldGroup49(); - } else if (Proto2TestingLite.FieldGroupList51.class.isAssignableFrom(clazz)) { - return newMessageInfoForExtensionFieldGroupList51(); - } else if (Proto2TestingLite.Proto2MessageLiteWithMaps.class.isAssignableFrom(clazz)) { - return newMessageInfoForProto2MessageLiteWithMaps(); - } else { - throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); - } - } - - /** - * Creates a new hard-coded info for {@link Proto2MessageLite}. Each time this is called, we - * manually go through the entire process of what a message would do if it self-registered its own - * info, including looking up each field by name. This is done for benchmarking purposes, so that - * we get a more accurate representation of the time it takes to perform this process. - */ - private static StructuralMessageInfo newMessageInfoForProto2MessageLite() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(48); - builder.withCheckInitialized( - new int[] { - 10, 27, 62, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, - }); - lookupFieldsByName(builder); - return builder.build(); - } - - private static void lookupFieldsByName(StructuralMessageInfo.Builder builder) { - Field bitField0 = field(Proto2MessageLite.class, "bitField0_"); - - builder.withDefaultInstance(Proto2MessageLite.getDefaultInstance()); - builder.withSyntax(ProtoSyntax.PROTO2); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldDouble1_"), - 1, - FieldType.DOUBLE, - bitField0, - 0x00000001, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldFloat2_"), - 2, - FieldType.FLOAT, - bitField0, - 0x00000002, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldInt643_"), - 3, - FieldType.INT64, - bitField0, - 0x00000004, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldUint644_"), - 4, - FieldType.UINT64, - bitField0, - 0x00000008, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldInt325_"), - 5, - FieldType.INT32, - bitField0, - 0x00000010, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldFixed646_"), - 6, - FieldType.FIXED64, - bitField0, - 0x00000020, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldFixed327_"), - 7, - FieldType.FIXED32, - bitField0, - 0x00000040, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldBool8_"), - 8, - FieldType.BOOL, - bitField0, - 0x00000080, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldString9_"), - 9, - FieldType.STRING, - bitField0, - 0x00000100, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldMessage10_"), - 10, - FieldType.MESSAGE, - bitField0, - 0x00000200, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldBytes11_"), - 11, - FieldType.BYTES, - bitField0, - 0x00000400, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldUint3212_"), - 12, - FieldType.UINT32, - bitField0, - 0x00000800, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldEnum13_"), - 13, - FieldType.ENUM, - bitField0, - 0x00001000, - false, - TestEnum.internalGetVerifier())); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldSfixed3214_"), - 14, - FieldType.SFIXED32, - bitField0, - 0x00002000, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldSfixed6415_"), - 15, - FieldType.SFIXED64, - bitField0, - 0x00004000, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldSint3216_"), - 16, - FieldType.SINT32, - bitField0, - 0x00008000, - false, - null)); - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldSint6417_"), - 17, - FieldType.SINT64, - bitField0, - 0x00010000, - false, - null)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldDoubleList18_"), - 18, - FieldType.DOUBLE_LIST, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldFloatList19_"), 19, FieldType.FLOAT_LIST, false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldInt64List20_"), 20, FieldType.INT64_LIST, false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldUint64List21_"), - 21, - FieldType.UINT64_LIST, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldInt32List22_"), 22, FieldType.INT32_LIST, false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldFixed64List23_"), - 23, - FieldType.FIXED64_LIST, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldFixed32List24_"), - 24, - FieldType.FIXED32_LIST, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldBoolList25_"), 25, FieldType.BOOL_LIST, false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldStringList26_"), - 26, - FieldType.STRING_LIST, - false)); - builder.withField( - forRepeatedMessageField( - field(Proto2MessageLite.class, "fieldMessageList27_"), - 27, - FieldType.MESSAGE_LIST, - Proto2MessageLite.class)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldBytesList28_"), 28, FieldType.BYTES_LIST, false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldUint32List29_"), - 29, - FieldType.UINT32_LIST, - false)); - builder.withField( - forFieldWithEnumVerifier( - field(Proto2MessageLite.class, "fieldEnumList30_"), - 30, - FieldType.ENUM_LIST, - TestEnum.internalGetVerifier())); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldSfixed32List31_"), - 31, - FieldType.SFIXED32_LIST, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldSfixed64List32_"), - 32, - FieldType.SFIXED64_LIST, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldSint32List33_"), - 33, - FieldType.SINT32_LIST, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldSint64List34_"), - 34, - FieldType.SINT64_LIST, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldDoubleListPacked35_"), - 35, - FieldType.DOUBLE_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldFloatListPacked36_"), - 36, - FieldType.FLOAT_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldInt64ListPacked37_"), - 37, - FieldType.INT64_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldUint64ListPacked38_"), - 38, - FieldType.UINT64_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldInt32ListPacked39_"), - 39, - FieldType.INT32_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldFixed64ListPacked40_"), - 40, - FieldType.FIXED64_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldFixed32ListPacked41_"), - 41, - FieldType.FIXED32_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldBoolListPacked42_"), - 42, - FieldType.BOOL_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldUint32ListPacked43_"), - 43, - FieldType.UINT32_LIST_PACKED, - false)); - builder.withField( - forFieldWithEnumVerifier( - field(Proto2MessageLite.class, "fieldEnumListPacked44_"), - 44, - FieldType.ENUM_LIST_PACKED, - TestEnum.internalGetVerifier())); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldSfixed32ListPacked45_"), - 45, - FieldType.SFIXED32_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldSfixed64ListPacked46_"), - 46, - FieldType.SFIXED64_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldSint32ListPacked47_"), - 47, - FieldType.SINT32_LIST_PACKED, - false)); - builder.withField( - forField( - field(Proto2MessageLite.class, "fieldSint64ListPacked48_"), - 48, - FieldType.SINT64_LIST_PACKED, - false)); - - builder.withField( - forProto2OptionalField( - field(Proto2MessageLite.class, "fieldGroup49_"), - 49, - FieldType.GROUP, - bitField0, - 0x00020000, - false, - null)); - builder.withField( - forRepeatedMessageField( - field(Proto2MessageLite.class, "fieldGroupList51_"), - 51, - FieldType.GROUP_LIST, - Proto2MessageLite.FieldGroupList51.class)); - - OneofInfo oneof = - new OneofInfo( - 0, - field(Proto2MessageLite.class, "testOneofCase_"), - field(Proto2MessageLite.class, "testOneof_")); - builder.withField(forOneofMemberField(53, FieldType.DOUBLE, oneof, Double.class, false, null)); - builder.withField(forOneofMemberField(54, FieldType.FLOAT, oneof, Float.class, false, null)); - builder.withField(forOneofMemberField(55, FieldType.INT64, oneof, Long.class, false, null)); - builder.withField(forOneofMemberField(56, FieldType.UINT64, oneof, Long.class, false, null)); - builder.withField(forOneofMemberField(57, FieldType.INT32, oneof, Integer.class, false, null)); - builder.withField(forOneofMemberField(58, FieldType.FIXED64, oneof, Long.class, false, null)); - builder.withField( - forOneofMemberField(59, FieldType.FIXED32, oneof, Integer.class, false, null)); - builder.withField(forOneofMemberField(60, FieldType.BOOL, oneof, Boolean.class, false, null)); - builder.withField(forOneofMemberField(61, FieldType.STRING, oneof, String.class, false, null)); - builder.withField( - forOneofMemberField(62, FieldType.MESSAGE, oneof, Proto2MessageLite.class, false, null)); - builder.withField( - forOneofMemberField(63, FieldType.BYTES, oneof, ByteString.class, false, null)); - builder.withField(forOneofMemberField(64, FieldType.UINT32, oneof, Integer.class, false, null)); - builder.withField( - forOneofMemberField(65, FieldType.SFIXED32, oneof, Integer.class, false, null)); - builder.withField(forOneofMemberField(66, FieldType.SFIXED64, oneof, Long.class, false, null)); - builder.withField(forOneofMemberField(67, FieldType.SINT32, oneof, Integer.class, false, null)); - builder.withField(forOneofMemberField(68, FieldType.SINT64, oneof, Long.class, false, null)); - builder.withField( - forOneofMemberField( - 69, FieldType.GROUP, oneof, Proto2MessageLite.FieldGroup69.class, false, null)); - - Field bitField1 = field(Proto2MessageLite.class, "bitField1_"); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredDouble71_"), - 71, - FieldType.DOUBLE, - bitField1, - 0x00000008, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredFloat72_"), - 72, - FieldType.FLOAT, - bitField1, - 0x00000010, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredInt6473_"), - 73, - FieldType.INT64, - bitField1, - 0x00000020, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredUint6474_"), - 74, - FieldType.UINT64, - bitField1, - 0x00000040, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredInt3275_"), - 75, - FieldType.INT32, - bitField1, - 0x00000080, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredFixed6476_"), - 76, - FieldType.FIXED64, - bitField1, - 0x00000100, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredFixed3277_"), - 77, - FieldType.FIXED32, - bitField1, - 0x00000200, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredBool78_"), - 78, - FieldType.BOOL, - bitField1, - 0x00000400, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredString79_"), - 79, - FieldType.STRING, - bitField1, - 0x00000800, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredMessage80_"), - 80, - FieldType.MESSAGE, - bitField1, - 0x00001000, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredBytes81_"), - 81, - FieldType.BYTES, - bitField1, - 0x00002000, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredUint3282_"), - 82, - FieldType.UINT32, - bitField1, - 0x00004000, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredEnum83_"), - 83, - FieldType.ENUM, - bitField1, - 0x00008000, - false, - TestEnum.internalGetVerifier())); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredSfixed3284_"), - 84, - FieldType.SFIXED32, - bitField1, - 0x00010000, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredSfixed6485_"), - 85, - FieldType.SFIXED64, - bitField1, - 0x00020000, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredSint3286_"), - 86, - FieldType.SINT32, - bitField1, - 0x00040000, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredSint6487_"), - 87, - FieldType.SINT64, - bitField1, - 0x00080000, - false, - null)); - builder.withField( - forProto2RequiredField( - field(Proto2MessageLite.class, "fieldRequiredGroup88_"), - 88, - FieldType.GROUP, - bitField1, - 0x00100000, - false, - null)); - } - - private static StructuralMessageInfo newMessageInfoForFieldGroup49() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(FieldGroup49.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(FieldGroup49.class, "fieldInt3250_"), - 50, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForFieldGroupList51() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(FieldGroup49.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(FieldGroupList51.class, "fieldInt3252_"), - 52, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForFieldGroup69() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(FieldGroup69.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(FieldGroup69.class, "fieldInt3270_"), - 70, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForRequiredNestedMessage() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(RequiredNestedMessage.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(RequiredNestedMessage.class, "value_"), - 1, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForFieldRequiredGroup88() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(FieldRequiredGroup88.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(FieldRequiredGroup88.class, "fieldInt3289_"), - 89, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForProto2EmptyLite() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForProto2MessageLiteWithExtensions() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(0); - builder.withSyntax(ProtoSyntax.PROTO2); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForExtensionFieldGroup49() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(Proto2TestingLite.FieldGroup49.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(Proto2TestingLite.FieldGroup49.class, "fieldInt3250_"), - 50, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - private static StructuralMessageInfo newMessageInfoForExtensionFieldGroupList51() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(1); - builder.withSyntax(ProtoSyntax.PROTO2); - Field bitField0 = field(Proto2TestingLite.FieldGroup49.class, "bitField0_"); - builder.withField( - forProto2OptionalField( - field(Proto2TestingLite.FieldGroupList51.class, "fieldInt3252_"), - 52, - FieldType.INT32, - bitField0, - 0x00000001, - false, - null)); - return builder.build(); - } - - - private static StructuralMessageInfo newMessageInfoForProto2MessageLiteWithMaps() { - StructuralMessageInfo.Builder builder = StructuralMessageInfo.newBuilder(); - builder.withCheckInitialized( - new int[] { - 10, 27, 44, 61, 78, 95, 112, 129, 146, 163, 180, 197, - }); - builder.withSyntax(ProtoSyntax.PROTO2); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_bool_1", 1)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_bytes_2", 2)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_double_3", 3)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_enum_4", 4)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_fixed32_5", 5)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_fixed64_6", 6)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_float_7", 7)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_int32_8", 8)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_int64_9", 9)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_message_10", 10)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_sfixed32_11", 11)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_sfixed64_12", 12)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_sint32_13", 13)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_sint64_14", 14)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_string_15", 15)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_uint32_16", 16)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_bool_uint64_17", 17)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_bool_18", 18)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_bytes_19", 19)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_double_20", 20)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_enum_21", 21)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_fixed32_22", 22)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_fixed64_23", 23)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_float_24", 24)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_int32_25", 25)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_int64_26", 26)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_message_27", 27)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_sfixed32_28", 28)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_sfixed64_29", 29)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_sint32_30", 30)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_sint64_31", 31)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_string_32", 32)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_uint32_33", 33)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed32_uint64_34", 34)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_bool_35", 35)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_bytes_36", 36)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_double_37", 37)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_enum_38", 38)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_fixed32_39", 39)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_fixed64_40", 40)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_float_41", 41)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_int32_42", 42)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_int64_43", 43)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_message_44", 44)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_sfixed32_45", 45)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_sfixed64_46", 46)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_sint32_47", 47)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_sint64_48", 48)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_string_49", 49)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_uint32_50", 50)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_fixed64_uint64_51", 51)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_bool_52", 52)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_bytes_53", 53)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_double_54", 54)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_enum_55", 55)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_fixed32_56", 56)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_fixed64_57", 57)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_float_58", 58)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_int32_59", 59)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_int64_60", 60)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_message_61", 61)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_sfixed32_62", 62)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_sfixed64_63", 63)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_sint32_64", 64)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_sint64_65", 65)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_string_66", 66)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_uint32_67", 67)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int32_uint64_68", 68)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_bool_69", 69)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_bytes_70", 70)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_double_71", 71)); - builder.withField(mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_enum_72", 72)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_fixed32_73", 73)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_fixed64_74", 74)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_float_75", 75)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_int32_76", 76)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_int64_77", 77)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_message_78", 78)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_sfixed32_79", 79)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_sfixed64_80", 80)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_sint32_81", 81)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_sint64_82", 82)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_string_83", 83)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_uint32_84", 84)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_int64_uint64_85", 85)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_bool_86", 86)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_bytes_87", 87)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_double_88", 88)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_enum_89", 89)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_fixed32_90", 90)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_fixed64_91", 91)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_float_92", 92)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_int32_93", 93)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_int64_94", 94)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_message_95", 95)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_sfixed32_96", 96)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_sfixed64_97", 97)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_sint32_98", 98)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_sint64_99", 99)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_string_100", 100)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_uint32_101", 101)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed32_uint64_102", 102)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_bool_103", 103)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_bytes_104", 104)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_double_105", 105)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_enum_106", 106)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_fixed32_107", 107)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_fixed64_108", 108)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_float_109", 109)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_int32_110", 110)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_int64_111", 111)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_message_112", 112)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_sfixed32_113", 113)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_sfixed64_114", 114)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_sint32_115", 115)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_sint64_116", 116)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_string_117", 117)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_uint32_118", 118)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sfixed64_uint64_119", 119)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_bool_120", 120)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_bytes_121", 121)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_double_122", 122)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_enum_123", 123)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_fixed32_124", 124)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_fixed64_125", 125)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_float_126", 126)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_int32_127", 127)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_int64_128", 128)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_message_129", 129)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_sfixed32_130", 130)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_sfixed64_131", 131)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_sint32_132", 132)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_sint64_133", 133)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_string_134", 134)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_uint32_135", 135)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint32_uint64_136", 136)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_bool_137", 137)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_bytes_138", 138)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_double_139", 139)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_enum_140", 140)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_fixed32_141", 141)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_fixed64_142", 142)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_float_143", 143)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_int32_144", 144)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_int64_145", 145)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_message_146", 146)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_sfixed32_147", 147)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_sfixed64_148", 148)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_sint32_149", 149)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_sint64_150", 150)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_string_151", 151)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_uint32_152", 152)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_sint64_uint64_153", 153)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_bool_154", 154)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_bytes_155", 155)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_double_156", 156)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_enum_157", 157)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_fixed32_158", 158)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_fixed64_159", 159)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_float_160", 160)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_int32_161", 161)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_int64_162", 162)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_message_163", 163)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_sfixed32_164", 164)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_sfixed64_165", 165)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_sint32_166", 166)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_sint64_167", 167)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_string_168", 168)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_uint32_169", 169)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_string_uint64_170", 170)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_bool_171", 171)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_bytes_172", 172)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_double_173", 173)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_enum_174", 174)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_fixed32_175", 175)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_fixed64_176", 176)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_float_177", 177)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_int32_178", 178)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_int64_179", 179)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_message_180", 180)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_sfixed32_181", 181)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_sfixed64_182", 182)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_sint32_183", 183)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_sint64_184", 184)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_string_185", 185)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_uint32_186", 186)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint32_uint64_187", 187)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_bool_188", 188)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_bytes_189", 189)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_double_190", 190)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_enum_191", 191)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_fixed32_192", 192)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_fixed64_193", 193)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_float_194", 194)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_int32_195", 195)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_int64_196", 196)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_message_197", 197)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_sfixed32_198", 198)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_sfixed64_199", 199)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_sint32_200", 200)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_sint64_201", 201)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_string_202", 202)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_uint32_203", 203)); - builder.withField( - mapFieldInfo(Proto2MessageLiteWithMaps.class, "field_map_uint64_uint64_204", 204)); - - return builder.build(); - } - - private static Field field(Class clazz, String name) { - try { - return clazz.getDeclaredField(name); - } catch (NoSuchFieldException | SecurityException e) { - throw new RuntimeException(e); - } - } - - private static FieldInfo mapFieldInfo(Class clazz, String fieldName, int fieldNumber) { - try { - return forMapField( - field(clazz, SchemaUtil.toCamelCase(fieldName, false) + "_"), - fieldNumber, - SchemaUtil.getMapDefaultEntry(clazz, fieldName), - fieldName.contains("_enum_") ? TestEnum.internalGetVerifier() : null); - } catch (Throwable t) { - throw new RuntimeException(t); - } - } -} From dfd99e7ec037cec1161c880f0bb2032033d181cf Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 12 Jan 2022 21:54:30 +0000 Subject: [PATCH 132/207] Adding kotlin bazel tests --- BUILD | 162 +++++++- WORKSPACE | 15 + java/BUILD | 5 +- java/core/BUILD | 2 + java/kotlin-lite/BUILD | 169 ++++++++ .../generate-test-sources-build.xml | 4 +- java/kotlin-lite/pom.xml | 4 +- java/kotlin-lite/pom_template.xml | 22 ++ .../ExtendableMessageLiteExtensions.kt | 0 .../com/google/protobuf/Proto3LiteTest.kt | 365 ++++++++++++++++++ .../google/protobuf/evil_names_proto2.proto | 93 +++++ .../google/protobuf/evil_names_proto3.proto | 107 +++++ .../protobuf/multiple_files_proto3.proto | 42 ++ java/kotlin/BUILD | 278 +++++++++++++ java/kotlin/pom.xml | 4 +- java/kotlin/pom_template.xml | 23 ++ maven_install.json | 52 ++- protobuf_deps.bzl | 1 + 18 files changed, 1327 insertions(+), 21 deletions(-) create mode 100644 java/kotlin-lite/BUILD create mode 100644 java/kotlin-lite/pom_template.xml rename java/{kotlin => kotlin-lite}/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt (100%) create mode 100644 java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto3LiteTest.kt create mode 100644 java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto2.proto create mode 100644 java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto3.proto create mode 100644 java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto create mode 100644 java/kotlin/BUILD create mode 100644 java/kotlin/pom_template.xml diff --git a/BUILD b/BUILD index 45a64abc9a..738034ede6 100644 --- a/BUILD +++ b/BUILD @@ -656,6 +656,8 @@ RELATIVE_TEST_PROTOS = [ TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS] GENERIC_RELATIVE_TEST_PROTOS = [ + "google/protobuf/map_proto2_unittest.proto", + "google/protobuf/map_unittest.proto", "google/protobuf/unittest.proto", "google/protobuf/unittest_arena.proto", "google/protobuf/unittest_custom_options.proto", @@ -1182,7 +1184,7 @@ proto_library( name = "generated_protos_proto", srcs = [ "src/google/protobuf/unittest_import_public.proto", - "unittest_gen.proto", + "unittest_gen_import.proto", ], ) @@ -1190,7 +1192,7 @@ py_proto_library( name = "generated_protos_py", srcs = [ "src/google/protobuf/unittest_import_public.proto", - "unittest_gen.proto", + "unittest_gen_import.proto", ], default_runtime = "", protoc = ":protoc", @@ -1320,6 +1322,19 @@ cc_binary( # ], # ) + +java_proto_library( + name = "java_test_protos", + deps = [":generic_test_protos"], + visibility = ["//visibility:public"], +) + +java_lite_proto_library( + name = "java_lite_test_protos", + deps = [":generic_test_protos"], + visibility = ["//visibility:public"], +) + java_proto_library( name = "test_messages_proto2_java_proto", visibility = [ @@ -1413,3 +1428,146 @@ filegroup( srcs = glob(["**/*.bzl"]), visibility = ["//visibility:public"], ) + +# Kotlin proto rules + +genrule( + name = "gen_kotlin_unittest_lite", + srcs = [ + "src/google/protobuf/unittest_lite.proto", + "src/google/protobuf/unittest_import_lite.proto", + "src/google/protobuf/unittest_import_public_lite.proto", + "src/google/protobuf/map_lite_unittest.proto", + ], + outs = [ + "TestAllTypesLiteKt.kt", + "ForeignMessageLiteKt.kt", + "TestAllExtensionsLiteKt.kt", + "TestEmptyMessageLiteKt.kt", + "TestEmptyMessageWithExtensionsLiteKt.kt", + "TestMapLiteKt.kt", + "OptionalGroup_extension_liteKt.kt", + "RepeatedGroup_extension_liteKt.kt", + ], + visibility = ["//visibility:public"], + cmd = "$(location //:protoc) " + + "--kotlin_out=lite:$(@D) -Isrc/ " + + "$(locations src/google/protobuf/unittest_lite.proto) && " + + "$(location //:protoc) " + + "--kotlin_out=lite:$(@D) -Isrc/ " + + "$(locations src/google/protobuf/map_lite_unittest.proto) && " + + "cp $(@D)/com/google/protobuf/TestAllTypesLiteKt.kt " + + "$(location TestAllTypesLiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/ForeignMessageLiteKt.kt " + + "$(location ForeignMessageLiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/TestAllExtensionsLiteKt.kt " + + "$(location TestAllExtensionsLiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/TestAllTypesLiteKt.kt " + + "$(location TestAllTypesLiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/TestEmptyMessageLiteKt.kt " + + "$(location TestEmptyMessageLiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/TestEmptyMessageWithExtensionsLiteKt.kt " + + "$(location TestEmptyMessageWithExtensionsLiteKt.kt) && " + + "cp $(@D)/protobuf_unittest/TestMapLiteKt.kt " + + "$(location TestMapLiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/OptionalGroup_extension_liteKt.kt " + + "$(location OptionalGroup_extension_liteKt.kt) && " + + "cp $(@D)/com/google/protobuf/RepeatedGroup_extension_liteKt.kt " + + "$(location RepeatedGroup_extension_liteKt.kt)", + tools = [":protoc"], +) + +genrule( + name = "gen_kotlin_unittest", + srcs = [ + "src/google/protobuf/unittest.proto", + "src/google/protobuf/unittest_import.proto", + "src/google/protobuf/unittest_import_public.proto", + "src/google/protobuf/map_proto2_unittest.proto", + ], + outs = [ + "TestAllTypesKt.kt", + "ForeignMessageKt.kt", + "TestAllExtensionsKt.kt", + "TestEmptyMessageKt.kt", + "TestEmptyMessageWithExtensionsKt.kt", + "TestIntIntMapKt.kt", + "TestEnumMapKt.kt", + "TestMapsKt.kt", + "OptionalGroup_extensionKt.kt", + "RepeatedGroup_extensionKt.kt", + ], + visibility = ["//visibility:public"], + cmd = "$(location //:protoc) " + + "--kotlin_out=shared,immutable:$(@D) -Isrc/ " + + "$(location src/google/protobuf/unittest.proto) && " + + "$(location //:protoc) " + + "--kotlin_out=shared,immutable:$(@D) -Isrc/ " + + "$(location src/google/protobuf/map_proto2_unittest.proto) && " + + "cp $(@D)/protobuf_unittest/TestAllTypesKt.kt " + + "$(location TestAllTypesKt.kt) && " + + "cp $(@D)/protobuf_unittest/ForeignMessageKt.kt " + + "$(location ForeignMessageKt.kt) && " + + "cp $(@D)/protobuf_unittest/TestAllExtensionsKt.kt " + + "$(location TestAllExtensionsKt.kt) && " + + "cp $(@D)/protobuf_unittest/TestEmptyMessageKt.kt " + + "$(location TestEmptyMessageKt.kt) && " + + "cp $(@D)/protobuf_unittest/TestEmptyMessageWithExtensionsKt.kt " + + "$(location TestEmptyMessageWithExtensionsKt.kt) && " + + "cp $(@D)/protobuf_unittest/TestIntIntMapKt.kt " + + "$(location TestIntIntMapKt.kt) && " + + "cp $(@D)/protobuf_unittest/TestEnumMapKt.kt " + + "$(location TestEnumMapKt.kt) && " + + "cp $(@D)/protobuf_unittest/TestMapsKt.kt " + + "$(location TestMapsKt.kt) && " + + "cp $(@D)/protobuf_unittest/OptionalGroup_extensionKt.kt " + + "$(location OptionalGroup_extensionKt.kt) && " + + "cp $(@D)/protobuf_unittest/RepeatedGroup_extensionKt.kt " + + "$(location RepeatedGroup_extensionKt.kt)", + tools = ["//:protoc"], +) + +genrule( + name = "gen_kotlin_proto3_unittest_lite", + srcs = [ + "src/google/protobuf/unittest_proto3_lite.proto", + "src/google/protobuf/unittest_import.proto", + "src/google/protobuf/unittest_import_public.proto", + ], + outs = [ + "TestAllTypesProto3LiteKt.kt", + "TestEmptyMessageProto3LiteKt.kt", + ], + visibility = ["//visibility:public"], + cmd = "$(location //:protoc) " + + "--kotlin_out=lite:$(@D) -Isrc/ " + + "$(location src/google/protobuf/unittest_proto3_lite.proto) && " + + "cp $(@D)/proto3_lite_unittest/TestAllTypesKt.kt " + + "$(location TestAllTypesProto3LiteKt.kt) && " + + "cp $(@D)/proto3_lite_unittest/TestEmptyMessageKt.kt " + + "$(location TestEmptyMessageProto3LiteKt.kt)", + tools = ["//:protoc"], +) + +genrule( + name = "gen_kotlin_proto3_unittest", + srcs = [ + "src/google/protobuf/unittest_proto3.proto", + "src/google/protobuf/unittest_import.proto", + "src/google/protobuf/unittest_import_public.proto", + ], + outs = [ + "TestAllTypesProto3Kt.kt", + "TestEmptyMessageProto3Kt.kt", + ], + visibility = ["//visibility:public"], + cmd = "$(location //:protoc) " + + "--kotlin_out=shared,immutable:$(@D) -Isrc/ " + + "$(location src/google/protobuf/unittest_proto3.proto) && " + + "cp $(@D)/proto3_unittest/TestAllTypesKt.kt " + + "$(location TestAllTypesProto3Kt.kt) && " + + "cp $(@D)/proto3_unittest/TestEmptyMessageKt.kt " + + "$(location TestEmptyMessageProto3Kt.kt)", + tools = ["//:protoc"], +) + diff --git a/WORKSPACE b/WORKSPACE index 8104dccaf1..5778a58680 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -59,3 +59,18 @@ bazel_skylib_workspace() load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies() + +# For `kt_jvm_library` +rules_kotlin_version = "v1.5.0-beta-4" +rules_kotlin_sha = "6cbd4e5768bdfae1598662e40272729ec9ece8b7bded8f0d2c81c8ff96dc139d" +http_archive( + name = "io_bazel_rules_kotlin", + urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % rules_kotlin_version], + sha256 = rules_kotlin_sha, +) + +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") +kotlin_repositories() + +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") +kt_register_toolchains() diff --git a/java/BUILD b/java/BUILD index e12d472d8c..7a244d8f88 100644 --- a/java/BUILD +++ b/java/BUILD @@ -2,6 +2,8 @@ test_suite( name = "tests", tests = [ "//java/core:tests", + "//java/kotlin:tests", + "//java/kotlin-lite:tests", "//java/lite:tests", "//java/util:tests", ], @@ -11,6 +13,7 @@ filegroup( name = "release", srcs = [ "//java/core:release", # contains lite. + "//java/kotlin:release", # contains kotlin lite. "//java/util:release", ] -) \ No newline at end of file +) diff --git a/java/core/BUILD b/java/core/BUILD index aa7ba62155..a698fc8e36 100644 --- a/java/core/BUILD +++ b/java/core/BUILD @@ -231,6 +231,7 @@ java_library( "@maven//:com_google_guava_guava", "@maven//:junit_junit", ], + visibility = ["//java:__subpackages__"], ) test_suite( @@ -334,6 +335,7 @@ java_library( ], visibility = [ "//java/lite:__pkg__", + "//java/kotlin-lite:__pkg__", ], deps = [ ":generic_test_protos_java_proto_lite", diff --git a/java/kotlin-lite/BUILD b/java/kotlin-lite/BUILD new file mode 100644 index 0000000000..c9dab1d2de --- /dev/null +++ b/java/kotlin-lite/BUILD @@ -0,0 +1,169 @@ +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test") +load("@rules_java//java:defs.bzl", "java_lite_proto_library") + +java_lite_proto_library( + name = "example_extensible_message_java_proto_lite", + deps = ["//java/kotlin:example_extensible_message_proto"], +) + +kt_jvm_library( + name = "lite_extensions", + srcs = ["src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt"], + deps = ["//java/lite"], +) + +test_suite( + name = "tests", + tests = [ + "test_lite_extensions", + "proto2_test_lite", + "proto3_test_lite", + ], +) + +kt_jvm_test( + name = "test_lite_extensions", + srcs = ["src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt"], + deps = [ + ":example_extensible_message_java_proto_lite", + ":lite_extensions", + "//java/lite", + "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", + "//java/kotlin:shared_runtime", + "@com_github_jetbrains_kotlin//:kotlin-test", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], + test_class = "com.google.protobuf.kotlin.ExtendableMessageLiteExtensionsTest", +) + +java_lite_proto_library( + name = "evil_names_proto2_java_proto_lite", + deps = ["//java/kotlin:evil_names_proto2"], +) + +java_lite_proto_library( + name = "evil_names_proto3_java_proto_lite", + deps = ["//java/kotlin:evil_names_proto3"], +) + +java_lite_proto_library( + name = "multiple_files_proto3_java_proto_lite", + deps = ["//java/kotlin:multiple_files_proto3"], +) + +genrule( + name = "gen_kotlin_proto3_java_multiple_files_lite", + srcs = ["src/test/proto/com/google/protobuf/multiple_files_proto3.proto"], + outs = [ + "MultipleFilesMessageALiteKt.kt", + "MultipleFilesMessageBLiteKt.kt", + "MultipleFilesProto3LiteKt.kt", + ], + cmd = "$(location //:protoc) " + + "--kotlin_out=lite:$(@D) " + + "$(location src/test/proto/com/google/protobuf/multiple_files_proto3.proto) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesMessageAKt.kt " + + "$(location MultipleFilesMessageALiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesMessageBKt.kt " + + "$(location MultipleFilesMessageBLiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesProto3Kt.kt " + + "$(location MultipleFilesProto3LiteKt.kt)", + tools = ["//:protoc"], +) + +genrule( + name = "gen_evil_names_proto2_lite", + srcs = ["src/test/proto/com/google/protobuf/evil_names_proto2.proto"], + outs = [ + "EvilNamesProto2LiteKt.kt", + "HardKeywordsAllTypesProto2LiteKt.kt", + "InterfaceKt.kt", + ], + cmd = "$(location //:protoc) " + + "--kotlin_out=lite:$(@D) " + + "$(location src/test/proto/com/google/protobuf/evil_names_proto2.proto) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/EvilNamesProto2Kt.kt " + + "$(location EvilNamesProto2LiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/HardKeywordsAllTypesProto2Kt.kt " + + "$(location HardKeywordsAllTypesProto2LiteKt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/InterfaceKt.kt " + + "$(location InterfaceKt.kt)", + tools = ["//:protoc"], +) + +genrule( + name = "gen_evil_names_proto3_lite", + srcs = ["src/test/proto/com/google/protobuf/evil_names_proto3.proto"], + outs = [ + "ClassKt.kt", + "EvilNamesProto3Kt.kt", + "HardKeywordsAllTypesProto3Kt.kt", + ], + cmd = "$(location //:protoc) " + + "--kotlin_out=lite:$(@D) " + + "$(location src/test/proto/com/google/protobuf/evil_names_proto3.proto) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/ClassKt.kt " + + "$(location ClassKt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/EvilNamesProto3Kt.kt " + + "$(location EvilNamesProto3Kt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/HardKeywordsAllTypesProto3Kt.kt " + + "$(location HardKeywordsAllTypesProto3Kt.kt)", + tools = ["//:protoc"], +) + +kt_jvm_library( + name = "kotlin_unittest_lite", + srcs = [ + ":gen_evil_names_proto2_lite", + "//:gen_kotlin_unittest_lite", + ], + deps = [ + ":evil_names_proto2_java_proto_lite", + "//java/lite:lite", + "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", + "//java/kotlin:shared_runtime", + "//:java_lite_test_protos", + ], +) + +kt_jvm_library( + name = "kotlin_proto3_unittest_lite", + srcs = [ + ":gen_evil_names_proto3_lite", + ":gen_kotlin_proto3_java_multiple_files_lite", + "//:gen_kotlin_proto3_unittest_lite", + ], + deps = [ + ":evil_names_proto3_java_proto_lite", + ":multiple_files_proto3_java_proto_lite", + "//java/lite:lite", + "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", + "//java/kotlin:shared_runtime", + "//:java_lite_test_protos", + ], +) + +kt_jvm_test( + name = "proto2_test_lite", + srcs = ["src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt"], + deps = [ + ":kotlin_unittest_lite", + "//java/core:test_util_lite", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], + test_class = "com.google.protobuf.kotlin.Proto2LiteTest", +) + +kt_jvm_test( + name = "proto3_test_lite", + srcs = ["src/test/kotlin/com/google/protobuf/Proto3LiteTest.kt"], + deps = [ + ":kotlin_proto3_unittest_lite", + "//java/core:test_util_lite", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], + test_class = "com.google.protobuf.kotlin.Proto3LiteTest", +) diff --git a/java/kotlin-lite/generate-test-sources-build.xml b/java/kotlin-lite/generate-test-sources-build.xml index c5f60b8653..ed886207cb 100644 --- a/java/kotlin-lite/generate-test-sources-build.xml +++ b/java/kotlin-lite/generate-test-sources-build.xml @@ -12,7 +12,7 @@ - + @@ -25,7 +25,7 @@ - + diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 0348bddf20..2c33cc8c71 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -9,9 +9,9 @@ protobuf-kotlin-lite - Protocol Buffers [Lite] + Protocol Buffers [Kotlin-Lite] - Lite version of Protocol Buffers library. This version is optimized for code size, but does + Lite version of Kotlin Protocol Buffers library. This version is optimized for code size, but does not guarantee API/ABI stability. diff --git a/java/kotlin-lite/pom_template.xml b/java/kotlin-lite/pom_template.xml new file mode 100644 index 0000000000..d5e513e142 --- /dev/null +++ b/java/kotlin-lite/pom_template.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + {groupId} + protobuf-parent + {version} + + + {artifactId} + {type} + + Protocol Buffers [Kotlin lite] + + Kotlin lite Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an + efficient yet extensible format. + + + + 1.5.0 + + diff --git a/java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt b/java/kotlin-lite/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt similarity index 100% rename from java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt rename to java/kotlin-lite/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt diff --git a/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto3LiteTest.kt b/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto3LiteTest.kt new file mode 100644 index 0000000000..8d3680acab --- /dev/null +++ b/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto3LiteTest.kt @@ -0,0 +1,365 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package com.google.protobuf.kotlin + +import com.google.common.truth.Truth.assertThat +import com.google.protobuf.kotlin.generator.EvilNamesProto3OuterClass.Class +import com.google.protobuf.kotlin.generator.EvilNamesProto3OuterClass.EvilNamesProto3 +import com.google.protobuf.kotlin.generator.EvilNamesProto3OuterClass.HardKeywordsAllTypesProto3 +import com.google.protobuf.kotlin.generator.HardKeywordsAllTypesProto3Kt +import com.google.protobuf.kotlin.generator.class_ +import com.google.protobuf.kotlin.generator.evilNamesProto3 +import com.google.protobuf.kotlin.generator.hardKeywordsAllTypesProto3 +import proto3_lite_unittest.TestAllTypesKt +import proto3_lite_unittest.TestAllTypesKt.nestedMessage +import proto3_lite_unittest.UnittestProto3Lite.TestAllTypes +import proto3_lite_unittest.UnittestProto3Lite.TestAllTypes.NestedEnum +import proto3_lite_unittest.UnittestProto3Lite.TestEmptyMessage +import proto3_lite_unittest.copy +import proto3_lite_unittest.testAllTypes +import proto3_lite_unittest.testEmptyMessage +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +class Proto3LiteTest { + @Test + fun testGettersAndSetters() { + testAllTypes { + optionalInt32 = 101 + assertThat(optionalInt32).isEqualTo(101) + optionalString = "115" + assertThat(optionalString).isEqualTo("115") + optionalNestedMessage = TestAllTypesKt.nestedMessage { bb = 118 } + assertThat(optionalNestedMessage).isEqualTo(TestAllTypesKt.nestedMessage { bb = 118 }) + optionalNestedEnum = NestedEnum.BAZ + assertThat(optionalNestedEnum).isEqualTo(NestedEnum.BAZ) + oneofUint32 = 601 + assertThat(oneofUint32).isEqualTo(601) + } + } + + @Test + fun testRepeatedGettersAndSetters() { + testAllTypes { + repeatedInt32.addAll(listOf(1, 2)) + assertThat(repeatedInt32).isEqualTo(listOf(1, 2)) + repeatedInt32 += listOf(3, 4) + assertThat(repeatedInt32).isEqualTo(listOf(1, 2, 3, 4)) + repeatedInt32[0] = 5 + assertThat(repeatedInt32).isEqualTo(listOf(5, 2, 3, 4)) + + repeatedString.addAll(listOf("1", "2")) + assertThat(repeatedString).isEqualTo(listOf("1", "2")) + repeatedString += listOf("3", "4") + assertThat(repeatedString).isEqualTo(listOf("1", "2", "3", "4")) + repeatedString[0] = "5" + assertThat(repeatedString).isEqualTo(listOf("5", "2", "3", "4")) + + repeatedNestedMessage.addAll(listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 })) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 } + ) + ) + repeatedNestedMessage += listOf(nestedMessage { bb = 3 }, nestedMessage { bb = 4 }) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } + ) + ) + repeatedNestedMessage[0] = nestedMessage { bb = 5 } + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 5 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } + ) + ) + + repeatedNestedEnum.addAll(listOf(NestedEnum.FOO, NestedEnum.BAR)) + assertThat(repeatedNestedEnum).isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR)) + repeatedNestedEnum += listOf(NestedEnum.BAZ, NestedEnum.FOO) + assertThat(repeatedNestedEnum).isEqualTo( + listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) + repeatedNestedEnum[0] = NestedEnum.BAR + assertThat(repeatedNestedEnum).isEqualTo( + listOf(NestedEnum.BAR, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) + } + } + + @Test + fun testClears() { + assertThat( + testAllTypes { + optionalInt32 = 101 + clearOptionalInt32() + + optionalString = "115" + clearOptionalString() + + optionalNestedMessage = TestAllTypesKt.nestedMessage { bb = 118 } + clearOptionalNestedMessage() + + optionalNestedEnum = NestedEnum.BAZ + clearOptionalNestedEnum() + + oneofUint32 = 601 + clearOneofUint32() + } + ).isEqualTo( + TestAllTypes.newBuilder().build() + ) + } + + @Test + fun testCopy() { + val message = testAllTypes { + optionalInt32 = 101 + optionalString = "115" + } + val modifiedMessage = message.copy { + optionalInt32 = 201 + } + + assertThat(message).isEqualTo( + TestAllTypes.newBuilder() + .setOptionalInt32(101) + .setOptionalString("115") + .build() + ) + assertThat(modifiedMessage).isEqualTo( + TestAllTypes.newBuilder() + .setOptionalInt32(201) + .setOptionalString("115") + .build() + ) + } + + @Test + fun testOneof() { + val message = testAllTypes { + oneofString = "foo" + assertThat(oneofFieldCase) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOF_STRING) + assertThat(oneofString).isEqualTo("foo") + clearOneofField() + assertThat(oneofFieldCase) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOFFIELD_NOT_SET) + oneofUint32 = 5 + } + + assertThat(message.getOneofFieldCase()) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOF_UINT32) + assertThat(message.getOneofUint32()).isEqualTo(5) + } + + @Test + fun testEmptyMessages() { + assertThat( + testEmptyMessage {} + ).isEqualTo( + TestEmptyMessage.newBuilder().build() + ) + } + + @Test + fun testEvilNames() { + assertThat( + evilNamesProto3 { + initialized = true + hasFoo = true + bar = "foo" + isInitialized = true + fooBar = "foo" + aLLCAPS += "foo" + aLLCAPSMAP[1] = true + hasUnderbarPrecedingNumeric1Foo = true + hasUnderbarPrecedingNumeric42Bar = true + hasUnderbarPrecedingNumeric123Foo42BarBaz = true + extension += "foo" + class_ = "foo" + int = 1.0 + long = true + boolean = 1L + sealed = "foo" + interface_ = 1F + in_ = 1 + object_ = "foo" + cachedSize_ = "foo" + serializedSize_ = true + value = "foo" + index = 1L + values += "foo" + newValues += "foo" + builder = true + k[1] = 1 + v["foo"] = "foo" + key["foo"] = 1 + map[1] = "foo" + pairs["foo"] = 1 + LeadingUnderscore = "foo" + option = 1 + } + ).isEqualTo( + EvilNamesProto3.newBuilder() + .setInitialized(true) + .setHasFoo(true) + .setBar("foo") + .setIsInitialized(true) + .setFooBar("foo") + .addALLCAPS("foo") + .putALLCAPSMAP(1, true) + .setHasUnderbarPrecedingNumeric1Foo(true) + .setHasUnderbarPrecedingNumeric42Bar(true) + .setHasUnderbarPrecedingNumeric123Foo42BarBaz(true) + .addExtension("foo") + .setClass_("foo") + .setInt(1.0) + .setLong(true) + .setBoolean(1L) + .setSealed("foo") + .setInterface(1F) + .setIn(1) + .setObject("foo") + .setCachedSize_("foo") + .setSerializedSize_(true) + .setValue("foo") + .setIndex(1L) + .addValues("foo") + .addNewValues("foo") + .setBuilder(true) + .putK(1, 1) + .putV("foo", "foo") + .putKey("foo", 1) + .putMap(1, "foo") + .putPairs("foo", 1) + .setLeadingUnderscore("foo") + .setOption(1) + .build() + ) + + assertThat(class_ {}).isEqualTo(Class.newBuilder().build()) + } + + @Test + fun testHardKeywordGettersAndSetters() { + hardKeywordsAllTypesProto3 { + as_ = 1 + assertThat(as_).isEqualTo(1) + + in_ = "foo" + assertThat(in_).isEqualTo("foo") + + break_ = HardKeywordsAllTypesProto3.NestedEnum.FOO + assertThat(break_).isEqualTo(HardKeywordsAllTypesProto3.NestedEnum.FOO) + + do_ = HardKeywordsAllTypesProto3Kt.nestedMessage { while_ = 1 } + assertThat(do_).isEqualTo(HardKeywordsAllTypesProto3Kt.nestedMessage { while_ = 1 }) + + continue_[1] = 1 + assertThat(continue_[1]).isEqualTo(1) + + else_ += 1 + assertThat(else_).isEqualTo(listOf(1)) + + for_ += "foo" + assertThat(for_).isEqualTo(listOf("foo")) + + fun_ += HardKeywordsAllTypesProto3.NestedEnum.FOO + assertThat(fun_).isEqualTo(listOf(HardKeywordsAllTypesProto3.NestedEnum.FOO)) + + if_ += HardKeywordsAllTypesProto3Kt.nestedMessage { while_ = 1 } + assertThat(if_).isEqualTo(listOf(HardKeywordsAllTypesProto3Kt.nestedMessage { while_ = 1 })) + } + } + + @Test + fun testHardKeywordHazzers() { + hardKeywordsAllTypesProto3 { + as_ = 1 + assertThat(hasAs_()).isTrue() + + in_ = "foo" + assertThat(hasIn_()).isTrue() + + break_ = HardKeywordsAllTypesProto3.NestedEnum.FOO + assertThat(hasBreak_()).isTrue() + + do_ = HardKeywordsAllTypesProto3Kt.nestedMessage { while_ = 1 } + assertThat(hasDo_()).isTrue() + } + } + + @Test + fun testHardKeywordClears() { + hardKeywordsAllTypesProto3 { + as_ = 1 + clearAs_() + assertThat(hasAs_()).isFalse() + + in_ = "foo" + clearIn_() + assertThat(hasIn_()).isFalse() + + break_ = HardKeywordsAllTypesProto3.NestedEnum.FOO + clearBreak_() + assertThat(hasBreak_()).isFalse() + + do_ = HardKeywordsAllTypesProto3Kt.nestedMessage { while_ = 1 } + clearDo_() + assertThat(hasDo_()).isFalse() + } + } + + @Test + fun testMultipleFiles() { + assertThat( + com.google.protobuf.kotlin.generator.multipleFilesMessageA {} + ).isEqualTo( + com.google.protobuf.kotlin.generator.MultipleFilesMessageA.newBuilder().build() + ) + + assertThat( + com.google.protobuf.kotlin.generator.multipleFilesMessageB {} + ).isEqualTo( + com.google.protobuf.kotlin.generator.MultipleFilesMessageB.newBuilder().build() + ) + } +} diff --git a/java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto2.proto b/java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto2.proto new file mode 100644 index 0000000000..3735baf9f6 --- /dev/null +++ b/java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto2.proto @@ -0,0 +1,93 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// LINT: LEGACY_NAMES +syntax = "proto2"; + +package protobuf.kotlin.generator; + +option java_package = "com.google.protobuf.kotlin.generator"; + +message EvilNamesProto2 { + optional bool initialized = 1; + optional bool has_foo = 2; + optional string Bar = 3; + optional bool is_initialized = 4; + + oneof camelCase { + string fooBar = 5; + } + + repeated string ALL_CAPS = 7; + map ALL_CAPS_MAP = 8; + + optional bool has_underbar_preceding_numeric_1foo = 9; + optional bool has_underbar_preceding_numeric_42bar = 13; + optional bool has_underbar_preceding_numeric_123foo42bar_baz = 14; + + extensions 100 to max; + + repeated string extension = 12; + repeated int32 class = 15; + optional double int = 16; + optional bool long = 17; + optional int64 boolean = 18; + optional string sealed = 19; + optional float interface = 20; + optional int32 in = 21; + optional string object = 22; + optional string cached_size = 23; + optional bool serialized_size = 24; + optional string by = 25; +} + +message HardKeywordsAllTypesProto2 { + message NestedMessage { + optional int32 while = 1; + } + + enum NestedEnum { + FOO = 1; + BAR = 2; + } + + optional int32 as = 1; + optional string in = 2; + optional NestedEnum break = 3; + map continue = 4; + optional NestedMessage do = 5; + + repeated int32 else = 6; + repeated string for = 7; + repeated NestedEnum fun = 8; + repeated NestedMessage if = 9; +} + +message Interface {} diff --git a/java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto3.proto b/java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto3.proto new file mode 100644 index 0000000000..f6b06d3727 --- /dev/null +++ b/java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto3.proto @@ -0,0 +1,107 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// LINT: LEGACY_NAMES +syntax = "proto3"; + +package protobuf.kotlin.generator; + +option java_package = "com.google.protobuf.kotlin.generator"; + +message EvilNamesProto3 { + bool initialized = 1; + bool has_foo = 2; + string Bar = 3; + bool is_initialized = 4; + + oneof camelCase { + string fooBar = 5; + } + + repeated string ALL_CAPS = 7; + map ALL_CAPS_MAP = 8; + + bool has_underbar_preceding_numeric_1foo = 9; + bool has_underbar_preceding_numeric_42bar = 10; + bool has_underbar_preceding_numeric_123foo42bar_baz = 11; + + repeated string extension = 12; + + string class = 13; + double int = 14; + bool long = 15; + int64 boolean = 16; + string sealed = 17; + float interface = 18; + int32 in = 19; + string object = 20; + string cached_size = 21; + bool serialized_size = 22; + string value = 23; + int64 index = 24; + repeated string values = 25; + repeated string new_values = 26; + bool builder = 27; + map k = 28; + map v = 29; + map key = 30; + map map = 31; + map pairs = 32; + + string _leading_underscore = 33; + oneof _leading_underscore_oneof { + int32 option = 34; + } +} + +message HardKeywordsAllTypesProto3 { + message NestedMessage { + optional int32 while = 1; + } + + enum NestedEnum { + ZERO = 0; + FOO = 1; + BAR = 2; + } + + optional int32 as = 1; + optional string in = 2; + optional NestedEnum break = 3; + map continue = 4; + optional NestedMessage do = 5; + + repeated int32 else = 6; + repeated string for = 7; + repeated NestedEnum fun = 8; + repeated NestedMessage if = 9; +} + +message Class {} diff --git a/java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto b/java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto new file mode 100644 index 0000000000..61141c54eb --- /dev/null +++ b/java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto @@ -0,0 +1,42 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +syntax = "proto3"; + +package protobuf.kotlin.generator; + +option java_package = "com.google.protobuf.kotlin.generator"; +option java_multiple_files = true; + +enum NestedEnum { FOO = 0; } + +message MultipleFilesMessageA {} + +message MultipleFilesMessageB {} diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD new file mode 100644 index 0000000000..97c81628cb --- /dev/null +++ b/java/kotlin/BUILD @@ -0,0 +1,278 @@ +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test", "kt_jvm_binary") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_jvm_external//:defs.bzl", "java_export") +load("@rules_proto//proto:defs.bzl", "proto_library") +load("//:protobuf_version.bzl", "PROTOBUF_VERSION") + +# Kotlin generated protos depend on this and only this. +kt_jvm_library( + name = "shared_runtime", + srcs = [ + "src/main/kotlin/com/google/protobuf/DslList.kt", + "src/main/kotlin/com/google/protobuf/DslMap.kt", + "src/main/kotlin/com/google/protobuf/DslProxy.kt", + "src/main/kotlin/com/google/protobuf/ExtensionList.kt", + "src/main/kotlin/com/google/protobuf/ProtoDslMarker.kt", + "src/main/kotlin/com/google/protobuf/UnmodifiableCollections.kt", + ], + visibility = ["//visibility:public"], + deps = [ + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + "//java/lite", + ], +) + +kt_jvm_library( + name = "only_for_use_in_proto_generated_code_its_generator_and_tests", + srcs = ["src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt"], + visibility = ["//java:__subpackages__"], +) + +kt_jvm_library( + name = "bytestring_lib", + srcs = ["src/main/kotlin/com/google/protobuf/ByteStrings.kt"], + deps = ["//java/lite"], +) + +kt_jvm_library( + name = "full_extensions", + srcs = ["src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt"], + deps = ["//java/core"], +) + +test_suite( + name = "tests", + tests = [ + "bytestring_test", + "shared_tests", + "test_extensions", + "proto2_test", + "proto3_test", + ], +) + +kt_jvm_test( + name = "bytestring_test", + srcs = ["src/test/kotlin/com/google/protobuf/ByteStringsTest.kt"], + deps = [ + ":bytestring_lib", + "//java/lite", + "@com_github_jetbrains_kotlin//:kotlin-test", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], + test_class = "com.google.protobuf.kotlin.ByteStringsTest", +) + +proto_library( + name = "example_extensible_message_proto", + srcs = ["src/test/proto/com/google/protobuf/example_extensible_message.proto"], + visibility = ["//visibility:public"], +) + +java_proto_library( + name = "example_extensible_message_java_proto", + deps = [":example_extensible_message_proto"], +) + +kt_jvm_test( + name = "shared_tests", + srcs = [ + "src/test/kotlin/com/google/protobuf/DslListTest.kt", + "src/test/kotlin/com/google/protobuf/DslMapTest.kt", + "src/test/kotlin/com/google/protobuf/ExtensionListTest.kt", + ], + deps = [ + ":bytestring_lib", + ":example_extensible_message_java_proto", + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + ":shared_runtime", + "@com_github_jetbrains_kotlin//:kotlin-test", + "@maven//:com_google_truth_truth", + "@maven//:com_google_guava_guava_testlib", + "@maven//:junit_junit", + ], + test_class = "com.google.protobuf.kotlin.DslListTest", +) + +kt_jvm_test( + name = "test_extensions", + srcs = ["src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt"], + deps = [ + ":example_extensible_message_java_proto", + ":full_extensions", + "//java/lite", + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + ":shared_runtime", + "@com_github_jetbrains_kotlin//:kotlin-test", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], + test_class = "com.google.protobuf.kotlin.ExtendableMessageExtensionsTest", +) + +proto_library( + name = "evil_names_proto2", + srcs = ["src/test/proto/com/google/protobuf/evil_names_proto2.proto"], + visibility = ["//:__subpackages__"], +) + +proto_library( + name = "evil_names_proto3", + srcs = ["src/test/proto/com/google/protobuf/evil_names_proto3.proto"], + visibility = ["//:__subpackages__"], +) + +java_proto_library( + name = "evil_names_proto2_java_proto", + deps = [":evil_names_proto2"], +) + +java_proto_library( + name = "evil_names_proto3_java_proto", + deps = [":evil_names_proto3"], +) + +proto_library( + name = "multiple_files_proto3", + srcs = ["src/test/proto/com/google/protobuf/multiple_files_proto3.proto"], + visibility = ["//:__subpackages__"], +) + +java_proto_library( name = "multiple_files_proto3_java_proto", + deps = [":multiple_files_proto3"], +) + +genrule( + name = "gen_kotlin_proto3_java_multiple_files", + srcs = ["src/test/proto/com/google/protobuf/multiple_files_proto3.proto"], + outs = [ + "MultipleFilesMessageAKt.kt", + "MultipleFilesMessageBKt.kt", + "MultipleFilesProto3Kt.kt", + ], + cmd = "$(location //:protoc) " + + "--kotlin_out=shared,immutable:$(@D) " + + "$(location src/test/proto/com/google/protobuf/multiple_files_proto3.proto) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesMessageAKt.kt " + + "$(location MultipleFilesMessageAKt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesMessageBKt.kt " + + "$(location MultipleFilesMessageBKt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesProto3Kt.kt " + + "$(location MultipleFilesProto3Kt.kt)", + tools = ["//:protoc"], +) + +genrule( + name = "gen_evil_names_proto2", + srcs = ["src/test/proto/com/google/protobuf/evil_names_proto2.proto"], + outs = [ + "EvilNamesProto2Kt.kt", + "HardKeywordsAllTypesProto2Kt.kt", + "InterfaceKt.kt", + ], + cmd = "$(location //:protoc) " + + "--kotlin_out=shared,immutable:$(@D) " + + "$(location src/test/proto/com/google/protobuf/evil_names_proto2.proto) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/EvilNamesProto2Kt.kt " + + "$(location EvilNamesProto2Kt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/HardKeywordsAllTypesProto2Kt.kt " + + "$(location HardKeywordsAllTypesProto2Kt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/InterfaceKt.kt " + + "$(location InterfaceKt.kt)", + tools = ["//:protoc"], +) + +genrule( + name = "gen_evil_names_proto3", + srcs = ["src/test/proto/com/google/protobuf/evil_names_proto3.proto"], + outs = [ + "ClassKt.kt", + "EvilNamesProto3Kt.kt", + "HardKeywordsAllTypesProto3Kt.kt", + ], + cmd = "$(location //:protoc) " + + "--kotlin_out=shared,immutable:$(@D) " + + "$(location src/test/proto/com/google/protobuf/evil_names_proto3.proto) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/ClassKt.kt " + + "$(location ClassKt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/EvilNamesProto3Kt.kt " + + "$(location EvilNamesProto3Kt.kt) && " + + "cp $(@D)/com/google/protobuf/kotlin/generator/HardKeywordsAllTypesProto3Kt.kt " + + "$(location HardKeywordsAllTypesProto3Kt.kt)", + tools = ["//:protoc"], +) + +kt_jvm_library( + name = "kotlin_unittest", + srcs = [ + ":gen_evil_names_proto2", + "//:gen_kotlin_unittest", + ], + deps = [ + ":evil_names_proto2_java_proto", + "//java/core:core", + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + ":shared_runtime", + "//:java_test_protos", + ], +) + +kt_jvm_library( + name = "kotlin_proto3_unittest", + srcs = [ + ":gen_evil_names_proto3", + ":gen_kotlin_proto3_java_multiple_files", + "//:gen_kotlin_proto3_unittest", + ], + deps = [ + ":evil_names_proto3_java_proto", + ":multiple_files_proto3_java_proto", + "//java/core:core", + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + ":shared_runtime", + "//:java_test_protos", + ], +) + +kt_jvm_test( + name = "proto2_test", + srcs = ["src/test/kotlin/com/google/protobuf/Proto2Test.kt"], + deps = [ + ":kotlin_unittest", + "//java/core:test_util", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], + test_class = "com.google.protobuf.kotlin.Proto2Test", +) + +kt_jvm_test( + name = "proto3_test", + srcs = ["src/test/kotlin/com/google/protobuf/Proto3Test.kt"], + deps = [ + ":kotlin_proto3_unittest", + "//java/core:test_util", + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], + test_class = "com.google.protobuf.kotlin.Proto3Test", +) + +java_export( + name = "kotlin_mvn", + maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_VERSION, + pom_template = "pom_template.xml", + runtime_deps = [":shared_runtime"], +) + +filegroup( + name = "release", + srcs = [ + ":kotlin_mvn-docs", + ":kotlin_mvn-maven-source", + ":kotlin_mvn-pom", + ":kotlin_mvn-project", + ], + visibility = ["//java:__pkg__"], +) diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index a275f24bd9..4157a53a50 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -9,9 +9,9 @@ protobuf-kotlin - Protocol Buffers [Core] + Protocol Buffers [Kotlin-Core] - Core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an + Kotlin core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. diff --git a/java/kotlin/pom_template.xml b/java/kotlin/pom_template.xml new file mode 100644 index 0000000000..3231fb33b5 --- /dev/null +++ b/java/kotlin/pom_template.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + {groupId} + protobuf-parent + {version} + + + {artifactId} + {type} + + Protocol Buffers [Kotlin] + + Kotlin core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an + efficient yet extensible format. + + + + 1.5.0 + + + diff --git a/maven_install.json b/maven_install.json index 3919de3e79..bce3e2b463 100644 --- a/maven_install.json +++ b/maven_install.json @@ -1,11 +1,11 @@ { "dependency_tree": { "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", - "__INPUT_ARTIFACTS_HASH": -1650978854, - "__RESOLVED_ARTIFACTS_HASH": -718494898, + "__INPUT_ARTIFACTS_HASH": 1634601905, + "__RESOLVED_ARTIFACTS_HASH": -143733866, "conflict_resolution": { "com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.5.1", - "junit:junit:4.12": "junit:junit:4.13.1" + "junit:junit:4.12": "junit:junit:4.13.2" }, "dependencies": [ { @@ -80,6 +80,35 @@ "sha256": "a171ee4c734dd2da837e4b16be9df4661afab72a41adaf31eb84dfdaf936ca26", "url": "https://repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" }, + { + "coord": "com.google.guava:guava-testlib:30.1.1-jre", + "dependencies": [ + "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava", + "com.google.j2objc:j2objc-annotations:1.3", + "com.google.code.findbugs:jsr305:3.0.2", + "org.hamcrest:hamcrest-core:1.3", + "com.google.guava:guava:30.1.1-jre", + "com.google.guava:failureaccess:1.0.1", + "com.google.errorprone:error_prone_annotations:2.5.1", + "junit:junit:4.13.2", + "org.checkerframework:checker-qual:3.9.1" + ], + "directDependencies": [ + "com.google.j2objc:j2objc-annotations:1.3", + "com.google.code.findbugs:jsr305:3.0.2", + "com.google.guava:guava:30.1.1-jre", + "com.google.errorprone:error_prone_annotations:2.5.1", + "junit:junit:4.13.2", + "org.checkerframework:checker-qual:3.9.1" + ], + "file": "v1/https/repo1.maven.org/maven2/com/google/guava/guava-testlib/30.1.1-jre/guava-testlib-30.1.1-jre.jar", + "mirror_urls": [ + "https://repo1.maven.org/maven2/com/google/guava/guava-testlib/30.1.1-jre/guava-testlib-30.1.1-jre.jar", + "https://repo.maven.apache.org/maven2/com/google/guava/guava-testlib/30.1.1-jre/guava-testlib-30.1.1-jre.jar" + ], + "sha256": "8a7fc9adfa1e7441d1d30ca288c593ebc7c4a24c601d01169b781c398f24099b", + "url": "https://repo1.maven.org/maven2/com/google/guava/guava-testlib/30.1.1-jre/guava-testlib-30.1.1-jre.jar" + }, { "coord": "com.google.guava:guava:30.1.1-jre", "dependencies": [ @@ -134,19 +163,18 @@ "coord": "com.google.truth:truth:1.1.2", "dependencies": [ "org.ow2.asm:asm:9.0", - "org.hamcrest:hamcrest-core:1.3", "com.google.auto.value:auto-value-annotations:1.7.4", - "junit:junit:4.13.1", "com.google.guava:guava:30.1.1-jre", "com.google.errorprone:error_prone_annotations:2.5.1", + "junit:junit:4.13.2", "org.checkerframework:checker-qual:3.9.1" ], "directDependencies": [ "org.ow2.asm:asm:9.0", "com.google.auto.value:auto-value-annotations:1.7.4", - "junit:junit:4.13.1", "com.google.guava:guava:30.1.1-jre", "com.google.errorprone:error_prone_annotations:2.5.1", + "junit:junit:4.13.2", "org.checkerframework:checker-qual:3.9.1" ], "file": "v1/https/repo1.maven.org/maven2/com/google/truth/truth/1.1.2/truth-1.1.2.jar", @@ -158,20 +186,20 @@ "url": "https://repo1.maven.org/maven2/com/google/truth/truth/1.1.2/truth-1.1.2.jar" }, { - "coord": "junit:junit:4.13.1", + "coord": "junit:junit:4.13.2", "dependencies": [ "org.hamcrest:hamcrest-core:1.3" ], "directDependencies": [ "org.hamcrest:hamcrest-core:1.3" ], - "file": "v1/https/repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1.jar", + "file": "v1/https/repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar", "mirror_urls": [ - "https://repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1.jar", - "https://repo.maven.apache.org/maven2/junit/junit/4.13.1/junit-4.13.1.jar" + "https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar", + "https://repo.maven.apache.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar" ], - "sha256": "c30719db974d6452793fe191b3638a5777005485bae145924044530ffa5f6122", - "url": "https://repo1.maven.org/maven2/junit/junit/4.13.1/junit-4.13.1.jar" + "sha256": "8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3", + "url": "https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar" }, { "coord": "org.checkerframework:checker-qual:3.9.1", diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index f78006862a..6f26a901b2 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -8,6 +8,7 @@ PROTOBUF_MAVEN_ARTIFACTS = [ "com.google.errorprone:error_prone_annotations:2.3.2", "com.google.j2objc:j2objc-annotations:1.3", "com.google.guava:guava:30.1.1-jre", + "com.google.guava:guava-testlib:30.1.1-jre", "com.google.truth:truth:1.1.2", "junit:junit:4.12", "org.easymock:easymock:3.2", From ab7cf573ab7829e24ed21a5480b542a8dd6be3d5 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 12 Jan 2022 21:58:46 +0000 Subject: [PATCH 133/207] Remove unfinished release work and make names consistent --- java/kotlin-lite/pom_template.xml | 2 +- java/kotlin/BUILD | 19 ------------------- java/kotlin/pom_template.xml | 2 +- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/java/kotlin-lite/pom_template.xml b/java/kotlin-lite/pom_template.xml index d5e513e142..92be0ea668 100644 --- a/java/kotlin-lite/pom_template.xml +++ b/java/kotlin-lite/pom_template.xml @@ -10,7 +10,7 @@ {artifactId} {type} - Protocol Buffers [Kotlin lite] + Protocol Buffers [Kotlin-Lite] Kotlin lite Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD index 97c81628cb..3ad9649127 100644 --- a/java/kotlin/BUILD +++ b/java/kotlin/BUILD @@ -1,6 +1,5 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test", "kt_jvm_binary") load("@rules_java//java:defs.bzl", "java_proto_library") -load("@rules_jvm_external//:defs.bzl", "java_export") load("@rules_proto//proto:defs.bzl", "proto_library") load("//:protobuf_version.bzl", "PROTOBUF_VERSION") @@ -258,21 +257,3 @@ kt_jvm_test( ], test_class = "com.google.protobuf.kotlin.Proto3Test", ) - -java_export( - name = "kotlin_mvn", - maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_VERSION, - pom_template = "pom_template.xml", - runtime_deps = [":shared_runtime"], -) - -filegroup( - name = "release", - srcs = [ - ":kotlin_mvn-docs", - ":kotlin_mvn-maven-source", - ":kotlin_mvn-pom", - ":kotlin_mvn-project", - ], - visibility = ["//java:__pkg__"], -) diff --git a/java/kotlin/pom_template.xml b/java/kotlin/pom_template.xml index 3231fb33b5..c8ddcad9aa 100644 --- a/java/kotlin/pom_template.xml +++ b/java/kotlin/pom_template.xml @@ -10,7 +10,7 @@ {artifactId} {type} - Protocol Buffers [Kotlin] + Protocol Buffers [Kotlin-Core] Kotlin core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. From 7924cd6726ab715df77074b00dc97ae3a1620039 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 13 Jan 2022 00:10:23 +0000 Subject: [PATCH 134/207] Addressing comments --- BUILD | 12 ++++++------ WORKSPACE | 8 -------- java/BUILD | 1 - java/kotlin/BUILD | 2 +- .../kotlin/com/google/protobuf/ByteStringsTest.kt | 3 ++- protobuf_deps.bzl | 9 ++++++++- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/BUILD b/BUILD index 738034ede6..df62e9e22b 100644 --- a/BUILD +++ b/BUILD @@ -1326,13 +1326,13 @@ cc_binary( java_proto_library( name = "java_test_protos", deps = [":generic_test_protos"], - visibility = ["//visibility:public"], + visibility = ["//java:__subpackages__"], ) java_lite_proto_library( name = "java_lite_test_protos", deps = [":generic_test_protos"], - visibility = ["//visibility:public"], + visibility = ["//java:__subpackages__"], ) java_proto_library( @@ -1449,7 +1449,7 @@ genrule( "OptionalGroup_extension_liteKt.kt", "RepeatedGroup_extension_liteKt.kt", ], - visibility = ["//visibility:public"], + visibility = ["//java:__subpackages__"], cmd = "$(location //:protoc) " + "--kotlin_out=lite:$(@D) -Isrc/ " + "$(locations src/google/protobuf/unittest_lite.proto) && " + @@ -1497,7 +1497,7 @@ genrule( "OptionalGroup_extensionKt.kt", "RepeatedGroup_extensionKt.kt", ], - visibility = ["//visibility:public"], + visibility = ["//java:__subpackages__"], cmd = "$(location //:protoc) " + "--kotlin_out=shared,immutable:$(@D) -Isrc/ " + "$(location src/google/protobuf/unittest.proto) && " + @@ -1538,7 +1538,7 @@ genrule( "TestAllTypesProto3LiteKt.kt", "TestEmptyMessageProto3LiteKt.kt", ], - visibility = ["//visibility:public"], + visibility = ["//java:__subpackages__"], cmd = "$(location //:protoc) " + "--kotlin_out=lite:$(@D) -Isrc/ " + "$(location src/google/protobuf/unittest_proto3_lite.proto) && " + @@ -1560,7 +1560,7 @@ genrule( "TestAllTypesProto3Kt.kt", "TestEmptyMessageProto3Kt.kt", ], - visibility = ["//visibility:public"], + visibility = ["//java:__subpackages__"], cmd = "$(location //:protoc) " + "--kotlin_out=shared,immutable:$(@D) -Isrc/ " + "$(location src/google/protobuf/unittest_proto3.proto) && " + diff --git a/WORKSPACE b/WORKSPACE index 5778a58680..36df3f3371 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -61,14 +61,6 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies() # For `kt_jvm_library` -rules_kotlin_version = "v1.5.0-beta-4" -rules_kotlin_sha = "6cbd4e5768bdfae1598662e40272729ec9ece8b7bded8f0d2c81c8ff96dc139d" -http_archive( - name = "io_bazel_rules_kotlin", - urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % rules_kotlin_version], - sha256 = rules_kotlin_sha, -) - load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") kotlin_repositories() diff --git a/java/BUILD b/java/BUILD index 7a244d8f88..3e57ab6d7b 100644 --- a/java/BUILD +++ b/java/BUILD @@ -13,7 +13,6 @@ filegroup( name = "release", srcs = [ "//java/core:release", # contains lite. - "//java/kotlin:release", # contains kotlin lite. "//java/util:release", ] ) diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD index 3ad9649127..2be2195bc3 100644 --- a/java/kotlin/BUILD +++ b/java/kotlin/BUILD @@ -66,7 +66,7 @@ kt_jvm_test( proto_library( name = "example_extensible_message_proto", srcs = ["src/test/proto/com/google/protobuf/example_extensible_message.proto"], - visibility = ["//visibility:public"], + visibility = ["//java:__subpackages__"], ) java_proto_library( diff --git a/java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt b/java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt index 99c8c9808f..92343cd3ef 100644 --- a/java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt +++ b/java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt @@ -33,6 +33,7 @@ package com.google.protobuf.kotlin import com.google.common.truth.Truth.assertThat import com.google.protobuf.ByteString import java.lang.IndexOutOfBoundsException +import java.nio.Buffer import java.nio.ByteBuffer import kotlin.test.assertFailsWith import org.junit.Test @@ -90,7 +91,7 @@ class ByteStringsTest { @Test fun byteBufferToByteStringRespectsPositionAndLimit() { val buffer = ByteBuffer.wrap("abc".toByteArray(Charsets.UTF_8)) - buffer.position(1) + (buffer as java.nio.Buffer).position(1) buffer.limit(2) assertThat(buffer.toByteString()).isEqualTo(ByteString.copyFromUtf8("b")) } diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 6f26a901b2..7e2caa3302 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -74,7 +74,7 @@ def protobuf_deps(): strip_prefix = "rules_jvm_external-4.1", urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/4.1.zip"], ) - + if not native.existing_rule("rules_pkg"): http_archive( name = "rules_pkg", @@ -84,3 +84,10 @@ def protobuf_deps(): ], sha256 = "a89e203d3cf264e564fcb96b6e06dd70bc0557356eb48400ce4b5d97c2c3720d", ) + + if not native.existing_rule("io_bazel_rules_kotlin"): + http_archive( + name = "io_bazel_rules_kotlin", + urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v1.5.0-beta-4/rules_kotlin_release.tgz"], + sha256 = "6cbd4e5768bdfae1598662e40272729ec9ece8b7bded8f0d2c81c8ff96dc139d", + ) From 01f09b3425b387590f6fcb02b36c07f1d2210d18 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 13 Jan 2022 00:29:28 +0000 Subject: [PATCH 135/207] Fixing bazel build failure --- .../src/test/kotlin/com/google/protobuf/ByteStringsTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt b/java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt index 92343cd3ef..e944d385aa 100644 --- a/java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt +++ b/java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt @@ -92,7 +92,7 @@ class ByteStringsTest { fun byteBufferToByteStringRespectsPositionAndLimit() { val buffer = ByteBuffer.wrap("abc".toByteArray(Charsets.UTF_8)) (buffer as java.nio.Buffer).position(1) - buffer.limit(2) + (buffer as java.nio.Buffer).limit(2) assertThat(buffer.toByteString()).isEqualTo(ByteString.copyFromUtf8("b")) } } From 0476a893e2ade3d2ff0fdb56b27285840086bb46 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 13 Jan 2022 11:45:07 +1100 Subject: [PATCH 136/207] conditionally adding mixed return type With guidance from Remi Collet, use ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_EX macro, and use a conditional to fake that macro for earlier php versions. Tested on 8.1 and 7.4, and deprecation notices gone plus all tests pass --- php/ext/google/protobuf/array.c | 18 ++++++++++++------ php/ext/google/protobuf/map.c | 17 ++++++++++++----- php/ext/google/protobuf/protobuf.h | 10 ++++++++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index a8ad9292a1..1ef72c4e40 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -309,7 +309,7 @@ PHP_METHOD(RepeatedField, offsetExists) { } /** - * RepeatedField::offsetGet() + * RepeatedField::offsetGet(): mixed * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -459,7 +459,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() @@ -575,7 +575,7 @@ PHP_METHOD(RepeatedFieldIter, rewind) { } /** - * RepeatedFieldIter::current() + * RepeatedFieldIter::current(): mixed * * Implements the Iterator interface. Returns the current value. */ @@ -598,7 +598,7 @@ PHP_METHOD(RepeatedFieldIter, current) { } /** - * RepeatedFieldIter::key() + * RepeatedFieldIter::key(): mixed * * Implements the Iterator interface. Returns the current key. */ @@ -628,6 +628,12 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() @@ -639,8 +645,8 @@ ZEND_END_ARG_INFO() static zend_function_entry repeated_field_iter_methods[] = { PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index b908fd586f..014e56afbd 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -329,7 +329,7 @@ PHP_METHOD(MapField, offsetExists) { } /** - * MapField::offsetGet() + * MapField::offsetGet(): mixed * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -453,7 +453,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 2) ZEND_ARG_INFO(0, value_class) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() @@ -573,7 +574,7 @@ PHP_METHOD(MapFieldIter, rewind) { } /** - * MapFieldIter::current() + * MapFieldIter::current(): mixed * * Implements the Iterator interface. Returns the current value. */ @@ -626,6 +627,12 @@ PHP_METHOD(MapFieldIter, valid) { ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() @@ -634,8 +641,8 @@ ZEND_END_ARG_INFO() static zend_function_entry map_field_iter_methods[] = { PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 7cbad84861..4490d683bf 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -84,6 +84,16 @@ const zval *get_generated_pool(); #define zend_ce_countable spl_ce_Countable #endif +// In PHP 8.1, mismatched tentative return types emit a depracation notice. +// https://wiki.php.net/rfc/internal_method_return_types +// +// When compiling for earlier php versions, the return type is dropped. +#if PHP_VERSION_ID < 80100 +#define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null) +#define IS_MIXED 16 +#endif + ZEND_BEGIN_ARG_INFO(arginfo_void, 0) ZEND_END_ARG_INFO() From 58d22b8cac376cb9b21a81726cf612071fd2eb09 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 13 Jan 2022 00:49:22 +0000 Subject: [PATCH 137/207] Add new files to makefile --- Makefile.am | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index ecfab8cda9..149e4750f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -536,15 +536,16 @@ java_EXTRA_DIST= java/core/src/test/proto/com/google/protobuf/wrappers_test.proto \ java/internal/BUILD \ java/internal/testing.bzl \ + java/kotlin/BUILD \ java/kotlin/generate-sources-build.xml \ java/kotlin/generate-test-sources-build.xml \ java/kotlin/pom.xml \ + java/kotlin/pom_template.xml \ java/kotlin/src/main/kotlin/com/google/protobuf/ByteStrings.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/DslList.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/DslMap.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/DslProxy.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt \ - java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt\ java/kotlin/src/main/kotlin/com/google/protobuf/ExtensionList.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt\ java/kotlin/src/main/kotlin/com/google/protobuf/ProtoDslMarker.kt \ @@ -560,13 +561,20 @@ java_EXTRA_DIST= java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto3.proto \ java/kotlin/src/test/proto/com/google/protobuf/example_extensible_message.proto \ java/kotlin/src/test/proto/com/google/protobuf/multiple_files_proto3.proto \ + java/kotlin-lite/BUILD \ java/kotlin-lite/generate-sources-build.xml \ java/kotlin-lite/generate-test-sources-build.xml \ java/kotlin-lite/lite.awk \ java/kotlin-lite/pom.xml \ + java/kotlin-lite/pom_template.xml \ java/kotlin-lite/process-lite-sources-build.xml \ + java/kotlin-lite/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt\ java/kotlin-lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt\ + java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto3LiteTest.kt \ java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt \ + java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto2.proto \ + java/kotlin-lite/src/test/proto/com/google/protobuf/evil_names_proto3.proto \ + java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto \ java/lite.md \ java/lite/BUILD \ java/lite/generate-sources-build.xml \ From 9e65df20a703618cd797828d73834fdd1d5a241d Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 13 Jan 2022 12:50:11 +1100 Subject: [PATCH 138/207] bump extension min version to 7.2 The macro ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX changed in 7.2, so it cannot be used in a compatible way with earlier versions --- php/ext/google/protobuf/package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 12c899ef85..6516373f1b 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -52,7 +52,7 @@ - 7.0.0 + 7.2.0 1.4.0 From a784e515e1db16da2fea60d2ea1c452e44801fe0 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 13 Jan 2022 22:50:11 +0000 Subject: [PATCH 139/207] fix pom errors --- java/kotlin-lite/pom.xml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 2c33cc8c71..fe3938a3e3 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -94,7 +94,6 @@ DslList.kt DslMap.kt DslProxy.kt - ExtendableMessageLiteExtensions.kt ExtensionList.kt OnlyForUseByGeneratedProtoCode.kt ProtoDslMarker.kt @@ -119,14 +118,6 @@ TestUtilLite.java - - ${basedir}/../kotlin/src/test/kotlin/com/google/protobuf - - ExtendableMessageExtensionsTest.kt - Proto2Test.kt - ProtoUtil.java - - @@ -223,8 +214,8 @@ compile - ${generated.sources.dir} ${project.basedir}/src/main/kotlin + ${generated.sources.dir} From 639551d445fd72be1b3dcc9600495f9f124e52fe Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 18 Jan 2022 19:15:32 +0100 Subject: [PATCH 140/207] Disable [[clang::musttail]] attribute on Windows x86 (#9421) --- src/google/protobuf/port_def.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 7e9119112b..aa9a6758a8 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -229,11 +229,13 @@ #ifdef PROTOBUF_TAILCALL #error PROTOBUF_TAILCALL was previously defined #endif -#if __has_cpp_attribute(clang::musttail) && \ - !defined(__arm__) && !defined(_ARCH_PPC) && !defined(__wasm__) +#if __has_cpp_attribute(clang::musttail) && \ + !defined(__arm__) && !defined(_ARCH_PPC) && !defined(__wasm__) && \ + !(defined(_MSC_VER) && defined(_M_IX86)) # ifndef PROTO2_OPENSOURCE // Compilation fails on ARM32: b/195943306 // Compilation fails on powerpc64le: b/187985113 +// Compilation fails on X86 Windows: https://github.com/llvm/llvm-project/issues/53271 # endif #define PROTOBUF_MUSTTAIL [[clang::musttail]] #define PROTOBUF_TAILCALL true From bfe33d7d080fb317e6650cf1682ed1f412dbf13a Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 20 Jan 2022 09:33:58 +1100 Subject: [PATCH 141/207] php 7.0 support instead of using the void return type, add more ReturnTypeWillChange annotations --- php/composer.json | 2 +- php/src/Google/Protobuf/Internal/MapField.php | 6 ++++-- php/src/Google/Protobuf/Internal/MapFieldIter.php | 6 ++++-- php/src/Google/Protobuf/Internal/RepeatedField.php | 6 ++++-- php/src/Google/Protobuf/Internal/RepeatedFieldIter.php | 6 ++++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/php/composer.json b/php/composer.json index d0d50ce713..71a1e758f1 100644 --- a/php/composer.json +++ b/php/composer.json @@ -6,7 +6,7 @@ "homepage": "https://developers.google.com/protocol-buffers/", "license": "BSD-3-Clause", "require": { - "php": ">=7.1.0", + "php": ">=7.0.0", "ext-bcmath": "*" }, "require-dev": { diff --git a/php/src/Google/Protobuf/Internal/MapField.php b/php/src/Google/Protobuf/Internal/MapField.php index 20ac6c2d66..86463a9a47 100644 --- a/php/src/Google/Protobuf/Internal/MapField.php +++ b/php/src/Google/Protobuf/Internal/MapField.php @@ -154,7 +154,8 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Invalid type for value. * @throws \ErrorException Non-existing key. */ - public function offsetSet($key, $value): void + #[\ReturnTypeWillChange] + public function offsetSet($key, $value) { $this->checkKey($this->key_type, $key); @@ -212,7 +213,8 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @return void * @throws \ErrorException Invalid type for key. */ - public function offsetUnset($key): void + #[\ReturnTypeWillChange] + public function offsetUnset($key) { $this->checkKey($this->key_type, $key); unset($this->container[$key]); diff --git a/php/src/Google/Protobuf/Internal/MapFieldIter.php b/php/src/Google/Protobuf/Internal/MapFieldIter.php index 8370787876..a3c834bd2c 100644 --- a/php/src/Google/Protobuf/Internal/MapFieldIter.php +++ b/php/src/Google/Protobuf/Internal/MapFieldIter.php @@ -68,7 +68,8 @@ class MapFieldIter implements \Iterator * * @return void */ - public function rewind(): void + #[\ReturnTypeWillChange] + public function rewind() { reset($this->container); } @@ -119,7 +120,8 @@ class MapFieldIter implements \Iterator * * @return void */ - public function next(): void + #[\ReturnTypeWillChange] + public function next() { next($this->container); } diff --git a/php/src/Google/Protobuf/Internal/RepeatedField.php b/php/src/Google/Protobuf/Internal/RepeatedField.php index e589b644fe..704123ad15 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -140,7 +140,8 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Non-existing index. * @throws \ErrorException Incorrect type of the element. */ - public function offsetSet($offset, $value): void + #[\ReturnTypeWillChange] + public function offsetSet($offset, $value) { switch ($this->type) { case GPBType::SFIXED32: @@ -211,7 +212,8 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException The element to be removed is not at the end of the * RepeatedField. */ - public function offsetUnset($offset): void + #[\ReturnTypeWillChange] + public function offsetUnset($offset) { $count = count($this->container); if (!is_numeric($offset) || $count === 0 || $offset !== $count - 1) { diff --git a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php index ad86f95f94..3c85869989 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php +++ b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php @@ -71,7 +71,8 @@ class RepeatedFieldIter implements \Iterator * * @return void */ - public function rewind(): void + #[\ReturnTypeWillChange] + public function rewind() { $this->position = 0; } @@ -103,7 +104,8 @@ class RepeatedFieldIter implements \Iterator * * @return void */ - public function next(): void + #[\ReturnTypeWillChange] + public function next() { ++$this->position; } From f689268ca3c6a7dfdf3f65701d7b25a4bd311abb Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 20 Jan 2022 12:01:51 +1100 Subject: [PATCH 142/207] fixing typo in comment --- php/ext/google/protobuf/protobuf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 4490d683bf..3b145fafca 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -84,7 +84,7 @@ const zval *get_generated_pool(); #define zend_ce_countable spl_ce_Countable #endif -// In PHP 8.1, mismatched tentative return types emit a depracation notice. +// In PHP 8.1, mismatched tentative return types emit a deprecation notice. // https://wiki.php.net/rfc/internal_method_return_types // // When compiling for earlier php versions, the return type is dropped. From 6e8b0dfcbfc24bd5a68b1e93b6d288020b2819fb Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 20 Jan 2022 22:24:59 +0000 Subject: [PATCH 143/207] Switch to java_test --- java/kotlin-lite/BUILD | 29 +++++++++++++++++++------- java/kotlin/BUILD | 47 ++++++++++++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/java/kotlin-lite/BUILD b/java/kotlin-lite/BUILD index c9dab1d2de..bfd7b8d02b 100644 --- a/java/kotlin-lite/BUILD +++ b/java/kotlin-lite/BUILD @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_lite_proto_library") java_lite_proto_library( @@ -21,8 +21,8 @@ test_suite( ], ) -kt_jvm_test( - name = "test_lite_extensions", +kt_jvm_library( + name = "test_lite_extensions_library", srcs = ["src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt"], deps = [ ":example_extensible_message_java_proto_lite", @@ -34,6 +34,11 @@ kt_jvm_test( "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], +) + +java_test( + name = "test_lite_extensions", + runtime_deps = [":test_lite_extensions_library"], test_class = "com.google.protobuf.kotlin.ExtendableMessageLiteExtensionsTest", ) @@ -144,8 +149,8 @@ kt_jvm_library( ], ) -kt_jvm_test( - name = "proto2_test_lite", +kt_jvm_library( + name = "proto2_test_lite_library", srcs = ["src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt"], deps = [ ":kotlin_unittest_lite", @@ -153,11 +158,16 @@ kt_jvm_test( "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], +) + +java_test( + name = "proto2_test_lite", + runtime_deps = [":proto2_test_lite_library"], test_class = "com.google.protobuf.kotlin.Proto2LiteTest", ) -kt_jvm_test( - name = "proto3_test_lite", +kt_jvm_library( + name = "proto3_test_lite_library", srcs = ["src/test/kotlin/com/google/protobuf/Proto3LiteTest.kt"], deps = [ ":kotlin_proto3_unittest_lite", @@ -165,5 +175,10 @@ kt_jvm_test( "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], +) + +java_test( + name = "proto3_test_lite", + runtime_deps = [":proto3_test_lite_library"], test_class = "com.google.protobuf.kotlin.Proto3LiteTest", ) diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD index 2be2195bc3..5403e6f201 100644 --- a/java/kotlin/BUILD +++ b/java/kotlin/BUILD @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test", "kt_jvm_binary") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_proto_library") load("@rules_proto//proto:defs.bzl", "proto_library") load("//:protobuf_version.bzl", "PROTOBUF_VERSION") @@ -50,8 +50,8 @@ test_suite( ], ) -kt_jvm_test( - name = "bytestring_test", +kt_jvm_library( + name = "bytestring_test_library", srcs = ["src/test/kotlin/com/google/protobuf/ByteStringsTest.kt"], deps = [ ":bytestring_lib", @@ -60,6 +60,11 @@ kt_jvm_test( "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], +) + +java_test( + name = "bytestring_test", + runtime_deps = [":bytestring_test_library"], test_class = "com.google.protobuf.kotlin.ByteStringsTest", ) @@ -74,8 +79,8 @@ java_proto_library( deps = [":example_extensible_message_proto"], ) -kt_jvm_test( - name = "shared_tests", +kt_jvm_library( + name = "shared_tests_library", srcs = [ "src/test/kotlin/com/google/protobuf/DslListTest.kt", "src/test/kotlin/com/google/protobuf/DslMapTest.kt", @@ -91,11 +96,16 @@ kt_jvm_test( "@maven//:com_google_guava_guava_testlib", "@maven//:junit_junit", ], +) + +java_test( + name = "shared_tests", + runtime_deps = [":shared_tests_library"], test_class = "com.google.protobuf.kotlin.DslListTest", ) -kt_jvm_test( - name = "test_extensions", +kt_jvm_library( + name = "test_extensions_library", srcs = ["src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt"], deps = [ ":example_extensible_message_java_proto", @@ -107,6 +117,11 @@ kt_jvm_test( "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], +) + +java_test( + name = "test_extensions", + runtime_deps = [":test_extensions_library"], test_class = "com.google.protobuf.kotlin.ExtendableMessageExtensionsTest", ) @@ -234,8 +249,8 @@ kt_jvm_library( ], ) -kt_jvm_test( - name = "proto2_test", +kt_jvm_library( + name = "proto2_test_library", srcs = ["src/test/kotlin/com/google/protobuf/Proto2Test.kt"], deps = [ ":kotlin_unittest", @@ -243,11 +258,16 @@ kt_jvm_test( "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], +) + +java_test( + name = "proto2_test", + runtime_deps = [":proto2_test_library"], test_class = "com.google.protobuf.kotlin.Proto2Test", ) -kt_jvm_test( - name = "proto3_test", +kt_jvm_library( + name = "proto3_test_library", srcs = ["src/test/kotlin/com/google/protobuf/Proto3Test.kt"], deps = [ ":kotlin_proto3_unittest", @@ -255,5 +275,10 @@ kt_jvm_test( "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], +) + +java_test( + name = "proto3_test", + runtime_deps = [":proto3_test_library"], test_class = "com.google.protobuf.kotlin.Proto3Test", ) From 70131e049584dd7a00814047c3a094c39ef2e859 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Thu, 20 Jan 2022 14:31:53 -0800 Subject: [PATCH 144/207] Update location of llvm-ar in bazel toolchain Change the location of the llvm-ar tool to match the new docker container. --- toolchain/cc_toolchain_config.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 6310c69762..1d54c1d70d 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -47,7 +47,7 @@ def _impl(ctx): ), tool_path( name = "ar", - path = "/usr/bin/llvm-ar", + path = "/usr/local/bin/llvm-ar", ), tool_path( name = "compat-ld", From c62cbe97deaae64aee16fd13a0f5c5050f2c9841 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 21 Jan 2022 09:59:46 +1100 Subject: [PATCH 145/207] working 7.0 extension --- php/ext/google/protobuf/array.c | 51 ++++++++++++++++++++++++++--- php/ext/google/protobuf/map.c | 14 ++++---- php/ext/google/protobuf/package.xml | 2 +- php/ext/google/protobuf/protobuf.h | 12 +++++++ 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index 1ef72c4e40..70db6da988 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -459,29 +459,53 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) +#if PHP_VERSION_ID < 70200 +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetExists, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) + ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetUnset, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_count, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_getIterator, 0) +ZEND_END_ARG_INFO() +#else ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, newval) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() +#endif static zend_function_entry repeated_field_methods[] = { PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) @@ -628,6 +652,22 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } +#if PHP_VERSION_ID < 70200 +ZEND_BEGIN_ARG_INFO(arginfo_current, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_key, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_next, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_valid, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_rewind, 0) +ZEND_END_ARG_INFO() +#else ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() @@ -642,6 +682,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() +#endif static zend_function_entry repeated_field_iter_methods[] = { PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index 014e56afbd..859cc6d0c6 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -458,23 +458,23 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MI ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0, /*is_null*/ 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0, /*is_null*/ 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0, /*is_null*/ 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0, /*is_null*/ 0) ZEND_END_ARG_INFO() static zend_function_entry MapField_methods[] = { @@ -624,7 +624,7 @@ PHP_METHOD(MapFieldIter, valid) { RETURN_BOOL(!done); } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0, /*is_null*/ 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) @@ -633,10 +633,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0, /*is_null*/ 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0, /*is_null*/ 0) ZEND_END_ARG_INFO() static zend_function_entry map_field_iter_methods[] = { diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 6516373f1b..12c899ef85 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -52,7 +52,7 @@ - 7.2.0 + 7.0.0 1.4.0 diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 3b145fafca..d5f8021888 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -82,6 +82,8 @@ const zval *get_generated_pool(); // PHP 7.2.0. #if PHP_VERSION_ID < 70200 #define zend_ce_countable spl_ce_Countable +#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \ + ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null) #endif // In PHP 8.1, mismatched tentative return types emit a deprecation notice. @@ -94,6 +96,16 @@ const zval *get_generated_pool(); #define IS_MIXED 16 #endif +#if PHP_VERSION_ID < 70100 +#define IS_VOID 99 +#endif + +#ifndef IS_MIXED +#define IS_MIXED 99 +#define IS_BOOL 99 +#define IS_LONG 99 +#endif + ZEND_BEGIN_ARG_INFO(arginfo_void, 0) ZEND_END_ARG_INFO() From 16941420c93f11f7480f6be47006419296a234f2 Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Fri, 21 Jan 2022 05:29:40 +0100 Subject: [PATCH 146/207] Fixed NullReferenceException when accessing FieldDescriptor.IsPacked --- csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index f9b90619ad..51d8735313 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -239,7 +239,8 @@ namespace Google.Protobuf.Reflection } else { - return !Proto.Options.HasPacked || Proto.Options.Packed; + // Packed by default with proto3 + return Proto.Options == null || !Proto.Options.HasPacked || Proto.Options.Packed; } } } From f41049a0f054e5548e672202341c3607ac1ed912 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 21 Jan 2022 14:41:25 -0800 Subject: [PATCH 147/207] Updated upb. --- ruby/ext/google/protobuf_c/ruby-upb.c | 8024 +++++++++++++++---------- ruby/ext/google/protobuf_c/ruby-upb.h | 3984 ++++++------ 2 files changed, 7222 insertions(+), 4786 deletions(-) diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index d68caac0e2..294be7f198 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -264,25 +264,25 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); /* Maps descriptor type -> elem_size_lg2. */ static const uint8_t desctype_to_elem_size_lg2[] = { - -1, /* invalid descriptor type */ - 3, /* DOUBLE */ - 2, /* FLOAT */ - 3, /* INT64 */ - 3, /* UINT64 */ - 2, /* INT32 */ - 3, /* FIXED64 */ - 2, /* FIXED32 */ - 0, /* BOOL */ - UPB_SIZE(3, 4), /* STRING */ - UPB_SIZE(2, 3), /* GROUP */ - UPB_SIZE(2, 3), /* MESSAGE */ - UPB_SIZE(3, 4), /* BYTES */ - 2, /* UINT32 */ - 2, /* ENUM */ - 2, /* SFIXED32 */ - 3, /* SFIXED64 */ - 2, /* SINT32 */ - 3, /* SINT64 */ + -1, /* invalid descriptor type */ + 3, /* DOUBLE */ + 2, /* FLOAT */ + 3, /* INT64 */ + 3, /* UINT64 */ + 2, /* INT32 */ + 3, /* FIXED64 */ + 2, /* FIXED32 */ + 0, /* BOOL */ + UPB_SIZE(3, 4), /* STRING */ + UPB_SIZE(2, 3), /* GROUP */ + UPB_SIZE(2, 3), /* MESSAGE */ + UPB_SIZE(3, 4), /* BYTES */ + 2, /* UINT32 */ + 2, /* ENUM */ + 2, /* SFIXED32 */ + 3, /* SFIXED64 */ + 2, /* SINT32 */ + 3, /* SINT64 */ }; /* Maps descriptor type -> upb map size. */ @@ -297,8 +297,8 @@ static const uint8_t desctype_to_mapsize[] = { 4, /* FIXED32 */ 1, /* BOOL */ UPB_MAPTYPE_STRING, /* STRING */ - sizeof(void *), /* GROUP */ - sizeof(void *), /* MESSAGE */ + sizeof(void*), /* GROUP */ + sizeof(void*), /* MESSAGE */ UPB_MAPTYPE_STRING, /* BYTES */ 4, /* UINT32 */ 4, /* ENUM */ @@ -308,66 +308,80 @@ static const uint8_t desctype_to_mapsize[] = { 8, /* SINT64 */ }; -static const unsigned fixed32_ok = (1 << UPB_DTYPE_FLOAT) | - (1 << UPB_DTYPE_FIXED32) | - (1 << UPB_DTYPE_SFIXED32); +static const unsigned FIXED32_OK_MASK = (1 << kUpb_FieldType_Float) | + (1 << kUpb_FieldType_Fixed32) | + (1 << kUpb_FieldType_SFixed32); -static const unsigned fixed64_ok = (1 << UPB_DTYPE_DOUBLE) | - (1 << UPB_DTYPE_FIXED64) | - (1 << UPB_DTYPE_SFIXED64); +static const unsigned FIXED64_OK_MASK = (1 << kUpb_FieldType_Double) | + (1 << kUpb_FieldType_Fixed64) | + (1 << kUpb_FieldType_SFixed64); + +/* Three fake field types for MessageSet. */ +#define TYPE_MSGSET_ITEM 19 +#define TYPE_MSGSET_TYPE_ID 20 +#define TYPE_COUNT 20 /* Op: an action to be performed for a wire-type/field-type combination. */ -#define OP_SCALAR_LG2(n) (n) /* n in [0, 2, 3] => op in [0, 2, 3] */ +#define OP_UNKNOWN -1 /* Unknown field. */ +#define OP_MSGSET_ITEM -2 +#define OP_MSGSET_TYPEID -3 +#define OP_SCALAR_LG2(n) (n) /* n in [0, 2, 3] => op in [0, 2, 3] */ +#define OP_ENUM 1 #define OP_STRING 4 #define OP_BYTES 5 #define OP_SUBMSG 6 -/* Ops above are scalar-only. Repeated fields can use any op. */ -#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ -#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ - -static const int8_t varint_ops[19] = { - -1, /* field not found */ - -1, /* DOUBLE */ - -1, /* FLOAT */ +/* Scalar fields use only ops above. Repeated fields can use any op. */ +#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ +#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ +#define OP_PACKED_ENUM 13 + +static const int8_t varint_ops[] = { + OP_UNKNOWN, /* field not found */ + OP_UNKNOWN, /* DOUBLE */ + OP_UNKNOWN, /* FLOAT */ OP_SCALAR_LG2(3), /* INT64 */ OP_SCALAR_LG2(3), /* UINT64 */ OP_SCALAR_LG2(2), /* INT32 */ - -1, /* FIXED64 */ - -1, /* FIXED32 */ + OP_UNKNOWN, /* FIXED64 */ + OP_UNKNOWN, /* FIXED32 */ OP_SCALAR_LG2(0), /* BOOL */ - -1, /* STRING */ - -1, /* GROUP */ - -1, /* MESSAGE */ - -1, /* BYTES */ + OP_UNKNOWN, /* STRING */ + OP_UNKNOWN, /* GROUP */ + OP_UNKNOWN, /* MESSAGE */ + OP_UNKNOWN, /* BYTES */ OP_SCALAR_LG2(2), /* UINT32 */ - OP_SCALAR_LG2(2), /* ENUM */ - -1, /* SFIXED32 */ - -1, /* SFIXED64 */ + OP_ENUM, /* ENUM */ + OP_UNKNOWN, /* SFIXED32 */ + OP_UNKNOWN, /* SFIXED64 */ OP_SCALAR_LG2(2), /* SINT32 */ OP_SCALAR_LG2(3), /* SINT64 */ + OP_UNKNOWN, /* MSGSET_ITEM */ + OP_MSGSET_TYPEID, /* MSGSET TYPEID */ }; -static const int8_t delim_ops[37] = { +static const int8_t delim_ops[] = { /* For non-repeated field type. */ - -1, /* field not found */ - -1, /* DOUBLE */ - -1, /* FLOAT */ - -1, /* INT64 */ - -1, /* UINT64 */ - -1, /* INT32 */ - -1, /* FIXED64 */ - -1, /* FIXED32 */ - -1, /* BOOL */ - OP_STRING, /* STRING */ - -1, /* GROUP */ - OP_SUBMSG, /* MESSAGE */ - OP_BYTES, /* BYTES */ - -1, /* UINT32 */ - -1, /* ENUM */ - -1, /* SFIXED32 */ - -1, /* SFIXED64 */ - -1, /* SINT32 */ - -1, /* SINT64 */ + OP_UNKNOWN, /* field not found */ + OP_UNKNOWN, /* DOUBLE */ + OP_UNKNOWN, /* FLOAT */ + OP_UNKNOWN, /* INT64 */ + OP_UNKNOWN, /* UINT64 */ + OP_UNKNOWN, /* INT32 */ + OP_UNKNOWN, /* FIXED64 */ + OP_UNKNOWN, /* FIXED32 */ + OP_UNKNOWN, /* BOOL */ + OP_STRING, /* STRING */ + OP_UNKNOWN, /* GROUP */ + OP_SUBMSG, /* MESSAGE */ + OP_BYTES, /* BYTES */ + OP_UNKNOWN, /* UINT32 */ + OP_UNKNOWN, /* ENUM */ + OP_UNKNOWN, /* SFIXED32 */ + OP_UNKNOWN, /* SFIXED64 */ + OP_UNKNOWN, /* SINT32 */ + OP_UNKNOWN, /* SINT64 */ + OP_UNKNOWN, /* MSGSET_ITEM */ + OP_UNKNOWN, /* MSGSET TYPEID */ /* For repeated field type. */ OP_FIXPCK_LG2(3), /* REPEATED DOUBLE */ OP_FIXPCK_LG2(2), /* REPEATED FLOAT */ @@ -382,11 +396,12 @@ static const int8_t delim_ops[37] = { OP_SUBMSG, /* REPEATED MESSAGE */ OP_BYTES, /* REPEATED BYTES */ OP_VARPCK_LG2(2), /* REPEATED UINT32 */ - OP_VARPCK_LG2(2), /* REPEATED ENUM */ + OP_PACKED_ENUM, /* REPEATED ENUM */ OP_FIXPCK_LG2(2), /* REPEATED SFIXED32 */ OP_FIXPCK_LG2(3), /* REPEATED SFIXED64 */ OP_VARPCK_LG2(2), /* REPEATED SINT32 */ OP_VARPCK_LG2(3), /* REPEATED SINT64 */ + /* Omitting MSGSET_*, because we never emit a repeated msgset type */ }; typedef union { @@ -396,61 +411,39 @@ typedef union { uint32_t size; } wireval; -static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *layout); - -UPB_NORETURN static void decode_err(upb_decstate *d) { UPB_LONGJMP(d->err, 1); } +static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout); -// We don't want to mark this NORETURN, see comment in .h. -// Unfortunately this code to suppress the warning doesn't appear to be working. -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunknown-warning-option" -#pragma clang diagnostic ignored "-Wsuggest-attribute" -#endif +UPB_NORETURN static void* decode_err(upb_Decoder* d, upb_DecodeStatus status) { + assert(status != kUpb_DecodeStatus_Ok); + UPB_LONGJMP(d->err, status); +} -const char *fastdecode_err(upb_decstate *d) { - longjmp(d->err, 1); +const char* fastdecode_err(upb_Decoder* d, int status) { + assert(status != kUpb_DecodeStatus_Ok); + UPB_LONGJMP(d->err, status); return NULL; } - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -const uint8_t upb_utf8_offsets[] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, -}; - -static void decode_verifyutf8(upb_decstate *d, const char *buf, int len) { - if (!decode_verifyutf8_inl(buf, len)) decode_err(d); +static void decode_verifyutf8(upb_Decoder* d, const char* buf, int len) { + if (!decode_verifyutf8_inl(buf, len)) + decode_err(d, kUpb_DecodeStatus_BadUtf8); } -static bool decode_reserve(upb_decstate *d, upb_array *arr, size_t elem) { +static bool decode_reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { bool need_realloc = arr->size - arr->len < elem; if (need_realloc && !_upb_array_realloc(arr, arr->len + elem, &d->arena)) { - decode_err(d); + decode_err(d, kUpb_DecodeStatus_OutOfMemory); } return need_realloc; } typedef struct { - const char *ptr; + const char* ptr; uint64_t val; } decode_vret; UPB_NOINLINE -static decode_vret decode_longvarint64(const char *ptr, uint64_t val) { +static decode_vret decode_longvarint64(const char* ptr, uint64_t val) { decode_vret ret = {NULL, 0}; uint64_t byte; int i; @@ -467,120 +460,92 @@ static decode_vret decode_longvarint64(const char *ptr, uint64_t val) { } UPB_FORCEINLINE -static const char *decode_varint64(upb_decstate *d, const char *ptr, - uint64_t *val) { +static const char* decode_varint64(upb_Decoder* d, const char* ptr, + uint64_t* val) { uint64_t byte = (uint8_t)*ptr; if (UPB_LIKELY((byte & 0x80) == 0)) { *val = byte; return ptr + 1; } else { decode_vret res = decode_longvarint64(ptr, byte); - if (!res.ptr) decode_err(d); + if (!res.ptr) return decode_err(d, kUpb_DecodeStatus_Malformed); *val = res.val; return res.ptr; } } UPB_FORCEINLINE -static const char *decode_tag(upb_decstate *d, const char *ptr, - uint32_t *val) { +static const char* decode_tag(upb_Decoder* d, const char* ptr, uint32_t* val) { uint64_t byte = (uint8_t)*ptr; if (UPB_LIKELY((byte & 0x80) == 0)) { *val = byte; return ptr + 1; } else { - const char *start = ptr; + const char* start = ptr; decode_vret res = decode_longvarint64(ptr, byte); - ptr = res.ptr; + if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { + return decode_err(d, kUpb_DecodeStatus_Malformed); + } *val = res.val; - if (!ptr || *val > UINT32_MAX || ptr - start > 5) decode_err(d); - return ptr; + return res.ptr; } } -static void decode_munge(int type, wireval *val) { +static void decode_munge_int32(wireval* val) { + if (!_upb_IsLittleEndian()) { + /* The next stage will memcpy(dst, &val, 4) */ + val->uint32_val = val->uint64_val; + } +} + +static void decode_munge(int type, wireval* val) { switch (type) { - case UPB_DESCRIPTOR_TYPE_BOOL: + case kUpb_FieldType_Bool: val->bool_val = val->uint64_val != 0; break; - case UPB_DESCRIPTOR_TYPE_SINT32: { - uint32_t n = val->uint32_val; + case kUpb_FieldType_SInt32: { + uint32_t n = val->uint64_val; val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); break; } - case UPB_DESCRIPTOR_TYPE_SINT64: { + case kUpb_FieldType_SInt64: { uint64_t n = val->uint64_val; val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); break; } - case UPB_DESCRIPTOR_TYPE_INT32: - case UPB_DESCRIPTOR_TYPE_UINT32: - if (!_upb_isle()) { - /* The next stage will memcpy(dst, &val, 4) */ - val->uint32_val = val->uint64_val; - } + case kUpb_FieldType_Int32: + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Enum: + decode_munge_int32(val); break; } } -static const upb_msglayout_field *upb_find_field(const upb_msglayout *l, - uint32_t field_number, - int *last_field_index) { - static upb_msglayout_field none = {0, 0, 0, 0, 0, 0}; - - if (l == NULL) return &none; - - size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX - if (idx < l->dense_below) { - goto found; - } - - /* Resume scanning from last_field_index since fields are usually in order. */ - int last = *last_field_index; - for (idx = last; idx < l->field_count; idx++) { - if (l->fields[idx].number == field_number) { - goto found; - } - } - - for (idx = 0; idx < last; idx++) { - if (l->fields[idx].number == field_number) { - goto found; - } - } - - return &none; /* Unknown field. */ - - found: - UPB_ASSERT(l->fields[idx].number == field_number); - *last_field_index = idx; - return &l->fields[idx]; -} - -static upb_msg *decode_newsubmsg(upb_decstate *d, - upb_msglayout const *const *submsgs, - const upb_msglayout_field *field) { - const upb_msglayout *subl = submsgs[field->submsg_index]; - return _upb_msg_new_inl(subl, &d->arena); +static upb_Message* decode_newsubmsg(upb_Decoder* d, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + const upb_MiniTable* subl = subs[field->submsg_index].submsg; + return _upb_Message_New_inl(subl, &d->arena); } UPB_NOINLINE -const char *decode_isdonefallback(upb_decstate *d, const char *ptr, +const char* decode_isdonefallback(upb_Decoder* d, const char* ptr, int overrun) { - ptr = decode_isdonefallback_inl(d, ptr, overrun); + int status; + ptr = decode_isdonefallback_inl(d, ptr, overrun, &status); if (ptr == NULL) { - decode_err(d); + return decode_err(d, status); } return ptr; } -static const char *decode_readstr(upb_decstate *d, const char *ptr, int size, - upb_strview *str) { - if (d->alias) { +static const char* decode_readstr(upb_Decoder* d, const char* ptr, int size, + upb_StringView* str) { + if (d->options & kUpb_DecodeOption_AliasString) { str->data = ptr; } else { - char *data = upb_arena_malloc(&d->arena, size); - if (!data) decode_err(d); + char* data = upb_Arena_Malloc(&d->arena, size); + if (!data) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); memcpy(data, ptr, size); str->data = data; } @@ -589,61 +554,222 @@ static const char *decode_readstr(upb_decstate *d, const char *ptr, int size, } UPB_FORCEINLINE -static const char *decode_tosubmsg(upb_decstate *d, const char *ptr, - upb_msg *submsg, - upb_msglayout const *const *submsgs, - const upb_msglayout_field *field, int size) { - const upb_msglayout *subl = submsgs[field->submsg_index]; +static const char* decode_tosubmsg2(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, int size) { int saved_delta = decode_pushlimit(d, ptr, size); - if (--d->depth < 0) decode_err(d); - if (!decode_isdone(d, &ptr)) { - ptr = decode_msg(d, ptr, submsg, subl); - } - if (d->end_group != DECODE_NOGROUP) decode_err(d); + if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); + ptr = decode_msg(d, ptr, submsg, subl); + if (d->end_group != DECODE_NOGROUP) + return decode_err(d, kUpb_DecodeStatus_Malformed); decode_poplimit(d, ptr, saved_delta); d->depth++; return ptr; } UPB_FORCEINLINE -static const char *decode_group(upb_decstate *d, const char *ptr, - upb_msg *submsg, const upb_msglayout *subl, +static const char* decode_tosubmsg(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, int size) { + return decode_tosubmsg2(d, ptr, submsg, subs[field->submsg_index].submsg, + size); +} + +UPB_FORCEINLINE +static const char* decode_group(upb_Decoder* d, const char* ptr, + upb_Message* submsg, const upb_MiniTable* subl, uint32_t number) { - if (--d->depth < 0) decode_err(d); + if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); if (decode_isdone(d, &ptr)) { - decode_err(d); + return decode_err(d, kUpb_DecodeStatus_Malformed); } ptr = decode_msg(d, ptr, submsg, subl); - if (d->end_group != number) decode_err(d); + if (d->end_group != number) return decode_err(d, kUpb_DecodeStatus_Malformed); d->end_group = DECODE_NOGROUP; d->depth++; return ptr; } UPB_FORCEINLINE -static const char *decode_togroup(upb_decstate *d, const char *ptr, - upb_msg *submsg, - upb_msglayout const *const *submsgs, - const upb_msglayout_field *field) { - const upb_msglayout *subl = submsgs[field->submsg_index]; +static const char* decode_togroup(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + const upb_MiniTable* subl = subs[field->submsg_index].submsg; return decode_group(d, ptr, submsg, subl, field->number); } -static const char *decode_toarray(upb_decstate *d, const char *ptr, - upb_msg *msg, - upb_msglayout const *const *submsgs, - const upb_msglayout_field *field, wireval *val, - int op) { - upb_array **arrp = UPB_PTR_AT(msg, field->offset, void); - upb_array *arr = *arrp; - void *mem; +static char* encode_varint32(uint32_t val, char* ptr) { + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + *(ptr++) = byte; + } while (val); + return ptr; +} + +UPB_NOINLINE +static bool decode_checkenum_slow(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Enum* e, + const upb_MiniTable_Field* field, + uint32_t v) { + // OPT: binary search long lists? + int n = e->value_count; + for (int i = 0; i < n; i++) { + if ((uint32_t)e->values[i] == v) return true; + } + + // Unrecognized enum goes into unknown fields. + // For packed fields the tag could be arbitrarily far in the past, so we + // just re-encode the tag here. + char buf[20]; + char* end = buf; + uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint; + end = encode_varint32(tag, end); + end = encode_varint32(v, end); + + if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + + return false; +} + +UPB_FORCEINLINE +static bool decode_checkenum(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable_Enum* e, + const upb_MiniTable_Field* field, wireval* val) { + uint32_t v = val->uint32_val; + + if (UPB_LIKELY(v < 64) && UPB_LIKELY(((1ULL << v) & e->mask))) return true; + + return decode_checkenum_slow(d, ptr, msg, e, field, v); +} + +UPB_NOINLINE +static const char* decode_enum_toarray(upb_Decoder* d, const char* ptr, + upb_Message* msg, upb_Array* arr, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; + if (!decode_checkenum(d, ptr, msg, e, field, val)) return ptr; + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + arr->len++; + memcpy(mem, val, 4); + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_fixed_packed(upb_Decoder* d, const char* ptr, + upb_Array* arr, wireval* val, + const upb_MiniTable_Field* field, + int lg2) { + int mask = (1 << lg2) - 1; + size_t count = val->size >> lg2; + if ((val->size & mask) != 0) { + // Length isn't a round multiple of elem size. + return decode_err(d, kUpb_DecodeStatus_Malformed); + } + decode_reserve(d, arr, count); + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + arr->len += count; + // Note: if/when the decoder supports multi-buffer input, we will need to + // handle buffer seams here. + if (_upb_IsLittleEndian()) { + memcpy(mem, ptr, val->size); + ptr += val->size; + } else { + const char* end = ptr + val->size; + char* dst = mem; + while (ptr < end) { + if (lg2 == 2) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap32(val); + memcpy(dst, &val, sizeof(val)); + } else { + UPB_ASSERT(lg2 == 3); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap64(val); + memcpy(dst, &val, sizeof(val)); + } + ptr += 1 << lg2; + dst += 1 << lg2; + } + } + + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_varint_packed(upb_Decoder* d, const char* ptr, + upb_Array* arr, wireval* val, + const upb_MiniTable_Field* field, + int lg2) { + int scale = 1 << lg2; + int saved_limit = decode_pushlimit(d, ptr, val->size); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + while (!decode_isdone(d, &ptr)) { + wireval elem; + ptr = decode_varint64(d, ptr, &elem.uint64_val); + decode_munge(field->descriptortype, &elem); + if (decode_reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + } + arr->len++; + memcpy(out, &elem, scale); + out += scale; + } + decode_poplimit(d, ptr, saved_limit); + return ptr; +} + +UPB_NOINLINE +static const char* decode_enum_packed(upb_Decoder* d, const char* ptr, + upb_Message* msg, upb_Array* arr, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; + int saved_limit = decode_pushlimit(d, ptr, val->size); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + while (!decode_isdone(d, &ptr)) { + wireval elem; + ptr = decode_varint64(d, ptr, &elem.uint64_val); + decode_munge_int32(&elem); + if (!decode_checkenum(d, ptr, msg, e, field, &elem)) { + continue; + } + if (decode_reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + } + arr->len++; + memcpy(out, &elem, 4); + out += 4; + } + decode_poplimit(d, ptr, saved_limit); + return ptr; +} + +static const char* decode_toarray(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val, int op) { + upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); + upb_Array* arr = *arrp; + void* mem; if (arr) { decode_reserve(d, arr, 1); } else { size_t lg2 = desctype_to_elem_size_lg2[field->descriptortype]; - arr = _upb_array_new(&d->arena, 4, lg2); - if (!arr) decode_err(d); + arr = _upb_Array_New(&d->arena, 4, lg2); + if (!arr) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); *arrp = arr; } @@ -661,111 +787,95 @@ static const char *decode_toarray(upb_decstate *d, const char *ptr, /* Fallthrough. */ case OP_BYTES: { /* Append bytes. */ - upb_strview *str = (upb_strview*)_upb_array_ptr(arr) + arr->len; + upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->len; arr->len++; return decode_readstr(d, ptr, val->size, str); } case OP_SUBMSG: { /* Append submessage / group. */ - upb_msg *submsg = decode_newsubmsg(d, submsgs, field); - *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void *), upb_msg *) = + upb_Message* submsg = decode_newsubmsg(d, subs, field); + *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void*), upb_Message*) = submsg; arr->len++; - if (UPB_UNLIKELY(field->descriptortype == UPB_DTYPE_GROUP)) { - return decode_togroup(d, ptr, submsg, submsgs, field); + if (UPB_UNLIKELY(field->descriptortype == kUpb_FieldType_Group)) { + return decode_togroup(d, ptr, submsg, subs, field); } else { - return decode_tosubmsg(d, ptr, submsg, submsgs, field, val->size); + return decode_tosubmsg(d, ptr, submsg, subs, field, val->size); } } case OP_FIXPCK_LG2(2): - case OP_FIXPCK_LG2(3): { - /* Fixed packed. */ - int lg2 = op - OP_FIXPCK_LG2(0); - int mask = (1 << lg2) - 1; - size_t count = val->size >> lg2; - if ((val->size & mask) != 0) { - decode_err(d); /* Length isn't a round multiple of elem size. */ - } - decode_reserve(d, arr, count); - mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); - arr->len += count; - memcpy(mem, ptr, val->size); /* XXX: ptr boundary. */ - return ptr + val->size; - } + case OP_FIXPCK_LG2(3): + return decode_fixed_packed(d, ptr, arr, val, field, + op - OP_FIXPCK_LG2(0)); case OP_VARPCK_LG2(0): case OP_VARPCK_LG2(2): - case OP_VARPCK_LG2(3): { - /* Varint packed. */ - int lg2 = op - OP_VARPCK_LG2(0); - int scale = 1 << lg2; - int saved_limit = decode_pushlimit(d, ptr, val->size); - char *out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); - while (!decode_isdone(d, &ptr)) { - wireval elem; - ptr = decode_varint64(d, ptr, &elem.uint64_val); - decode_munge(field->descriptortype, &elem); - if (decode_reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); - } - arr->len++; - memcpy(out, &elem, scale); - out += scale; - } - decode_poplimit(d, ptr, saved_limit); - return ptr; - } + case OP_VARPCK_LG2(3): + return decode_varint_packed(d, ptr, arr, val, field, + op - OP_VARPCK_LG2(0)); + case OP_ENUM: + return decode_enum_toarray(d, ptr, msg, arr, subs, field, val); + case OP_PACKED_ENUM: + return decode_enum_packed(d, ptr, msg, arr, subs, field, val); default: UPB_UNREACHABLE(); } } -static const char *decode_tomap(upb_decstate *d, const char *ptr, upb_msg *msg, - upb_msglayout const *const *submsgs, - const upb_msglayout_field *field, wireval *val) { - upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *); - upb_map *map = *map_p; - upb_map_entry ent; - const upb_msglayout *entry = submsgs[field->submsg_index]; +static const char* decode_tomap(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); + upb_Map* map = *map_p; + upb_MapEntry ent; + const upb_MiniTable* entry = subs[field->submsg_index].submsg; if (!map) { /* Lazily create map. */ - const upb_msglayout_field *key_field = &entry->fields[0]; - const upb_msglayout_field *val_field = &entry->fields[1]; + const upb_MiniTable_Field* key_field = &entry->fields[0]; + const upb_MiniTable_Field* val_field = &entry->fields[1]; char key_size = desctype_to_mapsize[key_field->descriptortype]; char val_size = desctype_to_mapsize[val_field->descriptortype]; UPB_ASSERT(key_field->offset == 0); - UPB_ASSERT(val_field->offset == sizeof(upb_strview)); - map = _upb_map_new(&d->arena, key_size, val_size); + UPB_ASSERT(val_field->offset == sizeof(upb_StringView)); + map = _upb_Map_New(&d->arena, key_size, val_size); *map_p = map; } /* Parse map entry. */ memset(&ent, 0, sizeof(ent)); - if (entry->fields[1].descriptortype == UPB_DESCRIPTOR_TYPE_MESSAGE || - entry->fields[1].descriptortype == UPB_DESCRIPTOR_TYPE_GROUP) { + if (entry->fields[1].descriptortype == kUpb_FieldType_Message || + entry->fields[1].descriptortype == kUpb_FieldType_Group) { /* Create proactively to handle the case where it doesn't appear. */ - ent.v.val = upb_value_ptr(_upb_msg_new(entry->submsgs[0], &d->arena)); + ent.v.val = + upb_value_ptr(_upb_Message_New(entry->subs[0].submsg, &d->arena)); } - ptr = decode_tosubmsg(d, ptr, &ent.k, submsgs, field, val->size); - _upb_map_set(map, &ent.k, map->key_size, &ent.v, map->val_size, &d->arena); + ptr = decode_tosubmsg(d, ptr, &ent.k, subs, field, val->size); + _upb_Map_Set(map, &ent.k, map->key_size, &ent.v, map->val_size, &d->arena); return ptr; } -static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, - upb_msglayout const *const *submsgs, - const upb_msglayout_field *field, wireval *val, +static const char* decode_tomsg(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, wireval* val, int op) { - void *mem = UPB_PTR_AT(msg, field->offset, void); + void* mem = UPB_PTR_AT(msg, field->offset, void); int type = field->descriptortype; + if (UPB_UNLIKELY(op == OP_ENUM) && + !decode_checkenum(d, ptr, msg, subs[field->submsg_index].subenum, field, + val)) { + return ptr; + } + /* Set presence if necessary. */ if (field->presence > 0) { _upb_sethas_field(msg, field); } else if (field->presence < 0) { /* Oneof case */ - uint32_t *oneof_case = _upb_oneofcase_field(msg, field); + uint32_t* oneof_case = _upb_oneofcase_field(msg, field); if (op == OP_SUBMSG && *oneof_case != field->number) { memset(mem, 0, sizeof(void*)); } @@ -775,16 +885,16 @@ static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, /* Store into message. */ switch (op) { case OP_SUBMSG: { - upb_msg **submsgp = mem; - upb_msg *submsg = *submsgp; + upb_Message** submsgp = mem; + upb_Message* submsg = *submsgp; if (!submsg) { - submsg = decode_newsubmsg(d, submsgs, field); + submsg = decode_newsubmsg(d, subs, field); *submsgp = submsg; } - if (UPB_UNLIKELY(type == UPB_DTYPE_GROUP)) { - ptr = decode_togroup(d, ptr, submsg, submsgs, field); + if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { + ptr = decode_togroup(d, ptr, submsg, subs, field); } else { - ptr = decode_tosubmsg(d, ptr, submsg, submsgs, field, val->size); + ptr = decode_tosubmsg(d, ptr, submsg, subs, field, val->size); } break; } @@ -796,6 +906,7 @@ static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, case OP_SCALAR_LG2(3): memcpy(mem, val, 8); break; + case OP_ENUM: case OP_SCALAR_LG2(2): memcpy(mem, val, 4); break; @@ -809,9 +920,27 @@ static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg, return ptr; } +UPB_NOINLINE +const char* decode_checkrequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* l) { + assert(l->required_count); + if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { + return ptr; + } + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = _upb_BigEndian_Swap64(msg_head); + if (upb_MiniTable_requiredmask(l) & ~msg_head) { + d->missing_required = true; + } + return ptr; +} + UPB_FORCEINLINE -static bool decode_tryfastdispatch(upb_decstate *d, const char **ptr, - upb_msg *msg, const upb_msglayout *layout) { +static bool decode_tryfastdispatch(upb_Decoder* d, const char** ptr, + upb_Message* msg, + const upb_MiniTable* layout) { #if UPB_FASTTABLE if (layout && layout->table_mask != (unsigned char)-1) { uint16_t tag = fastdecode_loadtag(*ptr); @@ -823,176 +952,385 @@ static bool decode_tryfastdispatch(upb_decstate *d, const char **ptr, return false; } +static const char* decode_msgset(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable* layout) { + // We create a temporary upb_MiniTable here and abuse its fields as temporary + // storage, to avoid creating lots of MessageSet-specific parsing code-paths: + // 1. We store 'layout' in item_layout.subs. We will need this later as + // a key to look up extensions for this MessageSet. + // 2. We use item_layout.fields as temporary storage to store the extension + // we + // found when parsing the type id. + upb_MiniTable item_layout = { + .subs = (const upb_MiniTable_Sub[]){{.submsg = layout}}, + .fields = NULL, + .size = 0, + .field_count = 0, + .ext = upb_ExtMode_IsMessageSet_ITEM, + .dense_below = 0, + .table_mask = -1}; + return decode_group(d, ptr, msg, &item_layout, 1); +} + +static const upb_MiniTable_Field* decode_findfield(upb_Decoder* d, + const upb_MiniTable* l, + uint32_t field_number, + int* last_field_index) { + static upb_MiniTable_Field none = {0, 0, 0, 0, 0, 0}; + if (l == NULL) return &none; + + size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX + if (idx < l->dense_below) { + /* Fastest case: index into dense fields. */ + goto found; + } + + if (l->dense_below < l->field_count) { + /* Linear search non-dense fields. Resume scanning from last_field_index + * since fields are usually in order. */ + int last = *last_field_index; + for (idx = last; idx < l->field_count; idx++) { + if (l->fields[idx].number == field_number) { + goto found; + } + } + + for (idx = l->dense_below; idx < last; idx++) { + if (l->fields[idx].number == field_number) { + goto found; + } + } + } + + if (d->extreg) { + switch (l->ext) { + case upb_ExtMode_Extendable: { + const upb_MiniTable_Extension* ext = + _upb_extreg_get(d->extreg, l, field_number); + if (ext) return &ext->field; + break; + } + case upb_ExtMode_IsMessageSet: + if (field_number == _UPB_MSGSET_ITEM) { + static upb_MiniTable_Field item = {0, 0, 0, 0, TYPE_MSGSET_ITEM, 0}; + return &item; + } + break; + case upb_ExtMode_IsMessageSet_ITEM: + switch (field_number) { + case _UPB_MSGSET_TYPEID: { + static upb_MiniTable_Field type_id = { + 0, 0, 0, 0, TYPE_MSGSET_TYPE_ID, 0}; + return &type_id; + } + case _UPB_MSGSET_MESSAGE: + if (l->fields) { + // We saw type_id previously and succeeded in looking up msg. + return l->fields; + } else { + // TODO: out of order MessageSet. + // This is a very rare case: all serializers will emit in-order + // MessageSets. To hit this case there has to be some kind of + // re-ordering proxy. We should eventually handle this case, but + // not today. + } + break; + } + } + } + + return &none; /* Unknown field. */ + +found: + UPB_ASSERT(l->fields[idx].number == field_number); + *last_field_index = idx; + return &l->fields[idx]; +} + +UPB_FORCEINLINE +static const char* decode_wireval(upb_Decoder* d, const char* ptr, + const upb_MiniTable_Field* field, + int wire_type, wireval* val, int* op) { + switch (wire_type) { + case kUpb_WireType_Varint: + ptr = decode_varint64(d, ptr, &val->uint64_val); + *op = varint_ops[field->descriptortype]; + decode_munge(field->descriptortype, val); + return ptr; + case kUpb_WireType_32Bit: + memcpy(&val->uint32_val, ptr, 4); + val->uint32_val = _upb_BigEndian_Swap32(val->uint32_val); + *op = OP_SCALAR_LG2(2); + if (((1 << field->descriptortype) & FIXED32_OK_MASK) == 0) { + *op = OP_UNKNOWN; + } + return ptr + 4; + case kUpb_WireType_64Bit: + memcpy(&val->uint64_val, ptr, 8); + val->uint64_val = _upb_BigEndian_Swap64(val->uint64_val); + *op = OP_SCALAR_LG2(3); + if (((1 << field->descriptortype) & FIXED64_OK_MASK) == 0) { + *op = OP_UNKNOWN; + } + return ptr + 8; + case kUpb_WireType_Delimited: { + int ndx = field->descriptortype; + uint64_t size; + if (upb_FieldMode_Get(field) == kUpb_FieldMode_Array) ndx += TYPE_COUNT; + ptr = decode_varint64(d, ptr, &size); + if (size >= INT32_MAX || ptr - d->end + (int32_t)size > d->limit) { + break; /* Length overflow. */ + } + *op = delim_ops[ndx]; + val->size = size; + return ptr; + } + case kUpb_WireType_StartGroup: + val->uint32_val = field->number; + if (field->descriptortype == kUpb_FieldType_Group) { + *op = OP_SUBMSG; + } else if (field->descriptortype == TYPE_MSGSET_ITEM) { + *op = OP_MSGSET_ITEM; + } else { + *op = OP_UNKNOWN; + } + return ptr; + default: + break; + } + return decode_err(d, kUpb_DecodeStatus_Malformed); +} + +UPB_FORCEINLINE +static const char* decode_known(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable* layout, + const upb_MiniTable_Field* field, int op, + wireval* val) { + const upb_MiniTable_Sub* subs = layout->subs; + uint8_t mode = field->mode; + + if (UPB_UNLIKELY(mode & upb_LabelFlags_IsExtension)) { + const upb_MiniTable_Extension* ext_layout = + (const upb_MiniTable_Extension*)field; + upb_Message_Extension* ext = + _upb_Message_Getorcreateext(msg, ext_layout, &d->arena); + if (UPB_UNLIKELY(!ext)) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + msg = &ext->data; + subs = &ext->ext->sub; + } + + switch (mode & kUpb_FieldMode_Mask) { + case kUpb_FieldMode_Array: + return decode_toarray(d, ptr, msg, subs, field, val, op); + case kUpb_FieldMode_Map: + return decode_tomap(d, ptr, msg, subs, field, val); + case kUpb_FieldMode_Scalar: + return decode_tomsg(d, ptr, msg, subs, field, val, op); + default: + UPB_UNREACHABLE(); + } +} + +static const char* decode_reverse_skip_varint(const char* ptr, uint32_t val) { + uint32_t seen = 0; + do { + ptr--; + seen <<= 7; + seen |= *ptr & 0x7f; + } while (seen != val); + return ptr; +} + +static const char* decode_unknown(upb_Decoder* d, const char* ptr, + upb_Message* msg, int field_number, + int wire_type, wireval val) { + if (field_number == 0) return decode_err(d, kUpb_DecodeStatus_Malformed); + + // Since unknown fields are the uncommon case, we do a little extra work here + // to walk backwards through the buffer to find the field start. This frees + // up a register in the fast paths (when the field is known), which leads to + // significant speedups in benchmarks. + const char* start = ptr; + + if (wire_type == kUpb_WireType_Delimited) ptr += val.size; + if (msg) { + switch (wire_type) { + case kUpb_WireType_Varint: + case kUpb_WireType_Delimited: + start--; + while (start[-1] & 0x80) start--; + break; + case kUpb_WireType_32Bit: + start -= 4; + break; + case kUpb_WireType_64Bit: + start -= 8; + break; + default: + break; + } + + assert(start == d->debug_valstart); + uint32_t tag = ((uint32_t)field_number << 3) | wire_type; + start = decode_reverse_skip_varint(start, tag); + assert(start == d->debug_tagstart); + + if (wire_type == kUpb_WireType_StartGroup) { + d->unknown = start; + d->unknown_msg = msg; + ptr = decode_group(d, ptr, NULL, NULL, field_number); + start = d->unknown; + d->unknown_msg = NULL; + d->unknown = NULL; + } + if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { + return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + } else if (wire_type == kUpb_WireType_StartGroup) { + ptr = decode_group(d, ptr, NULL, NULL, field_number); + } + return ptr; +} + UPB_NOINLINE -static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, - const upb_msglayout *layout) { +static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout) { int last_field_index = 0; - while (true) { + +#if UPB_FASTTABLE + // The first time we want to skip fast dispatch, because we may have just been + // invoked by the fast parser to handle a case that it bailed on. + if (!decode_isdone(d, &ptr)) goto nofast; +#endif + + while (!decode_isdone(d, &ptr)) { uint32_t tag; - const upb_msglayout_field *field; + const upb_MiniTable_Field* field; int field_number; int wire_type; - const char *field_start = ptr; wireval val; int op; + if (decode_tryfastdispatch(d, &ptr, msg, layout)) break; + +#if UPB_FASTTABLE + nofast: +#endif + +#ifndef NDEBUG + d->debug_tagstart = ptr; +#endif + UPB_ASSERT(ptr < d->limit_ptr); ptr = decode_tag(d, ptr, &tag); field_number = tag >> 3; wire_type = tag & 7; - field = upb_find_field(layout, field_number, &last_field_index); +#ifndef NDEBUG + d->debug_valstart = ptr; +#endif - switch (wire_type) { - case UPB_WIRE_TYPE_VARINT: - ptr = decode_varint64(d, ptr, &val.uint64_val); - op = varint_ops[field->descriptortype]; - decode_munge(field->descriptortype, &val); - break; - case UPB_WIRE_TYPE_32BIT: - memcpy(&val.uint32_val, ptr, 4); - val.uint32_val = _upb_be_swap32(val.uint32_val); - ptr += 4; - op = OP_SCALAR_LG2(2); - if (((1 << field->descriptortype) & fixed32_ok) == 0) goto unknown; - break; - case UPB_WIRE_TYPE_64BIT: - memcpy(&val.uint64_val, ptr, 8); - val.uint64_val = _upb_be_swap64(val.uint64_val); - ptr += 8; - op = OP_SCALAR_LG2(3); - if (((1 << field->descriptortype) & fixed64_ok) == 0) goto unknown; - break; - case UPB_WIRE_TYPE_DELIMITED: { - int ndx = field->descriptortype; - uint64_t size; - if (_upb_getmode(field) == _UPB_MODE_ARRAY) ndx += 18; - ptr = decode_varint64(d, ptr, &size); - if (size >= INT32_MAX || - ptr - d->end + (int32_t)size > d->limit) { - decode_err(d); /* Length overflow. */ - } - op = delim_ops[ndx]; - val.size = size; - break; - } - case UPB_WIRE_TYPE_START_GROUP: - val.uint32_val = field_number; - op = OP_SUBMSG; - if (field->descriptortype != UPB_DTYPE_GROUP) goto unknown; - break; - case UPB_WIRE_TYPE_END_GROUP: - d->end_group = field_number; - return ptr; - default: - decode_err(d); + if (wire_type == kUpb_WireType_EndGroup) { + d->end_group = field_number; + return ptr; } + field = decode_findfield(d, layout, field_number, &last_field_index); + ptr = decode_wireval(d, ptr, field, wire_type, &val, &op); + if (op >= 0) { - /* Parse, using op for dispatch. */ - switch (_upb_getmode(field)) { - case _UPB_MODE_ARRAY: - ptr = decode_toarray(d, ptr, msg, layout->submsgs, field, &val, op); + ptr = decode_known(d, ptr, msg, layout, field, op, &val); + } else { + switch (op) { + case OP_UNKNOWN: + ptr = decode_unknown(d, ptr, msg, field_number, wire_type, val); break; - case _UPB_MODE_MAP: - ptr = decode_tomap(d, ptr, msg, layout->submsgs, field, &val); + case OP_MSGSET_ITEM: + ptr = decode_msgset(d, ptr, msg, layout); break; - case _UPB_MODE_SCALAR: - ptr = decode_tomsg(d, ptr, msg, layout->submsgs, field, &val, op); + case OP_MSGSET_TYPEID: { + const upb_MiniTable_Extension* ext = _upb_extreg_get( + d->extreg, layout->subs[0].submsg, val.uint64_val); + if (ext) ((upb_MiniTable*)layout)->fields = &ext->field; break; - default: - UPB_UNREACHABLE(); - } - } else { - unknown: - /* Skip unknown field. */ - if (field_number == 0) decode_err(d); - if (wire_type == UPB_WIRE_TYPE_DELIMITED) ptr += val.size; - if (msg) { - if (wire_type == UPB_WIRE_TYPE_START_GROUP) { - d->unknown = field_start; - d->unknown_msg = msg; - ptr = decode_group(d, ptr, NULL, NULL, field_number); - d->unknown_msg = NULL; - field_start = d->unknown; } - if (!_upb_msg_addunknown(msg, field_start, ptr - field_start, - &d->arena)) { - decode_err(d); - } - } else if (wire_type == UPB_WIRE_TYPE_START_GROUP) { - ptr = decode_group(d, ptr, NULL, NULL, field_number); } } - - if (decode_isdone(d, &ptr)) return ptr; - if (decode_tryfastdispatch(d, &ptr, msg, layout)) return ptr; } + + return UPB_UNLIKELY(layout && layout->required_count) + ? decode_checkrequired(d, ptr, msg, layout) + : ptr; } -const char *fastdecode_generic(struct upb_decstate *d, const char *ptr, - upb_msg *msg, intptr_t table, uint64_t hasbits, - uint64_t data) { +const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { (void)data; *(uint32_t*)msg |= hasbits; return decode_msg(d, ptr, msg, decode_totablep(table)); } -static bool decode_top(struct upb_decstate *d, const char *buf, void *msg, - const upb_msglayout *l) { +static upb_DecodeStatus decode_top(struct upb_Decoder* d, const char* buf, + void* msg, const upb_MiniTable* l) { if (!decode_tryfastdispatch(d, &buf, msg, l)) { decode_msg(d, buf, msg, l); } - return d->end_group == DECODE_NOGROUP; + if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; + if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; + return kUpb_DecodeStatus_Ok; } -bool _upb_decode(const char *buf, size_t size, void *msg, - const upb_msglayout *l, const upb_extreg *extreg, int options, - upb_arena *arena) { - bool ok; - upb_decstate state; +upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, + const upb_MiniTable* l, + const upb_ExtensionRegistry* extreg, int options, + upb_Arena* arena) { + upb_Decoder state; unsigned depth = (unsigned)options >> 16; - if (size == 0) { - return true; - } else if (size <= 16) { + if (size <= 16) { memset(&state.patch, 0, 32); memcpy(&state.patch, buf, size); buf = state.patch; state.end = buf + size; state.limit = 0; - state.alias = false; + options &= ~kUpb_DecodeOption_AliasString; // Can't alias patch buf. } else { state.end = buf + size - 16; state.limit = 16; - state.alias = options & UPB_DECODE_ALIAS; } + state.extreg = extreg; state.limit_ptr = state.end; state.unknown_msg = NULL; state.depth = depth ? depth : 64; state.end_group = DECODE_NOGROUP; + state.options = (uint16_t)options; + state.missing_required = false; state.arena.head = arena->head; state.arena.last_size = arena->last_size; state.arena.cleanup_metadata = arena->cleanup_metadata; state.arena.parent = arena; - if (UPB_UNLIKELY(UPB_SETJMP(state.err))) { - ok = false; - } else { - ok = decode_top(&state, buf, msg, l); + upb_DecodeStatus status = UPB_SETJMP(state.err); + if (UPB_LIKELY(status == kUpb_DecodeStatus_Ok)) { + status = decode_top(&state, buf, msg, l); } arena->head.ptr = state.arena.head.ptr; arena->head.end = state.arena.head.end; arena->cleanup_metadata = state.arena.cleanup_metadata; - return ok; + return status; } +#undef OP_UNKNOWN +#undef OP_SKIP #undef OP_SCALAR_LG2 #undef OP_FIXPCK_LG2 #undef OP_VARPCK_LG2 #undef OP_STRING +#undef OP_BYTES #undef OP_SUBMSG /** upb/encode.c ************************************************************/ @@ -1008,7 +1346,7 @@ bool _upb_decode(const char *buf, size_t size, void *msg, #define UPB_PB_VARINT_MAX_LEN 10 UPB_NOINLINE -static size_t encode_varint64(uint64_t val, char *buf) { +static size_t encode_varint64(uint64_t val, char* buf) { size_t i = 0; do { uint8_t byte = val & 0x7fU; @@ -1019,12 +1357,16 @@ static size_t encode_varint64(uint64_t val, char *buf) { return i; } -static uint32_t encode_zz32(int32_t n) { return ((uint32_t)n << 1) ^ (n >> 31); } -static uint64_t encode_zz64(int64_t n) { return ((uint64_t)n << 1) ^ (n >> 63); } +static uint32_t encode_zz32(int32_t n) { + return ((uint32_t)n << 1) ^ (n >> 31); +} +static uint64_t encode_zz64(int64_t n) { + return ((uint64_t)n << 1) ^ (n >> 63); +} typedef struct { jmp_buf err; - upb_alloc *alloc; + upb_alloc* alloc; char *buf, *ptr, *limit; int options; int depth; @@ -1039,15 +1381,13 @@ static size_t upb_roundup_pow2(size_t bytes) { return ret; } -UPB_NORETURN static void encode_err(upb_encstate *e) { - UPB_LONGJMP(e->err, 1); -} +UPB_NORETURN static void encode_err(upb_encstate* e) { UPB_LONGJMP(e->err, 1); } UPB_NOINLINE -static void encode_growbuffer(upb_encstate *e, size_t bytes) { +static void encode_growbuffer(upb_encstate* e, size_t bytes) { size_t old_size = e->limit - e->buf; size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size); + char* new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size); if (!new_buf) encode_err(e); @@ -1066,7 +1406,7 @@ static void encode_growbuffer(upb_encstate *e, size_t bytes) { /* Call to ensure that at least "bytes" bytes are available for writing at * e->ptr. Returns false if the bytes could not be allocated. */ UPB_FORCEINLINE -static void encode_reserve(upb_encstate *e, size_t bytes) { +static void encode_reserve(upb_encstate* e, size_t bytes) { if ((size_t)(e->ptr - e->buf) < bytes) { encode_growbuffer(e, bytes); return; @@ -1076,26 +1416,26 @@ static void encode_reserve(upb_encstate *e, size_t bytes) { } /* Writes the given bytes to the buffer, handling reserve/advance. */ -static void encode_bytes(upb_encstate *e, const void *data, size_t len) { - if (len == 0) return; /* memcpy() with zero size is UB */ +static void encode_bytes(upb_encstate* e, const void* data, size_t len) { + if (len == 0) return; /* memcpy() with zero size is UB */ encode_reserve(e, len); memcpy(e->ptr, data, len); } -static void encode_fixed64(upb_encstate *e, uint64_t val) { - val = _upb_be_swap64(val); +static void encode_fixed64(upb_encstate* e, uint64_t val) { + val = _upb_BigEndian_Swap64(val); encode_bytes(e, &val, sizeof(uint64_t)); } -static void encode_fixed32(upb_encstate *e, uint32_t val) { - val = _upb_be_swap32(val); +static void encode_fixed32(upb_encstate* e, uint32_t val) { + val = _upb_BigEndian_Swap32(val); encode_bytes(e, &val, sizeof(uint32_t)); } UPB_NOINLINE -static void encode_longvarint(upb_encstate *e, uint64_t val) { +static void encode_longvarint(upb_encstate* e, uint64_t val) { size_t len; - char *start; + char* start; encode_reserve(e, UPB_PB_VARINT_MAX_LEN); len = encode_varint64(val, e->ptr); @@ -1105,7 +1445,7 @@ static void encode_longvarint(upb_encstate *e, uint64_t val) { } UPB_FORCEINLINE -static void encode_varint(upb_encstate *e, uint64_t val) { +static void encode_varint(upb_encstate* e, uint64_t val) { if (val < 128 && e->ptr != e->buf) { --e->ptr; *e->ptr = val; @@ -1114,34 +1454,47 @@ static void encode_varint(upb_encstate *e, uint64_t val) { } } -static void encode_double(upb_encstate *e, double d) { +static void encode_double(upb_encstate* e, double d) { uint64_t u64; UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); memcpy(&u64, &d, sizeof(uint64_t)); encode_fixed64(e, u64); } -static void encode_float(upb_encstate *e, float d) { +static void encode_float(upb_encstate* e, float d) { uint32_t u32; UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); memcpy(&u32, &d, sizeof(uint32_t)); encode_fixed32(e, u32); } -static void encode_tag(upb_encstate *e, uint32_t field_number, +static void encode_tag(upb_encstate* e, uint32_t field_number, uint8_t wire_type) { encode_varint(e, (field_number << 3) | wire_type); } -static void encode_fixedarray(upb_encstate *e, const upb_array *arr, - size_t elem_size, uint32_t tag) { +static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, + size_t elem_size, uint32_t tag) { size_t bytes = arr->len * elem_size; const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; - if (tag) { + + if (tag || !_upb_IsLittleEndian()) { while (true) { - encode_bytes(e, ptr, elem_size); - encode_varint(e, tag); + if (elem_size == 4) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap32(val); + encode_bytes(e, &val, elem_size); + } else { + UPB_ASSERT(elem_size == 8); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap64(val); + encode_bytes(e, &val, elem_size); + } + + if (tag) encode_varint(e, tag); if (ptr == data) break; ptr -= elem_size; } @@ -1150,87 +1503,81 @@ static void encode_fixedarray(upb_encstate *e, const upb_array *arr, } } -static void encode_message(upb_encstate *e, const upb_msg *msg, - const upb_msglayout *m, size_t *size); +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size); -static void encode_scalar(upb_encstate *e, const void *_field_mem, - const upb_msglayout *m, const upb_msglayout_field *f, - bool skip_zero_value) { - const char *field_mem = _field_mem; +static void encode_scalar(upb_encstate* e, const void* _field_mem, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const char* field_mem = _field_mem; int wire_type; #define CASE(ctype, type, wtype, encodeval) \ { \ - ctype val = *(ctype *)field_mem; \ - if (skip_zero_value && val == 0) { \ - return; \ - } \ + ctype val = *(ctype*)field_mem; \ encode_##type(e, encodeval); \ wire_type = wtype; \ break; \ } switch (f->descriptortype) { - case UPB_DESCRIPTOR_TYPE_DOUBLE: - CASE(double, double, UPB_WIRE_TYPE_64BIT, val); - case UPB_DESCRIPTOR_TYPE_FLOAT: - CASE(float, float, UPB_WIRE_TYPE_32BIT, val); - case UPB_DESCRIPTOR_TYPE_INT64: - case UPB_DESCRIPTOR_TYPE_UINT64: - CASE(uint64_t, varint, UPB_WIRE_TYPE_VARINT, val); - case UPB_DESCRIPTOR_TYPE_UINT32: - CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val); - case UPB_DESCRIPTOR_TYPE_INT32: - case UPB_DESCRIPTOR_TYPE_ENUM: - CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, (int64_t)val); - case UPB_DESCRIPTOR_TYPE_SFIXED64: - case UPB_DESCRIPTOR_TYPE_FIXED64: - CASE(uint64_t, fixed64, UPB_WIRE_TYPE_64BIT, val); - case UPB_DESCRIPTOR_TYPE_FIXED32: - case UPB_DESCRIPTOR_TYPE_SFIXED32: - CASE(uint32_t, fixed32, UPB_WIRE_TYPE_32BIT, val); - case UPB_DESCRIPTOR_TYPE_BOOL: - CASE(bool, varint, UPB_WIRE_TYPE_VARINT, val); - case UPB_DESCRIPTOR_TYPE_SINT32: - CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, encode_zz32(val)); - case UPB_DESCRIPTOR_TYPE_SINT64: - CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, encode_zz64(val)); - case UPB_DESCRIPTOR_TYPE_STRING: - case UPB_DESCRIPTOR_TYPE_BYTES: { - upb_strview view = *(upb_strview*)field_mem; - if (skip_zero_value && view.size == 0) { - return; - } + case kUpb_FieldType_Double: + CASE(double, double, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Float: + CASE(float, float, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + CASE(uint64_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_UInt32: + CASE(uint32_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Bool: + CASE(bool, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_SInt32: + CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); + case kUpb_FieldType_SInt64: + CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + upb_StringView view = *(upb_StringView*)field_mem; encode_bytes(e, view.data, view.size); encode_varint(e, view.size); - wire_type = UPB_WIRE_TYPE_DELIMITED; + wire_type = kUpb_WireType_Delimited; break; } - case UPB_DESCRIPTOR_TYPE_GROUP: { + case kUpb_FieldType_Group: { size_t size; - void *submsg = *(void **)field_mem; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; + void* submsg = *(void**)field_mem; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; if (submsg == NULL) { return; } if (--e->depth == 0) encode_err(e); - encode_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP); + encode_tag(e, f->number, kUpb_WireType_EndGroup); encode_message(e, submsg, subm, &size); - wire_type = UPB_WIRE_TYPE_START_GROUP; + wire_type = kUpb_WireType_StartGroup; e->depth++; break; } - case UPB_DESCRIPTOR_TYPE_MESSAGE: { + case kUpb_FieldType_Message: { size_t size; - void *submsg = *(void **)field_mem; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; + void* submsg = *(void**)field_mem; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; if (submsg == NULL) { return; } if (--e->depth == 0) encode_err(e); encode_message(e, submsg, subm, &size); encode_varint(e, size); - wire_type = UPB_WIRE_TYPE_DELIMITED; + wire_type = kUpb_WireType_Delimited; e->depth++; break; } @@ -1242,10 +1589,11 @@ static void encode_scalar(upb_encstate *e, const void *_field_mem, encode_tag(e, f->number, wire_type); } -static void encode_array(upb_encstate *e, const upb_msg *msg, - const upb_msglayout *m, const upb_msglayout_field *f) { - const upb_array *arr = *UPB_PTR_AT(msg, f->offset, upb_array*); - bool packed = f->mode & _UPB_MODE_IS_PACKED; +static void encode_array(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); + bool packed = f->mode & upb_LabelFlags_IsPacked; size_t pre_len = e->limit - e->ptr; if (arr == NULL || arr->len == 0) { @@ -1254,9 +1602,9 @@ static void encode_array(upb_encstate *e, const upb_msg *msg, #define VARINT_CASE(ctype, encode) \ { \ - const ctype *start = _upb_array_constptr(arr); \ - const ctype *ptr = start + arr->len; \ - uint32_t tag = packed ? 0 : (f->number << 3) | UPB_WIRE_TYPE_VARINT; \ + const ctype* start = _upb_array_constptr(arr); \ + const ctype* ptr = start + arr->len; \ + uint32_t tag = packed ? 0 : (f->number << 3) | kUpb_WireType_Varint; \ do { \ ptr--; \ encode_varint(e, encode); \ @@ -1268,72 +1616,72 @@ static void encode_array(upb_encstate *e, const upb_msg *msg, #define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type)) switch (f->descriptortype) { - case UPB_DESCRIPTOR_TYPE_DOUBLE: - encode_fixedarray(e, arr, sizeof(double), TAG(UPB_WIRE_TYPE_64BIT)); + case kUpb_FieldType_Double: + encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); break; - case UPB_DESCRIPTOR_TYPE_FLOAT: - encode_fixedarray(e, arr, sizeof(float), TAG(UPB_WIRE_TYPE_32BIT)); + case kUpb_FieldType_Float: + encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); break; - case UPB_DESCRIPTOR_TYPE_SFIXED64: - case UPB_DESCRIPTOR_TYPE_FIXED64: - encode_fixedarray(e, arr, sizeof(uint64_t), TAG(UPB_WIRE_TYPE_64BIT)); + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); break; - case UPB_DESCRIPTOR_TYPE_FIXED32: - case UPB_DESCRIPTOR_TYPE_SFIXED32: - encode_fixedarray(e, arr, sizeof(uint32_t), TAG(UPB_WIRE_TYPE_32BIT)); + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); break; - case UPB_DESCRIPTOR_TYPE_INT64: - case UPB_DESCRIPTOR_TYPE_UINT64: + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: VARINT_CASE(uint64_t, *ptr); - case UPB_DESCRIPTOR_TYPE_UINT32: + case kUpb_FieldType_UInt32: VARINT_CASE(uint32_t, *ptr); - case UPB_DESCRIPTOR_TYPE_INT32: - case UPB_DESCRIPTOR_TYPE_ENUM: + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: VARINT_CASE(int32_t, (int64_t)*ptr); - case UPB_DESCRIPTOR_TYPE_BOOL: + case kUpb_FieldType_Bool: VARINT_CASE(bool, *ptr); - case UPB_DESCRIPTOR_TYPE_SINT32: + case kUpb_FieldType_SInt32: VARINT_CASE(int32_t, encode_zz32(*ptr)); - case UPB_DESCRIPTOR_TYPE_SINT64: + case kUpb_FieldType_SInt64: VARINT_CASE(int64_t, encode_zz64(*ptr)); - case UPB_DESCRIPTOR_TYPE_STRING: - case UPB_DESCRIPTOR_TYPE_BYTES: { - const upb_strview *start = _upb_array_constptr(arr); - const upb_strview *ptr = start + arr->len; + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + const upb_StringView* start = _upb_array_constptr(arr); + const upb_StringView* ptr = start + arr->len; do { ptr--; encode_bytes(e, ptr->data, ptr->size); encode_varint(e, ptr->size); - encode_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED); + encode_tag(e, f->number, kUpb_WireType_Delimited); } while (ptr != start); return; } - case UPB_DESCRIPTOR_TYPE_GROUP: { - const void *const*start = _upb_array_constptr(arr); - const void *const*ptr = start + arr->len; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; + case kUpb_FieldType_Group: { + const void* const* start = _upb_array_constptr(arr); + const void* const* ptr = start + arr->len; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; if (--e->depth == 0) encode_err(e); do { size_t size; ptr--; - encode_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP); + encode_tag(e, f->number, kUpb_WireType_EndGroup); encode_message(e, *ptr, subm, &size); - encode_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP); + encode_tag(e, f->number, kUpb_WireType_StartGroup); } while (ptr != start); e->depth++; return; } - case UPB_DESCRIPTOR_TYPE_MESSAGE: { - const void *const*start = _upb_array_constptr(arr); - const void *const*ptr = start + arr->len; - const upb_msglayout *subm = m->submsgs[f->submsg_index]; + case kUpb_FieldType_Message: { + const void* const* start = _upb_array_constptr(arr); + const void* const* ptr = start + arr->len; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; if (--e->depth == 0) encode_err(e); do { size_t size; ptr--; encode_message(e, *ptr, subm, &size); encode_varint(e, size); - encode_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED); + encode_tag(e, f->number, kUpb_WireType_Delimited); } while (ptr != start); e->depth++; return; @@ -1343,37 +1691,38 @@ static void encode_array(upb_encstate *e, const upb_msg *msg, if (packed) { encode_varint(e, e->limit - e->ptr - pre_len); - encode_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED); + encode_tag(e, f->number, kUpb_WireType_Delimited); } } -static void encode_mapentry(upb_encstate *e, uint32_t number, - const upb_msglayout *layout, - const upb_map_entry *ent) { - const upb_msglayout_field *key_field = &layout->fields[0]; - const upb_msglayout_field *val_field = &layout->fields[1]; +static void encode_mapentry(upb_encstate* e, uint32_t number, + const upb_MiniTable* layout, + const upb_MapEntry* ent) { + const upb_MiniTable_Field* key_field = &layout->fields[0]; + const upb_MiniTable_Field* val_field = &layout->fields[1]; size_t pre_len = e->limit - e->ptr; size_t size; - encode_scalar(e, &ent->v, layout, val_field, false); - encode_scalar(e, &ent->k, layout, key_field, false); + encode_scalar(e, &ent->v, layout->subs, val_field); + encode_scalar(e, &ent->k, layout->subs, key_field); size = (e->limit - e->ptr) - pre_len; encode_varint(e, size); - encode_tag(e, number, UPB_WIRE_TYPE_DELIMITED); + encode_tag(e, number, kUpb_WireType_Delimited); } -static void encode_map(upb_encstate *e, const upb_msg *msg, - const upb_msglayout *m, const upb_msglayout_field *f) { - const upb_map *map = *UPB_PTR_AT(msg, f->offset, const upb_map*); - const upb_msglayout *layout = m->submsgs[f->submsg_index]; +static void encode_map(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); + const upb_MiniTable* layout = subs[f->submsg_index].submsg; UPB_ASSERT(layout->field_count == 2); if (map == NULL) return; - if (e->options & UPB_ENCODE_DETERMINISTIC) { + if (e->options & kUpb_Encode_Deterministic) { _upb_sortedmap sorted; _upb_mapsorter_pushmap(&e->sorter, layout->fields[0].descriptortype, map, &sorted); - upb_map_entry ent; + upb_MapEntry ent; while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { encode_mapentry(e, f->number, layout, &ent); } @@ -1381,10 +1730,10 @@ static void encode_map(upb_encstate *e, const upb_msg *msg, } else { upb_strtable_iter i; upb_strtable_begin(&i, &map->table); - for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { - upb_strview key = upb_strtable_iter_key(&i); + for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { + upb_StringView key = upb_strtable_iter_key(&i); const upb_value val = upb_strtable_iter_value(&i); - upb_map_entry ent; + upb_MapEntry ent; _upb_map_fromkey(key, &ent.k, map->key_size); _upb_map_fromvalue(val, &ent.v, map->val_size); encode_mapentry(e, f->number, layout, &ent); @@ -1392,71 +1741,145 @@ static void encode_map(upb_encstate *e, const upb_msg *msg, } } -static void encode_scalarfield(upb_encstate *e, const char *msg, - const upb_msglayout *m, - const upb_msglayout_field *f) { - bool skip_empty = false; +static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { if (f->presence == 0) { - /* Proto3 presence. */ - skip_empty = true; + /* Proto3 presence or map/array. */ + const void* mem = UPB_PTR_AT(msg, f->offset, void); + switch (f->mode >> upb_FieldRep_Shift) { + case upb_FieldRep_1Byte: { + char ch; + memcpy(&ch, mem, 1); + return ch != 0; + } + case upb_FieldRep_4Byte: { + uint32_t u32; + memcpy(&u32, mem, 4); + return u32 != 0; + } + case upb_FieldRep_8Byte: { + uint64_t u64; + memcpy(&u64, mem, 8); + return u64 != 0; + } + case upb_FieldRep_StringView: { + const upb_StringView* str = (const upb_StringView*)mem; + return str->size != 0; + } + default: + UPB_UNREACHABLE(); + } } else if (f->presence > 0) { /* Proto2 presence: hasbit. */ - if (!_upb_hasbit_field(msg, f)) return; + return _upb_hasbit_field(msg, f); } else { /* Field is in a oneof. */ - if (_upb_getoneofcase_field(msg, f) != f->number) return; + return _upb_getoneofcase_field(msg, f) == f->number; + } +} + +static void encode_field(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + switch (upb_FieldMode_Get(field)) { + case kUpb_FieldMode_Array: + encode_array(e, msg, subs, field); + break; + case kUpb_FieldMode_Map: + encode_map(e, msg, subs, field); + break; + case kUpb_FieldMode_Scalar: + encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); + break; + default: + UPB_UNREACHABLE(); } - encode_scalar(e, msg + f->offset, m, f, skip_empty); } -static void encode_message(upb_encstate *e, const upb_msg *msg, - const upb_msglayout *m, size_t *size) { +/* message MessageSet { + * repeated group Item = 1 { + * required int32 type_id = 2; + * required string message = 3; + * } + * } */ +static void encode_msgset_item(upb_encstate* e, + const upb_Message_Extension* ext) { + size_t size; + encode_tag(e, 1, kUpb_WireType_EndGroup); + encode_message(e, ext->data.ptr, ext->ext->sub.submsg, &size); + encode_varint(e, size); + encode_tag(e, 3, kUpb_WireType_Delimited); + encode_varint(e, ext->ext->field.number); + encode_tag(e, 2, kUpb_WireType_Varint); + encode_tag(e, 1, kUpb_WireType_StartGroup); +} + +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size) { size_t pre_len = e->limit - e->ptr; - const upb_msglayout_field *f = &m->fields[m->field_count]; - const upb_msglayout_field *first = &m->fields[0]; - if ((e->options & UPB_ENCODE_SKIPUNKNOWN) == 0) { + if ((e->options & kUpb_Encode_CheckRequired) && m->required_count) { + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = _upb_BigEndian_Swap64(msg_head); + if (upb_MiniTable_requiredmask(m) & ~msg_head) { + encode_err(e); + } + } + + if ((e->options & kUpb_Encode_SkipUnknown) == 0) { size_t unknown_size; - const char *unknown = upb_msg_getunknown(msg, &unknown_size); + const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); if (unknown) { encode_bytes(e, unknown, unknown_size); } } + if (m->ext != upb_ExtMode_NonExtendable) { + /* Encode all extensions together. Unlike C++, we do not attempt to keep + * these in field number order relative to normal fields or even to each + * other. */ + size_t ext_count; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + const upb_Message_Extension* end = ext + ext_count; + if (ext_count) { + for (; ext != end; ext++) { + if (UPB_UNLIKELY(m->ext == upb_ExtMode_IsMessageSet)) { + encode_msgset_item(e, ext); + } else { + encode_field(e, &ext->data, &ext->ext->sub, &ext->ext->field); + } + } + } + } + + const upb_MiniTable_Field* f = &m->fields[m->field_count]; + const upb_MiniTable_Field* first = &m->fields[0]; while (f != first) { f--; - switch (_upb_getmode(f)) { - case _UPB_MODE_ARRAY: - encode_array(e, msg, m, f); - break; - case _UPB_MODE_MAP: - encode_map(e, msg, m, f); - break; - case _UPB_MODE_SCALAR: - encode_scalarfield(e, msg, m, f); - break; - default: - UPB_UNREACHABLE(); + if (encode_shouldencode(e, msg, m->subs, f)) { + encode_field(e, msg, m->subs, f); } } *size = (e->limit - e->ptr) - pre_len; } -char *upb_encode_ex(const void *msg, const upb_msglayout *l, int options, - upb_arena *arena, size_t *size) { +char* upb_Encode(const void* msg, const upb_MiniTable* l, int options, + upb_Arena* arena, size_t* size) { upb_encstate e; unsigned depth = (unsigned)options >> 16; - e.alloc = upb_arena_alloc(arena); + e.alloc = upb_Arena_Alloc(arena); e.buf = NULL; e.limit = NULL; e.ptr = NULL; e.depth = depth ? depth : 64; e.options = options; _upb_mapsorter_init(&e.sorter); - char *ret = NULL; + char* ret = NULL; if (UPB_SETJMP(e.err)) { *size = 0; @@ -1480,30 +1903,32 @@ char *upb_encode_ex(const void *msg, const upb_msglayout *l, int options, /** upb/msg.c ************************************************************/ -/** upb_msg *******************************************************************/ +/** upb_Message + * *******************************************************************/ -static const size_t overhead = sizeof(upb_msg_internaldata); +static const size_t overhead = sizeof(upb_Message_InternalData); -static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) { - ptrdiff_t size = sizeof(upb_msg_internal); - return (upb_msg_internal*)((char*)msg - size); +static const upb_Message_Internal* upb_Message_Getinternal_const( + const upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); } -upb_msg *_upb_msg_new(const upb_msglayout *l, upb_arena *a) { - return _upb_msg_new_inl(l, a); +upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a) { + return _upb_Message_New_inl(l, a); } -void _upb_msg_clear(upb_msg *msg, const upb_msglayout *l) { - void *mem = UPB_PTR_AT(msg, -sizeof(upb_msg_internal), char); +void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { + void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); memset(mem, 0, upb_msg_sizeof(l)); } -static bool realloc_internal(upb_msg *msg, size_t need, upb_arena *arena) { - upb_msg_internal *in = upb_msg_getinternal(msg); +static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) { /* No internal data, allocate from scratch. */ - size_t size = UPB_MAX(128, _upb_lg2ceilsize(need + overhead)); - upb_msg_internaldata *internal = upb_arena_malloc(arena, size); + size_t size = UPB_MAX(128, _upb_Log2Ceilingsize(need + overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); if (!internal) return false; internal->size = size; internal->unknown_end = overhead; @@ -1511,15 +1936,15 @@ static bool realloc_internal(upb_msg *msg, size_t need, upb_arena *arena) { in->internal = internal; } else if (in->internal->ext_begin - in->internal->unknown_end < need) { /* Internal data is too small, reallocate. */ - size_t new_size = _upb_lg2ceilsize(in->internal->size + need); + size_t new_size = _upb_Log2Ceilingsize(in->internal->size + need); size_t ext_bytes = in->internal->size - in->internal->ext_begin; size_t new_ext_begin = new_size - ext_bytes; - upb_msg_internaldata *internal = - upb_arena_realloc(arena, in->internal, in->internal->size, new_size); + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); if (!internal) return false; if (ext_bytes) { /* Need to move extension data to the end. */ - char *ptr = (char*)internal; + char* ptr = (char*)internal; memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); } internal->ext_begin = new_ext_begin; @@ -1530,24 +1955,24 @@ static bool realloc_internal(upb_msg *msg, size_t need, upb_arena *arena) { return true; } -bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, - upb_arena *arena) { +bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena) { if (!realloc_internal(msg, len, arena)) return false; - upb_msg_internal *in = upb_msg_getinternal(msg); + upb_Message_Internal* in = upb_Message_Getinternal(msg); memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); in->internal->unknown_end += len; return true; } -void _upb_msg_discardunknown_shallow(upb_msg *msg) { - upb_msg_internal *in = upb_msg_getinternal(msg); +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); if (in->internal) { in->internal->unknown_end = overhead; } } -const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) { - const upb_msg_internal *in = upb_msg_getinternal_const(msg); +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); if (in->internal) { *len = in->internal->unknown_end - overhead; return (char*)(in->internal + 1); @@ -1557,11 +1982,12 @@ const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) { } } -const upb_msg_ext *_upb_msg_getexts(const upb_msg *msg, size_t *count) { - const upb_msg_internal *in = upb_msg_getinternal_const(msg); +const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); if (in->internal) { - *count = - (in->internal->size - in->internal->ext_begin) / sizeof(upb_msg_ext); + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(upb_Message_Extension); return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); } else { *count = 0; @@ -1569,10 +1995,10 @@ const upb_msg_ext *_upb_msg_getexts(const upb_msg *msg, size_t *count) { } } -const upb_msg_ext *_upb_msg_getext(const upb_msg *msg, - const upb_msglayout_ext *e) { +const upb_Message_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTable_Extension* e) { size_t n; - const upb_msg_ext *ext = _upb_msg_getexts(msg, &n); + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); /* For now we use linear search exclusively to find extensions. If this * becomes an issue due to messages with lots of extensions, we can introduce @@ -1586,22 +2012,43 @@ const upb_msg_ext *_upb_msg_getext(const upb_msg *msg, return NULL; } -upb_msg_ext *_upb_msg_getorcreateext(upb_msg *msg, const upb_msglayout_ext *e, - upb_arena *arena) { - upb_msg_ext *ext = (upb_msg_ext*)_upb_msg_getext(msg, e); +void _upb_Message_Clearext(upb_Message* msg, + const upb_MiniTable_Extension* ext_l) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) return; + const upb_Message_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); + if (ext) { + *ext = *base; + in->internal->ext_begin += sizeof(upb_Message_Extension); + } +} + +upb_Message_Extension* _upb_Message_Getorcreateext( + upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!realloc_internal(msg, sizeof(upb_msg_ext), arena)) return NULL; - upb_msg_internal *in = upb_msg_getinternal(msg); - in->internal->ext_begin -= sizeof(upb_msg_ext); + if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(upb_Message_Extension); ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_msg_ext)); + memset(ext, 0, sizeof(upb_Message_Extension)); ext->ext = e; return ext; } -/** upb_array *****************************************************************/ +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + _upb_Message_Getexts(msg, &count); + return count; +} + +/** upb_Array *****************************************************************/ -bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena) { +bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena) { size_t new_size = UPB_MAX(arr->size, 4); int elem_size_lg2 = arr->data & 7; size_t old_bytes = arr->size << elem_size_lg2; @@ -1612,7 +2059,7 @@ bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena) { while (new_size < min_size) new_size *= 2; new_bytes = new_size << elem_size_lg2; - ptr = upb_arena_realloc(arena, ptr, old_bytes, new_bytes); + ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); if (!ptr) { return false; @@ -1623,44 +2070,44 @@ bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena) { return true; } -static upb_array *getorcreate_array(upb_array **arr_ptr, int elem_size_lg2, - upb_arena *arena) { - upb_array *arr = *arr_ptr; +static upb_Array* getorcreate_array(upb_Array** arr_ptr, int elem_size_lg2, + upb_Arena* arena) { + upb_Array* arr = *arr_ptr; if (!arr) { - arr = _upb_array_new(arena, 4, elem_size_lg2); + arr = _upb_Array_New(arena, 4, elem_size_lg2); if (!arr) return NULL; *arr_ptr = arr; } return arr; } -void *_upb_array_resize_fallback(upb_array **arr_ptr, size_t size, - int elem_size_lg2, upb_arena *arena) { - upb_array *arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); - return arr && _upb_array_resize(arr, size, arena) ? _upb_array_ptr(arr) +void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, + int elem_size_lg2, upb_Arena* arena) { + upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); + return arr && _upb_Array_Resize(arr, size, arena) ? _upb_array_ptr(arr) : NULL; } -bool _upb_array_append_fallback(upb_array **arr_ptr, const void *value, - int elem_size_lg2, upb_arena *arena) { - upb_array *arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); +bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, + int elem_size_lg2, upb_Arena* arena) { + upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); if (!arr) return false; size_t elems = arr->len; - if (!_upb_array_resize(arr, elems + 1, arena)) { + if (!_upb_Array_Resize(arr, elems + 1, arena)) { return false; } - char *data = _upb_array_ptr(arr); + char* data = _upb_array_ptr(arr); memcpy(data + (elems << elem_size_lg2), value, 1 << elem_size_lg2); return true; } -/** upb_map *******************************************************************/ +/** upb_Map *******************************************************************/ -upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size) { - upb_map *map = upb_arena_malloc(a, sizeof(upb_map)); +upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { + upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); if (!map) { return NULL; @@ -1673,65 +2120,69 @@ upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size) { return map; } -static void _upb_mapsorter_getkeys(const void *_a, const void *_b, void *a_key, - void *b_key, size_t size) { - const upb_tabent *const*a = _a; - const upb_tabent *const*b = _b; - upb_strview a_tabkey = upb_tabstrview((*a)->key); - upb_strview b_tabkey = upb_tabstrview((*b)->key); +static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, + void* b_key, size_t size) { + const upb_tabent* const* a = _a; + const upb_tabent* const* b = _b; + upb_StringView a_tabkey = upb_tabstrview((*a)->key); + upb_StringView b_tabkey = upb_tabstrview((*b)->key); _upb_map_fromkey(a_tabkey, a_key, size); _upb_map_fromkey(b_tabkey, b_key, size); } -static int _upb_mapsorter_cmpi64(const void *_a, const void *_b) { +#define UPB_COMPARE_INTEGERS(a, b) ((a) < (b) ? -1 : ((a) == (b) ? 0 : 1)) + +static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { int64_t a, b; _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a - b; + return UPB_COMPARE_INTEGERS(a, b); } -static int _upb_mapsorter_cmpu64(const void *_a, const void *_b) { +static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { uint64_t a, b; _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a - b; + return UPB_COMPARE_INTEGERS(a, b); } -static int _upb_mapsorter_cmpi32(const void *_a, const void *_b) { +static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { int32_t a, b; _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a - b; + return UPB_COMPARE_INTEGERS(a, b); } -static int _upb_mapsorter_cmpu32(const void *_a, const void *_b) { +static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { uint32_t a, b; _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a - b; + return UPB_COMPARE_INTEGERS(a, b); } -static int _upb_mapsorter_cmpbool(const void *_a, const void *_b) { +static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { bool a, b; _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); - return a - b; + return UPB_COMPARE_INTEGERS(a, b); } -static int _upb_mapsorter_cmpstr(const void *_a, const void *_b) { - upb_strview a, b; +static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { + upb_StringView a, b; _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); size_t common_size = UPB_MIN(a.size, b.size); int cmp = memcmp(a.data, b.data, common_size); - if (cmp) return cmp; - return a.size - b.size; + if (cmp) return -cmp; + return UPB_COMPARE_INTEGERS(a.size, b.size); } -bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, - const upb_map *map, _upb_sortedmap *sorted) { - int map_size = _upb_map_size(map); +#undef UPB_COMPARE_INTEGERS + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted) { + int map_size = _upb_Map_Size(map); sorted->start = s->size; sorted->pos = sorted->start; sorted->end = sorted->start + map_size; /* Grow s->entries if necessary. */ if (sorted->end > s->cap) { - s->cap = _upb_lg2ceilsize(sorted->end); + s->cap = _upb_Log2Ceilingsize(sorted->end); s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); if (!s->entries) return false; } @@ -1739,9 +2190,9 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, s->size = sorted->end; /* Copy non-empty entries from the table to s->entries. */ - upb_tabent const**dst = &s->entries[sorted->start]; - const upb_tabent *src = map->table.t.entries; - const upb_tabent *end = src + upb_table_size(&map->table.t); + upb_tabent const** dst = &s->entries[sorted->start]; + const upb_tabent* src = map->table.t.entries; + const upb_tabent* end = src + upb_table_size(&map->table.t); for (; src < end; src++) { if (!upb_tabent_isempty(src)) { *dst = src; @@ -1752,32 +2203,33 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, /* Sort entries according to the key type. */ - int (*compar)(const void *, const void *); + int (*compar)(const void*, const void*); switch (key_type) { - case UPB_DESCRIPTOR_TYPE_INT64: - case UPB_DESCRIPTOR_TYPE_SFIXED64: - case UPB_DESCRIPTOR_TYPE_SINT64: + case kUpb_FieldType_Int64: + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_SInt64: compar = _upb_mapsorter_cmpi64; break; - case UPB_DESCRIPTOR_TYPE_UINT64: - case UPB_DESCRIPTOR_TYPE_FIXED64: + case kUpb_FieldType_UInt64: + case kUpb_FieldType_Fixed64: compar = _upb_mapsorter_cmpu64; break; - case UPB_DESCRIPTOR_TYPE_INT32: - case UPB_DESCRIPTOR_TYPE_SINT32: - case UPB_DESCRIPTOR_TYPE_SFIXED32: - case UPB_DESCRIPTOR_TYPE_ENUM: + case kUpb_FieldType_Int32: + case kUpb_FieldType_SInt32: + case kUpb_FieldType_SFixed32: + case kUpb_FieldType_Enum: compar = _upb_mapsorter_cmpi32; break; - case UPB_DESCRIPTOR_TYPE_UINT32: - case UPB_DESCRIPTOR_TYPE_FIXED32: + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Fixed32: compar = _upb_mapsorter_cmpu32; break; - case UPB_DESCRIPTOR_TYPE_BOOL: + case kUpb_FieldType_Bool: compar = _upb_mapsorter_cmpbool; break; - case UPB_DESCRIPTOR_TYPE_STRING: + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: compar = _upb_mapsorter_cmpstr; break; default: @@ -1788,36 +2240,39 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, return true; } -/** upb_extreg ****************************************************************/ +/** upb_ExtensionRegistry + * ****************************************************************/ -struct upb_extreg { - upb_arena *arena; - upb_strtable exts; /* Key is upb_msglayout* concatenated with fieldnum. */ +struct upb_ExtensionRegistry { + upb_Arena* arena; + upb_strtable exts; /* Key is upb_MiniTable* concatenated with fieldnum. */ }; -#define EXTREG_KEY_SIZE (sizeof(upb_msglayout*) + sizeof(uint32_t)) +#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) -static void extreg_key(char *buf, const upb_msglayout *l, uint32_t fieldnum) { +static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { memcpy(buf, &l, sizeof(l)); memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); } -upb_extreg *upb_extreg_new(upb_arena *arena) { - upb_extreg *r = upb_arena_malloc(arena, sizeof(*r)); +upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { + upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); if (!r) return NULL; r->arena = arena; if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; return r; } -bool _upb_extreg_add(upb_extreg *r, const upb_msglayout_ext *e, size_t count) { +bool _upb_extreg_add(upb_ExtensionRegistry* r, + const upb_MiniTable_Extension** e, size_t count) { char buf[EXTREG_KEY_SIZE]; - const upb_msglayout_ext *start = e; - const upb_msglayout_ext *end = e + count; + const upb_MiniTable_Extension** start = e; + const upb_MiniTable_Extension** end = UPB_PTRADD(e, count); for (; e < end; e++) { - extreg_key(buf, e->extendee, e->field.number); + const upb_MiniTable_Extension* ext = *e; + extreg_key(buf, ext->extendee, ext->field.number); if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, - upb_value_constptr(e), r->arena)) { + upb_value_constptr(ext), r->arena)) { goto failure; } } @@ -1826,15 +2281,16 @@ bool _upb_extreg_add(upb_extreg *r, const upb_msglayout_ext *e, size_t count) { failure: /* Back out the entries previously added. */ for (end = e, e = start; e < end; e++) { - extreg_key(buf, e->extendee, e->field.number); - upb_strtable_remove(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + const upb_MiniTable_Extension* ext = *e; + extreg_key(buf, ext->extendee, ext->field.number); + upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); } return false; } -const upb_msglayout_field *_upb_extreg_get(const upb_extreg *r, - const upb_msglayout *l, - uint32_t num) { +const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, + const upb_MiniTable* l, + uint32_t num) { char buf[EXTREG_KEY_SIZE]; upb_value v; extreg_key(buf, l, num); @@ -1857,11 +2313,11 @@ const upb_msglayout_field *_upb_extreg_get(const upb_extreg *r, /* Must be last. */ -#define UPB_MAXARRSIZE 16 /* 64k. */ +#define UPB_MAXARRSIZE 16 /* 64k. */ /* From Chromium. */ #define ARRAY_SIZE(x) \ - ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) + ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) static const double MAX_LOAD = 0.85; @@ -1882,20 +2338,20 @@ static int log2ceil(uint64_t v) { int ret = 0; bool pow2 = is_pow2(v); while (v >>= 1) ret++; - ret = pow2 ? ret : ret + 1; /* Ceiling. */ + ret = pow2 ? ret : ret + 1; /* Ceiling. */ return UPB_MIN(UPB_MAXARRSIZE, ret); } -char *upb_strdup2(const char *s, size_t len, upb_arena *a) { +char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { size_t n; - char *p; + char* p; /* Prevent overflow errors. */ if (len == SIZE_MAX) return NULL; /* Always null-terminate, even if binary data; but don't rely on the input to * have a null-terminating byte since it may be a raw binary buffer. */ n = len + 1; - p = upb_arena_malloc(a, n); + p = upb_Arena_Malloc(a, n); if (p) { memcpy(p, s, len); p[len] = 0; @@ -1907,12 +2363,12 @@ char *upb_strdup2(const char *s, size_t len, upb_arena *a) { typedef union { uintptr_t num; struct { - const char *str; + const char* str; size_t len; } str; } lookupkey_t; -static lookupkey_t strkey2(const char *str, size_t len) { +static lookupkey_t strkey2(const char* str, size_t len) { lookupkey_t k; k.str.str = str; k.str.len = len; @@ -1930,24 +2386,17 @@ typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); /* Base table (shared code) ***************************************************/ -static uint32_t upb_inthash(uintptr_t key) { - return (uint32_t)key; -} +static uint32_t upb_inthash(uintptr_t key) { return (uint32_t)key; } -static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) { +static const upb_tabent* upb_getentry(const upb_table* t, uint32_t hash) { return t->entries + (hash & t->mask); } -static bool upb_arrhas(upb_tabval key) { - return key.val != (uint64_t)-1; -} - +static bool upb_arrhas(upb_tabval key) { return key.val != (uint64_t)-1; } -static bool isfull(upb_table *t) { - return t->count == t->max_count; -} +static bool isfull(upb_table* t) { return t->count == t->max_count; } -static bool init(upb_table *t, uint8_t size_lg2, upb_arena *a) { +static bool init(upb_table* t, uint8_t size_lg2, upb_Arena* a) { size_t bytes; t->count = 0; @@ -1956,7 +2405,7 @@ static bool init(upb_table *t, uint8_t size_lg2, upb_arena *a) { t->max_count = upb_table_size(t) * MAX_LOAD; bytes = upb_table_size(t) * sizeof(upb_tabent); if (bytes > 0) { - t->entries = upb_arena_malloc(a, bytes); + t->entries = upb_Arena_Malloc(a, bytes); if (!t->entries) return false; memset(t->entries, 0, bytes); } else { @@ -1965,9 +2414,9 @@ static bool init(upb_table *t, uint8_t size_lg2, upb_arena *a) { return true; } -static upb_tabent *emptyent(upb_table *t, upb_tabent *e) { - upb_tabent *begin = t->entries; - upb_tabent *end = begin + upb_table_size(t); +static upb_tabent* emptyent(upb_table* t, upb_tabent* e) { + upb_tabent* begin = t->entries; + upb_tabent* end = begin + upb_table_size(t); for (e = e + 1; e < end; e++) { if (upb_tabent_isempty(e)) return e; } @@ -1978,13 +2427,13 @@ static upb_tabent *emptyent(upb_table *t, upb_tabent *e) { return NULL; } -static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) { +static upb_tabent* getentry_mutable(upb_table* t, uint32_t hash) { return (upb_tabent*)upb_getentry(t, hash); } -static const upb_tabent *findentry(const upb_table *t, lookupkey_t key, - uint32_t hash, eqlfunc_t *eql) { - const upb_tabent *e; +static const upb_tabent* findentry(const upb_table* t, lookupkey_t key, + uint32_t hash, eqlfunc_t* eql) { + const upb_tabent* e; if (t->size_lg2 == 0) return NULL; e = upb_getentry(t, hash); @@ -1995,14 +2444,14 @@ static const upb_tabent *findentry(const upb_table *t, lookupkey_t key, } } -static upb_tabent *findentry_mutable(upb_table *t, lookupkey_t key, - uint32_t hash, eqlfunc_t *eql) { +static upb_tabent* findentry_mutable(upb_table* t, lookupkey_t key, + uint32_t hash, eqlfunc_t* eql) { return (upb_tabent*)findentry(t, key, hash, eql); } -static bool lookup(const upb_table *t, lookupkey_t key, upb_value *v, - uint32_t hash, eqlfunc_t *eql) { - const upb_tabent *e = findentry(t, key, hash, eql); +static bool lookup(const upb_table* t, lookupkey_t key, upb_value* v, + uint32_t hash, eqlfunc_t* eql) { + const upb_tabent* e = findentry(t, key, hash, eql); if (e) { if (v) { _upb_value_setval(v, e->val.val); @@ -2014,11 +2463,11 @@ static bool lookup(const upb_table *t, lookupkey_t key, upb_value *v, } /* The given key must not already exist in the table. */ -static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, - upb_value val, uint32_t hash, - hashfunc_t *hashfunc, eqlfunc_t *eql) { - upb_tabent *mainpos_e; - upb_tabent *our_e; +static void insert(upb_table* t, lookupkey_t key, upb_tabkey tabkey, + upb_value val, uint32_t hash, hashfunc_t* hashfunc, + eqlfunc_t* eql) { + upb_tabent* mainpos_e; + upb_tabent* our_e; UPB_ASSERT(findentry(t, key, hash, eql) == NULL); @@ -2031,12 +2480,13 @@ static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, our_e->next = NULL; } else { /* Collision. */ - upb_tabent *new_e = emptyent(t, mainpos_e); + upb_tabent* new_e = emptyent(t, mainpos_e); /* Head of collider's chain. */ - upb_tabent *chain = getentry_mutable(t, hashfunc(mainpos_e->key)); + upb_tabent* chain = getentry_mutable(t, hashfunc(mainpos_e->key)); if (chain == mainpos_e) { /* Existing ent is in its main position (it has the same hash as us, and - * is the head of our chain). Insert to new ent and append to this chain. */ + * is the head of our chain). Insert to new ent and append to this chain. + */ new_e->next = mainpos_e->next; mainpos_e->next = new_e; our_e = new_e; @@ -2044,7 +2494,7 @@ static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, /* Existing ent is not in its main position (it is a node in some other * chain). This implies that no existing ent in the table has our hash. * Evict it (updating its chain) and use its ent for head of our chain. */ - *new_e = *mainpos_e; /* copies next. */ + *new_e = *mainpos_e; /* copies next. */ while (chain->next != mainpos_e) { chain = (upb_tabent*)chain->next; UPB_ASSERT(chain); @@ -2059,9 +2509,9 @@ static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, UPB_ASSERT(findentry(t, key, hash, eql) == our_e); } -static bool rm(upb_table *t, lookupkey_t key, upb_value *val, - upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql) { - upb_tabent *chain = getentry_mutable(t, hash); +static bool rm(upb_table* t, lookupkey_t key, upb_value* val, + upb_tabkey* removed, uint32_t hash, eqlfunc_t* eql) { + upb_tabent* chain = getentry_mutable(t, hash); if (upb_tabent_isempty(chain)) return false; if (eql(chain->key, key)) { /* Element to remove is at the head of its chain. */ @@ -2069,11 +2519,11 @@ static bool rm(upb_table *t, lookupkey_t key, upb_value *val, if (val) _upb_value_setval(val, chain->val.val); if (removed) *removed = chain->key; if (chain->next) { - upb_tabent *move = (upb_tabent*)chain->next; + upb_tabent* move = (upb_tabent*)chain->next; *chain = *move; - move->key = 0; /* Make the slot empty. */ + move->key = 0; /* Make the slot empty. */ } else { - chain->key = 0; /* Make the slot empty. */ + chain->key = 0; /* Make the slot empty. */ } return true; } else { @@ -2084,11 +2534,11 @@ static bool rm(upb_table *t, lookupkey_t key, upb_value *val, } if (chain->next) { /* Found element to remove. */ - upb_tabent *rm = (upb_tabent*)chain->next; + upb_tabent* rm = (upb_tabent*)chain->next; t->count--; if (val) _upb_value_setval(val, chain->next->val.val); if (removed) *removed = rm->key; - rm->key = 0; /* Make the slot empty. */ + rm->key = 0; /* Make the slot empty. */ chain->next = rm->next; return true; } else { @@ -2098,27 +2548,24 @@ static bool rm(upb_table *t, lookupkey_t key, upb_value *val, } } -static size_t next(const upb_table *t, size_t i) { +static size_t next(const upb_table* t, size_t i) { do { - if (++i >= upb_table_size(t)) - return SIZE_MAX - 1; /* Distinct from -1. */ - } while(upb_tabent_isempty(&t->entries[i])); + if (++i >= upb_table_size(t)) return SIZE_MAX - 1; /* Distinct from -1. */ + } while (upb_tabent_isempty(&t->entries[i])); return i; } -static size_t begin(const upb_table *t) { - return next(t, -1); -} - +static size_t begin(const upb_table* t) { return next(t, -1); } /* upb_strtable ***************************************************************/ -/* A simple "subclass" of upb_table that only adds a hash function for strings. */ +/* A simple "subclass" of upb_table that only adds a hash function for strings. + */ -static upb_tabkey strcopy(lookupkey_t k2, upb_arena *a) { - uint32_t len = (uint32_t) k2.str.len; - char *str = upb_arena_malloc(a, k2.str.len + sizeof(uint32_t) + 1); +static upb_tabkey strcopy(lookupkey_t k2, upb_Arena* a) { + uint32_t len = (uint32_t)k2.str.len; + char* str = upb_Arena_Malloc(a, k2.str.len + sizeof(uint32_t) + 1); if (str == NULL) return 0; memcpy(str, &len, sizeof(uint32_t)); if (k2.str.len) memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len); @@ -2128,13 +2575,13 @@ static upb_tabkey strcopy(lookupkey_t k2, upb_arena *a) { /* Adapted from ABSL's wyhash. */ -static uint64_t UnalignedLoad64(const void *p) { +static uint64_t UnalignedLoad64(const void* p) { uint64_t val; memcpy(&val, p, 8); return val; } -static uint32_t UnalignedLoad32(const void *p) { +static uint32_t UnalignedLoad32(const void* p) { uint32_t val; memcpy(&val, p, 4); return val; @@ -2177,8 +2624,8 @@ static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { return low ^ high; } -uint64_t Wyhash(const void *data, size_t len, uint64_t seed, - const uint64_t salt[]) { +static uint64_t Wyhash(const void* data, size_t len, uint64_t seed, + const uint64_t salt[]) { const uint8_t* ptr = (const uint8_t*)data; uint64_t starting_length = (uint64_t)len; uint64_t current_state = seed ^ salt[0]; @@ -2261,45 +2708,45 @@ const uint64_t kWyhashSalt[5] = { 0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL, }; -static uint32_t table_hash(const char *p, size_t n) { +static uint32_t table_hash(const char* p, size_t n) { return Wyhash(p, n, 0, kWyhashSalt); } static uint32_t strhash(upb_tabkey key) { uint32_t len; - char *str = upb_tabstr(key, &len); + char* str = upb_tabstr(key, &len); return table_hash(str, len); } static bool streql(upb_tabkey k1, lookupkey_t k2) { uint32_t len; - char *str = upb_tabstr(k1, &len); + char* str = upb_tabstr(k1, &len); return len == k2.str.len && (len == 0 || memcmp(str, k2.str.str, len) == 0); } -bool upb_strtable_init(upb_strtable *t, size_t expected_size, upb_arena *a) { - // Multiply by approximate reciprocal of MAX_LOAD (0.85), with pow2 denominator. +bool upb_strtable_init(upb_strtable* t, size_t expected_size, upb_Arena* a) { + // Multiply by approximate reciprocal of MAX_LOAD (0.85), with pow2 + // denominator. size_t need_entries = (expected_size + 1) * 1204 / 1024; UPB_ASSERT(need_entries >= expected_size * 0.85); - int size_lg2 = _upb_lg2ceil(need_entries); + int size_lg2 = _upb_Log2Ceiling(need_entries); return init(&t->t, size_lg2, a); } -void upb_strtable_clear(upb_strtable *t) { +void upb_strtable_clear(upb_strtable* t) { size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent); t->t.count = 0; memset((char*)t->t.entries, 0, bytes); } -bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_arena *a) { +bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a) { upb_strtable new_table; upb_strtable_iter i; - if (!init(&new_table.t, size_lg2, a)) - return false; + if (!init(&new_table.t, size_lg2, a)) return false; upb_strtable_begin(&i, t); - for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) { - upb_strview key = upb_strtable_iter_key(&i); + for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { + upb_StringView key = upb_strtable_iter_key(&i); upb_strtable_insert(&new_table, key.data, key.size, upb_strtable_iter_value(&i), a); } @@ -2307,8 +2754,8 @@ bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_arena *a) { return true; } -bool upb_strtable_insert(upb_strtable *t, const char *k, size_t len, - upb_value v, upb_arena *a) { +bool upb_strtable_insert(upb_strtable* t, const char* k, size_t len, + upb_value v, upb_Arena* a) { lookupkey_t key; upb_tabkey tabkey; uint32_t hash; @@ -2329,14 +2776,14 @@ bool upb_strtable_insert(upb_strtable *t, const char *k, size_t len, return true; } -bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, - upb_value *v) { +bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, + upb_value* v) { uint32_t hash = table_hash(key, len); return lookup(&t->t, strkey2(key, len), v, hash, &streql); } -bool upb_strtable_remove(upb_strtable *t, const char *key, size_t len, - upb_value *val) { +bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, + upb_value* val) { uint32_t hash = table_hash(key, len); upb_tabkey tabkey; return rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql); @@ -2344,23 +2791,23 @@ bool upb_strtable_remove(upb_strtable *t, const char *key, size_t len, /* Iteration */ -void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) { +void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t) { i->t = t; i->index = begin(&t->t); } -void upb_strtable_next(upb_strtable_iter *i) { +void upb_strtable_next(upb_strtable_iter* i) { i->index = next(&i->t->t, i->index); } -bool upb_strtable_done(const upb_strtable_iter *i) { +bool upb_strtable_done(const upb_strtable_iter* i) { if (!i->t) return true; return i->index >= upb_table_size(&i->t->t) || upb_tabent_isempty(str_tabent(i)); } -upb_strview upb_strtable_iter_key(const upb_strtable_iter *i) { - upb_strview key; +upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i) { + upb_StringView key; uint32_t len; UPB_ASSERT(!upb_strtable_done(i)); key.data = upb_tabstr(str_tabent(i)->key, &len); @@ -2368,24 +2815,22 @@ upb_strview upb_strtable_iter_key(const upb_strtable_iter *i) { return key; } -upb_value upb_strtable_iter_value(const upb_strtable_iter *i) { +upb_value upb_strtable_iter_value(const upb_strtable_iter* i) { UPB_ASSERT(!upb_strtable_done(i)); return _upb_value_val(str_tabent(i)->val.val); } -void upb_strtable_iter_setdone(upb_strtable_iter *i) { +void upb_strtable_iter_setdone(upb_strtable_iter* i) { i->t = NULL; i->index = SIZE_MAX; } -bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, - const upb_strtable_iter *i2) { - if (upb_strtable_done(i1) && upb_strtable_done(i2)) - return true; +bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, + const upb_strtable_iter* i2) { + if (upb_strtable_done(i1) && upb_strtable_done(i2)) return true; return i1->t == i2->t && i1->index == i2->index; } - /* upb_inttable ***************************************************************/ /* For inttables we use a hybrid structure where small keys are kept in an @@ -2393,34 +2838,32 @@ bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, static uint32_t inthash(upb_tabkey key) { return upb_inthash(key); } -static bool inteql(upb_tabkey k1, lookupkey_t k2) { - return k1 == k2.num; -} +static bool inteql(upb_tabkey k1, lookupkey_t k2) { return k1 == k2.num; } -static upb_tabval *mutable_array(upb_inttable *t) { +static upb_tabval* mutable_array(upb_inttable* t) { return (upb_tabval*)t->array; } -static upb_tabval *inttable_val(upb_inttable *t, uintptr_t key) { +static upb_tabval* inttable_val(upb_inttable* t, uintptr_t key) { if (key < t->array_size) { return upb_arrhas(t->array[key]) ? &(mutable_array(t)[key]) : NULL; } else { - upb_tabent *e = + upb_tabent* e = findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql); return e ? &e->val : NULL; } } -static const upb_tabval *inttable_val_const(const upb_inttable *t, +static const upb_tabval* inttable_val_const(const upb_inttable* t, uintptr_t key) { return inttable_val((upb_inttable*)t, key); } -size_t upb_inttable_count(const upb_inttable *t) { +size_t upb_inttable_count(const upb_inttable* t) { return t->t.count + t->array_count; } -static void check(upb_inttable *t) { +static void check(upb_inttable* t) { UPB_UNUSED(t); #if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) { @@ -2428,7 +2871,7 @@ static void check(upb_inttable *t) { size_t count = 0; upb_inttable_iter i; upb_inttable_begin(&i, t); - for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) { + for (; !upb_inttable_done(&i); upb_inttable_next(&i), count++) { UPB_ASSERT(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL)); } UPB_ASSERT(count == upb_inttable_count(t)); @@ -2436,8 +2879,8 @@ static void check(upb_inttable *t) { #endif } -bool upb_inttable_sizedinit(upb_inttable *t, size_t asize, int hsize_lg2, - upb_arena *a) { +bool upb_inttable_sizedinit(upb_inttable* t, size_t asize, int hsize_lg2, + upb_Arena* a) { size_t array_bytes; if (!init(&t->t, hsize_lg2, a)) return false; @@ -2446,7 +2889,7 @@ bool upb_inttable_sizedinit(upb_inttable *t, size_t asize, int hsize_lg2, t->array_size = UPB_MAX(1, asize); t->array_count = 0; array_bytes = t->array_size * sizeof(upb_value); - t->array = upb_arena_malloc(a, array_bytes); + t->array = upb_Arena_Malloc(a, array_bytes); if (!t->array) { return false; } @@ -2455,15 +2898,16 @@ bool upb_inttable_sizedinit(upb_inttable *t, size_t asize, int hsize_lg2, return true; } -bool upb_inttable_init(upb_inttable *t, upb_arena *a) { +bool upb_inttable_init(upb_inttable* t, upb_Arena* a) { return upb_inttable_sizedinit(t, 0, 4, a); } -bool upb_inttable_insert(upb_inttable *t, uintptr_t key, upb_value val, - upb_arena *a) { +bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, + upb_Arena* a) { upb_tabval tabval; tabval.val = val.val; - UPB_ASSERT(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */ + UPB_ASSERT( + upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */ if (key < t->array_size) { UPB_ASSERT(!upb_arrhas(t->array[key])); @@ -2480,7 +2924,7 @@ bool upb_inttable_insert(upb_inttable *t, uintptr_t key, upb_value val, } for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { - const upb_tabent *e = &t->t.entries[i]; + const upb_tabent* e = &t->t.entries[i]; uint32_t hash; upb_value v; @@ -2499,21 +2943,21 @@ bool upb_inttable_insert(upb_inttable *t, uintptr_t key, upb_value val, return true; } -bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) { - const upb_tabval *table_v = inttable_val_const(t, key); +bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v) { + const upb_tabval* table_v = inttable_val_const(t, key); if (!table_v) return false; if (v) _upb_value_setval(v, table_v->val); return true; } -bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val) { - upb_tabval *table_v = inttable_val(t, key); +bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val) { + upb_tabval* table_v = inttable_val(t, key); if (!table_v) return false; table_v->val = val.val; return true; } -bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val) { +bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val) { bool success; if (key < t->array_size) { if (upb_arrhas(t->array[key])) { @@ -2534,7 +2978,7 @@ bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val) { return success; } -void upb_inttable_compact(upb_inttable *t, upb_arena *a) { +void upb_inttable_compact(upb_inttable* t, upb_Arena* a) { /* A power-of-two histogram of the table keys. */ size_t counts[UPB_MAXARRSIZE + 1] = {0}; @@ -2573,7 +3017,7 @@ void upb_inttable_compact(upb_inttable *t, upb_arena *a) { { /* Insert all elements into new, perfectly-sized table. */ - size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ + size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ size_t hash_count = upb_inttable_count(t) - arr_count; size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; int hashsize_lg2 = log2ceil(hash_size); @@ -2592,25 +3036,25 @@ void upb_inttable_compact(upb_inttable *t, upb_arena *a) { /* Iteration. */ -static const upb_tabent *int_tabent(const upb_inttable_iter *i) { +static const upb_tabent* int_tabent(const upb_inttable_iter* i) { UPB_ASSERT(!i->array_part); return &i->t->t.entries[i->index]; } -static upb_tabval int_arrent(const upb_inttable_iter *i) { +static upb_tabval int_arrent(const upb_inttable_iter* i) { UPB_ASSERT(i->array_part); return i->t->array[i->index]; } -void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t) { +void upb_inttable_begin(upb_inttable_iter* i, const upb_inttable* t) { i->t = t; i->index = -1; i->array_part = true; upb_inttable_next(i); } -void upb_inttable_next(upb_inttable_iter *iter) { - const upb_inttable *t = iter->t; +void upb_inttable_next(upb_inttable_iter* iter) { + const upb_inttable* t = iter->t; if (iter->array_part) { while (++iter->index < t->array_size) { if (upb_arrhas(int_arrent(iter))) { @@ -2624,45 +3068,137 @@ void upb_inttable_next(upb_inttable_iter *iter) { } } -bool upb_inttable_done(const upb_inttable_iter *i) { +bool upb_inttable_next2(const upb_inttable* t, uintptr_t* key, upb_value* val, + intptr_t* iter) { + intptr_t i = *iter; + if (i < t->array_size) { + while (++i < t->array_size) { + upb_tabval ent = t->array[i]; + if (upb_arrhas(ent)) { + *key = i; + *val = _upb_value_val(ent.val); + *iter = i; + return true; + } + } + } + + size_t tab_idx = next(&t->t, i == -1 ? -1 : i - t->array_size); + if (tab_idx < upb_table_size(&t->t)) { + upb_tabent* ent = &t->t.entries[tab_idx]; + *key = ent->key; + *val = _upb_value_val(ent->val.val); + *iter = tab_idx + t->array_size; + return true; + } + + return false; +} + +void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter) { + intptr_t i = *iter; + if (i < t->array_size) { + t->array_count--; + mutable_array(t)[i].val = -1; + } else { + upb_tabent* ent = &t->t.entries[i - t->array_size]; + upb_tabent* prev = NULL; + + // Linear search, not great. + upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; + for (upb_tabent* e = t->t.entries; e != end; e++) { + if (e->next == ent) { + prev = e; + break; + } + } + + if (prev) { + prev->next = ent->next; + } + + t->t.count--; + ent->key = 0; + ent->next = NULL; + } +} + +bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, + upb_value* val, intptr_t* iter) { + size_t tab_idx = next(&t->t, *iter); + if (tab_idx < upb_table_size(&t->t)) { + upb_tabent* ent = &t->t.entries[tab_idx]; + uint32_t len; + key->data = upb_tabstr(ent->key, &len); + key->size = len; + *val = _upb_value_val(ent->val.val); + *iter = tab_idx; + return true; + } + + return false; +} + +void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter) { + intptr_t i = *iter; + upb_tabent* ent = &t->t.entries[i]; + upb_tabent* prev = NULL; + + // Linear search, not great. + upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; + for (upb_tabent* e = t->t.entries; e != end; e++) { + if (e->next == ent) { + prev = e; + break; + } + } + + if (prev) { + prev->next = ent->next; + } + + t->t.count--; + ent->key = 0; + ent->next = NULL; +} + +bool upb_inttable_done(const upb_inttable_iter* i) { if (!i->t) return true; if (i->array_part) { - return i->index >= i->t->array_size || - !upb_arrhas(int_arrent(i)); + return i->index >= i->t->array_size || !upb_arrhas(int_arrent(i)); } else { return i->index >= upb_table_size(&i->t->t) || upb_tabent_isempty(int_tabent(i)); } } -uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) { +uintptr_t upb_inttable_iter_key(const upb_inttable_iter* i) { UPB_ASSERT(!upb_inttable_done(i)); return i->array_part ? i->index : int_tabent(i)->key; } -upb_value upb_inttable_iter_value(const upb_inttable_iter *i) { +upb_value upb_inttable_iter_value(const upb_inttable_iter* i) { UPB_ASSERT(!upb_inttable_done(i)); - return _upb_value_val( - i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val); + return _upb_value_val(i->array_part ? i->t->array[i->index].val + : int_tabent(i)->val.val); } -void upb_inttable_iter_setdone(upb_inttable_iter *i) { +void upb_inttable_iter_setdone(upb_inttable_iter* i) { i->t = NULL; i->index = SIZE_MAX; i->array_part = false; } -bool upb_inttable_iter_isequal(const upb_inttable_iter *i1, - const upb_inttable_iter *i2) { - if (upb_inttable_done(i1) && upb_inttable_done(i2)) - return true; +bool upb_inttable_iter_isequal(const upb_inttable_iter* i1, + const upb_inttable_iter* i2) { + if (upb_inttable_done(i1) && upb_inttable_done(i2)) return true; return i1->t == i2->t && i1->index == i2->index && i1->array_part == i2->array_part; } /** upb/upb.c ************************************************************/ - #include +#include #include #include #include @@ -2671,51 +3207,57 @@ bool upb_inttable_iter_isequal(const upb_inttable_iter *i1, #include -/* upb_status *****************************************************************/ +// Must be last. + +/* upb_Status *****************************************************************/ -void upb_status_clear(upb_status *status) { +void upb_Status_Clear(upb_Status* status) { if (!status) return; status->ok = true; status->msg[0] = '\0'; } -bool upb_ok(const upb_status *status) { return status->ok; } +bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } -const char *upb_status_errmsg(const upb_status *status) { return status->msg; } +const char* upb_Status_ErrorMessage(const upb_Status* status) { + return status->msg; +} -void upb_status_seterrmsg(upb_status *status, const char *msg) { +void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { if (!status) return; status->ok = false; - strncpy(status->msg, msg, UPB_STATUS_MAX_MESSAGE - 1); - status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0'; + strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; } -void upb_status_seterrf(upb_status *status, const char *fmt, ...) { +void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { va_list args; va_start(args, fmt); - upb_status_vseterrf(status, fmt, args); + upb_Status_VSetErrorFormat(status, fmt, args); va_end(args); } -void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { +void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, + va_list args) { if (!status) return; status->ok = false; vsnprintf(status->msg, sizeof(status->msg), fmt, args); - status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0'; + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; } -void upb_status_vappenderrf(upb_status *status, const char *fmt, va_list args) { +void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, + va_list args) { size_t len; if (!status) return; status->ok = false; len = strlen(status->msg); vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); - status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0'; + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; } /* upb_alloc ******************************************************************/ -static void *upb_global_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize, +static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, size_t size) { UPB_UNUSED(alloc); UPB_UNUSED(oldsize); @@ -2727,53 +3269,53 @@ static void *upb_global_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize, } } -static uint32_t *upb_cleanup_pointer(uintptr_t cleanup_metadata) { - return (uint32_t *)(cleanup_metadata & ~0x1); +static uint32_t* upb_cleanup_pointer(uintptr_t cleanup_metadata) { + return (uint32_t*)(cleanup_metadata & ~0x1); } static bool upb_cleanup_has_initial_block(uintptr_t cleanup_metadata) { return cleanup_metadata & 0x1; } -static uintptr_t upb_cleanup_metadata(uint32_t *cleanup, +static uintptr_t upb_cleanup_metadata(uint32_t* cleanup, bool has_initial_block) { return (uintptr_t)cleanup | has_initial_block; } upb_alloc upb_alloc_global = {&upb_global_allocfunc}; -/* upb_arena ******************************************************************/ +/* upb_Arena ******************************************************************/ /* Be conservative and choose 16 in case anyone is using SSE. */ struct mem_block { - struct mem_block *next; + struct mem_block* next; uint32_t size; uint32_t cleanups; /* Data follows. */ }; typedef struct cleanup_ent { - upb_cleanup_func *cleanup; - void *ud; + upb_CleanupFunc* cleanup; + void* ud; } cleanup_ent; static const size_t memblock_reserve = UPB_ALIGN_UP(sizeof(mem_block), 16); -static upb_arena *arena_findroot(upb_arena *a) { +static upb_Arena* arena_findroot(upb_Arena* a) { /* Path splitting keeps time complexity down, see: * https://en.wikipedia.org/wiki/Disjoint-set_data_structure */ while (a->parent != a) { - upb_arena *next = a->parent; + upb_Arena* next = a->parent; a->parent = next->parent; a = next; } return a; } -static void upb_arena_addblock(upb_arena *a, upb_arena *root, void *ptr, +static void upb_Arena_addblock(upb_Arena* a, upb_Arena* root, void* ptr, size_t size) { - mem_block *block = ptr; + mem_block* block = ptr; /* The block is for arena |a|, but should appear in the freelist of |root|. */ block->next = root->freelist; @@ -2791,33 +3333,33 @@ static void upb_arena_addblock(upb_arena *a, upb_arena *root, void *ptr, UPB_POISON_MEMORY_REGION(a->head.ptr, a->head.end - a->head.ptr); } -static bool upb_arena_allocblock(upb_arena *a, size_t size) { - upb_arena *root = arena_findroot(a); +static bool upb_Arena_Allocblock(upb_Arena* a, size_t size) { + upb_Arena* root = arena_findroot(a); size_t block_size = UPB_MAX(size, a->last_size * 2) + memblock_reserve; - mem_block *block = upb_malloc(root->block_alloc, block_size); + mem_block* block = upb_malloc(root->block_alloc, block_size); if (!block) return false; - upb_arena_addblock(a, root, block, block_size); + upb_Arena_addblock(a, root, block, block_size); return true; } -void *_upb_arena_slowmalloc(upb_arena *a, size_t size) { - if (!upb_arena_allocblock(a, size)) return NULL; /* Out of memory. */ - UPB_ASSERT(_upb_arenahas(a) >= size); - return upb_arena_malloc(a, size); +void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size) { + if (!upb_Arena_Allocblock(a, size)) return NULL; /* Out of memory. */ + UPB_ASSERT(_upb_ArenaHas(a) >= size); + return upb_Arena_Malloc(a, size); } -static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize, +static void* upb_Arena_doalloc(upb_alloc* alloc, void* ptr, size_t oldsize, size_t size) { - upb_arena *a = (upb_arena*)alloc; /* upb_alloc is initial member. */ - return upb_arena_realloc(a, ptr, oldsize, size); + upb_Arena* a = (upb_Arena*)alloc; /* upb_alloc is initial member. */ + return upb_Arena_Realloc(a, ptr, oldsize, size); } /* Public Arena API ***********************************************************/ -upb_arena *arena_initslow(void *mem, size_t n, upb_alloc *alloc) { - const size_t first_block_overhead = sizeof(upb_arena) + memblock_reserve; - upb_arena *a; +upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { + const size_t first_block_overhead = sizeof(upb_Arena) + memblock_reserve; + upb_Arena* a; /* We need to malloc the initial block. */ n = first_block_overhead + 256; @@ -2825,10 +3367,10 @@ upb_arena *arena_initslow(void *mem, size_t n, upb_alloc *alloc) { return NULL; } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_arena); + a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); n -= sizeof(*a); - a->head.alloc.func = &upb_arena_doalloc; + a->head.alloc.func = &upb_Arena_doalloc; a->block_alloc = alloc; a->parent = a; a->refcount = 1; @@ -2836,25 +3378,33 @@ upb_arena *arena_initslow(void *mem, size_t n, upb_alloc *alloc) { a->freelist_tail = NULL; a->cleanup_metadata = upb_cleanup_metadata(NULL, false); - upb_arena_addblock(a, a, mem, n); + upb_Arena_addblock(a, a, mem, n); return a; } -upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc) { - upb_arena *a; +upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { + upb_Arena* a; + + if (n) { + /* Align initial pointer up so that we return properly-aligned pointers. */ + void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, 16); + size_t delta = (uintptr_t)aligned - (uintptr_t)mem; + n = delta <= n ? n - delta : 0; + mem = aligned; + } /* Round block size down to alignof(*a) since we will allocate the arena * itself at the end. */ - n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_arena)); + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena)); - if (UPB_UNLIKELY(n < sizeof(upb_arena))) { + if (UPB_UNLIKELY(n < sizeof(upb_Arena))) { return arena_initslow(mem, n, alloc); } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_arena); + a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); - a->head.alloc.func = &upb_arena_doalloc; + a->head.alloc.func = &upb_Arena_doalloc; a->block_alloc = alloc; a->parent = a; a->refcount = 1; @@ -2867,18 +3417,18 @@ upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc) { return a; } -static void arena_dofree(upb_arena *a) { - mem_block *block = a->freelist; +static void arena_dofree(upb_Arena* a) { + mem_block* block = a->freelist; UPB_ASSERT(a->parent == a); UPB_ASSERT(a->refcount == 0); while (block) { /* Load first since we are deleting block. */ - mem_block *next = block->next; + mem_block* next = block->next; if (block->cleanups > 0) { - cleanup_ent *end = UPB_PTR_AT(block, block->size, void); - cleanup_ent *ptr = end - block->cleanups; + cleanup_ent* end = UPB_PTR_AT(block, block->size, void); + cleanup_ent* ptr = end - block->cleanups; for (; ptr < end; ptr++) { ptr->cleanup(ptr->ud); @@ -2890,18 +3440,18 @@ static void arena_dofree(upb_arena *a) { } } -void upb_arena_free(upb_arena *a) { +void upb_Arena_Free(upb_Arena* a) { a = arena_findroot(a); if (--a->refcount == 0) arena_dofree(a); } -bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func) { - cleanup_ent *ent; +bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func) { + cleanup_ent* ent; uint32_t* cleanups = upb_cleanup_pointer(a->cleanup_metadata); - if (!cleanups || _upb_arenahas(a) < sizeof(cleanup_ent)) { - if (!upb_arena_allocblock(a, 128)) return false; /* Out of memory. */ - UPB_ASSERT(_upb_arenahas(a) >= sizeof(cleanup_ent)); + if (!cleanups || _upb_ArenaHas(a) < sizeof(cleanup_ent)) { + if (!upb_Arena_Allocblock(a, 128)) return false; /* Out of memory. */ + UPB_ASSERT(_upb_ArenaHas(a) >= sizeof(cleanup_ent)); cleanups = upb_cleanup_pointer(a->cleanup_metadata); } @@ -2916,11 +3466,11 @@ bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func) { return true; } -bool upb_arena_fuse(upb_arena *a1, upb_arena *a2) { - upb_arena *r1 = arena_findroot(a1); - upb_arena *r2 = arena_findroot(a2); +bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { + upb_Arena* r1 = arena_findroot(a1); + upb_Arena* r2 = arena_findroot(a2); - if (r1 == r2) return true; /* Already fused. */ + if (r1 == r2) return true; /* Already fused. */ /* Do not fuse initial blocks since we cannot lifetime extend them. */ if (upb_cleanup_has_initial_block(r1->cleanup_metadata)) return false; @@ -2932,7 +3482,7 @@ bool upb_arena_fuse(upb_arena *a1, upb_arena *a2) { /* We want to join the smaller tree to the larger tree. * So swap first if they are backwards. */ if (r1->refcount < r2->refcount) { - upb_arena *tmp = r1; + upb_Arena* tmp = r1; r1 = r2; r2 = tmp; } @@ -2948,6 +3498,40 @@ bool upb_arena_fuse(upb_arena *a1, upb_arena *a2) { return true; } +/* Miscellaneous utilities ****************************************************/ + +static void upb_FixLocale(char* p) { + /* printf() is dependent on locales; sadly there is no easy and portable way + * to avoid this. This little post-processing step will translate 1,2 -> 1.2 + * since JSON needs the latter. Arguably a hack, but it is simple and the + * alternatives are far more complicated, platform-dependent, and/or larger + * in code size. */ + for (; *p; p++) { + if (*p == ',') *p = '.'; + } +} + + +void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", DBL_DIG, val); + if (strtod(buf, NULL) != val) { + snprintf(buf, size, "%.*g", DBL_DIG + 2, val); + assert(strtod(buf, NULL) == val); + } + upb_FixLocale(buf); +} + +void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", FLT_DIG, val); + if (strtof(buf, NULL) != val) { + snprintf(buf, size, "%.*g", FLT_DIG + 3, val); + assert(strtof(buf, NULL) == val); + } + upb_FixLocale(buf); +} + /** upb/decode_fast.c ************************************************************/ // Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. // Also the table size grows by 2x. @@ -2967,44 +3551,48 @@ bool upb_arena_fuse(upb_arena *a1, upb_arena *a2) { // The standard set of arguments passed to each parsing function. // Thanks to x86-64 calling conventions, these will stay in registers. -#define UPB_PARSE_PARAMS \ - upb_decstate *d, const char *ptr, upb_msg *msg, intptr_t table, \ +#define UPB_PARSE_PARAMS \ + upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ uint64_t hasbits, uint64_t data #define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data -#define RETURN_GENERIC(m) \ - /* Uncomment either of these for debugging purposes. */ \ - /* fprintf(stderr, m); */ \ - /*__builtin_trap(); */ \ +#define RETURN_GENERIC(m) \ + /* Uncomment either of these for debugging purposes. */ \ + /* fprintf(stderr, m); */ \ + /*__builtin_trap(); */ \ return fastdecode_generic(d, ptr, msg, table, hasbits, 0); typedef enum { - CARD_s = 0, /* Singular (optional, non-repeated) */ - CARD_o = 1, /* Oneof */ - CARD_r = 2, /* Repeated */ - CARD_p = 3 /* Packed Repeated */ + CARD_s = 0, /* Singular (optional, non-repeated) */ + CARD_o = 1, /* Oneof */ + CARD_r = 2, /* Repeated */ + CARD_p = 3 /* Packed Repeated */ } upb_card; UPB_NOINLINE -static const char *fastdecode_isdonefallback(UPB_PARSE_PARAMS) { +static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { int overrun = data; - ptr = decode_isdonefallback_inl(d, ptr, overrun); + int status; + ptr = decode_isdonefallback_inl(d, ptr, overrun, &status); if (ptr == NULL) { - return fastdecode_err(d); + return fastdecode_err(d, status); } data = fastdecode_loadtag(ptr); UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); } UPB_FORCEINLINE -static const char *fastdecode_dispatch(UPB_PARSE_PARAMS) { +static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { if (UPB_UNLIKELY(ptr >= d->limit_ptr)) { int overrun = ptr - d->end; if (UPB_LIKELY(overrun == d->limit)) { // Parse is finished. *(uint32_t*)msg |= hasbits; // Sync hasbits. - return ptr; + const upb_MiniTable* l = decode_totablep(table); + return UPB_UNLIKELY(l->required_count) + ? decode_checkrequired(d, ptr, msg, l) + : ptr; } else { data = overrun; UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); @@ -3026,7 +3614,7 @@ static bool fastdecode_checktag(uint16_t data, int tagbytes) { } UPB_FORCEINLINE -static const char *fastdecode_longsize(const char *ptr, int *size) { +static const char* fastdecode_longsize(const char* ptr, int* size) { int i; UPB_ASSERT(*size & 0x80); *size &= 0xff; @@ -3046,8 +3634,8 @@ static const char *fastdecode_longsize(const char *ptr, int *size) { } UPB_FORCEINLINE -static bool fastdecode_boundscheck(const char *ptr, size_t len, - const char *end) { +static bool fastdecode_boundscheck(const char* ptr, size_t len, + const char* end) { uintptr_t uptr = (uintptr_t)ptr; uintptr_t uend = (uintptr_t)end + 16; uintptr_t res = uptr + len; @@ -3055,8 +3643,8 @@ static bool fastdecode_boundscheck(const char *ptr, size_t len, } UPB_FORCEINLINE -static bool fastdecode_boundscheck2(const char *ptr, size_t len, - const char *end) { +static bool fastdecode_boundscheck2(const char* ptr, size_t len, + const char* end) { // This is one extra branch compared to the more normal: // return (size_t)(end - ptr) < size; // However it is one less computation if we are just about to use "ptr + len": @@ -3068,12 +3656,12 @@ static bool fastdecode_boundscheck2(const char *ptr, size_t len, return res < uptr || res > uend; } -typedef const char *fastdecode_delimfunc(upb_decstate *d, const char *ptr, - void *ctx); +typedef const char* fastdecode_delimfunc(upb_Decoder* d, const char* ptr, + void* ctx); UPB_FORCEINLINE -static const char *fastdecode_delimited(upb_decstate *d, const char *ptr, - fastdecode_delimfunc *func, void *ctx) { +static const char* fastdecode_delimited(upb_Decoder* d, const char* ptr, + fastdecode_delimfunc* func, void* ctx) { ptr++; int len = (int8_t)ptr[-1]; if (fastdecode_boundscheck2(ptr, len, d->limit_ptr)) { @@ -3098,7 +3686,7 @@ static const char *fastdecode_delimited(upb_decstate *d, const char *ptr, } else { // Fast case: Sub-message is <128 bytes and fits in the current buffer. // This means we can preserve limit/limit_ptr verbatim. - const char *saved_limit_ptr = d->limit_ptr; + const char* saved_limit_ptr = d->limit_ptr; int saved_limit = d->limit; d->limit_ptr = ptr + len; d->limit = d->limit_ptr - d->end; @@ -3114,8 +3702,8 @@ static const char *fastdecode_delimited(upb_decstate *d, const char *ptr, /* singular, oneof, repeated field handling ***********************************/ typedef struct { - upb_array *arr; - void *end; + upb_Array* arr; + void* end; } fastdecode_arr; typedef enum { @@ -3125,21 +3713,21 @@ typedef enum { } fastdecode_next; typedef struct { - void *dst; + void* dst; fastdecode_next next; uint32_t tag; } fastdecode_nextret; UPB_FORCEINLINE -static void *fastdecode_resizearr(upb_decstate *d, void *dst, - fastdecode_arr *farr, int valbytes) { +static void* fastdecode_resizearr(upb_Decoder* d, void* dst, + fastdecode_arr* farr, int valbytes) { if (UPB_UNLIKELY(dst == farr->end)) { size_t old_size = farr->arr->size; size_t old_bytes = old_size * valbytes; size_t new_size = old_size * 2; size_t new_bytes = new_size * valbytes; - char *old_ptr = _upb_array_ptr(farr->arr); - char *new_ptr = upb_arena_realloc(&d->arena, old_ptr, old_bytes, new_bytes); + char* old_ptr = _upb_array_ptr(farr->arr); + char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); uint8_t elem_size_lg2 = __builtin_ctz(valbytes); farr->arr->size = new_size; farr->arr->data = _upb_array_tagptr(new_ptr, elem_size_lg2); @@ -3159,20 +3747,20 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { } UPB_FORCEINLINE -static void fastdecode_commitarr(void *dst, fastdecode_arr *farr, +static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) { farr->arr->len = - (size_t)((char *)dst - (char *)_upb_array_ptr(farr->arr)) / valbytes; + (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; } UPB_FORCEINLINE -static fastdecode_nextret fastdecode_nextrepeated(upb_decstate *d, void *dst, - const char **ptr, - fastdecode_arr *farr, +static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, + const char** ptr, + fastdecode_arr* farr, uint64_t data, int tagbytes, int valbytes) { fastdecode_nextret ret; - dst = (char *)dst + valbytes; + dst = (char*)dst + valbytes; if (UPB_LIKELY(!decode_isdone(d, ptr))) { ret.tag = fastdecode_loadtag(*ptr); @@ -3192,16 +3780,16 @@ static fastdecode_nextret fastdecode_nextrepeated(upb_decstate *d, void *dst, } UPB_FORCEINLINE -static void *fastdecode_fieldmem(upb_msg *msg, uint64_t data) { +static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { size_t ofs = data >> 48; - return (char *)msg + ofs; + return (char*)msg + ofs; } UPB_FORCEINLINE -static void *fastdecode_getfield(upb_decstate *d, const char *ptr, upb_msg *msg, - uint64_t *data, uint64_t *hasbits, - fastdecode_arr *farr, int valbytes, - upb_card card) { +static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, + upb_Message* msg, uint64_t* data, + uint64_t* hasbits, fastdecode_arr* farr, + int valbytes, upb_card card) { switch (card) { case CARD_s: { uint8_t hasbit_index = *data >> 24; @@ -3211,20 +3799,20 @@ static void *fastdecode_getfield(upb_decstate *d, const char *ptr, upb_msg *msg, } case CARD_o: { uint16_t case_ofs = *data >> 32; - uint32_t *oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); + uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); uint8_t field_number = *data >> 24; *oneof_case = field_number; return fastdecode_fieldmem(msg, *data); } case CARD_r: { - // Get pointer to upb_array and allocate/expand if necessary. + // Get pointer to upb_Array and allocate/expand if necessary. uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - upb_array **arr_p = fastdecode_fieldmem(msg, *data); - char *begin; + upb_Array** arr_p = fastdecode_fieldmem(msg, *data); + char* begin; *(uint32_t*)msg |= *hasbits; *hasbits = 0; if (UPB_LIKELY(!*arr_p)) { - farr->arr = _upb_array_new(&d->arena, 8, elem_size_lg2); + farr->arr = _upb_Array_New(&d->arena, 8, elem_size_lg2); *arr_p = farr->arr; } else { farr->arr = *arr_p; @@ -3240,17 +3828,17 @@ static void *fastdecode_getfield(upb_decstate *d, const char *ptr, upb_msg *msg, } UPB_FORCEINLINE -static bool fastdecode_flippacked(uint64_t *data, int tagbytes) { +static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. return fastdecode_checktag(*data, tagbytes); } -#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ - UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ - } \ - RETURN_GENERIC("packed check tag mismatch\n"); \ +#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ + UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ + } \ + RETURN_GENERIC("packed check tag mismatch\n"); \ } /* varint fields **************************************************************/ @@ -3272,7 +3860,7 @@ static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { } UPB_FORCEINLINE -static const char *fastdecode_varint64(const char *ptr, uint64_t *val) { +static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { ptr++; *val = (uint8_t)ptr[-1]; if (UPB_UNLIKELY(*val & 0x80)) { @@ -3298,7 +3886,7 @@ done: #define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ valbytes, card, zigzag, packed) \ uint64_t val; \ - void *dst; \ + void* dst; \ fastdecode_arr farr; \ \ FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ @@ -3318,8 +3906,7 @@ done: \ ptr += tagbytes; \ ptr = fastdecode_varint64(ptr, &val); \ - if (ptr == NULL) \ - return fastdecode_err(d); \ + if (ptr == NULL) return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ val = fastdecode_munge(val, valbytes, zigzag); \ memcpy(dst, &val, valbytes); \ \ @@ -3327,14 +3914,14 @@ done: fastdecode_nextret ret = fastdecode_nextrepeated( \ d, dst, &ptr, &farr, data, tagbytes, valbytes); \ switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ } \ } \ \ @@ -3343,15 +3930,15 @@ done: typedef struct { uint8_t valbytes; bool zigzag; - void *dst; + void* dst; fastdecode_arr farr; } fastdecode_varintdata; UPB_FORCEINLINE -static const char *fastdecode_topackedvarint(upb_decstate *d, const char *ptr, - void *ctx) { - fastdecode_varintdata *data = ctx; - void *dst = data->dst; +static const char* fastdecode_topackedvarint(upb_Decoder* d, const char* ptr, + void* ctx) { + fastdecode_varintdata* data = ctx; + void* dst = data->dst; uint64_t val; while (!decode_isdone(d, &ptr)) { @@ -3360,32 +3947,32 @@ static const char *fastdecode_topackedvarint(upb_decstate *d, const char *ptr, if (ptr == NULL) return NULL; val = fastdecode_munge(val, data->valbytes, data->zigzag); memcpy(dst, &val, data->valbytes); - dst = (char *)dst + data->valbytes; + dst = (char*)dst + data->valbytes; } fastdecode_commitarr(dst, &data->farr, data->valbytes); return ptr; } -#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked) \ - fastdecode_varintdata ctx = {valbytes, zigzag}; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ - \ - ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ - valbytes, CARD_r); \ - if (UPB_UNLIKELY(!ctx.dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ - \ - if (UPB_UNLIKELY(ptr == NULL)) { \ - return fastdecode_err(d); \ - } \ - \ +#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked) \ + fastdecode_varintdata ctx = {valbytes, zigzag}; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ + \ + ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ + valbytes, CARD_r); \ + if (UPB_UNLIKELY(!ctx.dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ + \ + if (UPB_UNLIKELY(ptr == NULL)) { \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); #define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ @@ -3407,7 +3994,7 @@ static const char *fastdecode_topackedvarint(upb_decstate *d, const char *ptr, #define F(card, type, valbytes, tagbytes) \ UPB_NOINLINE \ - const char *upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ CARD_##card, type##_ZZ, \ upb_pr##type##valbytes##_##tagbytes##bt, \ @@ -3443,48 +4030,47 @@ TAGBYTES(p) #undef FASTDECODE_PACKEDVARINT #undef FASTDECODE_VARINT - /* fixed fields ***************************************************************/ -#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed) \ - void *dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("couldn't allocate array in arena\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - memcpy(dst, ptr, valbytes); \ - ptr += valbytes; \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ +#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed) \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("couldn't allocate array in arena\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + memcpy(dst, ptr, valbytes); \ + ptr += valbytes; \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); #define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ @@ -3500,24 +4086,24 @@ TAGBYTES(p) \ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr) || \ (size % valbytes) != 0)) { \ - return fastdecode_err(d); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ - upb_array **arr_p = fastdecode_fieldmem(msg, data); \ - upb_array *arr = *arr_p; \ + upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ + upb_Array* arr = *arr_p; \ uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ int elems = size / valbytes; \ \ if (UPB_LIKELY(!arr)) { \ - *arr_p = arr = _upb_array_new(&d->arena, elems, elem_size_lg2); \ + *arr_p = arr = _upb_Array_New(&d->arena, elems, elem_size_lg2); \ if (!arr) { \ - return fastdecode_err(d); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ } else { \ - _upb_array_resize(arr, elems, &d->arena); \ + _upb_Array_Resize(arr, elems, &d->arena); \ } \ \ - char *dst = _upb_array_ptr(arr); \ + char* dst = _upb_array_ptr(arr); \ memcpy(dst, ptr, size); \ arr->len = elems; \ \ @@ -3539,7 +4125,7 @@ TAGBYTES(p) #define F(card, valbytes, tagbytes) \ UPB_NOINLINE \ - const char *upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ upb_prf##valbytes##_##tagbytes##bt); \ @@ -3566,18 +4152,19 @@ TAGBYTES(p) /* string fields **************************************************************/ -typedef const char *fastdecode_copystr_func(struct upb_decstate *d, - const char *ptr, upb_msg *msg, - const upb_msglayout *table, - uint64_t hasbits, upb_strview *dst); +typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + const upb_MiniTable* table, + uint64_t hasbits, + upb_StringView* dst); UPB_NOINLINE -static const char *fastdecode_verifyutf8(upb_decstate *d, const char *ptr, - upb_msg *msg, intptr_t table, +static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data) { - upb_strview *dst = (upb_strview*)data; + upb_StringView* dst = (upb_StringView*)data; if (!decode_verifyutf8_inl(dst->data, dst->size)) { - return fastdecode_err(d); + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); } UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); } @@ -3591,16 +4178,16 @@ static const char *fastdecode_verifyutf8(upb_decstate *d, const char *ptr, \ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr))) { \ dst->size = 0; \ - return fastdecode_err(d); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ - if (d->alias) { \ + if (d->options & kUpb_DecodeOption_AliasString) { \ dst->data = ptr; \ dst->size = size; \ } else { \ - char *data = upb_arena_malloc(&d->arena, size); \ + char* data = upb_Arena_Malloc(&d->arena, size); \ if (!data) { \ - return fastdecode_err(d); \ + return fastdecode_err(d, kUpb_DecodeStatus_OutOfMemory); \ } \ memcpy(data, ptr, size); \ dst->data = data; \ @@ -3616,27 +4203,25 @@ static const char *fastdecode_verifyutf8(upb_decstate *d, const char *ptr, } UPB_NOINLINE -static const char *fastdecode_longstring_utf8(struct upb_decstate *d, - const char *ptr, upb_msg *msg, +static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data) { - upb_strview *dst = (upb_strview*)data; + upb_StringView* dst = (upb_StringView*)data; FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); } UPB_NOINLINE -static const char *fastdecode_longstring_noutf8(struct upb_decstate *d, - const char *ptr, upb_msg *msg, - intptr_t table, - uint64_t hasbits, - uint64_t data) { - upb_strview *dst = (upb_strview*)data; +static const char* fastdecode_longstring_noutf8( + struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); } UPB_FORCEINLINE -static void fastdecode_docopy(upb_decstate *d, const char *ptr, uint32_t size, - int copy, char *data, upb_strview *dst) { +static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, + int copy, char* data, upb_StringView* dst) { d->arena.head.ptr += copy; dst->data = data; UPB_UNPOISON_MEMORY_REGION(data, copy); @@ -3644,96 +4229,95 @@ static void fastdecode_docopy(upb_decstate *d, const char *ptr, uint32_t size, UPB_POISON_MEMORY_REGION(data + size, copy - size); } -#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - card, validate_utf8) \ - upb_strview *dst; \ - fastdecode_arr farr; \ - int64_t size; \ - size_t arena_has; \ - size_t common_has; \ - char *buf; \ - \ - UPB_ASSERT(!d->alias); \ - UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_strview), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_strview)); \ - } \ - \ - size = (uint8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - dst->size = size; \ - \ - buf = d->arena.head.ptr; \ - arena_has = _upb_arenahas(&d->arena); \ - common_has = UPB_MIN(arena_has, (d->end - ptr) + 16); \ - \ - if (UPB_LIKELY(size <= 15 - tagbytes)) { \ - if (arena_has < 16) \ - goto longstr; \ - d->arena.head.ptr += 16; \ - memcpy(buf, ptr - tagbytes - 1, 16); \ - dst->data = buf + tagbytes + 1; \ - } else if (UPB_LIKELY(size <= 32)) { \ - if (UPB_UNLIKELY(common_has < 32)) \ - goto longstr; \ - fastdecode_docopy(d, ptr, size, 32, buf, dst); \ - } else if (UPB_LIKELY(size <= 64)) { \ - if (UPB_UNLIKELY(common_has < 64)) \ - goto longstr; \ - fastdecode_docopy(d, ptr, size, 64, buf, dst); \ - } else if (UPB_LIKELY(size < 128)) { \ - if (UPB_UNLIKELY(common_has < 128)) \ - goto longstr; \ - fastdecode_docopy(d, ptr, size, 128, buf, dst); \ - } else { \ - goto longstr; \ - } \ - \ - ptr += size; \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \ - return fastdecode_err(d); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_strview)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ - \ - longstr: \ - ptr--; \ - if (validate_utf8) { \ - UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ - } else { \ - UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ +#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + card, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + size_t arena_has; \ + size_t common_has; \ + char* buf; \ + \ + UPB_ASSERT((d->options & kUpb_DecodeOption_AliasString) == 0); \ + UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (uint8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + dst->size = size; \ + \ + buf = d->arena.head.ptr; \ + arena_has = _upb_ArenaHas(&d->arena); \ + common_has = UPB_MIN(arena_has, (d->end - ptr) + 16); \ + \ + if (UPB_LIKELY(size <= 15 - tagbytes)) { \ + if (arena_has < 16) goto longstr; \ + d->arena.head.ptr += 16; \ + memcpy(buf, ptr - tagbytes - 1, 16); \ + dst->data = buf + tagbytes + 1; \ + } else if (UPB_LIKELY(size <= 32)) { \ + if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 32, buf, dst); \ + } else if (UPB_LIKELY(size <= 64)) { \ + if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 64, buf, dst); \ + } else if (UPB_LIKELY(size < 128)) { \ + if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 128, buf, dst); \ + } else { \ + goto longstr; \ + } \ + \ + ptr += size; \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \ + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + \ + longstr: \ + if (card == CARD_r) { \ + fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ + } \ + ptr--; \ + if (validate_utf8) { \ + UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } else { \ + UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ } #define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ copyfunc, validate_utf8) \ - upb_strview *dst; \ + upb_StringView* dst; \ fastdecode_arr farr; \ int64_t size; \ \ @@ -3741,16 +4325,16 @@ static void fastdecode_docopy(upb_decstate *d, const char *ptr, uint32_t size, RETURN_GENERIC("string field tag mismatch\n"); \ } \ \ - if (UPB_UNLIKELY(!d->alias)) { \ + if (UPB_UNLIKELY((d->options & kUpb_DecodeOption_AliasString) == 0)) { \ UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ } \ \ dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_strview), card); \ + sizeof(upb_StringView), card); \ \ again: \ if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_strview)); \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ } \ \ size = (int8_t)ptr[tagbytes]; \ @@ -3773,27 +4357,27 @@ static void fastdecode_docopy(upb_decstate *d, const char *ptr, uint32_t size, \ if (card == CARD_r) { \ if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \ - return fastdecode_err(d); \ + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); \ } \ fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_strview)); \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - if (UPB_UNLIKELY(!d->alias)) { \ - /* Buffer flipped and we can't alias any more. Bounce to */ \ - /* copyfunc(), but via dispatch since we need to reload table */ \ - /* data also. */ \ - fastdecode_commitarr(dst, &farr, sizeof(upb_strview)); \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + if (UPB_UNLIKELY((d->options & kUpb_DecodeOption_AliasString) == 0)) { \ + /* Buffer flipped and we can't alias any more. Bounce to */ \ + /* copyfunc(), but via dispatch since we need to reload table */ \ + /* data also. */ \ + fastdecode_commitarr(dst, &farr, sizeof(upb_StringView)); \ + data = ret.tag; \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ + } \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ - } \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ } \ } \ \ @@ -3812,11 +4396,11 @@ static void fastdecode_docopy(upb_decstate *d, const char *ptr, uint32_t size, #define F(card, tagbytes, type) \ UPB_NOINLINE \ - const char *upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ CARD_##card, type##_VALIDATE); \ } \ - const char *upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ CARD_##card, upb_c##card##type##_##tagbytes##bt, \ type##_VALIDATE); \ @@ -3845,12 +4429,12 @@ TAGBYTES(r) /* message fields *************************************************************/ UPB_INLINE -upb_msg *decode_newmsg_ceil(upb_decstate *d, const upb_msglayout *l, - int msg_ceil_bytes) { - size_t size = l->size + sizeof(upb_msg_internal); - char *msg_data; +upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* l, + int msg_ceil_bytes) { + size_t size = l->size + sizeof(upb_Message_Internal); + char* msg_data; if (UPB_LIKELY(msg_ceil_bytes > 0 && - _upb_arenahas(&d->arena) >= msg_ceil_bytes)) { + _upb_ArenaHas(&d->arena) >= msg_ceil_bytes)) { UPB_ASSERT(size <= (size_t)msg_ceil_bytes); msg_data = d->arena.head.ptr; d->arena.head.ptr += size; @@ -3858,21 +4442,21 @@ upb_msg *decode_newmsg_ceil(upb_decstate *d, const upb_msglayout *l, memset(msg_data, 0, msg_ceil_bytes); UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); } else { - msg_data = (char*)upb_arena_malloc(&d->arena, size); + msg_data = (char*)upb_Arena_Malloc(&d->arena, size); memset(msg_data, 0, size); } - return msg_data + sizeof(upb_msg_internal); + return msg_data + sizeof(upb_Message_Internal); } typedef struct { intptr_t table; - upb_msg *msg; + upb_Message* msg; } fastdecode_submsgdata; UPB_FORCEINLINE -static const char *fastdecode_tosubmsg(upb_decstate *d, const char *ptr, - void *ctx) { - fastdecode_submsgdata *submsg = ctx; +static const char* fastdecode_tosubmsg(upb_Decoder* d, const char* ptr, + void* ctx) { + fastdecode_submsgdata* submsg = ctx; ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); UPB_ASSUME(ptr != NULL); return ptr; @@ -3885,12 +4469,14 @@ static const char *fastdecode_tosubmsg(upb_decstate *d, const char *ptr, RETURN_GENERIC("submessage field tag mismatch\n"); \ } \ \ - if (--d->depth == 0) return fastdecode_err(d); \ + if (--d->depth == 0) { \ + return fastdecode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + } \ \ - upb_msg **dst; \ + upb_Message** dst; \ uint32_t submsg_idx = (data >> 16) & 0xff; \ - const upb_msglayout *tablep = decode_totablep(table); \ - const upb_msglayout *subtablep = tablep->submsgs[submsg_idx]; \ + const upb_MiniTable* tablep = decode_totablep(table); \ + const upb_MiniTable* subtablep = tablep->subs[submsg_idx].submsg; \ fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ fastdecode_arr farr; \ \ @@ -3899,16 +4485,16 @@ static const char *fastdecode_tosubmsg(upb_decstate *d, const char *ptr, } \ \ dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_msg *), card); \ + sizeof(upb_Message*), card); \ \ if (card == CARD_s) { \ - *(uint32_t *)msg |= hasbits; \ + *(uint32_t*)msg |= hasbits; \ hasbits = 0; \ } \ \ again: \ if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_msg *)); \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ } \ \ submsg.msg = *dst; \ @@ -3921,12 +4507,12 @@ static const char *fastdecode_tosubmsg(upb_decstate *d, const char *ptr, ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ \ if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - return fastdecode_err(d); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ if (card == CARD_r) { \ fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_msg *)); \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ switch (ret.next) { \ case FD_NEXT_SAMEFIELD: \ dst = ret.dst; \ @@ -3945,21 +4531,21 @@ static const char *fastdecode_tosubmsg(upb_decstate *d, const char *ptr, UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); #define F(card, tagbytes, size_ceil, ceil_arg) \ - const char *upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ + const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ UPB_PARSE_PARAMS) { \ FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ CARD_##card); \ } #define SIZES(card, tagbytes) \ - F(card, tagbytes, 64, 64) \ + F(card, tagbytes, 64, 64) \ F(card, tagbytes, 128, 128) \ F(card, tagbytes, 192, 192) \ F(card, tagbytes, 256, 256) \ F(card, tagbytes, max, -1) #define TAGBYTES(card) \ - SIZES(card, 1) \ + SIZES(card, 1) \ SIZES(card, 2) TAGBYTES(s) @@ -3971,7 +4557,7 @@ TAGBYTES(r) #undef F #undef FASTDECODE_SUBMSG -#endif /* UPB_FASTTABLE */ +#endif /* UPB_FASTTABLE */ /** bazel-out/k8-fastbuild/bin/external/com_google_protobuf/google/protobuf/descriptor.upb.c ************************************************************//* This file was generated by upbc (the upb compiler) from the input * file: @@ -3984,474 +4570,564 @@ TAGBYTES(r) #include -static const upb_msglayout *const google_protobuf_FileDescriptorSet_submsgs[1] = { - &google_protobuf_FileDescriptorProto_msginit, +static const upb_MiniTable_Sub google_protobuf_FileDescriptorSet_submsgs[1] = { + {.submsg = &google_protobuf_FileDescriptorProto_msginit}, }; -static const upb_msglayout_field google_protobuf_FileDescriptorSet__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_FileDescriptorSet__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_FileDescriptorSet_msginit = { +const upb_MiniTable google_protobuf_FileDescriptorSet_msginit = { &google_protobuf_FileDescriptorSet_submsgs[0], &google_protobuf_FileDescriptorSet__fields[0], - UPB_SIZE(8, 8), 1, false, 1, 255, + UPB_SIZE(8, 8), 1, upb_ExtMode_NonExtendable, 1, 255, 0, }; -static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = { - &google_protobuf_DescriptorProto_msginit, - &google_protobuf_EnumDescriptorProto_msginit, - &google_protobuf_FieldDescriptorProto_msginit, - &google_protobuf_FileOptions_msginit, - &google_protobuf_ServiceDescriptorProto_msginit, - &google_protobuf_SourceCodeInfo_msginit, +static const upb_MiniTable_Sub google_protobuf_FileDescriptorProto_submsgs[6] = { + {.submsg = &google_protobuf_DescriptorProto_msginit}, + {.submsg = &google_protobuf_EnumDescriptorProto_msginit}, + {.submsg = &google_protobuf_FieldDescriptorProto_msginit}, + {.submsg = &google_protobuf_FileOptions_msginit}, + {.submsg = &google_protobuf_ServiceDescriptorProto_msginit}, + {.submsg = &google_protobuf_SourceCodeInfo_msginit}, }; -static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(36, 72), 0, 0, 12, _UPB_MODE_ARRAY}, - {4, UPB_SIZE(40, 80), 0, 0, 11, _UPB_MODE_ARRAY}, - {5, UPB_SIZE(44, 88), 0, 1, 11, _UPB_MODE_ARRAY}, - {6, UPB_SIZE(48, 96), 0, 4, 11, _UPB_MODE_ARRAY}, - {7, UPB_SIZE(52, 104), 0, 2, 11, _UPB_MODE_ARRAY}, - {8, UPB_SIZE(28, 56), 3, 3, 11, _UPB_MODE_SCALAR}, - {9, UPB_SIZE(32, 64), 4, 5, 11, _UPB_MODE_SCALAR}, - {10, UPB_SIZE(56, 112), 0, 0, 5, _UPB_MODE_ARRAY}, - {11, UPB_SIZE(60, 120), 0, 0, 5, _UPB_MODE_ARRAY}, - {12, UPB_SIZE(20, 40), 5, 0, 12, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[12] = { + {1, UPB_SIZE(4, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), 2, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {3, UPB_SIZE(36, 72), 0, 0, 12, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {4, UPB_SIZE(40, 80), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {5, UPB_SIZE(44, 88), 0, 1, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {6, UPB_SIZE(48, 96), 0, 4, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {7, UPB_SIZE(52, 104), 0, 2, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {8, UPB_SIZE(28, 56), 3, 3, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {9, UPB_SIZE(32, 64), 4, 5, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {10, UPB_SIZE(56, 112), 0, 0, 5, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {11, UPB_SIZE(60, 120), 0, 0, 5, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {12, UPB_SIZE(20, 40), 5, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_FileDescriptorProto_msginit = { +const upb_MiniTable google_protobuf_FileDescriptorProto_msginit = { &google_protobuf_FileDescriptorProto_submsgs[0], &google_protobuf_FileDescriptorProto__fields[0], - UPB_SIZE(64, 128), 12, false, 12, 255, + UPB_SIZE(64, 128), 12, upb_ExtMode_NonExtendable, 12, 255, 0, }; -static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[7] = { - &google_protobuf_DescriptorProto_msginit, - &google_protobuf_DescriptorProto_ExtensionRange_msginit, - &google_protobuf_DescriptorProto_ReservedRange_msginit, - &google_protobuf_EnumDescriptorProto_msginit, - &google_protobuf_FieldDescriptorProto_msginit, - &google_protobuf_MessageOptions_msginit, - &google_protobuf_OneofDescriptorProto_msginit, +static const upb_MiniTable_Sub google_protobuf_DescriptorProto_submsgs[7] = { + {.submsg = &google_protobuf_DescriptorProto_msginit}, + {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msginit}, + {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msginit}, + {.submsg = &google_protobuf_EnumDescriptorProto_msginit}, + {.submsg = &google_protobuf_FieldDescriptorProto_msginit}, + {.submsg = &google_protobuf_MessageOptions_msginit}, + {.submsg = &google_protobuf_OneofDescriptorProto_msginit}, }; -static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(16, 32), 0, 4, 11, _UPB_MODE_ARRAY}, - {3, UPB_SIZE(20, 40), 0, 0, 11, _UPB_MODE_ARRAY}, - {4, UPB_SIZE(24, 48), 0, 3, 11, _UPB_MODE_ARRAY}, - {5, UPB_SIZE(28, 56), 0, 1, 11, _UPB_MODE_ARRAY}, - {6, UPB_SIZE(32, 64), 0, 4, 11, _UPB_MODE_ARRAY}, - {7, UPB_SIZE(12, 24), 2, 5, 11, _UPB_MODE_SCALAR}, - {8, UPB_SIZE(36, 72), 0, 6, 11, _UPB_MODE_ARRAY}, - {9, UPB_SIZE(40, 80), 0, 2, 11, _UPB_MODE_ARRAY}, - {10, UPB_SIZE(44, 88), 0, 0, 12, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_DescriptorProto__fields[10] = { + {1, UPB_SIZE(4, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 32), 0, 4, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {3, UPB_SIZE(20, 40), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {4, UPB_SIZE(24, 48), 0, 3, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {5, UPB_SIZE(28, 56), 0, 1, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {6, UPB_SIZE(32, 64), 0, 4, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {7, UPB_SIZE(12, 24), 2, 5, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {8, UPB_SIZE(36, 72), 0, 6, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {9, UPB_SIZE(40, 80), 0, 2, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {10, UPB_SIZE(44, 88), 0, 0, 12, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_DescriptorProto_msginit = { +const upb_MiniTable google_protobuf_DescriptorProto_msginit = { &google_protobuf_DescriptorProto_submsgs[0], &google_protobuf_DescriptorProto__fields[0], - UPB_SIZE(48, 96), 10, false, 10, 255, + UPB_SIZE(48, 96), 10, upb_ExtMode_NonExtendable, 10, 255, 0, }; -static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { - &google_protobuf_ExtensionRangeOptions_msginit, +static const upb_MiniTable_Sub google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { + {.submsg = &google_protobuf_ExtensionRangeOptions_msginit}, }; -static const upb_msglayout_field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(12, 16), 3, 0, 11, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {2, UPB_SIZE(8, 8), 2, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {3, UPB_SIZE(12, 16), 3, 0, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = { +const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msginit = { &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0], &google_protobuf_DescriptorProto_ExtensionRange__fields[0], - UPB_SIZE(16, 24), 3, false, 3, 255, + UPB_SIZE(16, 24), 3, upb_ExtMode_NonExtendable, 3, 255, 0, }; -static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_DescriptorProto_ReservedRange__fields[2] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {2, UPB_SIZE(8, 8), 2, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = { +const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msginit = { NULL, &google_protobuf_DescriptorProto_ReservedRange__fields[0], - UPB_SIZE(16, 16), 2, false, 2, 255, + UPB_SIZE(16, 16), 2, upb_ExtMode_NonExtendable, 2, 255, 0, }; -static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_ExtensionRangeOptions_submsgs[1] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; -static const upb_msglayout_field google_protobuf_ExtensionRangeOptions__fields[1] = { - {999, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_ExtensionRangeOptions__fields[1] = { + {999, UPB_SIZE(0, 0), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = { +const upb_MiniTable google_protobuf_ExtensionRangeOptions_msginit = { &google_protobuf_ExtensionRangeOptions_submsgs[0], &google_protobuf_ExtensionRangeOptions__fields[0], - UPB_SIZE(8, 8), 1, false, 0, 255, + UPB_SIZE(8, 8), 1, upb_ExtMode_Extendable, 0, 255, 0, }; -static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1] = { - &google_protobuf_FieldOptions_msginit, +static const upb_MiniTable_Sub google_protobuf_FieldDescriptorProto_submsgs[3] = { + {.submsg = &google_protobuf_FieldOptions_msginit}, + {.subenum = &google_protobuf_FieldDescriptorProto_Label_enuminit}, + {.subenum = &google_protobuf_FieldDescriptorProto_Type_enuminit}, }; -static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = { - {1, UPB_SIZE(24, 24), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(32, 40), 2, 0, 12, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(12, 12), 3, 0, 5, _UPB_MODE_SCALAR}, - {4, UPB_SIZE(4, 4), 4, 0, 14, _UPB_MODE_SCALAR}, - {5, UPB_SIZE(8, 8), 5, 0, 14, _UPB_MODE_SCALAR}, - {6, UPB_SIZE(40, 56), 6, 0, 12, _UPB_MODE_SCALAR}, - {7, UPB_SIZE(48, 72), 7, 0, 12, _UPB_MODE_SCALAR}, - {8, UPB_SIZE(64, 104), 8, 0, 11, _UPB_MODE_SCALAR}, - {9, UPB_SIZE(16, 16), 9, 0, 5, _UPB_MODE_SCALAR}, - {10, UPB_SIZE(56, 88), 10, 0, 12, _UPB_MODE_SCALAR}, - {17, UPB_SIZE(20, 20), 11, 0, 8, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_FieldDescriptorProto__fields[11] = { + {1, UPB_SIZE(24, 24), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(32, 40), 2, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {3, UPB_SIZE(12, 12), 3, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {4, UPB_SIZE(4, 4), 4, 1, 14, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {5, UPB_SIZE(8, 8), 5, 2, 14, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {6, UPB_SIZE(40, 56), 6, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {7, UPB_SIZE(48, 72), 7, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {8, UPB_SIZE(64, 104), 8, 0, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {9, UPB_SIZE(16, 16), 9, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {10, UPB_SIZE(56, 88), 10, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {17, UPB_SIZE(20, 20), 11, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = { +const upb_MiniTable google_protobuf_FieldDescriptorProto_msginit = { &google_protobuf_FieldDescriptorProto_submsgs[0], &google_protobuf_FieldDescriptorProto__fields[0], - UPB_SIZE(72, 112), 11, false, 10, 255, + UPB_SIZE(72, 112), 11, upb_ExtMode_NonExtendable, 10, 255, 0, }; -static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = { - &google_protobuf_OneofOptions_msginit, +static const upb_MiniTable_Sub google_protobuf_OneofDescriptorProto_submsgs[1] = { + {.submsg = &google_protobuf_OneofOptions_msginit}, }; -static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(12, 24), 2, 0, 11, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_OneofDescriptorProto__fields[2] = { + {1, UPB_SIZE(4, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), 2, 0, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = { +const upb_MiniTable google_protobuf_OneofDescriptorProto_msginit = { &google_protobuf_OneofDescriptorProto_submsgs[0], &google_protobuf_OneofDescriptorProto__fields[0], - UPB_SIZE(16, 32), 2, false, 2, 255, + UPB_SIZE(16, 32), 2, upb_ExtMode_NonExtendable, 2, 255, 0, }; -static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = { - &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, - &google_protobuf_EnumOptions_msginit, - &google_protobuf_EnumValueDescriptorProto_msginit, +static const upb_MiniTable_Sub google_protobuf_EnumDescriptorProto_submsgs[3] = { + {.submsg = &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit}, + {.submsg = &google_protobuf_EnumOptions_msginit}, + {.submsg = &google_protobuf_EnumValueDescriptorProto_msginit}, }; -static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(16, 32), 0, 2, 11, _UPB_MODE_ARRAY}, - {3, UPB_SIZE(12, 24), 2, 1, 11, _UPB_MODE_SCALAR}, - {4, UPB_SIZE(20, 40), 0, 0, 11, _UPB_MODE_ARRAY}, - {5, UPB_SIZE(24, 48), 0, 0, 12, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_EnumDescriptorProto__fields[5] = { + {1, UPB_SIZE(4, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 32), 0, 2, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {3, UPB_SIZE(12, 24), 2, 1, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {4, UPB_SIZE(20, 40), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {5, UPB_SIZE(24, 48), 0, 0, 12, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = { +const upb_MiniTable google_protobuf_EnumDescriptorProto_msginit = { &google_protobuf_EnumDescriptorProto_submsgs[0], &google_protobuf_EnumDescriptorProto__fields[0], - UPB_SIZE(32, 64), 5, false, 5, 255, + UPB_SIZE(32, 64), 5, upb_ExtMode_NonExtendable, 5, 255, 0, }; -static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = { - {1, UPB_SIZE(4, 4), 1, 0, 5, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(8, 8), 2, 0, 5, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = { + {1, UPB_SIZE(4, 4), 1, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {2, UPB_SIZE(8, 8), 2, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { +const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { NULL, &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0], - UPB_SIZE(16, 16), 2, false, 2, 255, + UPB_SIZE(16, 16), 2, upb_ExtMode_NonExtendable, 2, 255, 0, }; -static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = { - &google_protobuf_EnumValueOptions_msginit, +static const upb_MiniTable_Sub google_protobuf_EnumValueDescriptorProto_submsgs[1] = { + {.submsg = &google_protobuf_EnumValueOptions_msginit}, }; -static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = { - {1, UPB_SIZE(8, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(4, 4), 2, 0, 5, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(16, 24), 3, 0, 11, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_EnumValueDescriptorProto__fields[3] = { + {1, UPB_SIZE(8, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(4, 4), 2, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {3, UPB_SIZE(16, 24), 3, 0, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = { +const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msginit = { &google_protobuf_EnumValueDescriptorProto_submsgs[0], &google_protobuf_EnumValueDescriptorProto__fields[0], - UPB_SIZE(24, 32), 3, false, 3, 255, + UPB_SIZE(24, 32), 3, upb_ExtMode_NonExtendable, 3, 255, 0, }; -static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = { - &google_protobuf_MethodDescriptorProto_msginit, - &google_protobuf_ServiceOptions_msginit, +static const upb_MiniTable_Sub google_protobuf_ServiceDescriptorProto_submsgs[2] = { + {.submsg = &google_protobuf_MethodDescriptorProto_msginit}, + {.submsg = &google_protobuf_ServiceOptions_msginit}, }; -static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(16, 32), 0, 0, 11, _UPB_MODE_ARRAY}, - {3, UPB_SIZE(12, 24), 2, 1, 11, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_ServiceDescriptorProto__fields[3] = { + {1, UPB_SIZE(4, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 32), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {3, UPB_SIZE(12, 24), 2, 1, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = { +const upb_MiniTable google_protobuf_ServiceDescriptorProto_msginit = { &google_protobuf_ServiceDescriptorProto_submsgs[0], &google_protobuf_ServiceDescriptorProto__fields[0], - UPB_SIZE(24, 48), 3, false, 3, 255, + UPB_SIZE(24, 48), 3, upb_ExtMode_NonExtendable, 3, 255, 0, }; -static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = { - &google_protobuf_MethodOptions_msginit, +static const upb_MiniTable_Sub google_protobuf_MethodDescriptorProto_submsgs[1] = { + {.submsg = &google_protobuf_MethodOptions_msginit}, }; -static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(20, 40), 3, 0, 12, _UPB_MODE_SCALAR}, - {4, UPB_SIZE(28, 56), 4, 0, 11, _UPB_MODE_SCALAR}, - {5, UPB_SIZE(1, 1), 5, 0, 8, _UPB_MODE_SCALAR}, - {6, UPB_SIZE(2, 2), 6, 0, 8, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_MethodDescriptorProto__fields[6] = { + {1, UPB_SIZE(4, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), 2, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {3, UPB_SIZE(20, 40), 3, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {4, UPB_SIZE(28, 56), 4, 0, 11, kUpb_FieldMode_Scalar | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {5, UPB_SIZE(1, 1), 5, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {6, UPB_SIZE(2, 2), 6, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = { +const upb_MiniTable google_protobuf_MethodDescriptorProto_msginit = { &google_protobuf_MethodDescriptorProto_submsgs[0], &google_protobuf_MethodDescriptorProto__fields[0], - UPB_SIZE(32, 64), 6, false, 6, 255, + UPB_SIZE(32, 64), 6, upb_ExtMode_NonExtendable, 6, 255, 0, }; -static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_FileOptions_submsgs[2] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, + {.subenum = &google_protobuf_FileOptions_OptimizeMode_enuminit}, }; -static const upb_msglayout_field google_protobuf_FileOptions__fields[21] = { - {1, UPB_SIZE(20, 24), 1, 0, 12, _UPB_MODE_SCALAR}, - {8, UPB_SIZE(28, 40), 2, 0, 12, _UPB_MODE_SCALAR}, - {9, UPB_SIZE(4, 4), 3, 0, 14, _UPB_MODE_SCALAR}, - {10, UPB_SIZE(8, 8), 4, 0, 8, _UPB_MODE_SCALAR}, - {11, UPB_SIZE(36, 56), 5, 0, 12, _UPB_MODE_SCALAR}, - {16, UPB_SIZE(9, 9), 6, 0, 8, _UPB_MODE_SCALAR}, - {17, UPB_SIZE(10, 10), 7, 0, 8, _UPB_MODE_SCALAR}, - {18, UPB_SIZE(11, 11), 8, 0, 8, _UPB_MODE_SCALAR}, - {20, UPB_SIZE(12, 12), 9, 0, 8, _UPB_MODE_SCALAR}, - {23, UPB_SIZE(13, 13), 10, 0, 8, _UPB_MODE_SCALAR}, - {27, UPB_SIZE(14, 14), 11, 0, 8, _UPB_MODE_SCALAR}, - {31, UPB_SIZE(15, 15), 12, 0, 8, _UPB_MODE_SCALAR}, - {36, UPB_SIZE(44, 72), 13, 0, 12, _UPB_MODE_SCALAR}, - {37, UPB_SIZE(52, 88), 14, 0, 12, _UPB_MODE_SCALAR}, - {39, UPB_SIZE(60, 104), 15, 0, 12, _UPB_MODE_SCALAR}, - {40, UPB_SIZE(68, 120), 16, 0, 12, _UPB_MODE_SCALAR}, - {41, UPB_SIZE(76, 136), 17, 0, 12, _UPB_MODE_SCALAR}, - {42, UPB_SIZE(16, 16), 18, 0, 8, _UPB_MODE_SCALAR}, - {44, UPB_SIZE(84, 152), 19, 0, 12, _UPB_MODE_SCALAR}, - {45, UPB_SIZE(92, 168), 20, 0, 12, _UPB_MODE_SCALAR}, - {999, UPB_SIZE(100, 184), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_FileOptions__fields[21] = { + {1, UPB_SIZE(20, 24), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {8, UPB_SIZE(28, 40), 2, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {9, UPB_SIZE(4, 4), 3, 1, 14, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {10, UPB_SIZE(8, 8), 4, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {11, UPB_SIZE(36, 56), 5, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {16, UPB_SIZE(9, 9), 6, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {17, UPB_SIZE(10, 10), 7, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {18, UPB_SIZE(11, 11), 8, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {20, UPB_SIZE(12, 12), 9, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {23, UPB_SIZE(13, 13), 10, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {27, UPB_SIZE(14, 14), 11, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {31, UPB_SIZE(15, 15), 12, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {36, UPB_SIZE(44, 72), 13, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {37, UPB_SIZE(52, 88), 14, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {39, UPB_SIZE(60, 104), 15, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {40, UPB_SIZE(68, 120), 16, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {41, UPB_SIZE(76, 136), 17, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {42, UPB_SIZE(16, 16), 18, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {44, UPB_SIZE(84, 152), 19, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {45, UPB_SIZE(92, 168), 20, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {999, UPB_SIZE(100, 184), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_FileOptions_msginit = { +const upb_MiniTable google_protobuf_FileOptions_msginit = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], - UPB_SIZE(104, 192), 21, false, 1, 255, + UPB_SIZE(104, 192), 21, upb_ExtMode_Extendable, 1, 255, 0, }; -static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_MessageOptions_submsgs[1] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; -static const upb_msglayout_field google_protobuf_MessageOptions__fields[5] = { - {1, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(2, 2), 2, 0, 8, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(3, 3), 3, 0, 8, _UPB_MODE_SCALAR}, - {7, UPB_SIZE(4, 4), 4, 0, 8, _UPB_MODE_SCALAR}, - {999, UPB_SIZE(8, 8), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_MessageOptions__fields[5] = { + {1, UPB_SIZE(1, 1), 1, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {2, UPB_SIZE(2, 2), 2, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {3, UPB_SIZE(3, 3), 3, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {7, UPB_SIZE(4, 4), 4, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {999, UPB_SIZE(8, 8), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_MessageOptions_msginit = { +const upb_MiniTable google_protobuf_MessageOptions_msginit = { &google_protobuf_MessageOptions_submsgs[0], &google_protobuf_MessageOptions__fields[0], - UPB_SIZE(16, 16), 5, false, 3, 255, + UPB_SIZE(16, 16), 5, upb_ExtMode_Extendable, 3, 255, 0, }; -static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_FieldOptions_submsgs[3] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, + {.subenum = &google_protobuf_FieldOptions_CType_enuminit}, + {.subenum = &google_protobuf_FieldOptions_JSType_enuminit}, }; -static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = { - {1, UPB_SIZE(4, 4), 1, 0, 14, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(12, 12), 2, 0, 8, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(13, 13), 3, 0, 8, _UPB_MODE_SCALAR}, - {5, UPB_SIZE(14, 14), 4, 0, 8, _UPB_MODE_SCALAR}, - {6, UPB_SIZE(8, 8), 5, 0, 14, _UPB_MODE_SCALAR}, - {10, UPB_SIZE(15, 15), 6, 0, 8, _UPB_MODE_SCALAR}, - {999, UPB_SIZE(16, 16), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_FieldOptions__fields[7] = { + {1, UPB_SIZE(4, 4), 1, 1, 14, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 12), 2, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {3, UPB_SIZE(13, 13), 3, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {5, UPB_SIZE(14, 14), 4, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {6, UPB_SIZE(8, 8), 5, 2, 14, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {10, UPB_SIZE(15, 15), 6, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {999, UPB_SIZE(16, 16), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_FieldOptions_msginit = { +const upb_MiniTable google_protobuf_FieldOptions_msginit = { &google_protobuf_FieldOptions_submsgs[0], &google_protobuf_FieldOptions__fields[0], - UPB_SIZE(24, 24), 7, false, 3, 255, + UPB_SIZE(24, 24), 7, upb_ExtMode_Extendable, 3, 255, 0, }; -static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_OneofOptions_submsgs[1] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; -static const upb_msglayout_field google_protobuf_OneofOptions__fields[1] = { - {999, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_OneofOptions__fields[1] = { + {999, UPB_SIZE(0, 0), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_OneofOptions_msginit = { +const upb_MiniTable google_protobuf_OneofOptions_msginit = { &google_protobuf_OneofOptions_submsgs[0], &google_protobuf_OneofOptions__fields[0], - UPB_SIZE(8, 8), 1, false, 0, 255, + UPB_SIZE(8, 8), 1, upb_ExtMode_Extendable, 0, 255, 0, }; -static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_EnumOptions_submsgs[1] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; -static const upb_msglayout_field google_protobuf_EnumOptions__fields[3] = { - {2, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(2, 2), 2, 0, 8, _UPB_MODE_SCALAR}, - {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_EnumOptions__fields[3] = { + {2, UPB_SIZE(1, 1), 1, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {3, UPB_SIZE(2, 2), 2, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_EnumOptions_msginit = { +const upb_MiniTable google_protobuf_EnumOptions_msginit = { &google_protobuf_EnumOptions_submsgs[0], &google_protobuf_EnumOptions__fields[0], - UPB_SIZE(8, 16), 3, false, 0, 255, + UPB_SIZE(8, 16), 3, upb_ExtMode_Extendable, 0, 255, 0, }; -static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_EnumValueOptions_submsgs[1] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; -static const upb_msglayout_field google_protobuf_EnumValueOptions__fields[2] = { - {1, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, - {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_EnumValueOptions__fields[2] = { + {1, UPB_SIZE(1, 1), 1, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_EnumValueOptions_msginit = { +const upb_MiniTable google_protobuf_EnumValueOptions_msginit = { &google_protobuf_EnumValueOptions_submsgs[0], &google_protobuf_EnumValueOptions__fields[0], - UPB_SIZE(8, 16), 2, false, 1, 255, + UPB_SIZE(8, 16), 2, upb_ExtMode_Extendable, 1, 255, 0, }; -static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_ServiceOptions_submsgs[1] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; -static const upb_msglayout_field google_protobuf_ServiceOptions__fields[2] = { - {33, UPB_SIZE(1, 1), 1, 0, 8, _UPB_MODE_SCALAR}, - {999, UPB_SIZE(4, 8), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_ServiceOptions__fields[2] = { + {33, UPB_SIZE(1, 1), 1, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_ServiceOptions_msginit = { +const upb_MiniTable google_protobuf_ServiceOptions_msginit = { &google_protobuf_ServiceOptions_submsgs[0], &google_protobuf_ServiceOptions__fields[0], - UPB_SIZE(8, 16), 2, false, 0, 255, + UPB_SIZE(8, 16), 2, upb_ExtMode_Extendable, 0, 255, 0, }; -static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = { - &google_protobuf_UninterpretedOption_msginit, +static const upb_MiniTable_Sub google_protobuf_MethodOptions_submsgs[2] = { + {.submsg = &google_protobuf_UninterpretedOption_msginit}, + {.subenum = &google_protobuf_MethodOptions_IdempotencyLevel_enuminit}, }; -static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = { - {33, UPB_SIZE(8, 8), 1, 0, 8, _UPB_MODE_SCALAR}, - {34, UPB_SIZE(4, 4), 2, 0, 14, _UPB_MODE_SCALAR}, - {999, UPB_SIZE(12, 16), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_MethodOptions__fields[3] = { + {33, UPB_SIZE(8, 8), 1, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, + {34, UPB_SIZE(4, 4), 2, 1, 14, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {999, UPB_SIZE(12, 16), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_MethodOptions_msginit = { +const upb_MiniTable google_protobuf_MethodOptions_msginit = { &google_protobuf_MethodOptions_submsgs[0], &google_protobuf_MethodOptions__fields[0], - UPB_SIZE(16, 24), 3, false, 0, 255, + UPB_SIZE(16, 24), 3, upb_ExtMode_Extendable, 0, 255, 0, }; -static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = { - &google_protobuf_UninterpretedOption_NamePart_msginit, +static const upb_MiniTable_Sub google_protobuf_UninterpretedOption_submsgs[1] = { + {.submsg = &google_protobuf_UninterpretedOption_NamePart_msginit}, }; -static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = { - {2, UPB_SIZE(56, 80), 0, 0, 11, _UPB_MODE_ARRAY}, - {3, UPB_SIZE(32, 32), 1, 0, 12, _UPB_MODE_SCALAR}, - {4, UPB_SIZE(8, 8), 2, 0, 4, _UPB_MODE_SCALAR}, - {5, UPB_SIZE(16, 16), 3, 0, 3, _UPB_MODE_SCALAR}, - {6, UPB_SIZE(24, 24), 4, 0, 1, _UPB_MODE_SCALAR}, - {7, UPB_SIZE(40, 48), 5, 0, 12, _UPB_MODE_SCALAR}, - {8, UPB_SIZE(48, 64), 6, 0, 12, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_UninterpretedOption__fields[7] = { + {2, UPB_SIZE(56, 80), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {3, UPB_SIZE(32, 32), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {4, UPB_SIZE(8, 8), 2, 0, 4, kUpb_FieldMode_Scalar | (upb_FieldRep_8Byte << upb_FieldRep_Shift)}, + {5, UPB_SIZE(16, 16), 3, 0, 3, kUpb_FieldMode_Scalar | (upb_FieldRep_8Byte << upb_FieldRep_Shift)}, + {6, UPB_SIZE(24, 24), 4, 0, 1, kUpb_FieldMode_Scalar | (upb_FieldRep_8Byte << upb_FieldRep_Shift)}, + {7, UPB_SIZE(40, 48), 5, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {8, UPB_SIZE(48, 64), 6, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_UninterpretedOption_msginit = { +const upb_MiniTable google_protobuf_UninterpretedOption_msginit = { &google_protobuf_UninterpretedOption_submsgs[0], &google_protobuf_UninterpretedOption__fields[0], - UPB_SIZE(64, 96), 7, false, 0, 255, + UPB_SIZE(64, 96), 7, upb_ExtMode_NonExtendable, 0, 255, 0, }; -static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = { - {1, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {2, UPB_SIZE(1, 1), 2, 0, 8, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_UninterpretedOption_NamePart__fields[2] = { + {1, UPB_SIZE(4, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {2, UPB_SIZE(1, 1), 2, 0, 8, kUpb_FieldMode_Scalar | (upb_FieldRep_1Byte << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = { +const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msginit = { NULL, &google_protobuf_UninterpretedOption_NamePart__fields[0], - UPB_SIZE(16, 32), 2, false, 2, 255, + UPB_SIZE(16, 32), 2, upb_ExtMode_NonExtendable, 2, 255, 2, }; -static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = { - &google_protobuf_SourceCodeInfo_Location_msginit, +static const upb_MiniTable_Sub google_protobuf_SourceCodeInfo_submsgs[1] = { + {.submsg = &google_protobuf_SourceCodeInfo_Location_msginit}, }; -static const upb_msglayout_field google_protobuf_SourceCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_SourceCodeInfo__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_SourceCodeInfo_msginit = { +const upb_MiniTable google_protobuf_SourceCodeInfo_msginit = { &google_protobuf_SourceCodeInfo_submsgs[0], &google_protobuf_SourceCodeInfo__fields[0], - UPB_SIZE(8, 8), 1, false, 1, 255, + UPB_SIZE(8, 8), 1, upb_ExtMode_NonExtendable, 1, 255, 0, }; -static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = { - {1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, - {2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, - {3, UPB_SIZE(4, 8), 1, 0, 12, _UPB_MODE_SCALAR}, - {4, UPB_SIZE(12, 24), 2, 0, 12, _UPB_MODE_SCALAR}, - {6, UPB_SIZE(28, 56), 0, 0, 12, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_SourceCodeInfo_Location__fields[5] = { + {1, UPB_SIZE(20, 40), 0, 0, 5, kUpb_FieldMode_Array | upb_LabelFlags_IsPacked | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {2, UPB_SIZE(24, 48), 0, 0, 5, kUpb_FieldMode_Array | upb_LabelFlags_IsPacked | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {3, UPB_SIZE(4, 8), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {4, UPB_SIZE(12, 24), 2, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {6, UPB_SIZE(28, 56), 0, 0, 12, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = { +const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msginit = { NULL, &google_protobuf_SourceCodeInfo_Location__fields[0], - UPB_SIZE(32, 64), 5, false, 4, 255, + UPB_SIZE(32, 64), 5, upb_ExtMode_NonExtendable, 4, 255, 0, }; -static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = { - &google_protobuf_GeneratedCodeInfo_Annotation_msginit, +static const upb_MiniTable_Sub google_protobuf_GeneratedCodeInfo_submsgs[1] = { + {.submsg = &google_protobuf_GeneratedCodeInfo_Annotation_msginit}, }; -static const upb_msglayout_field google_protobuf_GeneratedCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), 0, 0, 11, _UPB_MODE_ARRAY}, +static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo__fields[1] = { + {1, UPB_SIZE(0, 0), 0, 0, 11, kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = { +const upb_MiniTable google_protobuf_GeneratedCodeInfo_msginit = { &google_protobuf_GeneratedCodeInfo_submsgs[0], &google_protobuf_GeneratedCodeInfo__fields[0], - UPB_SIZE(8, 8), 1, false, 1, 255, + UPB_SIZE(8, 8), 1, upb_ExtMode_NonExtendable, 1, 255, 0, }; -static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { - {1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_MODE_ARRAY | _UPB_MODE_IS_PACKED}, - {2, UPB_SIZE(12, 16), 1, 0, 12, _UPB_MODE_SCALAR}, - {3, UPB_SIZE(4, 4), 2, 0, 5, _UPB_MODE_SCALAR}, - {4, UPB_SIZE(8, 8), 3, 0, 5, _UPB_MODE_SCALAR}, +static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { + {1, UPB_SIZE(20, 32), 0, 0, 5, kUpb_FieldMode_Array | upb_LabelFlags_IsPacked | (upb_FieldRep_Pointer << upb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 16), 1, 0, 12, kUpb_FieldMode_Scalar | (upb_FieldRep_StringView << upb_FieldRep_Shift)}, + {3, UPB_SIZE(4, 4), 2, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, + {4, UPB_SIZE(8, 8), 3, 0, 5, kUpb_FieldMode_Scalar | (upb_FieldRep_4Byte << upb_FieldRep_Shift)}, }; -const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = { +const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msginit = { NULL, &google_protobuf_GeneratedCodeInfo_Annotation__fields[0], - UPB_SIZE(24, 48), 4, false, 4, 255, + UPB_SIZE(24, 48), 4, upb_ExtMode_NonExtendable, 4, 255, 0, +}; + +static const upb_MiniTable *messages_layout[27] = { + &google_protobuf_FileDescriptorSet_msginit, + &google_protobuf_FileDescriptorProto_msginit, + &google_protobuf_DescriptorProto_msginit, + &google_protobuf_DescriptorProto_ExtensionRange_msginit, + &google_protobuf_DescriptorProto_ReservedRange_msginit, + &google_protobuf_ExtensionRangeOptions_msginit, + &google_protobuf_FieldDescriptorProto_msginit, + &google_protobuf_OneofDescriptorProto_msginit, + &google_protobuf_EnumDescriptorProto_msginit, + &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, + &google_protobuf_EnumValueDescriptorProto_msginit, + &google_protobuf_ServiceDescriptorProto_msginit, + &google_protobuf_MethodDescriptorProto_msginit, + &google_protobuf_FileOptions_msginit, + &google_protobuf_MessageOptions_msginit, + &google_protobuf_FieldOptions_msginit, + &google_protobuf_OneofOptions_msginit, + &google_protobuf_EnumOptions_msginit, + &google_protobuf_EnumValueOptions_msginit, + &google_protobuf_ServiceOptions_msginit, + &google_protobuf_MethodOptions_msginit, + &google_protobuf_UninterpretedOption_msginit, + &google_protobuf_UninterpretedOption_NamePart_msginit, + &google_protobuf_SourceCodeInfo_msginit, + &google_protobuf_SourceCodeInfo_Location_msginit, + &google_protobuf_GeneratedCodeInfo_msginit, + &google_protobuf_GeneratedCodeInfo_Annotation_msginit, +}; + +const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enuminit = { + NULL, + 0x7fffeULL, + 0, +}; + +const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enuminit = { + NULL, + 0xeULL, + 0, +}; + +const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enuminit = { + NULL, + 0xeULL, + 0, +}; + +const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enuminit = { + NULL, + 0x7ULL, + 0, +}; + +const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enuminit = { + NULL, + 0x7ULL, + 0, +}; + +const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enuminit = { + NULL, + 0x7ULL, + 0, +}; + +static const upb_MiniTable_Enum *enums_layout[6] = { + &google_protobuf_FieldDescriptorProto_Type_enuminit, + &google_protobuf_FieldDescriptorProto_Label_enuminit, + &google_protobuf_FileOptions_OptimizeMode_enuminit, + &google_protobuf_FieldOptions_CType_enuminit, + &google_protobuf_FieldOptions_JSType_enuminit, + &google_protobuf_MethodOptions_IdempotencyLevel_enuminit, +}; + +const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout = { + messages_layout, + enums_layout, + NULL, + 27, + 6, + 0, }; @@ -4469,143 +5145,240 @@ const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = { typedef struct { size_t len; - char str[1]; /* Null-terminated string data follows. */ + char str[1]; /* Null-terminated string data follows. */ } str_t; -struct upb_fielddef { - const upb_filedef *file; - const upb_msgdef *msgdef; - const char *full_name; - const char *json_name; +/* The upb core does not generally have a concept of default instances. However + * for descriptor options we make an exception since the max size is known and + * modest (<200 bytes). All types can share a default instance since it is + * initialized to zeroes. + * + * We have to allocate an extra pointer for upb's internal metadata. */ +static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; +static const char* opt_default = &opt_default_buf[sizeof(void*)]; + +struct upb_FieldDef { + const google_protobuf_FieldOptions* opts; + const upb_FileDef* file; + const upb_MessageDef* msgdef; + const char* full_name; + const char* json_name; union { int64_t sint; uint64_t uint; double dbl; float flt; bool boolean; - str_t *str; + str_t* str; } defaultval; - const upb_oneofdef *oneof; union { - const upb_msgdef *msgdef; - const upb_enumdef *enumdef; - const google_protobuf_FieldDescriptorProto *unresolved; + const upb_OneofDef* oneof; + const upb_MessageDef* extension_scope; + } scope; + union { + const upb_MessageDef* msgdef; + const upb_EnumDef* enumdef; + const google_protobuf_FieldDescriptorProto* unresolved; } sub; uint32_t number_; uint16_t index_; - uint16_t layout_index; + uint16_t layout_index; /* Index into msgdef->layout->fields or file->exts */ + bool has_default; bool is_extension_; - bool lazy_; bool packed_; bool proto3_optional_; - upb_descriptortype_t type_; - upb_label_t label_; + bool has_json_name_; + upb_FieldType type_; + upb_Label label_; +}; + +struct upb_ExtensionRange { + const google_protobuf_ExtensionRangeOptions* opts; + int32_t start; + int32_t end; }; -struct upb_msgdef { - const upb_msglayout *layout; - const upb_filedef *file; - const char *full_name; +struct upb_MessageDef { + const google_protobuf_MessageOptions* opts; + const upb_MiniTable* layout; + const upb_FileDef* file; + const upb_MessageDef* containing_type; + const char* full_name; /* Tables for looking up fields by number and name. */ upb_inttable itof; upb_strtable ntof; - const upb_fielddef *fields; - const upb_oneofdef *oneofs; + /* All nested defs. + * MEM: We could save some space here by putting nested defs in a contigous + * region and calculating counts from offets or vice-versa. */ + const upb_FieldDef* fields; + const upb_OneofDef* oneofs; + const upb_ExtensionRange* ext_ranges; + const upb_MessageDef* nested_msgs; + const upb_EnumDef* nested_enums; + const upb_FieldDef* nested_exts; int field_count; - int oneof_count; int real_oneof_count; - - /* Is this a map-entry message? */ - bool map_entry; - upb_wellknowntype_t well_known_type; - - /* TODO(haberman): proper extension ranges (there can be multiple). */ + int oneof_count; + int ext_range_count; + int nested_msg_count; + int nested_enum_count; + int nested_ext_count; + bool in_message_set; + upb_WellKnown well_known_type; }; -struct upb_enumdef { - const upb_filedef *file; - const char *full_name; +struct upb_EnumDef { + const google_protobuf_EnumOptions* opts; + const upb_MiniTable_Enum* layout; // Only for proto2. + const upb_FileDef* file; + const upb_MessageDef* containing_type; // Could be merged with "file". + const char* full_name; upb_strtable ntoi; upb_inttable iton; + const upb_EnumValueDef* values; + int value_count; int32_t defaultval; }; -struct upb_oneofdef { - const upb_msgdef *parent; - const char *full_name; +struct upb_EnumValueDef { + const google_protobuf_EnumValueOptions* opts; + const upb_EnumDef* parent; + const char* full_name; + int32_t number; +}; + +struct upb_OneofDef { + const google_protobuf_OneofOptions* opts; + const upb_MessageDef* parent; + const char* full_name; int field_count; bool synthetic; - const upb_fielddef **fields; + const upb_FieldDef** fields; upb_strtable ntof; upb_inttable itof; }; -struct upb_filedef { - const char *name; - const char *package; - const char *phpprefix; - const char *phpnamespace; - - const upb_filedef **deps; - const upb_msgdef *msgs; - const upb_enumdef *enums; - const upb_fielddef *exts; - const upb_symtab *symtab; +struct upb_FileDef { + const google_protobuf_FileOptions* opts; + const char* name; + const char* package; + + const upb_FileDef** deps; + const int32_t* public_deps; + const int32_t* weak_deps; + const upb_MessageDef* top_lvl_msgs; + const upb_EnumDef* top_lvl_enums; + const upb_FieldDef* top_lvl_exts; + const upb_ServiceDef* services; + const upb_MiniTable_Extension** ext_layouts; + const upb_DefPool* symtab; int dep_count; - int msg_count; - int enum_count; - int ext_count; - upb_syntax_t syntax; + int public_dep_count; + int weak_dep_count; + int top_lvl_msg_count; + int top_lvl_enum_count; + int top_lvl_ext_count; + int service_count; + int ext_count; /* All exts in the file. */ + upb_Syntax syntax; +}; + +struct upb_MethodDef { + const google_protobuf_MethodOptions* opts; + upb_ServiceDef* service; + const char* full_name; + const upb_MessageDef* input_type; + const upb_MessageDef* output_type; + bool client_streaming; + bool server_streaming; +}; + +struct upb_ServiceDef { + const google_protobuf_ServiceOptions* opts; + const upb_FileDef* file; + const char* full_name; + upb_MethodDef* methods; + int method_count; + int index; }; -struct upb_symtab { - upb_arena *arena; +struct upb_DefPool { + upb_Arena* arena; upb_strtable syms; /* full_name -> packed def ptr */ - upb_strtable files; /* file_name -> upb_filedef* */ + upb_strtable files; /* file_name -> upb_FileDef* */ + upb_inttable exts; /* upb_MiniTable_Extension* -> upb_FieldDef* */ + upb_ExtensionRegistry* extreg; size_t bytes_loaded; }; /* Inside a symtab we store tagged pointers to specific def types. */ typedef enum { - UPB_DEFTYPE_FIELD = 0, + UPB_DEFTYPE_MASK = 7, /* Only inside symtab table. */ + UPB_DEFTYPE_EXT = 0, UPB_DEFTYPE_MSG = 1, UPB_DEFTYPE_ENUM = 2, + UPB_DEFTYPE_ENUMVAL = 3, + UPB_DEFTYPE_SERVICE = 4, /* Only inside message table. */ + UPB_DEFTYPE_FIELD = 0, UPB_DEFTYPE_ONEOF = 1, - UPB_DEFTYPE_FIELD_JSONNAME = 2 + UPB_DEFTYPE_FIELD_JSONNAME = 2, + + /* Only inside file table. */ + UPB_DEFTYPE_FILE = 0, + UPB_DEFTYPE_LAYOUT = 1 } upb_deftype_t; -static const void *unpack_def(upb_value v, upb_deftype_t type) { +#define FIELD_TYPE_UNSPECIFIED 0 + +static upb_deftype_t deftype(upb_value v) { uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return (num & 3) == type ? (const void*)(num & ~3) : NULL; + return num & UPB_DEFTYPE_MASK; } -static upb_value pack_def(const void *ptr, upb_deftype_t type) { - uintptr_t num = (uintptr_t)ptr | type; +static const void* unpack_def(upb_value v, upb_deftype_t type) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return (num & UPB_DEFTYPE_MASK) == type + ? (const void*)(num & ~UPB_DEFTYPE_MASK) + : NULL; +} + +static upb_value pack_def(const void* ptr, upb_deftype_t type) { + uintptr_t num = (uintptr_t)ptr; + UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); + num |= type; return upb_value_constptr((const void*)num); } /* isalpha() etc. from are locale-dependent, which we don't want. */ -static bool upb_isbetween(char c, char low, char high) { +static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { return c >= low && c <= high; } +static char upb_ascii_lower(char ch) { + // Per ASCII this will lower-case a letter. If the result is a letter, the + // input was definitely a letter. If the output is not a letter, this may + // have transformed the character unpredictably. + return ch | 0x20; +} + static bool upb_isletter(char c) { - return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_'; + char lower = upb_ascii_lower(c); + return upb_isbetween(lower, 'a', 'z') || c == '_'; } static bool upb_isalphanum(char c) { return upb_isletter(c) || upb_isbetween(c, '0', '9'); } -static const char *shortdefname(const char *fullname) { - const char *p; +static const char* shortdefname(const char* fullname) { + const char* p; if (fullname == NULL) { return NULL; @@ -4620,371 +5393,417 @@ static const char *shortdefname(const char *fullname) { /* All submessage fields are lower than all other fields. * Secondly, fields are increasing in order. */ -uint32_t field_rank(const upb_fielddef *f) { - uint32_t ret = upb_fielddef_number(f); +uint32_t field_rank(const upb_FieldDef* f) { + uint32_t ret = upb_FieldDef_Number(f); const uint32_t high_bit = 1 << 30; UPB_ASSERT(ret < high_bit); - if (!upb_fielddef_issubmsg(f)) - ret |= high_bit; + if (!upb_FieldDef_IsSubMessage(f)) ret |= high_bit; return ret; } -int cmp_fields(const void *p1, const void *p2) { - const upb_fielddef *f1 = *(upb_fielddef*const*)p1; - const upb_fielddef *f2 = *(upb_fielddef*const*)p2; +int cmp_fields(const void* p1, const void* p2) { + const upb_FieldDef* f1 = *(upb_FieldDef* const*)p1; + const upb_FieldDef* f2 = *(upb_FieldDef* const*)p2; return field_rank(f1) - field_rank(f2); } -static void upb_status_setoom(upb_status *status) { - upb_status_seterrmsg(status, "out of memory"); +static void upb_Status_setoom(upb_Status* status) { + upb_Status_SetErrorMessage(status, "out of memory"); } -static void assign_msg_wellknowntype(upb_msgdef *m) { - const char *name = upb_msgdef_fullname(m); +static void assign_msg_wellknowntype(upb_MessageDef* m) { + const char* name = upb_MessageDef_FullName(m); if (name == NULL) { - m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; + m->well_known_type = kUpb_WellKnown_Unspecified; return; } if (!strcmp(name, "google.protobuf.Any")) { - m->well_known_type = UPB_WELLKNOWN_ANY; + m->well_known_type = kUpb_WellKnown_Any; } else if (!strcmp(name, "google.protobuf.FieldMask")) { - m->well_known_type = UPB_WELLKNOWN_FIELDMASK; + m->well_known_type = kUpb_WellKnown_FieldMask; } else if (!strcmp(name, "google.protobuf.Duration")) { - m->well_known_type = UPB_WELLKNOWN_DURATION; + m->well_known_type = kUpb_WellKnown_Duration; } else if (!strcmp(name, "google.protobuf.Timestamp")) { - m->well_known_type = UPB_WELLKNOWN_TIMESTAMP; + m->well_known_type = kUpb_WellKnown_Timestamp; } else if (!strcmp(name, "google.protobuf.DoubleValue")) { - m->well_known_type = UPB_WELLKNOWN_DOUBLEVALUE; + m->well_known_type = kUpb_WellKnown_DoubleValue; } else if (!strcmp(name, "google.protobuf.FloatValue")) { - m->well_known_type = UPB_WELLKNOWN_FLOATVALUE; + m->well_known_type = kUpb_WellKnown_FloatValue; } else if (!strcmp(name, "google.protobuf.Int64Value")) { - m->well_known_type = UPB_WELLKNOWN_INT64VALUE; + m->well_known_type = kUpb_WellKnown_Int64Value; } else if (!strcmp(name, "google.protobuf.UInt64Value")) { - m->well_known_type = UPB_WELLKNOWN_UINT64VALUE; + m->well_known_type = kUpb_WellKnown_UInt64Value; } else if (!strcmp(name, "google.protobuf.Int32Value")) { - m->well_known_type = UPB_WELLKNOWN_INT32VALUE; + m->well_known_type = kUpb_WellKnown_Int32Value; } else if (!strcmp(name, "google.protobuf.UInt32Value")) { - m->well_known_type = UPB_WELLKNOWN_UINT32VALUE; + m->well_known_type = kUpb_WellKnown_UInt32Value; } else if (!strcmp(name, "google.protobuf.BoolValue")) { - m->well_known_type = UPB_WELLKNOWN_BOOLVALUE; + m->well_known_type = kUpb_WellKnown_BoolValue; } else if (!strcmp(name, "google.protobuf.StringValue")) { - m->well_known_type = UPB_WELLKNOWN_STRINGVALUE; + m->well_known_type = kUpb_WellKnown_StringValue; } else if (!strcmp(name, "google.protobuf.BytesValue")) { - m->well_known_type = UPB_WELLKNOWN_BYTESVALUE; + m->well_known_type = kUpb_WellKnown_BytesValue; } else if (!strcmp(name, "google.protobuf.Value")) { - m->well_known_type = UPB_WELLKNOWN_VALUE; + m->well_known_type = kUpb_WellKnown_Value; } else if (!strcmp(name, "google.protobuf.ListValue")) { - m->well_known_type = UPB_WELLKNOWN_LISTVALUE; + m->well_known_type = kUpb_WellKnown_ListValue; } else if (!strcmp(name, "google.protobuf.Struct")) { - m->well_known_type = UPB_WELLKNOWN_STRUCT; + m->well_known_type = kUpb_WellKnown_Struct; } else { - m->well_known_type = UPB_WELLKNOWN_UNSPECIFIED; + m->well_known_type = kUpb_WellKnown_Unspecified; } } +/* upb_EnumDef ****************************************************************/ -/* upb_enumdef ****************************************************************/ - -const char *upb_enumdef_fullname(const upb_enumdef *e) { - return e->full_name; +const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e) { + return e->opts; } -const char *upb_enumdef_name(const upb_enumdef *e) { - return shortdefname(e->full_name); +bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { + return e->opts != (void*)opt_default; } -const upb_filedef *upb_enumdef_file(const upb_enumdef *e) { - return e->file; -} +const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } -int32_t upb_enumdef_default(const upb_enumdef *e) { - UPB_ASSERT(upb_enumdef_iton(e, e->defaultval)); - return e->defaultval; +const char* upb_EnumDef_Name(const upb_EnumDef* e) { + return shortdefname(e->full_name); } -int upb_enumdef_numvals(const upb_enumdef *e) { - return (int)upb_strtable_count(&e->ntoi); +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } + +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { + return e->containing_type; } -void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) { - /* We iterate over the ntoi table, to account for duplicate numbers. */ - upb_strtable_begin(i, &e->ntoi); +int32_t upb_EnumDef_Default(const upb_EnumDef* e) { + UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); + return e->defaultval; } -void upb_enum_next(upb_enum_iter *iter) { upb_strtable_next(iter); } -bool upb_enum_done(upb_enum_iter *iter) { return upb_strtable_done(iter); } +int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } -bool upb_enumdef_ntoi(const upb_enumdef *def, const char *name, - size_t len, int32_t *num) { +const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( + const upb_EnumDef* def, const char* name, size_t len) { upb_value v; - if (!upb_strtable_lookup2(&def->ntoi, name, len, &v)) { - return false; - } - if (num) *num = upb_value_getint32(v); - return true; + return upb_strtable_lookup2(&def->ntoi, name, len, &v) + ? upb_value_getconstptr(v) + : NULL; } -const char *upb_enumdef_iton(const upb_enumdef *def, int32_t num) { +const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* def, + int32_t num) { upb_value v; - return upb_inttable_lookup(&def->iton, num, &v) ? upb_value_getcstr(v) : NULL; + return upb_inttable_lookup(&def->iton, num, &v) ? upb_value_getconstptr(v) + : NULL; } -const char *upb_enum_iter_name(upb_enum_iter *iter) { - return upb_strtable_iter_key(iter).data; +bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { + // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect + // this to be faster (especially for small numbers). + return upb_MiniTable_Enum_CheckValue(e->layout, num); } -int32_t upb_enum_iter_number(upb_enum_iter *iter) { - return upb_value_getint32(upb_strtable_iter_value(iter)); +const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->value_count); + return &e->values[i]; } +/* upb_EnumValueDef ***********************************************************/ -/* upb_fielddef ***************************************************************/ - -const char *upb_fielddef_fullname(const upb_fielddef *f) { - return f->full_name; +const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( + const upb_EnumValueDef* e) { + return e->opts; } -upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) { - switch (f->type_) { - case UPB_DESCRIPTOR_TYPE_DOUBLE: - return UPB_TYPE_DOUBLE; - case UPB_DESCRIPTOR_TYPE_FLOAT: - return UPB_TYPE_FLOAT; - case UPB_DESCRIPTOR_TYPE_INT64: - case UPB_DESCRIPTOR_TYPE_SINT64: - case UPB_DESCRIPTOR_TYPE_SFIXED64: - return UPB_TYPE_INT64; - case UPB_DESCRIPTOR_TYPE_INT32: - case UPB_DESCRIPTOR_TYPE_SFIXED32: - case UPB_DESCRIPTOR_TYPE_SINT32: - return UPB_TYPE_INT32; - case UPB_DESCRIPTOR_TYPE_UINT64: - case UPB_DESCRIPTOR_TYPE_FIXED64: - return UPB_TYPE_UINT64; - case UPB_DESCRIPTOR_TYPE_UINT32: - case UPB_DESCRIPTOR_TYPE_FIXED32: - return UPB_TYPE_UINT32; - case UPB_DESCRIPTOR_TYPE_ENUM: - return UPB_TYPE_ENUM; - case UPB_DESCRIPTOR_TYPE_BOOL: - return UPB_TYPE_BOOL; - case UPB_DESCRIPTOR_TYPE_STRING: - return UPB_TYPE_STRING; - case UPB_DESCRIPTOR_TYPE_BYTES: - return UPB_TYPE_BYTES; - case UPB_DESCRIPTOR_TYPE_GROUP: - case UPB_DESCRIPTOR_TYPE_MESSAGE: - return UPB_TYPE_MESSAGE; - } - UPB_UNREACHABLE(); +bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* e) { + return e->opts != (void*)opt_default; } -upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f) { - return f->type_; +const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* ev) { + return ev->parent; } -uint32_t upb_fielddef_index(const upb_fielddef *f) { - return f->index_; +const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* ev) { + return ev->full_name; } -upb_label_t upb_fielddef_label(const upb_fielddef *f) { - return f->label_; +const char* upb_EnumValueDef_Name(const upb_EnumValueDef* ev) { + return shortdefname(ev->full_name); } -uint32_t upb_fielddef_number(const upb_fielddef *f) { - return f->number_; +int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* ev) { + return ev->number; } -bool upb_fielddef_isextension(const upb_fielddef *f) { - return f->is_extension_; +uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* ev) { + // Compute index in our parent's array. + return ev - ev->parent->values; } -bool upb_fielddef_lazy(const upb_fielddef *f) { - return f->lazy_; -} +/* upb_ExtensionRange + * ***************************************************************/ -bool upb_fielddef_packed(const upb_fielddef *f) { - return f->packed_; +const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( + const upb_ExtensionRange* r) { + return r->opts; } -const char *upb_fielddef_name(const upb_fielddef *f) { - return shortdefname(f->full_name); +bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { + return r->opts != (void*)opt_default; } -const char *upb_fielddef_jsonname(const upb_fielddef *f) { - return f->json_name; +int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* e) { + return e->start; } -const upb_filedef *upb_fielddef_file(const upb_fielddef *f) { - return f->file; -} +int32_t upb_ExtensionRange_End(const upb_ExtensionRange* e) { return e->end; } -const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) { - return f->msgdef; +/* upb_FieldDef ***************************************************************/ + +const google_protobuf_FieldOptions* upb_FieldDef_Options( + const upb_FieldDef* f) { + return f->opts; } -const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) { - return f->oneof; +bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { + return f->opts != (void*)opt_default; } -const upb_oneofdef *upb_fielddef_realcontainingoneof(const upb_fielddef *f) { - if (!f->oneof || upb_oneofdef_issynthetic(f->oneof)) return NULL; - return f->oneof; +const char* upb_FieldDef_FullName(const upb_FieldDef* f) { + return f->full_name; } -upb_msgval upb_fielddef_default(const upb_fielddef *f) { - UPB_ASSERT(!upb_fielddef_issubmsg(f)); - upb_msgval ret; - if (upb_fielddef_isstring(f)) { - str_t *str = f->defaultval.str; - if (str) { - ret.str_val.data = str->str; - ret.str_val.size = str->len; - } else { - ret.str_val.size = 0; - } - } else { - memcpy(&ret, &f->defaultval, 8); +upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { + switch (f->type_) { + case kUpb_FieldType_Double: + return kUpb_CType_Double; + case kUpb_FieldType_Float: + return kUpb_CType_Float; + case kUpb_FieldType_Int64: + case kUpb_FieldType_SInt64: + case kUpb_FieldType_SFixed64: + return kUpb_CType_Int64; + case kUpb_FieldType_Int32: + case kUpb_FieldType_SFixed32: + case kUpb_FieldType_SInt32: + return kUpb_CType_Int32; + case kUpb_FieldType_UInt64: + case kUpb_FieldType_Fixed64: + return kUpb_CType_UInt64; + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Fixed32: + return kUpb_CType_UInt32; + case kUpb_FieldType_Enum: + return kUpb_CType_Enum; + case kUpb_FieldType_Bool: + return kUpb_CType_Bool; + case kUpb_FieldType_String: + return kUpb_CType_String; + case kUpb_FieldType_Bytes: + return kUpb_CType_Bytes; + case kUpb_FieldType_Group: + case kUpb_FieldType_Message: + return kUpb_CType_Message; } - return ret; + UPB_UNREACHABLE(); } -static void chkdefaulttype(const upb_fielddef *f, int ctype) { - UPB_UNUSED(f); - UPB_UNUSED(ctype); -} +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; } -int64_t upb_fielddef_defaultint64(const upb_fielddef *f) { - chkdefaulttype(f, UPB_TYPE_INT64); - return f->defaultval.sint; -} +uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } -int32_t upb_fielddef_defaultint32(const upb_fielddef *f) { - chkdefaulttype(f, UPB_TYPE_INT32); - return (int32_t)f->defaultval.sint; -} +upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; } -uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { - chkdefaulttype(f, UPB_TYPE_UINT64); - return f->defaultval.uint; +uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } + +bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { + return f->is_extension_; } -uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) { - chkdefaulttype(f, UPB_TYPE_UINT32); - return (uint32_t)f->defaultval.uint; +bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { return f->packed_; } + +const char* upb_FieldDef_Name(const upb_FieldDef* f) { + return shortdefname(f->full_name); } -bool upb_fielddef_defaultbool(const upb_fielddef *f) { - chkdefaulttype(f, UPB_TYPE_BOOL); - return f->defaultval.boolean; +const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { + return f->json_name; } -float upb_fielddef_defaultfloat(const upb_fielddef *f) { - chkdefaulttype(f, UPB_TYPE_FLOAT); - return f->defaultval.flt; +bool upb_FieldDef_HasJsonName(const upb_FieldDef* f) { + return f->has_json_name_; } -double upb_fielddef_defaultdouble(const upb_fielddef *f) { - chkdefaulttype(f, UPB_TYPE_DOUBLE); - return f->defaultval.dbl; +const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f) { return f->file; } + +const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f) { + return f->msgdef; } -const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) { - str_t *str = f->defaultval.str; - UPB_ASSERT(upb_fielddef_type(f) == UPB_TYPE_STRING || - upb_fielddef_type(f) == UPB_TYPE_BYTES || - upb_fielddef_type(f) == UPB_TYPE_ENUM); - if (str) { - if (len) *len = str->len; - return str->str; - } else { - if (len) *len = 0; - return NULL; +const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f) { + return f->is_extension_ ? f->scope.extension_scope : NULL; +} + +const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f) { + return f->is_extension_ ? NULL : f->scope.oneof; +} + +const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f) { + const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(f); + if (!oneof || upb_OneofDef_IsSynthetic(oneof)) return NULL; + return oneof; +} + +upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f) { + UPB_ASSERT(!upb_FieldDef_IsSubMessage(f)); + upb_MessageValue ret; + + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + return (upb_MessageValue){.bool_val = f->defaultval.boolean}; + case kUpb_CType_Int64: + return (upb_MessageValue){.int64_val = f->defaultval.sint}; + case kUpb_CType_UInt64: + return (upb_MessageValue){.uint64_val = f->defaultval.uint}; + case kUpb_CType_Enum: + case kUpb_CType_Int32: + return (upb_MessageValue){.int32_val = (int32_t)f->defaultval.sint}; + case kUpb_CType_UInt32: + return (upb_MessageValue){.uint32_val = (uint32_t)f->defaultval.uint}; + case kUpb_CType_Float: + return (upb_MessageValue){.float_val = f->defaultval.flt}; + case kUpb_CType_Double: + return (upb_MessageValue){.double_val = f->defaultval.dbl}; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + str_t* str = f->defaultval.str; + if (str) { + return (upb_MessageValue){ + .str_val = (upb_StringView){.data = str->str, .size = str->len}}; + } else { + return (upb_MessageValue){ + .str_val = (upb_StringView){.data = NULL, .size = 0}}; + } + } + default: + UPB_UNREACHABLE(); } + + return ret; } -const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f) { - return upb_fielddef_type(f) == UPB_TYPE_MESSAGE ? f->sub.msgdef : NULL; +const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message ? f->sub.msgdef : NULL; } -const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f) { - return upb_fielddef_type(f) == UPB_TYPE_ENUM ? f->sub.enumdef : NULL; +const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Enum ? f->sub.enumdef : NULL; } -const upb_msglayout_field *upb_fielddef_layout(const upb_fielddef *f) { +const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f) { + UPB_ASSERT(!upb_FieldDef_IsExtension(f)); return &f->msgdef->layout->fields[f->layout_index]; } -bool upb_fielddef_issubmsg(const upb_fielddef *f) { - return upb_fielddef_type(f) == UPB_TYPE_MESSAGE; +const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( + const upb_FieldDef* f) { + UPB_ASSERT(upb_FieldDef_IsExtension(f)); + return f->file->ext_layouts[f->layout_index]; } -bool upb_fielddef_isstring(const upb_fielddef *f) { - return upb_fielddef_type(f) == UPB_TYPE_STRING || - upb_fielddef_type(f) == UPB_TYPE_BYTES; +bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { + return f->proto3_optional_; } -bool upb_fielddef_isseq(const upb_fielddef *f) { - return upb_fielddef_label(f) == UPB_LABEL_REPEATED; +bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message; } -bool upb_fielddef_isprimitive(const upb_fielddef *f) { - return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f); +bool upb_FieldDef_IsString(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_String || + upb_FieldDef_CType(f) == kUpb_CType_Bytes; } -bool upb_fielddef_ismap(const upb_fielddef *f) { - return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) && - upb_msgdef_mapentry(upb_fielddef_msgsubdef(f)); +bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { + return upb_FieldDef_Label(f) == kUpb_Label_Repeated; } -bool upb_fielddef_hassubdef(const upb_fielddef *f) { - return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM; +bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { + return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); +} + +bool upb_FieldDef_IsMap(const upb_FieldDef* f) { + return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && + upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); +} + +bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } + +bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { + return upb_FieldDef_IsSubMessage(f) || + upb_FieldDef_CType(f) == kUpb_CType_Enum; } -bool upb_fielddef_haspresence(const upb_fielddef *f) { - if (upb_fielddef_isseq(f)) return false; - return upb_fielddef_issubmsg(f) || upb_fielddef_containingoneof(f) || - f->file->syntax == UPB_SYNTAX_PROTO2; +bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { + if (upb_FieldDef_IsRepeated(f)) return false; + return upb_FieldDef_IsSubMessage(f) || upb_FieldDef_ContainingOneof(f) || + f->file->syntax == kUpb_Syntax_Proto2; } static bool between(int32_t x, int32_t low, int32_t high) { return x >= low && x <= high; } -bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); } -bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); } -bool upb_fielddef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } +bool upb_FieldDef_checklabel(int32_t label) { return between(label, 1, 3); } +bool upb_FieldDef_checktype(int32_t type) { return between(type, 1, 11); } +bool upb_FieldDef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } -bool upb_fielddef_checkdescriptortype(int32_t type) { +bool upb_FieldDef_checkdescriptortype(int32_t type) { return between(type, 1, 18); } -/* upb_msgdef *****************************************************************/ +/* upb_MessageDef + * *****************************************************************/ -const char *upb_msgdef_fullname(const upb_msgdef *m) { +const google_protobuf_MessageOptions* upb_MessageDef_Options( + const upb_MessageDef* m) { + return m->opts; +} + +bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { + return m->opts != (void*)opt_default; +} + +const char* upb_MessageDef_FullName(const upb_MessageDef* m) { return m->full_name; } -const upb_filedef *upb_msgdef_file(const upb_msgdef *m) { +const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { return m->file; } -const char *upb_msgdef_name(const upb_msgdef *m) { +const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { + return m->containing_type; +} + +const char* upb_MessageDef_Name(const upb_MessageDef* m) { return shortdefname(m->full_name); } -upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m) { +upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { return m->file->syntax; } -const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) { +const upb_FieldDef* upb_MessageDef_FindFieldByNumberWithSize( + const upb_MessageDef* m, uint32_t i) { upb_value val; return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) : NULL; } -const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, - size_t len) { +const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { upb_value val; if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { @@ -4994,8 +5813,8 @@ const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, return unpack_def(val, UPB_DEFTYPE_FIELD); } -const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, - size_t len) { +const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { upb_value val; if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { @@ -5005,23 +5824,27 @@ const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, return unpack_def(val, UPB_DEFTYPE_ONEOF); } -bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len, - const upb_fielddef **f, const upb_oneofdef **o) { +bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, + const char* name, size_t len, + const upb_FieldDef** out_f, + const upb_OneofDef** out_o) { upb_value val; if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { return false; } - *o = unpack_def(val, UPB_DEFTYPE_ONEOF); - *f = unpack_def(val, UPB_DEFTYPE_FIELD); - return *o || *f; /* False if this was a JSON name. */ + const upb_FieldDef* f = unpack_def(val, UPB_DEFTYPE_FIELD); + const upb_OneofDef* o = unpack_def(val, UPB_DEFTYPE_ONEOF); + if (out_f) *out_f = f; + if (out_o) *out_o = o; + return f || o; /* False if this was a JSON name. */ } -const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m, - const char *name, size_t len) { +const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { upb_value val; - const upb_fielddef* f; + const upb_FieldDef* f; if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { return NULL; @@ -5033,293 +5856,463 @@ const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m, return f; } -int upb_msgdef_numfields(const upb_msgdef *m) { +int upb_MessageDef_numfields(const upb_MessageDef* m) { return m->field_count; } + +int upb_MessageDef_numoneofs(const upb_MessageDef* m) { return m->oneof_count; } + +int upb_MessageDef_numrealoneofs(const upb_MessageDef* m) { + return m->real_oneof_count; +} + +int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { + return m->ext_range_count; +} + +int upb_MessageDef_FieldCount(const upb_MessageDef* m) { return m->field_count; } -int upb_msgdef_numoneofs(const upb_msgdef *m) { +int upb_MessageDef_OneofCount(const upb_MessageDef* m) { return m->oneof_count; } -int upb_msgdef_numrealoneofs(const upb_msgdef *m) { - return m->real_oneof_count; +int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { + return m->nested_msg_count; } -int upb_msgdef_fieldcount(const upb_msgdef *m) { - return m->field_count; +int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { + return m->nested_enum_count; } -int upb_msgdef_oneofcount(const upb_msgdef *m) { - return m->oneof_count; +int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { + return m->nested_ext_count; } -int upb_msgdef_realoneofcount(const upb_msgdef *m) { +int upb_MessageDef_realoneofcount(const upb_MessageDef* m) { return m->real_oneof_count; } -const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m) { +const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { return m->layout; } -const upb_fielddef *upb_msgdef_field(const upb_msgdef *m, int i) { - UPB_ASSERT(i >= 0 && i < m->field_count); +const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->ext_range_count); + return &m->ext_ranges[i]; +} + +const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->field_count); return &m->fields[i]; } -const upb_oneofdef *upb_msgdef_oneof(const upb_msgdef *m, int i) { - UPB_ASSERT(i >= 0 && i < m->oneof_count); +const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->oneof_count); return &m->oneofs[i]; } -bool upb_msgdef_mapentry(const upb_msgdef *m) { - return m->map_entry; +const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_msg_count); + return &m->nested_msgs[i]; } -upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m) { - return m->well_known_type; +const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->nested_enum_count); + return &m->nested_enums[i]; +} + +const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_ext_count); + return &m->nested_exts[i]; } -bool upb_msgdef_isnumberwrapper(const upb_msgdef *m) { - upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); - return type >= UPB_WELLKNOWN_DOUBLEVALUE && - type <= UPB_WELLKNOWN_UINT32VALUE; +upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { + return m->well_known_type; } -bool upb_msgdef_iswrapper(const upb_msgdef *m) { - upb_wellknowntype_t type = upb_msgdef_wellknowntype(m); - return type >= UPB_WELLKNOWN_DOUBLEVALUE && - type <= UPB_WELLKNOWN_BOOLVALUE; +/* upb_OneofDef ***************************************************************/ + +const google_protobuf_OneofOptions* upb_OneofDef_Options( + const upb_OneofDef* o) { + return o->opts; } -void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { - upb_inttable_begin(iter, &m->itof); +bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { + return o->opts != (void*)opt_default; } -void upb_msg_field_next(upb_msg_field_iter *iter) { upb_inttable_next(iter); } +const char* upb_OneofDef_Name(const upb_OneofDef* o) { + return shortdefname(o->full_name); +} -bool upb_msg_field_done(const upb_msg_field_iter *iter) { - return upb_inttable_done(iter); +const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { + return o->parent; } -upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) { - return (upb_fielddef *)upb_value_getconstptr(upb_inttable_iter_value(iter)); +int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } + +const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { + UPB_ASSERT(i < o->field_count); + return o->fields[i]; } -void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) { - upb_inttable_iter_setdone(iter); +int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } + +uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { + // Compute index in our parent's array. + return o - o->parent->oneofs; } -bool upb_msg_field_iter_isequal(const upb_msg_field_iter * iter1, - const upb_msg_field_iter * iter2) { - return upb_inttable_iter_isequal(iter1, iter2); +bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } + +const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, + const char* name, + size_t length) { + upb_value val; + return upb_strtable_lookup2(&o->ntof, name, length, &val) + ? upb_value_getptr(val) + : NULL; } -void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) { - upb_strtable_begin(iter, &m->ntof); - /* We need to skip past any initial fields. */ - while (!upb_strtable_done(iter) && - !unpack_def(upb_strtable_iter_value(iter), UPB_DEFTYPE_ONEOF)) { - upb_strtable_next(iter); - } +const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, + uint32_t num) { + upb_value val; + return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) + : NULL; } -void upb_msg_oneof_next(upb_msg_oneof_iter *iter) { - /* We need to skip past fields to return only oneofs. */ - do { - upb_strtable_next(iter); - } while (!upb_strtable_done(iter) && - !unpack_def(upb_strtable_iter_value(iter), UPB_DEFTYPE_ONEOF)); +/* upb_FileDef ****************************************************************/ + +const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f) { + return f->opts; } -bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) { - return upb_strtable_done(iter); +bool upb_FileDef_HasOptions(const upb_FileDef* f) { + return f->opts != (void*)opt_default; } -const upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) { - return unpack_def(upb_strtable_iter_value(iter), UPB_DEFTYPE_ONEOF); +const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } + +const char* upb_FileDef_Package(const upb_FileDef* f) { return f->package; } + +upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } + +int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { + return f->top_lvl_msg_count; } -void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) { - upb_strtable_iter_setdone(iter); +int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } + +int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { + return f->public_dep_count; } -bool upb_msg_oneof_iter_isequal(const upb_msg_oneof_iter *iter1, - const upb_msg_oneof_iter *iter2) { - return upb_strtable_iter_isequal(iter1, iter2); +int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { + return f->weak_dep_count; } -/* upb_oneofdef ***************************************************************/ +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { + return f->public_deps; +} -const char *upb_oneofdef_name(const upb_oneofdef *o) { - return shortdefname(o->full_name); +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { + return f->weak_deps; } -const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) { - return o->parent; +int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { + return f->top_lvl_enum_count; } -int upb_oneofdef_fieldcount(const upb_oneofdef *o) { - return o->field_count; +int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { + return f->top_lvl_ext_count; } -const upb_fielddef *upb_oneofdef_field(const upb_oneofdef *o, int i) { - UPB_ASSERT(i < o->field_count); - return o->fields[i]; +int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } + +const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->dep_count); + return f->deps[i]; } -int upb_oneofdef_numfields(const upb_oneofdef *o) { - return o->field_count; +const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->public_deps[i]]; } -uint32_t upb_oneofdef_index(const upb_oneofdef *o) { - return o - o->parent->oneofs; +const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->weak_deps[i]]; } -bool upb_oneofdef_issynthetic(const upb_oneofdef *o) { - return o->synthetic; +const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); + return &f->top_lvl_msgs[i]; } -const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o, - const char *name, size_t length) { - upb_value val; - return upb_strtable_lookup2(&o->ntof, name, length, &val) ? - upb_value_getptr(val) : NULL; +const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); + return &f->top_lvl_enums[i]; } -const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num) { - upb_value val; - return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) - : NULL; +const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); + return &f->top_lvl_exts[i]; } -void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o) { - upb_inttable_begin(iter, &o->itof); +const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->service_count); + return &f->services[i]; } -void upb_oneof_next(upb_oneof_iter *iter) { - upb_inttable_next(iter); +const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } + +/* upb_MethodDef **************************************************************/ + +const google_protobuf_MethodOptions* upb_MethodDef_Options( + const upb_MethodDef* m) { + return m->opts; } -bool upb_oneof_done(upb_oneof_iter *iter) { - return upb_inttable_done(iter); +bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { + return m->opts != (void*)opt_default; } -upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) { - return (upb_fielddef *)upb_value_getconstptr(upb_inttable_iter_value(iter)); +const char* upb_MethodDef_FullName(const upb_MethodDef* m) { + return m->full_name; } -void upb_oneof_iter_setdone(upb_oneof_iter *iter) { - upb_inttable_iter_setdone(iter); +const char* upb_MethodDef_Name(const upb_MethodDef* m) { + return shortdefname(m->full_name); } -/* upb_filedef ****************************************************************/ +const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { + return m->service; +} -const char *upb_filedef_name(const upb_filedef *f) { - return f->name; +const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { + return m->input_type; } -const char *upb_filedef_package(const upb_filedef *f) { - return f->package; +const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { + return m->output_type; } -const char *upb_filedef_phpprefix(const upb_filedef *f) { - return f->phpprefix; +bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { + return m->client_streaming; } -const char *upb_filedef_phpnamespace(const upb_filedef *f) { - return f->phpnamespace; +bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { + return m->server_streaming; } -upb_syntax_t upb_filedef_syntax(const upb_filedef *f) { - return f->syntax; +/* upb_ServiceDef *************************************************************/ + +const google_protobuf_ServiceOptions* upb_ServiceDef_Options( + const upb_ServiceDef* s) { + return s->opts; } -int upb_filedef_msgcount(const upb_filedef *f) { - return f->msg_count; +bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { + return s->opts != (void*)opt_default; } -int upb_filedef_depcount(const upb_filedef *f) { - return f->dep_count; +const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { + return s->full_name; } -int upb_filedef_enumcount(const upb_filedef *f) { - return f->enum_count; +const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { + return shortdefname(s->full_name); } -const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i) { - return i < 0 || i >= f->dep_count ? NULL : f->deps[i]; +int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } + +const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { + return s->file; } -const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i) { - return i < 0 || i >= f->msg_count ? NULL : &f->msgs[i]; +int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { + return s->method_count; } -const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i) { - return i < 0 || i >= f->enum_count ? NULL : &f->enums[i]; +const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { + return i < 0 || i >= s->method_count ? NULL : &s->methods[i]; } -const upb_symtab *upb_filedef_symtab(const upb_filedef *f) { - return f->symtab; +const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, + const char* name) { + for (int i = 0; i < s->method_count; i++) { + if (strcmp(name, upb_MethodDef_Name(&s->methods[i])) == 0) { + return &s->methods[i]; + } + } + return NULL; } -void upb_symtab_free(upb_symtab *s) { - upb_arena_free(s->arena); +/* upb_DefPool ****************************************************************/ + +void upb_DefPool_Free(upb_DefPool* s) { + upb_Arena_Free(s->arena); upb_gfree(s); } -upb_symtab *upb_symtab_new(void) { - upb_symtab *s = upb_gmalloc(sizeof(*s)); +upb_DefPool* upb_DefPool_New(void) { + upb_DefPool* s = upb_gmalloc(sizeof(*s)); if (!s) { return NULL; } - s->arena = upb_arena_new(); + s->arena = upb_Arena_New(); s->bytes_loaded = 0; if (!upb_strtable_init(&s->syms, 32, s->arena) || - !upb_strtable_init(&s->files, 4, s->arena)) { - upb_arena_free(s->arena); - upb_gfree(s); - s = NULL; + !upb_strtable_init(&s->files, 4, s->arena) || + !upb_inttable_init(&s->exts, s->arena)) { + goto err; } + + s->extreg = upb_ExtensionRegistry_New(s->arena); + if (!s->extreg) goto err; return s; + +err: + upb_Arena_Free(s->arena); + upb_gfree(s); + return NULL; } -const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { +static const void* symtab_lookup(const upb_DefPool* s, const char* sym, + upb_deftype_t type) { upb_value v; - return upb_strtable_lookup(&s->syms, sym, &v) ? - unpack_def(v, UPB_DEFTYPE_MSG) : NULL; + return upb_strtable_lookup(&s->syms, sym, &v) ? unpack_def(v, type) : NULL; } -const upb_msgdef *upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym, - size_t len) { +static const void* symtab_lookup2(const upb_DefPool* s, const char* sym, + size_t size, upb_deftype_t type) { upb_value v; - return upb_strtable_lookup2(&s->syms, sym, len, &v) ? - unpack_def(v, UPB_DEFTYPE_MSG) : NULL; + return upb_strtable_lookup2(&s->syms, sym, size, &v) ? unpack_def(v, type) + : NULL; +} + +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_MSG); } -const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) { +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len) { + return symtab_lookup2(s, sym, len, UPB_DEFTYPE_MSG); +} + +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_ENUM); +} + +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_ENUMVAL); +} + +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name) { upb_value v; - return upb_strtable_lookup(&s->syms, sym, &v) ? - unpack_def(v, UPB_DEFTYPE_ENUM) : NULL; + return upb_strtable_lookup(&s->files, name, &v) + ? unpack_def(v, UPB_DEFTYPE_FILE) + : NULL; } -const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name) { +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len) { upb_value v; - return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) - : NULL; + return upb_strtable_lookup2(&s->files, name, len, &v) + ? unpack_def(v, UPB_DEFTYPE_FILE) + : NULL; } -const upb_filedef *upb_symtab_lookupfile2( - const upb_symtab *s, const char *name, size_t len) { +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { upb_value v; - return upb_strtable_lookup2(&s->files, name, len, &v) ? - upb_value_getconstptr(v) : NULL; + if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; + + switch (deftype(v)) { + case UPB_DEFTYPE_FIELD: + return unpack_def(v, UPB_DEFTYPE_FIELD); + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = unpack_def(v, UPB_DEFTYPE_MSG); + return m->in_message_set ? &m->nested_exts[0] : NULL; + } + default: + break; + } + + return NULL; +} + +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym) { + return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); +} + +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name) { + return symtab_lookup(s, name, UPB_DEFTYPE_SERVICE); } -int upb_symtab_filecount(const upb_symtab *s) { - return (int)upb_strtable_count(&s->files); +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + return symtab_lookup2(s, name, size, UPB_DEFTYPE_SERVICE); +} + +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name) { + upb_value v; + // TODO(haberman): non-extension fields and oneofs. + if (upb_strtable_lookup(&s->syms, name, &v)) { + switch (deftype(v)) { + case UPB_DEFTYPE_EXT: { + const upb_FieldDef* f = unpack_def(v, UPB_DEFTYPE_EXT); + return upb_FieldDef_File(f); + } + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = unpack_def(v, UPB_DEFTYPE_MSG); + return upb_MessageDef_File(m); + } + case UPB_DEFTYPE_ENUM: { + const upb_EnumDef* e = unpack_def(v, UPB_DEFTYPE_ENUM); + return upb_EnumDef_File(e); + } + case UPB_DEFTYPE_ENUMVAL: { + const upb_EnumValueDef* ev = unpack_def(v, UPB_DEFTYPE_ENUMVAL); + return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); + } + case UPB_DEFTYPE_SERVICE: { + const upb_ServiceDef* service = unpack_def(v, UPB_DEFTYPE_SERVICE); + return upb_ServiceDef_File(service); + } + default: + UPB_UNREACHABLE(); + } + } + + const char* last_dot = strrchr(name, '.'); + if (last_dot) { + const upb_MessageDef* parent = + upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); + if (parent) { + const char* shortname = last_dot + 1; + if (upb_MessageDef_FindByNameWithSize(parent, shortname, + strlen(shortname), NULL, NULL)) { + return upb_MessageDef_File(parent); + } + } + } + + return NULL; } /* Code to build defs from descriptor protos. *********************************/ @@ -5329,40 +6322,61 @@ int upb_symtab_filecount(const upb_symtab *s) { * this code is used to directly build defs from Ruby (for example) we do need * to validate important constraints like uniqueness of names and numbers. */ -#define CHK_OOM(x) if (!(x)) { symtab_oomerr(ctx); } +#define CHK_OOM(x) \ + if (!(x)) { \ + symtab_oomerr(ctx); \ + } typedef struct { - upb_symtab *symtab; - upb_filedef *file; /* File we are building. */ - upb_arena *arena; /* Allocate defs here. */ - const upb_msglayout **layouts; /* NULL if we should build layouts. */ - upb_status *status; /* Record errors here. */ - jmp_buf err; /* longjmp() on error. */ + upb_DefPool* symtab; + upb_FileDef* file; /* File we are building. */ + upb_Arena* arena; /* Allocate defs here. */ + upb_Arena* tmp_arena; /* For temporary allocations. */ + const upb_MiniTable_File* layout; /* NULL if we should build layouts. */ + int enum_count; /* Count of enums built so far. */ + int msg_count; /* Count of messages built so far. */ + int ext_count; /* Count of extensions built so far. */ + upb_Status* status; /* Record errors here. */ + jmp_buf err; /* longjmp() on error. */ } symtab_addctx; -UPB_NORETURN UPB_NOINLINE UPB_PRINTF(2, 3) -static void symtab_errf(symtab_addctx *ctx, const char *fmt, ...) { +UPB_NORETURN UPB_NOINLINE UPB_PRINTF(2, 3) static void symtab_errf( + symtab_addctx* ctx, const char* fmt, ...) { va_list argp; va_start(argp, fmt); - upb_status_vseterrf(ctx->status, fmt, argp); + upb_Status_VSetErrorFormat(ctx->status, fmt, argp); va_end(argp); UPB_LONGJMP(ctx->err, 1); } -UPB_NORETURN UPB_NOINLINE -static void symtab_oomerr(symtab_addctx *ctx) { - upb_status_setoom(ctx->status); +UPB_NORETURN UPB_NOINLINE static void symtab_oomerr(symtab_addctx* ctx) { + upb_Status_setoom(ctx->status); UPB_LONGJMP(ctx->err, 1); } -void *symtab_alloc(symtab_addctx *ctx, size_t bytes) { - void *ret = upb_arena_malloc(ctx->arena, bytes); +void* symtab_alloc(symtab_addctx* ctx, size_t bytes) { + if (bytes == 0) return NULL; + void* ret = upb_Arena_Malloc(ctx->arena, bytes); if (!ret) symtab_oomerr(ctx); return ret; } -static void check_ident(symtab_addctx *ctx, upb_strview name, bool full) { - const char *str = name.data; +// We want to copy the options verbatim into the destination options proto. +// We use serialize+parse as our deep copy. +#define SET_OPTIONS(target, desc_type, options_type, proto) \ + if (google_protobuf_##desc_type##_has_options(proto)) { \ + size_t size; \ + char* pb = google_protobuf_##options_type##_serialize( \ + google_protobuf_##desc_type##_options(proto), ctx->tmp_arena, &size); \ + CHK_OOM(pb); \ + target = google_protobuf_##options_type##_parse(pb, size, ctx->arena); \ + CHK_OOM(target); \ + } else { \ + target = (const google_protobuf_##options_type*)opt_default; \ + } + +static void check_ident(symtab_addctx* ctx, upb_StringView name, bool full) { + const char* str = name.data; size_t len = name.size; bool start = true; size_t i; @@ -5393,158 +6407,218 @@ static void check_ident(symtab_addctx *ctx, upb_strview name, bool full) { } } -static size_t div_round_up(size_t n, size_t d) { - return (n + d - 1) / d; -} +static size_t div_round_up(size_t n, size_t d) { return (n + d - 1) / d; } -static size_t upb_msgval_sizeof(upb_fieldtype_t type) { +static size_t upb_MessageValue_sizeof(upb_CType type) { switch (type) { - case UPB_TYPE_DOUBLE: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT64: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: return 8; - case UPB_TYPE_ENUM: - case UPB_TYPE_INT32: - case UPB_TYPE_UINT32: - case UPB_TYPE_FLOAT: + case kUpb_CType_Enum: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Float: return 4; - case UPB_TYPE_BOOL: + case kUpb_CType_Bool: return 1; - case UPB_TYPE_MESSAGE: + case kUpb_CType_Message: return sizeof(void*); - case UPB_TYPE_BYTES: - case UPB_TYPE_STRING: - return sizeof(upb_strview); + case kUpb_CType_Bytes: + case kUpb_CType_String: + return sizeof(upb_StringView); } UPB_UNREACHABLE(); } -static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) { - if (upb_msgdef_mapentry(upb_fielddef_containingtype(f))) { - upb_map_entry ent; +static uint8_t upb_msg_fielddefsize(const upb_FieldDef* f) { + if (upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f))) { + upb_MapEntry ent; UPB_ASSERT(sizeof(ent.k) == sizeof(ent.v)); return sizeof(ent.k); - } else if (upb_fielddef_isseq(f)) { + } else if (upb_FieldDef_IsRepeated(f)) { return sizeof(void*); } else { - return upb_msgval_sizeof(upb_fielddef_type(f)); + return upb_MessageValue_sizeof(upb_FieldDef_CType(f)); } } -static uint32_t upb_msglayout_place(upb_msglayout *l, size_t size) { - uint32_t ret; +static uint32_t upb_MiniTable_place(symtab_addctx* ctx, upb_MiniTable* l, + size_t size, const upb_MessageDef* m) { + size_t ofs = UPB_ALIGN_UP(l->size, size); + size_t next = ofs + size; - l->size = UPB_ALIGN_UP(l->size, size); - ret = l->size; - l->size += size; - return ret; + if (next > UINT16_MAX) { + symtab_errf(ctx, "size of message %s exceeded max size of %zu bytes", + upb_MessageDef_FullName(m), (size_t)UINT16_MAX); + } + + l->size = next; + return ofs; } -static int field_number_cmp(const void *p1, const void *p2) { - const upb_msglayout_field *f1 = p1; - const upb_msglayout_field *f2 = p2; +static int field_number_cmp(const void* p1, const void* p2) { + const upb_MiniTable_Field* f1 = p1; + const upb_MiniTable_Field* f2 = p2; return f1->number - f2->number; } -static void assign_layout_indices(const upb_msgdef *m, upb_msglayout *l, - upb_msglayout_field *fields) { +static void assign_layout_indices(const upb_MessageDef* m, upb_MiniTable* l, + upb_MiniTable_Field* fields) { int i; - int n = upb_msgdef_numfields(m); + int n = upb_MessageDef_numfields(m); int dense_below = 0; for (i = 0; i < n; i++) { - upb_fielddef *f = (upb_fielddef*)upb_msgdef_itof(m, fields[i].number); + upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_FindFieldByNumberWithSize( + m, fields[i].number); UPB_ASSERT(f); f->layout_index = i; if (i < UINT8_MAX && fields[i].number == i + 1 && - (i == 0 || fields[i-1].number == i)) { + (i == 0 || fields[i - 1].number == i)) { dense_below = i + 1; } } l->dense_below = dense_below; } -static void fill_fieldlayout(upb_msglayout_field *field, const upb_fielddef *f) { - field->number = upb_fielddef_number(f); - field->descriptortype = upb_fielddef_descriptortype(f); - - if (field->descriptortype == UPB_DTYPE_STRING && - f->file->syntax == UPB_SYNTAX_PROTO2) { - /* See TableDescriptorType() in upbc/generator.cc for details and - * rationale. */ - field->descriptortype = UPB_DTYPE_BYTES; +static uint8_t map_descriptortype(const upb_FieldDef* f) { + uint8_t type = upb_FieldDef_Type(f); + /* See TableDescriptorType() in upbc/generator.cc for details and + * rationale of these exceptions. */ + if (type == kUpb_FieldType_String && f->file->syntax == kUpb_Syntax_Proto2) { + return kUpb_FieldType_Bytes; + } else if (type == kUpb_FieldType_Enum && + f->sub.enumdef->file->syntax == kUpb_Syntax_Proto3) { + return kUpb_FieldType_Int32; } + return type; +} - if (upb_fielddef_ismap(f)) { - field->mode = _UPB_MODE_MAP; - } else if (upb_fielddef_isseq(f)) { - field->mode = _UPB_MODE_ARRAY; - } else { - field->mode = _UPB_MODE_SCALAR; - } +static void fill_fieldlayout(upb_MiniTable_Field* field, + const upb_FieldDef* f) { + field->number = upb_FieldDef_Number(f); + field->descriptortype = map_descriptortype(f); - if (upb_fielddef_packed(f)) { - field->mode |= _UPB_MODE_IS_PACKED; + if (upb_FieldDef_IsMap(f)) { + field->mode = + kUpb_FieldMode_Map | (upb_FieldRep_Pointer << upb_FieldRep_Shift); + } else if (upb_FieldDef_IsRepeated(f)) { + field->mode = + kUpb_FieldMode_Array | (upb_FieldRep_Pointer << upb_FieldRep_Shift); + } else { + /* Maps descriptor type -> elem_size_lg2. */ + static const uint8_t sizes[] = { + -1, /* invalid descriptor type */ + upb_FieldRep_8Byte, /* DOUBLE */ + upb_FieldRep_4Byte, /* FLOAT */ + upb_FieldRep_8Byte, /* INT64 */ + upb_FieldRep_8Byte, /* UINT64 */ + upb_FieldRep_4Byte, /* INT32 */ + upb_FieldRep_8Byte, /* FIXED64 */ + upb_FieldRep_4Byte, /* FIXED32 */ + upb_FieldRep_1Byte, /* BOOL */ + upb_FieldRep_StringView, /* STRING */ + upb_FieldRep_Pointer, /* GROUP */ + upb_FieldRep_Pointer, /* MESSAGE */ + upb_FieldRep_StringView, /* BYTES */ + upb_FieldRep_4Byte, /* UINT32 */ + upb_FieldRep_4Byte, /* ENUM */ + upb_FieldRep_4Byte, /* SFIXED32 */ + upb_FieldRep_8Byte, /* SFIXED64 */ + upb_FieldRep_4Byte, /* SINT32 */ + upb_FieldRep_8Byte, /* SINT64 */ + }; + field->mode = kUpb_FieldMode_Scalar | + (sizes[field->descriptortype] << upb_FieldRep_Shift); + } + + if (upb_FieldDef_IsPacked(f)) { + field->mode |= upb_LabelFlags_IsPacked; + } + + if (upb_FieldDef_IsExtension(f)) { + field->mode |= upb_LabelFlags_IsExtension; } } /* This function is the dynamic equivalent of message_layout.{cc,h} in upbc. * It computes a dynamic layout for all of the fields in |m|. */ -static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { - upb_msglayout *l = (upb_msglayout*)m->layout; - upb_msg_field_iter it; - upb_msg_oneof_iter oit; - size_t hasbit; - size_t field_count = upb_msgdef_numfields(m); - size_t submsg_count = 0; - const upb_msglayout **submsgs; - upb_msglayout_field *fields; - - memset(l, 0, sizeof(*l) + sizeof(_upb_fasttable_entry)); +static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) { + upb_MiniTable* l = (upb_MiniTable*)m->layout; + size_t field_count = upb_MessageDef_numfields(m); + size_t sublayout_count = 0; + upb_MiniTable_Sub* subs; + upb_MiniTable_Field* fields; + + memset(l, 0, sizeof(*l) + sizeof(_upb_FastTable_Entry)); /* Count sub-messages. */ for (size_t i = 0; i < field_count; i++) { - if (upb_fielddef_issubmsg(&m->fields[i])) { - submsg_count++; + const upb_FieldDef* f = &m->fields[i]; + if (upb_FieldDef_IsSubMessage(f)) { + sublayout_count++; + } + if (upb_FieldDef_CType(f) == kUpb_CType_Enum && + f->sub.enumdef->file->syntax == kUpb_Syntax_Proto2) { + sublayout_count++; } } fields = symtab_alloc(ctx, field_count * sizeof(*fields)); - submsgs = symtab_alloc(ctx, submsg_count * sizeof(*submsgs)); + subs = symtab_alloc(ctx, sublayout_count * sizeof(*subs)); - l->field_count = upb_msgdef_numfields(m); + l->field_count = upb_MessageDef_numfields(m); l->fields = fields; - l->submsgs = submsgs; + l->subs = subs; l->table_mask = 0; + l->required_count = 0; + + if (upb_MessageDef_ExtensionRangeCount(m) > 0) { + if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { + l->ext = upb_ExtMode_IsMessageSet; + } else { + l->ext = upb_ExtMode_Extendable; + } + } else { + l->ext = upb_ExtMode_NonExtendable; + } /* TODO(haberman): initialize fast tables so that reflection-based parsing * can get the same speeds as linked-in types. */ l->fasttable[0].field_parser = &fastdecode_generic; l->fasttable[0].field_data = 0; - if (upb_msgdef_mapentry(m)) { + if (upb_MessageDef_IsMapEntry(m)) { /* TODO(haberman): refactor this method so this special case is more * elegant. */ - const upb_fielddef *key = upb_msgdef_itof(m, 1); - const upb_fielddef *val = upb_msgdef_itof(m, 2); + const upb_FieldDef* key = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_FieldDef* val = upb_MessageDef_FindFieldByNumberWithSize(m, 2); fields[0].number = 1; fields[1].number = 2; - fields[0].mode = _UPB_MODE_SCALAR; - fields[1].mode = _UPB_MODE_SCALAR; + fields[0].mode = kUpb_FieldMode_Scalar; + fields[1].mode = kUpb_FieldMode_Scalar; fields[0].presence = 0; fields[1].presence = 0; - fields[0].descriptortype = upb_fielddef_descriptortype(key); - fields[1].descriptortype = upb_fielddef_descriptortype(val); + fields[0].descriptortype = map_descriptortype(key); + fields[1].descriptortype = map_descriptortype(val); fields[0].offset = 0; - fields[1].offset = sizeof(upb_strview); + fields[1].offset = sizeof(upb_StringView); fields[1].submsg_index = 0; - if (upb_fielddef_type(val) == UPB_TYPE_MESSAGE) { - submsgs[0] = upb_fielddef_msgsubdef(val)->layout; + if (upb_FieldDef_CType(val) == kUpb_CType_Message) { + subs[0].submsg = upb_FieldDef_MessageSubDef(val)->layout; } + upb_FieldDef* fielddefs = (upb_FieldDef*)&m->fields[0]; + UPB_ASSERT(fielddefs[0].number_ == 1); + UPB_ASSERT(fielddefs[1].number_ == 2); + fielddefs[0].layout_index = 0; + fielddefs[1].layout_index = 1; + l->field_count = 2; - l->size = 2 * sizeof(upb_strview); + l->size = 2 * sizeof(upb_StringView); l->size = UPB_ALIGN_UP(l->size, 8); + l->dense_below = 2; return; } @@ -5557,23 +6631,44 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { * OPT: There is a lot of room for optimization here to minimize the size. */ + /* Assign hasbits for required fields first. */ + size_t hasbit = 0; + + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + upb_MiniTable_Field* field = &fields[upb_FieldDef_Index(f)]; + if (upb_FieldDef_Label(f) == kUpb_Label_Required) { + field->presence = ++hasbit; + if (hasbit >= 63) { + symtab_errf(ctx, "Message with >=63 required fields: %s", + upb_MessageDef_FullName(m)); + } + l->required_count++; + } + } + /* Allocate hasbits and set basic field attributes. */ - submsg_count = 0; - for (upb_msg_field_begin(&it, m), hasbit = 0; - !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - upb_fielddef* f = upb_msg_iter_field(&it); - upb_msglayout_field *field = &fields[upb_fielddef_index(f)]; + sublayout_count = 0; + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + upb_MiniTable_Field* field = &fields[upb_FieldDef_Index(f)]; fill_fieldlayout(field, f); - if (upb_fielddef_issubmsg(f)) { - const upb_msgdef *subm = upb_fielddef_msgsubdef(f); - field->submsg_index = submsg_count++; - submsgs[field->submsg_index] = subm->layout; + if (upb_FieldDef_IsSubMessage(f)) { + field->submsg_index = sublayout_count++; + subs[field->submsg_index].submsg = upb_FieldDef_MessageSubDef(f)->layout; + } else if (upb_FieldDef_CType(f) == kUpb_CType_Enum && + f->file->syntax == kUpb_Syntax_Proto2) { + field->submsg_index = sublayout_count++; + subs[field->submsg_index].subenum = upb_FieldDef_EnumSubDef(f)->layout; + UPB_ASSERT(subs[field->submsg_index].subenum); } - if (upb_fielddef_haspresence(f) && !upb_fielddef_realcontainingoneof(f)) { + if (upb_FieldDef_Label(f) == kUpb_Label_Required) { + /* Hasbit was already assigned. */ + } else if (upb_FieldDef_HasPresence(f) && + !upb_FieldDef_RealContainingOneof(f)) { /* We don't use hasbit 0, so that 0 can indicate "no presence" in the * table. This wastes one hasbit, but we don't worry about it for now. */ field->presence = ++hasbit; @@ -5586,52 +6681,44 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { l->size = div_round_up(hasbit, 8); /* Allocate non-oneof fields. */ - for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* f = upb_msg_iter_field(&it); + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; size_t field_size = upb_msg_fielddefsize(f); - size_t index = upb_fielddef_index(f); + size_t index = upb_FieldDef_Index(f); - if (upb_fielddef_realcontainingoneof(f)) { + if (upb_FieldDef_RealContainingOneof(f)) { /* Oneofs are handled separately below. */ continue; } - fields[index].offset = upb_msglayout_place(l, field_size); + fields[index].offset = upb_MiniTable_place(ctx, l, field_size, m); } /* Allocate oneof fields. Each oneof field consists of a uint32 for the case * and space for the actual data. */ - for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit); - upb_msg_oneof_next(&oit)) { - const upb_oneofdef* o = upb_msg_iter_oneof(&oit); - upb_oneof_iter fit; - - size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ + for (int i = 0; i < m->oneof_count; i++) { + const upb_OneofDef* o = &m->oneofs[i]; + size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ size_t field_size = 0; uint32_t case_offset; uint32_t data_offset; - if (upb_oneofdef_issynthetic(o)) continue; + if (upb_OneofDef_IsSynthetic(o)) continue; /* Calculate field size: the max of all field sizes. */ - for (upb_oneof_begin(&fit, o); - !upb_oneof_done(&fit); - upb_oneof_next(&fit)) { - const upb_fielddef* f = upb_oneof_iter_field(&fit); + for (int j = 0; j < o->field_count; j++) { + const upb_FieldDef* f = o->fields[j]; field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f)); } /* Align and allocate case offset. */ - case_offset = upb_msglayout_place(l, case_size); - data_offset = upb_msglayout_place(l, field_size); + case_offset = upb_MiniTable_place(ctx, l, case_size, m); + data_offset = upb_MiniTable_place(ctx, l, field_size, m); - for (upb_oneof_begin(&fit, o); - !upb_oneof_done(&fit); - upb_oneof_next(&fit)) { - const upb_fielddef* f = upb_oneof_iter_field(&fit); - fields[upb_fielddef_index(f)].offset = data_offset; - fields[upb_fielddef_index(f)].presence = ~case_offset; + for (int i = 0; i < o->field_count; i++) { + const upb_FieldDef* f = o->fields[i]; + fields[upb_FieldDef_Index(f)].offset = data_offset; + fields[upb_FieldDef_Index(f)].presence = ~case_offset; } } @@ -5640,28 +6727,30 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { l->size = UPB_ALIGN_UP(l->size, 8); /* Sort fields by number. */ - qsort(fields, upb_msgdef_numfields(m), sizeof(*fields), field_number_cmp); + qsort(fields, upb_MessageDef_numfields(m), sizeof(*fields), field_number_cmp); assign_layout_indices(m, l, fields); } -static char *strviewdup(symtab_addctx *ctx, upb_strview view) { - return upb_strdup2(view.data, view.size, ctx->arena); +static char* strviewdup(symtab_addctx* ctx, upb_StringView view) { + char* ret = upb_strdup2(view.data, view.size, ctx->arena); + CHK_OOM(ret); + return ret; } -static bool streql2(const char *a, size_t n, const char *b) { +static bool streql2(const char* a, size_t n, const char* b) { return n == strlen(b) && memcmp(a, b, n) == 0; } -static bool streql_view(upb_strview view, const char *b) { +static bool streql_view(upb_StringView view, const char* b) { return streql2(view.data, view.size, b); } -static const char *makefullname(symtab_addctx *ctx, const char *prefix, - upb_strview name) { +static const char* makefullname(symtab_addctx* ctx, const char* prefix, + upb_StringView name) { if (prefix) { /* ret = prefix + '.' + name; */ size_t n = strlen(prefix); - char *ret = symtab_alloc(ctx, n + name.size + 2); + char* ret = symtab_alloc(ctx, n + name.size + 2); strcpy(ret, prefix); ret[n] = '.'; memcpy(&ret[n + 1], name.data, name.size); @@ -5672,33 +6761,33 @@ static const char *makefullname(symtab_addctx *ctx, const char *prefix, } } -static void finalize_oneofs(symtab_addctx *ctx, upb_msgdef *m) { +static void finalize_oneofs(symtab_addctx* ctx, upb_MessageDef* m) { int i; int synthetic_count = 0; - upb_oneofdef *mutable_oneofs = (upb_oneofdef*)m->oneofs; + upb_OneofDef* mutable_oneofs = (upb_OneofDef*)m->oneofs; for (i = 0; i < m->oneof_count; i++) { - upb_oneofdef *o = &mutable_oneofs[i]; + upb_OneofDef* o = &mutable_oneofs[i]; if (o->synthetic && o->field_count != 1) { symtab_errf(ctx, "Synthetic oneofs must have one field, not %d: %s", - o->field_count, upb_oneofdef_name(o)); + o->field_count, upb_OneofDef_Name(o)); } if (o->synthetic) { synthetic_count++; } else if (synthetic_count != 0) { symtab_errf(ctx, "Synthetic oneofs must be after all other oneofs: %s", - upb_oneofdef_name(o)); + upb_OneofDef_Name(o)); } - o->fields = symtab_alloc(ctx, sizeof(upb_fielddef *) * o->field_count); + o->fields = symtab_alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); o->field_count = 0; } for (i = 0; i < m->field_count; i++) { - const upb_fielddef *f = &m->fields[i]; - upb_oneofdef *o = (upb_oneofdef*)f->oneof; + const upb_FieldDef* f = &m->fields[i]; + upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); if (o) { o->fields[o->field_count++] = f; } @@ -5707,14 +6796,16 @@ static void finalize_oneofs(symtab_addctx *ctx, upb_msgdef *m) { m->real_oneof_count = m->oneof_count - synthetic_count; } -size_t getjsonname(const char *name, char *buf, size_t len) { +size_t getjsonname(const char* name, char* buf, size_t len) { size_t src, dst = 0; bool ucase_next = false; -#define WRITE(byte) \ - ++dst; \ - if (dst < len) buf[dst - 1] = byte; \ - else if (dst == len) buf[dst - 1] = '\0' +#define WRITE(byte) \ + ++dst; \ + if (dst < len) \ + buf[dst - 1] = byte; \ + else if (dst == len) \ + buf[dst - 1] = '\0' if (!name) { WRITE('\0'); @@ -5745,14 +6836,19 @@ size_t getjsonname(const char *name, char *buf, size_t len) { #undef WRITE } -static char* makejsonname(symtab_addctx *ctx, const char* name) { +static char* makejsonname(symtab_addctx* ctx, const char* name) { size_t size = getjsonname(name, NULL, 0); char* json_name = symtab_alloc(ctx, size); getjsonname(name, json_name, size); return json_name; } -static void symtab_add(symtab_addctx *ctx, const char *name, upb_value v) { +/* Adds a symbol |v| to the symtab, which must be a def pointer previously + * packed with pack_def(). The def's pointer to upb_FileDef* must be set before + * adding, so we know which entries to remove if building this file fails. */ +static void symtab_add(symtab_addctx* ctx, const char* name, upb_value v) { + // TODO: table should support an operation "tryinsert" to avoid the double + // lookup. if (upb_strtable_lookup(&ctx->symtab->syms, name, NULL)) { symtab_errf(ctx, "duplicate symbol '%s'", name); } @@ -5761,83 +6857,264 @@ static void symtab_add(symtab_addctx *ctx, const char *name, upb_value v) { ctx->symtab->arena)); } +static bool remove_component(char* base, size_t* len) { + if (*len == 0) return false; + + for (size_t i = *len - 1; i > 0; i--) { + if (base[i] == '.') { + *len = i; + return true; + } + } + + *len = 0; + return true; +} + /* Given a symbol and the base symbol inside which it is defined, find the * symbol's definition in t. */ -static const void *symtab_resolve(symtab_addctx *ctx, const upb_fielddef *f, - const char *base, upb_strview sym, - upb_deftype_t type) { - const upb_strtable *t = &ctx->symtab->syms; - if(sym.size == 0) goto notfound; - if(sym.data[0] == '.') { +static const void* symtab_resolveany(symtab_addctx* ctx, + const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t* type) { + const upb_strtable* t = &ctx->symtab->syms; + if (sym.size == 0) goto notfound; + upb_value v; + if (sym.data[0] == '.') { /* Symbols starting with '.' are absolute, so we do a single lookup. * Slice to omit the leading '.' */ - upb_value v; if (!upb_strtable_lookup2(t, sym.data + 1, sym.size - 1, &v)) { goto notfound; } - - const void *ret = unpack_def(v, type); - if (!ret) { - symtab_errf(ctx, "type mismatch when resolving field %s, name %s", - f->full_name, sym.data); - } - return ret; } else { - /* Remove components from base until we find an entry or run out. - * TODO: This branch is totally broken, but currently not used. */ - (void)base; - UPB_ASSERT(false); - goto notfound; + /* Remove components from base until we find an entry or run out. */ + size_t baselen = strlen(base); + char* tmp = malloc(sym.size + strlen(base) + 1); + while (1) { + char* p = tmp; + if (baselen) { + memcpy(p, base, baselen); + p[baselen] = '.'; + p += baselen + 1; + } + memcpy(p, sym.data, sym.size); + p += sym.size; + if (upb_strtable_lookup2(t, tmp, p - tmp, &v)) { + break; + } + if (!remove_component(tmp, &baselen)) { + free(tmp); + goto notfound; + } + } + free(tmp); } + *type = deftype(v); + return unpack_def(v, *type); + notfound: - symtab_errf(ctx, "couldn't resolve name '" UPB_STRVIEW_FORMAT "'", - UPB_STRVIEW_ARGS(sym)); + symtab_errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(sym)); +} + +static const void* symtab_resolve(symtab_addctx* ctx, const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t type) { + upb_deftype_t found_type; + const void* ret = + symtab_resolveany(ctx, from_name_dbg, base, sym, &found_type); + if (ret && found_type != type) { + symtab_errf( + ctx, + "type mismatch when resolving %s: couldn't find name %s with type=%d", + from_name_dbg, sym.data, (int)type); + } + return ret; } static void create_oneofdef( - symtab_addctx *ctx, upb_msgdef *m, - const google_protobuf_OneofDescriptorProto *oneof_proto) { - upb_oneofdef *o; - upb_strview name = google_protobuf_OneofDescriptorProto_name(oneof_proto); + symtab_addctx* ctx, upb_MessageDef* m, + const google_protobuf_OneofDescriptorProto* oneof_proto, + const upb_OneofDef* _o) { + upb_OneofDef* o = (upb_OneofDef*)_o; + upb_StringView name = google_protobuf_OneofDescriptorProto_name(oneof_proto); upb_value v; - o = (upb_oneofdef*)&m->oneofs[m->oneof_count++]; o->parent = m; o->full_name = makefullname(ctx, m->full_name, name); o->field_count = 0; o->synthetic = false; + SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + v = pack_def(o, UPB_DEFTYPE_ONEOF); - symtab_add(ctx, o->full_name, v); CHK_OOM(upb_strtable_insert(&m->ntof, name.data, name.size, v, ctx->arena)); CHK_OOM(upb_inttable_init(&o->itof, ctx->arena)); CHK_OOM(upb_strtable_init(&o->ntof, 4, ctx->arena)); } -static str_t *newstr(symtab_addctx *ctx, const char *data, size_t len) { - str_t *ret = symtab_alloc(ctx, sizeof(*ret) + len); - if (!ret) return NULL; +static str_t* newstr(symtab_addctx* ctx, const char* data, size_t len) { + str_t* ret = symtab_alloc(ctx, sizeof(*ret) + len); + CHK_OOM(ret); ret->len = len; if (len) memcpy(ret->str, data, len); ret->str[len] = '\0'; return ret; } -static void parse_default(symtab_addctx *ctx, const char *str, size_t len, - upb_fielddef *f) { - char *end; +static bool upb_DefPool_TryGetChar(const char** src, const char* end, + char* ch) { + if (*src == end) return false; + *ch = **src; + *src += 1; + return true; +} + +static char upb_DefPool_TryGetHexDigit(symtab_addctx* ctx, + const upb_FieldDef* f, const char** src, + const char* end) { + char ch; + if (!upb_DefPool_TryGetChar(src, end, &ch)) return -1; + if ('0' <= ch && ch <= '9') { + return ch - '0'; + } + ch = upb_ascii_lower(ch); + if ('a' <= ch && ch <= 'f') { + return ch - 'a' + 0xa; + } + *src -= 1; // Char wasn't actually a hex digit. + return -1; +} + +static char upb_DefPool_ParseHexEscape(symtab_addctx* ctx, + const upb_FieldDef* f, const char** src, + const char* end) { + char hex_digit = upb_DefPool_TryGetHexDigit(ctx, f, src, end); + if (hex_digit < 0) { + symtab_errf(ctx, + "\\x cannot be followed by non-hex digit in field '%s' default", + upb_FieldDef_FullName(f)); + return 0; + } + unsigned int ret = hex_digit; + while ((hex_digit = upb_DefPool_TryGetHexDigit(ctx, f, src, end)) >= 0) { + ret = (ret << 4) | hex_digit; + } + if (ret > 0xff) { + symtab_errf(ctx, "Value of hex escape in field %s exceeds 8 bits", + upb_FieldDef_FullName(f)); + return 0; + } + return ret; +} + +char upb_DefPool_TryGetOctalDigit(const char** src, const char* end) { + char ch; + if (!upb_DefPool_TryGetChar(src, end, &ch)) return -1; + if ('0' <= ch && ch <= '7') { + return ch - '0'; + } + *src -= 1; // Char wasn't actually an octal digit. + return -1; +} + +static char upb_DefPool_ParseOctalEscape(symtab_addctx* ctx, + const upb_FieldDef* f, + const char** src, const char* end) { + char ch = 0; + for (int i = 0; i < 3; i++) { + char digit; + if ((digit = upb_DefPool_TryGetOctalDigit(src, end)) >= 0) { + ch = (ch << 3) | digit; + } + } + return ch; +} + +static char upb_DefPool_ParseEscape(symtab_addctx* ctx, const upb_FieldDef* f, + const char** src, const char* end) { + char ch; + if (!upb_DefPool_TryGetChar(src, end, &ch)) { + symtab_errf(ctx, "unterminated escape sequence in field %s", + upb_FieldDef_FullName(f)); + return 0; + } + switch (ch) { + case 'a': + return '\a'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + case 'v': + return '\v'; + case '\\': + return '\\'; + case '\'': + return '\''; + case '\"': + return '\"'; + case '?': + return '\?'; + case 'x': + case 'X': + return upb_DefPool_ParseHexEscape(ctx, f, src, end); + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + *src -= 1; + return upb_DefPool_ParseOctalEscape(ctx, f, src, end); + } + symtab_errf(ctx, "Unknown escape sequence: \\%c", ch); +} + +static str_t* unescape(symtab_addctx* ctx, const upb_FieldDef* f, + const char* data, size_t len) { + // Size here is an upper bound; escape sequences could ultimately shrink it. + str_t* ret = symtab_alloc(ctx, sizeof(*ret) + len); + char* dst = &ret->str[0]; + const char* src = data; + const char* end = data + len; + + while (src < end) { + if (*src == '\\') { + src++; + *dst++ = upb_DefPool_ParseEscape(ctx, f, &src, end); + } else { + *dst++ = *src++; + } + } + + ret->len = dst - &ret->str[0]; + return ret; +} + +static void parse_default(symtab_addctx* ctx, const char* str, size_t len, + upb_FieldDef* f) { + char* end; char nullz[64]; errno = 0; - switch (upb_fielddef_type(f)) { - case UPB_TYPE_INT32: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT32: - case UPB_TYPE_UINT64: - case UPB_TYPE_DOUBLE: - case UPB_TYPE_FLOAT: + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: + case kUpb_CType_Int64: + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: + case kUpb_CType_Double: + case kUpb_CType_Float: /* Standard C number parsing functions expect null-terminated strings. */ if (len >= sizeof(nullz) - 1) { symtab_errf(ctx, "Default too long: %.*s", (int)len, str); @@ -5850,8 +7127,8 @@ static void parse_default(symtab_addctx *ctx, const char *str, size_t len, break; } - switch (upb_fielddef_type(f)) { - case UPB_TYPE_INT32: { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: { long val = strtol(str, &end, 0); if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) { goto invalid; @@ -5859,16 +7136,17 @@ static void parse_default(symtab_addctx *ctx, const char *str, size_t len, f->defaultval.sint = val; break; } - case UPB_TYPE_ENUM: { - const upb_enumdef *e = f->sub.enumdef; - int32_t val; - if (!upb_enumdef_ntoi(e, str, len, &val)) { + case kUpb_CType_Enum: { + const upb_EnumDef* e = f->sub.enumdef; + const upb_EnumValueDef* ev = + upb_EnumDef_FindValueByNameWithSize(e, str, len); + if (!ev) { goto invalid; } - f->defaultval.sint = val; + f->defaultval.sint = ev->number; break; } - case UPB_TYPE_INT64: { + case kUpb_CType_Int64: { long long val = strtoll(str, &end, 0); if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) { goto invalid; @@ -5876,7 +7154,7 @@ static void parse_default(symtab_addctx *ctx, const char *str, size_t len, f->defaultval.sint = val; break; } - case UPB_TYPE_UINT32: { + case kUpb_CType_UInt32: { unsigned long val = strtoul(str, &end, 0); if (val > UINT32_MAX || errno == ERANGE || *end) { goto invalid; @@ -5884,7 +7162,7 @@ static void parse_default(symtab_addctx *ctx, const char *str, size_t len, f->defaultval.uint = val; break; } - case UPB_TYPE_UINT64: { + case kUpb_CType_UInt64: { unsigned long long val = strtoull(str, &end, 0); if (val > UINT64_MAX || errno == ERANGE || *end) { goto invalid; @@ -5892,7 +7170,7 @@ static void parse_default(symtab_addctx *ctx, const char *str, size_t len, f->defaultval.uint = val; break; } - case UPB_TYPE_DOUBLE: { + case kUpb_CType_Double: { double val = strtod(str, &end); if (errno == ERANGE || *end) { goto invalid; @@ -5900,7 +7178,7 @@ static void parse_default(symtab_addctx *ctx, const char *str, size_t len, f->defaultval.dbl = val; break; } - case UPB_TYPE_FLOAT: { + case kUpb_CType_Float: { float val = strtof(str, &end); if (errno == ERANGE || *end) { goto invalid; @@ -5908,75 +7186,78 @@ static void parse_default(symtab_addctx *ctx, const char *str, size_t len, f->defaultval.flt = val; break; } - case UPB_TYPE_BOOL: { + case kUpb_CType_Bool: { if (streql2(str, len, "false")) { f->defaultval.boolean = false; } else if (streql2(str, len, "true")) { f->defaultval.boolean = true; } else { + goto invalid; } break; } - case UPB_TYPE_STRING: + case kUpb_CType_String: f->defaultval.str = newstr(ctx, str, len); break; - case UPB_TYPE_BYTES: - /* XXX: need to interpret the C-escaped value. */ - f->defaultval.str = newstr(ctx, str, len); + case kUpb_CType_Bytes: + f->defaultval.str = unescape(ctx, f, str, len); break; - case UPB_TYPE_MESSAGE: + case kUpb_CType_Message: /* Should not have a default value. */ symtab_errf(ctx, "Message should not have a default (%s)", - upb_fielddef_fullname(f)); + upb_FieldDef_FullName(f)); } return; invalid: - symtab_errf(ctx, "Invalid default '%.*s' for field %s", (int)len, str, - upb_fielddef_fullname(f)); + symtab_errf(ctx, "Invalid default '%.*s' for field %s of type %d", (int)len, + str, upb_FieldDef_FullName(f), (int)upb_FieldDef_Type(f)); } -static void set_default_default(symtab_addctx *ctx, upb_fielddef *f) { - switch (upb_fielddef_type(f)) { - case UPB_TYPE_INT32: - case UPB_TYPE_INT64: - case UPB_TYPE_ENUM: +static void set_default_default(symtab_addctx* ctx, upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: + case kUpb_CType_Int64: f->defaultval.sint = 0; break; - case UPB_TYPE_UINT64: - case UPB_TYPE_UINT32: + case kUpb_CType_UInt64: + case kUpb_CType_UInt32: f->defaultval.uint = 0; break; - case UPB_TYPE_DOUBLE: - case UPB_TYPE_FLOAT: + case kUpb_CType_Double: + case kUpb_CType_Float: f->defaultval.dbl = 0; break; - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: + case kUpb_CType_String: + case kUpb_CType_Bytes: f->defaultval.str = newstr(ctx, NULL, 0); break; - case UPB_TYPE_BOOL: + case kUpb_CType_Bool: f->defaultval.boolean = false; break; - case UPB_TYPE_MESSAGE: + case kUpb_CType_Enum: + f->defaultval.sint = f->sub.enumdef->values[0].number; + case kUpb_CType_Message: break; } } static void create_fielddef( - symtab_addctx *ctx, const char *prefix, upb_msgdef *m, - const google_protobuf_FieldDescriptorProto *field_proto) { - upb_fielddef *f; - const google_protobuf_FieldOptions *options; - upb_strview name; - const char *full_name; - const char *json_name; - const char *shortname; - uint32_t field_number; + symtab_addctx* ctx, const char* prefix, upb_MessageDef* m, + const google_protobuf_FieldDescriptorProto* field_proto, + const upb_FieldDef* _f, bool is_extension) { + upb_FieldDef* f = (upb_FieldDef*)_f; + upb_StringView name; + const char* full_name; + const char* json_name; + const char* shortname; + int32_t field_number; + + f->file = ctx->file; /* Must happen prior to symtab_add(). */ if (!google_protobuf_FieldDescriptorProto_has_name(field_proto)) { - symtab_errf(ctx, "field has no name (%s)", upb_msgdef_fullname(m)); + symtab_errf(ctx, "field has no name (%s)", upb_MessageDef_FullName(m)); } name = google_protobuf_FieldDescriptorProto_name(field_proto); @@ -5987,57 +7268,94 @@ static void create_fielddef( if (google_protobuf_FieldDescriptorProto_has_json_name(field_proto)) { json_name = strviewdup( ctx, google_protobuf_FieldDescriptorProto_json_name(field_proto)); + f->has_json_name_ = true; } else { json_name = makejsonname(ctx, shortname); + f->has_json_name_ = false; } field_number = google_protobuf_FieldDescriptorProto_number(field_proto); - if (field_number == 0 || field_number > UPB_MAX_FIELDNUMBER) { - symtab_errf(ctx, "invalid field number (%u)", field_number); - } + f->full_name = full_name; + f->json_name = json_name; + f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto); + f->number_ = field_number; + f->scope.oneof = NULL; + f->proto3_optional_ = + google_protobuf_FieldDescriptorProto_proto3_optional(field_proto); - if (m) { - /* direct message field. */ - upb_value v, field_v, json_v; - size_t json_size; + bool has_type = google_protobuf_FieldDescriptorProto_has_type(field_proto); + bool has_type_name = + google_protobuf_FieldDescriptorProto_has_type_name(field_proto); - f = (upb_fielddef*)&m->fields[m->field_count]; - f->index_ = m->field_count++; - f->msgdef = m; - f->is_extension_ = false; + f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto); - if (upb_strtable_lookup(&m->ntof, shortname, NULL)) { - symtab_errf(ctx, "duplicate field name (%s)", shortname); + if (has_type) { + switch (f->type_) { + case kUpb_FieldType_Message: + case kUpb_FieldType_Group: + case kUpb_FieldType_Enum: + if (!has_type_name) { + symtab_errf(ctx, "field of type %d requires type name (%s)", + (int)f->type_, full_name); + } + break; + default: + if (has_type_name) { + symtab_errf(ctx, "invalid type for field with type_name set (%s, %d)", + full_name, (int)f->type_); + } } + } else if (has_type_name) { + f->type_ = + FIELD_TYPE_UNSPECIFIED; // We'll fill this in in resolve_fielddef(). + } - if (upb_strtable_lookup(&m->ntof, json_name, NULL)) { - symtab_errf(ctx, "duplicate json_name (%s)", json_name); - } + if (!is_extension) { + /* direct message field. */ + upb_value v, field_v, json_v, existing_v; + size_t json_size; - if (upb_inttable_lookup(&m->itof, field_number, NULL)) { - symtab_errf(ctx, "duplicate field number (%u)", field_number); + if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { + symtab_errf(ctx, "invalid field number (%u)", field_number); } + f->index_ = f - m->fields; + f->msgdef = m; + f->is_extension_ = false; + field_v = pack_def(f, UPB_DEFTYPE_FIELD); json_v = pack_def(f, UPB_DEFTYPE_FIELD_JSONNAME); v = upb_value_constptr(f); json_size = strlen(json_name); + if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { + symtab_errf(ctx, "duplicate field name (%s)", shortname); + } + CHK_OOM(upb_strtable_insert(&m->ntof, name.data, name.size, field_v, ctx->arena)); - CHK_OOM(upb_inttable_insert(&m->itof, field_number, v, ctx->arena)); if (strcmp(shortname, json_name) != 0) { - upb_strtable_insert(&m->ntof, json_name, json_size, json_v, ctx->arena); + if (upb_strtable_lookup(&m->ntof, json_name, &v)) { + symtab_errf(ctx, "duplicate json_name (%s)", json_name); + } else { + CHK_OOM(upb_strtable_insert(&m->ntof, json_name, json_size, json_v, + ctx->arena)); + } } - if (ctx->layouts) { - const upb_msglayout_field *fields = m->layout->fields; + if (upb_inttable_lookup(&m->itof, field_number, NULL)) { + symtab_errf(ctx, "duplicate field number (%u)", field_number); + } + + CHK_OOM(upb_inttable_insert(&m->itof, field_number, v, ctx->arena)); + + if (ctx->layout) { + const upb_MiniTable_Field* fields = m->layout->fields; int count = m->layout->field_count; bool found = false; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (fields[i].number == field_number) { f->layout_index = i; found = true; @@ -6048,37 +7366,42 @@ static void create_fielddef( } } else { /* extension field. */ - f = (upb_fielddef*)&ctx->file->exts[ctx->file->ext_count++]; f->is_extension_ = true; - symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_FIELD)); + f->scope.extension_scope = m; + symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_EXT)); + f->layout_index = ctx->ext_count++; + if (ctx->layout) { + UPB_ASSERT(ctx->file->ext_layouts[f->layout_index]->field.number == + field_number); + } + } + + if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { + symtab_errf(ctx, "invalid type for field %s (%d)", f->full_name, f->type_); + } + + if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { + symtab_errf(ctx, "invalid label for field %s (%d)", f->full_name, + f->label_); } - f->full_name = full_name; - f->json_name = json_name; - f->file = ctx->file; - f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto); - f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto); - f->number_ = field_number; - f->oneof = NULL; - f->proto3_optional_ = - google_protobuf_FieldDescriptorProto_proto3_optional(field_proto); - /* We can't resolve the subdef or (in the case of extensions) the containing * message yet, because it may not have been defined yet. We stash a pointer * to the field_proto until later when we can properly resolve it. */ f->sub.unresolved = field_proto; - if (f->label_ == UPB_LABEL_REQUIRED && f->file->syntax == UPB_SYNTAX_PROTO3) { + if (f->label_ == kUpb_Label_Required && + f->file->syntax == kUpb_Syntax_Proto3) { symtab_errf(ctx, "proto3 fields cannot be required (%s)", f->full_name); } if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { int oneof_index = google_protobuf_FieldDescriptorProto_oneof_index(field_proto); - upb_oneofdef *oneof; + upb_OneofDef* oneof; upb_value v = upb_value_constptr(f); - if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) { + if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { symtab_errf(ctx, "fields in oneof must have OPTIONAL label (%s)", f->full_name); } @@ -6092,8 +7415,8 @@ static void create_fielddef( symtab_errf(ctx, "oneof_index out of range (%s)", f->full_name); } - oneof = (upb_oneofdef *)&m->oneofs[oneof_index]; - f->oneof = oneof; + oneof = (upb_OneofDef*)&m->oneofs[oneof_index]; + f->scope.oneof = oneof; oneof->field_count++; if (f->proto3_optional_) { @@ -6103,43 +7426,166 @@ static void create_fielddef( CHK_OOM( upb_strtable_insert(&oneof->ntof, name.data, name.size, v, ctx->arena)); } else { - f->oneof = NULL; if (f->proto3_optional_) { symtab_errf(ctx, "field with proto3_optional was not in a oneof (%s)", f->full_name); } } - options = google_protobuf_FieldDescriptorProto_has_options(field_proto) ? - google_protobuf_FieldDescriptorProto_options(field_proto) : NULL; + SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); - if (options && google_protobuf_FieldOptions_has_packed(options)) { - f->packed_ = google_protobuf_FieldOptions_packed(options); + if (google_protobuf_FieldOptions_has_packed(f->opts)) { + f->packed_ = google_protobuf_FieldOptions_packed(f->opts); } else { /* Repeated fields default to packed for proto3 only. */ - f->packed_ = upb_fielddef_isprimitive(f) && - f->label_ == UPB_LABEL_REPEATED && f->file->syntax == UPB_SYNTAX_PROTO3; + f->packed_ = upb_FieldDef_IsPrimitive(f) && + f->label_ == kUpb_Label_Repeated && + f->file->syntax == kUpb_Syntax_Proto3; } +} - if (options) { - f->lazy_ = google_protobuf_FieldOptions_lazy(options); - } else { - f->lazy_ = false; +static void create_service( + symtab_addctx* ctx, const google_protobuf_ServiceDescriptorProto* svc_proto, + const upb_ServiceDef* _s) { + upb_ServiceDef* s = (upb_ServiceDef*)_s; + upb_StringView name; + const google_protobuf_MethodDescriptorProto* const* methods; + size_t i, n; + + s->file = ctx->file; /* Must happen prior to symtab_add. */ + + name = google_protobuf_ServiceDescriptorProto_name(svc_proto); + check_ident(ctx, name, false); + s->full_name = makefullname(ctx, ctx->file->package, name); + symtab_add(ctx, s->full_name, pack_def(s, UPB_DEFTYPE_SERVICE)); + + methods = google_protobuf_ServiceDescriptorProto_method(svc_proto, &n); + + s->method_count = n; + s->methods = symtab_alloc(ctx, sizeof(*s->methods) * n); + + SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, svc_proto); + + for (i = 0; i < n; i++) { + const google_protobuf_MethodDescriptorProto* method_proto = methods[i]; + upb_MethodDef* m = (upb_MethodDef*)&s->methods[i]; + upb_StringView name = + google_protobuf_MethodDescriptorProto_name(method_proto); + + m->service = s; + m->full_name = makefullname(ctx, s->full_name, name); + m->client_streaming = + google_protobuf_MethodDescriptorProto_client_streaming(method_proto); + m->server_streaming = + google_protobuf_MethodDescriptorProto_server_streaming(method_proto); + m->input_type = symtab_resolve( + ctx, m->full_name, m->full_name, + google_protobuf_MethodDescriptorProto_input_type(method_proto), + UPB_DEFTYPE_MSG); + m->output_type = symtab_resolve( + ctx, m->full_name, m->full_name, + google_protobuf_MethodDescriptorProto_output_type(method_proto), + UPB_DEFTYPE_MSG); + + SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, method_proto); + } +} + +static int count_bits_debug(uint64_t x) { + // For assertions only, speed does not matter. + int n = 0; + while (x) { + if (x & 1) n++; + x >>= 1; + } + return n; +} + +upb_MiniTable_Enum* create_enumlayout(symtab_addctx* ctx, + const upb_EnumDef* e) { + int n = 0; + uint64_t mask = 0; + + for (int i = 0; i < e->value_count; i++) { + uint32_t val = (uint32_t)e->values[i].number; + if (val < 64) { + mask |= 1 << val; + } else { + n++; + } + } + + int32_t* values = symtab_alloc(ctx, sizeof(*values) * n); + + if (n) { + int32_t* p = values; + + // Add values outside the bitmask range to the list, as described in the + // comments for upb_MiniTable_Enum. + for (int i = 0; i < e->value_count; i++) { + int32_t val = e->values[i].number; + if ((uint32_t)val >= 64) { + *p++ = val; + } + } + UPB_ASSERT(p == values + n); + } + + UPB_ASSERT(upb_inttable_count(&e->iton) == n + count_bits_debug(mask)); + + upb_MiniTable_Enum* layout = symtab_alloc(ctx, sizeof(*layout)); + layout->value_count = n; + layout->mask = mask; + layout->values = values; + + return layout; +} + +static void create_enumvaldef( + symtab_addctx* ctx, const char* prefix, + const google_protobuf_EnumValueDescriptorProto* val_proto, upb_EnumDef* e, + int i) { + upb_EnumValueDef* val = (upb_EnumValueDef*)&e->values[i]; + upb_StringView name = + google_protobuf_EnumValueDescriptorProto_name(val_proto); + upb_value v = upb_value_constptr(val); + + val->parent = e; /* Must happen prior to symtab_add(). */ + val->full_name = makefullname(ctx, prefix, name); + val->number = google_protobuf_EnumValueDescriptorProto_number(val_proto); + symtab_add(ctx, val->full_name, pack_def(val, UPB_DEFTYPE_ENUMVAL)); + + SET_OPTIONS(val->opts, EnumValueDescriptorProto, EnumValueOptions, val_proto); + + if (i == 0 && e->file->syntax == kUpb_Syntax_Proto3 && val->number != 0) { + symtab_errf(ctx, "for proto3, the first enum value must be zero (%s)", + e->full_name); + } + + CHK_OOM(upb_strtable_insert(&e->ntoi, name.data, name.size, v, ctx->arena)); + + // Multiple enumerators can have the same number, first one wins. + if (!upb_inttable_lookup(&e->iton, val->number, NULL)) { + CHK_OOM(upb_inttable_insert(&e->iton, val->number, v, ctx->arena)); } } static void create_enumdef( - symtab_addctx *ctx, const char *prefix, - const google_protobuf_EnumDescriptorProto *enum_proto) { - upb_enumdef *e; - const google_protobuf_EnumValueDescriptorProto *const *values; - upb_strview name; + symtab_addctx* ctx, const char* prefix, + const google_protobuf_EnumDescriptorProto* enum_proto, + const upb_MessageDef* containing_type, const upb_EnumDef* _e) { + upb_EnumDef* e = (upb_EnumDef*)_e; + ; + const google_protobuf_EnumValueDescriptorProto* const* values; + upb_StringView name; size_t i, n; + e->file = ctx->file; /* Must happen prior to symtab_add() */ + e->containing_type = containing_type; + name = google_protobuf_EnumDescriptorProto_name(enum_proto); check_ident(ctx, name, false); - e = (upb_enumdef*)&ctx->file->enums[ctx->file->enum_count++]; e->full_name = makefullname(ctx, prefix, name); symtab_add(ctx, e->full_name, pack_def(e, UPB_DEFTYPE_ENUM)); @@ -6147,225 +7593,374 @@ static void create_enumdef( CHK_OOM(upb_strtable_init(&e->ntoi, n, ctx->arena)); CHK_OOM(upb_inttable_init(&e->iton, ctx->arena)); - e->file = ctx->file; e->defaultval = 0; + e->value_count = n; + e->values = symtab_alloc(ctx, sizeof(*e->values) * n); if (n == 0) { symtab_errf(ctx, "enums must contain at least one value (%s)", e->full_name); } - for (i = 0; i < n; i++) { - const google_protobuf_EnumValueDescriptorProto *value = values[i]; - upb_strview name = google_protobuf_EnumValueDescriptorProto_name(value); - char *name2 = strviewdup(ctx, name); - int32_t num = google_protobuf_EnumValueDescriptorProto_number(value); - upb_value v = upb_value_int32(num); - - if (i == 0 && e->file->syntax == UPB_SYNTAX_PROTO3 && num != 0) { - symtab_errf(ctx, "for proto3, the first enum value must be zero (%s)", - e->full_name); - } + SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - if (upb_strtable_lookup(&e->ntoi, name2, NULL)) { - symtab_errf(ctx, "duplicate enum label '%s'", name2); - } + for (i = 0; i < n; i++) { + create_enumvaldef(ctx, prefix, values[i], e, i); + } - CHK_OOM(name2) - CHK_OOM(upb_strtable_insert(&e->ntoi, name2, strlen(name2), v, ctx->arena)); + upb_inttable_compact(&e->iton, ctx->arena); - if (!upb_inttable_lookup(&e->iton, num, NULL)) { - upb_value v = upb_value_cstr(name2); - CHK_OOM(upb_inttable_insert(&e->iton, num, v, ctx->arena)); + if (e->file->syntax == kUpb_Syntax_Proto2) { + if (ctx->layout) { + UPB_ASSERT(ctx->enum_count < ctx->layout->enum_count); + e->layout = ctx->layout->enums[ctx->enum_count++]; + UPB_ASSERT(n == + e->layout->value_count + count_bits_debug(e->layout->mask)); + } else { + e->layout = create_enumlayout(ctx, e); } + } else { + e->layout = NULL; } - - upb_inttable_compact(&e->iton, ctx->arena); } -static void create_msgdef(symtab_addctx *ctx, const char *prefix, - const google_protobuf_DescriptorProto *msg_proto) { - upb_msgdef *m; - const google_protobuf_MessageOptions *options; - const google_protobuf_OneofDescriptorProto *const *oneofs; - const google_protobuf_FieldDescriptorProto *const *fields; - const google_protobuf_EnumDescriptorProto *const *enums; - const google_protobuf_DescriptorProto *const *msgs; - size_t i, n_oneof, n_field, n; - upb_strview name; +static void msgdef_create_nested( + symtab_addctx* ctx, const google_protobuf_DescriptorProto* msg_proto, + upb_MessageDef* m); + +static void create_msgdef(symtab_addctx* ctx, const char* prefix, + const google_protobuf_DescriptorProto* msg_proto, + const upb_MessageDef* containing_type, + const upb_MessageDef* _m) { + upb_MessageDef* m = (upb_MessageDef*)_m; + const google_protobuf_OneofDescriptorProto* const* oneofs; + const google_protobuf_FieldDescriptorProto* const* fields; + const google_protobuf_DescriptorProto_ExtensionRange* const* ext_ranges; + size_t i, n_oneof, n_field, n_ext_range; + upb_StringView name; + + m->file = ctx->file; /* Must happen prior to symtab_add(). */ + m->containing_type = containing_type; name = google_protobuf_DescriptorProto_name(msg_proto); check_ident(ctx, name, false); - m = (upb_msgdef*)&ctx->file->msgs[ctx->file->msg_count++]; m->full_name = makefullname(ctx, prefix, name); symtab_add(ctx, m->full_name, pack_def(m, UPB_DEFTYPE_MSG)); oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof); fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field); + ext_ranges = + google_protobuf_DescriptorProto_extension_range(msg_proto, &n_ext_range); CHK_OOM(upb_inttable_init(&m->itof, ctx->arena)); CHK_OOM(upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena)); - m->file = ctx->file; - m->map_entry = false; - - options = google_protobuf_DescriptorProto_options(msg_proto); - - if (options) { - m->map_entry = google_protobuf_MessageOptions_map_entry(options); - } - - if (ctx->layouts) { - m->layout = *ctx->layouts; - ctx->layouts++; + if (ctx->layout) { + /* create_fielddef() below depends on this being set. */ + UPB_ASSERT(ctx->msg_count < ctx->layout->msg_count); + m->layout = ctx->layout->msgs[ctx->msg_count++]; + UPB_ASSERT(n_field == m->layout->field_count); } else { /* Allocate now (to allow cross-linking), populate later. */ - m->layout = symtab_alloc( - ctx, sizeof(*m->layout) + sizeof(_upb_fasttable_entry)); + m->layout = + symtab_alloc(ctx, sizeof(*m->layout) + sizeof(_upb_FastTable_Entry)); } - m->oneof_count = 0; + SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + + m->oneof_count = n_oneof; m->oneofs = symtab_alloc(ctx, sizeof(*m->oneofs) * n_oneof); for (i = 0; i < n_oneof; i++) { - create_oneofdef(ctx, m, oneofs[i]); + create_oneofdef(ctx, m, oneofs[i], &m->oneofs[i]); } - m->field_count = 0; + m->field_count = n_field; m->fields = symtab_alloc(ctx, sizeof(*m->fields) * n_field); for (i = 0; i < n_field; i++) { - create_fielddef(ctx, m->full_name, m, fields[i]); + create_fielddef(ctx, m->full_name, m, fields[i], &m->fields[i], + /* is_extension= */ false); } - finalize_oneofs(ctx, m); - assign_msg_wellknowntype(m); - upb_inttable_compact(&m->itof, ctx->arena); + m->ext_range_count = n_ext_range; + m->ext_ranges = symtab_alloc(ctx, sizeof(*m->ext_ranges) * n_ext_range); + for (i = 0; i < n_ext_range; i++) { + const google_protobuf_DescriptorProto_ExtensionRange* r = ext_ranges[i]; + upb_ExtensionRange* r_def = (upb_ExtensionRange*)&m->ext_ranges[i]; + int32_t start = google_protobuf_DescriptorProto_ExtensionRange_start(r); + int32_t end = google_protobuf_DescriptorProto_ExtensionRange_end(r); + int32_t max = + google_protobuf_MessageOptions_message_set_wire_format(m->opts) + ? INT32_MAX + : kUpb_MaxFieldNumber + 1; - /* This message is built. Now build nested messages and enums. */ + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + if (start < 1 || end <= start || end > max) { + symtab_errf(ctx, "Extension range (%d, %d) is invalid, message=%s\n", + (int)start, (int)end, m->full_name); + } - enums = google_protobuf_DescriptorProto_enum_type(msg_proto, &n); - for (i = 0; i < n; i++) { - create_enumdef(ctx, m->full_name, enums[i]); + r_def->start = start; + r_def->end = end; + SET_OPTIONS(r_def->opts, DescriptorProto_ExtensionRange, + ExtensionRangeOptions, r); } - msgs = google_protobuf_DescriptorProto_nested_type(msg_proto, &n); - for (i = 0; i < n; i++) { - create_msgdef(ctx, m->full_name, msgs[i]); - } + finalize_oneofs(ctx, m); + assign_msg_wellknowntype(m); + upb_inttable_compact(&m->itof, ctx->arena); + msgdef_create_nested(ctx, msg_proto, m); } -static void count_types_in_msg(const google_protobuf_DescriptorProto *msg_proto, - upb_filedef *file) { - const google_protobuf_DescriptorProto *const *msgs; - size_t i, n; - - file->msg_count++; +static void msgdef_create_nested( + symtab_addctx* ctx, const google_protobuf_DescriptorProto* msg_proto, + upb_MessageDef* m) { + size_t n; - msgs = google_protobuf_DescriptorProto_nested_type(msg_proto, &n); - for (i = 0; i < n; i++) { - count_types_in_msg(msgs[i], file); + const google_protobuf_EnumDescriptorProto* const* enums = + google_protobuf_DescriptorProto_enum_type(msg_proto, &n); + m->nested_enum_count = n; + m->nested_enums = symtab_alloc(ctx, sizeof(*m->nested_enums) * n); + for (size_t i = 0; i < n; i++) { + m->nested_enum_count = i + 1; + create_enumdef(ctx, m->full_name, enums[i], m, &m->nested_enums[i]); } - google_protobuf_DescriptorProto_enum_type(msg_proto, &n); - file->enum_count += n; + const google_protobuf_FieldDescriptorProto* const* exts = + google_protobuf_DescriptorProto_extension(msg_proto, &n); + m->nested_ext_count = n; + m->nested_exts = symtab_alloc(ctx, sizeof(*m->nested_exts) * n); + for (size_t i = 0; i < n; i++) { + create_fielddef(ctx, m->full_name, m, exts[i], &m->nested_exts[i], + /* is_extension= */ true); + ((upb_FieldDef*)&m->nested_exts[i])->index_ = i; + } - google_protobuf_DescriptorProto_extension(msg_proto, &n); - file->ext_count += n; + const google_protobuf_DescriptorProto* const* msgs = + google_protobuf_DescriptorProto_nested_type(msg_proto, &n); + m->nested_msg_count = n; + m->nested_msgs = symtab_alloc(ctx, sizeof(*m->nested_msgs) * n); + for (size_t i = 0; i < n; i++) { + create_msgdef(ctx, m->full_name, msgs[i], m, &m->nested_msgs[i]); + } +} + +static void resolve_subdef(symtab_addctx* ctx, const char* prefix, + upb_FieldDef* f) { + const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; + upb_StringView name = + google_protobuf_FieldDescriptorProto_type_name(field_proto); + bool has_name = + google_protobuf_FieldDescriptorProto_has_type_name(field_proto); + switch ((int)f->type_) { + case FIELD_TYPE_UNSPECIFIED: { + // Type was not specified and must be inferred. + UPB_ASSERT(has_name); + upb_deftype_t type; + const void* def = + symtab_resolveany(ctx, f->full_name, prefix, name, &type); + switch (type) { + case UPB_DEFTYPE_ENUM: + f->sub.enumdef = def; + f->type_ = kUpb_FieldType_Enum; + break; + case UPB_DEFTYPE_MSG: + f->sub.msgdef = def; + f->type_ = kUpb_FieldType_Message; // It appears there is no way of + // this being a group. + break; + default: + symtab_errf(ctx, "Couldn't resolve type name for field %s", + f->full_name); + } + } + case kUpb_FieldType_Message: + case kUpb_FieldType_Group: + UPB_ASSERT(has_name); + f->sub.msgdef = + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); + break; + case kUpb_FieldType_Enum: + UPB_ASSERT(has_name); + f->sub.enumdef = + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_ENUM); + break; + default: + // No resolution necessary. + break; + } } -static void count_types_in_file( - const google_protobuf_FileDescriptorProto *file_proto, - upb_filedef *file) { - const google_protobuf_DescriptorProto *const *msgs; - size_t i, n; - - msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); - for (i = 0; i < n; i++) { - count_types_in_msg(msgs[i], file); +static void resolve_extension( + symtab_addctx* ctx, const char* prefix, upb_FieldDef* f, + const google_protobuf_FieldDescriptorProto* field_proto) { + if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) { + symtab_errf(ctx, "extension for field '%s' had no extendee", f->full_name); } - google_protobuf_FileDescriptorProto_enum_type(file_proto, &n); - file->enum_count += n; + upb_StringView name = + google_protobuf_FieldDescriptorProto_extendee(field_proto); + const upb_MessageDef* m = + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); + f->msgdef = m; - google_protobuf_FileDescriptorProto_extension(file_proto, &n); - file->ext_count += n; -} + bool found = false; -static void resolve_fielddef(symtab_addctx *ctx, const char *prefix, - upb_fielddef *f) { - upb_strview name; - const google_protobuf_FieldDescriptorProto *field_proto = f->sub.unresolved; - - if (f->is_extension_) { - if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) { - symtab_errf(ctx, "extension for field '%s' had no extendee", - f->full_name); + for (int i = 0, n = m->ext_range_count; i < n; i++) { + const upb_ExtensionRange* r = &m->ext_ranges[i]; + if (r->start <= f->number_ && f->number_ < r->end) { + found = true; + break; } - - name = google_protobuf_FieldDescriptorProto_extendee(field_proto); - f->msgdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_MSG); } - if ((upb_fielddef_issubmsg(f) || f->type_ == UPB_DESCRIPTOR_TYPE_ENUM) && - !google_protobuf_FieldDescriptorProto_has_type_name(field_proto)) { - symtab_errf(ctx, "field '%s' is missing type name", f->full_name); + if (!found) { + symtab_errf(ctx, + "field number %u in extension %s has no extension range in " + "message %s", + (unsigned)f->number_, f->full_name, f->msgdef->full_name); } - name = google_protobuf_FieldDescriptorProto_type_name(field_proto); - - if (upb_fielddef_issubmsg(f)) { - f->sub.msgdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_MSG); - } else if (f->type_ == UPB_DESCRIPTOR_TYPE_ENUM) { - f->sub.enumdef = symtab_resolve(ctx, f, prefix, name, UPB_DEFTYPE_ENUM); + const upb_MiniTable_Extension* ext = ctx->file->ext_layouts[f->layout_index]; + if (ctx->layout) { + UPB_ASSERT(upb_FieldDef_Number(f) == ext->field.number); + } else { + upb_MiniTable_Extension* mut_ext = (upb_MiniTable_Extension*)ext; + fill_fieldlayout(&mut_ext->field, f); + mut_ext->field.presence = 0; + mut_ext->field.offset = 0; + mut_ext->field.submsg_index = 0; + mut_ext->extendee = f->msgdef->layout; + mut_ext->sub.submsg = f->sub.msgdef->layout; } - /* Have to delay resolving of the default value until now because of the enum - * case, since enum defaults are specified with a label. */ + CHK_OOM(upb_inttable_insert(&ctx->symtab->exts, (uintptr_t)ext, + upb_value_constptr(f), ctx->arena)); +} + +static void resolve_default( + symtab_addctx* ctx, upb_FieldDef* f, + const google_protobuf_FieldDescriptorProto* field_proto) { + // Have to delay resolving of the default value until now because of the enum + // case, since enum defaults are specified with a label. if (google_protobuf_FieldDescriptorProto_has_default_value(field_proto)) { - upb_strview defaultval = + upb_StringView defaultval = google_protobuf_FieldDescriptorProto_default_value(field_proto); - if (f->file->syntax == UPB_SYNTAX_PROTO3) { + if (f->file->syntax == kUpb_Syntax_Proto3) { symtab_errf(ctx, "proto3 fields cannot have explicit defaults (%s)", f->full_name); } - if (upb_fielddef_issubmsg(f)) { + if (upb_FieldDef_IsSubMessage(f)) { symtab_errf(ctx, "message fields cannot have explicit defaults (%s)", f->full_name); } parse_default(ctx, defaultval.data, defaultval.size, f); + f->has_default = true; } else { set_default_default(ctx, f); + f->has_default = false; + } +} + +static void resolve_fielddef(symtab_addctx* ctx, const char* prefix, + upb_FieldDef* f) { + // We have to stash this away since resolve_subdef() may overwrite it. + const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; + + resolve_subdef(ctx, prefix, f); + resolve_default(ctx, f, field_proto); + + if (f->is_extension_) { + resolve_extension(ctx, prefix, f, field_proto); + } +} + +static void resolve_msgdef(symtab_addctx* ctx, upb_MessageDef* m) { + for (int i = 0; i < m->field_count; i++) { + resolve_fielddef(ctx, m->full_name, (upb_FieldDef*)&m->fields[i]); + } + + for (int i = 0; i < m->nested_ext_count; i++) { + resolve_fielddef(ctx, m->full_name, (upb_FieldDef*)&m->nested_exts[i]); + } + + if (!ctx->layout) make_layout(ctx, m); + + m->in_message_set = false; + if (m->nested_ext_count == 1) { + const upb_FieldDef* ext = &m->nested_exts[0]; + if (ext->type_ == kUpb_FieldType_Message && + ext->label_ == kUpb_Label_Optional && ext->sub.msgdef == m && + google_protobuf_MessageOptions_message_set_wire_format( + ext->msgdef->opts)) { + m->in_message_set = true; + } + } + + for (int i = 0; i < m->nested_msg_count; i++) { + resolve_msgdef(ctx, (upb_MessageDef*)&m->nested_msgs[i]); + } +} + +static int count_exts_in_msg(const google_protobuf_DescriptorProto* msg_proto) { + size_t n; + google_protobuf_DescriptorProto_extension(msg_proto, &n); + int ext_count = n; + + const google_protobuf_DescriptorProto* const* nested_msgs = + google_protobuf_DescriptorProto_nested_type(msg_proto, &n); + for (size_t i = 0; i < n; i++) { + ext_count += count_exts_in_msg(nested_msgs[i]); } + + return ext_count; } static void build_filedef( - symtab_addctx *ctx, upb_filedef *file, - const google_protobuf_FileDescriptorProto *file_proto) { - const google_protobuf_FileOptions *file_options_proto; - const google_protobuf_DescriptorProto *const *msgs; - const google_protobuf_EnumDescriptorProto *const *enums; - const google_protobuf_FieldDescriptorProto *const *exts; - const upb_strview* strs; + symtab_addctx* ctx, upb_FileDef* file, + const google_protobuf_FileDescriptorProto* file_proto) { + const google_protobuf_DescriptorProto* const* msgs; + const google_protobuf_EnumDescriptorProto* const* enums; + const google_protobuf_FieldDescriptorProto* const* exts; + const google_protobuf_ServiceDescriptorProto* const* services; + const upb_StringView* strs; + const int32_t* public_deps; + const int32_t* weak_deps; size_t i, n; file->symtab = ctx->symtab; - /* One pass to count and allocate. */ - file->msg_count = 0; - file->enum_count = 0; - file->ext_count = 0; - count_types_in_file(file_proto, file); - file->msgs = symtab_alloc(ctx, sizeof(*file->msgs) * file->msg_count); - file->enums = symtab_alloc(ctx, sizeof(*file->enums) * file->enum_count); - file->exts = symtab_alloc(ctx, sizeof(*file->exts) * file->ext_count); + /* Count all extensions in the file, to build a flat array of layouts. */ + google_protobuf_FileDescriptorProto_extension(file_proto, &n); + int ext_count = n; + msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); + for (int i = 0; i < n; i++) { + ext_count += count_exts_in_msg(msgs[i]); + } + file->ext_count = ext_count; - /* In the second pass we increment these as defs are added. */ - file->msg_count = 0; - file->enum_count = 0; - file->ext_count = 0; + if (ctx->layout) { + /* We are using the ext layouts that were passed in. */ + file->ext_layouts = ctx->layout->exts; + if (ctx->layout->ext_count != file->ext_count) { + symtab_errf(ctx, "Extension count did not match layout (%d vs %d)", + ctx->layout->ext_count, file->ext_count); + } + } else { + /* We are building ext layouts from scratch. */ + file->ext_layouts = + symtab_alloc(ctx, sizeof(*file->ext_layouts) * file->ext_count); + upb_MiniTable_Extension* ext = + symtab_alloc(ctx, sizeof(*ext) * file->ext_count); + for (int i = 0; i < file->ext_count; i++) { + file->ext_layouts[i] = &ext[i]; + } + } if (!google_protobuf_FileDescriptorProto_has_name(file_proto)) { symtab_errf(ctx, "File has no name"); @@ -6373,11 +7968,9 @@ static void build_filedef( file->name = strviewdup(ctx, google_protobuf_FileDescriptorProto_name(file_proto)); - file->phpprefix = NULL; - file->phpnamespace = NULL; if (google_protobuf_FileDescriptorProto_has_package(file_proto)) { - upb_strview package = + upb_StringView package = google_protobuf_FileDescriptorProto_package(file_proto); check_ident(ctx, package, true); file->package = strviewdup(ctx, package); @@ -6386,133 +7979,189 @@ static void build_filedef( } if (google_protobuf_FileDescriptorProto_has_syntax(file_proto)) { - upb_strview syntax = + upb_StringView syntax = google_protobuf_FileDescriptorProto_syntax(file_proto); if (streql_view(syntax, "proto2")) { - file->syntax = UPB_SYNTAX_PROTO2; + file->syntax = kUpb_Syntax_Proto2; } else if (streql_view(syntax, "proto3")) { - file->syntax = UPB_SYNTAX_PROTO3; + file->syntax = kUpb_Syntax_Proto3; } else { - symtab_errf(ctx, "Invalid syntax '" UPB_STRVIEW_FORMAT "'", - UPB_STRVIEW_ARGS(syntax)); + symtab_errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(syntax)); } } else { - file->syntax = UPB_SYNTAX_PROTO2; + file->syntax = kUpb_Syntax_Proto2; } /* Read options. */ - file_options_proto = google_protobuf_FileDescriptorProto_options(file_proto); - if (file_options_proto) { - if (google_protobuf_FileOptions_has_php_class_prefix(file_options_proto)) { - file->phpprefix = strviewdup( - ctx, - google_protobuf_FileOptions_php_class_prefix(file_options_proto)); - } - if (google_protobuf_FileOptions_has_php_namespace(file_options_proto)) { - file->phpnamespace = strviewdup( - ctx, google_protobuf_FileOptions_php_namespace(file_options_proto)); - } - } + SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); /* Verify dependencies. */ strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n); + file->dep_count = n; file->deps = symtab_alloc(ctx, sizeof(*file->deps) * n); for (i = 0; i < n; i++) { - upb_strview dep_name = strs[i]; - upb_value v; - if (!upb_strtable_lookup2(&ctx->symtab->files, dep_name.data, - dep_name.size, &v)) { + upb_StringView str = strs[i]; + file->deps[i] = + upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); + if (!file->deps[i]) { symtab_errf(ctx, - "Depends on file '" UPB_STRVIEW_FORMAT + "Depends on file '" UPB_STRINGVIEW_FORMAT "', but it has not been loaded", - UPB_STRVIEW_ARGS(dep_name)); + UPB_STRINGVIEW_ARGS(str)); } - file->deps[i] = upb_value_getconstptr(v); } - /* Create messages. */ - msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); + public_deps = + google_protobuf_FileDescriptorProto_public_dependency(file_proto, &n); + file->public_dep_count = n; + file->public_deps = symtab_alloc(ctx, sizeof(*file->public_deps) * n); + int32_t* mutable_public_deps = (int32_t*)file->public_deps; for (i = 0; i < n; i++) { - create_msgdef(ctx, file->package, msgs[i]); + if (public_deps[i] >= file->dep_count) { + symtab_errf(ctx, "public_dep %d is out of range", (int)public_deps[i]); + } + mutable_public_deps[i] = public_deps[i]; + } + + weak_deps = + google_protobuf_FileDescriptorProto_weak_dependency(file_proto, &n); + file->weak_dep_count = n; + file->weak_deps = symtab_alloc(ctx, sizeof(*file->weak_deps) * n); + int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; + for (i = 0; i < n; i++) { + if (weak_deps[i] >= file->dep_count) { + symtab_errf(ctx, "public_dep %d is out of range", (int)public_deps[i]); + } + mutable_weak_deps[i] = weak_deps[i]; } /* Create enums. */ enums = google_protobuf_FileDescriptorProto_enum_type(file_proto, &n); + file->top_lvl_enum_count = n; + file->top_lvl_enums = symtab_alloc(ctx, sizeof(*file->top_lvl_enums) * n); for (i = 0; i < n; i++) { - create_enumdef(ctx, file->package, enums[i]); + create_enumdef(ctx, file->package, enums[i], NULL, &file->top_lvl_enums[i]); } /* Create extensions. */ exts = google_protobuf_FileDescriptorProto_extension(file_proto, &n); - file->exts = symtab_alloc(ctx, sizeof(*file->exts) * n); + file->top_lvl_ext_count = n; + file->top_lvl_exts = symtab_alloc(ctx, sizeof(*file->top_lvl_exts) * n); for (i = 0; i < n; i++) { - create_fielddef(ctx, file->package, NULL, exts[i]); + create_fielddef(ctx, file->package, NULL, exts[i], &file->top_lvl_exts[i], + /* is_extension= */ true); + ((upb_FieldDef*)&file->top_lvl_exts[i])->index_ = i; } - /* Now that all names are in the table, build layouts and resolve refs. */ - for (i = 0; i < (size_t)file->ext_count; i++) { - resolve_fielddef(ctx, file->package, (upb_fielddef*)&file->exts[i]); + /* Create messages. */ + msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); + file->top_lvl_msg_count = n; + file->top_lvl_msgs = symtab_alloc(ctx, sizeof(*file->top_lvl_msgs) * n); + for (i = 0; i < n; i++) { + create_msgdef(ctx, file->package, msgs[i], NULL, &file->top_lvl_msgs[i]); } - for (i = 0; i < (size_t)file->msg_count; i++) { - const upb_msgdef *m = &file->msgs[i]; - int j; - for (j = 0; j < m->field_count; j++) { - resolve_fielddef(ctx, m->full_name, (upb_fielddef*)&m->fields[j]); - } + /* Create services. */ + services = google_protobuf_FileDescriptorProto_service(file_proto, &n); + file->service_count = n; + file->services = symtab_alloc(ctx, sizeof(*file->services) * n); + for (i = 0; i < n; i++) { + create_service(ctx, services[i], &file->services[i]); + ((upb_ServiceDef*)&file->services[i])->index = i; } - if (!ctx->layouts) { - for (i = 0; i < (size_t)file->msg_count; i++) { - const upb_msgdef *m = &file->msgs[i]; - make_layout(ctx, m); - } + /* Now that all names are in the table, build layouts and resolve refs. */ + for (i = 0; i < (size_t)file->top_lvl_ext_count; i++) { + resolve_fielddef(ctx, file->package, (upb_FieldDef*)&file->top_lvl_exts[i]); } -} -static void remove_filedef(upb_symtab *s, upb_filedef *file) { - int i; - for (i = 0; i < file->msg_count; i++) { - const char *name = file->msgs[i].full_name; - upb_strtable_remove(&s->syms, name, strlen(name), NULL); + for (i = 0; i < (size_t)file->top_lvl_msg_count; i++) { + resolve_msgdef(ctx, (upb_MessageDef*)&file->top_lvl_msgs[i]); } - for (i = 0; i < file->enum_count; i++) { - const char *name = file->enums[i].full_name; - upb_strtable_remove(&s->syms, name, strlen(name), NULL); + + if (file->ext_count) { + CHK_OOM(_upb_extreg_add(ctx->symtab->extreg, file->ext_layouts, + file->ext_count)); } - for (i = 0; i < file->ext_count; i++) { - const char *name = file->exts[i].full_name; - upb_strtable_remove(&s->syms, name, strlen(name), NULL); +} + +static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { + intptr_t iter = UPB_INTTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { + const upb_FileDef* f; + switch (deftype(val)) { + case UPB_DEFTYPE_EXT: + f = upb_FieldDef_File(unpack_def(val, UPB_DEFTYPE_EXT)); + break; + case UPB_DEFTYPE_MSG: + f = upb_MessageDef_File(unpack_def(val, UPB_DEFTYPE_MSG)); + break; + case UPB_DEFTYPE_ENUM: + f = upb_EnumDef_File(unpack_def(val, UPB_DEFTYPE_ENUM)); + break; + case UPB_DEFTYPE_ENUMVAL: + f = upb_EnumDef_File( + upb_EnumValueDef_Enum(unpack_def(val, UPB_DEFTYPE_ENUMVAL))); + break; + case UPB_DEFTYPE_SERVICE: + f = upb_ServiceDef_File(unpack_def(val, UPB_DEFTYPE_SERVICE)); + break; + default: + UPB_UNREACHABLE(); + } + + if (f == file) upb_strtable_removeiter(&s->syms, &iter); } } -static const upb_filedef *_upb_symtab_addfile( - upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, - const upb_msglayout **layouts, upb_status *status) { +static const upb_FileDef* _upb_DefPool_AddFile( + upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, + const upb_MiniTable_File* layout, upb_Status* status) { symtab_addctx ctx; - upb_strview name = google_protobuf_FileDescriptorProto_name(file_proto); + upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto); + upb_value v; - if (upb_strtable_lookup2(&s->files, name.data, name.size, NULL)) { - upb_status_seterrf(status, "duplicate file name (%.*s)", - UPB_STRVIEW_ARGS(name)); - return NULL; + if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { + if (unpack_def(v, UPB_DEFTYPE_FILE)) { + upb_Status_SetErrorFormat(status, "duplicate file name (%.*s)", + UPB_STRINGVIEW_ARGS(name)); + return NULL; + } + const upb_MiniTable_File* registered = unpack_def(v, UPB_DEFTYPE_LAYOUT); + UPB_ASSERT(registered); + if (layout && layout != registered) { + upb_Status_SetErrorFormat( + status, "tried to build with a different layout (filename=%.*s)", + UPB_STRINGVIEW_ARGS(name)); + return NULL; + } + layout = registered; } ctx.symtab = s; - ctx.layouts = layouts; + ctx.layout = layout; + ctx.msg_count = 0; + ctx.enum_count = 0; + ctx.ext_count = 0; ctx.status = status; ctx.file = NULL; - ctx.arena = upb_arena_new(); + ctx.arena = upb_Arena_New(); + ctx.tmp_arena = upb_Arena_New(); - if (!ctx.arena) { - upb_status_setoom(status); + if (!ctx.arena || !ctx.tmp_arena) { + if (ctx.arena) upb_Arena_Free(ctx.arena); + if (ctx.tmp_arena) upb_Arena_Free(ctx.tmp_arena); + upb_Status_setoom(status); return NULL; } if (UPB_UNLIKELY(UPB_SETJMP(ctx.err))) { - UPB_ASSERT(!upb_ok(status)); + UPB_ASSERT(!upb_Status_IsOk(status)); if (ctx.file) { remove_filedef(s, ctx.file); ctx.file = NULL; @@ -6521,51 +8170,52 @@ static const upb_filedef *_upb_symtab_addfile( ctx.file = symtab_alloc(&ctx, sizeof(*ctx.file)); build_filedef(&ctx, ctx.file, file_proto); upb_strtable_insert(&s->files, name.data, name.size, - upb_value_constptr(ctx.file), ctx.arena); - UPB_ASSERT(upb_ok(status)); - upb_arena_fuse(s->arena, ctx.arena); + pack_def(ctx.file, UPB_DEFTYPE_FILE), ctx.arena); + UPB_ASSERT(upb_Status_IsOk(status)); + upb_Arena_Fuse(s->arena, ctx.arena); } - upb_arena_free(ctx.arena); + upb_Arena_Free(ctx.arena); + upb_Arena_Free(ctx.tmp_arena); return ctx.file; } -const upb_filedef *upb_symtab_addfile( - upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, - upb_status *status) { - return _upb_symtab_addfile(s, file_proto, NULL, status); +const upb_FileDef* upb_DefPool_AddFile( + upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, + upb_Status* status) { + return _upb_DefPool_AddFile(s, file_proto, NULL, status); } /* Include here since we want most of this file to be stdio-free. */ #include -bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) { +bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { /* Since this function should never fail (it would indicate a bug in upb) we * print errors to stderr instead of returning error status to the user. */ - upb_def_init **deps = init->deps; - google_protobuf_FileDescriptorProto *file; - upb_arena *arena; - upb_status status; + _upb_DefPool_Init** deps = init->deps; + google_protobuf_FileDescriptorProto* file; + upb_Arena* arena; + upb_Status status; - upb_status_clear(&status); + upb_Status_Clear(&status); - if (upb_strtable_lookup(&s->files, init->filename, NULL)) { + if (upb_DefPool_FindFileByName(s, init->filename)) { return true; } - arena = upb_arena_new(); + arena = upb_Arena_New(); for (; *deps; deps++) { - if (!_upb_symtab_loaddefinit(s, *deps)) goto err; + if (!_upb_DefPool_LoadDefInit(s, *deps)) goto err; } file = google_protobuf_FileDescriptorProto_parse_ex( - init->descriptor.data, init->descriptor.size, NULL, UPB_DECODE_ALIAS, - arena); + init->descriptor.data, init->descriptor.size, NULL, + kUpb_DecodeOption_AliasString, arena); s->bytes_loaded += init->descriptor.size; if (!file) { - upb_status_seterrf( + upb_Status_SetErrorFormat( &status, "Failed to parse compiled-in descriptor for file '%s'. This should " "never happen.", @@ -6573,24 +8223,80 @@ bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) { goto err; } - if (!_upb_symtab_addfile(s, file, init->layouts, &status)) goto err; + if (!_upb_DefPool_AddFile(s, file, init->layout, &status)) { + goto err; + } - upb_arena_free(arena); + upb_Arena_Free(arena); return true; err: - fprintf(stderr, "Error loading compiled-in descriptor: %s\n", - upb_status_errmsg(&status)); - upb_arena_free(arena); + fprintf(stderr, + "Error loading compiled-in descriptor for file '%s' (this should " + "never happen): %s\n", + init->filename, upb_Status_ErrorMessage(&status)); + upb_Arena_Free(arena); return false; } -size_t _upb_symtab_bytesloaded(const upb_symtab *s) { +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { return s->bytes_loaded; } -upb_arena *_upb_symtab_arena(const upb_symtab *s) { - return s->arena; +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } + +const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTable_Extension* ext) { + upb_value v; + bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); + UPB_ASSERT(ok); + return upb_value_getconstptr(v); +} + +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum) { + const upb_MiniTable* l = upb_MessageDef_MiniTable(m); + const upb_MiniTable_Extension* ext = _upb_extreg_get(s->extreg, l, fieldnum); + return ext ? _upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; +} + +bool _upb_DefPool_registerlayout(upb_DefPool* s, const char* filename, + const upb_MiniTable_File* file) { + if (upb_DefPool_FindFileByName(s, filename)) return false; + upb_value v = pack_def(file, UPB_DEFTYPE_LAYOUT); + return upb_strtable_insert(&s->files, filename, strlen(filename), v, + s->arena); +} + +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s) { + return s->extreg; +} + +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count) { + size_t n = 0; + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + // This is O(all exts) instead of O(exts for m). If we need this to be + // efficient we may need to make extreg into a two-level table, or have a + // second per-message index. + while (upb_inttable_next2(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) n++; + } + const upb_FieldDef** exts = malloc(n * sizeof(*exts)); + iter = UPB_INTTABLE_BEGIN; + size_t i = 0; + while (upb_inttable_next2(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; + } + *count = n; + return exts; } #undef CHK_OOM @@ -6600,199 +8306,234 @@ upb_arena *_upb_symtab_arena(const upb_symtab *s) { #include -static size_t get_field_size(const upb_msglayout_field *f) { +static size_t get_field_size(const upb_MiniTable_Field* f) { static unsigned char sizes[] = { - 0,/* 0 */ - 8, /* UPB_DESCRIPTOR_TYPE_DOUBLE */ - 4, /* UPB_DESCRIPTOR_TYPE_FLOAT */ - 8, /* UPB_DESCRIPTOR_TYPE_INT64 */ - 8, /* UPB_DESCRIPTOR_TYPE_UINT64 */ - 4, /* UPB_DESCRIPTOR_TYPE_INT32 */ - 8, /* UPB_DESCRIPTOR_TYPE_FIXED64 */ - 4, /* UPB_DESCRIPTOR_TYPE_FIXED32 */ - 1, /* UPB_DESCRIPTOR_TYPE_BOOL */ - sizeof(upb_strview), /* UPB_DESCRIPTOR_TYPE_STRING */ - sizeof(void*), /* UPB_DESCRIPTOR_TYPE_GROUP */ - sizeof(void*), /* UPB_DESCRIPTOR_TYPE_MESSAGE */ - sizeof(upb_strview), /* UPB_DESCRIPTOR_TYPE_BYTES */ - 4, /* UPB_DESCRIPTOR_TYPE_UINT32 */ - 4, /* UPB_DESCRIPTOR_TYPE_ENUM */ - 4, /* UPB_DESCRIPTOR_TYPE_SFIXED32 */ - 8, /* UPB_DESCRIPTOR_TYPE_SFIXED64 */ - 4, /* UPB_DESCRIPTOR_TYPE_SINT32 */ - 8, /* UPB_DESCRIPTOR_TYPE_SINT64 */ + 0, /* 0 */ + 8, /* kUpb_FieldType_Double */ + 4, /* kUpb_FieldType_Float */ + 8, /* kUpb_FieldType_Int64 */ + 8, /* kUpb_FieldType_UInt64 */ + 4, /* kUpb_FieldType_Int32 */ + 8, /* kUpb_FieldType_Fixed64 */ + 4, /* kUpb_FieldType_Fixed32 */ + 1, /* kUpb_FieldType_Bool */ + sizeof(upb_StringView), /* kUpb_FieldType_String */ + sizeof(void*), /* kUpb_FieldType_Group */ + sizeof(void*), /* kUpb_FieldType_Message */ + sizeof(upb_StringView), /* kUpb_FieldType_Bytes */ + 4, /* kUpb_FieldType_UInt32 */ + 4, /* kUpb_FieldType_Enum */ + 4, /* kUpb_FieldType_SFixed32 */ + 8, /* kUpb_FieldType_SFixed64 */ + 4, /* kUpb_FieldType_SInt32 */ + 8, /* kUpb_FieldType_SInt64 */ }; - return _upb_repeated_or_map(f) ? sizeof(void *) : sizes[f->descriptortype]; + return upb_IsRepeatedOrMap(f) ? sizeof(void*) : sizes[f->descriptortype]; } /* Strings/bytes are special-cased in maps. */ -static char _upb_fieldtype_to_mapsize[12] = { - 0, - 1, /* UPB_TYPE_BOOL */ - 4, /* UPB_TYPE_FLOAT */ - 4, /* UPB_TYPE_INT32 */ - 4, /* UPB_TYPE_UINT32 */ - 4, /* UPB_TYPE_ENUM */ - sizeof(void*), /* UPB_TYPE_MESSAGE */ - 8, /* UPB_TYPE_DOUBLE */ - 8, /* UPB_TYPE_INT64 */ - 8, /* UPB_TYPE_UINT64 */ - 0, /* UPB_TYPE_STRING */ - 0, /* UPB_TYPE_BYTES */ +static char _upb_CTypeo_mapsize[12] = { + 0, + 1, /* kUpb_CType_Bool */ + 4, /* kUpb_CType_Float */ + 4, /* kUpb_CType_Int32 */ + 4, /* kUpb_CType_UInt32 */ + 4, /* kUpb_CType_Enum */ + sizeof(void*), /* kUpb_CType_Message */ + 8, /* kUpb_CType_Double */ + 8, /* kUpb_CType_Int64 */ + 8, /* kUpb_CType_UInt64 */ + 0, /* kUpb_CType_String */ + 0, /* kUpb_CType_Bytes */ }; -static const char _upb_fieldtype_to_sizelg2[12] = { - 0, - 0, /* UPB_TYPE_BOOL */ - 2, /* UPB_TYPE_FLOAT */ - 2, /* UPB_TYPE_INT32 */ - 2, /* UPB_TYPE_UINT32 */ - 2, /* UPB_TYPE_ENUM */ - UPB_SIZE(2, 3), /* UPB_TYPE_MESSAGE */ - 3, /* UPB_TYPE_DOUBLE */ - 3, /* UPB_TYPE_INT64 */ - 3, /* UPB_TYPE_UINT64 */ - UPB_SIZE(3, 4), /* UPB_TYPE_STRING */ - UPB_SIZE(3, 4), /* UPB_TYPE_BYTES */ +static const char _upb_CTypeo_sizelg2[12] = { + 0, + 0, /* kUpb_CType_Bool */ + 2, /* kUpb_CType_Float */ + 2, /* kUpb_CType_Int32 */ + 2, /* kUpb_CType_UInt32 */ + 2, /* kUpb_CType_Enum */ + UPB_SIZE(2, 3), /* kUpb_CType_Message */ + 3, /* kUpb_CType_Double */ + 3, /* kUpb_CType_Int64 */ + 3, /* kUpb_CType_UInt64 */ + UPB_SIZE(3, 4), /* kUpb_CType_String */ + UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ }; -/** upb_msg *******************************************************************/ +/** upb_Message + * *******************************************************************/ -upb_msg *upb_msg_new(const upb_msgdef *m, upb_arena *a) { - return _upb_msg_new(upb_msgdef_layout(m), a); +upb_Message* upb_Message_New(const upb_MessageDef* m, upb_Arena* a) { + return _upb_Message_New(upb_MessageDef_MiniTable(m), a); } -static bool in_oneof(const upb_msglayout_field *field) { +static bool in_oneof(const upb_MiniTable_Field* field) { return field->presence < 0; } -static upb_msgval _upb_msg_getraw(const upb_msg *msg, const upb_fielddef *f) { - const upb_msglayout_field *field = upb_fielddef_layout(f); - const char *mem = UPB_PTR_AT(msg, field->offset, char); - upb_msgval val = {0}; +static upb_MessageValue _upb_Message_Getraw(const upb_Message* msg, + const upb_FieldDef* f) { + const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f); + const char* mem = UPB_PTR_AT(msg, field->offset, char); + upb_MessageValue val = {0}; memcpy(&val, mem, get_field_size(field)); return val; } -bool upb_msg_has(const upb_msg *msg, const upb_fielddef *f) { - const upb_msglayout_field *field = upb_fielddef_layout(f); - if (in_oneof(field)) { - return _upb_getoneofcase_field(msg, field) == field->number; - } else if (field->presence > 0) { - return _upb_hasbit_field(msg, field); +bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f) { + assert(upb_FieldDef_HasPresence(f)); + if (upb_FieldDef_IsExtension(f)) { + const upb_MiniTable_Extension* ext = _upb_FieldDef_ExtensionMiniTable(f); + return _upb_Message_Getext(msg, ext) != NULL; } else { - UPB_ASSERT(field->descriptortype == UPB_DESCRIPTOR_TYPE_MESSAGE || - field->descriptortype == UPB_DESCRIPTOR_TYPE_GROUP); - return _upb_msg_getraw(msg, f).msg_val != NULL; + const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f); + if (in_oneof(field)) { + return _upb_getoneofcase_field(msg, field) == field->number; + } else if (field->presence > 0) { + return _upb_hasbit_field(msg, field); + } else { + UPB_ASSERT(field->descriptortype == kUpb_FieldType_Message || + field->descriptortype == kUpb_FieldType_Group); + return _upb_Message_Getraw(msg, f).msg_val != NULL; + } } } -const upb_fielddef *upb_msg_whichoneof(const upb_msg *msg, - const upb_oneofdef *o) { - const upb_fielddef *f = upb_oneofdef_field(o, 0); - if (upb_oneofdef_issynthetic(o)) { - UPB_ASSERT(upb_oneofdef_fieldcount(o) == 1); - return upb_msg_has(msg, f) ? f : NULL; +const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, + const upb_OneofDef* o) { + const upb_FieldDef* f = upb_OneofDef_Field(o, 0); + if (upb_OneofDef_IsSynthetic(o)) { + UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1); + return upb_Message_Has(msg, f) ? f : NULL; } else { - const upb_msglayout_field *field = upb_fielddef_layout(f); + const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f); uint32_t oneof_case = _upb_getoneofcase_field(msg, field); - f = oneof_case ? upb_oneofdef_itof(o, oneof_case) : NULL; + f = oneof_case ? upb_OneofDef_LookupNumber(o, oneof_case) : NULL; UPB_ASSERT((f != NULL) == (oneof_case != 0)); return f; } } -upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f) { - if (!upb_fielddef_haspresence(f) || upb_msg_has(msg, f)) { - return _upb_msg_getraw(msg, f); +upb_MessageValue upb_Message_Get(const upb_Message* msg, + const upb_FieldDef* f) { + if (upb_FieldDef_IsExtension(f)) { + const upb_Message_Extension* ext = + _upb_Message_Getext(msg, _upb_FieldDef_ExtensionMiniTable(f)); + if (ext) { + upb_MessageValue val; + memcpy(&val, &ext->data, sizeof(val)); + return val; + } else if (upb_FieldDef_IsRepeated(f)) { + return (upb_MessageValue){.array_val = NULL}; + } + } else if (!upb_FieldDef_HasPresence(f) || upb_Message_Has(msg, f)) { + return _upb_Message_Getraw(msg, f); + } + return upb_FieldDef_Default(f); +} + +upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg, + const upb_FieldDef* f, + upb_Arena* a) { + UPB_ASSERT(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsRepeated(f)); + if (upb_FieldDef_HasPresence(f) && !upb_Message_Has(msg, f)) { + // We need to skip the upb_Message_Get() call in this case. + goto make; + } + + upb_MessageValue val = upb_Message_Get(msg, f); + if (val.array_val) { + return (upb_MutableMessageValue){.array = (upb_Array*)val.array_val}; + } + + upb_MutableMessageValue ret; +make: + if (!a) return (upb_MutableMessageValue){.array = NULL}; + if (upb_FieldDef_IsMap(f)) { + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key = upb_MessageDef_FindFieldByNumberWithSize( + entry, kUpb_MapEntry_KeyFieldNumber); + const upb_FieldDef* value = upb_MessageDef_FindFieldByNumberWithSize( + entry, kUpb_MapEntry_ValueFieldNumber); + ret.map = + upb_Map_New(a, upb_FieldDef_CType(key), upb_FieldDef_CType(value)); + } else if (upb_FieldDef_IsRepeated(f)) { + ret.array = upb_Array_New(a, upb_FieldDef_CType(f)); } else { - return upb_fielddef_default(f); + UPB_ASSERT(upb_FieldDef_IsSubMessage(f)); + ret.msg = upb_Message_New(upb_FieldDef_MessageSubDef(f), a); } -} -upb_mutmsgval upb_msg_mutable(upb_msg *msg, const upb_fielddef *f, - upb_arena *a) { - const upb_msglayout_field *field = upb_fielddef_layout(f); - upb_mutmsgval ret; - char *mem = UPB_PTR_AT(msg, field->offset, char); - bool wrong_oneof = - in_oneof(field) && _upb_getoneofcase_field(msg, field) != field->number; + val.array_val = ret.array; + upb_Message_Set(msg, f, val, a); - memcpy(&ret, mem, sizeof(void*)); - - if (a && (!ret.msg || wrong_oneof)) { - if (upb_fielddef_ismap(f)) { - const upb_msgdef *entry = upb_fielddef_msgsubdef(f); - const upb_fielddef *key = upb_msgdef_itof(entry, UPB_MAPENTRY_KEY); - const upb_fielddef *value = upb_msgdef_itof(entry, UPB_MAPENTRY_VALUE); - ret.map = upb_map_new(a, upb_fielddef_type(key), upb_fielddef_type(value)); - } else if (upb_fielddef_isseq(f)) { - ret.array = upb_array_new(a, upb_fielddef_type(f)); - } else { - UPB_ASSERT(upb_fielddef_issubmsg(f)); - ret.msg = upb_msg_new(upb_fielddef_msgsubdef(f), a); - } - - memcpy(mem, &ret, sizeof(void*)); + return ret; +} - if (wrong_oneof) { - *_upb_oneofcase_field(msg, field) = field->number; - } else if (field->presence > 0) { +bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f, + upb_MessageValue val, upb_Arena* a) { + if (upb_FieldDef_IsExtension(f)) { + upb_Message_Extension* ext = _upb_Message_Getorcreateext( + msg, _upb_FieldDef_ExtensionMiniTable(f), a); + if (!ext) return false; + memcpy(&ext->data, &val, sizeof(val)); + } else { + const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f); + char* mem = UPB_PTR_AT(msg, field->offset, char); + memcpy(mem, &val, get_field_size(field)); + if (field->presence > 0) { _upb_sethas_field(msg, field); + } else if (in_oneof(field)) { + *_upb_oneofcase_field(msg, field) = field->number; } } - return ret; + return true; } -void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val, - upb_arena *a) { - const upb_msglayout_field *field = upb_fielddef_layout(f); - char *mem = UPB_PTR_AT(msg, field->offset, char); - UPB_UNUSED(a); /* We reserve the right to make set insert into a map. */ - memcpy(mem, &val, get_field_size(field)); - if (field->presence > 0) { - _upb_sethas_field(msg, field); - } else if (in_oneof(field)) { - *_upb_oneofcase_field(msg, field) = field->number; - } -} +void upb_Message_ClearField(upb_Message* msg, const upb_FieldDef* f) { + if (upb_FieldDef_IsExtension(f)) { + _upb_Message_Clearext(msg, _upb_FieldDef_ExtensionMiniTable(f)); + } else { + const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f); + char* mem = UPB_PTR_AT(msg, field->offset, char); -void upb_msg_clearfield(upb_msg *msg, const upb_fielddef *f) { - const upb_msglayout_field *field = upb_fielddef_layout(f); - char *mem = UPB_PTR_AT(msg, field->offset, char); + if (field->presence > 0) { + _upb_clearhas_field(msg, field); + } else if (in_oneof(field)) { + uint32_t* oneof_case = _upb_oneofcase_field(msg, field); + if (*oneof_case != field->number) return; + *oneof_case = 0; + } - if (field->presence > 0) { - _upb_clearhas_field(msg, field); - } else if (in_oneof(field)) { - uint32_t *oneof_case = _upb_oneofcase_field(msg, field); - if (*oneof_case != field->number) return; - *oneof_case = 0; + memset(mem, 0, get_field_size(field)); } - - memset(mem, 0, get_field_size(field)); } -void upb_msg_clear(upb_msg *msg, const upb_msgdef *m) { - _upb_msg_clear(msg, upb_msgdef_layout(m)); +void upb_Message_Clear(upb_Message* msg, const upb_MessageDef* m) { + _upb_Message_Clear(msg, upb_MessageDef_MiniTable(m)); } -bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m, - const upb_symtab *ext_pool, const upb_fielddef **out_f, - upb_msgval *out_val, size_t *iter) { - int i = *iter; - int n = upb_msgdef_fieldcount(m); - const upb_msgval zero = {0}; +bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, const upb_FieldDef** out_f, + upb_MessageValue* out_val, size_t* iter) { + size_t i = *iter; + size_t n = upb_MessageDef_FieldCount(m); + const upb_MessageValue zero = {0}; UPB_UNUSED(ext_pool); + + /* Iterate over normal fields, returning the first one that is set. */ while (++i < n) { - const upb_fielddef *f = upb_msgdef_field(m, i); - upb_msgval val = _upb_msg_getraw(msg, f); + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + upb_MessageValue val = _upb_Message_Getraw(msg, f); /* Skip field if unset or empty. */ - if (upb_fielddef_haspresence(f)) { - if (!upb_msg_has(msg, f)) continue; + if (upb_FieldDef_HasPresence(f)) { + if (!upb_Message_Has(msg, f)) continue; } else { - upb_msgval test = val; - if (upb_fielddef_isstring(f) && !upb_fielddef_isseq(f)) { + upb_MessageValue test = val; + if (upb_FieldDef_IsString(f) && !upb_FieldDef_IsRepeated(f)) { /* Clear string pointer, only size matters (ptr could be non-NULL). */ test.str_val.data = NULL; } @@ -6800,10 +8541,10 @@ bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m, if (memcmp(&test, &zero, sizeof(test)) == 0) continue; /* Continue on empty array or map. */ - if (upb_fielddef_ismap(f)) { - if (upb_map_size(test.map_val) == 0) continue; - } else if (upb_fielddef_isseq(f)) { - if (upb_array_size(test.array_val) == 0) continue; + if (upb_FieldDef_IsMap(f)) { + if (upb_Map_Size(test.map_val) == 0) continue; + } else if (upb_FieldDef_IsRepeated(f)) { + if (upb_Array_Size(test.array_val) == 0) continue; } } @@ -6812,48 +8553,67 @@ bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m, *iter = i; return true; } + + if (ext_pool) { + /* Return any extensions that are set. */ + size_t count; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + if (i - n < count) { + ext += count - 1 - (i - n); + memcpy(out_val, &ext->data, sizeof(*out_val)); + *out_f = _upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); + *iter = i; + return true; + } + } + *iter = i; return false; } -bool _upb_msg_discardunknown(upb_msg *msg, const upb_msgdef *m, int depth) { - size_t iter = UPB_MSG_BEGIN; - const upb_fielddef *f; - upb_msgval val; +bool _upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, + int depth) { + size_t iter = kUpb_Message_Begin; + const upb_FieldDef* f; + upb_MessageValue val; bool ret = true; if (--depth == 0) return false; - _upb_msg_discardunknown_shallow(msg); + _upb_Message_DiscardUnknown_shallow(msg); - while (upb_msg_next(msg, m, NULL /*ext_pool*/, &f, &val, &iter)) { - const upb_msgdef *subm = upb_fielddef_msgsubdef(f); + while (upb_Message_Next(msg, m, NULL /*ext_pool*/, &f, &val, &iter)) { + const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); if (!subm) continue; - if (upb_fielddef_ismap(f)) { - const upb_fielddef *val_f = upb_msgdef_itof(subm, 2); - const upb_msgdef *val_m = upb_fielddef_msgsubdef(val_f); - upb_map *map = (upb_map*)val.map_val; - size_t iter = UPB_MAP_BEGIN; + if (upb_FieldDef_IsMap(f)) { + const upb_FieldDef* val_f = + upb_MessageDef_FindFieldByNumberWithSize(subm, 2); + const upb_MessageDef* val_m = upb_FieldDef_MessageSubDef(val_f); + upb_Map* map = (upb_Map*)val.map_val; + size_t iter = kUpb_Map_Begin; if (!val_m) continue; - while (upb_mapiter_next(map, &iter)) { - upb_msgval map_val = upb_mapiter_value(map, iter); - if (!_upb_msg_discardunknown((upb_msg*)map_val.msg_val, val_m, depth)) { + while (upb_MapIterator_Next(map, &iter)) { + upb_MessageValue map_val = upb_MapIterator_Value(map, iter); + if (!_upb_Message_DiscardUnknown((upb_Message*)map_val.msg_val, val_m, + depth)) { ret = false; } } - } else if (upb_fielddef_isseq(f)) { - const upb_array *arr = val.array_val; - size_t i, n = upb_array_size(arr); + } else if (upb_FieldDef_IsRepeated(f)) { + const upb_Array* arr = val.array_val; + size_t i, n = upb_Array_Size(arr); for (i = 0; i < n; i++) { - upb_msgval elem = upb_array_get(arr, i); - if (!_upb_msg_discardunknown((upb_msg*)elem.msg_val, subm, depth)) { + upb_MessageValue elem = upb_Array_Get(arr, i); + if (!_upb_Message_DiscardUnknown((upb_Message*)elem.msg_val, subm, + depth)) { ret = false; } } } else { - if (!_upb_msg_discardunknown((upb_msg*)val.msg_val, subm, depth)) { + if (!_upb_Message_DiscardUnknown((upb_Message*)val.msg_val, subm, + depth)) { ret = false; } } @@ -6862,22 +8622,21 @@ bool _upb_msg_discardunknown(upb_msg *msg, const upb_msgdef *m, int depth) { return ret; } -bool upb_msg_discardunknown(upb_msg *msg, const upb_msgdef *m, int maxdepth) { - return _upb_msg_discardunknown(msg, m, maxdepth); +bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, + int maxdepth) { + return _upb_Message_DiscardUnknown(msg, m, maxdepth); } -/** upb_array *****************************************************************/ +/** upb_Array *****************************************************************/ -upb_array *upb_array_new(upb_arena *a, upb_fieldtype_t type) { - return _upb_array_new(a, 4, _upb_fieldtype_to_sizelg2[type]); +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); } -size_t upb_array_size(const upb_array *arr) { - return arr->len; -} +size_t upb_Array_Size(const upb_Array* arr) { return arr->len; } -upb_msgval upb_array_get(const upb_array *arr, size_t i) { - upb_msgval ret; +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; const char* data = _upb_array_constptr(arr); int lg2 = arr->data & 7; UPB_ASSERT(i < arr->len); @@ -6885,86 +8644,114 @@ upb_msgval upb_array_get(const upb_array *arr, size_t i) { return ret; } -void upb_array_set(upb_array *arr, size_t i, upb_msgval val) { +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { char* data = _upb_array_ptr(arr); int lg2 = arr->data & 7; UPB_ASSERT(i < arr->len); memcpy(data + (i << lg2), &val, 1 << lg2); } -bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) { - if (!upb_array_resize(arr, arr->len + 1, arena)) { +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + if (!upb_Array_Resize(arr, arr->len + 1, arena)) { return false; } - upb_array_set(arr, arr->len - 1, val); + upb_Array_Set(arr, arr->len - 1, val); return true; } -bool upb_array_resize(upb_array *arr, size_t size, upb_arena *arena) { - return _upb_array_resize(arr, size, arena); +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); } -/** upb_map *******************************************************************/ +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(i <= arr->len); + UPB_ASSERT(count + arr->len >= count); + size_t oldsize = arr->len; + if (!upb_Array_Resize(arr, arr->len + count, arena)) { + return false; + } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; +} -upb_map *upb_map_new(upb_arena *a, upb_fieldtype_t key_type, - upb_fieldtype_t value_type) { - return _upb_map_new(a, _upb_fieldtype_to_mapsize[key_type], - _upb_fieldtype_to_mapsize[value_type]); +/* + * i end arr->len + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->len); + upb_Array_Move(arr, i, end, arr->len - end); + arr->len -= count; } -size_t upb_map_size(const upb_map *map) { - return _upb_map_size(map); +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + return _upb_Array_Resize(arr, size, arena); } -bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val) { - return _upb_map_get(map, &key, map->key_size, val, map->val_size); +/** upb_Map *******************************************************************/ + +upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) { + return _upb_Map_New(a, _upb_CTypeo_mapsize[key_type], + _upb_CTypeo_mapsize[value_type]); } -void upb_map_clear(upb_map *map) { - _upb_map_clear(map); +size_t upb_Map_Size(const upb_Map* map) { return _upb_Map_Size(map); } + +bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val) { + return _upb_Map_Get(map, &key, map->key_size, val, map->val_size); } -bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, - upb_arena *arena) { - return _upb_map_set(map, &key, map->key_size, &val, map->val_size, arena); +void upb_Map_Clear(upb_Map* map) { _upb_Map_Clear(map); } + +bool upb_Map_Set(upb_Map* map, upb_MessageValue key, upb_MessageValue val, + upb_Arena* arena) { + return _upb_Map_Set(map, &key, map->key_size, &val, map->val_size, arena); } -bool upb_map_delete(upb_map *map, upb_msgval key) { - return _upb_map_delete(map, &key, map->key_size); +bool upb_Map_Delete(upb_Map* map, upb_MessageValue key) { + return _upb_Map_Delete(map, &key, map->key_size); } -bool upb_mapiter_next(const upb_map *map, size_t *iter) { +bool upb_MapIterator_Next(const upb_Map* map, size_t* iter) { return _upb_map_next(map, iter); } -bool upb_mapiter_done(const upb_map *map, size_t iter) { +bool upb_MapIterator_Done(const upb_Map* map, size_t iter) { upb_strtable_iter i; - UPB_ASSERT(iter != UPB_MAP_BEGIN); + UPB_ASSERT(iter != kUpb_Map_Begin); i.t = &map->table; i.index = iter; return upb_strtable_done(&i); } /* Returns the key and value for this entry of the map. */ -upb_msgval upb_mapiter_key(const upb_map *map, size_t iter) { +upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter) { upb_strtable_iter i; - upb_msgval ret; + upb_MessageValue ret; i.t = &map->table; i.index = iter; _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size); return ret; } -upb_msgval upb_mapiter_value(const upb_map *map, size_t iter) { +upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { upb_strtable_iter i; - upb_msgval ret; + upb_MessageValue ret; i.t = &map->table; i.index = iter; _upb_map_fromvalue(upb_strtable_iter_value(&i), &ret, map->val_size); return ret; } -/* void upb_mapiter_setvalue(upb_map *map, size_t iter, upb_msgval value); */ +/* void upb_MapIterator_SetValue(upb_Map *map, size_t iter, upb_MessageValue + * value); */ /** upb/json_decode.c ************************************************************/ @@ -6982,62 +8769,64 @@ upb_msgval upb_mapiter_value(const upb_map *map, size_t iter) { typedef struct { const char *ptr, *end; - upb_arena *arena; /* TODO: should we have a tmp arena for tmp data? */ - const upb_symtab *any_pool; + upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */ + const upb_DefPool* symtab; int depth; - upb_status *status; + upb_Status* status; jmp_buf err; int line; - const char *line_begin; + const char* line_begin; bool is_first; int options; - const upb_fielddef *debug_field; + const upb_FieldDef* debug_field; } jsondec; enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; /* Forward declarations of mutually-recursive functions. */ -static void jsondec_wellknown(jsondec *d, upb_msg *msg, const upb_msgdef *m); -static upb_msgval jsondec_value(jsondec *d, const upb_fielddef *f); -static void jsondec_wellknownvalue(jsondec *d, upb_msg *msg, - const upb_msgdef *m); -static void jsondec_object(jsondec *d, upb_msg *msg, const upb_msgdef *m); - -static bool jsondec_streql(upb_strview str, const char *lit) { +static void jsondec_wellknown(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); +static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); +static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); +static void jsondec_object(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); + +static bool jsondec_streql(upb_StringView str, const char* lit) { return str.size == strlen(lit) && memcmp(str.data, lit, str.size) == 0; } -static bool jsondec_isnullvalue(const upb_fielddef *f) { - return upb_fielddef_type(f) == UPB_TYPE_ENUM && - strcmp(upb_enumdef_fullname(upb_fielddef_enumsubdef(f)), +static bool jsondec_isnullvalue(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Enum && + strcmp(upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(f)), "google.protobuf.NullValue") == 0; } -static bool jsondec_isvalue(const upb_fielddef *f) { - return (upb_fielddef_type(f) == UPB_TYPE_MESSAGE && - upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(f)) == - UPB_WELLKNOWN_VALUE) || +static bool jsondec_isvalue(const upb_FieldDef* f) { + return (upb_FieldDef_CType(f) == kUpb_CType_Message && + upb_MessageDef_WellKnownType(upb_FieldDef_MessageSubDef(f)) == + kUpb_WellKnown_Value) || jsondec_isnullvalue(f); } -UPB_NORETURN static void jsondec_err(jsondec *d, const char *msg) { - upb_status_seterrf(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) { + upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, + (int)(d->ptr - d->line_begin), msg); UPB_LONGJMP(d->err, 1); } UPB_PRINTF(2, 3) -UPB_NORETURN static void jsondec_errf(jsondec *d, const char *fmt, ...) { +UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { va_list argp; - upb_status_seterrf(d->status, "Error parsing JSON @%d:%d: ", d->line, - (int)(d->ptr - d->line_begin)); + upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: ", d->line, + (int)(d->ptr - d->line_begin)); va_start(argp, fmt); - upb_status_vappenderrf(d->status, fmt, argp); + upb_Status_VAppendErrorFormat(d->status, fmt, argp); va_end(argp); UPB_LONGJMP(d->err, 1); } -static void jsondec_skipws(jsondec *d) { +static void jsondec_skipws(jsondec* d) { while (d->ptr != d->end) { switch (*d->ptr) { case '\n': @@ -7056,13 +8845,13 @@ static void jsondec_skipws(jsondec *d) { jsondec_err(d, "Unexpected EOF"); } -static bool jsondec_tryparsech(jsondec *d, char ch) { +static bool jsondec_tryparsech(jsondec* d, char ch) { if (d->ptr == d->end || *d->ptr != ch) return false; d->ptr++; return true; } -static void jsondec_parselit(jsondec *d, const char *lit) { +static void jsondec_parselit(jsondec* d, const char* lit) { size_t avail = d->end - d->ptr; size_t len = strlen(lit); if (avail < len || memcmp(d->ptr, lit, len) != 0) { @@ -7071,23 +8860,23 @@ static void jsondec_parselit(jsondec *d, const char *lit) { d->ptr += len; } -static void jsondec_wsch(jsondec *d, char ch) { +static void jsondec_wsch(jsondec* d, char ch) { jsondec_skipws(d); if (!jsondec_tryparsech(d, ch)) { jsondec_errf(d, "Expected: '%c'", ch); } } -static void jsondec_true(jsondec *d) { jsondec_parselit(d, "true"); } -static void jsondec_false(jsondec *d) { jsondec_parselit(d, "false"); } -static void jsondec_null(jsondec *d) { jsondec_parselit(d, "null"); } +static void jsondec_true(jsondec* d) { jsondec_parselit(d, "true"); } +static void jsondec_false(jsondec* d) { jsondec_parselit(d, "false"); } +static void jsondec_null(jsondec* d) { jsondec_parselit(d, "null"); } -static void jsondec_entrysep(jsondec *d) { +static void jsondec_entrysep(jsondec* d) { jsondec_skipws(d); jsondec_parselit(d, ":"); } -static int jsondec_rawpeek(jsondec *d) { +static int jsondec_rawpeek(jsondec* d) { switch (*d->ptr) { case '{': return JD_OBJECT; @@ -7128,19 +8917,19 @@ static int jsondec_rawpeek(jsondec *d) { * } * jsondec_objend(d) */ -static int jsondec_peek(jsondec *d) { +static int jsondec_peek(jsondec* d) { jsondec_skipws(d); return jsondec_rawpeek(d); } -static void jsondec_push(jsondec *d) { +static void jsondec_push(jsondec* d) { if (--d->depth < 0) { jsondec_err(d, "Recursion limit exceeded"); } d->is_first = true; } -static bool jsondec_seqnext(jsondec *d, char end_ch) { +static bool jsondec_seqnext(jsondec* d, char end_ch) { bool is_first = d->is_first; d->is_first = false; jsondec_skipws(d); @@ -7149,31 +8938,29 @@ static bool jsondec_seqnext(jsondec *d, char end_ch) { return true; } -static void jsondec_arrstart(jsondec *d) { +static void jsondec_arrstart(jsondec* d) { jsondec_push(d); jsondec_wsch(d, '['); } -static void jsondec_arrend(jsondec *d) { +static void jsondec_arrend(jsondec* d) { d->depth++; jsondec_wsch(d, ']'); } -static bool jsondec_arrnext(jsondec *d) { - return jsondec_seqnext(d, ']'); -} +static bool jsondec_arrnext(jsondec* d) { return jsondec_seqnext(d, ']'); } -static void jsondec_objstart(jsondec *d) { +static void jsondec_objstart(jsondec* d) { jsondec_push(d); jsondec_wsch(d, '{'); } -static void jsondec_objend(jsondec *d) { +static void jsondec_objend(jsondec* d) { d->depth++; jsondec_wsch(d, '}'); } -static bool jsondec_objnext(jsondec *d) { +static bool jsondec_objnext(jsondec* d) { if (!jsondec_seqnext(d, '}')) return false; if (jsondec_peek(d) != JD_STRING) { jsondec_err(d, "Object must start with string"); @@ -7183,8 +8970,8 @@ static bool jsondec_objnext(jsondec *d) { /* JSON number ****************************************************************/ -static bool jsondec_tryskipdigits(jsondec *d) { - const char *start = d->ptr; +static bool jsondec_tryskipdigits(jsondec* d) { + const char* start = d->ptr; while (d->ptr < d->end) { if (*d->ptr < '0' || *d->ptr > '9') { @@ -7196,14 +8983,14 @@ static bool jsondec_tryskipdigits(jsondec *d) { return d->ptr != start; } -static void jsondec_skipdigits(jsondec *d) { +static void jsondec_skipdigits(jsondec* d) { if (!jsondec_tryskipdigits(d)) { jsondec_err(d, "Expected one or more digits"); } } -static double jsondec_number(jsondec *d) { - const char *start = d->ptr; +static double jsondec_number(jsondec* d) { + const char* start = d->ptr; assert(jsondec_rawpeek(d) == JD_NUMBER); @@ -7263,7 +9050,7 @@ parse: /* JSON string ****************************************************************/ -static char jsondec_escape(jsondec *d) { +static char jsondec_escape(jsondec* d) { switch (*d->ptr++) { case '"': return '\"'; @@ -7286,9 +9073,9 @@ static char jsondec_escape(jsondec *d) { } } -static uint32_t jsondec_codepoint(jsondec *d) { +static uint32_t jsondec_codepoint(jsondec* d) { uint32_t cp = 0; - const char *end; + const char* end; if (d->end - d->ptr < 4) { jsondec_err(d, "EOF inside string"); @@ -7313,7 +9100,7 @@ static uint32_t jsondec_codepoint(jsondec *d) { } /* Parses a \uXXXX unicode escape (possibly a surrogate pair). */ -static size_t jsondec_unicode(jsondec *d, char* out) { +static size_t jsondec_unicode(jsondec* d, char* out) { uint32_t cp = jsondec_codepoint(d); if (cp >= 0xd800 && cp <= 0xdbff) { /* Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. */ @@ -7355,22 +9142,22 @@ static size_t jsondec_unicode(jsondec *d, char* out) { } } -static void jsondec_resize(jsondec *d, char **buf, char **end, char **buf_end) { +static void jsondec_resize(jsondec* d, char** buf, char** end, char** buf_end) { size_t oldsize = *buf_end - *buf; size_t len = *end - *buf; size_t size = UPB_MAX(8, 2 * oldsize); - *buf = upb_arena_realloc(d->arena, *buf, len, size); + *buf = upb_Arena_Realloc(d->arena, *buf, len, size); if (!*buf) jsondec_err(d, "Out of memory"); *end = *buf + len; *buf_end = *buf + size; } -static upb_strview jsondec_string(jsondec *d) { - char *buf = NULL; - char *end = NULL; - char *buf_end = NULL; +static upb_StringView jsondec_string(jsondec* d) { + char* buf = NULL; + char* end = NULL; + char* buf_end = NULL; jsondec_skipws(d); @@ -7387,10 +9174,10 @@ static upb_strview jsondec_string(jsondec *d) { switch (ch) { case '"': { - upb_strview ret; + upb_StringView ret; ret.data = buf; ret.size = end - buf; - *end = '\0'; /* Needed for possible strtod(). */ + *end = '\0'; /* Needed for possible strtod(). */ return ret; } case '\\': @@ -7419,7 +9206,7 @@ eof: jsondec_err(d, "EOF inside string"); } -static void jsondec_skipval(jsondec *d) { +static void jsondec_skipval(jsondec* d) { switch (jsondec_peek(d)) { case JD_OBJECT: jsondec_objstart(d); @@ -7502,8 +9289,8 @@ static unsigned int jsondec_base64_tablelookup(const char ch) { return table[(unsigned)ch]; } -static char *jsondec_partialbase64(jsondec *d, const char *ptr, const char *end, - char *out) { +static char* jsondec_partialbase64(jsondec* d, const char* ptr, const char* end, + char* out) { int32_t val = -1; switch (end - ptr) { @@ -7530,13 +9317,13 @@ static char *jsondec_partialbase64(jsondec *d, const char *ptr, const char *end, return out; } -static size_t jsondec_base64(jsondec *d, upb_strview str) { +static size_t jsondec_base64(jsondec* d, upb_StringView str) { /* We decode in place. This is safe because this is a new buffer (not * aliasing the input) and because base64 decoding shrinks 4 bytes into 3. */ - char *out = (char*)str.data; - const char *ptr = str.data; - const char *end = ptr + str.size; - const char *end4 = ptr + (str.size & -4); /* Round down to multiple of 4. */ + char* out = (char*)str.data; + const char* ptr = str.data; + const char* end = ptr + str.size; + const char* end4 = ptr + (str.size & -4); /* Round down to multiple of 4. */ for (; ptr < end4; ptr += 4, out += 3) { int val = jsondec_base64_tablelookup(ptr[0]) << 18 | @@ -7574,8 +9361,8 @@ static size_t jsondec_base64(jsondec *d, upb_strview str) { /* We use these hand-written routines instead of strto[u]l() because the "long * long" variants aren't in c89. Also our version allows setting a ptr limit. */ -static const char *jsondec_buftouint64(jsondec *d, const char *ptr, - const char *end, uint64_t *val) { +static const char* jsondec_buftouint64(jsondec* d, const char* ptr, + const char* end, uint64_t* val) { uint64_t u64 = 0; while (ptr < end) { unsigned ch = *ptr - '0'; @@ -7592,8 +9379,8 @@ static const char *jsondec_buftouint64(jsondec *d, const char *ptr, return ptr; } -static const char *jsondec_buftoint64(jsondec *d, const char *ptr, - const char *end, int64_t *val) { +static const char* jsondec_buftoint64(jsondec* d, const char* ptr, + const char* end, int64_t* val) { bool neg = false; uint64_t u64; @@ -7611,8 +9398,8 @@ static const char *jsondec_buftoint64(jsondec *d, const char *ptr, return ptr; } -static uint64_t jsondec_strtouint64(jsondec *d, upb_strview str) { - const char *end = str.data + str.size; +static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { + const char* end = str.data + str.size; uint64_t ret; if (jsondec_buftouint64(d, str.data, end, &ret) != end) { jsondec_err(d, "Non-number characters in quoted integer"); @@ -7620,8 +9407,8 @@ static uint64_t jsondec_strtouint64(jsondec *d, upb_strview str) { return ret; } -static int64_t jsondec_strtoint64(jsondec *d, upb_strview str) { - const char *end = str.data + str.size; +static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) { + const char* end = str.data + str.size; int64_t ret; if (jsondec_buftoint64(d, str.data, end, &ret) != end) { jsondec_err(d, "Non-number characters in quoted integer"); @@ -7632,8 +9419,8 @@ static int64_t jsondec_strtoint64(jsondec *d, upb_strview str) { /* Primitive value types ******************************************************/ /* Parse INT32 or INT64 value. */ -static upb_msgval jsondec_int(jsondec *d, const upb_fielddef *f) { - upb_msgval val; +static upb_MessageValue jsondec_int(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val; switch (jsondec_peek(d)) { case JD_NUMBER: { @@ -7641,7 +9428,7 @@ static upb_msgval jsondec_int(jsondec *d, const upb_fielddef *f) { if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) { jsondec_err(d, "JSON number is out of range."); } - val.int64_val = dbl; /* must be guarded, overflow here is UB */ + val.int64_val = dbl; /* must be guarded, overflow here is UB */ if (val.int64_val != dbl) { jsondec_errf(d, "JSON number was not integral (%f != %" PRId64 ")", dbl, val.int64_val); @@ -7649,7 +9436,7 @@ static upb_msgval jsondec_int(jsondec *d, const upb_fielddef *f) { break; } case JD_STRING: { - upb_strview str = jsondec_string(d); + upb_StringView str = jsondec_string(d); val.int64_val = jsondec_strtoint64(d, str); break; } @@ -7657,7 +9444,8 @@ static upb_msgval jsondec_int(jsondec *d, const upb_fielddef *f) { jsondec_err(d, "Expected number or string"); } - if (upb_fielddef_type(f) == UPB_TYPE_INT32) { + if (upb_FieldDef_CType(f) == kUpb_CType_Int32 || + upb_FieldDef_CType(f) == kUpb_CType_Enum) { if (val.int64_val > INT32_MAX || val.int64_val < INT32_MIN) { jsondec_err(d, "Integer out of range."); } @@ -7668,8 +9456,8 @@ static upb_msgval jsondec_int(jsondec *d, const upb_fielddef *f) { } /* Parse UINT32 or UINT64 value. */ -static upb_msgval jsondec_uint(jsondec *d, const upb_fielddef *f) { - upb_msgval val = {0}; +static upb_MessageValue jsondec_uint(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val = {0}; switch (jsondec_peek(d)) { case JD_NUMBER: { @@ -7677,7 +9465,7 @@ static upb_msgval jsondec_uint(jsondec *d, const upb_fielddef *f) { if (dbl > 18446744073709549568.0 || dbl < 0) { jsondec_err(d, "JSON number is out of range."); } - val.uint64_val = dbl; /* must be guarded, overflow here is UB */ + val.uint64_val = dbl; /* must be guarded, overflow here is UB */ if (val.uint64_val != dbl) { jsondec_errf(d, "JSON number was not integral (%f != %" PRIu64 ")", dbl, val.uint64_val); @@ -7685,7 +9473,7 @@ static upb_msgval jsondec_uint(jsondec *d, const upb_fielddef *f) { break; } case JD_STRING: { - upb_strview str = jsondec_string(d); + upb_StringView str = jsondec_string(d); val.uint64_val = jsondec_strtouint64(d, str); break; } @@ -7693,7 +9481,7 @@ static upb_msgval jsondec_uint(jsondec *d, const upb_fielddef *f) { jsondec_err(d, "Expected number or string"); } - if (upb_fielddef_type(f) == UPB_TYPE_UINT32) { + if (upb_FieldDef_CType(f) == kUpb_CType_UInt32) { if (val.uint64_val > UINT32_MAX) { jsondec_err(d, "Integer out of range."); } @@ -7704,9 +9492,9 @@ static upb_msgval jsondec_uint(jsondec *d, const upb_fielddef *f) { } /* Parse DOUBLE or FLOAT value. */ -static upb_msgval jsondec_double(jsondec *d, const upb_fielddef *f) { - upb_strview str; - upb_msgval val = {0}; +static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) { + upb_StringView str; + upb_MessageValue val = {0}; switch (jsondec_peek(d)) { case JD_NUMBER: @@ -7728,7 +9516,7 @@ static upb_msgval jsondec_double(jsondec *d, const upb_fielddef *f) { jsondec_err(d, "Expected number or string"); } - if (upb_fielddef_type(f) == UPB_TYPE_FLOAT) { + if (upb_FieldDef_CType(f) == kUpb_CType_Float) { if (val.double_val != INFINITY && val.double_val != -INFINITY && (val.double_val > FLT_MAX || val.double_val < -FLT_MAX)) { jsondec_err(d, "Float out of range"); @@ -7740,34 +9528,38 @@ static upb_msgval jsondec_double(jsondec *d, const upb_fielddef *f) { } /* Parse STRING or BYTES value. */ -static upb_msgval jsondec_strfield(jsondec *d, const upb_fielddef *f) { - upb_msgval val; +static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val; val.str_val = jsondec_string(d); - if (upb_fielddef_type(f) == UPB_TYPE_BYTES) { + if (upb_FieldDef_CType(f) == kUpb_CType_Bytes) { val.str_val.size = jsondec_base64(d, val.str_val); } return val; } -static upb_msgval jsondec_enum(jsondec *d, const upb_fielddef *f) { +static upb_MessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { switch (jsondec_peek(d)) { case JD_STRING: { - const upb_enumdef *e = upb_fielddef_enumsubdef(f); - upb_strview str = jsondec_string(d); - upb_msgval val; - if (!upb_enumdef_ntoi(e, str.data, str.size, &val.int32_val)) { - if (d->options & UPB_JSONDEC_IGNOREUNKNOWN) { + upb_StringView str = jsondec_string(d); + const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); + const upb_EnumValueDef* ev = + upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); + upb_MessageValue val; + if (ev) { + val.int32_val = upb_EnumValueDef_Number(ev); + } else { + if (d->options & upb_JsonDecode_IgnoreUnknown) { val.int32_val = 0; } else { - jsondec_errf(d, "Unknown enumerator: '" UPB_STRVIEW_FORMAT "'", - UPB_STRVIEW_ARGS(str)); + jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(str)); } } return val; } case JD_NULL: { if (jsondec_isnullvalue(f)) { - upb_msgval val; + upb_MessageValue val; jsondec_null(d); val.int32_val = 0; return val; @@ -7779,13 +9571,13 @@ static upb_msgval jsondec_enum(jsondec *d, const upb_fielddef *f) { } } -static upb_msgval jsondec_bool(jsondec *d, const upb_fielddef *f) { - bool is_map_key = upb_fielddef_number(f) == 1 && - upb_msgdef_mapentry(upb_fielddef_containingtype(f)); - upb_msgval val; +static upb_MessageValue jsondec_bool(jsondec* d, const upb_FieldDef* f) { + bool is_map_key = upb_FieldDef_Number(f) == 1 && + upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f)); + upb_MessageValue val; if (is_map_key) { - upb_strview str = jsondec_string(d); + upb_StringView str = jsondec_string(d); if (jsondec_streql(str, "true")) { val.bool_val = true; } else if (jsondec_streql(str, "false")) { @@ -7813,65 +9605,83 @@ static upb_msgval jsondec_bool(jsondec *d, const upb_fielddef *f) { /* Composite types (array/message/map) ****************************************/ -static void jsondec_array(jsondec *d, upb_msg *msg, const upb_fielddef *f) { - upb_array *arr = upb_msg_mutable(msg, f, d->arena).array; +static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { + upb_Array* arr = upb_Message_Mutable(msg, f, d->arena).array; jsondec_arrstart(d); while (jsondec_arrnext(d)) { - upb_msgval elem = jsondec_value(d, f); - upb_array_append(arr, elem, d->arena); + upb_MessageValue elem = jsondec_value(d, f); + upb_Array_Append(arr, elem, d->arena); } jsondec_arrend(d); } -static void jsondec_map(jsondec *d, upb_msg *msg, const upb_fielddef *f) { - upb_map *map = upb_msg_mutable(msg, f, d->arena).map; - const upb_msgdef *entry = upb_fielddef_msgsubdef(f); - const upb_fielddef *key_f = upb_msgdef_itof(entry, 1); - const upb_fielddef *val_f = upb_msgdef_itof(entry, 2); +static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { + upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map; + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key_f = + upb_MessageDef_FindFieldByNumberWithSize(entry, 1); + const upb_FieldDef* val_f = + upb_MessageDef_FindFieldByNumberWithSize(entry, 2); jsondec_objstart(d); while (jsondec_objnext(d)) { - upb_msgval key, val; + upb_MessageValue key, val; key = jsondec_value(d, key_f); jsondec_entrysep(d); val = jsondec_value(d, val_f); - upb_map_set(map, key, val, d->arena); + upb_Map_Set(map, key, val, d->arena); } jsondec_objend(d); } -static void jsondec_tomsg(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - if (upb_msgdef_wellknowntype(m) == UPB_WELLKNOWN_UNSPECIFIED) { +static void jsondec_tomsg(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { jsondec_object(d, msg, m); } else { jsondec_wellknown(d, msg, m); } } -static upb_msgval jsondec_msg(jsondec *d, const upb_fielddef *f) { - const upb_msgdef *m = upb_fielddef_msgsubdef(f); - upb_msg *msg = upb_msg_new(m, d->arena); - upb_msgval val; +static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { + const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); + upb_Message* msg = upb_Message_New(m, d->arena); + upb_MessageValue val; jsondec_tomsg(d, msg, m); val.msg_val = msg; return val; } -static void jsondec_field(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - upb_strview name; - const upb_fielddef *f; - const upb_fielddef *preserved; +static void jsondec_field(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_StringView name; + const upb_FieldDef* f; + const upb_FieldDef* preserved; name = jsondec_string(d); jsondec_entrysep(d); - f = upb_msgdef_lookupjsonname(m, name.data, name.size); + + if (name.size >= 2 && name.data[0] == '[' && + name.data[name.size - 1] == ']') { + f = upb_DefPool_FindExtensionByNameWithSize(d->symtab, name.data + 1, + name.size - 2); + if (f && upb_FieldDef_ContainingType(f) != m) { + jsondec_errf( + d, "Extension %s extends message %s, but was seen in message %s", + upb_FieldDef_FullName(f), + upb_MessageDef_FullName(upb_FieldDef_ContainingType(f)), + upb_MessageDef_FullName(m)); + } + } else { + f = upb_MessageDef_FindByJsonNameWithSize(m, name.data, name.size); + } if (!f) { - if ((d->options & UPB_JSONDEC_IGNOREUNKNOWN) == 0) { - jsondec_errf(d, "No such field: " UPB_STRVIEW_FORMAT, - UPB_STRVIEW_ARGS(name)); + if ((d->options & upb_JsonDecode_IgnoreUnknown) == 0) { + jsondec_errf(d, "No such field: " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(name)); } jsondec_skipval(d); return; @@ -7883,31 +9693,32 @@ static void jsondec_field(jsondec *d, upb_msg *msg, const upb_msgdef *m) { return; } - if (upb_fielddef_realcontainingoneof(f) && - upb_msg_whichoneof(msg, upb_fielddef_containingoneof(f))) { + if (upb_FieldDef_RealContainingOneof(f) && + upb_Message_WhichOneof(msg, upb_FieldDef_ContainingOneof(f))) { jsondec_err(d, "More than one field for this oneof."); } preserved = d->debug_field; d->debug_field = f; - if (upb_fielddef_ismap(f)) { + if (upb_FieldDef_IsMap(f)) { jsondec_map(d, msg, f); - } else if (upb_fielddef_isseq(f)) { + } else if (upb_FieldDef_IsRepeated(f)) { jsondec_array(d, msg, f); - } else if (upb_fielddef_issubmsg(f)) { - upb_msg *submsg = upb_msg_mutable(msg, f, d->arena).msg; - const upb_msgdef *subm = upb_fielddef_msgsubdef(f); + } else if (upb_FieldDef_IsSubMessage(f)) { + upb_Message* submsg = upb_Message_Mutable(msg, f, d->arena).msg; + const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); jsondec_tomsg(d, submsg, subm); } else { - upb_msgval val = jsondec_value(d, f); - upb_msg_set(msg, f, val, d->arena); + upb_MessageValue val = jsondec_value(d, f); + upb_Message_Set(msg, f, val, d->arena); } d->debug_field = preserved; } -static void jsondec_object(jsondec *d, upb_msg *msg, const upb_msgdef *m) { +static void jsondec_object(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { jsondec_objstart(d); while (jsondec_objnext(d)) { jsondec_field(d, msg, m); @@ -7915,25 +9726,25 @@ static void jsondec_object(jsondec *d, upb_msg *msg, const upb_msgdef *m) { jsondec_objend(d); } -static upb_msgval jsondec_value(jsondec *d, const upb_fielddef *f) { - switch (upb_fielddef_type(f)) { - case UPB_TYPE_BOOL: +static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: return jsondec_bool(d, f); - case UPB_TYPE_FLOAT: - case UPB_TYPE_DOUBLE: + case kUpb_CType_Float: + case kUpb_CType_Double: return jsondec_double(d, f); - case UPB_TYPE_UINT32: - case UPB_TYPE_UINT64: + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: return jsondec_uint(d, f); - case UPB_TYPE_INT32: - case UPB_TYPE_INT64: + case kUpb_CType_Int32: + case kUpb_CType_Int64: return jsondec_int(d, f); - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: + case kUpb_CType_String: + case kUpb_CType_Bytes: return jsondec_strfield(d, f); - case UPB_TYPE_ENUM: + case kUpb_CType_Enum: return jsondec_enum(d, f); - case UPB_TYPE_MESSAGE: + case kUpb_CType_Message: return jsondec_msg(d, f); default: UPB_UNREACHABLE(); @@ -7942,14 +9753,14 @@ static upb_msgval jsondec_value(jsondec *d, const upb_fielddef *f) { /* Well-known types ***********************************************************/ -static int jsondec_tsdigits(jsondec *d, const char **ptr, size_t digits, - const char *after) { +static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, + const char* after) { uint64_t val; - const char *p = *ptr; - const char *end = p + digits; + const char* p = *ptr; + const char* end = p + digits; size_t after_len = after ? strlen(after) : 0; - UPB_ASSERT(digits <= 9); /* int can't overflow. */ + UPB_ASSERT(digits <= 9); /* int can't overflow. */ if (jsondec_buftouint64(d, p, end, &val) != end || (after_len && memcmp(end, after, after_len) != 0)) { @@ -7962,12 +9773,12 @@ static int jsondec_tsdigits(jsondec *d, const char **ptr, size_t digits, return (int)val; } -static int jsondec_nanos(jsondec *d, const char **ptr, const char *end) { +static int jsondec_nanos(jsondec* d, const char** ptr, const char* end) { uint64_t nanos = 0; - const char *p = *ptr; + const char* p = *ptr; if (p != end && *p == '.') { - const char *nano_end = jsondec_buftouint64(d, p + 1, end, &nanos); + const char* nano_end = jsondec_buftouint64(d, p + 1, end, &nanos); int digits = (int)(nano_end - p - 1); int exp_lg10 = 9 - digits; if (digits > 9) { @@ -7984,8 +9795,8 @@ static int jsondec_nanos(jsondec *d, const char **ptr, const char *end) { /* jsondec_epochdays(1970, 1, 1) == 1970-01-01 == 0. */ int jsondec_epochdays(int y, int m, int d) { - const uint32_t year_base = 4800; /* Before min year, multiple of 400. */ - const uint32_t m_adj = m - 3; /* March-based month. */ + const uint32_t year_base = 4800; /* Before min year, multiple of 400. */ + const uint32_t m_adj = m - 3; /* March-based month. */ const uint32_t carry = m_adj > (uint32_t)m ? 1 : 0; const uint32_t adjust = carry ? 12 : 0; const uint32_t y_adj = y + year_base - carry; @@ -7998,12 +9809,13 @@ static int64_t jsondec_unixtime(int y, int m, int d, int h, int min, int s) { return (int64_t)jsondec_epochdays(y, m, d) * 86400 + h * 3600 + min * 60 + s; } -static void jsondec_timestamp(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - upb_msgval seconds; - upb_msgval nanos; - upb_strview str = jsondec_string(d); - const char *ptr = str.data; - const char *end = ptr + str.size; +static void jsondec_timestamp(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue seconds; + upb_MessageValue nanos; + upb_StringView str = jsondec_string(d); + const char* ptr = str.data; + const char* end = ptr + str.size; if (str.size < 20) goto malformed; @@ -8052,20 +9864,23 @@ static void jsondec_timestamp(jsondec *d, upb_msg *msg, const upb_msgdef *m) { jsondec_err(d, "Timestamp out of range"); } - upb_msg_set(msg, upb_msgdef_itof(m, 1), seconds, d->arena); - upb_msg_set(msg, upb_msgdef_itof(m, 2), nanos, d->arena); + upb_Message_Set(msg, upb_MessageDef_FindFieldByNumberWithSize(m, 1), seconds, + d->arena); + upb_Message_Set(msg, upb_MessageDef_FindFieldByNumberWithSize(m, 2), nanos, + d->arena); return; malformed: jsondec_err(d, "Malformed timestamp"); } -static void jsondec_duration(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - upb_msgval seconds; - upb_msgval nanos; - upb_strview str = jsondec_string(d); - const char *ptr = str.data; - const char *end = ptr + str.size; +static void jsondec_duration(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue seconds; + upb_MessageValue nanos; + upb_StringView str = jsondec_string(d); + const char* ptr = str.data; + const char* end = ptr + str.size; const int64_t max = (uint64_t)3652500 * 86400; /* "3.000000001s", "3s", etc. */ @@ -8081,110 +9896,116 @@ static void jsondec_duration(jsondec *d, upb_msg *msg, const upb_msgdef *m) { } if (seconds.int64_val < 0) { - nanos.int32_val = - nanos.int32_val; + nanos.int32_val = -nanos.int32_val; } - upb_msg_set(msg, upb_msgdef_itof(m, 1), seconds, d->arena); - upb_msg_set(msg, upb_msgdef_itof(m, 2), nanos, d->arena); + upb_Message_Set(msg, upb_MessageDef_FindFieldByNumberWithSize(m, 1), seconds, + d->arena); + upb_Message_Set(msg, upb_MessageDef_FindFieldByNumberWithSize(m, 2), nanos, + d->arena); } -static void jsondec_listvalue(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - const upb_fielddef *values_f = upb_msgdef_itof(m, 1); - const upb_msgdef *value_m = upb_fielddef_msgsubdef(values_f); - upb_array *values = upb_msg_mutable(msg, values_f, d->arena).array; +static void jsondec_listvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); + upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array; jsondec_arrstart(d); while (jsondec_arrnext(d)) { - upb_msg *value_msg = upb_msg_new(value_m, d->arena); - upb_msgval value; + upb_Message* value_msg = upb_Message_New(value_m, d->arena); + upb_MessageValue value; value.msg_val = value_msg; - upb_array_append(values, value, d->arena); + upb_Array_Append(values, value, d->arena); jsondec_wellknownvalue(d, value_msg, value_m); } jsondec_arrend(d); } -static void jsondec_struct(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - const upb_fielddef *fields_f = upb_msgdef_itof(m, 1); - const upb_msgdef *entry_m = upb_fielddef_msgsubdef(fields_f); - const upb_fielddef *value_f = upb_msgdef_itof(entry_m, 2); - const upb_msgdef *value_m = upb_fielddef_msgsubdef(value_f); - upb_map *fields = upb_msg_mutable(msg, fields_f, d->arena).map; +static void jsondec_struct(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); + const upb_FieldDef* value_f = + upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2); + const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f); + upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map; jsondec_objstart(d); while (jsondec_objnext(d)) { - upb_msgval key, value; - upb_msg *value_msg = upb_msg_new(value_m, d->arena); + upb_MessageValue key, value; + upb_Message* value_msg = upb_Message_New(value_m, d->arena); key.str_val = jsondec_string(d); value.msg_val = value_msg; - upb_map_set(fields, key, value, d->arena); + upb_Map_Set(fields, key, value, d->arena); jsondec_entrysep(d); jsondec_wellknownvalue(d, value_msg, value_m); } jsondec_objend(d); } -static void jsondec_wellknownvalue(jsondec *d, upb_msg *msg, - const upb_msgdef *m) { - upb_msgval val; - const upb_fielddef *f; - upb_msg *submsg; +static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue val; + const upb_FieldDef* f; + upb_Message* submsg; switch (jsondec_peek(d)) { case JD_NUMBER: /* double number_value = 2; */ - f = upb_msgdef_itof(m, 2); + f = upb_MessageDef_FindFieldByNumberWithSize(m, 2); val.double_val = jsondec_number(d); break; case JD_STRING: /* string string_value = 3; */ - f = upb_msgdef_itof(m, 3); + f = upb_MessageDef_FindFieldByNumberWithSize(m, 3); val.str_val = jsondec_string(d); break; case JD_FALSE: /* bool bool_value = 4; */ - f = upb_msgdef_itof(m, 4); + f = upb_MessageDef_FindFieldByNumberWithSize(m, 4); val.bool_val = false; jsondec_false(d); break; case JD_TRUE: /* bool bool_value = 4; */ - f = upb_msgdef_itof(m, 4); + f = upb_MessageDef_FindFieldByNumberWithSize(m, 4); val.bool_val = true; jsondec_true(d); break; case JD_NULL: /* NullValue null_value = 1; */ - f = upb_msgdef_itof(m, 1); + f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); val.int32_val = 0; jsondec_null(d); break; - /* Note: these cases return, because upb_msg_mutable() is enough. */ + /* Note: these cases return, because upb_Message_Mutable() is enough. */ case JD_OBJECT: /* Struct struct_value = 5; */ - f = upb_msgdef_itof(m, 5); - submsg = upb_msg_mutable(msg, f, d->arena).msg; - jsondec_struct(d, submsg, upb_fielddef_msgsubdef(f)); + f = upb_MessageDef_FindFieldByNumberWithSize(m, 5); + submsg = upb_Message_Mutable(msg, f, d->arena).msg; + jsondec_struct(d, submsg, upb_FieldDef_MessageSubDef(f)); return; case JD_ARRAY: /* ListValue list_value = 6; */ - f = upb_msgdef_itof(m, 6); - submsg = upb_msg_mutable(msg, f, d->arena).msg; - jsondec_listvalue(d, submsg, upb_fielddef_msgsubdef(f)); + f = upb_MessageDef_FindFieldByNumberWithSize(m, 6); + submsg = upb_Message_Mutable(msg, f, d->arena).msg; + jsondec_listvalue(d, submsg, upb_FieldDef_MessageSubDef(f)); return; default: UPB_UNREACHABLE(); } - upb_msg_set(msg, f, val, d->arena); + upb_Message_Set(msg, f, val, d->arena); } -static upb_strview jsondec_mask(jsondec *d, const char *buf, const char *end) { +static upb_StringView jsondec_mask(jsondec* d, const char* buf, + const char* end) { /* FieldMask fields grow due to inserted '_' characters, so we can't do the * transform in place. */ - const char *ptr = buf; - upb_strview ret; - char *out; + const char* ptr = buf; + upb_StringView ret; + char* out; ret.size = end - ptr; while (ptr < end) { @@ -8192,7 +10013,7 @@ static upb_strview jsondec_mask(jsondec *d, const char *buf, const char *end) { ptr++; } - out = upb_arena_malloc(d->arena, ret.size); + out = upb_Arena_Malloc(d->arena, ret.size); ptr = buf; ret.data = out; @@ -8211,17 +10032,18 @@ static upb_strview jsondec_mask(jsondec *d, const char *buf, const char *end) { return ret; } -static void jsondec_fieldmask(jsondec *d, upb_msg *msg, const upb_msgdef *m) { +static void jsondec_fieldmask(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { /* repeated string paths = 1; */ - const upb_fielddef *paths_f = upb_msgdef_itof(m, 1); - upb_array *arr = upb_msg_mutable(msg, paths_f, d->arena).array; - upb_strview str = jsondec_string(d); - const char *ptr = str.data; - const char *end = ptr + str.size; - upb_msgval val; + const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array; + upb_StringView str = jsondec_string(d); + const char* ptr = str.data; + const char* end = ptr + str.size; + upb_MessageValue val; while (ptr < end) { - const char *elem_end = memchr(ptr, ',', end - ptr); + const char* elem_end = memchr(ptr, ',', end - ptr); if (elem_end) { val.str_val = jsondec_mask(d, ptr, elem_end); ptr = elem_end + 1; @@ -8229,19 +10051,20 @@ static void jsondec_fieldmask(jsondec *d, upb_msg *msg, const upb_msgdef *m) { val.str_val = jsondec_mask(d, ptr, end); ptr = end; } - upb_array_append(arr, val, d->arena); + upb_Array_Append(arr, val, d->arena); } } -static void jsondec_anyfield(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - if (upb_msgdef_wellknowntype(m) == UPB_WELLKNOWN_UNSPECIFIED) { +static void jsondec_anyfield(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { /* For regular types: {"@type": "[user type]", "f1": , "f2": } * where f1, f2, etc. are the normal fields of this type. */ jsondec_field(d, msg, m); } else { /* For well-known types: {"@type": "[well-known type]", "value": } * where is whatever encoding the WKT normally uses. */ - upb_strview str = jsondec_string(d); + upb_StringView str = jsondec_string(d); jsondec_entrysep(d); if (!jsondec_streql(str, "value")) { jsondec_err(d, "Key for well-known type must be 'value'"); @@ -8250,27 +10073,29 @@ static void jsondec_anyfield(jsondec *d, upb_msg *msg, const upb_msgdef *m) { } } -static const upb_msgdef *jsondec_typeurl(jsondec *d, upb_msg *msg, - const upb_msgdef *m) { - const upb_fielddef *type_url_f = upb_msgdef_itof(m, 1); - const upb_msgdef *type_m; - upb_strview type_url = jsondec_string(d); - const char *end = type_url.data + type_url.size; - const char *ptr = end; - upb_msgval val; +static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* type_url_f = + upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_MessageDef* type_m; + upb_StringView type_url = jsondec_string(d); + const char* end = type_url.data + type_url.size; + const char* ptr = end; + upb_MessageValue val; val.str_val = type_url; - upb_msg_set(msg, type_url_f, val, d->arena); + upb_Message_Set(msg, type_url_f, val, d->arena); /* Find message name after the last '/' */ - while (ptr > type_url.data && *--ptr != '/') {} + while (ptr > type_url.data && *--ptr != '/') { + } if (ptr == type_url.data || ptr == end) { jsondec_err(d, "Type url must have at least one '/' and non-empty host"); } ptr++; - type_m = upb_symtab_lookupmsg2(d->any_pool, ptr, end - ptr); + type_m = upb_DefPool_FindMessageByNameWithSize(d->symtab, ptr, end - ptr); if (!type_m) { jsondec_err(d, "Type was not found"); @@ -8279,22 +10104,22 @@ static const upb_msgdef *jsondec_typeurl(jsondec *d, upb_msg *msg, return type_m; } -static void jsondec_any(jsondec *d, upb_msg *msg, const upb_msgdef *m) { +static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { /* string type_url = 1; * bytes value = 2; */ - const upb_fielddef *value_f = upb_msgdef_itof(m, 2); - upb_msg *any_msg; - const upb_msgdef *any_m = NULL; - const char *pre_type_data = NULL; - const char *pre_type_end = NULL; - upb_msgval encoded; + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumberWithSize(m, 2); + upb_Message* any_msg; + const upb_MessageDef* any_m = NULL; + const char* pre_type_data = NULL; + const char* pre_type_end = NULL; + upb_MessageValue encoded; jsondec_objstart(d); /* Scan looking for "@type", which is not necessarily first. */ while (!any_m && jsondec_objnext(d)) { - const char *start = d->ptr; - upb_strview name = jsondec_string(d); + const char* start = d->ptr; + upb_StringView name = jsondec_string(d); jsondec_entrysep(d); if (jsondec_streql(name, "@type")) { any_m = jsondec_typeurl(d, msg, m); @@ -8312,13 +10137,13 @@ static void jsondec_any(jsondec *d, upb_msg *msg, const upb_msgdef *m) { jsondec_err(d, "Any object didn't contain a '@type' field"); } - any_msg = upb_msg_new(any_m, d->arena); + any_msg = upb_Message_New(any_m, d->arena); if (pre_type_data) { size_t len = pre_type_end - pre_type_data + 1; - char *tmp = upb_arena_malloc(d->arena, len); - const char *saved_ptr = d->ptr; - const char *saved_end = d->end; + char* tmp = upb_Arena_Malloc(d->arena, len); + const char* saved_ptr = d->ptr; + const char* saved_end = d->end; memcpy(tmp, pre_type_data, len - 1); tmp[len - 1] = '}'; d->ptr = tmp; @@ -8337,49 +10162,51 @@ static void jsondec_any(jsondec *d, upb_msg *msg, const upb_msgdef *m) { jsondec_objend(d); - encoded.str_val.data = upb_encode(any_msg, upb_msgdef_layout(any_m), d->arena, - &encoded.str_val.size); - upb_msg_set(msg, value_f, encoded, d->arena); + encoded.str_val.data = upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, + d->arena, &encoded.str_val.size); + upb_Message_Set(msg, value_f, encoded, d->arena); } -static void jsondec_wrapper(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - const upb_fielddef *value_f = upb_msgdef_itof(m, 1); - upb_msgval val = jsondec_value(d, value_f); - upb_msg_set(msg, value_f, val, d->arena); +static void jsondec_wrapper(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + upb_MessageValue val = jsondec_value(d, value_f); + upb_Message_Set(msg, value_f, val, d->arena); } -static void jsondec_wellknown(jsondec *d, upb_msg *msg, const upb_msgdef *m) { - switch (upb_msgdef_wellknowntype(m)) { - case UPB_WELLKNOWN_ANY: +static void jsondec_wellknown(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + switch (upb_MessageDef_WellKnownType(m)) { + case kUpb_WellKnown_Any: jsondec_any(d, msg, m); break; - case UPB_WELLKNOWN_FIELDMASK: + case kUpb_WellKnown_FieldMask: jsondec_fieldmask(d, msg, m); break; - case UPB_WELLKNOWN_DURATION: + case kUpb_WellKnown_Duration: jsondec_duration(d, msg, m); break; - case UPB_WELLKNOWN_TIMESTAMP: + case kUpb_WellKnown_Timestamp: jsondec_timestamp(d, msg, m); break; - case UPB_WELLKNOWN_VALUE: + case kUpb_WellKnown_Value: jsondec_wellknownvalue(d, msg, m); break; - case UPB_WELLKNOWN_LISTVALUE: + case kUpb_WellKnown_ListValue: jsondec_listvalue(d, msg, m); break; - case UPB_WELLKNOWN_STRUCT: + case kUpb_WellKnown_Struct: jsondec_struct(d, msg, m); break; - case UPB_WELLKNOWN_DOUBLEVALUE: - case UPB_WELLKNOWN_FLOATVALUE: - case UPB_WELLKNOWN_INT64VALUE: - case UPB_WELLKNOWN_UINT64VALUE: - case UPB_WELLKNOWN_INT32VALUE: - case UPB_WELLKNOWN_UINT32VALUE: - case UPB_WELLKNOWN_STRINGVALUE: - case UPB_WELLKNOWN_BYTESVALUE: - case UPB_WELLKNOWN_BOOLVALUE: + case kUpb_WellKnown_DoubleValue: + case kUpb_WellKnown_FloatValue: + case kUpb_WellKnown_Int64Value: + case kUpb_WellKnown_UInt64Value: + case kUpb_WellKnown_Int32Value: + case kUpb_WellKnown_UInt32Value: + case kUpb_WellKnown_StringValue: + case kUpb_WellKnown_BytesValue: + case kUpb_WellKnown_BoolValue: jsondec_wrapper(d, msg, m); break; default: @@ -8387,9 +10214,9 @@ static void jsondec_wellknown(jsondec *d, upb_msg *msg, const upb_msgdef *m) { } } -bool upb_json_decode(const char *buf, size_t size, upb_msg *msg, - const upb_msgdef *m, const upb_symtab *any_pool, - int options, upb_arena *arena, upb_status *status) { +bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, + const upb_MessageDef* m, const upb_DefPool* symtab, + int options, upb_Arena* arena, upb_Status* status) { jsondec d; if (size == 0) return true; @@ -8397,7 +10224,7 @@ bool upb_json_decode(const char *buf, size_t size, upb_msg *msg, d.ptr = buf; d.end = buf + size; d.arena = arena; - d.any_pool = any_pool; + d.symtab = symtab; d.status = status; d.options = options; d.depth = 64; @@ -8431,43 +10258,46 @@ typedef struct { size_t overflow; int indent_depth; int options; - const upb_symtab *ext_pool; + const upb_DefPool* ext_pool; jmp_buf err; - upb_status *status; - upb_arena *arena; + upb_Status* status; + upb_Arena* arena; } jsonenc; -static void jsonenc_msg(jsonenc *e, const upb_msg *msg, const upb_msgdef *m); -static void jsonenc_scalar(jsonenc *e, upb_msgval val, const upb_fielddef *f); -static void jsonenc_msgfield(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m); -static void jsonenc_msgfields(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m, bool first); -static void jsonenc_value(jsonenc *e, const upb_msg *msg, const upb_msgdef *m); - -UPB_NORETURN static void jsonenc_err(jsonenc *e, const char *msg) { - upb_status_seterrmsg(e->status, msg); +static void jsonenc_msg(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); +static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f); +static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); +static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m, bool first); +static void jsonenc_value(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); + +UPB_NORETURN static void jsonenc_err(jsonenc* e, const char* msg) { + upb_Status_SetErrorMessage(e->status, msg); longjmp(e->err, 1); } UPB_PRINTF(2, 3) -UPB_NORETURN static void jsonenc_errf(jsonenc *e, const char *fmt, ...) { +UPB_NORETURN static void jsonenc_errf(jsonenc* e, const char* fmt, ...) { va_list argp; va_start(argp, fmt); - upb_status_vseterrf(e->status, fmt, argp); + upb_Status_VSetErrorFormat(e->status, fmt, argp); va_end(argp); longjmp(e->err, 1); } -static upb_arena *jsonenc_arena(jsonenc *e) { +static upb_Arena* jsonenc_arena(jsonenc* e) { /* Create lazily, since it's only needed for Any */ if (!e->arena) { - e->arena = upb_arena_new(); + e->arena = upb_Arena_New(); } return e->arena; } -static void jsonenc_putbytes(jsonenc *e, const void *data, size_t len) { +static void jsonenc_putbytes(jsonenc* e, const void* data, size_t len) { size_t have = e->end - e->ptr; if (UPB_LIKELY(have >= len)) { memcpy(e->ptr, data, len); @@ -8481,12 +10311,12 @@ static void jsonenc_putbytes(jsonenc *e, const void *data, size_t len) { } } -static void jsonenc_putstr(jsonenc *e, const char *str) { +static void jsonenc_putstr(jsonenc* e, const char* str) { jsonenc_putbytes(e, str, strlen(str)); } UPB_PRINTF(2, 3) -static void jsonenc_printf(jsonenc *e, const char *fmt, ...) { +static void jsonenc_printf(jsonenc* e, const char* fmt, ...) { size_t n; size_t have = e->end - e->ptr; va_list args; @@ -8503,7 +10333,7 @@ static void jsonenc_printf(jsonenc *e, const char *fmt, ...) { } } -static void jsonenc_nanos(jsonenc *e, int32_t nanos) { +static void jsonenc_nanos(jsonenc* e, int32_t nanos) { int digits = 9; if (nanos == 0) return; @@ -8519,12 +10349,13 @@ static void jsonenc_nanos(jsonenc *e, int32_t nanos) { jsonenc_printf(e, ".%.*" PRId32, digits, nanos); } -static void jsonenc_timestamp(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m) { - const upb_fielddef *seconds_f = upb_msgdef_itof(m, 1); - const upb_fielddef *nanos_f = upb_msgdef_itof(m, 2); - int64_t seconds = upb_msg_get(msg, seconds_f).int64_val; - int32_t nanos = upb_msg_get(msg, nanos_f).int32_val; +static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* seconds_f = + upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumberWithSize(m, 2); + int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val; + int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val; int L, N, I, J, K, hour, min, sec; if (seconds < -62135596800) { @@ -8561,11 +10392,13 @@ static void jsonenc_timestamp(jsonenc *e, const upb_msg *msg, jsonenc_putstr(e, "Z\""); } -static void jsonenc_duration(jsonenc *e, const upb_msg *msg, const upb_msgdef *m) { - const upb_fielddef *seconds_f = upb_msgdef_itof(m, 1); - const upb_fielddef *nanos_f = upb_msgdef_itof(m, 2); - int64_t seconds = upb_msg_get(msg, seconds_f).int64_val; - int32_t nanos = upb_msg_get(msg, nanos_f).int32_val; +static void jsonenc_duration(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* seconds_f = + upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumberWithSize(m, 2); + int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val; + int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val; if (seconds > 315576000000 || seconds < -315576000000 || (seconds < 0) != (nanos < 0)) { @@ -8581,28 +10414,28 @@ static void jsonenc_duration(jsonenc *e, const upb_msg *msg, const upb_msgdef *m jsonenc_putstr(e, "s\""); } -static void jsonenc_enum(int32_t val, const upb_fielddef *f, jsonenc *e) { - const upb_enumdef *e_def = upb_fielddef_enumsubdef(f); +static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) { + const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f); - if (strcmp(upb_enumdef_fullname(e_def), "google.protobuf.NullValue") == 0) { + if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) { jsonenc_putstr(e, "null"); } else { - const char *name = upb_enumdef_iton(e_def, val); + const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e_def, val); - if (name) { - jsonenc_printf(e, "\"%s\"", name); + if (ev) { + jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev)); } else { jsonenc_printf(e, "%" PRId32, val); } } } -static void jsonenc_bytes(jsonenc *e, upb_strview str) { +static void jsonenc_bytes(jsonenc* e, upb_StringView str) { /* This is the regular base64, not the "web-safe" version. */ static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - const unsigned char *ptr = (unsigned char*)str.data; - const unsigned char *end = UPB_PTRADD(ptr, str.size); + const unsigned char* ptr = (unsigned char*)str.data; + const unsigned char* end = UPB_PTRADD(ptr, str.size); char buf[4]; jsonenc_putstr(e, "\""); @@ -8636,9 +10469,9 @@ static void jsonenc_bytes(jsonenc *e, upb_strview str) { jsonenc_putstr(e, "\""); } -static void jsonenc_stringbody(jsonenc *e, upb_strview str) { - const char *ptr = str.data; - const char *end = UPB_PTRADD(ptr, str.size); +static void jsonenc_stringbody(jsonenc* e, upb_StringView str) { + const char* ptr = str.data; + const char* end = UPB_PTRADD(ptr, str.size); while (ptr < end) { switch (*ptr) { @@ -8677,13 +10510,13 @@ static void jsonenc_stringbody(jsonenc *e, upb_strview str) { } } -static void jsonenc_string(jsonenc *e, upb_strview str) { +static void jsonenc_string(jsonenc* e, upb_StringView str) { jsonenc_putstr(e, "\""); jsonenc_stringbody(e, str); jsonenc_putstr(e, "\""); } -static void jsonenc_double(jsonenc *e, const char *fmt, double val) { +static bool upb_JsonEncode_HandleSpecialDoubles(jsonenc* e, double val) { if (val == INFINITY) { jsonenc_putstr(e, "\"Infinity\""); } else if (val == -INFINITY) { @@ -8691,32 +10524,38 @@ static void jsonenc_double(jsonenc *e, const char *fmt, double val) { } else if (val != val) { jsonenc_putstr(e, "\"NaN\""); } else { - char *p = e->ptr; - jsonenc_printf(e, fmt, val); - - /* printf() is dependent on locales; sadly there is no easy and portable way - * to avoid this. This little post-processing step will translate 1,2 -> 1.2 - * since JSON needs the latter. Arguably a hack, but it is simple and the - * alternatives are far more complicated, platform-dependent, and/or larger - * in code size. */ - for (char *end = e->ptr; p < end; p++) { - if (*p == ',') *p = '.'; - } + return false; } + return true; +} + +static void upb_JsonEncode_Double(jsonenc* e, double val) { + if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; + char buf[32]; + _upb_EncodeRoundTripDouble(val, buf, sizeof(buf)); + jsonenc_putstr(e, buf); +} + +static void upb_JsonEncode_Float(jsonenc* e, float val) { + if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; + char buf[32]; + _upb_EncodeRoundTripFloat(val, buf, sizeof(buf)); + jsonenc_putstr(e, buf); } -static void jsonenc_wrapper(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m) { - const upb_fielddef *val_f = upb_msgdef_itof(m, 1); - upb_msgval val = upb_msg_get(msg, val_f); +static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + upb_MessageValue val = upb_Message_Get(msg, val_f); jsonenc_scalar(e, val, val_f); } -static const upb_msgdef *jsonenc_getanymsg(jsonenc *e, upb_strview type_url) { +static const upb_MessageDef* jsonenc_getanymsg(jsonenc* e, + upb_StringView type_url) { /* Find last '/', if any. */ - const char *end = type_url.data + type_url.size; - const char *ptr = end; - const upb_msgdef *ret; + const char* end = type_url.data + type_url.size; + const char* ptr = end; + const upb_MessageDef* ret; if (!e->ext_pool) { jsonenc_err(e, "Tried to encode Any, but no symtab was provided"); @@ -8735,7 +10574,7 @@ static const upb_msgdef *jsonenc_getanymsg(jsonenc *e, upb_strview type_url) { } } - ret = upb_symtab_lookupmsg2(e->ext_pool, ptr, end - ptr); + ret = upb_DefPool_FindMessageByNameWithSize(e->ext_pool, ptr, end - ptr); if (!ret) { jsonenc_errf(e, "Couldn't find Any type: %.*s", (int)(end - ptr), ptr); @@ -8744,28 +10583,31 @@ static const upb_msgdef *jsonenc_getanymsg(jsonenc *e, upb_strview type_url) { return ret; badurl: - jsonenc_errf( - e, "Bad type URL: " UPB_STRVIEW_FORMAT, UPB_STRVIEW_ARGS(type_url)); -} - -static void jsonenc_any(jsonenc *e, const upb_msg *msg, const upb_msgdef *m) { - const upb_fielddef *type_url_f = upb_msgdef_itof(m, 1); - const upb_fielddef *value_f = upb_msgdef_itof(m, 2); - upb_strview type_url = upb_msg_get(msg, type_url_f).str_val; - upb_strview value = upb_msg_get(msg, value_f).str_val; - const upb_msgdef *any_m = jsonenc_getanymsg(e, type_url); - const upb_msglayout *any_layout = upb_msgdef_layout(any_m); - upb_arena *arena = jsonenc_arena(e); - upb_msg *any = upb_msg_new(any_m, arena); - - if (!upb_decode(value.data, value.size, any, any_layout, arena)) { + jsonenc_errf(e, "Bad type URL: " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(type_url)); +} + +static void jsonenc_any(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* type_url_f = + upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumberWithSize(m, 2); + upb_StringView type_url = upb_Message_Get(msg, type_url_f).str_val; + upb_StringView value = upb_Message_Get(msg, value_f).str_val; + const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url); + const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); + upb_Arena* arena = jsonenc_arena(e); + upb_Message* any = upb_Message_New(any_m, arena); + + if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { jsonenc_err(e, "Error decoding message in Any"); } jsonenc_putstr(e, "{\"@type\":"); jsonenc_string(e, type_url); - if (upb_msgdef_wellknowntype(any_m) == UPB_WELLKNOWN_UNSPECIFIED) { + if (upb_MessageDef_WellKnownType(any_m) == kUpb_WellKnown_Unspecified) { /* Regular messages: {"@type": "...","foo": 1, "bar": 2} */ jsonenc_msgfields(e, any, any_m, false); } else { @@ -8777,7 +10619,7 @@ static void jsonenc_any(jsonenc *e, const upb_msg *msg, const upb_msgdef *m) { jsonenc_putstr(e, "}"); } -static void jsonenc_putsep(jsonenc *e, const char *str, bool *first) { +static void jsonenc_putsep(jsonenc* e, const char* str, bool* first) { if (*first) { *first = false; } else { @@ -8785,9 +10627,9 @@ static void jsonenc_putsep(jsonenc *e, const char *str, bool *first) { } } -static void jsonenc_fieldpath(jsonenc *e, upb_strview path) { - const char *ptr = path.data; - const char *end = ptr + path.size; +static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) { + const char* ptr = path.data; + const char* end = ptr + path.size; while (ptr < end) { char ch = *ptr; @@ -8806,65 +10648,66 @@ static void jsonenc_fieldpath(jsonenc *e, upb_strview path) { } } -static void jsonenc_fieldmask(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m) { - const upb_fielddef *paths_f = upb_msgdef_itof(m, 1); - const upb_array *paths = upb_msg_get(msg, paths_f).array_val; +static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_Array* paths = upb_Message_Get(msg, paths_f).array_val; bool first = true; size_t i, n = 0; - if (paths) n = upb_array_size(paths); + if (paths) n = upb_Array_Size(paths); jsonenc_putstr(e, "\""); for (i = 0; i < n; i++) { jsonenc_putsep(e, ",", &first); - jsonenc_fieldpath(e, upb_array_get(paths, i).str_val); + jsonenc_fieldpath(e, upb_Array_Get(paths, i).str_val); } jsonenc_putstr(e, "\""); } -static void jsonenc_struct(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m) { - const upb_fielddef *fields_f = upb_msgdef_itof(m, 1); - const upb_map *fields = upb_msg_get(msg, fields_f).map_val; - const upb_msgdef *entry_m = upb_fielddef_msgsubdef(fields_f); - const upb_fielddef *value_f = upb_msgdef_itof(entry_m, 2); - size_t iter = UPB_MAP_BEGIN; +static void jsonenc_struct(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_Map* fields = upb_Message_Get(msg, fields_f).map_val; + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); + const upb_FieldDef* value_f = + upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2); + size_t iter = kUpb_Map_Begin; bool first = true; jsonenc_putstr(e, "{"); if (fields) { - while (upb_mapiter_next(fields, &iter)) { - upb_msgval key = upb_mapiter_key(fields, iter); - upb_msgval val = upb_mapiter_value(fields, iter); + while (upb_MapIterator_Next(fields, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(fields, iter); + upb_MessageValue val = upb_MapIterator_Value(fields, iter); jsonenc_putsep(e, ",", &first); jsonenc_string(e, key.str_val); jsonenc_putstr(e, ":"); - jsonenc_value(e, val.msg_val, upb_fielddef_msgsubdef(value_f)); + jsonenc_value(e, val.msg_val, upb_FieldDef_MessageSubDef(value_f)); } } jsonenc_putstr(e, "}"); } -static void jsonenc_listvalue(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m) { - const upb_fielddef *values_f = upb_msgdef_itof(m, 1); - const upb_msgdef *values_m = upb_fielddef_msgsubdef(values_f); - const upb_array *values = upb_msg_get(msg, values_f).array_val; +static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f); + const upb_Array* values = upb_Message_Get(msg, values_f).array_val; size_t i; bool first = true; jsonenc_putstr(e, "["); if (values) { - const size_t size = upb_array_size(values); + const size_t size = upb_Array_Size(values); for (i = 0; i < size; i++) { - upb_msgval elem = upb_array_get(values, i); + upb_MessageValue elem = upb_Array_Get(values, i); jsonenc_putsep(e, ",", &first); jsonenc_value(e, elem.msg_val, values_m); @@ -8874,22 +10717,23 @@ static void jsonenc_listvalue(jsonenc *e, const upb_msg *msg, jsonenc_putstr(e, "]"); } -static void jsonenc_value(jsonenc *e, const upb_msg *msg, const upb_msgdef *m) { +static void jsonenc_value(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { /* TODO(haberman): do we want a reflection method to get oneof case? */ - size_t iter = UPB_MSG_BEGIN; - const upb_fielddef *f; - upb_msgval val; + size_t iter = kUpb_Message_Begin; + const upb_FieldDef* f; + upb_MessageValue val; - if (!upb_msg_next(msg, m, NULL, &f, &val, &iter)) { + if (!upb_Message_Next(msg, m, NULL, &f, &val, &iter)) { jsonenc_err(e, "No value set in Value proto"); } - switch (upb_fielddef_number(f)) { + switch (upb_FieldDef_Number(f)) { case 1: jsonenc_putstr(e, "null"); break; case 2: - jsonenc_double(e, "%.17g", val.double_val); + upb_JsonEncode_Double(e, val.double_val); break; case 3: jsonenc_string(e, val.str_val); @@ -8898,113 +10742,115 @@ static void jsonenc_value(jsonenc *e, const upb_msg *msg, const upb_msgdef *m) { jsonenc_putstr(e, val.bool_val ? "true" : "false"); break; case 5: - jsonenc_struct(e, val.msg_val, upb_fielddef_msgsubdef(f)); + jsonenc_struct(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); break; case 6: - jsonenc_listvalue(e, val.msg_val, upb_fielddef_msgsubdef(f)); + jsonenc_listvalue(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); break; } } -static void jsonenc_msgfield(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m) { - switch (upb_msgdef_wellknowntype(m)) { - case UPB_WELLKNOWN_UNSPECIFIED: +static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + switch (upb_MessageDef_WellKnownType(m)) { + case kUpb_WellKnown_Unspecified: jsonenc_msg(e, msg, m); break; - case UPB_WELLKNOWN_ANY: + case kUpb_WellKnown_Any: jsonenc_any(e, msg, m); break; - case UPB_WELLKNOWN_FIELDMASK: + case kUpb_WellKnown_FieldMask: jsonenc_fieldmask(e, msg, m); break; - case UPB_WELLKNOWN_DURATION: + case kUpb_WellKnown_Duration: jsonenc_duration(e, msg, m); break; - case UPB_WELLKNOWN_TIMESTAMP: + case kUpb_WellKnown_Timestamp: jsonenc_timestamp(e, msg, m); break; - case UPB_WELLKNOWN_DOUBLEVALUE: - case UPB_WELLKNOWN_FLOATVALUE: - case UPB_WELLKNOWN_INT64VALUE: - case UPB_WELLKNOWN_UINT64VALUE: - case UPB_WELLKNOWN_INT32VALUE: - case UPB_WELLKNOWN_UINT32VALUE: - case UPB_WELLKNOWN_STRINGVALUE: - case UPB_WELLKNOWN_BYTESVALUE: - case UPB_WELLKNOWN_BOOLVALUE: + case kUpb_WellKnown_DoubleValue: + case kUpb_WellKnown_FloatValue: + case kUpb_WellKnown_Int64Value: + case kUpb_WellKnown_UInt64Value: + case kUpb_WellKnown_Int32Value: + case kUpb_WellKnown_UInt32Value: + case kUpb_WellKnown_StringValue: + case kUpb_WellKnown_BytesValue: + case kUpb_WellKnown_BoolValue: jsonenc_wrapper(e, msg, m); break; - case UPB_WELLKNOWN_VALUE: + case kUpb_WellKnown_Value: jsonenc_value(e, msg, m); break; - case UPB_WELLKNOWN_LISTVALUE: + case kUpb_WellKnown_ListValue: jsonenc_listvalue(e, msg, m); break; - case UPB_WELLKNOWN_STRUCT: + case kUpb_WellKnown_Struct: jsonenc_struct(e, msg, m); break; } } -static void jsonenc_scalar(jsonenc *e, upb_msgval val, const upb_fielddef *f) { - switch (upb_fielddef_type(f)) { - case UPB_TYPE_BOOL: +static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: jsonenc_putstr(e, val.bool_val ? "true" : "false"); break; - case UPB_TYPE_FLOAT: - jsonenc_double(e, "%.9g", val.float_val); + case kUpb_CType_Float: + upb_JsonEncode_Float(e, val.float_val); break; - case UPB_TYPE_DOUBLE: - jsonenc_double(e, "%.17g", val.double_val); + case kUpb_CType_Double: + upb_JsonEncode_Double(e, val.double_val); break; - case UPB_TYPE_INT32: + case kUpb_CType_Int32: jsonenc_printf(e, "%" PRId32, val.int32_val); break; - case UPB_TYPE_UINT32: + case kUpb_CType_UInt32: jsonenc_printf(e, "%" PRIu32, val.uint32_val); break; - case UPB_TYPE_INT64: + case kUpb_CType_Int64: jsonenc_printf(e, "\"%" PRId64 "\"", val.int64_val); break; - case UPB_TYPE_UINT64: + case kUpb_CType_UInt64: jsonenc_printf(e, "\"%" PRIu64 "\"", val.uint64_val); break; - case UPB_TYPE_STRING: + case kUpb_CType_String: jsonenc_string(e, val.str_val); break; - case UPB_TYPE_BYTES: + case kUpb_CType_Bytes: jsonenc_bytes(e, val.str_val); break; - case UPB_TYPE_ENUM: + case kUpb_CType_Enum: jsonenc_enum(val.int32_val, f, e); break; - case UPB_TYPE_MESSAGE: - jsonenc_msgfield(e, val.msg_val, upb_fielddef_msgsubdef(f)); + case kUpb_CType_Message: + jsonenc_msgfield(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); break; } } -static void jsonenc_mapkey(jsonenc *e, upb_msgval val, const upb_fielddef *f) { +static void jsonenc_mapkey(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f) { jsonenc_putstr(e, "\""); - switch (upb_fielddef_type(f)) { - case UPB_TYPE_BOOL: + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: jsonenc_putstr(e, val.bool_val ? "true" : "false"); break; - case UPB_TYPE_INT32: + case kUpb_CType_Int32: jsonenc_printf(e, "%" PRId32, val.int32_val); break; - case UPB_TYPE_UINT32: + case kUpb_CType_UInt32: jsonenc_printf(e, "%" PRIu32, val.uint32_val); break; - case UPB_TYPE_INT64: + case kUpb_CType_Int64: jsonenc_printf(e, "%" PRId64, val.int64_val); break; - case UPB_TYPE_UINT64: + case kUpb_CType_UInt64: jsonenc_printf(e, "%" PRIu64, val.uint64_val); break; - case UPB_TYPE_STRING: + case kUpb_CType_String: jsonenc_stringbody(e, val.str_val); break; default: @@ -9014,95 +10860,105 @@ static void jsonenc_mapkey(jsonenc *e, upb_msgval val, const upb_fielddef *f) { jsonenc_putstr(e, "\":"); } -static void jsonenc_array(jsonenc *e, const upb_array *arr, - const upb_fielddef *f) { +static void jsonenc_array(jsonenc* e, const upb_Array* arr, + const upb_FieldDef* f) { size_t i; - size_t size = arr ? upb_array_size(arr) : 0; + size_t size = arr ? upb_Array_Size(arr) : 0; bool first = true; jsonenc_putstr(e, "["); for (i = 0; i < size; i++) { jsonenc_putsep(e, ",", &first); - jsonenc_scalar(e, upb_array_get(arr, i), f); + jsonenc_scalar(e, upb_Array_Get(arr, i), f); } jsonenc_putstr(e, "]"); } -static void jsonenc_map(jsonenc *e, const upb_map *map, const upb_fielddef *f) { - const upb_msgdef *entry = upb_fielddef_msgsubdef(f); - const upb_fielddef *key_f = upb_msgdef_itof(entry, 1); - const upb_fielddef *val_f = upb_msgdef_itof(entry, 2); - size_t iter = UPB_MAP_BEGIN; +static void jsonenc_map(jsonenc* e, const upb_Map* map, const upb_FieldDef* f) { + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key_f = + upb_MessageDef_FindFieldByNumberWithSize(entry, 1); + const upb_FieldDef* val_f = + upb_MessageDef_FindFieldByNumberWithSize(entry, 2); + size_t iter = kUpb_Map_Begin; bool first = true; jsonenc_putstr(e, "{"); if (map) { - while (upb_mapiter_next(map, &iter)) { + while (upb_MapIterator_Next(map, &iter)) { jsonenc_putsep(e, ",", &first); - jsonenc_mapkey(e, upb_mapiter_key(map, iter), key_f); - jsonenc_scalar(e, upb_mapiter_value(map, iter), val_f); + jsonenc_mapkey(e, upb_MapIterator_Key(map, iter), key_f); + jsonenc_scalar(e, upb_MapIterator_Value(map, iter), val_f); } } jsonenc_putstr(e, "}"); } -static void jsonenc_fieldval(jsonenc *e, const upb_fielddef *f, - upb_msgval val, bool *first) { - const char *name; +static void jsonenc_fieldval(jsonenc* e, const upb_FieldDef* f, + upb_MessageValue val, bool* first) { + const char* name; + + jsonenc_putsep(e, ",", first); - if (e->options & UPB_JSONENC_PROTONAMES) { - name = upb_fielddef_name(f); + if (upb_FieldDef_IsExtension(f)) { + // TODO: For MessageSet, I would have expected this to print the message + // name here, but Python doesn't appear to do this. We should do more + // research here about what various implementations do. + jsonenc_printf(e, "\"[%s]\":", upb_FieldDef_FullName(f)); } else { - name = upb_fielddef_jsonname(f); + if (e->options & upb_JsonEncode_UseProtoNames) { + name = upb_FieldDef_Name(f); + } else { + name = upb_FieldDef_JsonName(f); + } + jsonenc_printf(e, "\"%s\":", name); } - jsonenc_putsep(e, ",", first); - jsonenc_printf(e, "\"%s\":", name); - - if (upb_fielddef_ismap(f)) { + if (upb_FieldDef_IsMap(f)) { jsonenc_map(e, val.map_val, f); - } else if (upb_fielddef_isseq(f)) { + } else if (upb_FieldDef_IsRepeated(f)) { jsonenc_array(e, val.array_val, f); } else { jsonenc_scalar(e, val, f); } } -static void jsonenc_msgfields(jsonenc *e, const upb_msg *msg, - const upb_msgdef *m, bool first) { - upb_msgval val; - const upb_fielddef *f; +static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m, bool first) { + upb_MessageValue val; + const upb_FieldDef* f; - if (e->options & UPB_JSONENC_EMITDEFAULTS) { + if (e->options & upb_JsonEncode_EmitDefaults) { /* Iterate over all fields. */ int i = 0; - int n = upb_msgdef_fieldcount(m); + int n = upb_MessageDef_FieldCount(m); for (i = 0; i < n; i++) { - f = upb_msgdef_field(m, i); - if (!upb_fielddef_haspresence(f) || upb_msg_has(msg, f)) { - jsonenc_fieldval(e, f, upb_msg_get(msg, f), &first); + f = upb_MessageDef_Field(m, i); + if (!upb_FieldDef_HasPresence(f) || upb_Message_Has(msg, f)) { + jsonenc_fieldval(e, f, upb_Message_Get(msg, f), &first); } } } else { /* Iterate over non-empty fields. */ - size_t iter = UPB_MSG_BEGIN; - while (upb_msg_next(msg, m, e->ext_pool, &f, &val, &iter)) { + size_t iter = kUpb_Message_Begin; + while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) { jsonenc_fieldval(e, f, val, &first); } } } -static void jsonenc_msg(jsonenc *e, const upb_msg *msg, const upb_msgdef *m) { +static void jsonenc_msg(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { jsonenc_putstr(e, "{"); jsonenc_msgfields(e, msg, m, true); jsonenc_putstr(e, "}"); } -static size_t jsonenc_nullz(jsonenc *e, size_t size) { +static size_t jsonenc_nullz(jsonenc* e, size_t size) { size_t ret = e->ptr - e->buf + e->overflow; if (size > 0) { @@ -9113,9 +10969,9 @@ static size_t jsonenc_nullz(jsonenc *e, size_t size) { return ret; } -size_t upb_json_encode(const upb_msg *msg, const upb_msgdef *m, - const upb_symtab *ext_pool, int options, char *buf, - size_t size, upb_status *status) { +size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, int options, char* buf, + size_t size, upb_Status* status) { jsonenc e; e.buf = buf; @@ -9130,7 +10986,7 @@ size_t upb_json_encode(const upb_msg *msg, const upb_msgdef *m, if (setjmp(e.err)) return -1; jsonenc_msgfield(&e, msg, m); - if (e.arena) upb_arena_free(e.arena); + if (e.arena) upb_Arena_Free(e.arena); return jsonenc_nullz(&e, size); } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 40072772b2..276f6b1095 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -255,7 +255,7 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); /** upb/decode.h ************************************************************/ /* - * upb_decode: parsing into a upb_msg using a upb_msglayout. + * upb_decode: parsing into a upb_Message using a upb_MiniTable. */ #ifndef UPB_DECODE_H_ @@ -297,54 +297,56 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); extern "C" { #endif -/* upb_status *****************************************************************/ +/* upb_Status *****************************************************************/ -#define UPB_STATUS_MAX_MESSAGE 127 +#define _kUpb_Status_MaxMessage 127 typedef struct { bool ok; - char msg[UPB_STATUS_MAX_MESSAGE]; /* Error message; NULL-terminated. */ -} upb_status; + char msg[_kUpb_Status_MaxMessage]; /* Error message; NULL-terminated. */ +} upb_Status; -const char *upb_status_errmsg(const upb_status *status); -bool upb_ok(const upb_status *status); +const char* upb_Status_ErrorMessage(const upb_Status* status); +bool upb_Status_IsOk(const upb_Status* status); /* These are no-op if |status| is NULL. */ -void upb_status_clear(upb_status *status); -void upb_status_seterrmsg(upb_status *status, const char *msg); -void upb_status_seterrf(upb_status *status, const char *fmt, ...) +void upb_Status_Clear(upb_Status* status); +void upb_Status_SetErrorMessage(upb_Status* status, const char* msg); +void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) UPB_PRINTF(2, 3); -void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) - UPB_PRINTF(2, 0); -void upb_status_vappenderrf(upb_status *status, const char *fmt, va_list args) - UPB_PRINTF(2, 0); +void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, + va_list args) UPB_PRINTF(2, 0); +void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, + va_list args) UPB_PRINTF(2, 0); -/** upb_strview ************************************************************/ +/** upb_StringView ************************************************************/ typedef struct { - const char *data; + const char* data; size_t size; -} upb_strview; +} upb_StringView; -UPB_INLINE upb_strview upb_strview_make(const char *data, size_t size) { - upb_strview ret; +UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data, + size_t size) { + upb_StringView ret; ret.data = data; ret.size = size; return ret; } -UPB_INLINE upb_strview upb_strview_makez(const char *data) { - return upb_strview_make(data, strlen(data)); +UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) { + return upb_StringView_FromDataAndSize(data, strlen(data)); } -UPB_INLINE bool upb_strview_eql(upb_strview a, upb_strview b) { +UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { return a.size == b.size && memcmp(a.data, b.data, a.size) == 0; } -#define UPB_STRVIEW_INIT(ptr, len) {ptr, len} +#define UPB_STRINGVIEW_INIT(ptr, len) \ + { ptr, len } -#define UPB_STRVIEW_FORMAT "%.*s" -#define UPB_STRVIEW_ARGS(view) (int)(view).size, (view).data +#define UPB_STRINGVIEW_FORMAT "%.*s" +#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data /** upb_alloc *****************************************************************/ @@ -360,25 +362,25 @@ typedef struct upb_alloc upb_alloc; /* A malloc()/free() function. * If "size" is 0 then the function acts like free(), otherwise it acts like * realloc(). Only "oldsize" bytes from a previous allocation are preserved. */ -typedef void *upb_alloc_func(upb_alloc *alloc, void *ptr, size_t oldsize, +typedef void* upb_alloc_func(upb_alloc* alloc, void* ptr, size_t oldsize, size_t size); struct upb_alloc { - upb_alloc_func *func; + upb_alloc_func* func; }; -UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) { +UPB_INLINE void* upb_malloc(upb_alloc* alloc, size_t size) { UPB_ASSERT(alloc); return alloc->func(alloc, NULL, 0, size); } -UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize, +UPB_INLINE void* upb_realloc(upb_alloc* alloc, void* ptr, size_t oldsize, size_t size) { UPB_ASSERT(alloc); return alloc->func(alloc, ptr, oldsize, size); } -UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) { +UPB_INLINE void upb_free(upb_alloc* alloc, void* ptr) { assert(alloc); alloc->func(alloc, ptr, 0, 0); } @@ -392,69 +394,67 @@ extern upb_alloc upb_alloc_global; * We still get benefit because we can put custom logic into our global * allocator, like injecting out-of-memory faults in debug/testing builds. */ -UPB_INLINE void *upb_gmalloc(size_t size) { +UPB_INLINE void* upb_gmalloc(size_t size) { return upb_malloc(&upb_alloc_global, size); } -UPB_INLINE void *upb_grealloc(void *ptr, size_t oldsize, size_t size) { +UPB_INLINE void* upb_grealloc(void* ptr, size_t oldsize, size_t size) { return upb_realloc(&upb_alloc_global, ptr, oldsize, size); } -UPB_INLINE void upb_gfree(void *ptr) { - upb_free(&upb_alloc_global, ptr); -} +UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } -/* upb_arena ******************************************************************/ +/* upb_Arena ******************************************************************/ -/* upb_arena is a specific allocator implementation that uses arena allocation. +/* upb_Arena is a specific allocator implementation that uses arena allocation. * The user provides an allocator that will be used to allocate the underlying * arena blocks. Arenas by nature do not require the individual allocations * to be freed. However the Arena does allow users to register cleanup * functions that will run when the arena is destroyed. * - * A upb_arena is *not* thread-safe. + * A upb_Arena is *not* thread-safe. * * You could write a thread-safe arena allocator that satisfies the * upb_alloc interface, but it would not be as efficient for the * single-threaded case. */ -typedef void upb_cleanup_func(void *ud); +typedef void upb_CleanupFunc(void* ud); -struct upb_arena; -typedef struct upb_arena upb_arena; +struct upb_Arena; +typedef struct upb_Arena upb_Arena; typedef struct { /* We implement the allocator interface. - * This must be the first member of upb_arena! + * This must be the first member of upb_Arena! * TODO(haberman): remove once handlers are gone. */ upb_alloc alloc; char *ptr, *end; -} _upb_arena_head; +} _upb_ArenaHead; /* Creates an arena from the given initial block (if any -- n may be 0). * Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this * is a fixed-size arena and cannot grow. */ -upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc); -void upb_arena_free(upb_arena *a); -bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func); -bool upb_arena_fuse(upb_arena *a, upb_arena *b); -void *_upb_arena_slowmalloc(upb_arena *a, size_t size); +upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc); +void upb_Arena_Free(upb_Arena* a); +bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func); +bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b); +void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size); -UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; } +UPB_INLINE upb_alloc* upb_Arena_Alloc(upb_Arena* a) { return (upb_alloc*)a; } -UPB_INLINE size_t _upb_arenahas(upb_arena *a) { - _upb_arena_head *h = (_upb_arena_head*)a; +UPB_INLINE size_t _upb_ArenaHas(upb_Arena* a) { + _upb_ArenaHead* h = (_upb_ArenaHead*)a; return (size_t)(h->end - h->ptr); } -UPB_INLINE void *upb_arena_malloc(upb_arena *a, size_t size) { - _upb_arena_head *h = (_upb_arena_head*)a; +UPB_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { + _upb_ArenaHead* h = (_upb_ArenaHead*)a; void* ret; size = UPB_ALIGN_MALLOC(size); - if (UPB_UNLIKELY(_upb_arenahas(a) < size)) { - return _upb_arena_slowmalloc(a, size); + if (UPB_UNLIKELY(_upb_ArenaHas(a) < size)) { + return _upb_Arena_SlowMalloc(a, size); } ret = h->ptr; @@ -464,7 +464,7 @@ UPB_INLINE void *upb_arena_malloc(upb_arena *a, size_t size) { #if UPB_ASAN { size_t guard_size = 32; - if (_upb_arenahas(a) >= guard_size) { + if (_upb_ArenaHas(a) >= guard_size) { h->ptr += guard_size; } else { h->ptr = h->end; @@ -475,9 +475,9 @@ UPB_INLINE void *upb_arena_malloc(upb_arena *a, size_t size) { return ret; } -UPB_INLINE void *upb_arena_realloc(upb_arena *a, void *ptr, size_t oldsize, +UPB_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, size_t size) { - void *ret = upb_arena_malloc(a, size); + void* ret = upb_Arena_Malloc(a, size); if (ret && oldsize > 0) { memcpy(ret, ptr, oldsize); @@ -486,100 +486,77 @@ UPB_INLINE void *upb_arena_realloc(upb_arena *a, void *ptr, size_t oldsize, return ret; } -UPB_INLINE upb_arena *upb_arena_new(void) { - return upb_arena_init(NULL, 0, &upb_alloc_global); +UPB_INLINE upb_Arena* upb_Arena_New(void) { + return upb_Arena_Init(NULL, 0, &upb_alloc_global); } /* Constants ******************************************************************/ -/* Generic function type. */ -typedef void upb_func(void); - /* A list of types as they are encoded on-the-wire. */ typedef enum { - UPB_WIRE_TYPE_VARINT = 0, - UPB_WIRE_TYPE_64BIT = 1, - UPB_WIRE_TYPE_DELIMITED = 2, - UPB_WIRE_TYPE_START_GROUP = 3, - UPB_WIRE_TYPE_END_GROUP = 4, - UPB_WIRE_TYPE_32BIT = 5 -} upb_wiretype_t; + kUpb_WireType_Varint = 0, + kUpb_WireType_64Bit = 1, + kUpb_WireType_Delimited = 2, + kUpb_WireType_StartGroup = 3, + kUpb_WireType_EndGroup = 4, + kUpb_WireType_32Bit = 5 +} upb_WireType; /* The types a field can have. Note that this list is not identical to the * types defined in descriptor.proto, which gives INT32 and SINT32 separate * types (we distinguish the two with the "integer encoding" enum below). */ typedef enum { - UPB_TYPE_BOOL = 1, - UPB_TYPE_FLOAT = 2, - UPB_TYPE_INT32 = 3, - UPB_TYPE_UINT32 = 4, - UPB_TYPE_ENUM = 5, /* Enum values are int32. */ - UPB_TYPE_MESSAGE = 6, - UPB_TYPE_DOUBLE = 7, - UPB_TYPE_INT64 = 8, - UPB_TYPE_UINT64 = 9, - UPB_TYPE_STRING = 10, - UPB_TYPE_BYTES = 11 -} upb_fieldtype_t; + kUpb_CType_Bool = 1, + kUpb_CType_Float = 2, + kUpb_CType_Int32 = 3, + kUpb_CType_UInt32 = 4, + kUpb_CType_Enum = 5, /* Enum values are int32. */ + kUpb_CType_Message = 6, + kUpb_CType_Double = 7, + kUpb_CType_Int64 = 8, + kUpb_CType_UInt64 = 9, + kUpb_CType_String = 10, + kUpb_CType_Bytes = 11 +} upb_CType; /* The repeated-ness of each field; this matches descriptor.proto. */ typedef enum { - UPB_LABEL_OPTIONAL = 1, - UPB_LABEL_REQUIRED = 2, - UPB_LABEL_REPEATED = 3 -} upb_label_t; + kUpb_Label_Optional = 1, + kUpb_Label_Required = 2, + kUpb_Label_Repeated = 3 +} upb_Label; /* Descriptor types, as defined in descriptor.proto. */ typedef enum { - /* Old (long) names. TODO(haberman): remove */ - UPB_DESCRIPTOR_TYPE_DOUBLE = 1, - UPB_DESCRIPTOR_TYPE_FLOAT = 2, - UPB_DESCRIPTOR_TYPE_INT64 = 3, - UPB_DESCRIPTOR_TYPE_UINT64 = 4, - UPB_DESCRIPTOR_TYPE_INT32 = 5, - UPB_DESCRIPTOR_TYPE_FIXED64 = 6, - UPB_DESCRIPTOR_TYPE_FIXED32 = 7, - UPB_DESCRIPTOR_TYPE_BOOL = 8, - UPB_DESCRIPTOR_TYPE_STRING = 9, - UPB_DESCRIPTOR_TYPE_GROUP = 10, - UPB_DESCRIPTOR_TYPE_MESSAGE = 11, - UPB_DESCRIPTOR_TYPE_BYTES = 12, - UPB_DESCRIPTOR_TYPE_UINT32 = 13, - UPB_DESCRIPTOR_TYPE_ENUM = 14, - UPB_DESCRIPTOR_TYPE_SFIXED32 = 15, - UPB_DESCRIPTOR_TYPE_SFIXED64 = 16, - UPB_DESCRIPTOR_TYPE_SINT32 = 17, - UPB_DESCRIPTOR_TYPE_SINT64 = 18, - - UPB_DTYPE_DOUBLE = 1, - UPB_DTYPE_FLOAT = 2, - UPB_DTYPE_INT64 = 3, - UPB_DTYPE_UINT64 = 4, - UPB_DTYPE_INT32 = 5, - UPB_DTYPE_FIXED64 = 6, - UPB_DTYPE_FIXED32 = 7, - UPB_DTYPE_BOOL = 8, - UPB_DTYPE_STRING = 9, - UPB_DTYPE_GROUP = 10, - UPB_DTYPE_MESSAGE = 11, - UPB_DTYPE_BYTES = 12, - UPB_DTYPE_UINT32 = 13, - UPB_DTYPE_ENUM = 14, - UPB_DTYPE_SFIXED32 = 15, - UPB_DTYPE_SFIXED64 = 16, - UPB_DTYPE_SINT32 = 17, - UPB_DTYPE_SINT64 = 18 -} upb_descriptortype_t; - -#define UPB_MAP_BEGIN ((size_t)-1) - -UPB_INLINE bool _upb_isle(void) { + kUpb_FieldType_Double = 1, + kUpb_FieldType_Float = 2, + kUpb_FieldType_Int64 = 3, + kUpb_FieldType_UInt64 = 4, + kUpb_FieldType_Int32 = 5, + kUpb_FieldType_Fixed64 = 6, + kUpb_FieldType_Fixed32 = 7, + kUpb_FieldType_Bool = 8, + kUpb_FieldType_String = 9, + kUpb_FieldType_Group = 10, + kUpb_FieldType_Message = 11, + kUpb_FieldType_Bytes = 12, + kUpb_FieldType_UInt32 = 13, + kUpb_FieldType_Enum = 14, + kUpb_FieldType_SFixed32 = 15, + kUpb_FieldType_SFixed64 = 16, + kUpb_FieldType_SInt32 = 17, + kUpb_FieldType_SInt64 = 18 +} upb_FieldType; + +#define kUpb_Map_Begin ((size_t)-1) + +UPB_INLINE bool _upb_IsLittleEndian(void) { int x = 1; return *(char*)&x == 1; } -UPB_INLINE uint32_t _upb_be_swap32(uint32_t val) { - if (_upb_isle()) { +UPB_INLINE uint32_t _upb_BigEndian_Swap32(uint32_t val) { + if (_upb_IsLittleEndian()) { return val; } else { return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | @@ -587,15 +564,16 @@ UPB_INLINE uint32_t _upb_be_swap32(uint32_t val) { } } -UPB_INLINE uint64_t _upb_be_swap64(uint64_t val) { - if (_upb_isle()) { +UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) { + if (_upb_IsLittleEndian()) { return val; } else { - return ((uint64_t)_upb_be_swap32(val) << 32) | _upb_be_swap32(val >> 32); + return ((uint64_t)_upb_BigEndian_Swap32(val) << 32) | + _upb_BigEndian_Swap32(val >> 32); } } -UPB_INLINE int _upb_lg2ceil(int x) { +UPB_INLINE int _upb_Log2Ceiling(int x) { if (x <= 1) return 0; #ifdef __GNUC__ return 32 - __builtin_clz(x - 1); @@ -606,54 +584,59 @@ UPB_INLINE int _upb_lg2ceil(int x) { #endif } -UPB_INLINE int _upb_lg2ceilsize(int x) { - return 1 << _upb_lg2ceil(x); -} +UPB_INLINE int _upb_Log2Ceilingsize(int x) { return 1 << _upb_Log2Ceiling(x); } #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif -#endif /* UPB_H_ */ +#endif /* UPB_H_ */ #ifdef __cplusplus extern "C" { #endif -typedef void upb_msg; +/** upb_Message + * *******************************************************************/ + +typedef void upb_Message; -/* For users these are opaque. They can be obtained from upb_msgdef_layout() - * but users cannot access any of the members. */ -struct upb_msglayout; -typedef struct upb_msglayout upb_msglayout; +/* For users these are opaque. They can be obtained from + * upb_MessageDef_MiniTable() but users cannot access any of the members. */ +struct upb_MiniTable; +typedef struct upb_MiniTable upb_MiniTable; /* Adds unknown data (serialized protobuf data) to the given message. The data * is copied into the message instance. */ -void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, - upb_arena *arena); +void upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena); /* Returns a reference to the message's unknown data. */ -const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); -/** upb_extreg *******************************************************************/ +/* Returns the number of extensions present in this message. */ +size_t upb_Message_ExtensionCount(const upb_Message* msg); + +/** upb_ExtensionRegistry *****************************************************/ /* Extension registry: a dynamic data structure that stores a map of: - * (upb_msglayout, number) -> extension info + * (upb_MiniTable, number) -> extension info * - * upb_decode() uses upb_extreg to look up extensions while parsing binary - * format. + * upb_decode() uses upb_ExtensionRegistry to look up extensions while parsing + * binary format. * - * upb_extreg is part of the mini-table (msglayout) family of objects. Like all - * mini-table objects, it is suitable for reflection-less builds that do not - * want to expose names into the binary. + * upb_ExtensionRegistry is part of the mini-table (msglayout) family of + * objects. Like all mini-table objects, it is suitable for reflection-less + * builds that do not want to expose names into the binary. * - * Unlike most mini-table types, upb_extreg requires dynamic memory allocation - * and dynamic initialization: - * * If reflection is being used, then upb_symtab will construct an appropriate - * upb_extreg automatically. + * Unlike most mini-table types, upb_ExtensionRegistry requires dynamic memory + * allocation and dynamic initialization: + * * If reflection is being used, then upb_DefPool will construct an appropriate + * upb_ExtensionRegistry automatically. * * For a mini-table only build, the user must manually construct the - * upb_extreg and populate it with all of the extensions the user cares about. + * upb_ExtensionRegistry and populate it with all of the extensions the user + * cares about. * * A third alternative is to manually unpack relevant extensions after the * main parse is complete, similar to how Any works. This is perhaps the * nicest solution from the perspective of reducing dependencies, avoiding @@ -667,19 +650,19 @@ const char *upb_msg_getunknown(const upb_msg *msg, size_t *len); * extensions from a generated module and pass the extension registry to the * binary decoder. * - * A upb_symtab provides a upb_extreg, so any users who use reflection do not - * need to populate a upb_extreg directly. + * A upb_DefPool provides a upb_ExtensionRegistry, so any users who use + * reflection do not need to populate a upb_ExtensionRegistry directly. */ -struct upb_extreg; -typedef struct upb_extreg upb_extreg; +struct upb_ExtensionRegistry; +typedef struct upb_ExtensionRegistry upb_ExtensionRegistry; -/* Creates a upb_extreg in the given arena. The arena must outlive any use of - * the extreg. */ -upb_extreg *upb_extreg_new(upb_arena *arena); +/* Creates a upb_ExtensionRegistry in the given arena. The arena must outlive + * any use of the extreg. */ +upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif #endif /* UPB_MSG_INT_H_ */ @@ -693,27 +676,53 @@ extern "C" { enum { /* If set, strings will alias the input buffer instead of copying into the * arena. */ - UPB_DECODE_ALIAS = 1, + kUpb_DecodeOption_AliasString = 1, + + /* If set, the parse will return failure if any message is missing any + * required fields when the message data ends. The parse will still continue, + * and the failure will only be reported at the end. + * + * IMPORTANT CAVEATS: + * + * 1. This can throw a false positive failure if an incomplete message is seen + * on the wire but is later completed when the sub-message occurs again. + * For this reason, a second pass is required to verify a failure, to be + * truly robust. + * + * 2. This can return a false success if you are decoding into a message that + * already has some sub-message fields present. If the sub-message does + * not occur in the binary payload, we will never visit it and discover the + * incomplete sub-message. For this reason, this check is only useful for + * implemting ParseFromString() semantics. For MergeFromString(), a + * post-parse validation step will always be necessary. */ + kUpb_DecodeOption_CheckRequired = 2, }; #define UPB_DECODE_MAXDEPTH(depth) ((depth) << 16) -bool _upb_decode(const char *buf, size_t size, upb_msg *msg, - const upb_msglayout *l, const upb_extreg *extreg, int options, - upb_arena *arena); - -UPB_INLINE -bool upb_decode(const char *buf, size_t size, upb_msg *msg, - const upb_msglayout *l, upb_arena *arena) { - return _upb_decode(buf, size, msg, l, NULL, 0, arena); -} +typedef enum { + kUpb_DecodeStatus_Ok = 0, + kUpb_DecodeStatus_Malformed = 1, // Wire format was corrupt + kUpb_DecodeStatus_OutOfMemory = 2, // Arena alloc failed + kUpb_DecodeStatus_BadUtf8 = 3, // String field had bad UTF-8 + kUpb_DecodeStatus_MaxDepthExceeded = 4, // Exceeded UPB_DECODE_MAXDEPTH + + // kUpb_DecodeOption_CheckRequired failed (see above), but the parse otherwise + // succeeded. + kUpb_DecodeStatus_MissingRequired = 5, +} upb_DecodeStatus; + +upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, + const upb_MiniTable* l, + const upb_ExtensionRegistry* extreg, int options, + upb_Arena* arena); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif -#endif /* UPB_DECODE_H_ */ +#endif /* UPB_DECODE_H_ */ /** upb/decode_internal.h ************************************************************/ /* @@ -726,8 +735,10 @@ bool upb_decode(const char *buf, size_t size, upb_msg *msg, #include +#include "third_party/utf8_range/utf8_range.h" -/** upb/msg_internal.h ************************************************************//* +/** upb/msg_internal.h ************************************************************/ +/* ** Our memory representation for parsing tables and messages themselves. ** Functions in this file are used by generated code and possibly reflection. ** @@ -769,11 +780,12 @@ bool upb_decode(const char *buf, size_t size, upb_msg *msg, #include +// Must be last. + #ifdef __cplusplus extern "C" { #endif - /* upb_value ******************************************************************/ typedef struct { @@ -782,11 +794,9 @@ typedef struct { /* Variant that works with a length-delimited rather than NULL-delimited string, * as supported by strtable. */ -char *upb_strdup2(const char *s, size_t len, upb_arena *a); +char* upb_strdup2(const char* s, size_t len, upb_Arena* a); -UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val) { - v->val = val; -} +UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } /* For each value ctype, define the following set of functions: * @@ -796,36 +806,35 @@ UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val) { * * // Construct a new upb_value from an int32. * upb_value upb_value_int32(int32_t val); */ -#define FUNCS(name, membername, type_t, converter, proto_type) \ - UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \ - val->val = (converter)cval; \ - } \ - UPB_INLINE upb_value upb_value_ ## name(type_t val) { \ - upb_value ret; \ - upb_value_set ## name(&ret, val); \ - return ret; \ - } \ - UPB_INLINE type_t upb_value_get ## name(upb_value val) { \ - return (type_t)(converter)val.val; \ +#define FUNCS(name, membername, type_t, converter, proto_type) \ + UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ + val->val = (converter)cval; \ + } \ + UPB_INLINE upb_value upb_value_##name(type_t val) { \ + upb_value ret; \ + upb_value_set##name(&ret, val); \ + return ret; \ + } \ + UPB_INLINE type_t upb_value_get##name(upb_value val) { \ + return (type_t)(converter)val.val; \ } -FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32) -FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64) -FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32) -FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64) -FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL) -FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR) -FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR) -FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR) -FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR) +FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32) +FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64) +FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32) +FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64) +FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL) +FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR) +FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR) +FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR) #undef FUNCS -UPB_INLINE void upb_value_setfloat(upb_value *val, float cval) { +UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { memcpy(&val->val, &cval, sizeof(cval)); } -UPB_INLINE void upb_value_setdouble(upb_value *val, double cval) { +UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { memcpy(&val->val, &cval, sizeof(cval)); } @@ -843,7 +852,6 @@ UPB_INLINE upb_value upb_value_double(double cval) { #undef SET_TYPE - /* upb_tabkey *****************************************************************/ /* Either: @@ -855,14 +863,14 @@ UPB_INLINE upb_value upb_value_double(double cval) { * initializing a non-first union member. */ typedef uintptr_t upb_tabkey; -UPB_INLINE char *upb_tabstr(upb_tabkey key, uint32_t *len) { +UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { char* mem = (char*)key; if (len) memcpy(len, mem, sizeof(*len)); return mem + sizeof(*len); } -UPB_INLINE upb_strview upb_tabstrview(upb_tabkey key) { - upb_strview ret; +UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { + upb_StringView ret; uint32_t len; ret.data = upb_tabstr(key, &len); ret.size = len; @@ -875,14 +883,11 @@ typedef struct upb_tabval { uint64_t val; } upb_tabval; -#define UPB_TABVALUE_EMPTY_INIT {-1} +#define UPB_TABVALUE_EMPTY_INIT \ + { -1 } /* upb_table ******************************************************************/ -uint64_t Wyhash(const void *data, size_t len, uint64_t seed, - const uint64_t salt[]); -extern const uint64_t kWyhashSalt[5]; - typedef struct _upb_tabent { upb_tabkey key; upb_tabval val; @@ -891,15 +896,15 @@ typedef struct _upb_tabent { * tables. We cast away const sometimes, but *only* when the containing * upb_table is known to be non-const. This requires a bit of care, but * the subtlety is confined to table.c. */ - const struct _upb_tabent *next; + const struct _upb_tabent* next; } upb_tabent; typedef struct { - size_t count; /* Number of entries in the hash part. */ - uint32_t mask; /* Mask to turn hash value -> bucket. */ - uint32_t max_count; /* Max count before we hit our load limit. */ - uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ - upb_tabent *entries; + size_t count; /* Number of entries in the hash part. */ + uint32_t mask; /* Mask to turn hash value -> bucket. */ + uint32_t max_count; /* Max count before we hit our load limit. */ + uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ + upb_tabent* entries; } upb_table; typedef struct { @@ -907,13 +912,13 @@ typedef struct { } upb_strtable; typedef struct { - upb_table t; /* For entries that don't fit in the array part. */ - const upb_tabval *array; /* Array part of the table. See const note above. */ - size_t array_size; /* Array part size. */ - size_t array_count; /* Array part number of elements. */ + upb_table t; /* For entries that don't fit in the array part. */ + const upb_tabval* array; /* Array part of the table. See const note above. */ + size_t array_size; /* Array part size. */ + size_t array_count; /* Array part number of elements. */ } upb_inttable; -UPB_INLINE size_t upb_table_size(const upb_table *t) { +UPB_INLINE size_t upb_table_size(const upb_table* t) { if (t->size_lg2 == 0) return 0; else @@ -921,22 +926,20 @@ UPB_INLINE size_t upb_table_size(const upb_table *t) { } /* Internal-only functions, in .h file only out of necessity. */ -UPB_INLINE bool upb_tabent_isempty(const upb_tabent *e) { - return e->key == 0; -} +UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } /* Initialize and uninitialize a table, respectively. If memory allocation * failed, false is returned that the table is uninitialized. */ -bool upb_inttable_init(upb_inttable *table, upb_arena *a); -bool upb_strtable_init(upb_strtable *table, size_t expected_size, upb_arena *a); +bool upb_inttable_init(upb_inttable* table, upb_Arena* a); +bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); /* Returns the number of values in the table. */ -size_t upb_inttable_count(const upb_inttable *t); -UPB_INLINE size_t upb_strtable_count(const upb_strtable *t) { +size_t upb_inttable_count(const upb_inttable* t); +UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { return t->t.count; } -void upb_strtable_clear(upb_strtable *t); +void upb_strtable_clear(upb_strtable* t); /* Inserts the given key into the hashtable with the given value. The key must * not already exist in the hash table. For string tables, the key must be @@ -945,45 +948,84 @@ void upb_strtable_clear(upb_strtable *t); * * If a table resize was required but memory allocation failed, false is * returned and the table is unchanged. */ -bool upb_inttable_insert(upb_inttable *t, uintptr_t key, upb_value val, - upb_arena *a); -bool upb_strtable_insert(upb_strtable *t, const char *key, size_t len, - upb_value val, upb_arena *a); +bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, + upb_Arena* a); +bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, + upb_value val, upb_Arena* a); /* Looks up key in this table, returning "true" if the key was found. * If v is non-NULL, copies the value for this key into *v. */ -bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v); -bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, - upb_value *v); +bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v); +bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, + upb_value* v); /* For NULL-terminated strings. */ -UPB_INLINE bool upb_strtable_lookup(const upb_strtable *t, const char *key, - upb_value *v) { +UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, + upb_value* v) { return upb_strtable_lookup2(t, key, strlen(key), v); } /* Removes an item from the table. Returns true if the remove was successful, * and stores the removed item in *val if non-NULL. */ -bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val); -bool upb_strtable_remove(upb_strtable *t, const char *key, size_t len, - upb_value *val); +bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val); +bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, + upb_value* val); + +UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_remove2(t, key, strlen(key), v); +} /* Updates an existing entry in an inttable. If the entry does not exist, * returns false and does nothing. Unlike insert/remove, this does not * invalidate iterators. */ -bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val); +bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val); /* Optimizes the table for the current set of entries, for both memory use and * lookup time. Client should call this after all entries have been inserted; * inserting more entries is legal, but will likely require a table resize. */ -void upb_inttable_compact(upb_inttable *t, upb_arena *a); +void upb_inttable_compact(upb_inttable* t, upb_Arena* a); /* Exposed for testing only. */ -bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_arena *a); +bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); /* Iterators ******************************************************************/ -/* Iterators for int and string tables. We are subject to some kind of unusual +/* Iteration over inttable. + * + * intptr_t iter = UPB_INTTABLE_BEGIN; + * uintptr_t key; + * upb_value val; + * while (upb_inttable_next2(t, &key, &val, &iter)) { + * // ... + * } + */ + +#define UPB_INTTABLE_BEGIN -1 + +bool upb_inttable_next2(const upb_inttable* t, uintptr_t* key, upb_value* val, + intptr_t* iter); +void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); + +/* Iteration over strtable. + * + * intptr_t iter = UPB_INTTABLE_BEGIN; + * upb_StringView key; + * upb_value val; + * while (upb_strtable_next2(t, &key, &val, &iter)) { + * // ... + * } + */ + +#define UPB_STRTABLE_BEGIN -1 + +bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, + upb_value* val, intptr_t* iter); +void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); + +/* DEPRECATED iterators, slated for removal. + * + * Iterators for int and string tables. We are subject to some kind of unusual * design constraints: * * For high-level languages: @@ -1004,7 +1046,6 @@ bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_arena *a); * guaranteed not to crash and to return real table elements (except when done() * is true). */ - /* upb_strtable_iter **********************************************************/ /* upb_strtable_iter i; @@ -1017,19 +1058,18 @@ bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_arena *a); */ typedef struct { - const upb_strtable *t; + const upb_strtable* t; size_t index; } upb_strtable_iter; -void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t); -void upb_strtable_next(upb_strtable_iter *i); -bool upb_strtable_done(const upb_strtable_iter *i); -upb_strview upb_strtable_iter_key(const upb_strtable_iter *i); -upb_value upb_strtable_iter_value(const upb_strtable_iter *i); -void upb_strtable_iter_setdone(upb_strtable_iter *i); -bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, - const upb_strtable_iter *i2); - +void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); +void upb_strtable_next(upb_strtable_iter* i); +bool upb_strtable_done(const upb_strtable_iter* i); +upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); +upb_value upb_strtable_iter_value(const upb_strtable_iter* i); +void upb_strtable_iter_setdone(upb_strtable_iter* i); +bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, + const upb_strtable_iter* i2); /* upb_inttable_iter **********************************************************/ @@ -1043,31 +1083,30 @@ bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, */ typedef struct { - const upb_inttable *t; + const upb_inttable* t; size_t index; bool array_part; } upb_inttable_iter; -UPB_INLINE const upb_tabent *str_tabent(const upb_strtable_iter *i) { +UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { return &i->t->t.entries[i->index]; } -void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t); -void upb_inttable_next(upb_inttable_iter *i); -bool upb_inttable_done(const upb_inttable_iter *i); -uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i); -upb_value upb_inttable_iter_value(const upb_inttable_iter *i); -void upb_inttable_iter_setdone(upb_inttable_iter *i); -bool upb_inttable_iter_isequal(const upb_inttable_iter *i1, - const upb_inttable_iter *i2); - +void upb_inttable_begin(upb_inttable_iter* i, const upb_inttable* t); +void upb_inttable_next(upb_inttable_iter* i); +bool upb_inttable_done(const upb_inttable_iter* i); +uintptr_t upb_inttable_iter_key(const upb_inttable_iter* i); +upb_value upb_inttable_iter_value(const upb_inttable_iter* i); +void upb_inttable_iter_setdone(upb_inttable_iter* i); +bool upb_inttable_iter_isequal(const upb_inttable_iter* i1, + const upb_inttable_iter* i2); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif -#endif /* UPB_TABLE_H_ */ +#endif /* UPB_TABLE_H_ */ /* Must be last. */ @@ -1075,110 +1114,196 @@ bool upb_inttable_iter_isequal(const upb_inttable_iter *i1, extern "C" { #endif -/** upb_msglayout *************************************************************/ +/** upb_MiniTable *************************************************************/ -/* upb_msglayout represents the memory layout of a given upb_msgdef. The +/* upb_MiniTable represents the memory layout of a given upb_MessageDef. The * members are public so generated code can initialize them, but users MUST NOT * read or write any of its members. */ -/* These aren't real labels according to descriptor.proto, but in the table we - * use these for map/packed fields instead of UPB_LABEL_REPEATED. */ -enum { - _UPB_LABEL_MAP = 4, - _UPB_LABEL_PACKED = 7 /* Low 3 bits are common with UPB_LABEL_REPEATED. */ -}; - typedef struct { uint32_t number; uint16_t offset; - int16_t presence; /* If >0, hasbit_index. If <0, ~oneof_index. */ - uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */ + int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index + uint16_t submsg_index; // undefined if descriptortype != MESSAGE/GROUP/ENUM uint8_t descriptortype; - int8_t mode; /* upb_fieldmode, with flags from upb_labelflags */ -} upb_msglayout_field; + uint8_t mode; /* upb_FieldMode | upb_LabelFlags | + (upb_FieldRep << upb_FieldRep_Shift) */ +} upb_MiniTable_Field; typedef enum { - _UPB_MODE_MAP = 0, - _UPB_MODE_ARRAY = 1, - _UPB_MODE_SCALAR = 2, -} upb_fieldmode; + kUpb_FieldMode_Map = 0, + kUpb_FieldMode_Array = 1, + kUpb_FieldMode_Scalar = 2, + + kUpb_FieldMode_Mask = 3, /* Mask to isolate the mode from upb_FieldRep. */ +} upb_FieldMode; /* Extra flags on the mode field. */ -enum upb_labelflags { - _UPB_MODE_IS_PACKED = 4, +enum upb_LabelFlags { + upb_LabelFlags_IsPacked = 4, + upb_LabelFlags_IsExtension = 8, +}; + +/* Representation in the message. Derivable from descriptortype and mode, but + * fast access helps the serializer. */ +enum upb_FieldRep { + upb_FieldRep_1Byte = 0, + upb_FieldRep_4Byte = 1, + upb_FieldRep_8Byte = 2, + upb_FieldRep_StringView = 3, + +#if UINTPTR_MAX == 0xffffffff + upb_FieldRep_Pointer = upb_FieldRep_4Byte, +#else + upb_FieldRep_Pointer = upb_FieldRep_8Byte, +#endif + + upb_FieldRep_Shift = + 6, /* Bit offset of the rep in upb_MiniTable_Field.mode */ }; -UPB_INLINE upb_fieldmode _upb_getmode(const upb_msglayout_field *field) { - return (upb_fieldmode)(field->mode & 3); +UPB_INLINE upb_FieldMode upb_FieldMode_Get(const upb_MiniTable_Field* field) { + return (upb_FieldMode)(field->mode & 3); } -UPB_INLINE bool _upb_repeated_or_map(const upb_msglayout_field *field) { - /* This works because upb_fieldmode has no value 3. */ - return !(field->mode & _UPB_MODE_SCALAR); +UPB_INLINE bool upb_IsRepeatedOrMap(const upb_MiniTable_Field* field) { + /* This works because upb_FieldMode has no value 3. */ + return !(field->mode & kUpb_FieldMode_Scalar); } -UPB_INLINE bool _upb_issubmsg(const upb_msglayout_field *field) { - return field->descriptortype == UPB_DTYPE_MESSAGE || - field->descriptortype == UPB_DTYPE_GROUP; +UPB_INLINE bool upb_IsSubMessage(const upb_MiniTable_Field* field) { + return field->descriptortype == kUpb_FieldType_Message || + field->descriptortype == kUpb_FieldType_Group; } -struct upb_decstate; -struct upb_msglayout; +struct upb_Decoder; +struct upb_MiniTable; -typedef const char *_upb_field_parser(struct upb_decstate *d, const char *ptr, - upb_msg *msg, intptr_t table, - uint64_t hasbits, uint64_t data); +typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data); typedef struct { uint64_t field_data; - _upb_field_parser *field_parser; -} _upb_fasttable_entry; + _upb_FieldParser* field_parser; +} _upb_FastTable_Entry; + +typedef struct { + const int32_t* values; // List of values <0 or >63 + uint64_t mask; // Bits are set for acceptable value 0 <= x < 64 + int value_count; +} upb_MiniTable_Enum; + +UPB_INLINE bool upb_MiniTable_Enum_CheckValue(const upb_MiniTable_Enum* e, + int32_t val) { + uint32_t uval = (uint32_t)val; + if (uval < 64) return e->mask & (1 << uval); + // OPT: binary search long lists? + int n = e->value_count; + for (int i = 0; i < n; i++) { + if (e->values[i] == val) return true; + } + return false; +} + +typedef union { + const struct upb_MiniTable* submsg; + const upb_MiniTable_Enum* subenum; +} upb_MiniTable_Sub; -struct upb_msglayout { - const struct upb_msglayout *const* submsgs; - const upb_msglayout_field *fields; +typedef enum { + upb_ExtMode_NonExtendable = 0, // Non-extendable message. + upb_ExtMode_Extendable = 1, // Normal extendable message. + upb_ExtMode_IsMessageSet = 2, // MessageSet message. + upb_ExtMode_IsMessageSet_ITEM = + 3, // MessageSet item (temporary only, see decode.c) +} upb_ExtMode; + +/* MessageSet wire format is: + * message MessageSet { + * repeated group Item = 1 { + * required int32 type_id = 2; + * required string message = 3; + * } + * } + */ +typedef enum { + _UPB_MSGSET_ITEM = 1, + _UPB_MSGSET_TYPEID = 2, + _UPB_MSGSET_MESSAGE = 3, +} upb_msgext_fieldnum; + +struct upb_MiniTable { + const upb_MiniTable_Sub* subs; + const upb_MiniTable_Field* fields; /* Must be aligned to sizeof(void*). Doesn't include internal members like * unknown fields, extension dict, pointer to msglayout, etc. */ uint16_t size; uint16_t field_count; - bool extendable; + uint8_t ext; // upb_ExtMode, declared as uint8_t so sizeof(ext) == 1 uint8_t dense_below; uint8_t table_mask; - /* To constant-initialize the tables of variable length, we need a flexible - * array member, and we need to compile in C99 mode. */ - _upb_fasttable_entry fasttable[]; + uint8_t required_count; // Required fields have the lowest hasbits. + /* To statically initialize the tables of variable length, we need a flexible + * array member, and we need to compile in gnu99 mode (constant initialization + * of flexible array members is a GNU extension, not in C99 unfortunately. */ + _upb_FastTable_Entry fasttable[]; }; typedef struct { - upb_msglayout_field field; - const upb_msglayout *extendee; - const upb_msglayout *submsg; /* NULL for non-submessage fields. */ -} upb_msglayout_ext; + upb_MiniTable_Field field; + const upb_MiniTable* extendee; + upb_MiniTable_Sub sub; /* NULL unless submessage or proto2 enum */ +} upb_MiniTable_Extension; + +typedef struct { + const upb_MiniTable** msgs; + const upb_MiniTable_Enum** enums; + const upb_MiniTable_Extension** exts; + int msg_count; + int enum_count; + int ext_count; +} upb_MiniTable_File; + +// Computes a bitmask in which the |l->required_count| lowest bits are set, +// except that we skip the lowest bit (because upb never uses hasbit 0). +// +// Sample output: +// requiredmask(1) => 0b10 (0x2) +// requiredmask(5) => 0b111110 (0x3e) +UPB_INLINE uint64_t upb_MiniTable_requiredmask(const upb_MiniTable* l) { + int n = l->required_count; + assert(0 < n && n <= 63); + return ((1ULL << n) - 1) << 1; +} -/** upb_extreg ****************************************************************/ +/** upb_ExtensionRegistry + * ****************************************************************/ /* Adds the given extension info for message type |l| and field number |num| * into the registry. Returns false if this message type and field number were * already in the map, or if memory allocation fails. */ -bool _upb_extreg_add(upb_extreg *r, const upb_msglayout_ext *e, size_t count); +bool _upb_extreg_add(upb_ExtensionRegistry* r, + const upb_MiniTable_Extension** e, size_t count); /* Looks up the extension (if any) defined for message type |l| and field * number |num|. If an extension was found, copies the field info into |*ext| * and returns true. Otherwise returns false. */ -const upb_msglayout_field *_upb_extreg_get(const upb_extreg *r, - const upb_msglayout *l, - uint32_t num); +const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, + const upb_MiniTable* l, + uint32_t num); -/** upb_msg *******************************************************************/ +/** upb_Message + * *******************************************************************/ -/* Internal members of a upb_msg that track unknown fields and/or extensions. - * We can change this without breaking binary compatibility. We put these - * before the user's data. The user's upb_msg* points after the - * upb_msg_internal. */ +/* Internal members of a upb_Message that track unknown fields and/or + * extensions. We can change this without breaking binary compatibility. We put + * these before the user's data. The user's upb_Message* points after the + * upb_Message_Internal. */ typedef struct { /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_msg_ext) */ + * Must be aligned to 8, which is alignof(upb_Message_Extension) */ uint32_t size; /* Offsets relative to the beginning of this structure. @@ -1188,160 +1313,176 @@ typedef struct { * When the two meet, we're out of data and have to realloc. * * If we imagine that the final member of this struct is: - * char data[size - overhead]; // overhead = sizeof(upb_msg_internaldata) - * + * char data[size - overhead]; // overhead = + * sizeof(upb_Message_InternalData) + * * Then we have: * unknown data: data[0 .. (unknown_end - overhead)] * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ uint32_t unknown_end; uint32_t ext_begin; /* Data follows, as if there were an array: - * char data[size - sizeof(upb_msg_internaldata)]; */ -} upb_msg_internaldata; + * char data[size - sizeof(upb_Message_InternalData)]; */ +} upb_Message_InternalData; typedef struct { - upb_msg_internaldata *internal; -} upb_msg_internal; + upb_Message_InternalData* internal; + /* Message data follows. */ +} upb_Message_Internal; -/* Maps upb_fieldtype_t -> memory size. */ -extern char _upb_fieldtype_to_size[12]; +/* Maps upb_CType -> memory size. */ +extern char _upb_CTypeo_size[12]; -UPB_INLINE size_t upb_msg_sizeof(const upb_msglayout *l) { - return l->size + sizeof(upb_msg_internal); +UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* l) { + return l->size + sizeof(upb_Message_Internal); } -UPB_INLINE upb_msg *_upb_msg_new_inl(const upb_msglayout *l, upb_arena *a) { +UPB_INLINE upb_Message* _upb_Message_New_inl(const upb_MiniTable* l, + upb_Arena* a) { size_t size = upb_msg_sizeof(l); - void *mem = upb_arena_malloc(a, size); - upb_msg *msg; + void* mem = upb_Arena_Malloc(a, size); + upb_Message* msg; if (UPB_UNLIKELY(!mem)) return NULL; - msg = UPB_PTR_AT(mem, sizeof(upb_msg_internal), upb_msg); + msg = UPB_PTR_AT(mem, sizeof(upb_Message_Internal), upb_Message); memset(mem, 0, size); return msg; } /* Creates a new messages with the given layout on the given arena. */ -upb_msg *_upb_msg_new(const upb_msglayout *l, upb_arena *a); +upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a); -UPB_INLINE upb_msg_internal *upb_msg_getinternal(upb_msg *msg) { - ptrdiff_t size = sizeof(upb_msg_internal); - return (upb_msg_internal*)((char*)msg - size); +UPB_INLINE upb_Message_Internal* upb_Message_Getinternal(upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); } /* Clears the given message. */ -void _upb_msg_clear(upb_msg *msg, const upb_msglayout *l); +void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l); /* Discards the unknown fields for this message only. */ -void _upb_msg_discardunknown_shallow(upb_msg *msg); +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg); /* Adds unknown data (serialized protobuf data) to the given message. The data * is copied into the message instance. */ -bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len, - upb_arena *arena); +bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena); -/** upb_msg_ext ***************************************************************/ +/** upb_Message_Extension + * ***************************************************************/ /* The internal representation of an extension is self-describing: it contains * enough information that we can serialize it to binary format without needing - * to look it up in a registry. */ + * to look it up in a upb_ExtensionRegistry. + * + * This representation allocates 16 bytes to data on 64-bit platforms. This is + * rather wasteful for scalars (in the extreme case of bool, it wastes 15 + * bytes). We accept this because we expect messages to be the most common + * extension type. */ typedef struct { - const upb_msglayout_ext *ext; + const upb_MiniTable_Extension* ext; union { - upb_strview str; - void *ptr; - double dbl; + upb_StringView str; + void* ptr; char scalar_data[8]; } data; -} upb_msg_ext; +} upb_Message_Extension; -/* Adds the given extension data to the given message. The returned extension will - * have its "ext" member initialized according to |ext|. */ -upb_msg_ext *_upb_msg_getorcreateext(upb_msg *msg, const upb_msglayout_ext *ext, - upb_arena *arena); +/* Adds the given extension data to the given message. |ext| is copied into the + * message instance. This logically replaces any previously-added extension with + * this number */ +upb_Message_Extension* _upb_Message_Getorcreateext( + upb_Message* msg, const upb_MiniTable_Extension* ext, upb_Arena* arena); /* Returns an array of extensions for this message. Note: the array is * ordered in reverse relative to the order of creation. */ -const upb_msg_ext *_upb_msg_getexts(const upb_msg *msg, size_t *count); +const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count); /* Returns an extension for the given field number, or NULL if no extension * exists for this field number. */ -const upb_msg_ext *_upb_msg_getext(const upb_msg *msg, - const upb_msglayout_ext *ext); +const upb_Message_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTable_Extension* ext); + +void _upb_Message_Clearext(upb_Message* msg, + const upb_MiniTable_Extension* ext); + +void _upb_Message_Clearext(upb_Message* msg, + const upb_MiniTable_Extension* ext); /** Hasbit access *************************************************************/ -UPB_INLINE bool _upb_hasbit(const upb_msg *msg, size_t idx) { +UPB_INLINE bool _upb_hasbit(const upb_Message* msg, size_t idx) { return (*UPB_PTR_AT(msg, idx / 8, const char) & (1 << (idx % 8))) != 0; } -UPB_INLINE void _upb_sethas(const upb_msg *msg, size_t idx) { +UPB_INLINE void _upb_sethas(const upb_Message* msg, size_t idx) { (*UPB_PTR_AT(msg, idx / 8, char)) |= (char)(1 << (idx % 8)); } -UPB_INLINE void _upb_clearhas(const upb_msg *msg, size_t idx) { +UPB_INLINE void _upb_clearhas(const upb_Message* msg, size_t idx) { (*UPB_PTR_AT(msg, idx / 8, char)) &= (char)(~(1 << (idx % 8))); } -UPB_INLINE size_t _upb_msg_hasidx(const upb_msglayout_field *f) { +UPB_INLINE size_t _upb_Message_Hasidx(const upb_MiniTable_Field* f) { UPB_ASSERT(f->presence > 0); return f->presence; } -UPB_INLINE bool _upb_hasbit_field(const upb_msg *msg, - const upb_msglayout_field *f) { - return _upb_hasbit(msg, _upb_msg_hasidx(f)); +UPB_INLINE bool _upb_hasbit_field(const upb_Message* msg, + const upb_MiniTable_Field* f) { + return _upb_hasbit(msg, _upb_Message_Hasidx(f)); } -UPB_INLINE void _upb_sethas_field(const upb_msg *msg, - const upb_msglayout_field *f) { - _upb_sethas(msg, _upb_msg_hasidx(f)); +UPB_INLINE void _upb_sethas_field(const upb_Message* msg, + const upb_MiniTable_Field* f) { + _upb_sethas(msg, _upb_Message_Hasidx(f)); } -UPB_INLINE void _upb_clearhas_field(const upb_msg *msg, - const upb_msglayout_field *f) { - _upb_clearhas(msg, _upb_msg_hasidx(f)); +UPB_INLINE void _upb_clearhas_field(const upb_Message* msg, + const upb_MiniTable_Field* f) { + _upb_clearhas(msg, _upb_Message_Hasidx(f)); } /** Oneof case access *********************************************************/ -UPB_INLINE uint32_t *_upb_oneofcase(upb_msg *msg, size_t case_ofs) { +UPB_INLINE uint32_t* _upb_oneofcase(upb_Message* msg, size_t case_ofs) { return UPB_PTR_AT(msg, case_ofs, uint32_t); } -UPB_INLINE uint32_t _upb_getoneofcase(const void *msg, size_t case_ofs) { +UPB_INLINE uint32_t _upb_getoneofcase(const void* msg, size_t case_ofs) { return *UPB_PTR_AT(msg, case_ofs, uint32_t); } -UPB_INLINE size_t _upb_oneofcase_ofs(const upb_msglayout_field *f) { +UPB_INLINE size_t _upb_oneofcase_ofs(const upb_MiniTable_Field* f) { UPB_ASSERT(f->presence < 0); return ~(ptrdiff_t)f->presence; } -UPB_INLINE uint32_t *_upb_oneofcase_field(upb_msg *msg, - const upb_msglayout_field *f) { +UPB_INLINE uint32_t* _upb_oneofcase_field(upb_Message* msg, + const upb_MiniTable_Field* f) { return _upb_oneofcase(msg, _upb_oneofcase_ofs(f)); } -UPB_INLINE uint32_t _upb_getoneofcase_field(const upb_msg *msg, - const upb_msglayout_field *f) { +UPB_INLINE uint32_t _upb_getoneofcase_field(const upb_Message* msg, + const upb_MiniTable_Field* f) { return _upb_getoneofcase(msg, _upb_oneofcase_ofs(f)); } -UPB_INLINE bool _upb_has_submsg_nohasbit(const upb_msg *msg, size_t ofs) { - return *UPB_PTR_AT(msg, ofs, const upb_msg*) != NULL; +UPB_INLINE bool _upb_has_submsg_nohasbit(const upb_Message* msg, size_t ofs) { + return *UPB_PTR_AT(msg, ofs, const upb_Message*) != NULL; } -/** upb_array *****************************************************************/ +/** upb_Array *****************************************************************/ /* Our internal representation for repeated fields. */ typedef struct { - uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ - size_t len; /* Measured in elements. */ - size_t size; /* Measured in elements. */ + uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ + size_t len; /* Measured in elements. */ + size_t size; /* Measured in elements. */ uint64_t junk; -} upb_array; +} upb_Array; -UPB_INLINE const void *_upb_array_constptr(const upb_array *arr) { +UPB_INLINE const void* _upb_array_constptr(const upb_Array* arr) { UPB_ASSERT((arr->data & 7) <= 4); return (void*)(arr->data & ~(uintptr_t)7); } @@ -1351,7 +1492,7 @@ UPB_INLINE uintptr_t _upb_array_tagptr(void* ptr, int elem_size_lg2) { return (uintptr_t)ptr | elem_size_lg2; } -UPB_INLINE void *_upb_array_ptr(upb_array *arr) { +UPB_INLINE void* _upb_array_ptr(upb_Array* arr) { return (void*)_upb_array_constptr(arr); } @@ -1361,11 +1502,11 @@ UPB_INLINE uintptr_t _upb_tag_arrptr(void* ptr, int elem_size_lg2) { return (uintptr_t)ptr | (unsigned)elem_size_lg2; } -UPB_INLINE upb_array *_upb_array_new(upb_arena *a, size_t init_size, +UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, size_t init_size, int elem_size_lg2) { - const size_t arr_size = UPB_ALIGN_UP(sizeof(upb_array), 8); - const size_t bytes = sizeof(upb_array) + (init_size << elem_size_lg2); - upb_array *arr = (upb_array*)upb_arena_malloc(a, bytes); + const size_t arr_size = UPB_ALIGN_UP(sizeof(upb_Array), 8); + const size_t bytes = sizeof(upb_Array) + (init_size << elem_size_lg2); + upb_Array* arr = (upb_Array*)upb_Arena_Malloc(a, bytes); if (!arr) return NULL; arr->data = _upb_tag_arrptr(UPB_PTR_AT(arr, arr_size, void), elem_size_lg2); arr->len = 0; @@ -1374,30 +1515,30 @@ UPB_INLINE upb_array *_upb_array_new(upb_arena *a, size_t init_size, } /* Resizes the capacity of the array to be at least min_size. */ -bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena); +bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena); /* Fallback functions for when the accessors require a resize. */ -void *_upb_array_resize_fallback(upb_array **arr_ptr, size_t size, - int elem_size_lg2, upb_arena *arena); -bool _upb_array_append_fallback(upb_array **arr_ptr, const void *value, - int elem_size_lg2, upb_arena *arena); +void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, + int elem_size_lg2, upb_Arena* arena); +bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, + int elem_size_lg2, upb_Arena* arena); -UPB_INLINE bool _upb_array_reserve(upb_array *arr, size_t size, - upb_arena *arena) { +UPB_INLINE bool _upb_array_reserve(upb_Array* arr, size_t size, + upb_Arena* arena) { if (arr->size < size) return _upb_array_realloc(arr, size, arena); return true; } -UPB_INLINE bool _upb_array_resize(upb_array *arr, size_t size, - upb_arena *arena) { +UPB_INLINE bool _upb_Array_Resize(upb_Array* arr, size_t size, + upb_Arena* arena) { if (!_upb_array_reserve(arr, size, arena)) return false; arr->len = size; return true; } -UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs, - size_t *size) { - const upb_array *arr = *UPB_PTR_AT(msg, ofs, const upb_array*); +UPB_INLINE const void* _upb_array_accessor(const void* msg, size_t ofs, + size_t* size) { + const upb_Array* arr = *UPB_PTR_AT(msg, ofs, const upb_Array*); if (arr) { if (size) *size = arr->len; return _upb_array_constptr(arr); @@ -1407,9 +1548,9 @@ UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs, } } -UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs, - size_t *size) { - upb_array *arr = *UPB_PTR_AT(msg, ofs, upb_array*); +UPB_INLINE void* _upb_array_mutable_accessor(void* msg, size_t ofs, + size_t* size) { + upb_Array* arr = *UPB_PTR_AT(msg, ofs, upb_Array*); if (arr) { if (size) *size = arr->len; return _upb_array_ptr(arr); @@ -1419,28 +1560,28 @@ UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs, } } -UPB_INLINE void *_upb_array_resize_accessor2(void *msg, size_t ofs, size_t size, +UPB_INLINE void* _upb_Array_Resize_accessor2(void* msg, size_t ofs, size_t size, int elem_size_lg2, - upb_arena *arena) { - upb_array **arr_ptr = UPB_PTR_AT(msg, ofs, upb_array *); - upb_array *arr = *arr_ptr; + upb_Arena* arena) { + upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); + upb_Array* arr = *arr_ptr; if (!arr || arr->size < size) { - return _upb_array_resize_fallback(arr_ptr, size, elem_size_lg2, arena); + return _upb_Array_Resize_fallback(arr_ptr, size, elem_size_lg2, arena); } arr->len = size; return _upb_array_ptr(arr); } -UPB_INLINE bool _upb_array_append_accessor2(void *msg, size_t ofs, +UPB_INLINE bool _upb_Array_Append_accessor2(void* msg, size_t ofs, int elem_size_lg2, - const void *value, - upb_arena *arena) { - upb_array **arr_ptr = UPB_PTR_AT(msg, ofs, upb_array *); + const void* value, + upb_Arena* arena) { + upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); size_t elem_size = 1 << elem_size_lg2; - upb_array *arr = *arr_ptr; - void *ptr; + upb_Array* arr = *arr_ptr; + void* ptr; if (!arr || arr->len == arr->size) { - return _upb_array_append_fallback(arr_ptr, value, elem_size_lg2, arena); + return _upb_Array_Append_fallback(arr_ptr, value, elem_size_lg2, arena); } ptr = _upb_array_ptr(arr); memcpy(UPB_PTR_AT(ptr, arr->len * elem_size, char), value, elem_size); @@ -1449,42 +1590,41 @@ UPB_INLINE bool _upb_array_append_accessor2(void *msg, size_t ofs, } /* Used by old generated code, remove once all code has been regenerated. */ -UPB_INLINE int _upb_sizelg2(upb_fieldtype_t type) { +UPB_INLINE int _upb_sizelg2(upb_CType type) { switch (type) { - case UPB_TYPE_BOOL: + case kUpb_CType_Bool: return 0; - case UPB_TYPE_FLOAT: - case UPB_TYPE_INT32: - case UPB_TYPE_UINT32: - case UPB_TYPE_ENUM: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: return 2; - case UPB_TYPE_MESSAGE: + case kUpb_CType_Message: return UPB_SIZE(2, 3); - case UPB_TYPE_DOUBLE: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT64: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: return 3; - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: + case kUpb_CType_String: + case kUpb_CType_Bytes: return UPB_SIZE(3, 4); } UPB_UNREACHABLE(); } -UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size, - upb_fieldtype_t type, - upb_arena *arena) { - return _upb_array_resize_accessor2(msg, ofs, size, _upb_sizelg2(type), arena); +UPB_INLINE void* _upb_Array_Resize_accessor(void* msg, size_t ofs, size_t size, + upb_CType type, upb_Arena* arena) { + return _upb_Array_Resize_accessor2(msg, ofs, size, _upb_sizelg2(type), arena); } -UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs, - size_t elem_size, upb_fieldtype_t type, - const void *value, - upb_arena *arena) { +UPB_INLINE bool _upb_Array_Append_accessor(void* msg, size_t ofs, + size_t elem_size, upb_CType type, + const void* value, + upb_Arena* arena) { (void)elem_size; - return _upb_array_append_accessor2(msg, ofs, _upb_sizelg2(type), value, + return _upb_Array_Append_accessor2(msg, ofs, _upb_sizelg2(type), value, arena); } -/** upb_map *******************************************************************/ +/** upb_Map *******************************************************************/ /* Right now we use strmaps for everything. We'll likely want to use * integer-specific maps for integer-keyed maps.*/ @@ -1495,25 +1635,25 @@ typedef struct { char val_size; upb_strtable table; -} upb_map; +} upb_Map; /* Map entries aren't actually stored, they are only used during parsing. For * parsing, it helps a lot if all map entry messages have the same layout. * The compiler and def.c must ensure that all map entries have this layout. */ typedef struct { - upb_msg_internal internal; + upb_Message_Internal internal; union { - upb_strview str; /* For str/bytes. */ - upb_value val; /* For all other types. */ + upb_StringView str; /* For str/bytes. */ + upb_value val; /* For all other types. */ } k; union { - upb_strview str; /* For str/bytes. */ - upb_value val; /* For all other types. */ + upb_StringView str; /* For str/bytes. */ + upb_value val; /* For all other types. */ } v; -} upb_map_entry; +} upb_MapEntry; /* Creates a new map on the given arena with this key/value type. */ -upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size); +upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); /* Converting between internal table representation and user values. * @@ -1524,15 +1664,15 @@ upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size); * from other types when stored in a map. */ -UPB_INLINE upb_strview _upb_map_tokey(const void *key, size_t size) { +UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { if (size == UPB_MAPTYPE_STRING) { - return *(upb_strview*)key; + return *(upb_StringView*)key; } else { - return upb_strview_make((const char*)key, size); + return upb_StringView_FromDataAndSize((const char*)key, size); } } -UPB_INLINE void _upb_map_fromkey(upb_strview key, void* out, size_t size) { +UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { if (size == UPB_MAPTYPE_STRING) { memcpy(out, &key, sizeof(key)); } else { @@ -1540,12 +1680,12 @@ UPB_INLINE void _upb_map_fromkey(upb_strview key, void* out, size_t size) { } } -UPB_INLINE bool _upb_map_tovalue(const void *val, size_t size, upb_value *msgval, - upb_arena *a) { +UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, + upb_value* msgval, upb_Arena* a) { if (size == UPB_MAPTYPE_STRING) { - upb_strview *strp = (upb_strview*)upb_arena_malloc(a, sizeof(*strp)); + upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); if (!strp) return false; - *strp = *(upb_strview*)val; + *strp = *(upb_StringView*)val; *msgval = upb_value_ptr(strp); } else { memcpy(msgval, val, size); @@ -1555,8 +1695,8 @@ UPB_INLINE bool _upb_map_tovalue(const void *val, size_t size, upb_value *msgval UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { if (size == UPB_MAPTYPE_STRING) { - const upb_strview *strp = (const upb_strview*)upb_value_getptr(val); - memcpy(out, strp, sizeof(upb_strview)); + const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); + memcpy(out, strp, sizeof(upb_StringView)); } else { memcpy(out, &val, size); } @@ -1564,14 +1704,14 @@ UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { /* Map operations, shared by reflection and generated code. */ -UPB_INLINE size_t _upb_map_size(const upb_map *map) { +UPB_INLINE size_t _upb_Map_Size(const upb_Map* map) { return map->table.t.count; } -UPB_INLINE bool _upb_map_get(const upb_map *map, const void *key, - size_t key_size, void *val, size_t val_size) { +UPB_INLINE bool _upb_Map_Get(const upb_Map* map, const void* key, + size_t key_size, void* val, size_t val_size) { upb_value tabval; - upb_strview k = _upb_map_tokey(key, key_size); + upb_StringView k = _upb_map_tokey(key, key_size); bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); if (ret && val) { _upb_map_fromvalue(tabval, val, val_size); @@ -1579,7 +1719,7 @@ UPB_INLINE bool _upb_map_get(const upb_map *map, const void *key, return ret; } -UPB_INLINE void* _upb_map_next(const upb_map *map, size_t *iter) { +UPB_INLINE void* _upb_map_next(const upb_Map* map, size_t* iter) { upb_strtable_iter it; it.t = &map->table; it.index = *iter; @@ -1589,108 +1729,111 @@ UPB_INLINE void* _upb_map_next(const upb_map *map, size_t *iter) { return (void*)str_tabent(&it); } -UPB_INLINE bool _upb_map_set(upb_map *map, const void *key, size_t key_size, - void *val, size_t val_size, upb_arena *a) { - upb_strview strkey = _upb_map_tokey(key, key_size); +UPB_INLINE bool _upb_Map_Set(upb_Map* map, const void* key, size_t key_size, + void* val, size_t val_size, upb_Arena* a) { + upb_StringView strkey = _upb_map_tokey(key, key_size); upb_value tabval = {0}; if (!_upb_map_tovalue(val, val_size, &tabval, a)) return false; /* TODO(haberman): add overwrite operation to minimize number of lookups. */ - upb_strtable_remove(&map->table, strkey.data, strkey.size, NULL); + upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); return upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a); } -UPB_INLINE bool _upb_map_delete(upb_map *map, const void *key, size_t key_size) { - upb_strview k = _upb_map_tokey(key, key_size); - return upb_strtable_remove(&map->table, k.data, k.size, NULL); +UPB_INLINE bool _upb_Map_Delete(upb_Map* map, const void* key, + size_t key_size) { + upb_StringView k = _upb_map_tokey(key, key_size); + return upb_strtable_remove2(&map->table, k.data, k.size, NULL); } -UPB_INLINE void _upb_map_clear(upb_map *map) { +UPB_INLINE void _upb_Map_Clear(upb_Map* map) { upb_strtable_clear(&map->table); } /* Message map operations, these get the map from the message first. */ -UPB_INLINE size_t _upb_msg_map_size(const upb_msg *msg, size_t ofs) { - upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); - return map ? _upb_map_size(map) : 0; +UPB_INLINE size_t _upb_msg_map_size(const upb_Message* msg, size_t ofs) { + upb_Map* map = *UPB_PTR_AT(msg, ofs, upb_Map*); + return map ? _upb_Map_Size(map) : 0; } -UPB_INLINE bool _upb_msg_map_get(const upb_msg *msg, size_t ofs, - const void *key, size_t key_size, void *val, +UPB_INLINE bool _upb_msg_map_get(const upb_Message* msg, size_t ofs, + const void* key, size_t key_size, void* val, size_t val_size) { - upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); + upb_Map* map = *UPB_PTR_AT(msg, ofs, upb_Map*); if (!map) return false; - return _upb_map_get(map, key, key_size, val, val_size); + return _upb_Map_Get(map, key, key_size, val, val_size); } -UPB_INLINE void *_upb_msg_map_next(const upb_msg *msg, size_t ofs, - size_t *iter) { - upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); +UPB_INLINE void* _upb_msg_map_next(const upb_Message* msg, size_t ofs, + size_t* iter) { + upb_Map* map = *UPB_PTR_AT(msg, ofs, upb_Map*); if (!map) return NULL; return _upb_map_next(map, iter); } -UPB_INLINE bool _upb_msg_map_set(upb_msg *msg, size_t ofs, const void *key, - size_t key_size, void *val, size_t val_size, - upb_arena *arena) { - upb_map **map = UPB_PTR_AT(msg, ofs, upb_map *); +UPB_INLINE bool _upb_msg_map_set(upb_Message* msg, size_t ofs, const void* key, + size_t key_size, void* val, size_t val_size, + upb_Arena* arena) { + upb_Map** map = UPB_PTR_AT(msg, ofs, upb_Map*); if (!*map) { - *map = _upb_map_new(arena, key_size, val_size); + *map = _upb_Map_New(arena, key_size, val_size); } - return _upb_map_set(*map, key, key_size, val, val_size, arena); + return _upb_Map_Set(*map, key, key_size, val, val_size, arena); } -UPB_INLINE bool _upb_msg_map_delete(upb_msg *msg, size_t ofs, const void *key, - size_t key_size) { - upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); +UPB_INLINE bool _upb_msg_map_delete(upb_Message* msg, size_t ofs, + const void* key, size_t key_size) { + upb_Map* map = *UPB_PTR_AT(msg, ofs, upb_Map*); if (!map) return false; - return _upb_map_delete(map, key, key_size); + return _upb_Map_Delete(map, key, key_size); } -UPB_INLINE void _upb_msg_map_clear(upb_msg *msg, size_t ofs) { - upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *); +UPB_INLINE void _upb_msg_map_clear(upb_Message* msg, size_t ofs) { + upb_Map* map = *UPB_PTR_AT(msg, ofs, upb_Map*); if (!map) return; - _upb_map_clear(map); + _upb_Map_Clear(map); } /* Accessing map key/value from a pointer, used by generated code only. */ UPB_INLINE void _upb_msg_map_key(const void* msg, void* key, size_t size) { - const upb_tabent *ent = (const upb_tabent*)msg; + const upb_tabent* ent = (const upb_tabent*)msg; uint32_t u32len; - upb_strview k; + upb_StringView k; k.data = upb_tabstr(ent->key, &u32len); k.size = u32len; _upb_map_fromkey(k, key, size); } UPB_INLINE void _upb_msg_map_value(const void* msg, void* val, size_t size) { - const upb_tabent *ent = (const upb_tabent*)msg; + const upb_tabent* ent = (const upb_tabent*)msg; upb_value v = {ent->val.val}; _upb_map_fromvalue(v, val, size); } -UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, size_t size) { - upb_tabent *ent = (upb_tabent*)msg; +UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, + size_t size) { + upb_tabent* ent = (upb_tabent*)msg; /* This is like _upb_map_tovalue() except the entry already exists so we can - * reuse the allocated upb_strview for string fields. */ + * reuse the allocated upb_StringView for string fields. */ if (size == UPB_MAPTYPE_STRING) { - upb_strview *strp = (upb_strview*)(uintptr_t)ent->val.val; + upb_StringView* strp = (upb_StringView*)(uintptr_t)ent->val.val; memcpy(strp, val, sizeof(*strp)); } else { memcpy(&ent->val.val, val, size); } } -/** _upb_mapsorter *************************************************************/ +/** _upb_mapsorter + * *************************************************************/ /* _upb_mapsorter sorts maps and provides ordered iteration over the entries. - * Since maps can be recursive (map values can be messages which contain other maps). - * _upb_mapsorter can contain a stack of maps. */ + * Since maps can be recursive (map values can be messages which contain other + * maps). _upb_mapsorter can contain a stack of maps. */ typedef struct { - upb_tabent const**entries; + upb_tabent const** entries; int size; int cap; } _upb_mapsorter; @@ -1701,29 +1844,29 @@ typedef struct { int end; } _upb_sortedmap; -UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter *s) { +UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { s->entries = NULL; s->size = 0; s->cap = 0; } -UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter *s) { +UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { if (s->entries) free(s->entries); } -bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type, - const upb_map *map, _upb_sortedmap *sorted); +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted); -UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter *s, _upb_sortedmap *sorted) { +UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, + _upb_sortedmap* sorted) { s->size = sorted->start; } -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter *s, const upb_map *map, - _upb_sortedmap *sorted, - upb_map_entry *ent) { +UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, + _upb_sortedmap* sorted, upb_MapEntry* ent) { if (sorted->pos == sorted->end) return false; - const upb_tabent *tabent = s->entries[sorted->pos++]; - upb_strview key = upb_tabstrview(tabent->key); + const upb_tabent* tabent = s->entries[sorted->pos++]; + upb_StringView key = upb_tabstrview(tabent->key); _upb_map_fromkey(key, &ent->k, map->key_size); upb_value val = {tabent->val.val}; _upb_map_fromvalue(val, &ent->v, map->val_size); @@ -1731,7 +1874,7 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter *s, const upb_map *map, } #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif @@ -1745,8 +1888,8 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter *s, const upb_map *map, struct mem_block; typedef struct mem_block mem_block; -struct upb_arena { - _upb_arena_head head; +struct upb_Arena { + _upb_ArenaHead head; /* Stores cleanup metadata for this arena. * - a pointer to the current cleanup counter. * - a boolean indicating if there is an unowned initial block. */ @@ -1754,38 +1897,58 @@ struct upb_arena { /* Allocator to allocate arena blocks. We are responsible for freeing these * when we are destroyed. */ - upb_alloc *block_alloc; + upb_alloc* block_alloc; uint32_t last_size; /* When multiple arenas are fused together, each arena points to a parent * arena (root points to itself). The root tracks how many live arenas * reference it. */ - uint32_t refcount; /* Only used when a->parent == a */ - struct upb_arena *parent; + uint32_t refcount; /* Only used when a->parent == a */ + struct upb_Arena* parent; /* Linked list of blocks to free/cleanup. */ mem_block *freelist, *freelist_tail; }; -#endif /* UPB_INT_H_ */ +// Encodes a float or double that is round-trippable, but as short as possible. +// These routines are not fully optimal (not guaranteed to be shortest), but are +// short-ish and match the implementation that has been used in protobuf since +// the beginning. +// +// The given buffer size must be at least kUpb_RoundTripBufferSize. +enum { + kUpb_RoundTripBufferSize = 32 +}; +void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size); +void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); + +#endif /* UPB_INT_H_ */ /* Must be last. */ -#define DECODE_NOGROUP (uint32_t)-1 - -typedef struct upb_decstate { - const char *end; /* Can read up to 16 bytes slop beyond this. */ - const char *limit_ptr; /* = end + UPB_MIN(limit, 0) */ - upb_msg *unknown_msg; /* If non-NULL, add unknown data at buffer flip. */ - const char *unknown; /* Start of unknown data. */ - int limit; /* Submessage limit relative to end. */ - int depth; - uint32_t end_group; /* field number of END_GROUP tag, else DECODE_NOGROUP */ - bool alias; +#define DECODE_NOGROUP (uint32_t) - 1 + +typedef struct upb_Decoder { + const char* end; /* Can read up to 16 bytes slop beyond this. */ + const char* limit_ptr; /* = end + UPB_MIN(limit, 0) */ + upb_Message* unknown_msg; /* If non-NULL, add unknown data at buffer flip. */ + const char* unknown; /* Start of unknown data. */ + const upb_ExtensionRegistry* + extreg; /* For looking up extensions during the parse. */ + int limit; /* Submessage limit relative to end. */ + int depth; /* Tracks recursion depth to bound stack usage. */ + uint32_t end_group; /* field number of END_GROUP tag, else DECODE_NOGROUP */ + uint16_t options; + bool missing_required; char patch[32]; - upb_arena arena; + upb_Arena arena; jmp_buf err; -} upb_decstate; + +#ifndef NDEBUG + const char* debug_tagstart; + const char* debug_valstart; +#endif +} upb_Decoder; /* Error function that will abort decoding with longjmp(). We can't declare this * UPB_NORETURN, even though it is appropriate, because if we do then compilers @@ -1794,50 +1957,58 @@ typedef struct upb_decstate { * of our optimizations. That is also why we must declare it in a separate file, * otherwise the compiler will see that it calls longjmp() and deduce that it is * noreturn. */ -const char *fastdecode_err(upb_decstate *d); +const char* fastdecode_err(upb_Decoder* d, int status); extern const uint8_t upb_utf8_offsets[]; UPB_INLINE -bool decode_verifyutf8_inl(const char *buf, int len) { - int i, j; - uint8_t offset; - - i = 0; - while (i < len) { - offset = upb_utf8_offsets[(uint8_t)buf[i]]; - if (offset == 0 || i + offset > len) { - return false; - } - for (j = i + 1; j < i + offset; j++) { - if ((buf[j] & 0xc0) != 0x80) { - return false; - } - } - i += offset; +bool decode_verifyutf8_inl(const char* ptr, int len) { + const char* end = ptr + len; + + // Check 8 bytes at a time for any non-ASCII char. + while (end - ptr >= 8) { + uint64_t data; + memcpy(&data, ptr, 8); + if (data & 0x8080808080808080) goto non_ascii; + ptr += 8; + } + + // Check one byte at a time for non-ASCII. + while (ptr < end) { + if (*ptr & 0x80) goto non_ascii; + ptr++; } - return i == len; + + return true; + +non_ascii: + return utf8_range2((const unsigned char*)ptr, end - ptr) == 0; } +const char* decode_checkrequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* l); + /* x86-64 pointers always have the high 16 bits matching. So we can shift * left 8 and right 8 without loss of information. */ -UPB_INLINE intptr_t decode_totable(const upb_msglayout *tablep) { +UPB_INLINE intptr_t decode_totable(const upb_MiniTable* tablep) { return ((intptr_t)tablep << 8) | tablep->table_mask; } -UPB_INLINE const upb_msglayout *decode_totablep(intptr_t table) { - return (const upb_msglayout*)(table >> 8); +UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) { + return (const upb_MiniTable*)(table >> 8); } UPB_INLINE -const char *decode_isdonefallback_inl(upb_decstate *d, const char *ptr, - int overrun) { +const char* decode_isdonefallback_inl(upb_Decoder* d, const char* ptr, + int overrun, int* status) { if (overrun < d->limit) { /* Need to copy remaining data into patch buffer. */ UPB_ASSERT(overrun < 16); if (d->unknown_msg) { - if (!_upb_msg_addunknown(d->unknown_msg, d->unknown, ptr - d->unknown, - &d->arena)) { + if (!_upb_Message_AddUnknown(d->unknown_msg, d->unknown, ptr - d->unknown, + &d->arena)) { + *status = kUpb_DecodeStatus_OutOfMemory; return NULL; } d->unknown = &d->patch[0] + overrun; @@ -1848,19 +2019,19 @@ const char *decode_isdonefallback_inl(upb_decstate *d, const char *ptr, d->end = &d->patch[16]; d->limit -= 16; d->limit_ptr = d->end + d->limit; - d->alias = false; + d->options &= ~kUpb_DecodeOption_AliasString; UPB_ASSERT(ptr < d->limit_ptr); return ptr; } else { + *status = kUpb_DecodeStatus_Malformed; return NULL; } } -const char *decode_isdonefallback(upb_decstate *d, const char *ptr, - int overrun); +const char* decode_isdonefallback(upb_Decoder* d, const char* ptr, int overrun); UPB_INLINE -bool decode_isdone(upb_decstate *d, const char **ptr) { +bool decode_isdone(upb_Decoder* d, const char** ptr) { int overrun = *ptr - d->end; if (UPB_LIKELY(*ptr < d->limit_ptr)) { return false; @@ -1874,10 +2045,10 @@ bool decode_isdone(upb_decstate *d, const char **ptr) { #if UPB_FASTTABLE UPB_INLINE -const char *fastdecode_tagdispatch(upb_decstate *d, const char *ptr, - upb_msg *msg, intptr_t table, - uint64_t hasbits, uint64_t tag) { - const upb_msglayout *table_p = decode_totablep(table); +const char* fastdecode_tagdispatch(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t tag) { + const upb_MiniTable* table_p = decode_totablep(table); uint8_t mask = table; uint64_t data; size_t idx = tag & mask; @@ -1895,11 +2066,11 @@ UPB_INLINE uint32_t fastdecode_loadtag(const char* ptr) { return tag; } -UPB_INLINE void decode_checklimit(upb_decstate *d) { +UPB_INLINE void decode_checklimit(upb_Decoder* d) { UPB_ASSERT(d->limit_ptr == d->end + UPB_MIN(0, d->limit)); } -UPB_INLINE int decode_pushlimit(upb_decstate *d, const char *ptr, int size) { +UPB_INLINE int decode_pushlimit(upb_Decoder* d, const char* ptr, int size) { int limit = size + (int)(ptr - d->end); int delta = d->limit - limit; decode_checklimit(d); @@ -1909,7 +2080,7 @@ UPB_INLINE int decode_pushlimit(upb_decstate *d, const char *ptr, int size) { return delta; } -UPB_INLINE void decode_poplimit(upb_decstate *d, const char *ptr, +UPB_INLINE void decode_poplimit(upb_Decoder* d, const char* ptr, int saved_delta) { UPB_ASSERT(ptr - d->end == d->limit); decode_checklimit(d); @@ -1919,11 +2090,11 @@ UPB_INLINE void decode_poplimit(upb_decstate *d, const char *ptr, } -#endif /* UPB_DECODE_INT_H_ */ +#endif /* UPB_DECODE_INT_H_ */ /** upb/encode.h ************************************************************/ /* - * upb_encode: parsing into a upb_msg using a upb_msglayout. + * upb_Encode: parsing into a upb_Message using a upb_MiniTable. */ #ifndef UPB_ENCODE_H_ @@ -1943,28 +2114,26 @@ enum { * * If your proto contains maps, the encoder will need to malloc()/free() * memory during encode. */ - UPB_ENCODE_DETERMINISTIC = 1, + kUpb_Encode_Deterministic = 1, /* When set, unknown fields are not printed. */ - UPB_ENCODE_SKIPUNKNOWN = 2, + kUpb_Encode_SkipUnknown = 2, + + /* When set, the encode will fail if any required fields are missing. */ + kUpb_Encode_CheckRequired = 4, }; #define UPB_ENCODE_MAXDEPTH(depth) ((depth) << 16) -char *upb_encode_ex(const void *msg, const upb_msglayout *l, int options, - upb_arena *arena, size_t *size); - -UPB_INLINE char *upb_encode(const void *msg, const upb_msglayout *l, - upb_arena *arena, size_t *size) { - return upb_encode_ex(msg, l, 0, arena, size); -} +char* upb_Encode(const void* msg, const upb_MiniTable* l, int options, + upb_Arena* arena, size_t* size); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif -#endif /* UPB_ENCODE_H_ */ +#endif /* UPB_ENCODE_H_ */ /** upb/decode_fast.h ************************************************************/ // These are the specialized field parser functions for the fast parser. @@ -2005,22 +2174,22 @@ UPB_INLINE char *upb_encode(const void *msg, const upb_msglayout *l, #define UPB_DECODE_FAST_H_ -struct upb_decstate; +struct upb_Decoder; // The fallback, generic parsing function that can handle any field type. // This just uses the regular (non-fast) parser to parse a single field. -const char *fastdecode_generic(struct upb_decstate *d, const char *ptr, - upb_msg *msg, intptr_t table, uint64_t hasbits, - uint64_t data); +const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data); -#define UPB_PARSE_PARAMS \ - struct upb_decstate *d, const char *ptr, upb_msg *msg, intptr_t table, \ +#define UPB_PARSE_PARAMS \ + struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ uint64_t hasbits, uint64_t data /* primitive fields ***********************************************************/ #define F(card, type, valbytes, tagbytes) \ - const char *upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS); + const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS); #define TYPES(card, tagbytes) \ F(card, b, 1, tagbytes) \ @@ -2047,8 +2216,8 @@ TAGBYTES(p) /* string fields **************************************************************/ #define F(card, tagbytes, type) \ - const char *upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); \ - const char *upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); + const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); \ + const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); #define UTF8(card, tagbytes) \ F(card, tagbytes, s) \ @@ -2068,17 +2237,17 @@ TAGBYTES(r) /* sub-message fields *********************************************************/ #define F(card, tagbytes, size_ceil, ceil_arg) \ - const char *upb_p##card##m_##tagbytes##bt_max##size_ceil##b(UPB_PARSE_PARAMS); + const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b(UPB_PARSE_PARAMS); #define SIZES(card, tagbytes) \ - F(card, tagbytes, 64, 64) \ + F(card, tagbytes, 64, 64) \ F(card, tagbytes, 128, 128) \ F(card, tagbytes, 192, 192) \ F(card, tagbytes, 256, 256) \ F(card, tagbytes, max, -1) #define TAGBYTES(card) \ - SIZES(card, 1) \ + SIZES(card, 1) \ SIZES(card, 2) TAGBYTES(s) @@ -2091,7 +2260,7 @@ TAGBYTES(r) #undef UPB_PARSE_PARAMS -#endif /* UPB_DECODE_FAST_H_ */ +#endif /* UPB_DECODE_FAST_H_ */ /** google/protobuf/descriptor.upb.h ************************************************************//* This file was generated by upbc (the upb compiler) from the input * file: @@ -2164,33 +2333,33 @@ typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; -extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit; -extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit; -extern const upb_msglayout google_protobuf_DescriptorProto_msginit; -extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit; -extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit; -extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit; -extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit; -extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit; -extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit; -extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; -extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit; -extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit; -extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit; -extern const upb_msglayout google_protobuf_FileOptions_msginit; -extern const upb_msglayout google_protobuf_MessageOptions_msginit; -extern const upb_msglayout google_protobuf_FieldOptions_msginit; -extern const upb_msglayout google_protobuf_OneofOptions_msginit; -extern const upb_msglayout google_protobuf_EnumOptions_msginit; -extern const upb_msglayout google_protobuf_EnumValueOptions_msginit; -extern const upb_msglayout google_protobuf_ServiceOptions_msginit; -extern const upb_msglayout google_protobuf_MethodOptions_msginit; -extern const upb_msglayout google_protobuf_UninterpretedOption_msginit; -extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit; -extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit; -extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit; -extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit; -extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit; +extern const upb_MiniTable google_protobuf_FileDescriptorSet_msginit; +extern const upb_MiniTable google_protobuf_FileDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msginit; +extern const upb_MiniTable google_protobuf_ExtensionRangeOptions_msginit; +extern const upb_MiniTable google_protobuf_FieldDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_OneofDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_EnumDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; +extern const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_ServiceDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_MethodDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_FileOptions_msginit; +extern const upb_MiniTable google_protobuf_MessageOptions_msginit; +extern const upb_MiniTable google_protobuf_FieldOptions_msginit; +extern const upb_MiniTable google_protobuf_OneofOptions_msginit; +extern const upb_MiniTable google_protobuf_EnumOptions_msginit; +extern const upb_MiniTable google_protobuf_EnumValueOptions_msginit; +extern const upb_MiniTable google_protobuf_ServiceOptions_msginit; +extern const upb_MiniTable google_protobuf_MethodOptions_msginit; +extern const upb_MiniTable google_protobuf_UninterpretedOption_msginit; +extern const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msginit; +extern const upb_MiniTable google_protobuf_SourceCodeInfo_msginit; +extern const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msginit; +extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_msginit; +extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msginit; typedef enum { google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, @@ -2244,44 +2413,56 @@ typedef enum { } google_protobuf_MethodOptions_IdempotencyLevel; +extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enuminit; +extern const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enuminit; + /* google.protobuf.FileDescriptorSet */ -UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) { - return (google_protobuf_FileDescriptorSet *)_upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena); +UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_new(upb_Arena* arena) { + return (google_protobuf_FileDescriptorSet*)_upb_Message_New(&google_protobuf_FileDescriptorSet_msginit, arena); } -UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); +UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena); +UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len); +UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FileDescriptorSet_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FileDescriptorSet_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg, size_t *len) { return (const google_protobuf_FileDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet *msg, size_t *len) { return (google_protobuf_FileDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } -UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet *msg, size_t len, upb_arena *arena) { - return (google_protobuf_FileDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_FileDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet *msg, upb_arena *arena) { - struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet *msg, upb_Arena *arena) { + struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2289,35 +2470,44 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescr /* google.protobuf.FileDescriptorProto */ -UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_FileDescriptorProto *)_upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena); +UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_new(upb_Arena* arena) { + return (google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msginit, arena); } -UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); +UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena); +UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len); +UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FileDescriptorProto_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FileDescriptorProto_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); } -UPB_INLINE upb_strview const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); } +UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); +} +UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(44, 88)); } @@ -2327,41 +2517,47 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(52, 104)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(52, 104), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_FileOptions*); } +UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_FileOptions*); +} UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 4); } -UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_SourceCodeInfo*); } +UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_SourceCodeInfo*); +} UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(56, 112), len); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(60, 120), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto *msg) { return _upb_hasbit(msg, 5); } -UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView); +} -UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; } -UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) { - return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); +UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) { + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); } -UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (upb_strview*)_upb_array_resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(3, 4), arena); +UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(3, 4), arena); } -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto *msg, upb_strview val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(36, 72), UPB_SIZE(3, 4), &val, +UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto *msg, upb_StringView val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 72), UPB_SIZE(3, 4), &val, arena); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len); } -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(40, 80), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(40, 80), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(40, 80), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2369,12 +2565,12 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescripto UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len); } -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(44, 88), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(44, 88), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(44, 88), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2382,12 +2578,12 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescr UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(48, 96), len); } -UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_ServiceDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(48, 96), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_ServiceDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(48, 96), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(48, 96), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2395,12 +2591,12 @@ UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDe UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(52, 104), len); } -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(52, 104), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(52, 104), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(52, 104), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2409,10 +2605,10 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_ _upb_sethas(msg, 3); *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_FileOptions*) = value; } -UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_FileOptions*)_upb_msg_new(&google_protobuf_FileOptions_msginit, arena); + sub = (struct google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msginit, arena); if (!sub) return NULL; google_protobuf_FileDescriptorProto_set_options(msg, sub); } @@ -2422,10 +2618,10 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_ _upb_sethas(msg, 4); *UPB_PTR_AT(msg, UPB_SIZE(32, 64), google_protobuf_SourceCodeInfo*) = value; } -UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); if (sub == NULL) { - sub = (struct google_protobuf_SourceCodeInfo*)_upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); + sub = (struct google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msginit, arena); if (!sub) return NULL; google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub); } @@ -2434,56 +2630,63 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptor UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 112), len); } -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor2(msg, UPB_SIZE(56, 112), len, 2, arena); +UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(56, 112), len, 2, arena); } -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(56, 112), 2, &val, +UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(56, 112), 2, &val, arena); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(60, 120), len); } -UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor2(msg, UPB_SIZE(60, 120), len, 2, arena); +UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(60, 120), len, 2, arena); } -UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(60, 120), 2, &val, +UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(60, 120), 2, &val, arena); } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = value; } /* google.protobuf.DescriptorProto */ -UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) { - return (google_protobuf_DescriptorProto *)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); +UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new(upb_Arena* arena) { + return (google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); } -UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); +UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena); +UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len); +UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_DescriptorProto_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_DescriptorProto_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); } @@ -2495,26 +2698,28 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(32, 64)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(32, 64), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_MessageOptions*); } +UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_MessageOptions*); +} UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(36, 72)); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); } -UPB_INLINE upb_strview const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); } +UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg, size_t *len) { return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); } -UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto *msg, size_t *len) { return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len); } -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(16, 32), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2522,12 +2727,12 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto *msg, size_t *len) { return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } -UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(20, 40), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2535,12 +2740,12 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorPro UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto *msg, size_t *len) { return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } -UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(24, 48), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2548,12 +2753,12 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_Descripto UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto *msg, size_t *len) { return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); } -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(28, 56), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2561,12 +2766,12 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobu UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto *msg, size_t *len) { return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 64), len); } -UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(32, 64), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(32, 64), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(32, 64), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2575,10 +2780,10 @@ UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_Desc _upb_sethas(msg, 2); *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_MessageOptions*) = value; } -UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_MessageOptions*)_upb_msg_new(&google_protobuf_MessageOptions_msginit, arena); + sub = (struct google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msginit, arena); if (!sub) return NULL; google_protobuf_DescriptorProto_set_options(msg, sub); } @@ -2587,12 +2792,12 @@ UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProt UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto *msg, size_t *len) { return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); } -UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_OneofDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_OneofDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(36, 72), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2600,59 +2805,70 @@ UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_Descript UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto *msg, size_t *len) { return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len); } -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_resize_accessor2(msg, UPB_SIZE(40, 80), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_DescriptorProto_ReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(40, 80), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(40, 80), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } -UPB_INLINE upb_strview* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto *msg, size_t *len) { - return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len); +UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto *msg, size_t *len) { + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len); } -UPB_INLINE upb_strview* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) { - return (upb_strview*)_upb_array_resize_accessor2(msg, UPB_SIZE(44, 88), len, UPB_SIZE(3, 4), arena); +UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto *msg, size_t len, upb_Arena *arena) { + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(44, 88), len, UPB_SIZE(3, 4), arena); } -UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto *msg, upb_strview val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(44, 88), UPB_SIZE(3, 4), &val, +UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto *msg, upb_StringView val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(44, 88), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.DescriptorProto.ExtensionRange */ -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) { - return (google_protobuf_DescriptorProto_ExtensionRange *)_upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); +UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_new(upb_Arena* arena) { + return (google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); } -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); +UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); +UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len); +UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); +} UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); +} UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const google_protobuf_ExtensionRangeOptions*); } +UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const google_protobuf_ExtensionRangeOptions*); +} UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { _upb_sethas(msg, 1); @@ -2666,10 +2882,10 @@ UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(googl _upb_sethas(msg, 3); *UPB_PTR_AT(msg, UPB_SIZE(12, 16), google_protobuf_ExtensionRangeOptions*) = value; } -UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_Arena *arena) { struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); + sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msginit, arena); if (!sub) return NULL; google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub); } @@ -2678,34 +2894,43 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_Descrip /* google.protobuf.DescriptorProto.ReservedRange */ -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) { - return (google_protobuf_DescriptorProto_ReservedRange *)_upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); +UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_new(upb_Arena* arena) { + return (google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); } -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); +UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); +UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len); +UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); +} UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } +UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); +} UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { _upb_sethas(msg, 1); @@ -2718,42 +2943,47 @@ UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_pro /* google.protobuf.ExtensionRangeOptions */ -UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) { - return (google_protobuf_ExtensionRangeOptions *)_upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena); +UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_new(upb_Arena* arena) { + return (google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msginit, arena); } -UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); +UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena); +UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2761,60 +2991,87 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_Extension /* google.protobuf.FieldDescriptorProto */ -UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_FieldDescriptorProto *)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena); +UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_new(upb_Arena* arena) { + return (google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); } -UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); +UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena); +UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len); +UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView); +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView); +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t); +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 4); } -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { + return google_protobuf_FieldDescriptorProto_has_label(msg) ? *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) : 1; +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 5); } -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { + return google_protobuf_FieldDescriptorProto_has_type(msg) ? *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) : 1; +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 6); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView); +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 7); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView); +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 8); } -UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(64, 104), const google_protobuf_FieldOptions*); } +UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(64, 104), const google_protobuf_FieldOptions*); +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 9); } -UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); } +UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 10); } -UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_StringView); +} UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return _upb_hasbit(msg, 11); } -UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool); } +UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool); +} -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 3); @@ -2828,22 +3085,22 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_Fi _upb_sethas(msg, 5); *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 7); - *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { _upb_sethas(msg, 8); *UPB_PTR_AT(msg, UPB_SIZE(64, 104), google_protobuf_FieldOptions*) = value; } -UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions*)_upb_msg_new(&google_protobuf_FieldOptions_msginit, arena); + sub = (struct google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msginit, arena); if (!sub) return NULL; google_protobuf_FieldDescriptorProto_set_options(msg, sub); } @@ -2853,9 +3110,9 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_prot _upb_sethas(msg, 9); *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value; } -UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 10); - *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) { _upb_sethas(msg, 11); @@ -2864,47 +3121,56 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_ /* google.protobuf.OneofDescriptorProto */ -UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_OneofDescriptorProto *)_upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena); +UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_new(upb_Arena* arena) { + return (google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msginit, arena); } -UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); +UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena); +UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len); +UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_OneofOptions*); } +UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_OneofOptions*); +} -UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { _upb_sethas(msg, 2); *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_OneofOptions*) = value; } -UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_OneofOptions*)_upb_msg_new(&google_protobuf_OneofOptions_msginit, arena); + sub = (struct google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msginit, arena); if (!sub) return NULL; google_protobuf_OneofDescriptorProto_set_options(msg, sub); } @@ -2913,53 +3179,62 @@ UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorP /* google.protobuf.EnumDescriptorProto */ -UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto *)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena); +UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_new(upb_Arena* arena) { + return (google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); } -UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); +UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena); +UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len); +UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_EnumOptions*); } +UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_EnumOptions*); +} UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); } -UPB_INLINE upb_strview const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } +UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } -UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len); } -UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_EnumValueDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_EnumValueDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(16, 32), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2968,10 +3243,10 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_ _upb_sethas(msg, 2); *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_EnumOptions*) = value; } -UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_EnumOptions*)_upb_msg_new(&google_protobuf_EnumOptions_msginit, arena); + sub = (struct google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msginit, arena); if (!sub) return NULL; google_protobuf_EnumDescriptorProto_set_options(msg, sub); } @@ -2980,57 +3255,66 @@ UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorPro UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(20, 40), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } -UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t *len) { - return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); +UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t *len) { + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } -UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) { - return (upb_strview*)_upb_array_resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(3, 4), arena); +UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(3, 4), arena); } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_strview val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(3, 4), &val, +UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.EnumDescriptorProto.EnumReservedRange */ -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange *)_upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); +UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_Arena* arena) { + return (google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); } -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); +UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); +UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len); +UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); +} UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } +UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); +} UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { _upb_sethas(msg, 1); @@ -3043,40 +3327,51 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(go /* google.protobuf.EnumValueDescriptorProto */ -UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_EnumValueDescriptorProto *)_upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena); +UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_new(upb_Arena* arena) { + return (google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msginit, arena); } -UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); +UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena); +UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len); +UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); +} UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); } +UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); +} -UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 2); @@ -3086,10 +3381,10 @@ UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_prot _upb_sethas(msg, 3); *UPB_PTR_AT(msg, UPB_SIZE(16, 24), google_protobuf_EnumValueOptions*) = value; } -UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_EnumValueOptions*)_upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); + sub = (struct google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msginit, arena); if (!sub) return NULL; google_protobuf_EnumValueDescriptorProto_set_options(msg, sub); } @@ -3098,50 +3393,59 @@ UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDes /* google.protobuf.ServiceDescriptorProto */ -UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_ServiceDescriptorProto *)_upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena); +UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_new(upb_Arena* arena) { + return (google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msginit, arena); } -UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); +UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena); +UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len); +UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg, size_t *len) { return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_ServiceOptions*); } +UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_ServiceOptions*); +} -UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto *msg, size_t *len) { return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len); } -UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto *msg, size_t len, upb_arena *arena) { - return (google_protobuf_MethodDescriptorProto**)_upb_array_resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_MethodDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) { - struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto *msg, upb_Arena *arena) { + struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(16, 32), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3150,10 +3454,10 @@ UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protob _upb_sethas(msg, 2); *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_ServiceOptions*) = value; } -UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_ServiceOptions*)_upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena); + sub = (struct google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msginit, arena); if (!sub) return NULL; google_protobuf_ServiceDescriptorProto_set_options(msg, sub); } @@ -3162,63 +3466,80 @@ UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescrip /* google.protobuf.MethodDescriptorProto */ -UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) { - return (google_protobuf_MethodDescriptorProto *)_upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena); +UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_new(upb_Arena* arena) { + return (google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msginit, arena); } -UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); +UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena); +UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len); +UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); +} UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView); +} UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 4); } -UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); } +UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); +} UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 5); } -UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } +UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); +} UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_hasbit(msg, 6); } -UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); } +UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); +} -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; } -UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) { +UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { _upb_sethas(msg, 4); *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_MethodOptions*) = value; } -UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto *msg, upb_arena *arena) { +UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto *msg, upb_Arena *arena) { struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_MethodOptions*)_upb_msg_new(&google_protobuf_MethodOptions_msginit, arena); + sub = (struct google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msginit, arena); if (!sub) return NULL; google_protobuf_MethodDescriptorProto_set_options(msg, sub); } @@ -3235,80 +3556,125 @@ UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(googl /* google.protobuf.FileOptions */ -UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) { - return (google_protobuf_FileOptions *)_upb_msg_new(&google_protobuf_FileOptions_msginit, arena); +UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Arena* arena) { + return (google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msginit, arena); } -UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); +UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena); +UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FileOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FileOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { + return google_protobuf_FileOptions_has_optimize_for(msg) ? *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) : 1; +} UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 4); } -UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool); } +UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool); +} UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 5); } -UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 6); } -UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(9, 9), bool); } +UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(9, 9), bool); +} UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 7); } -UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(10, 10), bool); } +UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(10, 10), bool); +} UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 8); } -UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(11, 11), bool); } +UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(11, 11), bool); +} UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 9); } -UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), bool); } +UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), bool); +} UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 10); } -UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(13, 13), bool); } +UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(13, 13), bool); +} UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 11); } -UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(14, 14), bool); } +UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(14, 14), bool); +} UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 12); } -UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(15, 15), bool); } +UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { + return google_protobuf_FileOptions_has_cc_enable_arenas(msg) ? *UPB_PTR_AT(msg, UPB_SIZE(15, 15), bool) : true; +} UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 13); } -UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 14); } -UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 15); } -UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 16); } -UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 17); } -UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 18); } -UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); } +UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); +} UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 19); } -UPB_INLINE upb_strview google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions *msg) { return _upb_hasbit(msg, 20); } -UPB_INLINE upb_strview google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_StringView); +} UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(100, 184)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(100, 184), len); } -UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { _upb_sethas(msg, 3); @@ -3318,9 +3684,9 @@ UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_proto _upb_sethas(msg, 4); *UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 6); @@ -3350,47 +3716,47 @@ UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf _upb_sethas(msg, 12); *UPB_PTR_AT(msg, UPB_SIZE(15, 15), bool) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 13); - *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 14); - *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 15); - *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 16); - *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 17); - *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 18); *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 19); - *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_strview value) { +UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 20); - *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_StringView) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(100, 184), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(100, 184), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(100, 184), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(100, 184), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3398,38 +3764,51 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptio /* google.protobuf.MessageOptions */ -UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) { - return (google_protobuf_MessageOptions *)_upb_msg_new(&google_protobuf_MessageOptions_msginit, arena); +UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(upb_Arena* arena) { + return (google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msginit, arena); } -UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); +UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena); +UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_MessageOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_MessageOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } +UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); +} UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); } +UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); +} UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(3, 3), bool); } +UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(3, 3), bool); +} UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions *msg) { return _upb_hasbit(msg, 4); } -UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), bool); } +UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), bool); +} UPB_INLINE bool google_protobuf_MessageOptions_has_uninterpreted_option(const google_protobuf_MessageOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(8, 8)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(8, 8), len); } @@ -3452,12 +3831,12 @@ UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_Mes UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 8), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(8, 8), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 8), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(8, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3465,42 +3844,59 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOp /* google.protobuf.FieldOptions */ -UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) { - return (google_protobuf_FieldOptions *)_upb_msg_new(&google_protobuf_FieldOptions_msginit, arena); +UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Arena* arena) { + return (google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msginit, arena); } -UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); +UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena); +UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FieldOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_FieldOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); +} UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), bool); } +UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), bool); +} UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(13, 13), bool); } +UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(13, 13), bool); +} UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 4); } -UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(14, 14), bool); } +UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(14, 14), bool); +} UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 5); } -UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } +UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); +} UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions *msg) { return _upb_hasbit(msg, 6); } -UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(15, 15), bool); } +UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(15, 15), bool); +} UPB_INLINE bool google_protobuf_FieldOptions_has_uninterpreted_option(const google_protobuf_FieldOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 16)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(16, 16), len); } @@ -3531,12 +3927,12 @@ UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptio UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 16), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(16, 16), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 16), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(16, 16), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3544,42 +3940,47 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOpti /* google.protobuf.OneofOptions */ -UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) { - return (google_protobuf_OneofOptions *)_upb_msg_new(&google_protobuf_OneofOptions_msginit, arena); +UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Arena* arena) { + return (google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msginit, arena); } -UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); +UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena); +UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_OneofOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_OneofOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3587,34 +3988,43 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOpti /* google.protobuf.EnumOptions */ -UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) { - return (google_protobuf_EnumOptions *)_upb_msg_new(&google_protobuf_EnumOptions_msginit, arena); +UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Arena* arena) { + return (google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msginit, arena); } -UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); +UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena); +UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } +UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); +} UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); } +UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); +} UPB_INLINE bool google_protobuf_EnumOptions_has_uninterpreted_option(const google_protobuf_EnumOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); } @@ -3629,12 +4039,12 @@ UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumO UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3642,32 +4052,39 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptio /* google.protobuf.EnumValueOptions */ -UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) { - return (google_protobuf_EnumValueOptions *)_upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena); +UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_new(upb_Arena* arena) { + return (google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msginit, arena); } -UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); +UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena); +UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumValueOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_EnumValueOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } +UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); +} UPB_INLINE bool google_protobuf_EnumValueOptions_has_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); } @@ -3678,12 +4095,12 @@ UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3691,32 +4108,39 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValue /* google.protobuf.ServiceOptions */ -UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) { - return (google_protobuf_ServiceOptions *)_upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena); +UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(upb_Arena* arena) { + return (google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msginit, arena); } -UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); +UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena); +UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_ServiceOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_ServiceOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } +UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); +} UPB_INLINE bool google_protobuf_ServiceOptions_has_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); } @@ -3727,12 +4151,12 @@ UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_Se UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3740,34 +4164,43 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOp /* google.protobuf.MethodOptions */ -UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) { - return (google_protobuf_MethodOptions *)_upb_msg_new(&google_protobuf_MethodOptions_msginit, arena); +UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_Arena* arena) { + return (google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msginit, arena); } -UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); +UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena); +UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len); +UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_MethodOptions_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_MethodOptions_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool); } +UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), bool); +} UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); +} UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 16)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(12, 16), len); } @@ -3782,12 +4215,12 @@ UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_proto UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t *len) { return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 16), len); } -UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor2(msg, UPB_SIZE(12, 16), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 16), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(12, 16), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3795,61 +4228,78 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOpt /* google.protobuf.UninterpretedOption */ -UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) { - return (google_protobuf_UninterpretedOption *)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena); +UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_new(upb_Arena* arena) { + return (google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); } -UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); +UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena); +UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len); +UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_UninterpretedOption_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_UninterpretedOption_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(56, 80)); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg, size_t *len) { return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_accessor(msg, UPB_SIZE(56, 80), len); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_StringView); +} UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t); } +UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t); +} UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t); } +UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t); +} UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 4); } -UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double); } +UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double); +} UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 5); } -UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_StringView); +} UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return _upb_hasbit(msg, 6); } -UPB_INLINE upb_strview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_StringView); +} UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption *msg, size_t *len) { return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 80), len); } -UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption *msg, size_t len, upb_arena *arena) { - return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_resize_accessor2(msg, UPB_SIZE(56, 80), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_UninterpretedOption_NamePart**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(56, 80), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption *msg, upb_arena *arena) { - struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption *msg, upb_Arena *arena) { + struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(56, 80), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_strview value) { +UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_StringView) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { _upb_sethas(msg, 2); @@ -3863,49 +4313,58 @@ UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_prot _upb_sethas(msg, 4); *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_strview value) { +UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_StringView) = value; } -UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_strview value) { +UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_StringView) = value; } /* google.protobuf.UninterpretedOption.NamePart */ -UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) { - return (google_protobuf_UninterpretedOption_NamePart *)_upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); +UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_new(upb_Arena* arena) { + return (google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); } -UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); +UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena); +UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len); +UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } +UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); +} -UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_strview value) { +UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { _upb_sethas(msg, 2); @@ -3914,42 +4373,47 @@ UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(go /* google.protobuf.SourceCodeInfo */ -UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) { - return (google_protobuf_SourceCodeInfo *)_upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena); +UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(upb_Arena* arena) { + return (google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msginit, arena); } -UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); +UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena); +UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len); +UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg, size_t *len) { return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo *msg, size_t *len) { return (google_protobuf_SourceCodeInfo_Location**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } -UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo *msg, size_t len, upb_arena *arena) { - return (google_protobuf_SourceCodeInfo_Location**)_upb_array_resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_SourceCodeInfo_Location**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo *msg, upb_arena *arena) { - struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo *msg, upb_Arena *arena) { + struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3957,115 +4421,129 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_Sourc /* google.protobuf.SourceCodeInfo.Location */ -UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) { - return (google_protobuf_SourceCodeInfo_Location *)_upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena); +UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_new(upb_Arena* arena) { + return (google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msginit, arena); } -UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); +UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena); +UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len); +UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, options, arena, len); } - UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); +} UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); } -UPB_INLINE upb_strview const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); } +UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); +} +UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor2(msg, UPB_SIZE(20, 40), len, 2, arena); +UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_Arena *arena) { + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, 2, arena); } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(20, 40), 2, &val, +UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), 2, &val, arena); } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } -UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor2(msg, UPB_SIZE(24, 48), len, 2, arena); +UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_Arena *arena) { + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, 2, arena); } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(24, 48), 2, &val, +UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), 2, &val, arena); } -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) { +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } -UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) { +UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; } -UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { - return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); +UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); } -UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) { - return (upb_strview*)_upb_array_resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(3, 4), arena); +UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_Arena *arena) { + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(3, 4), arena); } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(3, 4), &val, +UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.GeneratedCodeInfo */ -UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) { - return (google_protobuf_GeneratedCodeInfo *)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena); +UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_new(upb_Arena* arena) { + return (google_protobuf_GeneratedCodeInfo*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_msginit, arena); } -UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); +UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena); +UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len); +UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, options, arena, len); } - UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg, size_t *len) { return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t *len) { return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len); } -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t len, upb_arena *arena) { - return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); +UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t len, upb_Arena *arena) { + return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } -UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena) { - struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); - bool ok = _upb_array_append_accessor2( +UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_Arena *arena) { + struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); + bool ok = _upb_Array_Append_accessor2( msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4073,51 +4551,62 @@ UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_ /* google.protobuf.GeneratedCodeInfo.Annotation */ -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) { - return (google_protobuf_GeneratedCodeInfo_Annotation *)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); +UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_new(upb_Arena* arena) { + return (google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); } -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse(const char *buf, size_t size, - upb_arena *arena) { - google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); +UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, upb_Arena* arena) { + google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (!upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena)) return NULL; + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + return NULL; + } return ret; } -UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse_ex(const char *buf, size_t size, - const upb_extreg *extreg, int options, - upb_arena *arena) { - google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); +UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse_ex(const char* buf, size_t size, + const upb_ExtensionRegistry* extreg, + int options, upb_Arena* arena) { + google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (!_upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, extreg, options, arena)) { + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, extreg, options, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; } -UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) { - return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len); +UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, 0, arena, len); +} +UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, int options, + upb_Arena* arena, size_t* len) { + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, options, arena, len); } - UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 32), len); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 1); } -UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview); } +UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_StringView); +} UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 2); } -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } +UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); +} UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_hasbit(msg, 3); } -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } +UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); +} UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) { return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 32), len); } -UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t len, upb_arena *arena) { - return (int32_t*)_upb_array_resize_accessor2(msg, UPB_SIZE(20, 32), len, 2, arena); +UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t len, upb_Arena *arena) { + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 32), len, 2, arena); } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t val, upb_arena *arena) { - return _upb_array_append_accessor2(msg, UPB_SIZE(20, 32), 2, &val, +UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t val, upb_Arena *arena) { + return _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 32), 2, &val, arena); } -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_strview value) { +UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_StringView) = value; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 2); @@ -4128,6 +4617,12 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_prot *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } +extern const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout; + +/* Max size 32 is google.protobuf.FileOptions */ +/* Max size 64 is google.protobuf.FileOptions */ +#define _UPB_MAXOPT_SIZE UPB_SIZE(104, 192) + #ifdef __cplusplus } /* extern "C" */ #endif @@ -4136,19 +4631,6 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_prot #endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */ /** upb/def.h ************************************************************/ -/* - * Defs are upb's internal representation of the constructs that can appear - * in a .proto file: - * - * - upb_msgdef: describes a "message" construct. - * - upb_fielddef: describes a message field. - * - upb_filedef: describes a .proto file and its defs. - * - upb_enumdef: describes an enum. - * - upb_oneofdef: describes a oneof. - * - * TODO: definitions of services. - */ - #ifndef UPB_DEF_H_ #define UPB_DEF_H_ @@ -4157,288 +4639,364 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_prot #ifdef __cplusplus extern "C" { -#endif /* __cplusplus */ - -struct upb_enumdef; -typedef struct upb_enumdef upb_enumdef; -struct upb_fielddef; -typedef struct upb_fielddef upb_fielddef; -struct upb_filedef; -typedef struct upb_filedef upb_filedef; -struct upb_msgdef; -typedef struct upb_msgdef upb_msgdef; -struct upb_oneofdef; -typedef struct upb_oneofdef upb_oneofdef; -struct upb_symtab; -typedef struct upb_symtab upb_symtab; - -typedef enum { - UPB_SYNTAX_PROTO2 = 2, - UPB_SYNTAX_PROTO3 = 3 -} upb_syntax_t; +#endif /* __cplusplus */ + +struct upb_EnumDef; +typedef struct upb_EnumDef upb_EnumDef; +struct upb_EnumValueDef; +typedef struct upb_EnumValueDef upb_EnumValueDef; +struct upb_ExtensionRange; +typedef struct upb_ExtensionRange upb_ExtensionRange; +struct upb_FieldDef; +typedef struct upb_FieldDef upb_FieldDef; +struct upb_FileDef; +typedef struct upb_FileDef upb_FileDef; +struct upb_MethodDef; +typedef struct upb_MethodDef upb_MethodDef; +struct upb_MessageDef; +typedef struct upb_MessageDef upb_MessageDef; +struct upb_OneofDef; +typedef struct upb_OneofDef upb_OneofDef; +struct upb_ServiceDef; +typedef struct upb_ServiceDef upb_ServiceDef; +struct upb_streamdef; +typedef struct upb_streamdef upb_streamdef; +struct upb_DefPool; +typedef struct upb_DefPool upb_DefPool; + +typedef enum { kUpb_Syntax_Proto2 = 2, kUpb_Syntax_Proto3 = 3 } upb_Syntax; /* All the different kind of well known type messages. For simplicity of check, * number wrappers and string wrappers are grouped together. Make sure the * order and merber of these groups are not changed. */ typedef enum { - UPB_WELLKNOWN_UNSPECIFIED, - UPB_WELLKNOWN_ANY, - UPB_WELLKNOWN_FIELDMASK, - UPB_WELLKNOWN_DURATION, - UPB_WELLKNOWN_TIMESTAMP, + kUpb_WellKnown_Unspecified, + kUpb_WellKnown_Any, + kUpb_WellKnown_FieldMask, + kUpb_WellKnown_Duration, + kUpb_WellKnown_Timestamp, /* number wrappers */ - UPB_WELLKNOWN_DOUBLEVALUE, - UPB_WELLKNOWN_FLOATVALUE, - UPB_WELLKNOWN_INT64VALUE, - UPB_WELLKNOWN_UINT64VALUE, - UPB_WELLKNOWN_INT32VALUE, - UPB_WELLKNOWN_UINT32VALUE, + kUpb_WellKnown_DoubleValue, + kUpb_WellKnown_FloatValue, + kUpb_WellKnown_Int64Value, + kUpb_WellKnown_UInt64Value, + kUpb_WellKnown_Int32Value, + kUpb_WellKnown_UInt32Value, /* string wrappers */ - UPB_WELLKNOWN_STRINGVALUE, - UPB_WELLKNOWN_BYTESVALUE, - UPB_WELLKNOWN_BOOLVALUE, - UPB_WELLKNOWN_VALUE, - UPB_WELLKNOWN_LISTVALUE, - UPB_WELLKNOWN_STRUCT -} upb_wellknowntype_t; + kUpb_WellKnown_StringValue, + kUpb_WellKnown_BytesValue, + kUpb_WellKnown_BoolValue, + kUpb_WellKnown_Value, + kUpb_WellKnown_ListValue, + kUpb_WellKnown_Struct +} upb_WellKnown; -/* upb_fielddef ***************************************************************/ +/* upb_FieldDef ***************************************************************/ /* Maximum field number allowed for FieldDefs. This is an inherent limit of the * protobuf wire format. */ -#define UPB_MAX_FIELDNUMBER ((1 << 29) - 1) - -const char *upb_fielddef_fullname(const upb_fielddef *f); -upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f); -upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f); -upb_label_t upb_fielddef_label(const upb_fielddef *f); -uint32_t upb_fielddef_number(const upb_fielddef *f); -const char *upb_fielddef_name(const upb_fielddef *f); -const char *upb_fielddef_jsonname(const upb_fielddef *f); -bool upb_fielddef_isextension(const upb_fielddef *f); -bool upb_fielddef_lazy(const upb_fielddef *f); -bool upb_fielddef_packed(const upb_fielddef *f); -const upb_filedef *upb_fielddef_file(const upb_fielddef *f); -const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f); -const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f); -const upb_oneofdef *upb_fielddef_realcontainingoneof(const upb_fielddef *f); -uint32_t upb_fielddef_index(const upb_fielddef *f); -bool upb_fielddef_issubmsg(const upb_fielddef *f); -bool upb_fielddef_isstring(const upb_fielddef *f); -bool upb_fielddef_isseq(const upb_fielddef *f); -bool upb_fielddef_isprimitive(const upb_fielddef *f); -bool upb_fielddef_ismap(const upb_fielddef *f); -int64_t upb_fielddef_defaultint64(const upb_fielddef *f); -int32_t upb_fielddef_defaultint32(const upb_fielddef *f); -uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f); -uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f); -bool upb_fielddef_defaultbool(const upb_fielddef *f); -float upb_fielddef_defaultfloat(const upb_fielddef *f); -double upb_fielddef_defaultdouble(const upb_fielddef *f); -const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len); -bool upb_fielddef_hassubdef(const upb_fielddef *f); -bool upb_fielddef_haspresence(const upb_fielddef *f); -const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f); -const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f); -const upb_msglayout_field *upb_fielddef_layout(const upb_fielddef *f); - -/* upb_oneofdef ***************************************************************/ - -typedef upb_inttable_iter upb_oneof_iter; - -const char *upb_oneofdef_name(const upb_oneofdef *o); -const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o); -uint32_t upb_oneofdef_index(const upb_oneofdef *o); -bool upb_oneofdef_issynthetic(const upb_oneofdef *o); -int upb_oneofdef_fieldcount(const upb_oneofdef *o); -const upb_fielddef *upb_oneofdef_field(const upb_oneofdef *o, int i); +#define kUpb_MaxFieldNumber ((1 << 29) - 1) + +const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f); +bool upb_FieldDef_HasOptions(const upb_FieldDef* f); +const char* upb_FieldDef_FullName(const upb_FieldDef* f); +upb_CType upb_FieldDef_CType(const upb_FieldDef* f); +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); +upb_Label upb_FieldDef_Label(const upb_FieldDef* f); +uint32_t upb_FieldDef_Number(const upb_FieldDef* f); +const char* upb_FieldDef_Name(const upb_FieldDef* f); +const char* upb_FieldDef_JsonName(const upb_FieldDef* f); +bool upb_FieldDef_HasJsonName(const upb_FieldDef* f); +bool upb_FieldDef_IsExtension(const upb_FieldDef* f); +bool upb_FieldDef_IsPacked(const upb_FieldDef* f); +const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f); +const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f); +const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f); +uint32_t upb_FieldDef_Index(const upb_FieldDef* f); +bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f); +bool upb_FieldDef_IsString(const upb_FieldDef* f); +bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); +bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); +bool upb_FieldDef_IsMap(const upb_FieldDef* f); +bool upb_FieldDef_HasDefault(const upb_FieldDef* f); +bool upb_FieldDef_HasSubDef(const upb_FieldDef* f); +bool upb_FieldDef_HasPresence(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f); +const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f); +const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f); +const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( + const upb_FieldDef* f); +bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); + +/* upb_OneofDef ***************************************************************/ + +const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o); +bool upb_OneofDef_HasOptions(const upb_OneofDef* o); +const char* upb_OneofDef_Name(const upb_OneofDef* o); +const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o); +uint32_t upb_OneofDef_Index(const upb_OneofDef* o); +bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o); +int upb_OneofDef_FieldCount(const upb_OneofDef* o); +const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i); /* Oneof lookups: * - ntof: look up a field by name. * - ntofz: look up a field by name (as a null-terminated string). * - itof: look up a field by number. */ -const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o, - const char *name, size_t length); -UPB_INLINE const upb_fielddef *upb_oneofdef_ntofz(const upb_oneofdef *o, - const char *name) { - return upb_oneofdef_ntof(o, name, strlen(name)); -} -const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num); - -/* DEPRECATED, slated for removal. */ -int upb_oneofdef_numfields(const upb_oneofdef *o); -void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o); -void upb_oneof_next(upb_oneof_iter *iter); -bool upb_oneof_done(upb_oneof_iter *iter); -upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter); -void upb_oneof_iter_setdone(upb_oneof_iter *iter); -bool upb_oneof_iter_isequal(const upb_oneof_iter *iter1, - const upb_oneof_iter *iter2); -/* END DEPRECATED */ - -/* upb_msgdef *****************************************************************/ - -typedef upb_inttable_iter upb_msg_field_iter; -typedef upb_strtable_iter upb_msg_oneof_iter; +const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, + const char* name, + size_t length); +UPB_INLINE const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, + const char* name) { + return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); +} +const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, + uint32_t num); + +/* upb_MessageDef *************************************************************/ /* Well-known field tag numbers for map-entry messages. */ -#define UPB_MAPENTRY_KEY 1 -#define UPB_MAPENTRY_VALUE 2 +#define kUpb_MapEntry_KeyFieldNumber 1 +#define kUpb_MapEntry_ValueFieldNumber 2 /* Well-known field tag numbers for Any messages. */ -#define UPB_ANY_TYPE 1 -#define UPB_ANY_VALUE 2 +#define kUpb_Any_TypeFieldNumber 1 +#define kUpb_Any_ValueFieldNumber 2 /* Well-known field tag numbers for timestamp messages. */ -#define UPB_DURATION_SECONDS 1 -#define UPB_DURATION_NANOS 2 +#define kUpb_Duration_SecondsFieldNumber 1 +#define kUpb_Duration_NanosFieldNumber 2 /* Well-known field tag numbers for duration messages. */ -#define UPB_TIMESTAMP_SECONDS 1 -#define UPB_TIMESTAMP_NANOS 2 - -const char *upb_msgdef_fullname(const upb_msgdef *m); -const upb_filedef *upb_msgdef_file(const upb_msgdef *m); -const char *upb_msgdef_name(const upb_msgdef *m); -upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m); -bool upb_msgdef_mapentry(const upb_msgdef *m); -upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m); -bool upb_msgdef_iswrapper(const upb_msgdef *m); -bool upb_msgdef_isnumberwrapper(const upb_msgdef *m); -int upb_msgdef_fieldcount(const upb_msgdef *m); -int upb_msgdef_oneofcount(const upb_msgdef *m); -const upb_fielddef *upb_msgdef_field(const upb_msgdef *m, int i); -const upb_oneofdef *upb_msgdef_oneof(const upb_msgdef *m, int i); -const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i); -const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, - size_t len); -const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, - size_t len); -const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m); - -UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m, - const char *name) { - return upb_msgdef_ntoo(m, name, strlen(name)); -} - -UPB_INLINE const upb_fielddef *upb_msgdef_ntofz(const upb_msgdef *m, - const char *name) { - return upb_msgdef_ntof(m, name, strlen(name)); -} +#define kUpb_Timestamp_SecondsFieldNumber 1 +#define kUpb_Timestamp_NanosFieldNumber 2 + +const google_protobuf_MessageOptions* upb_MessageDef_Options( + const upb_MessageDef* m); +bool upb_MessageDef_HasOptions(const upb_MessageDef* m); +const char* upb_MessageDef_FullName(const upb_MessageDef* m); +const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m); +const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m); +const char* upb_MessageDef_Name(const upb_MessageDef* m); +upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m); +upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m); +int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m); +int upb_MessageDef_FieldCount(const upb_MessageDef* m); +int upb_MessageDef_OneofCount(const upb_MessageDef* m); +const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, + int i); +const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i); +const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i); +const upb_FieldDef* upb_MessageDef_FindFieldByNumberWithSize( + const upb_MessageDef* m, uint32_t i); +const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m); + +UPB_INLINE const upb_OneofDef* upb_MessageDef_FindOneofByName( + const upb_MessageDef* m, const char* name) { + return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); +} + +UPB_INLINE const upb_FieldDef* upb_MessageDef_FindFieldByName( + const upb_MessageDef* m, const char* name) { + return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); +} + +UPB_INLINE bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { + return google_protobuf_MessageOptions_map_entry(upb_MessageDef_Options(m)); +} + +/* Nested entities. */ +int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m); +int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m); +int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m); +const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, + int i); +const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i); +const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, + int i); /* Lookup of either field or oneof by name. Returns whether either was found. * If the return is true, then the found def will be set, and the non-found * one set to NULL. */ -bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len, - const upb_fielddef **f, const upb_oneofdef **o); +bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, + const char* name, size_t len, + const upb_FieldDef** f, + const upb_OneofDef** o); -UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name, - const upb_fielddef **f, - const upb_oneofdef **o) { - return upb_msgdef_lookupname(m, name, strlen(name), f, o); +UPB_INLINE bool upb_MessageDef_FindByName(const upb_MessageDef* m, + const char* name, + const upb_FieldDef** f, + const upb_OneofDef** o) { + return upb_MessageDef_FindByNameWithSize(m, name, strlen(name), f, o); } /* Returns a field by either JSON name or regular proto name. */ -const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m, - const char *name, size_t len); - -/* DEPRECATED, slated for removal */ -int upb_msgdef_numfields(const upb_msgdef *m); -int upb_msgdef_numoneofs(const upb_msgdef *m); -int upb_msgdef_numrealoneofs(const upb_msgdef *m); -void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m); -void upb_msg_field_next(upb_msg_field_iter *iter); -bool upb_msg_field_done(const upb_msg_field_iter *iter); -upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter); -void upb_msg_field_iter_setdone(upb_msg_field_iter *iter); -bool upb_msg_field_iter_isequal(const upb_msg_field_iter * iter1, - const upb_msg_field_iter * iter2); -void upb_msg_oneof_begin(upb_msg_oneof_iter * iter, const upb_msgdef *m); -void upb_msg_oneof_next(upb_msg_oneof_iter * iter); -bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter); -const upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter); -void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter * iter); -bool upb_msg_oneof_iter_isequal(const upb_msg_oneof_iter *iter1, - const upb_msg_oneof_iter *iter2); -/* END DEPRECATED */ - -/* upb_enumdef ****************************************************************/ - -typedef upb_strtable_iter upb_enum_iter; - -const char *upb_enumdef_fullname(const upb_enumdef *e); -const char *upb_enumdef_name(const upb_enumdef *e); -const upb_filedef *upb_enumdef_file(const upb_enumdef *e); -int32_t upb_enumdef_default(const upb_enumdef *e); -int upb_enumdef_numvals(const upb_enumdef *e); - -/* Enum lookups: - * - ntoi: look up a name with specified length. - * - ntoiz: look up a name provided as a null-terminated string. - * - iton: look up an integer, returning the name as a null-terminated - * string. */ -bool upb_enumdef_ntoi(const upb_enumdef *e, const char *name, size_t len, - int32_t *num); -UPB_INLINE bool upb_enumdef_ntoiz(const upb_enumdef *e, - const char *name, int32_t *num) { - return upb_enumdef_ntoi(e, name, strlen(name), num); -} -const char *upb_enumdef_iton(const upb_enumdef *e, int32_t num); - -void upb_enum_begin(upb_enum_iter *iter, const upb_enumdef *e); -void upb_enum_next(upb_enum_iter *iter); -bool upb_enum_done(upb_enum_iter *iter); -const char *upb_enum_iter_name(upb_enum_iter *iter); -int32_t upb_enum_iter_number(upb_enum_iter *iter); - -/* upb_filedef ****************************************************************/ - -const char *upb_filedef_name(const upb_filedef *f); -const char *upb_filedef_package(const upb_filedef *f); -const char *upb_filedef_phpprefix(const upb_filedef *f); -const char *upb_filedef_phpnamespace(const upb_filedef *f); -upb_syntax_t upb_filedef_syntax(const upb_filedef *f); -int upb_filedef_depcount(const upb_filedef *f); -int upb_filedef_msgcount(const upb_filedef *f); -int upb_filedef_enumcount(const upb_filedef *f); -const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i); -const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i); -const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i); -const upb_symtab *upb_filedef_symtab(const upb_filedef *f); - -/* upb_symtab *****************************************************************/ - -upb_symtab *upb_symtab_new(void); -void upb_symtab_free(upb_symtab* s); -const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym); -const upb_msgdef *upb_symtab_lookupmsg2( - const upb_symtab *s, const char *sym, size_t len); -const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym); -const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name); -const upb_filedef *upb_symtab_lookupfile2( - const upb_symtab *s, const char *name, size_t len); -int upb_symtab_filecount(const upb_symtab *s); -const upb_filedef *upb_symtab_addfile( - upb_symtab *s, const google_protobuf_FileDescriptorProto *file, - upb_status *status); -size_t _upb_symtab_bytesloaded(const upb_symtab *s); -upb_arena *_upb_symtab_arena(const upb_symtab *s); +const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +UPB_INLINE const upb_FieldDef* upb_MessageDef_FindByJsonName( + const upb_MessageDef* m, const char* name) { + return upb_MessageDef_FindByJsonNameWithSize(m, name, strlen(name)); +} + +/* upb_ExtensionRange *********************************************************/ + +const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( + const upb_ExtensionRange* r); +bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); +int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r); +int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); + +/* upb_EnumDef ****************************************************************/ + +const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e); +bool upb_EnumDef_HasOptions(const upb_EnumDef* e); +const char* upb_EnumDef_FullName(const upb_EnumDef* e); +const char* upb_EnumDef_Name(const upb_EnumDef* e); +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e); +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e); +int32_t upb_EnumDef_Default(const upb_EnumDef* e); +int upb_EnumDef_ValueCount(const upb_EnumDef* e); +const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i); + +const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( + const upb_EnumDef* e, const char* name, size_t len); +const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, + int32_t num); +bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num); + +// Convenience wrapper. +UPB_INLINE const upb_EnumValueDef* upb_EnumDef_FindValueByName( + const upb_EnumDef* e, const char* name) { + return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); +} + +/* upb_EnumValueDef ***********************************************************/ + +const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( + const upb_EnumValueDef* e); +bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* e); +const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* e); +const char* upb_EnumValueDef_Name(const upb_EnumValueDef* e); +int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* e); +uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* e); +const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* e); + +/* upb_FileDef ****************************************************************/ + +const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f); +bool upb_FileDef_HasOptions(const upb_FileDef* f); +const char* upb_FileDef_Name(const upb_FileDef* f); +const char* upb_FileDef_Package(const upb_FileDef* f); +upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f); +int upb_FileDef_DependencyCount(const upb_FileDef* f); +int upb_FileDef_PublicDependencyCount(const upb_FileDef* f); +int upb_FileDef_WeakDependencyCount(const upb_FileDef* f); +int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f); +int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f); +int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f); +int upb_FileDef_ServiceCount(const upb_FileDef* f); +const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i); +const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i); +const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i); +const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i); +const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i); +const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i); +const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i); +const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f); +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); + +/* upb_MethodDef **************************************************************/ + +const google_protobuf_MethodOptions* upb_MethodDef_Options( + const upb_MethodDef* m); +bool upb_MethodDef_HasOptions(const upb_MethodDef* m); +const char* upb_MethodDef_FullName(const upb_MethodDef* m); +const char* upb_MethodDef_Name(const upb_MethodDef* m); +const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); +const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); +const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); +bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m); +bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); + +/* upb_ServiceDef *************************************************************/ + +const google_protobuf_ServiceOptions* upb_ServiceDef_Options( + const upb_ServiceDef* s); +bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s); +const char* upb_ServiceDef_FullName(const upb_ServiceDef* s); +const char* upb_ServiceDef_Name(const upb_ServiceDef* s); +int upb_ServiceDef_Index(const upb_ServiceDef* s); +const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s); +int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); +const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i); +const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, + const char* name); + +/* upb_DefPool ****************************************************************/ + +upb_DefPool* upb_DefPool_New(void); +void upb_DefPool_Free(upb_DefPool* s); +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym); +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len); +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym); +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym); +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym); +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len); +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name); +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name); +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size); +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name); +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len); +const upb_FileDef* upb_DefPool_AddFile( + upb_DefPool* s, const google_protobuf_FileDescriptorProto* file, + upb_Status* status); +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); +const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTable_Extension* ext); +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum); +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s); +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count); /* For generated code only: loads a generated descriptor. */ -typedef struct upb_def_init { - struct upb_def_init **deps; /* Dependencies of this file. */ - const upb_msglayout **layouts; /* Pre-order layouts of all messages. */ - const char *filename; - upb_strview descriptor; /* Serialized descriptor. */ -} upb_def_init; +typedef struct _upb_DefPool_Init { + struct _upb_DefPool_Init** deps; /* Dependencies of this file. */ + const upb_MiniTable_File* layout; + const char* filename; + upb_StringView descriptor; /* Serialized descriptor. */ +} _upb_DefPool_Init; -bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init); +bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init); #ifdef __cplusplus -} /* extern "C" */ -#endif /* __cplusplus */ +} /* extern "C" */ +#endif /* __cplusplus */ #endif /* UPB_DEF_H_ */ @@ -4447,7 +5005,6 @@ bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init); #define UPB_REFLECTION_H_ - #ifdef __cplusplus extern "C" { #endif @@ -4460,57 +5017,63 @@ typedef union { int64_t int64_val; uint32_t uint32_val; uint64_t uint64_val; - const upb_map* map_val; - const upb_msg* msg_val; - const upb_array* array_val; - upb_strview str_val; -} upb_msgval; + const upb_Map* map_val; + const upb_Message* msg_val; + const upb_Array* array_val; + upb_StringView str_val; +} upb_MessageValue; typedef union { - upb_map* map; - upb_msg* msg; - upb_array* array; -} upb_mutmsgval; + upb_Map* map; + upb_Message* msg; + upb_Array* array; +} upb_MutableMessageValue; -upb_msgval upb_fielddef_default(const upb_fielddef *f); +upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f); -/** upb_msg *******************************************************************/ +/** upb_Message + * *******************************************************************/ /* Creates a new message of the given type in the given arena. */ -upb_msg *upb_msg_new(const upb_msgdef *m, upb_arena *a); +upb_Message* upb_Message_New(const upb_MessageDef* m, upb_Arena* a); /* Returns the value associated with this field. */ -upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f); +upb_MessageValue upb_Message_Get(const upb_Message* msg, const upb_FieldDef* f); /* Returns a mutable pointer to a map, array, or submessage value. If the given * arena is non-NULL this will construct a new object if it was not previously * present. May not be called for primitive fields. */ -upb_mutmsgval upb_msg_mutable(upb_msg *msg, const upb_fielddef *f, upb_arena *a); +upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg, + const upb_FieldDef* f, + upb_Arena* a); -/* May only be called for fields where upb_fielddef_haspresence(f) == true. */ -bool upb_msg_has(const upb_msg *msg, const upb_fielddef *f); +/* May only be called for fields where upb_FieldDef_HasPresence(f) == true. */ +bool upb_Message_Has(const upb_Message* msg, const upb_FieldDef* f); /* Returns the field that is set in the oneof, or NULL if none are set. */ -const upb_fielddef *upb_msg_whichoneof(const upb_msg *msg, - const upb_oneofdef *o); +const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, + const upb_OneofDef* o); /* Sets the given field to the given value. For a msg/array/map/string, the - * value must be in the same arena. */ -void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val, - upb_arena *a); + * caller must ensure that the target data outlives |msg| (by living either in + * the same arena or a different arena that outlives it). + * + * Returns false if allocation fails. */ +bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f, + upb_MessageValue val, upb_Arena* a); /* Clears any field presence and sets the value back to its default. */ -void upb_msg_clearfield(upb_msg *msg, const upb_fielddef *f); +void upb_Message_ClearField(upb_Message* msg, const upb_FieldDef* f); /* Clear all data and unknown fields. */ -void upb_msg_clear(upb_msg *msg, const upb_msgdef *m); +void upb_Message_Clear(upb_Message* msg, const upb_MessageDef* m); /* Iterate over present fields. * - * size_t iter = UPB_MSG_BEGIN; - * const upb_fielddef *f; - * upb_msgval val; - * while (upb_msg_next(msg, m, ext_pool, &f, &val, &iter)) { + * size_t iter = kUpb_Message_Begin; + * const upb_FieldDef *f; + * upb_MessageValue val; + * while (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) { * process_field(f, val); * } * @@ -4519,90 +5082,109 @@ void upb_msg_clear(upb_msg *msg, const upb_msgdef *m); * will be skipped. */ -#define UPB_MSG_BEGIN -1 -bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m, - const upb_symtab *ext_pool, const upb_fielddef **f, - upb_msgval *val, size_t *iter); +#define kUpb_Message_Begin -1 +bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, const upb_FieldDef** f, + upb_MessageValue* val, size_t* iter); /* Clears all unknown field data from this message and all submessages. */ -bool upb_msg_discardunknown(upb_msg *msg, const upb_msgdef *m, int maxdepth); +bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, + int maxdepth); -/** upb_array *****************************************************************/ +/** upb_Array *****************************************************************/ /* Creates a new array on the given arena that holds elements of this type. */ -upb_array *upb_array_new(upb_arena *a, upb_fieldtype_t type); +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); /* Returns the size of the array. */ -size_t upb_array_size(const upb_array *arr); +size_t upb_Array_Size(const upb_Array* arr); /* Returns the given element, which must be within the array's current size. */ -upb_msgval upb_array_get(const upb_array *arr, size_t i); +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); /* Sets the given element, which must be within the array's current size. */ -void upb_array_set(upb_array *arr, size_t i, upb_msgval val); +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); /* Appends an element to the array. Returns false on allocation failure. */ -bool upb_array_append(upb_array *array, upb_msgval val, upb_arena *arena); +bool upb_Array_Append(upb_Array* array, upb_MessageValue val, upb_Arena* arena); + +/* Moves elements within the array using memmove(). Like memmove(), the source + * and destination elements may be overlapping. */ +void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, + size_t count); + +/* Inserts one or more empty elements into the array. Existing elements are + * shifted right. The new elements have undefined state and must be set with + * `upb_Array_Set()`. + * REQUIRES: `i <= upb_Array_Size(arr)` */ +bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, + upb_Arena* arena); + +/* Deletes one or more elements from the array. Existing elements are shifted + * left. + * REQUIRES: `i + count <= upb_Array_Size(arr)` */ +void upb_Array_Delete(upb_Array* array, size_t i, size_t count); /* Changes the size of a vector. New elements are initialized to empty/0. * Returns false on allocation failure. */ -bool upb_array_resize(upb_array *array, size_t size, upb_arena *arena); +bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); -/** upb_map *******************************************************************/ +/** upb_Map *******************************************************************/ /* Creates a new map on the given arena with the given key/value size. */ -upb_map *upb_map_new(upb_arena *a, upb_fieldtype_t key_type, - upb_fieldtype_t value_type); +upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type); /* Returns the number of entries in the map. */ -size_t upb_map_size(const upb_map *map); +size_t upb_Map_Size(const upb_Map* map); /* Stores a value for the given key into |*val| (or the zero value if the key is * not present). Returns whether the key was present. The |val| pointer may be * NULL, in which case the function tests whether the given key is present. */ -bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val); +bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); /* Removes all entries in the map. */ -void upb_map_clear(upb_map *map); +void upb_Map_Clear(upb_Map* map); /* Sets the given key to the given value. Returns true if this was a new key in * the map, or false if an existing key was replaced. */ -bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val, - upb_arena *arena); +bool upb_Map_Set(upb_Map* map, upb_MessageValue key, upb_MessageValue val, + upb_Arena* arena); /* Deletes this key from the table. Returns true if the key was present. */ -bool upb_map_delete(upb_map *map, upb_msgval key); +bool upb_Map_Delete(upb_Map* map, upb_MessageValue key); /* Map iteration: * - * size_t iter = UPB_MAP_BEGIN; - * while (upb_mapiter_next(map, &iter)) { - * upb_msgval key = upb_mapiter_key(map, iter); - * upb_msgval val = upb_mapiter_value(map, iter); + * size_t iter = kUpb_Map_Begin; + * while (upb_MapIterator_Next(map, &iter)) { + * upb_MessageValue key = upb_MapIterator_Key(map, iter); + * upb_MessageValue val = upb_MapIterator_Value(map, iter); * * // If mutating is desired. - * upb_mapiter_setvalue(map, iter, value2); + * upb_MapIterator_SetValue(map, iter, value2); * } */ /* Advances to the next entry. Returns false if no more entries are present. */ -bool upb_mapiter_next(const upb_map *map, size_t *iter); +bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); /* Returns true if the iterator still points to a valid entry, or false if the * iterator is past the last element. It is an error to call this function with - * UPB_MAP_BEGIN (you must call next() at least once first). */ -bool upb_mapiter_done(const upb_map *map, size_t iter); + * kUpb_Map_Begin (you must call next() at least once first). */ +bool upb_MapIterator_Done(const upb_Map* map, size_t iter); /* Returns the key and value for this entry of the map. */ -upb_msgval upb_mapiter_key(const upb_map *map, size_t iter); -upb_msgval upb_mapiter_value(const upb_map *map, size_t iter); +upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); +upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); /* Sets the value for this entry. The iterator must not be done, and the * iterator must not have been initialized const. */ -void upb_mapiter_setvalue(upb_map *map, size_t iter, upb_msgval value); +void upb_MapIterator_SetValue(upb_Map* map, size_t iter, + upb_MessageValue value); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif @@ -4617,19 +5199,17 @@ void upb_mapiter_setvalue(upb_map *map, size_t iter, upb_msgval value); extern "C" { #endif -enum { - UPB_JSONDEC_IGNOREUNKNOWN = 1 -}; +enum { upb_JsonDecode_IgnoreUnknown = 1 }; -bool upb_json_decode(const char *buf, size_t size, upb_msg *msg, - const upb_msgdef *m, const upb_symtab *any_pool, - int options, upb_arena *arena, upb_status *status); +bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, + const upb_MessageDef* m, const upb_DefPool* symtab, + int options, upb_Arena* arena, upb_Status* status); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif -#endif /* UPB_JSONDECODE_H_ */ +#endif /* UPB_JSONDECODE_H_ */ /** upb/json_encode.h ************************************************************/ #ifndef UPB_JSONENCODE_H_ @@ -4642,11 +5222,11 @@ extern "C" { enum { /* When set, emits 0/default values. TODO(haberman): proto3 only? */ - UPB_JSONENC_EMITDEFAULTS = 1, + upb_JsonEncode_EmitDefaults = 1, /* When set, use normal (snake_caes) field names instead of JSON (camelCase) names. */ - UPB_JSONENC_PROTONAMES = 2 + upb_JsonEncode_UseProtoNames = 2 }; /* Encodes the given |msg| to JSON format. The message's reflection is given in @@ -4657,15 +5237,15 @@ enum { * size (excluding NULL) is returned. This means that a return value >= |size| * implies that the output was truncated. (These are the same semantics as * snprintf()). */ -size_t upb_json_encode(const upb_msg *msg, const upb_msgdef *m, - const upb_symtab *ext_pool, int options, char *buf, - size_t size, upb_status *status); +size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, int options, char* buf, + size_t size, upb_Status* status); #ifdef __cplusplus -} /* extern "C" */ +} /* extern "C" */ #endif -#endif /* UPB_JSONENCODE_H_ */ +#endif /* UPB_JSONENCODE_H_ */ /** upb/port_undef.inc ************************************************************/ /* See port_def.inc. This should #undef all macros #defined there. */ From e554bd6cbf8d6325ce13bc0fe822124a81d36008 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Sat, 22 Jan 2022 00:38:59 +0100 Subject: [PATCH 148/207] Use constexpr for FieldTypeClass (#9434) Otherwise in C++20 / VisualStudio 2022 the following warning is emitted: ``` warning C5054: operator '*': deprecated between enumerations of different types ``` --- src/google/protobuf/generated_message_table_driven.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/generated_message_table_driven.h b/src/google/protobuf/generated_message_table_driven.h index 15eebcbf87..f960818cb9 100644 --- a/src/google/protobuf/generated_message_table_driven.h +++ b/src/google/protobuf/generated_message_table_driven.h @@ -103,13 +103,11 @@ struct PROTOBUF_EXPORT FieldMetadata { }; // C++ protobuf has 20 fundamental types, were we added Cord and StringPiece // and also distinguish the same types if they have different wire format. - enum { - kCordType = 19, - kStringPieceType = 20, - kInlinedType = 21, - kNumTypes = 21, - kSpecial = kNumTypes * kNumTypeClasses, - }; + static constexpr auto kCordType = 19; + static constexpr auto kStringPieceType = 20; + static constexpr auto kInlinedType = 21; + static constexpr auto kNumTypes = 21; + static constexpr auto kSpecial = kNumTypes * kNumTypeClasses; static int CalculateType(int fundamental_type, FieldTypeClass type_class); }; From c153dd9bf75e934d47277aacb56518e95f7766c3 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 21 Jan 2022 15:46:56 -0800 Subject: [PATCH 149/207] Updated to new upb APIs. --- ruby/Rakefile | 8 + ruby/ext/google/protobuf_c/convert.c | 229 +++---- ruby/ext/google/protobuf_c/convert.h | 21 +- ruby/ext/google/protobuf_c/defs.c | 397 ++++++------- ruby/ext/google/protobuf_c/defs.h | 38 +- ruby/ext/google/protobuf_c/map.c | 210 +++---- ruby/ext/google/protobuf_c/map.h | 15 +- ruby/ext/google/protobuf_c/message.c | 626 +++++++++++--------- ruby/ext/google/protobuf_c/message.h | 41 +- ruby/ext/google/protobuf_c/protobuf.c | 115 ++-- ruby/ext/google/protobuf_c/protobuf.h | 23 +- ruby/ext/google/protobuf_c/repeated_field.c | 166 +++--- ruby/ext/google/protobuf_c/repeated_field.h | 12 +- ruby/ext/google/protobuf_c/ruby-upb.c | 2 +- ruby/ext/google/protobuf_c/ruby-upb.h | 4 + ruby/ext/google/protobuf_c/wrap_memcpy.c | 7 +- ruby/tests/common_tests.rb | 8 +- 17 files changed, 1000 insertions(+), 922 deletions(-) diff --git a/ruby/Rakefile b/ruby/Rakefile index 89b9ca5bfc..762dc2c00d 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -80,6 +80,14 @@ if RUBY_PLATFORM == "java" end else + unless ENV['IN_DOCKER'] == 'true' + # We need utf8_range in-tree. + FileUtils.mkdir_p("ext/google/protobuf_c/third_party/utf8_range") + FileUtils.cp("../third_party/utf8_range/utf8_range.h", "ext/google/protobuf_c/third_party/utf8_range") + FileUtils.cp("../third_party/utf8_range/utf8_range.c", "ext/google/protobuf_c/third_party/utf8_range") + FileUtils.cp("../third_party/utf8_range/LICENSE", "ext/google/protobuf_c/third_party/utf8_range") + end + Rake::ExtensionTask.new("protobuf_c", spec) do |ext| unless RUBY_PLATFORM =~ /darwin/ # TODO: also set "no_native to true" for mac if possible. As is, diff --git a/ruby/ext/google/protobuf_c/convert.c b/ruby/ext/google/protobuf_c/convert.c index 8bcf6eee00..8b98aeeb56 100644 --- a/ruby/ext/google/protobuf_c/convert.c +++ b/ruby/ext/google/protobuf_c/convert.c @@ -31,7 +31,7 @@ // ----------------------------------------------------------------------------- // Ruby <-> upb data conversion functions. // -// This file Also contains a few other assorted algorithms on upb_msgval. +// This file Also contains a few other assorted algorithms on upb_MessageValue. // // None of the algorithms in this file require any access to the internal // representation of Ruby or upb objects. @@ -42,10 +42,10 @@ #include "message.h" #include "protobuf.h" -static upb_strview Convert_StringData(VALUE str, upb_arena *arena) { - upb_strview ret; +static upb_StringView Convert_StringData(VALUE str, upb_Arena* arena) { + upb_StringView ret; if (arena) { - char *ptr = upb_arena_malloc(arena, RSTRING_LEN(str)); + char* ptr = upb_Arena_Malloc(arena, RSTRING_LEN(str)); memcpy(ptr, RSTRING_PTR(str), RSTRING_LEN(str)); ret.data = ptr; } else { @@ -57,13 +57,11 @@ static upb_strview Convert_StringData(VALUE str, upb_arena *arena) { } static bool is_ruby_num(VALUE value) { - return (TYPE(value) == T_FLOAT || - TYPE(value) == T_FIXNUM || + return (TYPE(value) == T_FLOAT || TYPE(value) == T_FIXNUM || TYPE(value) == T_BIGNUM); } -static void Convert_CheckInt(const char* name, upb_fieldtype_t type, - VALUE val) { +static void Convert_CheckInt(const char* name, upb_CType type, VALUE val) { if (!is_ruby_num(val)) { rb_raise(cTypeError, "Expected number type for integral field '%s' (given %s).", name, @@ -82,7 +80,7 @@ static void Convert_CheckInt(const char* name, upb_fieldtype_t type, name, rb_class2name(CLASS_OF(val))); } } - if (type == UPB_TYPE_UINT32 || type == UPB_TYPE_UINT64) { + if (type == kUpb_CType_UInt32 || type == kUpb_CType_UInt64) { if (NUM2DBL(val) < 0) { rb_raise( rb_eRangeError, @@ -93,26 +91,31 @@ static void Convert_CheckInt(const char* name, upb_fieldtype_t type, } static int32_t Convert_ToEnum(VALUE value, const char* name, - const upb_enumdef* e) { + const upb_EnumDef* e) { int32_t val; switch (TYPE(value)) { case T_FLOAT: case T_FIXNUM: case T_BIGNUM: - Convert_CheckInt(name, UPB_TYPE_INT32, value); + Convert_CheckInt(name, kUpb_CType_Int32, value); val = NUM2INT(value); break; - case T_STRING: - if (!upb_enumdef_ntoi(e, RSTRING_PTR(value), RSTRING_LEN(value), &val)) { - goto unknownval; - } + case T_STRING: { + const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNameWithSize( + e, RSTRING_PTR(value), RSTRING_LEN(value)); + if (!ev) goto unknownval; + val = upb_EnumValueDef_Number(ev); break; - case T_SYMBOL: - if (!upb_enumdef_ntoiz(e, rb_id2name(SYM2ID(value)), &val)) { + } + case T_SYMBOL: { + const upb_EnumValueDef* ev = + upb_EnumDef_FindValueByName(e, rb_id2name(SYM2ID(value))); + if (!ev) goto unknownval; - } + val = upb_EnumValueDef_Number(ev); break; + } default: rb_raise(cTypeError, "Expected number or symbol type for enum field '%s'.", name); @@ -124,47 +127,52 @@ unknownval: rb_raise(rb_eRangeError, "Unknown symbol value for enum field '%s'.", name); } -upb_msgval Convert_RubyToUpb(VALUE value, const char* name, TypeInfo type_info, - upb_arena* arena) { - upb_msgval ret; +upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name, + TypeInfo type_info, upb_Arena* arena) { + upb_MessageValue ret; switch (type_info.type) { - case UPB_TYPE_FLOAT: + case kUpb_CType_Float: if (!is_ruby_num(value)) { - rb_raise(cTypeError, "Expected number type for float field '%s' (given %s).", - name, rb_class2name(CLASS_OF(value))); + rb_raise(cTypeError, + "Expected number type for float field '%s' (given %s).", name, + rb_class2name(CLASS_OF(value))); } ret.float_val = NUM2DBL(value); break; - case UPB_TYPE_DOUBLE: + case kUpb_CType_Double: if (!is_ruby_num(value)) { - rb_raise(cTypeError, "Expected number type for double field '%s' (given %s).", - name, rb_class2name(CLASS_OF(value))); + rb_raise(cTypeError, + "Expected number type for double field '%s' (given %s).", name, + rb_class2name(CLASS_OF(value))); } ret.double_val = NUM2DBL(value); break; - case UPB_TYPE_BOOL: { + case kUpb_CType_Bool: { if (value == Qtrue) { ret.bool_val = 1; } else if (value == Qfalse) { ret.bool_val = 0; } else { - rb_raise(cTypeError, "Invalid argument for boolean field '%s' (given %s).", - name, rb_class2name(CLASS_OF(value))); + rb_raise(cTypeError, + "Invalid argument for boolean field '%s' (given %s).", name, + rb_class2name(CLASS_OF(value))); } break; } - case UPB_TYPE_STRING: { + case kUpb_CType_String: { VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding()); if (CLASS_OF(value) == rb_cSymbol) { value = rb_funcall(value, rb_intern("to_s"), 0); } else if (CLASS_OF(value) != rb_cString) { - rb_raise(cTypeError, "Invalid argument for string field '%s' (given %s).", - name, rb_class2name(CLASS_OF(value))); + rb_raise(cTypeError, + "Invalid argument for string field '%s' (given %s).", name, + rb_class2name(CLASS_OF(value))); } if (rb_obj_encoding(value) != utf8) { - // Note: this will not duplicate underlying string data unless necessary. + // Note: this will not duplicate underlying string data unless + // necessary. value = rb_str_encode(value, utf8, 0, Qnil); if (rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) { @@ -175,15 +183,17 @@ upb_msgval Convert_RubyToUpb(VALUE value, const char* name, TypeInfo type_info, ret.str_val = Convert_StringData(value, arena); break; } - case UPB_TYPE_BYTES: { + case kUpb_CType_Bytes: { VALUE bytes = rb_enc_from_encoding(rb_ascii8bit_encoding()); if (CLASS_OF(value) != rb_cString) { - rb_raise(cTypeError, "Invalid argument for bytes field '%s' (given %s).", - name, rb_class2name(CLASS_OF(value))); + rb_raise(cTypeError, + "Invalid argument for bytes field '%s' (given %s).", name, + rb_class2name(CLASS_OF(value))); } if (rb_obj_encoding(value) != bytes) { - // Note: this will not duplicate underlying string data unless necessary. + // Note: this will not duplicate underlying string data unless + // necessary. // TODO(haberman): is this really necessary to get raw bytes? value = rb_str_encode(value, bytes, 0, Qnil); } @@ -191,33 +201,33 @@ upb_msgval Convert_RubyToUpb(VALUE value, const char* name, TypeInfo type_info, ret.str_val = Convert_StringData(value, arena); break; } - case UPB_TYPE_MESSAGE: + case kUpb_CType_Message: ret.msg_val = Message_GetUpbMessage(value, type_info.def.msgdef, name, arena); break; - case UPB_TYPE_ENUM: + case kUpb_CType_Enum: ret.int32_val = Convert_ToEnum(value, name, type_info.def.enumdef); break; - case UPB_TYPE_INT32: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT32: - case UPB_TYPE_UINT64: + case kUpb_CType_Int32: + case kUpb_CType_Int64: + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: Convert_CheckInt(name, type_info.type, value); switch (type_info.type) { - case UPB_TYPE_INT32: - ret.int32_val = NUM2INT(value); - break; - case UPB_TYPE_INT64: - ret.int64_val = NUM2LL(value); - break; - case UPB_TYPE_UINT32: - ret.uint32_val = NUM2UINT(value); - break; - case UPB_TYPE_UINT64: - ret.uint64_val = NUM2ULL(value); - break; - default: - break; + case kUpb_CType_Int32: + ret.int32_val = NUM2INT(value); + break; + case kUpb_CType_Int64: + ret.int64_val = NUM2LL(value); + break; + case kUpb_CType_UInt32: + ret.uint32_val = NUM2UINT(value); + break; + case kUpb_CType_UInt64: + ret.uint64_val = NUM2ULL(value); + break; + default: + break; } break; default: @@ -227,45 +237,46 @@ upb_msgval Convert_RubyToUpb(VALUE value, const char* name, TypeInfo type_info, return ret; } -VALUE Convert_UpbToRuby(upb_msgval upb_val, TypeInfo type_info, VALUE arena) { +VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info, + VALUE arena) { switch (type_info.type) { - case UPB_TYPE_FLOAT: + case kUpb_CType_Float: return DBL2NUM(upb_val.float_val); - case UPB_TYPE_DOUBLE: + case kUpb_CType_Double: return DBL2NUM(upb_val.double_val); - case UPB_TYPE_BOOL: + case kUpb_CType_Bool: return upb_val.bool_val ? Qtrue : Qfalse; - case UPB_TYPE_INT32: + case kUpb_CType_Int32: return INT2NUM(upb_val.int32_val); - case UPB_TYPE_INT64: + case kUpb_CType_Int64: return LL2NUM(upb_val.int64_val); - case UPB_TYPE_UINT32: + case kUpb_CType_UInt32: return UINT2NUM(upb_val.uint32_val); - case UPB_TYPE_UINT64: + case kUpb_CType_UInt64: return ULL2NUM(upb_val.int64_val); - case UPB_TYPE_ENUM: { - const char* name = - upb_enumdef_iton(type_info.def.enumdef, upb_val.int32_val); - if (name) { - return ID2SYM(rb_intern(name)); + case kUpb_CType_Enum: { + const upb_EnumValueDef *ev = upb_EnumDef_FindValueByNumber( + type_info.def.enumdef, upb_val.int32_val); + if (ev) { + return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev))); } else { return INT2NUM(upb_val.int32_val); } } - case UPB_TYPE_STRING: { + case kUpb_CType_String: { VALUE str_rb = rb_str_new(upb_val.str_val.data, upb_val.str_val.size); rb_enc_associate(str_rb, rb_utf8_encoding()); rb_obj_freeze(str_rb); return str_rb; } - case UPB_TYPE_BYTES: { + case kUpb_CType_Bytes: { VALUE str_rb = rb_str_new(upb_val.str_val.data, upb_val.str_val.size); rb_enc_associate(str_rb, rb_ascii8bit_encoding()); rb_obj_freeze(str_rb); return str_rb; } - case UPB_TYPE_MESSAGE: - return Message_GetRubyWrapper((upb_msg*)upb_val.msg_val, + case kUpb_CType_Message: + return Message_GetRubyWrapper((upb_Message*)upb_val.msg_val, type_info.def.msgdef, arena); default: rb_raise(rb_eRuntimeError, "Convert_UpbToRuby(): Unexpected type %d", @@ -273,24 +284,24 @@ VALUE Convert_UpbToRuby(upb_msgval upb_val, TypeInfo type_info, VALUE arena) { } } -upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info, - upb_arena* arena) { - upb_msgval new_msgval; +upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info, + upb_Arena* arena) { + upb_MessageValue new_msgval; switch (type_info.type) { default: memcpy(&new_msgval, &msgval, sizeof(msgval)); break; - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: { + case kUpb_CType_String: + case kUpb_CType_Bytes: { size_t n = msgval.str_val.size; - char *mem = upb_arena_malloc(arena, n); + char* mem = upb_Arena_Malloc(arena, n); new_msgval.str_val.data = mem; new_msgval.str_val.size = n; memcpy(mem, msgval.str_val.data, n); break; } - case UPB_TYPE_MESSAGE: + case kUpb_CType_Message: new_msgval.msg_val = Message_deep_copy(msgval.msg_val, type_info.def.msgdef, arena); break; @@ -299,48 +310,50 @@ upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info, return new_msgval; } -bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info) { +bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2, + TypeInfo type_info) { switch (type_info.type) { - case UPB_TYPE_BOOL: + case kUpb_CType_Bool: return memcmp(&val1, &val2, 1) == 0; - case UPB_TYPE_FLOAT: - case UPB_TYPE_INT32: - case UPB_TYPE_UINT32: - case UPB_TYPE_ENUM: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: return memcmp(&val1, &val2, 4) == 0; - case UPB_TYPE_DOUBLE: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT64: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: return memcmp(&val1, &val2, 8) == 0; - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: + case kUpb_CType_String: + case kUpb_CType_Bytes: return val1.str_val.size == val2.str_val.size && - memcmp(val1.str_val.data, val2.str_val.data, - val1.str_val.size) == 0; - case UPB_TYPE_MESSAGE: + memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) == + 0; + case kUpb_CType_Message: return Message_Equal(val1.msg_val, val2.msg_val, type_info.def.msgdef); default: rb_raise(rb_eRuntimeError, "Internal error, unexpected type"); } } -uint64_t Msgval_GetHash(upb_msgval val, TypeInfo type_info, uint64_t seed) { +uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info, + uint64_t seed) { switch (type_info.type) { - case UPB_TYPE_BOOL: + case kUpb_CType_Bool: return Wyhash(&val, 1, seed, kWyhashSalt); - case UPB_TYPE_FLOAT: - case UPB_TYPE_INT32: - case UPB_TYPE_UINT32: - case UPB_TYPE_ENUM: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: return Wyhash(&val, 4, seed, kWyhashSalt); - case UPB_TYPE_DOUBLE: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT64: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: return Wyhash(&val, 8, seed, kWyhashSalt); - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: + case kUpb_CType_String: + case kUpb_CType_Bytes: return Wyhash(val.str_val.data, val.str_val.size, seed, kWyhashSalt); - case UPB_TYPE_MESSAGE: + case kUpb_CType_Message: return Message_Hash(val.msg_val, type_info.def.msgdef, seed); default: rb_raise(rb_eRuntimeError, "Internal error, unexpected type"); diff --git a/ruby/ext/google/protobuf_c/convert.h b/ruby/ext/google/protobuf_c/convert.h index cda18a0547..e48c979455 100644 --- a/ruby/ext/google/protobuf_c/convert.h +++ b/ruby/ext/google/protobuf_c/convert.h @@ -36,7 +36,7 @@ #include "protobuf.h" #include "ruby-upb.h" -// Converts |ruby_val| to a upb_msgval according to |type_info|. +// Converts |ruby_val| to a upb_MessageValue according to |type_info|. // // The |arena| parameter indicates the lifetime of the container where this // value will be assigned. It is used as follows: @@ -47,8 +47,8 @@ // - If type is message and the Ruby value is a message instance, we will fuse // the message's arena into |arena|, to ensure that this message outlives the // container. -upb_msgval Convert_RubyToUpb(VALUE ruby_val, const char *name, - TypeInfo type_info, upb_arena *arena); +upb_MessageValue Convert_RubyToUpb(VALUE ruby_val, const char *name, + TypeInfo type_info, upb_Arena *arena); // Converts |upb_val| to a Ruby VALUE according to |type_info|. This may involve // creating a Ruby wrapper object. @@ -56,17 +56,20 @@ upb_msgval Convert_RubyToUpb(VALUE ruby_val, const char *name, // The |arena| parameter indicates the arena that owns the lifetime of // |upb_val|. Any Ruby wrapper object that is created will reference |arena| // and ensure it outlives the wrapper. -VALUE Convert_UpbToRuby(upb_msgval upb_val, TypeInfo type_info, VALUE arena); +VALUE Convert_UpbToRuby(upb_MessageValue upb_val, TypeInfo type_info, + VALUE arena); // Creates a deep copy of |msgval| in |arena|. -upb_msgval Msgval_DeepCopy(upb_msgval msgval, TypeInfo type_info, - upb_arena *arena); +upb_MessageValue Msgval_DeepCopy(upb_MessageValue msgval, TypeInfo type_info, + upb_Arena *arena); // Returns true if |val1| and |val2| are equal. Their type is given by // |type_info|. -bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info); +bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2, + TypeInfo type_info); -// Returns a hash value for the given upb_msgval. -uint64_t Msgval_GetHash(upb_msgval val, TypeInfo type_info, uint64_t seed); +// Returns a hash value for the given upb_MessageValue. +uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info, + uint64_t seed); #endif // RUBY_PROTOBUF_CONVERT_H_ diff --git a/ruby/ext/google/protobuf_c/defs.c b/ruby/ext/google/protobuf_c/defs.c index fd32cce665..aaa8b4dc7a 100644 --- a/ruby/ext/google/protobuf_c/defs.c +++ b/ruby/ext/google/protobuf_c/defs.c @@ -41,11 +41,11 @@ // instances. // ----------------------------------------------------------------------------- -static VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_msgdef* def); -static VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_enumdef* def); -static VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_fielddef* def); -static VALUE get_filedef_obj(VALUE descriptor_pool, const upb_filedef* def); -static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_oneofdef* def); +static VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_MessageDef* def); +static VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_EnumDef* def); +static VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_FieldDef* def); +static VALUE get_filedef_obj(VALUE descriptor_pool, const upb_FileDef* def); +static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_OneofDef* def); // A distinct object that is not accessible from Ruby. We use this as a // constructor argument to enforce that certain objects cannot be created from @@ -74,7 +74,7 @@ static VALUE rb_str_maybe_null(const char* s) { typedef struct { VALUE def_to_descriptor; // Hash table of def* -> Ruby descriptor. - upb_symtab* symtab; + upb_DefPool* symtab; } DescriptorPool; VALUE cDescriptorPool = Qnil; @@ -90,14 +90,14 @@ static void DescriptorPool_mark(void* _self) { static void DescriptorPool_free(void* _self) { DescriptorPool* self = _self; - upb_symtab_free(self->symtab); + upb_DefPool_Free(self->symtab); xfree(self); } static const rb_data_type_t DescriptorPool_type = { - "Google::Protobuf::DescriptorPool", - {DescriptorPool_mark, DescriptorPool_free, NULL}, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Google::Protobuf::DescriptorPool", + {DescriptorPool_mark, DescriptorPool_free, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; static DescriptorPool* ruby_to_DescriptorPool(VALUE val) { @@ -107,8 +107,8 @@ static DescriptorPool* ruby_to_DescriptorPool(VALUE val) { } // Exposed to other modules in defs.h. -const upb_symtab *DescriptorPool_GetSymtab(VALUE desc_pool_rb) { - DescriptorPool *pool = ruby_to_DescriptorPool(desc_pool_rb); +const upb_DefPool* DescriptorPool_GetSymtab(VALUE desc_pool_rb) { + DescriptorPool* pool = ruby_to_DescriptorPool(desc_pool_rb); return pool->symtab; } @@ -126,7 +126,7 @@ static VALUE DescriptorPool_alloc(VALUE klass) { ret = TypedData_Wrap_Struct(klass, &DescriptorPool_type, self); self->def_to_descriptor = rb_hash_new(); - self->symtab = upb_symtab_new(); + self->symtab = upb_DefPool_New(); ObjectCache_Add(self->symtab, ret); return ret; @@ -143,7 +143,7 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self, DescriptorPool* self = ruby_to_DescriptorPool(_self); Check_Type(serialized_file_proto, T_STRING); VALUE arena_rb = Arena_new(); - upb_arena *arena = Arena_get(arena_rb); + upb_Arena* arena = Arena_get(arena_rb); google_protobuf_FileDescriptorProto* file_proto = google_protobuf_FileDescriptorProto_parse( RSTRING_PTR(serialized_file_proto), @@ -151,13 +151,13 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self, if (!file_proto) { rb_raise(rb_eArgError, "Unable to parse FileDescriptorProto"); } - upb_status status; - upb_status_clear(&status); - const upb_filedef* filedef = - upb_symtab_addfile(self->symtab, file_proto, &status); + upb_Status status; + upb_Status_Clear(&status); + const upb_FileDef* filedef = + upb_DefPool_AddFile(self->symtab, file_proto, &status); if (!filedef) { rb_raise(cTypeError, "Unable to build file to DescriptorPool: %s", - upb_status_errmsg(&status)); + upb_Status_ErrorMessage(&status)); } return get_filedef_obj(_self, filedef); } @@ -172,15 +172,15 @@ VALUE DescriptorPool_add_serialized_file(VALUE _self, static VALUE DescriptorPool_lookup(VALUE _self, VALUE name) { DescriptorPool* self = ruby_to_DescriptorPool(_self); const char* name_str = get_str(name); - const upb_msgdef* msgdef; - const upb_enumdef* enumdef; + const upb_MessageDef* msgdef; + const upb_EnumDef* enumdef; - msgdef = upb_symtab_lookupmsg(self->symtab, name_str); + msgdef = upb_DefPool_FindMessageByName(self->symtab, name_str); if (msgdef) { return get_msgdef_obj(_self, msgdef); } - enumdef = upb_symtab_lookupenum(self->symtab, name_str); + enumdef = upb_DefPool_FindEnumByName(self->symtab, name_str); if (enumdef) { return get_enumdef_obj(_self, enumdef); } @@ -202,8 +202,7 @@ static VALUE DescriptorPool_generated_pool(VALUE _self) { } static void DescriptorPool_register(VALUE module) { - VALUE klass = rb_define_class_under( - module, "DescriptorPool", rb_cObject); + VALUE klass = rb_define_class_under(module, "DescriptorPool", rb_cObject); rb_define_alloc_func(klass, DescriptorPool_alloc); rb_define_method(klass, "add_serialized_file", DescriptorPool_add_serialized_file, 1); @@ -222,7 +221,7 @@ static void DescriptorPool_register(VALUE module) { // ----------------------------------------------------------------------------- typedef struct { - const upb_msgdef* msgdef; + const upb_MessageDef* msgdef; VALUE klass; VALUE descriptor_pool; } Descriptor; @@ -236,9 +235,9 @@ static void Descriptor_mark(void* _self) { } static const rb_data_type_t Descriptor_type = { - "Google::Protobuf::Descriptor", - {Descriptor_mark, RUBY_DEFAULT_FREE, NULL}, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Google::Protobuf::Descriptor", + {Descriptor_mark, RUBY_DEFAULT_FREE, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; static Descriptor* ruby_to_Descriptor(VALUE val) { @@ -281,7 +280,7 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie, } self->descriptor_pool = descriptor_pool; - self->msgdef = (const upb_msgdef*)NUM2ULL(ptr); + self->msgdef = (const upb_MessageDef*)NUM2ULL(ptr); return Qnil; } @@ -294,7 +293,8 @@ static VALUE Descriptor_initialize(VALUE _self, VALUE cookie, */ static VALUE Descriptor_file_descriptor(VALUE _self) { Descriptor* self = ruby_to_Descriptor(_self); - return get_filedef_obj(self->descriptor_pool, upb_msgdef_file(self->msgdef)); + return get_filedef_obj(self->descriptor_pool, + upb_MessageDef_File(self->msgdef)); } /* @@ -306,7 +306,7 @@ static VALUE Descriptor_file_descriptor(VALUE _self) { */ static VALUE Descriptor_name(VALUE _self) { Descriptor* self = ruby_to_Descriptor(_self); - return rb_str_maybe_null(upb_msgdef_fullname(self->msgdef)); + return rb_str_maybe_null(upb_MessageDef_FullName(self->msgdef)); } /* @@ -318,11 +318,9 @@ static VALUE Descriptor_name(VALUE _self) { static VALUE Descriptor_each(VALUE _self) { Descriptor* self = ruby_to_Descriptor(_self); - upb_msg_field_iter it; - for (upb_msg_field_begin(&it, self->msgdef); - !upb_msg_field_done(&it); - upb_msg_field_next(&it)) { - const upb_fielddef* field = upb_msg_iter_field(&it); + int n = upb_MessageDef_FieldCount(self->msgdef); + for (int i = 0; i < n; i++) { + const upb_FieldDef* field = upb_MessageDef_Field(self->msgdef, i); VALUE obj = get_fielddef_obj(self->descriptor_pool, field); rb_yield(obj); } @@ -339,7 +337,7 @@ static VALUE Descriptor_each(VALUE _self) { static VALUE Descriptor_lookup(VALUE _self, VALUE name) { Descriptor* self = ruby_to_Descriptor(_self); const char* s = get_str(name); - const upb_fielddef* field = upb_msgdef_ntofz(self->msgdef, s); + const upb_FieldDef* field = upb_MessageDef_FindFieldByName(self->msgdef, s); if (field == NULL) { return Qnil; } @@ -356,11 +354,9 @@ static VALUE Descriptor_lookup(VALUE _self, VALUE name) { static VALUE Descriptor_each_oneof(VALUE _self) { Descriptor* self = ruby_to_Descriptor(_self); - upb_msg_oneof_iter it; - for (upb_msg_oneof_begin(&it, self->msgdef); - !upb_msg_oneof_done(&it); - upb_msg_oneof_next(&it)) { - const upb_oneofdef* oneof = upb_msg_iter_oneof(&it); + int n = upb_MessageDef_OneofCount(self->msgdef); + for (int i = 0; i < n; i++) { + const upb_OneofDef* oneof = upb_MessageDef_Oneof(self->msgdef, i); VALUE obj = get_oneofdef_obj(self->descriptor_pool, oneof); rb_yield(obj); } @@ -377,7 +373,7 @@ static VALUE Descriptor_each_oneof(VALUE _self) { static VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) { Descriptor* self = ruby_to_Descriptor(_self); const char* s = get_str(name); - const upb_oneofdef* oneof = upb_msgdef_ntooz(self->msgdef, s); + const upb_OneofDef* oneof = upb_MessageDef_FindOneofByName(self->msgdef, s); if (oneof == NULL) { return Qnil; } @@ -399,8 +395,7 @@ static VALUE Descriptor_msgclass(VALUE _self) { } static void Descriptor_register(VALUE module) { - VALUE klass = rb_define_class_under( - module, "Descriptor", rb_cObject); + VALUE klass = rb_define_class_under(module, "Descriptor", rb_cObject); rb_define_alloc_func(klass, Descriptor_alloc); rb_define_method(klass, "initialize", Descriptor_initialize, 3); rb_define_method(klass, "each", Descriptor_each, 0); @@ -420,8 +415,8 @@ static void Descriptor_register(VALUE module) { // ----------------------------------------------------------------------------- typedef struct { - const upb_filedef* filedef; - VALUE descriptor_pool; // Owns the upb_filedef. + const upb_FileDef* filedef; + VALUE descriptor_pool; // Owns the upb_FileDef. } FileDescriptor; static VALUE cFileDescriptor = Qnil; @@ -432,9 +427,9 @@ static void FileDescriptor_mark(void* _self) { } static const rb_data_type_t FileDescriptor_type = { - "Google::Protobuf::FileDescriptor", - {FileDescriptor_mark, RUBY_DEFAULT_FREE, NULL}, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Google::Protobuf::FileDescriptor", + {FileDescriptor_mark, RUBY_DEFAULT_FREE, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; static FileDescriptor* ruby_to_FileDescriptor(VALUE val) { @@ -459,7 +454,7 @@ static VALUE FileDescriptor_alloc(VALUE klass) { * to a builder. */ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie, - VALUE descriptor_pool, VALUE ptr) { + VALUE descriptor_pool, VALUE ptr) { FileDescriptor* self = ruby_to_FileDescriptor(_self); if (cookie != c_only_cookie) { @@ -468,7 +463,7 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie, } self->descriptor_pool = descriptor_pool; - self->filedef = (const upb_filedef*)NUM2ULL(ptr); + self->filedef = (const upb_FileDef*)NUM2ULL(ptr); return Qnil; } @@ -481,7 +476,7 @@ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie, */ static VALUE FileDescriptor_name(VALUE _self) { FileDescriptor* self = ruby_to_FileDescriptor(_self); - const char* name = upb_filedef_name(self->filedef); + const char* name = upb_FileDef_Name(self->filedef); return name == NULL ? Qnil : rb_str_new2(name); } @@ -497,16 +492,18 @@ static VALUE FileDescriptor_name(VALUE _self) { static VALUE FileDescriptor_syntax(VALUE _self) { FileDescriptor* self = ruby_to_FileDescriptor(_self); - switch (upb_filedef_syntax(self->filedef)) { - case UPB_SYNTAX_PROTO3: return ID2SYM(rb_intern("proto3")); - case UPB_SYNTAX_PROTO2: return ID2SYM(rb_intern("proto2")); - default: return Qnil; + switch (upb_FileDef_Syntax(self->filedef)) { + case kUpb_Syntax_Proto3: + return ID2SYM(rb_intern("proto3")); + case kUpb_Syntax_Proto2: + return ID2SYM(rb_intern("proto2")); + default: + return Qnil; } } static void FileDescriptor_register(VALUE module) { - VALUE klass = rb_define_class_under( - module, "FileDescriptor", rb_cObject); + VALUE klass = rb_define_class_under(module, "FileDescriptor", rb_cObject); rb_define_alloc_func(klass, FileDescriptor_alloc); rb_define_method(klass, "initialize", FileDescriptor_initialize, 3); rb_define_method(klass, "name", FileDescriptor_name, 0); @@ -520,8 +517,8 @@ static void FileDescriptor_register(VALUE module) { // ----------------------------------------------------------------------------- typedef struct { - const upb_fielddef* fielddef; - VALUE descriptor_pool; // Owns the upb_fielddef. + const upb_FieldDef* fielddef; + VALUE descriptor_pool; // Owns the upb_FieldDef. } FieldDescriptor; static VALUE cFieldDescriptor = Qnil; @@ -532,9 +529,9 @@ static void FieldDescriptor_mark(void* _self) { } static const rb_data_type_t FieldDescriptor_type = { - "Google::Protobuf::FieldDescriptor", - {FieldDescriptor_mark, RUBY_DEFAULT_FREE, NULL}, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Google::Protobuf::FieldDescriptor", + {FieldDescriptor_mark, RUBY_DEFAULT_FREE, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; static FieldDescriptor* ruby_to_FieldDescriptor(VALUE val) { @@ -573,7 +570,7 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie, } self->descriptor_pool = descriptor_pool; - self->fielddef = (const upb_fielddef*)NUM2ULL(ptr); + self->fielddef = (const upb_FieldDef*)NUM2ULL(ptr); return Qnil; } @@ -586,31 +583,31 @@ static VALUE FieldDescriptor_initialize(VALUE _self, VALUE cookie, */ static VALUE FieldDescriptor_name(VALUE _self) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - return rb_str_maybe_null(upb_fielddef_name(self->fielddef)); + return rb_str_maybe_null(upb_FieldDef_Name(self->fielddef)); } // Non-static, exposed to other .c files. -upb_fieldtype_t ruby_to_fieldtype(VALUE type) { +upb_CType ruby_to_fieldtype(VALUE type) { if (TYPE(type) != T_SYMBOL) { rb_raise(rb_eArgError, "Expected symbol for field type."); } -#define CONVERT(upb, ruby) \ - if (SYM2ID(type) == rb_intern( # ruby )) { \ - return UPB_TYPE_ ## upb; \ +#define CONVERT(upb, ruby) \ + if (SYM2ID(type) == rb_intern(#ruby)) { \ + return kUpb_CType_##upb; \ } - CONVERT(FLOAT, float); - CONVERT(DOUBLE, double); - CONVERT(BOOL, bool); - CONVERT(STRING, string); - CONVERT(BYTES, bytes); - CONVERT(MESSAGE, message); - CONVERT(ENUM, enum); - CONVERT(INT32, int32); - CONVERT(INT64, int64); - CONVERT(UINT32, uint32); - CONVERT(UINT64, uint64); + CONVERT(Float, float); + CONVERT(Double, double); + CONVERT(Bool, bool); + CONVERT(String, string); + CONVERT(Bytes, bytes); + CONVERT(Message, message); + CONVERT(Enum, enum); + CONVERT(Int32, int32); + CONVERT(Int64, int64); + CONVERT(UInt32, uint32); + CONVERT(UInt64, uint64); #undef CONVERT @@ -618,28 +615,29 @@ upb_fieldtype_t ruby_to_fieldtype(VALUE type) { return 0; } -static VALUE descriptortype_to_ruby(upb_descriptortype_t type) { +static VALUE descriptortype_to_ruby(upb_FieldType type) { switch (type) { -#define CONVERT(upb, ruby) \ - case UPB_DESCRIPTOR_TYPE_ ## upb : return ID2SYM(rb_intern( # ruby )); - CONVERT(FLOAT, float); - CONVERT(DOUBLE, double); - CONVERT(BOOL, bool); - CONVERT(STRING, string); - CONVERT(BYTES, bytes); - CONVERT(MESSAGE, message); - CONVERT(GROUP, group); - CONVERT(ENUM, enum); - CONVERT(INT32, int32); - CONVERT(INT64, int64); - CONVERT(UINT32, uint32); - CONVERT(UINT64, uint64); - CONVERT(SINT32, sint32); - CONVERT(SINT64, sint64); - CONVERT(FIXED32, fixed32); - CONVERT(FIXED64, fixed64); - CONVERT(SFIXED32, sfixed32); - CONVERT(SFIXED64, sfixed64); +#define CONVERT(upb, ruby) \ + case kUpb_FieldType_##upb: \ + return ID2SYM(rb_intern(#ruby)); + CONVERT(Float, float); + CONVERT(Double, double); + CONVERT(Bool, bool); + CONVERT(String, string); + CONVERT(Bytes, bytes); + CONVERT(Message, message); + CONVERT(Group, group); + CONVERT(Enum, enum); + CONVERT(Int32, int32); + CONVERT(Int64, int64); + CONVERT(UInt32, uint32); + CONVERT(UInt64, uint64); + CONVERT(SInt32, sint32); + CONVERT(SInt64, sint64); + CONVERT(Fixed32, fixed32); + CONVERT(Fixed64, fixed64); + CONVERT(SFixed32, sfixed32); + CONVERT(SFixed64, sfixed64); #undef CONVERT } return Qnil; @@ -657,7 +655,7 @@ static VALUE descriptortype_to_ruby(upb_descriptortype_t type) { */ static VALUE FieldDescriptor__type(VALUE _self) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - return descriptortype_to_ruby(upb_fielddef_descriptortype(self->fielddef)); + return descriptortype_to_ruby(upb_FieldDef_Type(self->fielddef)); } /* @@ -668,17 +666,16 @@ static VALUE FieldDescriptor__type(VALUE _self) { */ static VALUE FieldDescriptor_default(VALUE _self) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - const upb_fielddef *f = self->fielddef; - upb_msgval default_val = {0}; - if (upb_fielddef_issubmsg(f)) { + const upb_FieldDef* f = self->fielddef; + upb_MessageValue default_val = {0}; + if (upb_FieldDef_IsSubMessage(f)) { return Qnil; - } else if (!upb_fielddef_isseq(f)) { - default_val = upb_fielddef_default(f); + } else if (!upb_FieldDef_IsRepeated(f)) { + default_val = upb_FieldDef_Default(f); } return Convert_UpbToRuby(default_val, TypeInfo_get(self->fielddef), Qnil); } - /* * call-seq: * FieldDescriptor.json_name => json_name @@ -687,8 +684,8 @@ static VALUE FieldDescriptor_default(VALUE _self) { */ static VALUE FieldDescriptor_json_name(VALUE _self) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - const upb_fielddef *f = self->fielddef; - const char *json_name = upb_fielddef_jsonname(f); + const upb_FieldDef* f = self->fielddef; + const char* json_name = upb_FieldDef_JsonName(f); return rb_str_new2(json_name); } @@ -703,13 +700,14 @@ static VALUE FieldDescriptor_json_name(VALUE _self) { */ static VALUE FieldDescriptor_label(VALUE _self) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - switch (upb_fielddef_label(self->fielddef)) { -#define CONVERT(upb, ruby) \ - case UPB_LABEL_ ## upb : return ID2SYM(rb_intern( # ruby )); + switch (upb_FieldDef_Label(self->fielddef)) { +#define CONVERT(upb, ruby) \ + case kUpb_Label_##upb: \ + return ID2SYM(rb_intern(#ruby)); - CONVERT(OPTIONAL, optional); - CONVERT(REQUIRED, required); - CONVERT(REPEATED, repeated); + CONVERT(Optional, optional); + CONVERT(Required, required); + CONVERT(Repeated, repeated); #undef CONVERT } @@ -725,7 +723,7 @@ static VALUE FieldDescriptor_label(VALUE _self) { */ static VALUE FieldDescriptor_number(VALUE _self) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - return INT2NUM(upb_fielddef_number(self->fielddef)); + return INT2NUM(upb_FieldDef_Number(self->fielddef)); } /* @@ -739,13 +737,13 @@ static VALUE FieldDescriptor_number(VALUE _self) { */ static VALUE FieldDescriptor_submsg_name(VALUE _self) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - switch (upb_fielddef_type(self->fielddef)) { - case UPB_TYPE_ENUM: + switch (upb_FieldDef_CType(self->fielddef)) { + case kUpb_CType_Enum: return rb_str_new2( - upb_enumdef_fullname(upb_fielddef_enumsubdef(self->fielddef))); - case UPB_TYPE_MESSAGE: + upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(self->fielddef))); + case kUpb_CType_Message: return rb_str_new2( - upb_msgdef_fullname(upb_fielddef_msgsubdef(self->fielddef))); + upb_MessageDef_FullName(upb_FieldDef_MessageSubDef(self->fielddef))); default: return Qnil; } @@ -762,13 +760,13 @@ static VALUE FieldDescriptor_submsg_name(VALUE _self) { */ static VALUE FieldDescriptor_subtype(VALUE _self) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - switch (upb_fielddef_type(self->fielddef)) { - case UPB_TYPE_ENUM: + switch (upb_FieldDef_CType(self->fielddef)) { + case kUpb_CType_Enum: return get_enumdef_obj(self->descriptor_pool, - upb_fielddef_enumsubdef(self->fielddef)); - case UPB_TYPE_MESSAGE: + upb_FieldDef_EnumSubDef(self->fielddef)); + case kUpb_CType_Message: return get_msgdef_obj(self->descriptor_pool, - upb_fielddef_msgsubdef(self->fielddef)); + upb_FieldDef_MessageSubDef(self->fielddef)); default: return Qnil; } @@ -783,11 +781,11 @@ static VALUE FieldDescriptor_subtype(VALUE _self) { */ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - const upb_msgdef *m; + const upb_MessageDef* m; Message_Get(msg_rb, &m); - if (m != upb_fielddef_containingtype(self->fielddef)) { + if (m != upb_FieldDef_ContainingType(self->fielddef)) { rb_raise(cTypeError, "get method called on wrong message type"); } @@ -803,16 +801,16 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) { */ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - const upb_msgdef *m; - const upb_msgdef *msg = Message_Get(msg_rb, &m); + const upb_MessageDef* m; + const upb_MessageDef* msg = Message_Get(msg_rb, &m); - if (m != upb_fielddef_containingtype(self->fielddef)) { + if (m != upb_FieldDef_ContainingType(self->fielddef)) { rb_raise(cTypeError, "has method called on wrong message type"); - } else if (!upb_fielddef_haspresence(self->fielddef)) { + } else if (!upb_FieldDef_HasPresence(self->fielddef)) { rb_raise(rb_eArgError, "does not track presence"); } - return upb_msg_has(msg, self->fielddef) ? Qtrue : Qfalse; + return upb_Message_Has(msg, self->fielddef) ? Qtrue : Qfalse; } /* @@ -823,14 +821,14 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) { */ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - const upb_msgdef *m; - upb_msgdef *msg = Message_GetMutable(msg_rb, &m); + const upb_MessageDef* m; + upb_MessageDef* msg = Message_GetMutable(msg_rb, &m); - if (m != upb_fielddef_containingtype(self->fielddef)) { + if (m != upb_FieldDef_ContainingType(self->fielddef)) { rb_raise(cTypeError, "has method called on wrong message type"); } - upb_msg_clearfield(msg, self->fielddef); + upb_Message_ClearField(msg, self->fielddef); return Qnil; } @@ -844,24 +842,23 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) { */ static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); - const upb_msgdef *m; - upb_msgdef *msg = Message_GetMutable(msg_rb, &m); - upb_arena *arena = Arena_get(Message_GetArena(msg_rb)); - upb_msgval msgval; + const upb_MessageDef* m; + upb_MessageDef* msg = Message_GetMutable(msg_rb, &m); + upb_Arena* arena = Arena_get(Message_GetArena(msg_rb)); + upb_MessageValue msgval; - if (m != upb_fielddef_containingtype(self->fielddef)) { + if (m != upb_FieldDef_ContainingType(self->fielddef)) { rb_raise(cTypeError, "set method called on wrong message type"); } - msgval = Convert_RubyToUpb(value, upb_fielddef_name(self->fielddef), + msgval = Convert_RubyToUpb(value, upb_FieldDef_Name(self->fielddef), TypeInfo_get(self->fielddef), arena); - upb_msg_set(msg, self->fielddef, msgval, arena); + upb_Message_Set(msg, self->fielddef, msgval, arena); return Qnil; } static void FieldDescriptor_register(VALUE module) { - VALUE klass = rb_define_class_under( - module, "FieldDescriptor", rb_cObject); + VALUE klass = rb_define_class_under(module, "FieldDescriptor", rb_cObject); rb_define_alloc_func(klass, FieldDescriptor_alloc); rb_define_method(klass, "initialize", FieldDescriptor_initialize, 3); rb_define_method(klass, "name", FieldDescriptor_name, 0); @@ -885,8 +882,8 @@ static void FieldDescriptor_register(VALUE module) { // ----------------------------------------------------------------------------- typedef struct { - const upb_oneofdef* oneofdef; - VALUE descriptor_pool; // Owns the upb_oneofdef. + const upb_OneofDef* oneofdef; + VALUE descriptor_pool; // Owns the upb_OneofDef. } OneofDescriptor; static VALUE cOneofDescriptor = Qnil; @@ -930,7 +927,7 @@ static VALUE OneofDescriptor_alloc(VALUE klass) { * Creates a descriptor wrapper object. May only be called from C. */ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie, - VALUE descriptor_pool, VALUE ptr) { + VALUE descriptor_pool, VALUE ptr) { OneofDescriptor* self = ruby_to_OneofDescriptor(_self); if (cookie != c_only_cookie) { @@ -939,7 +936,7 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie, } self->descriptor_pool = descriptor_pool; - self->oneofdef = (const upb_oneofdef*)NUM2ULL(ptr); + self->oneofdef = (const upb_OneofDef*)NUM2ULL(ptr); return Qnil; } @@ -952,7 +949,7 @@ static VALUE OneofDescriptor_initialize(VALUE _self, VALUE cookie, */ static VALUE OneofDescriptor_name(VALUE _self) { OneofDescriptor* self = ruby_to_OneofDescriptor(_self); - return rb_str_maybe_null(upb_oneofdef_name(self->oneofdef)); + return rb_str_maybe_null(upb_OneofDef_Name(self->oneofdef)); } /* @@ -963,11 +960,10 @@ static VALUE OneofDescriptor_name(VALUE _self) { */ static VALUE OneofDescriptor_each(VALUE _self) { OneofDescriptor* self = ruby_to_OneofDescriptor(_self); - upb_oneof_iter it; - for (upb_oneof_begin(&it, self->oneofdef); - !upb_oneof_done(&it); - upb_oneof_next(&it)) { - const upb_fielddef* f = upb_oneof_iter_field(&it); + + int n = upb_OneofDef_FieldCount(self->oneofdef); + for (int i = 0; i < n; i++) { + const upb_FieldDef* f = upb_OneofDef_Field(self->oneofdef, i); VALUE obj = get_fielddef_obj(self->descriptor_pool, f); rb_yield(obj); } @@ -975,8 +971,7 @@ static VALUE OneofDescriptor_each(VALUE _self) { } static void OneofDescriptor_register(VALUE module) { - VALUE klass = rb_define_class_under( - module, "OneofDescriptor", rb_cObject); + VALUE klass = rb_define_class_under(module, "OneofDescriptor", rb_cObject); rb_define_alloc_func(klass, OneofDescriptor_alloc); rb_define_method(klass, "initialize", OneofDescriptor_initialize, 3); rb_define_method(klass, "name", OneofDescriptor_name, 0); @@ -991,9 +986,9 @@ static void OneofDescriptor_register(VALUE module) { // ----------------------------------------------------------------------------- typedef struct { - const upb_enumdef* enumdef; - VALUE module; // begins as nil - VALUE descriptor_pool; // Owns the upb_enumdef. + const upb_EnumDef* enumdef; + VALUE module; // begins as nil + VALUE descriptor_pool; // Owns the upb_EnumDef. } EnumDescriptor; static VALUE cEnumDescriptor = Qnil; @@ -1005,9 +1000,9 @@ static void EnumDescriptor_mark(void* _self) { } static const rb_data_type_t EnumDescriptor_type = { - "Google::Protobuf::EnumDescriptor", - {EnumDescriptor_mark, RUBY_DEFAULT_FREE, NULL}, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Google::Protobuf::EnumDescriptor", + {EnumDescriptor_mark, RUBY_DEFAULT_FREE, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; static EnumDescriptor* ruby_to_EnumDescriptor(VALUE val) { @@ -1026,8 +1021,8 @@ static VALUE EnumDescriptor_alloc(VALUE klass) { } // Exposed to other modules in defs.h. -const upb_enumdef *EnumDescriptor_GetEnumDef(VALUE enum_desc_rb) { - EnumDescriptor *desc = ruby_to_EnumDescriptor(enum_desc_rb); +const upb_EnumDef* EnumDescriptor_GetEnumDef(VALUE enum_desc_rb) { + EnumDescriptor* desc = ruby_to_EnumDescriptor(enum_desc_rb); return desc->enumdef; } @@ -1047,7 +1042,7 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie, } self->descriptor_pool = descriptor_pool; - self->enumdef = (const upb_enumdef*)NUM2ULL(ptr); + self->enumdef = (const upb_EnumDef*)NUM2ULL(ptr); return Qnil; } @@ -1061,7 +1056,7 @@ static VALUE EnumDescriptor_initialize(VALUE _self, VALUE cookie, static VALUE EnumDescriptor_file_descriptor(VALUE _self) { EnumDescriptor* self = ruby_to_EnumDescriptor(_self); return get_filedef_obj(self->descriptor_pool, - upb_enumdef_file(self->enumdef)); + upb_EnumDef_File(self->enumdef)); } /* @@ -1072,7 +1067,7 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) { */ static VALUE EnumDescriptor_name(VALUE _self) { EnumDescriptor* self = ruby_to_EnumDescriptor(_self); - return rb_str_maybe_null(upb_enumdef_fullname(self->enumdef)); + return rb_str_maybe_null(upb_EnumDef_FullName(self->enumdef)); } /* @@ -1084,10 +1079,11 @@ static VALUE EnumDescriptor_name(VALUE _self) { */ static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) { EnumDescriptor* self = ruby_to_EnumDescriptor(_self); - const char* name_str= rb_id2name(SYM2ID(name)); - int32_t val = 0; - if (upb_enumdef_ntoiz(self->enumdef, name_str, &val)) { - return INT2NUM(val); + const char* name_str = rb_id2name(SYM2ID(name)); + const upb_EnumValueDef *ev = + upb_EnumDef_FindValueByName(self->enumdef, name_str); + if (ev) { + return INT2NUM(upb_EnumValueDef_Number(ev)); } else { return Qnil; } @@ -1103,9 +1099,9 @@ static VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) { static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) { EnumDescriptor* self = ruby_to_EnumDescriptor(_self); int32_t val = NUM2INT(number); - const char* name = upb_enumdef_iton(self->enumdef, val); - if (name != NULL) { - return ID2SYM(rb_intern(name)); + const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(self->enumdef, val); + if (ev) { + return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev))); } else { return Qnil; } @@ -1121,12 +1117,11 @@ static VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) { static VALUE EnumDescriptor_each(VALUE _self) { EnumDescriptor* self = ruby_to_EnumDescriptor(_self); - upb_enum_iter it; - for (upb_enum_begin(&it, self->enumdef); - !upb_enum_done(&it); - upb_enum_next(&it)) { - VALUE key = ID2SYM(rb_intern(upb_enum_iter_name(&it))); - VALUE number = INT2NUM(upb_enum_iter_number(&it)); + int n = upb_EnumDef_ValueCount(self->enumdef); + for (int i = 0; i < n; i++) { + const upb_EnumValueDef* ev = upb_EnumDef_Value(self->enumdef, i); + VALUE key = ID2SYM(rb_intern(upb_EnumValueDef_Name(ev))); + VALUE number = INT2NUM(upb_EnumValueDef_Number(ev)); rb_yield_values(2, key, number); } @@ -1148,8 +1143,7 @@ static VALUE EnumDescriptor_enummodule(VALUE _self) { } static void EnumDescriptor_register(VALUE module) { - VALUE klass = rb_define_class_under( - module, "EnumDescriptor", rb_cObject); + VALUE klass = rb_define_class_under(module, "EnumDescriptor", rb_cObject); rb_define_alloc_func(klass, EnumDescriptor_alloc); rb_define_method(klass, "initialize", EnumDescriptor_initialize, 3); rb_define_method(klass, "name", EnumDescriptor_name, 0); @@ -1176,7 +1170,7 @@ static VALUE get_def_obj(VALUE _descriptor_pool, const void* ptr, VALUE klass) { if (def == Qnil) { // Lazily create wrapper object. - VALUE args[3] = { c_only_cookie, _descriptor_pool, key }; + VALUE args[3] = {c_only_cookie, _descriptor_pool, key}; def = rb_class_new_instance(3, args, klass); rb_hash_aset(descriptor_pool->def_to_descriptor, key, def); } @@ -1184,23 +1178,23 @@ static VALUE get_def_obj(VALUE _descriptor_pool, const void* ptr, VALUE klass) { return def; } -static VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_msgdef* def) { +static VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_MessageDef* def) { return get_def_obj(descriptor_pool, def, cDescriptor); } -static VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_enumdef* def) { +static VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_EnumDef* def) { return get_def_obj(descriptor_pool, def, cEnumDescriptor); } -static VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_fielddef* def) { +static VALUE get_fielddef_obj(VALUE descriptor_pool, const upb_FieldDef* def) { return get_def_obj(descriptor_pool, def, cFieldDescriptor); } -static VALUE get_filedef_obj(VALUE descriptor_pool, const upb_filedef* def) { +static VALUE get_filedef_obj(VALUE descriptor_pool, const upb_FileDef* def) { return get_def_obj(descriptor_pool, def, cFileDescriptor); } -static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_oneofdef* def) { +static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_OneofDef* def) { return get_def_obj(descriptor_pool, def, cOneofDescriptor); } @@ -1210,8 +1204,8 @@ static VALUE get_oneofdef_obj(VALUE descriptor_pool, const upb_oneofdef* def) { // Functions exposed to other modules in defs.h. -VALUE Descriptor_DefToClass(const upb_msgdef *m) { - const upb_symtab *symtab = upb_filedef_symtab(upb_msgdef_file(m)); +VALUE Descriptor_DefToClass(const upb_MessageDef* m) { + const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m)); VALUE pool = ObjectCache_Get(symtab); PBRUBY_ASSERT(pool != Qnil); VALUE desc_rb = get_msgdef_obj(pool, m); @@ -1219,15 +1213,16 @@ VALUE Descriptor_DefToClass(const upb_msgdef *m) { return desc->klass; } -const upb_msgdef *Descriptor_GetMsgDef(VALUE desc_rb) { +const upb_MessageDef* Descriptor_GetMsgDef(VALUE desc_rb) { const Descriptor* desc = ruby_to_Descriptor(desc_rb); return desc->msgdef; } -VALUE TypeInfo_InitArg(int argc, VALUE *argv, int skip_arg) { +VALUE TypeInfo_InitArg(int argc, VALUE* argv, int skip_arg) { if (argc > skip_arg) { if (argc > 1 + skip_arg) { - rb_raise(rb_eArgError, "Expected a maximum of %d arguments.", skip_arg + 1); + rb_raise(rb_eArgError, "Expected a maximum of %d arguments.", + skip_arg + 1); } return argv[skip_arg]; } else { @@ -1239,7 +1234,7 @@ TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg, VALUE* type_class, VALUE* init_arg) { TypeInfo ret = {ruby_to_fieldtype(argv[skip_arg])}; - if (ret.type == UPB_TYPE_MESSAGE || ret.type == UPB_TYPE_ENUM) { + if (ret.type == kUpb_CType_Message || ret.type == kUpb_CType_Enum) { *init_arg = TypeInfo_InitArg(argc, argv, skip_arg + 2); if (argc < 2 + skip_arg) { @@ -1257,11 +1252,11 @@ TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg, "class or enum as returned by the DescriptorPool."); } - if (ret.type == UPB_TYPE_MESSAGE) { + if (ret.type == kUpb_CType_Message) { ret.def.msgdef = ruby_to_Descriptor(desc)->msgdef; Message_CheckClass(klass); } else { - PBRUBY_ASSERT(ret.type == UPB_TYPE_ENUM); + PBRUBY_ASSERT(ret.type == kUpb_CType_Enum); ret.def.enumdef = ruby_to_EnumDescriptor(desc)->enumdef; } } else { diff --git a/ruby/ext/google/protobuf_c/defs.h b/ruby/ext/google/protobuf_c/defs.h index 97a94bb7b5..f559cb0b9d 100644 --- a/ruby/ext/google/protobuf_c/defs.h +++ b/ruby/ext/google/protobuf_c/defs.h @@ -40,9 +40,9 @@ // TypeInfo // ----------------------------------------------------------------------------- -// This bundles a upb_fieldtype_t and msgdef/enumdef when appropriate. This is +// This bundles a upb_CType and msgdef/enumdef when appropriate. This is // convenient for functions that need type information but cannot necessarily -// assume a upb_fielddef will be available. +// assume a upb_FieldDef will be available. // // For example, Google::Protobuf::Map and Google::Protobuf::RepeatedField can // be constructed with type information alone: @@ -51,21 +51,21 @@ // Google::Protobuf::RepeatedField.new(:message, FooMessage) typedef struct { - upb_fieldtype_t type; + upb_CType type; union { - const upb_msgdef* msgdef; // When type == UPB_TYPE_MESSAGE - const upb_enumdef* enumdef; // When type == UPB_TYPE_ENUM + const upb_MessageDef* msgdef; // When type == kUpb_CType_Message + const upb_EnumDef* enumdef; // When type == kUpb_CType_Enum } def; } TypeInfo; -static inline TypeInfo TypeInfo_get(const upb_fielddef *f) { - TypeInfo ret = {upb_fielddef_type(f), {NULL}}; +static inline TypeInfo TypeInfo_get(const upb_FieldDef* f) { + TypeInfo ret = {upb_FieldDef_CType(f), {NULL}}; switch (ret.type) { - case UPB_TYPE_MESSAGE: - ret.def.msgdef = upb_fielddef_msgsubdef(f); + case kUpb_CType_Message: + ret.def.msgdef = upb_FieldDef_MessageSubDef(f); break; - case UPB_TYPE_ENUM: - ret.def.enumdef = upb_fielddef_enumsubdef(f); + case kUpb_CType_Enum: + ret.def.enumdef = upb_FieldDef_EnumSubDef(f); break; default: break; @@ -76,9 +76,9 @@ static inline TypeInfo TypeInfo_get(const upb_fielddef *f) { TypeInfo TypeInfo_FromClass(int argc, VALUE* argv, int skip_arg, VALUE* type_class, VALUE* init_arg); -static inline TypeInfo TypeInfo_from_type(upb_fieldtype_t type) { +static inline TypeInfo TypeInfo_from_type(upb_CType type) { TypeInfo ret = {type}; - assert(type != UPB_TYPE_MESSAGE && type != UPB_TYPE_ENUM); + assert(type != kUpb_CType_Message && type != kUpb_CType_Enum); return ret; } @@ -86,17 +86,17 @@ static inline TypeInfo TypeInfo_from_type(upb_fieldtype_t type) { // Other utilities // ----------------------------------------------------------------------------- -VALUE Descriptor_DefToClass(const upb_msgdef *m); +VALUE Descriptor_DefToClass(const upb_MessageDef* m); // Returns the underlying msgdef, enumdef, or symtab (respectively) for the // given Descriptor, EnumDescriptor, or DescriptorPool Ruby object. -const upb_enumdef *EnumDescriptor_GetEnumDef(VALUE enum_desc_rb); -const upb_symtab *DescriptorPool_GetSymtab(VALUE desc_pool_rb); -const upb_msgdef *Descriptor_GetMsgDef(VALUE desc_rb); +const upb_EnumDef* EnumDescriptor_GetEnumDef(VALUE enum_desc_rb); +const upb_DefPool* DescriptorPool_GetSymtab(VALUE desc_pool_rb); +const upb_MessageDef* Descriptor_GetMsgDef(VALUE desc_rb); // Returns a upb field type for the given Ruby symbol -// (eg. :float => UPB_TYPE_FLOAT). -upb_fieldtype_t ruby_to_fieldtype(VALUE type); +// (eg. :float => kUpb_CType_Float). +upb_CType ruby_to_fieldtype(VALUE type); // The singleton generated pool (a DescriptorPool object). extern VALUE generated_pool; diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index 2f6de4d8ba..5d30319c19 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -34,7 +34,7 @@ #include "protobuf.h" // ----------------------------------------------------------------------------- -// Basic map operations on top of upb_map. +// Basic map operations on top of upb_Map. // // Note that we roll our own `Map` container here because, as for // `RepeatedField`, we want a strongly-typed container. This is so that any user @@ -48,8 +48,8 @@ // ----------------------------------------------------------------------------- typedef struct { - const upb_map *map; // Can convert to mutable when non-frozen. - upb_fieldtype_t key_type; + const upb_Map* map; // Can convert to mutable when non-frozen. + upb_CType key_type; TypeInfo value_type_info; VALUE value_type_class; VALUE arena; @@ -62,9 +62,9 @@ static void Map_mark(void* _self) { } const rb_data_type_t Map_type = { - "Google::Protobuf::Map", - { Map_mark, RUBY_DEFAULT_FREE, NULL }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Google::Protobuf::Map", + {Map_mark, RUBY_DEFAULT_FREE, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; VALUE cMap; @@ -84,8 +84,8 @@ static VALUE Map_alloc(VALUE klass) { return TypedData_Wrap_Struct(klass, &Map_type, self); } -VALUE Map_GetRubyWrapper(upb_map* map, upb_fieldtype_t key_type, - TypeInfo value_type, VALUE arena) { +VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type, + VALUE arena) { PBRUBY_ASSERT(map); VALUE val = ObjectCache_Get(map); @@ -99,8 +99,8 @@ VALUE Map_GetRubyWrapper(upb_map* map, upb_fieldtype_t key_type, self->arena = arena; self->key_type = key_type; self->value_type_info = value_type; - if (self->value_type_info.type == UPB_TYPE_MESSAGE) { - const upb_msgdef *val_m = self->value_type_info.def.msgdef; + if (self->value_type_info.type == kUpb_CType_Message) { + const upb_MessageDef* val_m = self->value_type_info.def.msgdef; self->value_type_class = Descriptor_DefToClass(val_m); } } @@ -108,9 +108,9 @@ VALUE Map_GetRubyWrapper(upb_map* map, upb_fieldtype_t key_type, return val; } -static VALUE Map_new_this_type(Map *from) { +static VALUE Map_new_this_type(Map* from) { VALUE arena_rb = Arena_new(); - upb_map* map = upb_map_new(Arena_get(arena_rb), from->key_type, + upb_Map* map = upb_Map_New(Arena_get(arena_rb), from->key_type, from->value_type_info.type); VALUE ret = Map_GetRubyWrapper(map, from->key_type, from->value_type_info, arena_rb); @@ -125,22 +125,22 @@ static TypeInfo Map_keyinfo(Map* self) { return ret; } -static upb_map *Map_GetMutable(VALUE _self) { +static upb_Map* Map_GetMutable(VALUE _self) { rb_check_frozen(_self); - return (upb_map*)ruby_to_Map(_self)->map; + return (upb_Map*)ruby_to_Map(_self)->map; } -VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type, +VALUE Map_CreateHash(const upb_Map* map, upb_CType key_type, TypeInfo val_info) { VALUE hash = rb_hash_new(); - size_t iter = UPB_MAP_BEGIN; + size_t iter = kUpb_Map_Begin; TypeInfo key_info = TypeInfo_from_type(key_type); if (!map) return hash; - while (upb_mapiter_next(map, &iter)) { - upb_msgval key = upb_mapiter_key(map, iter); - upb_msgval val = upb_mapiter_value(map, iter); + while (upb_MapIterator_Next(map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(map, iter); + upb_MessageValue val = upb_MapIterator_Value(map, iter); VALUE key_val = Convert_UpbToRuby(key, key_info, Qnil); VALUE val_val = Scalar_CreateHash(val, val_info); rb_hash_aset(hash, key_val, val_val); @@ -152,25 +152,26 @@ VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type, VALUE Map_deep_copy(VALUE obj) { Map* self = ruby_to_Map(obj); VALUE new_arena_rb = Arena_new(); - upb_arena *arena = Arena_get(new_arena_rb); - upb_map* new_map = - upb_map_new(arena, self->key_type, self->value_type_info.type); - size_t iter = UPB_MAP_BEGIN; - while (upb_mapiter_next(self->map, &iter)) { - upb_msgval key = upb_mapiter_key(self->map, iter); - upb_msgval val = upb_mapiter_value(self->map, iter); - upb_msgval val_copy = Msgval_DeepCopy(val, self->value_type_info, arena); - upb_map_set(new_map, key, val_copy, arena); + upb_Arena* arena = Arena_get(new_arena_rb); + upb_Map* new_map = + upb_Map_New(arena, self->key_type, self->value_type_info.type); + size_t iter = kUpb_Map_Begin; + while (upb_MapIterator_Next(self->map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(self->map, iter); + upb_MessageValue val = upb_MapIterator_Value(self->map, iter); + upb_MessageValue val_copy = + Msgval_DeepCopy(val, self->value_type_info, arena); + upb_Map_Set(new_map, key, val_copy, arena); } return Map_GetRubyWrapper(new_map, self->key_type, self->value_type_info, new_arena_rb); } -const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef* field, - upb_arena* arena) { - const upb_fielddef* key_field = map_field_key(field); - const upb_fielddef* value_field = map_field_value(field); +const upb_Map* Map_GetUpbMap(VALUE val, const upb_FieldDef* field, + upb_Arena* arena) { + const upb_FieldDef* key_field = map_field_key(field); + const upb_FieldDef* value_field = map_field_value(field); TypeInfo value_type_info = TypeInfo_get(value_field); Map* self; @@ -180,7 +181,7 @@ const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef* field, } self = ruby_to_Map(val); - if (self->key_type != upb_fielddef_type(key_field)) { + if (self->key_type != upb_FieldDef_CType(key_field)) { rb_raise(cTypeError, "Map key type does not match field's key type"); } if (self->value_type_info.type != value_type_info.type) { @@ -194,16 +195,16 @@ const upb_map* Map_GetUpbMap(VALUE val, const upb_fielddef* field, return self->map; } -void Map_Inspect(StringBuilder* b, const upb_map* map, upb_fieldtype_t key_type, +void Map_Inspect(StringBuilder* b, const upb_Map* map, upb_CType key_type, TypeInfo val_type) { bool first = true; TypeInfo key_type_info = {key_type}; StringBuilder_Printf(b, "{"); if (map) { - size_t iter = UPB_MAP_BEGIN; - while (upb_mapiter_next(map, &iter)) { - upb_msgval key = upb_mapiter_key(map, iter); - upb_msgval val = upb_mapiter_value(map, iter); + size_t iter = kUpb_Map_Begin; + while (upb_MapIterator_Next(map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(map, iter); + upb_MessageValue val = upb_MapIterator_Value(map, iter); if (first) { first = false; } else { @@ -219,10 +220,12 @@ void Map_Inspect(StringBuilder* b, const upb_map* map, upb_fieldtype_t key_type, static int merge_into_self_callback(VALUE key, VALUE val, VALUE _self) { Map* self = ruby_to_Map(_self); - upb_arena *arena = Arena_get(self->arena); - upb_msgval key_val = Convert_RubyToUpb(key, "", Map_keyinfo(self), arena); - upb_msgval val_val = Convert_RubyToUpb(val, "", self->value_type_info, arena); - upb_map_set(Map_GetMutable(_self), key_val, val_val, arena); + upb_Arena* arena = Arena_get(self->arena); + upb_MessageValue key_val = + Convert_RubyToUpb(key, "", Map_keyinfo(self), arena); + upb_MessageValue val_val = + Convert_RubyToUpb(val, "", self->value_type_info, arena); + upb_Map_Set(Map_GetMutable(_self), key_val, val_val, arena); return ST_CONTINUE; } @@ -234,9 +237,9 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) { RTYPEDDATA_TYPE(hashmap) == &Map_type) { Map* self = ruby_to_Map(_self); Map* other = ruby_to_Map(hashmap); - upb_arena *arena = Arena_get(self->arena); - upb_msg *self_msg = Map_GetMutable(_self); - size_t iter = UPB_MAP_BEGIN; + upb_Arena* arena = Arena_get(self->arena); + upb_Message* self_msg = Map_GetMutable(_self); + size_t iter = kUpb_Map_Begin; Arena_fuse(other->arena, arena); @@ -246,10 +249,10 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) { rb_raise(rb_eArgError, "Attempt to merge Map with mismatching types"); } - while (upb_mapiter_next(other->map, &iter)) { - upb_msgval key = upb_mapiter_key(other->map, iter); - upb_msgval val = upb_mapiter_value(other->map, iter); - upb_map_set(self_msg, key, val, arena); + while (upb_MapIterator_Next(other->map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(other->map, iter); + upb_MessageValue val = upb_MapIterator_Value(other->map, iter); + upb_Map_Set(self_msg, key, val, arena); } } else { rb_raise(rb_eArgError, "Unknown type merging into Map"); @@ -305,20 +308,20 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) { // Check that the key type is an allowed type. switch (self->key_type) { - case UPB_TYPE_INT32: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT32: - case UPB_TYPE_UINT64: - case UPB_TYPE_BOOL: - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: + case kUpb_CType_Int32: + case kUpb_CType_Int64: + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: + case kUpb_CType_Bool: + case kUpb_CType_String: + case kUpb_CType_Bytes: // These are OK. break; default: rb_raise(rb_eArgError, "Invalid key type for map."); } - self->map = upb_map_new(Arena_get(self->arena), self->key_type, + self->map = upb_Map_New(Arena_get(self->arena), self->key_type, self->value_type_info.type); ObjectCache_Add(self->map, _self); @@ -339,11 +342,11 @@ static VALUE Map_init(int argc, VALUE* argv, VALUE _self) { */ static VALUE Map_each(VALUE _self) { Map* self = ruby_to_Map(_self); - size_t iter = UPB_MAP_BEGIN; + size_t iter = kUpb_Map_Begin; - while (upb_mapiter_next(self->map, &iter)) { - upb_msgval key = upb_mapiter_key(self->map, iter); - upb_msgval val = upb_mapiter_value(self->map, iter); + while (upb_MapIterator_Next(self->map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(self->map, iter); + upb_MessageValue val = upb_MapIterator_Value(self->map, iter); VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena); VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena); rb_yield_values(2, key_val, val_val); @@ -360,11 +363,11 @@ static VALUE Map_each(VALUE _self) { */ static VALUE Map_keys(VALUE _self) { Map* self = ruby_to_Map(_self); - size_t iter = UPB_MAP_BEGIN; + size_t iter = kUpb_Map_Begin; VALUE ret = rb_ary_new(); - while (upb_mapiter_next(self->map, &iter)) { - upb_msgval key = upb_mapiter_key(self->map, iter); + while (upb_MapIterator_Next(self->map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(self->map, iter); VALUE key_val = Convert_UpbToRuby(key, Map_keyinfo(self), self->arena); rb_ary_push(ret, key_val); } @@ -380,11 +383,11 @@ static VALUE Map_keys(VALUE _self) { */ static VALUE Map_values(VALUE _self) { Map* self = ruby_to_Map(_self); - size_t iter = UPB_MAP_BEGIN; + size_t iter = kUpb_Map_Begin; VALUE ret = rb_ary_new(); - while (upb_mapiter_next(self->map, &iter)) { - upb_msgval val = upb_mapiter_value(self->map, iter); + while (upb_MapIterator_Next(self->map, &iter)) { + upb_MessageValue val = upb_MapIterator_Value(self->map, iter); VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena); rb_ary_push(ret, val_val); } @@ -401,10 +404,11 @@ static VALUE Map_values(VALUE _self) { */ static VALUE Map_index(VALUE _self, VALUE key) { Map* self = ruby_to_Map(_self); - upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); - upb_msgval val; + upb_MessageValue key_upb = + Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); + upb_MessageValue val; - if (upb_map_get(self->map, key_upb, &val)) { + if (upb_Map_Get(self->map, key_upb, &val)) { return Convert_UpbToRuby(val, self->value_type_info, self->arena); } else { return Qnil; @@ -421,11 +425,13 @@ static VALUE Map_index(VALUE _self, VALUE key) { */ static VALUE Map_index_set(VALUE _self, VALUE key, VALUE val) { Map* self = ruby_to_Map(_self); - upb_arena *arena = Arena_get(self->arena); - upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); - upb_msgval val_upb = Convert_RubyToUpb(val, "", self->value_type_info, arena); + upb_Arena* arena = Arena_get(self->arena); + upb_MessageValue key_upb = + Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); + upb_MessageValue val_upb = + Convert_RubyToUpb(val, "", self->value_type_info, arena); - upb_map_set(Map_GetMutable(_self), key_upb, val_upb, arena); + upb_Map_Set(Map_GetMutable(_self), key_upb, val_upb, arena); return val; } @@ -439,9 +445,10 @@ static VALUE Map_index_set(VALUE _self, VALUE key, VALUE val) { */ static VALUE Map_has_key(VALUE _self, VALUE key) { Map* self = ruby_to_Map(_self); - upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); + upb_MessageValue key_upb = + Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); - if (upb_map_get(self->map, key_upb, NULL)) { + if (upb_Map_Get(self->map, key_upb, NULL)) { return Qtrue; } else { return Qfalse; @@ -457,21 +464,22 @@ static VALUE Map_has_key(VALUE _self, VALUE key) { */ static VALUE Map_delete(VALUE _self, VALUE key) { Map* self = ruby_to_Map(_self); - upb_msgval key_upb = Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); - upb_msgval val_upb; + upb_MessageValue key_upb = + Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); + upb_MessageValue val_upb; VALUE ret; rb_check_frozen(_self); - // TODO(haberman): make upb_map_delete() also capable of returning the deleted + // TODO(haberman): make upb_Map_Delete() also capable of returning the deleted // value. - if (upb_map_get(self->map, key_upb, &val_upb)) { + if (upb_Map_Get(self->map, key_upb, &val_upb)) { ret = Convert_UpbToRuby(val_upb, self->value_type_info, self->arena); } else { ret = Qnil; } - upb_map_delete(Map_GetMutable(_self), key_upb); + upb_Map_Delete(Map_GetMutable(_self), key_upb); return ret; } @@ -483,7 +491,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) { * Removes all entries from the map. */ static VALUE Map_clear(VALUE _self) { - upb_map_clear(Map_GetMutable(_self)); + upb_Map_Clear(Map_GetMutable(_self)); return Qnil; } @@ -495,7 +503,7 @@ static VALUE Map_clear(VALUE _self) { */ static VALUE Map_length(VALUE _self) { Map* self = ruby_to_Map(_self); - return ULL2NUM(upb_map_size(self->map)); + return ULL2NUM(upb_Map_Size(self->map)); } /* @@ -509,16 +517,16 @@ static VALUE Map_dup(VALUE _self) { Map* self = ruby_to_Map(_self); VALUE new_map_rb = Map_new_this_type(self); Map* new_self = ruby_to_Map(new_map_rb); - size_t iter = UPB_MAP_BEGIN; - upb_arena *arena = Arena_get(new_self->arena); - upb_map *new_map = Map_GetMutable(new_map_rb); + size_t iter = kUpb_Map_Begin; + upb_Arena* arena = Arena_get(new_self->arena); + upb_Map* new_map = Map_GetMutable(new_map_rb); Arena_fuse(self->arena, arena); - while (upb_mapiter_next(self->map, &iter)) { - upb_msgval key = upb_mapiter_key(self->map, iter); - upb_msgval val = upb_mapiter_value(self->map, iter); - upb_map_set(new_map, key, val, arena); + while (upb_MapIterator_Next(self->map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(self->map, iter); + upb_MessageValue val = upb_MapIterator_Value(self->map, iter); + upb_Map_Set(new_map, key, val, arena); } return new_map_rb; @@ -559,18 +567,18 @@ VALUE Map_eq(VALUE _self, VALUE _other) { self->value_type_class != other->value_type_class) { return Qfalse; } - if (upb_map_size(self->map) != upb_map_size(other->map)) { + if (upb_Map_Size(self->map) != upb_Map_Size(other->map)) { return Qfalse; } // For each member of self, check that an equal member exists at the same key // in other. - size_t iter = UPB_MAP_BEGIN; - while (upb_mapiter_next(self->map, &iter)) { - upb_msgval key = upb_mapiter_key(self->map, iter); - upb_msgval val = upb_mapiter_value(self->map, iter); - upb_msgval other_val; - if (!upb_map_get(other->map, key, &other_val)) { + size_t iter = kUpb_Map_Begin; + while (upb_MapIterator_Next(self->map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(self->map, iter); + upb_MessageValue val = upb_MapIterator_Value(self->map, iter); + upb_MessageValue other_val; + if (!upb_Map_Get(other->map, key, &other_val)) { // Not present in other map. return Qfalse; } @@ -609,11 +617,11 @@ VALUE Map_hash(VALUE _self) { Map* self = ruby_to_Map(_self); uint64_t hash = 0; - size_t iter = UPB_MAP_BEGIN; + size_t iter = kUpb_Map_Begin; TypeInfo key_info = {self->key_type}; - while (upb_mapiter_next(self->map, &iter)) { - upb_msgval key = upb_mapiter_key(self->map, iter); - upb_msgval val = upb_mapiter_value(self->map, iter); + while (upb_MapIterator_Next(self->map, &iter)) { + upb_MessageValue key = upb_MapIterator_Key(self->map, iter); + upb_MessageValue val = upb_MapIterator_Value(self->map, iter); hash = Msgval_GetHash(key, key_info, hash); hash = Msgval_GetHash(val, self->value_type_info, hash); } diff --git a/ruby/ext/google/protobuf_c/map.h b/ruby/ext/google/protobuf_c/map.h index 411362cab3..7b4a1514ca 100644 --- a/ruby/ext/google/protobuf_c/map.h +++ b/ruby/ext/google/protobuf_c/map.h @@ -38,22 +38,21 @@ // Returns a Ruby wrapper object for the given map, which will be created if // one does not exist already. -VALUE Map_GetRubyWrapper(upb_map *map, upb_fieldtype_t key_type, - TypeInfo value_type, VALUE arena); +VALUE Map_GetRubyWrapper(upb_Map *map, upb_CType key_type, TypeInfo value_type, + VALUE arena); -// Gets the underlying upb_map for this Ruby map object, which must have +// Gets the underlying upb_Map for this Ruby map object, which must have // key/value type that match |field|. If this is not a map or the type doesn't // match, raises an exception. -const upb_map *Map_GetUpbMap(VALUE val, const upb_fielddef *field, - upb_arena *arena); +const upb_Map *Map_GetUpbMap(VALUE val, const upb_FieldDef *field, + upb_Arena *arena); // Implements #inspect for this map by appending its contents to |b|. -void Map_Inspect(StringBuilder *b, const upb_map *map, upb_fieldtype_t key_type, +void Map_Inspect(StringBuilder *b, const upb_Map *map, upb_CType key_type, TypeInfo val_type); // Returns a new Hash object containing the contents of this Map. -VALUE Map_CreateHash(const upb_map* map, upb_fieldtype_t key_type, - TypeInfo val_info); +VALUE Map_CreateHash(const upb_Map *map, upb_CType key_type, TypeInfo val_info); // Returns a deep copy of this Map object. VALUE Map_deep_copy(VALUE obj); diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index d07eba760d..7feee75db8 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -40,7 +40,7 @@ static VALUE cParseError = Qnil; static ID descriptor_instancevar_interned; static VALUE initialize_rb_class_with_no_args(VALUE klass) { - return rb_funcall(klass, rb_intern("new"), 0); + return rb_funcall(klass, rb_intern("new"), 0); } VALUE MessageOrEnum_GetDescriptor(VALUE klass) { @@ -53,19 +53,20 @@ VALUE MessageOrEnum_GetDescriptor(VALUE klass) { typedef struct { VALUE arena; - const upb_msg* msg; // Can get as mutable when non-frozen. - const upb_msgdef* msgdef; // kept alive by self.class.descriptor reference. + const upb_Message* msg; // Can get as mutable when non-frozen. + const upb_MessageDef* + msgdef; // kept alive by self.class.descriptor reference. } Message; static void Message_mark(void* _self) { - Message* self = (Message *)_self; + Message* self = (Message*)_self; rb_gc_mark(self->arena); } static rb_data_type_t Message_type = { - "Message", - { Message_mark, RUBY_DEFAULT_FREE, NULL }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Message", + {Message_mark, RUBY_DEFAULT_FREE, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; static Message* ruby_to_Message(VALUE msg_rb) { @@ -89,18 +90,18 @@ static VALUE Message_alloc(VALUE klass) { return ret; } -const upb_msg *Message_Get(VALUE msg_rb, const upb_msgdef **m) { +const upb_Message* Message_Get(VALUE msg_rb, const upb_MessageDef** m) { Message* msg = ruby_to_Message(msg_rb); if (m) *m = msg->msgdef; return msg->msg; } -upb_msg *Message_GetMutable(VALUE msg_rb, const upb_msgdef **m) { +upb_Message* Message_GetMutable(VALUE msg_rb, const upb_MessageDef** m) { rb_check_frozen(msg_rb); - return (upb_msg*)Message_Get(msg_rb, m); + return (upb_Message*)Message_Get(msg_rb, m); } -void Message_InitPtr(VALUE self_, upb_msg *msg, VALUE arena) { +void Message_InitPtr(VALUE self_, upb_Message* msg, VALUE arena) { Message* self = ruby_to_Message(self_); self->msg = msg; self->arena = arena; @@ -119,7 +120,8 @@ void Message_CheckClass(VALUE klass) { } } -VALUE Message_GetRubyWrapper(upb_msg* msg, const upb_msgdef* m, VALUE arena) { +VALUE Message_GetRubyWrapper(upb_Message* msg, const upb_MessageDef* m, + VALUE arena) { if (msg == NULL) return Qnil; VALUE val = ObjectCache_Get(msg); @@ -133,17 +135,17 @@ VALUE Message_GetRubyWrapper(upb_msg* msg, const upb_msgdef* m, VALUE arena) { return val; } -void Message_PrintMessage(StringBuilder* b, const upb_msg* msg, - const upb_msgdef* m) { +void Message_PrintMessage(StringBuilder* b, const upb_Message* msg, + const upb_MessageDef* m) { bool first = true; - int n = upb_msgdef_fieldcount(m); + int n = upb_MessageDef_FieldCount(m); VALUE klass = Descriptor_DefToClass(m); StringBuilder_Printf(b, "<%s: ", rb_class2name(klass)); for (int i = 0; i < n; i++) { - const upb_fielddef* field = upb_msgdef_field(m, i); + const upb_FieldDef* field = upb_MessageDef_Field(m, i); - if (upb_fielddef_haspresence(field) && !upb_msg_has(msg, field)) { + if (upb_FieldDef_HasPresence(field) && !upb_Message_Has(msg, field)) { continue; } @@ -153,17 +155,19 @@ void Message_PrintMessage(StringBuilder* b, const upb_msg* msg, first = false; } - upb_msgval msgval = upb_msg_get(msg, field); + upb_MessageValue msgval = upb_Message_Get(msg, field); - StringBuilder_Printf(b, "%s: ", upb_fielddef_name(field)); + StringBuilder_Printf(b, "%s: ", upb_FieldDef_Name(field)); - if (upb_fielddef_ismap(field)) { - const upb_msgdef* entry_m = upb_fielddef_msgsubdef(field); - const upb_fielddef* key_f = upb_msgdef_itof(entry_m, 1); - const upb_fielddef* val_f = upb_msgdef_itof(entry_m, 2); + if (upb_FieldDef_IsMap(field)) { + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(field); + const upb_FieldDef* key_f = + upb_MessageDef_FindFieldByNumberWithSize(entry_m, 1); + const upb_FieldDef* val_f = + upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2); TypeInfo val_info = TypeInfo_get(val_f); - Map_Inspect(b, msgval.map_val, upb_fielddef_type(key_f), val_info); - } else if (upb_fielddef_isseq(field)) { + Map_Inspect(b, msgval.map_val, upb_FieldDef_CType(key_f), val_info); + } else if (upb_FieldDef_IsRepeated(field)) { RepeatedField_Inspect(b, msgval.array_val, TypeInfo_get(field)); } else { StringBuilder_PrintMsgval(b, msgval, TypeInfo_get(field)); @@ -187,14 +191,31 @@ enum { }; // Check if the field is a well known wrapper type -static bool IsWrapper(const upb_fielddef* f) { - return upb_fielddef_issubmsg(f) && - upb_msgdef_iswrapper(upb_fielddef_msgsubdef(f)); +static bool IsWrapper(const upb_MessageDef* m) { + if (!m) return false; + switch (upb_MessageDef_WellKnownType(m)) { + case kUpb_WellKnown_DoubleValue: + case kUpb_WellKnown_FloatValue: + case kUpb_WellKnown_Int64Value: + case kUpb_WellKnown_UInt64Value: + case kUpb_WellKnown_Int32Value: + case kUpb_WellKnown_UInt32Value: + case kUpb_WellKnown_StringValue: + case kUpb_WellKnown_BytesValue: + case kUpb_WellKnown_BoolValue: + return true; + default: + return false; + } } -static bool Match(const upb_msgdef* m, const char* name, const upb_fielddef** f, - const upb_oneofdef** o, const char* prefix, - const char* suffix) { +static bool IsFieldWrapper(const upb_FieldDef* f) { + return IsWrapper(upb_FieldDef_MessageSubDef(f)); +} + +static bool Match(const upb_MessageDef* m, const char* name, + const upb_FieldDef** f, const upb_OneofDef** o, + const char* prefix, const char* suffix) { size_t sp = strlen(prefix); size_t ss = strlen(suffix); size_t sn = strlen(name); @@ -206,12 +227,12 @@ static bool Match(const upb_msgdef* m, const char* name, const upb_fielddef** f, return false; } - return upb_msgdef_lookupname(m, name + sp, sn - sp - ss, f, o); + return upb_MessageDef_FindByNameWithSize(m, name + sp, sn - sp - ss, f, o); } static int extract_method_call(VALUE method_name, Message* self, - const upb_fielddef** f, const upb_oneofdef** o) { - const upb_msgdef* m = self->msgdef; + const upb_FieldDef** f, const upb_OneofDef** o) { + const upb_MessageDef* m = self->msgdef; const char* name; Check_Type(method_name, T_SYMBOL); @@ -221,156 +242,159 @@ static int extract_method_call(VALUE method_name, Message* self, if (Match(m, name, f, o, "", "=")) return METHOD_SETTER; if (Match(m, name, f, o, "clear_", "")) return METHOD_CLEAR; if (Match(m, name, f, o, "has_", "?") && - (*o || (*f && upb_fielddef_haspresence(*f)))) { + (*o || (*f && upb_FieldDef_HasPresence(*f)))) { // Disallow oneof hazzers for proto3. // TODO(haberman): remove this test when we are enabling oneof hazzers for // proto3. - if (*f && !upb_fielddef_issubmsg(*f) && - upb_fielddef_realcontainingoneof(*f) && - upb_msgdef_syntax(upb_fielddef_containingtype(*f)) != - UPB_SYNTAX_PROTO2) { + if (*f && !upb_FieldDef_IsSubMessage(*f) && + upb_FieldDef_RealContainingOneof(*f) && + upb_MessageDef_Syntax(upb_FieldDef_ContainingType(*f)) != + kUpb_Syntax_Proto2) { return METHOD_UNKNOWN; } return METHOD_PRESENCE; } - if (Match(m, name, f, o, "", "_as_value") && *f && !upb_fielddef_isseq(*f) && - IsWrapper(*f)) { + if (Match(m, name, f, o, "", "_as_value") && *f && + !upb_FieldDef_IsRepeated(*f) && IsFieldWrapper(*f)) { return METHOD_WRAPPER_GETTER; } - if (Match(m, name, f, o, "", "_as_value=") && *f && !upb_fielddef_isseq(*f) && - IsWrapper(*f)) { + if (Match(m, name, f, o, "", "_as_value=") && *f && + !upb_FieldDef_IsRepeated(*f) && IsFieldWrapper(*f)) { return METHOD_WRAPPER_SETTER; } if (Match(m, name, f, o, "", "_const") && *f && - upb_fielddef_type(*f) == UPB_TYPE_ENUM) { + upb_FieldDef_CType(*f) == kUpb_CType_Enum) { return METHOD_ENUM_GETTER; } return METHOD_UNKNOWN; } -static VALUE Message_oneof_accessor(VALUE _self, const upb_oneofdef* o, +static VALUE Message_oneof_accessor(VALUE _self, const upb_OneofDef* o, int accessor_type) { Message* self = ruby_to_Message(_self); - const upb_fielddef* oneof_field = upb_msg_whichoneof(self->msg, o); + const upb_FieldDef* oneof_field = upb_Message_WhichOneof(self->msg, o); switch (accessor_type) { case METHOD_PRESENCE: return oneof_field == NULL ? Qfalse : Qtrue; case METHOD_CLEAR: if (oneof_field != NULL) { - upb_msg_clearfield(Message_GetMutable(_self, NULL), oneof_field); + upb_Message_ClearField(Message_GetMutable(_self, NULL), oneof_field); } return Qnil; case METHOD_GETTER: return oneof_field == NULL ? Qnil - : ID2SYM(rb_intern(upb_fielddef_name(oneof_field))); + : ID2SYM(rb_intern(upb_FieldDef_Name(oneof_field))); case METHOD_SETTER: rb_raise(rb_eRuntimeError, "Oneof accessors are read-only."); } rb_raise(rb_eRuntimeError, "Invalid access of oneof field."); } -static void Message_setfield(upb_msg* msg, const upb_fielddef* f, VALUE val, - upb_arena* arena) { - upb_msgval msgval; - if (upb_fielddef_ismap(f)) { +static void Message_setfield(upb_Message* msg, const upb_FieldDef* f, VALUE val, + upb_Arena* arena) { + upb_MessageValue msgval; + if (upb_FieldDef_IsMap(f)) { msgval.map_val = Map_GetUpbMap(val, f, arena); - } else if (upb_fielddef_isseq(f)) { + } else if (upb_FieldDef_IsRepeated(f)) { msgval.array_val = RepeatedField_GetUpbArray(val, f, arena); } else { if (val == Qnil && - (upb_fielddef_issubmsg(f) || upb_fielddef_realcontainingoneof(f))) { - upb_msg_clearfield(msg, f); + (upb_FieldDef_IsSubMessage(f) || upb_FieldDef_RealContainingOneof(f))) { + upb_Message_ClearField(msg, f); return; } msgval = - Convert_RubyToUpb(val, upb_fielddef_name(f), TypeInfo_get(f), arena); + Convert_RubyToUpb(val, upb_FieldDef_Name(f), TypeInfo_get(f), arena); } - upb_msg_set(msg, f, msgval, arena); + upb_Message_Set(msg, f, msgval, arena); } -VALUE Message_getfield(VALUE _self, const upb_fielddef* f) { +VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) { Message* self = ruby_to_Message(_self); - // This is a special-case: upb_msg_mutable() for map & array are logically + // This is a special-case: upb_Message_Mutable() for map & array are logically // const (they will not change what is serialized) but physically // non-const, as they do allocate a repeated field or map. The logical // constness means it's ok to do even if the message is frozen. - upb_msg *msg = (upb_msg*)self->msg; - upb_arena *arena = Arena_get(self->arena); - if (upb_fielddef_ismap(f)) { - upb_map *map = upb_msg_mutable(msg, f, arena).map; - const upb_fielddef *key_f = map_field_key(f); - const upb_fielddef *val_f = map_field_value(f); - upb_fieldtype_t key_type = upb_fielddef_type(key_f); + upb_Message* msg = (upb_Message*)self->msg; + upb_Arena* arena = Arena_get(self->arena); + if (upb_FieldDef_IsMap(f)) { + upb_Map* map = upb_Message_Mutable(msg, f, arena).map; + const upb_FieldDef* key_f = map_field_key(f); + const upb_FieldDef* val_f = map_field_value(f); + upb_CType key_type = upb_FieldDef_CType(key_f); TypeInfo value_type_info = TypeInfo_get(val_f); return Map_GetRubyWrapper(map, key_type, value_type_info, self->arena); - } else if (upb_fielddef_isseq(f)) { - upb_array *arr = upb_msg_mutable(msg, f, arena).array; + } else if (upb_FieldDef_IsRepeated(f)) { + upb_Array* arr = upb_Message_Mutable(msg, f, arena).array; return RepeatedField_GetRubyWrapper(arr, TypeInfo_get(f), self->arena); - } else if (upb_fielddef_issubmsg(f)) { - if (!upb_msg_has(self->msg, f)) return Qnil; - upb_msg *submsg = upb_msg_mutable(msg, f, arena).msg; - const upb_msgdef *m = upb_fielddef_msgsubdef(f); + } else if (upb_FieldDef_IsSubMessage(f)) { + if (!upb_Message_Has(self->msg, f)) return Qnil; + upb_Message* submsg = upb_Message_Mutable(msg, f, arena).msg; + const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); return Message_GetRubyWrapper(submsg, m, self->arena); } else { - upb_msgval msgval = upb_msg_get(self->msg, f); + upb_MessageValue msgval = upb_Message_Get(self->msg, f); return Convert_UpbToRuby(msgval, TypeInfo_get(f), self->arena); } } -static VALUE Message_field_accessor(VALUE _self, const upb_fielddef* f, +static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f, int accessor_type, int argc, VALUE* argv) { - upb_arena *arena = Arena_get(Message_GetArena(_self)); + upb_Arena* arena = Arena_get(Message_GetArena(_self)); switch (accessor_type) { case METHOD_SETTER: Message_setfield(Message_GetMutable(_self, NULL), f, argv[1], arena); return Qnil; case METHOD_CLEAR: - upb_msg_clearfield(Message_GetMutable(_self, NULL), f); + upb_Message_ClearField(Message_GetMutable(_self, NULL), f); return Qnil; case METHOD_PRESENCE: - if (!upb_fielddef_haspresence(f)) { + if (!upb_FieldDef_HasPresence(f)) { rb_raise(rb_eRuntimeError, "Field does not have presence."); } - return upb_msg_has(Message_Get(_self, NULL), f); + return upb_Message_Has(Message_Get(_self, NULL), f); case METHOD_WRAPPER_GETTER: { Message* self = ruby_to_Message(_self); - if (upb_msg_has(self->msg, f)) { - PBRUBY_ASSERT(upb_fielddef_issubmsg(f) && !upb_fielddef_isseq(f)); - upb_msgval wrapper = upb_msg_get(self->msg, f); - const upb_msgdef *wrapper_m = upb_fielddef_msgsubdef(f); - const upb_fielddef *value_f = upb_msgdef_itof(wrapper_m, 1); - upb_msgval value = upb_msg_get(wrapper.msg_val, value_f); + if (upb_Message_Has(self->msg, f)) { + PBRUBY_ASSERT(upb_FieldDef_IsSubMessage(f) && + !upb_FieldDef_IsRepeated(f)); + upb_MessageValue wrapper = upb_Message_Get(self->msg, f); + const upb_MessageDef* wrapper_m = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* value_f = + upb_MessageDef_FindFieldByNumberWithSize(wrapper_m, 1); + upb_MessageValue value = upb_Message_Get(wrapper.msg_val, value_f); return Convert_UpbToRuby(value, TypeInfo_get(value_f), self->arena); } else { return Qnil; } } case METHOD_WRAPPER_SETTER: { - upb_msg *msg = Message_GetMutable(_self, NULL); + upb_Message* msg = Message_GetMutable(_self, NULL); if (argv[1] == Qnil) { - upb_msg_clearfield(msg, f); + upb_Message_ClearField(msg, f); } else { - const upb_fielddef *val_f = upb_msgdef_itof(upb_fielddef_msgsubdef(f), 1); - upb_msgval msgval = Convert_RubyToUpb(argv[1], upb_fielddef_name(f), - TypeInfo_get(val_f), arena); - upb_msg *wrapper = upb_msg_mutable(msg, f, arena).msg; - upb_msg_set(wrapper, val_f, msgval, arena); + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumberWithSize( + upb_FieldDef_MessageSubDef(f), 1); + upb_MessageValue msgval = Convert_RubyToUpb( + argv[1], upb_FieldDef_Name(f), TypeInfo_get(val_f), arena); + upb_Message* wrapper = upb_Message_Mutable(msg, f, arena).msg; + upb_Message_Set(wrapper, val_f, msgval, arena); } return Qnil; } case METHOD_ENUM_GETTER: { - upb_msgval msgval = upb_msg_get(Message_Get(_self, NULL), f); + upb_MessageValue msgval = upb_Message_Get(Message_Get(_self, NULL), f); - if (upb_fielddef_label(f) == UPB_LABEL_REPEATED) { + if (upb_FieldDef_Label(f) == kUpb_Label_Repeated) { // Map repeated fields to a new type with ints VALUE arr = rb_ary_new(); - size_t i, n = upb_array_size(msgval.array_val); + size_t i, n = upb_Array_Size(msgval.array_val); for (i = 0; i < n; i++) { - upb_msgval elem = upb_array_get(msgval.array_val, i); + upb_MessageValue elem = upb_Array_Get(msgval.array_val, i); rb_ary_push(arr, INT2NUM(elem.int32_val)); } return arr; @@ -415,8 +439,8 @@ static VALUE Message_field_accessor(VALUE _self, const upb_fielddef* f, */ static VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) { Message* self = ruby_to_Message(_self); - const upb_oneofdef* o; - const upb_fielddef* f; + const upb_OneofDef* o; + const upb_FieldDef* f; int accessor_type; if (argc < 1) { @@ -453,8 +477,8 @@ static VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) { static VALUE Message_respond_to_missing(int argc, VALUE* argv, VALUE _self) { Message* self = ruby_to_Message(_self); - const upb_oneofdef* o; - const upb_fielddef* f; + const upb_OneofDef* o; + const upb_FieldDef* f; int accessor_type; if (argc < 1) { @@ -472,53 +496,56 @@ static VALUE Message_respond_to_missing(int argc, VALUE* argv, VALUE _self) { } } -void Message_InitFromValue(upb_msg* msg, const upb_msgdef* m, VALUE val, - upb_arena* arena); +void Message_InitFromValue(upb_Message* msg, const upb_MessageDef* m, VALUE val, + upb_Arena* arena); typedef struct { - upb_map *map; + upb_Map* map; TypeInfo key_type; TypeInfo val_type; - upb_arena *arena; + upb_Arena* arena; } MapInit; static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { - MapInit *map_init = (MapInit*)_self; - upb_msgval k, v; + MapInit* map_init = (MapInit*)_self; + upb_MessageValue k, v; k = Convert_RubyToUpb(key, "", map_init->key_type, NULL); - if (map_init->val_type.type == UPB_TYPE_MESSAGE && TYPE(val) == T_HASH) { - upb_msg *msg = upb_msg_new(map_init->val_type.def.msgdef, map_init->arena); + if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) { + upb_Message* msg = + upb_Message_New(map_init->val_type.def.msgdef, map_init->arena); Message_InitFromValue(msg, map_init->val_type.def.msgdef, val, map_init->arena); v.msg_val = msg; } else { v = Convert_RubyToUpb(val, "", map_init->val_type, map_init->arena); } - upb_map_set(map_init->map, k, v, map_init->arena); + upb_Map_Set(map_init->map, k, v, map_init->arena); return ST_CONTINUE; } -static void Map_InitFromValue(upb_map* map, const upb_fielddef* f, VALUE val, - upb_arena* arena) { - const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f); - const upb_fielddef* key_f = upb_msgdef_itof(entry_m, 1); - const upb_fielddef* val_f = upb_msgdef_itof(entry_m, 2); +static void Map_InitFromValue(upb_Map* map, const upb_FieldDef* f, VALUE val, + upb_Arena* arena) { + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key_f = + upb_MessageDef_FindFieldByNumberWithSize(entry_m, 1); + const upb_FieldDef* val_f = + upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2); if (TYPE(val) != T_HASH) { rb_raise(rb_eArgError, "Expected Hash object as initializer value for map field '%s' " "(given %s).", - upb_fielddef_name(f), rb_class2name(CLASS_OF(val))); + upb_FieldDef_Name(f), rb_class2name(CLASS_OF(val))); } MapInit map_init = {map, TypeInfo_get(key_f), TypeInfo_get(val_f), arena}; rb_hash_foreach(val, Map_initialize_kwarg, (VALUE)&map_init); } -static upb_msgval MessageValue_FromValue(VALUE val, TypeInfo info, - upb_arena* arena) { - if (info.type == UPB_TYPE_MESSAGE) { - upb_msgval msgval; - upb_msg* msg = upb_msg_new(info.def.msgdef, arena); +static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info, + upb_Arena* arena) { + if (info.type == kUpb_CType_Message) { + upb_MessageValue msgval; + upb_Message* msg = upb_Message_New(info.def.msgdef, arena); Message_InitFromValue(msg, info.def.msgdef, val, arena); msgval.msg_val = msg; return msgval; @@ -527,61 +554,62 @@ static upb_msgval MessageValue_FromValue(VALUE val, TypeInfo info, } } -static void RepeatedField_InitFromValue(upb_array* arr, const upb_fielddef* f, - VALUE val, upb_arena* arena) { +static void RepeatedField_InitFromValue(upb_Array* arr, const upb_FieldDef* f, + VALUE val, upb_Arena* arena) { TypeInfo type_info = TypeInfo_get(f); if (TYPE(val) != T_ARRAY) { rb_raise(rb_eArgError, - "Expected array as initializer value for repeated field '%s' (given %s).", - upb_fielddef_name(f), rb_class2name(CLASS_OF(val))); + "Expected array as initializer value for repeated field '%s' " + "(given %s).", + upb_FieldDef_Name(f), rb_class2name(CLASS_OF(val))); } for (int i = 0; i < RARRAY_LEN(val); i++) { VALUE entry = rb_ary_entry(val, i); - upb_msgval msgval; - if (upb_fielddef_issubmsg(f) && TYPE(entry) == T_HASH) { + upb_MessageValue msgval; + if (upb_FieldDef_IsSubMessage(f) && TYPE(entry) == T_HASH) { msgval = MessageValue_FromValue(entry, type_info, arena); } else { - msgval = Convert_RubyToUpb(entry, upb_fielddef_name(f), type_info, arena); + msgval = Convert_RubyToUpb(entry, upb_FieldDef_Name(f), type_info, arena); } - upb_array_append(arr, msgval, arena); + upb_Array_Append(arr, msgval, arena); } } -static void Message_InitFieldFromValue(upb_msg* msg, const upb_fielddef* f, - VALUE val, upb_arena* arena) { +static void Message_InitFieldFromValue(upb_Message* msg, const upb_FieldDef* f, + VALUE val, upb_Arena* arena) { if (TYPE(val) == T_NIL) return; - if (upb_fielddef_ismap(f)) { - upb_map *map = upb_msg_mutable(msg, f, arena).map; + if (upb_FieldDef_IsMap(f)) { + upb_Map* map = upb_Message_Mutable(msg, f, arena).map; Map_InitFromValue(map, f, val, arena); - } else if (upb_fielddef_label(f) == UPB_LABEL_REPEATED) { - upb_array *arr = upb_msg_mutable(msg, f, arena).array; + } else if (upb_FieldDef_Label(f) == kUpb_Label_Repeated) { + upb_Array* arr = upb_Message_Mutable(msg, f, arena).array; RepeatedField_InitFromValue(arr, f, val, arena); - } else if (upb_fielddef_issubmsg(f)) { + } else if (upb_FieldDef_IsSubMessage(f)) { if (TYPE(val) == T_HASH) { - upb_msg *submsg = upb_msg_mutable(msg, f, arena).msg; - Message_InitFromValue(submsg, upb_fielddef_msgsubdef(f), val, arena); + upb_Message* submsg = upb_Message_Mutable(msg, f, arena).msg; + Message_InitFromValue(submsg, upb_FieldDef_MessageSubDef(f), val, arena); } else { Message_setfield(msg, f, val, arena); } } else { - upb_msgval msgval = - Convert_RubyToUpb(val, upb_fielddef_name(f), TypeInfo_get(f), arena); - upb_msg_set(msg, f, msgval, arena); + upb_MessageValue msgval = + Convert_RubyToUpb(val, upb_FieldDef_Name(f), TypeInfo_get(f), arena); + upb_Message_Set(msg, f, msgval, arena); } } typedef struct { - upb_msg *msg; - const upb_msgdef *msgdef; - upb_arena *arena; + upb_Message* msg; + const upb_MessageDef* msgdef; + upb_Arena* arena; } MsgInit; static int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { - MsgInit *msg_init = (MsgInit*)_self; - const char *name; + MsgInit* msg_init = (MsgInit*)_self; + const char* name; if (TYPE(key) == T_STRING) { name = RSTRING_PTR(key); @@ -589,10 +617,12 @@ static int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { name = RSTRING_PTR(rb_id2str(SYM2ID(key))); } else { rb_raise(rb_eArgError, - "Expected string or symbols as hash keys when initializing proto from hash."); + "Expected string or symbols as hash keys when initializing proto " + "from hash."); } - const upb_fielddef* f = upb_msgdef_ntofz(msg_init->msgdef, name); + const upb_FieldDef* f = + upb_MessageDef_FindFieldByName(msg_init->msgdef, name); if (f == NULL) { rb_raise(rb_eArgError, @@ -603,8 +633,8 @@ static int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { return ST_CONTINUE; } -void Message_InitFromValue(upb_msg* msg, const upb_msgdef* m, VALUE val, - upb_arena* arena) { +void Message_InitFromValue(upb_Message* msg, const upb_MessageDef* m, VALUE val, + upb_Arena* arena) { MsgInit msg_init = {msg, m, arena}; if (TYPE(val) == T_HASH) { rb_hash_foreach(val, Message_initialize_kwarg, (VALUE)&msg_init); @@ -629,8 +659,8 @@ void Message_InitFromValue(upb_msg* msg, const upb_msgdef* m, VALUE val, static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) { Message* self = ruby_to_Message(_self); VALUE arena_rb = Arena_new(); - upb_arena *arena = Arena_get(arena_rb); - upb_msg *msg = upb_msg_new(self->msgdef, arena); + upb_Arena* arena = Arena_get(arena_rb); + upb_Message* msg = upb_Message_New(self->msgdef, arena); Message_InitPtr(_self, msg, arena_rb); @@ -640,7 +670,7 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) { if (argc != 1) { rb_raise(rb_eArgError, "Expected 0 or 1 arguments."); } - Message_InitFromValue((upb_msg*)self->msg, self->msgdef, argv[0], arena); + Message_InitFromValue((upb_Message*)self->msg, self->msgdef, argv[0], arena); return Qnil; } @@ -654,34 +684,35 @@ static VALUE Message_dup(VALUE _self) { Message* self = ruby_to_Message(_self); VALUE new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self)); Message* new_msg_self = ruby_to_Message(new_msg); - size_t size = upb_msgdef_layout(self->msgdef)->size; + size_t size = upb_MessageDef_MiniTable(self->msgdef)->size; // TODO(copy unknown fields?) // TODO(use official upb msg copy function) - memcpy((upb_msg*)new_msg_self->msg, self->msg, size); + memcpy((upb_Message*)new_msg_self->msg, self->msg, size); Arena_fuse(self->arena, Arena_get(new_msg_self->arena)); return new_msg; } // Support function for Message_eq, and also used by other #eq functions. -bool Message_Equal(const upb_msg *m1, const upb_msg *m2, const upb_msgdef *m) { +bool Message_Equal(const upb_Message* m1, const upb_Message* m2, + const upb_MessageDef* m) { if (m1 == m2) return true; size_t size1, size2; - int encode_opts = UPB_ENCODE_SKIPUNKNOWN | UPB_ENCODE_DETERMINISTIC; - upb_arena *arena_tmp = upb_arena_new(); - const upb_msglayout *layout = upb_msgdef_layout(m); + int encode_opts = kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic; + upb_Arena* arena_tmp = upb_Arena_New(); + const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); // Compare deterministically serialized payloads with no unknown fields. - char *data1 = upb_encode_ex(m1, layout, encode_opts, arena_tmp, &size1); - char *data2 = upb_encode_ex(m2, layout, encode_opts, arena_tmp, &size2); + char* data1 = upb_Encode(m1, layout, encode_opts, arena_tmp, &size1); + char* data2 = upb_Encode(m2, layout, encode_opts, arena_tmp, &size2); if (data1 && data2) { bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); - upb_arena_free(arena_tmp); + upb_Arena_Free(arena_tmp); return ret; } else { - upb_arena_free(arena_tmp); + upb_Arena_Free(arena_tmp); rb_raise(cParseError, "Error comparing messages"); } } @@ -705,22 +736,23 @@ static VALUE Message_eq(VALUE _self, VALUE _other) { return Message_Equal(self->msg, other->msg, self->msgdef) ? Qtrue : Qfalse; } -uint64_t Message_Hash(const upb_msg* msg, const upb_msgdef* m, uint64_t seed) { - upb_arena *arena = upb_arena_new(); - const char *data; +uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m, + uint64_t seed) { + upb_Arena* arena = upb_Arena_New(); + const char* data; size_t size; // Hash a deterministically serialized payloads with no unknown fields. - data = upb_encode_ex(msg, upb_msgdef_layout(m), - UPB_ENCODE_SKIPUNKNOWN | UPB_ENCODE_DETERMINISTIC, arena, - &size); + data = upb_Encode(msg, upb_MessageDef_MiniTable(m), + kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic, arena, + &size); if (data) { uint64_t ret = Wyhash(data, size, seed, kWyhashSalt); - upb_arena_free(arena); + upb_Arena_Free(arena); return ret; } else { - upb_arena_free(arena); + upb_Arena_Free(arena); rb_raise(cParseError, "Error calculating hash"); } } @@ -759,13 +791,13 @@ static VALUE Message_inspect(VALUE _self) { // Support functions for Message_to_h ////////////////////////////////////////// -static VALUE RepeatedField_CreateArray(const upb_array* arr, +static VALUE RepeatedField_CreateArray(const upb_Array* arr, TypeInfo type_info) { - int size = arr ? upb_array_size(arr) : 0; + int size = arr ? upb_Array_Size(arr) : 0; VALUE ary = rb_ary_new2(size); for (int i = 0; i < size; i++) { - upb_msgval msgval = upb_array_get(arr, i); + upb_MessageValue msgval = upb_Array_Get(arr, i); VALUE val = Scalar_CreateHash(msgval, type_info); rb_ary_push(ary, val); } @@ -773,54 +805,57 @@ static VALUE RepeatedField_CreateArray(const upb_array* arr, return ary; } -static VALUE Message_CreateHash(const upb_msg *msg, const upb_msgdef *m) { +static VALUE Message_CreateHash(const upb_Message* msg, + const upb_MessageDef* m) { if (!msg) return Qnil; VALUE hash = rb_hash_new(); - int n = upb_msgdef_fieldcount(m); + int n = upb_MessageDef_FieldCount(m); bool is_proto2; // We currently have a few behaviors that are specific to proto2. // This is unfortunate, we should key behaviors off field attributes (like // whether a field has presence), not proto2 vs. proto3. We should see if we // can change this without breaking users. - is_proto2 = upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2; + is_proto2 = upb_MessageDef_Syntax(m) == kUpb_Syntax_Proto2; for (int i = 0; i < n; i++) { - const upb_fielddef* field = upb_msgdef_field(m, i); + const upb_FieldDef* field = upb_MessageDef_Field(m, i); TypeInfo type_info = TypeInfo_get(field); - upb_msgval msgval; + upb_MessageValue msgval; VALUE msg_value; VALUE msg_key; - if (!is_proto2 && upb_fielddef_issubmsg(field) && - !upb_fielddef_isseq(field) && !upb_msg_has(msg, field)) { + if (!is_proto2 && upb_FieldDef_IsSubMessage(field) && + !upb_FieldDef_IsRepeated(field) && !upb_Message_Has(msg, field)) { // TODO: Legacy behavior, remove when we fix the is_proto2 differences. - msg_key = ID2SYM(rb_intern(upb_fielddef_name(field))); + msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field))); rb_hash_aset(hash, msg_key, Qnil); continue; } // Do not include fields that are not present (oneof or optional fields). - if (is_proto2 && upb_fielddef_haspresence(field) && - !upb_msg_has(msg, field)) { + if (is_proto2 && upb_FieldDef_HasPresence(field) && + !upb_Message_Has(msg, field)) { continue; } - msg_key = ID2SYM(rb_intern(upb_fielddef_name(field))); - msgval = upb_msg_get(msg, field); + msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field))); + msgval = upb_Message_Get(msg, field); // Proto2 omits empty map/repeated filds also. - if (upb_fielddef_ismap(field)) { - const upb_msgdef *entry_m = upb_fielddef_msgsubdef(field); - const upb_fielddef *key_f = upb_msgdef_itof(entry_m, 1); - const upb_fielddef *val_f = upb_msgdef_itof(entry_m, 2); - upb_fieldtype_t key_type = upb_fielddef_type(key_f); + if (upb_FieldDef_IsMap(field)) { + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(field); + const upb_FieldDef* key_f = + upb_MessageDef_FindFieldByNumberWithSize(entry_m, 1); + const upb_FieldDef* val_f = + upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2); + upb_CType key_type = upb_FieldDef_CType(key_f); msg_value = Map_CreateHash(msgval.map_val, key_type, TypeInfo_get(val_f)); - } else if (upb_fielddef_isseq(field)) { + } else if (upb_FieldDef_IsRepeated(field)) { if (is_proto2 && - (!msgval.array_val || upb_array_size(msgval.array_val) == 0)) { + (!msgval.array_val || upb_Array_Size(msgval.array_val) == 0)) { continue; } msg_value = RepeatedField_CreateArray(msgval.array_val, type_info); @@ -834,8 +869,8 @@ static VALUE Message_CreateHash(const upb_msg *msg, const upb_msgdef *m) { return hash; } -VALUE Scalar_CreateHash(upb_msgval msgval, TypeInfo type_info) { - if (type_info.type == UPB_TYPE_MESSAGE) { +VALUE Scalar_CreateHash(upb_MessageValue msgval, TypeInfo type_info) { + if (type_info.type == kUpb_CType_Message) { return Message_CreateHash(msgval.msg_val, type_info.def.msgdef); } else { return Convert_UpbToRuby(msgval, type_info, Qnil); @@ -878,10 +913,10 @@ static VALUE Message_freeze(VALUE _self) { */ static VALUE Message_index(VALUE _self, VALUE field_name) { Message* self = ruby_to_Message(_self); - const upb_fielddef* field; + const upb_FieldDef* field; Check_Type(field_name, T_STRING); - field = upb_msgdef_ntofz(self->msgdef, RSTRING_PTR(field_name)); + field = upb_MessageDef_FindFieldByName(self->msgdef, RSTRING_PTR(field_name)); if (field == NULL) { return Qnil; @@ -899,19 +934,19 @@ static VALUE Message_index(VALUE _self, VALUE field_name) { */ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) { Message* self = ruby_to_Message(_self); - const upb_fielddef* f; - upb_msgval val; - upb_arena *arena = Arena_get(self->arena); + const upb_FieldDef* f; + upb_MessageValue val; + upb_Arena* arena = Arena_get(self->arena); Check_Type(field_name, T_STRING); - f = upb_msgdef_ntofz(self->msgdef, RSTRING_PTR(field_name)); + f = upb_MessageDef_FindFieldByName(self->msgdef, RSTRING_PTR(field_name)); if (f == NULL) { rb_raise(rb_eArgError, "Unknown field: %s", RSTRING_PTR(field_name)); } - val = Convert_RubyToUpb(value, upb_fielddef_name(f), TypeInfo_get(f), arena); - upb_msg_set(Message_GetMutable(_self, NULL), f, val, arena); + val = Convert_RubyToUpb(value, upb_FieldDef_Name(f), TypeInfo_get(f), arena); + upb_Message_Set(Message_GetMutable(_self, NULL), f, val, arena); return Qnil; } @@ -932,9 +967,11 @@ static VALUE Message_decode(VALUE klass, VALUE data) { VALUE msg_rb = initialize_rb_class_with_no_args(klass); Message* msg = ruby_to_Message(msg_rb); - if (!upb_decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_msg*)msg->msg, - upb_msgdef_layout(msg->msgdef), - Arena_get(msg->arena))) { + upb_DecodeStatus status = upb_Decode( + RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg, + upb_MessageDef_MiniTable(msg->msgdef), NULL, 0, Arena_get(msg->arena)); + + if (status != kUpb_DecodeStatus_Ok) { rb_raise(cParseError, "Error occurred during parsing"); } @@ -956,10 +993,10 @@ static VALUE Message_decode(VALUE klass, VALUE data) { static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { VALUE data = argv[0]; int options = 0; - upb_status status; + upb_Status status; // TODO(haberman): use this message's pool instead. - const upb_symtab *symtab = DescriptorPool_GetSymtab(generated_pool); + const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool); if (argc < 1 || argc > 2) { rb_raise(rb_eArgError, "Expected 1 or 2 arguments."); @@ -971,8 +1008,9 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { rb_raise(rb_eArgError, "Expected hash arguments."); } - if (RTEST(rb_hash_lookup2( hash_args, ID2SYM(rb_intern("ignore_unknown_fields")), Qfalse))) { - options |= UPB_JSONDEC_IGNOREUNKNOWN; + if (RTEST(rb_hash_lookup2( + hash_args, ID2SYM(rb_intern("ignore_unknown_fields")), Qfalse))) { + options |= upb_JsonDecode_IgnoreUnknown; } } @@ -988,16 +1026,16 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { Message* msg = ruby_to_Message(msg_rb); // We don't allow users to decode a wrapper type directly. - if (upb_msgdef_iswrapper(msg->msgdef)) { + if (IsWrapper(msg->msgdef)) { rb_raise(rb_eRuntimeError, "Cannot parse a wrapper directly."); } - upb_status_clear(&status); - if (!upb_json_decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_msg*)msg->msg, - msg->msgdef, symtab, options, - Arena_get(msg->arena), &status)) { + upb_Status_Clear(&status); + if (!upb_JsonDecode(RSTRING_PTR(data), RSTRING_LEN(data), + (upb_Message*)msg->msg, msg->msgdef, symtab, options, + Arena_get(msg->arena), &status)) { rb_raise(cParseError, "Error occurred during parsing: %s", - upb_status_errmsg(&status)); + upb_Status_ErrorMessage(&status)); } return msg_rb; @@ -1012,25 +1050,25 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { */ static VALUE Message_encode(VALUE klass, VALUE msg_rb) { Message* msg = ruby_to_Message(msg_rb); - const char *data; + const char* data; size_t size; if (CLASS_OF(msg_rb) != klass) { rb_raise(rb_eArgError, "Message of wrong type."); } - upb_arena *arena = upb_arena_new(); + upb_Arena* arena = upb_Arena_New(); - data = upb_encode(msg->msg, upb_msgdef_layout(msg->msgdef), arena, + data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), 0, arena, &size); if (data) { VALUE ret = rb_str_new(data, size); rb_enc_associate(ret, rb_ascii8bit_encoding()); - upb_arena_free(arena); + upb_Arena_Free(arena); return ret; } else { - upb_arena_free(arena); + upb_Arena_Free(arena); rb_raise(rb_eRuntimeError, "Exceeded maximum depth (possibly cycle)"); } } @@ -1041,18 +1079,19 @@ static VALUE Message_encode(VALUE klass, VALUE msg_rb) { * * Encodes the given message object into its serialized JSON representation. * @param options [Hash] options for the decoder - * preserve_proto_fieldnames: set true to use original fieldnames (default is to camelCase) - * emit_defaults: set true to emit 0/false values (default is to omit them) + * preserve_proto_fieldnames: set true to use original fieldnames (default is + * to camelCase) emit_defaults: set true to emit 0/false values (default is to + * omit them) */ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { Message* msg = ruby_to_Message(argv[0]); int options = 0; char buf[1024]; size_t size; - upb_status status; + upb_Status status; // TODO(haberman): use this message's pool instead. - const upb_symtab *symtab = DescriptorPool_GetSymtab(generated_pool); + const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool); if (argc < 1 || argc > 2) { rb_raise(rb_eArgError, "Expected 1 or 2 arguments."); @@ -1067,29 +1106,29 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { if (RTEST(rb_hash_lookup2(hash_args, ID2SYM(rb_intern("preserve_proto_fieldnames")), Qfalse))) { - options |= UPB_JSONENC_PROTONAMES; + options |= upb_JsonEncode_UseProtoNames; } if (RTEST(rb_hash_lookup2(hash_args, ID2SYM(rb_intern("emit_defaults")), Qfalse))) { - options |= UPB_JSONENC_EMITDEFAULTS; + options |= upb_JsonEncode_EmitDefaults; } } - upb_status_clear(&status); - size = upb_json_encode(msg->msg, msg->msgdef, symtab, options, buf, - sizeof(buf), &status); + upb_Status_Clear(&status); + size = upb_JsonEncode(msg->msg, msg->msgdef, symtab, options, buf, + sizeof(buf), &status); - if (!upb_ok(&status)) { + if (!upb_Status_IsOk(&status)) { rb_raise(cParseError, "Error occurred during encoding: %s", - upb_status_errmsg(&status)); + upb_Status_ErrorMessage(&status)); } VALUE ret; if (size >= sizeof(buf)) { char* buf2 = malloc(size + 1); - upb_json_encode(msg->msg, msg->msgdef, symtab, options, buf2, size + 1, - &status); + upb_JsonEncode(msg->msg, msg->msgdef, symtab, options, buf2, size + 1, + &status); ret = rb_str_new(buf2, size); free(buf2); } else { @@ -1112,10 +1151,10 @@ static VALUE Message_descriptor(VALUE klass) { } VALUE build_class_from_descriptor(VALUE descriptor) { - const char *name; + const char* name; VALUE klass; - name = upb_msgdef_fullname(Descriptor_GetMsgDef(descriptor)); + name = upb_MessageDef_FullName(Descriptor_GetMsgDef(descriptor)); if (name == NULL) { rb_raise(rb_eRuntimeError, "Descriptor does not have assigned name."); } @@ -1123,8 +1162,7 @@ VALUE build_class_from_descriptor(VALUE descriptor) { klass = rb_define_class_id( // Docs say this parameter is ignored. User will assign return value to // their own toplevel constant class name. - rb_intern("Message"), - rb_cObject); + rb_intern("Message"), rb_cObject); rb_ivar_set(klass, descriptor_instancevar_interned, descriptor); rb_define_alloc_func(klass, Message_alloc); rb_require("google/protobuf/message_exts"); @@ -1132,10 +1170,9 @@ VALUE build_class_from_descriptor(VALUE descriptor) { rb_extend_object( klass, rb_eval_string("::Google::Protobuf::MessageExts::ClassMethods")); - rb_define_method(klass, "method_missing", - Message_method_missing, -1); - rb_define_method(klass, "respond_to_missing?", - Message_respond_to_missing, -1); + rb_define_method(klass, "method_missing", Message_method_missing, -1); + rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing, + -1); rb_define_method(klass, "initialize", Message_initialize, -1); rb_define_method(klass, "dup", Message_dup, 0); // Also define #clone so that we don't inherit Object#clone. @@ -1168,13 +1205,12 @@ VALUE build_class_from_descriptor(VALUE descriptor) { static VALUE enum_lookup(VALUE self, VALUE number) { int32_t num = NUM2INT(number); VALUE desc = rb_ivar_get(self, descriptor_instancevar_interned); - const upb_enumdef *e = EnumDescriptor_GetEnumDef(desc); - - const char* name = upb_enumdef_iton(e, num); - if (name == NULL) { - return Qnil; + const upb_EnumDef* e = EnumDescriptor_GetEnumDef(desc); + const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e, num); + if (ev) { + return ID2SYM(rb_intern(upb_EnumValueDef_Name(ev))); } else { - return ID2SYM(rb_intern(name)); + return Qnil; } } @@ -1188,14 +1224,12 @@ static VALUE enum_lookup(VALUE self, VALUE number) { static VALUE enum_resolve(VALUE self, VALUE sym) { const char* name = rb_id2name(SYM2ID(sym)); VALUE desc = rb_ivar_get(self, descriptor_instancevar_interned); - const upb_enumdef *e = EnumDescriptor_GetEnumDef(desc); - - int32_t num = 0; - bool found = upb_enumdef_ntoiz(e, name, &num); - if (!found) { - return Qnil; + const upb_EnumDef* e = EnumDescriptor_GetEnumDef(desc); + const upb_EnumValueDef* ev = upb_EnumDef_FindValueByName(e, name); + if (ev) { + return INT2NUM(upb_EnumValueDef_Number(ev)); } else { - return INT2NUM(num); + return Qnil; } } @@ -1211,19 +1245,19 @@ static VALUE enum_descriptor(VALUE self) { } VALUE build_module_from_enumdesc(VALUE _enumdesc) { - const upb_enumdef *e = EnumDescriptor_GetEnumDef(_enumdesc); - VALUE mod = rb_define_module_id(rb_intern(upb_enumdef_fullname(e))); - - upb_enum_iter it; - for (upb_enum_begin(&it, e); - !upb_enum_done(&it); - upb_enum_next(&it)) { - const char* name = upb_enum_iter_name(&it); - int32_t value = upb_enum_iter_number(&it); + const upb_EnumDef* e = EnumDescriptor_GetEnumDef(_enumdesc); + VALUE mod = rb_define_module_id(rb_intern(upb_EnumDef_FullName(e))); + + int n = upb_EnumDef_ValueCount(e); + for (int i = 0; i < n; i++) { + const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i); + const char* name = upb_EnumValueDef_Name(ev); + int32_t value = upb_EnumValueDef_Number(ev); if (name[0] < 'A' || name[0] > 'Z') { - rb_warn("Enum value '%s' does not start with an uppercase letter " - "as is required for Ruby constants.", - name); + rb_warn( + "Enum value '%s' does not start with an uppercase letter " + "as is required for Ruby constants.", + name); } rb_define_const(mod, name, INT2NUM(value)); } @@ -1237,80 +1271,84 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { } // Internal only; used by Google::Protobuf.deep_copy. -upb_msg* Message_deep_copy(const upb_msg* msg, const upb_msgdef* m, - upb_arena *arena) { +upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m, + upb_Arena* arena) { // Serialize and parse. - upb_arena *tmp_arena = upb_arena_new(); - const upb_msglayout *layout = upb_msgdef_layout(m); + upb_Arena* tmp_arena = upb_Arena_New(); + const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); size_t size; - char* data = upb_encode_ex(msg, layout, 0, tmp_arena, &size); - upb_msg* new_msg = upb_msg_new(m, arena); + char* data = upb_Encode(msg, layout, 0, tmp_arena, &size); + upb_Message* new_msg = upb_Message_New(m, arena); - if (!data || !upb_decode(data, size, new_msg, layout, arena)) { - upb_arena_free(tmp_arena); + if (!data || upb_Decode(data, size, new_msg, layout, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { + upb_Arena_Free(tmp_arena); rb_raise(cParseError, "Error occurred copying proto"); } - upb_arena_free(tmp_arena); + upb_Arena_Free(tmp_arena); return new_msg; } -const upb_msg* Message_GetUpbMessage(VALUE value, const upb_msgdef* m, - const char* name, upb_arena* arena) { +const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m, + const char* name, upb_Arena* arena) { if (value == Qnil) { rb_raise(cTypeError, "nil message not allowed here."); } VALUE klass = CLASS_OF(value); VALUE desc_rb = rb_ivar_get(klass, descriptor_instancevar_interned); - const upb_msgdef* val_m = + const upb_MessageDef* val_m = desc_rb == Qnil ? NULL : Descriptor_GetMsgDef(desc_rb); if (val_m != m) { // Check for possible implicit conversions // TODO: hash conversion? - switch (upb_msgdef_wellknowntype(m)) { - case UPB_WELLKNOWN_TIMESTAMP: { + switch (upb_MessageDef_WellKnownType(m)) { + case kUpb_WellKnown_Timestamp: { // Time -> Google::Protobuf::Timestamp - upb_msg *msg = upb_msg_new(m, arena); - upb_msgval sec, nsec; + upb_Message* msg = upb_Message_New(m, arena); + upb_MessageValue sec, nsec; struct timespec time; - const upb_fielddef *sec_f = upb_msgdef_itof(m, 1); - const upb_fielddef *nsec_f = upb_msgdef_itof(m, 2); + const upb_FieldDef* sec_f = + upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_FieldDef* nsec_f = + upb_MessageDef_FindFieldByNumberWithSize(m, 2); if (!rb_obj_is_kind_of(value, rb_cTime)) goto badtype; time = rb_time_timespec(value); sec.int64_val = time.tv_sec; nsec.int32_val = time.tv_nsec; - upb_msg_set(msg, sec_f, sec, arena); - upb_msg_set(msg, nsec_f, nsec, arena); + upb_Message_Set(msg, sec_f, sec, arena); + upb_Message_Set(msg, nsec_f, nsec, arena); return msg; } - case UPB_WELLKNOWN_DURATION: { + case kUpb_WellKnown_Duration: { // Numeric -> Google::Protobuf::Duration - upb_msg *msg = upb_msg_new(m, arena); - upb_msgval sec, nsec; - const upb_fielddef *sec_f = upb_msgdef_itof(m, 1); - const upb_fielddef *nsec_f = upb_msgdef_itof(m, 2); + upb_Message* msg = upb_Message_New(m, arena); + upb_MessageValue sec, nsec; + const upb_FieldDef* sec_f = + upb_MessageDef_FindFieldByNumberWithSize(m, 1); + const upb_FieldDef* nsec_f = + upb_MessageDef_FindFieldByNumberWithSize(m, 2); if (!rb_obj_is_kind_of(value, rb_cNumeric)) goto badtype; sec.int64_val = NUM2LL(value); nsec.int32_val = round((NUM2DBL(value) - NUM2LL(value)) * 1000000000); - upb_msg_set(msg, sec_f, sec, arena); - upb_msg_set(msg, nsec_f, nsec, arena); + upb_Message_Set(msg, sec_f, sec, arena); + upb_Message_Set(msg, nsec_f, nsec, arena); return msg; } default: badtype: rb_raise(cTypeError, "Invalid type %s to assign to submessage field '%s'.", - rb_class2name(CLASS_OF(value)), name); + rb_class2name(CLASS_OF(value)), name); } - } Message* self = ruby_to_Message(value); diff --git a/ruby/ext/google/protobuf_c/message.h b/ruby/ext/google/protobuf_c/message.h index 2ec440c869..b409650ef8 100644 --- a/ruby/ext/google/protobuf_c/message.h +++ b/ruby/ext/google/protobuf_c/message.h @@ -36,55 +36,58 @@ #include "protobuf.h" #include "ruby-upb.h" -// Gets the underlying upb_msg* and upb_msgdef for the given Ruby message -// wrapper. Requires that |value| is indeed a message object. -const upb_msg *Message_Get(VALUE value, const upb_msgdef **m); +// Gets the underlying upb_Message* and upb_MessageDef for the given Ruby +// message wrapper. Requires that |value| is indeed a message object. +const upb_Message* Message_Get(VALUE value, const upb_MessageDef** m); // Like Message_Get(), but checks that the object is not frozen and returns a // mutable pointer. -upb_msg *Message_GetMutable(VALUE value, const upb_msgdef **m); +upb_Message* Message_GetMutable(VALUE value, const upb_MessageDef** m); // Returns the Arena object for this message. VALUE Message_GetArena(VALUE value); -// Converts |value| into a upb_msg value of the expected upb_msgdef type, -// raising an error if this is not possible. Used when assigning |value| to a -// field of another message, which means the message must be of a particular -// type. +// Converts |value| into a upb_Message value of the expected upb_MessageDef +// type, raising an error if this is not possible. Used when assigning |value| +// to a field of another message, which means the message must be of a +// particular type. // // This will perform automatic conversions in some cases (for example, Time -> // Google::Protobuf::Timestamp). If any new message is created, it will be // created on |arena|, and any existing message will have its arena fused with // |arena|. -const upb_msg* Message_GetUpbMessage(VALUE value, const upb_msgdef* m, - const char* name, upb_arena* arena); +const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m, + const char* name, upb_Arena* arena); // Gets or constructs a Ruby wrapper object for the given message. The wrapper // object will reference |arena| and ensure that it outlives this object. -VALUE Message_GetRubyWrapper(upb_msg* msg, const upb_msgdef* m, VALUE arena); +VALUE Message_GetRubyWrapper(upb_Message* msg, const upb_MessageDef* m, + VALUE arena); // Gets the given field from this message. -VALUE Message_getfield(VALUE _self, const upb_fielddef* f); +VALUE Message_getfield(VALUE _self, const upb_FieldDef* f); // Implements #inspect for this message, printing the text to |b|. -void Message_PrintMessage(StringBuilder* b, const upb_msg* msg, - const upb_msgdef* m); +void Message_PrintMessage(StringBuilder* b, const upb_Message* msg, + const upb_MessageDef* m); // Returns a hash value for the given message. -uint64_t Message_Hash(const upb_msg *msg, const upb_msgdef *m, uint64_t seed); +uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m, + uint64_t seed); // Returns a deep copy of the given message. -upb_msg* Message_deep_copy(const upb_msg* msg, const upb_msgdef* m, - upb_arena *arena); +upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m, + upb_Arena* arena); // Returns true if these two messages are equal. -bool Message_Equal(const upb_msg *m1, const upb_msg *m2, const upb_msgdef *m); +bool Message_Equal(const upb_Message* m1, const upb_Message* m2, + const upb_MessageDef* m); // Checks that this Ruby object is a message, and raises an exception if not. void Message_CheckClass(VALUE klass); // Returns a new Hash object containing the contents of this message. -VALUE Scalar_CreateHash(upb_msgval val, TypeInfo type_info); +VALUE Scalar_CreateHash(upb_MessageValue val, TypeInfo type_info); // Creates a message class or enum module for this descriptor, respectively. VALUE build_class_from_descriptor(VALUE descriptor); diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index a61328b442..4d3e1a5144 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c @@ -40,14 +40,14 @@ VALUE cParseError; VALUE cTypeError; -const upb_fielddef* map_field_key(const upb_fielddef* field) { - const upb_msgdef *entry = upb_fielddef_msgsubdef(field); - return upb_msgdef_itof(entry, 1); +const upb_FieldDef *map_field_key(const upb_FieldDef *field) { + const upb_MessageDef *entry = upb_FieldDef_MessageSubDef(field); + return upb_MessageDef_FindFieldByNumberWithSize(entry, 1); } -const upb_fielddef* map_field_value(const upb_fielddef* field) { - const upb_msgdef *entry = upb_fielddef_msgsubdef(field); - return upb_msgdef_itof(entry, 2); +const upb_FieldDef *map_field_value(const upb_FieldDef *field) { + const upb_MessageDef *entry = upb_FieldDef_MessageSubDef(field); + return upb_MessageDef_FindFieldByNumberWithSize(entry, 2); } // ----------------------------------------------------------------------------- @@ -66,21 +66,21 @@ static size_t StringBuilder_SizeOf(size_t cap) { return sizeof(StringBuilder) + cap; } -StringBuilder* StringBuilder_New() { +StringBuilder *StringBuilder_New() { const size_t cap = 128; - StringBuilder* builder = malloc(sizeof(*builder)); + StringBuilder *builder = malloc(sizeof(*builder)); builder->size = 0; builder->cap = cap; builder->data = malloc(builder->cap); return builder; } -void StringBuilder_Free(StringBuilder* b) { +void StringBuilder_Free(StringBuilder *b) { free(b->data); free(b); } -void StringBuilder_Printf(StringBuilder* b, const char *fmt, ...) { +void StringBuilder_Printf(StringBuilder *b, const char *fmt, ...) { size_t have = b->cap - b->size; size_t n; va_list args; @@ -104,60 +104,62 @@ void StringBuilder_Printf(StringBuilder* b, const char *fmt, ...) { b->size += n; } -VALUE StringBuilder_ToRubyString(StringBuilder* b) { +VALUE StringBuilder_ToRubyString(StringBuilder *b) { VALUE ret = rb_str_new(b->data, b->size); rb_enc_associate(ret, rb_utf8_encoding()); return ret; } -static void StringBuilder_PrintEnum(StringBuilder* b, int32_t val, - const upb_enumdef* e) { - const char *name = upb_enumdef_iton(e, val); - if (name) { - StringBuilder_Printf(b, ":%s", name); +static void StringBuilder_PrintEnum(StringBuilder *b, int32_t val, + const upb_EnumDef *e) { + const upb_EnumValueDef *ev = upb_EnumDef_FindValueByNumber(e, val); + if (ev) { + StringBuilder_Printf(b, ":%s", upb_EnumValueDef_Name(ev)); } else { StringBuilder_Printf(b, "%" PRId32, val); } } -void StringBuilder_PrintMsgval(StringBuilder* b, upb_msgval val, +void StringBuilder_PrintMsgval(StringBuilder *b, upb_MessageValue val, TypeInfo info) { switch (info.type) { - case UPB_TYPE_BOOL: + case kUpb_CType_Bool: StringBuilder_Printf(b, "%s", val.bool_val ? "true" : "false"); break; - case UPB_TYPE_FLOAT: { + case kUpb_CType_Float: { VALUE str = rb_inspect(DBL2NUM(val.float_val)); StringBuilder_Printf(b, "%s", RSTRING_PTR(str)); break; } - case UPB_TYPE_DOUBLE: { + case kUpb_CType_Double: { VALUE str = rb_inspect(DBL2NUM(val.double_val)); StringBuilder_Printf(b, "%s", RSTRING_PTR(str)); break; } - case UPB_TYPE_INT32: + case kUpb_CType_Int32: StringBuilder_Printf(b, "%" PRId32, val.int32_val); break; - case UPB_TYPE_UINT32: + case kUpb_CType_UInt32: StringBuilder_Printf(b, "%" PRIu32, val.uint32_val); break; - case UPB_TYPE_INT64: + case kUpb_CType_Int64: StringBuilder_Printf(b, "%" PRId64, val.int64_val); break; - case UPB_TYPE_UINT64: + case kUpb_CType_UInt64: StringBuilder_Printf(b, "%" PRIu64, val.uint64_val); break; - case UPB_TYPE_STRING: - StringBuilder_Printf(b, "\"%.*s\"", (int)val.str_val.size, val.str_val.data); + case kUpb_CType_String: + StringBuilder_Printf(b, "\"%.*s\"", (int)val.str_val.size, + val.str_val.data); break; - case UPB_TYPE_BYTES: - StringBuilder_Printf(b, "\"%.*s\"", (int)val.str_val.size, val.str_val.data); + case kUpb_CType_Bytes: + StringBuilder_Printf(b, "\"%.*s\"", (int)val.str_val.size, + val.str_val.data); break; - case UPB_TYPE_ENUM: + case kUpb_CType_Enum: StringBuilder_PrintEnum(b, val.int32_val, info.def.enumdef); break; - case UPB_TYPE_MESSAGE: + case kUpb_CType_Message: Message_PrintMessage(b, val.msg_val, info.def.msgdef); break; } @@ -168,7 +170,7 @@ void StringBuilder_PrintMsgval(StringBuilder* b, upb_msgval val, // ----------------------------------------------------------------------------- typedef struct { - upb_arena *arena; + upb_Arena *arena; VALUE pinned_objs; } Arena; @@ -179,44 +181,42 @@ static void Arena_mark(void *data) { static void Arena_free(void *data) { Arena *arena = data; - upb_arena_free(arena->arena); + upb_Arena_Free(arena->arena); xfree(arena); } static VALUE cArena; const rb_data_type_t Arena_type = { - "Google::Protobuf::Internal::Arena", - { Arena_mark, Arena_free, NULL }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Google::Protobuf::Internal::Arena", + {Arena_mark, Arena_free, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; static VALUE Arena_alloc(VALUE klass) { Arena *arena = ALLOC(Arena); - arena->arena = upb_arena_new(); + arena->arena = upb_Arena_New(); arena->pinned_objs = Qnil; return TypedData_Wrap_Struct(klass, &Arena_type, arena); } -upb_arena *Arena_get(VALUE _arena) { +upb_Arena *Arena_get(VALUE _arena) { Arena *arena; TypedData_Get_Struct(_arena, Arena, &Arena_type, arena); return arena->arena; } -void Arena_fuse(VALUE _arena, upb_arena *other) { +void Arena_fuse(VALUE _arena, upb_Arena *other) { Arena *arena; TypedData_Get_Struct(_arena, Arena, &Arena_type, arena); - if (!upb_arena_fuse(arena->arena, other)) { + if (!upb_Arena_Fuse(arena->arena, other)) { rb_raise(rb_eRuntimeError, "Unable to fuse arenas. This should never happen since Ruby does " "not use initial blocks"); } } -VALUE Arena_new() { - return Arena_alloc(cArena); -} +VALUE Arena_new() { return Arena_alloc(cArena); } void Arena_Pin(VALUE _arena, VALUE obj) { Arena *arena; @@ -333,8 +333,8 @@ static void SecondaryMap_MaybeGC() { // avoid O(N^2) CPU costs. size_t threshold = PBRUBY_MAX(secondary_len * 0.2, 2000); if (waste > threshold) { - rb_funcall(gc_secondary_map_lambda, rb_intern("call"), 2, - secondary_map, weak_obj_cache); + rb_funcall(gc_secondary_map_lambda, rb_intern("call"), 2, secondary_map, + weak_obj_cache); } } @@ -353,7 +353,7 @@ static VALUE SecondaryMap_Get(VALUE key, bool create) { #endif // Requires: secondary_map_mutex is held by this thread iff create == true. -static VALUE ObjectCache_GetKey(const void* key, bool create) { +static VALUE ObjectCache_GetKey(const void *key, bool create) { VALUE key_val = (VALUE)key; PBRUBY_ASSERT((key_val & 3) == 0); VALUE ret = LL2NUM(key_val >> 2); @@ -380,7 +380,7 @@ static void ObjectCache_Init() { #endif } -void ObjectCache_Add(const void* key, VALUE val) { +void ObjectCache_Add(const void *key, VALUE val) { PBRUBY_ASSERT(ObjectCache_Get(key) == Qnil); #if USE_SECONDARY_MAP rb_mutex_lock(secondary_map_mutex); @@ -394,7 +394,7 @@ void ObjectCache_Add(const void* key, VALUE val) { } // Returns the cached object for this key, if any. Otherwise returns Qnil. -VALUE ObjectCache_Get(const void* key) { +VALUE ObjectCache_Get(const void *key) { VALUE key_rb = ObjectCache_GetKey(key, false); return rb_funcall(weak_obj_cache, item_get, 1, key_rb); } @@ -407,9 +407,9 @@ VALUE ObjectCache_Get(const void* key) { * unknown fields in submessages. */ static VALUE Google_Protobuf_discard_unknown(VALUE self, VALUE msg_rb) { - const upb_msgdef *m; - upb_msg *msg = Message_GetMutable(msg_rb, &m); - if (!upb_msg_discardunknown(msg, m, 128)) { + const upb_MessageDef *m; + upb_Message *msg = Message_GetMutable(msg_rb, &m); + if (!upb_Message_DiscardUnknown(msg, m, 128)) { rb_raise(rb_eRuntimeError, "Messages nested too deeply."); } @@ -431,10 +431,10 @@ VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj) { return Map_deep_copy(obj); } else { VALUE new_arena_rb = Arena_new(); - upb_arena *new_arena = Arena_get(new_arena_rb); - const upb_msgdef *m; - const upb_msg *msg = Message_Get(obj, &m); - upb_msg* new_msg = Message_deep_copy(msg, m, new_arena); + upb_Arena *new_arena = Arena_get(new_arena_rb); + const upb_MessageDef *m; + const upb_Message *msg = Message_Get(obj, &m); + upb_Message *new_msg = Message_deep_copy(msg, m, new_arena); return Message_GetRubyWrapper(new_msg, m, new_arena_rb); } } @@ -445,8 +445,7 @@ VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj) { // This must be named "Init_protobuf_c" because the Ruby module is named // "protobuf_c" -- the VM looks for this symbol in our .so. -__attribute__ ((visibility ("default"))) -void Init_protobuf_c() { +__attribute__((visibility("default"))) void Init_protobuf_c() { ObjectCache_Init(); VALUE google = rb_define_module("Google"); @@ -465,6 +464,6 @@ void Init_protobuf_c() { rb_define_singleton_method(protobuf, "discard_unknown", Google_Protobuf_discard_unknown, 1); - rb_define_singleton_method(protobuf, "deep_copy", - Google_Protobuf_deep_copy, 1); + rb_define_singleton_method(protobuf, "deep_copy", Google_Protobuf_deep_copy, + 1); } diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index f7ac2049d7..c6af98fa47 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -31,33 +31,33 @@ #ifndef __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__ #define __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__ +#include #include #include -#include -#include "ruby-upb.h" #include "defs.h" +#include "ruby-upb.h" // These operate on a map field (i.e., a repeated field of submessages whose // submessage type is a map-entry msgdef). -const upb_fielddef* map_field_key(const upb_fielddef* field); -const upb_fielddef* map_field_value(const upb_fielddef* field); +const upb_FieldDef* map_field_key(const upb_FieldDef* field); +const upb_FieldDef* map_field_value(const upb_FieldDef* field); // ----------------------------------------------------------------------------- // Arena // ----------------------------------------------------------------------------- -// A Ruby object that wraps an underlying upb_arena. Any objects that are +// A Ruby object that wraps an underlying upb_Arena. Any objects that are // allocated from this arena should reference the Arena in rb_gc_mark(), to // ensure that the object's underlying memory outlives any Ruby object that can // reach it. VALUE Arena_new(); -upb_arena *Arena_get(VALUE arena); +upb_Arena* Arena_get(VALUE arena); // Fuses this arena to another, throwing a Ruby exception if this is not // possible. -void Arena_fuse(VALUE arena, upb_arena *other); +void Arena_fuse(VALUE arena, upb_Arena* other); // Pins this Ruby object to the lifetime of this arena, so that as long as the // arena is alive this object will not be collected. @@ -93,10 +93,11 @@ typedef struct StringBuilder StringBuilder; StringBuilder* StringBuilder_New(); void StringBuilder_Free(StringBuilder* b); -void StringBuilder_Printf(StringBuilder* b, const char *fmt, ...); +void StringBuilder_Printf(StringBuilder* b, const char* fmt, ...); VALUE StringBuilder_ToRubyString(StringBuilder* b); -void StringBuilder_PrintMsgval(StringBuilder* b, upb_msgval val, TypeInfo info); +void StringBuilder_PrintMsgval(StringBuilder* b, upb_MessageValue val, + TypeInfo info); // ----------------------------------------------------------------------------- // Utilities. @@ -105,7 +106,9 @@ void StringBuilder_PrintMsgval(StringBuilder* b, upb_msgval val, TypeInfo info); extern VALUE cTypeError; #ifdef NDEBUG -#define PBRUBY_ASSERT(expr) do {} while (false && (expr)) +#define PBRUBY_ASSERT(expr) \ + do { \ + } while (false && (expr)) #else #define PBRUBY_ASSERT(expr) assert(expr) #endif diff --git a/ruby/ext/google/protobuf_c/repeated_field.c b/ruby/ext/google/protobuf_c/repeated_field.c index 5ff3c769ac..700ca16f38 100644 --- a/ruby/ext/google/protobuf_c/repeated_field.c +++ b/ruby/ext/google/protobuf_c/repeated_field.c @@ -40,10 +40,10 @@ // ----------------------------------------------------------------------------- typedef struct { - const upb_array *array; // Can get as mutable when non-frozen. + const upb_Array* array; // Can get as mutable when non-frozen. TypeInfo type_info; VALUE type_class; // To GC-root the msgdef/enumdef in type_info. - VALUE arena; // To GC-root the upb_array. + VALUE arena; // To GC-root the upb_Array. } RepeatedField; VALUE cRepeatedField; @@ -55,9 +55,9 @@ static void RepeatedField_mark(void* _self) { } const rb_data_type_t RepeatedField_type = { - "Google::Protobuf::RepeatedField", - { RepeatedField_mark, RUBY_DEFAULT_FREE, NULL }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY, + "Google::Protobuf::RepeatedField", + {RepeatedField_mark, RUBY_DEFAULT_FREE, NULL}, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, }; static RepeatedField* ruby_to_RepeatedField(VALUE _self) { @@ -66,9 +66,9 @@ static RepeatedField* ruby_to_RepeatedField(VALUE _self) { return self; } -static upb_array *RepeatedField_GetMutable(VALUE _self) { +static upb_Array* RepeatedField_GetMutable(VALUE _self) { rb_check_frozen(_self); - return (upb_array*)ruby_to_RepeatedField(_self)->array; + return (upb_Array*)ruby_to_RepeatedField(_self)->array; } VALUE RepeatedField_alloc(VALUE klass) { @@ -79,7 +79,7 @@ VALUE RepeatedField_alloc(VALUE klass) { return TypedData_Wrap_Struct(klass, &RepeatedField_type, self); } -VALUE RepeatedField_GetRubyWrapper(upb_array* array, TypeInfo type_info, +VALUE RepeatedField_GetRubyWrapper(upb_Array* array, TypeInfo type_info, VALUE arena) { PBRUBY_ASSERT(array); VALUE val = ObjectCache_Get(array); @@ -92,7 +92,7 @@ VALUE RepeatedField_GetRubyWrapper(upb_array* array, TypeInfo type_info, self->array = array; self->arena = arena; self->type_info = type_info; - if (self->type_info.type == UPB_TYPE_MESSAGE) { + if (self->type_info.type == kUpb_CType_Message) { self->type_class = Descriptor_DefToClass(type_info.def.msgdef); } } @@ -105,24 +105,24 @@ VALUE RepeatedField_GetRubyWrapper(upb_array* array, TypeInfo type_info, static VALUE RepeatedField_new_this_type(RepeatedField* from) { VALUE arena_rb = Arena_new(); - upb_array *array = upb_array_new(Arena_get(arena_rb), from->type_info.type); + upb_Array* array = upb_Array_New(Arena_get(arena_rb), from->type_info.type); VALUE ret = RepeatedField_GetRubyWrapper(array, from->type_info, arena_rb); PBRUBY_ASSERT(ruby_to_RepeatedField(ret)->type_class == from->type_class); return ret; } -void RepeatedField_Inspect(StringBuilder* b, const upb_array* array, +void RepeatedField_Inspect(StringBuilder* b, const upb_Array* array, TypeInfo info) { bool first = true; StringBuilder_Printf(b, "["); - size_t n = array ? upb_array_size(array) : 0; + size_t n = array ? upb_Array_Size(array) : 0; for (size_t i = 0; i < n; i++) { if (first) { first = false; } else { StringBuilder_Printf(b, ", "); } - StringBuilder_PrintMsgval(b, upb_array_get(array, i), info); + StringBuilder_PrintMsgval(b, upb_Array_Get(array, i), info); } StringBuilder_Printf(b, "]"); } @@ -132,24 +132,24 @@ VALUE RepeatedField_deep_copy(VALUE _self) { VALUE new_rptfield = RepeatedField_new_this_type(self); RepeatedField* new_self = ruby_to_RepeatedField(new_rptfield); VALUE arena_rb = new_self->arena; - upb_array *new_array = RepeatedField_GetMutable(new_rptfield); - upb_arena *arena = Arena_get(arena_rb); - size_t elements = upb_array_size(self->array); + upb_Array* new_array = RepeatedField_GetMutable(new_rptfield); + upb_Arena* arena = Arena_get(arena_rb); + size_t elements = upb_Array_Size(self->array); - upb_array_resize(new_array, elements, arena); + upb_Array_Resize(new_array, elements, arena); - size_t size = upb_array_size(self->array); + size_t size = upb_Array_Size(self->array); for (size_t i = 0; i < size; i++) { - upb_msgval msgval = upb_array_get(self->array, i); - upb_msgval copy = Msgval_DeepCopy(msgval, self->type_info, arena); - upb_array_set(new_array, i, copy); + upb_MessageValue msgval = upb_Array_Get(self->array, i); + upb_MessageValue copy = Msgval_DeepCopy(msgval, self->type_info, arena); + upb_Array_Set(new_array, i, copy); } return new_rptfield; } -const upb_array* RepeatedField_GetUpbArray(VALUE val, const upb_fielddef* field, - upb_arena* arena) { +const upb_Array* RepeatedField_GetUpbArray(VALUE val, const upb_FieldDef* field, + upb_Arena* arena) { RepeatedField* self; TypeInfo type_info = TypeInfo_get(field); @@ -173,17 +173,17 @@ const upb_array* RepeatedField_GetUpbArray(VALUE val, const upb_fielddef* field, static int index_position(VALUE _index, RepeatedField* repeated_field) { int index = NUM2INT(_index); - if (index < 0) index += upb_array_size(repeated_field->array); + if (index < 0) index += upb_Array_Size(repeated_field->array); return index; } static VALUE RepeatedField_subarray(RepeatedField* self, long beg, long len) { - size_t size = upb_array_size(self->array); + size_t size = upb_Array_Size(self->array); VALUE ary = rb_ary_new2(size); long i; for (i = beg; i < beg + len; i++) { - upb_msgval msgval = upb_array_get(self->array, i); + upb_MessageValue msgval = upb_Array_Get(self->array, i); VALUE elem = Convert_UpbToRuby(msgval, self->type_info, self->arena); rb_ary_push(ary, elem); } @@ -200,18 +200,17 @@ static VALUE RepeatedField_subarray(RepeatedField* self, long beg, long len) { */ static VALUE RepeatedField_each(VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - int size = upb_array_size(self->array); + int size = upb_Array_Size(self->array); int i; for (i = 0; i < size; i++) { - upb_msgval msgval = upb_array_get(self->array, i); + upb_MessageValue msgval = upb_Array_Get(self->array, i); VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena); rb_yield(val); } return _self; } - /* * call-seq: * RepeatedField.[](index) => value @@ -220,20 +219,20 @@ static VALUE RepeatedField_each(VALUE _self) { */ static VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - long size = upb_array_size(self->array); + long size = upb_Array_Size(self->array); VALUE arg = argv[0]; long beg, len; - if (argc == 1){ + if (argc == 1) { if (FIXNUM_P(arg)) { /* standard case */ - upb_msgval msgval; + upb_MessageValue msgval; int index = index_position(argv[0], self); - if (index < 0 || (size_t)index >= upb_array_size(self->array)) { + if (index < 0 || (size_t)index >= upb_Array_Size(self->array)) { return Qnil; } - msgval = upb_array_get(self->array, index); + msgval = upb_Array_Get(self->array, index); return Convert_UpbToRuby(msgval, self->type_info, self->arena); } else { /* check if idx is Range */ @@ -269,10 +268,10 @@ static VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) { */ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) { RepeatedField* self = ruby_to_RepeatedField(_self); - int size = upb_array_size(self->array); - upb_array *array = RepeatedField_GetMutable(_self); - upb_arena *arena = Arena_get(self->arena); - upb_msgval msgval = Convert_RubyToUpb(val, "", self->type_info, arena); + int size = upb_Array_Size(self->array); + upb_Array* array = RepeatedField_GetMutable(_self); + upb_Arena* arena = Arena_get(self->arena); + upb_MessageValue msgval = Convert_RubyToUpb(val, "", self->type_info, arena); int index = index_position(_index, self); if (index < 0 || index >= (INT_MAX - 1)) { @@ -280,17 +279,17 @@ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) { } if (index >= size) { - upb_array_resize(array, index + 1, arena); - upb_msgval fill; + upb_Array_Resize(array, index + 1, arena); + upb_MessageValue fill; memset(&fill, 0, sizeof(fill)); for (int i = size; i < index; i++) { // Fill default values. // TODO(haberman): should this happen at the upb level? - upb_array_set(array, i, fill); + upb_Array_Set(array, i, fill); } } - upb_array_set(array, index, msgval); + upb_Array_Set(array, index, msgval); return Qnil; } @@ -302,13 +301,14 @@ static VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) { */ static VALUE RepeatedField_push_vararg(int argc, VALUE* argv, VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - upb_arena *arena = Arena_get(self->arena); - upb_array *array = RepeatedField_GetMutable(_self); + upb_Arena* arena = Arena_get(self->arena); + upb_Array* array = RepeatedField_GetMutable(_self); int i; for (i = 0; i < argc; i++) { - upb_msgval msgval = Convert_RubyToUpb(argv[i], "", self->type_info, arena); - upb_array_append(array, msgval, arena); + upb_MessageValue msgval = + Convert_RubyToUpb(argv[i], "", self->type_info, arena); + upb_Array_Append(array, msgval, arena); } return _self; @@ -322,11 +322,11 @@ static VALUE RepeatedField_push_vararg(int argc, VALUE* argv, VALUE _self) { */ static VALUE RepeatedField_push(VALUE _self, VALUE val) { RepeatedField* self = ruby_to_RepeatedField(_self); - upb_arena *arena = Arena_get(self->arena); - upb_array *array = RepeatedField_GetMutable(_self); + upb_Arena* arena = Arena_get(self->arena); + upb_Array* array = RepeatedField_GetMutable(_self); - upb_msgval msgval = Convert_RubyToUpb(val, "", self->type_info, arena); - upb_array_append(array, msgval, arena); + upb_MessageValue msgval = Convert_RubyToUpb(val, "", self->type_info, arena); + upb_Array_Append(array, msgval, arena); return _self; } @@ -336,19 +336,19 @@ static VALUE RepeatedField_push(VALUE _self, VALUE val) { */ static VALUE RepeatedField_pop_one(VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - size_t size = upb_array_size(self->array); - upb_array *array = RepeatedField_GetMutable(_self); - upb_msgval last; + size_t size = upb_Array_Size(self->array); + upb_Array* array = RepeatedField_GetMutable(_self); + upb_MessageValue last; VALUE ret; if (size == 0) { return Qnil; } - last = upb_array_get(self->array, size - 1); + last = upb_Array_Get(self->array, size - 1); ret = Convert_UpbToRuby(last, self->type_info, self->arena); - upb_array_resize(array, size - 1, Arena_get(self->arena)); + upb_Array_Resize(array, size - 1, Arena_get(self->arena)); return ret; } @@ -360,11 +360,11 @@ static VALUE RepeatedField_pop_one(VALUE _self) { */ static VALUE RepeatedField_replace(VALUE _self, VALUE list) { RepeatedField* self = ruby_to_RepeatedField(_self); - upb_array *array = RepeatedField_GetMutable(_self); + upb_Array* array = RepeatedField_GetMutable(_self); int i; Check_Type(list, T_ARRAY); - upb_array_resize(array, 0, Arena_get(self->arena)); + upb_Array_Resize(array, 0, Arena_get(self->arena)); for (i = 0; i < RARRAY_LEN(list); i++) { RepeatedField_push(_self, rb_ary_entry(list, i)); @@ -381,8 +381,8 @@ static VALUE RepeatedField_replace(VALUE _self, VALUE list) { */ static VALUE RepeatedField_clear(VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - upb_array *array = RepeatedField_GetMutable(_self); - upb_array_resize(array, 0, Arena_get(self->arena)); + upb_Array* array = RepeatedField_GetMutable(_self); + upb_Array_Resize(array, 0, Arena_get(self->arena)); return _self; } @@ -394,7 +394,7 @@ static VALUE RepeatedField_clear(VALUE _self) { */ static VALUE RepeatedField_length(VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - return INT2NUM(upb_array_size(self->array)); + return INT2NUM(upb_Array_Size(self->array)); } /* @@ -408,16 +408,16 @@ static VALUE RepeatedField_dup(VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); VALUE new_rptfield = RepeatedField_new_this_type(self); RepeatedField* new_rptfield_self = ruby_to_RepeatedField(new_rptfield); - upb_array *new_array = RepeatedField_GetMutable(new_rptfield); - upb_arena* arena = Arena_get(new_rptfield_self->arena); - int size = upb_array_size(self->array); + upb_Array* new_array = RepeatedField_GetMutable(new_rptfield); + upb_Arena* arena = Arena_get(new_rptfield_self->arena); + int size = upb_Array_Size(self->array); int i; Arena_fuse(self->arena, arena); for (i = 0; i < size; i++) { - upb_msgval msgval = upb_array_get(self->array, i); - upb_array_append(new_array, msgval, arena); + upb_MessageValue msgval = upb_Array_Get(self->array, i); + upb_Array_Append(new_array, msgval, arena); } return new_rptfield; @@ -432,12 +432,12 @@ static VALUE RepeatedField_dup(VALUE _self) { */ VALUE RepeatedField_to_ary(VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - int size = upb_array_size(self->array); + int size = upb_Array_Size(self->array); VALUE ary = rb_ary_new2(size); int i; for (i = 0; i < size; i++) { - upb_msgval msgval = upb_array_get(self->array, i); + upb_MessageValue msgval = upb_Array_Get(self->array, i); VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena); rb_ary_push(ary, val); } @@ -473,17 +473,17 @@ VALUE RepeatedField_eq(VALUE _self, VALUE _other) { self = ruby_to_RepeatedField(_self); other = ruby_to_RepeatedField(_other); - size_t n = upb_array_size(self->array); + size_t n = upb_Array_Size(self->array); if (self->type_info.type != other->type_info.type || self->type_class != other->type_class || - upb_array_size(other->array) != n) { + upb_Array_Size(other->array) != n) { return Qfalse; } for (size_t i = 0; i < n; i++) { - upb_msgval val1 = upb_array_get(self->array, i); - upb_msgval val2 = upb_array_get(other->array, i); + upb_MessageValue val1 = upb_Array_Get(self->array, i); + upb_MessageValue val2 = upb_Array_Get(other->array, i); if (!Msgval_IsEqual(val1, val2, self->type_info)) { return Qfalse; } @@ -517,10 +517,10 @@ static VALUE RepeatedField_freeze(VALUE _self) { VALUE RepeatedField_hash(VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); uint64_t hash = 0; - size_t n = upb_array_size(self->array); + size_t n = upb_Array_Size(self->array); for (size_t i = 0; i < n; i++) { - upb_msgval val = upb_array_get(self->array, i); + upb_MessageValue val = upb_Array_Get(self->array, i); hash = Msgval_GetHash(val, self->type_info, hash); } @@ -549,10 +549,10 @@ VALUE RepeatedField_plus(VALUE _self, VALUE list) { RepeatedField* self = ruby_to_RepeatedField(_self); RepeatedField* list_rptfield = ruby_to_RepeatedField(list); RepeatedField* dupped = ruby_to_RepeatedField(dupped_); - upb_array *dupped_array = RepeatedField_GetMutable(dupped_); - upb_arena* arena = Arena_get(dupped->arena); + upb_Array* dupped_array = RepeatedField_GetMutable(dupped_); + upb_Arena* arena = Arena_get(dupped->arena); Arena_fuse(list_rptfield->arena, arena); - int size = upb_array_size(list_rptfield->array); + int size = upb_Array_Size(list_rptfield->array); int i; if (self->type_info.type != list_rptfield->type_info.type || @@ -562,8 +562,8 @@ VALUE RepeatedField_plus(VALUE _self, VALUE list) { } for (i = 0; i < size; i++) { - upb_msgval msgval = upb_array_get(list_rptfield->array, i); - upb_array_append(dupped_array, msgval, arena); + upb_MessageValue msgval = upb_Array_Get(list_rptfield->array, i); + upb_Array_Append(dupped_array, msgval, arena); } } else { rb_raise(rb_eArgError, "Unknown type appending to RepeatedField"); @@ -601,7 +601,7 @@ VALUE RepeatedField_concat(VALUE _self, VALUE list) { */ VALUE RepeatedField_init(int argc, VALUE* argv, VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - upb_arena *arena; + upb_Arena* arena; VALUE ary = Qnil; self->arena = Arena_new(); @@ -612,7 +612,7 @@ VALUE RepeatedField_init(int argc, VALUE* argv, VALUE _self) { } self->type_info = TypeInfo_FromClass(argc, argv, 0, &self->type_class, &ary); - self->array = upb_array_new(arena, self->type_info.type); + self->array = upb_Array_New(arena, self->type_info.type); ObjectCache_Add(self->array, _self); if (ary != Qnil) { @@ -627,14 +627,12 @@ VALUE RepeatedField_init(int argc, VALUE* argv, VALUE _self) { } void RepeatedField_register(VALUE module) { - VALUE klass = rb_define_class_under( - module, "RepeatedField", rb_cObject); + VALUE klass = rb_define_class_under(module, "RepeatedField", rb_cObject); rb_define_alloc_func(klass, RepeatedField_alloc); rb_gc_register_address(&cRepeatedField); cRepeatedField = klass; - rb_define_method(klass, "initialize", - RepeatedField_init, -1); + rb_define_method(klass, "initialize", RepeatedField_init, -1); rb_define_method(klass, "each", RepeatedField_each, 0); rb_define_method(klass, "[]", RepeatedField_index, -1); rb_define_method(klass, "at", RepeatedField_index, -1); diff --git a/ruby/ext/google/protobuf_c/repeated_field.h b/ruby/ext/google/protobuf_c/repeated_field.h index e4ef252924..b0581635b8 100644 --- a/ruby/ext/google/protobuf_c/repeated_field.h +++ b/ruby/ext/google/protobuf_c/repeated_field.h @@ -36,19 +36,19 @@ #include "protobuf.h" #include "ruby-upb.h" -// Returns a Ruby wrapper object for the given upb_array, which will be created +// Returns a Ruby wrapper object for the given upb_Array, which will be created // if one does not exist already. -VALUE RepeatedField_GetRubyWrapper(upb_array* msg, TypeInfo type_info, +VALUE RepeatedField_GetRubyWrapper(upb_Array* msg, TypeInfo type_info, VALUE arena); -// Gets the underlying upb_array for this Ruby RepeatedField object, which must +// Gets the underlying upb_Array for this Ruby RepeatedField object, which must // have a type that matches |f|. If this is not a repeated field or the type // doesn't match, raises an exception. -const upb_array* RepeatedField_GetUpbArray(VALUE value, const upb_fielddef* f, - upb_arena* arena); +const upb_Array* RepeatedField_GetUpbArray(VALUE value, const upb_FieldDef* f, + upb_Arena* arena); // Implements #inspect for this repeated field by appending its contents to |b|. -void RepeatedField_Inspect(StringBuilder* b, const upb_array* array, +void RepeatedField_Inspect(StringBuilder* b, const upb_Array* array, TypeInfo info); // Returns a deep copy of this RepeatedField object. diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 294be7f198..79a480eff6 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -2624,7 +2624,7 @@ static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { return low ^ high; } -static uint64_t Wyhash(const void* data, size_t len, uint64_t seed, +uint64_t Wyhash(const void* data, size_t len, uint64_t seed, const uint64_t salt[]) { const uint8_t* ptr = (const uint8_t*)data; uint64_t starting_length = (uint64_t)len; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 276f6b1095..369861c508 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -786,6 +786,10 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, extern "C" { #endif +uint64_t Wyhash(const void* data, size_t len, uint64_t seed, + const uint64_t salt[]); +extern const uint64_t kWyhashSalt[5]; + /* upb_value ******************************************************************/ typedef struct { diff --git a/ruby/ext/google/protobuf_c/wrap_memcpy.c b/ruby/ext/google/protobuf_c/wrap_memcpy.c index 18c036780c..6bbd4bad35 100644 --- a/ruby/ext/google/protobuf_c/wrap_memcpy.c +++ b/ruby/ext/google/protobuf_c/wrap_memcpy.c @@ -33,7 +33,8 @@ // On x86-64 Linux with glibc, we link against the 2.2.5 version of memcpy so // that we avoid depending on the 2.14 version of the symbol. This way, // distributions that are using pre-2.14 versions of glibc can successfully use -// the gem we distribute (https://github.com/protocolbuffers/protobuf/issues/2783). +// the gem we distribute +// (https://github.com/protocolbuffers/protobuf/issues/2783). // // This wrapper is enabled by passing the linker flags -Wl,-wrap,memcpy in // extconf.rb. @@ -41,11 +42,11 @@ #if defined(__x86_64__) && defined(__GNU_LIBRARY__) __asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); void *__wrap_memcpy(void *dest, const void *src, size_t n) { - return memcpy(dest, src, n); + return memcpy(dest, src, n); } #else void *__wrap_memcpy(void *dest, const void *src, size_t n) { - return memmove(dest, src, n); + return memmove(dest, src, n); } #endif #endif diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb index 3d9f67eb93..3ab9a0ca84 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -816,11 +816,17 @@ module CommonTests :optional_enum => :B, :repeated_string => ["a", "b", "c"], :repeated_int32 => [42, 43, 44], - :repeated_enum => [:A, :B, :C, 100], + :repeated_enum => [:A, :B, :C], :repeated_msg => [proto_module::TestMessage2.new(:foo => 1), proto_module::TestMessage2.new(:foo => 2)]) + if proto_module == ::BasicTest + # For proto3 we can add an unknown enum value safely. + m.repeated_enum << 100 + end + data = proto_module::TestMessage.encode m m2 = proto_module::TestMessage.decode data + assert_equal m, m2 data = Google::Protobuf.encode m From 706ed2d17a0dbb844b1197d9b7788e4d066b0fc6 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 21 Jan 2022 17:32:34 -0800 Subject: [PATCH 150/207] Added utf8_range.c as a source file. --- ruby/ext/google/protobuf_c/extconf.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ruby/ext/google/protobuf_c/extconf.rb b/ruby/ext/google/protobuf_c/extconf.rb index ec17787f79..d8f081a431 100755 --- a/ruby/ext/google/protobuf_c/extconf.rb +++ b/ruby/ext/google/protobuf_c/extconf.rb @@ -2,6 +2,10 @@ require 'mkmf' +ext_name = "google/protobuf_c" + +dir_config(ext_name) + if RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/ $CFLAGS += " -std=gnu99 -O3 -DNDEBUG -fvisibility=hidden -Wall -Wsign-compare -Wno-declaration-after-statement" else @@ -14,7 +18,11 @@ if RUBY_PLATFORM =~ /linux/ $LDFLAGS += " -Wl,-wrap,memcpy" end -$objs = ["protobuf.o", "convert.o", "defs.o", "message.o", - "repeated_field.o", "map.o", "ruby-upb.o", "wrap_memcpy.o"] +$VPATH << "$(srcdir)/third_party/utf8_range" +$INCFLAGS << "$(srcdir)/third_party/utf8_range" + +$srcs = ["protobuf.c", "convert.c", "defs.c", "message.c", + "repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c", + "utf8_range.c"] -create_makefile("google/protobuf_c") +create_makefile(ext_name) From 90065d39a78718f677328a4b8f0f145e67c950a7 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 21 Jan 2022 20:18:11 -0800 Subject: [PATCH 151/207] Fixed crash bug with proto2 enums. --- ruby/ext/google/protobuf_c/ruby-upb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 79a480eff6..fc1b57242a 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -6494,6 +6494,11 @@ static uint8_t map_descriptortype(const upb_FieldDef* f) { return type; } +static bool IsProto2Enum(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Enum && + f->sub.enumdef->file->syntax == kUpb_Syntax_Proto2; +} + static void fill_fieldlayout(upb_MiniTable_Field* field, const upb_FieldDef* f) { field->number = upb_FieldDef_Number(f); @@ -6557,9 +6562,7 @@ static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) { const upb_FieldDef* f = &m->fields[i]; if (upb_FieldDef_IsSubMessage(f)) { sublayout_count++; - } - if (upb_FieldDef_CType(f) == kUpb_CType_Enum && - f->sub.enumdef->file->syntax == kUpb_Syntax_Proto2) { + } else if (IsProto2Enum(f)) { sublayout_count++; } } @@ -6607,6 +6610,8 @@ static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) { if (upb_FieldDef_CType(val) == kUpb_CType_Message) { subs[0].submsg = upb_FieldDef_MessageSubDef(val)->layout; + } else if (IsProto2Enum(val)) { + subs[0].subenum = upb_FieldDef_EnumSubDef(val)->layout; } upb_FieldDef* fielddefs = (upb_FieldDef*)&m->fields[0]; From 79951dac8439fa1068121e85f8e8fea783e3377a Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 21 Jan 2022 20:25:32 -0800 Subject: [PATCH 152/207] Added changelog entries. --- CHANGES.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index d919ae1b6a..8c6cdce1b6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,14 @@ +Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Ruby + * JSON will now output shorter strings for double and float fields when possible + without losing precision. + * Encoding and decoding of binary format will now work properly on big-endian + systems. + * UTF-8 verification was fixed to properly reject surrogate code points. + * Unknown enums for proto2 protos now properly implement proto2's behavior of + putting such values in unknown fields. + 2022-01-10 version 3.19.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Python From 012c8892ab7aa8660cdc3df6a4472903d9fe49e0 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 21 Jan 2022 21:01:07 -0800 Subject: [PATCH 153/207] Added utf8_range. --- third_party/utf8_range/BUILD | 13 + third_party/utf8_range/LICENSE | 21 ++ third_party/utf8_range/utf8_range.c | 395 ++++++++++++++++++++++++++++ third_party/utf8_range/utf8_range.h | 9 + 4 files changed, 438 insertions(+) create mode 100644 third_party/utf8_range/BUILD create mode 100644 third_party/utf8_range/LICENSE create mode 100644 third_party/utf8_range/utf8_range.c create mode 100644 third_party/utf8_range/utf8_range.h diff --git a/third_party/utf8_range/BUILD b/third_party/utf8_range/BUILD new file mode 100644 index 0000000000..68b3e9e74f --- /dev/null +++ b/third_party/utf8_range/BUILD @@ -0,0 +1,13 @@ + +cc_library( + name = "utf8_range", + hdrs = ["utf8_range.h"], + srcs = ["utf8_range.c"], + visibility = ["//:__pkg__"], +) + +filegroup( + name = "cmake_files", + srcs = glob(["*"]), + visibility = ["//cmake:__pkg__"], +) diff --git a/third_party/utf8_range/LICENSE b/third_party/utf8_range/LICENSE new file mode 100644 index 0000000000..c1f087ecc8 --- /dev/null +++ b/third_party/utf8_range/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Yibo Cai + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/third_party/utf8_range/utf8_range.c b/third_party/utf8_range/utf8_range.c new file mode 100644 index 0000000000..109a54da5c --- /dev/null +++ b/third_party/utf8_range/utf8_range.c @@ -0,0 +1,395 @@ + +/* + * http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf - page 94 + * + * Table 3-7. Well-Formed UTF-8 Byte Sequences + * + * +--------------------+------------+-------------+------------+-------------+ + * | Code Points | First Byte | Second Byte | Third Byte | Fourth Byte | + * +--------------------+------------+-------------+------------+-------------+ + * | U+0000..U+007F | 00..7F | | | | + * +--------------------+------------+-------------+------------+-------------+ + * | U+0080..U+07FF | C2..DF | 80..BF | | | + * +--------------------+------------+-------------+------------+-------------+ + * | U+0800..U+0FFF | E0 | A0..BF | 80..BF | | + * +--------------------+------------+-------------+------------+-------------+ + * | U+1000..U+CFFF | E1..EC | 80..BF | 80..BF | | + * +--------------------+------------+-------------+------------+-------------+ + * | U+D000..U+D7FF | ED | 80..9F | 80..BF | | + * +--------------------+------------+-------------+------------+-------------+ + * | U+E000..U+FFFF | EE..EF | 80..BF | 80..BF | | + * +--------------------+------------+-------------+------------+-------------+ + * | U+10000..U+3FFFF | F0 | 90..BF | 80..BF | 80..BF | + * +--------------------+------------+-------------+------------+-------------+ + * | U+40000..U+FFFFF | F1..F3 | 80..BF | 80..BF | 80..BF | + * +--------------------+------------+-------------+------------+-------------+ + * | U+100000..U+10FFFF | F4 | 80..8F | 80..BF | 80..BF | + * +--------------------+------------+-------------+------------+-------------+ + */ + +/* Return 0 - success, >0 - index(1 based) of first error char */ +int utf8_naive(const unsigned char* data, int len) { + int err_pos = 1; + + while (len) { + int bytes; + const unsigned char byte1 = data[0]; + + /* 00..7F */ + if (byte1 <= 0x7F) { + bytes = 1; + /* C2..DF, 80..BF */ + } else if (len >= 2 && byte1 >= 0xC2 && byte1 <= 0xDF && + (signed char)data[1] <= (signed char)0xBF) { + bytes = 2; + } else if (len >= 3) { + const unsigned char byte2 = data[1]; + + /* Is byte2, byte3 between 0x80 ~ 0xBF */ + const int byte2_ok = (signed char)byte2 <= (signed char)0xBF; + const int byte3_ok = (signed char)data[2] <= (signed char)0xBF; + + if (byte2_ok && byte3_ok && + /* E0, A0..BF, 80..BF */ + ((byte1 == 0xE0 && byte2 >= 0xA0) || + /* E1..EC, 80..BF, 80..BF */ + (byte1 >= 0xE1 && byte1 <= 0xEC) || + /* ED, 80..9F, 80..BF */ + (byte1 == 0xED && byte2 <= 0x9F) || + /* EE..EF, 80..BF, 80..BF */ + (byte1 >= 0xEE && byte1 <= 0xEF))) { + bytes = 3; + } else if (len >= 4) { + /* Is byte4 between 0x80 ~ 0xBF */ + const int byte4_ok = (signed char)data[3] <= (signed char)0xBF; + + if (byte2_ok && byte3_ok && byte4_ok && + /* F0, 90..BF, 80..BF, 80..BF */ + ((byte1 == 0xF0 && byte2 >= 0x90) || + /* F1..F3, 80..BF, 80..BF, 80..BF */ + (byte1 >= 0xF1 && byte1 <= 0xF3) || + /* F4, 80..8F, 80..BF, 80..BF */ + (byte1 == 0xF4 && byte2 <= 0x8F))) { + bytes = 4; + } else { + return err_pos; + } + } else { + return err_pos; + } + } else { + return err_pos; + } + + len -= bytes; + err_pos += bytes; + data += bytes; + } + + return 0; +} + +#ifdef __SSE4_1__ + +#include +#include +#include + +int utf8_naive(const unsigned char* data, int len); + +static const int8_t _first_len_tbl[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, +}; + +static const int8_t _first_range_tbl[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, +}; + +static const int8_t _range_min_tbl[] = { + 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, + 0xC2, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, +}; +static const int8_t _range_max_tbl[] = { + 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, + 0xF4, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, +}; + +static const int8_t _df_ee_tbl[] = { + 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, +}; +static const int8_t _ef_fe_tbl[] = { + 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +/* Return 0 on success, -1 on error */ +int utf8_range2(const unsigned char* data, int len) { + if (len >= 32) { + __m128i prev_input = _mm_set1_epi8(0); + __m128i prev_first_len = _mm_set1_epi8(0); + + const __m128i first_len_tbl = + _mm_loadu_si128((const __m128i*)_first_len_tbl); + const __m128i first_range_tbl = + _mm_loadu_si128((const __m128i*)_first_range_tbl); + const __m128i range_min_tbl = + _mm_loadu_si128((const __m128i*)_range_min_tbl); + const __m128i range_max_tbl = + _mm_loadu_si128((const __m128i*)_range_max_tbl); + const __m128i df_ee_tbl = _mm_loadu_si128((const __m128i*)_df_ee_tbl); + const __m128i ef_fe_tbl = _mm_loadu_si128((const __m128i*)_ef_fe_tbl); + + __m128i error = _mm_set1_epi8(0); + + while (len >= 32) { + /***************************** block 1 ****************************/ + const __m128i input_a = _mm_loadu_si128((const __m128i*)data); + + __m128i high_nibbles = + _mm_and_si128(_mm_srli_epi16(input_a, 4), _mm_set1_epi8(0x0F)); + + __m128i first_len_a = _mm_shuffle_epi8(first_len_tbl, high_nibbles); + + __m128i range_a = _mm_shuffle_epi8(first_range_tbl, high_nibbles); + + range_a = _mm_or_si128(range_a, + _mm_alignr_epi8(first_len_a, prev_first_len, 15)); + + __m128i tmp; + tmp = _mm_alignr_epi8(first_len_a, prev_first_len, 14); + tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(1)); + range_a = _mm_or_si128(range_a, tmp); + + tmp = _mm_alignr_epi8(first_len_a, prev_first_len, 13); + tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(2)); + range_a = _mm_or_si128(range_a, tmp); + + __m128i shift1, pos, range2; + shift1 = _mm_alignr_epi8(input_a, prev_input, 15); + pos = _mm_sub_epi8(shift1, _mm_set1_epi8(0xEF)); + tmp = _mm_subs_epu8(pos, _mm_set1_epi8(0xF0)); + range2 = _mm_shuffle_epi8(df_ee_tbl, tmp); + tmp = _mm_adds_epu8(pos, _mm_set1_epi8(0x70)); + range2 = _mm_add_epi8(range2, _mm_shuffle_epi8(ef_fe_tbl, tmp)); + + range_a = _mm_add_epi8(range_a, range2); + + __m128i minv = _mm_shuffle_epi8(range_min_tbl, range_a); + __m128i maxv = _mm_shuffle_epi8(range_max_tbl, range_a); + + tmp = _mm_or_si128(_mm_cmplt_epi8(input_a, minv), + _mm_cmpgt_epi8(input_a, maxv)); + error = _mm_or_si128(error, tmp); + + /***************************** block 2 ****************************/ + const __m128i input_b = _mm_loadu_si128((const __m128i*)(data + 16)); + + high_nibbles = + _mm_and_si128(_mm_srli_epi16(input_b, 4), _mm_set1_epi8(0x0F)); + + __m128i first_len_b = _mm_shuffle_epi8(first_len_tbl, high_nibbles); + + __m128i range_b = _mm_shuffle_epi8(first_range_tbl, high_nibbles); + + range_b = + _mm_or_si128(range_b, _mm_alignr_epi8(first_len_b, first_len_a, 15)); + + tmp = _mm_alignr_epi8(first_len_b, first_len_a, 14); + tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(1)); + range_b = _mm_or_si128(range_b, tmp); + + tmp = _mm_alignr_epi8(first_len_b, first_len_a, 13); + tmp = _mm_subs_epu8(tmp, _mm_set1_epi8(2)); + range_b = _mm_or_si128(range_b, tmp); + + shift1 = _mm_alignr_epi8(input_b, input_a, 15); + pos = _mm_sub_epi8(shift1, _mm_set1_epi8(0xEF)); + tmp = _mm_subs_epu8(pos, _mm_set1_epi8(0xF0)); + range2 = _mm_shuffle_epi8(df_ee_tbl, tmp); + tmp = _mm_adds_epu8(pos, _mm_set1_epi8(0x70)); + range2 = _mm_add_epi8(range2, _mm_shuffle_epi8(ef_fe_tbl, tmp)); + + range_b = _mm_add_epi8(range_b, range2); + + minv = _mm_shuffle_epi8(range_min_tbl, range_b); + maxv = _mm_shuffle_epi8(range_max_tbl, range_b); + + tmp = _mm_or_si128(_mm_cmplt_epi8(input_b, minv), + _mm_cmpgt_epi8(input_b, maxv)); + error = _mm_or_si128(error, tmp); + + /************************ next iteration **************************/ + prev_input = input_b; + prev_first_len = first_len_b; + + data += 32; + len -= 32; + } + + if (!_mm_testz_si128(error, error)) return -1; + + int32_t token4 = _mm_extract_epi32(prev_input, 3); + const int8_t* token = (const int8_t*)&token4; + int lookahead = 0; + if (token[3] > (int8_t)0xBF) + lookahead = 1; + else if (token[2] > (int8_t)0xBF) + lookahead = 2; + else if (token[1] > (int8_t)0xBF) + lookahead = 3; + + data -= lookahead; + len += lookahead; + } + + return utf8_naive(data, len); +} + +#endif + +#ifdef __ARM_NEON + +#include +#include +#include + +int utf8_naive(const unsigned char* data, int len); + +static const uint8_t _first_len_tbl[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, +}; + +static const uint8_t _first_range_tbl[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, +}; + +static const uint8_t _range_min_tbl[] = { + 0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, + 0xC2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +}; +static const uint8_t _range_max_tbl[] = { + 0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, + 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +static const uint8_t _range_adjust_tbl[] = { + 2, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, +}; + +/* Return 0 on success, -1 on error */ +int utf8_range2(const unsigned char* data, int len) { + if (len >= 32) { + uint8x16_t prev_input = vdupq_n_u8(0); + uint8x16_t prev_first_len = vdupq_n_u8(0); + + const uint8x16_t first_len_tbl = vld1q_u8(_first_len_tbl); + const uint8x16_t first_range_tbl = vld1q_u8(_first_range_tbl); + const uint8x16_t range_min_tbl = vld1q_u8(_range_min_tbl); + const uint8x16_t range_max_tbl = vld1q_u8(_range_max_tbl); + const uint8x16x2_t range_adjust_tbl = vld2q_u8(_range_adjust_tbl); + + const uint8x16_t const_1 = vdupq_n_u8(1); + const uint8x16_t const_2 = vdupq_n_u8(2); + const uint8x16_t const_e0 = vdupq_n_u8(0xE0); + + uint8x16_t error1 = vdupq_n_u8(0); + uint8x16_t error2 = vdupq_n_u8(0); + uint8x16_t error3 = vdupq_n_u8(0); + uint8x16_t error4 = vdupq_n_u8(0); + + while (len >= 32) { + /******************* two blocks interleaved **********************/ + +#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 8) + /* gcc doesn't support vldq1_u8_x2 until version 8 */ + const uint8x16_t input_a = vld1q_u8(data); + const uint8x16_t input_b = vld1q_u8(data + 16); +#else + /* Forces a double load on Clang */ + const uint8x16x2_t input_pair = vld1q_u8_x2(data); + const uint8x16_t input_a = input_pair.val[0]; + const uint8x16_t input_b = input_pair.val[1]; +#endif + + const uint8x16_t high_nibbles_a = vshrq_n_u8(input_a, 4); + const uint8x16_t high_nibbles_b = vshrq_n_u8(input_b, 4); + + const uint8x16_t first_len_a = vqtbl1q_u8(first_len_tbl, high_nibbles_a); + const uint8x16_t first_len_b = vqtbl1q_u8(first_len_tbl, high_nibbles_b); + + uint8x16_t range_a = vqtbl1q_u8(first_range_tbl, high_nibbles_a); + uint8x16_t range_b = vqtbl1q_u8(first_range_tbl, high_nibbles_b); + + range_a = vorrq_u8(range_a, vextq_u8(prev_first_len, first_len_a, 15)); + range_b = vorrq_u8(range_b, vextq_u8(first_len_a, first_len_b, 15)); + + uint8x16_t tmp1_a, tmp2_a, tmp1_b, tmp2_b; + tmp1_a = vextq_u8(prev_first_len, first_len_a, 14); + tmp1_a = vqsubq_u8(tmp1_a, const_1); + range_a = vorrq_u8(range_a, tmp1_a); + + tmp1_b = vextq_u8(first_len_a, first_len_b, 14); + tmp1_b = vqsubq_u8(tmp1_b, const_1); + range_b = vorrq_u8(range_b, tmp1_b); + + tmp2_a = vextq_u8(prev_first_len, first_len_a, 13); + tmp2_a = vqsubq_u8(tmp2_a, const_2); + range_a = vorrq_u8(range_a, tmp2_a); + + tmp2_b = vextq_u8(first_len_a, first_len_b, 13); + tmp2_b = vqsubq_u8(tmp2_b, const_2); + range_b = vorrq_u8(range_b, tmp2_b); + + uint8x16_t shift1_a = vextq_u8(prev_input, input_a, 15); + uint8x16_t pos_a = vsubq_u8(shift1_a, const_e0); + range_a = vaddq_u8(range_a, vqtbl2q_u8(range_adjust_tbl, pos_a)); + + uint8x16_t shift1_b = vextq_u8(input_a, input_b, 15); + uint8x16_t pos_b = vsubq_u8(shift1_b, const_e0); + range_b = vaddq_u8(range_b, vqtbl2q_u8(range_adjust_tbl, pos_b)); + + uint8x16_t minv_a = vqtbl1q_u8(range_min_tbl, range_a); + uint8x16_t maxv_a = vqtbl1q_u8(range_max_tbl, range_a); + + uint8x16_t minv_b = vqtbl1q_u8(range_min_tbl, range_b); + uint8x16_t maxv_b = vqtbl1q_u8(range_max_tbl, range_b); + + error1 = vorrq_u8(error1, vcltq_u8(input_a, minv_a)); + error2 = vorrq_u8(error2, vcgtq_u8(input_a, maxv_a)); + + error3 = vorrq_u8(error3, vcltq_u8(input_b, minv_b)); + error4 = vorrq_u8(error4, vcgtq_u8(input_b, maxv_b)); + + /************************ next iteration *************************/ + prev_input = input_b; + prev_first_len = first_len_b; + + data += 32; + len -= 32; + } + error1 = vorrq_u8(error1, error2); + error1 = vorrq_u8(error1, error3); + error1 = vorrq_u8(error1, error4); + + if (vmaxvq_u8(error1)) return -1; + + uint32_t token4; + vst1q_lane_u32(&token4, vreinterpretq_u32_u8(prev_input), 3); + + const int8_t* token = (const int8_t*)&token4; + int lookahead = 0; + if (token[3] > (int8_t)0xBF) + lookahead = 1; + else if (token[2] > (int8_t)0xBF) + lookahead = 2; + else if (token[1] > (int8_t)0xBF) + lookahead = 3; + + data -= lookahead; + len += lookahead; + } + + return utf8_naive(data, len); +} + +#endif diff --git a/third_party/utf8_range/utf8_range.h b/third_party/utf8_range/utf8_range.h new file mode 100644 index 0000000000..86daa0b5a4 --- /dev/null +++ b/third_party/utf8_range/utf8_range.h @@ -0,0 +1,9 @@ + +#if defined(__ARM_NEON) || defined(__SSE4_1__) +int utf8_range2(const unsigned char* data, int len); +#else +int utf8_naive(const unsigned char* data, int len); +static inline int utf8_range2(const unsigned char* data, int len) { + return utf8_naive(data, len); +} +#endif From 5ef010cb85eb35ef8aa066161138a72e8b2c8852 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 23 Jan 2022 16:13:12 -0800 Subject: [PATCH 154/207] Fixed spelling errors in comments. --- ruby/ext/google/protobuf_c/ruby-upb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index fc1b57242a..0e47668b44 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5210,8 +5210,8 @@ struct upb_MessageDef { upb_strtable ntof; /* All nested defs. - * MEM: We could save some space here by putting nested defs in a contigous - * region and calculating counts from offets or vice-versa. */ + * MEM: We could save some space here by putting nested defs in a contiguous + * region and calculating counts from offsets or vice-versa. */ const upb_FieldDef* fields; const upb_OneofDef* oneofs; const upb_ExtensionRange* ext_ranges; From 110d6c10b2d876c796909bae706c9062914a167e Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 24 Jan 2022 22:40:17 +1100 Subject: [PATCH 155/207] polyfill ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX --- php/ext/google/protobuf/array.c | 31 +++++++----------------------- php/ext/google/protobuf/map.c | 14 +++++++------- php/ext/google/protobuf/protobuf.h | 20 ++++++++++++++++--- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index 70db6da988..af1b3a5223 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -483,7 +483,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_getIterator, 0) ZEND_END_ARG_INFO() #else -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() @@ -491,16 +491,16 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MI ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) @@ -652,37 +652,20 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } -#if PHP_VERSION_ID < 70200 -ZEND_BEGIN_ARG_INFO(arginfo_current, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_key, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_next, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_valid, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_rewind, 0) -ZEND_END_ARG_INFO() -#else ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -#endif static zend_function_entry repeated_field_iter_methods[] = { PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index 859cc6d0c6..f4fac167f5 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -458,23 +458,23 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MI ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() static zend_function_entry MapField_methods[] = { @@ -624,7 +624,7 @@ PHP_METHOD(MapFieldIter, valid) { RETURN_BOOL(!done); } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) @@ -633,10 +633,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() static zend_function_entry map_field_iter_methods[] = { diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index d5f8021888..ef57b12976 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -86,6 +86,15 @@ const zval *get_generated_pool(); ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null) #endif +// polyfill for ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX, which changes between 7.1 and 7.2 +#if PHP_VERSION_ID < 70200 +#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, /*class_name*/ 0, allow_null) +#else +#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) +#endif + // In PHP 8.1, mismatched tentative return types emit a deprecation notice. // https://wiki.php.net/rfc/internal_method_return_types // @@ -93,16 +102,21 @@ const zval *get_generated_pool(); #if PHP_VERSION_ID < 80100 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null) -#define IS_MIXED 16 #endif -#if PHP_VERSION_ID < 70100 +#ifndef IS_VOID #define IS_VOID 99 #endif #ifndef IS_MIXED #define IS_MIXED 99 -#define IS_BOOL 99 +#endif + +#ifndef _IS_BOOL +#define _IS_BOOL 99 +#endif + +#ifndef IS_LONG #define IS_LONG 99 #endif From 6a3f3840f662fe44d27a239c345ba06a136a45f1 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 24 Jan 2022 23:17:16 +1100 Subject: [PATCH 156/207] tidy --- php/ext/google/protobuf/array.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index af1b3a5223..c26364ff29 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -459,30 +459,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -#if PHP_VERSION_ID < 70200 -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetExists, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) - ZEND_ARG_INFO(0, index) - ZEND_ARG_INFO(0, newval) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetUnset, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_count, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_getIterator, 0) -ZEND_END_ARG_INFO() -#else PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() @@ -505,7 +481,6 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) ZEND_END_ARG_INFO() -#endif static zend_function_entry repeated_field_methods[] = { PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) From 3e724d8a2ef39ea5a781fd6009e0ed2700a260c5 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 24 Jan 2022 23:23:40 +1100 Subject: [PATCH 157/207] formatting --- php/ext/google/protobuf/array.c | 10 +++++----- php/ext/google/protobuf/map.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index c26364ff29..9c290f7dd9 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -643,11 +643,11 @@ PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() static zend_function_entry repeated_field_iter_methods[] = { - PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index f4fac167f5..252b1f5b3c 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -640,11 +640,11 @@ PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() static zend_function_entry map_field_iter_methods[] = { - PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; From f180289c4670ca1afde5865bb8a7f2b61a3efcc5 Mon Sep 17 00:00:00 2001 From: David Geldreich Date: Mon, 24 Jan 2022 22:17:14 +0100 Subject: [PATCH 158/207] link with correct C runtime on MSVC (#9437) when using CMake >= 3.15, we use CMAKE_MSVC_RUNTIME_LIBRARY to reproduce the /MT vs /MD when protobuf_MSVC_STATIC_RUNTIME is TRUE or FALSE MultiThreaded is for /MT MultiThreadedDebug is for /MTd MultiThreadedDLL is for /MD MultiThreadedDebugDLL is for /MDd --- cmake/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 51e8478f6e..ebdc85bed5 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -182,7 +182,11 @@ else (protobuf_BUILD_SHARED_LIBS) # making programmatic control difficult. Prefer the functionality in newer # CMake versions when available. if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15) - set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$:Debug>) + if (protobuf_MSVC_STATIC_RUNTIME) + set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$:Debug>) + else() + set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$:Debug>DLL) + endif() else() # In case we are building static libraries, link also the runtime library statically # so that MSVCR*.DLL is not required at runtime. From a78b89ef2a3f1022f3ee91cc420033dc697d8c38 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Tue, 25 Jan 2022 21:00:02 +1100 Subject: [PATCH 159/207] removing ext-bcmath require I think it _should_ be required, but a test (linux, 32bit, 7.0-zts) is choking on composer install, so putting things back to how I found them --- php/composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/php/composer.json b/php/composer.json index 71a1e758f1..f712f0ebb9 100644 --- a/php/composer.json +++ b/php/composer.json @@ -6,8 +6,7 @@ "homepage": "https://developers.google.com/protocol-buffers/", "license": "BSD-3-Clause", "require": { - "php": ">=7.0.0", - "ext-bcmath": "*" + "php": ">=7.0.0" }, "require-dev": { "phpunit/phpunit": ">=5.0.0" From a035bd0882f74d42798cf65fced7ce785b837646 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 25 Jan 2022 08:24:12 -0800 Subject: [PATCH 160/207] Make libprotobuf symbols local on OSX (#8346) (#9435) @gnossen gave a great overview in https://github.com/grpc/grpc/pull/24992 of the overall problem. If a python process using both protobuf _and_ another native library linking in libprotobuf frequently can cause crashes. This seems to frequently affect tensorflow as well: tensorflow/tensorflow#8394, tensorflow/tensorflow#9525 (comment) tensorflow/tensorflow#24976, tensorflow/tensorflow#35573, https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/contrib/makefile/rename_protobuf.sh, tensorflow/tensorflow#16104 Testing locally this fixes both crashes when linking in multiple versions of protobuf and fixes `DescriptorPool` clashes as well (e.g. Python and Native code import different versions of the same message). Co-authored-by: Roy Williams --- python/setup.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python/setup.py b/python/setup.py index 77d9cd1f6c..4a6161c21f 100755 --- a/python/setup.py +++ b/python/setup.py @@ -210,6 +210,18 @@ if __name__ == '__main__': extra_compile_args = [] + message_extra_link_args = None + api_implementation_link_args = None + if "darwin" in sys.platform: + if sys.version_info[0] == 2: + message_init_symbol = 'init_message' + api_implementation_init_symbol = 'init_api_implementation' + else: + message_init_symbol = 'PyInit__message' + api_implementation_init_symbol = 'PyInit__api_implementation' + message_extra_link_args = ['-Wl,-exported_symbol,_%s' % message_init_symbol] + api_implementation_link_args = ['-Wl,-exported_symbol,_%s' % api_implementation_init_symbol] + if sys.platform != 'win32': extra_compile_args.append('-Wno-write-strings') extra_compile_args.append('-Wno-invalid-offsetof') @@ -260,6 +272,7 @@ if __name__ == '__main__': include_dirs=[".", "../src"], libraries=libraries, extra_objects=extra_objects, + extra_link_args=message_extra_link_args, library_dirs=['../src/.libs'], extra_compile_args=extra_compile_args, ), @@ -267,6 +280,7 @@ if __name__ == '__main__': "google.protobuf.internal._api_implementation", glob.glob('google/protobuf/internal/api_implementation.cc'), extra_compile_args=extra_compile_args + ['-DPYTHON_PROTO2_CPP_IMPL_V2'], + extra_link_args=api_implementation_link_args, ), ]) os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' From 82372d8fe61686c2fe56e2231e928c212e9341d6 Mon Sep 17 00:00:00 2001 From: Maximilian Date: Thu, 27 Jan 2022 01:23:14 +0100 Subject: [PATCH 161/207] Use proper SPDX license identifier (#9441) The previously used term "3-Clause BSD License" is not properly standarized. A common standard is SPDX, therefore "3-Clause BSD License" is substituted with "BSD-3-Clause" which is a SPDX identifier. `grep -rl "3-Clause BSD License" | xargs -n1 sed -i "s/3-Clause BSD License/BSD-3-Clause/g"` --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- java/bom/pom.xml | 2 +- java/pom.xml | 2 +- php/ext/google/protobuf/package.xml | 154 ++++++++++++++-------------- protoc-artifacts/pom.xml | 2 +- python/protobuf_distutils/setup.py | 2 +- python/setup.py | 2 +- ruby/pom.xml | 2 +- 9 files changed, 85 insertions(+), 85 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index ab241b9432..766e2d18d3 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -3,7 +3,7 @@ Pod::Spec.new do |s| s.version = '3.19.3' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' - s.license = '3-Clause BSD License' + s.license = 'BSD-3-Clause' s.authors = { 'The Protocol Buffers contributors' => 'protobuf@googlegroups.com' } s.cocoapods_version = '>= 1.0' diff --git a/Protobuf.podspec b/Protobuf.podspec index 39f83393fa..3453b0de2b 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.version = '3.19.3' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' - s.license = '3-Clause BSD License' + s.license = 'BSD-3-Clause' s.authors = { 'The Protocol Buffers contributors' => 'protobuf@googlegroups.com' } s.cocoapods_version = '>= 1.0' diff --git a/java/bom/pom.xml b/java/bom/pom.xml index cb0fad22c3..326305dcb2 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -29,7 +29,7 @@ - 3-Clause BSD License + BSD-3-Clause https://opensource.org/licenses/BSD-3-Clause diff --git a/java/pom.xml b/java/pom.xml index f9c2d1fe6e..bb094a01ed 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -41,7 +41,7 @@ - 3-Clause BSD License + BSD-3-Clause https://opensource.org/licenses/BSD-3-Clause repo diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 2986347904..8086f4ae70 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -20,7 +20,7 @@ stable stable - 3-Clause BSD License + BSD-3-Clause * No new changes in 3.19.3 @@ -73,7 +73,7 @@ 2016-09-23 - 3-Clause BSD License + BSD-3-Clause First alpha release @@ -89,7 +89,7 @@ First alpha release 2017-01-13 - 3-Clause BSD License + BSD-3-Clause Second alpha release. @@ -105,7 +105,7 @@ Second alpha release. 2017-04-28 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -121,7 +121,7 @@ GA release. 2017-05-08 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -137,7 +137,7 @@ GA release. 2017-06-21 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -153,7 +153,7 @@ GA release. 2017-08-16 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -169,7 +169,7 @@ GA release. 2017-09-14 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -185,7 +185,7 @@ GA release. 2017-11-15 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -201,7 +201,7 @@ GA release. 2017-12-06 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -217,7 +217,7 @@ GA release. 2017-12-11 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -233,7 +233,7 @@ GA release. 2018-03-06 - 3-Clause BSD License + BSD-3-Clause G A release. @@ -249,7 +249,7 @@ G A release. 2018-06-06 - 3-Clause BSD License + BSD-3-Clause G A release. @@ -265,7 +265,7 @@ G A release. 2018-08-03 - 3-Clause BSD License + BSD-3-Clause G A release. @@ -281,7 +281,7 @@ G A release. 2019-02-1 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -295,7 +295,7 @@ G A release. 2019-02-22 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -309,7 +309,7 @@ G A release. 2019-02-28 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -323,7 +323,7 @@ G A release. 2019-03-25 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -337,7 +337,7 @@ G A release. 2019-04-23 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -351,7 +351,7 @@ G A release. 2019-05-21 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -365,7 +365,7 @@ G A release. 2019-06-17 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -379,7 +379,7 @@ G A release. 2019-07-10 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -393,7 +393,7 @@ G A release. 2019-08-02 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -407,7 +407,7 @@ G A release. 2019-09-04 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -421,7 +421,7 @@ G A release. 2019-09-05 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -435,7 +435,7 @@ G A release. 2019-09-12 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -449,7 +449,7 @@ G A release. 2019-11-15 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -463,7 +463,7 @@ G A release. 2019-11-21 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -477,7 +477,7 @@ G A release. 2019-11-25 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -491,7 +491,7 @@ G A release. 2019-12-02 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -505,7 +505,7 @@ G A release. 2019-12-10 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -519,7 +519,7 @@ G A release. 2020-01-28 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -533,7 +533,7 @@ G A release. 2020-02-12 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -547,7 +547,7 @@ G A release. 2020-04-30 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -561,7 +561,7 @@ G A release. 2020-05-12 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -575,7 +575,7 @@ G A release. 2020-05-15 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -589,7 +589,7 @@ G A release. 2020-05-20 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -603,7 +603,7 @@ G A release. 2020-05-26 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -617,7 +617,7 @@ G A release. 2020-06-01 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -631,7 +631,7 @@ G A release. 2020-08-05 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -645,7 +645,7 @@ G A release. 2020-08-05 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -659,7 +659,7 @@ G A release. 2020-08-12 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -673,7 +673,7 @@ G A release. 2020-08-14 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -687,7 +687,7 @@ G A release. 2020-10-08 - 3-Clause BSD License + BSD-3-Clause GA release. @@ -701,7 +701,7 @@ G A release. 2020-11-05 - 3-Clause BSD License + BSD-3-Clause @@ -716,7 +716,7 @@ G A release. 2020-11-10 - 3-Clause BSD License + BSD-3-Clause @@ -731,7 +731,7 @@ G A release. 2020-11-11 - 3-Clause BSD License + BSD-3-Clause @@ -746,7 +746,7 @@ G A release. 2020-11-12 - 3-Clause BSD License + BSD-3-Clause @@ -761,7 +761,7 @@ G A release. 2021-02-05 - 3-Clause BSD License + BSD-3-Clause @@ -776,7 +776,7 @@ G A release. 2021-02-17 - 3-Clause BSD License + BSD-3-Clause @@ -791,7 +791,7 @@ G A release. 2021-02-18 - 3-Clause BSD License + BSD-3-Clause @@ -806,7 +806,7 @@ G A release. 2021-02-19 - 3-Clause BSD License + BSD-3-Clause @@ -821,7 +821,7 @@ G A release. 2021-02-23 - 3-Clause BSD License + BSD-3-Clause @@ -836,7 +836,7 @@ G A release. 2021-02-24 - 3-Clause BSD License + BSD-3-Clause @@ -851,7 +851,7 @@ G A release. 2021-03-02 - 3-Clause BSD License + BSD-3-Clause @@ -866,7 +866,7 @@ G A release. 2021-03-04 - 3-Clause BSD License + BSD-3-Clause @@ -881,7 +881,7 @@ G A release. 2021-03-10 - 3-Clause BSD License + BSD-3-Clause @@ -896,7 +896,7 @@ G A release. 2021-04-02 - 3-Clause BSD License + BSD-3-Clause @@ -911,7 +911,7 @@ G A release. 2021-04-02 - 3-Clause BSD License + BSD-3-Clause @@ -926,7 +926,7 @@ G A release. 2021-05-03 - 3-Clause BSD License + BSD-3-Clause @@ -941,7 +941,7 @@ G A release. 2021-05-05 - 3-Clause BSD License + BSD-3-Clause @@ -956,7 +956,7 @@ G A release. 2021-05-06 - 3-Clause BSD License + BSD-3-Clause @@ -971,7 +971,7 @@ G A release. 2021-05-07 - 3-Clause BSD License + BSD-3-Clause @@ -986,7 +986,7 @@ G A release. 2021-05-11 - 3-Clause BSD License + BSD-3-Clause @@ -1001,7 +1001,7 @@ G A release. 2021-05-19 - 3-Clause BSD License + BSD-3-Clause * Fixed PHP memory leaks and arginfo errors. (#8614) * Fixed JSON parser to allow multiple values from the same oneof as long as @@ -1019,7 +1019,7 @@ G A release. 2021-05-25 - 3-Clause BSD License + BSD-3-Clause @@ -1034,7 +1034,7 @@ G A release. 2021-06-04 - 3-Clause BSD License + BSD-3-Clause @@ -1049,7 +1049,7 @@ G A release. 2021-08-18 - 3-Clause BSD License + BSD-3-Clause @@ -1064,7 +1064,7 @@ G A release. 2021-08-27 - 3-Clause BSD License + BSD-3-Clause @@ -1079,7 +1079,7 @@ G A release. 2021-09-13 - 3-Clause BSD License + BSD-3-Clause @@ -1094,7 +1094,7 @@ G A release. 2021-10-04 - 3-Clause BSD License + BSD-3-Clause @@ -1109,7 +1109,7 @@ G A release. 2021-10-15 - 3-Clause BSD License + BSD-3-Clause @@ -1124,7 +1124,7 @@ G A release. 2021-10-18 - 3-Clause BSD License + BSD-3-Clause @@ -1139,7 +1139,7 @@ G A release. 2021-10-19 - 3-Clause BSD License + BSD-3-Clause @@ -1154,7 +1154,7 @@ G A release. 2021-10-28 - 3-Clause BSD License + BSD-3-Clause @@ -1169,7 +1169,7 @@ G A release. 2022-01-05 - 3-Clause BSD License + BSD-3-Clause @@ -1184,7 +1184,7 @@ G A release. 2022-01-11 - 3-Clause BSD License + BSD-3-Clause diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 8c2948c586..0c42370958 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -19,7 +19,7 @@ https://developers.google.com/protocol-buffers/ - 3-Clause BSD License + BSD-3-Clause https://opensource.org/licenses/BSD-3-Clause repo diff --git a/python/protobuf_distutils/setup.py b/python/protobuf_distutils/setup.py index 1092930fa5..9a19032910 100644 --- a/python/protobuf_distutils/setup.py +++ b/python/protobuf_distutils/setup.py @@ -46,7 +46,7 @@ setup( packages=find_packages(), maintainer='protobuf@googlegroups.com', maintainer_email='protobuf@googlegroups.com', - license='3-Clause BSD License', + license='BSD-3-Clause', classifiers=[ "Framework :: Setuptools Plugin", "Operating System :: OS Independent", diff --git a/python/setup.py b/python/setup.py index 77d9cd1f6c..87dff52ad3 100755 --- a/python/setup.py +++ b/python/setup.py @@ -283,7 +283,7 @@ if __name__ == '__main__': url='https://developers.google.com/protocol-buffers/', maintainer='protobuf@googlegroups.com', maintainer_email='protobuf@googlegroups.com', - license='3-Clause BSD License', + license='BSD-3-Clause', classifiers=[ "Programming Language :: Python", "Programming Language :: Python :: 3", diff --git a/ruby/pom.xml b/ruby/pom.xml index 255d840bb9..d4a8c103fe 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -19,7 +19,7 @@ https://developers.google.com/protocol-buffers/ - 3-Clause BSD License + BSD-3-Clause https://opensource.org/licenses/BSD-3-Clause repo From 4c03fcf8fb757ba0c771bcca45634afa3e9f2e88 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 27 Jan 2022 15:45:20 +1100 Subject: [PATCH 162/207] php8.1 testing --- kokoro/linux/dockerfile/test/php80/Dockerfile | 32 +++++++++++++++++-- tests.sh | 6 ++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/kokoro/linux/dockerfile/test/php80/Dockerfile b/kokoro/linux/dockerfile/test/php80/Dockerfile index 8093eae16c..5b382d0a10 100644 --- a/kokoro/linux/dockerfile/test/php80/Dockerfile +++ b/kokoro/linux/dockerfile/test/php80/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:jessie +FROM debian:stretch # Install dependencies. We start with the basic ones require to build protoc # and the C++ build @@ -29,7 +29,7 @@ RUN apt-get update && apt-get install -y \ # Install php dependencies RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ - php5 \ + php \ libcurl4-openssl-dev \ libgmp-dev \ libgmp3-dev \ @@ -90,6 +90,34 @@ RUN wget -O phpunit https://phar.phpunit.de/phpunit-9.phar \ && cp phpunit /usr/local/php-8.0/bin \ && mv phpunit /usr/local/php-8.0-zts/bin +# php 8.1 +RUN cd php-src \ + && git checkout php-8.1.2 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.1 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.1-zts \ + && make \ + && make install \ + && make clean + # Install php dependencies RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ valgrind \ diff --git a/tests.sh b/tests.sh index 290f110a8c..13bf034da6 100755 --- a/tests.sh +++ b/tests.sh @@ -496,6 +496,8 @@ build_php() { use_php $1 pushd php rm -rf vendor + php -v + php -m composer update composer test popd @@ -505,6 +507,8 @@ build_php() { test_php_c() { pushd php rm -rf vendor + php -v + php -m composer update composer test_c popd @@ -572,7 +576,9 @@ build_php_multirequest() { build_php8.0_all() { build_php 8.0 + build_php 8.1 build_php_c 8.0 + build_php_c 8.1 } build_php_all_32() { From a30167f016c64017f3f973e57765344cc795a726 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 27 Jan 2022 18:07:30 +0000 Subject: [PATCH 163/207] simplify mergeable UI messages (#9445) No "Please" see https://docs.google.com/document/d/1mIHBZQXI3F5VEPPmR54PySixl8wSsdwVciSENJ0Unxg/edit#heading=h.vvb6vlxagbv8 for justification also make the and clause a little simpler. That is, this is now "Include release notes: yes AND at least a language label" instead of "Please include release notes: yes AND Please include at least a language label" --- .github/mergeable.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/mergeable.yml b/.github/mergeable.yml index ade6c679a4..17688527de 100644 --- a/.github/mergeable.yml +++ b/.github/mergeable.yml @@ -9,10 +9,10 @@ mergeable: - and: - must_include: regex: 'release notes: yes' - message: 'Please include release notes: yes' + message: 'Include release notes: yes' - must_include: regex: '^(autotools|bazel|c#|c\+\+|cleanup|cmake|conformance tests|integration|go|java|javascript|objective-c|php|protoc|python|ruby|kotlin)' - message: 'Please include at least a language label (e.g., c++, java, python). Or apply one of the following labels: autotools, bazel, cmake, cleanup, conformance tests, integration, protoc.' + message: 'at least a language label (e.g., c++, java, python). Or apply one of the following labels: autotools, bazel, cmake, cleanup, conformance tests, integration, protoc.' - must_include: regex: 'release notes: no' - message: 'Please include release notes: no' + message: 'Include release notes: no' From 779b97260d6f75c4701bee27ba5863f3bf246a41 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 27 Jan 2022 16:27:45 -0800 Subject: [PATCH 164/207] Update CHANGES.txt for 3.19.4 release (#9448) --- CHANGES.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 92d220f35b..c59259a953 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,8 @@ +2022-01-28 version 3.19.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + Python + * Make libprotobuf symbols local on OSX to fix issue #9395 (#9435) + 2022-01-10 version 3.19.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Python From 67995fb4e9ccd43195993dddc051a018fd888086 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 27 Jan 2022 17:06:41 -0800 Subject: [PATCH 165/207] Fixed data loss bug with PHP C extension. --- php/ext/google/protobuf/php-upb.c | 2 +- php/tests/GeneratedClassTest.php | 10 +++++++++ php/tests/proto/test.proto | 35 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index a668fe0c6d..925faa645a 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5968,7 +5968,7 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { } /* Account for space used by hasbits. */ - l->size = div_round_up(hasbit, 8); + l->size = div_round_up(hasbit + 1, 8); /* Allocate non-oneof fields. */ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); diff --git a/php/tests/GeneratedClassTest.php b/php/tests/GeneratedClassTest.php index 837f05215d..a6101dcbfb 100644 --- a/php/tests/GeneratedClassTest.php +++ b/php/tests/GeneratedClassTest.php @@ -9,6 +9,7 @@ use Google\Protobuf\Internal\GPBType; use Bar\TestLegacyMessage; use Bar\TestLegacyMessage_NestedEnum; use Bar\TestLegacyMessage_NestedMessage; +use Foo\Test32Fields; use Foo\TestEnum; use Foo\TestIncludeNamespaceMessage; use Foo\TestIncludePrefixMessage; @@ -1849,4 +1850,13 @@ class GeneratedClassTest extends TestBase $this->assertTrue(true); } + + public function testIssue9440() + { + $m = new Test32Fields(); + $m->setId(8); + $this->assertEquals(8, $m->getId()); + $m->setVersion('1'); + $this->assertEquals(8, $m->getId()); + } } diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto index 609b8cfe0c..421292ab52 100644 --- a/php/tests/proto/test.proto +++ b/php/tests/proto/test.proto @@ -306,3 +306,38 @@ message TestBytesValue { int32 int32_field = 4; } } + +message Test32Fields { + optional uint32 id = 1; + optional uint32 random_name_a0 = 2; + optional uint32 random_name_a1 = 3; + optional uint32 random_name_a2 = 4; + optional uint32 random_name_a3 = 5; + optional uint32 random_name_a4 = 6; + optional uint32 random_name_a5 = 7; + optional uint32 random_name_a6 = 8; + optional uint32 random_name_a7 = 9; + optional uint32 random_name_a8 = 10; + optional uint32 random_name_a9 = 11; + optional uint32 random_name_b0 = 12; + optional uint32 random_name_b1 = 13; + optional uint32 random_name_b2 = 14; + optional uint32 random_name_b3 = 15; + optional uint32 random_name_b4 = 16; + optional uint32 random_name_b5 = 17; + optional uint32 random_name_b6 = 18; + optional uint32 random_name_b7 = 19; + optional uint32 random_name_b8 = 20; + optional uint32 random_name_b9 = 21; + optional uint32 random_name_c0 = 22; + optional uint32 random_name_c1 = 23; + optional uint32 random_name_c2 = 24; + optional uint32 random_name_c3 = 25; + optional uint32 random_name_c4 = 26; + optional uint32 random_name_c5 = 27; + optional uint32 random_name_c6 = 28; + optional uint32 random_name_c7 = 29; + optional uint32 random_name_c8 = 30; + optional uint32 random_name_c9 = 31; + optional string version = 32; +} From 35a21c124971bb062cffe0b6bda6159fbbbb3297 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 27 Jan 2022 17:14:07 -0800 Subject: [PATCH 166/207] Added CHANGES.txt entry. --- CHANGES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index c59259a953..1bb36d5504 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,10 @@ Python * Make libprotobuf symbols local on OSX to fix issue #9395 (#9435) + PHP + * Fixed a data loss bug that could occur when the number of `optional` + fields in a message is an exact multiple of 32. (#9440). + 2022-01-10 version 3.19.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Python From aceff710f4caef3269308a6c50ab075f3879176d Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 27 Jan 2022 17:29:12 -0800 Subject: [PATCH 167/207] Fixed data loss bug in Ruby extension. --- CHANGES.txt | 4 +++ ruby/ext/google/protobuf_c/ruby-upb.c | 2 +- ruby/tests/basic.rb | 8 ++++++ ruby/tests/basic_test.proto | 35 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index c59259a953..f5afcdf47c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,10 @@ Python * Make libprotobuf symbols local on OSX to fix issue #9395 (#9435) + Ruby + * Fixed a data loss bug that could occur when the number of `optional` + fields in a message is an exact multiple of 32. (#9440). + 2022-01-10 version 3.19.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Python diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index d68caac0e2..d6c2a0bc5d 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5583,7 +5583,7 @@ static void make_layout(symtab_addctx *ctx, const upb_msgdef *m) { } /* Account for space used by hasbits. */ - l->size = div_round_up(hasbit, 8); + l->size = div_round_up(hasbit + 1, 8); /* Allocate non-oneof fields. */ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it); diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 841b8b502f..b9d1554dbd 100755 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -71,6 +71,14 @@ module BasicTest TestMessage.encode(msg) end + def test_issue_9440 + msg = HelloRequest.new + msg.id = 8 + assert_equal 8, msg.id + msg.version = '1' + assert_equal 8, msg.id + end + def test_has_field m = TestSingularFields.new assert !m.has_singular_msg? diff --git a/ruby/tests/basic_test.proto b/ruby/tests/basic_test.proto index bca172a722..fb70f479db 100644 --- a/ruby/tests/basic_test.proto +++ b/ruby/tests/basic_test.proto @@ -215,3 +215,38 @@ message WithJsonName { optional int32 foo_bar = 1 [json_name="jsonFooBar"]; repeated WithJsonName baz = 2 [json_name="jsonBaz"]; } + +message HelloRequest { + optional uint32 id = 1; + optional uint32 random_name_a0 = 2; + optional uint32 random_name_a1 = 3; + optional uint32 random_name_a2 = 4; + optional uint32 random_name_a3 = 5; + optional uint32 random_name_a4 = 6; + optional uint32 random_name_a5 = 7; + optional uint32 random_name_a6 = 8; + optional uint32 random_name_a7 = 9; + optional uint32 random_name_a8 = 10; + optional uint32 random_name_a9 = 11; + optional uint32 random_name_b0 = 12; + optional uint32 random_name_b1 = 13; + optional uint32 random_name_b2 = 14; + optional uint32 random_name_b3 = 15; + optional uint32 random_name_b4 = 16; + optional uint32 random_name_b5 = 17; + optional uint32 random_name_b6 = 18; + optional uint32 random_name_b7 = 19; + optional uint32 random_name_b8 = 20; + optional uint32 random_name_b9 = 21; + optional uint32 random_name_c0 = 22; + optional uint32 random_name_c1 = 23; + optional uint32 random_name_c2 = 24; + optional uint32 random_name_c3 = 25; + optional uint32 random_name_c4 = 26; + optional uint32 random_name_c5 = 27; + optional uint32 random_name_c6 = 28; + optional uint32 random_name_c7 = 29; + optional uint32 random_name_c8 = 30; + optional uint32 random_name_c9 = 31; + optional string version = 32; +} From 22d0e265de7d2b3d2e9a00d071313502e7d4cccf Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 27 Jan 2022 19:35:56 -0800 Subject: [PATCH 168/207] Update protobuf version for 3.19.4 (#9449) I also updated the PHP release notes in php/ext/google/protobuf/package.xml. --- Protobuf-C++.podspec | 2 +- Protobuf.podspec | 2 +- configure.ac | 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/util/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 25 +++++++++++++++---- php/ext/google/protobuf/protobuf.h | 2 +- protobuf_version.bzl | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 4 +-- src/Makefile.am | 2 +- 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/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 +- 37 files changed, 59 insertions(+), 44 deletions(-) diff --git a/Protobuf-C++.podspec b/Protobuf-C++.podspec index ab241b9432..1c557a04df 100644 --- a/Protobuf-C++.podspec +++ b/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.19.3' + s.version = '3.19.4' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = '3-Clause BSD License' diff --git a/Protobuf.podspec b/Protobuf.podspec index 39f83393fa..c70b2ef68c 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.19.3' + s.version = '3.19.4' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = '3-Clause BSD License' diff --git a/configure.ac b/configure.ac index 02085ca809..4c774b0bea 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.19.3],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.19.4],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index b57bab299a..098d79d09c 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.19.3 + 3.19.4 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 1caa7de93c..010e4b4272 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.19.3 + 3.19.4 7.2 Google Inc. diff --git a/java/README.md b/java/README.md index 46b3f563d4..0170b9d772 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.19.3 + 3.19.4 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.19.3 + 3.19.4 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.19.3' + implementation 'com.google.protobuf:protobuf-java:3.19.4' ``` 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 cb0fad22c3..c818a142dd 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.19.3 + 3.19.4 pom Protocol Buffers [BOM] diff --git a/java/core/pom.xml b/java/core/pom.xml index f288746711..ce068ee684 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.3 + 3.19.4 protobuf-java diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 0348bddf20..977959b504 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.3 + 3.19.4 protobuf-kotlin-lite diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index a275f24bd9..286af32f7b 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.3 + 3.19.4 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index cbb5960793..755a1a69f2 100644 --- a/java/lite.md +++ b/java/lite.md @@ -30,7 +30,7 @@ protobuf Java runtime. If you are using Maven, use the following: com.google.protobuf protobuf-javalite - 3.19.3 + 3.19.4 ``` diff --git a/java/lite/pom.xml b/java/lite/pom.xml index ee8c73ca51..901ae6767a 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.3 + 3.19.4 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index 16df630384..a6161214a8 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.3 + 3.19.4 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 606c445321..2c5e2926ca 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.19.3 + 3.19.4 protobuf-java-util diff --git a/js/package.json b/js/package.json index aecbbc1c84..f7e8a3f1f4 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.19.3", + "version": "3.19.4", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 2986347904..5ef101bc7a 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2022-01-11 - + 2022-01-28 + - 3.19.3 - 3.19.3 + 3.19.4 + 3.19.4 stable @@ -22,7 +22,7 @@ 3-Clause BSD License - * No new changes in 3.19.3 + * Fixed a data loss bug that could occur when the number of optional fields in a message is an exact multiple of 32. (#9440). @@ -1188,5 +1188,20 @@ G A release. + + + 3.19.4 + 3.19.4 + + + stable + stable + + 2022-01-28 + + 3-Clause BSD License + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index df52892111..41ae2718b4 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -91,7 +91,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.19.3" +#define PHP_PROTOBUF_VERSION "3.19.4" // 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 3a5a72dec6..9ae1340741 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1 @@ -PROTOBUF_VERSION = '3.19.3' +PROTOBUF_VERSION = '3.19.4' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 8c2948c586..dec2e7047c 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.19.3 + 3.19.4 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 07a4d94fd2..9319c67f1f 100644 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.19.3' +__version__ = '3.19.4' diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 1c151a5983..87d75a3ba7 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.19.3" + s.version = "3.19.4" 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 255d840bb9..0320a05161 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.19.3 + 3.19.4 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.19.3 + 3.19.4 org.jruby diff --git a/src/Makefile.am b/src/Makefile.am index 3312e5db33..225061a313 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ else PTHREAD_DEF = endif -PROTOBUF_VERSION = 30:3:0 +PROTOBUF_VERSION = 30:4:0 if GCC # Turn on all warnings except for sign comparison (we ignore sign comparison diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index a04547b453..ff7ef9cfa0 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 c13eaab1ea..093a02ef51 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 3e9d7c5b6e..d558f5b7a3 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 71b018eb83..82fdb7f3c0 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 4f04a0b83a..2cfada9be0 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 658ceea0f6..be4f73b68a 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 c641a4acc2..dac4f5f0a3 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 2c71f9b5e5..37632cf5a9 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -153,7 +153,7 @@ #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 3019003 +#define PROTOBUF_VERSION 3019004 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 58b1cb8f62..28af27d606 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 f2beaef09c..8ac5cdbce2 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 44d680a197..2d71f08b44 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -82,7 +82,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 3019003 +#define GOOGLE_PROTOBUF_VERSION 3019004 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 671961edd5..cf66335515 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 d3c198a3e3..cf5943c68f 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 a4ac2896bc..36e906cd62 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -13,7 +13,7 @@ #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3019003 < PROTOBUF_MIN_PROTOC_VERSION +#if 3019004 < 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 b926a7d2097405fd3be4cc4009d61710562852d7 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 20 Jan 2022 08:39:38 +0000 Subject: [PATCH 169/207] Add ToProto() method to all C# descriptor classes Fixes #9425. --- .../Reflection/DescriptorsTest.cs | 24 +++++++++++++++++++ .../Reflection/EnumDescriptor.cs | 8 +++++++ .../Reflection/EnumValueDescriptor.cs | 8 +++++++ .../Reflection/FieldDescriptor.cs | 8 +++++++ .../Reflection/FileDescriptor.cs | 8 +++++++ .../Reflection/MessageDescriptor.cs | 8 +++++++ .../Reflection/MethodDescriptor.cs | 8 +++++++ .../Reflection/OneofDescriptor.cs | 24 +++++++++++++------ .../Reflection/ServiceDescriptor.cs | 8 +++++++ 9 files changed, 97 insertions(+), 7 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs index fab983d463..65c8b8267f 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs @@ -124,6 +124,7 @@ namespace Google.Protobuf.Reflection } Assert.AreEqual(10, file.SerializedData[0]); + TestDescriptorToProto(file.ToProto, file.Proto); } [Test] @@ -231,6 +232,7 @@ namespace Google.Protobuf.Reflection { Assert.AreEqual(i, messageType.EnumTypes[i].Index); } + TestDescriptorToProto(messageType.ToProto, messageType.Proto); } [Test] @@ -294,6 +296,11 @@ namespace Google.Protobuf.Reflection // For a field in a regular onoef, ContainingOneof and RealContainingOneof should be the same. Assert.AreEqual("oneof_field", fieldInOneof.ContainingOneof.Name); Assert.AreSame(fieldInOneof.ContainingOneof, fieldInOneof.RealContainingOneof); + + TestDescriptorToProto(primitiveField.ToProto, primitiveField.Proto); + TestDescriptorToProto(enumField.ToProto, enumField.Proto); + TestDescriptorToProto(foreignMessageField.ToProto, foreignMessageField.Proto); + TestDescriptorToProto(fieldInOneof.ToProto, fieldInOneof.Proto); } [Test] @@ -338,6 +345,8 @@ namespace Google.Protobuf.Reflection { Assert.AreEqual(i, enumType.Values[i].Index); } + TestDescriptorToProto(enumType.ToProto, enumType.Proto); + TestDescriptorToProto(nestedType.ToProto, nestedType.Proto); } [Test] @@ -361,6 +370,7 @@ namespace Google.Protobuf.Reflection } CollectionAssert.AreEquivalent(expectedFields, descriptor.Fields); + TestDescriptorToProto(descriptor.ToProto, descriptor.Proto); } [Test] @@ -370,6 +380,7 @@ namespace Google.Protobuf.Reflection Assert.IsNull(descriptor.Parser); Assert.IsNull(descriptor.ClrType); Assert.IsNull(descriptor.Fields[1].Accessor); + TestDescriptorToProto(descriptor.ToProto, descriptor.Proto); } // From TestFieldOrdering: @@ -391,6 +402,7 @@ namespace Google.Protobuf.Reflection { var descriptor = Google.Protobuf.Reflection.FileDescriptor.DescriptorProtoFileDescriptor; Assert.AreEqual("google/protobuf/descriptor.proto", descriptor.Name); + TestDescriptorToProto(descriptor.ToProto, descriptor.Proto); } [Test] @@ -453,5 +465,17 @@ namespace Google.Protobuf.Reflection } } } + + private static void TestDescriptorToProto(Func toProtoFunction, IMessage expectedProto) + { + var clone1 = toProtoFunction(); + var clone2 = toProtoFunction(); + Assert.AreNotSame(clone1, clone2); + Assert.AreNotSame(clone1, expectedProto); + Assert.AreNotSame(clone2, expectedProto); + + Assert.AreEqual(clone1, clone2); + Assert.AreEqual(clone1, expectedProto); + } } } diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index f7e8b5b5f2..3f2e1c41f5 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -68,6 +68,14 @@ namespace Google.Protobuf.Reflection internal EnumDescriptorProto Proto { get { return proto; } } + /// + /// Returns a clone of the underlying describing this enum. + /// Note that a copy is taken every time this method is called, so clients using it frequently + /// (and not modifying it) may want to cache the returned value. + /// + /// A protobuf representation of this enum descriptor. + public EnumDescriptorProto ToProto() => Proto.Clone(); + /// /// The brief name of the descriptor's target. /// diff --git a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs index 05097bd1da..50b26a46bb 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -55,6 +55,14 @@ namespace Google.Protobuf.Reflection internal EnumValueDescriptorProto Proto { get { return proto; } } + /// + /// Returns a clone of the underlying describing this enum value. + /// Note that a copy is taken every time this method is called, so clients using it frequently + /// (and not modifying it) may want to cache the returned value. + /// + /// A protobuf representation of this enum value descriptor. + public EnumValueDescriptorProto ToProto() => Proto.Clone(); + /// /// Returns the name of the enum value described by this object. /// diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index f9b90619ad..aeab686080 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -91,6 +91,14 @@ namespace Google.Protobuf.Reflection internal FieldDescriptorProto Proto { get; } + /// + /// Returns a clone of the underlying describing this field. + /// Note that a copy is taken every time this method is called, so clients using it frequently + /// (and not modifying it) may want to cache the returned value. + /// + /// A protobuf representation of this field descriptor. + public FieldDescriptorProto ToProto() => Proto.Clone(); + /// /// An extension identifier for this field, or null if this field isn't an extension. /// diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 724bb3a04d..d7701da92e 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -249,6 +249,14 @@ namespace Google.Protobuf.Reflection /// internal FileDescriptorProto Proto { get; } + /// + /// Returns a clone of the underlying describing this file. + /// Note that a copy is taken every time this method is called, so clients using it frequently + /// (and not modifying it) may want to cache the returned value. + /// + /// A protobuf representation of this file descriptor. + public FileDescriptorProto ToProto() => Proto.Clone(); + /// /// The syntax of the file /// diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index f56dd893b8..40a6ff832b 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -151,6 +151,14 @@ namespace Google.Protobuf.Reflection internal DescriptorProto Proto { get; } + /// + /// Returns a clone of the underlying describing this message. + /// Note that a copy is taken every time this method is called, so clients using it frequently + /// (and not modifying it) may want to cache the returned value. + /// + /// A protobuf representation of this message descriptor. + public DescriptorProto ToProto() => Proto.Clone(); + internal bool IsExtensionsInitialized(IMessage message) { if (Proto.ExtensionRange.Count == 0) diff --git a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs index 8e1503767b..f5ecf2ea83 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -114,6 +114,14 @@ namespace Google.Protobuf.Reflection internal MethodDescriptorProto Proto { get { return proto; } } + /// + /// Returns a clone of the underlying describing this method. + /// Note that a copy is taken every time this method is called, so clients using it frequently + /// (and not modifying it) may want to cache the returned value. + /// + /// A protobuf representation of this method descriptor. + public MethodDescriptorProto ToProto() => Proto.Clone(); + /// /// The brief name of the descriptor's target. /// diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs index b41d520515..ae29ded647 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -45,7 +45,6 @@ namespace Google.Protobuf.Reflection ///
public sealed class OneofDescriptor : DescriptorBase { - private readonly OneofDescriptorProto proto; private MessageDescriptor containingType; private IList fields; private readonly OneofAccessor accessor; @@ -53,7 +52,7 @@ namespace Google.Protobuf.Reflection internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName) : base(file, file.ComputeFullName(parent, proto.Name), index) { - this.proto = proto; + this.Proto = proto; containingType = parent; file.DescriptorPool.AddSymbol(this); @@ -68,7 +67,18 @@ namespace Google.Protobuf.Reflection /// /// The brief name of the descriptor's target. /// - public override string Name { get { return proto.Name; } } + public override string Name => Proto.Name; + + // Visible for testing + internal OneofDescriptorProto Proto { get; } + + /// + /// Returns a clone of the underlying describing this oneof. + /// Note that a copy is taken every time this method is called, so clients using it frequently + /// (and not modifying it) may want to cache the returned value. + /// + /// A protobuf representation of this oneof descriptor. + public OneofDescriptorProto ToProto() => Proto.Clone(); /// /// Gets the message type containing this oneof. @@ -118,7 +128,7 @@ namespace Google.Protobuf.Reflection /// The (possibly empty) set of custom options for this oneof. /// [Obsolete("CustomOptions are obsolete. Use the GetOptions method.")] - public CustomOptions CustomOptions => new CustomOptions(proto.Options?._extensions?.ValuesByNumber); + public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// /// The OneofOptions, defined in descriptor.proto. @@ -126,7 +136,7 @@ namespace Google.Protobuf.Reflection /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public OneofOptions GetOptions() => proto.Options?.Clone(); + public OneofOptions GetOptions() => Proto.Options?.Clone(); /// /// Gets a single value oneof option for this descriptor @@ -134,7 +144,7 @@ namespace Google.Protobuf.Reflection [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { - var value = proto.Options.GetExtension(extension); + var value = Proto.Options.GetExtension(extension); return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } @@ -144,7 +154,7 @@ namespace Google.Protobuf.Reflection [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { - return proto.Options.GetExtension(extension).Clone(); + return Proto.Options.GetExtension(extension).Clone(); } internal void CrossLink() diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index dab348b6f8..944ea11de1 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -73,6 +73,14 @@ namespace Google.Protobuf.Reflection internal ServiceDescriptorProto Proto { get { return proto; } } + /// + /// Returns a clone of the underlying describing this service. + /// Note that a copy is taken every time this method is called, so clients using it frequently + /// (and not modifying it) may want to cache the returned value. + /// + /// A protobuf representation of this service descriptor. + public ServiceDescriptorProto ToProto() => Proto.Clone(); + /// /// An unmodifiable list of methods in this service. /// From 749243db7e63deb763f7667d04784b8453957d10 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 28 Jan 2022 21:50:35 +0000 Subject: [PATCH 170/207] Must build project before running benchmarks (#9454) * Must build project before running benchmarks That is, it does not test the version downloaded from Maven central. * Update README.md --- benchmarks/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/benchmarks/README.md b/benchmarks/README.md index 9c25c7803d..7f9693ca13 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -87,7 +87,17 @@ To run all the benchmark dataset: ### Java: +First build the Java binary in the usual way with Maven: + +``` +$ cd java +$ mvn install +``` + +Assuming that completes successfully, + ``` +$ cd ../benchmarks $ make java ``` From 15add1af49f13d1661d3910d0eb6697b415a19d1 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Sat, 29 Jan 2022 01:44:42 +0100 Subject: [PATCH 171/207] Selectively add source or gen dir to includes. (#9438) When both directories are added this results in protoc emitting a "warning: directory does not exist.". This makes sense because when there are no inputs from the other directory, it is also not present n the sandbox where protoc is executed. --- protobuf.bzl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/protobuf.bzl b/protobuf.bzl index 26b6625327..826b6100b8 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -80,7 +80,14 @@ def _proto_gen_impl(ctx): source_dir = _SourceDir(ctx) gen_dir = _GenDir(ctx).rstrip("/") if source_dir: - import_flags = depset(direct=["-I" + source_dir, "-I" + gen_dir]) + has_sources = any([src.is_source for src in srcs]) + has_generated = any([not src.is_source for src in srcs]) + import_flags = [] + if has_sources: + import_flags += ["-I" + source_dir] + if has_generated: + import_flags += ["-I" + gen_dir] + import_flags = depset(direct=import_flags) else: import_flags = depset(direct=["-I."]) From a6a66a9ac8a84c91f137137a026e3f82cb83dac3 Mon Sep 17 00:00:00 2001 From: deannagarcia <69992229+deannagarcia@users.noreply.github.com> Date: Mon, 31 Jan 2022 16:10:49 -0800 Subject: [PATCH 172/207] Update package.xml Have PHP release notes link back to general release notes . --- php/ext/google/protobuf/package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index a451e92807..5bdb92833e 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -22,7 +22,7 @@ BSD-3-Clause - * Fixed a data loss bug that could occur when the number of optional fields in a message is an exact multiple of 32. (#9440). + * See github.com/protocolbuffers/protobuf/releases for release notes. From 7e5bfe88833c0319819fd2ce96eb379fa0d99164 Mon Sep 17 00:00:00 2001 From: Biswapriyo Nath Date: Wed, 2 Feb 2022 03:28:39 +0530 Subject: [PATCH 173/207] Fix checking Windows platform with preprocessor (#9460) Check _WIN32 instead of _MSC_VER because the later one is for MSVC only. This fixes building with mingw-w64 toolchain which uses GCC or Clang. --- src/google/protobuf/io/zero_copy_stream_unittest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index fe9b6a191e..d4e5b54514 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -49,7 +49,7 @@ #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #include #endif @@ -764,7 +764,7 @@ TEST_F(IoTest, FileIo) { } } -#ifndef _MSC_VER +#ifndef _WIN32 // This tests the FileInputStream with a non blocking file. It opens a pipe in // non blocking mode, then starts reading it. The writing thread starts writing // 100ms after that. From 349738dde50ec75940e9866d6c82a93f9c880f92 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Tue, 1 Feb 2022 23:22:23 +0000 Subject: [PATCH 174/207] Fixing java and protoc builds --- BUILD | 4 +- java/core/BUILD | 2 + .../protobuf/dynamic_message_test.proto | 15 - .../com/google/protobuf/Proto2LiteTest.kt | 913 +++++++++--------- .../protobuf/multiple_files_proto3.proto | 15 - .../kotlin/com/google/protobuf/Proto2Test.kt | 13 - .../kotlin/com/google/protobuf/Proto3Test.kt | 284 +++--- java/lite/generate-test-sources-build.xml | 1 + java/lite/pom.xml | 2 + 9 files changed, 630 insertions(+), 619 deletions(-) diff --git a/BUILD b/BUILD index df62e9e22b..5092c961f2 100644 --- a/BUILD +++ b/BUILD @@ -163,7 +163,6 @@ cc_library( "src/google/protobuf/arenastring.cc", "src/google/protobuf/extension_set.cc", "src/google/protobuf/generated_enum_util.cc", - "src/google/protobuf/generated_message_table_driven_lite.cc", "src/google/protobuf/generated_message_tctable_lite.cc", "src/google/protobuf/generated_message_util.cc", "src/google/protobuf/implicit_weak_message.cc", @@ -225,7 +224,6 @@ cc_library( "src/google/protobuf/field_mask.pb.cc", "src/google/protobuf/generated_message_bases.cc", "src/google/protobuf/generated_message_reflection.cc", - "src/google/protobuf/generated_message_table_driven.cc", "src/google/protobuf/generated_message_tctable_full.cc", "src/google/protobuf/io/gzip_stream.cc", "src/google/protobuf/io/printer.cc", @@ -501,6 +499,8 @@ cc_library( "src/google/protobuf/compiler/plugin.cc", "src/google/protobuf/compiler/plugin.pb.cc", "src/google/protobuf/compiler/python/python_generator.cc", + "src/google/protobuf/compiler/python/python_helpers.cc", + "src/google/protobuf/compiler/python/python_pyi_generator.cc", "src/google/protobuf/compiler/ruby/ruby_generator.cc", "src/google/protobuf/compiler/subprocess.cc", "src/google/protobuf/compiler/zip_writer.cc", diff --git a/java/core/BUILD b/java/core/BUILD index a698fc8e36..cf4ae7cd74 100644 --- a/java/core/BUILD +++ b/java/core/BUILD @@ -27,6 +27,7 @@ LITE_SRCS = [ "src/main/java/com/google/protobuf/CodedInputStreamReader.java", "src/main/java/com/google/protobuf/CodedOutputStream.java", "src/main/java/com/google/protobuf/CodedOutputStreamWriter.java", + "src/main/java/com/google/protobuf/CompileTimeConstant.java", "src/main/java/com/google/protobuf/DoubleArrayList.java", "src/main/java/com/google/protobuf/ExperimentalApi.java", "src/main/java/com/google/protobuf/ExtensionLite.java", @@ -41,6 +42,7 @@ LITE_SRCS = [ "src/main/java/com/google/protobuf/FloatArrayList.java", "src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java", "src/main/java/com/google/protobuf/GeneratedMessageLite.java", + "src/main/java/com/google/protobuf/InlineMe.java", "src/main/java/com/google/protobuf/IntArrayList.java", "src/main/java/com/google/protobuf/Internal.java", "src/main/java/com/google/protobuf/InvalidProtocolBufferException.java", diff --git a/java/core/src/test/proto/com/google/protobuf/dynamic_message_test.proto b/java/core/src/test/proto/com/google/protobuf/dynamic_message_test.proto index 42d09f0ac9..a0f28ac036 100644 --- a/java/core/src/test/proto/com/google/protobuf/dynamic_message_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/dynamic_message_test.proto @@ -28,20 +28,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -<<<<<<<< HEAD:java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto -syntax = "proto3"; - -package protobuf.kotlin.generator; - -option java_package = "com.google.protobuf.kotlin.generator"; -option java_multiple_files = true; - -enum NestedEnum { FOO = 0; } - -message MultipleFilesMessageA {} - -message MultipleFilesMessageB {} -======== syntax = "proto2"; package dynamic_message_test; @@ -54,4 +40,3 @@ message EmptyMessage {} message MessageWithMapFields { map string_message_map = 1; } ->>>>>>>> refs/tags/sync-piper:java/core/src/test/proto/com/google/protobuf/dynamic_message_test.proto diff --git a/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt b/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt index 1f45f654a7..76d4847bf5 100644 --- a/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt +++ b/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt @@ -71,110 +71,123 @@ class Proto2LiteTest { @Test fun testSetters() { assertThat( - testAllTypesLite { - optionalInt32 = 101 - optionalInt64 = 102 - optionalUint32 = 103 - optionalUint64 = 104 - optionalSint32 = 105 - optionalSint64 = 106 - optionalFixed32 = 107 - optionalFixed64 = 108 - optionalSfixed32 = 109 - optionalSfixed64 = 110 - optionalFloat = 111.0f - optionalDouble = 112.0 - optionalBool = true - optionalString = "115" - optionalBytes = toBytes("116") - optionalGroup = TestAllTypesLiteKt.optionalGroup { a = 117 } - optionalNestedMessage = nestedMessage { bb = 118 } - optionalForeignMessage = foreignMessageLite { c = 119 } - optionalImportMessage = ImportMessageLite.newBuilder().setD(120).build() - optionalPublicImportMessage = PublicImportMessageLite.newBuilder().setE(126).build() - optionalLazyMessage = nestedMessage { bb = 127 } - optionalNestedEnum = NestedEnum.BAZ - optionalForeignEnum = ForeignEnumLite.FOREIGN_LITE_BAZ - optionalImportEnum = ImportEnumLite.IMPORT_LITE_BAZ - optionalStringPiece = "124" - optionalCord = "125" - repeatedInt32.add(201) - repeatedInt64.add(202) - repeatedUint32.add(203) - repeatedUint64.add(204) - repeatedSint32.add(205) - repeatedSint64.add(206) - repeatedFixed32.add(207) - repeatedFixed64.add(208) - repeatedSfixed32.add(209) - repeatedSfixed64.add(210) - repeatedFloat.add(211f) - repeatedDouble.add(212.0) - repeatedBool.add(true) - repeatedString.add("215") - repeatedBytes.add(toBytes("216")) - repeatedGroup.add(TestAllTypesLiteKt.repeatedGroup { a = 217 }) - repeatedNestedMessage.add(nestedMessage { bb = 218 }) - repeatedForeignMessage.add(foreignMessageLite { c = 219 }) - repeatedImportMessage.add(ImportMessageLite.newBuilder().setD(220).build()) - repeatedLazyMessage.add(nestedMessage { bb = 227 }) - repeatedNestedEnum.add(NestedEnum.BAR) - repeatedForeignEnum.add(ForeignEnumLite.FOREIGN_LITE_BAR) - repeatedImportEnum.add(ImportEnumLite.IMPORT_LITE_BAR) - repeatedStringPiece.add("224") - repeatedCord.add("225") - repeatedInt32 += 301 - repeatedInt64 += 302 - repeatedUint32 += 303 - repeatedUint64 += 304 - repeatedSint32 += 305 - repeatedSint64 += 306 - repeatedFixed32 += 307 - repeatedFixed64 += 308 - repeatedSfixed32 += 309 - repeatedSfixed64 += 310 - repeatedFloat += 311f - repeatedDouble += 312.0 - repeatedBool += false - repeatedString += "315" - repeatedBytes += toBytes("316") - repeatedGroup += TestAllTypesLiteKt.repeatedGroup { a = 317 } - repeatedNestedMessage += nestedMessage { bb = 318 } - repeatedForeignMessage += foreignMessageLite { c = 319 } - repeatedImportMessage += ImportMessageLite.newBuilder().setD(320).build() - repeatedLazyMessage += TestAllTypesLiteKt.nestedMessage { bb = 327 } - repeatedNestedEnum += NestedEnum.BAZ - repeatedForeignEnum += ForeignEnumLite.FOREIGN_LITE_BAZ - repeatedImportEnum += ImportEnumLite.IMPORT_LITE_BAZ - repeatedStringPiece += "324" - repeatedCord += "325" - defaultInt32 = 401 - defaultInt64 = 402 - defaultUint32 = 403 - defaultUint64 = 404 - defaultSint32 = 405 - defaultSint64 = 406 - defaultFixed32 = 407 - defaultFixed64 = 408 - defaultSfixed32 = 409 - defaultSfixed64 = 410 - defaultFloat = 411f - defaultDouble = 412.0 - defaultBool = false - defaultString = "415" - defaultBytes = toBytes("416") - defaultNestedEnum = NestedEnum.FOO - defaultForeignEnum = ForeignEnumLite.FOREIGN_LITE_FOO - defaultImportEnum = ImportEnumLite.IMPORT_LITE_FOO - defaultStringPiece = "424" - defaultCord = "425" - oneofUint32 = 601 - oneofNestedMessage = TestAllTypesLiteKt.nestedMessage { bb = 602 } - oneofString = "603" - oneofBytes = toBytes("604") - } - ) - .isEqualTo(TestUtilLite.getAllLiteSetBuilder().build()) + testAllTypesLite { + optionalInt32 = 101 + optionalInt64 = 102 + optionalUint32 = 103 + optionalUint64 = 104 + optionalSint32 = 105 + optionalSint64 = 106 + optionalFixed32 = 107 + optionalFixed64 = 108 + optionalSfixed32 = 109 + optionalSfixed64 = 110 + optionalFloat = 111.0f + optionalDouble = 112.0 + optionalBool = true + optionalString = "115" + optionalBytes = toBytes("116") + optionalGroup = + TestAllTypesLiteKt.optionalGroup { a = 117 } + optionalNestedMessage = nestedMessage { bb = 118 } + optionalForeignMessage = + foreignMessageLite { c = 119 } + optionalImportMessage = + ImportMessageLite.newBuilder().setD(120).build() + optionalPublicImportMessage = + PublicImportMessageLite.newBuilder().setE(126).build() + optionalLazyMessage = nestedMessage { bb = 127 } + optionalNestedEnum = NestedEnum.BAZ + optionalForeignEnum = ForeignEnumLite.FOREIGN_LITE_BAZ + optionalImportEnum = ImportEnumLite.IMPORT_LITE_BAZ + optionalStringPiece = "124" + optionalCord = "125" + repeatedInt32.add(201) + repeatedInt64.add(202) + repeatedUint32.add(203) + repeatedUint64.add(204) + repeatedSint32.add(205) + repeatedSint64.add(206) + repeatedFixed32.add(207) + repeatedFixed64.add(208) + repeatedSfixed32.add(209) + repeatedSfixed64.add(210) + repeatedFloat.add(211f) + repeatedDouble.add(212.0) + repeatedBool.add(true) + repeatedString.add("215") + repeatedBytes.add(toBytes("216")) + repeatedGroup.add(TestAllTypesLiteKt.repeatedGroup { a = 217 }) + repeatedNestedMessage.add(nestedMessage { bb = 218 }) + repeatedForeignMessage.add( + foreignMessageLite { c = 219 } + ) + repeatedImportMessage.add( + ImportMessageLite.newBuilder().setD(220).build() + ) + repeatedLazyMessage.add(nestedMessage { bb = 227 }) + repeatedNestedEnum.add(NestedEnum.BAR) + repeatedForeignEnum.add(ForeignEnumLite.FOREIGN_LITE_BAR) + repeatedImportEnum.add(ImportEnumLite.IMPORT_LITE_BAR) + repeatedStringPiece.add("224") + repeatedCord.add("225") + repeatedInt32 += 301 + repeatedInt64 += 302 + repeatedUint32 += 303 + repeatedUint64 += 304 + repeatedSint32 += 305 + repeatedSint64 += 306 + repeatedFixed32 += 307 + repeatedFixed64 += 308 + repeatedSfixed32 += 309 + repeatedSfixed64 += 310 + repeatedFloat += 311f + repeatedDouble += 312.0 + repeatedBool += false + repeatedString += "315" + repeatedBytes += toBytes("316") + repeatedGroup += TestAllTypesLiteKt.repeatedGroup { a = 317 } + repeatedNestedMessage += nestedMessage { bb = 318 } + repeatedForeignMessage += + foreignMessageLite { c = 319 } + repeatedImportMessage += + ImportMessageLite.newBuilder().setD(320).build() + repeatedLazyMessage += + TestAllTypesLiteKt.nestedMessage { bb = 327 } + repeatedNestedEnum += NestedEnum.BAZ + repeatedForeignEnum += ForeignEnumLite.FOREIGN_LITE_BAZ + repeatedImportEnum += ImportEnumLite.IMPORT_LITE_BAZ + repeatedStringPiece += "324" + repeatedCord += "325" + defaultInt32 = 401 + defaultInt64 = 402 + defaultUint32 = 403 + defaultUint64 = 404 + defaultSint32 = 405 + defaultSint64 = 406 + defaultFixed32 = 407 + defaultFixed64 = 408 + defaultSfixed32 = 409 + defaultSfixed64 = 410 + defaultFloat = 411f + defaultDouble = 412.0 + defaultBool = false + defaultString = "415" + defaultBytes = toBytes("416") + defaultNestedEnum = NestedEnum.FOO + defaultForeignEnum = ForeignEnumLite.FOREIGN_LITE_FOO + defaultImportEnum = ImportEnumLite.IMPORT_LITE_FOO + defaultStringPiece = "424" + defaultCord = "425" + oneofUint32 = 601 + oneofNestedMessage = + TestAllTypesLiteKt.nestedMessage { bb = 602 } + oneofString = "603" + oneofBytes = toBytes("604") + } + ).isEqualTo( + TestUtilLite.getAllLiteSetBuilder().build() + ) } @Test @@ -230,70 +243,71 @@ class Proto2LiteTest { TestAllTypesLiteKt.repeatedGroup { a = 2 } ) ) - assertThat(repeatedGroup) - .isEqualTo( - listOf( - TestAllTypesLiteKt.repeatedGroup { a = 1 }, - TestAllTypesLiteKt.repeatedGroup { a = 2 } - ) + assertThat(repeatedGroup).isEqualTo( + listOf( + TestAllTypesLiteKt.repeatedGroup { a = 1 }, + TestAllTypesLiteKt.repeatedGroup { a = 2 } ) + ) repeatedGroup += listOf( TestAllTypesLiteKt.repeatedGroup { a = 3 }, TestAllTypesLiteKt.repeatedGroup { a = 4 } ) - assertThat(repeatedGroup) - .isEqualTo( - listOf( - TestAllTypesLiteKt.repeatedGroup { a = 1 }, - TestAllTypesLiteKt.repeatedGroup { a = 2 }, - TestAllTypesLiteKt.repeatedGroup { a = 3 }, - TestAllTypesLiteKt.repeatedGroup { a = 4 } - ) + assertThat(repeatedGroup).isEqualTo( + listOf( + TestAllTypesLiteKt.repeatedGroup { a = 1 }, + TestAllTypesLiteKt.repeatedGroup { a = 2 }, + TestAllTypesLiteKt.repeatedGroup { a = 3 }, + TestAllTypesLiteKt.repeatedGroup { a = 4 } ) + ) repeatedGroup[0] = TestAllTypesLiteKt.repeatedGroup { a = 5 } - assertThat(repeatedGroup) - .isEqualTo( - listOf( - TestAllTypesLiteKt.repeatedGroup { a = 5 }, - TestAllTypesLiteKt.repeatedGroup { a = 2 }, - TestAllTypesLiteKt.repeatedGroup { a = 3 }, - TestAllTypesLiteKt.repeatedGroup { a = 4 } - ) + assertThat(repeatedGroup).isEqualTo( + listOf( + TestAllTypesLiteKt.repeatedGroup { a = 5 }, + TestAllTypesLiteKt.repeatedGroup { a = 2 }, + TestAllTypesLiteKt.repeatedGroup { a = 3 }, + TestAllTypesLiteKt.repeatedGroup { a = 4 } ) + ) repeatedNestedMessage.addAll(listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 })) - assertThat(repeatedNestedMessage) - .isEqualTo(listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 })) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 } + ) + ) repeatedNestedMessage += listOf(nestedMessage { bb = 3 }, nestedMessage { bb = 4 }) - assertThat(repeatedNestedMessage) - .isEqualTo( - listOf( - nestedMessage { bb = 1 }, - nestedMessage { bb = 2 }, - nestedMessage { bb = 3 }, - nestedMessage { bb = 4 } - ) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } ) + ) repeatedNestedMessage[0] = nestedMessage { bb = 5 } - assertThat(repeatedNestedMessage) - .isEqualTo( - listOf( - nestedMessage { bb = 5 }, - nestedMessage { bb = 2 }, - nestedMessage { bb = 3 }, - nestedMessage { bb = 4 } - ) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 5 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } ) + ) repeatedNestedEnum.addAll(listOf(NestedEnum.FOO, NestedEnum.BAR)) assertThat(repeatedNestedEnum).isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR)) repeatedNestedEnum += listOf(NestedEnum.BAZ, NestedEnum.FOO) - assertThat(repeatedNestedEnum) - .isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO)) + assertThat(repeatedNestedEnum).isEqualTo( + listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) repeatedNestedEnum[0] = NestedEnum.BAR - assertThat(repeatedNestedEnum) - .isEqualTo(listOf(NestedEnum.BAR, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO)) + assertThat(repeatedNestedEnum).isEqualTo( + listOf(NestedEnum.BAR, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) } } @@ -366,155 +380,165 @@ class Proto2LiteTest { optionalInt32 = 101 optionalString = "115" } - val modifiedMessage = message.copy { optionalInt32 = 201 } + val modifiedMessage = message.copy { + optionalInt32 = 201 + } - assertThat(message) - .isEqualTo( - TestAllTypesLite.newBuilder().setOptionalInt32(101).setOptionalString("115").build() - ) - assertThat(modifiedMessage) - .isEqualTo( - TestAllTypesLite.newBuilder().setOptionalInt32(201).setOptionalString("115").build() - ) + assertThat(message).isEqualTo( + TestAllTypesLite.newBuilder() + .setOptionalInt32(101) + .setOptionalString("115") + .build() + ) + assertThat(modifiedMessage).isEqualTo( + TestAllTypesLite.newBuilder() + .setOptionalInt32(201) + .setOptionalString("115") + .build() + ) } @Test fun testOneof() { val message = testAllTypesLite { oneofString = "foo" - assertThat(oneofFieldCase).isEqualTo(TestAllTypesLite.OneofFieldCase.ONEOF_STRING) + assertThat(oneofFieldCase) + .isEqualTo(TestAllTypesLite.OneofFieldCase.ONEOF_STRING) assertThat(oneofString).isEqualTo("foo") clearOneofField() assertThat(hasOneofUint32()).isFalse() - assertThat(oneofFieldCase).isEqualTo(TestAllTypesLite.OneofFieldCase.ONEOFFIELD_NOT_SET) + assertThat(oneofFieldCase) + .isEqualTo(TestAllTypesLite.OneofFieldCase.ONEOFFIELD_NOT_SET) oneofUint32 = 5 } - assertThat(message.getOneofFieldCase()).isEqualTo(TestAllTypesLite.OneofFieldCase.ONEOF_UINT32) + assertThat(message.getOneofFieldCase()) + .isEqualTo(TestAllTypesLite.OneofFieldCase.ONEOF_UINT32) assertThat(message.getOneofUint32()).isEqualTo(5) } @Test fun testExtensionsSet() { assertThat( - testAllExtensionsLite { - this[UnittestLite.optionalInt32ExtensionLite] = 101 - this[UnittestLite.optionalInt64ExtensionLite] = 102L - this[UnittestLite.optionalUint32ExtensionLite] = 103 - this[UnittestLite.optionalUint64ExtensionLite] = 104L - this[UnittestLite.optionalSint32ExtensionLite] = 105 - this[UnittestLite.optionalSint64ExtensionLite] = 106L - this[UnittestLite.optionalFixed32ExtensionLite] = 107 - this[UnittestLite.optionalFixed64ExtensionLite] = 108L - this[UnittestLite.optionalSfixed32ExtensionLite] = 109 - this[UnittestLite.optionalSfixed64ExtensionLite] = 110L - this[UnittestLite.optionalFloatExtensionLite] = 111F - this[UnittestLite.optionalDoubleExtensionLite] = 112.0 - this[UnittestLite.optionalBoolExtensionLite] = true - this[UnittestLite.optionalStringExtensionLite] = "115" - this[UnittestLite.optionalBytesExtensionLite] = toBytes("116") - this[UnittestLite.optionalGroupExtensionLite] = optionalGroupExtensionLite { a = 117 } - this[UnittestLite.optionalNestedMessageExtensionLite] = - TestAllTypesLiteKt.nestedMessage { bb = 118 } - this[UnittestLite.optionalForeignMessageExtensionLite] = foreignMessageLite { c = 119 } - this[UnittestLite.optionalImportMessageExtensionLite] = - ImportMessageLite.newBuilder().setD(120).build() - this[UnittestLite.optionalPublicImportMessageExtensionLite] = - PublicImportMessageLite.newBuilder().setE(126).build() - this[UnittestLite.optionalLazyMessageExtensionLite] = - TestAllTypesLiteKt.nestedMessage { bb = 127 } - this[UnittestLite.optionalNestedEnumExtensionLite] = NestedEnum.BAZ - this[UnittestLite.optionalForeignEnumExtensionLite] = ForeignEnumLite.FOREIGN_LITE_BAZ - this[UnittestLite.optionalImportEnumExtensionLite] = ImportEnumLite.IMPORT_LITE_BAZ - this[UnittestLite.optionalStringPieceExtensionLite] = "124" - this[UnittestLite.optionalCordExtensionLite] = "125" - this[UnittestLite.repeatedInt32ExtensionLite].add(201) - this[UnittestLite.repeatedInt64ExtensionLite].add(202L) - this[UnittestLite.repeatedUint32ExtensionLite].add(203) - this[UnittestLite.repeatedUint64ExtensionLite].add(204L) - this[UnittestLite.repeatedSint32ExtensionLite].add(205) - this[UnittestLite.repeatedSint64ExtensionLite].add(206L) - this[UnittestLite.repeatedFixed32ExtensionLite].add(207) - this[UnittestLite.repeatedFixed64ExtensionLite].add(208L) - this[UnittestLite.repeatedSfixed32ExtensionLite].add(209) - this[UnittestLite.repeatedSfixed64ExtensionLite].add(210L) - this[UnittestLite.repeatedFloatExtensionLite].add(211F) - this[UnittestLite.repeatedDoubleExtensionLite].add(212.0) - this[UnittestLite.repeatedBoolExtensionLite].add(true) - this[UnittestLite.repeatedStringExtensionLite].add("215") - this[UnittestLite.repeatedBytesExtensionLite].add(toBytes("216")) - this[UnittestLite.repeatedGroupExtensionLite].add(repeatedGroupExtensionLite { a = 217 }) - this[UnittestLite.repeatedNestedMessageExtensionLite].add( - TestAllTypesLiteKt.nestedMessage { bb = 218 } - ) - this[UnittestLite.repeatedForeignMessageExtensionLite].add(foreignMessageLite { c = 219 }) - this[UnittestLite.repeatedImportMessageExtensionLite].add( - ImportMessageLite.newBuilder().setD(220).build() - ) - this[UnittestLite.repeatedLazyMessageExtensionLite].add( - TestAllTypesLiteKt.nestedMessage { bb = 227 } - ) - this[UnittestLite.repeatedNestedEnumExtensionLite].add(NestedEnum.BAR) - this[UnittestLite.repeatedForeignEnumExtensionLite].add(ForeignEnumLite.FOREIGN_LITE_BAR) - this[UnittestLite.repeatedImportEnumExtensionLite].add(ImportEnumLite.IMPORT_LITE_BAR) - this[UnittestLite.repeatedStringPieceExtensionLite].add("224") - this[UnittestLite.repeatedCordExtensionLite].add("225") - this[UnittestLite.repeatedInt32ExtensionLite] += 301 - this[UnittestLite.repeatedInt64ExtensionLite] += 302L - this[UnittestLite.repeatedUint32ExtensionLite] += 303 - this[UnittestLite.repeatedUint64ExtensionLite] += 304L - this[UnittestLite.repeatedSint32ExtensionLite] += 305 - this[UnittestLite.repeatedSint64ExtensionLite] += 306L - this[UnittestLite.repeatedFixed32ExtensionLite] += 307 - this[UnittestLite.repeatedFixed64ExtensionLite] += 308L - this[UnittestLite.repeatedSfixed32ExtensionLite] += 309 - this[UnittestLite.repeatedSfixed64ExtensionLite] += 310L - this[UnittestLite.repeatedFloatExtensionLite] += 311F - this[UnittestLite.repeatedDoubleExtensionLite] += 312.0 - this[UnittestLite.repeatedBoolExtensionLite] += false - this[UnittestLite.repeatedStringExtensionLite] += "315" - this[UnittestLite.repeatedBytesExtensionLite] += toBytes("316") - this[UnittestLite.repeatedGroupExtensionLite] += repeatedGroupExtensionLite { a = 317 } - this[UnittestLite.repeatedNestedMessageExtensionLite] += - TestAllTypesLiteKt.nestedMessage { bb = 318 } - this[UnittestLite.repeatedForeignMessageExtensionLite] += foreignMessageLite { c = 319 } - this[UnittestLite.repeatedImportMessageExtensionLite] += - ImportMessageLite.newBuilder().setD(320).build() - this[UnittestLite.repeatedLazyMessageExtensionLite] += - TestAllTypesLiteKt.nestedMessage { bb = 327 } - this[UnittestLite.repeatedNestedEnumExtensionLite] += NestedEnum.BAZ - this[UnittestLite.repeatedForeignEnumExtensionLite] += ForeignEnumLite.FOREIGN_LITE_BAZ - this[UnittestLite.repeatedImportEnumExtensionLite] += ImportEnumLite.IMPORT_LITE_BAZ - this[UnittestLite.repeatedStringPieceExtensionLite] += "324" - this[UnittestLite.repeatedCordExtensionLite] += "325" - this[UnittestLite.defaultInt32ExtensionLite] = 401 - this[UnittestLite.defaultInt64ExtensionLite] = 402L - this[UnittestLite.defaultUint32ExtensionLite] = 403 - this[UnittestLite.defaultUint64ExtensionLite] = 404L - this[UnittestLite.defaultSint32ExtensionLite] = 405 - this[UnittestLite.defaultSint64ExtensionLite] = 406L - this[UnittestLite.defaultFixed32ExtensionLite] = 407 - this[UnittestLite.defaultFixed64ExtensionLite] = 408L - this[UnittestLite.defaultSfixed32ExtensionLite] = 409 - this[UnittestLite.defaultSfixed64ExtensionLite] = 410L - this[UnittestLite.defaultFloatExtensionLite] = 411F - this[UnittestLite.defaultDoubleExtensionLite] = 412.0 - this[UnittestLite.defaultBoolExtensionLite] = false - this[UnittestLite.defaultStringExtensionLite] = "415" - this[UnittestLite.defaultBytesExtensionLite] = toBytes("416") - this[UnittestLite.defaultNestedEnumExtensionLite] = NestedEnum.FOO - this[UnittestLite.defaultForeignEnumExtensionLite] = ForeignEnumLite.FOREIGN_LITE_FOO - this[UnittestLite.defaultImportEnumExtensionLite] = ImportEnumLite.IMPORT_LITE_FOO - this[UnittestLite.defaultStringPieceExtensionLite] = "424" - this[UnittestLite.defaultCordExtensionLite] = "425" - this[UnittestLite.oneofUint32ExtensionLite] = 601 - this[UnittestLite.oneofNestedMessageExtensionLite] = - TestAllTypesLiteKt.nestedMessage { bb = 602 } - this[UnittestLite.oneofStringExtensionLite] = "603" - this[UnittestLite.oneofBytesExtensionLite] = toBytes("604") - } - ) - .isEqualTo(TestUtilLite.getAllLiteExtensionsSet()) + testAllExtensionsLite { + this[UnittestLite.optionalInt32ExtensionLite] = 101 + this[UnittestLite.optionalInt64ExtensionLite] = 102L + this[UnittestLite.optionalUint32ExtensionLite] = 103 + this[UnittestLite.optionalUint64ExtensionLite] = 104L + this[UnittestLite.optionalSint32ExtensionLite] = 105 + this[UnittestLite.optionalSint64ExtensionLite] = 106L + this[UnittestLite.optionalFixed32ExtensionLite] = 107 + this[UnittestLite.optionalFixed64ExtensionLite] = 108L + this[UnittestLite.optionalSfixed32ExtensionLite] = 109 + this[UnittestLite.optionalSfixed64ExtensionLite] = 110L + this[UnittestLite.optionalFloatExtensionLite] = 111F + this[UnittestLite.optionalDoubleExtensionLite] = 112.0 + this[UnittestLite.optionalBoolExtensionLite] = true + this[UnittestLite.optionalStringExtensionLite] = "115" + this[UnittestLite.optionalBytesExtensionLite] = toBytes("116") + this[UnittestLite.optionalGroupExtensionLite] = optionalGroupExtensionLite { a = 117 } + this[UnittestLite.optionalNestedMessageExtensionLite] = + TestAllTypesLiteKt.nestedMessage { bb = 118 } + this[UnittestLite.optionalForeignMessageExtensionLite] = foreignMessageLite { c = 119 } + this[UnittestLite.optionalImportMessageExtensionLite] = + ImportMessageLite.newBuilder().setD(120).build() + this[UnittestLite.optionalPublicImportMessageExtensionLite] = + PublicImportMessageLite.newBuilder().setE(126).build() + this[UnittestLite.optionalLazyMessageExtensionLite] = + TestAllTypesLiteKt.nestedMessage { bb = 127 } + this[UnittestLite.optionalNestedEnumExtensionLite] = NestedEnum.BAZ + this[UnittestLite.optionalForeignEnumExtensionLite] = ForeignEnumLite.FOREIGN_LITE_BAZ + this[UnittestLite.optionalImportEnumExtensionLite] = ImportEnumLite.IMPORT_LITE_BAZ + this[UnittestLite.optionalStringPieceExtensionLite] = "124" + this[UnittestLite.optionalCordExtensionLite] = "125" + this[UnittestLite.repeatedInt32ExtensionLite].add(201) + this[UnittestLite.repeatedInt64ExtensionLite].add(202L) + this[UnittestLite.repeatedUint32ExtensionLite].add(203) + this[UnittestLite.repeatedUint64ExtensionLite].add(204L) + this[UnittestLite.repeatedSint32ExtensionLite].add(205) + this[UnittestLite.repeatedSint64ExtensionLite].add(206L) + this[UnittestLite.repeatedFixed32ExtensionLite].add(207) + this[UnittestLite.repeatedFixed64ExtensionLite].add(208L) + this[UnittestLite.repeatedSfixed32ExtensionLite].add(209) + this[UnittestLite.repeatedSfixed64ExtensionLite].add(210L) + this[UnittestLite.repeatedFloatExtensionLite].add(211F) + this[UnittestLite.repeatedDoubleExtensionLite].add(212.0) + this[UnittestLite.repeatedBoolExtensionLite].add(true) + this[UnittestLite.repeatedStringExtensionLite].add("215") + this[UnittestLite.repeatedBytesExtensionLite].add(toBytes("216")) + this[UnittestLite.repeatedGroupExtensionLite].add(repeatedGroupExtensionLite { a = 217 }) + this[UnittestLite.repeatedNestedMessageExtensionLite].add( + TestAllTypesLiteKt.nestedMessage { bb = 218 } + ) + this[UnittestLite.repeatedForeignMessageExtensionLite].add(foreignMessageLite { c = 219 }) + this[UnittestLite.repeatedImportMessageExtensionLite].add( + ImportMessageLite.newBuilder().setD(220).build() + ) + this[UnittestLite.repeatedLazyMessageExtensionLite].add( + TestAllTypesLiteKt.nestedMessage { bb = 227 } + ) + this[UnittestLite.repeatedNestedEnumExtensionLite].add(NestedEnum.BAR) + this[UnittestLite.repeatedForeignEnumExtensionLite].add(ForeignEnumLite.FOREIGN_LITE_BAR) + this[UnittestLite.repeatedImportEnumExtensionLite].add(ImportEnumLite.IMPORT_LITE_BAR) + this[UnittestLite.repeatedStringPieceExtensionLite].add("224") + this[UnittestLite.repeatedCordExtensionLite].add("225") + this[UnittestLite.repeatedInt32ExtensionLite] += 301 + this[UnittestLite.repeatedInt64ExtensionLite] += 302L + this[UnittestLite.repeatedUint32ExtensionLite] += 303 + this[UnittestLite.repeatedUint64ExtensionLite] += 304L + this[UnittestLite.repeatedSint32ExtensionLite] += 305 + this[UnittestLite.repeatedSint64ExtensionLite] += 306L + this[UnittestLite.repeatedFixed32ExtensionLite] += 307 + this[UnittestLite.repeatedFixed64ExtensionLite] += 308L + this[UnittestLite.repeatedSfixed32ExtensionLite] += 309 + this[UnittestLite.repeatedSfixed64ExtensionLite] += 310L + this[UnittestLite.repeatedFloatExtensionLite] += 311F + this[UnittestLite.repeatedDoubleExtensionLite] += 312.0 + this[UnittestLite.repeatedBoolExtensionLite] += false + this[UnittestLite.repeatedStringExtensionLite] += "315" + this[UnittestLite.repeatedBytesExtensionLite] += toBytes("316") + this[UnittestLite.repeatedGroupExtensionLite] += repeatedGroupExtensionLite { a = 317 } + this[UnittestLite.repeatedNestedMessageExtensionLite] += + TestAllTypesLiteKt.nestedMessage { bb = 318 } + this[UnittestLite.repeatedForeignMessageExtensionLite] += foreignMessageLite { c = 319 } + this[UnittestLite.repeatedImportMessageExtensionLite] += + ImportMessageLite.newBuilder().setD(320).build() + this[UnittestLite.repeatedLazyMessageExtensionLite] += + TestAllTypesLiteKt.nestedMessage { bb = 327 } + this[UnittestLite.repeatedNestedEnumExtensionLite] += NestedEnum.BAZ + this[UnittestLite.repeatedForeignEnumExtensionLite] += ForeignEnumLite.FOREIGN_LITE_BAZ + this[UnittestLite.repeatedImportEnumExtensionLite] += ImportEnumLite.IMPORT_LITE_BAZ + this[UnittestLite.repeatedStringPieceExtensionLite] += "324" + this[UnittestLite.repeatedCordExtensionLite] += "325" + this[UnittestLite.defaultInt32ExtensionLite] = 401 + this[UnittestLite.defaultInt64ExtensionLite] = 402L + this[UnittestLite.defaultUint32ExtensionLite] = 403 + this[UnittestLite.defaultUint64ExtensionLite] = 404L + this[UnittestLite.defaultSint32ExtensionLite] = 405 + this[UnittestLite.defaultSint64ExtensionLite] = 406L + this[UnittestLite.defaultFixed32ExtensionLite] = 407 + this[UnittestLite.defaultFixed64ExtensionLite] = 408L + this[UnittestLite.defaultSfixed32ExtensionLite] = 409 + this[UnittestLite.defaultSfixed64ExtensionLite] = 410L + this[UnittestLite.defaultFloatExtensionLite] = 411F + this[UnittestLite.defaultDoubleExtensionLite] = 412.0 + this[UnittestLite.defaultBoolExtensionLite] = false + this[UnittestLite.defaultStringExtensionLite] = "415" + this[UnittestLite.defaultBytesExtensionLite] = toBytes("416") + this[UnittestLite.defaultNestedEnumExtensionLite] = NestedEnum.FOO + this[UnittestLite.defaultForeignEnumExtensionLite] = ForeignEnumLite.FOREIGN_LITE_FOO + this[UnittestLite.defaultImportEnumExtensionLite] = ImportEnumLite.IMPORT_LITE_FOO + this[UnittestLite.defaultStringPieceExtensionLite] = "424" + this[UnittestLite.defaultCordExtensionLite] = "425" + this[UnittestLite.oneofUint32ExtensionLite] = 601 + this[UnittestLite.oneofNestedMessageExtensionLite] = + TestAllTypesLiteKt.nestedMessage { bb = 602 } + this[UnittestLite.oneofStringExtensionLite] = "603" + this[UnittestLite.oneofBytesExtensionLite] = toBytes("604") + } + ).isEqualTo( + TestUtilLite.getAllLiteExtensionsSet() + ) } @Test @@ -560,72 +584,78 @@ class Proto2LiteTest { .isEqualTo(listOf("5", "2", "3", "4")) this[UnittestLite.repeatedGroupExtensionLite].addAll( - listOf(repeatedGroupExtensionLite { a = 1 }, repeatedGroupExtensionLite { a = 2 }) + listOf( + repeatedGroupExtensionLite { a = 1 }, + repeatedGroupExtensionLite { a = 2 } + ) ) - assertThat(this[UnittestLite.repeatedGroupExtensionLite]) - .isEqualTo( - listOf(repeatedGroupExtensionLite { a = 1 }, repeatedGroupExtensionLite { a = 2 }) + assertThat(this[UnittestLite.repeatedGroupExtensionLite]).isEqualTo( + listOf( + repeatedGroupExtensionLite { a = 1 }, + repeatedGroupExtensionLite { a = 2 } ) + ) this[UnittestLite.repeatedGroupExtensionLite] += - listOf(repeatedGroupExtensionLite { a = 3 }, repeatedGroupExtensionLite { a = 4 }) - assertThat(this[UnittestLite.repeatedGroupExtensionLite]) - .isEqualTo( - listOf( - repeatedGroupExtensionLite { a = 1 }, - repeatedGroupExtensionLite { a = 2 }, - repeatedGroupExtensionLite { a = 3 }, - repeatedGroupExtensionLite { a = 4 } - ) + listOf( + repeatedGroupExtensionLite { a = 3 }, + repeatedGroupExtensionLite { a = 4 } ) + assertThat(this[UnittestLite.repeatedGroupExtensionLite]).isEqualTo( + listOf( + repeatedGroupExtensionLite { a = 1 }, + repeatedGroupExtensionLite { a = 2 }, + repeatedGroupExtensionLite { a = 3 }, + repeatedGroupExtensionLite { a = 4 } + ) + ) this[UnittestLite.repeatedGroupExtensionLite][0] = repeatedGroupExtensionLite { a = 5 } - assertThat(this[UnittestLite.repeatedGroupExtensionLite]) - .isEqualTo( - listOf( - repeatedGroupExtensionLite { a = 5 }, - repeatedGroupExtensionLite { a = 2 }, - repeatedGroupExtensionLite { a = 3 }, - repeatedGroupExtensionLite { a = 4 } - ) + assertThat(this[UnittestLite.repeatedGroupExtensionLite]).isEqualTo( + listOf( + repeatedGroupExtensionLite { a = 5 }, + repeatedGroupExtensionLite { a = 2 }, + repeatedGroupExtensionLite { a = 3 }, + repeatedGroupExtensionLite { a = 4 } ) + ) this[UnittestLite.repeatedNestedMessageExtensionLite].addAll( listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 }) ) - assertThat(this[UnittestLite.repeatedNestedMessageExtensionLite]) - .isEqualTo(listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 })) + assertThat(this[UnittestLite.repeatedNestedMessageExtensionLite]).isEqualTo( + listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 }) + ) this[UnittestLite.repeatedNestedMessageExtensionLite] += listOf(nestedMessage { bb = 3 }, nestedMessage { bb = 4 }) - assertThat(this[UnittestLite.repeatedNestedMessageExtensionLite]) - .isEqualTo( - listOf( - nestedMessage { bb = 1 }, - nestedMessage { bb = 2 }, - nestedMessage { bb = 3 }, - nestedMessage { bb = 4 } - ) + assertThat(this[UnittestLite.repeatedNestedMessageExtensionLite]).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } ) + ) this[UnittestLite.repeatedNestedMessageExtensionLite][0] = nestedMessage { bb = 5 } - assertThat(this[UnittestLite.repeatedNestedMessageExtensionLite]) - .isEqualTo( - listOf( - nestedMessage { bb = 5 }, - nestedMessage { bb = 2 }, - nestedMessage { bb = 3 }, - nestedMessage { bb = 4 } - ) + assertThat(this[UnittestLite.repeatedNestedMessageExtensionLite]).isEqualTo( + listOf( + nestedMessage { bb = 5 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } ) - - this[UnittestLite.repeatedNestedEnumExtensionLite].addAll( - listOf(NestedEnum.FOO, NestedEnum.BAR) ) + + this[UnittestLite.repeatedNestedEnumExtensionLite] + .addAll(listOf(NestedEnum.FOO, NestedEnum.BAR)) assertThat(this[UnittestLite.repeatedNestedEnumExtensionLite]) .isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR)) this[UnittestLite.repeatedNestedEnumExtensionLite] += listOf(NestedEnum.BAZ, NestedEnum.FOO) - assertThat(this[UnittestLite.repeatedNestedEnumExtensionLite]) - .isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO)) + assertThat(this[UnittestLite.repeatedNestedEnumExtensionLite]).isEqualTo( + listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) this[UnittestLite.repeatedNestedEnumExtensionLite][0] = NestedEnum.BAR - assertThat(this[UnittestLite.repeatedNestedEnumExtensionLite]) - .isEqualTo(listOf(NestedEnum.BAR, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO)) + assertThat(this[UnittestLite.repeatedNestedEnumExtensionLite]).isEqualTo( + listOf(NestedEnum.BAR, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) } } @@ -696,56 +726,62 @@ class Proto2LiteTest { @Test fun testEmptyMessages() { - assertThat(testEmptyMessageLite {}).isEqualTo(TestEmptyMessageLite.newBuilder().build()) + assertThat( + testEmptyMessageLite {} + ).isEqualTo( + TestEmptyMessageLite.newBuilder().build() + ) - assertThat(testEmptyMessageWithExtensionsLite {}) - .isEqualTo(TestEmptyMessageWithExtensionsLite.newBuilder().build()) + assertThat( + testEmptyMessageWithExtensionsLite {} + ).isEqualTo( + TestEmptyMessageWithExtensionsLite.newBuilder().build() + ) } @Test fun testMapSetters() { assertThat( - testMapLite { - mapInt32Int32[1] = 2 - mapInt64Int64[1L] = 2L - mapUint32Uint32[1] = 2 - mapUint64Uint64[1L] = 2L - mapSint32Sint32[1] = 2 - mapSint64Sint64[1L] = 2L - mapFixed32Fixed32[1] = 2 - mapFixed64Fixed64[1L] = 2L - mapSfixed32Sfixed32[1] = 2 - mapSfixed64Sfixed64[1L] = 2L - mapInt32Float[1] = 2F - mapInt32Double[1] = 2.0 - mapBoolBool[true] = true - mapStringString["1"] = "2" - mapInt32Bytes[1] = toBytes("2") - mapInt32Enum[1] = MapEnumLite.MAP_ENUM_FOO_LITE - mapInt32ForeignMessage[1] = foreignMessageLite { c = 1 } - } - ) - .isEqualTo( - TestMapLite.newBuilder() - .putMapInt32Int32(1, 2) - .putMapInt64Int64(1L, 2L) - .putMapUint32Uint32(1, 2) - .putMapUint64Uint64(1L, 2L) - .putMapSint32Sint32(1, 2) - .putMapSint64Sint64(1L, 2L) - .putMapFixed32Fixed32(1, 2) - .putMapFixed64Fixed64(1L, 2L) - .putMapSfixed32Sfixed32(1, 2) - .putMapSfixed64Sfixed64(1L, 2L) - .putMapInt32Float(1, 2F) - .putMapInt32Double(1, 2.0) - .putMapBoolBool(true, true) - .putMapStringString("1", "2") - .putMapInt32Bytes(1, toBytes("2")) - .putMapInt32Enum(1, MapEnumLite.MAP_ENUM_FOO_LITE) - .putMapInt32ForeignMessage(1, foreignMessageLite { c = 1 }) - .build() - ) + testMapLite { + mapInt32Int32[1] = 2 + mapInt64Int64[1L] = 2L + mapUint32Uint32[1] = 2 + mapUint64Uint64[1L] = 2L + mapSint32Sint32[1] = 2 + mapSint64Sint64[1L] = 2L + mapFixed32Fixed32[1] = 2 + mapFixed64Fixed64[1L] = 2L + mapSfixed32Sfixed32[1] = 2 + mapSfixed64Sfixed64[1L] = 2L + mapInt32Float[1] = 2F + mapInt32Double[1] = 2.0 + mapBoolBool[true] = true + mapStringString["1"] = "2" + mapInt32Bytes[1] = toBytes("2") + mapInt32Enum[1] = MapEnumLite.MAP_ENUM_FOO_LITE + mapInt32ForeignMessage[1] = foreignMessageLite { c = 1 } + } + ).isEqualTo( + TestMapLite.newBuilder() + .putMapInt32Int32(1, 2) + .putMapInt64Int64(1L, 2L) + .putMapUint32Uint32(1, 2) + .putMapUint64Uint64(1L, 2L) + .putMapSint32Sint32(1, 2) + .putMapSint64Sint64(1L, 2L) + .putMapFixed32Fixed32(1, 2) + .putMapFixed64Fixed64(1L, 2L) + .putMapSfixed32Sfixed32(1, 2) + .putMapSfixed64Sfixed64(1L, 2L) + .putMapInt32Float(1, 2F) + .putMapInt32Double(1, 2.0) + .putMapBoolBool(true, true) + .putMapStringString("1", "2") + .putMapInt32Bytes(1, toBytes("2")) + .putMapInt32Enum(1, MapEnumLite.MAP_ENUM_FOO_LITE) + .putMapInt32ForeignMessage(1, foreignMessageLite { c = 1 }) + .build() + ) } @Test @@ -768,38 +804,38 @@ class Proto2LiteTest { mapInt32Enum.put(1, MapEnumLite.MAP_ENUM_FOO_LITE) assertThat(mapInt32Enum).isEqualTo(mapOf(1 to MapEnumLite.MAP_ENUM_FOO_LITE)) mapInt32Enum[2] = MapEnumLite.MAP_ENUM_BAR_LITE - assertThat(mapInt32Enum) - .isEqualTo(mapOf(1 to MapEnumLite.MAP_ENUM_FOO_LITE, 2 to MapEnumLite.MAP_ENUM_BAR_LITE)) + assertThat(mapInt32Enum).isEqualTo( + mapOf(1 to MapEnumLite.MAP_ENUM_FOO_LITE, 2 to MapEnumLite.MAP_ENUM_BAR_LITE) + ) mapInt32Enum.putAll( mapOf(3 to MapEnumLite.MAP_ENUM_BAZ_LITE, 4 to MapEnumLite.MAP_ENUM_FOO_LITE) ) - assertThat(mapInt32Enum) - .isEqualTo( - mapOf( - 1 to MapEnumLite.MAP_ENUM_FOO_LITE, - 2 to MapEnumLite.MAP_ENUM_BAR_LITE, - 3 to MapEnumLite.MAP_ENUM_BAZ_LITE, - 4 to MapEnumLite.MAP_ENUM_FOO_LITE - ) + assertThat(mapInt32Enum).isEqualTo( + mapOf( + 1 to MapEnumLite.MAP_ENUM_FOO_LITE, + 2 to MapEnumLite.MAP_ENUM_BAR_LITE, + 3 to MapEnumLite.MAP_ENUM_BAZ_LITE, + 4 to MapEnumLite.MAP_ENUM_FOO_LITE ) + ) mapInt32ForeignMessage.put(1, foreignMessageLite { c = 1 }) assertThat(mapInt32ForeignMessage).isEqualTo(mapOf(1 to foreignMessageLite { c = 1 })) mapInt32ForeignMessage[2] = foreignMessageLite { c = 2 } - assertThat(mapInt32ForeignMessage) - .isEqualTo(mapOf(1 to foreignMessageLite { c = 1 }, 2 to foreignMessageLite { c = 2 })) + assertThat(mapInt32ForeignMessage).isEqualTo( + mapOf(1 to foreignMessageLite { c = 1 }, 2 to foreignMessageLite { c = 2 }) + ) mapInt32ForeignMessage.putAll( mapOf(3 to foreignMessageLite { c = 3 }, 4 to foreignMessageLite { c = 4 }) ) - assertThat(mapInt32ForeignMessage) - .isEqualTo( - mapOf( - 1 to foreignMessageLite { c = 1 }, - 2 to foreignMessageLite { c = 2 }, - 3 to foreignMessageLite { c = 3 }, - 4 to foreignMessageLite { c = 4 } - ) + assertThat(mapInt32ForeignMessage).isEqualTo( + mapOf( + 1 to foreignMessageLite { c = 1 }, + 2 to foreignMessageLite { c = 2 }, + 3 to foreignMessageLite { c = 3 }, + 4 to foreignMessageLite { c = 4 } ) + ) } } @@ -856,57 +892,56 @@ class Proto2LiteTest { @Test fun testEvilNames() { assertThat( - evilNamesProto2 { - initialized = true - hasFoo = true - bar = "foo" - isInitialized = true - fooBar = "foo" - aLLCAPS += "foo" - aLLCAPSMAP[1] = true - hasUnderbarPrecedingNumeric1Foo = true - hasUnderbarPrecedingNumeric42Bar = true - hasUnderbarPrecedingNumeric123Foo42BarBaz = true - extension += "foo" - class_ += 1 - int = 1.0 - long = true - boolean = 1L - sealed = "foo" - interface_ = 1F - in_ = 1 - object_ = "foo" - cachedSize_ = "foo" - serializedSize_ = true - by = "foo" - } - ) - .isEqualTo( - EvilNamesProto2.newBuilder() - .setInitialized(true) - .setHasFoo(true) - .setBar("foo") - .setIsInitialized(true) - .setFooBar("foo") - .addALLCAPS("foo") - .putALLCAPSMAP(1, true) - .setHasUnderbarPrecedingNumeric1Foo(true) - .setHasUnderbarPrecedingNumeric42Bar(true) - .setHasUnderbarPrecedingNumeric123Foo42BarBaz(true) - .addExtension("foo") - .addClass_(1) - .setInt(1.0) - .setLong(true) - .setBoolean(1L) - .setSealed("foo") - .setInterface(1F) - .setIn(1) - .setObject("foo") - .setCachedSize_("foo") - .setSerializedSize_(true) - .setBy("foo") - .build() - ) + evilNamesProto2 { + initialized = true + hasFoo = true + bar = "foo" + isInitialized = true + fooBar = "foo" + aLLCAPS += "foo" + aLLCAPSMAP[1] = true + hasUnderbarPrecedingNumeric1Foo = true + hasUnderbarPrecedingNumeric42Bar = true + hasUnderbarPrecedingNumeric123Foo42BarBaz = true + extension += "foo" + class_ += 1 + int = 1.0 + long = true + boolean = 1L + sealed = "foo" + interface_ = 1F + in_ = 1 + object_ = "foo" + cachedSize_ = "foo" + serializedSize_ = true + by = "foo" + } + ).isEqualTo( + EvilNamesProto2.newBuilder() + .setInitialized(true) + .setHasFoo(true) + .setBar("foo") + .setIsInitialized(true) + .setFooBar("foo") + .addALLCAPS("foo") + .putALLCAPSMAP(1, true) + .setHasUnderbarPrecedingNumeric1Foo(true) + .setHasUnderbarPrecedingNumeric42Bar(true) + .setHasUnderbarPrecedingNumeric123Foo42BarBaz(true) + .addExtension("foo") + .addClass_(1) + .setInt(1.0) + .setLong(true) + .setBoolean(1L) + .setSealed("foo") + .setInterface(1F) + .setIn(1) + .setObject("foo") + .setCachedSize_("foo") + .setSerializedSize_(true) + .setBy("foo") + .build() + ) assertThat(interface_ {}).isEqualTo(Interface.newBuilder().build()) } diff --git a/java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto b/java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto index 42d09f0ac9..61141c54eb 100644 --- a/java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto +++ b/java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto @@ -28,7 +28,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -<<<<<<<< HEAD:java/kotlin-lite/src/test/proto/com/google/protobuf/multiple_files_proto3.proto syntax = "proto3"; package protobuf.kotlin.generator; @@ -41,17 +40,3 @@ enum NestedEnum { FOO = 0; } message MultipleFilesMessageA {} message MultipleFilesMessageB {} -======== -syntax = "proto2"; - -package dynamic_message_test; - -option java_package = "dynamicmessagetest"; -option java_outer_classname = "DynamicMessageTestProto"; - -message EmptyMessage {} - -message MessageWithMapFields { - map string_message_map = 1; -} ->>>>>>>> refs/tags/sync-piper:java/core/src/test/proto/com/google/protobuf/dynamic_message_test.proto diff --git a/java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt b/java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt index 4463bc1492..f3cbf2d04a 100644 --- a/java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt +++ b/java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt @@ -58,7 +58,6 @@ import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions import protobuf_unittest.copy import protobuf_unittest.foreignMessage import protobuf_unittest.optionalGroupExtension -import protobuf_unittest.optionalNestedMessageOrNull import protobuf_unittest.repeatedGroupExtension import protobuf_unittest.testAllExtensions import protobuf_unittest.testAllTypes @@ -954,16 +953,4 @@ class Proto2Test { assertThat(hasDo_()).isFalse() } } - - @Test - fun testGetOrNull() { - val noNestedMessage = testAllTypes {} - assertThat(noNestedMessage.optionalNestedMessageOrNull).isEqualTo(null) - - val someNestedMessage = testAllTypes { - optionalNestedMessage = TestAllTypesKt.nestedMessage { bb = 118 } - } - assertThat(someNestedMessage.optionalNestedMessageOrNull) - .isEqualTo(TestAllTypesKt.nestedMessage { bb = 118 }) - } } diff --git a/java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt b/java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt index ba69dca8fc..7b394da941 100644 --- a/java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt +++ b/java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt @@ -44,7 +44,6 @@ import proto3_unittest.UnittestProto3.TestAllTypes import proto3_unittest.UnittestProto3.TestAllTypes.NestedEnum import proto3_unittest.UnittestProto3.TestEmptyMessage import proto3_unittest.copy -import proto3_unittest.optionalNestedMessageOrNull import proto3_unittest.testAllTypes import proto3_unittest.testEmptyMessage import org.junit.Test @@ -87,61 +86,66 @@ class Proto3Test { assertThat(repeatedString).isEqualTo(listOf("5", "2", "3", "4")) repeatedNestedMessage.addAll(listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 })) - assertThat(repeatedNestedMessage) - .isEqualTo(listOf(nestedMessage { bb = 1 }, nestedMessage { bb = 2 })) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 } + ) + ) repeatedNestedMessage += listOf(nestedMessage { bb = 3 }, nestedMessage { bb = 4 }) - assertThat(repeatedNestedMessage) - .isEqualTo( - listOf( - nestedMessage { bb = 1 }, - nestedMessage { bb = 2 }, - nestedMessage { bb = 3 }, - nestedMessage { bb = 4 } - ) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 1 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } ) + ) repeatedNestedMessage[0] = nestedMessage { bb = 5 } - assertThat(repeatedNestedMessage) - .isEqualTo( - listOf( - nestedMessage { bb = 5 }, - nestedMessage { bb = 2 }, - nestedMessage { bb = 3 }, - nestedMessage { bb = 4 } - ) + assertThat(repeatedNestedMessage).isEqualTo( + listOf( + nestedMessage { bb = 5 }, + nestedMessage { bb = 2 }, + nestedMessage { bb = 3 }, + nestedMessage { bb = 4 } ) + ) repeatedNestedEnum.addAll(listOf(NestedEnum.FOO, NestedEnum.BAR)) assertThat(repeatedNestedEnum).isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR)) repeatedNestedEnum += listOf(NestedEnum.BAZ, NestedEnum.FOO) - assertThat(repeatedNestedEnum) - .isEqualTo(listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO)) + assertThat(repeatedNestedEnum).isEqualTo( + listOf(NestedEnum.FOO, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) repeatedNestedEnum[0] = NestedEnum.BAR - assertThat(repeatedNestedEnum) - .isEqualTo(listOf(NestedEnum.BAR, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO)) + assertThat(repeatedNestedEnum).isEqualTo( + listOf(NestedEnum.BAR, NestedEnum.BAR, NestedEnum.BAZ, NestedEnum.FOO) + ) } } @Test fun testClears() { assertThat( - testAllTypes { - optionalInt32 = 101 - clearOptionalInt32() + testAllTypes { + optionalInt32 = 101 + clearOptionalInt32() - optionalString = "115" - clearOptionalString() + optionalString = "115" + clearOptionalString() - optionalNestedMessage = TestAllTypesKt.nestedMessage { bb = 118 } - clearOptionalNestedMessage() + optionalNestedMessage = TestAllTypesKt.nestedMessage { bb = 118 } + clearOptionalNestedMessage() - optionalNestedEnum = NestedEnum.BAZ - clearOptionalNestedEnum() + optionalNestedEnum = NestedEnum.BAZ + clearOptionalNestedEnum() - oneofUint32 = 601 - clearOneofUint32() - } - ) - .isEqualTo(TestAllTypes.newBuilder().build()) + oneofUint32 = 601 + clearOneofUint32() + } + ).isEqualTo( + TestAllTypes.newBuilder().build() + ) } @Test @@ -150,110 +154,126 @@ class Proto3Test { optionalInt32 = 101 optionalString = "115" } - val modifiedMessage = message.copy { optionalInt32 = 201 } + val modifiedMessage = message.copy { + optionalInt32 = 201 + } - assertThat(message) - .isEqualTo(TestAllTypes.newBuilder().setOptionalInt32(101).setOptionalString("115").build()) - assertThat(modifiedMessage) - .isEqualTo(TestAllTypes.newBuilder().setOptionalInt32(201).setOptionalString("115").build()) + assertThat(message).isEqualTo( + TestAllTypes.newBuilder() + .setOptionalInt32(101) + .setOptionalString("115") + .build() + ) + assertThat(modifiedMessage).isEqualTo( + TestAllTypes.newBuilder() + .setOptionalInt32(201) + .setOptionalString("115") + .build() + ) } @Test fun testOneof() { val message = testAllTypes { oneofString = "foo" - assertThat(oneofFieldCase).isEqualTo(TestAllTypes.OneofFieldCase.ONEOF_STRING) + assertThat(oneofFieldCase) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOF_STRING) assertThat(oneofString).isEqualTo("foo") clearOneofField() - assertThat(oneofFieldCase).isEqualTo(TestAllTypes.OneofFieldCase.ONEOFFIELD_NOT_SET) + assertThat(oneofFieldCase) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOFFIELD_NOT_SET) oneofUint32 = 5 } - assertThat(message.getOneofFieldCase()).isEqualTo(TestAllTypes.OneofFieldCase.ONEOF_UINT32) + assertThat(message.getOneofFieldCase()) + .isEqualTo(TestAllTypes.OneofFieldCase.ONEOF_UINT32) assertThat(message.getOneofUint32()).isEqualTo(5) } @Test fun testEmptyMessages() { - assertThat(testEmptyMessage {}).isEqualTo(TestEmptyMessage.newBuilder().build()) + assertThat( + testEmptyMessage {} + ).isEqualTo( + TestEmptyMessage.newBuilder().build() + ) } @Test fun testEvilNames() { assertThat( - evilNamesProto3 { - initialized = true - hasFoo = true - bar = "foo" - isInitialized = true - fooBar = "foo" - aLLCAPS += "foo" - aLLCAPSMAP[1] = true - hasUnderbarPrecedingNumeric1Foo = true - hasUnderbarPrecedingNumeric42Bar = true - hasUnderbarPrecedingNumeric123Foo42BarBaz = true - extension += "foo" - class_ = "foo" - int = 1.0 - long = true - boolean = 1L - sealed = "foo" - interface_ = 1F - in_ = 1 - object_ = "foo" - cachedSize_ = "foo" - serializedSize_ = true - value = "foo" - index = 1L - values += "foo" - newValues += "foo" - builder = true - k[1] = 1 - v["foo"] = "foo" - key["foo"] = 1 - map[1] = "foo" - pairs["foo"] = 1 - LeadingUnderscore = "foo" - option = 1 - } - ) - .isEqualTo( - EvilNamesProto3.newBuilder() - .setInitialized(true) - .setHasFoo(true) - .setBar("foo") - .setIsInitialized(true) - .setFooBar("foo") - .addALLCAPS("foo") - .putALLCAPSMAP(1, true) - .setHasUnderbarPrecedingNumeric1Foo(true) - .setHasUnderbarPrecedingNumeric42Bar(true) - .setHasUnderbarPrecedingNumeric123Foo42BarBaz(true) - .addExtension("foo") - .setClass_("foo") - .setInt(1.0) - .setLong(true) - .setBoolean(1L) - .setSealed("foo") - .setInterface(1F) - .setIn(1) - .setObject("foo") - .setCachedSize_("foo") - .setSerializedSize_(true) - .setValue("foo") - .setIndex(1L) - .addValues("foo") - .addNewValues("foo") - .setBuilder(true) - .putK(1, 1) - .putV("foo", "foo") - .putKey("foo", 1) - .putMap(1, "foo") - .putPairs("foo", 1) - .setLeadingUnderscore("foo") - .setOption(1) - .build() - ) + evilNamesProto3 { + initialized = true + hasFoo = true + bar = "foo" + isInitialized = true + fooBar = "foo" + aLLCAPS += "foo" + aLLCAPSMAP[1] = true + hasUnderbarPrecedingNumeric1Foo = true + hasUnderbarPrecedingNumeric42Bar = true + hasUnderbarPrecedingNumeric123Foo42BarBaz = true + extension += "foo" + class_ = "foo" + int = 1.0 + long = true + boolean = 1L + sealed = "foo" + interface_ = 1F + in_ = 1 + object_ = "foo" + cachedSize_ = "foo" + serializedSize_ = true + value = "foo" + index = 1L + values += "foo" + newValues += "foo" + builder = true + k[1] = 1 + v["foo"] = "foo" + key["foo"] = 1 + map[1] = "foo" + pairs["foo"] = 1 + LeadingUnderscore = "foo" + option = 1 + } + ).isEqualTo( + EvilNamesProto3.newBuilder() + .setInitialized(true) + .setHasFoo(true) + .setBar("foo") + .setIsInitialized(true) + .setFooBar("foo") + .addALLCAPS("foo") + .putALLCAPSMAP(1, true) + .setHasUnderbarPrecedingNumeric1Foo(true) + .setHasUnderbarPrecedingNumeric42Bar(true) + .setHasUnderbarPrecedingNumeric123Foo42BarBaz(true) + .addExtension("foo") + .setClass_("foo") + .setInt(1.0) + .setLong(true) + .setBoolean(1L) + .setSealed("foo") + .setInterface(1F) + .setIn(1) + .setObject("foo") + .setCachedSize_("foo") + .setSerializedSize_(true) + .setValue("foo") + .setIndex(1L) + .addValues("foo") + .addNewValues("foo") + .setBuilder(true) + .putK(1, 1) + .putV("foo", "foo") + .putKey("foo", 1) + .putMap(1, "foo") + .putPairs("foo", 1) + .setLeadingUnderscore("foo") + .setOption(1) + .build() + ) assertThat(class_ {}).isEqualTo(Class.newBuilder().build()) } @@ -330,22 +350,16 @@ class Proto3Test { @Test fun testMultipleFiles() { - assertThat(com.google.protobuf.kotlin.generator.multipleFilesMessageA {}) - .isEqualTo(com.google.protobuf.kotlin.generator.MultipleFilesMessageA.newBuilder().build()) - - assertThat(com.google.protobuf.kotlin.generator.multipleFilesMessageB {}) - .isEqualTo(com.google.protobuf.kotlin.generator.MultipleFilesMessageB.newBuilder().build()) - } - - @Test - fun testGetOrNull() { - val noNestedMessage = testAllTypes {} - assertThat(noNestedMessage.optionalNestedMessageOrNull).isEqualTo(null) + assertThat( + com.google.protobuf.kotlin.generator.multipleFilesMessageA {} + ).isEqualTo( + com.google.protobuf.kotlin.generator.MultipleFilesMessageA.newBuilder().build() + ) - val someNestedMessage = testAllTypes { - optionalNestedMessage = TestAllTypesKt.nestedMessage { bb = 118 } - } - assertThat(someNestedMessage.optionalNestedMessageOrNull) - .isEqualTo(TestAllTypesKt.nestedMessage { bb = 118 }) + assertThat( + com.google.protobuf.kotlin.generator.multipleFilesMessageB {} + ).isEqualTo( + com.google.protobuf.kotlin.generator.MultipleFilesMessageB.newBuilder().build() + ) } } diff --git a/java/lite/generate-test-sources-build.xml b/java/lite/generate-test-sources-build.xml index 365194e1db..8123efb3f1 100644 --- a/java/lite/generate-test-sources-build.xml +++ b/java/lite/generate-test-sources-build.xml @@ -5,6 +5,7 @@ + diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 901ae6767a..c19d596868 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -105,6 +105,7 @@ CodedInputStreamReader.java CodedOutputStream.java CodedOutputStreamWriter.java + CompileTimeConstant.java DoubleArrayList.java ExperimentalApi.java ExtensionLite.java @@ -119,6 +120,7 @@ FloatArrayList.java GeneratedMessageInfoFactory.java GeneratedMessageLite.java + InlineMe.java IntArrayList.java Internal.java InvalidProtocolBufferException.java From a9cf69a0ed7766f56976e48a0c96300e94433511 Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 1 Feb 2022 16:27:56 -0700 Subject: [PATCH 175/207] Use matching soname when building with CMake as Makefile (#9178) This updates the CMake support to additionally symlink the soversion value to the generated shared library when so generated. This aligns the generated soversion with that traditionally used by the Makefile build workflow and provides cross-compatibility irrespective of build approach used. The primary version of the non-symlink library retains the actual (non-SO) project version for clarity and compatibility with installations built using prior versions of CMake support. An example of the net resulting symlink structures is shown below, where the most important aspect is that the symlink matching the embedded SONAME is present (libprotobuf.so.30 in the example case). Makefile: libprotobuf.so -> libprotobuf.so.30.0.0 libprotobuf.so.30 -> libprotobuf.so.30.0.0 libprotobuf.so.30.0.0 CMake: libprotobuf.so -> libprotobuf.so.30 libprotobuf.so.30 -> libprotobuf.so.3.19.0.0 libprotobuf.so.3.19.0.0 Fixes: #8635 --- cmake/libprotobuf.cmake | 2 ++ update_version.py | 36 +++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 668b8c2784..42f25668e1 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -125,6 +125,8 @@ if(MSVC AND protobuf_BUILD_SHARED_LIBS) endif() set_target_properties(libprotobuf PROPERTIES VERSION ${protobuf_VERSION} + # Use only the first SO version component for compatibility with Makefile emitted SONAME. + SOVERSION 30 OUTPUT_NAME ${LIB_PREFIX}protobuf DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") add_library(protobuf::libprotobuf ALIAS libprotobuf) diff --git a/update_version.py b/update_version.py index 2c2b4890eb..6e89555c87 100755 --- a/update_version.py +++ b/update_version.py @@ -61,6 +61,19 @@ def GetFullVersion(rc_suffix = '-rc-'): return '%s%s%s' % (NEW_VERSION, rc_suffix, RC_VERSION) +def GetSharedObjectVersion(): + protobuf_version_offset = 11 + expected_major_version = 3 + if NEW_VERSION_INFO[0] != expected_major_version: + print("""[ERROR] Major protobuf version has changed. Please update +update_version.py to readjust the protobuf_version_offset and +expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is +always increasing. + """) + exit(1) + return [NEW_VERSION_INFO[1] + protobuf_version_offset, NEW_VERSION_INFO[2], 0] + + def RewriteXml(filename, rewriter, add_xml_prefix=True): document = minidom.parse(filename) rewriter(document) @@ -89,6 +102,14 @@ def RewriteTextFile(filename, line_rewriter): f.close() +def UpdateCMake(): + RewriteTextFile('cmake/libprotobuf.cmake', + lambda line : re.sub( + r'SOVERSION [0-9]+\.[0-9]+(\.[0-9]+)?', + 'SOVERSION %s' % GetSharedObjectVersion()[0], + line)) + + def UpdateConfigure(): RewriteTextFile('configure.ac', lambda line : re.sub( @@ -270,22 +291,10 @@ def UpdateJavaScript(): def UpdateMakefile(): - protobuf_version_offset = 11 - expected_major_version = 3 - if NEW_VERSION_INFO[0] != expected_major_version: - print("""[ERROR] Major protobuf version has changed. Please update -update_version.py to readjust the protobuf_version_offset and -expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is -always increasing. - """) - exit(1) - - protobuf_version_info = '%d:%d:0' % ( - NEW_VERSION_INFO[1] + protobuf_version_offset, NEW_VERSION_INFO[2]) RewriteTextFile('src/Makefile.am', lambda line : re.sub( r'^PROTOBUF_VERSION = .*$', - 'PROTOBUF_VERSION = %s' % protobuf_version_info, + 'PROTOBUF_VERSION = %s' % ":".join(map(str,GetSharedObjectVersion())), line)) @@ -397,6 +406,7 @@ def UpdateBazel(): line)) +UpdateCMake() UpdateConfigure() UpdateCsharp() UpdateCpp() From fc9fb726f10fb4e129ab433496eee00ae78ea4ba Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 2 Feb 2022 01:02:08 +0000 Subject: [PATCH 176/207] Fix python and kotlin tests --- CHANGES.txt | 1 - .../protobuf/internal/json_format_test.py | 26 ------------------- .../protobuf/compiler/java/java_message.cc | 16 ++++++------ .../compiler/java/java_message_lite.cc | 16 ++++++------ 4 files changed, 16 insertions(+), 43 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 4054f35ad6..6a1e8b91b2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -23,7 +23,6 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Fix initialization bug in doc comment line numbers Kotlin - * Enhancements to Kotlin support for Any protobuf. * Add orNull extensions for optional message fields in Kotlin. Python diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index be33be171a..cb533c1f33 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -1049,14 +1049,8 @@ class JsonFormatTest(JsonFormatBase): def testInvalidTimestamp(self): message = json_format_proto3_pb2.TestTimestamp() text = '{"value": "10000-01-01T00:00:00.00Z"}' -<<<<<<< HEAD - self.assertRaisesRegex( - json_format.ParseError, - 'Failed to parse value field: ' -======= self.assertRaisesRegexp( json_format.ParseError, 'Failed to parse value field: ' ->>>>>>> refs/tags/sync-piper 'time data \'10000-01-01T00:00:00\' does not match' ' format \'%Y-%m-%dT%H:%M:%S\' at TestTimestamp.value.', json_format.Parse, text, message) @@ -1095,16 +1089,9 @@ class JsonFormatTest(JsonFormatBase): def testInvalidOneof(self): message = json_format_proto3_pb2.TestOneof() text = '{"oneofInt32Value": 1, "oneofStringValue": "2"}' -<<<<<<< HEAD - self.assertRaisesRegex( - json_format.ParseError, - 'Message type "proto3.TestOneof"' - ' should not have multiple "oneof_value" oneof fields.', -======= self.assertRaisesRegexp( json_format.ParseError, 'Message type "proto3.TestOneof"' ' should not have multiple "oneof_value" oneof fields at "TestOneof".', ->>>>>>> refs/tags/sync-piper json_format.Parse, text, message) def testInvalidListValue(self): @@ -1167,18 +1154,6 @@ class JsonFormatTest(JsonFormatBase): 'value', json_format.Parse, text, message) text = '{"value": 1234}' -<<<<<<< HEAD - self.assertRaisesRegex( - json_format.ParseError, - '@type is missing when parsing any message.', - json_format.Parse, text, message) - text = '{"@type": "type.googleapis.com/MessageNotExist", "value": 1234}' - self.assertRaisesRegex( - TypeError, - 'Can not find message descriptor by type_url: ' - 'type.googleapis.com/MessageNotExist.', - json_format.Parse, text, message) -======= self.assertRaisesRegex(json_format.ParseError, '@type is missing when parsing any message at Any', json_format.Parse, text, message) @@ -1187,7 +1162,6 @@ class JsonFormatTest(JsonFormatBase): json_format.ParseError, 'Can not find message descriptor by type_url: ' 'type.googleapis.com/MessageNotExist at Any', json_format.Parse, text, message) ->>>>>>> refs/tags/sync-piper # Only last part is to be used: b/25630112 text = (r'{"@type": "incorrect.googleapis.com/google.protobuf.Int32Value",' r'"value": 1234}') diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index b2a236f2cb..7fbad3f842 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -1526,7 +1526,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@Suppress(\"UNCHECKED_CAST\")\n" "@kotlin.jvm.JvmSynthetic\n" - "public operator fun get(extension: " + "public operator fun get(extension: " "com.google.protobuf.ExtensionLite<$message$, T>): T {\n" " return if (extension.isRepeated) {\n" " get(extension as com.google.protobuf.ExtensionLite<$message$, " @@ -1542,7 +1542,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" "@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n" - "public operator fun get(\n" + "public operator fun get(\n" " extension: com.google.protobuf.ExtensionLite<$message$, List>\n" "): com.google.protobuf.kotlin.ExtensionList {\n" " return com.google.protobuf.kotlin.ExtensionList(extension, " @@ -1571,7 +1571,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.PublishedApi\n" - "internal fun setExtension(extension: " + "internal fun setExtension(extension: " "com.google.protobuf.ExtensionLite<$message$, T>, " "value: T) {\n" " _builder.setExtension(extension, value)\n" @@ -1614,7 +1614,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "public fun com.google.protobuf.kotlin.ExtensionList com.google.protobuf.kotlin.ExtensionList.add(value: E) {\n" " _builder.addExtension(this.extension, value)\n" "}\n\n", @@ -1623,7 +1623,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "public inline operator fun " + "public inline operator fun " "com.google.protobuf.kotlin.ExtensionList.plusAssign" "(value: E) {\n" @@ -1633,7 +1633,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "public fun com.google.protobuf.kotlin.ExtensionList com.google.protobuf.kotlin.ExtensionList.addAll(values: Iterable) {\n" " for (value in values) {\n" " add(value)\n" @@ -1644,7 +1644,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "public inline operator fun " + "public inline operator fun " "com.google.protobuf.kotlin.ExtensionList.plusAssign(values: " "Iterable) {\n" @@ -1654,7 +1654,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "public operator fun " + "public operator fun " "com.google.protobuf.kotlin.ExtensionList.set(index: Int, value: " "E) {\n" diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index dd32c261ec..5be4b6b3ee 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -847,7 +847,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@Suppress(\"UNCHECKED_CAST\")\n" "@kotlin.jvm.JvmSynthetic\n" - "public operator fun get(extension: " + "public operator fun get(extension: " "com.google.protobuf.ExtensionLite<$message$, T>): T {\n" " return if (extension.isRepeated) {\n" " get(extension as com.google.protobuf.ExtensionLite<$message$, " @@ -863,7 +863,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" "@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n" - "public operator fun get(\n" + "public operator fun get(\n" " extension: com.google.protobuf.ExtensionLite<$message$, List>\n" "): com.google.protobuf.kotlin.ExtensionList {\n" " return com.google.protobuf.kotlin.ExtensionList(extension, " @@ -892,7 +892,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@kotlin.PublishedApi\n" - "internal fun setExtension(extension: " + "internal fun setExtension(extension: " "com.google.protobuf.ExtensionLite<$message$, T>, " "value: T) {\n" " _builder.setExtension(extension, value)\n" @@ -935,7 +935,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "public fun com.google.protobuf.kotlin.ExtensionList com.google.protobuf.kotlin.ExtensionList.add(value: E) {\n" " _builder.addExtension(this.extension, value)\n" "}\n\n", @@ -944,7 +944,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "public inline operator fun " + "public inline operator fun " "com.google.protobuf.kotlin.ExtensionList.plusAssign" "(value: E) {\n" @@ -954,7 +954,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "public fun com.google.protobuf.kotlin.ExtensionList com.google.protobuf.kotlin.ExtensionList.addAll(values: Iterable) {\n" " for (value in values) {\n" " add(value)\n" @@ -965,7 +965,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "public inline operator fun " + "public inline operator fun " "com.google.protobuf.kotlin.ExtensionList.plusAssign(values: " "Iterable) {\n" @@ -975,7 +975,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" - "public operator fun " + "public operator fun " "com.google.protobuf.kotlin.ExtensionList.set(index: Int, value: " "E) {\n" From 55645ca5138e8e745ad1af0251c5036e8bfe496d Mon Sep 17 00:00:00 2001 From: JCooky Date: Thu, 3 Feb 2022 01:29:25 +0900 Subject: [PATCH 177/207] Add cmake option protobuf_INSTALL for installation files (#7123) --- cmake/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ebdc85bed5..0896b852ca 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -41,6 +41,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES Intel) endif() # Options +option(protobuf_INSTALL "Install protobuf binaries and files" ON) if(WITH_PROTOC) set(protobuf_PROTOC_EXE ${WITH_PROTOC} CACHE FILEPATH "Protocol Buffer Compiler executable" FORCE) endif() @@ -305,7 +306,9 @@ if (protobuf_BUILD_CONFORMANCE) include(conformance.cmake) endif (protobuf_BUILD_CONFORMANCE) -include(install.cmake) +if (protobuf_INSTALL) + include(install.cmake) +endif (protobuf_INSTALL) if (protobuf_BUILD_EXAMPLES) include(examples.cmake) From e56d6936f3bfce2c786b39a6f50d8d9100160efd Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 2 Feb 2022 18:35:49 +0000 Subject: [PATCH 178/207] Fix spelling --- .../protobuf/compiler/cpp/cpp_parse_function_generator.cc | 2 +- src/google/protobuf/compiler/main.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc b/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc index 43a5adeda0..f26717b0e3 100644 --- a/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc @@ -326,7 +326,7 @@ TailCallTableInfo::TailCallTableInfo( const EnumDescriptor* enum_type = field->enum_type(); GOOGLE_CHECK_GT(enum_type->value_count(), 0) << enum_type->DebugString(); - // Check if the enum values are a single, continguous range. + // Check if the enum values are a single, contiguous range. std::vector enum_values; for (int i = 0, N = enum_type->value_count(); i < N; ++i) { enum_values.push_back(enum_type->value(i)->number()); diff --git a/src/google/protobuf/compiler/main.cc b/src/google/protobuf/compiler/main.cc index 7bddb314ba..08d77a639c 100644 --- a/src/google/protobuf/compiler/main.cc +++ b/src/google/protobuf/compiler/main.cc @@ -77,7 +77,7 @@ int ProtobufMain(int argc, char* argv[]) { python::Generator py_generator; cli.RegisterGenerator("--python_out", "--python_opt", &py_generator, "Generate Python source file."); - // Pyton pyi + // Python pyi python::PyiGenerator pyi_generator; cli.RegisterGenerator("--pyi_out", &pyi_generator, "Generate python pyi stub."); From d2ca349c2adfd2913bcc220787cd9fd8b1dc3c4f Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 2 Feb 2022 18:48:58 +0000 Subject: [PATCH 179/207] Fix python tests --- .../internal/well_known_types_test.py | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index c572bbf466..5a83bc8dd5 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -36,8 +36,6 @@ import collections.abc as collections_abc import datetime import unittest -import dateutil.tz - from google.protobuf import any_pb2 from google.protobuf import duration_pb2 from google.protobuf import field_mask_pb2 @@ -268,37 +266,25 @@ class TimeUtilTest(TimeUtilTestBase): message.FromDatetime(naive_end_of_time) self.assertEqual(naive_end_of_time, message.ToDatetime()) - # Two hours after the Unix Epoch, around the world. - @_parameterized.named_parameters( - ('London', [1970, 1, 1, 2], dateutil.tz.UTC), - ('Tokyo', [1970, 1, 1, 11], dateutil.tz.gettz('Japan')), - ('LA', [1969, 12, 31, 18], dateutil.tz.gettz('US/Pacific')), - ) - def testTimezoneAwareDatetimeConversion(self, date_parts, tzinfo): - original_datetime = datelib.CreateDatetime(*date_parts, tzinfo=tzinfo) + def testDatetimeConversionWithTimezone(self): + class TZ(datetime.tzinfo): - message = timestamp_pb2.Timestamp() - message.FromDatetime(original_datetime) - self.assertEqual(7200, message.seconds) - self.assertEqual(0, message.nanos) + def utcoffset(self, _): + return datetime.timedelta(hours=1) + + def dst(self, _): + return datetime.timedelta(0) + + def tzname(self, _): + return 'UTC+1' - # ToDatetime() with no parameters produces a naive UTC datetime, i.e. it not - # only loses the original timezone information (e.g. US/Pacific) as it's - # "normalised" to UTC, but also drops the information that the datetime - # represents a UTC one. - naive_datetime = message.ToDatetime() - self.assertEqual(datetime.datetime(1970, 1, 1, 2), naive_datetime) - self.assertIsNone(naive_datetime.tzinfo) - self.assertNotEqual(original_datetime, naive_datetime) # not even for UTC! - - # In contrast, ToDatetime(tzinfo=) produces an aware datetime in the given - # timezone. - aware_datetime = message.ToDatetime(tzinfo=tzinfo) - self.assertEqual(original_datetime, aware_datetime) - self.assertEqual( - datelib.CreateDatetime(1970, 1, 1, 2, tzinfo=dateutil.tz.UTC), - aware_datetime) - self.assertEqual(tzinfo, aware_datetime.tzinfo) + message1 = timestamp_pb2.Timestamp() + dt = datetime.datetime(1970, 1, 1, 1, tzinfo=TZ()) + message1.FromDatetime(dt) + message2 = timestamp_pb2.Timestamp() + dt = datetime.datetime(1970, 1, 1, 0) + message2.FromDatetime(dt) + self.assertEqual(message1, message2) def testTimedeltaConversion(self): message = duration_pb2.Duration() From 000da39ada672edc0836dbbfbd8992213e97bfbb Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 2 Feb 2022 19:21:42 +0000 Subject: [PATCH 180/207] Fix python tests --- Makefile.am | 1 - python/google/protobuf/internal/well_known_types_test.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index f9e4c7b185..d9ba7c1abf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -442,7 +442,6 @@ java_EXTRA_DIST= java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java \ java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java \ java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java \ - java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java \ java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java \ java/core/src/test/java/com/google/protobuf/IntArrayListTest.java \ java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java \ diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index 5a83bc8dd5..ec8c151795 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -266,7 +266,7 @@ class TimeUtilTest(TimeUtilTestBase): message.FromDatetime(naive_end_of_time) self.assertEqual(naive_end_of_time, message.ToDatetime()) - def testDatetimeConversionWithTimezone(self): + def testDatetimeConversionWithTimezone(self): class TZ(datetime.tzinfo): def utcoffset(self, _): From 7dff52929f19aa6ece36adbcef1d003cf54f7360 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 2 Feb 2022 21:08:44 +0000 Subject: [PATCH 181/207] Fixing tests --- Makefile.am | 2 ++ java/core/generate-test-sources-build.xml | 2 ++ python/google/protobuf/internal/well_known_types_test.py | 1 - .../protobuf/compiler/cpp/cpp_parse_function_generator.cc | 4 ---- src/google/protobuf/descriptor.cc | 3 ++- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index d9ba7c1abf..a447be4d2b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -308,6 +308,7 @@ java_EXTRA_DIST= java/core/src/main/java/com/google/protobuf/CodedInputStreamReader.java \ java/core/src/main/java/com/google/protobuf/CodedOutputStream.java \ java/core/src/main/java/com/google/protobuf/CodedOutputStreamWriter.java \ + java/core/src/main/java/com/google/protobuf/CompileTimeConstant.java \ java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java \ java/core/src/main/java/com/google/protobuf/Descriptors.java \ java/core/src/main/java/com/google/protobuf/DiscardUnknownFieldsParser.java \ @@ -331,6 +332,7 @@ java_EXTRA_DIST= java/core/src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java \ java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java \ java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java \ + java/core/src/main/java/com/google/protobuf/InlineMe.java \ java/core/src/main/java/com/google/protobuf/IntArrayList.java \ java/core/src/main/java/com/google/protobuf/Internal.java \ java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java \ diff --git a/java/core/generate-test-sources-build.xml b/java/core/generate-test-sources-build.xml index db44a15ab2..bad6f19c61 100644 --- a/java/core/generate-test-sources-build.xml +++ b/java/core/generate-test-sources-build.xml @@ -4,6 +4,7 @@ + @@ -22,6 +23,7 @@ + diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index ec8c151795..6653596b98 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -48,7 +48,6 @@ from google.protobuf.internal import test_util from google.protobuf.internal import well_known_types from google.protobuf import descriptor from google.protobuf import text_format -from google3.pyglib import datelib from google.protobuf.internal import _parameterized diff --git a/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc b/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc index f26717b0e3..a0bd93756c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc @@ -73,10 +73,6 @@ int TagSize(uint32_t field_number) { return 2; } -const char* CodedTagType(int tag_size) { - return tag_size == 1 ? "uint8_t" : "uint16_t"; -} - std::string FieldParseFunctionName( const TailCallTableInfo::FieldEntryInfo& entry, const Options& options); diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index a2552f67ec..8738df9105 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -256,7 +256,8 @@ class FlatAllocation { template bool Init() { - if (std::is_trivially_constructible::value) return true; + // Skip for the `char` block. No need to zero initialize it. + if (std::is_same::value) return true; for (int i = 0, size = Size(); i < size; ++i) { ::new (data() + BeginOffset() + sizeof(U) * i) U{}; } From a2f7cfab27739b0134fb86abab7597607928aa81 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 2 Feb 2022 22:21:04 +0000 Subject: [PATCH 182/207] Fixing more tests --- Makefile.am | 4 ++++ conformance/conformance_python.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index a447be4d2b..343b5f7020 100644 --- a/Makefile.am +++ b/Makefile.am @@ -446,6 +446,7 @@ java_EXTRA_DIST= java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java \ java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java \ java/core/src/test/java/com/google/protobuf/IntArrayListTest.java \ + java/core/src/test/java/com/google/protobuf/InvalidProtocolBufferExceptionTest.java \ java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java \ java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java \ java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java \ @@ -507,6 +508,7 @@ java_EXTRA_DIST= java/core/src/test/proto/com/google/protobuf/any_test.proto \ java/core/src/test/proto/com/google/protobuf/cached_field_size_test.proto \ java/core/src/test/proto/com/google/protobuf/deprecated_file.proto \ + java/core/src/test/proto/com/google/protobuf/dynamic_message_test.proto \ java/core/src/test/proto/com/google/protobuf/field_presence_test.proto \ java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto \ java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto \ @@ -597,10 +599,12 @@ java_EXTRA_DIST= java/util/src/main/java/com/google/protobuf/util/Structs.java \ java/util/src/main/java/com/google/protobuf/util/Timestamps.java \ java/util/src/main/java/com/google/protobuf/util/Values.java \ + java/util/src/test/java/com/google/protobuf/util/DurationsTest.java \ java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java \ java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java \ java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java \ java/util/src/test/java/com/google/protobuf/util/StructsTest.java \ + java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java \ java/util/src/test/java/com/google/protobuf/util/ValuesTest.java \ java/util/src/test/proto/com/google/protobuf/util/json_test.proto diff --git a/conformance/conformance_python.py b/conformance/conformance_python.py index f812752440..37ee36e24c 100755 --- a/conformance/conformance_python.py +++ b/conformance/conformance_python.py @@ -39,8 +39,8 @@ import sys import os from google.protobuf import json_format from google.protobuf import message -from google3.third_party.protobuf import test_messages_proto3_pb2 -from google3.third_party.protobuf import test_messages_proto2_pb2 +from google.protobuf import test_messages_proto3_pb2 +from google.protobuf import test_messages_proto2_pb2 from google.protobuf import text_format import conformance_pb2 From 2d87ce3cfec1ee66e781284176da350d6b2a3fe8 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 2 Feb 2022 23:10:04 +0000 Subject: [PATCH 183/207] Fix test --- src/google/protobuf/arenastring.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc index 4c19c919cd..cc154e9417 100644 --- a/src/google/protobuf/arenastring.cc +++ b/src/google/protobuf/arenastring.cc @@ -30,6 +30,7 @@ #include +#include #include #include #include From 8495372e1eb78a385f53bbc562c8935777107ce9 Mon Sep 17 00:00:00 2001 From: Stephen Kennedy Date: Wed, 2 Feb 2022 23:10:15 +0000 Subject: [PATCH 184/207] [cleanup] Msvc warnings (#9263) * Fix and reenable signed/unsigned warning C4018 * Only disable unary minus warning C4146 in tests --- BUILD | 2 -- cmake/CMakeLists.txt | 2 -- cmake/README.md | 2 -- cmake/tests.cmake | 5 +++++ src/google/protobuf/descriptor.cc | 2 +- src/google/protobuf/io/io_win32_unittest.cc | 6 +++--- src/google/protobuf/stubs/int128.cc | 7 ++++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/BUILD b/BUILD index df62e9e22b..23dcd6f910 100644 --- a/BUILD +++ b/BUILD @@ -28,9 +28,7 @@ ZLIB_DEPS = ["@zlib//:zlib"] ################################################################################ MSVC_COPTS = [ - "/wd4018", # -Wno-sign-compare "/wd4065", # switch statement contains 'default' but no 'case' labels - "/wd4146", # unary minus operator applied to unsigned type, result still unsigned "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 0896b852ca..da366b8b12 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -215,9 +215,7 @@ if (MSVC) add_definitions(/utf-8) # MSVC warning suppressions add_definitions( - /wd4018 # 'expression' : signed/unsigned mismatch /wd4065 # switch statement contains 'default' but no 'case' labels - /wd4146 # unary minus operator applied to unsigned type, result still unsigned /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data /wd4251 # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data diff --git a/cmake/README.md b/cmake/README.md index 89d00c1b6f..d75012cff0 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -320,8 +320,6 @@ The following warnings have been disabled while building the protobuf libraries and compiler. You may have to disable some of them in your own project as well, or live with them. -* C4018 - 'expression' : signed/unsigned mismatch -* C4146 - unary minus operator applied to unsigned type, result still unsigned * C4244 - Conversion from 'type1' to 'type2', possible loss of data. * C4251 - 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 529685856e..2c9e38ee5a 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -222,6 +222,11 @@ if(MINGW) endif() add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files}) +if (MSVC) + target_compile_options(tests PRIVATE + /wd4146 # unary minus operator applied to unsigned type, result still unsigned + ) +endif() target_link_libraries(tests libprotoc libprotobuf gmock_main) set(test_plugin_files diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index c8ce218a98..9a984c4801 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -1007,7 +1007,7 @@ class TableArena { } for (int i = kSmallSizes.size(); --i >= 0;) { - if (to_relocate->space_left() >= 1 + kSmallSizes[i]) { + if (to_relocate->space_left() >= 1U + kSmallSizes[i]) { to_relocate->PrependTo(small_size_blocks_[i]); return; } diff --git a/src/google/protobuf/io/io_win32_unittest.cc b/src/google/protobuf/io/io_win32_unittest.cc index c50f68d6a9..e8f378fcac 100644 --- a/src/google/protobuf/io/io_win32_unittest.cc +++ b/src/google/protobuf/io/io_win32_unittest.cc @@ -164,8 +164,8 @@ void IoWin32Test::SetUp() { test_tmpdir.clear(); wtest_tmpdir.clear(); DWORD size = ::GetCurrentDirectoryW(MAX_PATH, working_directory); - EXPECT_GT(size, 0); - EXPECT_LT(size, MAX_PATH); + EXPECT_GT(size, 0U); + EXPECT_LT(size, static_cast(MAX_PATH)); string tmp; bool ok = false; @@ -581,7 +581,7 @@ TEST_F(IoWin32Test, ExpandWildcardsFailsIfNoFileMatchesTest) { TEST_F(IoWin32Test, AsWindowsPathTest) { DWORD size = GetCurrentDirectoryW(0, nullptr); std::unique_ptr cwd_str(new wchar_t[size]); - EXPECT_GT(GetCurrentDirectoryW(size, cwd_str.get()), 0); + EXPECT_GT(GetCurrentDirectoryW(size, cwd_str.get()), 0U); wstring cwd = wstring(L"\\\\?\\") + cwd_str.get(); ASSERT_EQ(testonly_utf8_to_winpath("relative_mkdirtest"), diff --git a/src/google/protobuf/stubs/int128.cc b/src/google/protobuf/stubs/int128.cc index e5e159e1f8..36ead7e015 100644 --- a/src/google/protobuf/stubs/int128.cc +++ b/src/google/protobuf/stubs/int128.cc @@ -173,12 +173,13 @@ std::ostream& operator<<(std::ostream& o, const uint128& b) { // Add the requisite padding. std::streamsize width = o.width(0); - if (width > rep.size()) { + auto repSize = static_cast(rep.size()); + if (width > repSize) { if ((flags & std::ios::adjustfield) == std::ios::left) { - rep.append(width - rep.size(), o.fill()); + rep.append(width - repSize, o.fill()); } else { rep.insert(static_cast(0), - width - rep.size(), o.fill()); + width - repSize, o.fill()); } } From b2ff4f82c2ac82a9e2d68a08a8a5e0284a409daa Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 3 Feb 2022 01:05:20 +0000 Subject: [PATCH 185/207] Fixing tests --- .../com/google/protobuf/InvalidProtocolBufferException.java | 4 ++-- .../protobuf/compiler/cpp/cpp_parse_function_generator.cc | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java index 71ccb14b13..bd7039e1bc 100644 --- a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +++ b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java @@ -47,11 +47,11 @@ public class InvalidProtocolBufferException extends IOException { super(description); } - public InvalidProtocolBufferException(Exception e) { + public InvalidProtocolBufferException(IOException e) { super(e.getMessage(), e); } - public InvalidProtocolBufferException(String description, Exception e) { + public InvalidProtocolBufferException(String description, IOException e) { super(description, e); } diff --git a/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc b/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc index a0bd93756c..1070cae063 100644 --- a/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc @@ -283,7 +283,8 @@ TailCallTableInfo::TailCallTableInfo( // Fill in mini table entries. for (const FieldDescriptor* field : ordered_fields) { field_entries.push_back( - {field, (HasHasbit(field) ? has_bit_indices[field->index()] : -1)}); + {field, (HasHasbit(field) ? has_bit_indices[field->index()] : -1), 0, 0} + ); auto& entry = field_entries.back(); if (field->type() == FieldDescriptor::TYPE_MESSAGE || From 369388b472e5cc67d755abd7593617618defdbce Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 3 Feb 2022 01:09:18 +0000 Subject: [PATCH 186/207] More test fixes. --- BUILD | 1 - .../protobuf/compiler/cpp/cpp_parse_function_generator.cc | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/BUILD b/BUILD index 5092c961f2..9528848bd7 100644 --- a/BUILD +++ b/BUILD @@ -48,7 +48,6 @@ COPTS = select({ ":msvc": MSVC_COPTS, "//conditions:default": [ "-DHAVE_ZLIB", - "-Wmissing-field-initializers", "-Woverloaded-virtual", "-Wno-sign-compare", ], diff --git a/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc b/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc index 1070cae063..a0bd93756c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc @@ -283,8 +283,7 @@ TailCallTableInfo::TailCallTableInfo( // Fill in mini table entries. for (const FieldDescriptor* field : ordered_fields) { field_entries.push_back( - {field, (HasHasbit(field) ? has_bit_indices[field->index()] : -1), 0, 0} - ); + {field, (HasHasbit(field) ? has_bit_indices[field->index()] : -1)}); auto& entry = field_entries.back(); if (field->type() == FieldDescriptor::TYPE_MESSAGE || From 937b56f57bb74ce3348893c71c20b846d9da25cd Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Thu, 3 Feb 2022 09:14:44 -0800 Subject: [PATCH 187/207] Match service argument names to abstract interface (#9418) The base class/documentation suggest that the argument names are `self` and `done`, while the runtime used argument names `srvc` and `callback`. `mypy.stubtest` was able to identify this - as it compares the types (autogenerated by [`mypy-protobuf`](https://github.com/dropbox/mypy-protobuf/)) to the actual code generated by protoc at runtime. Since the stubs assume the generated code matches the abstract interface in service.py - it saw these differences. --- CONTRIBUTORS.txt | 5 ++++ python/google/protobuf/service_reflection.py | 29 ++++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index b8d97fc23d..c2da98f2c6 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -100,3 +100,8 @@ Patch contributors: Andrew Paprocki * Fixed minor IBM xlC compiler build issues * Added atomicops for AIX (POWER) + Nipunn Koorapati + * Provide a type alias field ValueType on EnumTypeWrapper + * Match service argument names to abstract interface + + diff --git a/python/google/protobuf/service_reflection.py b/python/google/protobuf/service_reflection.py index 75c51ff322..c39a1f5545 100644 --- a/python/google/protobuf/service_reflection.py +++ b/python/google/protobuf/service_reflection.py @@ -133,7 +133,7 @@ class _ServiceBuilder(object): """ self.descriptor = service_descriptor - def BuildService(self, cls): + def BuildService(builder, cls): """Constructs the service class. Args: @@ -143,18 +143,25 @@ class _ServiceBuilder(object): # CallMethod needs to operate with an instance of the Service class. This # internal wrapper function exists only to be able to pass the service # instance to the method that does the real CallMethod work. - def _WrapCallMethod(srvc, method_descriptor, - rpc_controller, request, callback): - return self._CallMethod(srvc, method_descriptor, - rpc_controller, request, callback) - self.cls = cls + # Making sure to use exact argument names from the abstract interface in + # service.py to match the type signature + def _WrapCallMethod(self, method_descriptor, + rpc_controller, request, done): + return builder._CallMethod(self, method_descriptor, + rpc_controller, request, done) + def _WrapGetRequestClass(self, method_descriptor): + return builder._GetRequestClass(method_descriptor) + def _WrapGetResponseClass(self, method_descriptor): + return builder._GetResponseClass(method_descriptor) + + builder.cls = cls cls.CallMethod = _WrapCallMethod - cls.GetDescriptor = staticmethod(lambda: self.descriptor) + cls.GetDescriptor = staticmethod(lambda: builder.descriptor) cls.GetDescriptor.__doc__ = "Returns the service descriptor." - cls.GetRequestClass = self._GetRequestClass - cls.GetResponseClass = self._GetResponseClass - for method in self.descriptor.methods: - setattr(cls, method.name, self._GenerateNonImplementedMethod(method)) + cls.GetRequestClass = _WrapGetRequestClass + cls.GetResponseClass = _WrapGetResponseClass + for method in builder.descriptor.methods: + setattr(cls, method.name, builder._GenerateNonImplementedMethod(method)) def _CallMethod(self, srvc, method_descriptor, rpc_controller, request, callback): From 3be46483ba11605ec9d29ae439a16c4fc6bf02c3 Mon Sep 17 00:00:00 2001 From: Phil Clay Date: Thu, 3 Feb 2022 09:49:57 -0800 Subject: [PATCH 188/207] Resolve more java field accessor name conflicts (#8198) * Remove javanano from .gitignore. Ignore java/lite/target * Resolve more java field accessor name conflicts. Previously, some proto field names would cause the java code generator to generate accessor names that conflict with method names from the message super classes/interfaces. A list of field names that cause such conflicts previously existed, but the list did not contain every field name that would cause a conflict. Additionally, only snake_case field names would be detected. If the field name was in camelCase, the conflict would not be detected. This change adds the complete set of field names that will cause assessor name conflicts, and detects conflicts in both snake_case and camelCase field names. Fixes #8142 * Prevent java accessor name conflicts for fields with leading underscores. Previously, some protobuf field names beginning with leading underscores (e.g. _class) would cause uncompilable java code to be generated due to assessor name conflicts. Now, non-conflicting java accessor method names are created for those fields * Improve comments/documentation for conversion from snake case to camel case Rename snakeCaseToCamelCase to snakeCaseToLowerCamelCase Add snakeCaseToUpperCamelCase Add clarifying in-line comments for field name generation Remove explicit version numbers from references. * Fix indents and typo * Unnest
 tag

* improve grammar in comments
are colliding -> collide

* Remove ternary operator and improve comments

* Fix typo in comment
---
 .../DescriptorMessageInfoFactory.java         | 123 ++++++++++++++++--
 .../protobuf/test_bad_identifiers.proto       |  71 ++++++++--
 .../protobuf/compiler/java/java_helpers.cc    |  27 ++--
 3 files changed, 193 insertions(+), 28 deletions(-)

diff --git a/java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java b/java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
index 7975136596..adee556903 100644
--- a/java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
+++ b/java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
@@ -61,8 +61,31 @@ import java.util.concurrent.ConcurrentHashMap;
 final class DescriptorMessageInfoFactory implements MessageInfoFactory {
   private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
   private static final DescriptorMessageInfoFactory instance = new DescriptorMessageInfoFactory();
+
+  /**
+   * Names that should be avoided (in UpperCamelCase format).
+   * Using them causes the compiler to generate accessors whose names
+   * collide with methods defined in base classes.
+   *
+   * Keep this list in sync with kForbiddenWordList in
+   * src/google/protobuf/compiler/java/java_helpers.cc
+   */
   private static final Set specialFieldNames =
-      new HashSet<>(Arrays.asList("cached_size", "serialized_size", "class"));
+      new HashSet<>(Arrays.asList(
+        // java.lang.Object:
+        "Class",
+        // com.google.protobuf.MessageLiteOrBuilder:
+        "DefaultInstanceForType",
+        // com.google.protobuf.MessageLite:
+        "ParserForType",
+        "SerializedSize",
+        // com.google.protobuf.MessageOrBuilder:
+        "AllFields",
+        "DescriptorForType",
+        "InitializationErrorString",
+        "UnknownFields",
+        // obsolete. kept for backwards compatibility of generated code
+        "CachedSize"));
 
   // Disallow construction - it's a singleton.
   private DescriptorMessageInfoFactory() {}
@@ -593,21 +616,101 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
     String name = (fd.getType() == FieldDescriptor.Type.GROUP)
                   ? fd.getMessageType().getName()
                   : fd.getName();
-    String suffix = specialFieldNames.contains(name) ? "__" : "_";
-    return snakeCaseToCamelCase(name) + suffix;
+
+    // convert to UpperCamelCase for comparison to the specialFieldNames
+    // (which are in UpperCamelCase)
+    String upperCamelCaseName = snakeCaseToUpperCamelCase(name);
+
+    // Append underscores to match the behavior of the protoc java compiler
+    final String suffix;
+    if (specialFieldNames.contains(upperCamelCaseName)) {
+      // For proto field names that match the specialFieldNames,
+      // the protoc java compiler appends "__" to the java field name
+      // to prevent the field's accessor method names from clashing with other methods.
+      // For example:
+      //     proto field name = "class"
+      //     java field name = "class__"
+      //     accessor method name = "getClass_()"  (so that it does not clash with Object.getClass())
+      suffix = "__";
+    } else {
+      // For other proto field names,
+      // the protoc java compiler appends "_" to the java field name
+      // to prevent field names from clashing with java keywords.
+      // For example:
+      //     proto field name = "int"
+      //     java field name = "int_" (so that it does not clash with int keyword)
+      //     accessor method name = "getInt()"
+      suffix = "_";
+    }
+    return snakeCaseToLowerCamelCase(name) + suffix;
   }
 
   private static String getCachedSizeFieldName(FieldDescriptor fd) {
-    return snakeCaseToCamelCase(fd.getName()) + "MemoizedSerializedSize";
+    return snakeCaseToLowerCamelCase(fd.getName()) + "MemoizedSerializedSize";
+  }
+
+  /**
+   * Converts a snake case string into lower camel case.
+   *
+   * 

Some examples:

+ *
+   *     snakeCaseToLowerCamelCase("foo_bar") => "fooBar"
+   *     snakeCaseToLowerCamelCase("foo") => "foo"
+   * 
+ * + * @param snakeCase the string in snake case to convert + * @return the string converted to camel case, with a lowercase first character + */ + private static String snakeCaseToLowerCamelCase(String snakeCase) { + return snakeCaseToCamelCase(snakeCase, false); } /** - * This method must match exactly with the corresponding function in protocol compiler. See: - * https://github.com/google/protobuf/blob/v3.0.0/src/google/protobuf/compiler/java/java_helpers.cc#L153 + * Converts a snake case string into upper camel case. + * + *

Some examples:

+ *
+   *     snakeCaseToUpperCamelCase("foo_bar") => "FooBar"
+   *     snakeCaseToUpperCamelCase("foo") => "Foo"
+   * 
+ * + * @param snakeCase the string in snake case to convert + * @return the string converted to camel case, with an uppercase first character + */ + private static String snakeCaseToUpperCamelCase(String snakeCase) { + return snakeCaseToCamelCase(snakeCase, true); + } + + /** + * Converts a snake case string into camel case. + * + *

For better readability, prefer calling either + * {@link #snakeCaseToLowerCamelCase(String)} or {@link #snakeCaseToUpperCamelCase(String)}.

+ * + *

Some examples:

+ *
+   *     snakeCaseToCamelCase("foo_bar", false) => "fooBar"
+   *     snakeCaseToCamelCase("foo_bar", true) => "FooBar"
+   *     snakeCaseToCamelCase("foo", false) => "foo"
+   *     snakeCaseToCamelCase("foo", true) => "Foo"
+   *     snakeCaseToCamelCase("Foo", false) => "foo"
+   *     snakeCaseToCamelCase("fooBar", false) => "fooBar"
+   * 
+ * + *

This implementation of this method must exactly match the corresponding + * function in the protocol compiler. Specifically, the + * {@code UnderscoresToCamelCase} function in + * {@code src/google/protobuf/compiler/java/java_helpers.cc}.

+ * + * @param snakeCase the string in snake case to convert + * @param capFirst true if the first letter of the returned string should be uppercase. + * false if the first letter of the returned string should be lowercase. + * @return the string converted to camel case, with an uppercase or lowercase first + * character depending on if {@code capFirst} is true or false, respectively */ - private static String snakeCaseToCamelCase(String snakeCase) { + private static String snakeCaseToCamelCase(String snakeCase, boolean capFirst) { StringBuilder sb = new StringBuilder(snakeCase.length() + 1); - boolean capNext = false; + boolean capNext = capFirst; for (int ctr = 0; ctr < snakeCase.length(); ctr++) { char next = snakeCase.charAt(ctr); if (next == '_') { @@ -653,7 +756,7 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory { /** Constructs the name of the get method for the given field in the proto. */ private static String getterForField(String snakeCase) { - String camelCase = snakeCaseToCamelCase(snakeCase); + String camelCase = snakeCaseToLowerCamelCase(snakeCase); StringBuilder builder = new StringBuilder("get"); // Capitalize the first character in the field name. builder.append(Character.toUpperCase(camelCase.charAt(0))); @@ -679,7 +782,7 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory { } private static OneofInfo newInfo(Class messageType, OneofDescriptor desc) { - String camelCase = snakeCaseToCamelCase(desc.getName()); + String camelCase = snakeCaseToLowerCamelCase(desc.getName()); String valueFieldName = camelCase + "_"; String caseFieldName = camelCase + "Case_"; diff --git a/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto b/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto index 8bf1691431..0f481f5639 100644 --- a/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto +++ b/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto @@ -43,10 +43,61 @@ option java_generic_services = true; // auto-added option java_package = "com.google.protobuf"; option java_outer_classname = "TestBadIdentifiersProto"; -message TestMessage { - optional string cached_size = 1; - optional string serialized_size = 2; - optional string class = 3; +// Message with field names using underscores that conflict with accessors in the base message class in java. +// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc +message ForbiddenWordsUnderscoreMessage { + // java.lang.Object + optional bool class = 1; + // com.google.protobuf.MessageLiteOrBuilder + optional bool default_instance_for_type = 2; + // com.google.protobuf.MessageLite + optional bool parser_for_type = 3; + optional bool serialized_size = 4; + // com.google.protobuf.MessageOrBuilder + optional bool all_fields = 5; + optional bool descriptor_for_type = 6; + optional bool initialization_error_string = 7; + optional bool unknown_fields = 8; + // obsolete. kept for backwards compatibility of generated code + optional bool cached_size = 9; +} + +// Message with field names using leading underscores that conflict with accessors in the base message class in java. +// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc +message ForbiddenWordsLeadingUnderscoreMessage { + // java.lang.Object + optional bool _class = 1; + // com.google.protobuf.MessageLiteOrBuilder + optional bool _default_instance_for_type = 2; + // com.google.protobuf.MessageLite + optional bool _parser_for_type = 3; + optional bool _serialized_size = 4; + // com.google.protobuf.MessageOrBuilder + optional bool _all_fields = 5; + optional bool _descriptor_for_type = 6; + optional bool _initialization_error_string = 7; + optional bool _unknown_fields = 8; + // obsolete. kept for backwards compatibility of generated code + optional bool _cached_size = 9; +} + +// Message with field names in camel case that conflict with accessors in the base message class in java. +// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc +message ForbiddenWordsCamelMessage { + // java.lang.Object + optional bool class = 1; + // com.google.protobuf.MessageLiteOrBuilder + optional bool defaultInstanceForType = 2; + // com.google.protobuf.MessageLite + optional bool serializedSize = 3; + optional bool parserForType = 4; + // com.google.protobuf.MessageOrBuilder: + optional bool initializationErrorString = 5; + optional bool descriptorForType = 6; + optional bool allFields = 7; + optional bool unknownFields = 8; + // obsolete. kept for backwards compatibility of generated code + optional bool cachedSize = 9; } message Descriptor { @@ -84,7 +135,7 @@ message Deprecated { optional int32 field1 = 1 [deprecated = true]; optional TestEnum field2 = 2 [deprecated = true]; - optional TestMessage field3 = 3 [deprecated = true]; + optional ForbiddenWordsUnderscoreMessage field3 = 3 [deprecated = true]; } message Override { @@ -117,7 +168,7 @@ message Double { } service TestConflictingMethodNames { - rpc Override(TestMessage) returns (TestMessage); + rpc Override(ForbiddenWordsUnderscoreMessage) returns (ForbiddenWordsUnderscoreMessage); } message TestConflictingFieldNames { @@ -125,24 +176,24 @@ message TestConflictingFieldNames { UNKNOWN = 0; FOO = 1; } - message TestMessage {} + message ForbiddenWordsUnderscoreMessage {} repeated int32 int32_field = 1; repeated TestEnum enum_field = 2; repeated string string_field = 3; repeated bytes bytes_field = 4; - repeated TestMessage message_field = 5; + repeated ForbiddenWordsUnderscoreMessage message_field = 5; optional int32 int32_field_count = 11; optional TestEnum enum_field_count = 12; optional string string_field_count = 13; optional bytes bytes_field_count = 14; - optional TestMessage message_field_count = 15; + optional ForbiddenWordsUnderscoreMessage message_field_count = 15; repeated int32 Int32Field = 21; // NO_PROTO3 repeated TestEnum EnumField = 22; // NO_PROTO3 repeated string StringField = 23; // NO_PROTO3 repeated bytes BytesField = 24; // NO_PROTO3 - repeated TestMessage MessageField = 25; // NO_PROTO3 + repeated ForbiddenWordsUnderscoreMessage MessageField = 25; // NO_PROTO3 // This field conflicts with "int32_field" as they both generate // the method getInt32FieldList(). diff --git a/src/google/protobuf/compiler/java/java_helpers.cc b/src/google/protobuf/compiler/java/java_helpers.cc index 1b1aebff34..681d597833 100644 --- a/src/google/protobuf/compiler/java/java_helpers.cc +++ b/src/google/protobuf/compiler/java/java_helpers.cc @@ -66,15 +66,26 @@ namespace { const char* kDefaultPackage = ""; -// Names that should be avoided as field names. -// Using them will cause the compiler to generate accessors whose names are -// colliding with methods defined in base classes. +// Names that should be avoided (in UpperCamelCase format). +// Using them will cause the compiler to generate accessors whose names +// collide with methods defined in base classes. +// Keep this list in sync with specialFieldNames in +// java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java const char* kForbiddenWordList[] = { - // message base class: - "cached_size", - "serialized_size", // java.lang.Object: - "class", + "Class", + // com.google.protobuf.MessageLiteOrBuilder: + "DefaultInstanceForType", + // com.google.protobuf.MessageLite: + "ParserForType", + "SerializedSize", + // com.google.protobuf.MessageOrBuilder: + "AllFields", + "DescriptorForType", + "InitializationErrorString", + "UnknownFields", + // obsolete. kept for backwards compatibility of generated code + "CachedSize", }; const std::unordered_set* kReservedNames = @@ -93,7 +104,7 @@ const std::unordered_set* kReservedNames = bool IsForbidden(const std::string& field_name) { for (int i = 0; i < GOOGLE_ARRAYSIZE(kForbiddenWordList); ++i) { - if (field_name == kForbiddenWordList[i]) { + if (UnderscoresToCamelCase(field_name, true) == kForbiddenWordList[i]) { return true; } } From 5e0fc2f1df694c34431ac93b9b93aab4e1ae1de6 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 3 Feb 2022 18:02:13 +0000 Subject: [PATCH 189/207] Fix java tests --- .../com/google/protobuf/InvalidProtocolBufferException.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java index bd7039e1bc..71ccb14b13 100644 --- a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +++ b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java @@ -47,11 +47,11 @@ public class InvalidProtocolBufferException extends IOException { super(description); } - public InvalidProtocolBufferException(IOException e) { + public InvalidProtocolBufferException(Exception e) { super(e.getMessage(), e); } - public InvalidProtocolBufferException(String description, IOException e) { + public InvalidProtocolBufferException(String description, Exception e) { super(description, e); } From 8dc77b995732590ec1fb0f6cf7c6ceb6d6a9b9c3 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Thu, 3 Feb 2022 20:46:48 +0000 Subject: [PATCH 190/207] Fix more tests --- src/google/protobuf/inlined_string_field_unittest.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/google/protobuf/inlined_string_field_unittest.cc b/src/google/protobuf/inlined_string_field_unittest.cc index ae731d643c..90c141220f 100644 --- a/src/google/protobuf/inlined_string_field_unittest.cc +++ b/src/google/protobuf/inlined_string_field_unittest.cc @@ -52,8 +52,6 @@ namespace protobuf { using internal::ArenaStringPtr; using internal::InlinedStringField; -static std::string WrapString(const char* value) { return value; } - namespace { } // namespace } // namespace protobuf From c8b388a6cb516618bdeed6fb3917ce16989b8467 Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Fri, 4 Feb 2022 00:23:34 +0000 Subject: [PATCH 191/207] Fixing java test --- .../google/protobuf/InvalidProtocolBufferException.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java index 71ccb14b13..7f36e09830 100644 --- a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +++ b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java @@ -55,6 +55,14 @@ public class InvalidProtocolBufferException extends IOException { super(description, e); } + public InvalidProtocolBufferException(IOException e) { + super(e.getMessage(), e); + } + + public InvalidProtocolBufferException(String description, IOException e) { + super(description, e); + } + /** * Attaches an unfinished message to the exception to support best-effort parsing in {@code * Parser} interface. From 867436c0b848d11f3b55eda3c97f1ca4db998ae8 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 4 Feb 2022 11:54:43 -0500 Subject: [PATCH 192/207] add test for clone of non-empty message (#9193) * add test for clone * use var * reorder --- .../UnknownFieldSetTest.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs b/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs index 15debc1b6c..f3e5af2056 100644 --- a/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs +++ b/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs @@ -138,6 +138,29 @@ namespace Google.Protobuf Assert.AreEqual(message.ToByteArray(), otherEmptyMessage.ToByteArray()); } + [Test] + public void TestClone_LengthDelimited() + { + var unknownVarintField = new UnknownField(); + unknownVarintField.AddVarint(99); + + var unknownLengthDelimitedField1 = new UnknownField(); + unknownLengthDelimitedField1.AddLengthDelimited(ByteString.CopyFromUtf8("some data")); + + var unknownLengthDelimitedField2 = new UnknownField(); + unknownLengthDelimitedField2.AddLengthDelimited(ByteString.CopyFromUtf8("some more data")); + + var destUnknownFieldSet = new UnknownFieldSet(); + destUnknownFieldSet.AddOrReplaceField(997, unknownVarintField); + destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField1); + destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField2); + + var clone = UnknownFieldSet.Clone(destUnknownFieldSet); + + Assert.IsTrue(clone.HasField(997)); + Assert.IsTrue(clone.HasField(999)); + } + [Test] [TestCaseSource(typeof(Data), "Messages")] public void TestDiscardUnknownFields(IMessage message) From 5a0887fc6529596eff5c0f72febc602a9d494cc2 Mon Sep 17 00:00:00 2001 From: appledragon Date: Tue, 8 Feb 2022 07:50:16 +0800 Subject: [PATCH 193/207] for ios shared library export api visibility (#9160) * for ios shared library export api visibility * for shared library export api visibility * for shared library export api visibility --- cmake/libprotobuf-lite.cmake | 2 +- cmake/libprotobuf.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index f36a7acf6c..a0bc9945fd 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -103,7 +103,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android") target_link_libraries(libprotobuf-lite log) endif() target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src) -if(MSVC AND protobuf_BUILD_SHARED_LIBS) +if(protobuf_BUILD_SHARED_LIBS) target_compile_definitions(libprotobuf-lite PUBLIC PROTOBUF_USE_DLLS PRIVATE LIBPROTOBUF_EXPORTS) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 42f25668e1..51003b80a9 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -118,7 +118,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android") target_link_libraries(libprotobuf log) endif() target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src) -if(MSVC AND protobuf_BUILD_SHARED_LIBS) +if(protobuf_BUILD_SHARED_LIBS) target_compile_definitions(libprotobuf PUBLIC PROTOBUF_USE_DLLS PRIVATE LIBPROTOBUF_EXPORTS) From 18c951efb164400ea3c4233eb7375f04a56298e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florin=20Cri=C8=99an?= Date: Tue, 8 Feb 2022 03:38:38 +0200 Subject: [PATCH 194/207] Enable testing via CTest (#8737) Convenience feature: enable users to test via the familiar `ctest` command rather than making the `check` target. They would be able to use the familiar CMake pattern: ``` cmake -S source/protobuf -B build/protobuf ... cmake --build build/protobuf ctest --test-dir build/protobuf cmake --install build/protobuf ``` This is a follow-up to 9f447fc9d3da93da29b8301f1a8ca57b1ea812d7 --- cmake/CMakeLists.txt | 1 + cmake/README.md | 8 ++++++-- cmake/tests.cmake | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index da366b8b12..2366d4b427 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -297,6 +297,7 @@ if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLE endif () if (protobuf_BUILD_TESTS) + enable_testing() include(tests.cmake) endif (protobuf_BUILD_TESTS) diff --git a/cmake/README.md b/cmake/README.md index d75012cff0..857d146aa0 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -164,7 +164,11 @@ Testing To run unit-tests, first you must compile protobuf as described above. Then run: - C:\Path\to\protobuf\cmake\build\release>nmake check + C:\Path\to\protobuf\cmake\build\release>ctest --progress --output-on-failure + +You can also build the `check` target (not idiomatic CMake usage, though): + + C:\Path\to\protobuf\cmake\build\release>cmake --build . --target check or @@ -183,7 +187,7 @@ You should see output similar to: [==========] 1546 tests from 165 test cases ran. (2529 ms total) [ PASSED ] 1546 tests. -To run specific tests: +To run specific tests, you need to pass some command line arguments to the test program itself: C:\Path\to\protobuf>cmake\build\release\tests.exe --gtest_filter=AnyTest* Running main() from gmock_main.cc diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 2c9e38ee5a..7a359e268a 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -255,3 +255,7 @@ add_custom_target(check COMMAND tests DEPENDS tests test_plugin WORKING_DIRECTORY ${protobuf_source_dir}) + +add_test(NAME check + COMMAND tests + WORKING_DIRECTORY "${protobuf_source_dir}") From 9ebb31726cef11e4e940b50ec751df4e863e3d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florin=20Cri=C8=99an?= Date: Tue, 8 Feb 2022 06:41:29 +0200 Subject: [PATCH 195/207] Add option to use external GTest in CMake (#8736) If `-Dprotobuf_USE_EXTERNAL_GTEST=ON` is passed to CMake, it will use an external Google Test copy (i.e. by calling `find_package(GTest REQUIRED)`) rather than the one provided as a submodule. This makes sense for larger projects that might already include Google Test and want to use a more standard CMake approach. Also updated build instructions with this information, and more idiomatic usage. Co-authored-by: Adam Cozzette --- cmake/README.md | 170 ++++++++++++++++++++++++++++++---------------- cmake/tests.cmake | 64 +++++++++-------- 2 files changed, 148 insertions(+), 86 deletions(-) diff --git a/cmake/README.md b/cmake/README.md index 857d146aa0..3fee4a0414 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -36,6 +36,10 @@ If *git* command is not available from *Command Prompt*, add it to system *PATH* C:\Path\to>set PATH=%PATH%;C:\Program Files\Git\cmd +Optionally, you will want to download [ninja](https://ninja-build.org/) and add it to your *PATH* variable. + + C:\Path\to>set PATH=%PATH%;C:\tools\ninja + Good. Now you are ready to continue. Getting Sources @@ -52,29 +56,25 @@ download `protobuf-all-[VERSION].tar.gz`. Or you can use git to clone from protobuf git repository. - C:\Path\to> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git + C:\Path\to> mkdir src & cd src + C:\Path\to\src> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git Where *[release_tag]* is a git tag like *v3.0.0-beta-1* or a branch name like *master* if you want to get the latest code. Go to the project folder: - C:\Path\to>cd protobuf - C:\Path\to\protobuf> + C:\Path\to\src> cd protobuf + C:\Path\to\src\protobuf> Remember to update any submodules if you are using git clone (you can skip this step if you are using a release .tar.gz or .zip package): ```console -C:\Path\to> git submodule update --init --recursive +C:\Path\to\src\protobuf> git submodule update --init --recursive ``` -Now go to *cmake* folder in protobuf sources: - - C:\Path\to\protobuf>cd cmake - C:\Path\to\protobuf\cmake> - -Good. Now you are ready to *CMake* configuration. +Good. Now you are ready for *CMake* configuration. CMake Configuration =================== @@ -82,71 +82,119 @@ CMake Configuration *CMake* supports a lot of different [generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html) for various native build systems. -We are only interested in -[Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators) -and -[Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators) -generators. -We will use shadow building to separate the temporary files from the protobuf source code. +Of most interest to Windows programmers are the following: + +* [Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators). + This generates NMake Makefiles for Visual Studio. These work, but they are rather slow. + +* [Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators) + This generates a Visual Studio solution for the project. + +* [Ninja](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#ninja-generator) + This uses the external tool [Ninja](https://ninja-build.org/) to build. It is the fastest solution available. + +Note that as of Visual Studio 2015, Visual Studio includes +[support for opening directly CMake-based projects](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio). + +It is considered good practice not to build CMake projects in the source tree but in a separate folder. Create a temporary *build* folder and change your working directory to it: - C:\Path\to\protobuf\cmake>mkdir build & cd build - C:\Path\to\protobuf\cmake\build> + mkdir C:\Path\to\build\protobuf + cd C:\Path\to\build\protobuf + C:\Path\to\build\protobuf> -The *Makefile* generator can build the project in only one configuration, so you need to build +The *Makefile* and *Ninja* generators can build the project in only one configuration, so you need to build a separate folder for each configuration. -To start using a *Release* configuration: +To start using a *Release* configuration via the *NMmake* generator: - C:\Path\to\protobuf\cmake\build>mkdir release & cd release - C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^ + C:\Path\to\build\protobuf>mkdir release & cd release + C:\Path\to\build\protobuf\release>cmake -G "NMake Makefiles" ^ -DCMAKE_BUILD_TYPE=Release ^ - -DCMAKE_INSTALL_PREFIX=../../../../install ^ - ../.. + -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^ + C:\Path\to\src\protobuf -It will generate *nmake* *Makefile* in current directory. +It will generate a *NMake* *Makefile* in the current directory. -To use *Debug* configuration: +To use *Debug* configuration using *Ninja*: - C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug - C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" ^ + C:\Path\to\build\protobuf>mkdir debug & cd debug + C:\Path\to\build\protobuf\debug>cmake -G "Ninja" ^ -DCMAKE_BUILD_TYPE=Debug ^ - -DCMAKE_INSTALL_PREFIX=../../../../install ^ - ../.. + -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^ + C:\Path\to\src\protobuf -It will generate *nmake* *Makefile* in current directory. +It will generate *Ninja* build scripts in current directory. -To create *Visual Studio* solution file: +The *Visual Studio* generator is multi-configuration: it will generate a single *.sln* file that can be used for both *Debug* and *Release*: - C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution - C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 16 2019" ^ - -DCMAKE_INSTALL_PREFIX=../../../../install ^ - ../.. + C:\Path\to\build\protobuf>mkdir solution & cd solution + C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^ + -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^ + C:\Path\to\src\protobuf It will generate *Visual Studio* solution file *protobuf.sln* in current directory. -If the *gmock* directory does not exist, and you do not want to build protobuf unit tests, -you need to add *cmake* command argument `-Dprotobuf_BUILD_TESTS=OFF` to disable testing. +Unit Tests +---------- + +Unit tests are being built along with the rest of protobuf. The unit tests require Google Mock (now a part of Google Test). + +A copy of [Google Test](https://github.com/google/googletest) is included as a Git submodule in the `third-party/googletest` folder. +(You do need to initialize the Git submodules as explained above.) + +Alternately, you may want to use protobuf in a larger set-up, you may want to use that standard CMake approach where +you build and install a shared copy of Google Test. -To make a *Visual Studio* file for Visual Studio 16 2019, create the *Visual Studio* -solution file above and edit the CMakeCache file. +After you've built and installed your Google Test copy, you need add the following definition to your *cmake* command line +during the configuration step: `-Dprotobuf_USE_EXTERNAL_GTEST=ON`. +This will cause the standard CMake `find_package(GTest REQUIRED)` to be used. - C:Path\to\protobuf\cmake\build\solution\CMakeCache +[find_package](https://cmake.org/cmake/help/latest/command/find_package.html) will search in a default location, +which on Windows is *C:\Program Files*. This is most likely not what you want. You will want instead to search for +Google Test in your project's root directory (i.e. the same directory you've passed to `CMAKE_INSTALL_PREFIX` when +building Google Test). For this, you need to set the `CMAKE_PREFIX_PATH` CMake variable. (There are other ways in CMake, +see the [manual](https://cmake.org/cmake/help/latest/command/find_package.html) for details.) -Then create the *Visual Studio* solution file again +For example: + + C:\Path\to\build\protobuf>mkdir solution & cd solution + C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^ + -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^ + -DCMAKE_PREFIX_PATH=C:\Path\to\my_big_project ^ + -Dprotobuf_USE_EXTERNAL_GTEST=ON ^ + C:\Path\to\src\protobuf + +In most cases, `CMAKE_PREFIX_PATH` and `CMAKE_INSTALL_PREFIX` will point to the same directory. + +To disable testing completely, you need to add the following argument to you *cmake* command line: `-Dprotobuf_BUILD_TESTS=OFF`. + +For example: + + C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^ + -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^ + -Dprotobuf_BUILD_TESTS=OFF ^ + C:\Path\to\src\protobuf Compiling ========= -To compile protobuf: +The standard way to compile a *CMake* project is `cmake --build `. + - C:\Path\to\protobuf\cmake\build\release>nmake +Note that if your generator supports multiple configurations, you will probably want to specify which one to build: + + cmake --build C:\Path\to\build\protobuf\solution --config Release + +You can also run directly the build tool you've configured: + + C:\Path\to\build\protobuf\release>nmake or - C:\Path\to\protobuf\cmake\build\debug>nmake + C:\Path\to\build\protobuf\debug>ninja And wait for the compilation to finish. @@ -172,7 +220,7 @@ You can also build the `check` target (not idiomatic CMake usage, though): or - C:\Path\to\protobuf\cmake\build\debug>nmake check + C:\Path\to\build\protobuf\release>ninja check You can also build project *check* from Visual Studio solution. Yes, it may sound strange, but it works. @@ -189,7 +237,7 @@ You should see output similar to: To run specific tests, you need to pass some command line arguments to the test program itself: - C:\Path\to\protobuf>cmake\build\release\tests.exe --gtest_filter=AnyTest* + C:\Path\to\build\protobuf\release>tests.exe --gtest_filter=AnyTest* Running main() from gmock_main.cc Note: Google Test filter = AnyTest* [==========] Running 3 tests from 1 test case. @@ -214,13 +262,17 @@ If all tests are passed, safely continue. Installing ========== -To install protobuf to the specified *install* folder: +To install protobuf to the *install* folder you've specified in the configuration step, you need to build the `install` target: + + cmake --build C:\Path\to\build\protobuf\solution --config Release --target install + +Or if you prefer: - C:\Path\to\protobuf\cmake\build\release>nmake install + C:\Path\to\build\protobuf\release>nmake install or - C:\Path\to\protobuf\cmake\build\debug>nmake install + C:\Path\to\build\protobuf\debug>ninja install You can also build project *INSTALL* from Visual Studio solution. It sounds not so strange and it works. @@ -284,16 +336,16 @@ You can also compile it from source by yourself. Getting sources: - C:\Path\to>git clone -b v1.2.8 https://github.com/madler/zlib.git - C:\Path\to>cd zlib + C:\Path\to\src>git clone -b v1.2.8 https://github.com/madler/zlib.git + C:\Path\to\src>cd zlib Compiling and Installing: - C:\Path\to\zlib>mkdir build & cd build - C:\Path\to\zlib\build>mkdir release & cd release - C:\Path\to\zlib\build\release>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ^ - -DCMAKE_INSTALL_PREFIX=../../../install ../.. - C:\Path\to\zlib\build\release>nmake & nmake install + C:\Path\to\src\zlib>mkdir C:\Path\to\build\zlib & cd C:\Path\to\build\zlib + C:\Path\to\build\zlib>mkdir release & cd release + C:\Path\to\build\zlib\release>cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release ^ + -DCMAKE_INSTALL_PREFIX=C:\Path\to\install C:\Path\to\src\zlib + C:\Path\to\src\zlib\build\release>cmake --build . --target install You can make *debug* version or use *Visual Studio* generator also as before for the protobuf project. @@ -312,8 +364,8 @@ the headers or the .lib file in the right directory. If you already have ZLIB library and headers at some other location on your system then alternatively you can define following configuration flags to locate them: - -DZLIB_INCLUDE_DIR= - -DZLIB_LIB= + -DZLIB_INCLUDE_DIR= + -DZLIB_LIB= Build and testing protobuf as usual. diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 7a359e268a..1556838528 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -1,32 +1,42 @@ -if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../third_party/googletest/CMakeLists.txt") - message(FATAL_ERROR - "Cannot find third_party/googletest directory that's needed to " - "build tests. If you use git, make sure you have cloned submodules:\n" - " git submodule update --init --recursive\n" - "If instead you want to skip tests, run cmake with:\n" - " cmake -Dprotobuf_BUILD_TESTS=OFF\n") -endif() +option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF) option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH "Using absolute test_plugin path in tests" ON) mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH) -set(googlemock_source_dir "${protobuf_source_dir}/third_party/googletest/googlemock") -set(googletest_source_dir "${protobuf_source_dir}/third_party/googletest/googletest") -include_directories( - ${googlemock_source_dir} - ${googletest_source_dir} - ${googletest_source_dir}/include - ${googlemock_source_dir}/include -) +if (protobuf_USE_EXTERNAL_GTEST) + find_package(GTest REQUIRED) +else() + if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../third_party/googletest/CMakeLists.txt") + message(FATAL_ERROR + "Cannot find third_party/googletest directory that's needed to " + "build tests. If you use git, make sure you have cloned submodules:\n" + " git submodule update --init --recursive\n" + "If instead you want to skip tests, run cmake with:\n" + " cmake -Dprotobuf_BUILD_TESTS=OFF\n") + endif() + + set(googlemock_source_dir "${protobuf_source_dir}/third_party/googletest/googlemock") + set(googletest_source_dir "${protobuf_source_dir}/third_party/googletest/googletest") + include_directories( + ${googlemock_source_dir} + ${googletest_source_dir} + ${googletest_source_dir}/include + ${googlemock_source_dir}/include + ) + + add_library(gmock STATIC + "${googlemock_source_dir}/src/gmock-all.cc" + "${googletest_source_dir}/src/gtest-all.cc" + ) + target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) + add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc") + target_link_libraries(gmock_main gmock) + + add_library(GTest::gmock ALIAS gmock) + add_library(GTest::gmock_main ALIAS gmock_main) +endif() -add_library(gmock STATIC - "${googlemock_source_dir}/src/gmock-all.cc" - "${googletest_source_dir}/src/gtest-all.cc" -) -target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) -add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc") -target_link_libraries(gmock_main gmock) set(lite_test_protos google/protobuf/map_lite_unittest.proto @@ -227,7 +237,7 @@ if (MSVC) /wd4146 # unary minus operator applied to unsigned type, result still unsigned ) endif() -target_link_libraries(tests libprotoc libprotobuf gmock_main) +target_link_libraries(tests libprotoc libprotobuf GTest::gmock_main) set(test_plugin_files ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc @@ -237,19 +247,19 @@ set(test_plugin_files ) add_executable(test_plugin ${test_plugin_files}) -target_link_libraries(test_plugin libprotoc libprotobuf gmock) +target_link_libraries(test_plugin libprotoc libprotobuf GTest::gmock) set(lite_test_files ${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc ) add_executable(lite-test ${lite_test_files} ${common_lite_test_files} ${lite_test_proto_files}) -target_link_libraries(lite-test libprotobuf-lite gmock_main) +target_link_libraries(lite-test libprotobuf-lite GTest::gmock_main) set(lite_arena_test_files ${protobuf_source_dir}/src/google/protobuf/lite_arena_unittest.cc ) add_executable(lite-arena-test ${lite_arena_test_files} ${common_lite_test_files} ${lite_test_proto_files}) -target_link_libraries(lite-arena-test libprotobuf-lite gmock_main) +target_link_libraries(lite-arena-test libprotobuf-lite GTest::gmock_main) add_custom_target(check COMMAND tests From b5ab0b7a18b7336c60130f4ddb2d97c51792f896 Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Sun, 6 Feb 2022 16:54:32 -0800 Subject: [PATCH 196/207] objective-c: Add `objc_class_prefix` generation option. --- objectivec/README.md | 10 ++++++++-- .../compiler/objectivec/objectivec_generator.cc | 14 ++++++++++++-- .../compiler/objectivec/objectivec_helpers.cc | 17 +++++++++++++++-- .../compiler/objectivec/objectivec_helpers.h | 4 ++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/objectivec/README.md b/objectivec/README.md index 9aedb219f5..b0278f2aee 100644 --- a/objectivec/README.md +++ b/objectivec/README.md @@ -133,8 +133,8 @@ This options allow you to provide a custom prefix for all the symbols generated from a proto file (classes (from message), enums, the Root for extension support). -If not set, the generation option `use_package_as_prefix` (documented below) -controls what is used instead. Since Objective C uses a global namespace for all +If not set, the generation options `default_objc_class_prefix` and `use_package_as_prefix` +(documented below) control what is used instead. Since Objective C uses a global namespace for all of its classes, there can be collisions. `use_package_as_prefix=yes` should avoid collisions since proto package are used to scope/name things in other languages, but this option can be used to get shorter names instead. Convention @@ -182,6 +182,12 @@ supported keys are: having to add the runtime directory to the header search path since the generate `#import` will be more complete. + * `default_objc_class_prefix`: The default ObjC prefix value to use when + generating sources. The generator will use this if the `objc_class_prefix` + file option is not set. This option can be useful if multiple iOS apps + consume the same proto file but wish to use a different prefix for their + generated sources. + * `use_package_as_prefix` and `proto_package_prefix_exceptions_path`: The `value` for `use_package_as_prefix` can be `yes` or `no`, and indicates if a prefix should be derived from the proto package for all the symbols diff --git a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index 713f93ef1b..b6f53a5a9f 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_generator.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -190,10 +190,20 @@ bool ObjectiveCGenerator::GenerateAll( // header search path since the generate #import will be more complete. generation_options.runtime_import_prefix = StripSuffixString(options[i].second, "/"); + } else if (options[i].first == "default_objc_class_prefix") { + // The default objc class prefix to use if specified by the command line + // invocation. The file option is always honored first if one is present. + std::string value = options[i].second; + if (value.empty()) { + *error = "error: default_objc_class_prefix cannot be empty."; + return false; + } + SetDefaultObjcClassPrefix(value); } else if (options[i].first == "use_package_as_prefix") { // Controls how the symbols should be prefixed to avoid symbols - // collisions. The objc_class_prefix file option is always honored, this - // is just what to do if that isn't set. The available options are: + // collisions. The objc_class_prefix file option is always honored first + // followed by the default_objc_class_prefix generator option. This is is just + // what to do if either of these options are not set. The available options are: // "no": Not prefixed (the existing mode). // "yes": Make a prefix out of the proto package. bool value = false; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index cf926071fc..7b85c517f2 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -99,6 +99,9 @@ class PrefixModeStorage { public: PrefixModeStorage(); + const std::string default_objc_class_prefix() const { return default_objc_class_prefix_; } + void set_default_objc_class_prefix(const std::string& default_objc_class_prefix) { default_objc_class_prefix_ = default_objc_class_prefix; } + bool use_package_name() const { return use_package_name_; } void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; } @@ -116,13 +119,14 @@ class PrefixModeStorage { private: bool use_package_name_; + std::string default_objc_class_prefix_; std::string exception_path_; std::string forced_prefix_; std::unordered_set exceptions_; }; PrefixModeStorage::PrefixModeStorage() { - // Even thought there are generation options, have an env back door since some + // Even though there are generation options, have an env back door since some // of these helpers could be used in other plugins. use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false); @@ -169,6 +173,10 @@ PrefixModeStorage g_prefix_mode; } // namespace +void SetDefaultObjcClassPrefix(const std::string& default_objc_class_prefix) { + g_prefix_mode.set_default_objc_class_prefix(default_objc_class_prefix); +} + bool UseProtoPackageAsDefaultPrefix() { return g_prefix_mode.use_package_name(); } @@ -526,11 +534,16 @@ std::string BaseFileName(const FileDescriptor* file) { } std::string FileClassPrefix(const FileDescriptor* file) { - // Always honor the file option. + // Always honor the file option first. if (file->options().has_objc_class_prefix()) { return file->options().objc_class_prefix(); } + // If a default prefix is passed through objc_opt then accept it. + if (!g_prefix_mode.default_objc_class_prefix().empty()) { + return g_prefix_mode.default_objc_class_prefix(); + } + // If package prefix isn't enabled, done. if (!g_prefix_mode.use_package_name()) { return ""; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index f4b71ced8e..418ffaba5e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -47,6 +47,9 @@ namespace protobuf { namespace compiler { namespace objectivec { +// Set the default objc class prefix that should be used. This method is used only +// when default_objc_class_prefix is passed through objc_opt. +void PROTOC_EXPORT SetDefaultObjcClassPrefix(const std::string& objc_class_prefix); // Get/Set if the proto package should be used to make the default prefix for // symbols. This will then impact most of the type naming apis below. It is done // as a global to not break any other generator reusing the methods since they @@ -68,6 +71,7 @@ struct Options { std::string generate_for_named_framework; std::string named_framework_to_proto_path_mappings_path; std::string runtime_import_prefix; + std::string default_objc_class_prefix; bool prefixes_must_be_registered; bool require_prefixes; }; From f739286b1acd3e47778f31fe8387012a2b700ad8 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 10:31:54 -0800 Subject: [PATCH 197/207] For GCC < 4.9.0 use ::max_align_t instead of std::max_align_t. --- src/google/protobuf/arenastring.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/google/protobuf/arenastring.cc b/src/google/protobuf/arenastring.cc index cc154e9417..c70abf7582 100644 --- a/src/google/protobuf/arenastring.cc +++ b/src/google/protobuf/arenastring.cc @@ -57,6 +57,8 @@ namespace { // - alignof(std::string) #ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__ constexpr size_t kNewAlign = __STDCPP_DEFAULT_NEW_ALIGNMENT__; +#elif (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900 +constexpr size_t kNewAlign = alignof(::max_align_t); #else constexpr size_t kNewAlign = alignof(std::max_align_t); #endif From 301d315dc4674d1bc799446644e88eff0af1ac86 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 18:31:50 -0800 Subject: [PATCH 198/207] Dropped support for Python < 3.7 (#9480) * Drop Python versions <3.7. * Updated README to clarify that Python 3.7 is the minimum. * Removed more Python 3.5-specific code. Also changed tests to skip missing interpreters. * Invoke tox directly instead of through Python. Hopefully this will pick up python3. * Updated java_stretch image to bullseye to get Python >= 3.7. * Use jdk11 instead of jdk8. * Installed python2 for gtest. * Use "python3 -m venv" instead of "virtualenv." * Install python3-venv. --- .../dockerfile/test/java_stretch/Dockerfile | 11 +++- kokoro/linux/python36/build.sh | 18 ------ kokoro/linux/python36/continuous.cfg | 11 ---- kokoro/linux/python36/presubmit.cfg | 11 ---- kokoro/linux/python36_cpp/build.sh | 18 ------ kokoro/linux/python36_cpp/continuous.cfg | 11 ---- kokoro/linux/python36_cpp/presubmit.cfg | 11 ---- .../python/windows/build_artifacts.bat | 10 ---- .../python/windows/build_single_artifact.bat | 6 -- python/README.md | 2 +- python/setup.py | 4 +- python/tox.ini | 4 +- tests.sh | 58 ++++--------------- 13 files changed, 22 insertions(+), 153 deletions(-) delete mode 100755 kokoro/linux/python36/build.sh delete mode 100644 kokoro/linux/python36/continuous.cfg delete mode 100644 kokoro/linux/python36/presubmit.cfg delete mode 100755 kokoro/linux/python36_cpp/build.sh delete mode 100644 kokoro/linux/python36_cpp/continuous.cfg delete mode 100644 kokoro/linux/python36_cpp/presubmit.cfg diff --git a/kokoro/linux/dockerfile/test/java_stretch/Dockerfile b/kokoro/linux/dockerfile/test/java_stretch/Dockerfile index b9f562a2b4..7e1feeafad 100644 --- a/kokoro/linux/dockerfile/test/java_stretch/Dockerfile +++ b/kokoro/linux/dockerfile/test/java_stretch/Dockerfile @@ -1,4 +1,7 @@ -FROM debian:stretch +# Despite the name of this image, we are no longer on stretch. +# We should consider renaming this image, and/or evaluating what +# software versions we actually need. +FROM debian:bullseye # Install dependencies. We start with the basic ones required to build protoc # and the C++ build @@ -22,9 +25,11 @@ RUN apt-get update && apt-get install -y \ wget \ # Java dependencies maven \ - openjdk-8-jdk \ + openjdk-11-jdk \ + # Required for the gtest build. + python2 \ # Python dependencies python3-setuptools \ python3-pip \ - virtualenv \ + python3-venv \ && apt-get clean diff --git a/kokoro/linux/python36/build.sh b/kokoro/linux/python36/build.sh deleted file mode 100755 index a483efc302..0000000000 --- a/kokoro/linux/python36/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERHUB_ORGANIZATION=protobuftesting -export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python36 -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="python36" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python36/continuous.cfg b/kokoro/linux/python36/continuous.cfg deleted file mode 100644 index ee7f4888f8..0000000000 --- a/kokoro/linux/python36/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python36/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/python36/presubmit.cfg b/kokoro/linux/python36/presubmit.cfg deleted file mode 100644 index ee7f4888f8..0000000000 --- a/kokoro/linux/python36/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python36/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/python36_cpp/build.sh b/kokoro/linux/python36_cpp/build.sh deleted file mode 100755 index eb71bda92c..0000000000 --- a/kokoro/linux/python36_cpp/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERHUB_ORGANIZATION=protobuftesting -export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python36 -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="python36_cpp" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python36_cpp/continuous.cfg b/kokoro/linux/python36_cpp/continuous.cfg deleted file mode 100644 index df9e714494..0000000000 --- a/kokoro/linux/python36_cpp/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python36_cpp/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/python36_cpp/presubmit.cfg b/kokoro/linux/python36_cpp/presubmit.cfg deleted file mode 100644 index df9e714494..0000000000 --- a/kokoro/linux/python36_cpp/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python36_cpp/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/release/python/windows/build_artifacts.bat b/kokoro/release/python/windows/build_artifacts.bat index a8f8f78314..121283a438 100644 --- a/kokoro/release/python/windows/build_artifacts.bat +++ b/kokoro/release/python/windows/build_artifacts.bat @@ -40,16 +40,6 @@ mkdir %ARTIFACT_DIR% REM Build wheel -SET PYTHON=C:\python36_32bit -SET PYTHON_VERSION=3.6 -SET PYTHON_ARCH=32 -CALL build_single_artifact.bat || goto :error - -SET PYTHON=C:\python36 -SET PYTHON_VERSION=3.6 -SET PYTHON_ARCH=64 -CALL build_single_artifact.bat || goto :error - SET PYTHON=C:\python37_32bit SET PYTHON_VERSION=3.7 SET PYTHON_ARCH=32 diff --git a/kokoro/release/python/windows/build_single_artifact.bat b/kokoro/release/python/windows/build_single_artifact.bat index 8d3cd0c9d8..af2d265263 100644 --- a/kokoro/release/python/windows/build_single_artifact.bat +++ b/kokoro/release/python/windows/build_single_artifact.bat @@ -1,11 +1,5 @@ setlocal -if %PYTHON%==C:\python36_32bit set generator=Visual Studio 14 -if %PYTHON%==C:\python36_32bit set vcplatform=Win32 - -if %PYTHON%==C:\python36 set generator=Visual Studio 14 Win64 -if %PYTHON%==C:\python36 set vcplatform=x64 - if %PYTHON%==C:\python37_32bit set generator=Visual Studio 14 if %PYTHON%==C:\python37_32bit set vcplatform=Win32 diff --git a/python/README.md b/python/README.md index f0c9ce4f44..27f22c82c0 100644 --- a/python/README.md +++ b/python/README.md @@ -26,7 +26,7 @@ use python c++ implementation. Installation ============ -1) Make sure you have Python 3.5 or newer. If in doubt, run: +1) Make sure you have Python 3.7 or newer. If in doubt, run: $ python -V diff --git a/python/setup.py b/python/setup.py index 4a2c71c763..290beb4168 100755 --- a/python/setup.py +++ b/python/setup.py @@ -301,8 +301,6 @@ if __name__ == '__main__': classifiers=[ "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", @@ -323,5 +321,5 @@ if __name__ == '__main__': }, install_requires=install_requires, ext_modules=ext_module_list, - python_requires=">=3.5", + python_requires=">=3.7", ) diff --git a/python/tox.ini b/python/tox.ini index 7142b86f0f..b923a4a58e 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{35,36,37,38,39,310}-{cpp,python} + py{37,38,39,310}-{cpp,python} [testenv] usedevelop=true @@ -14,7 +14,7 @@ setenv = commands = python setup.py -q build_py python: python setup.py -q build - py{35,36,37,38,39,310}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension + py{37,38,39,310}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension python: python setup.py -q test -q cpp: python setup.py -q test -q --cpp_implementation python: python setup.py -q test_conformance diff --git a/tests.sh b/tests.sh index 13bf034da6..8ea5ae6f6b 100755 --- a/tests.sh +++ b/tests.sh @@ -116,12 +116,12 @@ build_dist_install() { # Try to install Java pushd java - use_java jdk8 + use_java jdk11 $MVN install popd # Try to install Python - virtualenv --no-site-packages venv + python3 -m venv venv source venv/bin/activate pushd python python3 setup.py clean build sdist @@ -189,6 +189,10 @@ build_golang() { use_java() { version=$1 case "$version" in + jdk11) + export PATH=/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH + export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 + ;; jdk8) export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 @@ -268,7 +272,7 @@ build_java_linkage_monitor() { # Linkage Monitor checks compatibility with other Google libraries # https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor - use_java jdk8 + use_java jdk11 internal_build_cpp # Linkage Monitor uses $HOME/.m2 local repository @@ -330,12 +334,7 @@ build_objectivec_cocoapods_integration() { build_python() { internal_build_cpp cd python - if [ $(uname -s) == "Linux" ]; then - envlist=py\{35,36\}-python - else - envlist=py\{36\}-python - fi - python -m tox -e $envlist + tox --skip-missing-interpreters cd .. } @@ -343,26 +342,10 @@ build_python_version() { internal_build_cpp cd python envlist=$1 - python -m tox -e $envlist + tox -e $envlist cd .. } -build_python33() { - build_python_version py33-python -} - -build_python34() { - build_python_version py34-python -} - -build_python35() { - build_python_version py35-python -} - -build_python36() { - build_python_version py36-python -} - build_python37() { build_python_version py37-python } @@ -384,12 +367,7 @@ build_python_cpp() { export LD_LIBRARY_PATH=../src/.libs # for Linux export DYLD_LIBRARY_PATH=../src/.libs # for OS X cd python - if [ $(uname -s) == "Linux" ]; then - envlist=py\{35,36\}-cpp - else - envlist=py\{36\}-cpp - fi - tox -e $envlist + tox --skip-missing-interpreters cd .. } @@ -403,22 +381,6 @@ build_python_cpp_version() { cd .. } -build_python33_cpp() { - build_python_cpp_version py33-cpp -} - -build_python34_cpp() { - build_python_cpp_version py34-cpp -} - -build_python35_cpp() { - build_python_cpp_version py35-cpp -} - -build_python36_cpp() { - build_python_cpp_version py36-cpp -} - build_python37_cpp() { build_python_cpp_version py37-cpp } From 5aacba062ba35d9a492a354002eb4c5f04713462 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 18:38:48 -0800 Subject: [PATCH 199/207] Resolved remaining conflict markers. --- java/core/src/main/java/com/google/protobuf/ByteString.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index 6aae17c9d0..cd270ed52b 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -316,13 +316,8 @@ public abstract class ByteString implements Iterable, Serializable { }; /** -<<<<<<< HEAD - * Returns a {@link Comparator} which compares {@link ByteString}-s lexicographically - * as sequences of unsigned byte values between 0 and 255, inclusive. -======= * Returns a {@link Comparator} which compares {@link ByteString}-s lexicographically as sequences * of unsigned bytes (i.e. values between 0 and 255, inclusive). ->>>>>>> refs/tags/sync-piper * *

For example, {@code (byte) -1} is considered to be greater than {@code (byte) 1} because it * is interpreted as an unsigned value, {@code 255}: From 53d409ca548dea4fdf5691c71b0ea0b7cc87e5e9 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 20:03:11 -0800 Subject: [PATCH 200/207] Removed redundant/unnecessary variable definition. --- src/google/protobuf/generated_message_tctable_lite.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index cda0cc4a42..a31d8f40de 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -53,8 +53,6 @@ template void AlignFail<4>(uintptr_t); template void AlignFail<8>(uintptr_t); #endif -const uint32_t TcParser::kMtSmallScanSize; - const char* TcParser::GenericFallbackLite(PROTOBUF_TC_PARAM_DECL) { return GenericFallbackImpl(PROTOBUF_TC_PARAM_PASS); } From b1751761245d0cc943c4603374829a882a4250c3 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 21:01:46 -0800 Subject: [PATCH 201/207] Added changelog entries. --- CHANGES.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 6a1e8b91b2..6491e2bf23 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -21,6 +21,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Report original exceptions when parsing JSON * Add more info to @deprecated javadoc for set/get/has methods * Fix initialization bug in doc comment line numbers + * Fix comments for message set wire format. Kotlin * Add orNull extensions for optional message fields in Kotlin. @@ -46,6 +47,8 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) zone. If omitted or None, the function returns a timezone-naive UTC datetime (as previously). * Adds client_streaming and server_streaming fields to MethodDescriptor. + * Add "ensure_ascii" parameter to json_format.MessageToJson. This allows smaller + JSON serializations with UTF-8 or other non-ASCII encodings. Compiler * Migrate IsDefault(const std::string*) and UnsafeSetDefault(const std::string*) @@ -63,6 +66,7 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Do not log/report the same descriptor symbol multiple times if it contains more than one invalid character. * Add UnknownFieldSet::SerializeToString and SerializeToCodedStream. + * Remove explicit default pointers and deprecated API from protocol compiler Arenas * Change Repeated*Field to reuse memory when using arenas. @@ -80,6 +84,10 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) * Generate narrower code * Fix https://github.com/protocolbuffers/protobuf/issues/9378 by removing shadowed _cached_size_ field + * Remove GetPointer() and explicit nullptr defaults. + * add proto_h flag for speeding up large builds + * Add missing overload for reference wrapped fields. + 2022-01-28 version 3.19.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) From fb9f5862d33e5460041d0fe6b2a29040b217b3be Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 23:06:32 -0800 Subject: [PATCH 202/207] Fixed JavaScript conformance test and failure list. --- conformance/conformance_nodejs.js | 9 +++-- conformance/failure_list_js.txt | 58 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/conformance/conformance_nodejs.js b/conformance/conformance_nodejs.js index 95da893f71..8dfb82e311 100755 --- a/conformance/conformance_nodejs.js +++ b/conformance/conformance_nodejs.js @@ -41,11 +41,16 @@ function doTest(request) { var response = new conformance.ConformanceResponse(); try { - if (request.getRequestedOutputFormat() === conformance.WireFormat.JSON) { + if (request.getRequestedOutputFormat() == conformance.WireFormat.JSON) { response.setSkipped("JSON not supported."); return response; } + if (request.getRequestedOutputFormat() == conformance.WireFormat.TEXT_FORMAT) { + response.setSkipped('Text format is not supported as output format.'); + return response; + } + switch (request.getPayloadCase()) { case conformance.ConformanceRequest.PayloadCase.PROTOBUF_PAYLOAD: { if (request.getMessageType() == "protobuf_test_messages.proto3.TestAllTypesProto3") { @@ -67,7 +72,7 @@ function doTest(request) { } else { throw "Protobuf request doesn\'t have specific payload type"; } - } + } break; case conformance.ConformanceRequest.PayloadCase.JSON_PAYLOAD: response.setSkipped("JSON not supported."); diff --git a/conformance/failure_list_js.txt b/conformance/failure_list_js.txt index 591cbbe9f2..b7d36b6dd0 100644 --- a/conformance/failure_list_js.txt +++ b/conformance/failure_list_js.txt @@ -1,9 +1,18 @@ +Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput @@ -22,23 +31,42 @@ Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOu Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.ENUM[5].ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.FIXED64[2].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.INT32[7].ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.INT64[2].ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.SFIXED64[2].ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.SINT64[2].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.UINT32[8].ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.UINT64[2].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput @@ -57,48 +85,78 @@ Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOu Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[5].ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.FIXED64[2].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.INT32[7].ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.INT64[2].ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.SFIXED64[2].ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.SINT64[2].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT32[8].ProtobufOutput Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT64[2].ProtobufOutput +Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.ENUM.ProtobufOutput Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.ProtobufOutput Required.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.ENUM[4].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.ENUM[5].ProtobufOutput Required.Proto2.ProtobufInput.ValidDataScalar.FIXED64[2].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.INT32[7].ProtobufOutput Required.Proto2.ProtobufInput.ValidDataScalar.INT64[2].ProtobufOutput Required.Proto2.ProtobufInput.ValidDataScalar.SFIXED64[2].ProtobufOutput Required.Proto2.ProtobufInput.ValidDataScalar.SINT64[2].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.UINT32[8].ProtobufOutput Required.Proto2.ProtobufInput.ValidDataScalar.UINT64[2].ProtobufOutput +Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.ProtobufOutput Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[4].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[5].ProtobufOutput Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.INT32[7].ProtobufOutput Required.Proto3.ProtobufInput.ValidDataScalar.INT64[2].ProtobufOutput Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].ProtobufOutput Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[2].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[8].ProtobufOutput Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].ProtobufOutput From 5c5cd186b04c4c571e7d55a5bf3fdd1d2acdd3ae Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 23:06:55 -0800 Subject: [PATCH 203/207] Added missing Kotlin file to EXTRA_DIST. --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 343b5f7020..94f8f48d3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -544,6 +544,7 @@ java_EXTRA_DIST= java/kotlin/generate-test-sources-build.xml \ java/kotlin/pom.xml \ java/kotlin/pom_template.xml \ + java/kotlin/src/main/kotlin/com/google/protobuf/Anies.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/ByteStrings.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/DslList.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/DslMap.kt \ From 09b2c6a2b42bcc2490ca4e6193c6f1967e5fa0cd Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 23:07:12 -0800 Subject: [PATCH 204/207] Removed conflicting/redundant variable declaration. --- src/google/protobuf/generated_message_tctable_lite.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index e0ba5fc4a1..e892444a1f 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -46,8 +46,6 @@ namespace google { namespace protobuf { namespace internal { -const uint32_t TcParser::kMtSmallScanSize; - using FieldEntry = TcParseTableBase::FieldEntry; ////////////////////////////////////////////////////////////////////////////// From 73f772b666e9b5cb8e2e341eafe2e8d4057ffbf3 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 8 Feb 2022 23:28:10 -0800 Subject: [PATCH 205/207] Added AniesTest.kt to Makefile.am. --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 94f8f48d3d..fd304a91f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -554,6 +554,7 @@ java_EXTRA_DIST= java/kotlin/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt\ java/kotlin/src/main/kotlin/com/google/protobuf/ProtoDslMarker.kt \ java/kotlin/src/main/kotlin/com/google/protobuf/UnmodifiableCollections.kt \ + java/kotlin/src/test/kotlin/com/google/protobuf/AniesTest.kt \ java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt \ java/kotlin/src/test/kotlin/com/google/protobuf/DslListTest.kt \ java/kotlin/src/test/kotlin/com/google/protobuf/DslMapTest.kt \ From 4ed3941e27c38b67f11e3eb4a3aefe4ae18fb387 Mon Sep 17 00:00:00 2001 From: Timo Lange Date: Wed, 9 Feb 2022 17:21:45 +0100 Subject: [PATCH 206/207] [CMake] Allow custom plugin options e.g. to generate mocks (#9105) * add plugin options * refactored comment message * added tabs for better readability * removed newlines as they are not working properly * allow PROTOC_OPTIONS and EXPORT_MACRO in parallel for protobuf_generate --- cmake/protobuf-config.cmake.in | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in index 9197625dc2..b4332099c9 100644 --- a/cmake/protobuf-config.cmake.in +++ b/cmake/protobuf-config.cmake.in @@ -11,7 +11,7 @@ function(protobuf_generate) include(CMakeParseArguments) set(_options APPEND_PATH) - set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN) + set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN PLUGIN_OPTIONS) if(COMMAND target_sources) list(APPEND _singleargs TARGET) endif() @@ -39,9 +39,18 @@ function(protobuf_generate) endif() if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp) - set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:") + set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}") endif() - + + foreach(_option ${_dll_export_decl} ${protobuf_generate_PLUGIN_OPTIONS}) + # append comma - not using CMake lists and string replacement as users + # might have semicolons in options + if(_plugin_options) + set( _plugin_options "${_plugin_options},") + endif() + set(_plugin_options "${_plugin_options}${_option}") + endforeach() + if(protobuf_generate_PLUGIN) set(_plugin "--plugin=${protobuf_generate_PLUGIN}") endif() @@ -127,12 +136,20 @@ function(protobuf_generate) endforeach() list(APPEND _generated_srcs_all ${_generated_srcs}) + set(_comment "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}") + if(protobuf_generate_PROTOC_OPTIONS) + set(_comment "${_comment}, protoc-options: ${protobuf_generate_PROTOC_OPTIONS}") + endif() + if(_plugin_options) + set(_comment "${_comment}, plugin-options: ${_plugin_options}") + endif() + add_custom_command( OUTPUT ${_generated_srcs} - COMMAND protobuf::protoc - ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file} + COMMAND protobuf::protoc + ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file} DEPENDS ${_abs_file} protobuf::protoc - COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}. Custom options: ${protobuf_generate_PROTOC_OPTIONS}" + COMMENT ${_comment} VERBATIM ) endforeach() From fbe6ab248787743f2f72a5bd477808244067f2d4 Mon Sep 17 00:00:00 2001 From: Lukas Fittl Date: Wed, 9 Feb 2022 08:44:12 -0800 Subject: [PATCH 207/207] [Ruby] Message.decode/encode: Add max_recursion_depth option (#9218) * Message.decode/encode: Add max_recursion_depth option This allows increasing the recursing depth from the default of 64, by setting the "max_recursion_depth" to the desired integer value. This is useful to encode or decode complex nested protobuf messages that otherwise error out with a RuntimeError or "Error occurred during parsing". Fixes #1493 * Address review comments Co-authored-by: Adam Cozzette --- ruby/ext/google/protobuf_c/message.c | 65 +++++++++++++--- ruby/lib/google/protobuf.rb | 8 +- ruby/lib/google/protobuf/message_exts.rb | 4 +- .../com/google/protobuf/jruby/RubyMap.java | 4 +- .../google/protobuf/jruby/RubyMessage.java | 78 ++++++++++++------- ruby/tests/encode_decode_test.rb | 51 ++++++++++++ 6 files changed, 164 insertions(+), 46 deletions(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 7feee75db8..8d25b7928c 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -953,13 +953,35 @@ static VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) { /* * call-seq: - * MessageClass.decode(data) => message + * MessageClass.decode(data, options) => message * * Decodes the given data (as a string containing bytes in protocol buffers wire * format) under the interpretration given by this message class's definition * and returns a message object with the corresponding field values. + * @param options [Hash] options for the decoder + * max_recursion_depth: set to maximum decoding depth for message (default is 64) */ -static VALUE Message_decode(VALUE klass, VALUE data) { +static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) { + VALUE data = argv[0]; + int options = 0; + + if (argc < 1 || argc > 2) { + rb_raise(rb_eArgError, "Expected 1 or 2 arguments."); + } + + if (argc == 2) { + VALUE hash_args = argv[1]; + if (TYPE(hash_args) != T_HASH) { + rb_raise(rb_eArgError, "Expected hash arguments."); + } + + VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("max_recursion_depth"))); + + if (depth != Qnil && TYPE(depth) == T_FIXNUM) { + options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth)); + } + } + if (TYPE(data) != T_STRING) { rb_raise(rb_eArgError, "Expected string for binary protobuf data."); } @@ -969,7 +991,7 @@ static VALUE Message_decode(VALUE klass, VALUE data) { upb_DecodeStatus status = upb_Decode( RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg, - upb_MessageDef_MiniTable(msg->msgdef), NULL, 0, Arena_get(msg->arena)); + upb_MessageDef_MiniTable(msg->msgdef), NULL, options, Arena_get(msg->arena)); if (status != kUpb_DecodeStatus_Ok) { rb_raise(cParseError, "Error occurred during parsing"); @@ -1043,24 +1065,43 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { /* * call-seq: - * MessageClass.encode(msg) => bytes + * MessageClass.encode(msg, options) => bytes * * Encodes the given message object to its serialized form in protocol buffers * wire format. + * @param options [Hash] options for the encoder + * max_recursion_depth: set to maximum encoding depth for message (default is 64) */ -static VALUE Message_encode(VALUE klass, VALUE msg_rb) { - Message* msg = ruby_to_Message(msg_rb); +static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) { + Message* msg = ruby_to_Message(argv[0]); + int options = 0; const char* data; size_t size; - if (CLASS_OF(msg_rb) != klass) { + if (CLASS_OF(argv[0]) != klass) { rb_raise(rb_eArgError, "Message of wrong type."); } - upb_Arena* arena = upb_Arena_New(); + if (argc < 1 || argc > 2) { + rb_raise(rb_eArgError, "Expected 1 or 2 arguments."); + } - data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), 0, arena, - &size); + if (argc == 2) { + VALUE hash_args = argv[1]; + if (TYPE(hash_args) != T_HASH) { + rb_raise(rb_eArgError, "Expected hash arguments."); + } + VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("max_recursion_depth"))); + + if (depth != Qnil && TYPE(depth) == T_FIXNUM) { + options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth)); + } + } + + upb_Arena *arena = upb_Arena_New(); + + data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), + options, arena, &size); if (data) { VALUE ret = rb_str_new(data, size); @@ -1186,8 +1227,8 @@ VALUE build_class_from_descriptor(VALUE descriptor) { rb_define_method(klass, "to_s", Message_inspect, 0); rb_define_method(klass, "[]", Message_index, 1); rb_define_method(klass, "[]=", Message_index_set, 2); - rb_define_singleton_method(klass, "decode", Message_decode, 1); - rb_define_singleton_method(klass, "encode", Message_encode, 1); + rb_define_singleton_method(klass, "decode", Message_decode, -1); + rb_define_singleton_method(klass, "encode", Message_encode, -1); rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1); rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1); rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0); diff --git a/ruby/lib/google/protobuf.rb b/ruby/lib/google/protobuf.rb index f939a4c7dc..b7a6711051 100644 --- a/ruby/lib/google/protobuf.rb +++ b/ruby/lib/google/protobuf.rb @@ -59,16 +59,16 @@ require 'google/protobuf/repeated_field' module Google module Protobuf - def self.encode(msg) - msg.to_proto + def self.encode(msg, options = {}) + msg.to_proto(options) end def self.encode_json(msg, options = {}) msg.to_json(options) end - def self.decode(klass, proto) - klass.decode(proto) + def self.decode(klass, proto, options = {}) + klass.decode(proto, options) end def self.decode_json(klass, json, options = {}) diff --git a/ruby/lib/google/protobuf/message_exts.rb b/ruby/lib/google/protobuf/message_exts.rb index f432f89fed..6608521728 100644 --- a/ruby/lib/google/protobuf/message_exts.rb +++ b/ruby/lib/google/protobuf/message_exts.rb @@ -44,8 +44,8 @@ module Google self.class.encode_json(self, options) end - def to_proto - self.class.encode(self) + def to_proto(options = {}) + self.class.encode(self, options) end end diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java index f7379b148e..b5e4903e2e 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java @@ -389,7 +389,7 @@ public class RubyMap extends RubyObject { return newMap; } - protected List build(ThreadContext context, RubyDescriptor descriptor, int depth) { + protected List build(ThreadContext context, RubyDescriptor descriptor, int depth, int maxRecursionDepth) { List list = new ArrayList(); RubyClass rubyClass = (RubyClass) descriptor.msgclass(context); FieldDescriptor keyField = descriptor.getField("key"); @@ -398,7 +398,7 @@ public class RubyMap extends RubyObject { RubyMessage mapMessage = (RubyMessage) rubyClass.newInstance(context, Block.NULL_BLOCK); mapMessage.setField(context, keyField, key); mapMessage.setField(context, valueField, table.get(key)); - list.add(mapMessage.build(context, depth + 1)); + list.add(mapMessage.build(context, depth + 1, maxRecursionDepth)); } return list; } diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java index cf59f62597..2ba132e628 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java @@ -39,6 +39,7 @@ import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; import com.google.protobuf.ByteString; +import com.google.protobuf.CodedInputStream; import com.google.protobuf.DynamicMessage; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.Message; @@ -461,35 +462,63 @@ public class RubyMessage extends RubyObject { /* * call-seq: - * MessageClass.encode(msg) => bytes + * MessageClass.encode(msg, options = {}) => bytes * * Encodes the given message object to its serialized form in protocol buffers * wire format. + * @param options [Hash] options for the encoder + * max_recursion_depth: set to maximum encoding depth for message (default is 64) */ - @JRubyMethod(meta = true) - public static IRubyObject encode(ThreadContext context, IRubyObject recv, IRubyObject value) { - if (recv != value.getMetaClass()) { - throw context.runtime.newArgumentError("Tried to encode a " + value.getMetaClass() + " message with " + recv); + @JRubyMethod(required = 1, optional = 1, meta = true) + public static IRubyObject encode(ThreadContext context, IRubyObject recv, IRubyObject[] args) { + if (recv != args[0].getMetaClass()) { + throw context.runtime.newArgumentError("Tried to encode a " + args[0].getMetaClass() + " message with " + recv); } - RubyMessage message = (RubyMessage) value; - return context.runtime.newString(new ByteList(message.build(context).toByteArray())); + RubyMessage message = (RubyMessage) args[0]; + int maxRecursionDepthInt = SINK_MAXIMUM_NESTING; + + if (args.length > 1) { + RubyHash options = (RubyHash) args[1]; + IRubyObject maxRecursionDepth = options.fastARef(context.runtime.newSymbol("max_recursion_depth")); + + if (maxRecursionDepth != null) { + maxRecursionDepthInt = ((RubyNumeric) maxRecursionDepth).getIntValue(); + } + } + return context.runtime.newString(new ByteList(message.build(context, 0, maxRecursionDepthInt).toByteArray())); } /* * call-seq: - * MessageClass.decode(data) => message + * MessageClass.decode(data, options = {}) => message * * Decodes the given data (as a string containing bytes in protocol buffers wire * format) under the interpretation given by this message class's definition * and returns a message object with the corresponding field values. + * @param options [Hash] options for the decoder + * max_recursion_depth: set to maximum decoding depth for message (default is 100) */ - @JRubyMethod(meta = true) - public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyObject data) { + @JRubyMethod(required = 1, optional = 1, meta = true) + public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyObject[] args) { + IRubyObject data = args[0]; byte[] bin = data.convertToString().getBytes(); + CodedInputStream input = CodedInputStream.newInstance(bin); RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK); + + if (args.length == 2) { + if (!(args[1] instanceof RubyHash)) { + throw context.runtime.newArgumentError("Expected hash arguments."); + } + + IRubyObject maxRecursionDepth = ((RubyHash) args[1]).fastARef(context.runtime.newSymbol("max_recursion_depth")); + if (maxRecursionDepth != null) { + input.setRecursionLimit(((RubyNumeric) maxRecursionDepth).getIntValue()); + } + } + try { - ret.builder.mergeFrom(bin); - } catch (InvalidProtocolBufferException e) { + ret.builder.mergeFrom(input); + } catch (Exception e) { throw RaiseException.from(context.runtime, (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::ParseError"), e.getMessage()); } @@ -541,7 +570,7 @@ public class RubyMessage extends RubyObject { printer = printer.usingTypeRegistry(JsonFormat.TypeRegistry.newBuilder().add(message.descriptor).build()); try { - result = printer.print(message.build(context)); + result = printer.print(message.build(context, 0, SINK_MAXIMUM_NESTING)); } catch (InvalidProtocolBufferException e) { throw runtime.newRuntimeError(e.getMessage()); } catch (IllegalArgumentException e) { @@ -635,12 +664,8 @@ public class RubyMessage extends RubyObject { return ret; } - protected DynamicMessage build(ThreadContext context) { - return build(context, 0); - } - - protected DynamicMessage build(ThreadContext context, int depth) { - if (depth > SINK_MAXIMUM_NESTING) { + protected DynamicMessage build(ThreadContext context, int depth, int maxRecursionDepth) { + if (depth >= maxRecursionDepth) { throw context.runtime.newRuntimeError("Maximum recursion depth exceeded during encoding."); } @@ -651,7 +676,7 @@ public class RubyMessage extends RubyObject { if (value instanceof RubyMap) { builder.clearField(fieldDescriptor); RubyDescriptor mapDescriptor = (RubyDescriptor) getDescriptorForField(context, fieldDescriptor); - for (DynamicMessage kv : ((RubyMap) value).build(context, mapDescriptor, depth)) { + for (DynamicMessage kv : ((RubyMap) value).build(context, mapDescriptor, depth, maxRecursionDepth)) { builder.addRepeatedField(fieldDescriptor, kv); } @@ -660,7 +685,7 @@ public class RubyMessage extends RubyObject { builder.clearField(fieldDescriptor); for (int i = 0; i < repeatedField.size(); i++) { - Object item = convert(context, fieldDescriptor, repeatedField.get(i), depth, + Object item = convert(context, fieldDescriptor, repeatedField.get(i), depth, maxRecursionDepth, /*isDefaultValueForBytes*/ false); builder.addRepeatedField(fieldDescriptor, item); } @@ -682,7 +707,7 @@ public class RubyMessage extends RubyObject { fieldDescriptor.getFullName().equals("google.protobuf.FieldDescriptorProto.default_value")) { isDefaultStringForBytes = true; } - builder.setField(fieldDescriptor, convert(context, fieldDescriptor, value, depth, isDefaultStringForBytes)); + builder.setField(fieldDescriptor, convert(context, fieldDescriptor, value, depth, maxRecursionDepth, isDefaultStringForBytes)); } } @@ -702,7 +727,7 @@ public class RubyMessage extends RubyObject { builder.clearField(fieldDescriptor); RubyDescriptor mapDescriptor = (RubyDescriptor) getDescriptorForField(context, fieldDescriptor); - for (DynamicMessage kv : ((RubyMap) value).build(context, mapDescriptor, depth)) { + for (DynamicMessage kv : ((RubyMap) value).build(context, mapDescriptor, depth, maxRecursionDepth)) { builder.addRepeatedField(fieldDescriptor, kv); } } @@ -814,7 +839,8 @@ public class RubyMessage extends RubyObject { // convert a ruby object to protobuf type, skip type check since it is checked on the way in private Object convert(ThreadContext context, FieldDescriptor fieldDescriptor, - IRubyObject value, int depth, boolean isDefaultStringForBytes) { + IRubyObject value, int depth, int maxRecursionDepth, + boolean isDefaultStringForBytes) { Object val = null; switch (fieldDescriptor.getType()) { case INT32: @@ -855,7 +881,7 @@ public class RubyMessage extends RubyObject { } break; case MESSAGE: - val = ((RubyMessage) value).build(context, depth + 1); + val = ((RubyMessage) value).build(context, depth + 1, maxRecursionDepth); break; case ENUM: EnumDescriptor enumDescriptor = fieldDescriptor.getEnumType(); @@ -1214,7 +1240,7 @@ public class RubyMessage extends RubyObject { private static final String CONST_SUFFIX = "_const"; private static final String HAS_PREFIX = "has_"; private static final String QUESTION_MARK = "?"; - private static final int SINK_MAXIMUM_NESTING = 63; + private static final int SINK_MAXIMUM_NESTING = 64; private Descriptor descriptor; private DynamicMessage.Builder builder; diff --git a/ruby/tests/encode_decode_test.rb b/ruby/tests/encode_decode_test.rb index 429ac43322..9513cc37d9 100755 --- a/ruby/tests/encode_decode_test.rb +++ b/ruby/tests/encode_decode_test.rb @@ -101,4 +101,55 @@ class EncodeDecodeTest < Test::Unit::TestCase assert_match json, "{\"CustomJsonName\":42}" end + def test_decode_depth_limit + msg = A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + ) + ) + ) + ) + ) + ) + msg_encoded = A::B::C::TestMessage.encode(msg) + msg_out = A::B::C::TestMessage.decode(msg_encoded) + assert_match msg.to_json, msg_out.to_json + + assert_raise Google::Protobuf::ParseError do + A::B::C::TestMessage.decode(msg_encoded, { max_recursion_depth: 4 }) + end + + msg_out = A::B::C::TestMessage.decode(msg_encoded, { max_recursion_depth: 5 }) + assert_match msg.to_json, msg_out.to_json + end + + def test_encode_depth_limit + msg = A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + optional_msg: A::B::C::TestMessage.new( + ) + ) + ) + ) + ) + ) + msg_encoded = A::B::C::TestMessage.encode(msg) + msg_out = A::B::C::TestMessage.decode(msg_encoded) + assert_match msg.to_json, msg_out.to_json + + assert_raise RuntimeError do + A::B::C::TestMessage.encode(msg, { max_recursion_depth: 5 }) + end + + msg_encoded = A::B::C::TestMessage.encode(msg, { max_recursion_depth: 6 }) + msg_out = A::B::C::TestMessage.decode(msg_encoded) + assert_match msg.to_json, msg_out.to_json + end + end