summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/date/date_core.c5
-rw-r--r--test/date/test_date_ractor.rb27
2 files changed, 31 insertions, 1 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index c6bceb1354..38deba6034 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 = {
"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)
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 0000000000..7b0c3f4911
--- /dev/null
+++ b/test/date/test_date_ractor.rb
@@ -0,0 +1,27 @@
+# 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