Merge ssize_t branch.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 8ba317a..41f7390 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -22,11 +22,11 @@
  * than ob_size on entry.
  */
 static int
-list_resize(PyListObject *self, int newsize)
+list_resize(PyListObject *self, Py_ssize_t newsize)
 {
 	PyObject **items;
 	size_t new_allocated;
-	int allocated = self->allocated;
+	Py_ssize_t allocated = self->allocated;
 
 	/* Bypass realloc() when a previous overallocation is large enough
 	   to accommodate the newsize.  If the newsize falls lower than half
@@ -82,7 +82,7 @@
 }
 
 PyObject *
-PyList_New(int size)
+PyList_New(Py_ssize_t size)
 {
 	PyListObject *op;
 	size_t nbytes;
@@ -118,7 +118,7 @@
 	return (PyObject *) op;
 }
 
-int
+Py_ssize_t
 PyList_Size(PyObject *op)
 {
 	if (!PyList_Check(op)) {
@@ -132,7 +132,7 @@
 static PyObject *indexerr = NULL;
 
 PyObject *
-PyList_GetItem(PyObject *op, int i)
+PyList_GetItem(PyObject *op, Py_ssize_t i)
 {
 	if (!PyList_Check(op)) {
 		PyErr_BadInternalCall();
@@ -149,7 +149,7 @@
 }
 
 int
-PyList_SetItem(register PyObject *op, register int i,
+PyList_SetItem(register PyObject *op, register Py_ssize_t i,
                register PyObject *newitem)
 {
 	register PyObject *olditem;
@@ -173,9 +173,9 @@
 }
 
 static int
-ins1(PyListObject *self, int where, PyObject *v)
+ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
 {
-	int i, n = self->ob_size;
+	Py_ssize_t i, n = self->ob_size;
 	PyObject **items;
 	if (v == NULL) {
 		PyErr_BadInternalCall();
@@ -206,7 +206,7 @@
 }
 
 int
-PyList_Insert(PyObject *op, int where, PyObject *newitem)
+PyList_Insert(PyObject *op, Py_ssize_t where, PyObject *newitem)
 {
 	if (!PyList_Check(op)) {
 		PyErr_BadInternalCall();
@@ -218,7 +218,7 @@
 static int
 app1(PyListObject *self, PyObject *v)
 {
-	int n = PyList_GET_SIZE(self);
+	Py_ssize_t n = PyList_GET_SIZE(self);
 
 	assert (v != NULL);
 	if (n == INT_MAX) {
@@ -249,7 +249,7 @@
 static void
 list_dealloc(PyListObject *op)
 {
-	int i;
+	Py_ssize_t i;
 	PyObject_GC_UnTrack(op);
 	Py_TRASHCAN_SAFE_BEGIN(op)
 	if (op->ob_item != NULL) {
@@ -273,12 +273,13 @@
 static int
 list_print(PyListObject *op, FILE *fp, int flags)
 {
-	int i;
+	int rc;
+	Py_ssize_t i;
 
-	i = Py_ReprEnter((PyObject*)op);
-	if (i != 0) {
-		if (i < 0)
-			return i;
+	rc = Py_ReprEnter((PyObject*)op);
+	if (rc != 0) {
+		if (rc < 0)
+			return rc;
 		fprintf(fp, "[...]");
 		return 0;
 	}
@@ -299,7 +300,7 @@
 static PyObject *
 list_repr(PyListObject *v)
 {
-	int i;
+	Py_ssize_t i;
 	PyObject *s, *temp;
 	PyObject *pieces = NULL, *result = NULL;
 
@@ -363,7 +364,7 @@
 	return result;
 }
 
-static int
+static Py_ssize_t
 list_length(PyListObject *a)
 {
 	return a->ob_size;
@@ -372,7 +373,8 @@
 static int
 list_contains(PyListObject *a, PyObject *el)
 {
-	int i, cmp;
+	Py_ssize_t i;
+	int cmp;
 
 	for (i = 0, cmp = 0 ; cmp == 0 && i < a->ob_size; ++i)
 		cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i),
@@ -381,7 +383,7 @@
 }
 
 static PyObject *
-list_item(PyListObject *a, int i)
+list_item(PyListObject *a, Py_ssize_t i)
 {
 	if (i < 0 || i >= a->ob_size) {
 		if (indexerr == NULL)
@@ -395,11 +397,11 @@
 }
 
 static PyObject *
-list_slice(PyListObject *a, int ilow, int ihigh)
+list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
 {
 	PyListObject *np;
 	PyObject **src, **dest;
-	int i, len;
+	Py_ssize_t i, len;
 	if (ilow < 0)
 		ilow = 0;
 	else if (ilow > a->ob_size)
@@ -424,7 +426,7 @@
 }
 
 PyObject *
-PyList_GetSlice(PyObject *a, int ilow, int ihigh)
+PyList_GetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
 {
 	if (!PyList_Check(a)) {
 		PyErr_BadInternalCall();
@@ -436,8 +438,8 @@
 static PyObject *
 list_concat(PyListObject *a, PyObject *bb)
 {
-	int size;
-	int i;
+	Py_ssize_t size;
+	Py_ssize_t i;
 	PyObject **src, **dest;
 	PyListObject *np;
 	if (!PyList_Check(bb)) {
@@ -473,10 +475,10 @@
 }
 
 static PyObject *
-list_repeat(PyListObject *a, int n)
+list_repeat(PyListObject *a, Py_ssize_t n)
 {
-	int i, j;
-	int size;
+	Py_ssize_t i, j;
+	Py_ssize_t size;
 	PyListObject *np;
 	PyObject **p, **items;
 	PyObject *elem;
@@ -515,7 +517,7 @@
 static int
 list_clear(PyListObject *a)
 {
-	int i;
+	Py_ssize_t i;
 	PyObject **item = a->ob_item;
 	if (item != NULL) {
 		/* Because XDECREF can recursively invoke operations on
@@ -542,7 +544,7 @@
  * guaranteed the call cannot fail.
  */
 static int
-list_ass_slice(PyListObject *a, int ilow, int ihigh, PyObject *v)
+list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
 {
 	/* Because [X]DECREF can recursively invoke list operations on
 	   this list, we must postpone all [X]DECREF activity until
@@ -555,10 +557,10 @@
 	PyObject **item;
 	PyObject **vitem = NULL;
 	PyObject *v_as_SF = NULL; /* PySequence_Fast(v) */
-	int n; /* # of elements in replacement list */
-	int norig; /* # of elements in list getting replaced */
-	int d; /* Change in size */
-	int k;
+	Py_ssize_t n; /* # of elements in replacement list */
+	Py_ssize_t norig; /* # of elements in list getting replaced */
+	Py_ssize_t d; /* Change in size */
+	Py_ssize_t k;
 	size_t s;
 	int result = -1;	/* guilty until proved innocent */
 #define b ((PyListObject *)v)
@@ -640,7 +642,7 @@
 }
 
 int
-PyList_SetSlice(PyObject *a, int ilow, int ihigh, PyObject *v)
+PyList_SetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
 {
 	if (!PyList_Check(a)) {
 		PyErr_BadInternalCall();
@@ -650,10 +652,10 @@
 }
 
 static PyObject *
-list_inplace_repeat(PyListObject *self, int n)
+list_inplace_repeat(PyListObject *self, Py_ssize_t n)
 {
 	PyObject **items;
-	int size, i, j, p;
+	Py_ssize_t size, i, j, p;
 
 
 	size = PyList_GET_SIZE(self);
@@ -685,7 +687,7 @@
 }
 
 static int
-list_ass_item(PyListObject *a, int i, PyObject *v)
+list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v)
 {
 	PyObject *old_value;
 	if (i < 0 || i >= a->ob_size) {
@@ -705,9 +707,9 @@
 static PyObject *
 listinsert(PyListObject *self, PyObject *args)
 {
-	int i;
+	Py_ssize_t i;
 	PyObject *v;
-	if (!PyArg_ParseTuple(args, "iO:insert", &i, &v))
+	if (!PyArg_ParseTuple(args, "nO:insert", &i, &v))
 		return NULL;
 	if (ins1(self, i, v) == 0)
 		Py_RETURN_NONE;
@@ -726,10 +728,10 @@
 listextend(PyListObject *self, PyObject *b)
 {
 	PyObject *it;      /* iter(v) */
-	int m;		   /* size of self */
-	int n;		   /* guess for size of b */
-	int mn;		   /* m + n */
-	int i;
+	Py_ssize_t m;		   /* size of self */
+	Py_ssize_t n;		   /* guess for size of b */
+	Py_ssize_t mn;		   /* m + n */
+	Py_ssize_t i;
 	PyObject *(*iternext)(PyObject *);
 
 	/* Special cases:
@@ -858,7 +860,7 @@
 static PyObject *
 listpop(PyListObject *self, PyObject *args)
 {
-	int i = -1;
+	Py_ssize_t i = -1;
 	PyObject *v, *arg = NULL;
 	int status;
 
@@ -866,8 +868,8 @@
 		return NULL;
 	if (arg != NULL) {
 		if (PyInt_Check(arg))
-			i = (int)(PyInt_AS_LONG((PyIntObject*) arg));
-		else if (!PyArg_ParseTuple(args, "|i:pop", &i))
+			i = PyInt_AS_LONG((PyIntObject*) arg);
+		else if (!PyArg_ParseTuple(args, "|n:pop", &i))
    			return NULL;
 	}
 	if (self->ob_size == 0) {
@@ -929,7 +931,7 @@
 {
 	PyObject *res;
 	PyObject *args;
-	int i;
+	Py_ssize_t i;
 
 	assert(compare != NULL);
 	/* Call the user's comparison function and translate the 3-way
@@ -988,7 +990,7 @@
 binarysort(PyObject **lo, PyObject **hi, PyObject **start, PyObject *compare)
      /* compare -- comparison function object, or NULL for default */
 {
-	register int k;
+	register Py_ssize_t k;
 	register PyObject **l, **p, **r;
 	register PyObject *pivot;
 
@@ -1050,11 +1052,11 @@
 
 Returns -1 in case of error.
 */
-static int
+static Py_ssize_t
 count_run(PyObject **lo, PyObject **hi, PyObject *compare, int *descending)
 {
-	int k;
-	int n;
+	Py_ssize_t k;
+	Py_ssize_t n;
 
 	assert(lo < hi);
 	*descending = 0;
@@ -1105,12 +1107,12 @@
 
 Returns -1 on error.  See listsort.txt for info on the method.
 */
-static int
-gallop_left(PyObject *key, PyObject **a, int n, int hint, PyObject *compare)
+static Py_ssize_t
+gallop_left(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint, PyObject *compare)
 {
-	int ofs;
-	int lastofs;
-	int k;
+	Py_ssize_t ofs;
+	Py_ssize_t lastofs;
+	Py_ssize_t k;
 
 	assert(key && a && n > 0 && hint >= 0 && hint < n);
 
@@ -1121,7 +1123,7 @@
 		/* a[hint] < key -- gallop right, until
 		 * a[hint + lastofs] < key <= a[hint + ofs]
 		 */
-		const int maxofs = n - hint;	/* &a[n-1] is highest */
+		const Py_ssize_t maxofs = n - hint;	/* &a[n-1] is highest */
 		while (ofs < maxofs) {
 			IFLT(a[ofs], key) {
 				lastofs = ofs;
@@ -1142,7 +1144,7 @@
 		/* key <= a[hint] -- gallop left, until
 		 * a[hint - ofs] < key <= a[hint - lastofs]
 		 */
-		const int maxofs = hint + 1;	/* &a[0] is lowest */
+		const Py_ssize_t maxofs = hint + 1;	/* &a[0] is lowest */
 		while (ofs < maxofs) {
 			IFLT(*(a-ofs), key)
 				break;
@@ -1168,7 +1170,7 @@
 	 */
 	++lastofs;
 	while (lastofs < ofs) {
-		int m = lastofs + ((ofs - lastofs) >> 1);
+		Py_ssize_t m = lastofs + ((ofs - lastofs) >> 1);
 
 		IFLT(a[m], key)
 			lastofs = m+1;	/* a[m] < key */
@@ -1196,12 +1198,12 @@
 we're sticking to "<" comparisons that it's much harder to follow if
 written as one routine with yet another "left or right?" flag.
 */
-static int
-gallop_right(PyObject *key, PyObject **a, int n, int hint, PyObject *compare)
+static Py_ssize_t
+gallop_right(PyObject *key, PyObject **a, Py_ssize_t n, Py_ssize_t hint, PyObject *compare)
 {
-	int ofs;
-	int lastofs;
-	int k;
+	Py_ssize_t ofs;
+	Py_ssize_t lastofs;
+	Py_ssize_t k;
 
 	assert(key && a && n > 0 && hint >= 0 && hint < n);
 
@@ -1212,7 +1214,7 @@
 		/* key < a[hint] -- gallop left, until
 		 * a[hint - ofs] <= key < a[hint - lastofs]
 		 */
-		const int maxofs = hint + 1;	/* &a[0] is lowest */
+		const Py_ssize_t maxofs = hint + 1;	/* &a[0] is lowest */
 		while (ofs < maxofs) {
 			IFLT(key, *(a-ofs)) {
 				lastofs = ofs;
@@ -1234,7 +1236,7 @@
 		/* a[hint] <= key -- gallop right, until
 		 * a[hint + lastofs] <= key < a[hint + ofs]
 		*/
-		const int maxofs = n - hint;	/* &a[n-1] is highest */
+		const Py_ssize_t maxofs = n - hint;	/* &a[n-1] is highest */
 		while (ofs < maxofs) {
 			IFLT(key, a[ofs])
 				break;
@@ -1259,7 +1261,7 @@
 	 */
 	++lastofs;
 	while (lastofs < ofs) {
-		int m = lastofs + ((ofs - lastofs) >> 1);
+		Py_ssize_t m = lastofs + ((ofs - lastofs) >> 1);
 
 		IFLT(key, a[m])
 			ofs = m;	/* key < a[m] */
@@ -1294,7 +1296,7 @@
  */
 struct s_slice {
 	PyObject **base;
-	int len;
+	Py_ssize_t len;
 };
 
 typedef struct s_MergeState {
@@ -1305,13 +1307,13 @@
 	 * to MIN_GALLOP.  merge_lo and merge_hi tend to nudge it higher for
 	 * random data, and lower for highly structured data.
 	 */
-	int min_gallop;
+	Py_ssize_t min_gallop;
 
 	/* 'a' is temp storage to help with merges.  It contains room for
 	 * alloced entries.
 	 */
 	PyObject **a;	/* may point to temparray below */
-	int alloced;
+	Py_ssize_t alloced;
 
 	/* A stack of n pending runs yet to be merged.  Run #i starts at
 	 * address base[i] and extends for len[i] elements.  It's always
@@ -1359,7 +1361,7 @@
  * Returns 0 on success and -1 if the memory can't be gotten.
  */
 static int
-merge_getmem(MergeState *ms, int need)
+merge_getmem(MergeState *ms, Py_ssize_t need)
 {
 	assert(ms != NULL);
 	if (need <= ms->alloced)
@@ -1386,14 +1388,15 @@
  * merge, and should have na <= nb.  See listsort.txt for more info.
  * Return 0 if successful, -1 if error.
  */
-static int
-merge_lo(MergeState *ms, PyObject **pa, int na, PyObject **pb, int nb)
+static Py_ssize_t
+merge_lo(MergeState *ms, PyObject **pa, Py_ssize_t na,
+                         PyObject **pb, Py_ssize_t nb)
 {
-	int k;
+	Py_ssize_t k;
 	PyObject *compare;
 	PyObject **dest;
 	int result = -1;	/* guilty until proved innocent */
-	int min_gallop = ms->min_gallop;
+	Py_ssize_t min_gallop = ms->min_gallop;
 
 	assert(ms && pa && pb && na > 0 && nb > 0 && pa + na == pb);
 	if (MERGE_GETMEM(ms, na) < 0)
@@ -1411,8 +1414,8 @@
 
 	compare = ms->compare;
 	for (;;) {
-		int acount = 0;	/* # of times A won in a row */
-		int bcount = 0;	/* # of times B won in a row */
+		Py_ssize_t acount = 0;	/* # of times A won in a row */
+		Py_ssize_t bcount = 0;	/* # of times B won in a row */
 
 		/* Do the straightforward thing until (if ever) one run
 		 * appears to win consistently.
@@ -1517,16 +1520,16 @@
  * merge, and should have na >= nb.  See listsort.txt for more info.
  * Return 0 if successful, -1 if error.
  */
-static int
-merge_hi(MergeState *ms, PyObject **pa, int na, PyObject **pb, int nb)
+static Py_ssize_t
+merge_hi(MergeState *ms, PyObject **pa, Py_ssize_t na, PyObject **pb, Py_ssize_t nb)
 {
-	int k;
+	Py_ssize_t k;
 	PyObject *compare;
 	PyObject **dest;
 	int result = -1;	/* guilty until proved innocent */
 	PyObject **basea;
 	PyObject **baseb;
-	int min_gallop = ms->min_gallop;
+	Py_ssize_t min_gallop = ms->min_gallop;
 
 	assert(ms && pa && pb && na > 0 && nb > 0 && pa + na == pb);
 	if (MERGE_GETMEM(ms, nb) < 0)
@@ -1547,8 +1550,8 @@
 
 	compare = ms->compare;
 	for (;;) {
-		int acount = 0;	/* # of times A won in a row */
-		int bcount = 0;	/* # of times B won in a row */
+		Py_ssize_t acount = 0;	/* # of times A won in a row */
+		Py_ssize_t bcount = 0;	/* # of times B won in a row */
 
 		/* Do the straightforward thing until (if ever) one run
 		 * appears to win consistently.
@@ -1654,12 +1657,12 @@
 /* Merge the two runs at stack indices i and i+1.
  * Returns 0 on success, -1 on error.
  */
-static int
-merge_at(MergeState *ms, int i)
+static Py_ssize_t
+merge_at(MergeState *ms, Py_ssize_t i)
 {
 	PyObject **pa, **pb;
-	int na, nb;
-	int k;
+	Py_ssize_t na, nb;
+	Py_ssize_t k;
 	PyObject *compare;
 
 	assert(ms != NULL);
@@ -1728,7 +1731,7 @@
 
 	assert(ms);
 	while (ms->n > 1) {
-		int n = ms->n - 2;
+		Py_ssize_t n = ms->n - 2;
 		if (n > 0 && p[n-1].len <= p[n].len + p[n+1].len) {
 		    	if (p[n-1].len < p[n+1].len)
 		    		--n;
@@ -1757,7 +1760,7 @@
 
 	assert(ms);
 	while (ms->n > 1) {
-		int n = ms->n - 2;
+		Py_ssize_t n = ms->n - 2;
 		if (n > 0 && p[n-1].len < p[n+1].len)
 			--n;
 		if (merge_at(ms, n) < 0)
@@ -1776,10 +1779,10 @@
  *
  * See listsort.txt for more info.
  */
-static int
-merge_compute_minrun(int n)
+static Py_ssize_t
+merge_compute_minrun(Py_ssize_t n)
 {
-	int r = 0;	/* becomes 1 if any 1 bits are shifted off */
+	Py_ssize_t r = 0;	/* becomes 1 if any 1 bits are shifted off */
 
 	assert(n >= 0);
 	while (n >= 64) {
@@ -1972,16 +1975,16 @@
 {
 	MergeState ms;
 	PyObject **lo, **hi;
-	int nremaining;
-	int minrun;
-	int saved_ob_size, saved_allocated;
+	Py_ssize_t nremaining;
+	Py_ssize_t minrun;
+	Py_ssize_t saved_ob_size, saved_allocated;
 	PyObject **saved_ob_item;
 	PyObject **final_ob_item;
 	PyObject *compare = NULL;
 	PyObject *result = NULL;	/* guilty until proved innocent */
 	int reverse = 0;
 	PyObject *keyfunc = NULL;
-	int i;
+	Py_ssize_t i;
 	PyObject *key, *value, *kvpair;
 	static const char *kwlist[] = {"cmp", "key", "reverse", 0};
 
@@ -2055,7 +2058,7 @@
 	minrun = merge_compute_minrun(nremaining);
 	do {
 		int descending;
-		int n;
+		Py_ssize_t n;
 
 		/* Identify next run. */
 		n = count_run(lo, hi, compare, &descending);
@@ -2065,7 +2068,7 @@
 			reverse_slice(lo, lo + n);
 		/* If short, extend to min(minrun, nremaining). */
 		if (n < minrun) {
-			const int force = nremaining <= minrun ?
+			const Py_ssize_t force = nremaining <= minrun ?
 	 			  	  nremaining : minrun;
 			if (binarysort(lo, lo + force, lo + n, compare) < 0)
 				goto fail;
@@ -2177,7 +2180,7 @@
 {
 	PyObject *w;
 	PyObject **p;
-	int n;
+	Py_ssize_t n;
 	if (v == NULL || !PyList_Check(v)) {
 		PyErr_BadInternalCall();
 		return NULL;
@@ -2200,7 +2203,7 @@
 static PyObject *
 listindex(PyListObject *self, PyObject *args)
 {
-	int i, start=0, stop=self->ob_size;
+	Py_ssize_t i, start=0, stop=self->ob_size;
 	PyObject *v;
 
 	if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
@@ -2220,7 +2223,7 @@
 	for (i = start; i < stop && i < self->ob_size; i++) {
 		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
 		if (cmp > 0)
-			return PyInt_FromLong((long)i);
+			return PyInt_FromSsize_t(i);
 		else if (cmp < 0)
 			return NULL;
 	}
@@ -2231,8 +2234,8 @@
 static PyObject *
 listcount(PyListObject *self, PyObject *v)
 {
-	int count = 0;
-	int i;
+	Py_ssize_t count = 0;
+	Py_ssize_t i;
 
 	for (i = 0; i < self->ob_size; i++) {
 		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
@@ -2241,13 +2244,13 @@
 		else if (cmp < 0)
 			return NULL;
 	}
-	return PyInt_FromLong((long)count);
+	return PyInt_FromSsize_t(count);
 }
 
 static PyObject *
 listremove(PyListObject *self, PyObject *v)
 {
-	int i;
+	Py_ssize_t i;
 
 	for (i = 0; i < self->ob_size; i++) {
 		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
@@ -2267,13 +2270,13 @@
 static int
 list_traverse(PyListObject *o, visitproc visit, void *arg)
 {
-	int i, err;
+	Py_ssize_t i;
 	PyObject *x;
 
 	for (i = o->ob_size; --i >= 0; ) {
 		x = o->ob_item[i];
 		if (x != NULL) {
-			err = visit(x, arg);
+			int err = visit(x, arg);
 			if (err)
 				return err;
 		}
@@ -2285,7 +2288,7 @@
 list_richcompare(PyObject *v, PyObject *w, int op)
 {
 	PyListObject *vl, *wl;
-	int i;
+	Py_ssize_t i;
 
 	if (!PyList_Check(v) || !PyList_Check(w)) {
 		Py_INCREF(Py_NotImplemented);
@@ -2318,8 +2321,8 @@
 
 	if (i >= vl->ob_size || i >= wl->ob_size) {
 		/* No more items to compare -- compare sizes */
-		int vs = vl->ob_size;
-		int ws = wl->ob_size;
+		Py_ssize_t vs = vl->ob_size;
+		Py_ssize_t ws = wl->ob_size;
 		int cmp;
 		PyObject *res;
 		switch (op) {
@@ -2433,16 +2436,16 @@
 };
 
 static PySequenceMethods list_as_sequence = {
-	(inquiry)list_length,			/* sq_length */
+	(lenfunc)list_length,			/* sq_length */
 	(binaryfunc)list_concat,		/* sq_concat */
-	(intargfunc)list_repeat,		/* sq_repeat */
-	(intargfunc)list_item,			/* sq_item */
-	(intintargfunc)list_slice,		/* sq_slice */
-	(intobjargproc)list_ass_item,		/* sq_ass_item */
-	(intintobjargproc)list_ass_slice,	/* sq_ass_slice */
+	(ssizeargfunc)list_repeat,		/* sq_repeat */
+	(ssizeargfunc)list_item,		/* sq_item */
+	(ssizessizeargfunc)list_slice,		/* sq_slice */
+	(ssizeobjargproc)list_ass_item,		/* sq_ass_item */
+	(ssizessizeobjargproc)list_ass_slice,	/* sq_ass_slice */
 	(objobjproc)list_contains,		/* sq_contains */
 	(binaryfunc)list_inplace_concat,	/* sq_inplace_concat */
-	(intargfunc)list_inplace_repeat,	/* sq_inplace_repeat */
+	(ssizeargfunc)list_inplace_repeat,	/* sq_inplace_repeat */
 };
 
 PyDoc_STRVAR(list_doc,
@@ -2452,14 +2455,8 @@
 static PyObject *
 list_subscript(PyListObject* self, PyObject* item)
 {
-	if (PyInt_Check(item)) {
-		long i = PyInt_AS_LONG(item);
-		if (i < 0)
-			i += PyList_GET_SIZE(self);
-		return list_item(self, i);
-	}
-	else if (PyLong_Check(item)) {
-		long i = PyLong_AsLong(item);
+	if (PyInt_Check(item) || PyLong_Check(item)) {
+		Py_ssize_t i = PyInt_AsSsize_t(item);
 		if (i == -1 && PyErr_Occurred())
 			return NULL;
 		if (i < 0)
@@ -2467,7 +2464,7 @@
 		return list_item(self, i);
 	}
 	else if (PySlice_Check(item)) {
-		int start, stop, step, slicelength, cur, i;
+		Py_ssize_t start, stop, step, slicelength, cur, i;
 		PyObject* result;
 		PyObject* it;
 		PyObject **src, **dest;
@@ -2521,7 +2518,7 @@
 		return list_ass_item(self, i, value);
 	}
 	else if (PySlice_Check(item)) {
-		int start, stop, step, slicelength;
+		Py_ssize_t start, stop, step, slicelength;
 
 		if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
 				 &start, &stop, &step, &slicelength) < 0) {
@@ -2535,7 +2532,7 @@
 		if (value == NULL) {
 			/* delete slice */
 			PyObject **garbage;
-			int cur, i;
+			Py_ssize_t cur, i;
 
 			if (slicelength <= 0)
 				return 0;
@@ -2554,7 +2551,7 @@
 			for (cur = start, i = 0;
 			     cur < stop;
 			     cur += step, i++) {
-				int lim = step;
+				Py_ssize_t lim = step;
 
 				garbage[i] = PyList_GET_ITEM(self, cur);
 
@@ -2586,7 +2583,7 @@
 		else {
 			/* assign slice */
 			PyObject **garbage, *ins, *seq, **seqitems, **selfitems;
-			int cur, i;
+			Py_ssize_t cur, i;
 
 			/* protect against a[::-1] = a */
 			if (self == (PyListObject*)value) {
@@ -2601,8 +2598,9 @@
 			}
 
 			if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
+				/* XXX can we use %zd here? */
 				PyErr_Format(PyExc_ValueError,
-            "attempt to assign sequence of size %d to extended slice of size %d",
+            "attempt to assign sequence of size %ld to extended slice of size %ld",
 					     PySequence_Fast_GET_SIZE(seq),
 					     slicelength);
 				Py_DECREF(seq);
@@ -2645,7 +2643,7 @@
 }
 
 static PyMappingMethods list_as_mapping = {
-	(inquiry)list_length,
+	(lenfunc)list_length,
 	(binaryfunc)list_subscript,
 	(objobjargproc)list_ass_subscript
 };
@@ -2767,11 +2765,11 @@
 static PyObject *
 listiter_len(listiterobject *it)
 {
-	int len;
+	Py_ssize_t len;
 	if (it->it_seq) {
 		len = PyList_GET_SIZE(it->it_seq) - it->it_index;
 		if (len >= 0)
-			return PyInt_FromLong((long)len);
+			return PyInt_FromSsize_t(len);
 	}
 	return PyInt_FromLong(0);
 }
@@ -2880,17 +2878,17 @@
 	return NULL;
 }
 
-static int
+static Py_ssize_t
 listreviter_len(listreviterobject *it)
 {
-	int len = it->it_index + 1;
+	Py_ssize_t len = it->it_index + 1;
 	if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len)
 		return 0;
 	return len;
 }
 
 static PySequenceMethods listreviter_as_sequence = {
-	(inquiry)listreviter_len,	/* sq_length */
+	(lenfunc)listreviter_len,	/* sq_length */
 	0,				/* sq_concat */
 };