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

ruby-changes:69303

From: Koichi <ko1@a...>
Date: Thu, 21 Oct 2021 16:18:04 +0900 (JST)
Subject: [ruby-changes:69303] 7185c00fcc (master): freeze (make shareable) script_lines

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

From 7185c00fcc330db8951b684f548ba3d10983bb92 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 30 Sep 2021 17:30:04 +0900
Subject: freeze (make shareable) script_lines

---
 common.mk                | 1 +
 iseq.c                   | 9 +++++++--
 test/ruby/test_rubyvm.rb | 1 +
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/common.mk b/common.mk
index c703a6da48..05c807e3d2 100644
--- a/common.mk
+++ b/common.mk
@@ -6989,6 +6989,7 @@ iseq.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h https://github.com/ruby/ruby/blob/trunk/common.mk#L6989
 iseq.$(OBJEXT): $(CCAN_DIR)/list/list.h
 iseq.$(OBJEXT): $(CCAN_DIR)/str/str.h
 iseq.$(OBJEXT): $(hdrdir)/ruby.h
+iseq.$(OBJEXT): $(hdrdir)/ruby/ractor.h
 iseq.$(OBJEXT): $(hdrdir)/ruby/ruby.h
 iseq.$(OBJEXT): $(top_srcdir)/internal/array.h
 iseq.$(OBJEXT): $(top_srcdir)/internal/bits.h
diff --git a/iseq.c b/iseq.c
index 0551e0c99a..eb65ec5f79 100644
--- a/iseq.c
+++ b/iseq.c
@@ -39,7 +39,7 @@ https://github.com/ruby/ruby/blob/trunk/iseq.c#L39
 #include "vm_core.h"
 #include "vm_callinfo.h"
 #include "yjit.h"
-
+#include "ruby/ractor.h"
 #include "builtin.h"
 #include "insns.inc"
 #include "insns_info.inc"
@@ -617,7 +617,12 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L617
     ISEQ_ORIGINAL_ISEQ_CLEAR(iseq);
     body->variable.flip_count = 0;
 
-    RB_OBJ_WRITE(iseq, &body->variable.script_lines, script_lines);
+    if (NIL_P(script_lines)) {
+        RB_OBJ_WRITE(iseq, &body->variable.script_lines, Qnil);
+    }
+    else {
+        RB_OBJ_WRITE(iseq, &body->variable.script_lines, rb_ractor_make_shareable(script_lines));
+    }
 
     ISEQ_COMPILE_DATA_ALLOC(iseq);
     RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err_info);
diff --git a/test/ruby/test_rubyvm.rb b/test/ruby/test_rubyvm.rb
index fecaacfa78..a6d0b1a727 100644
--- a/test/ruby/test_rubyvm.rb
+++ b/test/ruby/test_rubyvm.rb
@@ -49,6 +49,7 @@ class TestRubyVM < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyvm.rb#L49
     iseq.each_child{|child|
       assert_equal lines, child.script_lines
     }
+    assert lines.frozen?
 
     # don't keep
     RubyVM.keep_script_lines = false
-- 
cgit v1.2.1


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

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