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

ruby-changes:29065

From: akr <ko1@a...>
Date: Fri, 7 Jun 2013 07:31:35 +0900 (JST)
Subject: [ruby-changes:29065] akr:r41117 (trunk): * internal.h (rb_int_export): countp argument is split into

akr	2013-06-07 07:31:23 +0900 (Fri, 07 Jun 2013)

  New Revision: 41117

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

  Log:
    * internal.h (rb_int_export): countp argument is split into
      wordcount_allocated and wordcount.
    
    * bignum.c (rb_int_export): Follow the above change.
    
    * pack.c (pack_pack): Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/ext/-test-/bignum/export.c
    trunk/internal.h
    trunk/pack.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41116)
+++ ChangeLog	(revision 41117)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jun  7 07:29:33 2013  Tanaka Akira  <akr@f...>
+
+	* internal.h (rb_int_export): countp argument is split into
+	  wordcount_allocated and wordcount.
+
+	* bignum.c (rb_int_export): Follow the above change.
+
+	* pack.c (pack_pack): Ditto.
+
 Fri Jun  7 07:17:00 2013  Kenta Murata  <mrkn@m...>
 
 	* NEWS: describe a compatibility issue of Numeric#quo
Index: pack.c
===================================================================
--- pack.c	(revision 41116)
+++ pack.c	(revision 41117)
@@ -1014,7 +1014,6 @@ pack_pack(VALUE ary, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/pack.c#L1014
 		VALUE buf = rb_str_new(0, 0);
                 size_t numbytes;
                 int sign;
-                size_t count;
                 char *cp;
 
 		from = NEXTFROM;
@@ -1024,8 +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);
 
-                count = RSTRING_LEN(buf);
-                rb_int_export(from, &sign, RSTRING_PTR(buf), &count, 1, 1, 1, 1);
+                rb_int_export(from, &sign, NULL, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, 1, 1);
 
                 if (sign < 0)
                     rb_raise(rb_eArgError, "can't compress negative numbers");
