Fix Ruby FFI to pass `MiniTable` to `upb_Message_New()` aka `new_message_from_def()`.

PiperOrigin-RevId: 635226405
pull/16887/head
Protobuf Team Bot 6 months ago committed by Copybara-Service
parent 1f8208031a
commit 47f4bc958b
  1. 2
      ruby/lib/google/protobuf/ffi/descriptor.rb
  2. 4
      ruby/lib/google/protobuf/ffi/internal/convert.rb
  3. 2
      ruby/lib/google/protobuf/ffi/message.rb

@ -152,7 +152,7 @@ module Google
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

@ -70,7 +70,7 @@ module Google
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 @@ module Google
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

@ -551,7 +551,7 @@ module Google
# 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

Loading…
Cancel
Save