Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FFI] FFI::Struct.by_ref mapped type accepts arbitrary structs in it’s #to_native #612

Burgestrand opened this issue Mar 28, 2013 · 1 comment


None yet
1 participant
Copy link

commented Mar 28, 2013

require "ffi"

module Moo
  extend FFI::Library
  ffi_lib "C"

  class Cow < FFI::Struct
    layout :cool => :int

  class Bozo < FFI::Struct
    layout :cool => :int

  attach_function :puts, [ Cow.by_ref ], :void


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: wrong argument type Moo::Bozo (expected Moo::Cow) (TypeError)

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.

ghost pushed a commit to ffi/ffi that referenced this issue Mar 29, 2013

Wayne Meissner

ghost pushed a commit that referenced this issue Mar 29, 2013


This comment has been minimized.

Copy link

commented Mar 29, 2013

Should be fixed now in commit 6b3d677

@ghost ghost closed this Mar 29, 2013

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.