diff --git a/coverage/ctracer/tracer.c b/coverage/ctracer/tracer.c index 02394f319..8a9e0a5ed 100644 --- a/coverage/ctracer/tracer.c +++ b/coverage/ctracer/tracer.c @@ -508,15 +508,14 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame) Py_XDECREF(self->pcur_entry->file_data); self->pcur_entry->file_data = NULL; self->pcur_entry->file_tracer = Py_None; - frame->f_trace_lines = 0; + MyFrame_NoTraceLines(frame); SHOWLOG(PyFrame_GetLineNumber(frame), filename, "skipped"); } self->pcur_entry->disposition = disposition; /* Make the frame right in case settrace(gettrace()) happens. */ - Py_INCREF(self); - Py_XSETREF(frame->f_trace, (PyObject*)self); + MyFrame_SetTrace(frame, self); /* A call event is really a "start frame" event, and can happen for * re-entering a generator also. How we tell the difference depends on diff --git a/coverage/ctracer/util.h b/coverage/ctracer/util.h index e961639b2..1e99313dc 100644 --- a/coverage/ctracer/util.h +++ b/coverage/ctracer/util.h @@ -16,7 +16,10 @@ // 3.11 moved f_lasti into an internal structure. This is totally the wrong way // to make this work, but it's all I've got until https://bugs.python.org/issue40421 // is resolved. +#if PY_VERSION_HEX < 0x030D0000 #include +#endif + #if PY_VERSION_HEX >= 0x030B00A7 #define MyFrame_GetLasti(f) (PyFrame_GetLasti(f)) #else @@ -30,6 +33,14 @@ #define MyFrame_GetLasti(f) ((f)->f_lasti) #endif +#if PY_VERSION_HEX >= 0x030D0000 +#define MyFrame_NoTraceLines(f) (PyObject_SetAttrString((PyObject*)(f), "f_trace_lines", Py_False)) +#define MyFrame_SetTrace(f, obj) (PyObject_SetAttrString((PyObject*)(f), "f_trace", (PyObject*)(obj))) +#else +#define MyFrame_NoTraceLines(f) ((f)->f_trace_lines = 0) +#define MyFrame_SetTrace(f, obj) {Py_INCREF(obj); Py_XSETREF((f)->f_trace, (PyObject*)(obj));} +#endif + // Access f_code should be done through a helper starting in 3.9. #if PY_VERSION_HEX >= 0x03090000 #define MyFrame_GetCode(f) (PyFrame_GetCode(f))