Skip to content

Commit eea9fd0

Browse files
authored
Fix Fiddle::Handle.new for a missing library in the FFI backend (#156)
* From ruby/reline#766 (comment)
1 parent 1f818e4 commit eea9fd0

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎lib/fiddle/ffi_backend.rb‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,11 @@ class Handle
475475
RTLD_NOW=FFI::DynamicLibrary::RTLD_NOW
476476

477477
definitialize(libname=nil,flags=RTLD_LAZY | RTLD_GLOBAL)
478-
@lib=FFI::DynamicLibrary.open(libname,flags)rescueLoadError
479-
raiseDLError.new("Could not open #{libname}")unless@lib
478+
begin
479+
@lib=FFI::DynamicLibrary.open(libname,flags)
480+
rescueLoadError,RuntimeError# LoadError for JRuby, RuntimeError for TruffleRuby
481+
raiseDLError,"Could not open #{libname}"
482+
end
480483

481484
@open=true
482485

‎test/fiddle/test_handle.rb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ module Fiddle
88
classTestHandle < TestCase
99
includeFiddle
1010

11+
deftest_library_unavailable
12+
assert_raise(DLError)do
13+
Fiddle::Handle.new("does-not-exist-library")
14+
end
15+
assert_raise(DLError)do
16+
Fiddle::Handle.new("/does/not/exist/library.#{RbConfig::CONFIG['SOEXT']}")
17+
end
18+
end
19+
1120
deftest_to_i
1221
ifffi_backend?
1322
omit("Fiddle::Handle#to_i is unavailable with FFI backend")

0 commit comments

Comments
 (0)