Commit 34f96b8d authored by Victor Stinner's avatar Victor Stinner

Issue #18520: Fix PyFunction_NewWithQualName() error handling

parent 4d1f5d6e
...@@ -12,6 +12,12 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname ...@@ -12,6 +12,12 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
PyObject *doc, *consts, *module; PyObject *doc, *consts, *module;
static PyObject *__name__ = NULL; static PyObject *__name__ = NULL;
if (__name__ == NULL) {
__name__ = PyUnicode_InternFromString("__name__");
if (__name__ == NULL)
return NULL;
}
op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type); op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type);
if (op == NULL) if (op == NULL)
return NULL; return NULL;
...@@ -26,6 +32,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname ...@@ -26,6 +32,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
op->func_defaults = NULL; /* No default arguments */ op->func_defaults = NULL; /* No default arguments */
op->func_kwdefaults = NULL; /* No keyword only defaults */ op->func_kwdefaults = NULL; /* No keyword only defaults */
op->func_closure = NULL; op->func_closure = NULL;
consts = ((PyCodeObject *)code)->co_consts; consts = ((PyCodeObject *)code)->co_consts;
if (PyTuple_Size(consts) >= 1) { if (PyTuple_Size(consts) >= 1) {
doc = PyTuple_GetItem(consts, 0); doc = PyTuple_GetItem(consts, 0);
...@@ -36,21 +43,13 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname ...@@ -36,21 +43,13 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
doc = Py_None; doc = Py_None;
Py_INCREF(doc); Py_INCREF(doc);
op->func_doc = doc; op->func_doc = doc;
op->func_dict = NULL; op->func_dict = NULL;
op->func_module = NULL; op->func_module = NULL;
op->func_annotations = NULL; op->func_annotations = NULL;
/* __module__: If module name is in globals, use it. /* __module__: If module name is in globals, use it.
Otherwise, use None. Otherwise, use None. */
*/
if (!__name__) {
__name__ = PyUnicode_InternFromString("__name__");
if (!__name__) {
Py_DECREF(op);
return NULL;
}
}
module = PyDict_GetItem(globals, __name__); module = PyDict_GetItem(globals, __name__);
if (module) { if (module) {
Py_INCREF(module); Py_INCREF(module);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment