(original) (raw)

changeset: 84798:9267a0b836b7 user: Victor Stinner victor.stinner@gmail.com date: Mon Jul 22 23:04:55 2013 +0200 files: Objects/funcobject.c description: Issue #18520: Fix PyFunction_NewWithQualName() error handling diff -r b20bc1aa5686 -r 9267a0b836b7 Objects/funcobject.c --- a/Objects/funcobject.c Mon Jul 22 23:02:05 2013 +0200 +++ b/Objects/funcobject.c Mon Jul 22 23:04:55 2013 +0200 @@ -12,6 +12,12 @@ 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 @@ 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 @@ 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); /victor.stinner@gmail.com