[前][次][番号順一覧][スレッド一覧]

ruby-changes:29143

From: akr <ko1@a...>
Date: Sun, 9 Jun 2013 14:53:16 +0900 (JST)
Subject: [ruby-changes:29143] akr:r41195 (trunk): * bignum.c (rb_integer_pack): numwords_allocated argument removed.

akr	2013-06-09 14:53:00 +0900 (Sun, 09 Jun 2013)

  New Revision: 41195

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41195

  Log:
    * bignum.c (rb_integer_pack): numwords_allocated argument removed.
    
    * internal.h (rb_integer_pack): Follow the above change.
    
    * hash.c (rb_hash): Ditto.
    
    * time.c (v2w_bignum): Ditto.
    
    * pack.c (pack_pack): Ditto.
    
    * random.c (int_pair_to_real_inclusive): Ditto.
      (rand_init): Ditto.
      (random_load): Ditto.
      (limited_big_rand): Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/ext/-test-/bignum/pack.c
    trunk/hash.c
    trunk/internal.h
    trunk/pack.c
    trunk/random.c
    trunk/test/-ext-/bignum/test_pack.rb
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 41194)
+++ time.c	(revision 41195)
@@ -302,7 +302,7 @@ v2w_bignum(VALUE v) https://github.com/ruby/ruby/blob/trunk/time.c#L302
     int sign;
     uwideint_t u;
     wideint_t i;
-    rb_integer_pack(v, &sign, NULL, &u, 1, sizeof(i), 0,
+    rb_integer_pack(v, &sign, &u, 1, sizeof(i), 0,
         INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
     if (sign == 0)
         return WINT2FIXWV(0);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41194)
+++ ChangeLog	(revision 41195)
@@ -1,3 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun  9 14:41:05 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (rb_integer_pack): numwords_allocated argument removed.
+
+	* internal.h (rb_integer_pack): Follow the above change.
+
+	* hash.c (rb_hash): Ditto.
+
+	* time.c (v2w_bignum): Ditto.
+
+	* pack.c (pack_pack): Ditto.
+
+	* random.c (int_pair_to_real_inclusive): Ditto.
+	  (rand_init): Ditto.
+	  (random_load): Ditto.
+	  (limited_big_rand): Ditto.
+
 Sun Jun  9 09:34:44 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (big2str_base_powerof2): New function.
Index: pack.c
===================================================================
--- pack.c	(revision 41194)
+++ pack.c	(revision 41195)
@@ -1023,7 +1023,7 @@ pack_pack(VALUE ary, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/pack.c#L1023
                     numbytes = 1;
                 buf = rb_str_new(NULL, numbytes);
 
-                rb_integer_pack(from, &sign, NULL, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, INTEGER_PACK_BIG_ENDIAN);
+                rb_integer_pack(from, &sign, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, INTEGER_PACK_BIG_ENDIAN);
 
                 if (sign < 0)
                     rb_raise(rb_eArgError, "can't compress negative numbers");
Index: ext/-test-/bignum/pack.c
===================================================================
--- ext/-test-/bignum/pack.c	(revision 41194)
+++ ext/-test-/bignum/pack.c	(revision 41195)
@@ -9,14 +9,11 @@ rb_integer_pack_m(VALUE val, VALUE buf, https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/pack.c#L9
   void *ret;
   size_t wordsize = NUM2SIZET(wordsize_arg);
 
-  if (!NIL_P(buf)) {
-      StringValue(buf);
-      rb_str_modify(buf);
-      count = RSTRING_LEN(buf) / wordsize;
-  }
-
+  StringValue(buf);
+  rb_str_modify(buf);
+  count = wordsize == 0 ? 0 : RSTRING_LEN(buf) / wordsize;
   ret = rb_integer_pack(val,
-      &sign, &count, NIL_P(buf) ? NULL : RSTRING_PTR(buf), count,
+      &sign, RSTRING_PTR(buf), count,
       wordsize, NUM2SIZET(nails), NUM2INT(flags));
 
   return rb_ary_new_from_args(3, INT2NUM(sign), ret ? rb_str_new(ret, wordsize * count) : Qnil, SIZET2NUM(count));
Index: hash.c
===================================================================
--- hash.c	(revision 41194)
+++ hash.c	(revision 41195)
@@ -92,7 +92,7 @@ rb_hash(VALUE obj) https://github.com/ruby/ruby/blob/trunk/hash.c#L92
         {
             int sign;
             unsigned long ul;
-            rb_integer_pack(hval, &sign, NULL, &ul, 1, sizeof(ul), 0,
+            rb_integer_pack(hval, &sign, &ul, 1, sizeof(ul), 0,
                     INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
             ul &= (1UL << (sizeof(long)*CHAR_BIT-1)) - 1;
             if (sign < 0)
Index: internal.h
===================================================================
--- internal.h	(revision 41194)
+++ internal.h	(revision 41195)
@@ -447,7 +447,7 @@ const char *rb_objspace_data_type_name(V https://github.com/ruby/ruby/blob/trunk/internal.h#L447
 VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
 
 /* bignum.c */
-void *rb_integer_pack(VALUE val, int *signp, size_t *numwords_allocated, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
+void *rb_integer_pack(VALUE val, int *signp, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
 VALUE rb_integer_unpack(int sign, const void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
 
 /* io.c */
Index: bignum.c
===================================================================
--- bignum.c	(revision 41194)
+++ bignum.c	(revision 41195)
@@ -707,10 +707,8 @@ integer_pack_take_lowbits(int n, BDIGIT_ https://github.com/ruby/ruby/blob/trunk/bignum.c#L707
  *   0 for zero.
  *   -1 for negative without overflow.  1 for positive without overflow.
  *   -2 for negative overflow.  2 for positive overflow.
- * [numwords_allocated] the number of words allocated is returned in *numwords_allocated if it is not NULL.
- *   It is not modified if words is not NULL.
- * [words] buffer to export abs(val).  allocated by xmalloc if it is NULL.
- * [numwords] the size of given buffer as number of words (only meaningful when words is not NULL).
+ * [words] buffer to export abs(val).
+ * [numwords] the size of given buffer as number of words.
  * [wordsize] the size of word as number of bytes.
  * [nails] number of padding bits in a word.  Most significant nails bits of each word are filled by zero.
  * [flags] bitwise or of constants which name starts "INTEGER_PACK_".  It specifies word order and byte order.
@@ -720,7 +718,7 @@ integer_pack_take_lowbits(int n, BDIGIT_ https://github.com/ruby/ruby/blob/trunk/bignum.c#L718
  */
 
 void *
-rb_integer_pack(VALUE val, int *signp, size_t *numwords_allocated, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
+rb_integer_pack(VALUE val, int *signp, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
 {
     int sign;
     BDIGIT *dp;
@@ -731,7 +729,7 @@ rb_integer_pack(VALUE val, int *signp, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L729
     val = rb_to_int(val);
 
     validate_integer_pack_format(wordsize, nails, flags);
-    if (words && SIZE_MAX / wordsize < numwords)
+    if (SIZE_MAX / wordsize < numwords)
         rb_raise(rb_eArgError, "too big count * wordsize: %"PRI_SIZE_PREFIX"u * %"PRI_SIZE_PREFIX"u", numwords, wordsize);
 
     if (FIXNUM_P(val)) {
@@ -768,32 +766,8 @@ rb_integer_pack(VALUE val, int *signp, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L766
         sign = 0;
     }
 
-    if (words) {
-        buf = words;
-        bufend = buf + numwords * wordsize;
-    }
-    else {
-        /*
-         * val_numbits = (de - dp) * SIZEOF_BDIGITS * CHAR_BIT - nlz(de[-1])
-         * word_numbits = wordsize * CHAR_BIT - nails
-         * numwords = (val_numbits + word_numbits - 1) / word_numbits
-         */
-        VALUE val_numbits, word_numbits, numwordsv;
-        val_numbits = SIZET2NUM((de - dp) * SIZEOF_BDIGITS);
-        val_numbits = rb_funcall(val_numbits, '*', 1, LONG2FIX(CHAR_BIT));
-        if (dp != de)
-            val_numbits = rb_funcall(val_numbits, '-', 1, LONG2FIX(nlz(de[-1])));
-        word_numbits = SIZET2NUM(wordsize);
-        word_numbits = rb_funcall(word_numbits, '*', 1, LONG2FIX(CHAR_BIT));
-        if (nails != 0)
-            word_numbits = rb_funcall(word_numbits, '-', 1, SIZET2NUM(nails));
-        numwordsv = rb_funcall(val_numbits, '+', 1, word_numbits);
-        numwordsv = rb_funcall(numwordsv, '-', 1, LONG2FIX(1));
-        numwordsv = rb_funcall(numwordsv, rb_intern("div"), 1, word_numbits);
-        numwords = NUM2SIZET(numwordsv);
-        buf = xmalloc(numwords * wordsize);
-        bufend = buf + numwords * wordsize;
-    }
+    buf = words;
+    bufend = buf + numwords * wordsize;
 
     if (buf == bufend) {
         sign *= 2; /* overflow if non-zero*/
@@ -862,9 +836,6 @@ rb_integer_pack(VALUE val, int *signp, s https://github.com/ruby/ruby/blob/trunk/bignum.c#L836
     if (signp)
         *signp = sign;
 
-    if (!words && numwords_allocated)
-        *numwords_allocated = numwords;
-
     return buf;
 #undef FILL_DD
 #undef TAKE_LOWBITS
@@ -1705,7 +1676,7 @@ big2str_base_powerof2(VALUE x, size_t le https://github.com/ruby/ruby/blob/trunk/bignum.c#L1676
         result = rb_usascii_str_new(0, numwords);
         ptr = RSTRING_PTR(result);
     }
-    rb_integer_pack(x, NULL, NULL, ptr, numwords, 1, CHAR_BIT-word_numbits,
+    rb_integer_pack(x, NULL, ptr, numwords, 1, CHAR_BIT-word_numbits,
                     INTEGER_PACK_BIG_ENDIAN);
     while (0 < numwords) {
         *ptr = ruby_digitmap[*(unsigned char *)ptr];
Index: test/-ext-/bignum/test_pack.rb
===================================================================
--- test/-ext-/bignum/test_pack.rb	(revision 41194)
+++ test/-ext-/bignum/test_pack.rb	(revision 41195)
@@ -15,26 +15,26 @@ class TestBignum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_pack.rb#L15
     BIG_ENDIAN = Integer::INTEGER_PACK_BIG_ENDIAN
 
     def test_pack_zero
-      assert_equal([0, "", 0], 0.test_pack(nil, 1, 0, BIG_ENDIAN))
+      assert_equal([0, "", 0], 0.test_pack("", 1, 0, BIG_ENDIAN))
     end
 
     def test_pack_argument_check
-      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 0, MSBYTE_FIRST) }
-      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 0, MSWORD_FIRST) }
-      assert_raise(ArgumentError) { 0.test_pack(nil, 0, 0, BIG_ENDIAN) }
-      assert_raise(ArgumentError) { 0.test_pack(nil, 1, 8, BIG_ENDIAN) }
+      assert_raise(ArgumentError) { 0.test_pack("", 1, 0, MSBYTE_FIRST) }
+      assert_raise(ArgumentError) { 0.test_pack("", 1, 0, MSWORD_FIRST) }
+      assert_raise(ArgumentError) { 0.test_pack("", 0, 0, BIG_ENDIAN) }
+      assert_raise(ArgumentError) { 0.test_pack("", 1, 8, BIG_ENDIAN) }
 
       # assume sizeof(ssize_t) == sizeof(intptr_t)
-      assert_raise(ArgumentError) { 0.test_pack(nil, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
+      assert_raise(ArgumentError) { 0.test_pack("", 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
     end
 
     def test_pack_wordsize
-      assert_equal([1, "\x01", 1], 1.test_pack(nil, 1, 0, BIG_ENDIAN))
-      assert_equal([1, "\x00\x01", 1], 1.test_pack(nil, 2, 0, BIG_ENDIAN))
-      assert_equal([1, "\x00\x00\x01", 1], 1.test_pack(nil, 3, 0, BIG_ENDIAN))
-      assert_equal([1, "\x01", 1], 1.test_pack(nil, 1, 0, LITTLE_ENDIAN))
-      assert_equal([1, "\x01\x00", 1], 1.test_pack(nil, 2, 0, LITTLE_ENDIAN))
-      assert_equal([1, "\x01\x00\x00", 1], 1.test_pack(nil, 3, 0, LITTLE_ENDIAN))
+      assert_equal([1, "\x01", 1], 1.test_pack("x", 1, 0, BIG_ENDIAN))
+      assert_equal([1, "\x00\x01", 1], 1.test_pack("xx", 2, 0, BIG_ENDIAN))
+      assert_equal([1, "\x00\x00\x01", 1], 1.test_pack("xxx", 3, 0, BIG_ENDIAN))
+      assert_equal([1, "\x01", 1], 1.test_pack("x", 1, 0, LITTLE_ENDIAN))
+      assert_equal([1, "\x01\x00", 1], 1.test_pack("xx", 2, 0, LITTLE_ENDIAN))
+      assert_equal([1, "\x01\x00\x00", 1], 1.test_pack("xxx", 3, 0, LITTLE_ENDIAN))
     end
 
     def test_pack_fixed_buffer
@@ -51,25 +51,25 @@ class TestBignum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_pack.rb#L51
     end
 
     def test_pack_wordorder_and_endian
-      assert_equal([1, "\x12\x34\x56\x78", 2], 0x12345678.test_pack(nil, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
-      assert_equal([1, "\x34\x12\x78\x56", 2], 0x12345678.test_pack(nil, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
-      assert_equal([1, "\x56\x78\x12\x34", 2], 0x12345678.test_pack(nil, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
-      assert_equal([1, "\x78\x56\x34\x12", 2], 0x12345678.test_pack(nil, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
+      assert_equal([1, "\x12\x34\x56\x78", 2], 0x12345678.test_pack("xxxx", 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
+      assert_equal([1, "\x34\x12\x78\x56", 2], 0x12345678.test_pack("xxxx", 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
+      assert_equal([1, "\x56\x78\x12\x34", 2], 0x12345678.test_pack("xxxx", 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
+      assert_equal([1, "\x78\x56\x34\x12", 2], 0x12345678.test_pack("xxxx", 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
     end
 
     def test_pack_native_endian
-      assert_equal([1, [0x1234].pack("S!"), 1], 0x1234.test_pack(nil, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
+      assert_equal([1, [0x1234].pack("S!"), 1], 0x1234.test_pack("xx", 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
     end
 
     def test_pack_nail
-      assert_equal([1, "\x01\x00\x00\x00\x01\x01", 6], 0b100011.test_pack(nil, 1, 7, BIG_ENDIAN))
-      assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8], 0x12345678.test_pack(nil, 1, 4, BIG_ENDIAN))
-      assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4], 0x12345678.test_pack(nil, 2, 8, BIG_ENDIAN))
+      assert_equal([1, "\x01\x00\x00\x00\x01\x01", 6], 0b100011.test_pack("xxxxxx", 1, 7, BIG_ENDIAN))
+      assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8], 0x12345678.test_pack("xxxxxxxx", 1, 4, BIG_ENDIAN))
+      assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4], 0x12345678.test_pack("xxxxxxxx", 2, 8, BIG_ENDIAN))
     end
 
     def test_pack_sign
-      assert_equal([-1, "\x01", 1], (-1).test_pack(nil, 1, 0, BIG_ENDIAN))
-      assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8], (-0x8070605040302010).test_pack(nil, 1, 0, BIG_ENDIAN))
+      assert_equal([-1, "\x01", 1], (-1).test_pack("x", 1, 0, BIG_ENDIAN))
+      assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8], (-0x8070605040302010).test_pack("xxxxxxxx", 1, 0, BIG_ENDIAN))
     end
 
     def test_unpack_zero
Index: random.c
===================================================================
--- random.c	(revision 41194)
+++ random.c	(revision 41195)
@@ -295,7 +295,7 @@ int_pair_to_real_inclusive(uint32_t a, u https://github.com/ruby/ruby/blob/trunk/random.c#L295
     }
     else {
         uint32_t uary[4];
-        rb_integer_pack(x, NULL, NULL, uary, numberof(uary), sizeof(uint32_t), 0,
+        rb_integer_pack(x, NULL, uary, numberof(uary), sizeof(uint32_t), 0,
                 INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
         /* r = x >> 64 */
         r = (double)uary[0] * (0x10000 * (double)0x10000) + (double)uary[1];
@@ -380,7 +380,7 @@ rand_init(struct MT *mt, VALUE vseed) https://github.com/ruby/ruby/blob/trunk/random.c#L380
         len = MT_MAX_STATE;
     if (len > numberof(buf0))
         buf = ALLOC_N(unsigned int, len);
-    rb_integer_pack(seed, &sign, NULL, buf, len, sizeof(uint32_t), 0,
+    rb_integer_pack(seed, &sign, buf, len, sizeof(uint32_t), 0,
         INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
     if (sign < 0)
         sign = -sign;
@@ -644,7 +644,7 @@ random_load(VALUE obj, VALUE dump) https://github.com/ruby/ruby/blob/trunk/random.c#L644
       default:
 	rb_raise(rb_eArgError, "wrong dump data");
     }
-    rb_integer_pack(state, NULL, NULL, mt->state, numberof(mt->state),
+    rb_integer_pack(state, NULL, mt->state, numberof(mt->state),
         sizeof(*mt->state), 0,
         INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
     x = NUM2ULONG(left);
@@ -754,7 +754,7 @@ limited_big_rand(struct MT *mt, VALUE li https://github.com/ruby/ruby/blob/trunk/random.c#L754
     tmp = ALLOCV_N(uint32_t, vtmp, len*2);
     lim_array = tmp;
     rnd_array = tmp + len;
-    rb_integer_pack(limit, NULL, NULL, lim_array, len, sizeof(uint32_t), 0,
+    rb_integer_pack(limit, NULL, lim_array, len, sizeof(uint32_t), 0,
         INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
 
   retry:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]