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