summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-10-13 13:48:53 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-10-13 13:48:53 -0700
commit9479cd28a8ea5b073c7dd01d352e398b3bb497f5 (patch)
treea0ed3c84b115960c8577ee56861b2770fc002545 /lib
parentd41c232591806892ebcb78574cd81fd51b03e1d9 (diff)
downloadffi-yajl-9479cd28a8ea5b073c7dd01d352e398b3bb497f5.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/ffi_yajl.rb21
1 files changed, 19 insertions, 2 deletions
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