Skip to content

Commit a4226f5

Browse files
committed
Sync sliceobject.c with CPython
1 parent 3ff8e45 commit a4226f5

File tree

2 files changed

+620
-28
lines changed

2 files changed

+620
-28
lines changed

graalpython/com.oracle.graal.python.cext/src/ceval.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,27 @@ void Py_LeaveRecursiveCall(void)
155155
{
156156
_Py_LeaveRecursiveCall();
157157
}
158+
159+
/* Extract a slice index from a PyLong or an object with the
160+
nb_index slot defined, and store in *pi.
161+
Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
162+
and silently boost values less than PY_SSIZE_T_MIN to PY_SSIZE_T_MIN.
163+
Return 0 on error, 1 on success. */
164+
int _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi) {
165+
if (v != Py_None) {
166+
Py_ssize_t x;
167+
if (PyIndex_Check(v)) {
168+
x = PyNumber_AsSsize_t(v, NULL);
169+
if (x == -1 && PyErr_Occurred())
170+
return 0;
171+
}
172+
else {
173+
PyErr_SetString(PyExc_TypeError,
174+
"slice indices must be integers or "
175+
"None or have an __index__ method");
176+
return 0;
177+
}
178+
*pi = x;
179+
}
180+
return 1;
181+
}

0 commit comments

Comments
 (0)