aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/flowgraph.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/flowgraph.c')
-rw-r--r--Python/flowgraph.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index 719ed921050..e620e7cf1b9 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -2404,17 +2404,31 @@ build_cellfixedoffsets(_PyCompile_CodeUnitMetadata *umd)
PyObject *varname, *cellindex;
Py_ssize_t pos = 0;
while (PyDict_Next(umd->u_cellvars, &pos, &varname, &cellindex)) {
- PyObject *varindex = PyDict_GetItem(umd->u_varnames, varname);
- if (varindex != NULL) {
- assert(PyLong_AS_LONG(cellindex) < INT_MAX);
- assert(PyLong_AS_LONG(varindex) < INT_MAX);
- int oldindex = (int)PyLong_AS_LONG(cellindex);
- int argoffset = (int)PyLong_AS_LONG(varindex);
- fixed[oldindex] = argoffset;
+ PyObject *varindex;
+ if (PyDict_GetItemRef(umd->u_varnames, varname, &varindex) < 0) {
+ goto error;
+ }
+ if (varindex == NULL) {
+ continue;
+ }
+
+ int argoffset = _PyLong_AsInt(varindex);
+ Py_DECREF(varindex);
+ if (argoffset == -1 && PyErr_Occurred()) {
+ goto error;
}
- }
+ int oldindex = _PyLong_AsInt(cellindex);
+ if (oldindex == -1 && PyErr_Occurred()) {
+ goto error;
+ }
+ fixed[oldindex] = argoffset;
+ }
return fixed;
+
+error:
+ PyMem_Free(fixed);
+ return NULL;
}
#define IS_GENERATOR(CF) \