Skip to content

Commit 84acb8a

Browse files
authored
Merge branch 'master' into zjit-block-params
2 parents da4fdb1 + 29c206d commit 84acb8a

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎process.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9173,6 +9173,8 @@ InitVM_process(void)
91739173

91749174
rb_gvar_ractor_local("$$");
91759175
rb_gvar_ractor_local("$?");
9176+
rb_gvar_box_ready("$$");
9177+
rb_gvar_box_ready("$?");
91769178

91779179
rb_define_global_function("exec", f_exec, -1);
91789180
rb_define_global_function("fork", rb_f_fork, 0);

‎test/ruby/test_box.rb‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,45 @@ def test_stdio_gvar_reassignment_in_box_seen_by_kernel_methods
878878
end;
879879
end
880880

881+
def test_child_status_gvar_not_cached_in_box
882+
assert_separately([ENV_ENABLE_BOX], __FILE__, __LINE__, "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
883+
begin;
884+
system(EnvUtil.rubybin, "-e", "exit 3")
885+
assert_equal 3, $?.exitstatus
886+
assert_equal Process.last_status.pid, $?.pid
887+
IO.popen([EnvUtil.rubybin, "-e", "exit 5"]) {|io| io.read}
888+
assert_equal 5, $?.exitstatus
889+
end;
890+
end
891+
892+
def test_child_status_gvar_not_cached_in_user_box
893+
assert_separately([ENV_ENABLE_BOX], __FILE__, __LINE__, "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
894+
begin;
895+
ruby = EnvUtil.rubybin.dump
896+
first, second = Ruby::Box.new.eval(<<~CODE)
897+
system(#{ruby}, "-e", "exit 3")
898+
first = $?.exitstatus
899+
system(#{ruby}, "-e", "exit 5")
900+
[first, $?.exitstatus]
901+
CODE
902+
assert_equal 3, first
903+
assert_equal 5, second
904+
end;
905+
end
906+
907+
def test_pid_gvar_not_cached_in_forked_child
908+
omit "fork is not supported" unless Process.respond_to?(:fork)
909+
assert_separately([ENV_ENABLE_BOX], __FILE__, __LINE__, "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
910+
begin;
911+
_parent_pid = $$
912+
r, w = IO.pipe
913+
pid = fork { r.close; w.puts($$ == Process.pid); exit!(true) }
914+
w.close
915+
Process.wait(pid)
916+
assert_equal "true", r.read.chomp
917+
end;
918+
end
919+
881920
def test_errinfo_isolated_between_boxes
882921
assert_separately([ENV_ENABLE_BOX], __FILE__, __LINE__, "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
883922
begin;

0 commit comments

Comments
 (0)