Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit faa6003

Browse files
author
Anselm Kruis
committed
Merge branch main into main-slp
2 parents 190fa92 + 0fd2c30 commit faa6003

File tree

11 files changed

+103
-99
lines changed

11 files changed

+103
-99
lines changed

‎Include/cpython/pystate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ struct _ts {
113113
* if the thread holds the last reference to the lock, decref'ing the
114114
* lock will delete the lock, and that may trigger arbitrary Python code
115115
* if there's a weakref, with a callback, to the lock. But by this time
116-
* _PyRuntimeState.gilstate.tstate_current is already NULL, so only the
117-
* simplest of C code can be allowed to run (in particular it must not be
118-
* possible to release the GIL).
116+
* _PyRuntime.gilstate.tstate_current is already NULL, so only the simplest
117+
* of C code can be allowed to run (in particular it must not be possible to
118+
* release the GIL).
119119
* So instead of holding the lock directly, the tstate holds a weakref to
120120
* the lock: that's the value of on_delete_data below. Decref'ing a
121121
* weakref is harmless.

‎Include/internal/pycore_object.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);
1919
* NB: While the object is tracked by the collector, it must be safe to call the
2020
* ob_traverse method.
2121
*
22-
* Internal note: _PyRuntimeState.gc.generation0->_gc_prev doesn't have
23-
* any bit flags because it's not object header. So we don't use
24-
* _PyGCHead_PREV() and _PyGCHead_SET_PREV() for it to avoid unnecessary
25-
* bitwise operations.
22+
* Internal note: _PyRuntime.gc.generation0->_gc_prev doesn't have any bit flags
23+
* because it's not object header. So we don't use _PyGCHead_PREV() and
24+
* _PyGCHead_SET_PREV() for it to avoid unnecessary bitwise operations.
2625
*
2726
* The PyObject_GC_Track() function is the public version of this macro.
2827
*/

‎Include/internal/pycore_pylifecycle.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ extern PyStatus _PyFaulthandler_Init(int enable);
3939
extern int _PyTraceMalloc_Init(int enable);
4040
extern PyObject * _PyBuiltin_Init(void);
4141
extern PyStatus _PySys_Create(
42+
_PyRuntimeState *runtime,
4243
PyInterpreterState *interp,
4344
PyObject **sysmod_p);
4445
extern PyStatus _PySys_SetPreliminaryStderr(PyObject *sysdict);
45-
extern int _PySys_InitMain(PyInterpreterState *interp);
46+
extern int _PySys_InitMain(
47+
_PyRuntimeState *runtime,
48+
PyInterpreterState *interp);
4649
extern PyStatus _PyImport_Init(PyInterpreterState *interp);
4750
extern PyStatus _PyExc_Init(void);
4851
extern PyStatus _PyErr_Init(void);
@@ -83,7 +86,10 @@ extern void _PyHash_Fini(void);
8386
extern int _PyTraceMalloc_Fini(void);
8487
extern void _PyWarnings_Fini(PyInterpreterState *interp);
8588

86-
extern void _PyGILState_Init(PyThreadState *tstate);
89+
extern void _PyGILState_Init(
90+
_PyRuntimeState *runtime,
91+
PyInterpreterState *interp,
92+
PyThreadState *tstate);
8793
extern void _PyGILState_Fini(_PyRuntimeState *runtime);
8894

8995
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(_PyRuntimeState *runtime);

‎Include/internal/pycore_pystate.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ extern "C" {
2323
#include "pycore_slp_pystate.h"
2424
#endif
2525

26-
// forward
27-
struct pyruntimestate;
28-
2926

3027
/* ceval state */
3128

@@ -75,7 +72,6 @@ struct _is {
7572

7673
struct _is *next;
7774
struct _ts *tstate_head;
78-
struct pyruntimestate *runtime;
7975

8076
int64_t id;
8177
int64_t id_refcount;
@@ -310,8 +306,12 @@ PyAPI_FUNC(void) _PyRuntime_Finalize(void);
310306

311307
/* Other */
312308

313-
PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *tstate);
314-
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate);
309+
PyAPI_FUNC(void) _PyThreadState_Init(
310+
_PyRuntimeState *runtime,
311+
PyThreadState *tstate);
312+
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(
313+
_PyRuntimeState *runtime,
314+
PyThreadState *tstate);
315315

