From c90b1ecaf81868ab64b014401ea75eb45da2c5d0 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 31 Oct 2000 08:37:47 +0000 Subject: matz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- marshal.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 6 deletions(-) (limited to 'marshal.c') diff --git a/marshal.c b/marshal.c index f0ae1f5d05..7ae88485a8 100644 --- a/marshal.c +++ b/marshal.c @@ -18,6 +18,42 @@ double strtod(); #endif +#if SIZEOF_LONG*2 <= SIZEOF_LONG_LONG +typedef unsigned long BDIGIT; +#define SIZEOF_BDIGITS SIZEOF_LONG +#elif SIZEOF_INT*2 <= SIZEOF_LONG_LONG +typedef unsigned int BDIGIT; +#define SIZEOF_BDIGITS SIZEOF_INT +#else +typedef unsigned short BDIGIT; +#define SIZEOF_BDIGITS SIZEOF_SHORT +#endif + +#define BITSPERSHORT (sizeof(short)*CHAR_BIT) +#define SHORTMASK ((1<sign?'+':'-'; int len = RBIGNUM(obj)->len; - unsigned short *d = RBIGNUM(obj)->digits; + BDIGIT *d = RBIGNUM(obj)->digits; w_byte(sign, arg); - w_long(len, arg); + w_long(SHORTLEN(len), arg); while (len--) { +#if SIZEOF_BDIGITS > SIZEOF_SHORT + BDIGIT num = *d; + int i; + + for (i=0; isign = (r_byte(arg) == '+'); - big->len = len = r_long(arg); - big->digits = digits = ALLOC_N(unsigned short, len); - while (len--) { + len = r_long(arg); + big->len = (len + 1) * sizeof(short) / sizeof(BDIGIT); + big->digits = digits = ALLOC_N(BDIGIT, big->len); + while (len > 0) { +#if SIZEOF_BDIGITS > SIZEOF_SHORT + BDIGIT num = 0; + int shift = 0; + int i; + + for (i=0; i