/* Interface to random parts in ceval.c */12#ifndef Py_CEVAL_H3#define Py_CEVAL_H4#ifdef __cplusplus5extern "C" {6#endif789PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *);1011PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co,12PyObject *globals,13PyObject *locals,14PyObject *const *args, int argc,15PyObject *const *kwds, int kwdc,16PyObject *const *defs, int defc,17PyObject *kwdefs, PyObject *closure);1819PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);20PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);21PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);22PyAPI_FUNC(PyFrameObject *) PyEval_GetFrame(void);2324PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);25PyAPI_FUNC(int) Py_MakePendingCalls(void);2627/* Protection against deeply nested recursive calls2829In Python 3.0, this protection has two levels:30* normal anti-recursion protection is triggered when the recursion level31exceeds the current recursion limit. It raises a RecursionError, and sets32the "overflowed" flag in the thread state structure. This flag33temporarily *disables* the normal protection; this allows cleanup code34to potentially outgrow the recursion limit while processing the35RecursionError.36* "last chance" anti-recursion protection is triggered when the recursion37level exceeds "current recursion limit + 50". By construction, this38protection can only be triggered when the "overflowed" flag is set. It39means the cleanup code has itself gone into an infinite loop, or the40RecursionError has been mistakingly ignored. When this protection is41triggered, the interpreter aborts with a Fatal Error.4243In addition, the "overflowed" flag is automatically reset when the44recursion level drops below "current recursion limit - 50". This heuristic45is meant to ensure that the normal anti-recursion protection doesn't get46disabled too long.4748Please note: this scheme has its own limitations. See:49http://mail.python.org/pipermail/python-dev/2008-August/082106.html50for some observations.51*/52PyAPI_FUNC(void) Py_SetRecursionLimit(int);53PyAPI_FUNC(int) Py_GetRecursionLimit(void);5455PyAPI_FUNC(int) Py_EnterRecursiveCall(const char *where);56PyAPI_FUNC(void) Py_LeaveRecursiveCall(void);5758PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);59PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);6061PyAPI_FUNC(PyObject *) PyEval_EvalFrame(PyFrameObject *);62PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc);6364/* Interface for threads.6566A module that plans to do a blocking system call (or something else67that lasts a long time and doesn't touch Python data) can allow other68threads to run as follows:6970...preparations here...71Py_BEGIN_ALLOW_THREADS72...blocking system call here...73Py_END_ALLOW_THREADS74...interpret result here...7576The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a77{}-surrounded block.78To leave the block in the middle (e.g., with return), you must insert79a line containing Py_BLOCK_THREADS before the return, e.g.8081if (...premature_exit...) {82Py_BLOCK_THREADS83PyErr_SetFromErrno(PyExc_OSError);84return NULL;85}8687An alternative is:8889Py_BLOCK_THREADS90if (...premature_exit...) {91PyErr_SetFromErrno(PyExc_OSError);92return NULL;93}94Py_UNBLOCK_THREADS9596For convenience, that the value of 'errno' is restored across97Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.9899WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND100Py_END_ALLOW_THREADS!!!101102Note that not yet all candidates have been converted to use this103mechanism!104*/105106PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);107PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);108109PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);110PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);111112#define Py_BEGIN_ALLOW_THREADS { \113PyThreadState *_save; \114_save = PyEval_SaveThread();115#define Py_BLOCK_THREADS PyEval_RestoreThread(_save);116#define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();117#define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \118}119120/* Masks and values used by FORMAT_VALUE opcode. */121#define FVC_MASK 0x3122#define FVC_NONE 0x0123#define FVC_STR 0x1124#define FVC_REPR 0x2125#define FVC_ASCII 0x3126#define FVS_MASK 0x4127#define FVS_HAVE_SPEC 0x4128129#ifndef Py_LIMITED_API130# define Py_CPYTHON_CEVAL_H131# include "cpython/ceval.h"132# undef Py_CPYTHON_CEVAL_H133#endif134135#ifdef __cplusplus136}137#endif138#endif /* !Py_CEVAL_H */139140141