@@ -80,7 +80,6 @@ static int call_trace Py_PROTO((PyObject **, PyObject **,
8080static PyObject * call_builtin Py_PROTO ((PyObject * , PyObject * , PyObject * ) );
8181static PyObject * call_function Py_PROTO ((PyObject * , PyObject * , PyObject * ) );
8282static PyObject * loop_subscript Py_PROTO ((PyObject * , PyObject * ) );
83- static int slice_index Py_PROTO ((PyObject * , int * ) );
8483static PyObject * apply_slice Py_PROTO ((PyObject * , PyObject * , PyObject * ) );
8584static int assign_slice Py_PROTO ((PyObject * , PyObject * ,
8685 PyObject * , PyObject * ) );
@@ -2587,8 +2586,12 @@ loop_subscript(v, w)
25872586 return NULL ;
25882587}
25892588
2590- static int
2591- slice_index (v , pi )
2589+ /* Extract a slice index from a PyInt or PyLong, the index is bound to
2590+ the range [-INT_MAX+1, INTMAX]. Returns 0 and an exception if there is
2591+ and error. Returns 1 on success.*/
2592+
2593+ int
2594+ _PyEval_SliceIndex (v , pi )
25922595 PyObject * v ;
25932596 int * pi ;
25942597{
@@ -2604,7 +2607,7 @@ slice_index(v, pi)
26042607 if (!PyErr_ExceptionMatches ( PyExc_OverflowError ) ) {
26052608 /* It's not an overflow error, so just
26062609 signal an error */
2607- return -1 ;
2610+ return 0 ;
26082611 }
26092612
26102613 /* It's an overflow error, so we need to
@@ -2614,7 +2617,7 @@ slice_index(v, pi)
26142617
26152618 /* Create a long integer with a value of 0 */
26162619 long_zero = PyLong_FromLong ( 0L );
2617- if (long_zero == NULL ) return -1 ;
2620+ if (long_zero == NULL ) return 0 ;
26182621
26192622 /* Check sign */
26202623 if (PyObject_Compare (long_zero , v ) < 0 )
@@ -2630,7 +2633,7 @@ slice_index(v, pi)
26302633 } else {
26312634 PyErr_SetString (PyExc_TypeError ,
26322635 "slice index must be int" );
2633- return -1 ;
2636+ return 0 ;
26342637 }
26352638 /* Truncate -- very long indices are truncated anyway */
26362639 if (x > INT_MAX )
@@ -2639,17 +2642,17 @@ slice_index(v, pi)
26392642 x = 0 ;
26402643 * pi = x ;
26412644 }
2642- return 0 ;
2645+ return 1 ;
26432646}
26442647
26452648static PyObject *
26462649apply_slice (u , v , w ) /* return u[v:w] */
26472650 PyObject * u , * v , * w ;
26482651{
26492652 int ilow = 0 , ihigh = INT_MAX ;
2650- if (slice_index (v , & ilow ) != 0 )
2653+ if (! _PyEval_SliceIndex (v , & ilow ))
26512654 return NULL ;
2652- if (slice_index (w , & ihigh ) != 0 )
2655+ if (! _PyEval_SliceIndex (w , & ihigh ))
26532656 return NULL ;
26542657 return PySequence_GetSlice (u , ilow , ihigh );
26552658}
@@ -2659,9 +2662,9 @@ assign_slice(u, v, w, x) /* u[v:w] = x */
26592662 PyObject * u , * v , * w , * x ;
26602663{
26612664 int ilow = 0 , ihigh = INT_MAX ;
2662- if (slice_index (v , & ilow ) != 0 )
2665+ if (! _PyEval_SliceIndex (v , & ilow ))
26632666 return -1 ;
2664- if (slice_index (w , & ihigh ) != 0 )
2667+ if (! _PyEval_SliceIndex (w , & ihigh ))
26652668 return -1 ;
26662669 if (x == NULL )
26672670 return PySequence_DelSlice (u , ilow , ihigh );
0 commit comments