mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
d82f2caf94
commit
135cabd328
25 changed files with 268 additions and 156 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue