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; |
Martin v. Löwis | f0473d5 | 2001-07-18 16:17:16 +0000 | [diff] [blame] | 26 | #ifdef HAVE_DLOPEN |
| 27 | int dlopenflags; |
| 28 | #endif |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 29 | |
| 30 | } PyInterpreterState; |
| 31 | |
| 32 | |
| 33 | /* State unique per thread */ |
| 34 | |
| 35 | struct _frame; /* Avoid including frameobject.h */ |
| 36 | |
Fred Drake | 55fb6e0 | 2001-06-27 19:18:03 +0000 | [diff] [blame] | 37 | /* Py_tracefunc return -1 when raising an exception, or 0 for success. */ |
| 38 | typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *); |
| 39 | |
| 40 | /* The following values are used for 'what' for tracefunc functions: */ |
| 41 | #define PyTrace_CALL 0 |
| 42 | #define PyTrace_EXCEPTION 1 |
| 43 | #define PyTrace_LINE 2 |
| 44 | #define PyTrace_RETURN 3 |
| 45 | |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 46 | typedef struct _ts { |
| 47 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 48 | struct _ts *next; |
| 49 | PyInterpreterState *interp; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 50 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 51 | struct _frame *frame; |
| 52 | int recursion_depth; |
| 53 | int ticker; |
| 54 | int tracing; |
Fred Drake | 9e3ad78 | 2001-07-03 23:39:52 +0000 | [diff] [blame] | 55 | int use_tracing; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 56 | |
Fred Drake | 55fb6e0 | 2001-06-27 19:18:03 +0000 | [diff] [blame] | 57 | Py_tracefunc c_profilefunc; |
| 58 | Py_tracefunc c_tracefunc; |
| 59 | PyObject *c_profileobj; |
| 60 | PyObject *c_traceobj; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 61 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 62 | PyObject *curexc_type; |
| 63 | PyObject *curexc_value; |
| 64 | PyObject *curexc_traceback; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 65 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 66 | PyObject *exc_type; |
| 67 | PyObject *exc_value; |
| 68 | PyObject *exc_traceback; |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 69 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 70 | PyObject *dict; |
Guido van Rossum | ee0a63b | 1998-04-13 20:24:05 +0000 | [diff] [blame] | 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 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 77 | DL_IMPORT(PyInterpreterState *) PyInterpreterState_New(void); |
| 78 | DL_IMPORT(void) PyInterpreterState_Clear(PyInterpreterState *); |
| 79 | DL_IMPORT(void) PyInterpreterState_Delete(PyInterpreterState *); |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 80 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 81 | DL_IMPORT(PyThreadState *) PyThreadState_New(PyInterpreterState *); |
| 82 | DL_IMPORT(void) PyThreadState_Clear(PyThreadState *); |
| 83 | DL_IMPORT(void) PyThreadState_Delete(PyThreadState *); |
Guido van Rossum | 2975786 | 2001-01-23 01:46:06 +0000 | [diff] [blame] | 84 | #ifdef WITH_THREAD |
| 85 | DL_IMPORT(void) PyThreadState_DeleteCurrent(void); |
| 86 | #endif |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 87 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 88 | DL_IMPORT(PyThreadState *) PyThreadState_Get(void); |
| 89 | DL_IMPORT(PyThreadState *) PyThreadState_Swap(PyThreadState *); |
| 90 | DL_IMPORT(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 | |
Guido van Rossum | a8b47fe | 1998-12-21 20:21:19 +0000 | [diff] [blame] | 95 | extern DL_IMPORT(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! */ |
| 105 | DL_IMPORT(PyInterpreterState *) PyInterpreterState_Head(void); |
| 106 | DL_IMPORT(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *); |
| 107 | DL_IMPORT(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *); |
| 108 | DL_IMPORT(PyThreadState *) PyThreadState_Next(PyThreadState *); |
| 109 | |
Guido van Rossum | a027efa | 1997-05-05 20:56:21 +0000 | [diff] [blame] | 110 | #ifdef __cplusplus |
| 111 | } |
| 112 | #endif |
| 113 | #endif /* !Py_PYSTATE_H */ |