This allows to reduce binary bloat (all calls to Clear are now defined out of line) and eliminate redundant calls to clear (since we only call it when it is needed).
PiperOrigin-RevId: 590944438
Do more inlining in certain callers of ParseLoop to avoid the extra stack frame.
This reduces the overall cost of maintaining the stack frames in functions like FastMtS1.
PiperOrigin-RevId: 590943926
## Issue
When an object that is an instance of a string-derived class is passed to a string field in a protobuf message in Ruby, it results in a `Google::Protobuf::TypeError`.
### Steps to reproduce
```rb
~/src/github.com/protocolbuffers/protobuf/ruby/tests ❯❯❯ irb -I .
irb(main):001:0> require 'basic_test_pb'
=> true
irb(main):002:0> myString = Class.new(String)
=> #<Class:0x00000001531540d8>
irb(main):003:0> str = myString.new("foo")
=> "foo"
irb(main):004:0> BasicTest::TestMessage.new(optional_string: "foo")
=> <BasicTest::TestMessage: optional_string: "foo", repeated_int32: [], repeated_int64: [], repeated_uint32: [], repeated_uint64: [], repeated_bool: [], repeated_float: [], repeated_double: [], repeated_string: [], repeated_bytes: [], repeated_msg: [], repeated_enum: []>
irb(main):005:0> BasicTest::TestMessage.new(optional_string: str)
(irb):5:in `initialize': Invalid argument for string field 'optional_string' (given #<Class:0x00000001531540d8>). (Google::Protobuf::TypeError)
irb(main):006:0>
```
## Fix
The issue appears to be caused by the field checking mechanism not properly handling instances of classes that inherit from basic types like String. My proposed solution is to improve the type checking for string fields to consider not just String instances but also instances of subclasses of String.
## Impact
The changes will allow instances of classes derived from String to be passed to string fields without any error.
This is a backwards-compatible change and will not affect the existing behaviour with standard String instances.
Closes#13818
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/13818 from NotFounds:support-string-subclass-for-ruby 2d2796c4f9
PiperOrigin-RevId: 590941235
This won't have much effect over the edition zero migration, since enums in any proto2/proto3 file are either exclusively closed/open, respectively. However, it will prefer enum-level features if there's only a single enum
PiperOrigin-RevId: 590642827
When attempting to run the Ruby tests, I noticed that the README is slightly off; it points to a target that doesn't exist:
```
charles@AlterCation:~/protobuf$ bazel test //ruby/tests/... //ruby:ffi=enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI
ERROR: Skipping '//ruby:ffi=enabled': no such target '//ruby:ffi=enabled': target 'ffi=enabled' not declared in package 'ruby' defined by /home/charles/protobuf/ruby/BUILD.bazel (did you mean 'ffi_enabled'? Tip: use `query "//ruby:*"` to see all the targets in that package)
ERROR: no such target '//ruby:ffi=enabled': target 'ffi=enabled' not declared in package 'ruby' defined by /home/charles/protobuf/ruby/BUILD.bazel (did you mean 'ffi_enabled'? Tip: use `query "//ruby:*"` to see all the targets in that package)
INFO: Elapsed time: 0.679s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Couldn't start the build. Unable to run tests
charles@AlterCation:~/protobuf$
```
Instead, it looks like `//ruby:ffi_enabled` is what you're supposed to use, which sets the flag on:
https://github.com/protocolbuffers/protobuf/blob/main/ruby/BUILD.bazel#L28-L30Closes#15041
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15041 from shaldengeki:ouguoc/fix-ruby-readme-ffi-enabled 245d84942d
PiperOrigin-RevId: 590501532
On my local setup (WSL Ubuntu), I noticed that attempting to build Ruby tests fails, because of an error in `rules_apple`:
```
charles@AlterCation:~/protobuf$ bazel test //ruby/tests/...
WARNING: Build option --test_env has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
/usr/local/bin/ruby: No such file or directory -- bundler/exe/bundler (LoadError)
ERROR: Traceback (most recent call last):
File "/home/charles/.cache/bazel/_bazel_charles/dcd9f4fa8672aac49359d11b9a237597/external/build_bazel_rules_apple/apple/internal/rule_support.bzl", line 221, column 36, in <toplevel>
deps_cfg = apple_common.multi_arch_split,
Error: 'apple_common' value has no field or method 'multi_arch_split'
```
This is an error previously reported in `rules_apple`, and fixed here: https://github.com/bazelbuild/rules_apple/pull/2034
Looks like that was pulled into release 3.0.0, but I figured we may as well try for 3.1.1 ([the latest release](https://github.com/bazelbuild/rules_apple/releases)).
With this bump, I no longer get the above error.
Closes#15040
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15040 from shaldengeki:ouguoc/bump-rules-apple-3.1.1 5e127dc4aa
PiperOrigin-RevId: 590284088
We do not expect well-behaved code to ever rely on this check and well-behaved code should not being paying the price for it. We still need to keep it until b/290091828 is fixed but we can move it to slow out-of-line function.
```
name old cpu/op new cpu/op delta
BM_RepeatedPtrField_Ctor 75.3ns ± 4% 63.8ns ± 1% -15.27% (p=0.000 n=99+86)
```
PiperOrigin-RevId: 590139004
Users should use the add-on unknown_fields.py support.
Old usage example:
unknown_field_set = msg.UnknownFields()
New usage should be:
from google.protobuf import unknown_fields
unknown_field_set = unknown_fields.UnknownFieldSet(msg)
PiperOrigin-RevId: 589969095
We augment the TYPE_STRING block inside message.cc:GetterForViewOrMut so that we properly return a Mut for strings when it comes to submessages.
PiperOrigin-RevId: 589944498
- Rename most usage of `'a` to `'msg`
- Remove a no-op unused lifetime param for `remove` in maps
- Elide lifetimes recommended by clippy
PiperOrigin-RevId: 589878364
This has been replaced by edition and feature getters. Any code depending on syntax will likely be broken by editions files, and should be migrated to the finer-grained feature helpers.
PiperOrigin-RevId: 589866745
This will guarantee that the output of TextFormat is always valid UTF-8. Prior to this change, any invalid UTF-8 would escape into the TextFormat output if users enabled `SetUseUtf8StringEscaping(true)` or called `Utf8DebugString()`.
This change currently only affects users who explicitly set `SetUseUtf8StringEscaping(true)` or use `Utf8DebugString()`, but the hope is to flip the default so that this mode is enabled unless overridden.
PiperOrigin-RevId: 589844142
This significantly simplifies the internals of PrimitiveMut,
and removes the need to refactor BytesMut and ProtoStrMut
to have the same runtime branching.
PiperOrigin-RevId: 589292565