Skip to content
Permalink
Browse files Browse the repository at this point in the history
Don't treat Symbol args different to Strings in ffi_lib
Symbols were sent directly to FFI::DynamicLibrary.open in the first
attempt, resulting in a TypeError, so that only the mangled library
name was actually loaded.

This moves conversion to String to the front, so that subsequent
calls can assume Strings only.
  • Loading branch information
larskanis committed Jun 1, 2018
1 parent 9826399 commit e0fe486
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/ffi/library.rb
Expand Up @@ -43,7 +43,6 @@ module FFI
# FFI.map_library_name 'jpeg' # -> "jpeg.dll"
def self.map_library_name(lib)
# Mangle the library name to reflect the native library naming conventions
lib = lib.to_s unless lib.kind_of?(String)
lib = Library::LIBC if lib == 'c'

if lib && File.basename(lib) == lib
Expand Down Expand Up @@ -103,7 +102,7 @@ def ffi_lib(*names)
FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL)

else
libnames = (name.is_a?(::Array) ? name : [ name ]).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
libnames = (name.is_a?(::Array) ? name : [ name ]).map(&:to_s).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
lib = nil
errors = {}

Expand All @@ -126,7 +125,6 @@ def ffi_lib(*names)
retry
else
# TODO better library lookup logic
libname = libname.to_s
unless libname.start_with?("/")
path = ['/usr/lib/','/usr/local/lib/'].find do |pth|
File.exist?(pth + libname)
Expand Down

1 comment on commit e0fe486

@Cbeg-76
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gem install ffi

Please sign in to comment.