gh-111789: Use PyDict_GetItemRef() in Objects/ (GH-111827)

This commit is contained in:
Serhiy Storchaka 2023-11-14 11:25:39 +02:00 committed by GitHub
parent e31d65e0b7
commit 18203a6bc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 120 deletions

View file

@ -92,8 +92,8 @@ PyFunction_ClearWatcher(int watcher_id)
PyFunctionObject *
_PyFunction_FromConstructor(PyFrameConstructor *constr)
{
PyObject *module = Py_XNewRef(PyDict_GetItemWithError(constr->fc_globals, &_Py_ID(__name__)));
if (!module && PyErr_Occurred()) {
PyObject *module;
if (PyDict_GetItemRef(constr->fc_globals, &_Py_ID(__name__), &module) < 0) {
return NULL;
}
@ -158,12 +158,11 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
Py_INCREF(doc);
// __module__: Use globals['__name__'] if it exists, or NULL.
PyObject *module = PyDict_GetItemWithError(globals, &_Py_ID(__name__));
PyObject *module;
PyObject *builtins = NULL;
if (module == NULL && _PyErr_Occurred(tstate)) {
if (PyDict_GetItemRef(globals, &_Py_ID(__name__), &module) < 0) {
goto error;
}
Py_XINCREF(module);
builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
if (builtins == NULL) {