Merged revisions 56467-56482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk

................
  r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines

  Merged revisions 56466-56476 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines

    PEP 3123: Provide forward compatibility with Python 3.0, while keeping
    backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
    PyVarObject_HEAD_INIT.
  ........
................
  r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines

  PEP 3123: Use proper C inheritance for PyObject.
................
  r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines

  Add longintrepr.h to Python.h, so that the compiler can
  see that PyFalse is really some kind of PyObject*.
................
  r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines

  Qualify SHIFT, MASK, BASE.
................
  r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines

  Correctly refer to _ob_next.
................
diff --git a/Objects/longobject.c b/Objects/longobject.c
index bfef437..930d07e 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -46,11 +46,11 @@
 #define CHECK_SMALL_INT(ival)
 #endif
 
-#define MEDIUM_VALUE(x) ((x)->ob_size < 0 ? -(x)->ob_digit[0] : ((x)->ob_size == 0 ? 0 : (x)->ob_digit[0]))
+#define MEDIUM_VALUE(x) (Py_Size(x) < 0 ? -(x)->ob_digit[0] : (Py_Size(x) == 0 ? 0 : (x)->ob_digit[0]))
 /* If a freshly-allocated long is already shared, it must
    be a small integer, so negating it must go to PyLong_FromLong */
 #define NEGATE(x) \
-	do if ((x)->ob_refcnt == 1) (x)->ob_size = -(x)->ob_size;  \
+	do if (Py_Refcnt(x) == 1) Py_Size(x) = -Py_Size(x);  \
 	   else { PyObject* tmp=PyInt_FromLong(-MEDIUM_VALUE(x));  \
 		   Py_DECREF(x); (x) = (PyLongObject*)tmp; }	   \
         while(0)
@@ -94,13 +94,13 @@
 static PyLongObject *
 long_normalize(register PyLongObject *v)
 {
-	Py_ssize_t j = ABS(v->ob_size);
+	Py_ssize_t j = ABS(Py_Size(v));
 	Py_ssize_t i = j;
 
 	while (i > 0 && v->ob_digit[i-1] == 0)
 		--i;
 	if (i != j)
-		v->ob_size = (v->ob_size < 0) ? -(i) : i;
+		Py_Size(v) = (Py_Size(v) < 0) ? -(i) : i;
 	return v;
 }
 
@@ -134,18 +134,18 @@
 	Py_ssize_t i;
 
 	assert(src != NULL);
-	i = src->ob_size;
+	i = Py_Size(src);
 	if (i < 0)
 		i = -(i);
 	if (i < 2) {
 		int ival = src->ob_digit[0];
-		if (src->ob_size < 0)
+		if (Py_Size(src) < 0)
 			ival = -ival;
 		CHECK_SMALL_INT(ival);
 	}
 	result = _PyLong_New(i);
 	if (result != NULL) {
-		result->ob_size = src->ob_size;
+		Py_Size(result) = Py_Size(src);
 		while (--i >= 0)
 			result->ob_digit[i] = src->ob_digit[i];
 	}
@@ -170,22 +170,22 @@
 	}
 
 	/* Fast path for single-digits ints */
-	if (!(ival>>SHIFT)) {
+	if (!(ival>>PyLong_SHIFT)) {
 		v = _PyLong_New(1);
 		if (v) {
-			v->ob_size = sign;
+			Py_Size(v) = sign;
 			v->ob_digit[0] = ival;
 		}
 		return (PyObject*)v;
 	}
 
 	/* 2 digits */
-	if (!(ival >> 2*SHIFT)) {
+	if (!(ival >> 2*PyLong_SHIFT)) {
 		v = _PyLong_New(2);
 		if (v) {
-			v->ob_size = 2*sign;
-			v->ob_digit[0] = (digit)ival & MASK;
-			v->ob_digit[1] = ival >> SHIFT;
+			Py_Size(v) = 2*sign;
+			v->ob_digit[0] = (digit)ival & PyLong_MASK;
+			v->ob_digit[1] = ival >> PyLong_SHIFT;
 		}
 		return (PyObject*)v;
 	}
@@ -194,16 +194,16 @@
 	t = (unsigned long)ival;
 	while (t) {
 		++ndigits;
-		t >>= SHIFT;
+		t >>= PyLong_SHIFT;
 	}
 	v = _PyLong_New(ndigits);
 	if (v != NULL) {
 		digit *p = v->ob_digit;
-		v->ob_size = ndigits*sign;
+		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;
-		v->ob_size = ndigits;
+		Py_Size(v) = ndigits;
 		while (ival) {
-			*p++ = (digit)(ival & MASK);
-			ival >>= SHIFT;
+			*p++ = (digit)(ival & PyLong_MASK);
+			ival >>= PyLong_SHIFT;
 		}
 	}
 	return (PyObject *)v;
@@ -260,19 +260,19 @@
 	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)
-		v->ob_size = -(v->ob_size);
+		Py_Size(v) = -(Py_Size(v));
 	return (PyObject *)v;
 }
 
@@ -328,7 +328,7 @@
 
 	res = -1;
 	v = (PyLongObject *)vv;
-	i = v->ob_size;
+	i = Py_Size(v);
 
 	switch (i) {
 	case -1:
@@ -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;
@@ -386,7 +386,7 @@
 		return 0;
 	}
 	/* conservative estimate */
-	size = ((PyLongObject*)vv)->ob_size;
+	size = Py_Size(vv);
 	return -2 <= size && size <= 2;
 }
 
@@ -405,7 +405,7 @@
 		return -1;
 	}
 	v = (PyLongObject *)vv;
-	i = v->ob_size;
+	i = Py_Size(v);
 	switch (i) {
 	case -1: return -v->ob_digit[0];
 	case 0: return 0;
@@ -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
@@ -455,7 +455,7 @@
 		return (unsigned long) -1;
 	}
 	v = (PyLongObject *)vv;
-	i = v->ob_size;
+	i = Py_Size(v);
 	x = 0;
 	if (i < 0) {
 		PyErr_SetString(PyExc_OverflowError,
@@ -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;
@@ -493,7 +493,7 @@
 		return (unsigned long) -1;
 	}
 	v = (PyLongObject *)vv;
-	i = v->ob_size;
+	i = Py_Size(v);
 	x = 0;
 	if (i < 0) {
 		PyErr_SetString(PyExc_OverflowError,
@@ -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;
@@ -532,7 +532,7 @@
 		return (unsigned long) -1;
 	}
 	v = (PyLongObject *)vv;
-	i = v->ob_size;
+	i = Py_Size(v);
 	switch (i) {
 	case 0: return 0;
 	case 1: return v->ob_digit[0];
@@ -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;
 }
@@ -592,7 +592,7 @@
 	assert(v != NULL);
 	assert(PyLong_Check(v));
 
-	return v->ob_size == 0 ? 0 : (v->ob_size < 0 ? -1 : 1);
+	return Py_Size(v) == 0 ? 0 : (Py_Size(v) < 0 ? -1 : 1);
 }
 
 size_t
@@ -604,13 +604,13 @@
 
 	assert(v != NULL);
 	assert(PyLong_Check(v));
-	ndigits = ABS(v->ob_size);
+	ndigits = ABS(Py_Size(v));
 	assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0);
 	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;
@@ -730,7 +730,7 @@
 		}
 	}
 
-	v->ob_size = is_signed ? -idigit : idigit;
+	Py_Size(v) = is_signed ? -idigit : idigit;
 	return (PyObject *)long_normalize(v);
 }
 
@@ -751,8 +751,8 @@
 
 	assert(v != NULL && PyLong_Check(v));
 
