Skip to content

Commit

Permalink
Fix Fiddle::Handle.new for a missing library in the FFI backend
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Oct 18, 2024
1 parent 1f818e4 commit 06f7d08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/fiddle/ffi_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,12 @@ class Handle
RTLD_NOW = FFI::DynamicLibrary::RTLD_NOW

def initialize(libname = nil, flags = RTLD_LAZY | RTLD_GLOBAL)
@lib = FFI::DynamicLibrary.open(libname, flags) rescue LoadError
raise DLError.new("Could not open #{libname}") unless @lib
@lib =
begin
FFI::DynamicLibrary.open(libname, flags)
rescue
raise DLError, "Could not open #{libname}"
end

@open = true

Expand Down
9 changes: 9 additions & 0 deletions test/fiddle/test_handle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ module Fiddle
class TestHandle < TestCase
include Fiddle

def test_library_unavailable
assert_raise(DLError) do
Fiddle::Handle.new("does-not-exist-library")
end
assert_raise(DLError) do
Fiddle::Handle.new("/does/not/exist/library.#{RbConfig::CONFIG['SOEXT']}")
end
end

def test_to_i
if ffi_backend?
omit("Fiddle::Handle#to_i is unavailable with FFI backend")
Expand Down

0 comments on commit 06f7d08

Please sign in to comment.