Skip to content

Commit 47f4bc9

Browse files
Fix Ruby FFI to pass MiniTable to upb_Message_New() aka new_message_from_def().
PiperOrigin-RevId: 635226405
1 parent 1f82080 commit 47f4bc9

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

ruby/lib/google/protobuf/ffi/descriptor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def pool
152152

153153
class FFI
154154
# MessageDef
155-
attach_function :new_message_from_def, :upb_Message_New, [Descriptor, Internal::Arena], :Message
155+
attach_function :new_message_from_def, :upb_Message_New, [MiniTable.by_ref, Internal::Arena], :Message
156156
attach_function :field_count, :upb_MessageDef_FieldCount, [Descriptor], :int
157157
attach_function :get_message_file_def, :upb_MessageDef_File, [:pointer], :FileDef
158158
attach_function :get_message_fullname, :upb_MessageDef_FullName, [Descriptor], :string

ruby/lib/google/protobuf/ffi/internal/convert.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def convert_ruby_to_upb(value, arena, c_type, msg_or_enum_def)
7070
case wkt
7171
when :Timestamp
7272
raise TypeError.new "Invalid type #{value.class} to assign to submessage field '#{name}'." unless value.kind_of? Time
73-
new_message = Google::Protobuf::FFI.new_message_from_def msg_or_enum_def, arena
73+
new_message = Google::Protobuf::FFI.new_message_from_def Google::Protobuf::FFI.get_mini_table(msg_or_enum_def), arena
7474
sec = Google::Protobuf::FFI::MessageValue.new
7575
sec[:int64_val] = value.tv_sec
7676
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)
8282
return_value[:msg_val] = new_message
8383
when :Duration
8484
raise TypeError.new "Invalid type #{value.class} to assign to submessage field '#{name}'." unless value.kind_of? Numeric
85-
new_message = Google::Protobuf::FFI.new_message_from_def msg_or_enum_def, arena
85+
new_message = Google::Protobuf::FFI.new_message_from_def Google::Protobuf::FFI.get_mini_table(msg_or_enum_def), arena
8686
sec = Google::Protobuf::FFI::MessageValue.new
8787
sec[:int64_val] = value
8888
sec_field_def = Google::Protobuf::FFI.get_field_by_number msg_or_enum_def, 1

ruby/lib/google/protobuf/ffi/message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def index_assign_internal(value, name: nil, field_descriptor: nil, wrap: false)
551551
# one if omitted or nil.
552552
def initialize(initial_value = nil, arena = nil, msg = nil)
553553
@arena = arena || Google::Protobuf::FFI.create_arena
554-
@msg = msg || Google::Protobuf::FFI.new_message_from_def(self.class.descriptor, @arena)
554+
@msg = msg || Google::Protobuf::FFI.new_message_from_def(Google::Protobuf::FFI.get_mini_table(self.class.descriptor), @arena)
555555

556556
unless initial_value.nil?
557557
raise ArgumentError.new "Expected hash arguments or message, not #{initial_value.class}" unless initial_value.respond_to? :each

0 commit comments

Comments
 (0)