From 8303b4ee475f2e24ee2cb4df7b2ec737d8d366c2 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Sat, 23 Aug 2014 21:10:55 -0700 Subject: fix rbx using dlopen via FFI this means rbx uses FFI in ways that I cannot work around. --- .travis.yml | 12 +++++------- CHANGELOG.md | 1 + lib/ffi_yajl/ext.rb | 55 ++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index d96b355..709e1d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ before_install: - sudo dpkg -P libyajl1 || true - - gem update bundler +# - gem update bundler - bundle --version - - gem update --system 2.1.11 +# - gem update --system - gem --version bundler_args: --without development_extras --jobs 3 --retry 3 script: rake compile; rake spec @@ -18,7 +18,7 @@ rvm: - 1.8.7 - ruby-head - ree - - rbx-2.2 + - rbx-2.2.10 - jruby-19mode - jruby-18mode - jruby-head @@ -28,8 +28,6 @@ jdk: - openjdk6 matrix: allow_failures: - - rvm: rbx-2.2 - jdk: oraclejdk7 - rvm: ruby-head jdk: oraclejdk7 - rvm: jruby-head @@ -65,9 +63,9 @@ matrix: jdk: openjdk6 - rvm: 1.8.7 jdk: openjdk7 - - rvm: rbx-2.2 + - rvm: rbx-2.2.10 jdk: openjdk6 - - rvm: rbx-2.2 + - rvm: rbx-2.2.10 jdk: openjdk7 - rvm: ruby-head jdk: openjdk6 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e470ab..ad16304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Bugs fixed +* Fixed Rubinious on at least Ubuntu 14.04 and Mac * [**Lennart Brinkmann**](https://github.com/lebrinkma): remove `-Wl,--no-undefined` if ruby mkmf.rb adds it in the CFLAGS because we do not directly link against `-lyajl` diff --git a/lib/ffi_yajl/ext.rb b/lib/ffi_yajl/ext.rb index 504cbe1..1441cba 100644 --- a/lib/ffi_yajl/ext.rb +++ b/lib/ffi_yajl/ext.rb @@ -4,28 +4,62 @@ require 'ffi_yajl/encoder' require 'ffi_yajl/parser' require 'ffi' require 'libyajl2' -begin - require 'fiddle' -rescue LoadError -end module FFI_Yajl # FIXME: DRY with ffi_yajl/ffi.rb + # FIXME: extract map_library_name from FFI and stop requiring it at the top level + # so that the C-library can be installed without FFI libname = ::FFI.map_library_name("yajl") libpath = File.expand_path(File.join(Libyajl2.opt_path, libname)) libpath.gsub!(/dylib/, 'bundle') libpath = ::FFI.map_library_name("yajl") unless File.exist?(libpath) - if defined?(Fiddle) && Fiddle.respond_to?(:dlopen) - ::Fiddle.dlopen(libpath) - else - # deliberately convoluted delayed require here to avoid deprecation - # warning from requiring dl + + # + # 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 - raise "cannot find dlopen in either DL or Fiddle, cannot proceed" + 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 Config::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 vi Fiddle, DL or FFI, what am I supposed to do?" end class Parser @@ -38,4 +72,3 @@ module FFI_Yajl include FFI_Yajl::Ext::Encoder end end - -- cgit v1.2.1