diff options
author | matt wrock <matt@mattwrock.com> | 2016-07-05 21:44:11 -0700 |
---|---|---|
committer | matt wrock <matt@mattwrock.com> | 2016-07-05 21:44:11 -0700 |
commit | cfc22902f01875fc7261bdab14677ee6865a891a (patch) | |
tree | 6b8b32e44884870e4d6fe2f7ebc9d6bd8de12ca7 | |
parent | f73c2e843f7eea39a0a2a49ffc19560ccb1ee029 (diff) | |
download | ffi-cfc22902f01875fc7261bdab14677ee6865a891a.tar.gz |
fix library loading by symblo
-rw-r--r-- | lib/ffi/library.rb | 3 | ||||
-rw-r--r-- | spec/ffi/library_spec.rb | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/ffi/library.rb b/lib/ffi/library.rb index 85406c1..a88e6f1 100644 --- a/lib/ffi/library.rb +++ b/lib/ffi/library.rb @@ -123,7 +123,8 @@ module FFI end # TODO better library lookup logic - unless libname.to_s.start_with?("/") + libname = libname.to_s + unless libname.start_with?("/") path = ['/usr/lib/','/usr/local/lib/'].find do |pth| File.exist?(pth + libname) end diff --git a/spec/ffi/library_spec.rb b/spec/ffi/library_spec.rb index 4359b93..c4900d3 100644 --- a/spec/ffi/library_spec.rb +++ b/spec/ffi/library_spec.rb @@ -96,6 +96,16 @@ describe "Library" do }.not_to raise_error end + it "loads library using symbol" do + expect { + expect(Module.new do |m| + m.extend FFI::Library + ffi_lib :c + attach_function :getpid, [ ], :uint + end.getpid).to eq(Process.pid) + }.not_to raise_error + end + it "attach_function :getpid from [ 'c', 'libc.so.6'] " do expect { expect(Module.new do |m| |