/
ffi.rb
28 lines (24 loc) · 919 Bytes
/
ffi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
Object.send(:remove_const, :FFI) if defined?(::FFI)
begin
require RUBY_VERSION.split('.')[0, 2].join('.') + '/ffi_c'
rescue Exception
require 'ffi_c'
end
require 'ffi/ffi'
elsif RUBY_ENGINE == 'jruby' && Gem::Version.new(RUBY_ENGINE_VERSION) >= Gem::Version.new("9.3.pre")
JRuby::Util.load_ext("org.jruby.ext.ffi.FFIService")
require 'ffi/ffi'
elsif RUBY_ENGINE == 'truffleruby' && Gem::Version.new(RUBY_ENGINE_VERSION) >= Gem::Version.new("20.1.0")
require 'truffleruby/ffi_backend'
require 'ffi/ffi'
else
# Remove the ffi gem dir from the load path, then reload the internal ffi implementation
$LOAD_PATH.delete(File.dirname(__FILE__))
$LOAD_PATH.delete(File.join(File.dirname(__FILE__), 'ffi'))
unless $LOADED_FEATURES.nil?
$LOADED_FEATURES.delete(__FILE__)
$LOADED_FEATURES.delete('ffi.rb')
end
require 'ffi.rb'
end