Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 1 | |
| 2 | /* Thread and interpreter state structures and their interfaces */ |
| 3 | |
| 4 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 5 | #ifndef Py_PYSTATE_H |
| 6 | #define Py_PYSTATE_H |
| 7 | #ifdef __cplusplus |
| 8 | extern "C" { |
| 9 | #endif |
| 10 | |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 11 | /* State shared between threads */ |
| 12 | |
Guido van Rossum | 29e46a9 | 1997-08-02 02:56:48 +0000 | [diff] [blame] | 13 | struct _ts; /* Forward */ |
| 14 | struct _is; /* Forward */ |
| 15 | |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 16 | typedef struct _is { |
| 17 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 18 | struct _is *next; |
| 19 | struct _ts *tstate_head; |
Guido van Rossum | 29e46a9 | 1997-08-02 02:56:48 +0000 | [diff] [blame] | 20 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 21 | PyObject *modules; |
| 22 | PyObject *sysdict; |
| 23 | PyObject *builtins; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 24 | |
Martin v. Löwis | f0473d5 | 2001-07-18 16:17:16 +0000 | [diff] [blame] | 25 | #ifdef HAVE_DLOPEN |
| 26 | int dlopenflags; |
| 27 | #endif |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 28 | |
| 29 | } PyInterpreterState; |
| 30 | |
| 31 | |
| 32 | /* State unique per thread */ |
| 33 | |
| 34 | struct _frame; /* Avoid including frameobject.h */ |
| 35 | |
Fred Drake | 55fb6e0 | 2001-06-27 19:18:03 +0000 | [diff] [blame] | 36 | /* Py_tracefunc return -1 when raising an exception, or 0 for success. */ |
| 37 | typedef 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 Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 45 | typedef struct _ts { |
| 46 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 47 | struct _ts *next; |
| 48 | PyInterpreterState *interp; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 49 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 50 | struct _frame *frame; |
| 51 | int recursion_depth; |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 52 | int tracing; |
Fred Drake | 9e3ad78 | 2001-07-03 23:39:52 +0000 | [diff] [blame] | 53 | int use_tracing; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 54 | |
Fred Drake | 55fb6e0 | 2001-06-27 19:18:03 +0000 | [diff] [blame] | 55 | Py_tracefunc c_profilefunc; |
| 56 | Py_tracefunc c_tracefunc; |
| 57 | PyObject *c_profileobj; |
| 58 | PyObject *c_traceobj; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 59 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 60 | PyObject *curexc_type; |
| 61 | PyObject *curexc_value; |
| 62 | PyObject *curexc_traceback; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 63 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 64 | PyObject *exc_type; |
| 65 | PyObject *exc_value; |
| 66 | PyObject *exc_traceback; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 67 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 68 | PyObject *dict; |
Guido van Rossum | ee0a63b | 1998-04-13 20:24:05 +0000 | [diff] [blame] | 69 | |
Michael W. Hudson | 019a78e | 2002-11-08 12:53:11 +0000 | [diff] [blame] | 70 | int tick_counter; |
| 71 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 72 | /* XXX signal handlers should also be here */ |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 73 | |
| 74 | } PyThreadState; |
| 75 | |
| 76 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 77 | PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void); |
| 78 | PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *); |
| 79 | PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *); |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 80 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 81 | PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *); |
| 82 | PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *); |
| 83 | PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *); |
Guido van Rossum | 2975786 | 2001-01-23 01:46:06 +0000 | [diff] [blame] | 84 | #ifdef WITH_THREAD |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 85 | PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); |
Guido van Rossum | 2975786 | 2001-01-23 01:46:06 +0000 | [diff] [blame] | 86 | #endif |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 87 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 88 | PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void); |
| 89 | PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *); |
| 90 | PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void); |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 91 | |
Guido van Rossum | 275ea67 | 1998-12-21 18:28:10 +0000 | [diff] [blame] | 92 | |
| 93 | /* Variable and macro for in-line access to current thread state */ |
| 94 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 95 | PyAPI_DATA(PyThreadState *) _PyThreadState_Current; |
Guido van Rossum | 275ea67 | 1998-12-21 18:28:10 +0000 | [diff] [blame] | 96 | |
| 97 | #ifdef Py_DEBUG |
| 98 | #define PyThreadState_GET() PyThreadState_Get() |
| 99 | #else |
| 100 | #define PyThreadState_GET() (_PyThreadState_Current) |
| 101 | #endif |
| 102 | |
Guido van Rossum | f5df46d | 2001-07-19 12:19:27 +0000 | [diff] [blame] | 103 | /* Routines for advanced debuggers, requested by David Beazley. |
| 104 | Don't use unless you know what you are doing! */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 105 | PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void); |
| 106 | PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *); |
| 107 | PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *); |
| 108 | PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *); |
Guido van Rossum | f5df46d | 2001-07-19 12:19:27 +0000 | [diff] [blame] | 109 | |
Guido van Rossum | 6297a7a | 2003-02-19 15:53:17 +0000 | [diff] [blame] | 110 | typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_); |
| 111 | |
Michael W. Hudson | 019a78e | 2002-11-08 12:53:11 +0000 | [diff] [blame] | 112 | /* hook for PyEval_GetFrame(), requested for Psyco */ |
Guido van Rossum | 6297a7a | 2003-02-19 15:53:17 +0000 | [diff] [blame] | 113 | PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame; |
Michael W. Hudson | 019a78e | 2002-11-08 12:53:11 +0000 | [diff] [blame] | 114 | |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 115 | #ifdef __cplusplus |
| 116 | } |
| 117 | #endif |
| 118 | #endif /* !Py_PYSTATE_H */ |