316316
PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap(
317317
struct _gilstate_runtime_state *gilstate,

‎Misc/NEWS.d/next/Core and Builtins/2019-05-06-14-46-48.bpo-36818.5UDDLj.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎Modules/_threadmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ t_bootstrap(void *boot_raw)
996996

997997
tstate = boot->tstate;
998998
tstate->thread_id = PyThread_get_thread_ident();
999-
_PyThreadState_Init(tstate);
999+
_PyThreadState_Init(&_PyRuntime, tstate);
10001000
PyEval_AcquireThread(tstate);
10011001
tstate->interp->num_threads++;
10021002
res = PyObject_Call(boot->func, boot->args, boot->keyw);

‎Python/ceval.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
239239
}
240240

241241
static inline void
242-
exit_thread_if_finalizing(PyThreadState *tstate)
242+
exit_thread_if_finalizing(_PyRuntimeState*runtime, PyThreadState *tstate)
243243
{
244-
_PyRuntimeState *runtime = tstate->interp->runtime;
245244
/* _Py_Finalizing is protected by the GIL */
246245
if (runtime->finalizing != NULL && !_Py_CURRENTLY_FINALIZING(runtime, tstate)) {
247246
drop_gil(&runtime->ceval, tstate);
@@ -288,7 +287,7 @@ PyEval_AcquireLock(void)
288287
Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
289288
}
290289
take_gil(ceval, tstate);
291-
exit_thread_if_finalizing(tstate);
290+
exit_thread_if_finalizing(runtime, tstate);
292291
}
293292

294293
void
@@ -309,15 +308,14 @@ PyEval_AcquireThread(PyThreadState *tstate)
309308
if (tstate == NULL) {
310309
Py_FatalError("PyEval_AcquireThread: NULL new thread state");
311310
}
312-
assert(tstate->interp != NULL);
313311

314-
_PyRuntimeState *runtime = tstate->interp->runtime;
312+
_PyRuntimeState *runtime = &_PyRuntime;
315313
struct _ceval_runtime_state *ceval = &runtime->ceval;
316314

317315
/* Check someone has called PyEval_InitThreads() to create the lock */
318316
assert(gil_created(&ceval->gil));
319317
take_gil(ceval, tstate);
320-
exit_thread_if_finalizing(tstate);
318+
exit_thread_if_finalizing(runtime, tstate);
321319
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
322320
Py_FatalError("PyEval_AcquireThread: non-NULL old thread state");
323321
}
@@ -329,9 +327,8 @@ PyEval_ReleaseThread(PyThreadState *tstate)
329327
if (tstate == NULL) {
330328
Py_FatalError("PyEval_ReleaseThread: NULL thread state");
331329
}
332-
assert(tstate->interp != NULL);
333330

334-
_PyRuntimeState *runtime = tstate->interp->runtime;
331+
_PyRuntimeState *runtime = &_PyRuntime;
335332
PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
336333
if (new_tstate != tstate) {
337334
Py_FatalError("PyEval_ReleaseThread: wrong thread state");
@@ -362,7 +359,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
362359
}
363360

364361
/* Destroy all threads except the current one */
365-
_PyThreadState_DeleteExcept(current_tstate);
362+
_PyThreadState_DeleteExcept(runtime, current_tstate);
366363
}
367364

