[ruby/date] Make Ractor-compatible
This commit is contained in:
parent
ee102de6d7
commit
f2f00e24fa
Notes:
git
2020-12-22 17:13:19 +09:00
@ -2977,7 +2977,7 @@ static const rb_data_type_t d_lite_type = {
|
|||||||
"Date",
|
"Date",
|
||||||
{d_lite_gc_mark, RUBY_TYPED_DEFAULT_FREE, d_lite_memsize,},
|
{d_lite_gc_mark, RUBY_TYPED_DEFAULT_FREE, d_lite_memsize,},
|
||||||
0, 0,
|
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
|
inline static VALUE
|
||||||
@ -9118,6 +9118,9 @@ d_lite_zero(VALUE x)
|
|||||||
void
|
void
|
||||||
Init_date_core(void)
|
Init_date_core(void)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
||||||
|
RB_EXT_RACTOR_SAFE(true);
|
||||||
|
#endif
|
||||||
id_cmp = rb_intern_const("<=>");
|
id_cmp = rb_intern_const("<=>");
|
||||||
id_le_p = rb_intern_const("<=");
|
id_le_p = rb_intern_const("<=");
|
||||||
id_ge_p = rb_intern_const(">=");
|
id_ge_p = rb_intern_const(">=");
|
||||||
|
27
test/date/test_date_ractor.rb
Normal file
27
test/date/test_date_ractor.rb
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user