[Python-checkins] [3.12] gh-106033: Get rid of PyDict_GetItem in _PyFunction_FromConstructor (GH-106044) (GH-106228)

serhiy-storchaka webhook-mailer at python.org
Thu Jun 29 06:45:43 EDT 2023


https://github.com/python/cpython/commit/e0fa531d7aa2f1e809dc77c222538620b2cf24b9
commit: e0fa531d7aa2f1e809dc77c222538620b2cf24b9
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2023-06-29T13:45:39+03:00
summary:

[3.12] gh-106033: Get rid of PyDict_GetItem in _PyFunction_FromConstructor (GH-106044) (GH-106228)

gh-106033: Get rid of PyDict_GetItem in _PyFunction_FromConstructor (GH-106044)
(cherry picked from commit 08c08d21b03d949452a77d9ed5e3cf48d6b9804d)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
M Objects/funcobject.c

diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 753038600aa85..f43e3a2787b84 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;



More information about the Python-checkins mailing list