-	if (v->ob_size < 0) {
-		ndigits = -(v->ob_size);
+	if (Py_Size(v) < 0) {
+		ndigits = -(Py_Size(v));
 		if (!is_signed) {
 			PyErr_SetString(PyExc_TypeError,
 				"can't convert negative int to unsigned");
@@ -761,7 +761,7 @@
 		do_twos_comp = 1;
 	}
 	else {
-		ndigits = v->ob_size;
+		ndigits = Py_Size(v);
 		do_twos_comp = 0;
 	}
 
@@ -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;
@@ -897,7 +897,7 @@
 		return -1;
 	}
 	v = (PyLongObject *)vv;
-	i = v->ob_size;
+	i = Py_Size(v);
 	sign = 1;
 	if (i < 0) {
 		sign = -1;
@@ -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,16 +1043,16 @@
 	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;
-		v->ob_size = negative ? -ndigits : ndigits;
+		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;
-		v->ob_size = ndigits;
+		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,
@@ -1152,7 +1152,7 @@
 	}
 
 	v = (PyLongObject*)vv;
-	switch(v->ob_size) {
+	switch(Py_Size(v)) {
 	case -1: return -v->ob_digit[0];
 	case 0: return 0;
 	case 1: return v->ob_digit[0];
@@ -1185,7 +1185,7 @@
 	}
 
 	v = (PyLongObject*)vv;
-	switch(v->ob_size) {
+	switch(Py_Size(v)) {
 	case 0: return 0;
 	case 1: return v->ob_digit[0];
 	}
@@ -1217,11 +1217,11 @@
 		return (unsigned long) -1;
 	}
 	v = (PyLongObject *)vv;
-	switch(v->ob_size) {
+	switch(Py_Size(v)) {
 	case 0: return 0;
 	case 1: return v->ob_digit[0];
 	}
-	i = v->ob_size;
+	i = Py_Size(v);
 	sign = 1;
 	x = 0;
 	if (i < 0) {
@@ -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;
@@ -1364,7 +1364,7 @@
 static PyLongObject *
 muladd1(PyLongObject *a, wdigit n, wdigit extra)
 {
-	Py_ssize_t size_a = ABS(a->ob_size);
+	Py_ssize_t size_a = ABS(Py_Size(a));
 	PyLongObject *z = _PyLong_New(size_a+1);
 	twodigits carry = extra;
 	Py_ssize_t i;
@@ -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;
 	}
@@ -1410,10 +1410,10 @@
 static PyLongObject *
 divrem1(PyLongObject *a, digit n, digit *prem)
 {
-	const Py_ssize_t size = ABS(a->ob_size);
+	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;
@@ -1441,7 +1441,7 @@
 		return NULL;
 	}
 	assert(base >= 2 && base <= 36);
-	size_a = ABS(a->ob_size);
+	size_a = ABS(Py_Size(a));
 
 	/* Compute a rough upper bound for the length of the string */
 	i = base;
@@ -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;
@@ -1463,10 +1463,10 @@
 		return NULL;
 	p = PyUnicode_AS_UNICODE(str) + sz;
 	*p = '\0';
-	if (a->ob_size < 0)
+	if (Py_Size(a) < 0)
 		sign = '-';
 
-	if (a->ob_size == 0) {
+	if (Py_Size(a) == 0) {
 		*--p = '0';
 	}
 	else if ((base & (base - 1)) == 0) {
@@ -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;
@@ -1589,7 +1589,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,
@@ -1637,14 +1637,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;
@@ -1659,16 +1659,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);
 	}
@@ -1829,10 +1829,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;
@@ -1859,7 +1859,7 @@
 		z = _PyLong_New(size_z);
 		if (z == NULL)
 			return NULL;
-		z->ob_size = 0;
+		Py_Size(z) = 0;
 
 		/* `convwidth` consecutive input digits are treated as a single
 		 * digit in base `convmultmax`.
@@ -1874,7 +1874,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;
@@ -1889,23 +1889,23 @@
 
 			/* Multiply z by convmult, and add c. */
 			pz = z->ob_digit;
-			pzstop = pz + z->ob_size;
+			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);
-				if (z->ob_size < size_z) {
+				assert(c < PyLong_BASE);
+				if (Py_Size(z) < size_z) {
 					*pz = (digit)c;
-					++z->ob_size;
+					++Py_Size(z);
 				}
 				else {
 					PyLongObject *tmp;
 					/* Extremely rare.  Get more space. */
-					assert(z->ob_size == size_z);
+					assert(Py_Size(z) == size_z);
 					tmp = _PyLong_New(size_z + 1);
 					if (tmp == NULL) {
 						Py_DECREF(z);
@@ -1928,7 +1928,7 @@
 		/* reset the base to 0, else the exception message
 		   doesn't make too much sense */
 		base = 0;
-		if (z->ob_size != 0)
+		if (Py_Size(z) != 0)
 			goto onError;
 		/* there might still be other problems, therefore base
 		   remains zero here for the same reason */
@@ -1936,7 +1936,7 @@
 	if (str == start)
 		goto onError;
 	if (sign < 0)
-		z->ob_size = -(z->ob_size);
+		Py_Size(z) = -(Py_Size(z));
 	if (*str == 'L' || *str == 'l')
 		str++;
 	while (*str && isspace(Py_CHARMASK(*str)))
@@ -1995,7 +1995,7 @@
 long_divrem(PyLongObject *a, PyLongObject *b,
 	    PyLongObject **pdiv, PyLongObject **prem)
 {
-	Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+	Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
 	PyLongObject *z;
 
 	if (size_b == 0) {
@@ -2034,9 +2034,9 @@
 	   The quotient z has the sign of a*b;
 	   the remainder r has the sign of a,
 	   so a = b*z + r. */
-	if ((a->ob_size < 0) != (b->ob_size < 0))
+	if ((Py_Size(a) < 0) != (Py_Size(b) < 0))
 		NEGATE(z);
-	if (a->ob_size < 0 && (*prem)->ob_size != 0)
+	if (Py_Size(a) < 0 && Py_Size(*prem) != 0)
 		NEGATE(*prem);
 	*pdiv = z;
 	return 0;
@@ -2047,8 +2047,8 @@
 static PyLongObject *
 x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
 {
-	Py_ssize_t size_v = ABS(v1->ob_size), size_w = ABS(w1->ob_size);
-	digit d = (digit) ((twodigits)BASE / (w1->ob_digit[size_w-1] + 1));
+	Py_ssize_t size_v = ABS(Py_Size(v1)), size_w = ABS(Py_Size(w1));
+	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;
@@ -2061,10 +2061,10 @@
 	}
 
 	assert(size_v >= size_w && size_w > 1); /* Assert checks by div() */
-	assert(v->ob_refcnt == 1); /* Since v will be used as accumulator! */
-	assert(size_w == ABS(w->ob_size)); /* That's how d was calculated */
+	assert(Py_Refcnt(v) == 1); /* Since v will be used as accumulator! */
+	assert(size_w == ABS(Py_Size(w))); /* That's how d was calculated */
 
-	size_v = ABS(v->ob_size);
+	size_v = ABS(Py_Size(v));
 	k = size_v - size_w;
 	a = _PyLong_New(k + 1);
 
@@ -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 */
@@ -2147,7 +2147,7 @@
 static void
 long_dealloc(PyObject *v)
 {
-	v->ob_type->tp_free(v);
+	Py_Type(v)->tp_free(v);
 }
 
 static PyObject *
@@ -2161,21 +2161,21 @@
 {
 	Py_ssize_t sign;
 
-	if (a->ob_size != b->ob_size) {
-		if (ABS(a->ob_size) == 0 && ABS(b->ob_size) == 0)
+	if (Py_Size(a) != Py_Size(b)) {
+		if (ABS(Py_Size(a)) == 0 && ABS(Py_Size(b)) == 0)
 			sign = 0;
 		else
-			sign = a->ob_size - b->ob_size;
+			sign = Py_Size(a) - Py_Size(b);
 	}
 	else {
-		Py_ssize_t i = ABS(a->ob_size);
+		Py_ssize_t i = ABS(Py_Size(a));
 		while (--i >= 0 && a->ob_digit[i] == b->ob_digit[i])
 			;
 		if (i < 0)
 			sign = 0;
 		else {
 			sign = (int)a->ob_digit[i] - (int)b->ob_digit[i];
-			if (a->ob_size < 0)
+			if (Py_Size(a) < 0)
 				sign = -sign;
 		}
 	}
@@ -2204,7 +2204,7 @@
 	/* This is designed so that Python ints and longs with the
 	   same value hash to the same value, otherwise comparisons
 	   of mapping keys will turn out weird */
-	i = v->ob_size;
+	i = Py_Size(v);
 	switch(i) {
 	case -1: return v->ob_digit[0]==1 ? -2 : -v->ob_digit[0];
 	case 0: return 0;
@@ -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;
@@ -2235,7 +2235,7 @@
 static PyLongObject *
 x_add(PyLongObject *a, PyLongObject *b)
 {
-	Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+	Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
 	PyLongObject *z;
 	int i;
 	digit carry = 0;
@@ -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);
@@ -2269,7 +2269,7 @@
 static PyLongObject *
 x_sub(PyLongObject *a, PyLongObject *b)
 {
-	Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size);
+	Py_ssize_t size_a = ABS(Py_Size(a)), size_b = ABS(Py_Size(b));
 	PyLongObject *z;
 	Py_ssize_t i;
 	int sign = 1;
@@ -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);
@@ -2326,24 +2326,24 @@
 
 	CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
 
-	if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) {
+	if (ABS(Py_Size(a)) <= 1 && ABS(Py_Size(b)) <= 1) {
 		PyObject *result = PyInt_FromLong(MEDIUM_VALUE(a) +
 						  MEDIUM_VALUE(b));
 		Py_DECREF(a);
 		Py_DECREF(b);
 		return result;
 	}
-	if (a->ob_size < 0) {
-		if (b->ob_size < 0) {
+	if (Py_Size(a) < 0) {
+		if (Py_Size(b) < 0) {
 			z = x_add(a, b);
-			if (z != NULL && z->ob_size != 0)
-				z->ob_size = -(z->ob_size);
+			if (z != NULL && Py_Size(z) != 0)
+				Py_Size(z) = -(Py_Size(z));
 		}
 		else
 			z = x_sub(b, a);
 	}
 	else {
-		if (b->ob_size < 0)
+		if (Py_Size(b) < 0)
 			z = x_sub(a, b);
 		else
 			z = x_add(a, b);
@@ -2360,23 +2360,23 @@
 
 	CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
 
-	if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) {
+	if (ABS(Py_Size(a)) <= 1 && ABS(Py_Size(b)) <= 1) {
 		PyObject* r;
 		r = PyLong_FromLong(MEDIUM_VALUE(a)-MEDIUM_VALUE(b));
 		Py_DECREF(a);
 		Py_DECREF(b);
 		return r;
 	}
-	if (a->ob_size < 0) {
-		if (b->ob_size < 0)
+	if (Py_Size(a) < 0) {
+		if (Py_Size(b) < 0)
 			z = x_sub(a, b);
 		else
 			z = x_add(a, b);
-		if (z != NULL && z->ob_size != 0)
-			z->ob_size = -(z->ob_size);
+		if (z != NULL && Py_Size(z) != 0)
+			Py_Size(z) = -(Py_Size(z));
 	}
 	else {
-		if (b->ob_size < 0)
+		if (Py_Size(b) < 0)
 			z = x_add(a, b);
 		else
 			z = x_sub(a, b);
@@ -2393,15 +2393,15 @@
 x_mul(PyLongObject *a, PyLongObject *b)
 {
 	PyLongObject *z;
-	Py_ssize_t size_a = ABS(a->ob_size);
-	Py_ssize_t size_b = ABS(b->ob_size);
+	Py_ssize_t size_a = ABS(Py_Size(a));
+	Py_ssize_t size_b = ABS(Py_Size(b));
 	Py_ssize_t i;
 
      	z = _PyLong_New(size_a + size_b);
 	if (z == NULL)
 		return NULL;
 
-	memset(z->ob_digit, 0, z->ob_size * sizeof(digit));
+	memset(z->ob_digit, 0, Py_Size(z) * sizeof(digit));
 	if (a == b) {
 		/* Efficient squaring per HAC, Algorithm 14.16:
 		 * http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf
@@ -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);
@@ -2485,7 +2485,7 @@
 {
 	PyLongObject *hi, *lo;
 	Py_ssize_t size_lo, size_hi;
-	const Py_ssize_t size_n = ABS(n->ob_size);
+	const Py_ssize_t size_n = ABS(Py_Size(n));
 
 	size_lo = MIN(size_n, size);
 	size_hi = size_n - size_lo;
@@ -2514,8 +2514,8 @@
 static PyLongObject *
 k_mul(PyLongObject *a, PyLongObject *b)
 {
-	Py_ssize_t asize = ABS(a->ob_size);
-	Py_ssize_t bsize = ABS(b->ob_size);
+	Py_ssize_t asize = ABS(Py_Size(a));
+	Py_ssize_t bsize = ABS(Py_Size(b));
 	PyLongObject *ah = NULL;
 	PyLongObject *al = NULL;
 	PyLongObject *bh = NULL;
@@ -2567,7 +2567,7 @@
 	/* Split a & b into hi & lo pieces. */
 	shift = bsize >> 1;
 	if (kmul_split(a, shift, &ah, &al) < 0) goto fail;
-	assert(ah->ob_size > 0);	/* the split isn't degenerate */
+	assert(Py_Size(ah) > 0);	/* the split isn't degenerate */
 
 	if (a == b) {
 		bh = ah;
@@ -2598,20 +2598,20 @@
 	if (ret == NULL) goto fail;
 #ifdef Py_DEBUG
 	/* Fill with trash, to catch reference to uninitialized digits. */
-	memset(ret->ob_digit, 0xDF, ret->ob_size * sizeof(digit));
+	memset(ret->ob_digit, 0xDF, Py_Size(ret) * sizeof(digit));
 #endif
 
 	/* 2. t1 <- ah*bh, and copy into high digits of result. */
 	if ((t1 = k_mul(ah, bh)) == NULL) goto fail;
-	assert(t1->ob_size >= 0);
-	assert(2*shift + t1->ob_size <= ret->ob_size);
+	assert(Py_Size(t1) >= 0);
+	assert(2*shift + Py_Size(t1) <= Py_Size(ret));
 	memcpy(ret->ob_digit + 2*shift, t1->ob_digit,
-	       t1->ob_size * sizeof(digit));
+	       Py_Size(t1) * sizeof(digit));
 
 	/* Zero-out the digits higher than the ah*bh copy. */
-	i = ret->ob_size - 2*shift - t1->ob_size;
+	i = Py_Size(ret) - 2*shift - Py_Size(t1);
 	if (i)
-		memset(ret->ob_digit + 2*shift + t1->ob_size, 0,
+		memset(ret->ob_digit + 2*shift + Py_Size(t1), 0,
 		       i * sizeof(digit));
 
 	/* 3. t2 <- al*bl, and copy into the low digits. */
@@ -2619,23 +2619,23 @@
 		Py_DECREF(t1);
 		goto fail;
 	}
-	assert(t2->ob_size >= 0);
-	assert(t2->ob_size <= 2*shift); /* no overlap with high digits */
-	memcpy(ret->ob_digit, t2->ob_digit, t2->ob_size * sizeof(digit));
+	assert(Py_Size(t2) >= 0);
+	assert(Py_Size(t2) <= 2*shift); /* no overlap with high digits */
+	memcpy(ret->ob_digit, t2->ob_digit, Py_Size(t2) * sizeof(digit));
 
 	/* Zero out remaining digits. */
-	i = 2*shift - t2->ob_size;	/* number of uninitialized digits */
+	i = 2*shift - Py_Size(t2);	/* number of uninitialized digits */
 	if (i)
-		memset(ret->ob_digit + t2->ob_size, 0, i * sizeof(digit));
+		memset(ret->ob_digit + Py_Size(t2), 0, i * sizeof(digit));
 
 	/* 4 & 5. Subtract ah*bh (t1) and al*bl (t2).  We do al*bl first
 	 * because it's fresher in cache.
 	 */
-	i = ret->ob_size - shift;  /* # digits after shift */
-	(void)v_isub(ret->ob_digit + shift, i, t2->ob_digit, t2->ob_size);
+	i = Py_Size(ret) - shift;  /* # digits after shift */
+	(void)v_isub(ret->ob_digit + shift, i, t2->ob_digit, Py_Size(t2));
 	Py_DECREF(t2);
 
-	(void)v_isub(ret->ob_digit + shift, i, t1->ob_digit, t1->ob_size);
+	(void)v_isub(ret->ob_digit + shift, i, t1->ob_digit, Py_Size(t1));
 	Py_DECREF(t1);
 
 	/* 6. t3 <- (ah+al)(bh+bl), and add into result. */
@@ -2660,12 +2660,12 @@
 	Py_DECREF(t1);
 	Py_DECREF(t2);
 	if (t3 == NULL) goto fail;
-	assert(t3->ob_size >= 0);
+	assert(Py_Size(t3) >= 0);
 
 	/* Add t3.  It's not obvious why we can't run out of room here.
 	 * See the (*) comment after this function.
 	 */
-	(void)v_iadd(ret->ob_digit + shift, i, t3->ob_digit, t3->ob_size);
+	(void)v_iadd(ret->ob_digit + shift, i, t3->ob_digit, Py_Size(t3));
 	Py_DECREF(t3);
 
 	return long_normalize(ret);
@@ -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
@@ -2735,8 +2735,8 @@
 static PyLongObject *
 k_lopsided_mul(PyLongObject *a, PyLongObject *b)
 {
-	const Py_ssize_t asize = ABS(a->ob_size);
-	Py_ssize_t bsize = ABS(b->ob_size);
+	const Py_ssize_t asize = ABS(Py_Size(a));
+	Py_ssize_t bsize = ABS(Py_Size(b));
 	Py_ssize_t nbdone;	/* # of b digits already multiplied */
 	PyLongObject *ret;
 	PyLongObject *bslice = NULL;
@@ -2748,7 +2748,7 @@
 	ret = _PyLong_New(asize + bsize);
 	if (ret == NULL)
 		return NULL;
-	memset(ret->ob_digit, 0, ret->ob_size * sizeof(digit));
+	memset(ret->ob_digit, 0, Py_Size(ret) * sizeof(digit));
 
 	/* Successive slices of b are copied into bslice. */
 	bslice = _PyLong_New(asize);
@@ -2763,14 +2763,14 @@
 		/* Multiply the next slice of b by a. */
 		memcpy(bslice->ob_digit, b->ob_digit + nbdone,
 		       nbtouse * sizeof(digit));
-		bslice->ob_size = nbtouse;
+		Py_Size(bslice) = nbtouse;
 		product = k_mul(a, bslice);
 		if (product == NULL)
 			goto fail;
 
 		/* Add into result. */
-		(void)v_iadd(ret->ob_digit + nbdone, ret->ob_size - nbdone,
-			     product->ob_digit, product->ob_size);
+		(void)v_iadd(ret->ob_digit + nbdone, Py_Size(ret) - nbdone,
+			     product->ob_digit, Py_Size(product));
 		Py_DECREF(product);
 
 		bsize -= nbtouse;
@@ -2796,7 +2796,7 @@
 		return Py_NotImplemented;
 	}
 
-	if (ABS(v->ob_size) <= 1 && ABS(w->ob_size) <= 1) {
+	if (ABS(Py_Size(v)) <= 1 && ABS(Py_Size(w)) <= 1) {
 		PyObject *r;
 		r = PyLong_FromLong(MEDIUM_VALUE(v)*MEDIUM_VALUE(w));
 		Py_DECREF(a);
@@ -2806,7 +2806,7 @@
 
 	z = k_mul(a, b);
 	/* Negate if exactly one of the inputs is negative. */
-	if (((a->ob_size ^ b->ob_size) < 0) && z)
+	if (((Py_Size(a) ^ Py_Size(b)) < 0) && z)
 		NEGATE(z);
 	Py_DECREF(a);
 	Py_DECREF(b);
@@ -2842,8 +2842,8 @@
 
 	if (long_divrem(v, w, &div, &mod) < 0)
 		return -1;
-	if ((mod->ob_size < 0 && w->ob_size > 0) ||
-	    (mod->ob_size > 0 && w->ob_size < 0)) {
+	if ((Py_Size(mod) < 0 && Py_Size(w) > 0) ||
+	    (Py_Size(mod) > 0 && Py_Size(w) < 0)) {
 		PyLongObject *temp;
 		PyLongObject *one;
 		temp = (PyLongObject *) long_add(mod, w);
@@ -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);
@@ -3010,7 +3010,7 @@
 		return Py_NotImplemented;
 	}
 
-	if (b->ob_size < 0) {  /* if exponent is negative */
+	if (Py_Size(b) < 0) {  /* if exponent is negative */
 		if (c) {
 			PyErr_SetString(PyExc_TypeError, "pow() 2nd argument "
 			    "cannot be negative when 3rd argument specified");
@@ -3029,7 +3029,7 @@
 	if (c) {
 		/* if modulus == 0:
 		       raise ValueError() */
-		if (c->ob_size == 0) {
+		if (Py_Size(c) == 0) {
 			PyErr_SetString(PyExc_ValueError,
 					"pow() 3rd argument cannot be 0");
 			goto Error;
@@ -3038,7 +3038,7 @@
 		/* if modulus < 0:
 		       negativeOutput = True
 		       modulus = -modulus */
-		if (c->ob_size < 0) {
+		if (Py_Size(c) < 0) {
 			negativeOutput = 1;
 			temp = (PyLongObject *)_PyLong_Copy(c);
 			if (temp == NULL)
@@ -3051,7 +3051,7 @@
 
 		/* if modulus == 1:
 		       return 0 */
-		if ((c->ob_size == 1) && (c->ob_digit[0] == 1)) {
+		if ((Py_Size(c) == 1) && (c->ob_digit[0] == 1)) {
 			z = (PyLongObject *)PyLong_FromLong(0L);
 			goto Done;
 		}
@@ -3059,7 +3059,7 @@
 		/* if base < 0:
 		       base = base % modulus
 		   Having the base positive just makes things easier. */
-		if (a->ob_size < 0) {
+		if (Py_Size(a) < 0) {
 			if (l_divmod(a, c, NULL, &temp) < 0)
 				goto Error;
 			Py_DECREF(a);
@@ -3100,13 +3100,13 @@
 	REDUCE(result)					\
 }
 
-	if (b->ob_size <= FIVEARY_CUTOFF) {
+	if (Py_Size(b) <= FIVEARY_CUTOFF) {
 		/* Left-to-right binary exponentiation (HAC Algorithm 14.79) */
 		/* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf    */
-		for (i = b->ob_size - 1; i >= 0; --i) {
+		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)
@@ -3120,10 +3120,10 @@
 		for (i = 1; i < 32; ++i)
 			MULT(table[i-1], a, table[i])
 
-		for (i = b->ob_size - 1; i >= 0; --i) {
+		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)
@@ -3133,7 +3133,7 @@
 		}
 	}
 
-	if (negativeOutput && (z->ob_size != 0)) {
+	if (negativeOutput && (Py_Size(z) != 0)) {
 		temp = (PyLongObject *)long_sub(z, c);
 		if (temp == NULL)
 			goto Error;
@@ -3150,7 +3150,7 @@
  	}
 	/* fall through */
  Done:
-	if (b->ob_size > FIVEARY_CUTOFF) {
+	if (Py_Size(b) > FIVEARY_CUTOFF) {
 		for (i = 0; i < 32; ++i)
 			Py_XDECREF(table[i]);
 	}
@@ -3167,7 +3167,7 @@
 	/* Implement ~x as -(x+1) */
 	PyLongObject *x;
 	PyLongObject *w;
-	if (ABS(v->ob_size) <=1)
+	if (ABS(Py_Size(v)) <=1)
 		return PyLong_FromLong(-(MEDIUM_VALUE(v)+1));
 	w = (PyLongObject *)PyLong_FromLong(1L);
 	if (w == NULL)
@@ -3176,7 +3176,7 @@
 	Py_DECREF(w);
 	if (x == NULL)
 		return NULL;
-	x->ob_size = -(x->ob_size);
+	Py_Size(x) = -(Py_Size(x));
 	return (PyObject *)x;
 }
 
@@ -3195,18 +3195,18 @@
 long_neg(PyLongObject *v)
 {
 	PyLongObject *z;
-	if (ABS(v->ob_size) <= 1)
+	if (ABS(Py_Size(v)) <= 1)
 		return PyLong_FromLong(-MEDIUM_VALUE(v));
 	z = (PyLongObject *)_PyLong_Copy(v);
 	if (z != NULL)
-		z->ob_size = -(v->ob_size);
+		Py_Size(z) = -(Py_Size(v));
 	return (PyObject *)z;
 }
 
 static PyObject *
 long_abs(PyLongObject *v)
 {
-	if (v->ob_size < 0)
+	if (Py_Size(v) < 0)
 		return long_neg(v);
 	else
 		return long_pos(v);
@@ -3215,7 +3215,7 @@
 static int
 long_bool(PyLongObject *v)
 {
-	return ABS(v->ob_size) != 0;
+	return ABS(Py_Size(v)) != 0;
 }
 
 static PyObject *
@@ -3229,7 +3229,7 @@
 
 	CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
 
-	if (a->ob_size < 0) {
+	if (Py_Size(a) < 0) {
 		/* Right shifting negative numbers is harder */
 		PyLongObject *a1, *a2;
 		a1 = (PyLongObject *) long_invert(a);
@@ -3252,23 +3252,23 @@
 					"negative shift count");
 			goto rshift_error;
 		}
-		wordshift = shiftby / SHIFT;
-		newsize = ABS(a->ob_size) - wordshift;
+		wordshift = shiftby / PyLong_SHIFT;
+		newsize = ABS(Py_Size(a)) - wordshift;
 		if (newsize <= 0) {
 			z = _PyLong_New(0);
 			Py_DECREF(a);
 			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;
-		if (a->ob_size < 0)
-			z->ob_size = -(z->ob_size);
+		if (Py_Size(a) < 0)
+			Py_Size(z) = -(Py_Size(z));
 		for (i = 0, j = wordshift; i < newsize; i++, j++) {
 			z->ob_digit[i] = (a->ob_digit[j] >> loshift) & lomask;
 			if (i+1 < newsize)
@@ -3308,26 +3308,26 @@
 				"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(a->ob_size);
+	oldsize = ABS(Py_Size(a));
 	newsize = oldsize + wordshift;
 	if (remshift)
 		++newsize;
 	z = _PyLong_New(newsize);
 	if (z == NULL)
 		goto lshift_error;
-	if (a->ob_size < 0)
+	if (Py_Size(a) < 0)
 		NEGATE(z);
 	for (i = 0; i < wordshift; i++)
 		z->ob_digit[i] = 0;
 	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;
@@ -3356,23 +3356,23 @@
 	digit diga, digb;
 	PyObject *v;
 
-	if (a->ob_size < 0) {
+	if (Py_Size(a) < 0) {
 		a = (PyLongObject *) long_invert(a);
 		if (a == NULL)
 			return NULL;
-		maska = MASK;
+		maska = PyLong_MASK;
 	}
 	else {
 		Py_INCREF(a);
 		maska = 0;
 	}
-	if (b->ob_size < 0) {
+	if (Py_Size(b) < 0) {
 		b = (PyLongObject *) long_invert(b);
 		if (b == NULL) {
 			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;
@@ -3415,8 +3415,8 @@
 	   whose length should be ignored.
 	*/
 
-	size_a = a->ob_size;
-	size_b = b->ob_size;
+	size_a = Py_Size(a);
+	size_b = Py_Size(b);
 	size_z = op == '&'
 		? (maska
 		   ? size_b
@@ -3585,7 +3585,7 @@
 	if (tmp == NULL)
 		return NULL;
 	assert(PyLong_CheckExact(tmp));
-	n = tmp->ob_size;
+	n = Py_Size(tmp);
 	if (n < 0)
 		n = -n;
 	newobj = (PyLongObject *)type->tp_alloc(type, n);
@@ -3594,7 +3594,7 @@
 		return NULL;
 	}
 	assert(PyLong_Check(newobj));
-	newobj->ob_size = tmp->ob_size;
+	Py_Size(newobj) = Py_Size(tmp);
 	for (i = 0; i < n; i++)
 		newobj->ob_digit[i] = tmp->ob_digit[i];
 	Py_DECREF(tmp);
@@ -3662,8 +3662,7 @@
 };
 
 PyTypeObject PyLong_Type = {
-	PyObject_HEAD_INIT(&PyType_Type)
-	0,					/* ob_size */
+	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"int",					/* tp_name */
 	/* See _PyLong_New for why this isn't
 	   sizeof(PyLongObject) - sizeof(digit) */
@@ -3715,12 +3714,12 @@
 	PyLongObject *v = small_ints;
 	for (ival = -NSMALLNEGINTS; ival < 0; ival++, v++) {
 		PyObject_INIT(v, &PyLong_Type);
-		v->ob_size = -1;
+		Py_Size(v) = -1;
 		v->ob_digit[0] = -ival;
 	}
 	for (; ival < NSMALLPOSINTS; ival++, v++) {
 		PyObject_INIT(v, &PyLong_Type);
-		v->ob_size = ival ? 1 : 0;
+		Py_Size(v) = ival ? 1 : 0;
 		v->ob_digit[0] = ival;
 	}
 #endif