Skip to content

Commit

Permalink
Support Python 3.13.
Browse files Browse the repository at this point in the history
Since we're using some cpython internals that change from time to time
we have to adjust for the 3.13 release accordingly.
  • Loading branch information
jorisvink committed Nov 8, 2024
1 parent c437e15 commit 4bd456a
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,33 @@

#include <frameobject.h>

/*
* Python 3.13.x requires that Py_BUILD_CORE is defined before we pull
* in the pycore_frame header file, and it loves using unnamed unions
* so we have to turn off pendatic mode before including it.
*
* The f_code member was removed from _PyInterpreterFrame and is replaced
* with a PyObject called f_executable. There is an _PyFrame_GetCode()
* helper function now.
*/
#if PY_VERSION_HEX >= 0x030d0000
#define Py_BUILD_CORE 1
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#endif

#if PY_VERSION_HEX < 0x030d0000
#define _PyFrame_GetCode(frame) (frame->f_code)
#endif

#if PY_VERSION_HEX >= 0x030b0000
#include <internal/pycore_frame.h>
#endif

#if PY_VERSION_HEX >= 0x030d0000
#pragma GCC diagnostic pop
#endif

#if PY_VERSION_HEX < 0x030A0000
typedef enum {
PYGEN_RETURN = 0,
Expand Down Expand Up @@ -1201,7 +1224,7 @@ python_resolve_frame_line(void *ptr)

frame = ptr;
addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT);
line = PyCode_Addr2Line(frame->f_code, addr);
line = PyCode_Addr2Line(_PyFrame_GetCode(frame), addr);
#else
line = PyFrame_GetLineNumber(ptr);
#endif
Expand Down Expand Up @@ -1232,8 +1255,8 @@ python_coro_trace(const char *label, struct python_coro *coro)
#else
frame = obj->cr_frame;
#endif
if (frame != NULL && frame->f_code != NULL) {
code = frame->f_code;
if (frame != NULL && _PyFrame_GetCode(frame) != NULL) {
code = _PyFrame_GetCode(frame);
func = PyUnicode_AsUTF8AndSize(code->co_name, NULL);
file = PyUnicode_AsUTF8AndSize(code->co_filename, NULL);

Expand Down

0 comments on commit 4bd456a

Please sign in to comment.