Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Include/ceval.h
12 views
1
/* Interface to random parts in ceval.c */
2
3
#ifndef Py_CEVAL_H
4
#define Py_CEVAL_H
5
#ifdef __cplusplus
6
extern "C" {
7
#endif
8
9
10
PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *);
11
12
PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co,
13
PyObject *globals,
14
PyObject *locals,
15
PyObject *const *args, int argc,
16
PyObject *const *kwds, int kwdc,
17
PyObject *const *defs, int defc,
18
PyObject *kwdefs, PyObject *closure);
19
20
PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
21
PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
22
PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
23
PyAPI_FUNC(PyFrameObject *) PyEval_GetFrame(void);
24
25
PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
26
PyAPI_FUNC(int) Py_MakePendingCalls(void);
27
28
/* Protection against deeply nested recursive calls
29
30
In Python 3.0, this protection has two levels:
31
* normal anti-recursion protection is triggered when the recursion level
32
exceeds the current recursion limit. It raises a RecursionError, and sets
33
the "overflowed" flag in the thread state structure. This flag
34
temporarily *disables* the normal protection; this allows cleanup code
35
to potentially outgrow the recursion limit while processing the
36
RecursionError.
37
* "last chance" anti-recursion protection is triggered when the recursion
38
level exceeds "current recursion limit + 50". By construction, this
39
protection can only be triggered when the "overflowed" flag is set. It
40
means the cleanup code has itself gone into an infinite loop, or the
41
RecursionError has been mistakingly ignored. When this protection is
42
triggered, the interpreter aborts with a Fatal Error.
43
44
In addition, the "overflowed" flag is automatically reset when the
45
recursion level drops below "current recursion limit - 50". This heuristic
46
is meant to ensure that the normal anti-recursion protection doesn't get
47
disabled too long.
48
49
Please note: this scheme has its own limitations. See:
50
http://mail.python.org/pipermail/python-dev/2008-August/082106.html
51
for some observations.
52
*/
53
PyAPI_FUNC(void) Py_SetRecursionLimit(int);
54
PyAPI_FUNC(int) Py_GetRecursionLimit(void);
55
56
PyAPI_FUNC(int) Py_EnterRecursiveCall(const char *where);
57
PyAPI_FUNC(void) Py_LeaveRecursiveCall(void);
58
59
PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
60
PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
61
62
PyAPI_FUNC(PyObject *) PyEval_EvalFrame(PyFrameObject *);
63
PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc);
64
65
/* Interface for threads.
66
67
A module that plans to do a blocking system call (or something else
68
that lasts a long time and doesn't touch Python data) can allow other
69
threads to run as follows:
70
71
...preparations here...
72
Py_BEGIN_ALLOW_THREADS
73
...blocking system call here...
74
Py_END_ALLOW_THREADS
75
...interpret result here...
76
77
The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
78
{}-surrounded block.
79
To leave the block in the middle (e.g., with return), you must insert
80
a line containing Py_BLOCK_THREADS before the return, e.g.
81
82
if (...premature_exit...) {
83
Py_BLOCK_THREADS
84
PyErr_SetFromErrno(PyExc_OSError);
85
return NULL;
86
}
87
88
An alternative is:
89
90
Py_BLOCK_THREADS
91
if (...premature_exit...) {
92
PyErr_SetFromErrno(PyExc_OSError);
93
return NULL;
94
}
95
Py_UNBLOCK_THREADS
96
97
For convenience, that the value of 'errno' is restored across
98
Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
99
100
WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
101
Py_END_ALLOW_THREADS!!!
102
103
Note that not yet all candidates have been converted to use this
104
mechanism!
105
*/
106
107
PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
108
PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
109
110
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
111
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
112
113
#define Py_BEGIN_ALLOW_THREADS { \
114
PyThreadState *_save; \
115
_save = PyEval_SaveThread();
116
#define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
117
#define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
118
#define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
119
}
120
121
/* Masks and values used by FORMAT_VALUE opcode. */
122
#define FVC_MASK 0x3
123
#define FVC_NONE 0x0
124
#define FVC_STR 0x1
125
#define FVC_REPR 0x2
126
#define FVC_ASCII 0x3
127
#define FVS_MASK 0x4
128
#define FVS_HAVE_SPEC 0x4
129
130
#ifndef Py_LIMITED_API
131
# define Py_CPYTHON_CEVAL_H
132
# include "cpython/ceval.h"
133
# undef Py_CPYTHON_CEVAL_H
134
#endif
135
136
#ifdef __cplusplus
137
}
138
#endif
139
#endif /* !Py_CEVAL_H */
140
141