]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
ceval.c's GETITEM should have asserts, not set exceptions (GH-96518)
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Sun, 4 Sep 2022 23:00:24 +0000 (19:00 -0400)
committerGitHub <noreply@github.com>
Sun, 4 Sep 2022 23:00:24 +0000 (19:00 -0400)
Python/ceval.c

index 76a81185e76da57a8a16ad90c9105c213b7caadb..c2fa90853592df3c3e656708341b153d0051b702 100644 (file)
@@ -733,9 +733,15 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
 /* Tuple access macros */
 
 #ifndef Py_DEBUG
-#define GETITEM(v, i) PyTuple_GET_ITEM((PyTupleObject *)(v), (i))
+#define GETITEM(v, i) PyTuple_GET_ITEM((v), (i))
 #else
-#define GETITEM(v, i) PyTuple_GetItem((v), (i))
+static inline PyObject *
+GETITEM(PyObject *v, Py_ssize_t i) {
+    assert(PyTuple_Check(v));
+    assert(i >= 0);
+    assert(i < PyTuple_GET_SIZE(v));
+    return PyTuple_GET_ITEM(v, i);
+}
 #endif
 
 /* Code access macros */