diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-04-06 12:22:11 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-04-06 12:24:04 -0700 |
commit | 9a536029c699ee501d9278577a300a5ef3d147dd (patch) | |
tree | 7e3d63890d70f72a048a64cd6f4e52c9075d99fa /lib/ffi_yajl/ext.rb | |
parent | 10c7da3b6002a59e21c9c8ee202f6f713c3959f9 (diff) | |
download | ffi-yajl-9a536029c699ee501d9278577a300a5ef3d147dd.tar.gz |
add native dlopen extension code
This will get dlopen in a consistent place on all the platforms
which need it.
Diffstat (limited to 'lib/ffi_yajl/ext.rb')
-rw-r--r-- | lib/ffi_yajl/ext.rb | 51 |
1 files changed, 4 insertions, 47 deletions
diff --git a/lib/ffi_yajl/ext.rb b/lib/ffi_yajl/ext.rb index bc4d410..12f74d9 100644 --- a/lib/ffi_yajl/ext.rb +++ b/lib/ffi_yajl/ext.rb @@ -4,60 +4,17 @@ require 'ffi_yajl/encoder' require 'ffi_yajl/parser' require 'libyajl2' require 'ffi_yajl/map_library_name' +require 'ffi_yajl/ext/dlopen' module FFI_Yajl extend FFI_Yajl::MapLibraryName + extend FFI_Yajl::Ext::Dlopen + libname = map_library_name libpath = File.expand_path(File.join(Libyajl2.opt_path, libname)) - # - # FFS, what exactly was so wrong with DL.dlopen that ruby had to get rid of it??? - # - - def self.try_fiddle_dlopen(libpath) - require 'fiddle' - if defined?(Fiddle) && Fiddle.respond_to?(:dlopen) - ::Fiddle.dlopen(libpath) - true - else - false - end - rescue LoadError - return false - end - - def self.try_dl_dlopen(libpath) - require 'dl' - if defined?(DL) && DL.respond_to?(:dlopen) - ::DL.dlopen(libpath) - true - else - false - end - rescue LoadError - return false - end - - def self.try_ffi_dlopen(libpath) - require 'ffi' - require 'rbconfig' - extend ::FFI::Library - ffi_lib 'dl' - attach_function 'dlopen', :dlopen, [:string, :int], :void - if RbConfig::CONFIG['host_os'] =~ /linux/i - dlopen libpath, 0x102 # linux: RTLD_GLOBAL | RTLD_NOW - else - dlopen libpath, 0 - end - true - rescue LoadError - return false - end - - unless try_fiddle_dlopen(libpath) || try_dl_dlopen(libpath) || try_ffi_dlopen(libpath) - raise "cannot find dlopen via Fiddle, DL or FFI, what am I supposed to do?" - end + dlopen(libpath) class Parser require 'ffi_yajl/ext/parser' |