* bignum.c: fix rb_quad_pack and rb_quad_unpack for environments
which don't have 8bytes integer type. This still depends on little endian. (rb_quad_pack): use quad_buf_complement. don't raise for large values. (rb_quad_unpack): use quad_buf_complement. (quad_buf_complement): new function extracted frm rb_quad_pack. add one after bitwise negation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d5a16d80be
commit
069d271eb5
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
Fri Feb 26 21:36:51 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* bignum.c: fix rb_quad_pack and rb_quad_unpack for environments
|
||||||
|
which don't have 8bytes integer type. This still depends on little
|
||||||
|
endian.
|
||||||
|
(rb_quad_pack): use quad_buf_complement. don't raise for large
|
||||||
|
values.
|
||||||
|
(rb_quad_unpack): use quad_buf_complement.
|
||||||
|
(quad_buf_complement): new function extracted frm rb_quad_pack.
|
||||||
|
add one after bitwise negation.
|
||||||
|
|
||||||
Fri Feb 26 21:29:48 2010 Tanaka Akira <akr@fsij.org>
|
Fri Feb 26 21:29:48 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* configure.in (RSHIFT): add parenthesis to supress warning.
|
* configure.in (RSHIFT): add parenthesis to supress warning.
|
||||||
|
30
bignum.c
30
bignum.c
@ -376,6 +376,20 @@ rb_quad_unpack(const char *buf, int sign)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
static int
|
||||||
|
quad_buf_complement(char *buf, size_t len)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
buf[i] = ~buf[i];
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
buf[i]++;
|
||||||
|
if (buf[i] != 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_quad_pack(char *buf, VALUE val)
|
rb_quad_pack(char *buf, VALUE val)
|
||||||
{
|
{
|
||||||
@ -388,15 +402,11 @@ rb_quad_pack(char *buf, VALUE val)
|
|||||||
}
|
}
|
||||||
len = RBIGNUM_LEN(val) * SIZEOF_BDIGITS;
|
len = RBIGNUM_LEN(val) * SIZEOF_BDIGITS;
|
||||||
if (len > QUAD_SIZE) {
|
if (len > QUAD_SIZE) {
|
||||||
rb_raise(rb_eRangeError, "bignum too big to convert into `quad int'");
|
len = QUAD_SIZE;
|
||||||
}
|
}
|
||||||
memcpy(buf, (char*)BDIGITS(val), len);
|
memcpy(buf, (char*)BDIGITS(val), len);
|
||||||
if (!RBIGNUM_SIGN(val)) {
|
if (RBIGNUM_NEGATIVE_P(val)) {
|
||||||
len = QUAD_SIZE;
|
quad_buf_complement(buf, QUAD_SIZE);
|
||||||
while (len--) {
|
|
||||||
*buf = ~*buf;
|
|
||||||
buf++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,14 +419,10 @@ rb_quad_unpack(const char *buf, int sign)
|
|||||||
|
|
||||||
memcpy((char*)BDIGITS(big), buf, QUAD_SIZE);
|
memcpy((char*)BDIGITS(big), buf, QUAD_SIZE);
|
||||||
if (sign && BNEG(buf)) {
|
if (sign && BNEG(buf)) {
|
||||||
long len = QUAD_SIZE;
|
|
||||||
char *tmp = (char*)BDIGITS(big);
|
char *tmp = (char*)BDIGITS(big);
|
||||||
|
|
||||||
RBIGNUM_SET_SIGN(big, 0);
|
RBIGNUM_SET_SIGN(big, 0);
|
||||||
while (len--) {
|
quad_buf_complement(tmp, QUAD_SIZE);
|
||||||
*tmp = ~*tmp;
|
|
||||||
tmp++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bignorm(big);
|
return bignorm(big);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user