* bignum.c (validate_integer_pack_format): Don't require a word order

flag if numwords is 1 or less.
  (absint_numwords_generic): Don't specify a word order for
  rb_integer_pack.

* hash.c (rb_hash): Ditto.

* time.c (v2w_bignum): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-06-11 14:40:16 +00:00
Родитель c4b12333f7
Коммит b23d9a8a63
5 изменённых файлов: 19 добавлений и 7 удалений

Просмотреть файл

@ -1,3 +1,14 @@
Tue Jun 11 23:37:19 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (validate_integer_pack_format): Don't require a word order
flag if numwords is 1 or less.
(absint_numwords_generic): Don't specify a word order for
rb_integer_pack.
* hash.c (rb_hash): Ditto.
* time.c (v2w_bignum): Ditto.
Tue Jun 11 23:01:57 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (validate_integer_pack_format): Refine error messages.

Просмотреть файл

@ -611,7 +611,7 @@ absint_numwords_generic(size_t numbytes, int nlz_bits_in_msbyte, size_t word_num
nlz_bits = word_numbits - NUM2SIZET(mod);
}
sign = rb_integer_pack(div, &numwords, 1, sizeof(numwords), 0,
INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
INTEGER_PACK_NATIVE_BYTE_ORDER);
if (sign == 2)
return (size_t)-1;
*nlz_bits_ret = nlz_bits;
@ -740,7 +740,8 @@ validate_integer_pack_format(size_t numwords, size_t wordsize, size_t nails, int
int wordorder_bits = flags & INTEGER_PACK_WORDORDER_MASK;
int byteorder_bits = flags & INTEGER_PACK_BYTEORDER_MASK;
if (wordorder_bits == 0) {
rb_raise(rb_eArgError, "word order not specified");
if (1 < numwords)
rb_raise(rb_eArgError, "word order not specified");
}
else if (wordorder_bits != INTEGER_PACK_MSWORD_FIRST &&
wordorder_bits != INTEGER_PACK_LSWORD_FIRST)

2
hash.c
Просмотреть файл

@ -93,7 +93,7 @@ rb_hash(VALUE obj)
int sign;
unsigned long ul;
sign = rb_integer_pack(hval, &ul, 1, sizeof(ul), 0,
INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
INTEGER_PACK_NATIVE_BYTE_ORDER);
ul &= (1UL << (sizeof(long)*CHAR_BIT-1)) - 1;
if (sign < 0)
return LONG2FIX(-(long)ul);

Просмотреть файл

@ -19,7 +19,7 @@ class TestBignum < Test::Unit::TestCase
end
def test_pack_argument_check
assert_raise(ArgumentError) { 0.test_pack_raw("", 0, 1, 0, MSBYTE_FIRST) }
assert_raise(ArgumentError) { 0.test_pack_raw("", 2, 1, 0, MSBYTE_FIRST) }
assert_raise(ArgumentError) { 0.test_pack_raw("", 0, 1, 0, MSWORD_FIRST) }
assert_raise(ArgumentError) { 0.test_pack_raw("", 0, 0, 0, BIG_ENDIAN) }
assert_raise(ArgumentError) { 0.test_pack_raw("", 0, 1, 8, BIG_ENDIAN) }
@ -121,7 +121,7 @@ class TestBignum < Test::Unit::TestCase
end
def test_unpack_argument_check
assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 0, MSBYTE_FIRST) }
assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 2, 1, 0, MSBYTE_FIRST) }
assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 0, MSWORD_FIRST) }
assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 0, 0, BIG_ENDIAN) }
assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 8, BIG_ENDIAN) }

4
time.c
Просмотреть файл

@ -302,8 +302,8 @@ v2w_bignum(VALUE v)
int sign;
uwideint_t u;
wideint_t i;
sign = rb_integer_pack(v, &u, 1, sizeof(i), 0,
INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
sign = rb_integer_pack(v, &u, 1, sizeof(u), 0,
INTEGER_PACK_NATIVE_BYTE_ORDER);
if (sign == 0)
return WINT2FIXWV(0);
else if (sign == -1) {