fix installing of extension modules
[python/dscho.git] / Include / pystate.h
blobe02df88f8c652490a490eb3a5c869b71e58a889d
2 /* Thread and interpreter state structures and their interfaces */
5 #ifndef Py_PYSTATE_H
6 #define Py_PYSTATE_H
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
11 /* State shared between threads */
13 struct _ts; /* Forward */
14 struct _is; /* Forward */
16 typedef struct _is {
18 struct _is *next;
19 struct _ts *tstate_head;
21 PyObject *modules;
22 PyObject *modules_by_index;
23 PyObject *sysdict;
24 PyObject *builtins;
25 PyObject *modules_reloading;
27 PyObject *codec_search_path;
28 PyObject *codec_search_cache;
29 PyObject *codec_error_registry;
30 int codecs_initialized;
32 #ifdef HAVE_DLOPEN
33 int dlopenflags;
34 #endif
35 #ifdef WITH_TSC
36 int tscdump;
37 #endif
39 } PyInterpreterState;
42 /* State unique per thread */
44 struct _frame; /* Avoid including frameobject.h */
46 /* Py_tracefunc return -1 when raising an exception, or 0 for success. */
47 typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
49 /* The following values are used for 'what' for tracefunc functions: */
50 #define PyTrace_CALL 0
51 #define PyTrace_EXCEPTION 1
52 #define PyTrace_LINE 2
53 #define PyTrace_RETURN 3
54 #define PyTrace_C_CALL 4
55 #define PyTrace_C_EXCEPTION 5
56 #define PyTrace_C_RETURN 6
58 typedef struct _ts {
59 /* See Python/ceval.c for comments explaining most fields */
61 struct _ts *next;
62 PyInterpreterState *interp;
64 struct _frame *frame;
65 int recursion_depth;
66 char overflowed; /* The stack has overflowed. Allow 50 more calls
67 to handle the runtime error. */
68 char recursion_critical; /* The current calls must not cause
69 a stack overflow. */
70 /* 'tracing' keeps track of the execution depth when tracing/profiling.
71 This is to prevent the actual trace/profile code from being recorded in
72 the trace/profile. */
73 int tracing;
74 int use_tracing;
76 Py_tracefunc c_profilefunc;
77 Py_tracefunc c_tracefunc;
78 PyObject *c_profileobj;
79 PyObject *c_traceobj;
81 PyObject *curexc_type;
82 PyObject *curexc_value;
83 PyObject *curexc_traceback;
85 PyObject *exc_type;
86 PyObject *exc_value;
87 PyObject *exc_traceback;
89 PyObject *dict; /* Stores per-thread state */
91 /* tick_counter is incremented whenever the check_interval ticker
92 * reaches zero. The purpose is to give a useful measure of the number
93 * of interpreted bytecode instructions in a given thread. This
94 * extremely lightweight statistic collector may be of interest to
95 * profilers (like psyco.jit()), although nothing in the core uses it.
97 int tick_counter;
99 int gilstate_counter;
101 PyObject *async_exc; /* Asynchronous exception to raise */
102 long thread_id; /* Thread id where this tstate was created */
104 /* XXX signal handlers should also be here */
106 } PyThreadState;
109 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
110 PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
111 PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
112 PyAPI_FUNC(int) _PyState_AddModule(PyObject*, struct PyModuleDef*);
113 PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
115 PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
116 PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
117 PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
118 #ifdef WITH_THREAD
119 PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
120 #endif
122 PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
123 PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
124 PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
125 PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);
128 /* Variable and macro for in-line access to current thread state */
130 PyAPI_DATA(PyThreadState *) _PyThreadState_Current;
132 #ifdef Py_DEBUG
133 #define PyThreadState_GET() PyThreadState_Get()
134 #else
135 #define PyThreadState_GET() (_PyThreadState_Current)
136 #endif
138 typedef
139 enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
140 PyGILState_STATE;
142 /* Ensure that the current thread is ready to call the Python
143 C API, regardless of the current state of Python, or of its
144 thread lock. This may be called as many times as desired
145 by a thread so long as each call is matched with a call to
146 PyGILState_Release(). In general, other thread-state APIs may
147 be used between _Ensure() and _Release() calls, so long as the
148 thread-state is restored to its previous state before the Release().
149 For example, normal use of the Py_BEGIN_ALLOW_THREADS/
150 Py_END_ALLOW_THREADS macros are acceptable.
152 The return value is an opaque "handle" to the thread state when
153 PyGILState_Ensure() was called, and must be passed to
154 PyGILState_Release() to ensure Python is left in the same state. Even
155 though recursive calls are allowed, these handles can *not* be shared -
156 each unique call to PyGILState_Ensure must save the handle for its
157 call to PyGILState_Release.
159 When the function returns, the current thread will hold the GIL.
161 Failure is a fatal error.
163 PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void);
165 /* Release any resources previously acquired. After this call, Python's
166 state will be the same as it was prior to the corresponding
167 PyGILState_Ensure() call (but generally this state will be unknown to
168 the caller, hence the use of the GILState API.)
170 Every call to PyGILState_Ensure must be matched by a call to
171 PyGILState_Release on the same thread.
173 PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
175 /* Helper/diagnostic function - get the current thread state for
176 this thread. May return NULL if no GILState API has been used
177 on the current thread. Note the main thread always has such a
178 thread-state, even if no auto-thread-state call has been made
179 on the main thread.
181 PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
183 /* The implementation of sys._current_frames() Returns a dict mapping
184 thread id to that thread's current frame.
186 PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void);
188 /* Routines for advanced debuggers, requested by David Beazley.
189 Don't use unless you know what you are doing! */
190 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
191 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
192 PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
193 PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
195 typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
197 /* hook for PyEval_GetFrame(), requested for Psyco */
198 PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;
200 #ifdef __cplusplus
202 #endif
203 #endif /* !Py_PYSTATE_H */