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

ruby-changes:69365

From: Sutou <ko1@a...>
Date: Sun, 24 Oct 2021 05:57:54 +0900 (JST)
Subject: [ruby-changes:69365] 39ecdabe67 (master): [ruby/csv] Resolve CSV::Converters and HeaderConverters lazy

https://git.ruby-lang.org/ruby.git/commit/?id=39ecdabe67

From 39ecdabe67d1bc7c864ada6f282590dbc9d3a14e Mon Sep 17 00:00:00 2001
From: Sutou Kouhei <kou@c...>
Date: Wed, 15 Sep 2021 15:58:57 +0900
Subject: [ruby/csv] Resolve CSV::Converters and HeaderConverters lazy

It's for Ractor. If you want to use the built-in converters, you
should call Ractor.make_shareable(CSV::Converters) and/or
Ractor.make_shareable(CSV::HeaderConverters).

https://github.com/ruby/csv/commit/b0b1325d6b
---
 lib/csv.rb                  | 4 ++--
 lib/csv/fields_converter.rb | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/csv.rb b/lib/csv.rb
index 7f1b404b2a..3881ba24c2 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -2575,7 +2575,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L2575
 
   def build_parser_fields_converter
     specific_options = {
-      builtin_converters: Converters,
+      builtin_converters_name: :Converters,
     }
     options = @base_fields_converter_options.merge(specific_options)
     build_fields_converter(@initial_converters, options)
@@ -2587,7 +2587,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L2587
 
   def build_header_fields_converter
     specific_options = {
-      builtin_converters: HeaderConverters,
+      builtin_converters_name: :HeaderConverters,
       accept_nil: true,
     }
     options = @base_fields_converter_options.merge(specific_options)
diff --git a/lib/csv/fields_converter.rb b/lib/csv/fields_converter.rb
index 178ffb37bc..b206118d99 100644
--- a/lib/csv/fields_converter.rb
+++ b/lib/csv/fields_converter.rb
@@ -16,7 +16,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv/fields_converter.rb#L16
       @empty_value = options[:empty_value]
       @empty_value_is_empty_string = (@empty_value == "")
       @accept_nil = options[:accept_nil]
-      @builtin_converters = options[:builtin_converters]
+      @builtin_converters_name = options[:builtin_converters_name]
       @need_static_convert = need_static_convert?
     end
 
@@ -24,7 +24,7 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv/fields_converter.rb#L24
       if name.nil?  # custom converter
         @converters << converter
       else          # named converter
-        combo = @builtin_converters[name]
+        combo = builtin_converters[name]
         case combo
         when Array  # combo converter
           combo.each do |sub_name|
@@ -80,5 +80,9 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv/fields_converter.rb#L80
       @need_static_convert or
         (not @converters.empty?)
     end
+
+    def builtin_converters
+      @builtin_converters ||= ::CSV.const_get(@builtin_converters_name)
+    end
   end
 end
-- 
cgit v1.2.1


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

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