blob: 15a264c6789886e876c4be965ac655a16a85183e [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
Fred Drake5eb6d4e2000-07-08 23:37:28 +000025 int checkinterval;
Guido van Rossuma027efa1997-05-05 20:56:21 +000026
27} PyInterpreterState;
28
29
30/* State unique per thread */
31
32struct _frame; /* Avoid including frameobject.h */
33
Fred Drake55fb6e02001-06-27 19:18:03 +000034/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
35typedef 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 Rossuma027efa1997-05-05 20:56:21 +000043typedef struct _ts {
44
Fred Drake5eb6d4e2000-07-08 23:37:28 +000045 struct _ts *next;
46 PyInterpreterState *interp;
Guido van Rossuma027efa1997-05-05 20:56:21 +000047
Fred Drake5eb6d4e2000-07-08 23:37:28 +000048 struct _frame *frame;
49 int recursion_depth;
50 int ticker;
51 int tracing;
Fred Drake9e3ad782001-07-03 23:39:52 +000052 int use_tracing;
Guido van Rossuma027efa1997-05-05 20:56:21 +000053
Fred Drake55fb6e02001-06-27 19:18:03 +000054 Py_tracefunc c_profilefunc;
55 Py_tracefunc c_tracefunc;
56 PyObject *c_profileobj;
57 PyObject *c_traceobj;
Guido van Rossuma027efa1997-05-05 20:56:21 +000058
Fred Drake5eb6d4e2000-07-08 23:37:28 +000059 PyObject *curexc_type;
60 PyObject *curexc_value;
61 PyObject *curexc_traceback;
Guido van Rossuma027efa1997-05-05 20:56:21 +000062
Fred Drake5eb6d4e2000-07-08 23:37:28 +000063 PyObject *exc_type;
64 PyObject *exc_value;
65 PyObject *exc_traceback;
Guido van Rossuma027efa1997-05-05 20:56:21 +000066
Fred Drake5eb6d4e2000-07-08 23:37:28 +000067 PyObject *dict;
Guido van Rossumee0a63b1998-04-13 20:24:05 +000068
Fred Drake5eb6d4e2000-07-08 23:37:28 +000069 /* XXX signal handlers should also be here */
Guido van Rossuma027efa1997-05-05 20:56:21 +000070
71} PyThreadState;
72
73
Fred Drake5eb6d4e2000-07-08 23:37:28 +000074DL_IMPORT(PyInterpreterState *) PyInterpreterState_New(void);
75DL_IMPORT(void) PyInterpreterState_Clear(PyInterpreterState *);
76DL_IMPORT(void) PyInterpreterState_Delete(PyInterpreterState *);
Guido van Rossuma027efa1997-05-05 20:56:21 +000077
Fred Drake5eb6d4e2000-07-08 23:37:28 +000078DL_IMPORT(PyThreadState *) PyThreadState_New(PyInterpreterState *);
79DL_IMPORT(void) PyThreadState_Clear(PyThreadState *);
80DL_IMPORT(void) PyThreadState_Delete(PyThreadState *);
Guido van Rossum29757862001-01-23 01:46:06 +000081#ifdef WITH_THREAD
82DL_IMPORT(void) PyThreadState_DeleteCurrent(void);
83#endif
Guido van Rossuma027efa1997-05-05 20:56:21 +000084
Fred Drake5eb6d4e2000-07-08 23:37:28 +000085DL_IMPORT(PyThreadState *) PyThreadState_Get(void);
86DL_IMPORT(PyThreadState *) PyThreadState_Swap(PyThreadState *);
87DL_IMPORT(PyObject *) PyThreadState_GetDict(void);
Guido van Rossuma027efa1997-05-05 20:56:21 +000088
Guido van Rossum275ea671998-12-21 18:28:10 +000089
90/* Variable and macro for in-line access to current thread state */
91
Guido van Rossuma8b47fe1998-12-21 20:21:19 +000092extern DL_IMPORT(PyThreadState *) _PyThreadState_Current;
Guido van Rossum275ea671998-12-21 18:28:10 +000093
94#ifdef Py_DEBUG
95#define PyThreadState_GET() PyThreadState_Get()
96#else
97#define PyThreadState_GET() (_PyThreadState_Current)
98#endif
99
Guido van Rossuma027efa1997-05-05 20:56:21 +0000100#ifdef __cplusplus
101}
102#endif
103#endif /* !Py_PYSTATE_H */