mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-43693: Add _PyCode_New(). (gh-26375)
This is an internal-only API that helps us manage the many values used to create a code object. https://bugs.python.org/issue43693
This commit is contained in:
parent
318adeba78
commit
9f494d4929
12 changed files with 4736 additions and 4648 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "code.h"
|
||||
#include "marshal.h"
|
||||
#include "pycore_hashtable.h"
|
||||
#include "pycore_code.h" // _PyCode_New()
|
||||
|
||||
/*[clinic input]
|
||||
module marshal
|
||||
|
@ -512,7 +513,6 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
|
|||
w_long(co->co_argcount, p);
|
||||
w_long(co->co_posonlyargcount, p);
|
||||
w_long(co->co_kwonlyargcount, p);
|
||||
w_long(co->co_nlocals, p);
|
||||
w_long(co->co_stacksize, p);
|
||||
w_long(co->co_flags, p);
|
||||
w_object(co->co_code, p);
|
||||
|
@ -1301,7 +1301,6 @@ r_object(RFILE *p)
|
|||
int argcount;
|
||||
int posonlyargcount;
|
||||
int kwonlyargcount;
|
||||
int nlocals;
|
||||
int stacksize;
|
||||
int flags;
|
||||
PyObject *code = NULL;
|
||||
|
@ -1331,9 +1330,6 @@ r_object(RFILE *p)
|
|||
goto code_error;
|
||||
}
|
||||
kwonlyargcount = (int)r_long(p);
|
||||
if (PyErr_Occurred())
|
||||
goto code_error;
|
||||
nlocals = (int)r_long(p);
|
||||
if (PyErr_Occurred())
|
||||
goto code_error;
|
||||
stacksize = (int)r_long(p);
|
||||
|
@ -1354,6 +1350,7 @@ r_object(RFILE *p)
|
|||
varnames = r_object(p);
|
||||
if (varnames == NULL)
|
||||
goto code_error;
|
||||
Py_ssize_t nlocals = PyTuple_GET_SIZE(varnames);
|
||||
freevars = r_object(p);
|
||||
if (freevars == NULL)
|
||||
goto code_error;
|
||||
|
@ -1376,19 +1373,43 @@ r_object(RFILE *p)
|
|||
if (exceptiontable == NULL)
|
||||
goto code_error;
|
||||
|
||||
|
||||
if (PySys_Audit("code.__new__", "OOOiiiiii",
|
||||
code, filename, name, argcount, posonlyargcount,
|
||||
kwonlyargcount, nlocals, stacksize, flags) < 0) {
|
||||
goto code_error;
|
||||
}
|
||||
|
||||
v = (PyObject *) PyCode_NewWithPosOnlyArgs(
|
||||
argcount, posonlyargcount, kwonlyargcount,
|
||||
nlocals, stacksize, flags,
|
||||
code, consts, names, varnames,
|
||||
freevars, cellvars, filename, name,
|
||||
firstlineno, linetable, exceptiontable);
|
||||
struct _PyCodeConstructor con = {
|
||||
.filename = filename,
|
||||
.name = name,
|
||||
.flags = flags,
|
||||
|
||||
.code = code,
|
||||
.firstlineno = firstlineno,
|
||||
.linetable = linetable,
|
||||
|
||||
.consts = consts,
|
||||
.names = names,
|
||||
|
||||
.varnames = varnames,
|
||||
.cellvars = cellvars,
|
||||
.freevars = freevars,
|
||||
|
||||
.argcount = argcount,
|
||||
.posonlyargcount = posonlyargcount,
|
||||
.kwonlyargcount = kwonlyargcount,
|
||||
|
||||
.stacksize = stacksize,
|
||||
|
||||
.exceptiontable = exceptiontable,
|
||||
};
|
||||
if (_PyCode_Validate(&con) < 0) {
|
||||
goto code_error;
|
||||
}
|
||||
v = (PyObject *)_PyCode_New(&con);
|
||||
if (v == NULL) {
|
||||
goto code_error;
|
||||
}
|
||||
v = r_ref_insert(v, idx, flag, p);
|
||||
|
||||
code_error:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue