1#ifndef Py_INTERNAL_CEVAL_H
2#define Py_INTERNAL_CEVAL_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#ifndef Py_BUILD_CORE
8# error "this header requires Py_BUILD_CORE define"
9#endif
10
11/* Forward declarations */
12struct pyruntimestate;
13struct _ceval_runtime_state;
14
15#include "pycore_interp.h" /* PyInterpreterState.eval_frame */
16
17extern void _Py_FinishPendingCalls(PyThreadState *tstate);
18extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
19extern int _PyEval_InitState(struct _ceval_state *ceval);
20extern void _PyEval_FiniState(struct _ceval_state *ceval);
21PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
22PyAPI_FUNC(int) _PyEval_AddPendingCall(
23 PyInterpreterState *interp,
24 int (*func)(void *),
25 void *arg);
26PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
27#ifdef HAVE_FORK
28extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
29#endif
30PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(
31 PyThreadState *tstate,
32 int new_depth);
33
34void _PyEval_Fini(void);
35
36
37extern PyObject* _PyEval_GetBuiltins(PyThreadState *tstate);
38extern PyObject *_PyEval_BuiltinsFromGlobals(
39 PyThreadState *tstate,
40 PyObject *globals);
41
42
43static inline PyObject*
44_PyEval_EvalFrame(PyThreadState *tstate, PyFrameObject *f, int throwflag)
45{
46 return tstate->interp->eval_frame(tstate, f, throwflag);
47}
48
49extern PyObject *
50_PyEval_Vector(PyThreadState *tstate,
51 PyFrameConstructor *desc, PyObject *locals,
52 PyObject* const* args, size_t argcount,
53 PyObject *kwnames);
54
55#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
56extern int _PyEval_ThreadsInitialized(PyInterpreterState *interp);
57#else
58extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
59#endif
60extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
61extern void _PyEval_FiniGIL(PyInterpreterState *interp);
62
63extern void _PyEval_ReleaseLock(PyThreadState *tstate);
64
65extern void _PyEval_DeactivateOpCache(void);
66
67
68/* --- _Py_EnterRecursiveCall() ----------------------------------------- */
69
70#ifdef USE_STACKCHECK
71/* With USE_STACKCHECK macro defined, trigger stack checks in
72 _Py_CheckRecursiveCall() on every 64th call to Py_EnterRecursiveCall. */
73static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
74 return (++tstate->recursion_depth > tstate->interp->ceval.recursion_limit
75 || ++tstate->stackcheck_counter > 64);
76}
77#else
78static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
79 return (++tstate->recursion_depth > tstate->interp->ceval.recursion_limit);
80}
81#endif
82
83PyAPI_FUNC(int) _Py_CheckRecursiveCall(
84 PyThreadState *tstate,
85 const char *where);
86
87static inline int _Py_EnterRecursiveCall(PyThreadState *tstate,
88 const char *where) {
89 return (_Py_MakeRecCheck(tstate) && _Py_CheckRecursiveCall(tstate, where));
90}
91
92static inline int _Py_EnterRecursiveCall_inline(const char *where) {
93 PyThreadState *tstate = PyThreadState_GET();
94 return _Py_EnterRecursiveCall(tstate, where);
95}
96
97#define Py_EnterRecursiveCall(where) _Py_EnterRecursiveCall_inline(where)
98
99static inline void _Py_LeaveRecursiveCall(PyThreadState *tstate) {
100 tstate->recursion_depth--;
101}
102
103static inline void _Py_LeaveRecursiveCall_inline(void) {
104 PyThreadState *tstate = PyThreadState_GET();
105 _Py_LeaveRecursiveCall(tstate);
106}
107
108#define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline()
109
110
111#ifdef __cplusplus
112}
113#endif
114#endif /* !Py_INTERNAL_CEVAL_H */
115