This project is closed and read-only.
Backport #5661 » 0001-random.c-random_s_rand-avoid-segfault-after-fork-rub.patch
| random.c | ||
|---|---|---|
|
static VALUE
|
||
|
random_s_rand(int argc, VALUE *argv, VALUE obj)
|
||
|
{
|
||
|
rand_start(&default_rand);
|
||
|
return random_rand(argc, argv, rb_Random_DEFAULT);
|
||
|
}
|
||
| test/ruby/test_rand.rb | ||
|---|---|---|
|
rescue NotImplementedError, ArgumentError
|
||
|
end
|
||
|
def fork_check(op = nil, &block)
|
||
|
r, w = IO.pipe
|
||
|
p1 = fork { w.puts(block.call.to_s) }
|
||
|
_, st = Process.waitpid2(p1)
|
||
|
assert st.success?, st.inspect
|
||
|
r1 = r.gets
|
||
|
p2 = fork { w.puts(block.call.to_s) }
|
||
|
_, st = Process.waitpid2(p2)
|
||
|
assert st.success?, st.inspect
|
||
|
r2 = r.gets
|
||
|
# technically, it *is* possible to fail this test _very_ rarely...
|
||
|
assert_operator(r1.strip, op, r2.strip) if op
|
||
|
rescue NotImplementedError
|
||
|
ensure
|
||
|
r.close if r
|
||
|
w.close if w
|
||
|
end
|
||
|
def test_rand_reseed_on_fork
|
||
|
# Bug 5661 / [ruby-core:41209]
|
||
|
fork_check { Random.rand(4) }
|
||
|
fork_check(:!=) { Random.rand }
|
||
|
fork_check { rand(4) }
|
||
|
fork_check(:!=) { rand }
|
||
|
stable = Random.new
|
||
|
fork_check(:==) { stable.rand(4) }
|
||
|
fork_check(:==) { stable.rand }
|
||
|
end
|
||
|
def test_seed
|
||
|
bug3104 = '[ruby-core:29292]'
|
||
|
rand_1 = Random.new(-1).rand
|
||
- « Previous
- 1
- 2
- Next »