ruby-changes:42923
From: nobu <ko1@a...>
Date: Sat, 14 May 2016 00:17:07 +0900 (JST)
Subject: [ruby-changes:42923] nobu:r54997 (trunk): random.c: no local copy of the seed
nobu 2016-05-14 00:16:57 +0900 (Sat, 14 May 2016) New Revision: 54997 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54997 Log: random.c: no local copy of the seed * random.c (make_seed_value): append leading-zero-guard and get rid of making a local copy of the seed. Modified files: trunk/ChangeLog trunk/random.c Index: ChangeLog =================================================================== --- ChangeLog (revision 54996) +++ ChangeLog (revision 54997) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat May 14 00:16:54 2016 Nobuyoshi Nakada <nobu@r...> + + * random.c (make_seed_value): append leading-zero-guard and get + rid of making a local copy of the seed. + Fri May 13 08:46:42 2016 cremno <cremno@m...> * NEWS: drop FreeBSD < 4 support. Index: random.c =================================================================== --- random.c (revision 54996) +++ random.c (revision 54997) @@ -567,21 +567,13 @@ fill_random_seed(uint32_t *seed, size_t https://github.com/ruby/ruby/blob/trunk/random.c#L567 } static VALUE -make_seed_value(const uint32_t *ptr) +make_seed_value(uint32_t *ptr, size_t len) { VALUE seed; - size_t len; - uint32_t buf[DEFAULT_SEED_CNT+1]; - if (ptr[DEFAULT_SEED_CNT-1] <= 1) { + if (ptr[len-1] <= 1) { /* set leading-zero-guard */ - MEMCPY(buf, ptr, uint32_t, DEFAULT_SEED_CNT); - buf[DEFAULT_SEED_CNT] = 1; - ptr = buf; - len = DEFAULT_SEED_CNT+1; - } - else { - len = DEFAULT_SEED_CNT; + ptr[len++] = 1; } seed = rb_integer_unpack(ptr, len, sizeof(uint32_t), 0, @@ -602,9 +594,9 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/random.c#L594 random_seed(void) { VALUE v; - uint32_t buf[DEFAULT_SEED_CNT]; + uint32_t buf[DEFAULT_SEED_CNT+1]; fill_random_seed(buf, DEFAULT_SEED_CNT); - v = make_seed_value(buf); + v = make_seed_value(buf, DEFAULT_SEED_CNT); explicit_bzero(buf, DEFAULT_SEED_LEN); return v; } @@ -1553,12 +1545,12 @@ Init_RandomSeedCore(void) https://github.com/ruby/ruby/blob/trunk/random.c#L1545 static VALUE init_randomseed(struct MT *mt) { - uint32_t initial[DEFAULT_SEED_CNT]; + uint32_t initial[DEFAULT_SEED_CNT+1]; VALUE seed; fill_random_seed(initial, DEFAULT_SEED_CNT); init_by_array(mt, initial, DEFAULT_SEED_CNT); - seed = make_seed_value(initial); + seed = make_seed_value(initial, DEFAULT_SEED_CNT); explicit_bzero(initial, DEFAULT_SEED_LEN); return seed; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/