Skip to content

Commit ac18665

Browse files
authored
ceval.c's GETITEM should have asserts, not set exceptions (GH-96518)
1 parent 9e55685 commit ac18665

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Python/ceval.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,15 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
733733
/* Tuple access macros */
734734

735735
#ifndef Py_DEBUG
736-
#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
736+
#define GETITEM(v, i) PyTuple_GET_ITEM((v), (i))
737737
#else
738-
#define GETITEM(v, i) PyTuple_GetItem((v), (i))
738+
static inline PyObject *
739+
GETITEM(PyObject *v, Py_ssize_t i) {
740+
assert(PyTuple_Check(v));
741+
assert(i >= 0);
742+
assert(i < PyTuple_GET_SIZE(v));
743+
return PyTuple_GET_ITEM(v, i);
744+
}
739745
#endif
740746

741747
/* Code access macros */

0 commit comments

Comments
 (0)