gh-99103: Normalize specialized traceback anchors against the current line (GH-99145)

Automerge-Triggered-By: GH:isidentical
This commit is contained in:
Batuhan Taskaya 2022-11-13 02:37:25 +03:00 committed by GitHub
parent c95f554a40
commit 57be545959
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 7 deletions

View file

@ -700,8 +700,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) {