From 9479cd28a8ea5b073c7dd01d352e398b3bb497f5 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 13 Oct 2014 13:48:53 -0700 Subject: add better ext-vs-ffi logic plus add warnings so its obvious what is happening and spammy warns will be a good indication of bugs. --- lib/ffi_yajl.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/ffi_yajl.rb b/lib/ffi_yajl.rb index ce099e0..a3d1322 100644 --- a/lib/ffi_yajl.rb +++ b/lib/ffi_yajl.rb @@ -1,13 +1,30 @@ +# +# 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 -- cgit v1.2.1 From bc11758c3c5477ef000794410286ab5a39d624d9 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 13 Oct 2014 13:59:10 -0700 Subject: line wrap on comment --- lib/ffi_yajl.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/ffi_yajl.rb b/lib/ffi_yajl.rb index a3d1322..7f39189 100644 --- a/lib/ffi_yajl.rb +++ b/lib/ffi_yajl.rb @@ -2,12 +2,15 @@ # # Precedence: # -# - The FORCE_FFI_YAJL env var takes precedence over everything else, the user theoretically knows best +# - 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. +# - 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" -- cgit v1.2.1