Index: Python/marshal.c =================================================================== --- Python/marshal.c (revision 66830) +++ Python/marshal.c (working copy) @@ -161,7 +161,7 @@ if (n < 0) n = -n; for (i = 0; i < n; i++) - w_short(ob->ob_digit[i], p); + w_long(ob->ob_digit[i], p); } else { #if SIZEOF_LONG > 4 @@ -562,7 +562,7 @@ } Py_SIZE(ob) = n; for (i = 0; i < size; i++) { - int digit = r_short(p); + long digit = r_long(p); if (digit < 0) { Py_DECREF(ob); PyErr_SetString(PyExc_ValueError, Index: Include/longintrepr.h =================================================================== --- Include/longintrepr.h (revision 66830) +++ Include/longintrepr.h (working copy) @@ -18,13 +18,14 @@ And, at some places it is assumed that MASK fits in an int, as well. long_pow() requires that SHIFT be divisible by 5. */ -typedef unsigned short digit; -typedef unsigned int wdigit; /* digit widened to parameter size */ -#define BASE_TWODIGITS_TYPE long +typedef unsigned long digit; +typedef long sdigit; /* signed variant of digit */ +typedef long wdigit; /* digit widened to parameter size */ +#define BASE_TWODIGITS_TYPE long long typedef unsigned BASE_TWODIGITS_TYPE twodigits; typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */ -#define PyLong_SHIFT 15 +#define PyLong_SHIFT 30 #define PyLong_BASE ((digit)1 << PyLong_SHIFT) #define PyLong_MASK ((int)(PyLong_BASE - 1)) Index: Objects/longobject.c =================================================================== --- Objects/longobject.c (revision 66830) +++ Objects/longobject.c (working copy) @@ -14,8 +14,8 @@ #define NSMALLNEGINTS 5 #endif -#define MEDIUM_VALUE(x) (Py_SIZE(x) < 0 ? -(x)->ob_digit[0] : \ - (Py_SIZE(x) == 0 ? 0 : (x)->ob_digit[0])) +#define MEDIUM_VALUE(x) (Py_SIZE(x) < 0 ? -(sdigit)(x)->ob_digit[0] : \ + (Py_SIZE(x) == 0 ? 0 : (sdigit)(x)->ob_digit[0])) #define ABS(x) ((x) < 0 ? -(x) : (x)) #if NSMALLNEGINTS + NSMALLPOSINTS > 0 @@ -203,17 +203,6 @@ return (PyObject*)v; } - /* 2 digits */ - if (!(ival >> 2*PyLong_SHIFT)) { - v = _PyLong_New(2); - if (v) { - Py_SIZE(v) = 2*sign; - v->ob_digit[0] = (digit)ival & PyLong_MASK; - v->ob_digit[1] = ival >> PyLong_SHIFT; - } - return (PyObject*)v; - } - /* Larger numbers: loop to determine number of digits */ t = abs_ival; while (t) { @@ -361,7 +350,7 @@ switch (i) { case -1: - res = -v->ob_digit[0]; + res = -(sdigit)v->ob_digit[0]; break; case 0: res = 0; @@ -436,7 +425,7 @@ v = (PyLongObject *)vv; i = Py_SIZE(v); switch (i) { - case -1: return -v->ob_digit[0]; + case -1: return -(sdigit)v->ob_digit[0]; case 0: return 0; case 1: return v->ob_digit[0]; } @@ -739,7 +728,7 @@ /* Because we're going LSB to MSB, thisbyte is more significant than what's already in accum, so needs to be prepended to accum. */ - accum |= thisbyte << accumbits; + accum |= (twodigits)thisbyte << accumbits; accumbits += 8; if (accumbits >= PyLong_SHIFT) { /* There's enough to fill a Python digit. */ @@ -822,7 +811,7 @@ /* Because we're going LSB to MSB, thisdigit is more significant than what's already in accum, so needs to be prepended to accum. */ - accum |= thisdigit << accumbits; + accum |= (twodigits)thisdigit << accumbits; accumbits += PyLong_SHIFT; /* The most-significant digit may be (probably is) at least @@ -1229,7 +1218,7 @@ v = (PyLongObject*)vv; switch(Py_SIZE(v)) { - case -1: return -v->ob_digit[0]; + case -1: return -(sdigit)v->ob_digit[0]; case 0: return 0; case 1: return v->ob_digit[0]; } @@ -1453,7 +1442,7 @@ digit hi; rem = (rem << PyLong_SHIFT) + *--pin; *--pout = hi = (digit)(rem / n); - rem -= hi * n; + rem -= (twodigits)hi * n; } return (digit)rem; } @@ -1712,7 +1701,7 @@ while (--p >= start) { int k = _PyLong_DigitValue[Py_CHARMASK(*p)]; assert(k >= 0 && k < base); - accum |= (twodigits)(k << bits_in_accum); + accum |= (twodigits)k << bits_in_accum; bits_in_accum += bits_per_char; if (bits_in_accum >= PyLong_SHIFT) { *pdigit++ = (digit)(accum & PyLong_MASK); @@ -2254,7 +2243,7 @@ of mapping keys will turn out weird */ i = Py_SIZE(v); switch(i) { - case -1: return v->ob_digit[0]==1 ? -2 : -v->ob_digit[0]; + case -1: return v->ob_digit[0]==1 ? -2 : -(sdigit)v->ob_digit[0]; case 0: return 0; case 1: return v->ob_digit[0]; } @@ -2843,7 +2832,8 @@ if (ABS(Py_SIZE(a)) <= 1 && ABS(Py_SIZE(b)) <= 1) { PyObject *r; - r = PyLong_FromLong(MEDIUM_VALUE(a)*MEDIUM_VALUE(b)); + r = PyLong_FromLongLong((stwodigits)MEDIUM_VALUE(a)* + MEDIUM_VALUE(b)); return r; }