mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* random.c (random_s_rand): ensure default PRNG is re-initialized
after fork. patched by Eric Wong. [ruby-core:41209][Bug #5661] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
06279f0e4a
commit
b87f2fe1e4
3 changed files with 37 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Mar 12 07:03:32 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* random.c (random_s_rand): ensure default PRNG is re-initialized
|
||||||
|
after fork. patched by Eric Wong. [ruby-core:41209][Bug #5661]
|
||||||
|
|
||||||
Sun Mar 11 23:57:29 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
Sun Mar 11 23:57:29 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* pack.c (pack_unpack): when unpack('M') occurs an illegal byte
|
* pack.c (pack_unpack): when unpack('M') occurs an illegal byte
|
||||||
|
|
1
random.c
1
random.c
|
@ -1293,6 +1293,7 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj)
|
||||||
static VALUE
|
static VALUE
|
||||||
random_s_rand(int argc, VALUE *argv, VALUE obj)
|
random_s_rand(int argc, VALUE *argv, VALUE obj)
|
||||||
{
|
{
|
||||||
|
rand_start(&default_rand);
|
||||||
return random_rand(argc, argv, rb_Random_DEFAULT);
|
return random_rand(argc, argv, rb_Random_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -423,6 +423,35 @@ END
|
||||||
rescue NotImplementedError, ArgumentError
|
rescue NotImplementedError, ArgumentError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_fork_status(n, mesg, &block)
|
||||||
|
IO.pipe do |r, w|
|
||||||
|
(1..n).map do
|
||||||
|
p1 = fork {w.puts(block.call.to_s)}
|
||||||
|
_, st = Process.waitpid2(p1)
|
||||||
|
assert_send([st, :success?], mesg)
|
||||||
|
r.gets.strip
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rand_reseed_on_fork
|
||||||
|
bug5661 = '[ruby-core:41209]'
|
||||||
|
|
||||||
|
assert_fork_status(1, bug5661) {Random.rand(4)}
|
||||||
|
r1, r2 = *assert_fork_status(2, bug5661) {Random.rand}
|
||||||
|
assert_not_equal(r1, r2, bug5661)
|
||||||
|
|
||||||
|
assert_fork_status(1, bug5661) {rand(4)}
|
||||||
|
r1, r2 = *assert_fork_status(2, bug5661) {rand}
|
||||||
|
assert_not_equal(r1, r2, bug5661)
|
||||||
|
|
||||||
|
stable = Random.new
|
||||||
|
assert_fork_status(1, bug5661) {stable.rand(4)}
|
||||||
|
r1, r2 = *assert_fork_status(2, bug5661) {stable.rand}
|
||||||
|
assert_equal(r1, r2, bug5661)
|
||||||
|
rescue NotImplementedError
|
||||||
|
end
|
||||||
|
|
||||||
def test_seed
|
def test_seed
|
||||||
bug3104 = '[ruby-core:29292]'
|
bug3104 = '[ruby-core:29292]'
|
||||||
rand_1 = Random.new(-1).rand
|
rand_1 = Random.new(-1).rand
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue