Skip to content

Commit cc6dfaa

Browse files
committed
styling: format the struct PyThreadStateHolder on Python>=3.15
1 parent dec747c commit cc6dfaa

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

‎src/PyEventLoop.cc‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,14 @@ PyEventLoop PyEventLoop::_getLoopOnThread(PyThreadState *tstate) {
154154
{
155155
// Every `PyThreadState` is actually allocated with extra fields as a `_PyThreadStateImpl` struct
156156
// See https://github.com/python/cpython/blob/v3.13.0rc1/Include/internal/pycore_tstate.h#L17-L24
157-
#if PY_VERSION_HEX >= 0x030f0000 // Python version is greater than 3.14
158-
// Python 3.15 embeds a frame and adds stack fields before asyncio_running_loop.
159157
using PyThreadStateHolder = struct { // _PyThreadStateImpl
160158
PyThreadState base;
159+
160+
#if PY_VERSION_HEX >= 0x030f0000 // Python version is greater than 3.15
161+
// Python 3.15 embeds a frame and adds stack fields before asyncio_running_loop.
162+
// See https://github.com/python/cpython/blob/v3.15.0/Include/internal/pycore_tstate.h#L34-L36
161163
struct { // _PyInterpreterFrame
164+
// Condensed from https://github.com/python/cpython/blob/main/Include/internal/pycore_interpframe_structs.h#L29-L53
162165
uintptr_t f_executable;
163166
void *previous;
164167
uintptr_t f_funcobj;
@@ -181,27 +184,25 @@ PyEventLoop PyEventLoop::_getLoopOnThread(PyThreadState *tstate) {
181184
#endif
182185
uintptr_t localsplus[1];
183186
} base_frame;
187+
#endif // Python >= 3.15
188+
189+
#if PY_VERSION_HEX >= 0x030e0000 // Python version is greater than 3.14
190+
// the struct is changed with more additional fields, see https://github.com/python/cpython/blob/v3.14.0rc3/Include/internal/pycore_tstate.h#L24-L40
184191
Py_ssize_t refcount;
185192
uintptr_t c_stack_top;
186193
uintptr_t c_stack_soft_limit;
187194
uintptr_t c_stack_hard_limit;
195+
#endif // Python >= 3.14
196+
197+
#if PY_VERSION_HEX >= 0x030f0000 // Python version is greater than 3.15
188198
uintptr_t c_stack_init_base;
189199
uintptr_t c_stack_init_top;
200+
#endif // Python >= 3.15
201+
190202
PyObject *asyncio_running_loop;
203+
// ...
204+
// (we only need the first few fields of `_PyThreadStateImpl`)
191205
};
192-
#else
193-
using PyThreadStateHolder = struct { // _PyThreadStateImpl
194-
PyThreadState base;
195-
#if PY_VERSION_HEX >= 0x030e0000 // Python version is greater than 3.14
196-
// the struct is changed with more additional fields, see https://github.com/python/cpython/blob/v3.14.0rc3/Include/internal/pycore_tstate.h#L24-L40
197-
Py_ssize_t refcount;
198-
uintptr_t c_stack_top;
199-
uintptr_t c_stack_soft_limit;
200-
uintptr_t c_stack_hard_limit;
201-
#endif
202-
PyObject *asyncio_running_loop; // we only need the first few fields of `_PyThreadStateImpl`
203-
};
204-
#endif
205206

206207
// Modified from https://github.com/python/cpython/blob/v3.13.0rc1/Modules/_asynciomodule.c#L3205-L3210
207208
PyObject *loop = ((PyThreadStateHolder *)tstate)->asyncio_running_loop;

0 commit comments

Comments
 (0)