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 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 25 | int checkinterval; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 26 | |
| 27 | } PyInterpreterState; |
| 28 | |
| 29 | |
| 30 | /* State unique per thread */ |
| 31 | |
| 32 | struct _frame; /* Avoid including frameobject.h */ |
| 33 | |
Fred Drake | 55fb6e0 | 2001-06-27 19:18:03 +0000 | [diff] [blame] | 34 | /* Py_tracefunc return -1 when raising an exception, or 0 for success. */ |
| 35 | typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *); |
| 36 | |
| 37 | /* The following values are used for 'what' for tracefunc functions: */ |
| 38 | #define PyTrace_CALL 0 |
| 39 | #define PyTrace_EXCEPTION 1 |
| 40 | #define PyTrace_LINE 2 |
| 41 | #define PyTrace_RETURN 3 |
| 42 | |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 43 | typedef struct _ts { |
| 44 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 45 | struct _ts *next; |
| 46 | PyInterpreterState *interp; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 47 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 48 | struct _frame *frame; |
| 49 | int recursion_depth; |
| 50 | int ticker; |
| 51 | int tracing; |
Fred Drake | 9e3ad78 | 2001-07-03 23:39:52 +0000 | [diff] [blame] | 52 | int use_tracing; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 53 | |
Fred Drake | 55fb6e0 | 2001-06-27 19:18:03 +0000 | [diff] [blame] | 54 | Py_tracefunc c_profilefunc; |
| 55 | Py_tracefunc c_tracefunc; |
| 56 | PyObject *c_profileobj; |
| 57 | PyObject *c_traceobj; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 58 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 59 | PyObject *curexc_type; |
| 60 | PyObject *curexc_value; |
| 61 | PyObject *curexc_traceback; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 62 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 63 | PyObject *exc_type; |
| 64 | PyObject *exc_value; |
| 65 | PyObject *exc_traceback; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 66 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 67 | PyObject *dict; |
Guido van Rossum | ee0a63b | 1998-04-13 20:24:05 +0000 | [diff] [blame] | 68 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 69 | /* XXX signal handlers should also be here */ |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 70 | |
| 71 | } PyThreadState; |
| 72 | |
| 73 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 74 | DL_IMPORT(PyInterpreterState *) PyInterpreterState_New(void); |
| 75 | DL_IMPORT(void) PyInterpreterState_Clear(PyInterpreterState *); |
| 76 | DL_IMPORT(void) PyInterpreterState_Delete(PyInterpreterState *); |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 77 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 78 | DL_IMPORT(PyThreadState *) PyThreadState_New(PyInterpreterState *); |
| 79 | DL_IMPORT(void) PyThreadState_Clear(PyThreadState *); |
| 80 | DL_IMPORT(void) PyThreadState_Delete(PyThreadState *); |
Guido van Rossum | 2975786 | 2001-01-23 01:46:06 +0000 | [diff] [blame] | 81 | #ifdef WITH_THREAD |
| 82 | DL_IMPORT(void) PyThreadState_DeleteCurrent(void); |
| 83 | #endif |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 84 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 85 | DL_IMPORT(PyThreadState *) PyThreadState_Get(void); |
| 86 | DL_IMPORT(PyThreadState *) PyThreadState_Swap(PyThreadState *); |
| 87 | DL_IMPORT(PyObject *) PyThreadState_GetDict(void); |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 88 | |
Guido van Rossum | 275ea67 | 1998-12-21 18:28:10 +0000 | [diff] [blame] | 89 | |
| 90 | /* Variable and macro for in-line access to current thread state */ |
| 91 | |
Guido van Rossum | a8b47fe | 1998-12-21 20:21:19 +0000 | [diff] [blame] | 92 | extern DL_IMPORT(PyThreadState *) _PyThreadState_Current; |
Guido van Rossum | 275ea67 | 1998-12-21 18:28:10 +0000 | [diff] [blame] | 93 | |
| 94 | #ifdef Py_DEBUG |
| 95 | #define PyThreadState_GET() PyThreadState_Get() |
| 96 | #else |
| 97 | #define PyThreadState_GET() (_PyThreadState_Current) |
| 98 | #endif |
| 99 | |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 100 | #ifdef __cplusplus |
| 101 | } |
| 102 | #endif |
| 103 | #endif /* !Py_PYSTATE_H */ |