зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
b87f2fe1e4
Коммит
42437780d6
|
@ -1,3 +1,8 @@
|
|||
Mon Mar 12 07:04:11 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* random.c (Init_Random): removed rb_Random_DEFAULT and register as
|
||||
mark-object instead of global variable.
|
||||
|
||||
Mon Mar 12 07:03:32 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* random.c (random_s_rand): ensure default PRNG is re-initialized
|
||||
|
|
21
random.c
21
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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче