summaryrefslogtreecommitdiffstats
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-10-05 00:30:03 (GMT)
committerGitHub <noreply@github.com>2022-10-05 00:30:03 (GMT)
commit0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85 (patch)
treeba515469a236a046b09329fbcd49c33eb65c267d /Objects/codeobject.c
parentc3648f4e4a12ec6efe65684facfcd08996e550ca (diff)
downloadcpython-0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85.zip
cpython-0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85.tar.gz
cpython-0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85.tar.bz2
GH-97779: Ensure that *all* frame objects are backed by "complete" frames (GH-97845)
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 7d0d038..14d1d00 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -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;
}