mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
GH-97779: Ensure that *all* frame objects are backed by "complete" frames (GH-97845)
This commit is contained in:
parent
c3648f4e4a
commit
0ff8fd6583
5 changed files with 75 additions and 4 deletions
|
@ -638,12 +638,22 @@ PyCode_New(int argcount, int kwonlyargcount,
|
|||
exceptiontable);
|
||||
}
|
||||
|
||||
static const char assert0[6] = {
|
||||
// NOTE: When modifying the construction of PyCode_NewEmpty, please also change
|
||||
// test.test_code.CodeLocationTest.test_code_new_empty to keep it in sync!
|
||||
|
||||
static const uint8_t assert0[6] = {
|
||||
RESUME, 0,
|
||||
LOAD_ASSERTION_ERROR, 0,
|
||||
RAISE_VARARGS, 1
|
||||
};
|
||||
|
||||
static const uint8_t linetable[2] = {
|
||||
(1 << 7) // New entry.
|
||||
| (PY_CODE_LOCATION_INFO_NO_COLUMNS << 3)
|
||||
| (3 - 1), // Three code units.
|
||||
0, // Offset from co_firstlineno.
|
||||
};
|
||||
|
||||
PyCodeObject *
|
||||
PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
|
||||
{
|
||||
|
@ -651,6 +661,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
|
|||
PyObject *filename_ob = NULL;
|
||||
PyObject *funcname_ob = NULL;
|
||||
PyObject *code_ob = NULL;
|
||||
PyObject *linetable_ob = NULL;
|
||||
PyCodeObject *result = NULL;
|
||||
|
||||
nulltuple = PyTuple_New(0);
|
||||
|
@ -665,10 +676,14 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
|
|||
if (filename_ob == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
code_ob = PyBytes_FromStringAndSize(assert0, 6);
|
||||
code_ob = PyBytes_FromStringAndSize((const char *)assert0, 6);
|
||||
if (code_ob == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
linetable_ob = PyBytes_FromStringAndSize((const char *)linetable, 2);
|
||||
if (linetable_ob == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
#define emptystring (PyObject *)&_Py_SINGLETON(bytes_empty)
|
||||
struct _PyCodeConstructor con = {
|
||||
|
@ -677,7 +692,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
|
|||
.qualname = funcname_ob,
|
||||
.code = code_ob,
|
||||
.firstlineno = firstlineno,
|
||||
.linetable = emptystring,
|
||||
.linetable = linetable_ob,
|
||||
.consts = nulltuple,
|
||||
.names = nulltuple,
|
||||
.localsplusnames = nulltuple,
|
||||
|
@ -692,6 +707,7 @@ failed:
|
|||
Py_XDECREF(funcname_ob);
|
||||
Py_XDECREF(filename_ob);
|
||||
Py_XDECREF(code_ob);
|
||||
Py_XDECREF(linetable_ob);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue