]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.10/Include/pystate.h
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Include / pystate.h
CommitLineData
c8042e10
DM
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 int trash_delete_nesting;\r
99 PyObject *trash_delete_later;\r
100\r
101 /* XXX signal handlers should also be here */\r
102\r
103} PyThreadState;\r
104\r
105\r
106PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);\r
107PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);\r
108PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);\r
109\r
110PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);\r
111PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);\r
112PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *);\r
113PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);\r
114PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);\r
115#ifdef WITH_THREAD\r
116PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);\r
117#endif\r
118\r
119PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);\r
120PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);\r
121PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);\r
122PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);\r
123\r
124\r
125/* Variable and macro for in-line access to current thread state */\r
126\r
127PyAPI_DATA(PyThreadState *) _PyThreadState_Current;\r
128\r
129#ifdef Py_DEBUG\r
130#define PyThreadState_GET() PyThreadState_Get()\r
131#else\r
132#define PyThreadState_GET() (_PyThreadState_Current)\r
133#endif\r
134\r
135typedef\r
136 enum {PyGILState_LOCKED, PyGILState_UNLOCKED}\r
137 PyGILState_STATE;\r
138\r
139/* Ensure that the current thread is ready to call the Python\r
140 C API, regardless of the current state of Python, or of its\r
141 thread lock. This may be called as many times as desired\r
142 by a thread so long as each call is matched with a call to\r
143 PyGILState_Release(). In general, other thread-state APIs may\r
144 be used between _Ensure() and _Release() calls, so long as the\r
145 thread-state is restored to its previous state before the Release().\r
146 For example, normal use of the Py_BEGIN_ALLOW_THREADS/\r
147 Py_END_ALLOW_THREADS macros are acceptable.\r
148\r
149 The return value is an opaque "handle" to the thread state when\r
150 PyGILState_Ensure() was called, and must be passed to\r
151 PyGILState_Release() to ensure Python is left in the same state. Even\r
152 though recursive calls are allowed, these handles can *not* be shared -\r
153 each unique call to PyGILState_Ensure must save the handle for its\r
154 call to PyGILState_Release.\r
155\r
156 When the function returns, the current thread will hold the GIL.\r
157\r
158 Failure is a fatal error.\r
159*/\r
160PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void);\r
161\r
162/* Release any resources previously acquired. After this call, Python's\r
163 state will be the same as it was prior to the corresponding\r
164 PyGILState_Ensure() call (but generally this state will be unknown to\r
165 the caller, hence the use of the GILState API.)\r
166\r
167 Every call to PyGILState_Ensure must be matched by a call to\r
168 PyGILState_Release on the same thread.\r
169*/\r
170PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);\r
171\r
172/* Helper/diagnostic function - get the current thread state for\r
173 this thread. May return NULL if no GILState API has been used\r
174 on the current thread. Note that the main thread always has such a\r
175 thread-state, even if no auto-thread-state call has been made\r
176 on the main thread.\r
177*/\r
178PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);\r
179\r
180/* The implementation of sys._current_frames() Returns a dict mapping\r
181 thread id to that thread's current frame.\r
182*/\r
183PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void);\r
184\r
185/* Routines for advanced debuggers, requested by David Beazley.\r
186 Don't use unless you know what you are doing! */\r
187PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);\r
188PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);\r
189PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);\r
190PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);\r
191\r
192typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);\r
193\r
194/* hook for PyEval_GetFrame(), requested for Psyco */\r
195PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;\r
196\r
197#ifdef __cplusplus\r
198}\r
199#endif\r
200#endif /* !Py_PYSTATE_H */\r