diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-07-22 21:04:55 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-07-22 21:04:55 (GMT) |
commit | 34f96b8dd35dd4339db86f18beeccfbec124df1a (patch) | |
tree | e0bb15288db16b790b25408f344160f495104ce8 /Objects/funcobject.c | |
parent | 4d1f5d6eee2864476c3042d7941e126b2c8a9c21 (diff) | |
download | cpython-34f96b8dd35dd4339db86f18beeccfbec124df1a.zip cpython-34f96b8dd35dd4339db86f18beeccfbec124df1a.tar.gz cpython-34f96b8dd35dd4339db86f18beeccfbec124df1a.tar.bz2 |
Issue #18520: Fix PyFunction_NewWithQualName() error handling
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r-- | Objects/funcobject.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c index b5525e3..b043934 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -12,6 +12,12 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname PyObject *doc, *consts, *module; static PyObject *__name__ = NULL; + if (__name__ == NULL) { + __name__ = PyUnicode_InternFromString("__name__"); + if (__name__ == NULL) + return NULL; + } + op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type); if (op == NULL) return NULL; @@ -26,6 +32,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname op->func_defaults = NULL; /* No default arguments */ op->func_kwdefaults = NULL; /* No keyword only defaults */ op->func_closure = NULL; + consts = ((PyCodeObject *)code)->co_consts; if (PyTuple_Size(consts) >= 1) { doc = PyTuple_GetItem(consts, 0); @@ -36,21 +43,13 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname doc = Py_None; Py_INCREF(doc); op->func_doc = doc; + op->func_dict = NULL; op->func_module = NULL; op->func_annotations = NULL; /* __module__: If module name is in globals, use it. - Otherwise, use None. - */ - if (!__name__) { - __name__ = PyUnicode_InternFromString("__name__"); - if (!__name__) { - Py_DECREF(op); - return NULL; - } - } - + Otherwise, use None. */ module = PyDict_GetItem(globals, __name__); if (module) { Py_INCREF(module); |