]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-121621: Move asyncio_running_loop to private struct (#121939)
authorSam Gross <colesbury@gmail.com>
Wed, 17 Jul 2024 22:21:24 +0000 (18:21 -0400)
committerGitHub <noreply@github.com>
Wed, 17 Jul 2024 22:21:24 +0000 (15:21 -0700)
This avoids changing the ABI and keeps the field in the private struct.

Include/cpython/pystate.h
Include/internal/pycore_tstate.h
Modules/_asynciomodule.c
Python/pystate.c

index ce050424cccd493641bf0b8627d8847ad3904545..bb2af78a376d7515bd3f76ad7bd19447eac25fdd 100644 (file)
@@ -68,8 +68,6 @@ struct _ts {
        pycore_ceval.h. */
     uintptr_t eval_breaker;
 
-    PyObject *asyncio_running_loop; // Strong reference
-
     struct {
         /* Has been initialized to a safe state.
 
index befca950920bacddf7d6524e206eccb691d8f4d9..1ed5b1d826aaa4a4b047017ffc3fc26300f9d12e 100644 (file)
@@ -21,6 +21,8 @@ typedef struct _PyThreadStateImpl {
     // semi-public fields are in PyThreadState.
     PyThreadState base;
 
+    PyObject *asyncio_running_loop; // Strong reference
+
     struct _qsbr_thread_state *qsbr;  // only used by free-threaded build
     struct llist_node mem_free_queue; // delayed free queue
 
index 31a45f8169be88a8bdf05626bf03d74175e07851..05ac09fe31c48da98bfcef027f1ba3993cee607d 100644 (file)
@@ -324,7 +324,7 @@ get_event_loop(asyncio_state *state)
     PyObject *loop;
     PyObject *policy;
 
-    PyThreadState *ts = _PyThreadState_GET();
+    _PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
     loop = Py_XNewRef(ts->asyncio_running_loop);
 
     if (loop != NULL) {
@@ -3278,7 +3278,7 @@ static PyObject *
 _asyncio__get_running_loop_impl(PyObject *module)
 /*[clinic end generated code: output=b4390af721411a0a input=0a21627e25a4bd43]*/
 {
-    PyThreadState *ts = _PyThreadState_GET();
+    _PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
     PyObject *loop = Py_XNewRef(ts->asyncio_running_loop);
     if (loop == NULL) {
         /* There's no currently running event loop */
@@ -3302,7 +3302,7 @@ static PyObject *
 _asyncio__set_running_loop(PyObject *module, PyObject *loop)
 /*[clinic end generated code: output=ae56bf7a28ca189a input=4c9720233d606604]*/
 {
-    PyThreadState *ts = _PyThreadState_GET();
+    _PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
     if (loop == Py_None) {
         loop = NULL;
     }
@@ -3344,7 +3344,7 @@ _asyncio_get_running_loop_impl(PyObject *module)
 /*[clinic end generated code: output=c247b5f9e529530e input=2a3bf02ba39f173d]*/
 {
     PyObject *loop;
-    PyThreadState *ts = _PyThreadState_GET();
+    _PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
     loop = Py_XNewRef(ts->asyncio_running_loop);
     if (loop == NULL) {
         /* There's no currently running event loop */
index f77a2cc54e867a43d353c14a701ff11370f5b69d..7a272de11ec761796e511090db58f8713150d716 100644 (file)
@@ -1499,7 +1499,7 @@ init_threadstate(_PyThreadStateImpl *_tstate,
     tstate->previous_executor = NULL;
     tstate->dict_global_version = 0;
 
-    tstate->asyncio_running_loop = NULL;
+    _tstate->asyncio_running_loop = NULL;
 
     tstate->delete_later = NULL;
 
@@ -1702,7 +1702,7 @@ PyThreadState_Clear(PyThreadState *tstate)
 
     /* Don't clear tstate->pyframe: it is a borrowed reference */
 
-    Py_CLEAR(tstate->asyncio_running_loop);
+    Py_CLEAR(((_PyThreadStateImpl *)tstate)->asyncio_running_loop);
 
     Py_CLEAR(tstate->dict);
     Py_CLEAR(tstate->async_exc);