File tree 3 files changed +23
-11
lines changed
3 files changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,8 @@ PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
149
149
* if it is NULL. */
150
150
PyAPI_FUNC (PyThreadState * ) _PyThreadState_UncheckedGet (void );
151
151
152
+ PyAPI_FUNC (PyObject * ) _PyThreadState_GetDict (PyThreadState * tstate );
153
+
152
154
/* PyGILState */
153
155
154
156
/* Helper/diagnostic function - return 1 if the current thread
Original file line number Diff line number Diff line change @@ -236,12 +236,13 @@ get_running_loop(PyObject **loop)
236
236
rl = cached_running_holder ; // borrowed
237
237
}
238
238
else {
239
- if (ts -> dict == NULL ) {
239
+ PyObject * ts_dict = _PyThreadState_GetDict (ts ); // borrowed
240
+ if (ts_dict == NULL ) {
240
241
goto not_found ;
241
242
}
242
243
243
244
rl = _PyDict_GetItemIdWithError (
244
- ts -> dict , & PyId___asyncio_running_event_loop__ ); // borrowed
245
+ ts_dict , & PyId___asyncio_running_event_loop__ ); // borrowed
245
246
if (rl == NULL ) {
246
247
if (PyErr_Occurred ()) {
247
248
goto error ;
Original file line number Diff line number Diff line change 4
4
#include "Python.h"
5
5
#include "pycore_ceval.h"
6
6
#include "pycore_initconfig.h"
7
+ #include "pycore_pyerrors.h"
8
+ #include "pycore_pylifecycle.h"
7
9
#include "pycore_pymem.h"
8
10
#include "pycore_pystate.h"
9
- #include "pycore_pylifecycle.h"
10
11
11
12
/* --------------------------------------------------------------------------
12
13
CAUTION
@@ -979,20 +980,28 @@ PyThreadState_Swap(PyThreadState *newts)
979
980
PyThreadState_GetDict() returns NULL, an exception has *not* been raised
980
981
and the caller should assume no per-thread state is available. */
981
982
983
+ PyObject *
984
+ _PyThreadState_GetDict (PyThreadState * tstate )
985
+ {
986
+ assert (tstate != NULL );
987
+ if (tstate -> dict == NULL ) {
988
+ tstate -> dict = PyDict_New ();
989
+ if (tstate -> dict == NULL ) {
990
+ _PyErr_Clear (tstate );
991
+ }
992
+ }
993
+ return tstate -> dict ;
994
+ }
995
+
996
+
982
997
PyObject *
983
998
PyThreadState_GetDict (void )
984
999
{
985
1000
PyThreadState * tstate = _PyThreadState_GET ();
986
- if (tstate == NULL )
1001
+ if (tstate == NULL ) {
987
1002
return NULL ;
988
-
989
- if (tstate -> dict == NULL ) {
990
- PyObject * d ;
991
- tstate -> dict = d = PyDict_New ();
992
- if (d == NULL )
993
- PyErr_Clear ();
994
1003
}
995
- return tstate -> dict ;
1004
+ return _PyThreadState_GetDict ( tstate ) ;
996
1005
}
997
1006
998
1007
You can’t perform that action at this time.
0 commit comments