* 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
This commit is contained in:
akr 2013-06-06 22:31:23 +00:00
parent 7ba52b04a4
commit d1f3d41f11
5 changed files with 26 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -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));

View File

@ -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 */

4
pack.c
View File

@ -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");