1 #ifndef Py_CEVAL_H 2 #define Py_CEVAL_H 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 7 8 /* Interface to random parts in ceval.c */ 9 10 /* PyEval_CallObjectWithKeywords(), PyEval_CallObject(), PyEval_CallFunction 11 * and PyEval_CallMethod are deprecated. Since they are officially part of the 12 * stable ABI (PEP 384), they must be kept for backward compatibility. 13 * PyObject_Call(), PyObject_CallFunction() and PyObject_CallMethod() are 14 * recommended to call a callable object. 15 */ 16 17 Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords( 18 PyObject *callable, 19 PyObject *args, 20 PyObject *kwargs); 21 22 /* Deprecated since PyEval_CallObjectWithKeywords is deprecated */ 23 #define PyEval_CallObject(callable, arg) \ 24 PyEval_CallObjectWithKeywords(callable, arg, (PyObject *)NULL) 25 26 Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallFunction( 27 PyObject *callable, const char *format, ...); 28 Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallMethod( 29 PyObject *obj, const char *name, const char *format, ...); 30 31 PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void); 32 PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void); 33 PyAPI_FUNC(PyObject *) PyEval_GetLocals(void); 34 PyAPI_FUNC(PyFrameObject *) PyEval_GetFrame(void); 35 36 PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg); 37 PyAPI_FUNC(int) Py_MakePendingCalls(void); 38 39 /* Protection against deeply nested recursive calls 40 41 In Python 3.0, this protection has two levels: 42 * normal anti-recursion protection is triggered when the recursion level 43 exceeds the current recursion limit. It raises a RecursionError, and sets 44 the "overflowed" flag in the thread state structure. This flag 45 temporarily *disables* the normal protection; this allows cleanup code 46 to potentially outgrow the recursion limit while processing the 47 RecursionError. 48 * "last chance" anti-recursion protection is triggered when the recursion 49 level exceeds "current recursion limit + 50". By construction, this 50 protection can only be triggered when the "overflowed" flag is set. It 51 means the cleanup code has itself gone into an infinite loop, or the 52 RecursionError has been mistakingly ignored. When this protection is 53 triggered, the interpreter aborts with a Fatal Error. 54 55 In addition, the "overflowed" flag is automatically reset when the 56 recursion level drops below "current recursion limit - 50". This heuristic 57 is meant to ensure that the normal anti-recursion protection doesn't get 58 disabled too long. 59 60 Please note: this scheme has its own limitations. See: 61 http://mail.python.org/pipermail/python-dev/2008-August/082106.html 62 for some observations. 63 */ 64 PyAPI_FUNC(void) Py_SetRecursionLimit(int); 65 PyAPI_FUNC(int) Py_GetRecursionLimit(void); 66 67 PyAPI_FUNC(int) Py_EnterRecursiveCall(const char *where); 68 PyAPI_FUNC(void) Py_LeaveRecursiveCall(void); 69 70 #define Py_ALLOW_RECURSION \ 71 do { unsigned char _old = PyThreadState_GET()->recursion_critical;\ 72 PyThreadState_GET()->recursion_critical = 1; 73 74 #define Py_END_ALLOW_RECURSION \ 75 PyThreadState_GET()->recursion_critical = _old; \ 76 } while(0); 77 78 PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *); 79 PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *); 80 81 PyAPI_FUNC(PyObject *) PyEval_EvalFrame(PyFrameObject *); 82 PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc); 83 84 /* Interface for threads. 85 86 A module that plans to do a blocking system call (or something else 87 that lasts a long time and doesn't touch Python data) can allow other 88 threads to run as follows: 89 90 ...preparations here... 91 Py_BEGIN_ALLOW_THREADS 92 ...blocking system call here... 93 Py_END_ALLOW_THREADS 94 ...interpret result here... 95 96 The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a 97 {}-surrounded block. 98 To leave the block in the middle (e.g., with return), you must insert 99 a line containing Py_BLOCK_THREADS before the return, e.g. 100 101 if (...premature_exit...) { 102 Py_BLOCK_THREADS 103 PyErr_SetFromErrno(PyExc_OSError); 104 return NULL; 105 } 106 107 An alternative is: 108 109 Py_BLOCK_THREADS 110 if (...premature_exit...) { 111 PyErr_SetFromErrno(PyExc_OSError); 112 return NULL; 113 } 114 Py_UNBLOCK_THREADS 115 116 For convenience, that the value of 'errno' is restored across 117 Py_END_ALLOW_THREADS and Py_BLOCK_THREADS. 118 119 WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND 120 Py_END_ALLOW_THREADS!!! 121 122 Note that not yet all candidates have been converted to use this 123 mechanism! 124 */ 125 126 PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void); 127 PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *); 128 129 Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void); 130 Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void); 131 /* PyEval_AcquireLock() and PyEval_ReleaseLock() are part of stable ABI. 132 * They will be removed from this header file in the future version. 133 * But they will be remained in ABI until Python 4.0. 134 */ 135 Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void); 136 Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_ReleaseLock(void); 137 PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); 138 PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); 139 140 #define Py_BEGIN_ALLOW_THREADS { \ 141 PyThreadState *_save; \ 142 _save = PyEval_SaveThread(); 143 #define Py_BLOCK_THREADS PyEval_RestoreThread(_save); 144 #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread(); 145 #define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \ 146 } 147 148 /* Masks and values used by FORMAT_VALUE opcode. */ 149 #define FVC_MASK 0x3 150 #define FVC_NONE 0x0 151 #define FVC_STR 0x1 152 #define FVC_REPR 0x2 153 #define FVC_ASCII 0x3 154 #define FVS_MASK 0x4 155 #define FVS_HAVE_SPEC 0x4 156 157 #ifndef Py_LIMITED_API 158 # define Py_CPYTHON_CEVAL_H 159 # include "cpython/ceval.h" 160 # undef Py_CPYTHON_CEVAL_H 161 #endif 162 163 #ifdef __cplusplus 164 } 165 #endif 166 #endif /* !Py_CEVAL_H */ 167