[Python-checkins] CVS: python/dist/src/Python ceval.c,2.167,2.168

Andrew M. Kuchling akuchlin@CNRI.Reston.VA.US
Wed, 23 Feb 2000 17:18:52 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Python
In directory amarok:/home/akuchlin/src/Python-1.5/Python

Modified Files:
	ceval.c 
Log Message:
Allow using long integers as slice indexes


Index: ceval.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/ceval.c,v
retrieving revision 2.167
retrieving revision 2.168
diff -C2 -r2.167 -r2.168
*** ceval.c	2000/02/21 17:59:48	2.167
--- ceval.c	2000/02/23 22:18:48	2.168
***************
*** 2536,2545 ****
  	if (v != NULL) {
  		long x;
! 		if (!PyInt_Check(v)) {
  			PyErr_SetString(PyExc_TypeError,
  					"slice index must be int");
  			return -1;
  		}
- 		x = PyInt_AsLong(v);
  		/* Truncate -- very long indices are truncated anyway */
  		if (x > INT_MAX)
--- 2536,2577 ----
  	if (v != NULL) {
  		long x;
! 		if (PyInt_Check(v)) {
! 			x = PyInt_AsLong(v);
! 		} else if (PyLong_Check(v)) {
! 			x = PyLong_AsLong(v);
! 			if (x==-1 && PyErr_Occurred()) {
! 				PyObject *long_zero;
! 
! 				if (!PyErr_ExceptionMatches( PyExc_OverflowError ) ) {
! 					/* It's not an overflow error, so just 
! 					   signal an error */
! 					return -1;
! 				}
! 
! 				/* It's an overflow error, so we need to 
! 				   check the sign of the long integer, 
! 				   set the value to INT_MAX or 0, and clear 
! 				   the error. */
! 
! 				/* Create a long integer with a value of 0 */
! 				long_zero = PyLong_FromLong( 0L );
! 				if (long_zero == NULL) return -1;
! 
! 				/* Check sign */
! 				if (PyObject_Compare(long_zero, v) < 0)
! 					x = INT_MAX;
! 				else
! 					x = 0;
! 				
! 				/* Free the long integer we created, and clear the
! 				   OverflowError */
! 				Py_DECREF(long_zero);
! 				PyErr_Clear();
! 			}
! 		} else {
  			PyErr_SetString(PyExc_TypeError,
  					"slice index must be int");
  			return -1;
  		}
  		/* Truncate -- very long indices are truncated anyway */
  		if (x > INT_MAX)