mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
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>
This commit is contained in:
parent
943e77d42d
commit
98eee94421
15 changed files with 7630 additions and 5185 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue