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