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::Library#enum_value difference between MRI and JRuby #1954

Burgestrand opened this issue Sep 6, 2014 · 1 comment

FFI::Library#enum_value difference between MRI and JRuby #1954

Burgestrand opened this issue Sep 6, 2014 · 1 comment


Copy link

@Burgestrand Burgestrand commented Sep 6, 2014

Here's the definition of FFI::Library#enum_value:

def enum_value(symbol)

When an enum value does not exist, MRI will return nil for FFI::Library#enum_value, but JRuby will raise an error. Here's code to reproduce the error:

require "ffi"

module MyLibrary
  extend FFI::Library

  enum :something, [:one, :two]

p MyLibrary.enum_value(:nonexistant)

MRI prints nil, JRuby raises an error. Here's the JRuby error stacktrace:

NoMethodError: undefined method `default' for #<FFI::Enums:0x3e19d688>
            [] at org/jruby/
  __map_symbol at org/jruby/ext/ffi/
    enum_value at /Users/Kim/.rvm/rubies/jruby-1.7.12/lib/ruby/shared/ffi/library.rb:456
        (root) at repro.rb:9

Looking at the stack trace I believe it's because Enums ( inherits from Hash, and when the lookup fails a default value is attempted to be retrieved but for some reason that method does not exist in FFI::Enums, and an error occurs.

I've worked around it locally with the following monkey patch:

unless FFI::Enums.method_defined?(:default)
  FFI::Enums.send(:attr_accessor, :default)
Burgestrand added a commit to Burgestrand/spotify that referenced this issue Sep 6, 2014
Copy link

@headius headius commented Nov 2, 2014

Fixed by #2003.

@headius headius closed this Nov 2, 2014
@headius headius added this to the JRuby 1.7.17 milestone Nov 2, 2014
@headius headius added the ffi label Nov 2, 2014
@headius headius self-assigned this Nov 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants