* random.c (InitVM_Random): move Random::DEFAULT initialization
bits to Init_Random_default. * random.c (Init_Random_default): renamed from Init_Rndom2. * random.c (Init_RandomSeedCore): renamed from Init_Random. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
99c05fb38e
commit
86af9bba63
@ -1,3 +1,10 @@
|
|||||||
|
Thu Oct 22 06:33:38 2015 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* random.c (InitVM_Random): move Random::DEFAULT initialization
|
||||||
|
bits to Init_Random_default.
|
||||||
|
* random.c (Init_Random_default): renamed from Init_Rndom2.
|
||||||
|
* random.c (Init_RandomSeedCore): renamed from Init_Random.
|
||||||
|
|
||||||
Thu Oct 22 06:20:48 2015 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Thu Oct 22 06:20:48 2015 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* random.c (Init_RandomSeed): move all Random::DEFAULT
|
* random.c (Init_RandomSeed): move all Random::DEFAULT
|
||||||
|
2
inits.c
2
inits.c
@ -17,7 +17,7 @@ void
|
|||||||
rb_call_inits(void)
|
rb_call_inits(void)
|
||||||
{
|
{
|
||||||
CALL(Method);
|
CALL(Method);
|
||||||
CALL(RandomSeed);
|
CALL(RandomSeedCore);
|
||||||
CALL(sym);
|
CALL(sym);
|
||||||
CALL(var_tables);
|
CALL(var_tables);
|
||||||
CALL(Object);
|
CALL(Object);
|
||||||
|
19
random.c
19
random.c
@ -1496,9 +1496,10 @@ rb_memhash(const void *ptr, long len)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize Ruby internal seeds */
|
/* Initialize Ruby internal seeds. This function is called at very early stage
|
||||||
|
* of Ruby startup. Thus, you can't use Ruby's object. */
|
||||||
void
|
void
|
||||||
Init_RandomSeed(void)
|
Init_RandomSeedCore(void)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Don't reuse this MT for Random::DEFAULT. Random::DEFAULT::seed shouldn't
|
Don't reuse this MT for Random::DEFAULT. Random::DEFAULT::seed shouldn't
|
||||||
@ -1530,14 +1531,20 @@ init_randomseed(struct MT *mt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* construct Random::DEFAULT bits */
|
/* construct Random::DEFAULT bits */
|
||||||
static void
|
static VALUE
|
||||||
Init_RandomSeed2(void)
|
Init_Random_default(void)
|
||||||
{
|
{
|
||||||
rb_random_t *r = &default_rand;
|
rb_random_t *r = &default_rand;
|
||||||
struct MT *mt = &r->mt;
|
struct MT *mt = &r->mt;
|
||||||
|
VALUE v;
|
||||||
|
|
||||||
r->seed = init_randomseed(mt);
|
r->seed = init_randomseed(mt);
|
||||||
rb_global_variable(&r->seed);
|
rb_global_variable(&r->seed);
|
||||||
|
|
||||||
|
v = TypedData_Wrap_Struct(rb_cRandom, &random_data_type, r);
|
||||||
|
rb_gc_register_mark_object(v);
|
||||||
|
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1575,7 +1582,6 @@ rb_reset_random_seed(void)
|
|||||||
void
|
void
|
||||||
InitVM_Random(void)
|
InitVM_Random(void)
|
||||||
{
|
{
|
||||||
Init_RandomSeed2();
|
|
||||||
rb_define_global_function("srand", rb_f_srand, -1);
|
rb_define_global_function("srand", rb_f_srand, -1);
|
||||||
rb_define_global_function("rand", rb_f_rand, -1);
|
rb_define_global_function("rand", rb_f_rand, -1);
|
||||||
|
|
||||||
@ -1593,9 +1599,8 @@ InitVM_Random(void)
|
|||||||
rb_define_method(rb_cRandom, "==", random_equal, 1);
|
rb_define_method(rb_cRandom, "==", random_equal, 1);
|
||||||
|
|
||||||
{
|
{
|
||||||
VALUE rand_default = TypedData_Wrap_Struct(rb_cRandom, &random_data_type, &default_rand);
|
|
||||||
rb_gc_register_mark_object(rand_default);
|
|
||||||
/* Direct access to Ruby's Pseudorandom number generator (PRNG). */
|
/* Direct access to Ruby's Pseudorandom number generator (PRNG). */
|
||||||
|
VALUE rand_default = Init_Random_default();
|
||||||
rb_define_const(rb_cRandom, "DEFAULT", rand_default);
|
rb_define_const(rb_cRandom, "DEFAULT", rand_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user