summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-06 22:31:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-06 22:31:23 +0000
commitd1f3d41f11a5b0d47a85182a4c55e39def0f08f4 (patch)
tree124b7e03f7c08b846b0f06a0a1c237e079c431d7
parent7ba52b04a4a2024488b2ba4201421805d714334c (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--bignum.c27
-rw-r--r--ext/-test-/bignum/export.c4
-rw-r--r--internal.h2
-rw-r--r--pack.c4
5 files changed, 26 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 27e10e18bf4..318c809032c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Fri Jun 7 07:29:33 2013 Tanaka Akira <akr@fsij.org>
+
+ * 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@mrkn.jp>
* NEWS: describe a compatibility issue of Numeric#quo
diff --git a/bignum.c b/bignum.c
index 1cedb8b1716..b7ead9c132f 100644
--- a/bignum.c
+++ b/bignum.c
@@ -565,28 +565,27 @@ int_export_take_lowbits(int n, BDIGIT_DBL *ddp, int *numbits_in_dd_p)
* 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, void *bufarg, size_t *countp, int wordorder
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, void *bufarg, size_t *countp, int wordorder
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, void *bufarg, size_t *countp, int wordorder
if (signp)
*signp = sign;
- if (!bufarg)
- *countp = wordcount;
+ if (!words && wordcount_allocated)
+ *wordcount_allocated = wordcount;
return buf;
#undef FILL_DD
diff --git a/ext/-test-/bignum/export.c b/ext/-test-/bignum/export.c
index 4483452777d..33cc2d0a425 100644
--- a/ext/-test-/bignum/export.c
+++ b/ext/-test-/bignum/export.c
@@ -5,7 +5,7 @@ static VALUE
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, VALUE wordorder, VALUE wordsize_arg, VALUE
}
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));
diff --git a/internal.h b/internal.h
index cd2c02c8f70..09f104562a5 100644
--- a/internal.h
+++ b/internal.h
@@ -426,7 +426,7 @@ const char *rb_objspace_data_type_name(VALUE obj);
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 */
diff --git a/pack.c b/pack.c
index d77ed999b49..f4c907cc2ea 100644
--- a/pack.c
+++ b/pack.c
@@ -1014,7 +1014,6 @@ pack_pack(VALUE ary, VALUE fmt)
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)
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");