Skip to content

Commit b2fb169

Browse files
committed
refactor: _getLoopOnThread getting thread dict
1 parent aea53bd commit b2fb169

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/PyEventLoop.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ PyEventLoop PyEventLoop::_loopNotFound() {
141141
PyEventLoop PyEventLoop::_getLoopOnThread(PyThreadState *tstate) {
142142
// Modified from Python 3.9 `get_running_loop` https://github.com/python/cpython/blob/7cb3a44/Modules/_asynciomodule.c#L241-L278
143143

144+
PyObject *ts_dict;
144145
#if PY_VERSION_HEX >= 0x030d0000 // Python version is greater than 3.13
145146
// The private `_PyThreadState_GetDict(tstate)` API gets removed in Python 3.13.
146147
// However, simply replacing it with `PyThreadState_GetDict()` does not work,
@@ -156,11 +157,11 @@ PyEventLoop PyEventLoop::_getLoopOnThread(PyThreadState *tstate) {
156157
return _loopNotFound();
157158
}
158159
}
159-
PyObject *ts_dict = tstate->dict;
160+
ts_dict = tstate->dict;
160161
#elif PY_VERSION_HEX >= 0x03090000 // Python version is greater than 3.9
161-
PyObject *ts_dict = _PyThreadState_GetDict(tstate); // borrowed reference
162+
ts_dict = _PyThreadState_GetDict(tstate); // borrowed reference
162163
#else // Python 3.8
163-
PyObject *ts_dict = tstate->dict; // see https://github.com/python/cpython/blob/v3.8.17/Modules/_asynciomodule.c#L244-L245
164+
ts_dict = tstate->dict; // see https://github.com/python/cpython/blob/v3.8.17/Modules/_asynciomodule.c#L244-L245
164165
#endif
165166
if (ts_dict == NULL) {
166167
return _loopNotFound();

0 commit comments

Comments
 (0)