[Python-checkins] r42454 - in python/trunk: Objects/classobject.c Python/ceval.c

martin.v.loewis python-checkins at python.org
Fri Feb 17 16:57:42 CET 2006


Author: martin.v.loewis
Date: Fri Feb 17 16:57:41 2006
New Revision: 42454

Modified:
   python/trunk/Objects/classobject.c
   python/trunk/Python/ceval.c
Log:
Remove size constraints in SLICE opcodes.


Modified: python/trunk/Objects/classobject.c
==============================================================================
--- python/trunk/Objects/classobject.c	(original)
+++ python/trunk/Objects/classobject.c	Fri Feb 17 16:57:41 2006
@@ -1170,7 +1170,7 @@
 			return NULL;
 		arg = Py_BuildValue("(N)", sliceobj_from_intint(i, j));
 	} else
-		arg = Py_BuildValue("(ii)", i, j);
+		arg = Py_BuildValue("(nn)", i, j);
 
 	if (arg == NULL) {
 		Py_DECREF(func);
@@ -1241,7 +1241,7 @@
 			arg = Py_BuildValue("(N)",
 					    sliceobj_from_intint(i, j));
 		} else
-			arg = Py_BuildValue("(ii)", i, j);
+			arg = Py_BuildValue("(nn)", i, j);
 	}
 	else {
 		if (setslicestr == NULL)
@@ -1262,7 +1262,7 @@
 			arg = Py_BuildValue("(NO)",
 					    sliceobj_from_intint(i, j), value);
 		} else
-			arg = Py_BuildValue("(iiO)", i, j, value);
+			arg = Py_BuildValue("(nnO)", i, j, value);
 	}
 	if (arg == NULL) {
 		Py_DECREF(func);

Modified: python/trunk/Python/ceval.c
==============================================================================
--- python/trunk/Python/ceval.c	(original)
+++ python/trunk/Python/ceval.c	Fri Feb 17 16:57:41 2006
@@ -3851,8 +3851,9 @@
 }
 
 /* Extract a slice index from a PyInt or PyLong, and store in *pi.
-   Silently reduce values larger than INT_MAX to INT_MAX, and silently
-   boost values less than -INT_MAX to 0.  Return 0 on error, 1 on success.
+   Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX, 
+   and silently boost values less than -PY_SSIZE_T_MAX to 0.  
+   Return 0 on error, 1 on success.
 */
 /* Note:  If v is NULL, return success without storing into *pi.  This
    is because_PyEval_SliceIndex() is called by apply_slice(), which can be
@@ -3862,11 +3863,11 @@
 _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
 {
 	if (v != NULL) {
-		long x;
+		Py_ssize_t x;
 		if (PyInt_Check(v)) {
 			x = PyInt_AsLong(v);
 		} else if (PyLong_Check(v)) {
-			x = PyLong_AsLong(v);
+			x = PyInt_AsSsize_t(v);
 			if (x==-1 && PyErr_Occurred()) {
 				PyObject *long_zero;
 				int cmp;
@@ -3883,8 +3884,8 @@
 
 				/* It's an overflow error, so we need to
 				   check the sign of the long integer,
-				   set the value to INT_MAX or -INT_MAX,
-				   and clear the error. */
+				   set the value to PY_SSIZE_T_MAX or 
+				   -PY_SSIZE_T_MAX, and clear the error. */
 
 				/* Create a long integer with a value of 0 */
 				long_zero = PyLong_FromLong(0L);
@@ -3898,21 +3899,15 @@
 				if (cmp < 0)
 					return 0;
 				else if (cmp)
-					x = INT_MAX;
+					x = PY_SSIZE_T_MAX;
 				else
-					x = -INT_MAX;
+					x = -PY_SSIZE_T_MAX;
 			}
 		} else {
 			PyErr_SetString(PyExc_TypeError,
 					"slice indices must be integers");
 			return 0;
 		}
-		/* Truncate -- very long indices are truncated anyway */
-		/* XXX truncate by ssize maximum */
-		if (x > INT_MAX)
-			x = INT_MAX;
-		else if (x < -INT_MAX)
-			x = -INT_MAX;
 		*pi = x;
 	}
 	return 1;
@@ -3928,7 +3923,7 @@
 	PySequenceMethods *sq = tp->tp_as_sequence;
 
 	if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) {
-		Py_ssize_t ilow = 0, ihigh = INT_MAX;
+		Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
 		if (!_PyEval_SliceIndex(v, &ilow))
 			return NULL;
 		if (!_PyEval_SliceIndex(w, &ihigh))
@@ -3955,7 +3950,7 @@
 	PySequenceMethods *sq = tp->tp_as_sequence;
 
 	if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) {
-		Py_ssize_t ilow = 0, ihigh = INT_MAX;
+		Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
 		if (!_PyEval_SliceIndex(v, &ilow))
 			return -1;
 		if (!_PyEval_SliceIndex(w, &ihigh))


More information about the Python-checkins mailing list