зеркало из https://github.com/github/ruby.git
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a8aaf13392
Коммит
0e8caa7d0f
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
Mon Jun 10 19:34:39 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* 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@atdot.net>
|
||||
|
||||
* gc.c (rgengc_remember): permit promoted object.
|
||||
|
|
45
bignum.c
45
bignum.c
|
@ -454,7 +454,7 @@ rb_big_unpack(unsigned long *buf, long num_longs)
|
|||
/* 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, int nlz_bits_in_msbyte, size_t word_num
|
|||
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, int nlz_bits_in_msbyte, size_t word_num
|
|||
}
|
||||
|
||||
/*
|
||||
* 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_DBL *ddp, int *numbits_in_dd_p)
|
|||
/*
|
||||
* 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, void *words, size_t numwords, size_t word
|
|||
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 numbits, BDIGIT_DBL *ddp, int *numbits_in
|
|||
* [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 len, int base, int trim)
|
|||
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];
|
||||
|
|
|
@ -6,17 +6,16 @@ rb_integer_pack_m(VALUE val, VALUE buf, VALUE wordsize_arg, VALUE nails, VALUE f
|
|||
{
|
||||
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
|
||||
|
|
2
hash.c
2
hash.c
|
@ -92,7 +92,7 @@ rb_hash(VALUE obj)
|
|||
{
|
||||
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)
|
||||
|
|
|
@ -447,7 +447,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_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 */
|
||||
|
|
2
pack.c
2
pack.c
|
@ -1023,7 +1023,7 @@ pack_pack(VALUE ary, VALUE fmt)
|
|||
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");
|
||||
|
|
8
random.c
8
random.c
|
@ -295,7 +295,7 @@ int_pair_to_real_inclusive(uint32_t a, uint32_t b)
|
|||
}
|
||||
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)
|
|||
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)
|
|||
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 limit)
|
|||
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:
|
||||
|
|
2
time.c
2
time.c
|
@ -302,7 +302,7 @@ v2w_bignum(VALUE v)
|
|||
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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче