blob: 61bbc4f69d531c35c96ea5b70220e09b2b06738d [file] [log] [blame]
Victor Stinnerf4b1e3d2019-11-04 19:48:34 +01001#ifndef Py_CPYTHON_CEVAL_H
2# error "this header file must not be included directly"
3#endif
4
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9PyAPI_DATA(int) _Py_CheckRecursionLimit;
10
11#ifdef USE_STACKCHECK
12/* With USE_STACKCHECK macro defined, trigger stack checks in
13 _Py_CheckRecursiveCall() on every 64th call to Py_EnterRecursiveCall. */
14# define _Py_MakeRecCheck(x) \
15 (++(x) > _Py_CheckRecursionLimit || \
16 ++(PyThreadState_GET()->stackcheck_counter) > 64)
17#else
18# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
19#endif
20
21PyAPI_FUNC(int) _Py_CheckRecursiveCall(const char *where);
22
23#define _Py_EnterRecursiveCall_macro(where) \
24 (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
25 _Py_CheckRecursiveCall(where))
26
27#define Py_EnterRecursiveCall(where) _Py_EnterRecursiveCall_macro(where)
28
29
30/* Compute the "lower-water mark" for a recursion limit. When
31 * Py_LeaveRecursiveCall() is called with a recursion depth below this mark,
32 * the overflowed flag is reset to 0. */
33#define _Py_RecursionLimitLowerWaterMark(limit) \
34 (((limit) > 200) \
35 ? ((limit) - 50) \
36 : (3 * ((limit) >> 2)))
37
38#define _Py_MakeEndRecCheck(x) \
39 (--(x) < _Py_RecursionLimitLowerWaterMark(_Py_CheckRecursionLimit))
40
41#define _Py_LeaveRecursiveCall_macro() \
42 do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \
43 PyThreadState_GET()->overflowed = 0; \
44 } while(0)
45
46#define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_macro()
47
48#ifdef __cplusplus
49}
50#endif