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

ruby-changes:66904

From: Benoit <ko1@a...>
Date: Tue, 27 Jul 2021 17:01:52 +0900 (JST)
Subject: [ruby-changes:66904] 090d799c24 (master): [ruby/uri] Revert "Fix to support Ruby 3.0 Ractor"

https://git.ruby-lang.org/ruby.git/commit/?id=090d799c24

From 090d799c2496f4c0e1f25c9970f4015fc693ff0e Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Fri, 25 Jun 2021 13:24:56 +0200
Subject: [ruby/uri] Revert "Fix to support Ruby 3.0 Ractor"

* This reverts commit 1faa4fdc161d7aeebdb5de0c407b923beaecf898.
* It has too many problems, see https://github.com/ruby/uri/pull/22 for discussion.

https://github.com/ruby/uri/commit/b959da2dc9
---
 lib/uri.rb              |  2 +-
 lib/uri/common.rb       | 32 +++++++-------------------------
 lib/uri/file.rb         |  2 ++
 lib/uri/ftp.rb          |  1 +
 lib/uri/http.rb         |  3 +++
 lib/uri/https.rb        |  1 +
 lib/uri/ldap.rb         |  2 ++
 lib/uri/ldaps.rb        |  1 +
 lib/uri/mailto.rb       |  2 ++
 lib/uri/ws.rb           |  3 +++
 lib/uri/wss.rb          |  1 +
 test/uri/test_common.rb | 19 -------------------
 12 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/lib/uri.rb b/lib/uri.rb
index 41b6854..5e820f4 100644
--- a/lib/uri.rb
+++ b/lib/uri.rb
@@ -29,8 +29,8 @@ https://github.com/ruby/ruby/blob/trunk/lib/uri.rb#L29
 #   module URI
 #     class RSYNC < Generic
 #       DEFAULT_PORT = 873
-#       URI.refresh_scheme_list
 #     end
+#     @@schemes['RSYNC'] = RSYNC
 #   end
 #   #=> URI::RSYNC
 #
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index ab3234c..915c0e9 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -16,7 +16,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L16
   REGEXP = RFC2396_REGEXP
   Parser = RFC2396_Parser
   RFC3986_PARSER = RFC3986_Parser.new
-  Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor)
 
   # URI::Parser.new
   DEFAULT_PARSER = Parser.new
@@ -28,7 +27,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L27
   DEFAULT_PARSER.regexp.each_pair do |sym, str|
     const_set(sym, str)
   end
-  Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor)
 
   module Util # :nodoc:
     def make_components_hash(klass, array_hash)
@@ -64,30 +62,10 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L62
 
   include REGEXP
 
-  SCHEME_LIST_MUTEX = Mutex.new
-  private_constant :SCHEME_LIST_MUTEX
-
+  @@schemes = {}
   # Returns a Hash of the defined schemes.
-  # The list is lazily calculated.
   def self.scheme_list
-    return const_get(:SCHEMES) if defined?(SCHEMES)
-
-    SCHEME_LIST_MUTEX.synchronize do
-      const_set(:SCHEMES, ObjectSpace.
-        each_object(Class).
-        select { |klass| klass < URI::Generic }.
-        each_with_object({}) { |klass, acc| acc[klass.name.split('::').last.upcase] = klass }.
-        freeze)
-    end
-  end
-
-  # Re-calculate scheme list
-  def self.refresh_scheme_list
-    SCHEME_LIST_MUTEX.synchronize do
-      remove_const(:SCHEMES) if defined?(SCHEMES)
-    end
-
-    scheme_list
+    @@schemes
   end
 
   #
@@ -95,7 +73,11 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L73
   # from +URI.scheme_list+.
   #
   def self.for(scheme, *arguments, default: Generic)
-    uri_class = scheme_list[scheme.to_s.upcase] || default
+    if scheme
+      uri_class = @@schemes[scheme.upcase] || default
+    else
+      uri_class = default
+    end
 
     return uri_class.new(scheme, *arguments)
   end
diff --git a/lib/uri/file.rb b/lib/uri/file.rb
index 45a7a8b..561ec70 100644
--- a/lib/uri/file.rb
+++ b/lib/uri/file.rb
@@ -89,4 +89,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/file.rb#L89
     def set_password(v)
     end
   end
+
+  @@schemes['FILE'] = File
 end
