PageRenderTime 34ms CodeModel.GetById 13ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Include/eval.h

http://unladen-swallow.googlecode.com/
C++ Header | 266 lines | 139 code | 53 blank | 74 comment | 1 complexity | 241060721319ec1ccd33efc60fb94915 MD5 | raw file
  1
  2/* Interface to execute compiled code. This also includes private functions
  3   and structs shared between the bytecode VM and the LLVM compiler. */
  4
  5#ifndef Py_EVAL_H
  6#define Py_EVAL_H
  7#ifdef __cplusplus
  8extern "C" {
  9#endif
 10
 11PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
 12	PyObject *, PyObject *, PyObject *);
 13
 14/* DLL-level Backwards compatibility: */
 15#undef PyEval_CallObject
 16PyAPI_FUNC(PyObject *) PyEval_CallObject(PyObject *, PyObject *);
 17
 18/* Inline this */
 19#define PyEval_CallObject(func,arg) \
 20        PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
 21
 22PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj,
 23                                           const char *format, ...);
 24PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,
 25                                         const char *methodname,
 26                                         const char *format, ...);
 27
 28PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
 29PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
 30
 31struct _frame; /* Avoid including frameobject.h */
 32
 33PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
 34PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
 35PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
 36PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void);
 37PyAPI_FUNC(int) PyEval_GetRestricted(void);
 38
 39/* Look at the current frame's (if any) code's co_flags, and turn on
 40   the corresponding compiler flags in cf->cf_flags.  Return 1 if any
 41   flag was set, else return 0. */
 42PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
 43
 44PyAPI_FUNC(int) Py_FlushLine(void);
 45
 46PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
 47PyAPI_FUNC(int) Py_MakePendingCalls(void);
 48
 49/* Protection against deeply nested recursive calls */
 50PyAPI_FUNC(void) Py_SetRecursionLimit(int);
 51PyAPI_FUNC(int) Py_GetRecursionLimit(void);
 52
 53#define Py_EnterRecursiveCall(where)                                    \
 54	    (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) &&  \
 55	     _Py_CheckRecursiveCall(where))
 56#define Py_LeaveRecursiveCall()				\
 57	    (--PyThreadState_GET()->recursion_depth)
 58PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);
 59PyAPI_DATA(int) _Py_CheckRecursionLimit;
 60#ifdef USE_STACKCHECK
 61#  define _Py_MakeRecCheck(x)  (++(x) > --_Py_CheckRecursionLimit)
 62#else
 63#  define _Py_MakeRecCheck(x)  (++(x) > _Py_CheckRecursionLimit)
 64#endif
 65
 66PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
 67PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
 68
 69PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
 70PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
 71PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
 72
 73/* this used to be handled on a per-thread basis - now just two globals */
 74PyAPI_DATA(volatile int) _Py_Ticker;
 75PyAPI_DATA(int) _Py_CheckInterval;
 76
 77#ifdef WITH_LLVM
 78/* Useful for debugging LLVM: if true, raise an exception if we bail from native
 79   code back to the interpreter. */
 80PyAPI_DATA(int) _Py_BailError;
 81#endif
 82
 83/* Interface for threads.
 84
 85   A module that plans to do a blocking system call (or something else
 86   that lasts a long time and doesn't touch Python data) can allow other
 87   threads to run as follows:
 88
 89	...preparations here...
 90	Py_BEGIN_ALLOW_THREADS
 91	...blocking system call here...
 92	Py_END_ALLOW_THREADS
 93	...interpret result here...
 94
 95   The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
 96   {}-surrounded block.
 97   To leave the block in the middle (e.g., with return), you must insert
 98   a line containing Py_BLOCK_THREADS before the return, e.g.
 99
100	if (...premature_exit...) {
101		Py_BLOCK_THREADS
102		PyErr_SetFromErrno(PyExc_IOError);
103		return NULL;
104	}
105
106   An alternative is:
107
108	Py_BLOCK_THREADS
109	if (...premature_exit...) {
110		PyErr_SetFromErrno(PyExc_IOError);
111		return NULL;
112	}
113	Py_UNBLOCK_THREADS
114
115   For convenience, that the value of 'errno' is restored across
116   Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
117
118   WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
119   Py_END_ALLOW_THREADS!!!
120
121   The function PyEval_InitThreads() should be called only from
122   initthread() in "threadmodule.c".
123
124   Note that not yet all candidates have been converted to use this
125   mechanism!
126*/
127
128PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
129PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
130
131#ifdef WITH_THREAD
132
133extern long _PyEval_main_thread;
134
135PyAPI_FUNC(int)  PyEval_ThreadsInitialized(void);
136PyAPI_FUNC(void) PyEval_InitThreads(void);
137PyAPI_FUNC(void) PyEval_AcquireLock(void);
138PyAPI_FUNC(void) PyEval_ReleaseLock(void);
139PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
140PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
141PyAPI_FUNC(void) PyEval_ReInitThreads(void);
142
143#define Py_BEGIN_ALLOW_THREADS { \
144			PyThreadState *_save; \
145			_save = PyEval_SaveThread();
146#define Py_BLOCK_THREADS	PyEval_RestoreThread(_save);
147#define Py_UNBLOCK_THREADS	_save = PyEval_SaveThread();
148#define Py_END_ALLOW_THREADS	PyEval_RestoreThread(_save); \
149		 }
150
151#else /* !WITH_THREAD */
152
153#define Py_BEGIN_ALLOW_THREADS {
154#define Py_BLOCK_THREADS
155#define Py_UNBLOCK_THREADS
156#define Py_END_ALLOW_THREADS }
157
158#endif /* !WITH_THREAD */
159
160PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyCodeObject *, PyObject *, PyObject *);
161
162PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyCodeObject *co,
163					PyObject *globals,
164					PyObject *locals,
165					PyObject **args, int argc,
166					PyObject **kwds, int kwdc,
167					PyObject **defs, int defc,
168					PyObject *closure);
169
170PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args);
171
172/* Instrumentation functions. */
173
174#ifdef Py_WITH_INSTRUMENTATION
175/* Record that a given code object failed a fatal guard, thus invalidating its
176   machine code function. We use this to analyze how many functions have their
177   machine code invalidated, but continue to be called, which can negatively
178   impact performance. */
179PyAPI_FUNC(void) _PyEval_RecordFatalBail(PyCodeObject *code);
180
181/* Record how many watchers a given dict has. This is used to track how many
182   watchers the globals/builtins dicts are accumulating. */
183PyAPI_FUNC(void) _PyEval_RecordWatcherCount(size_t watcher_count);
184#else
185#define _PyEval_RecordFatalBail(code)
186#define _PyEval_RecordWatcherCount(watcher_count)
187#endif  /* Py_WITH_INSTRUMENTATION */
188
189
190/* Helper functions and objects shared by the bytecode and LLVM
191   implementations. */
192
193/* Status code to indicate why the Python stack is being unwound. */
194enum _PyUnwindReason {
195    UNWIND_NOUNWIND  = 0x0001,	/* No error */
196    UNWIND_EXCEPTION = 0x0002,	/* Exception occurred */
197    UNWIND_RERAISE   = 0x0004,	/* Exception re-raised by 'finally' */
198    UNWIND_RETURN    = 0x0008,	/* 'return' statement */
199    UNWIND_BREAK     = 0x0010,	/* 'break' statement */
200    UNWIND_CONTINUE  = 0x0020,	/* 'continue' statement */
201    UNWIND_YIELD     = 0x0040	/* 'yield' operator */
202};
203
204PyAPI_FUNC(void) _PyEval_SetExcInfo(PyThreadState *tstate, PyObject *type,
205				    PyObject *value, PyObject *tb);
206PyAPI_FUNC(void) _PyEval_ResetExcInfo(PyThreadState *);
207
208PyAPI_FUNC(void) _PyEval_RaiseForUnboundLocal(struct _frame *frame,
209                                              int var_index);
210PyAPI_FUNC(int) _PyEval_CheckedExceptionMatches(PyObject *exc,
211                                                PyObject *exc_type);
212
213PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
214
215PyAPI_FUNC(void) _PyEval_RaiseForGlobalNameError(PyObject *name);
216PyAPI_FUNC(void) _PyEval_RaiseForUnboundFreeVar(struct _frame *, int);
217
218PyAPI_FUNC(PyObject *) _PyEval_CallFunction(PyObject **, int, int);
219PyAPI_FUNC(PyObject *) _PyEval_CallFunctionVarKw(PyObject **, int, int, int);
220
221PyAPI_FUNC(PyObject *) _PyEval_ApplySlice(PyObject *, PyObject *, PyObject *);
222PyAPI_FUNC(int) _PyEval_AssignSlice(PyObject *, PyObject *,
223                                    PyObject *, PyObject *);
224
225PyAPI_FUNC(enum _PyUnwindReason) _PyEval_DoRaise(PyObject *type, PyObject *val,
226                                                 PyObject *tb);
227
228PyAPI_FUNC(int) _PyEval_UnpackIterable(PyObject *, int, PyObject **);
229
230PyAPI_FUNC(PyObject *) _PyEval_ImportName(PyObject *level,
231                                          PyObject *names,
232                                          PyObject *module_name);
233
234PyAPI_FUNC(PyObject *) _PyEval_LoadName(struct _frame *, int);
235PyAPI_FUNC(int) _PyEval_StoreName(struct _frame *, int, PyObject *);
236PyAPI_FUNC(int) _PyEval_DeleteName(struct _frame *, int);
237
238PyAPI_FUNC(int) _PyEval_HandlePyTickerExpired(PyThreadState *tstate);
239
240/* Records whether tracing is on for any thread.  Counts the number of
241 * threads for which tstate->c_tracefunc is non-NULL, so if the value
242 * is 0, we know we don't have to check this thread's c_tracefunc.
243 * This speeds up the if statement in PyEval_EvalFrame() after
244 * fast_next_opcode. */
245PyAPI_DATA(int) _Py_TracingPossible;
246
247/* Records whether profiling is on for any thread.  Counts the number of
248 * threads for which tstate->c_profilefunc is non-NULL, so if the value
249 * is 0, we know we don't have to check this thread's c_profilefunc. */
250PyAPI_DATA(int) _Py_ProfilingPossible;
251
252PyAPI_FUNC(int) _PyEval_CallTrace(Py_tracefunc, PyObject *, struct _frame *,
253                                  int, PyObject *);
254PyAPI_FUNC(void) _PyEval_CallExcTrace(PyThreadState *, struct _frame *);
255PyAPI_FUNC(int) _PyEval_TraceEnterFunction(PyThreadState *, struct _frame *);
256PyAPI_FUNC(int) _PyEval_TraceLeaveFunction(PyThreadState *, struct _frame *,
257                                           PyObject *, char, char);
258
259
260/* Built-in functions which can be inlined by the LLVM code generator. */
261PyAPI_FUNC(PyObject *) _PyBuiltin_Len(PyObject *, PyObject *);
262
263#ifdef __cplusplus
264}
265#endif
266#endif /* !Py_EVAL_H */