ruby-changes:40737
From: kosaki <ko1@a...>
Date: Tue, 1 Dec 2015 05:32:55 +0900 (JST)
Subject: [ruby-changes:40737] kosaki:r52816 (trunk): * random.c (InitVM_Random): move Random::DEFAULT initialization
kosaki 2015-12-01 05:32:42 +0900 (Tue, 01 Dec 2015) New Revision: 52816 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52816 Log: * 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. Modified files: trunk/ChangeLog trunk/inits.c trunk/random.c Index: ChangeLog =================================================================== --- ChangeLog (revision 52815) +++ ChangeLog (revision 52816) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Oct 22 06:33:38 2015 KOSAKI Motohiro <kosaki.motohiro@g...> + + * 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@g...> * random.c (Init_RandomSeed): move all Random::DEFAULT Index: inits.c =================================================================== --- inits.c (revision 52815) +++ inits.c (revision 52816) @@ -17,7 +17,7 @@ void https://github.com/ruby/ruby/blob/trunk/inits.c#L17 rb_call_inits(void) { CALL(Method); - CALL(RandomSeed); + CALL(RandomSeedCore); CALL(sym); CALL(var_tables); CALL(Object); Index: random.c =================================================================== --- random.c (revision 52815) +++ random.c (revision 52816) @@ -1496,9 +1496,10 @@ rb_memhash(const void *ptr, long len) https://github.com/ruby/ruby/blob/trunk/random.c#L1496 #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 -Init_RandomSeed(void) +Init_RandomSeedCore(void) { /* Don't reuse this MT for Random::DEFAULT. Random::DEFAULT::seed shouldn't @@ -1530,14 +1531,20 @@ init_randomseed(struct MT *mt) https://github.com/ruby/ruby/blob/trunk/random.c#L1531 } /* construct Random::DEFAULT bits */ -static void -Init_RandomSeed2(void) +static VALUE +Init_Random_default(void) { rb_random_t *r = &default_rand; struct MT *mt = &r->mt; + VALUE v; r->seed = init_randomseed(mt); rb_global_variable(&r->seed); + + v = TypedData_Wrap_Struct(rb_cRandom, &random_data_type, r); + rb_gc_register_mark_object(v); + + return v; } void @@ -1575,7 +1582,6 @@ rb_reset_random_seed(void) https://github.com/ruby/ruby/blob/trunk/random.c#L1582 void InitVM_Random(void) { - Init_RandomSeed2(); rb_define_global_function("srand", rb_f_srand, -1); rb_define_global_function("rand", rb_f_rand, -1); @@ -1593,9 +1599,8 @@ InitVM_Random(void) https://github.com/ruby/ruby/blob/trunk/random.c#L1599 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). */ + VALUE rand_default = Init_Random_default(); rb_define_const(rb_cRandom, "DEFAULT", rand_default); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/