From 47f4bc958bc719b905942738470718f03ca70b33 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Sun, 19 May 2024 07:01:13 -0700 Subject: [PATCH] Fix Ruby FFI to pass `MiniTable` to `upb_Message_New()` aka `new_message_from_def()`. PiperOrigin-RevId: 635226405 --- ruby/lib/google/protobuf/ffi/descriptor.rb | 2 +- ruby/lib/google/protobuf/ffi/internal/convert.rb | 4 ++-- ruby/lib/google/protobuf/ffi/message.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ruby/lib/google/protobuf/ffi/descriptor.rb b/ruby/lib/google/protobuf/ffi/descriptor.rb index 1ccaf77a907a3..9a36012348726 100644 --- a/ruby/lib/google/protobuf/ffi/descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/descriptor.rb @@ -152,7 +152,7 @@ def pool class FFI # MessageDef - attach_function :new_message_from_def, :upb_Message_New, [Descriptor, Internal::Arena], :Message + attach_function :new_message_from_def, :upb_Message_New, [MiniTable.by_ref, Internal::Arena], :Message attach_function :field_count, :upb_MessageDef_FieldCount, [Descriptor], :int attach_function :get_message_file_def, :upb_MessageDef_File, [:pointer], :FileDef attach_function :get_message_fullname, :upb_MessageDef_FullName, [Descriptor], :string diff --git a/ruby/lib/google/protobuf/ffi/internal/convert.rb b/ruby/lib/google/protobuf/ffi/internal/convert.rb index cf8669329b194..ff59f8cd4e7b6 100644 --- a/ruby/lib/google/protobuf/ffi/internal/convert.rb +++ b/ruby/lib/google/protobuf/ffi/internal/convert.rb @@ -70,7 +70,7 @@ def convert_ruby_to_upb(value, arena, c_type, msg_or_enum_def) case wkt when :Timestamp raise TypeError.new "Invalid type #{value.class} to assign to submessage field '#{name}'." unless value.kind_of? Time - new_message = Google::Protobuf::FFI.new_message_from_def msg_or_enum_def, arena + new_message = Google::Protobuf::FFI.new_message_from_def Google::Protobuf::FFI.get_mini_table(msg_or_enum_def), arena sec = Google::Protobuf::FFI::MessageValue.new sec[:int64_val] = value.tv_sec sec_field_def = Google::Protobuf::FFI.get_field_by_number msg_or_enum_def, 1 @@ -82,7 +82,7 @@ def convert_ruby_to_upb(value, arena, c_type, msg_or_enum_def) return_value[:msg_val] = new_message when :Duration raise TypeError.new "Invalid type #{value.class} to assign to submessage field '#{name}'." unless value.kind_of? Numeric - new_message = Google::Protobuf::FFI.new_message_from_def msg_or_enum_def, arena + new_message = Google::Protobuf::FFI.new_message_from_def Google::Protobuf::FFI.get_mini_table(msg_or_enum_def), arena sec = Google::Protobuf::FFI::MessageValue.new sec[:int64_val] = value sec_field_def = Google::Protobuf::FFI.get_field_by_number msg_or_enum_def, 1 diff --git a/ruby/lib/google/protobuf/ffi/message.rb b/ruby/lib/google/protobuf/ffi/message.rb index c1b9b4318e0d5..a3dc2d189bbdc 100644 --- a/ruby/lib/google/protobuf/ffi/message.rb +++ b/ruby/lib/google/protobuf/ffi/message.rb @@ -551,7 +551,7 @@ def index_assign_internal(value, name: nil, field_descriptor: nil, wrap: false) # one if omitted or nil. def initialize(initial_value = nil, arena = nil, msg = nil) @arena = arena || Google::Protobuf::FFI.create_arena - @msg = msg || Google::Protobuf::FFI.new_message_from_def(self.class.descriptor, @arena) + @msg = msg || Google::Protobuf::FFI.new_message_from_def(Google::Protobuf::FFI.get_mini_table(self.class.descriptor), @arena) unless initial_value.nil? raise ArgumentError.new "Expected hash arguments or message, not #{initial_value.class}" unless initial_value.respond_to? :each