Skip to content

Commit

Permalink
Fix Ruby FFI to pass MiniTable to upb_Message_New() aka `new_mess…
Browse files Browse the repository at this point in the history
…age_from_def()`.

PiperOrigin-RevId: 635226405
  • Loading branch information
protobuf-github-bot authored and copybara-github committed May 19, 2024
1 parent 1f82080 commit 47f4bc9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ruby/lib/google/protobuf/ffi/descriptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ruby/lib/google/protobuf/ffi/internal/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ruby/lib/google/protobuf/ffi/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47f4bc9

Please sign in to comment.