• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_INTERNAL_CEVAL_H
2 #define Py_INTERNAL_CEVAL_H
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6 
7 #ifndef Py_BUILD_CORE
8 #  error "this header requires Py_BUILD_CORE define"
9 #endif
10 
11 /* Forward declarations */
12 struct pyruntimestate;
13 struct _ceval_runtime_state;
14 
15 #include "pycore_interp.h"   /* PyInterpreterState.eval_frame */
16 
17 extern void _Py_FinishPendingCalls(PyThreadState *tstate);
18 extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
19 extern int _PyEval_InitState(struct _ceval_state *ceval);
20 extern void _PyEval_FiniState(struct _ceval_state *ceval);
21 PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
22 PyAPI_FUNC(int) _PyEval_AddPendingCall(
23     PyInterpreterState *interp,
24     int (*func)(void *),
25     void *arg);
26 PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
27 #ifdef HAVE_FORK
28 extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
29 #endif
30 PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(
31     PyThreadState *tstate,
32     int new_depth);
33 
34 void _PyEval_Fini(void);
35 
36 
37 extern PyObject* _PyEval_GetBuiltins(PyThreadState *tstate);
38 extern PyObject *_PyEval_BuiltinsFromGlobals(
39     PyThreadState *tstate,
40     PyObject *globals);
41 
42 
43 static inline PyObject*
_PyEval_EvalFrame(PyThreadState * tstate,PyFrameObject * f,int throwflag)44 _PyEval_EvalFrame(PyThreadState *tstate, PyFrameObject *f, int throwflag)
45 {
46     return tstate->interp->eval_frame(tstate, f, throwflag);
47 }
48 
49 extern 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
56 extern int _PyEval_ThreadsInitialized(PyInterpreterState *interp);
57 #else
58 extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
59 #endif
60 extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
61 extern void _PyEval_FiniGIL(PyInterpreterState *interp);
62 
63 extern void _PyEval_ReleaseLock(PyThreadState *tstate);
64 
65 extern 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. */
_Py_MakeRecCheck(PyThreadState * tstate)73 static inline int _Py_MakeRecCheck(PyThreadState *tstate)  {
74     return (++tstate->recursion_depth > tstate->interp->ceval.recursion_limit
75             || ++tstate->stackcheck_counter > 64);
76 }
77 #else
_Py_MakeRecCheck(PyThreadState * tstate)78 static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
79     return (++tstate->recursion_depth > tstate->interp->ceval.recursion_limit);
80 }
81 #endif
82 
83 PyAPI_FUNC(int) _Py_CheckRecursiveCall(
84     PyThreadState *tstate,
85     const char *where);
86 
_Py_EnterRecursiveCall(PyThreadState * tstate,const char * where)87 static inline int _Py_EnterRecursiveCall(PyThreadState *tstate,
88                                          const char *where) {
89     return (_Py_MakeRecCheck(tstate) && _Py_CheckRecursiveCall(tstate, where));
90 }
91 
_Py_EnterRecursiveCall_inline(const char * where)92 static 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 
_Py_LeaveRecursiveCall(PyThreadState * tstate)99 static inline void _Py_LeaveRecursiveCall(PyThreadState *tstate)  {
100     tstate->recursion_depth--;
101 }
102 
_Py_LeaveRecursiveCall_inline(void)103 static 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