Index: ext/-test-/bignum/export.c
===================================================================
--- ext/-test-/bignum/export.c	(revision 41116)
+++ ext/-test-/bignum/export.c	(revision 41117)
@@ -5,7 +5,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/export.c#L5
 rb_int_export_m(VALUE val, VALUE buf, VALUE wordorder, VALUE wordsize_arg, VALUE endian, VALUE nails)
 {
   int sign;
-  size_t count;
+  size_t count = 0;
   void *ret;
   size_t wordsize = NUM2SIZE(wordsize_arg);
 
@@ -16,7 +16,7 @@ rb_int_export_m(VALUE val, VALUE buf, VA https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/export.c#L16
   }
 
   ret = rb_int_export(val,
-      &sign, NIL_P(buf) ? NULL : RSTRING_PTR(buf), &count,
+      &sign, &count, NIL_P(buf) ? NULL : RSTRING_PTR(buf), count,
       NUM2INT(wordorder), wordsize, NUM2INT(endian), NUM2INT(nails));
 
   return rb_ary_new_from_args(3, INT2NUM(sign), ret ? rb_str_new(ret, wordsize * count) : Qnil, SIZE2NUM(count));
Index: internal.h
===================================================================
--- internal.h	(revision 41116)
+++ internal.h	(revision 41117)
@@ -426,7 +426,7 @@ const char *rb_objspace_data_type_name(V https://github.com/ruby/ruby/blob/trunk/internal.h#L426
 VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
 
 /* bignum.c */
-void *rb_int_export(VALUE val, int *signp, void *bufarg, size_t *countp, int wordorder, size_t wordsize, int endian, size_t nails);
+void *rb_int_export(VALUE val, int *signp, size_t *wordcount_allocated, void *bufarg, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails);
 VALUE rb_int_import(int sign, const void *bufarg, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails);
 
 /* io.c */
Index: bignum.c
===================================================================
--- bignum.c	(revision 41116)
+++ bignum.c	(revision 41117)
@@ -565,28 +565,27 @@ int_export_take_lowbits(int n, BDIGIT_DB https://github.com/ruby/ruby/blob/trunk/bignum.c#L565
  *   0 for zero.
  *   -1 for negative without overflow.  1 for positive without overflow.
  *   -2 for negative overflow.  2 for positive overflow.
- * [buf] buffer to export abs(val).  allocated by xmalloc if it is NULL.
- * [countp] the size of given buffer as number of words (only meaningful when buf is not NULL).
- *   *countp is overwritten as the number of allocated words when buf is NULL and allocated.
+ * [wordcount_allocated] the number of words allocated is returned in *wordcount_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.
+ * [wordcount] the size of given buffer as number of words (only meaningful when words is not NULL).
  * [wordorder] order of words: 1 for most significant word first.  -1 for least significant word first.
  * [wordsize] the size of word as number of bytes.
  * [endian] order of bytes in a word: 1 for most significant byte first.  -1 for least significant byte first.  0 for native endian.
  * [nails] number of padding bits in a word.  Most significant nails bits of each word are filled by zero.
  *
- * This function returns buf or the allocated buffer if buf is NULL.
+ * This function returns words or the allocated buffer if words is NULL.
  *
  */
 void *
-rb_int_export(VALUE val, int *signp, void *bufarg, size_t *countp, int wordorder, size_t wordsize, int endian, size_t nails)
+rb_int_export(VALUE val, int *signp, size_t *wordcount_allocated, void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails)
 {
     int sign;
     BDIGIT *dp;
     BDIGIT *de;
     BDIGIT fixbuf[(sizeof(long) + SIZEOF_BDIGITS - 1) / SIZEOF_BDIGITS];
     int i;
-    unsigned char *buf = bufarg;
-    unsigned char *bufend;
-    size_t wordcount;
+    unsigned char *buf, *bufend;
 
     val = rb_to_int(val);
 
@@ -598,8 +597,8 @@ rb_int_export(VALUE val, int *signp, voi https://github.com/ruby/ruby/blob/trunk/bignum.c#L597
         rb_raise(rb_eArgError, "invalid wordsize: %"PRI_SIZE_PREFIX"u", wordsize);
     if (SSIZE_MAX < wordsize)
         rb_raise(rb_eArgError, "too big wordsize: %"PRI_SIZE_PREFIX"u", wordsize);
-    if (buf && SIZE_MAX / wordsize < *countp)
-        rb_raise(rb_eArgError, "too big count * wordsize: %"PRI_SIZE_PREFIX"u * %"PRI_SIZE_PREFIX"u", *countp, wordsize);
+    if (words && SIZE_MAX / wordsize < wordcount)
+        rb_raise(rb_eArgError, "too big count * wordsize: %"PRI_SIZE_PREFIX"u * %"PRI_SIZE_PREFIX"u", wordcount, wordsize);
     if (wordsize <= nails / CHAR_BIT)
         rb_raise(rb_eArgError, "too big nails: %"PRI_SIZE_PREFIX"u", nails);
 
@@ -642,8 +641,8 @@ rb_int_export(VALUE val, int *signp, voi https://github.com/ruby/ruby/blob/trunk/bignum.c#L641
         sign = 0;
     }
 
-    if (buf) {
-        wordcount = *countp;
+    if (words) {
+        buf = words;
         bufend = buf + wordcount * wordsize;
     }
     else {
@@ -762,8 +761,8 @@ rb_int_export(VALUE val, int *signp, voi https://github.com/ruby/ruby/blob/trunk/bignum.c#L761
     if (signp)
         *signp = sign;
 
-    if (!bufarg)
-        *countp = wordcount;
+    if (!words && wordcount_allocated)
+        *wordcount_allocated = wordcount;
 
     return buf;
 #undef FILL_DD

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

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