bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)

sys_setcheckinterval() now uses a local variable to parse arguments,
before writing into interp->check_interval.
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index b07667c..cedf11e 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -3,6 +3,7 @@
 #include "Python.h"
 #include "code.h"
 #include "structmember.h"
+#include "internal/pystate.h"
 
 /* Holder for co_extra information */
 typedef struct {
@@ -428,7 +429,7 @@
 code_dealloc(PyCodeObject *co)
 {
     if (co->co_extra != NULL) {
-        PyInterpreterState *interp = PyThreadState_Get()->interp;
+        PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
         _PyCodeObjectExtra *co_extra = co->co_extra;
 
         for (Py_ssize_t i = 0; i < co_extra->ce_size; i++) {
@@ -871,7 +872,7 @@
 int
 _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
 {
-    PyInterpreterState *interp = PyThreadState_Get()->interp;
+    PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
 
     if (!PyCode_Check(code) || index < 0 ||
             index >= interp->co_extra_user_count) {
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 4108f50..308ae83 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -85,7 +85,7 @@
 static void
 show_alloc(void)
 {
-    PyInterpreterState *interp = PyThreadState_GET()->interp;
+    PyInterpreterState *interp = _PyInterpreterState_Get();
     if (!interp->core_config.show_alloc_count) {
         return;
     }
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 5fad447..2156ca0 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -173,7 +173,7 @@
 PyObject *
 PyModule_Create2(struct PyModuleDef* module, int module_api_version)
 {
-    if (!_PyImport_IsInitialized(PyThreadState_GET()->interp))
+    if (!_PyImport_IsInitialized(_PyInterpreterState_Get()))
         Py_FatalError("Python import machinery not initialized");
     return _PyModule_CreateInitialized(module, module_api_version);
 }
@@ -693,8 +693,7 @@
 static PyObject *
 module_repr(PyModuleObject *m)
 {
-    PyThreadState *tstate = PyThreadState_GET();
-    PyInterpreterState *interp = tstate->interp;
+    PyInterpreterState *interp = _PyInterpreterState_Get();
 
     return PyObject_CallMethod(interp->importlib, "_module_repr", "O", m);
 }
diff --git a/Objects/object.c b/Objects/object.c
index 2471f6b..6498756 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -96,7 +96,7 @@
 void
 dump_counts(FILE* f)
 {
-    PyInterpreterState *interp = PyThreadState_GET()->interp;
+    PyInterpreterState *interp = _PyInterpreterState_Get();
     if (!interp->core_config.show_alloc_count) {
         return;
     }
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index e268f75..eaf92d5 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -44,7 +44,7 @@
 static void
 show_track(void)
 {
-    PyInterpreterState *interp = PyThreadState_GET()->interp;
+    PyInterpreterState *interp = _PyInterpreterState_Get();
     if (!interp->core_config.show_alloc_count) {
         return;
     }
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 2b06f15..04fd6d0 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3413,7 +3413,7 @@
 #if defined(__APPLE__)
     return _PyUnicode_AsUTF8String(unicode, Py_FileSystemDefaultEncodeErrors);
 #else
-    PyInterpreterState *interp = PyThreadState_GET()->interp;
+    PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
     /* Bootstrap check: if the filesystem codec is implemented in Python, we
        cannot use it to encode and decode filenames before it is loaded. Load
        the Python codec requires to encode at least its own filename. Use the C
@@ -3639,7 +3639,7 @@
 #if defined(__APPLE__)
     return PyUnicode_DecodeUTF8Stateful(s, size, Py_FileSystemDefaultEncodeErrors, NULL);
 #else
-    PyInterpreterState *interp = PyThreadState_GET()->interp;
+    PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
     /* Bootstrap check: if the filesystem codec is implemented in Python, we
        cannot use it to encode and decode filenames before it is loaded. Load
        the Python codec requires to encode at least its own filename. Use the C