@@ -537,26 +537,31 @@ tb_displayline(PyTracebackObject* tb, PyObject *f, PyObject *filename, int linen
537
537
/* ignore errors since we can't report them, can we? */
538
538
if (!_Py_DisplaySourceLine (f , filename , lineno , _TRACEBACK_SOURCE_LINE_INDENT , & truncation , & source_line )) {
539
539
int code_offset = tb -> tb_lasti ;
540
- if (PyCode_Addr2Line (_PyFrame_GetCode (frame ), code_offset ) != _PyCode_Addr2EndLine (_PyFrame_GetCode (frame ), code_offset )) {
540
+ PyCodeObject * code = _PyFrame_GetCode (frame );
541
+
542
+ int start_line ;
543
+ int end_line ;
544
+ int start_col_byte_offset ;
545
+ int end_col_byte_offset ;
546
+ if (!PyCode_Addr2Location (code , code_offset , & start_line , & start_col_byte_offset ,
547
+ & end_line , & end_col_byte_offset )) {
548
+ goto done ;
549
+ }
550
+ if (start_line != end_line ) {
541
551
goto done ;
542
552
}
543
553
544
- Py_ssize_t start_offset = (Py_ssize_t ) _PyCode_Addr2Offset (_PyFrame_GetCode (frame ), code_offset );
545
- Py_ssize_t end_offset = (Py_ssize_t ) _PyCode_Addr2EndOffset (_PyFrame_GetCode (frame ), code_offset );
546
-
547
- if (start_offset < 0 || end_offset < 0 ) {
554
+ if (start_col_byte_offset < 0 || end_col_byte_offset < 0 ) {
548
555
goto done ;
549
556
}
550
- if (end_offset == -1 ) {
557
+ if (end_col_byte_offset == -1 ) {
551
558
// TODO: highlight from start_offset to the end of line
552
559
goto done ;
553
560
}
554
561
// Convert the utf-8 byte offset to the actual character offset so we
555
- // print the right number of carets. We do -1 here because the column
556
- // offsets provided by _PyCode_Addr2Offset and _PyCode_Addr2EndOffset
557
- // are 1-indexed, not 0-indexed.
558
- start_offset = _byte_offset_to_character_offset (source_line , start_offset );
559
- end_offset = _byte_offset_to_character_offset (source_line , end_offset );
562
+ // print the right number of carets.
563
+ Py_ssize_t start_offset = _byte_offset_to_character_offset (source_line , start_col_byte_offset );
564
+ Py_ssize_t end_offset = _byte_offset_to_character_offset (source_line , end_col_byte_offset );
560
565
561
566
char offset = truncation ;
562
567
while (++ offset <= start_offset ) {
@@ -986,3 +991,4 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
986
991
987
992
return NULL ;
988
993
}
994
+
0 commit comments