Skip to content

Commit

Permalink
pythongh-106033: Get rid of PyDict_GetItem in _PyFunction_FromConstru…
Browse files Browse the repository at this point in the history
…ctor
  • Loading branch information
serhiy-storchaka committed Jun 23, 2023
1 parent 1d33d53 commit 857ec72
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ 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) {
Expand All @@ -122,10 +126,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;
Expand Down

0 comments on commit 857ec72

Please sign in to comment.