Author: martin.v.loewis
Date: Sat Jul 21 10:47:18 2007
New Revision: 56480

Modified:
   python/branches/p3yk/Include/longintrepr.h
   python/branches/p3yk/Modules/mathmodule.c
   python/branches/p3yk/Objects/longobject.c
Log:
Qualify SHIFT, MASK, BASE.


Modified: python/branches/p3yk/Include/longintrepr.h
==============================================================================
--- python/branches/p3yk/Include/longintrepr.h  (original)
+++ python/branches/p3yk/Include/longintrepr.h  Sat Jul 21 10:47:18 2007
@@ -24,11 +24,11 @@
 typedef unsigned BASE_TWODIGITS_TYPE twodigits;
 typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */
 
-#define SHIFT  15
-#define BASE   ((digit)1 << SHIFT)
-#define MASK   ((int)(BASE - 1))
+#define PyLong_SHIFT   15
+#define PyLong_BASE    ((digit)1 << PyLong_SHIFT)
+#define PyLong_MASK    ((int)(PyLong_BASE - 1))
 
-#if SHIFT % 5 != 0
+#if PyLong_SHIFT % 5 != 0
 #error "longobject.c requires that SHIFT be divisible by 5"
 #endif
 

Modified: python/branches/p3yk/Modules/mathmodule.c
==============================================================================
--- python/branches/p3yk/Modules/mathmodule.c   (original)
+++ python/branches/p3yk/Modules/mathmodule.c   Sat Jul 21 10:47:18 2007
@@ -229,7 +229,7 @@
                   log(x) + log(2) * e * SHIFT.
                   CAUTION:  e*SHIFT may overflow using int arithmetic,
                   so force use of double. */
-               x = func(x) + (e * (double)SHIFT) * func(2.0);
+               x = func(x) + (e * (double)PyLong_SHIFT) * func(2.0);
                return PyFloat_FromDouble(x);
        }
 

Modified: python/branches/p3yk/Objects/longobject.c
==============================================================================
--- python/branches/p3yk/Objects/longobject.c   (original)
+++ python/branches/p3yk/Objects/longobject.c   Sat Jul 21 10:47:18 2007
@@ -170,7 +170,7 @@
        }
 
        /* Fast path for single-digits ints */
