mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
random.c: ensure initialized
* random.c (get_rnd, try_get_rnd): ensure initialized to get rid of crash in forked processes. [ruby-core:82100] [Bug #13753] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
77f1277e1d
commit
a14cb8ad5b
2 changed files with 6 additions and 2 deletions
4
random.c
4
random.c
|
@ -338,7 +338,7 @@ get_rnd(VALUE obj)
|
|||
{
|
||||
rb_random_t *ptr;
|
||||
TypedData_Get_Struct(obj, rb_random_t, &random_data_type, ptr);
|
||||
return ptr;
|
||||
return rand_start(ptr);
|
||||
}
|
||||
|
||||
static rb_random_t *
|
||||
|
@ -348,7 +348,7 @@ try_get_rnd(VALUE obj)
|
|||
return rand_start(&default_rand);
|
||||
}
|
||||
if (!rb_typeddata_is_kind_of(obj, &random_data_type)) return NULL;
|
||||
return DATA_PTR(obj);
|
||||
return rand_start(DATA_PTR(obj));
|
||||
}
|
||||
|
||||
/* :nodoc: */
|
||||
|
|
|
@ -464,6 +464,10 @@ END
|
|||
assert_fork_status(1, bug5661) {stable.rand(4)}
|
||||
r1, r2 = *assert_fork_status(2, bug5661) {stable.rand}
|
||||
assert_equal(r1, r2, bug5661)
|
||||
|
||||
assert_fork_status(1, '[ruby-core:82100] [Bug #13753]') do
|
||||
Random::DEFAULT.rand(4)
|
||||
end
|
||||
rescue NotImplementedError
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue