bpo-36710: Add PyInterpreterState.runtime field (GH-17270) · python/cpython@01b1cc1 (original) (raw)
`@@ -191,7 +191,8 @@ static size_t opcache_global_misses = 0;
`
191
191
`int
`
192
192
`PyEval_ThreadsInitialized(void)
`
193
193
`{
`
194
``
`-
return gil_created(&_PyRuntime.ceval.gil);
`
``
194
`+
_PyRuntimeState *runtime = &_PyRuntime;
`
``
195
`+
return gil_created(&runtime->ceval.gil);
`
195
196
`}
`
196
197
``
197
198
`void
`
`@@ -235,8 +236,9 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
`
235
236
`}
`
236
237
``
237
238
`static inline void
`
238
``
`-
exit_thread_if_finalizing(_PyRuntimeState *runtime, PyThreadState *tstate)
`
``
239
`+
exit_thread_if_finalizing(PyThreadState *tstate)
`
239
240
`{
`
``
241
`+
_PyRuntimeState *runtime = tstate->interp->runtime;
`
240
242
`/* _Py_Finalizing is protected by the GIL */
`
241
243
`if (runtime->finalizing != NULL && !_Py_CURRENTLY_FINALIZING(runtime, tstate)) {
`
242
244
`drop_gil(&runtime->ceval, tstate);
`
`@@ -283,7 +285,7 @@ PyEval_AcquireLock(void)
`
283
285
`Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
`
284
286
` }
`
285
287
`take_gil(ceval, tstate);
`
286
``
`-
exit_thread_if_finalizing(runtime, tstate);
`
``
288
`+
exit_thread_if_finalizing(tstate);
`
287
289
`}
`
288
290
``
289
291
`void
`
`@@ -305,13 +307,13 @@ PyEval_AcquireThread(PyThreadState *tstate)
`
305
307
`Py_FatalError("PyEval_AcquireThread: NULL new thread state");
`
306
308
` }
`
307
309
``
308
``
`-
_PyRuntimeState *runtime = &_PyRuntime;
`
``
310
`+
_PyRuntimeState *runtime = tstate->interp->runtime;
`
309
311
`struct _ceval_runtime_state *ceval = &runtime->ceval;
`
310
312
``
311
313
`/* Check someone has called PyEval_InitThreads() to create the lock */
`
312
314
`assert(gil_created(&ceval->gil));
`
313
315
`take_gil(ceval, tstate);
`
314
``
`-
exit_thread_if_finalizing(runtime, tstate);
`
``
316
`+
exit_thread_if_finalizing(tstate);
`
315
317
`if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
`
316
318
`Py_FatalError("PyEval_AcquireThread: non-NULL old thread state");
`
317
319
` }
`
`@@ -324,7 +326,7 @@ PyEval_ReleaseThread(PyThreadState *tstate)
`
324
326
`Py_FatalError("PyEval_ReleaseThread: NULL thread state");
`
325
327
` }
`
326
328
``
327
``
`-
_PyRuntimeState *runtime = &_PyRuntime;
`
``
329
`+
_PyRuntimeState *runtime = tstate->interp->runtime;
`
328
330
`PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
`
329
331
`if (new_tstate != tstate) {
`
330
332
`Py_FatalError("PyEval_ReleaseThread: wrong thread state");
`
`@@ -384,7 +386,7 @@ PyEval_SaveThread(void)
`
384
386
`void
`
385
387
`PyEval_RestoreThread(PyThreadState *tstate)
`
386
388
`{
`
387
``
`-
_PyRuntimeState *runtime = &_PyRuntime;
`
``
389
`+
_PyRuntimeState *runtime = tstate->interp->runtime;
`
388
390
`struct _ceval_runtime_state *ceval = &runtime->ceval;
`
389
391
``
390
392
`if (tstate == NULL) {
`
`@@ -394,7 +396,7 @@ PyEval_RestoreThread(PyThreadState *tstate)
`
394
396
``
395
397
`int err = errno;
`
396
398
`take_gil(ceval, tstate);
`
397
``
`-
exit_thread_if_finalizing(runtime, tstate);
`
``
399
`+
exit_thread_if_finalizing(tstate);
`
398
400
`errno = err;
`
399
401
``
400
402
`_PyThreadState_Swap(&runtime->gilstate, tstate);
`
`@@ -649,7 +651,8 @@ _PyEval_Initialize(struct _ceval_runtime_state *state)
`
649
651
`int
`
650
652
`Py_GetRecursionLimit(void)
`
651
653
`{
`
652
``
`-
return _PyRuntime.ceval.recursion_limit;
`
``
654
`+
struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;
`
``
655
`+
return ceval->recursion_limit;
`
653
656
`}
`
654
657
``
655
658
`void
`
`@@ -668,7 +671,7 @@ Py_SetRecursionLimit(int new_limit)
`
668
671
`int
`
669
672
`_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
`
670
673
`{
`
671
``
`-
_PyRuntimeState *runtime = &_PyRuntime;
`
``
674
`+
_PyRuntimeState *runtime = tstate->interp->runtime;
`
672
675
`int recursion_limit = runtime->ceval.recursion_limit;
`
673
676
``
674
677
`#ifdef USE_STACKCHECK
`
`@@ -1245,7 +1248,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
`
1245
1248
`take_gil(ceval, tstate);
`
1246
1249
``
1247
1250
`/* Check if we should make a quick exit. */
`
1248
``
`-
exit_thread_if_finalizing(runtime, tstate);
`
``
1251
`+
exit_thread_if_finalizing(tstate);
`
1249
1252
``
1250
1253
`if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
`
1251
1254
`Py_FatalError("ceval: orphan tstate");
`
`@@ -4806,7 +4809,8 @@ _PyEval_GetAsyncGenFinalizer(void)
`
4806
4809
`static PyFrameObject *
`
4807
4810
`_PyEval_GetFrame(PyThreadState *tstate)
`
4808
4811
`{
`
4809
``
`-
return _PyRuntime.gilstate.getframe(tstate);
`
``
4812
`+
_PyRuntimeState *runtime = tstate->interp->runtime;
`
``
4813
`+
return runtime->gilstate.getframe(tstate);
`
4810
4814
`}
`
4811
4815
``
4812
4816
`PyFrameObject *
`