Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/fiddle/ffi_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,11 @@ 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
begin
@lib = FFI::DynamicLibrary.open(libname, flags)
rescue LoadError, RuntimeError # LoadError for JRuby, RuntimeError for TruffleRuby
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