cpython/Include/cpython/pystate.h

#ifndef Py_CPYTHON_PYSTATE_H
#  error "this header file must not be included directly"
#endif


/* private interpreter helpers */

PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *);
PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int);

PyAPI_FUNC(PyObject *) PyUnstable_InterpreterState_GetMainModule(PyInterpreterState *);

/* State unique per thread */

/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
Py_tracefunc;

/* The following values are used for 'what' for tracefunc functions
 *
 * To add a new kind of trace event, also update "trace_init" in
 * Python/sysmodule.c to define the Python level event name
 */
#define PyTrace_CALL
#define PyTrace_EXCEPTION
#define PyTrace_LINE
#define PyTrace_RETURN
#define PyTrace_C_CALL
#define PyTrace_C_EXCEPTION
#define PyTrace_C_RETURN
#define PyTrace_OPCODE

_PyErr_StackItem;

_PyStackChunk;

struct _ts {};

#ifdef Py_DEBUG
   // A debug build is likely built with low optimization level which implies
   // higher stack memory usage than a release build: use a lower limit.
#define Py_C_RECURSION_LIMIT
#elif defined(__s390x__)
#define Py_C_RECURSION_LIMIT
#elif defined(_WIN32) && defined(_M_ARM64)
#define Py_C_RECURSION_LIMIT
#elif defined(_WIN32)
#define Py_C_RECURSION_LIMIT
#elif defined(__ANDROID__)
   // On an ARM64 emulator, API level 34 was OK with 10000, but API level 21
   // crashed in test_compiler_recursion_limit.
#define Py_C_RECURSION_LIMIT
#elif defined(_Py_ADDRESS_SANITIZER)
#define Py_C_RECURSION_LIMIT
#elif defined(__sparc__)
   // test_descr crashed on sparc64 with >7000 but let's keep a margin of error.
#define Py_C_RECURSION_LIMIT
#elif defined(__wasi__)
   // Based on wasmtime 16.
#define Py_C_RECURSION_LIMIT
#elif defined(__hppa__) || defined(__powerpc64__)
   // test_descr crashed with >8000 but let's keep a margin of error.
#define Py_C_RECURSION_LIMIT
#else
   // This value is duplicated in Lib/test/support/__init__.py
#define Py_C_RECURSION_LIMIT
#endif


/* other API */

/* Similar to PyThreadState_Get(), but don't issue a fatal error
 * if it is NULL. */
PyAPI_FUNC(PyThreadState *) PyThreadState_GetUnchecked(void);

// Alias kept for backward compatibility
#define _PyThreadState_UncheckedGet


// Disable tracing and profiling.
PyAPI_FUNC(void) PyThreadState_EnterTracing(PyThreadState *tstate);

// Reset tracing and profiling: enable them if a trace function or a profile
// function is set, otherwise disable them.
PyAPI_FUNC(void) PyThreadState_LeaveTracing(PyThreadState *tstate);

/* PyGILState */

/* Helper/diagnostic function - return 1 if the current thread
   currently holds the GIL, 0 otherwise.

   The function returns 1 if _PyGILState_check_enabled is non-zero. */
PyAPI_FUNC(int) PyGILState_Check(void);

/* The implementation of sys._current_frames()  Returns a dict mapping
   thread id to that thread's current frame.
*/
PyAPI_FUNC(PyObject*) _PyThread_CurrentFrames(void);

/* Routines for advanced debuggers, requested by David Beazley.
   Don't use unless you know what you are doing! */
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Main(void);
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);

/* Frame evaluation API */

_PyFrameEvalFunction;

PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc(
    PyInterpreterState *interp);
PyAPI_FUNC(void) _PyInterpreterState_SetEvalFrameFunc(
    PyInterpreterState *interp,
    _PyFrameEvalFunction eval_frame);