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