bpo-39947: Add PyThreadState_GetInterpreter() (GH-18981)

Add PyThreadState_GetInterpreter(tstate): get the interpreter of a
Python thread state.
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index 661ed59..f309ad0 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -1064,12 +1064,21 @@
    :c:func:`PyThreadState_Clear`.
 
 
-   .. c:function:: void PyThreadState_DeleteCurrent()
+.. c:function:: void PyThreadState_DeleteCurrent(void)
 
-    Destroy the current thread state and release the global interpreter lock.
-    Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not
-    be held. The thread state must have been reset with a previous call
-    to :c:func:`PyThreadState_Clear`.
+   Destroy the current thread state and release the global interpreter lock.
+   Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not
+   be held. The thread state must have been reset with a previous call
+   to :c:func:`PyThreadState_Clear`.
+
+
+.. c:function:: PyInterpreterState* PyThreadState_GetInterpreter(PyThreadState *tstate)
+
+   Get the interpreter of the Python thread state *tstate*.
+
+   *tstate* must not be ``NULL``.
+
+   .. versionadded:: 3.9
 
 
 .. c:function:: PyInterpreterState* PyInterpreterState_Get(void)
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 4373e37..4ef82fe 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -406,7 +406,8 @@
 Build and C API Changes
 =======================
 
-* New :c:func:`PyInterpreterState_Get` function.
+* New :c:func:`PyThreadState_GetInterpreter` and
+  :c:func:`PyInterpreterState_Get` functions to get the interpreter.
 
 * Add ``--with-platlibdir`` option to the ``configure`` script: name of the
   platform-specific library directory, stored in the new :attr:`sys.platlibdir`