File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -1242,6 +1242,13 @@ _PyThreadState_Init(PyThreadState *tstate)
1242
1242
void
1243
1243
PyThreadState_Clear (PyThreadState * tstate )
1244
1244
{
1245
+ /* XXX Conditions we need to enforce:
1246
+
1247
+ * the GIL must be held by the current thread
1248
+ * current_fast_get()->interp must match tstate->interp
1249
+ * for the main interpreter, current_fast_get() must be the main thread
1250
+ */
1251
+
1245
1252
// The GIL must be held by the current thread,
1246
1253
// which must not be the target.
1247
1254
// XXX Enforce that (check current_fast_get()).
@@ -1260,6 +1267,17 @@ PyThreadState_Clear(PyThreadState *tstate)
1260
1267
"PyThreadState_Clear: warning: thread still has a frame\n" );
1261
1268
}
1262
1269
1270
+ /* At this point tstate shouldn't be used any more,
1271
+ neither to run Python code nor for other uses.
1272
+
1273
+ This is tricky when current_fast_get() == tstate, in the same way
1274
+ as noted in interpreter_clear() above. The below finalizers
1275
+ can possibly run Python code or otherwise use the partially
1276
+ cleared thread state. For now we trust that isn't a problem
1277
+ in practice.
1278
+ */
1279
+ // XXX Deal with the possibility of problematic finalizers.
1280
+
1263
1281
/* Don't clear tstate->pyframe: it is a borrowed reference */
1264
1282
1265
1283
Py_CLEAR (tstate -> dict );
You can’t perform that action at this time.
0 commit comments