@@ -3851,8 +3851,9 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
38513851}
38523852
38533853/* Extract a slice index from a PyInt or PyLong, and store in *pi.
3854- Silently reduce values larger than INT_MAX to INT_MAX, and silently
3855- boost values less than -INT_MAX to 0. Return 0 on error, 1 on success.
3854+ Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
3855+ and silently boost values less than -PY_SSIZE_T_MAX to 0.
3856+ Return 0 on error, 1 on success.
38563857*/
38573858/* Note: If v is NULL, return success without storing into *pi. This
38583859 is because_PyEval_SliceIndex() is called by apply_slice(), which can be
@@ -3862,11 +3863,11 @@ int
38623863_PyEval_SliceIndex (PyObject * v , Py_ssize_t * pi )
38633864{
38643865 if (v != NULL ) {
3865- long x ;
3866+ Py_ssize_t x ;
38663867 if (PyInt_Check (v )) {
38673868 x = PyInt_AsLong (v );
38683869 } else if (PyLong_Check (v )) {
3869- x = PyLong_AsLong (v );
3870+ x = PyInt_AsSsize_t (v );
38703871 if (x == -1 && PyErr_Occurred ()) {
38713872 PyObject * long_zero ;
38723873 int cmp ;
@@ -3883,8 +3884,8 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
38833884
38843885 /* It's an overflow error, so we need to
38853886 check the sign of the long integer,
3886- set the value to INT_MAX or -INT_MAX,
3887- and clear the error. */
3887+ set the value to PY_SSIZE_T_MAX or
3888+ -PY_SSIZE_T_MAX, and clear the error. */
38883889
38893890 /* Create a long integer with a value of 0 */
38903891 long_zero = PyLong_FromLong (0L );
@@ -3898,21 +3899,15 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
38983899 if (cmp < 0 )
38993900 return 0 ;
39003901 else if (cmp )
3901- x = INT_MAX ;
3902+ x = PY_SSIZE_T_MAX ;
39023903 else
3903- x = - INT_MAX ;
3904+ x = - PY_SSIZE_T_MAX ;
39043905 }
39053906 } else {
39063907 PyErr_SetString (PyExc_TypeError ,
39073908 "slice indices must be integers" );
39083909 return 0 ;
39093910 }
3910- /* Truncate -- very long indices are truncated anyway */
3911- /* XXX truncate by ssize maximum */
3912- if (x > INT_MAX )
3913- x = INT_MAX ;
3914- else if (x < - INT_MAX )
3915- x = - INT_MAX ;
39163911 * pi = x ;
39173912 }
39183913 return 1 ;
@@ -3928,7 +3923,7 @@ apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
39283923 PySequenceMethods * sq = tp -> tp_as_sequence ;
39293924
39303925 if (sq && sq -> sq_slice && ISINT (v ) && ISINT (w )) {
3931- Py_ssize_t ilow = 0 , ihigh = INT_MAX ;
3926+ Py_ssize_t ilow = 0 , ihigh = PY_SSIZE_T_MAX ;
39323927 if (!_PyEval_SliceIndex (v , & ilow ))
39333928 return NULL ;
39343929 if (!_PyEval_SliceIndex (w , & ihigh ))
@@ -3955,7 +3950,7 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
39553950 PySequenceMethods * sq = tp -> tp_as_sequence ;
39563951
39573952 if (sq && sq -> sq_slice && ISINT (v ) && ISINT (w )) {
3958- Py_ssize_t ilow = 0 , ihigh = INT_MAX ;
3953+ Py_ssize_t ilow = 0 , ihigh = PY_SSIZE_T_MAX ;
39593954 if (!_PyEval_SliceIndex (v , & ilow ))
39603955 return -1 ;
39613956 if (!_PyEval_SliceIndex (w , & ihigh ))
0 commit comments