Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Include/internal/pycore_ceval.h
12 views
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
#ifndef Py_DEFAULT_RECURSION_LIMIT
16
# define Py_DEFAULT_RECURSION_LIMIT 1000
17
#endif
18
19
#include "pycore_interp.h" // PyInterpreterState.eval_frame
20
#include "pycore_pystate.h" // _PyThreadState_GET()
21
22
23
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
24
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
25
extern void _PyEval_FiniState(struct _ceval_state *ceval);
26
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
27
PyAPI_FUNC(int) _PyEval_AddPendingCall(
28
PyInterpreterState *interp,
29
int (*func)(void *),
30
void *arg,
31
int mainthreadonly);
32
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
33
#ifdef HAVE_FORK
34
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
35
#endif
36
37
// Used by sys.call_tracing()
38
extern PyObject* _PyEval_CallTracing(PyObject *func, PyObject *args);
39
40
// Used by sys.get_asyncgen_hooks()
41
extern PyObject* _PyEval_GetAsyncGenFirstiter(void);
42
extern PyObject* _PyEval_GetAsyncGenFinalizer(void);
43
44
// Used by sys.set_asyncgen_hooks()
45
extern int _PyEval_SetAsyncGenFirstiter(PyObject *);
46
extern int _PyEval_SetAsyncGenFinalizer(PyObject *);
47
48
// Used by sys.get_coroutine_origin_tracking_depth()
49
// and sys.set_coroutine_origin_tracking_depth()
50
extern int _PyEval_GetCoroutineOriginTrackingDepth(void);
51
extern int _PyEval_SetCoroutineOriginTrackingDepth(int depth);
52
53
extern void _PyEval_Fini(void);
54
55
56
extern PyObject* _PyEval_GetBuiltins(PyThreadState *tstate);
57
extern PyObject* _PyEval_BuiltinsFromGlobals(
58
PyThreadState *tstate,
59
PyObject *globals);
60
61
// Trampoline API
62
63
typedef struct {
64
// Callback to initialize the trampoline state
65
void* (*init_state)(void);
66
// Callback to register every trampoline being created
67
void (*write_state)(void* state, const void *code_addr,
68
unsigned int code_size, PyCodeObject* code);
69
// Callback to free the trampoline state
70
int (*free_state)(void* state);
71
} _PyPerf_Callbacks;
72
73
extern int _PyPerfTrampoline_SetCallbacks(_PyPerf_Callbacks *);
74
extern void _PyPerfTrampoline_GetCallbacks(_PyPerf_Callbacks *);
75
extern int _PyPerfTrampoline_Init(int activate);
76
extern int _PyPerfTrampoline_Fini(void);
77
extern int _PyIsPerfTrampolineActive(void);
78
extern PyStatus _PyPerfTrampoline_AfterFork_Child(void);
79
#ifdef PY_HAVE_PERF_TRAMPOLINE
80
extern _PyPerf_Callbacks _Py_perfmap_callbacks;
81
#endif
82
83
static inline PyObject*
84
_PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int throwflag)
85
{
86
EVAL_CALL_STAT_INC(EVAL_CALL_TOTAL);
87
if (tstate->interp->eval_frame == NULL) {
88
return _PyEval_EvalFrameDefault(tstate, frame, throwflag);
89
}
90
return tstate->interp->eval_frame(tstate, frame, throwflag);
91
}
92
93
extern PyObject*
94
_PyEval_Vector(PyThreadState *tstate,
95
PyFunctionObject *func, PyObject *locals,
96
PyObject* const* args, size_t argcount,
97
PyObject *kwnames);
98
99
extern int _PyEval_ThreadsInitialized(void);
100
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate, int own_gil);
101
extern void _PyEval_FiniGIL(PyInterpreterState *interp);
102
103
extern void _PyEval_AcquireLock(PyThreadState *tstate);
104
extern void _PyEval_ReleaseLock(PyInterpreterState *, PyThreadState *);
105
extern PyThreadState * _PyThreadState_SwapNoGIL(PyThreadState *);
106
107
extern void _PyEval_DeactivateOpCache(void);
108
109
110
/* --- _Py_EnterRecursiveCall() ----------------------------------------- */
111
112
#ifdef USE_STACKCHECK
113
/* With USE_STACKCHECK macro defined, trigger stack checks in
114
_Py_CheckRecursiveCall() on every 64th call to _Py_EnterRecursiveCall. */
115
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
116
return (tstate->c_recursion_remaining-- <= 0
117
|| (tstate->c_recursion_remaining & 63) == 0);
118
}
119
#else
120
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
121
return tstate->c_recursion_remaining-- <= 0;
122
}
123
#endif
124
125
PyAPI_FUNC(int) _Py_CheckRecursiveCall(
126
PyThreadState *tstate,
127
const char *where);
128
129
int _Py_CheckRecursiveCallPy(
130
PyThreadState *tstate);
131
132
static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate,
133
const char *where) {
134
return (_Py_MakeRecCheck(tstate) && _Py_CheckRecursiveCall(tstate, where));
135
}
136
137
static inline int _Py_EnterRecursiveCall(const char *where) {
138
PyThreadState *tstate = _PyThreadState_GET();
139
return _Py_EnterRecursiveCallTstate(tstate, where);
140
}
141
142
static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate) {
143
tstate->c_recursion_remaining++;
144
}
145
146
static inline void _Py_LeaveRecursiveCall(void) {
147
PyThreadState *tstate = _PyThreadState_GET();
148
_Py_LeaveRecursiveCallTstate(tstate);
149
}
150
151
extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
152
153
extern PyObject* _Py_MakeCoro(PyFunctionObject *func);
154
155
extern int _Py_HandlePending(PyThreadState *tstate);
156
157
158
159
#ifdef __cplusplus
160
}
161
#endif
162
#endif /* !Py_INTERNAL_CEVAL_H */
163
164