Skip to content

Commit 86af9bb

Browse files
author
kosaki
committed
* 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
1 parent 99c05fb commit 86af9bb

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Thu Oct 22 06:33:38 2015 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
2+
3+
* random.c (InitVM_Random): move Random::DEFAULT initialization
4+
bits to Init_Random_default.
5+
* random.c (Init_Random_default): renamed from Init_Rndom2.
6+
* random.c (Init_RandomSeedCore): renamed from Init_Random.
7+
18
Thu Oct 22 06:20:48 2015 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
29

310
* random.c (Init_RandomSeed): move all Random::DEFAULT

inits.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void
1717
rb_call_inits(void)
1818
{
1919
CALL(Method);
20-
CALL(RandomSeed);
20+
CALL(RandomSeedCore);
2121
CALL(sym);
2222
CALL(var_tables);
2323
CALL(Object);

random.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,10 @@ rb_memhash(const void *ptr, long len)
14961496
#endif
14971497
}
14981498

1499-
/* Initialize Ruby internal seeds */
1499+
/* Initialize Ruby internal seeds. This function is called at very early stage
1500+
* of Ruby startup. Thus, you can't use Ruby's object. */
15001501
void
1501-
Init_RandomSeed(void)
1502+
Init_RandomSeedCore(void)
15021503
{
15031504
/*
15041505
Don't reuse this MT for Random::DEFAULT. Random::DEFAULT::seed shouldn't
@@ -1530,14 +1531,20 @@ init_randomseed(struct MT *mt)
15301531
}
15311532

15321533
/* construct Random::DEFAULT bits */
1533-
static void
1534-
Init_RandomSeed2(void)
1534+
static VALUE
1535+
Init_Random_default(void)
15351536
{
15361537
rb_random_t *r = &default_rand;
15371538
struct MT *mt = &r->mt;
1539+
VALUE v;
15381540

15391541
r->seed = init_randomseed(mt);
15401542
rb_global_variable(&r->seed);
1543+
1544+
v = TypedData_Wrap_Struct(rb_cRandom, &random_data_type, r);
1545+
rb_gc_register_mark_object(v);
1546+
1547+
return v;
15411548
}
15421549

15431550
void
@@ -1575,7 +1582,6 @@ rb_reset_random_seed(void)
15751582
void
15761583
InitVM_Random(void)
15771584
{
1578-
Init_RandomSeed2();
15791585
rb_define_global_function("srand", rb_f_srand, -1);
15801586
rb_define_global_function("rand", rb_f_rand, -1);
15811587

@@ -1593,9 +1599,8 @@ InitVM_Random(void)
15931599
rb_define_method(rb_cRandom, "==", random_equal, 1);
15941600

15951601
{
1596-
VALUE rand_default = TypedData_Wrap_Struct(rb_cRandom, &random_data_type, &default_rand);
1597-
rb_gc_register_mark_object(rand_default);
15981602
/* Direct access to Ruby's Pseudorandom number generator (PRNG). */
1603+
VALUE rand_default = Init_Random_default();
15991604
rb_define_const(rb_cRandom, "DEFAULT", rand_default);
16001605
}
16011606

0 commit comments

Comments
 (0)