summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2022-07-17 14:06:53 +0200
committerBenoit Daloze <eregontp@gmail.com>2022-07-17 14:11:50 +0200
commitc1793083c10e3113cd2ba880757b891658084e90 (patch)
tree1982c578cfd21feee135d7a0fcf23b5b27dae93e
parent602dfb3ec8e7f6e772e8f588f90b9994724aaed6 (diff)
downloadffi-c1793083c10e3113cd2ba880757b891658084e90.tar.gz
Simplify errors to an array
* The keys are not used, and the paths are typically already part of the error message. * Makes it possible to just use a recursive call instead of retry.
-rw-r--r--lib/ffi/dynamic_library.rb11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/ffi/dynamic_library.rb b/lib/ffi/dynamic_library.rb
index 5b2ec31..a5469c4 100644
--- a/lib/ffi/dynamic_library.rb
+++ b/lib/ffi/dynamic_library.rb
@@ -45,7 +45,7 @@ module FFI
libnames = (name.is_a?(::Array) ? name : [name])
libnames = libnames.map(&:to_s).map { |n| [n, FFI.map_library_name(n)].uniq }.flatten.compact
- errors = {}
+ errors = []
libnames.each do |libname|
lib = try_load(libname, flags, errors)
@@ -62,13 +62,12 @@ module FFI
end
end
- raise LoadError, [*errors.values, SEARCH_PATH_MESSAGE].join(".\n")
+ raise LoadError, [*errors, SEARCH_PATH_MESSAGE].join(".\n")
end
end
private_class_method :load_library
def self.try_load(libname, flags, errors)
- orig = libname
begin
lib = FFI::DynamicLibrary.open(libname, flags)
return lib if lib
@@ -77,13 +76,11 @@ module FFI
rescue LoadError, RuntimeError => ex
if ex.message =~ /(([^ \t()])+\.so([^ \t:()])*):([ \t])*(invalid ELF header|file too short|invalid file format)/
if File.binread($1) =~ /(?:GROUP|INPUT) *\( *([^ \)]+)/
- libname = $1
- retry
+ return try_load($1, flags, errors)
end
end
- libr = (orig == libname ? orig : "#{orig} #{libname}")
- errors[libr] = ex
+ errors << ex
nil
end
end