Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ffi/ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed Sep 29, 2023
2 parents c97b825 + c1ed9bc commit 87ff960
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/ffi/types.rb
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/ffi/struct_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 87ff960

Please sign in to comment.