diff --git a/lib/uri/ftp.rb b/lib/uri/ftp.rb
index ec8b6e6..fb38481 100644
--- a/lib/uri/ftp.rb
+++ b/lib/uri/ftp.rb
@@ -262,4 +262,5 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/ftp.rb#L262
       return str
     end
   end
+  @@schemes['FTP'] = FTP
 end
diff --git a/lib/uri/http.rb b/lib/uri/http.rb
index ccd09dd..70cfb2a 100644
--- a/lib/uri/http.rb
+++ b/lib/uri/http.rb
@@ -81,4 +81,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/http.rb#L81
       url.start_with?(?/.freeze) ? url : ?/ + url
     end
   end
+
+  @@schemes['HTTP'] = HTTP
+
 end
diff --git a/lib/uri/https.rb b/lib/uri/https.rb
index 98a0840..c481b1f 100644
--- a/lib/uri/https.rb
+++ b/lib/uri/https.rb
@@ -18,4 +18,5 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/https.rb#L18
     # A Default port of 443 for URI::HTTPS
     DEFAULT_PORT = 443
   end
+  @@schemes['HTTPS'] = HTTPS
 end
diff --git a/lib/uri/ldap.rb b/lib/uri/ldap.rb
index 3a0df23..14e6163 100644
--- a/lib/uri/ldap.rb
+++ b/lib/uri/ldap.rb
@@ -256,4 +256,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/ldap.rb#L256
       false
     end
   end
+
+  @@schemes['LDAP'] = LDAP
 end
diff --git a/lib/uri/ldaps.rb b/lib/uri/ldaps.rb
index fd3f7e8..227e7fa 100644
--- a/lib/uri/ldaps.rb
+++ b/lib/uri/ldaps.rb
@@ -17,4 +17,5 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/ldaps.rb#L17
     # A Default port of 636 for URI::LDAPS
     DEFAULT_PORT = 636
   end
+  @@schemes['LDAPS'] = LDAPS
 end
diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb
index 214dea8..d08c2ae 100644
--- a/lib/uri/mailto.rb
+++ b/lib/uri/mailto.rb
@@ -288,4 +288,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/mailto.rb#L288
     end
     alias to_rfc822text to_mailtext
   end
+
+  @@schemes['MAILTO'] = MailTo
 end
diff --git a/lib/uri/ws.rb b/lib/uri/ws.rb
index b846ba2..2bfee59 100644
--- a/lib/uri/ws.rb
+++ b/lib/uri/ws.rb
@@ -78,4 +78,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/ws.rb#L78
       url.start_with?(?/.freeze) ? url : ?/ + url
     end
   end
+
+  @@schemes['WS'] = WS
+
 end
diff --git a/lib/uri/wss.rb b/lib/uri/wss.rb
index 12a53c7..1cfa133 100644
--- a/lib/uri/wss.rb
+++ b/lib/uri/wss.rb
@@ -18,4 +18,5 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/wss.rb#L18
     # A Default port of 443 for URI::WSS
     DEFAULT_PORT = 443
   end
+  @@schemes['WSS'] = WSS
 end
diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb
index 311adc0..1afa35f 100644
--- a/test/uri/test_common.rb
+++ b/test/uri/test_common.rb
@@ -33,25 +33,6 @@ class TestCommon < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/uri/test_common.rb#L33
     end
   end
 
-  def test_ractor
-    return unless defined?(Ractor)
-    r = Ractor.new { URI.parse("https://ruby-lang.org/").inspect }
-    assert_equal(URI.parse("https://ruby-lang.org/").inspect, r.take)
-  end
-
-  def test_register_scheme
-    assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS"].sort, URI.scheme_list.keys.sort)
-
-    begin
-      URI::Generic.const_set :FOOBAR, Class.new(URI::Generic)
-      URI.refresh_scheme_list
-      assert_equal(["FILE", "FTP", "HTTP", "HTTPS", "LDAP", "LDAPS", "MAILTO", "WS", "FOOBAR"].sort, URI.scheme_list.keys.sort)
-    ensure
-      URI::Generic.send(:remove_const, :FOOBAR)
-      URI.refresh_scheme_list
-    end
-  end
-
   def test_regexp
     EnvUtil.suppress_warning do
       assert_instance_of Regexp, URI.regexp
-- 
cgit v1.1


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

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