summaryrefslogtreecommitdiff
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-07-02 15:10:11 +0100
committerGitHub <noreply@github.com>2021-07-02 15:10:11 +0100
commit98eee94421dcb42c15f2d7fc4cd21357722fbe2a (patch)
tree45a158d1e97f0b29d24ded80122559b50cc858f5 /Python/marshal.c
parent943e77d42d3f84b581f32c05f1fc8c05366b8ed3 (diff)
downloadcpython-git-98eee94421dcb42c15f2d7fc4cd21357722fbe2a.tar.gz
bpo-43950: Add code.co_positions (PEP 657) (GH-26955)
This PR is part of PEP 657 and augments the compiler to emit ending line numbers as well as starting and ending columns from the AST into compiled code objects. This allows bytecodes to be correlated to the exact source code ranges that generated them. This information is made available through the following public APIs: * The `co_positions` method on code objects. * The C API function `PyCode_Addr2Location`. Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 6c08189cca..d7fdb83a61 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -524,6 +524,8 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
w_object(co->co_name, p);
w_long(co->co_firstlineno, p);
w_object(co->co_linetable, p);
+ w_object(co->co_endlinetable, p);
+ w_object(co->co_columntable, p);
w_object(co->co_exceptiontable, p);
}
else if (PyObject_CheckBuffer(v)) {
@@ -1315,6 +1317,8 @@ r_object(RFILE *p)
PyObject *name = NULL;
int firstlineno;
PyObject *linetable = NULL;
+ PyObject* endlinetable = NULL;
+ PyObject* columntable = NULL;
PyObject *exceptiontable = NULL;
idx = r_ref_reserve(flag, p);
@@ -1367,6 +1371,12 @@ r_object(RFILE *p)
linetable = r_object(p);
if (linetable == NULL)
goto code_error;
+ endlinetable = r_object(p);
+ if (endlinetable == NULL)
+ goto code_error;
+ columntable = r_object(p);
+ if (columntable == NULL)
+ goto code_error;
exceptiontable = r_object(p);
if (exceptiontable == NULL)
goto code_error;
@@ -1379,6 +1389,8 @@ r_object(RFILE *p)
.code = code,
.firstlineno = firstlineno,
.linetable = linetable,
+ .endlinetable = endlinetable,
+ .columntable = columntable,
.consts = consts,
.names = names,
@@ -1415,6 +1427,8 @@ r_object(RFILE *p)
Py_XDECREF(filename);
Py_XDECREF(name);
Py_XDECREF(linetable);
+ Py_XDECREF(endlinetable);
+ Py_XDECREF(columntable);
Py_XDECREF(exceptiontable);
}
retval = v;