From 8bc16423cc6c5a85b0ec36575c869409a843bf28 Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 7 Jun 2013 21:01:42 +0000 Subject: [PATCH] * random.c: include internal.h. (mt_state): Use rb_integer_unpack. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ common.mk | 2 +- random.c | 21 ++++----------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99de7daf63..b1d31827de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jun 8 06:00:47 2013 Tanaka Akira + + * random.c: include internal.h. + (mt_state): Use rb_integer_unpack. + Sat Jun 8 00:55:51 2013 Tanaka Akira * bignum.c (integer_pack_loop_setup): word_num_nailbytes_ret argument diff --git a/common.mk b/common.mk index 826a77f12b..d1ba79b5c4 100644 --- a/common.mk +++ b/common.mk @@ -717,7 +717,7 @@ process.$(OBJEXT): {$(VPATH)}process.c $(RUBY_H_INCLUDES) \ $(VM_CORE_H_INCLUDES) {$(VPATH)}internal.h \ {$(VPATH)}thread.h {$(VPATH)}vm_opts.h random.$(OBJEXT): {$(VPATH)}random.c $(RUBY_H_INCLUDES) \ - {$(VPATH)}siphash.c {$(VPATH)}siphash.h + {$(VPATH)}siphash.c {$(VPATH)}siphash.h {$(VPATH)}internal.h range.$(OBJEXT): {$(VPATH)}range.c $(RUBY_H_INCLUDES) \ $(ENCODING_H_INCLUDES) {$(VPATH)}internal.h {$(VPATH)}id.h rational.$(OBJEXT): {$(VPATH)}rational.c $(RUBY_H_INCLUDES) {$(VPATH)}internal.h $(hdrdir)/ruby.h diff --git a/random.c b/random.c index 04fc32593a..4b43773cac 100644 --- a/random.c +++ b/random.c @@ -60,6 +60,7 @@ The original copyright notice follows. */ #include "ruby/ruby.h" +#include "internal.h" #include #ifdef HAVE_UNISTD_H @@ -617,23 +618,9 @@ random_copy(VALUE obj, VALUE orig) static VALUE mt_state(const struct MT *mt) { - VALUE bigo = rb_big_new(sizeof(mt->state) / sizeof(BDIGIT), 1); - BDIGIT *d = RBIGNUM_DIGITS(bigo); - int i; - - for (i = 0; i < numberof(mt->state); ++i) { - unsigned int x = mt->state[i]; -#if SIZEOF_BDIGITS < SIZEOF_INT32 - int j; - for (j = 0; j < SIZEOF_INT32 / SIZEOF_BDIGITS; ++j) { - *d++ = BIGLO(x); - x = BIGDN(x); - } -#else - *d++ = (BDIGIT)x; -#endif - } - return rb_big_norm(bigo); + return rb_integer_unpack(1, mt->state, numberof(mt->state), + sizeof(*mt->state), 0, + INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER); } /* :nodoc: */