bpo-38858: Add _Py_IsMainInterpreter(tstate) (GH-17293) · python/cpython@fff7bbf (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Commit fff7bbf
File tree
3 files changed
lines changed
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -269,6 +269,8 @@ PyAPI_FUNC(void) _PyRuntime_Finalize(void); | ||
269 | 269 | #define _Py_CURRENTLY_FINALIZING(runtime, tstate) \ |
270 | 270 | (runtime->finalizing == tstate) |
271 | 271 | |
272 | +PyAPI_FUNC(int) _Py_IsMainInterpreter(PyThreadState* tstate); | |
273 | + | |
272 | 274 | |
273 | 275 | /* Variable and macro for in-line access to current thread |
274 | 276 | and interpreter state */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1466,9 +1466,9 @@ static PyObject * | ||
1466 | 1466 | _thread__is_main_interpreter_impl(PyObject *module) |
1467 | 1467 | /*[clinic end generated code: output=7dd82e1728339adc input=cc1eb00fd4598915]*/ |
1468 | 1468 | { |
1469 | -_PyRuntimeState *runtime = &_PyRuntime; | |
1470 | -PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp; | |
1471 | -return PyBool_FromLong(interp == runtime->interpreters.main); | |
1469 | +PyThreadState *tstate = _PyThreadState_GET(); | |
1470 | +int is_main = _Py_IsMainInterpreter(tstate); | |
1471 | +return PyBool_FromLong(is_main); | |
1472 | 1472 | } |
1473 | 1473 | |
1474 | 1474 | static PyMethodDef thread_methods[] = { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -159,6 +159,12 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime) | ||
159 | 159 | #define HEAD_UNLOCK(runtime) \ |
160 | 160 | PyThread_release_lock((runtime)->interpreters.mutex) |
161 | 161 | |
162 | +int | |
163 | +_Py_IsMainInterpreter(PyThreadState* tstate) | |
164 | +{ | |
165 | +return (tstate->interp == tstate->interp->runtime->interpreters.main); | |
166 | +} | |
167 | + | |
162 | 168 | /* Forward declaration */ |
163 | 169 | static void _PyGILState_NoteThreadState( |
164 | 170 | struct _gilstate_runtime_state *gilstate, PyThreadState* tstate); |