diff --git a/README.md b/README.md index 574881f25..54b7ba26e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ using Ruby-FFI](https://github.com/ffi/ffi/wiki/why-use-ffi). * C structs (also nested), enums and global variables * Callbacks from C to Ruby * Automatic garbage collection of native memory -* Usable in Ractor +* Usable in Ractor: https://github.com/ffi/ffi/wiki/How-to-use-FFI-in-Ruby-Ractors ## Synopsis 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