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

Closed
Burgestrand opened this Issue Mar 28, 2013 · 1 comment

Comments

Projects
None yet
1 participant
@Burgestrand

Burgestrand commented Mar 28, 2013

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: 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

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

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Mar 29, 2013

Should be fixed now in commit 6b3d677

ghost 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