-       if (!(ival>>SHIFT)) {
+       if (!(ival>>PyLong_SHIFT)) {
                v = _PyLong_New(1);
                if (v) {
                        Py_Size(v) = sign;
@@ -180,12 +180,12 @@
        }
 
        /* 2 digits */
-       if (!(ival >> 2*SHIFT)) {
+       if (!(ival >> 2*PyLong_SHIFT)) {
                v = _PyLong_New(2);
                if (v) {
                        Py_Size(v) = 2*sign;
-                       v->ob_digit[0] = (digit)ival & MASK;
-                       v->ob_digit[1] = ival >> SHIFT;
+                       v->ob_digit[0] = (digit)ival & PyLong_MASK;
+                       v->ob_digit[1] = ival >> PyLong_SHIFT;
                }
                return (PyObject*)v;
        }
@@ -194,7 +194,7 @@
        t = (unsigned long)ival;
        while (t) {
                ++ndigits;
-               t >>= SHIFT;
+               t >>= PyLong_SHIFT;
        }
        v = _PyLong_New(ndigits);
        if (v != NULL) {
@@ -202,8 +202,8 @@
                Py_Size(v) = ndigits*sign;
                t = (unsigned long)ival;
                while (t) {
-                       *p++ = (digit)(t & MASK);
-                       t >>= SHIFT;
+                       *p++ = (digit)(t & PyLong_MASK);
+                       t >>= PyLong_SHIFT;
                }
        }
        return (PyObject *)v;
@@ -218,21 +218,21 @@
        unsigned long t;
        int ndigits = 0;
 
-       if (ival < BASE)
+       if (ival < PyLong_BASE)
                return PyLong_FromLong(ival);
        /* Count the number of Python digits. */
        t = (unsigned long)ival;
        while (t) {
                ++ndigits;
-               t >>= SHIFT;
+               t >>= PyLong_SHIFT;
        }
        v = _PyLong_New(ndigits);
        if (v != NULL) {
                digit *p = v->ob_digit;
                Py_Size(v) = ndigits;
                while (ival) {
-                       *p++ = (digit)(ival & MASK);
-                       ival >>= SHIFT;
+                       *p++ = (digit)(ival & PyLong_MASK);
+                       ival >>= PyLong_SHIFT;
                }
        }
        return (PyObject *)v;
@@ -260,16 +260,16 @@
        frac = frexp(dval, &expo); /* dval = frac*2**expo; 0.0 <= frac < 1.0 */
        if (expo <= 0)
                return PyLong_FromLong(0L);
-       ndig = (expo-1) / SHIFT + 1; /* Number of 'digits' in result */
+       ndig = (expo-1) / PyLong_SHIFT + 1; /* Number of 'digits' in result */
        v = _PyLong_New(ndig);
        if (v == NULL)
                return NULL;
-       frac = ldexp(frac, (expo-1) % SHIFT + 1);
+       frac = ldexp(frac, (expo-1) % PyLong_SHIFT + 1);
        for (i = ndig; --i >= 0; ) {
                long bits = (long)frac;
                v->ob_digit[i] = (digit) bits;
                frac = frac - (double)bits;
-               frac = ldexp(frac, SHIFT);
+               frac = ldexp(frac, PyLong_SHIFT);
        }
        if (neg)
                Py_Size(v) = -(Py_Size(v));
@@ -349,8 +349,8 @@
                }
                while (--i >= 0) {
                        prev = x;
-                       x = (x << SHIFT) + v->ob_digit[i];
-                       if ((x >> SHIFT) != prev) {
+                       x = (x << PyLong_SHIFT) + v->ob_digit[i];
+                       if ((x >> PyLong_SHIFT) != prev) {
                                PyErr_SetString(PyExc_OverflowError,
                                        "Python int too large to convert to C 
long");
                                goto exit;
@@ -419,8 +419,8 @@
        }
        while (--i >= 0) {
                prev = x;
-               x = (x << SHIFT) + v->ob_digit[i];
-               if ((x >> SHIFT) != prev)
+               x = (x << PyLong_SHIFT) + v->ob_digit[i];
+               if ((x >> PyLong_SHIFT) != prev)
                        goto overflow;
        }
        /* Haven't lost any bits, but casting to a signed type requires
@@ -468,8 +468,8 @@
        }
        while (--i >= 0) {
                prev = x;
-               x = (x << SHIFT) + v->ob_digit[i];
-               if ((x >> SHIFT) != prev) {
+               x = (x << PyLong_SHIFT) + v->ob_digit[i];
+               if ((x >> PyLong_SHIFT) != prev) {
                        PyErr_SetString(PyExc_OverflowError,
                         "python int too large to convert to C unsigned long");
                        return (unsigned long) -1;
@@ -506,8 +506,8 @@
        }
        while (--i >= 0) {
                prev = x;
-               x = (x << SHIFT) + v->ob_digit[i];
-               if ((x >> SHIFT) != prev) {
+               x = (x << PyLong_SHIFT) + v->ob_digit[i];
+               if ((x >> PyLong_SHIFT) != prev) {
                        PyErr_SetString(PyExc_OverflowError,
                            "Python int too large to convert to C size_t");
                        return (unsigned long) -1;
@@ -544,7 +544,7 @@
                i = -i;
        }
        while (--i >= 0) {
-               x = (x << SHIFT) + v->ob_digit[i];
+               x = (x << PyLong_SHIFT) + v->ob_digit[i];
        }
        return x * sign;
 }
@@ -609,8 +609,8 @@
        if (ndigits > 0) {
                digit msd = v->ob_digit[ndigits - 1];
 
-               result = (ndigits - 1) * SHIFT;
-               if (result / SHIFT != (size_t)(ndigits - 1))
+               result = (ndigits - 1) * PyLong_SHIFT;
+               if (result / PyLong_SHIFT != (size_t)(ndigits - 1))
                        goto Overflow;
                do {
                        ++result;
@@ -680,9 +680,9 @@
        }
 
        /* How many Python long digits do we need?  We have
-          8*numsignificantbytes bits, and each Python long digit has SHIFT
+          8*numsignificantbytes bits, and each Python long digit has 
PyLong_SHIFT
           bits, so it's the ceiling of the quotient. */
-       ndigits = (numsignificantbytes * 8 + SHIFT - 1) / SHIFT;
+       ndigits = (numsignificantbytes * 8 + PyLong_SHIFT - 1) / PyLong_SHIFT;
        if (ndigits > (size_t)INT_MAX)
                return PyErr_NoMemory();
        v = _PyLong_New((int)ndigits);
@@ -712,17 +712,17 @@
                           so needs to be prepended to accum. */
                        accum |= thisbyte << accumbits;
                        accumbits += 8;
-                       if (accumbits >= SHIFT) {
+                       if (accumbits >= PyLong_SHIFT) {
                                /* There's enough to fill a Python digit. */
                                assert(idigit < (int)ndigits);
-                               v->ob_digit[idigit] = (digit)(accum & MASK);
+                               v->ob_digit[idigit] = (digit)(accum & 
PyLong_MASK);
                                ++idigit;
-                               accum >>= SHIFT;
-                               accumbits -= SHIFT;
-                               assert(accumbits < SHIFT);
+                               accum >>= PyLong_SHIFT;
+                               accumbits -= PyLong_SHIFT;
+                               assert(accumbits < PyLong_SHIFT);
                        }
                }
-               assert(accumbits < SHIFT);
+               assert(accumbits < PyLong_SHIFT);
                if (accumbits) {
                        assert(idigit < (int)ndigits);
                        v->ob_digit[idigit] = (digit)accum;
@@ -776,7 +776,7 @@
 
        /* Copy over all the Python digits.
           It's crucial that every Python digit except for the MSD contribute
-          exactly SHIFT bits to the total, so first assert that the long is
+          exactly PyLong_SHIFT bits to the total, so first assert that the 
long is
           normalized. */
        assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0);
        j = 0;
@@ -786,15 +786,15 @@
        for (i = 0; i < ndigits; ++i) {
                twodigits thisdigit = v->ob_digit[i];
                if (do_twos_comp) {
-                       thisdigit = (thisdigit ^ MASK) + carry;
-                       carry = thisdigit >> SHIFT;
-                       thisdigit &= MASK;
+                       thisdigit = (thisdigit ^ PyLong_MASK) + carry;
+                       carry = thisdigit >> PyLong_SHIFT;
+                       thisdigit &= PyLong_MASK;
                }
                /* 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;
-               accumbits += SHIFT;
+               accumbits += PyLong_SHIFT;
 
                /* The most-significant digit may be (probably is) at least
                   partly empty. */
@@ -805,9 +805,9 @@
                         * First shift conceptual sign bit to real sign bit.
                         */
                        stwodigits s = (stwodigits)(thisdigit <<
-                               (8*sizeof(stwodigits) - SHIFT));
+                               (8*sizeof(stwodigits) - PyLong_SHIFT));
                        unsigned int nsignbits = 0;
-                       while ((s < 0) == do_twos_comp && nsignbits < SHIFT) {
+                       while ((s < 0) == do_twos_comp && nsignbits < 
PyLong_SHIFT) {
                                ++nsignbits;
                                s <<= 1;
                        }
@@ -887,7 +887,7 @@
 #define NBITS_WANTED 57
        PyLongObject *v;
        double x;
-       const double multiplier = (double)(1L << SHIFT);
+       const double multiplier = (double)(1L << PyLong_SHIFT);
        Py_ssize_t i;
        int sign;
        int nbitsneeded;
@@ -914,10 +914,10 @@
        while (i > 0 && nbitsneeded > 0) {
                --i;
                x = x * multiplier + (double)v->ob_digit[i];
-               nbitsneeded -= SHIFT;
+               nbitsneeded -= PyLong_SHIFT;
        }
        /* There are i digits we didn't shift in.  Pretending they're all
-          zeroes, the true value is x * 2**(i*SHIFT). */
+          zeroes, the true value is x * 2**(i*PyLong_SHIFT). */
        *exponent = i;
        assert(x > 0.0);
        return x * sign;
@@ -942,10 +942,10 @@
        /* 'e' initialized to -1 to silence gcc-4.0.x, but it should be
           set correctly after a successful _PyLong_AsScaledDouble() call */
        assert(e >= 0);
-       if (e > INT_MAX / SHIFT)
+       if (e > INT_MAX / PyLong_SHIFT)
                goto overflow;
        errno = 0;
-       x = ldexp(x, e * SHIFT);
+       x = ldexp(x, e * PyLong_SHIFT);
        if (Py_OVERFLOWED(x))
                goto overflow;
        return x;
@@ -1043,7 +1043,7 @@
        t = (unsigned PY_LONG_LONG)ival;
        while (t) {
                ++ndigits;
-               t >>= SHIFT;
+               t >>= PyLong_SHIFT;
        }
        v = _PyLong_New(ndigits);
        if (v != NULL) {
@@ -1051,8 +1051,8 @@
                Py_Size(v) = negative ? -ndigits : ndigits;
                t = (unsigned PY_LONG_LONG)ival;
                while (t) {
-                       *p++ = (digit)(t & MASK);
-                       t >>= SHIFT;
+                       *p++ = (digit)(t & PyLong_MASK);
+                       t >>= PyLong_SHIFT;
                }
        }
        return (PyObject *)v;
@@ -1067,21 +1067,21 @@
        unsigned PY_LONG_LONG t;
        int ndigits = 0;
 
-       if (ival < BASE)
+       if (ival < PyLong_BASE)
                return PyLong_FromLong(ival);
        /* Count the number of Python digits. */
        t = (unsigned PY_LONG_LONG)ival;
        while (t) {
                ++ndigits;
-               t >>= SHIFT;
+               t >>= PyLong_SHIFT;
        }
        v = _PyLong_New(ndigits);
        if (v != NULL) {
                digit *p = v->ob_digit;
                Py_Size(v) = ndigits;
                while (ival) {
-                       *p++ = (digit)(ival & MASK);
-                       ival >>= SHIFT;
+                       *p++ = (digit)(ival & PyLong_MASK);
+                       ival >>= PyLong_SHIFT;
                }
        }
        return (PyObject *)v;
@@ -1094,7 +1094,7 @@
 {
        Py_ssize_t bytes = ival;
        int one = 1;
-       if (ival < BASE)
+       if (ival < PyLong_BASE)
                return PyLong_FromLong(ival);
        return _PyLong_FromByteArray(
                        (unsigned char *)&bytes,
@@ -1108,7 +1108,7 @@
 {
        size_t bytes = ival;
        int one = 1;
-       if (ival < BASE)
+       if (ival < PyLong_BASE)
                return PyLong_FromLong(ival);
        return _PyLong_FromByteArray(
                        (unsigned char *)&bytes,
@@ -1229,7 +1229,7 @@
                i = -i;
        }
        while (--i >= 0) {
-               x = (x << SHIFT) + v->ob_digit[i];
+               x = (x << PyLong_SHIFT) + v->ob_digit[i];
        }
        return x * sign;
 }
@@ -1312,14 +1312,14 @@
        assert(m >= n);
        for (i = 0; i < n; ++i) {
                carry += x[i] + y[i];
-               x[i] = carry & MASK;
-               carry >>= SHIFT;
+               x[i] = carry & PyLong_MASK;
+               carry >>= PyLong_SHIFT;
                assert((carry & 1) == carry);
        }
        for (; carry && i < m; ++i) {
                carry += x[i];
-               x[i] = carry & MASK;
-               carry >>= SHIFT;
+               x[i] = carry & PyLong_MASK;
+               carry >>= PyLong_SHIFT;
                assert((carry & 1) == carry);
        }
        return carry;
@@ -1338,14 +1338,14 @@
        assert(m >= n);
        for (i = 0; i < n; ++i) {
                borrow = x[i] - y[i] - borrow;
-               x[i] = borrow & MASK;
-               borrow >>= SHIFT;
+               x[i] = borrow & PyLong_MASK;
+               borrow >>= PyLong_SHIFT;
                borrow &= 1;    /* keep only 1 sign bit */
        }
        for (; borrow && i < m; ++i) {
                borrow = x[i] - borrow;
-               x[i] = borrow & MASK;
-               borrow >>= SHIFT;
+               x[i] = borrow & PyLong_MASK;
+               borrow >>= PyLong_SHIFT;
                borrow &= 1;
        }
        return borrow;
@@ -1373,8 +1373,8 @@
                return NULL;
        for (i = 0; i < size_a; ++i) {
                carry += (twodigits)a->ob_digit[i] * n;
-               z->ob_digit[i] = (digit) (carry & MASK);
-               carry >>= SHIFT;
+               z->ob_digit[i] = (digit) (carry & PyLong_MASK);
+               carry >>= PyLong_SHIFT;
        }
        z->ob_digit[i] = (digit) carry;
        return long_normalize(z);
@@ -1391,12 +1391,12 @@
 {
        twodigits rem = 0;
 
-       assert(n > 0 && n <= MASK);
+       assert(n > 0 && n <= PyLong_MASK);
        pin += size;
        pout += size;
        while (--size >= 0) {
                digit hi;
-               rem = (rem << SHIFT) + *--pin;
+               rem = (rem << PyLong_SHIFT) + *--pin;
                *--pout = hi = (digit)(rem / n);
                rem -= hi * n;
        }
@@ -1413,7 +1413,7 @@
        const Py_ssize_t size = ABS(Py_Size(a));
        PyLongObject *z;
 
-       assert(n > 0 && n <= MASK);
+       assert(n > 0 && n <= PyLong_MASK);
        z = _PyLong_New(size);
        if (z == NULL)
                return NULL;
@@ -1451,9 +1451,9 @@
                i >>= 1;
        }
        i = 5;
-       j = size_a*SHIFT + bits-1;
+       j = size_a*PyLong_SHIFT + bits-1;
        sz = i + j / bits;
-       if (j / SHIFT < size_a || sz < i) {
+       if (j / PyLong_SHIFT < size_a || sz < i) {
                PyErr_SetString(PyExc_OverflowError,
                                "int is too large to format");
                return NULL;
@@ -1480,7 +1480,7 @@
 
                for (i = 0; i < size_a; ++i) {
                        accum |= (twodigits)a->ob_digit[i] << accumbits;
-                       accumbits += SHIFT;
+                       accumbits += PyLong_SHIFT;
                        assert(accumbits >= basebits);
                        do {
                                char cdigit = (char)(accum & (base - 1));
@@ -1505,7 +1505,7 @@
                int power = 1;
                for (;;) {
                        unsigned long newpow = powbase * (unsigned long)base;
-                       if (newpow >> SHIFT)  /* doesn't fit in a digit */
+                       if (newpow >> PyLong_SHIFT)  /* doesn't fit in a digit 
*/
                                break;
                        powbase = (digit)newpow;
                        ++power;
@@ -1587,7 +1587,7 @@
  * 'a' and 'A' map to 10, ..., 'z' and 'Z' map to 35.
  * All other indices map to 37.
  * Note that when converting a base B string, a char c is a legitimate
- * base B digit iff _PyLong_DigitValue[Py_CHARMASK(c)] < B.
+ * base B digit iff _PyLong_DigitValue[Py_CHARPyLong_MASK(c)] < B.
  */
 int _PyLong_DigitValue[256] = {
        37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
@@ -1635,14 +1635,14 @@
        while (_PyLong_DigitValue[Py_CHARMASK(*p)] < base)
                ++p;
        *str = p;
-       /* n <- # of Python digits needed, = ceiling(n/SHIFT). */
-       n = (p - start) * bits_per_char + SHIFT - 1;
+       /* n <- # of Python digits needed, = ceiling(n/PyLong_SHIFT). */
+       n = (p - start) * bits_per_char + PyLong_SHIFT - 1;
        if (n / bits_per_char < p - start) {
                PyErr_SetString(PyExc_ValueError,
                                "int string too large to convert");
                return NULL;
        }
-       n = n / SHIFT;
+       n = n / PyLong_SHIFT;
        z = _PyLong_New(n);
        if (z == NULL)
                return NULL;
@@ -1657,16 +1657,16 @@
                assert(k >= 0 && k < base);
                accum |= (twodigits)(k << bits_in_accum);
                bits_in_accum += bits_per_char;
-               if (bits_in_accum >= SHIFT) {
-                       *pdigit++ = (digit)(accum & MASK);
+               if (bits_in_accum >= PyLong_SHIFT) {
+                       *pdigit++ = (digit)(accum & PyLong_MASK);
                        assert(pdigit - z->ob_digit <= (int)n);
-                       accum >>= SHIFT;
-                       bits_in_accum -= SHIFT;
-                       assert(bits_in_accum < SHIFT);
+                       accum >>= PyLong_SHIFT;
+                       bits_in_accum -= PyLong_SHIFT;
+                       assert(bits_in_accum < PyLong_SHIFT);
                }
        }
        if (bits_in_accum) {
-               assert(bits_in_accum <= SHIFT);
+               assert(bits_in_accum <= PyLong_SHIFT);
                *pdigit++ = (digit)accum;
                assert(pdigit - z->ob_digit <= (int)n);
        }
@@ -1827,10 +1827,10 @@
                        int i = 1;
 
                        log_base_BASE[base] = log((double)base) /
-                                               log((double)BASE);
+                                               log((double)PyLong_BASE);
                        for (;;) {
                                twodigits next = convmax * base;
-                               if (next > BASE)
+                               if (next > PyLong_BASE)
                                        break;
                                convmax = next;
                                ++i;
@@ -1872,7 +1872,7 @@
                        for (i = 1; i < convwidth && str != scan; ++i, ++str) {
                                c = (twodigits)(c *  base +
                                        _PyLong_DigitValue[Py_CHARMASK(*str)]);
-                               assert(c < BASE);
+                               assert(c < PyLong_BASE);
                        }
 
                        convmult = convmultmax;
@@ -1890,12 +1890,12 @@
                        pzstop = pz + Py_Size(z);
                        for (; pz < pzstop; ++pz) {
                                c += (twodigits)*pz * convmult;
-                               *pz = (digit)(c & MASK);
-                               c >>= SHIFT;
+                               *pz = (digit)(c & PyLong_MASK);
+                               c >>= PyLong_SHIFT;
                        }
                        /* carry off the current end? */
                        if (c) {
-                               assert(c < BASE);
+                               assert(c < PyLong_BASE);
                                if (Py_Size(z) < size_z) {
                                        *pz = (digit)c;
                                        ++Py_Size(z);
@@ -2048,7 +2048,7 @@
 x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
 {
        Py_ssize_t size_v = ABS(Py_Size(v1)), size_w = ABS(Py_Size(w1));
-       digit d = (digit) ((twodigits)BASE / (w1->ob_digit[size_w-1] + 1));
+       digit d = (digit) ((twodigits)PyLong_BASE / (w1->ob_digit[size_w-1] + 
1));
        PyLongObject *v = mul1(v1, d);
        PyLongObject *w = mul1(w1, d);
        PyLongObject *a;
@@ -2080,28 +2080,28 @@
                        break;
                })
                if (vj == w->ob_digit[size_w-1])
-                       q = MASK;
+                       q = PyLong_MASK;
                else
-                       q = (((twodigits)vj << SHIFT) + v->ob_digit[j-1]) /
+                       q = (((twodigits)vj << PyLong_SHIFT) + 
v->ob_digit[j-1]) /
                                w->ob_digit[size_w-1];
 
                while (w->ob_digit[size_w-2]*q >
                                ((
-                                       ((twodigits)vj << SHIFT)
+                                       ((twodigits)vj << PyLong_SHIFT)
                                        + v->ob_digit[j-1]
                                        - q*w->ob_digit[size_w-1]
-                                                               ) << SHIFT)
+                                                               ) << 
PyLong_SHIFT)
                                + v->ob_digit[j-2])
                        --q;
 
                for (i = 0; i < size_w && i+k < size_v; ++i) {
                        twodigits z = w->ob_digit[i] * q;
-                       digit zz = (digit) (z >> SHIFT);
+                       digit zz = (digit) (z >> PyLong_SHIFT);
                        carry += v->ob_digit[i+k] - z
-                               + ((twodigits)zz << SHIFT);
-                       v->ob_digit[i+k] = (digit)(carry & MASK);
+                               + ((twodigits)zz << PyLong_SHIFT);
+                       v->ob_digit[i+k] = (digit)(carry & PyLong_MASK);
                        carry = Py_ARITHMETIC_RIGHT_SHIFT(BASE_TWODIGITS_TYPE,
-                                                         carry, SHIFT);
+                                                         carry, PyLong_SHIFT);
                        carry -= zz;
                }
 
@@ -2118,10 +2118,10 @@
                        carry = 0;
                        for (i = 0; i < size_w && i+k < size_v; ++i) {
                                carry += v->ob_digit[i+k] + w->ob_digit[i];
-                               v->ob_digit[i+k] = (digit)(carry & MASK);
+                               v->ob_digit[i+k] = (digit)(carry & PyLong_MASK);
                                carry = Py_ARITHMETIC_RIGHT_SHIFT(
                                                BASE_TWODIGITS_TYPE,
-                                               carry, SHIFT);
+                                               carry, PyLong_SHIFT);
                        }
                }
        } /* for j, k */
@@ -2216,13 +2216,13 @@
                sign = -1;
                i = -(i);
        }
-#define LONG_BIT_SHIFT (8*sizeof(long) - SHIFT)
+#define LONG_BIT_PyLong_SHIFT  (8*sizeof(long) - PyLong_SHIFT)
        while (--i >= 0) {
                /* Force a native long #-bits (32 or 64) circular shift */
-               x = ((x << SHIFT) & ~MASK) | ((x >> LONG_BIT_SHIFT) & MASK);
+               x = ((x << PyLong_SHIFT) & ~PyLong_MASK) | ((x >> 
LONG_BIT_PyLong_SHIFT) & PyLong_MASK);
                x += v->ob_digit[i];
        }
-#undef LONG_BIT_SHIFT
+#undef LONG_BIT_PyLong_SHIFT
        x = x * sign;
        if (x == -1)
                x = -2;
@@ -2252,13 +2252,13 @@
                return NULL;
        for (i = 0; i < size_b; ++i) {
                carry += a->ob_digit[i] + b->ob_digit[i];
-               z->ob_digit[i] = carry & MASK;
-               carry >>= SHIFT;
+               z->ob_digit[i] = carry & PyLong_MASK;
+               carry >>= PyLong_SHIFT;
        }
        for (; i < size_a; ++i) {
                carry += a->ob_digit[i];
-               z->ob_digit[i] = carry & MASK;
-               carry >>= SHIFT;
+               z->ob_digit[i] = carry & PyLong_MASK;
+               carry >>= PyLong_SHIFT;
        }
        z->ob_digit[i] = carry;
        return long_normalize(z);
@@ -2301,16 +2301,16 @@
                return NULL;
        for (i = 0; i < size_b; ++i) {
                /* The following assumes unsigned arithmetic
-                  works module 2**N for some N>SHIFT. */
+                  works module 2**N for some N>PyLong_SHIFT. */
                borrow = a->ob_digit[i] - b->ob_digit[i] - borrow;
-               z->ob_digit[i] = borrow & MASK;
-               borrow >>= SHIFT;
+               z->ob_digit[i] = borrow & PyLong_MASK;
+               borrow >>= PyLong_SHIFT;
                borrow &= 1; /* Keep only one sign bit */
        }
        for (; i < size_a; ++i) {
                borrow = a->ob_digit[i] - borrow;
-               z->ob_digit[i] = borrow & MASK;
-               borrow >>= SHIFT;
+               z->ob_digit[i] = borrow & PyLong_MASK;
+               borrow >>= PyLong_SHIFT;
                borrow &= 1; /* Keep only one sign bit */
        }
        assert(borrow == 0);
@@ -2422,9 +2422,9 @@
                        })
 
                        carry = *pz + f * f;
-                       *pz++ = (digit)(carry & MASK);
-                       carry >>= SHIFT;
-                       assert(carry <= MASK);
+                       *pz++ = (digit)(carry & PyLong_MASK);
+                       carry >>= PyLong_SHIFT;
+                       assert(carry <= PyLong_MASK);
 
                        /* Now f is added in twice in each column of the
                         * pyramid it appears.  Same as adding f<<1 once.
@@ -2432,18 +2432,18 @@
                        f <<= 1;
                        while (pa < paend) {
                                carry += *pz + *pa++ * f;
-                               *pz++ = (digit)(carry & MASK);
-                               carry >>= SHIFT;
-                               assert(carry <= (MASK << 1));
+                               *pz++ = (digit)(carry & PyLong_MASK);
+                               carry >>= PyLong_SHIFT;
+                               assert(carry <= (PyLong_MASK << 1));
                        }
                        if (carry) {
                                carry += *pz;
-                               *pz++ = (digit)(carry & MASK);
-                               carry >>= SHIFT;
+                               *pz++ = (digit)(carry & PyLong_MASK);
+                               carry >>= PyLong_SHIFT;
                        }
                        if (carry)
-                               *pz += (digit)(carry & MASK);
-                       assert((carry >> SHIFT) == 0);
+                               *pz += (digit)(carry & PyLong_MASK);
+                       assert((carry >> PyLong_SHIFT) == 0);
                }
        }
        else {  /* a is not the same as b -- gradeschool long mult */
@@ -2461,13 +2461,13 @@
 
                        while (pb < pbend) {
                                carry += *pz + *pb++ * f;
-                               *pz++ = (digit)(carry & MASK);
-                               carry >>= SHIFT;
-                               assert(carry <= MASK);
+                               *pz++ = (digit)(carry & PyLong_MASK);
+                               carry >>= PyLong_SHIFT;
+                               assert(carry <= PyLong_MASK);
                        }
                        if (carry)
-                               *pz += (digit)(carry & MASK);
-                       assert((carry >> SHIFT) == 0);
+                               *pz += (digit)(carry & PyLong_MASK);
+                       assert((carry >> PyLong_SHIFT) == 0);
                }
        }
        return long_normalize(z);
@@ -2713,7 +2713,7 @@
 (asize == bsize ? c(bsize/2) : f(bsize/2)) digits + 2 bits.  If asize < bsize,
 then we're asking whether asize digits >= f(bsize/2) digits + 2 bits.  By #4,
 asize is at least f(bsize/2)+1 digits, so this in turn reduces to whether 1
-digit is enough to hold 2 bits.  This is so since SHIFT=15 >= 2.  If
+digit is enough to hold 2 bits.  This is so since PyLong_SHIFT=15 >= 2.  If
 asize == bsize, then we're asking whether bsize digits is enough to hold
 c(bsize/2) digits + 2 bits, or equivalently (by #1) whether f(bsize/2) digits
 is enough to hold 2 bits.  This is so if bsize >= 2, which holds because
@@ -2917,15 +2917,15 @@
                return NULL;
        }
 
-       /* True value is very close to ad/bd * 2**(SHIFT*(aexp-bexp)) */
+       /* True value is very close to ad/bd * 2**(PyLong_SHIFT*(aexp-bexp)) */
        ad /= bd;       /* overflow/underflow impossible here */
        aexp -= bexp;
-       if (aexp > INT_MAX / SHIFT)
+       if (aexp > INT_MAX / PyLong_SHIFT)
                goto overflow;
-       else if (aexp < -(INT_MAX / SHIFT))
+       else if (aexp < -(INT_MAX / PyLong_SHIFT))
                return PyFloat_FromDouble(0.0); /* underflow to 0 */
        errno = 0;
-       ad = ldexp(ad, aexp * SHIFT);
+       ad = ldexp(ad, aexp * PyLong_SHIFT);
        if (Py_OVERFLOWED(ad)) /* ignore underflow to 0.0 */
                goto overflow;
        return PyFloat_FromDouble(ad);
@@ -3106,7 +3106,7 @@
                for (i = Py_Size(b) - 1; i >= 0; --i) {
                        digit bi = b->ob_digit[i];
 
-                       for (j = 1 << (SHIFT-1); j != 0; j >>= 1) {
+                       for (j = 1 << (PyLong_SHIFT-1); j != 0; j >>= 1) {
                                MULT(z, z, z)
                                if (bi & j)
                                        MULT(z, a, z)
@@ -3123,7 +3123,7 @@
                for (i = Py_Size(b) - 1; i >= 0; --i) {
                        const digit bi = b->ob_digit[i];
 
-                       for (j = SHIFT - 5; j >= 0; j -= 5) {
+                       for (j = PyLong_SHIFT - 5; j >= 0; j -= 5) {
                                const int index = (bi >> j) & 0x1f;
                                for (k = 0; k < 5; ++k)
                                        MULT(z, z, z)
@@ -3252,7 +3252,7 @@
                                        "negative shift count");
                        goto rshift_error;
                }
-               wordshift = shiftby / SHIFT;
+               wordshift = shiftby / PyLong_SHIFT;
                newsize = ABS(Py_Size(a)) - wordshift;
                if (newsize <= 0) {
                        z = _PyLong_New(0);
@@ -3260,10 +3260,10 @@
                        Py_DECREF(b);
                        return (PyObject *)z;
                }
-               loshift = shiftby % SHIFT;
-               hishift = SHIFT - loshift;
+               loshift = shiftby % PyLong_SHIFT;
+               hishift = PyLong_SHIFT - loshift;
                lomask = ((digit)1 << hishift) - 1;
-               himask = MASK ^ lomask;
+               himask = PyLong_MASK ^ lomask;
                z = _PyLong_New(newsize);
                if (z == NULL)
                        goto rshift_error;
@@ -3308,9 +3308,9 @@
                                "outrageous left shift count");
                goto lshift_error;
        }
-       /* wordshift, remshift = divmod(shiftby, SHIFT) */
-       wordshift = (int)shiftby / SHIFT;
-       remshift  = (int)shiftby - wordshift * SHIFT;
+       /* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */
+       wordshift = (int)shiftby / PyLong_SHIFT;
+       remshift  = (int)shiftby - wordshift * PyLong_SHIFT;
 
        oldsize = ABS(Py_Size(a));
        newsize = oldsize + wordshift;
@@ -3326,8 +3326,8 @@
        accum = 0;
        for (i = wordshift, j = 0; j < oldsize; i++, j++) {
                accum |= (twodigits)a->ob_digit[j] << remshift;
-               z->ob_digit[i] = (digit)(accum & MASK);
-               accum >>= SHIFT;
+               z->ob_digit[i] = (digit)(accum & PyLong_MASK);
+               accum >>= PyLong_SHIFT;
        }
        if (remshift)
                z->ob_digit[newsize-1] = (digit)accum;
@@ -3348,7 +3348,7 @@
             int op,  /* '&', '|', '^' */
             PyLongObject *b)
 {
-       digit maska, maskb; /* 0 or MASK */
+       digit maska, maskb; /* 0 or PyLong_MASK */
        int negz;
        Py_ssize_t size_a, size_b, size_z;
        PyLongObject *z;
@@ -3360,7 +3360,7 @@
                a = (PyLongObject *) long_invert(a);
                if (a == NULL)
                        return NULL;
-               maska = MASK;
+               maska = PyLong_MASK;
        }
        else {
                Py_INCREF(a);
@@ -3372,7 +3372,7 @@
                        Py_DECREF(a);
                        return NULL;
                }
-               maskb = MASK;
+               maskb = PyLong_MASK;
        }
        else {
                Py_INCREF(b);
@@ -3383,23 +3383,23 @@
        switch (op) {
        case '^':
                if (maska != maskb) {
-                       maska ^= MASK;
+                       maska ^= PyLong_MASK;
                        negz = -1;
                }
                break;
        case '&':
                if (maska && maskb) {
                        op = '|';
-                       maska ^= MASK;
-                       maskb ^= MASK;
+                       maska ^= PyLong_MASK;
+                       maskb ^= PyLong_MASK;
                        negz = -1;
                }
                break;
        case '|':
                if (maska || maskb) {
                        op = '&';
-                       maska ^= MASK;
-                       maskb ^= MASK;
+                       maska ^= PyLong_MASK;
+                       maskb ^= PyLong_MASK;
                        negz = -1;
                }
                break;
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to