368365
/* This function is used to signal that async exceptions are waiting to be
@@ -391,18 +388,17 @@ PyEval_SaveThread(void)
391388
void
392389
PyEval_RestoreThread(PyThreadState *tstate)
393390
{
391+
_PyRuntimeState *runtime = &_PyRuntime;
392+
struct _ceval_runtime_state *ceval = &runtime->ceval;
393+
394394
if (tstate == NULL) {
395395
Py_FatalError("PyEval_RestoreThread: NULL tstate");
396396
}
397-
assert(tstate->interp != NULL);
398-
399-
_PyRuntimeState *runtime = tstate->interp->runtime;
400-
struct _ceval_runtime_state *ceval = &runtime->ceval;
401397
assert(gil_created(&ceval->gil));
402398

403399
int err = errno;
404400
take_gil(ceval, tstate);
405-
exit_thread_if_finalizing(tstate);
401+
exit_thread_if_finalizing(runtime, tstate);
406402
errno = err;
407403

408404
_PyThreadState_Swap(&runtime->gilstate, tstate);
@@ -1431,7 +1427,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
14311427
take_gil(ceval, tstate);
14321428

14331429
/* Check if we should make a quick exit. */
1434-
exit_thread_if_finalizing(tstate);
1430+
exit_thread_if_finalizing(runtime, tstate);
14351431

14361432
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
14371433
Py_FatalError("ceval: orphan tstate");

‎Python/import.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,7 @@ PyImport_Cleanup(void)
541541
_PyGC_CollectNoFail();
542542
/* Dump GC stats before it's too late, since it uses the warnings
543543
machinery. */
544-
_PyRuntimeState *runtime = interp->runtime;
545-
_PyGC_DumpShutdownStats(runtime);
544+
_PyGC_DumpShutdownStats(&_PyRuntime);
546545

547546
/* Now, if there are any modules left alive, clear their globals to
548547
minimize potential leaks. All C extension modules actually end

‎Python/pylifecycle.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
547547
_PyEval_FiniThreads(&runtime->ceval);
548548

549549
/* Auto-thread-state API */
550-
_PyGILState_Init(tstate);
550+
_PyGILState_Init(runtime, interp, tstate);
551551

552552
/* Create the GIL */
553553
PyEval_InitThreads();
@@ -690,7 +690,7 @@ pyinit_config(_PyRuntimeState *runtime,
690690
}
691691

692692
PyObject *sysmod;
693-
status = _PySys_Create(interp, &sysmod);
693+
status = _PySys_Create(runtime, interp, &sysmod);
694694
if (_PyStatus_EXCEPTION(status)) {
695695
return status;
696696
}
@@ -899,9 +899,8 @@ _Py_ReconfigureMainInterpreter(PyInterpreterState *interp)
899899
* non-zero return code.
900900
*/
901901
static PyStatus
902-
pyinit_main(PyInterpreterState *interp)
902+
pyinit_main(_PyRuntimeState*runtime, PyInterpreterState *interp)
903903
{
904-
_PyRuntimeState *runtime = interp->runtime;
905904
if (!runtime->core_initialized) {
906905
return _PyStatus_ERR("runtime core not initialized");
907906
}
@@ -927,7 +926,7 @@ pyinit_main(PyInterpreterState *interp)
927926
return _PyStatus_ERR("can't initialize time");
928927
}
929928

930-
if (_PySys_InitMain(interp) < 0) {
929+
if (_PySys_InitMain(runtime, interp) < 0) {
931930
return _PyStatus_ERR("can't finish initializing sys");
932931
}
933932

@@ -1007,7 +1006,7 @@ _Py_InitializeMain(void)
10071006
_PyRuntimeState *runtime = &_PyRuntime;
10081007
PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
10091008

1010-
return pyinit_main(interp);
1009+
return pyinit_main(runtime, interp);
10111010
}
10121011

10131012

@@ -1034,7 +1033,7 @@ Py_InitializeFromConfig(const PyConfig *config)
10341033
config = &interp->config;
10351034

10361035
if (config->_init_main) {
1037-
status = pyinit_main(interp);
1036+
status = pyinit_main(runtime, interp);
10381037
if (_PyStatus_EXCEPTION(status)) {
10391038
return status;
10401039
}
@@ -1470,7 +1469,7 @@ new_interpreter(PyThreadState **tstate_p)
14701469
}
14711470
Py_INCREF(interp->sysdict);
14721471
PyDict_SetItemString(interp->sysdict, "modules", modules);
1473-
if (_PySys_InitMain(interp) < 0) {
1472+
if (_PySys_InitMain(runtime, interp) < 0) {
14741473
return _PyStatus_ERR("can't finish initializing sys");
14751474
}
14761475
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /