[macruby-changes] [4426] MacRuby/trunk/marshal.c
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 16 17:39:49 PDT 2010
Revision: 4426
http://trac.macosforge.org/projects/ruby/changeset/4426
Author: lsansonetti at apple.com
Date: 2010-08-16 17:39:48 -0700 (Mon, 16 Aug 2010)
Log Message:
-----------
fix marshal load of large integers (patch contributed by Jeff Hemmelgarn <jhemmelg at gmail.com>)
Modified Paths:
--------------
MacRuby/trunk/marshal.c
Modified: MacRuby/trunk/marshal.c
===================================================================
--- MacRuby/trunk/marshal.c 2010-08-16 20:15:54 UTC (rev 4425)
+++ MacRuby/trunk/marshal.c 2010-08-17 00:39:48 UTC (rev 4426)
@@ -1455,19 +1455,14 @@
OBJSETUP(big, rb_cBignum, T_BIGNUM);
RBIGNUM_SET_SIGN(big, (r_byte(arg) == '+'));
len = r_long(arg);
- data = r_bytes0(len * 2, arg);
- // TODO: this doesn't work at all
-#if SIZEOF_BDIGITS == SIZEOF_SHORT
- rb_big_resize((VALUE)big, len);
-#else
- rb_big_resize((VALUE)big, (len + 1) * 2 / sizeof(BDIGIT));
+ data = r_bytes0(len * SIZEOF_SHORT, arg);
+ rb_big_resize((VALUE)big, (len + (SIZEOF_BDIGITS/SIZEOF_SHORT - 1)) * SIZEOF_SHORT / SIZEOF_BDIGITS);
+ digits = RBIGNUM_DIGITS(big);
+ MEMCPY(digits, RSTRING_PTR(data), char, len * SIZEOF_SHORT);
+#if SIZEOF_BDIGITS > SIZEOF_SHORT
+ MEMZERO((char *)digits + len * SIZEOF_SHORT, char,
+ RBIGNUM_LEN(big) * SIZEOF_BDIGITS - len * SIZEOF_SHORT);
#endif
- digits = RBIGNUM_DIGITS(big);
- MEMCPY(digits, RSTRING_PTR(data), char, len * 2);
-#if 0//SIZEOF_BDIGITS > SIZEOF_SHORT
- MEMZERO((char *)digits + len * 2, char,
- RBIGNUM_LEN(big) * sizeof(BDIGIT) - len * 2);
-#endif
len = RBIGNUM_LEN(big);
while (len > 0) {
unsigned char *p = (unsigned char *)digits;
@@ -1477,7 +1472,7 @@
int i;
for (i=0; i<SIZEOF_BDIGITS; i++) {
- num |= (int)p[i] << shift;
+ num |= (BDIGIT)p[i] << shift;
shift += 8;
}
#else
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100816/fe6f2b87/attachment.html>
More information about the macruby-changes
mailing list