Skip to content

Commit

Permalink
Merge pull request #1057 from mvz/avoid-frozen-typemap
Browse files Browse the repository at this point in the history
Avoid trying to store new DataConverter type in frozen TypeDefs hash
  • Loading branch information
larskanis committed Sep 29, 2023
2 parents bf21280 + 6e29dc1 commit 13afd23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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 13afd23

Please sign in to comment.