8
/* Interface to random parts in ceval.c */
10
PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
11
PyObject *, PyObject *, PyObject *);
13
/* DLL-level Backwards compatibility: */
14
#undef PyEval_CallObject
15
PyAPI_FUNC(PyObject *) PyEval_CallObject(PyObject *, PyObject *);
18
#define PyEval_CallObject(func,arg) \
19
PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
21
PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj,
22
const char *format, ...);
23
PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,
24
const char *methodname,
25
const char *format, ...);
27
PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
28
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
30
struct _frame; /* Avoid including frameobject.h */
32
PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
33
PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
34
PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
35
PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void);
37
/* Look at the current frame's (if any) code's co_flags, and turn on
38
the corresponding compiler flags in cf->cf_flags. Return 1 if any
39
flag was set, else return 0. */
40
PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
42
PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
43
PyAPI_FUNC(int) Py_MakePendingCalls(void);
45
/* Protection against deeply nested recursive calls
47
In Python 3.0, this protection has two levels:
48
* normal anti-recursion protection is triggered when the recursion level
49
exceeds the current recursion limit. It raises a RuntimeError, and sets
50
the "overflowed" flag in the thread state structure. This flag
51
temporarily *disables* the normal protection; this allows cleanup code
52
to potentially outgrow the recursion limit while processing the
54
* "last chance" anti-recursion protection is triggered when the recursion
55
level exceeds "current recursion limit + 50". By construction, this
56
protection can only be triggered when the "overflowed" flag is set. It
57
means the cleanup code has itself gone into an infinite loop, or the
58
RuntimeError has been mistakingly ignored. When this protection is
59
triggered, the interpreter aborts with a Fatal Error.
61
In addition, the "overflowed" flag is automatically reset when the
62
recursion level drops below "current recursion limit - 50". This heuristic
63
is meant to ensure that the normal anti-recursion protection doesn't get
66
Please note: this scheme has its own limitations. See:
67
http://mail.python.org/pipermail/python-dev/2008-August/082106.html
68
for some observations.
70
PyAPI_FUNC(void) Py_SetRecursionLimit(int);
71
PyAPI_FUNC(int) Py_GetRecursionLimit(void);
73
#define Py_EnterRecursiveCall(where) \
74
(_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
75
_Py_CheckRecursiveCall(where))
76
#define Py_LeaveRecursiveCall() \
77
do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \
78
PyThreadState_GET()->overflowed = 0; \
80
PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);
81
PyAPI_DATA(int) _Py_CheckRecursionLimit;
84
/* With USE_STACKCHECK, we artificially decrement the recursion limit in order
85
to trigger regular stack checks in _Py_CheckRecursiveCall(), except if
86
the "overflowed" flag is set, in which case we need the true value
87
of _Py_CheckRecursionLimit for _Py_MakeEndRecCheck() to function properly.
89
# define _Py_MakeRecCheck(x) \
90
(++(x) > (_Py_CheckRecursionLimit += PyThreadState_GET()->overflowed - 1))
92
# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
95
#define _Py_MakeEndRecCheck(x) \
96
(--(x) < ((_Py_CheckRecursionLimit > 100) \
97
? (_Py_CheckRecursionLimit - 50) \
98
: (3 * (_Py_CheckRecursionLimit >> 2))))
100
#define Py_ALLOW_RECURSION \
101
do { unsigned char _old = PyThreadState_GET()->recursion_critical;\
102
PyThreadState_GET()->recursion_critical = 1;
104
#define Py_END_ALLOW_RECURSION \
105
PyThreadState_GET()->recursion_critical = _old; \
108
PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
109
PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
111
PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
112
PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
113
PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
115
/* this used to be handled on a per-thread basis - now just two globals */
116
PyAPI_DATA(volatile int) _Py_Ticker;
117
PyAPI_DATA(int) _Py_CheckInterval;
119
/* Interface for threads.
121
A module that plans to do a blocking system call (or something else
122
that lasts a long time and doesn't touch Python data) can allow other
123
threads to run as follows:
125
...preparations here...
126
Py_BEGIN_ALLOW_THREADS
127
...blocking system call here...
129
...interpret result here...
131
The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
133
To leave the block in the middle (e.g., with return), you must insert
134
a line containing Py_BLOCK_THREADS before the return, e.g.
136
if (...premature_exit...) {
138
PyErr_SetFromErrno(PyExc_IOError);
145
if (...premature_exit...) {
146
PyErr_SetFromErrno(PyExc_IOError);
151
For convenience, that the value of 'errno' is restored across
152
Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
154
WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
155
Py_END_ALLOW_THREADS!!!
157
The function PyEval_InitThreads() should be called only from
158
init_thread() in "_threadmodule.c".
160
Note that not yet all candidates have been converted to use this
164
PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
165
PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
169
PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
170
PyAPI_FUNC(void) PyEval_InitThreads(void);
171
PyAPI_FUNC(void) PyEval_AcquireLock(void);
172
PyAPI_FUNC(void) PyEval_ReleaseLock(void);
173
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
174
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
175
PyAPI_FUNC(void) PyEval_ReInitThreads(void);
177
#define Py_BEGIN_ALLOW_THREADS { \
178
PyThreadState *_save; \
179
_save = PyEval_SaveThread();
180
#define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
181
#define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
182
#define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
185
#else /* !WITH_THREAD */
187
#define Py_BEGIN_ALLOW_THREADS {
188
#define Py_BLOCK_THREADS
189
#define Py_UNBLOCK_THREADS
190
#define Py_END_ALLOW_THREADS }
192
#endif /* !WITH_THREAD */
194
PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
200
#endif /* !Py_CEVAL_H */