summaryrefslogtreecommitdiffstats
path: root/Objects/funcobject.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-11-23 09:53:24 (GMT)
committerGitHub <noreply@github.com>2021-11-23 09:53:24 (GMT)
commit135cabd328504e1648d17242b42b675cdbd0193b (patch)
tree4efa5418b1816ba02c206678ecfa4e2d8e8d8f14 /Objects/funcobject.c
parentd82f2caf942fa8b94e797a2f116ee54ec303c2df (diff)
downloadcpython-135cabd328504e1648d17242b42b675cdbd0193b.zip
cpython-135cabd328504e1648d17242b42b675cdbd0193b.tar.gz
cpython-135cabd328504e1648d17242b42b675cdbd0193b.tar.bz2
bpo-44525: Copy free variables in bytecode to allow calls to inner functions to be specialized (GH-29595)
* Make internal APIs that take PyFrameConstructor take a PyFunctionObject instead. * Add reference to function to frame, borrow references to builtins and globals. * Add COPY_FREE_VARS instruction to allow specialization of calls to inner functions.
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r--Objects/funcobject.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 5a17038..7891e4f 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -9,6 +9,39 @@
static uint32_t next_func_version = 1;
+PyFunctionObject *
+_PyFunction_FromConstructor(PyFrameConstructor *constr)
+{
+
+ PyFunctionObject *op = PyObject_GC_New(PyFunctionObject, &PyFunction_Type);
+ if (op == NULL) {
+ return NULL;
+ }
+ Py_INCREF(constr->fc_globals);
+ op->func_globals = constr->fc_globals;
+ Py_INCREF(constr->fc_builtins);
+ op->func_builtins = constr->fc_builtins;
+ Py_INCREF(constr->fc_name);
+ op->func_name = constr->fc_name;
+ Py_INCREF(constr->fc_qualname);
+ op->func_qualname = constr->fc_qualname;
+ Py_INCREF(constr->fc_code);
+ op->func_code = constr->fc_code;
+ op->func_defaults = NULL;
+ op->func_kwdefaults = NULL;
+ op->func_closure = NULL;
+ Py_INCREF(Py_None);
+ op->func_doc = Py_None;
+ op->func_dict = NULL;
+ op->func_weakreflist = NULL;
+ op->func_module = NULL;
+ op->func_annotations = NULL;
+ op->vectorcall = _PyFunction_Vectorcall;
+ op->func_version = 0;
+ _PyObject_GC_TRACK(op);
+ return op;
+}
+
PyObject *
PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname)
{