From cf28431816435e33e8ef190a17a53295584f2a7c Mon Sep 17 00:00:00 2001 From: Petr Chalupa Date: Tue, 6 Nov 2018 08:02:33 +0100 Subject: [PATCH] Defensive 1.9.3 support --- Rakefile | 10 +++++++++- lib/concurrent.rb | 2 -- lib/concurrent/utility/193.rb | 17 ----------------- .../utility/native_extension_loader.rb | 10 +++++++++- 4 files changed, 18 insertions(+), 21 deletions(-) delete mode 100644 lib/concurrent/utility/193.rb diff --git a/Rakefile b/Rakefile index 51e39f5cf..b6827341d 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,15 @@ require_relative 'lib/concurrent/version' require_relative 'lib/concurrent/utility/engine' -require_relative 'lib/concurrent/utility/193' + +if Concurrent.ruby_version :<, 2, 0, 0 + # @!visibility private + module Kernel + def __dir__ + File.dirname __FILE__ + end + end +end core_gemspec = Gem::Specification.load File.join(__dir__, 'concurrent-ruby.gemspec') ext_gemspec = Gem::Specification.load File.join(__dir__, 'concurrent-ruby-ext.gemspec') diff --git a/lib/concurrent.rb b/lib/concurrent.rb index d26dd8e0e..87de46f1b 100644 --- a/lib/concurrent.rb +++ b/lib/concurrent.rb @@ -1,5 +1,3 @@ -require 'concurrent/utility/193' - require 'concurrent/version' require 'concurrent/constants' require 'concurrent/errors' diff --git a/lib/concurrent/utility/193.rb b/lib/concurrent/utility/193.rb deleted file mode 100644 index 319dfc924..000000000 --- a/lib/concurrent/utility/193.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative 'engine' - -if Concurrent.ruby_version :<, 2, 0, 0 - # @!visibility private - module Kernel - def __dir__ - File.dirname __FILE__ - end - end - - # @!visibility private - class LoadError < ScriptError - def path - message.split(' -- ').last - end - end -end diff --git a/lib/concurrent/utility/native_extension_loader.rb b/lib/concurrent/utility/native_extension_loader.rb index 2a0e9e609..a944bd729 100644 --- a/lib/concurrent/utility/native_extension_loader.rb +++ b/lib/concurrent/utility/native_extension_loader.rb @@ -42,6 +42,14 @@ def load_native_extensions private + def load_error_path(error) + if error.respond_to? :path + error.path + else + error.message.split(' -- ').last + end + end + def set_c_extensions_loaded @c_extensions_loaded = true end @@ -54,7 +62,7 @@ def try_load_c_extension(path) require path set_c_extensions_loaded rescue LoadError => e - if e.path == path + if load_error_path(e) == path # move on with pure-Ruby implementations # TODO (pitr-ch 12-Jul-2018): warning on verbose? else