[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

Projects

None yet

1 participant

@Burgestrand
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 Unknown added a commit to ffi/ffi that referenced this issue Mar 29, 2013
Wayne Meissner Add specs for jruby/jruby#612 c86b4b3
@ghost Unknown added a commit that referenced this issue Mar 29, 2013
Wayne Meissner Fix issue #612 - restrict struct parameters to those of the appropria…
…te type.
6b3d677
@ghost
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