mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
gh-108308: Replace PyDict_GetItem() with PyDict_GetItemRef() (#108309)
Replace PyDict_GetItem() calls with PyDict_GetItemRef() or PyDict_GetItemWithError() to handle errors. * Replace PyLong_AS_LONG() with _PyLong_AsInt() and check for errors. * Check for PyDict_Contains() error. * pycore_init_builtins() checks for _PyType_Lookup() failure.
This commit is contained in:
parent
154477be72
commit
f5559f38d9
4 changed files with 105 additions and 32 deletions
|
@ -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) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue