annotate cos/python/Include/ceval.h @ 57:143ab220aa27

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