summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-06-29 09:31:08 (GMT)
committerGitHub <noreply@github.com>2023-06-29 09:31:08 (GMT)
commit08c08d21b03d949452a77d9ed5e3cf48d6b9804d (patch)
treef6976c8c9a954bd6d3863636548c0325db8ce1b0 /Objects
parent8bf6904b229583033035d91a3800da5604dcaad4 (diff)
downloadcpython-08c08d21b03d949452a77d9ed5e3cf48d6b9804d.zip
cpython-08c08d21b03d949452a77d9ed5e3cf48d6b9804d.tar.gz
cpython-08c08d21b03d949452a77d9ed5e3cf48d6b9804d.tar.bz2
gh-106033: Get rid of PyDict_GetItem in _PyFunction_FromConstructor (GH-106044)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/funcobject.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 7530386..f43e3a2 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -106,9 +106,14 @@ 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()) {
+ return NULL;
+ }
PyFunctionObject *op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type);
if (op == NULL) {
+ Py_XDECREF(module);
return NULL;
}
op->func_globals = Py_NewRef(constr->fc_globals);
@@ -122,10 +127,7 @@ _PyFunction_FromConstructor(PyFrameConstructor *constr)
op->func_doc = Py_NewRef(Py_None);
op->func_dict = NULL;
op->func_weakreflist = NULL;
- op->func_module = Py_XNewRef(PyDict_GetItem(op->func_globals, &_Py_ID(__name__)));
- if (!op->func_module) {
- PyErr_Clear();
- }
+ op->func_module = module;
op->func_annotations = NULL;
op->func_typeparams = NULL;
op->vectorcall = _PyFunction_Vectorcall;