summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBatuhan Taskaya <isidentical@gmail.com>2022-11-21 22:16:12 (GMT)
committerGitHub <noreply@github.com>2022-11-21 22:16:12 (GMT)
commita3480ec79512c6988fd9fcd6bf8959b45c3675d9 (patch)
tree9f91c382074f544aa483c0657e6016a7753fb451 /Python
parent2d5f4ba17480c1f883a0822c90af25d2ec9bf7ed (diff)
downloadcpython-a3480ec79512c6988fd9fcd6bf8959b45c3675d9.zip
cpython-a3480ec79512c6988fd9fcd6bf8959b45c3675d9.tar.gz
cpython-a3480ec79512c6988fd9fcd6bf8959b45c3675d9.tar.bz2
[3.11] gh-99103: Normalize specialized traceback anchors against the current line (#99423)
[3.11] gh-99103: Normalize specialized traceback anchors against the current line (GH-99145) Automerge-Triggered-By: GH:isidentical. (cherry picked from commit 57be5459593bbd09583317ebdafc4d58ae51dbf4) Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/traceback.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index 20348c0..7f47349 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -705,8 +705,13 @@ extract_anchors_from_line(PyObject *filename, PyObject *line,
done:
if (res > 0) {
- *left_anchor += start_offset;
- *right_anchor += start_offset;
+ // Normalize the AST offsets to byte offsets and adjust them with the
+ // start of the actual line (instead of the source code segment).
+ assert(segment != NULL);
+ assert(*left_anchor >= 0);
+ assert(*right_anchor >= 0);
+ *left_anchor = _PyPegen_byte_offset_to_character_offset(segment, *left_anchor) + start_offset;
+ *right_anchor = _PyPegen_byte_offset_to_character_offset(segment, *right_anchor) + start_offset;
}
Py_XDECREF(segment);
if (arena) {