Revert "bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)" … · python/cpython@0fd2c30 (original) (raw)
`@@ -238,9 +238,8 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
`
238
238
`}
`
239
239
``
240
240
`static inline void
`
241
``
`-
exit_thread_if_finalizing(PyThreadState *tstate)
`
``
241
`+
exit_thread_if_finalizing(_PyRuntimeState *runtime, PyThreadState *tstate)
`
242
242
`{
`
243
``
`-
_PyRuntimeState *runtime = tstate->interp->runtime;
`
244
243
`/* _Py_Finalizing is protected by the GIL */
`
245
244
`if (runtime->finalizing != NULL && !_Py_CURRENTLY_FINALIZING(runtime, tstate)) {
`
246
245
`drop_gil(&runtime->ceval, tstate);
`
`@@ -287,7 +286,7 @@ PyEval_AcquireLock(void)
`
287
286
`Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
`
288
287
` }
`
289
288
`take_gil(ceval, tstate);
`
290
``
`-
exit_thread_if_finalizing(tstate);
`
``
289
`+
exit_thread_if_finalizing(runtime, tstate);
`
291
290
`}
`
292
291
``
293
292
`void
`
`@@ -308,15 +307,14 @@ PyEval_AcquireThread(PyThreadState *tstate)
`
308
307
`if (tstate == NULL) {
`
309
308
`Py_FatalError("PyEval_AcquireThread: NULL new thread state");
`
310
309
` }
`
311
``
`-
assert(tstate->interp != NULL);
`
312
310
``
313
``
`-
_PyRuntimeState *runtime = tstate->interp->runtime;
`
``
311
`+
_PyRuntimeState *runtime = &_PyRuntime;
`
314
312
`struct _ceval_runtime_state *ceval = &runtime->ceval;
`
315
313
``
316
314
`/* Check someone has called PyEval_InitThreads() to create the lock */
`
317
315
`assert(gil_created(&ceval->gil));
`
318
316
`take_gil(ceval, tstate);
`
319
``
`-
exit_thread_if_finalizing(tstate);
`
``
317
`+
exit_thread_if_finalizing(runtime, tstate);
`
320
318
`if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
`
321
319
`Py_FatalError("PyEval_AcquireThread: non-NULL old thread state");
`
322
320
` }
`
`@@ -328,9 +326,8 @@ PyEval_ReleaseThread(PyThreadState *tstate)
`
328
326
`if (tstate == NULL) {
`
329
327
`Py_FatalError("PyEval_ReleaseThread: NULL thread state");
`
330
328
` }
`
331
``
`-
assert(tstate->interp != NULL);
`
332
329
``
333
``
`-
_PyRuntimeState *runtime = tstate->interp->runtime;
`
``
330
`+
_PyRuntimeState *runtime = &_PyRuntime;
`
334
331
`PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
`
335
332
`if (new_tstate != tstate) {
`
336
333
`Py_FatalError("PyEval_ReleaseThread: wrong thread state");
`
`@@ -361,7 +358,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
`
361
358
` }
`
362
359
``
363
360
`/* Destroy all threads except the current one */
`
364
``
`-
_PyThreadState_DeleteExcept(current_tstate);
`
``
361
`+
_PyThreadState_DeleteExcept(runtime, current_tstate);
`
365
362
`}
`
366
363
``
367
364
`/* This function is used to signal that async exceptions are waiting to be
`
`@@ -390,18 +387,17 @@ PyEval_SaveThread(void)
`
390
387
`void
`
391
388
`PyEval_RestoreThread(PyThreadState *tstate)
`
392
389
`{
`
``
390
`+
_PyRuntimeState *runtime = &_PyRuntime;
`
``
391
`+
struct _ceval_runtime_state *ceval = &runtime->ceval;
`
``
392
+
393
393
`if (tstate == NULL) {
`
394
394
`Py_FatalError("PyEval_RestoreThread: NULL tstate");
`
395
395
` }
`
396
``
`-
assert(tstate->interp != NULL);
`
397
``
-
398
``
`-
_PyRuntimeState *runtime = tstate->interp->runtime;
`
399
``
`-
struct _ceval_runtime_state *ceval = &runtime->ceval;
`
400
396
`assert(gil_created(&ceval->gil));
`
401
397
``
402
398
`int err = errno;
`
403
399
`take_gil(ceval, tstate);
`
404
``
`-
exit_thread_if_finalizing(tstate);
`
``
400
`+
exit_thread_if_finalizing(runtime, tstate);
`
405
401
`errno = err;
`
406
402
``
407
403
`_PyThreadState_Swap(&runtime->gilstate, tstate);
`
`@@ -1250,7 +1246,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
`
1250
1246
`take_gil(ceval, tstate);
`
1251
1247
``
1252
1248
`/* Check if we should make a quick exit. */
`
1253
``
`-
exit_thread_if_finalizing(tstate);
`
``
1249
`+
exit_thread_if_finalizing(runtime, tstate);
`
1254
1250
``
1255
1251
`if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
`
1256
1252
`Py_FatalError("ceval: orphan tstate");
`