diff options
Diffstat (limited to 'Include/pystate.h')
-rw-r--r-- | Include/pystate.h | 169 |
1 files changed, 117 insertions, 52 deletions
diff --git a/Include/pystate.h b/Include/pystate.h index 1cb2305..f2cfc30 100644 --- a/Include/pystate.h +++ b/Include/pystate.h @@ -1,3 +1,4 @@ + /* Thread and interpreter state structures and their interfaces */ @@ -7,80 +8,134 @@ extern "C" { #endif -#include "pythread.h" +/* State shared between threads */ -/* This limitation is for performance and simplicity. If needed it can be -removed (with effort). */ -#define MAX_CO_EXTRA_USERS 255 +struct _ts; /* Forward */ +struct _is; /* Forward */ -/* Forward declarations for PyFrameObject, PyThreadState - and PyInterpreterState */ -struct _frame; -struct _ts; -struct _is; +typedef struct _is { -/* struct _ts is defined in cpython/pystate.h */ -typedef struct _ts PyThreadState; -/* struct _is is defined in internal/pycore_pystate.h */ -typedef struct _is PyInterpreterState; + struct _is *next; + struct _ts *tstate_head; -PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void); -PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *); -PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *); + PyObject *modules; + PyObject *sysdict; + PyObject *builtins; + PyObject *modules_reloading; -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03080000 -/* New in 3.8 */ -PyAPI_FUNC(PyObject *) PyInterpreterState_GetDict(PyInterpreterState *); -#endif + PyObject *codec_search_path; + PyObject *codec_search_cache; + PyObject *codec_error_registry; -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000 -/* New in 3.7 */ -PyAPI_FUNC(int64_t) PyInterpreterState_GetID(PyInterpreterState *); +#ifdef HAVE_DLOPEN + int dlopenflags; +#endif +#ifdef WITH_TSC + int tscdump; #endif -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 + +} PyInterpreterState; + /* State unique per thread */ -/* New in 3.3 */ -PyAPI_FUNC(int) PyState_AddModule(PyObject*, struct PyModuleDef*); -PyAPI_FUNC(int) PyState_RemoveModule(struct PyModuleDef*); -#endif -PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*); +struct _frame; /* Avoid including frameobject.h */ -PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *); -PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *); -PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *); +/* Py_tracefunc return -1 when raising an exception, or 0 for success. */ +typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *); -/* Get the current thread state. +/* The following values are used for 'what' for tracefunc functions: */ +#define PyTrace_CALL 0 +#define PyTrace_EXCEPTION 1 +#define PyTrace_LINE 2 +#define PyTrace_RETURN 3 +#define PyTrace_C_CALL 4 +#define PyTrace_C_EXCEPTION 5 +#define PyTrace_C_RETURN 6 - When the current thread state is NULL, this issues a fatal error (so that - the caller needn't check for NULL). +typedef struct _ts { + /* See Python/ceval.c for comments explaining most fields */ - The caller must hold the GIL. + struct _ts *next; + PyInterpreterState *interp; - See also PyThreadState_GET() and _PyThreadState_GET(). */ -PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void); + struct _frame *frame; + int recursion_depth; + /* 'tracing' keeps track of the execution depth when tracing/profiling. + This is to prevent the actual trace/profile code from being recorded in + the trace/profile. */ + int tracing; + int use_tracing; -/* Get the current Python thread state. + Py_tracefunc c_profilefunc; + Py_tracefunc c_tracefunc; + PyObject *c_profileobj; + PyObject *c_traceobj; - Macro using PyThreadState_Get() or _PyThreadState_GET() depending if - pycore_pystate.h is included or not (this header redefines the macro). + PyObject *curexc_type; + PyObject *curexc_value; + PyObject *curexc_traceback; - If PyThreadState_Get() is used, issue a fatal error if the current thread - state is NULL. + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; + + PyObject *dict; /* Stores per-thread state */ + + /* tick_counter is incremented whenever the check_interval ticker + * reaches zero. The purpose is to give a useful measure of the number + * of interpreted bytecode instructions in a given thread. This + * extremely lightweight statistic collector may be of interest to + * profilers (like psyco.jit()), although nothing in the core uses it. + */ + int tick_counter; + + int gilstate_counter; + + PyObject *async_exc; /* Asynchronous exception to raise */ + long thread_id; /* Thread id where this tstate was created */ + + int trash_delete_nesting; + PyObject *trash_delete_later; + + /* XXX signal handlers should also be here */ + +} PyThreadState; - See also PyThreadState_Get() and _PyThreadState_GET(). */ -#define PyThreadState_GET() PyThreadState_Get() +PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void); +PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *); +PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *); + +PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *); +PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *); +PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *); +PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *); +PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *); +#ifdef WITH_THREAD +PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); +#endif + +PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void); PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *); PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void); -PyAPI_FUNC(int) PyThreadState_SetAsyncExc(unsigned long, PyObject *); +PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *); + + +/* Variable and macro for in-line access to current thread state */ + +PyAPI_DATA(PyThreadState *) _PyThreadState_Current; + +#ifdef Py_DEBUG +#define PyThreadState_GET() PyThreadState_Get() +#else +#define PyThreadState_GET() (_PyThreadState_Current) +#endif typedef enum {PyGILState_LOCKED, PyGILState_UNLOCKED} PyGILState_STATE; - /* Ensure that the current thread is ready to call the Python C API, regardless of the current state of Python, or of its thread lock. This may be called as many times as desired @@ -122,12 +177,22 @@ PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE); */ PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(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); -#ifndef Py_LIMITED_API -# define Py_CPYTHON_PYSTATE_H -# include "cpython/pystate.h" -# undef Py_CPYTHON_PYSTATE_H -#endif +/* Routines for advanced debuggers, requested by David Beazley. + Don't use unless you know what you are doing! */ +PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void); +PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *); +PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *); +PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *); + +typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_); + +/* hook for PyEval_GetFrame(), requested for Psyco */ +PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame; #ifdef __cplusplus } |