summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-11 22:04:13 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-11 22:04:13 (GMT)
commit42437780d62e5ddaf0c7bb5ec320f85970b0ee42 (patch)
treee547dc2341bbb36562afdb13f74dbf7a09c22d75 /random.c
parentb87f2fe1e44acd66a30fad24bad2d21ddb01e8a2 (diff)
* random.c (Init_Random): removed rb_Random_DEFAULT and register as
mark-object instead of global variable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/random.c b/random.c
index 9405ff1..616cd68 100644
--- a/random.c
+++ b/random.c
@@ -322,7 +322,6 @@ int_pair_to_real_inclusive(unsigned int a, unsigned int b)
}
VALUE rb_cRandom;
-static VALUE rb_Random_DEFAULT;
#define id_minus '-'
#define id_plus '+'
static ID id_rand, id_bytes;
@@ -1124,6 +1123,8 @@ rand_range(struct MT* mt, VALUE range)
return v;
}
+static VALUE rand_random(int argc, VALUE *argv, rb_random_t *rnd);
+
/*
* call-seq:
* prng.rand -> float
@@ -1156,7 +1157,12 @@ rand_range(struct MT* mt, VALUE range)
static VALUE
random_rand(int argc, VALUE *argv, VALUE obj)
{
- rb_random_t *rnd = get_rnd(obj);
+ return rand_random(argc, argv, get_rnd(obj));
+}
+
+static VALUE
+rand_random(int argc, VALUE *argv, rb_random_t *rnd)
+{
VALUE vmax, v;
if (argc == 0) {
@@ -1293,8 +1299,7 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj)
static VALUE
random_s_rand(int argc, VALUE *argv, VALUE obj)
{
- rand_start(&default_rand);
- return random_rand(argc, argv, rb_Random_DEFAULT);
+ return rand_random(argc, argv, rand_start(&default_rand));
}
static st_index_t hashseed;
@@ -1404,9 +1409,11 @@ Init_Random(void)
rb_define_private_method(rb_cRandom, "left", random_left, 0);
rb_define_method(rb_cRandom, "==", random_equal, 1);
- rb_Random_DEFAULT = TypedData_Wrap_Struct(rb_cRandom, &random_data_type, &default_rand);
- rb_global_variable(&rb_Random_DEFAULT);
- rb_define_const(rb_cRandom, "DEFAULT", rb_Random_DEFAULT);
+ {
+ VALUE rand_default = TypedData_Wrap_Struct(rb_cRandom, &random_data_type, &default_rand);
+ rb_gc_register_mark_object(rand_default);
+ rb_define_const(rb_cRandom, "DEFAULT", rand_default);
+ }
rb_define_singleton_method(rb_cRandom, "srand", rb_f_srand, -1);
rb_define_singleton_method(rb_cRandom, "rand", random_s_rand, -1);