Skip to content

Commit 019bd86

Browse files
committed
Add Ractor support
1 parent 49440b8 commit 019bd86

5 files changed

Lines changed: 14 additions & 2 deletions

File tree

ext/numo/narray/gen/tmpl/alloc_func.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static const rb_data_type_t <%=type_name%>_data_type = {
8787
{0, <%=type_name%>_free, <%=type_name%>_memsize,},
8888
&na_data_type,
8989
&<%=type_name%>_info,
90-
0, // flags
90+
RUBY_TYPED_FROZEN_SHAREABLE, // flags
9191
};
9292

9393
<% end %>

ext/numo/narray/gen/tmpl/init_class.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
rb_hash_aset(hCast, rb_cArray, cT);
1515
<% for x in upcast %>
1616
<%= x %><% end %>
17+
rb_obj_freeze(hCast);
1718

1819
<% @children.each do |m| %>
1920
<%= m.init_def %><% end %>

ext/numo/narray/narray.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,10 @@ na_equal(VALUE self, volatile VALUE other)
19891989
void
19901990
Init_narray()
19911991
{
1992+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
1993+
rb_ext_ractor_safe(true);
1994+
#endif
1995+
19921996
mNumo = rb_define_module("Numo");
19931997

19941998
/*

ext/numo/narray/numo/narray.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ typedef unsigned int BIT_DIGIT;
450450
#include "numo/ndloop.h"
451451
#include "numo/intern.h"
452452

453+
// for Ractor support code
454+
#ifndef HAVE_RB_EXT_RACTOR_SAFE
455+
# undef RUBY_TYPED_FROZEN_SHAREABLE
456+
# define RUBY_TYPED_FROZEN_SHAREABLE 0
457+
#endif
458+
453459
#if defined(__cplusplus)
454460
#if 0
455461
{ /* satisfy cc-mode */

test/ractor_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def test_frozen(data)
2424
[ary2, ary2 * 10]
2525
end
2626
ary2, res = r.take
27-
assert_same(ary1, ary2)
27+
assert_equal((dtype != Numo::RObject),
28+
ary1.equal?(ary2))
2829
assert_equal(ary1*10, res)
2930
end
3031

0 commit comments

Comments
 (0)