ruby-changes:14900
From: akr <ko1@a...>
Date: Fri, 26 Feb 2010 21:41:18 +0900 (JST)
Subject: [ruby-changes:14900] Ruby:r26770 (trunk): * bignum.c: fix rb_quad_pack and rb_quad_unpack for environments
akr 2010-02-26 21:41:02 +0900 (Fri, 26 Feb 2010) New Revision: 26770 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26770 Log: * 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. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 26769) +++ ChangeLog (revision 26770) @@ -1,3 +1,14 @@ +Fri Feb 26 21:36:51 2010 Tanaka Akira <akr@f...> + + * 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@f...> * configure.in (RSHIFT): add parenthesis to supress warning. Index: bignum.c =================================================================== --- bignum.c (revision 26769) +++ bignum.c (revision 26770) @@ -376,6 +376,20 @@ #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 rb_quad_pack(char *buf, VALUE val) { @@ -388,15 +402,11 @@ } len = RBIGNUM_LEN(val) * SIZEOF_BDIGITS; 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); - if (!RBIGNUM_SIGN(val)) { - len = QUAD_SIZE; - while (len--) { - *buf = ~*buf; - buf++; - } + if (RBIGNUM_NEGATIVE_P(val)) { + quad_buf_complement(buf, QUAD_SIZE); } } @@ -409,14 +419,10 @@ memcpy((char*)BDIGITS(big), buf, QUAD_SIZE); if (sign && BNEG(buf)) { - long len = QUAD_SIZE; char *tmp = (char*)BDIGITS(big); RBIGNUM_SET_SIGN(big, 0); - while (len--) { - *tmp = ~*tmp; - tmp++; - } + quad_buf_complement(tmp, QUAD_SIZE); } return bignorm(big); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/