Skip to content

Commit 37a082a

Browse files
committed
Fetch native thread state for _PyErr_Occurred
1 parent d6b10b7 commit 37a082a

File tree

1 file changed

+14
-7
lines changed
  • graalpython/com.oracle.graal.python.cext/src

1 file changed

+14
-7
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "capi.h"
4242

4343
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
44+
#include "pycore_pyerrors.h" // _PyErr_Fetch()
45+
#include "pycore_pystate.h" // _PyThreadState_GET()
4446

4547
PyObject* PyEval_CallObjectWithKeywords(PyObject *func, PyObject *args, PyObject *kwargs) {
4648
return PyObject_Call(func, args, kwargs);
@@ -160,19 +162,24 @@ void Py_LeaveRecursiveCall(void)
160162
nb_index slot defined, and store in *pi.
161163
Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
162164
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) {
165+
Return 0 on error, 1 on success.
166+
*/
167+
int
168+
_PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
169+
{
170+
PyThreadState *tstate = _PyThreadState_GET();
171+
if (!Py_IsNone(v)) {
166172
Py_ssize_t x;
173+
// GraalPy change: don't use '_PyIndex_Check'
167174
if (PyIndex_Check(v)) {
168175
x = PyNumber_AsSsize_t(v, NULL);
169-
if (x == -1 && PyErr_Occurred())
176+
if (x == -1 && _PyErr_Occurred(tstate))
170177
return 0;
171178
}
172179
else {
173-
PyErr_SetString(PyExc_TypeError,
174-
"slice indices must be integers or "
175-
"None or have an __index__ method");
180+
_PyErr_SetString(tstate, PyExc_TypeError,
181+
"slice indices must be integers or "
182+
"None or have an __index__ method");
176183
return 0;
177184
}
178185
*pi = x;

0 commit comments

Comments
 (0)