Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 1 | #ifndef Py_CPYTHON_CEVAL_H |
| 2 | # error "this header file must not be included directly" |
| 3 | #endif |
| 4 | |
| 5 | #ifdef __cplusplus |
| 6 | extern "C" { |
| 7 | #endif |
| 8 | |
Victor Stinner | 51edf8a | 2019-11-16 01:04:44 +0100 | [diff] [blame] | 9 | PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *); |
| 10 | PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *); |
| 11 | PyAPI_FUNC(int) _PyEval_GetCoroutineOriginTrackingDepth(void); |
| 12 | PyAPI_FUNC(void) _PyEval_SetAsyncGenFirstiter(PyObject *); |
| 13 | PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFirstiter(void); |
| 14 | PyAPI_FUNC(void) _PyEval_SetAsyncGenFinalizer(PyObject *); |
| 15 | PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void); |
| 16 | |
| 17 | /* Helper to look up a builtin object */ |
| 18 | PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *); |
| 19 | /* Look at the current frame's (if any) code's co_flags, and turn on |
| 20 | the corresponding compiler flags in cf->cf_flags. Return 1 if any |
| 21 | flag was set, else return 0. */ |
| 22 | PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf); |
| 23 | |
Victor Stinner | 0b72b23 | 2020-03-12 23:18:39 +0100 | [diff] [blame^] | 24 | PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _frame *f, int exc); |
Victor Stinner | 51edf8a | 2019-11-16 01:04:44 +0100 | [diff] [blame] | 25 | |
| 26 | PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); |
| 27 | PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); |
| 28 | |
| 29 | PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc); |
| 30 | |
| 31 | PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *); |
| 32 | PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *); |
| 33 | |
Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 34 | PyAPI_DATA(int) _Py_CheckRecursionLimit; |
| 35 | |
| 36 | #ifdef USE_STACKCHECK |
| 37 | /* With USE_STACKCHECK macro defined, trigger stack checks in |
| 38 | _Py_CheckRecursiveCall() on every 64th call to Py_EnterRecursiveCall. */ |
Victor Stinner | be434dc | 2019-11-05 00:51:22 +0100 | [diff] [blame] | 39 | static inline int _Py_MakeRecCheck(PyThreadState *tstate) { |
| 40 | return (++tstate->recursion_depth > _Py_CheckRecursionLimit |
| 41 | || ++tstate->stackcheck_counter > 64); |
| 42 | } |
Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 43 | #else |
Victor Stinner | be434dc | 2019-11-05 00:51:22 +0100 | [diff] [blame] | 44 | static inline int _Py_MakeRecCheck(PyThreadState *tstate) { |
| 45 | return (++tstate->recursion_depth > _Py_CheckRecursionLimit); |
| 46 | } |
Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 47 | #endif |
| 48 | |
Victor Stinner | be434dc | 2019-11-05 00:51:22 +0100 | [diff] [blame] | 49 | PyAPI_FUNC(int) _Py_CheckRecursiveCall( |
| 50 | PyThreadState *tstate, |
| 51 | const char *where); |
Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 52 | |
Victor Stinner | be434dc | 2019-11-05 00:51:22 +0100 | [diff] [blame] | 53 | static inline int _Py_EnterRecursiveCall(PyThreadState *tstate, |
| 54 | const char *where) { |
| 55 | return (_Py_MakeRecCheck(tstate) && _Py_CheckRecursiveCall(tstate, where)); |
| 56 | } |
Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 57 | |
Victor Stinner | be434dc | 2019-11-05 00:51:22 +0100 | [diff] [blame] | 58 | static inline int _Py_EnterRecursiveCall_inline(const char *where) { |
| 59 | PyThreadState *tstate = PyThreadState_GET(); |
| 60 | return _Py_EnterRecursiveCall(tstate, where); |
| 61 | } |
| 62 | |
| 63 | #define Py_EnterRecursiveCall(where) _Py_EnterRecursiveCall_inline(where) |
Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 64 | |
| 65 | |
| 66 | /* Compute the "lower-water mark" for a recursion limit. When |
| 67 | * Py_LeaveRecursiveCall() is called with a recursion depth below this mark, |
| 68 | * the overflowed flag is reset to 0. */ |
| 69 | #define _Py_RecursionLimitLowerWaterMark(limit) \ |
| 70 | (((limit) > 200) \ |
| 71 | ? ((limit) - 50) \ |
| 72 | : (3 * ((limit) >> 2))) |
| 73 | |
| 74 | #define _Py_MakeEndRecCheck(x) \ |
| 75 | (--(x) < _Py_RecursionLimitLowerWaterMark(_Py_CheckRecursionLimit)) |
| 76 | |
Victor Stinner | be434dc | 2019-11-05 00:51:22 +0100 | [diff] [blame] | 77 | static inline void _Py_LeaveRecursiveCall(PyThreadState *tstate) { |
| 78 | if (_Py_MakeEndRecCheck(tstate->recursion_depth)) { |
| 79 | tstate->overflowed = 0; |
| 80 | } |
| 81 | } |
Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 82 | |
Victor Stinner | be434dc | 2019-11-05 00:51:22 +0100 | [diff] [blame] | 83 | static inline void _Py_LeaveRecursiveCall_inline(void) { |
| 84 | PyThreadState *tstate = PyThreadState_GET(); |
| 85 | _Py_LeaveRecursiveCall(tstate); |
| 86 | } |
| 87 | |
| 88 | #define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline() |
Victor Stinner | f4b1e3d | 2019-11-04 19:48:34 +0100 | [diff] [blame] | 89 | |
| 90 | #ifdef __cplusplus |
| 91 | } |
| 92 | #endif |