Mercurial > lcfOS
comparison cos/python/Include/ceval.h @ 27:7f74363f4c82
Added some files for the python port
author | windel |
---|---|
date | Tue, 27 Dec 2011 18:59:02 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
26:dcce92b1efbc | 27:7f74363f4c82 |
---|---|
1 #ifndef Py_CEVAL_H | |
2 #define Py_CEVAL_H | |
3 | |
4 /* Interface to random parts in ceval.c */ | |
5 | |
6 PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords( | |
7 PyObject *, PyObject *, PyObject *); | |
8 | |
9 /* Inline this */ | |
10 #define PyEval_CallObject(func,arg) \ | |
11 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) | |
12 | |
13 PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj, | |
14 const char *format, ...); | |
15 PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj, | |
16 const char *methodname, | |
17 const char *format, ...); | |
18 | |
19 PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *); | |
20 PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *); | |
21 | |
22 struct _frame; /* Avoid including frameobject.h */ | |
23 | |
24 PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void); | |
25 PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void); | |
26 PyAPI_FUNC(PyObject *) PyEval_GetLocals(void); | |
27 PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void); | |
28 | |
29 /* Look at the current frame's (if any) code's co_flags, and turn on | |
30 the corresponding compiler flags in cf->cf_flags. Return 1 if any | |
31 flag was set, else return 0. */ | |
32 PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf); | |
33 | |
34 PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg); | |
35 PyAPI_FUNC(int) Py_MakePendingCalls(void); | |
36 | |
37 /* Protection against deeply nested recursive calls | |
38 | |
39 In Python 3.0, this protection has two levels: | |
40 * normal anti-recursion protection is triggered when the recursion level | |
41 exceeds the current recursion limit. It raises a RuntimeError, and sets | |
42 the "overflowed" flag in the thread state structure. This flag | |
43 temporarily *disables* the normal protection; this allows cleanup code | |
44 to potentially outgrow the recursion limit while processing the | |
45 RuntimeError. | |
46 * "last chance" anti-recursion protection is triggered when the recursion | |
47 level exceeds "current recursion limit + 50". By construction, this | |
48 protection can only be triggered when the "overflowed" flag is set. It | |
49 means the cleanup code has itself gone into an infinite loop, or the | |
50 RuntimeError has been mistakingly ignored. When this protection is | |
51 triggered, the interpreter aborts with a Fatal Error. | |
52 | |
53 In addition, the "overflowed" flag is automatically reset when the | |
54 recursion level drops below "current recursion limit - 50". This heuristic | |
55 is meant to ensure that the normal anti-recursion protection doesn't get | |
56 disabled too long. | |
57 | |
58 Please note: this scheme has its own limitations. See: | |
59 http://mail.python.org/pipermail/python-dev/2008-August/082106.html | |
60 for some observations. | |
61 */ | |
62 PyAPI_FUNC(void) Py_SetRecursionLimit(int); | |
63 PyAPI_FUNC(int) Py_GetRecursionLimit(void); | |
64 | |
65 #define Py_EnterRecursiveCall(where) \ | |
66 (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \ | |
67 _Py_CheckRecursiveCall(where)) | |
68 #define Py_LeaveRecursiveCall() \ | |
69 do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \ | |
70 PyThreadState_GET()->overflowed = 0; \ | |
71 } while(0) | |
72 PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where); | |
73 PyAPI_DATA(int) _Py_CheckRecursionLimit; | |
74 | |
75 # define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit) | |
76 | |
77 #define _Py_MakeEndRecCheck(x) \ | |
78 (--(x) < ((_Py_CheckRecursionLimit > 100) \ | |
79 ? (_Py_CheckRecursionLimit - 50) \ | |
80 : (3 * (_Py_CheckRecursionLimit >> 2)))) | |
81 | |
82 #define Py_ALLOW_RECURSION \ | |
83 do { unsigned char _old = PyThreadState_GET()->recursion_critical;\ | |
84 PyThreadState_GET()->recursion_critical = 1; | |
85 | |
86 #define Py_END_ALLOW_RECURSION \ | |
87 PyThreadState_GET()->recursion_critical = _old; \ | |
88 } while(0); | |
89 | |
90 PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *); | |
91 PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *); | |
92 | |
93 PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *); | |
94 PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *); | |
95 PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc); | |
96 | |
97 /* Interface for threads. | |
98 | |
99 A module that plans to do a blocking system call (or something else | |
100 that lasts a long time and doesn't touch Python data) can allow other | |
101 threads to run as follows: | |
102 | |
103 ...preparations here... | |
104 Py_BEGIN_ALLOW_THREADS | |
105 ...blocking system call here... | |
106 Py_END_ALLOW_THREADS | |
107 ...interpret result here... | |
108 | |
109 The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a | |
110 {}-surrounded block. | |
111 To leave the block in the middle (e.g., with return), you must insert | |
112 a line containing Py_BLOCK_THREADS before the return, e.g. | |
113 | |
114 if (...premature_exit...) { | |
115 Py_BLOCK_THREADS | |
116 PyErr_SetFromErrno(PyExc_IOError); | |
117 return NULL; | |
118 } | |
119 | |
120 An alternative is: | |
121 | |
122 Py_BLOCK_THREADS | |
123 if (...premature_exit...) { | |
124 PyErr_SetFromErrno(PyExc_IOError); | |
125 return NULL; | |
126 } | |
127 Py_UNBLOCK_THREADS | |
128 | |
129 For convenience, that the value of 'errno' is restored across | |
130 Py_END_ALLOW_THREADS and Py_BLOCK_THREADS. | |
131 | |
132 WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND | |
133 Py_END_ALLOW_THREADS!!! | |
134 | |
135 The function PyEval_InitThreads() should be called only from | |
136 init_thread() in "_threadmodule.c". | |
137 | |
138 Note that not yet all candidates have been converted to use this | |
139 mechanism! | |
140 */ | |
141 | |
142 PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void); | |
143 PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *); | |
144 | |
145 #ifdef WITH_THREAD | |
146 | |
147 PyAPI_FUNC(int) PyEval_ThreadsInitialized(void); | |
148 PyAPI_FUNC(void) PyEval_InitThreads(void); | |
149 PyAPI_FUNC(void) _PyEval_FiniThreads(void); | |
150 PyAPI_FUNC(void) PyEval_AcquireLock(void); | |
151 PyAPI_FUNC(void) PyEval_ReleaseLock(void); | |
152 PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); | |
153 PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); | |
154 PyAPI_FUNC(void) PyEval_ReInitThreads(void); | |
155 | |
156 PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); | |
157 PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); | |
158 | |
159 #define Py_BEGIN_ALLOW_THREADS { \ | |
160 PyThreadState *_save; \ | |
161 _save = PyEval_SaveThread(); | |
162 #define Py_BLOCK_THREADS PyEval_RestoreThread(_save); | |
163 #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread(); | |
164 #define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \ | |
165 } | |
166 | |
167 #else /* !WITH_THREAD */ | |
168 | |
169 #define Py_BEGIN_ALLOW_THREADS { | |
170 #define Py_BLOCK_THREADS | |
171 #define Py_UNBLOCK_THREADS | |
172 #define Py_END_ALLOW_THREADS } | |
173 | |
174 #endif /* !WITH_THREAD */ | |
175 | |
176 PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *); | |
177 PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void); | |
178 | |
179 | |
180 #endif /* !Py_CEVAL_H */ |