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

ruby-changes:64455

From: Marc-Andre <ko1@a...>
Date: Tue, 22 Dec 2020 17:13:15 +0900 (JST)
Subject: [ruby-changes:64455] f2f00e24fa (master): [ruby/date] Make Ractor-compatible

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

From f2f00e24fa14b8114d6c3bea11170b2b3e309719 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune <github@m...>
Date: Sat, 19 Dec 2020 22:29:16 -0500
Subject: [ruby/date] Make Ractor-compatible


diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index c6bceb1..38deba6 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -2977,7 +2977,7 @@ static const rb_data_type_t d_lite_type = { https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L2977
     "Date",
     {d_lite_gc_mark, RUBY_TYPED_DEFAULT_FREE, d_lite_memsize,},
     0, 0,
-    RUBY_TYPED_FREE_IMMEDIATELY|RUBY_TYPED_WB_PROTECTED,
+    RUBY_TYPED_FREE_IMMEDIATELY|RUBY_TYPED_WB_PROTECTED|RUBY_TYPED_FROZEN_SHAREABLE,
 };
 
 inline static VALUE
@@ -9118,6 +9118,9 @@ d_lite_zero(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L9118
 void
 Init_date_core(void)
 {
+    #ifdef HAVE_RB_EXT_RACTOR_SAFE
+	RB_EXT_RACTOR_SAFE(true);
+    #endif
     id_cmp = rb_intern_const("<=>");
     id_le_p = rb_intern_const("<=");
     id_ge_p = rb_intern_const(">=");
diff --git a/test/date/test_date_ractor.rb b/test/date/test_date_ractor.rb
new file mode 100644
index 0000000..7b0c3f4
--- /dev/null
+++ b/test/date/test_date_ractor.rb
@@ -0,0 +1,27 @@ https://github.com/ruby/ruby/blob/trunk/test/date/test_date_ractor.rb#L1
+# frozen_string_literal: true
+require 'test/unit'
+require 'date'
+
+class TestDateParse < Test::Unit::TestCase
+  def code(klass = Date, share: false)
+    <<~RUBY.gsub('Date', klass.name)
+      share = #{share}
+      d = Date.parse('Aug 23:55')
+      Ractor.make_shareable(d) if share
+      d2, d3 = Ractor.new(d) { |d| [d, Date.parse(d.to_s)] }.take
+      if share
+        assert_same d, d2
+      else
+        assert_equal d, d2
+      end
+      assert_equal d, d3
+    RUBY
+  end
+
+  def test_date_ractor
+    assert_ractor(code                       , require: 'date')
+    assert_ractor(code(          share: true), require: 'date')
+    assert_ractor(code(DateTime             ), require: 'date')
+    assert_ractor(code(DateTime, share: true), require: 'date')
+  end
+end
-- 
cgit v0.10.2


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

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