summaryrefslogtreecommitdiffstats
path: root/Objects/funcobject.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-01-29 13:24:55 (GMT)
committerGitHub <noreply@github.com>2021-01-29 13:24:55 (GMT)
commitd6c33fbd346765c6a8654dccacb2338006bf2b47 (patch)
tree857d7b70431dc74ca9b68e5ce1d56953f19f8d77 /Objects/funcobject.c
parent23a567c11ca36eedde0e119443c85cc16075deaf (diff)
downloadcpython-d6c33fbd346765c6a8654dccacb2338006bf2b47.zip
cpython-d6c33fbd346765c6a8654dccacb2338006bf2b47.tar.gz
cpython-d6c33fbd346765c6a8654dccacb2338006bf2b47.tar.bz2
bpo-42990: Introduce 'frame constructor' struct to simplify API for PyEval_CodeEval and friends (GH-24298)
* Introduce 'frame constructor' to simplify API for frame creation * Embed struct using a macro to conform to PEP 7
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r--Objects/funcobject.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index e7961b3..f839d7b 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -3,6 +3,7 @@
#include "Python.h"
#include "pycore_object.h"
+#include "frameobject.h"
#include "code.h"
#include "structmember.h" // PyMemberDef
@@ -40,8 +41,14 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
op->func_weakreflist = NULL;
Py_INCREF(code);
op->func_code = code;
+ assert(globals != NULL);
Py_INCREF(globals);
op->func_globals = globals;
+ PyObject *builtins = _PyEval_BuiltinsFromGlobals(globals);
+ if (builtins == NULL) {
+ return NULL;
+ }
+ op->func_builtins = builtins;
op->func_name = ((PyCodeObject *)code)->co_name;
Py_INCREF(op->func_name);
op->func_defaults = NULL; /* No default arguments */
@@ -592,15 +599,16 @@ func_clear(PyFunctionObject *op)
{
Py_CLEAR(op->func_code);
Py_CLEAR(op->func_globals);
- Py_CLEAR(op->func_module);
+ Py_CLEAR(op->func_builtins);
Py_CLEAR(op->func_name);
+ Py_CLEAR(op->func_qualname);
+ Py_CLEAR(op->func_module);
Py_CLEAR(op->func_defaults);
Py_CLEAR(op->func_kwdefaults);
Py_CLEAR(op->func_doc);
Py_CLEAR(op->func_dict);
Py_CLEAR(op->func_closure);
Py_CLEAR(op->func_annotations);
- Py_CLEAR(op->func_qualname);
return 0;
}
@@ -627,6 +635,7 @@ func_traverse(PyFunctionObject *f, visitproc visit, void *arg)
{
Py_VISIT(f->func_code);
Py_VISIT(f->func_globals);
+ Py_VISIT(f->func_builtins);
Py_VISIT(f->func_module);
Py_VISIT(f->func_defaults);
Py_VISIT(f->func_kwdefaults);