123456789_123456789_123456789_123456789_123456789_

Module: FFI::Function::RegisterAttach

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/ffi/function.rb

Overview

Stash the ::FFI::Function in a module variable so it can be inspected by attached_functions. On CRuby it also ensures that it does not get garbage collected.

Instance Method Summary

Instance Method Details

#attach(mod, name)

[ GitHub ]

  
# File 'lib/ffi/function.rb', line 57

def attach(mod, name)
  funcs = mod.instance_variable_defined?("@ffi_functions") && mod.instance_variable_get("@ffi_functions")
  unless funcs
    funcs = {}
    mod.instance_variable_set("@ffi_functions", funcs)
  end
  funcs[name.to_sym] = self
  # Jump to the native attach method of CRuby, JRuby or Tuffleruby
  super
end