diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-11-22 12:59:53 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-11-22 12:59:53 -0800 |
commit | 8af9a318340e34d083f26b9c7a253e570d9b930e (patch) | |
tree | 2e9d02a2a0133d60ff1f3c528cfdf7137ca46379 /lib | |
parent | 0c739b27dae2319271d576669e807d3da8e11dcf (diff) | |
parent | bc11758c3c5477ef000794410286ab5a39d624d9 (diff) | |
download | ffi-yajl-8af9a318340e34d083f26b9c7a253e570d9b930e.tar.gz |
Merge pull request #29 from opscode/lcg/better-ext-vs-ffi-logic
add better ext-vs-ffi logic
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ffi_yajl.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/ffi_yajl.rb b/lib/ffi_yajl.rb index ce099e0..7f39189 100644 --- a/lib/ffi_yajl.rb +++ b/lib/ffi_yajl.rb @@ -1,13 +1,33 @@ +# +# Precedence: +# +# - The FORCE_FFI_YAJL env var takes precedence over everything else, the user +# theoretically knows best +# - Java always gets ffi because jruby only supports ffi +# - There is a conflict between loading libyajl 1.x and 2.x in the same VM +# process (on a fundamental basis, simply guru medidate about how the +# c-symbols work if you load both libs). For some reason the ffi interface +# seems to work fine sometimes (i'm not sure how) so we fall back to that-- +# this is much more likely to be converted into a raise than to have the warn +# dropped, so don't bother asking for that. +# - Then we try the c-ext and rescue into ffi that fails +# if ENV['FORCE_FFI_YAJL'] == "ext" require 'ffi_yajl/ext' -elsif ENV['FORCE_FFI_YAJL'] == "ffi" || defined?(Yajl) - # - c-extension segfaults on ruby 1.8.7 +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' else begin require 'ffi_yajl/ext' rescue LoadError + warn "failed to load the ffi-yajl c-extension, falling back to ffi interface" require 'ffi_yajl/ffi' end end |