Skip to content

Commit 81fd625

Browse files
authored
gh-121621: Move asyncio_running_loop to private struct (#121939)
This avoids changing the ABI and keeps the field in the private struct.
1 parent f113c1a commit 81fd625

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

Include/cpython/pystate.h

Lines changed: 0 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ get_event_loop(asyncio_state *state)
324324
PyObject *loop;
325325
PyObject *policy;
326326

327-
PyThreadState *ts = _PyThreadState_GET();
327+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
328328
loop = Py_XNewRef(ts->asyncio_running_loop);
329329

330330
if (loop != NULL) {
@@ -3278,7 +3278,7 @@ static PyObject *
32783278
_asyncio__get_running_loop_impl(PyObject *module)
32793279
/*[clinic end generated code: output=b4390af721411a0a input=0a21627e25a4bd43]*/
32803280
{
3281-
PyThreadState *ts = _PyThreadState_GET();
3281+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
32823282
PyObject *loop = Py_XNewRef(ts->asyncio_running_loop);
32833283
if (loop == NULL) {
32843284
/* There's no currently running event loop */
@@ -3302,7 +3302,7 @@ static PyObject *
33023302
_asyncio__set_running_loop(PyObject *module, PyObject *loop)
33033303
/*[clinic end generated code: output=ae56bf7a28ca189a input=4c9720233d606604]*/
33043304
{
3305-
PyThreadState *ts = _PyThreadState_GET();
3305+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
33063306
if (loop == Py_None) {
33073307
loop = NULL;
33083308
}
@@ -3344,7 +3344,7 @@ _asyncio_get_running_loop_impl(PyObject *module)
33443344
/*[clinic end generated code: output=c247b5f9e529530e input=2a3bf02ba39f173d]*/
33453345
{
33463346
PyObject *loop;
3347-
PyThreadState *ts = _PyThreadState_GET();
3347+
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
33483348
loop = Py_XNewRef(ts->asyncio_running_loop);
33493349
if (loop == NULL) {
33503350
/* There's no currently running event loop */

Python/pystate.c

Lines changed: 2 additions & 2 deletions
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)