8000 Use the supported way to get a C frame's lineno · nedbat/coveragepy@7e5e28f · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e5e28f

Browse files
committed
Use the supported way to get a C frame's lineno
See https://bugs.python.org/issue42823 for discussion.
1 parent 5c3d094 commit 7e5e28f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

coverage/ctracer/tracer.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ CTracer_check_missing_return(CTracer *self, PyFrameObject *frame)
305305
goto error;
306306
}
307307
}
308-
SHOWLOG(self->pdata_stack->depth, frame->f_lineno, frame->f_code->co_filename, "missedreturn");
308+
SHOWLOG(self->pdata_stack->depth, PyFrame_GetLineNumber(frame), frame->f_code->co_filename, "missedreturn");
309309
self->pdata_stack->depth--;
310310
self->pcur_entry = &self->pdata_stack->stack[self->pdata_stack->depth];
311311
}
@@ -529,13 +529,13 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
529529
self->pcur_entry->file_data = file_data;
530530
self->pcur_entry->file_tracer = file_tracer;
531531

532-
SHOWLOG(self->pdata_stack->depth, frame->f_lineno, filename, "traced");
532+
SHOWLOG(self->pdata_stack->depth, PyFrame_GetLineNumber(frame), filename, "traced");
533533
}
534534
else {
535535
Py_XDECREF(self->pcur_entry->file_data);
536536
self->pcur_entry->file_data = NULL;
537537
self->pcur_entry->file_tracer = Py_None;
538-
SHOWLOG(self->pdata_stack->depth, frame->f_lineno, filename, "skipped");
538+
SHOWLOG(self->pdata_stack->depth, PyFrame_GetLineNumber(frame), filename, "skipped");
539539
}
540540

541541
self->pcur_entry->disposition = disposition;
@@ -552,7 +552,7 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
552552
self->pcur_entry->last_line = -frame->f_code->co_firstlineno;
553553
}
554554
else {
555-
self->pcur_entry->last_line = frame->f_lineno;
555+
self->pcur_entry->last_line = PyFrame_GetLineNumber(frame);
556556
}
557557

558558
ok:
@@ -633,7 +633,7 @@ CTracer_handle_line(CTracer *self, PyFrameObject *frame)
633633

634634
STATS( self->stats.lines++; )
635635
if (self->pdata_stack->depth >= 0) {
636-
SHOWLOG(self->pdata_stack->depth, frame->f_lineno, frame->f_code->co_filename, "line");
636+
SHOWLOG(self->pdata_stack->depth, PyFrame_GetLineNumber(frame), frame->f_code->co_filename, "line");
637637
if (self->pcur_entry->file_data) {
638638
int lineno_from = -1;
639639
int lineno_to = -1;
@@ -655,7 +655,7 @@ CTracer_handle_line(CTracer *self, PyFrameObject *frame)
655655
}
656656
}
657657
else {
658-
lineno_from = lineno_to = frame->f_lineno;
658+
lineno_from = lineno_to = PyFrame_GetLineNumber(frame);
659659
}
660660

661661
if (lineno_from != -1) {
@@ -744,7 +744,7 @@ CTracer_handle_return(CTracer *self, PyFrameObject *frame)
744744
}
745745

746746
/* Pop the stack. */
747-
SHOWLOG(self->pdata_stack->depth, frame->f_lineno, frame->f_code->co_filename, "return");
747+
SHOWLOG(self->pdata_stack->depth, PyFrame_GetLineNumber(frame), frame->f_code->co_filename, "return");
748748
self->pdata_stack->depth--;
749749
self->pcur_entry = &self->pdata_stack->stack[self->pdata_stack->depth];
750750
}
@@ -807,14 +807,14 @@ CTracer_trace(CTracer *self, PyFrameObject *frame, int what, PyObject *arg_unuse
807807
#if WHAT_LOG
808808
if (what <= (int)(sizeof(what_sym)/sizeof(const char *))) {
809809< 8000 div class="diff-text-inner"> ascii = MyText_AS_BYTES(frame->f_code->co_filename);
810-
printf("trace: %s @ %s %d\n", what_sym[what], MyBytes_AS_STRING(ascii), frame->f_lineno);
810+
printf("trace: %s @ %s %d\n", what_sym[what], MyBytes_AS_STRING(ascii), PyFrame_GetLineNumber(frame));
811811
Py_DECREF(ascii);
812812
}
813813
#endif
814814

815815
#if TRACE_LOG
816816
ascii = MyText_AS_BYTES(frame->f_code->co_filename);
817-
if (strstr(MyBytes_AS_STRING(ascii), start_file) && frame->f_lineno == start_line) {
817+
if (strstr(MyBytes_AS_STRING(ascii), start_file) && PyFrame_GetLineNumber(frame) == start_line) {
818818
logging = TRUE;
819819
}
820820
Py_DECREF(ascii);
@@ -931,7 +931,7 @@ CTracer_call(CTracer *self, PyObject *args, PyObject *kwds)
931931

932932
#if WHAT_LOG
933933
ascii = MyText_AS_BYTES(frame->f_code->co_filename);
934-
printf("pytrace: %s @ %s %d\n", what_sym[what], MyBytes_AS_STRING(ascii), frame->f_lineno);
934+
printf("pytrace: %s @ %s %d\n", what_sym[what], MyBytes_AS_STRING(ascii), PyFrame_GetLineNumber(frame));
935935
Py_DECREF(ascii);
936936
#endif
937937

0 commit comments

Comments
 (0)
0