Skip to content

Commit afa5321

Browse files
[3.13] gh-121621: Move asyncio_running_loop to private struct (GH-121939) (#121943)
gh-121621: Move asyncio_running_loop to private struct (GH-121939) This avoids changing the ABI and keeps the field in the private struct. (cherry picked from commit 81fd625) Co-authored-by: Sam Gross <[email protected]>
1 parent a12c105 commit afa5321

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

Include/cpython/pystate.h

-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ struct _ts {
6868
pycore_ceval.h. */
6969
uintptr_t eval_breaker;
7070

71-
PyObject *asyncio_running_loop; // Strong reference
72-
7371
struct {
7472
/* Has been initialized to a safe state.
7573

Include/internal/pycore_tstate.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ typedef struct _PyThreadStateImpl {
2121
// semi-public fields are in PyThreadState.
2222
PyThreadState base;
2323

24+
PyObject *asyncio_running_loop; // Strong reference
25+
2426
struct _qsbr_thread_state *qsbr; // only used by free-threaded build
2527
struct llist_node mem_free_queue; // delayed free queue
2628

Modules/_asynciomodule.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ get_event_loop(asyncio_state *state)
265265
PyObject *loop;
266266
PyObject *policy;
267267

268-
PyThreadState *ts = _PyThreadState_GET();
268+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
269269
loop = Py_XNewRef(ts->asyncio_running_loop);
270270

271271
if (loop != NULL) {
@@ -3189,7 +3189,7 @@ static PyObject *
31893189
_asyncio__get_running_loop_impl(PyObject *module)
31903190
/*[clinic end generated code: output=b4390af721411a0a input=0a21627e25a4bd43]*/
31913191
{
3192-
PyThreadState *ts = _PyThreadState_GET();
3192+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
31933193
PyObject *loop = Py_XNewRef(ts->asyncio_running_loop);
31943194
if (loop == NULL) {
31953195
/* There's no currently running event loop */
@@ -3213,7 +3213,7 @@ static PyObject *
32133213
_asyncio__set_running_loop(PyObject *module, PyObject *loop)
32143214
/*[clinic end generated code: output=ae56bf7a28ca189a input=4c9720233d606604]*/
32153215
{
3216-
PyThreadState *ts = _PyThreadState_GET();
3216+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
32173217
if (loop == Py_None) {
32183218
loop = NULL;
32193219
}
@@ -3255,7 +3255,7 @@ _asyncio_get_running_loop_impl(PyObject *module)
32553255
/*[clinic end generated code: output=c247b5f9e529530e input=2a3bf02ba39f173d]*/
32563256
{
32573257
PyObject *loop;
3258-
PyThreadState *ts = _PyThreadState_GET();
3258+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
32593259
loop = Py_XNewRef(ts->asyncio_running_loop);
32603260
if (loop == NULL) {
32613261
/* There's no currently running event loop */

Python/pystate.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ init_threadstate(_PyThreadStateImpl *_tstate,
14991499
tstate->previous_executor = NULL;
15001500
tstate->dict_global_version = 0;
15011501

1502-
tstate->asyncio_running_loop = NULL;
1502+
_tstate->asyncio_running_loop = NULL;
15031503

15041504
tstate->delete_later = NULL;
15051505

@@ -1702,7 +1702,7 @@ PyThreadState_Clear(PyThreadState *tstate)
17021702

17031703
/* Don't clear tstate->pyframe: it is a borrowed reference */
17041704

1705-
Py_CLEAR(tstate->asyncio_running_loop);
1705+
Py_CLEAR(((_PyThreadStateImpl *)tstate)->asyncio_running_loop);
17061706

17071707
Py_CLEAR(tstate->dict);
17081708
Py_CLEAR(tstate->async_exc);

0 commit comments

Comments
 (0)