summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNARUSE, Yui <naruse@airemix.jp>2021-03-13 05:12:54 +0900
committerNARUSE, Yui <naruse@airemix.jp>2021-03-13 05:12:54 +0900
commit6f9e007729d53fdbc22e37e52129ea5aa2556d0e (patch)
tree416fb1d9cd961cd9822e494e7709df557ee7d360
parent6bf32cbed8f3fd0b73b99737d671f833c594d800 (diff)
merge revision(s) b3c53a8a885be8f5cc2b712798b0d2741c488ce4: [Backport #17672]
Make Ractor stdio belonging to the Ractor [Bug #17672] Defer making ractor stdio until ractor started. Before ractor started, created objects belong to the caller ractor instead of the created ractor. --- bootstraptest/test_ractor.rb | 12 ++++++++++++ ractor.c | 9 --------- thread.c | 9 +++++++++ 3 files changed, 21 insertions(+), 9 deletions(-)
-rw-r--r--bootstraptest/test_ractor.rb12
-rw-r--r--ractor.c9
-rw-r--r--thread.c9
-rw-r--r--version.h2
4 files changed, 22 insertions, 10 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index fd698fa4d7..cbf58383c7 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -780,6 +780,18 @@ assert_equal 'ok', %q{
'ok'
}
+# $stdin,out,err belong to Ractor
+assert_equal 'ok', %q{
+ r = Ractor.new do
+ $stdin.itself
+ $stdout.itself
+ $stderr.itself
+ 'ok'
+ end
+
+ r.take
+}
+
# $DEBUG, $VERBOSE are Ractor local
assert_equal 'true', %q{
$DEBUG = true
diff --git a/ractor.c b/ractor.c
index 8de13954ce..452a2ac445 100644
--- a/ractor.c
+++ b/ractor.c
@@ -1542,11 +1542,6 @@ rb_ractor_main_setup(rb_vm_t *vm, rb_ractor_t *r, rb_thread_t *th)
rb_ractor_living_threads_insert(r, th);
}
-// io.c
-VALUE rb_io_prep_stdin(void);
-VALUE rb_io_prep_stdout(void);
-VALUE rb_io_prep_stderr(void);
-
static VALUE
ractor_create(rb_execution_context_t *ec, VALUE self, VALUE loc, VALUE name, VALUE args, VALUE block)
{
@@ -1558,10 +1553,6 @@ ractor_create(rb_execution_context_t *ec, VALUE self, VALUE loc, VALUE name, VAL
r->pub.id = ractor_next_id();
RUBY_DEBUG_LOG("r:%u", r->pub.id);
- r->r_stdin = rb_io_prep_stdin();
- r->r_stdout = rb_io_prep_stdout();
- r->r_stderr = rb_io_prep_stderr();
-
rb_ractor_t *cr = rb_ec_ractor_ptr(ec);
r->verbose = cr->verbose;
r->debug = cr->debug;
diff --git a/thread.c b/thread.c
index 1605644f83..2ee878939b 100644
--- a/thread.c
+++ b/thread.c
@@ -770,6 +770,11 @@ thread_do_start(rb_thread_t *th)
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
+// io.c
+VALUE rb_io_prep_stdin(void);
+VALUE rb_io_prep_stdout(void);
+VALUE rb_io_prep_stderr(void);
+
static int
thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
{
@@ -792,6 +797,10 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start)
RB_VM_LOCK();
{
rb_vm_ractor_blocking_cnt_dec(th->vm, th->ractor, __FILE__, __LINE__);
+ rb_ractor_t *r = th->ractor;
+ r->r_stdin = rb_io_prep_stdin();
+ r->r_stdout = rb_io_prep_stdout();
+ r->r_stderr = rb_io_prep_stderr();
}
RB_VM_UNLOCK();
}
diff --git a/version.h b/version.h
index 1ca6c45f81..3c2bc70b98 100644
--- a/version.h
+++ b/version.h
@@ -12,7 +12,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 54
+#define RUBY_PATCHLEVEL 55
#define RUBY_RELEASE_YEAR 2021
#define RUBY_RELEASE_MONTH 3