annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/python3.8/ceval.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 #ifndef Py_CEVAL_H
jpayne@69 2 #define Py_CEVAL_H
jpayne@69 3 #ifdef __cplusplus
jpayne@69 4 extern "C" {
jpayne@69 5 #endif
jpayne@69 6
jpayne@69 7
jpayne@69 8 /* Interface to random parts in ceval.c */
jpayne@69 9
jpayne@69 10 /* PyEval_CallObjectWithKeywords(), PyEval_CallObject(), PyEval_CallFunction
jpayne@69 11 * and PyEval_CallMethod are kept for backward compatibility: PyObject_Call(),
jpayne@69 12 * PyObject_CallFunction() and PyObject_CallMethod() are recommended to call
jpayne@69 13 * a callable object.
jpayne@69 14 */
jpayne@69 15
jpayne@69 16 PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
jpayne@69 17 PyObject *callable,
jpayne@69 18 PyObject *args,
jpayne@69 19 PyObject *kwargs);
jpayne@69 20
jpayne@69 21 /* Inline this */
jpayne@69 22 #define PyEval_CallObject(callable, arg) \
jpayne@69 23 PyEval_CallObjectWithKeywords(callable, arg, (PyObject *)NULL)
jpayne@69 24
jpayne@69 25 PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *callable,
jpayne@69 26 const char *format, ...);
jpayne@69 27 PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,
jpayne@69 28 const char *name,
jpayne@69 29 const char *format, ...);
jpayne@69 30
jpayne@69 31 #ifndef Py_LIMITED_API
jpayne@69 32 PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
jpayne@69 33 PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
jpayne@69 34 PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(int new_depth);
jpayne@69 35 PyAPI_FUNC(int) _PyEval_GetCoroutineOriginTrackingDepth(void);
jpayne@69 36 PyAPI_FUNC(void) _PyEval_SetAsyncGenFirstiter(PyObject *);
jpayne@69 37 PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFirstiter(void);
jpayne@69 38 PyAPI_FUNC(void) _PyEval_SetAsyncGenFinalizer(PyObject *);
jpayne@69 39 PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void);
jpayne@69 40 #endif
jpayne@69 41
jpayne@69 42 struct _frame; /* Avoid including frameobject.h */
jpayne@69 43
jpayne@69 44 PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
jpayne@69 45 PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
jpayne@69 46 PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
jpayne@69 47 PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void);
jpayne@69 48
jpayne@69 49 #ifndef Py_LIMITED_API
jpayne@69 50 /* Helper to look up a builtin object */
jpayne@69 51 PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *);
jpayne@69 52 /* Look at the current frame's (if any) code's co_flags, and turn on
jpayne@69 53 the corresponding compiler flags in cf->cf_flags. Return 1 if any
jpayne@69 54 flag was set, else return 0. */
jpayne@69 55 PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
jpayne@69 56 #endif
jpayne@69 57
jpayne@69 58 PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
jpayne@69 59 PyAPI_FUNC(int) Py_MakePendingCalls(void);
jpayne@69 60
jpayne@69 61 /* Protection against deeply nested recursive calls
jpayne@69 62
jpayne@69 63 In Python 3.0, this protection has two levels:
jpayne@69 64 * normal anti-recursion protection is triggered when the recursion level
jpayne@69 65 exceeds the current recursion limit. It raises a RecursionError, and sets
jpayne@69 66 the "overflowed" flag in the thread state structure. This flag
jpayne@69 67 temporarily *disables* the normal protection; this allows cleanup code
jpayne@69 68 to potentially outgrow the recursion limit while processing the
jpayne@69 69 RecursionError.
jpayne@69 70 * "last chance" anti-recursion protection is triggered when the recursion
jpayne@69 71 level exceeds "current recursion limit + 50". By construction, this
jpayne@69 72 protection can only be triggered when the "overflowed" flag is set. It
jpayne@69 73 means the cleanup code has itself gone into an infinite loop, or the
jpayne@69 74 RecursionError has been mistakingly ignored. When this protection is
jpayne@69 75 triggered, the interpreter aborts with a Fatal Error.
jpayne@69 76
jpayne@69 77 In addition, the "overflowed" flag is automatically reset when the
jpayne@69 78 recursion level drops below "current recursion limit - 50". This heuristic
jpayne@69 79 is meant to ensure that the normal anti-recursion protection doesn't get
jpayne@69 80 disabled too long.
jpayne@69 81
jpayne@69 82 Please note: this scheme has its own limitations. See:
jpayne@69 83 http://mail.python.org/pipermail/python-dev/2008-August/082106.html
jpayne@69 84 for some observations.
jpayne@69 85 */
jpayne@69 86 PyAPI_FUNC(void) Py_SetRecursionLimit(int);
jpayne@69 87 PyAPI_FUNC(int) Py_GetRecursionLimit(void);
jpayne@69 88
jpayne@69 89 #define Py_EnterRecursiveCall(where) \
jpayne@69 90 (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
jpayne@69 91 _Py_CheckRecursiveCall(where))
jpayne@69 92 #define Py_LeaveRecursiveCall() \
jpayne@69 93 do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \
jpayne@69 94 PyThreadState_GET()->overflowed = 0; \
jpayne@69 95 } while(0)
jpayne@69 96 PyAPI_FUNC(int) _Py_CheckRecursiveCall(const char *where);
jpayne@69 97
jpayne@69 98 /* Due to the macros in which it's used, _Py_CheckRecursionLimit is in
jpayne@69 99 the stable ABI. It should be removed therefrom when possible.
jpayne@69 100 */
jpayne@69 101 PyAPI_DATA(int) _Py_CheckRecursionLimit;
jpayne@69 102
jpayne@69 103 #ifdef USE_STACKCHECK
jpayne@69 104 /* With USE_STACKCHECK, trigger stack checks in _Py_CheckRecursiveCall()
jpayne@69 105 on every 64th call to Py_EnterRecursiveCall.
jpayne@69 106 */
jpayne@69 107 # define _Py_MakeRecCheck(x) \
jpayne@69 108 (++(x) > _Py_CheckRecursionLimit || \
jpayne@69 109 ++(PyThreadState_GET()->stackcheck_counter) > 64)
jpayne@69 110 #else
jpayne@69 111 # define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
jpayne@69 112 #endif
jpayne@69 113
jpayne@69 114 /* Compute the "lower-water mark" for a recursion limit. When
jpayne@69 115 * Py_LeaveRecursiveCall() is called with a recursion depth below this mark,
jpayne@69 116 * the overflowed flag is reset to 0. */
jpayne@69 117 #define _Py_RecursionLimitLowerWaterMark(limit) \
jpayne@69 118 (((limit) > 200) \
jpayne@69 119 ? ((limit) - 50) \
jpayne@69 120 : (3 * ((limit) >> 2)))
jpayne@69 121
jpayne@69 122 #define _Py_MakeEndRecCheck(x) \
jpayne@69 123 (--(x) < _Py_RecursionLimitLowerWaterMark(_Py_CheckRecursionLimit))
jpayne@69 124
jpayne@69 125 #define Py_ALLOW_RECURSION \
jpayne@69 126 do { unsigned char _old = PyThreadState_GET()->recursion_critical;\
jpayne@69 127 PyThreadState_GET()->recursion_critical = 1;
jpayne@69 128
jpayne@69 129 #define Py_END_ALLOW_RECURSION \
jpayne@69 130 PyThreadState_GET()->recursion_critical = _old; \
jpayne@69 131 } while(0);
jpayne@69 132
jpayne@69 133 PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
jpayne@69 134 PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
jpayne@69 135
jpayne@69 136 PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
jpayne@69 137 PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
jpayne@69 138 #ifndef Py_LIMITED_API
jpayne@69 139 PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc);
jpayne@69 140 #endif
jpayne@69 141
jpayne@69 142 /* Interface for threads.
jpayne@69 143
jpayne@69 144 A module that plans to do a blocking system call (or something else
jpayne@69 145 that lasts a long time and doesn't touch Python data) can allow other
jpayne@69 146 threads to run as follows:
jpayne@69 147
jpayne@69 148 ...preparations here...
jpayne@69 149 Py_BEGIN_ALLOW_THREADS
jpayne@69 150 ...blocking system call here...
jpayne@69 151 Py_END_ALLOW_THREADS
jpayne@69 152 ...interpret result here...
jpayne@69 153
jpayne@69 154 The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
jpayne@69 155 {}-surrounded block.
jpayne@69 156 To leave the block in the middle (e.g., with return), you must insert
jpayne@69 157 a line containing Py_BLOCK_THREADS before the return, e.g.
jpayne@69 158
jpayne@69 159 if (...premature_exit...) {
jpayne@69 160 Py_BLOCK_THREADS
jpayne@69 161 PyErr_SetFromErrno(PyExc_OSError);
jpayne@69 162 return NULL;
jpayne@69 163 }
jpayne@69 164
jpayne@69 165 An alternative is:
jpayne@69 166
jpayne@69 167 Py_BLOCK_THREADS
jpayne@69 168 if (...premature_exit...) {
jpayne@69 169 PyErr_SetFromErrno(PyExc_OSError);
jpayne@69 170 return NULL;
jpayne@69 171 }
jpayne@69 172 Py_UNBLOCK_THREADS
jpayne@69 173
jpayne@69 174 For convenience, that the value of 'errno' is restored across
jpayne@69 175 Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
jpayne@69 176
jpayne@69 177 WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
jpayne@69 178 Py_END_ALLOW_THREADS!!!
jpayne@69 179
jpayne@69 180 The function PyEval_InitThreads() should be called only from
jpayne@69 181 init_thread() in "_threadmodule.c".
jpayne@69 182
jpayne@69 183 Note that not yet all candidates have been converted to use this
jpayne@69 184 mechanism!
jpayne@69 185 */
jpayne@69 186
jpayne@69 187 PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
jpayne@69 188 PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
jpayne@69 189
jpayne@69 190 PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
jpayne@69 191 PyAPI_FUNC(void) PyEval_InitThreads(void);
jpayne@69 192 Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void);
jpayne@69 193 /* Py_DEPRECATED(3.2) */ PyAPI_FUNC(void) PyEval_ReleaseLock(void);
jpayne@69 194 PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
jpayne@69 195 PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
jpayne@69 196
jpayne@69 197 #ifndef Py_LIMITED_API
jpayne@69 198 PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
jpayne@69 199 PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
jpayne@69 200 #endif
jpayne@69 201
jpayne@69 202 #ifndef Py_LIMITED_API
jpayne@69 203 PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
jpayne@69 204 #endif
jpayne@69 205
jpayne@69 206 #define Py_BEGIN_ALLOW_THREADS { \
jpayne@69 207 PyThreadState *_save; \
jpayne@69 208 _save = PyEval_SaveThread();
jpayne@69 209 #define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
jpayne@69 210 #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
jpayne@69 211 #define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
jpayne@69 212 }
jpayne@69 213
jpayne@69 214 #ifndef Py_LIMITED_API
jpayne@69 215 PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
jpayne@69 216 PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *);
jpayne@69 217 #endif
jpayne@69 218
jpayne@69 219 /* Masks and values used by FORMAT_VALUE opcode. */
jpayne@69 220 #define FVC_MASK 0x3
jpayne@69 221 #define FVC_NONE 0x0
jpayne@69 222 #define FVC_STR 0x1
jpayne@69 223 #define FVC_REPR 0x2
jpayne@69 224 #define FVC_ASCII 0x3
jpayne@69 225 #define FVS_MASK 0x4
jpayne@69 226 #define FVS_HAVE_SPEC 0x4
jpayne@69 227
jpayne@69 228 #ifdef __cplusplus
jpayne@69 229 }
jpayne@69 230 #endif
jpayne@69 231 #endif /* !Py_CEVAL_H */