bpo-39947: Use _PyInterpreterState_GET_UNSAFE() (GH-18978)
Replace _PyInterpreterState_Get() function call with
_PyInterpreterState_GET_UNSAFE() macro which is more efficient but
don't check if tstate or interp is NULL.
_Py_GetConfigsAsDict() now uses _PyThreadState_GET().
diff --git a/Python/import.c b/Python/import.c
index c4a19bc..936ad1f 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -642,7 +642,7 @@
PyImport_GetMagicNumber(void)
{
long res;
- PyInterpreterState *interp = _PyInterpreterState_Get();
+ PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
PyObject *external, *pyc_magic;
external = PyObject_GetAttrString(interp->importlib, "_bootstrap_external");
@@ -2412,7 +2412,7 @@
goto failure;
}
- const wchar_t *mode = _PyInterpreterState_Get()->config.check_hash_pycs_mode;
+ const wchar_t *mode = _PyInterpreterState_GET_UNSAFE()->config.check_hash_pycs_mode;
PyObject *pyc_mode = PyUnicode_FromWideChar(mode, -1);
if (pyc_mode == NULL) {
goto failure;