mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 12:39:01 -04:00
Python improvements: Rework corotracing for 3.11.
In the upcoming Python 3.11 release the PyCoroObject no longer has a full PyFrameObject, but instead their internal frame struct _PyInterpreterFrame. Use that when we are building against 3.11 or higher so we can still provide useful tracing functionality (and so that it builds).
This commit is contained in:
parent
377295c04c
commit
d7cef82362
34
src/python.c
34
src/python.c
@ -55,6 +55,10 @@
|
|||||||
|
|
||||||
#include <frameobject.h>
|
#include <frameobject.h>
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x030b0000
|
||||||
|
#include <internal/pycore_frame.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if PY_VERSION_HEX < 0x030A0000
|
#if PY_VERSION_HEX < 0x030A0000
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PYGEN_RETURN = 0,
|
PYGEN_RETURN = 0,
|
||||||
@ -1183,17 +1187,27 @@ static void
|
|||||||
python_coro_trace(const char *label, struct python_coro *coro)
|
python_coro_trace(const char *label, struct python_coro *coro)
|
||||||
{
|
{
|
||||||
int line;
|
int line;
|
||||||
PyGenObject *gen;
|
PyCoroObject *obj;
|
||||||
PyCodeObject *code;
|
PyCodeObject *code;
|
||||||
|
#if PY_VERSION_HEX >= 0x030b0000
|
||||||
|
_PyInterpreterFrame *frame;
|
||||||
|
#else
|
||||||
|
PyFrameObject *frame;
|
||||||
|
#endif
|
||||||
const char *func, *fname, *file;
|
const char *func, *fname, *file;
|
||||||
|
|
||||||
if (coro_tracing == 0)
|
if (coro_tracing == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gen = (PyGenObject *)coro->obj;
|
obj = (PyCoroObject *)coro->obj;
|
||||||
|
|
||||||
if (gen->gi_frame != NULL && gen->gi_frame->f_code != NULL) {
|
#if PY_VERSION_HEX >= 0x030b0000
|
||||||
code = gen->gi_frame->f_code;
|
frame = (_PyInterpreterFrame *)obj->cr_iframe;
|
||||||
|
#else
|
||||||
|
frame = obj->cr_frame;
|
||||||
|
#endif
|
||||||
|
if (frame != NULL && frame->f_code != NULL) {
|
||||||
|
code = frame->f_code;
|
||||||
func = PyUnicode_AsUTF8AndSize(code->co_name, NULL);
|
func = PyUnicode_AsUTF8AndSize(code->co_name, NULL);
|
||||||
file = PyUnicode_AsUTF8AndSize(code->co_filename, NULL);
|
file = PyUnicode_AsUTF8AndSize(code->co_filename, NULL);
|
||||||
|
|
||||||
@ -1206,10 +1220,16 @@ python_coro_trace(const char *label, struct python_coro *coro)
|
|||||||
fname = "unknown";
|
fname = "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gen->gi_frame != NULL)
|
if (frame != NULL) {
|
||||||
line = PyFrame_GetLineNumber(gen->gi_frame);
|
#if PY_VERSION_HEX >= 0x030b0000
|
||||||
else
|
line = _PyInterpreterFrame_GetLine(frame);
|
||||||
|
#else
|
||||||
|
line = PyFrame_GetLineNumber(frame);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
line = -1;
|
line = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (coro->name) {
|
if (coro->name) {
|
||||||
kore_log(LOG_NOTICE, "coro '%s' %s <%s> @ [%s:%d]",
|
kore_log(LOG_NOTICE, "coro '%s' %s <%s> @ [%s:%d]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user