[Python-checkins] ceval.c's GETITEM should have asserts, not set exceptions (GH-96518)
sweeneyde
webhook-mailer at python.org
Sun Sep 4 19:00:32 EDT 2022
https://github.com/python/cpython/commit/ac1866547243ade5392ed9bc6e7989f4d4346594
commit: ac1866547243ade5392ed9bc6e7989f4d4346594
branch: main
author: Dennis Sweeney <36520290+sweeneyde at users.noreply.github.com>
committer: sweeneyde <36520290+sweeneyde at users.noreply.github.com>
date: 2022-09-04T19:00:24-04:00
summary:
ceval.c's GETITEM should have asserts, not set exceptions (GH-96518)
files:
M Python/ceval.c
diff --git a/Python/ceval.c b/Python/ceval.c
index 76a81185e76d..c2fa90853592 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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 */
More information about the Python-checkins
mailing list