File tree Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ extern "C" {
8
8
# error "this header requires Py_BUILD_CORE define"
9
9
#endif
10
10
11
+ #include "pycore_runtime.h" // _PyRuntimeState
12
+
11
13
/* Forward declarations */
12
14
struct _PyArgv ;
13
15
struct pyruntimestate ;
@@ -88,7 +90,8 @@ extern void _PyWarnings_Fini(PyInterpreterState *interp);
88
90
extern void _PyAST_Fini (PyInterpreterState * interp );
89
91
extern void _PyAtExit_Fini (PyInterpreterState * interp );
90
92
91
- extern PyStatus _PyGILState_Init (PyThreadState * tstate );
93
+ extern PyStatus _PyGILState_Init (_PyRuntimeState * runtime );
94
+ extern PyStatus _PyGILState_SetTstate (PyThreadState * tstate );
92
95
extern void _PyGILState_Fini (PyInterpreterState * interp );
93
96
94
97
PyAPI_FUNC (void ) _PyGC_DumpShutdownStats (PyInterpreterState * interp );
Original file line number Diff line number Diff line change @@ -577,7 +577,7 @@ init_interp_create_gil(PyThreadState *tstate)
577
577
_PyEval_FiniGIL (tstate -> interp );
578
578
579
579
/* Auto-thread-state API */
580
- status = _PyGILState_Init (tstate );
580
+ status = _PyGILState_SetTstate (tstate );
581
581
if (_PyStatus_EXCEPTION (status )) {
582
582
return status ;
583
583
}
@@ -597,12 +597,19 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
597
597
const PyConfig * config ,
598
598
PyThreadState * * tstate_p )
599
599
{
600
+ /* Auto-thread-state API */
601
+ PyStatus status = _PyGILState_Init (runtime );
602
+ if (_PyStatus_EXCEPTION (status )) {
603
+ return status ;
604
+ }
605
+
600
606
PyInterpreterState * interp = PyInterpreterState_New ();
601
607
if (interp == NULL ) {
602
608
return _PyStatus_ERR ("can't make main interpreter" );
603
609
}
610
+ assert (_Py_IsMainInterpreter (interp ));
604
611
605
- PyStatus status = _PyConfig_Copy (& interp -> config , config );
612
+ status = _PyConfig_Copy (& interp -> config , config );
606
613
if (_PyStatus_EXCEPTION (status )) {
607
614
return status ;
608
615
}
Original file line number Diff line number Diff line change @@ -1327,7 +1327,21 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
1327
1327
Py_Initialize/Py_FinalizeEx
1328
1328
*/
1329
1329
PyStatus
1330
- _PyGILState_Init (PyThreadState * tstate )
1330
+ _PyGILState_Init (_PyRuntimeState * runtime )
1331
+ {
1332
+ struct _gilstate_runtime_state * gilstate = & runtime -> gilstate ;
1333
+ if (PyThread_tss_create (& gilstate -> autoTSSkey ) != 0 ) {
1334
+ return _PyStatus_NO_MEMORY ();
1335
+ }
1336
+ // PyThreadState_New() calls _PyGILState_NoteThreadState() which does
1337
+ // nothing before autoInterpreterState is set.
1338
+ assert (gilstate -> autoInterpreterState == NULL );
1339
+ return _PyStatus_OK ();
1340
+ }
1341
+
1342
+
1343
+ PyStatus
1344
+ _PyGILState_SetTstate (PyThreadState * tstate )
1331
1345
{
1332
1346
if (!_Py_IsMainInterpreter (tstate -> interp )) {
1333
1347
/* Currently, PyGILState is shared by all interpreters. The main
@@ -1341,9 +1355,6 @@ _PyGILState_Init(PyThreadState *tstate)
1341
1355
1342
1356
struct _gilstate_runtime_state * gilstate = & tstate -> interp -> runtime -> gilstate ;
1343
1357
1344
- if (PyThread_tss_create (& gilstate -> autoTSSkey ) != 0 ) {
1345
- return _PyStatus_NO_MEMORY ();
1346
- }
1347
1358
gilstate -> autoInterpreterState = tstate -> interp ;
1348
1359
assert (PyThread_tss_get (& gilstate -> autoTSSkey ) == NULL );
1349
1360
assert (tstate -> gilstate_counter == 0 );
You can’t perform that action at this time.
0 commit comments