blob: 3e5b5b402d1a3962ab48516e966bf7fb5cd14a22 [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
Michael W. Hudson019a78e2002-11-08 12:53:11 +000070 int tick_counter;
71
Fred Drake5eb6d4e2000-07-08 23:37:28 +000072 /* XXX signal handlers should also be here */
Guido van Rossuma027efa1997-05-05 20:56:21 +000073
74} PyThreadState;
75
76
Mark Hammond91a681d2002-08-12 07:21:58 +000077PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
78PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
79PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
Guido van Rossuma027efa1997-05-05 20:56:21 +000080
Mark Hammond91a681d2002-08-12 07:21:58 +000081PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
82PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
83PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
Guido van Rossum29757862001-01-23 01:46:06 +000084#ifdef WITH_THREAD
Mark Hammond91a681d2002-08-12 07:21:58 +000085PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
Guido van Rossum29757862001-01-23 01:46:06 +000086#endif
Guido van Rossuma027efa1997-05-05 20:56:21 +000087
Mark Hammond91a681d2002-08-12 07:21:58 +000088PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
89PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
90PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
Guido van Rossuma027efa1997-05-05 20:56:21 +000091
Guido van Rossum275ea671998-12-21 18:28:10 +000092
93/* Variable and macro for in-line access to current thread state */
94
Mark Hammond91a681d2002-08-12 07:21:58 +000095PyAPI_DATA(PyThreadState *) _PyThreadState_Current;
Guido van Rossum275ea671998-12-21 18:28:10 +000096
97#ifdef Py_DEBUG
98#define PyThreadState_GET() PyThreadState_Get()
99#else
100#define PyThreadState_GET() (_PyThreadState_Current)
101#endif
102
Guido van Rossumf5df46d2001-07-19 12:19:27 +0000103/* Routines for advanced debuggers, requested by David Beazley.
104 Don't use unless you know what you are doing! */
Mark Hammond91a681d2002-08-12 07:21:58 +0000105PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
106PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
107PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
108PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
Guido van Rossumf5df46d2001-07-19 12:19:27 +0000109
Guido van Rossum6297a7a2003-02-19 15:53:17 +0000110typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
111
Michael W. Hudson019a78e2002-11-08 12:53:11 +0000112/* hook for PyEval_GetFrame(), requested for Psyco */
Guido van Rossum6297a7a2003-02-19 15:53:17 +0000113PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;
Michael W. Hudson019a78e2002-11-08 12:53:11 +0000114
Guido van Rossuma027efa1997-05-05 20:56:21 +0000115#ifdef __cplusplus
116}
117#endif
118#endif /* !Py_PYSTATE_H */