summaryrefslogtreecommitdiff
path: root/lib/ffi_yajl.rb
blob: 5edc4f6c30e30406f99e89a9ada50f94444aede1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#
# 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"
  require 'ffi_yajl/ffi'
elsif RUBY_PLATFORM == "java"
  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