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

ruby-changes:29161

From: akr <ko1@a...>
Date: Mon, 10 Jun 2013 19:37:52 +0900 (JST)
Subject: [ruby-changes:29161] akr:r41213 (trunk): * bignum.c (rb_integer_pack): Returns sign instead of words.

akr	2013-06-10 19:37:39 +0900 (Mon, 10 Jun 2013)

  New Revision: 41213

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

  Log:
    * bignum.c (rb_integer_pack): Returns sign instead of words.
      (absint_numwords_generic): Follow the above change.
      (big2str_base_powerof2): Follow the above change.
    
    * internal.h: Ditto.
    
    * hash.c (rb_hash): Ditto.
    
    * pack.c (pack_pack): Ditto.
    
    * random.c (int_pair_to_real_inclusive): Ditto.
      (rand_init): Ditto.
      (random_load): Ditto.
      (limited_big_rand): Ditto.
    
    * time.c (v2w_bignum): 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/time.c

Index: time.c
===================================================================
--- time.c	(revision 41212)
+++ time.c	(revision 41213)
@@ -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, &u, 1, sizeof(i), 0,
+    sign = rb_integer_pack(v, &u, 1, sizeof(i), 0,
         INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
     if (sign == 0)
         return WINT2FIXWV(0);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41212)
+++ ChangeLog	(revision 41213)
@@ -1,3 +1,22 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jun 10 19:34:39 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (rb_integer_pack): Returns sign instead of words.
+	  (absint_numwords_generic): Follow the above change.
+	  (big2str_base_powerof2): Follow the above change.
+
+	* internal.h: Ditto.
+
+	* hash.c (rb_hash): Ditto.
+
+	* pack.c (pack_pack): Ditto.
+
+	* random.c (int_pair_to_real_inclusive): Ditto.
+	  (rand_init): Ditto.
+	  (random_load): Ditto.
+	  (limited_big_rand): Ditto.
+
+	* time.c (v2w_bignum): Ditto.
+
 Mon Jun 10 17:20:01 2013  Koichi Sasada  <ko1@a...>
 
 	* gc.c (rgengc_remember): permit promoted object.
