diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-10-26 21:43:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-26 21:43:38 (GMT) |
commit | c81ebf5b3d9aa080d2039f1225f6fed91c29f5a8 (patch) | |
tree | 31d0a5052319b1480704f513aba52057ca829478 /Python/traceback.c | |
parent | e25d8b40cd70744513e190b1ca153087382b6b09 (diff) | |
download | cpython-c81ebf5b3d9aa080d2039f1225f6fed91c29f5a8.zip cpython-c81ebf5b3d9aa080d2039f1225f6fed91c29f5a8.tar.gz cpython-c81ebf5b3d9aa080d2039f1225f6fed91c29f5a8.tar.bz2 |
[3.12] bpo-43950: handle wide unicode characters in tracebacks (GH-28150) (#111346)
Diffstat (limited to 'Python/traceback.c')
-rw-r--r-- | Python/traceback.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index 0070f15..4fc4881 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -900,8 +900,39 @@ tb_displayline(PyTracebackObject* tb, PyObject *f, PyObject *filename, int linen goto done; } - if (print_error_location_carets(f, truncation, start_offset, end_offset, - right_start_offset, left_end_offset, + // Convert all offsets to display offsets (e.g. the space they would take up if printed + // on the screen). + Py_ssize_t dp_start = _PyPegen_calculate_display_width(source_line, start_offset); + if (dp_start < 0) { + err = ignore_source_errors() < 0; + goto done; + } + + Py_ssize_t dp_end = _PyPegen_calculate_display_width(source_line, end_offset); + if (dp_end < 0) { + err = ignore_source_errors() < 0; + goto done; + } + + Py_ssize_t dp_left_end = -1; + Py_ssize_t dp_right_start = -1; + if (has_secondary_ranges) { + dp_left_end = _PyPegen_calculate_display_width(source_line, left_end_offset); + if (dp_left_end < 0) { + err = ignore_source_errors() < 0; + goto done; + } + + dp_right_start = _PyPegen_calculate_display_width(source_line, right_start_offset); + if (dp_right_start < 0) { + err = ignore_source_errors() < 0; + goto done; + } + } + + + if (print_error_location_carets(f, truncation, dp_start, dp_end, + dp_right_start, dp_left_end, primary_error_char, secondary_error_char) < 0) { err = -1; goto done; |