ruby-changes:47253
From: nobu <ko1@a...>
Date: Wed, 19 Jul 2017 12:17:02 +0900 (JST)
Subject: [ruby-changes:47253] nobu:r59368 (trunk): random.c: ensure initialized
nobu 2017-07-19 12:16:58 +0900 (Wed, 19 Jul 2017) New Revision: 59368 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59368 Log: random.c: ensure initialized * random.c (get_rnd, try_get_rnd): ensure initialized to get rid of crash in forked processes. [ruby-core:82100] [Bug #13753] Modified files: trunk/random.c trunk/test/ruby/test_rand.rb Index: test/ruby/test_rand.rb =================================================================== --- test/ruby/test_rand.rb (revision 59367) +++ test/ruby/test_rand.rb (revision 59368) @@ -464,6 +464,10 @@ END https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rand.rb#L464 assert_fork_status(1, bug5661) {stable.rand(4)} r1, r2 = *assert_fork_status(2, bug5661) {stable.rand} assert_equal(r1, r2, bug5661) + + assert_fork_status(1, '[ruby-core:82100] [Bug #13753]') do + Random::DEFAULT.rand(4) + end rescue NotImplementedError end Index: random.c =================================================================== --- random.c (revision 59367) +++ random.c (revision 59368) @@ -338,7 +338,7 @@ get_rnd(VALUE obj) https://github.com/ruby/ruby/blob/trunk/random.c#L338 { rb_random_t *ptr; TypedData_Get_Struct(obj, rb_random_t, &random_data_type, ptr); - return ptr; + return rand_start(ptr); } static rb_random_t * @@ -348,7 +348,7 @@ try_get_rnd(VALUE obj) https://github.com/ruby/ruby/blob/trunk/random.c#L348 return rand_start(&default_rand); } if (!rb_typeddata_is_kind_of(obj, &random_data_type)) return NULL; - return DATA_PTR(obj); + return rand_start(DATA_PTR(obj)); } /* :nodoc: */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/