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

ruby-changes:65288

From: Koichi <ko1@a...>
Date: Thu, 18 Feb 2021 22:35:53 +0900 (JST)
Subject: [ruby-changes:65288] 7b9476fbfa (master): Ractor.allocate should not be allowed

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

From 7b9476fbfab738d1eb01b4b4c4af9a1680513019 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 18 Feb 2021 17:59:40 +0900
Subject: Ractor.allocate should not be allowed

Ractor.allocate and Ractor#dup should not be allowed like Thread.
[Bug #17642]
---
 bootstraptest/test_ractor.rb | 18 ++++++++++++++++++
 ractor.c                     |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index f1c3197..69f3337 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -8,6 +8,24 @@ assert_equal 'Ractor', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L8
   Ractor.new{}.class
 }
 
+# Ractor.allocate is not supported
+assert_equal "[:ok, :ok]", %q{
+  rs = []
+  begin
+    Ractor.allocate
+  rescue => e
+    rs << :ok if e.message == 'allocator undefined for Ractor'
+  end
+
+  begin
+    Ractor.new{}.dup
+  rescue
+    rs << :ok if e.message == 'allocator undefined for Ractor'
+  end
+
+  rs
+}
+
 # A Ractor can have a name
 assert_equal 'test-name', %q{
   r = Ractor.new name: 'test-name' do
diff --git a/ractor.c b/ractor.c
index c5bb0af..292a33b 100644
--- a/ractor.c
+++ b/ractor.c
@@ -2088,6 +2088,8 @@ void https://github.com/ruby/ruby/blob/trunk/ractor.c#L2088
 Init_Ractor(void)
 {
     rb_cRactor = rb_define_class("Ractor", rb_cObject);
+    rb_undef_alloc_func(rb_cRactor);
+
     rb_eRactorError          = rb_define_class_under(rb_cRactor, "Error", rb_eRuntimeError);
     rb_eRactorIsolationError = rb_define_class_under(rb_cRactor, "IsolationError", rb_eRactorError);
     rb_eRactorRemoteError    = rb_define_class_under(rb_cRactor, "RemoteError", rb_eRactorError);
-- 
cgit v1.1


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

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