[前][次][番号順一覧][スレッド一覧]

ruby-changes:68410

From: Akinori <ko1@a...>
Date: Tue, 12 Oct 2021 21:11:32 +0900 (JST)
Subject: [ruby-changes:68410] 58ae1efb49 (master): [ruby/digest] Avoid the constant redefinition warning

https://git.ruby-lang.org/ruby.git/commit/?id=58ae1efb49

From 58ae1efb49e2ba10960a62b4f4e1c01811b71e59 Mon Sep 17 00:00:00 2001
From: Akinori MUSHA <knu@i...>
Date: Fri, 1 Oct 2021 11:07:19 +0900
Subject: [ruby/digest] Avoid the constant redefinition warning

The gem and bundle commands first load digest via openssl, so loading
the digest gem would cause this warning every time one of these
commands is run:

```
.../lib/ruby/gems/3.0.0/gems/digest-3.1.0/lib/digest.rb:11: warning: already initialized constant Digest::REQUIRE_MUTEX
.../lib/ruby/3.0.0/digest.rb:7: warning: previous definition of REQUIRE_MUTEX was here
```

https://github.com/ruby/digest/commit/16172612d5
---
 lib/digest.rb | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/digest.rb b/lib/digest.rb
index b5ff067e44..7cb0d2c318 100644
--- a/lib/digest.rb
+++ b/lib/digest.rb
@@ -1,10 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/lib/digest.rb#L1
 # frozen_string_literal: false
 
+# The gem and bundle commands (except for bundle exec) first load
+# digest via openssl and then load gems, so if this is installed via
+# gem, we are overwriting the default version of digest.  Beware not
+# to break it or cause redefinition warnings.
+#
+# When we introduce incompatible changes and overwriting is not an
+# option, and given that the default version does not have security
+# defects, we may just give up and let those commands just use the
+# default version of digest.
+#
+# return if defined?(Digest) && caller_locations.any? { |l|
+#   %r{/(rubygems/gem_runner|bundler/cli)\.rb}.match?(l.path)
+# }
+
 require 'digest/loader'
 
 module Digest
   # A mutex for Digest().
-  REQUIRE_MUTEX = Thread::Mutex.new
+  REQUIRE_MUTEX ||= Thread::Mutex.new
 
   def self.const_missing(name) # :nodoc:
     case name
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]