blob: 9b61ad7d39e0d6792c31d1110cd2db1dca3aab51 [file] [log] [blame]
Guido van Rossuma027efa1997-05-05 20:56:21 +00001
2/* Thread and interpreter state structures and their interfaces */
3
4
Fred Drake5eb6d4e2000-07-08 23:37:28 +00005#ifndef Py_PYSTATE_H
6#define Py_PYSTATE_H
7#ifdef __cplusplus
8extern "C" {
9#endif
10
Guido van Rossuma027efa1997-05-05 20:56:21 +000011/* State shared between threads */
12
Guido van Rossum29e46a91997-08-02 02:56:48 +000013struct _ts; /* Forward */
14struct _is; /* Forward */
15
Guido van Rossuma027efa1997-05-05 20:56:21 +000016typedef struct _is {
17
Fred Drake5eb6d4e2000-07-08 23:37:28 +000018 struct _is *next;
19 struct _ts *tstate_head;
Guido van Rossum29e46a91997-08-02 02:56:48 +000020
Fred Drake5eb6d4e2000-07-08 23:37:28 +000021 PyObject *modules;
22 PyObject *sysdict;
23 PyObject *builtins;
Guido van Rossuma027efa1997-05-05 20:56:21 +000024
Martin v. Löwisf0473d52001-07-18 16:17:16 +000025#ifdef HAVE_DLOPEN
26 int dlopenflags;
27#endif
Guido van Rossuma027efa1997-05-05 20:56:21 +000028
29} PyInterpreterState;
30
31
32/* State unique per thread */
33
34struct _frame; /* Avoid including frameobject.h */
35
Fred Drake55fb6e02001-06-27 19:18:03 +000036/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
37typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
38
39/* The following values are used for 'what' for tracefunc functions: */
40#define PyTrace_CALL 0
41#define PyTrace_EXCEPTION 1
42#define PyTrace_LINE 2
43#define PyTrace_RETURN 3
44
Guido van Rossuma027efa1997-05-05 20:56:21 +000045typedef struct _ts {
46
Fred Drake5eb6d4e2000-07-08 23:37:28 +000047 struct _ts *next;
48 PyInterpreterState *interp;
Guido van Rossuma027efa1997-05-05 20:56:21 +000049
Fred Drake5eb6d4e2000-07-08 23:37:28 +000050 struct _frame *frame;
51 int recursion_depth;
Fred Drake5eb6d4e2000-07-08 23:37:28 +000052 int tracing;
Fred Drake9e3ad782001-07-03 23:39:52 +000053 int use_tracing;
Guido van Rossuma027efa1997-05-05 20:56:21 +000054
Fred Drake55fb6e02001-06-27 19:18:03 +000055 Py_tracefunc c_profilefunc;
56 Py_tracefunc c_tracefunc;
57 PyObject *c_profileobj;
58 PyObject *c_traceobj;
Guido van Rossuma027efa1997-05-05 20:56:21 +000059
Fred Drake5eb6d4e2000-07-08 23:37:28 +000060 PyObject *curexc_type;
61 PyObject *curexc_value;
62 PyObject *curexc_traceback;
Guido van Rossuma027efa1997-05-05 20:56:21 +000063
Fred Drake5eb6d4e2000-07-08 23:37:28 +000064 PyObject *exc_type;
65 PyObject *exc_value;
66 PyObject *exc_traceback;
Guido van Rossuma027efa1997-05-05 20:56:21 +000067
Fred Drake5eb6d4e2000-07-08 23:37:28 +000068 PyObject *dict;
Guido van Rossumee0a63b1998-04-13 20:24:05 +000069
Fred Drake5eb6d4e2000-07-08 23:37:28 +000070 /* XXX signal handlers should also be here */
Guido van Rossuma027efa1997-05-05 20:56:21 +000071
72} PyThreadState;
73
74
Mark Hammond91a681d2002-08-12 07:21:58 +000075PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
76PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
77PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
Guido van Rossuma027efa1997-05-05 20:56:21 +000078
Mark Hammond91a681d2002-08-12 07:21:58 +000079PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
80PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
81PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
Guido van Rossum29757862001-01-23 01:46:06 +000082#ifdef WITH_THREAD
Mark Hammond91a681d2002-08-12 07:21:58 +000083PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
Guido van Rossum29757862001-01-23 01:46:06 +000084#endif
Guido van Rossuma027efa1997-05-05 20:56:21 +000085
Mark Hammond91a681d2002-08-12 07:21:58 +000086PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
87PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
88PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
Guido van Rossuma027efa1997-05-05 20:56:21 +000089
Guido van Rossum275ea671998-12-21 18:28:10 +000090
91/* Variable and macro for in-line access to current thread state */
92
Mark Hammond91a681d2002-08-12 07:21:58 +000093PyAPI_DATA(PyThreadState *) _PyThreadState_Current;
Guido van Rossum275ea671998-12-21 18:28:10 +000094
95#ifdef Py_DEBUG
96#define PyThreadState_GET() PyThreadState_Get()
97#else
98#define PyThreadState_GET() (_PyThreadState_Current)
99#endif
100
Guido van Rossumf5df46d2001-07-19 12:19:27 +0000101/* Routines for advanced debuggers, requested by David Beazley.
102 Don't use unless you know what you are doing! */
Mark Hammond91a681d2002-08-12 07:21:58 +0000103PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
104PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
105PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
106PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
Guido van Rossumf5df46d2001-07-19 12:19:27 +0000107
Guido van Rossuma027efa1997-05-05 20:56:21 +0000108#ifdef __cplusplus
109}
110#endif
111#endif /* !Py_PYSTATE_H */