Skip to content

Commit 3fd4d3a

Browse files
committed
Add spec and fix exception for Fiddle::Handle.new with a missing library
* Fixes #2714
1 parent 7b23568 commit 3fd4d3a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Compatibility:
3333
* Implement `rb_eval_cmd_kw` to support the `tk` gem (#2556, @aardvark179).
3434
* Fix `rb_class2name` to call `inspect` on anonymous classes like in CRuby (#2701, @aardvark179).
3535
* Implement `rb_ivar_foreach` to iterate over instance and class variables like in CRuby (#2701, @aardvark179).
36+
* Fix exception for `Fiddle::Handle.new` with a missing library (#2714, @eregon).
3637

3738
Performance:
3839

lib/truffle/truffle/fiddle_backend.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,16 @@ def self.[](*args)
253253
RTLD_GLOBAL = Truffle::Config['platform.dlopen.RTLD_GLOBAL']
254254

255255
def initialize(library = nil, flags = RTLD_LAZY | RTLD_GLOBAL)
256-
raise DLError, 'unsupported dlopen flags' if flags != RTLD_LAZY | RTLD_GLOBAL
256+
raise DLError, 'unsupported dlopen flags' if flags != (RTLD_LAZY | RTLD_GLOBAL)
257+
257258
if library == Truffle::FiddleBackend::RTLD_NEXT
258259
@handle = :rtld_next
259260
else
260261
library = nil if library == Truffle::FiddleBackend::RTLD_DEFAULT
261262
begin
262263
@handle = Primitive.interop_eval_nfi(library ? "load '#{library}'" : 'default')
263-
rescue RuntimeError
264-
raise DLError, "#{library}: cannot open shared object file: No such file or directory"
264+
rescue Polyglot::ForeignException => e
265+
raise DLError, "#{e.message}"
265266
end
266267
end
267268
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require_relative '../../../spec_helper'
2+
require 'fiddle'
3+
4+
describe "Fiddle::Handle#initialize" do
5+
it "raises Fiddle::DLError if the library cannot be found" do
6+
-> {
7+
Fiddle::Handle.new("doesnotexist.doesnotexist")
8+
}.should raise_error(Fiddle::DLError)
9+
end
10+
end

0 commit comments

Comments
 (0)