From 6e29dc1086fa7126217e25963cd4853fd32867ea Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Fri, 29 Sep 2023 08:28:18 +0200 Subject: [PATCH] Avoid trying to store new DataConverter type in frozen TypeDefs hash --- lib/ffi/types.rb | 3 ++- spec/ffi/struct_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/ffi/types.rb b/lib/ffi/types.rb index 8f5d897dd..c0bea0534 100644 --- a/lib/ffi/types.rb +++ b/lib/ffi/types.rb @@ -87,7 +87,8 @@ def self.find_type(name, type_map = nil) TypeDefs[name] elsif name.is_a?(DataConverter) - (type_map || TypeDefs)[name] = Type::Mapped.new(name) + tm = (type_map || custom_typedefs) + tm[name] = Type::Mapped.new(name) else raise TypeError, "unable to resolve type '#{name}'" end diff --git a/spec/ffi/struct_spec.rb b/spec/ffi/struct_spec.rb index ab62da130..6afe47537 100644 --- a/spec/ffi/struct_spec.rb +++ b/spec/ffi/struct_spec.rb @@ -215,6 +215,19 @@ def initialize(a, b) expect(s[:b]).to eq(0xdeadcafebabe) end + it "Can use DataConverter in an embedded array" do + class Blub #< FFI::Struct + extend FFI::DataConverter + native_type FFI::Type::INT + end + + class Zork < FFI::Struct + layout :c, [Blub, 2], 2 + end + z = Zork.new + expect(z[:c].to_a).to eq [0, 0] + end + it "Can use Struct subclass as parameter type" do expect(module StructParam extend FFI::Library