summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-04-06 12:22:11 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-04-06 12:24:04 -0700
commit9a536029c699ee501d9278577a300a5ef3d147dd (patch)
tree7e3d63890d70f72a048a64cd6f4e52c9075d99fa /lib
parent10c7da3b6002a59e21c9c8ee202f6f713c3959f9 (diff)
downloadffi-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')
-rw-r--r--lib/ffi_yajl.rb8
-rw-r--r--lib/ffi_yajl/ext.rb51
2 files changed, 8 insertions, 51 deletions
diff --git a/lib/ffi_yajl.rb b/lib/ffi_yajl.rb
index 7f39189..1787766 100644
--- a/lib/ffi_yajl.rb
+++ b/lib/ffi_yajl.rb
@@ -19,10 +19,10 @@ elsif ENV['FORCE_FFI_YAJL'] == "ffi"
require 'ffi_yajl/ffi'
elsif RUBY_PLATFORM == "java"
require 'ffi_yajl/ffi'
-elsif defined?(Yajl)
- warn "the ffi-yajl and yajl-ruby gems have incompatible C libyajl libs and should not be loaded in the same Ruby VM"
- warn "falling back to ffi which might work (or might not, no promises)"
- require 'ffi_yajl/ffi'
+#elsif defined?(Yajl)
+# warn "the ffi-yajl and yajl-ruby gems have incompatible C libyajl libs and should not be loaded in the same Ruby VM"
+# warn "falling back to ffi which might work (or might not, no promises)"
+# require 'ffi_yajl/ffi'
else
begin
require 'ffi_yajl/ext'
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'