blob: f03b53ade92983f23100adf2823632759d4c2610 [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
Victor Stinner51edf8a2019-11-16 01:04:44 +01009PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
10PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
11PyAPI_FUNC(int) _PyEval_GetCoroutineOriginTrackingDepth(void);
12PyAPI_FUNC(void) _PyEval_SetAsyncGenFirstiter(PyObject *);
13PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFirstiter(void);
14PyAPI_FUNC(void) _PyEval_SetAsyncGenFinalizer(PyObject *);
15PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void);
16
17/* Helper to look up a builtin object */
18PyAPI_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. */
22PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
23
Victor Stinner0b72b232020-03-12 23:18:39 +010024PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _frame *f, int exc);
Victor Stinner51edf8a2019-11-16 01:04:44 +010025
26PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
27PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
28
29PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
30
31PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
32PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *);
33
Victor Stinnerf4b1e3d2019-11-04 19:48:34 +010034PyAPI_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 Stinnerbe434dc2019-11-05 00:51:22 +010039static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
40 return (++tstate->recursion_depth > _Py_CheckRecursionLimit
41 || ++tstate->stackcheck_counter > 64);
42}
Victor Stinnerf4b1e3d2019-11-04 19:48:34 +010043#else
Victor Stinnerbe434dc2019-11-05 00:51:22 +010044static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
45 return (++tstate->recursion_depth > _Py_CheckRecursionLimit);
46}
Victor Stinnerf4b1e3d2019-11-04 19:48:34 +010047#endif
48
Victor Stinnerbe434dc2019-11-05 00:51:22 +010049PyAPI_FUNC(int) _Py_CheckRecursiveCall(
50 PyThreadState *tstate,
51 const char *where);
Victor Stinnerf4b1e3d2019-11-04 19:48:34 +010052
Victor Stinnerbe434dc2019-11-05 00:51:22 +010053static inline int _Py_EnterRecursiveCall(PyThreadState *tstate,
54 const char *where) {
55 return (_Py_MakeRecCheck(tstate) && _Py_CheckRecursiveCall(tstate, where));
56}
Victor Stinnerf4b1e3d2019-11-04 19:48:34 +010057
Victor Stinnerbe434dc2019-11-05 00:51:22 +010058static 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 Stinnerf4b1e3d2019-11-04 19:48:34 +010064
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 Stinnerbe434dc2019-11-05 00:51:22 +010077static inline void _Py_LeaveRecursiveCall(PyThreadState *tstate) {
78 if (_Py_MakeEndRecCheck(tstate->recursion_depth)) {
79 tstate->overflowed = 0;
80 }
81}
Victor Stinnerf4b1e3d2019-11-04 19:48:34 +010082
Victor Stinnerbe434dc2019-11-05 00:51:22 +010083static 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 Stinnerf4b1e3d2019-11-04 19:48:34 +010089
90#ifdef __cplusplus
91}
92#endif