From 45a0b83ffdae6465767bd11973b3959ba1f36436 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 2 Sep 2022 12:12:10 +0200 Subject: [PATCH 1/3] Unexeclude passing Fiddle test --- test/mri/excludes/TestFiddle.rb | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test/mri/excludes/TestFiddle.rb diff --git a/test/mri/excludes/TestFiddle.rb b/test/mri/excludes/TestFiddle.rb deleted file mode 100644 index 6fbaa35b2ba8..000000000000 --- a/test/mri/excludes/TestFiddle.rb +++ /dev/null @@ -1 +0,0 @@ -exclude :test_windows_constant, "needs investigation" From 7b23568ce67852fbe23aeeee73f35409dacef8b9 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 2 Sep 2022 12:45:48 +0200 Subject: [PATCH 2/3] Fix check in spec_helper.rb to work even with --unguarded --- spec/ruby/spec_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/ruby/spec_helper.rb b/spec/ruby/spec_helper.rb index f92d316c2a1d..3404521c032a 100644 --- a/spec/ruby/spec_helper.rb +++ b/spec/ruby/spec_helper.rb @@ -27,7 +27,8 @@ def report_on_exception=(value) end end -ruby_version_is ""..."2.7" do +# Compare with SpecVersion directly here so it works even with --unguarded +if VersionGuard::FULL_RUBY_VERSION < SpecVersion.new('2.7') abort "This version of ruby/spec requires Ruby 2.7+" end From 3fd4d3a10a53ab0cf2eae9826c0589531d1d850c Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 2 Sep 2022 13:01:48 +0200 Subject: [PATCH 3/3] Add spec and fix exception for Fiddle::Handle.new with a missing library * Fixes https://github.com/oracle/truffleruby/issues/2714 --- CHANGELOG.md | 1 + lib/truffle/truffle/fiddle_backend.rb | 7 ++++--- spec/ruby/library/fiddle/handle/initialize_spec.rb | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 spec/ruby/library/fiddle/handle/initialize_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index e2559fdb4ff6..60067596489e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Compatibility: * Implement `rb_eval_cmd_kw` to support the `tk` gem (#2556, @aardvark179). * Fix `rb_class2name` to call `inspect` on anonymous classes like in CRuby (#2701, @aardvark179). * Implement `rb_ivar_foreach` to iterate over instance and class variables like in CRuby (#2701, @aardvark179). +* Fix exception for `Fiddle::Handle.new` with a missing library (#2714, @eregon). Performance: diff --git a/lib/truffle/truffle/fiddle_backend.rb b/lib/truffle/truffle/fiddle_backend.rb index 4bd5aebaa394..a577b4ee3e54 100644 --- a/lib/truffle/truffle/fiddle_backend.rb +++ b/lib/truffle/truffle/fiddle_backend.rb @@ -253,15 +253,16 @@ def self.[](*args) RTLD_GLOBAL = Truffle::Config['platform.dlopen.RTLD_GLOBAL'] def initialize(library = nil, flags = RTLD_LAZY | RTLD_GLOBAL) - raise DLError, 'unsupported dlopen flags' if flags != RTLD_LAZY | RTLD_GLOBAL + raise DLError, 'unsupported dlopen flags' if flags != (RTLD_LAZY | RTLD_GLOBAL) + if library == Truffle::FiddleBackend::RTLD_NEXT @handle = :rtld_next else library = nil if library == Truffle::FiddleBackend::RTLD_DEFAULT begin @handle = Primitive.interop_eval_nfi(library ? "load '#{library}'" : 'default') - rescue RuntimeError - raise DLError, "#{library}: cannot open shared object file: No such file or directory" + rescue Polyglot::ForeignException => e + raise DLError, "#{e.message}" end end end diff --git a/spec/ruby/library/fiddle/handle/initialize_spec.rb b/spec/ruby/library/fiddle/handle/initialize_spec.rb new file mode 100644 index 000000000000..51c2470efdf3 --- /dev/null +++ b/spec/ruby/library/fiddle/handle/initialize_spec.rb @@ -0,0 +1,10 @@ +require_relative '../../../spec_helper' +require 'fiddle' + +describe "Fiddle::Handle#initialize" do + it "raises Fiddle::DLError if the library cannot be found" do + -> { + Fiddle::Handle.new("doesnotexist.doesnotexist") + }.should raise_error(Fiddle::DLError) + end +end