Skip to content

Commit 101bf69

Browse files
authored
bpo-43268: _Py_IsMainInterpreter() now expects interp (GH-24577)
The _Py_IsMainInterpreter() function now expects interp rather than tstate.
1 parent 6207810 commit 101bf69

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed

Include/internal/pycore_pystate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ _Py_IsMainThread(void)
2222

2323

2424
static inline int
25-
_Py_IsMainInterpreter(PyThreadState* tstate)
25+
_Py_IsMainInterpreter(PyInterpreterState *interp)
2626
{
2727
/* Use directly _PyRuntime rather than tstate->interp->runtime, since
2828
this function is used in performance critical code path (ceval) */
29-
return (tstate->interp == _PyRuntime.interpreters.main);
29+
return (interp == _PyRuntime.interpreters.main);
3030
}
3131

3232

Objects/longobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5719,7 +5719,7 @@ _PyLong_Init(PyThreadState *tstate)
57195719
tstate->interp->small_ints[i] = v;
57205720
}
57215721

5722-
if (_Py_IsMainInterpreter(tstate)) {
5722+
if (_Py_IsMainInterpreter(tstate->interp)) {
57235723
/* initialize int_info */
57245724
if (Int_InfoType.tp_name == NULL) {
57255725
if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) {

Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void
286286
_PyType_Fini(PyThreadState *tstate)
287287
{
288288
_PyType_ClearCache(&tstate->interp->type_cache);
289-
if (_Py_IsMainInterpreter(tstate)) {
289+
if (_Py_IsMainInterpreter(tstate->interp)) {
290290
clear_slotdefs();
291291
}
292292
}

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15701,7 +15701,7 @@ _PyUnicode_Init(PyThreadState *tstate)
1570115701
return _PyStatus_NO_MEMORY();
1570215702
}
1570315703

15704-
if (_Py_IsMainInterpreter(tstate)) {
15704+
if (_Py_IsMainInterpreter(tstate->interp)) {
1570515705
/* initialize the linebreak bloom filter */
1570615706
bloom_linebreak = make_bloom_mask(
1570715707
PyUnicode_2BYTE_KIND, linebreak,

Python/ceval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ PyStatus
298298
_PyEval_InitGIL(PyThreadState *tstate)
299299
{
300300
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
301-
if (!_Py_IsMainInterpreter(tstate)) {
301+
if (!_Py_IsMainInterpreter(tstate->interp)) {
302302
/* Currently, the GIL is shared by all interpreters,
303303
and only the main interpreter is responsible to create
304304
and destroy it. */
@@ -326,7 +326,7 @@ void
326326
_PyEval_FiniGIL(PyThreadState *tstate)
327327
{
328328
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
329-
if (!_Py_IsMainInterpreter(tstate)) {
329+
if (!_Py_IsMainInterpreter(tstate->interp)) {
330330
/* Currently, the GIL is shared by all interpreters,
331331
and only the main interpreter is responsible to create
332332
and destroy it. */

Python/context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ _PyContext_ClearFreeList(PyThreadState *tstate)
13021302
void
13031303
_PyContext_Fini(PyThreadState *tstate)
13041304
{
1305-
if (_Py_IsMainInterpreter(tstate)) {
1305+
if (_Py_IsMainInterpreter(tstate->interp)) {
13061306
Py_CLEAR(_token_missing);
13071307
}
13081308
_PyContext_ClearFreeList(tstate);

Python/import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ _PyImport_FixupExtensionObject(PyObject *mod, PyObject *name,
441441
return -1;
442442
}
443443

444-
if (_Py_IsMainInterpreter(tstate)) {
444+
if (_Py_IsMainInterpreter(tstate->interp)) {
445445
if (def->m_size == -1) {
446446
if (def->m_base.m_copy) {
447447
/* Somebody already imported the module,

Python/pylifecycle.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ interpreter_update_config(PyThreadState *tstate, int only_update_path_config)
430430
}
431431
}
432432

433-
if (_Py_IsMainInterpreter(tstate)) {
433+
if (_Py_IsMainInterpreter(tstate->interp)) {
434434
PyStatus status = _PyConfig_WritePathConfig(config);
435435
if (_PyStatus_EXCEPTION(status)) {
436436
_PyErr_SetFromPyStatus(status);
@@ -627,7 +627,7 @@ static PyStatus
627627
pycore_init_types(PyThreadState *tstate)
628628
{
629629
PyStatus status;
630-
int is_main_interp = _Py_IsMainInterpreter(tstate);
630+
int is_main_interp = _Py_IsMainInterpreter(tstate->interp);
631631

632632
status = _PyGC_Init(tstate);
633633
if (_PyStatus_EXCEPTION(status)) {
@@ -1003,7 +1003,7 @@ init_interp_main(PyThreadState *tstate)
10031003
assert(!_PyErr_Occurred(tstate));
10041004

10051005
PyStatus status;
1006-
int is_main_interp = _Py_IsMainInterpreter(tstate);
1006+
int is_main_interp = _Py_IsMainInterpreter(tstate->interp);
10071007
PyInterpreterState *interp = tstate->interp;
10081008
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
10091009

@@ -1597,7 +1597,7 @@ finalize_interp_types(PyThreadState *tstate)
15971597
static void
15981598
finalize_interp_clear(PyThreadState *tstate)
15991599
{
1600-
int is_main_interp = _Py_IsMainInterpreter(tstate);
1600+
int is_main_interp = _Py_IsMainInterpreter(tstate->interp);
16011601

16021602
/* Clear interpreter state and all thread states */
16031603
_PyInterpreterState_Clear(tstate);
@@ -1622,7 +1622,7 @@ finalize_interp_clear(PyThreadState *tstate)
16221622
static void
16231623
finalize_interp_delete(PyThreadState *tstate)
16241624
{
1625-
if (_Py_IsMainInterpreter(tstate)) {
1625+
if (_Py_IsMainInterpreter(tstate->interp)) {
16261626
/* Cleanup auto-thread-state */
16271627
_PyGILState_Fini(tstate);
16281628
}

Python/pystate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
13271327
PyStatus
13281328
_PyGILState_Init(PyThreadState *tstate)
13291329
{
1330-
if (!_Py_IsMainInterpreter(tstate)) {
1330+
if (!_Py_IsMainInterpreter(tstate->interp)) {
13311331
/* Currently, PyGILState is shared by all interpreters. The main
13321332
* interpreter is responsible to initialize it. */
13331333
return _PyStatus_OK();

0 commit comments

Comments
 (0)