Index: pack.c
===================================================================
--- pack.c	(revision 41212)
+++ pack.c	(revision 41213)
@@ -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, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, INTEGER_PACK_BIG_ENDIAN);
+                sign = rb_integer_pack(from, 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 41212)
+++ ext/-test-/bignum/pack.c	(revision 41213)
@@ -6,17 +6,16 @@ rb_integer_pack_m(VALUE val, VALUE buf, https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/pack.c#L6
 {
   int sign;
   size_t count = 0;
-  void *ret;
   size_t wordsize = NUM2SIZET(wordsize_arg);
 
   StringValue(buf);
   rb_str_modify(buf);
   count = wordsize == 0 ? 0 : RSTRING_LEN(buf) / wordsize;
-  ret = rb_integer_pack(val,
-      &sign, RSTRING_PTR(buf), count,
+  sign = rb_integer_pack(val,
+      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));
+  return rb_ary_new_from_args(3, INT2NUM(sign), rb_str_new(RSTRING_PTR(buf), wordsize * count), SIZET2NUM(count));
 }
 
 static VALUE
Index: hash.c
===================================================================
--- hash.c	(revision 41212)
+++ hash.c	(revision 41213)
@@ -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, &ul, 1, sizeof(ul), 0,
+            sign = rb_integer_pack(hval, &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 41212)
+++ internal.h	(revision 41213)
@@ -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, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
+int rb_integer_pack(VALUE val, 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 41212)
+++ bignum.c	(revision 41213)
@@ -454,7 +454,7 @@ rb_big_unpack(unsigned long *buf, long n https://github.com/ruby/ruby/blob/trunk/bignum.c#L454
 /* number of bytes of abs(val). additionaly number of leading zeros can be returned. */
 
 /*
- * Calculate a number of bytes to be required to represent
+ * Calculate the number of bytes to be required to represent
  * the absolute value of the integer given as _val_.
  *
  * [val] an integer.
@@ -610,7 +610,7 @@ absint_numwords_generic(size_t numbytes, https://github.com/ruby/ruby/blob/trunk/bignum.c#L610
         div = rb_funcall(div, '+', 1, LONG2FIX(1));
         nlz_bits = word_numbits - NUM2SIZET(mod);
     }
-    rb_integer_pack(div, &sign, &numwords, 1, sizeof(numwords), 0,
+    sign = rb_integer_pack(div, &numwords, 1, sizeof(numwords), 0,
         INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
     if (sign == 2)
         return (size_t)-1;
@@ -619,7 +619,7 @@ absint_numwords_generic(size_t numbytes, https://github.com/ruby/ruby/blob/trunk/bignum.c#L619
 }
 
 /*
- * Calculate a number of words to be required to represent
+ * Calculate the number of words to be required to represent
  * the absolute value of the integer given as _val_.
  *
  * [val] an integer.
@@ -843,23 +843,25 @@ integer_pack_take_lowbits(int n, BDIGIT_ https://github.com/ruby/ruby/blob/trunk/bignum.c#L843
 /*
  * Export an integer into a buffer.
  *
- * [val] Fixnum, Bignum or another object which has to_int.
- * [signp] signedness is returned in *signp if it is not NULL.
- *   0 for zero.
- *   -1 for negative without overflow.  1 for positive without overflow.
- *   -2 for negative overflow.  2 for positive overflow.
+ * [val] Fixnum, Bignum or another integer like object which has to_int method.
  * [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.
- *
- * This function returns words or the allocated buffer if words is NULL.
+ * [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.
  *
+ * This function returns the signedness and overflow condition as follows:
+ *   -2 : negative overflow.
+ *   -1 : negative without overflow.
+ *   0 : zero.
+ *   1 : positive without overflow.
+ *   2 : positive overflow.
  */
 
-void *
-rb_integer_pack(VALUE val, int *signp, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
+int
+rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
 {
     int sign;
     BDIGIT *dp;
@@ -974,10 +976,7 @@ rb_integer_pack(VALUE val, int *signp, v https://github.com/ruby/ruby/blob/trunk/bignum.c#L976
             sign *= 2; /* overflow */
     }
 
-    if (signp)
-        *signp = sign;
-
-    return buf;
+    return sign;
 #undef FILL_DD
 #undef TAKE_LOWBITS
 }
@@ -1055,8 +1054,12 @@ integer_unpack_push_bits(int data, int n https://github.com/ruby/ruby/blob/trunk/bignum.c#L1054
  * [words] buffer to import.
  * [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 ignored.
- * [flags] bitwise or of constants which name starts "INTEGER_PACK_".  It specifies word order and byte order.
+ * [nails] number of padding bits in a word.
+ *   Most significant nails bits of each word are ignored.
+ * [flags] bitwise or of constants which name starts "INTEGER_PACK_".
+ *   It specifies word order and byte order.
+ *   Also, INTEGER_PACK_FORCE_BIGNUM specifies that the result will be a Bignum
+ *   even if it is representable as a Fixnum.
  *
  * This function returns the imported integer as Fixnum or Bignum.
  */
@@ -1882,7 +1885,7 @@ big2str_base_powerof2(VALUE x, size_t le https://github.com/ruby/ruby/blob/trunk/bignum.c#L1885
         result = rb_usascii_str_new(0, numwords);
         ptr = RSTRING_PTR(result);
     }
-    rb_integer_pack(x, NULL, ptr, numwords, 1, CHAR_BIT-word_numbits,
+    rb_integer_pack(x, ptr, numwords, 1, CHAR_BIT-word_numbits,
                     INTEGER_PACK_BIG_ENDIAN);
     while (0 < numwords) {
         *ptr = ruby_digitmap[*(unsigned char *)ptr];
Index: random.c
===================================================================
--- random.c	(revision 41212)
+++ random.c	(revision 41213)
@@ -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, uary, numberof(uary), sizeof(uint32_t), 0,
+        rb_integer_pack(x, 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, buf, len, sizeof(uint32_t), 0,
+    sign = rb_integer_pack(seed, 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, mt->state, numberof(mt->state),
+    rb_integer_pack(state, 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, lim_array, len, sizeof(uint32_t), 0,
+    rb_integer_pack(limit, 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/

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