Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[FFI] FFI::Struct.by_ref mapped type accepts arbitrary structs in it’s #to_native #612
require "ffi" module Moo extend FFI::Library ffi_lib "C" class Cow < FFI::Struct layout :cool => :int end class Bozo < FFI::Struct layout :cool => :int end attach_function :puts, [ Cow.by_ref ], :void end Moo.puts Moo::Bozo.new
The above code runs without error in JRuby, since for the mapped type returned by Moo::Cow.by_ref will accept any descendant of FFI::Struct, instead of only descendants of Moo::Cow.
In the FFI gem, the above code will raise an error:
Personally I feel that the behaviour from the FFI gem makes more sense, and is slightly less prone to accidents, which is why I created the issue on JRuby and not the FFI gem.