1 /** 2 Mirror _ceval.h 3 */ 4 module deimos.python.ceval; 5 6 import deimos.python.pyport; 7 import deimos.python.object; 8 import deimos.python.frameobject; 9 import deimos.python.pystate; 10 import deimos.python.pythonrun; 11 12 extern(C): 13 // Python-header-file: Include/ceval.h: 14 15 /// _ 16 PyObject* PyEval_CallObjectWithKeywords(PyObject* , PyObject* , PyObject* ); 17 version(Python_2_5_Or_Later){ 18 /// _ 19 PyObject* PyEval_CallObject()(PyObject* func, PyObject* arg) { 20 return PyEval_CallObjectWithKeywords(func, arg, null); 21 } 22 }else{ 23 /// _ 24 PyObject* PyEval_CallObject(PyObject* , PyObject* ); 25 } 26 /// _ 27 PyObject* PyEval_CallFunction(PyObject* obj, const(char)* format, ...); 28 /// _ 29 PyObject* PyEval_CallMethod( 30 PyObject* obj, 31 const(char)* methodname, 32 const(char)* format, ...); 33 34 /// _ 35 void PyEval_SetProfile(Py_tracefunc, PyObject*); 36 /// _ 37 void PyEval_SetTrace(Py_tracefunc, PyObject*); 38 /// _ 39 Borrowed!PyObject* PyEval_GetBuiltins(); 40 /// _ 41 Borrowed!PyObject* PyEval_GetGlobals(); 42 /// _ 43 Borrowed!PyObject* PyEval_GetLocals(); 44 /// _ 45 Borrowed!PyFrameObject* PyEval_GetFrame(); 46 version(Python_3_0_Or_Later) { 47 }else { 48 /// Availability: 2.* 49 int PyEval_GetRestricted(); 50 /// Availability: 2.* 51 int Py_FlushLine(); 52 } 53 54 /** Look at the current frame's (if any) code's co_flags, and turn on 55 the corresponding compiler flags in cf->cf_flags. Return 1 if any 56 flag was set, else return 0. */ 57 int PyEval_MergeCompilerFlags(PyCompilerFlags* cf); 58 /// _ 59 int Py_AddPendingCall(int function(void*) func, void* arg); 60 /// _ 61 int Py_MakePendingCalls(); 62 /// _ 63 void Py_SetRecursionLimit(int); 64 /// _ 65 int Py_GetRecursionLimit(); 66 67 // d translation of c macro: 68 /// _ 69 int Py_EnterRecursiveCall()(char* where) { 70 return _Py_MakeRecCheck(PyThreadState_GET().recursion_depth) && 71 _Py_CheckRecursiveCall(where); 72 } 73 /// _ 74 void Py_LeaveRecursiveCall()() { 75 version(Python_3_0_Or_Later) { 76 if(_Py_MakeEndRecCheck(PyThreadState_GET().recursion_depth)) 77 PyThreadState_GET().overflowed = 0; 78 }else { 79 --PyThreadState_GET().recursion_depth; 80 } 81 } 82 /// _ 83 int _Py_CheckRecursiveCall(char* where); 84 /// _ 85 mixin(PyAPI_DATA!"int _Py_CheckRecursionLimit"); 86 87 // TODO: version(STACKCHECK) 88 /// _ 89 int _Py_MakeRecCheck()(int x) { 90 return (++(x) > _Py_CheckRecursionLimit); 91 } 92 93 version(Python_3_0_Or_Later) { 94 // d translation of c macro: 95 /// Availability: 3.* 96 auto _Py_MakeEndRecCheck()(x) { 97 return (--(x) < ((_Py_CheckRecursionLimit > 100) 98 ? (_Py_CheckRecursionLimit - 50) 99 : (3 * (_Py_CheckRecursionLimit >> 2)))); 100 } 101 /* 102 auto Py_ALLOW_RECURSION()() { 103 do{ 104 ubyte _old = PyThreadState_GET()->recursion_critical; 105 PyThreadState_GET()->recursion_critical = 1; 106 } 107 108 auto Py_END_ALLOW_RECURSION()() { 109 PyThreadState_GET()->recursion_critical = _old; 110 }while(0); 111 } 112 */ 113 114 /** 115 D's answer to C's 116 --- 117 Py_ALLOW_RECURSION 118 ..code.. 119 Py_END_ALLOW_RECURSION 120 --- 121 122 is 123 --- 124 mixin(Py_ALLOW_RECURSION(q{ 125 ..code.. 126 })); 127 --- 128 */ 129 string Py_ALLOW_RECURSION()(string inner_code) { 130 import std.array; 131 return replace(q{ 132 { 133 ubyte _old = PyThreadState_GET().recursion_critical; 134 PyThreadState_GET().recursion_critical = 1; 135 $inner_code; 136 PyThreadState_GET().recursion_critical = _old; 137 } 138 }, "$inner_code", inner_code); 139 } 140 } 141 142 /// _ 143 const(char)* PyEval_GetFuncName(PyObject*); 144 /// _ 145 const(char)* PyEval_GetFuncDesc(PyObject*); 146 /// _ 147 PyObject* PyEval_GetCallStats(PyObject*); 148 /// _ 149 PyObject* PyEval_EvalFrame(PyFrameObject*); 150 version(Python_2_5_Or_Later){ 151 /// Availability: >= 2.5 152 PyObject* PyEval_EvalFrameEx(PyFrameObject*, int); 153 } 154 155 version(Python_3_0_Or_Later) { 156 }else{ 157 /// _ 158 mixin(PyAPI_DATA!"/*volatile*/ int _Py_Ticker"); 159 /// _ 160 mixin(PyAPI_DATA!"int _Py_CheckInterval"); 161 } 162 163 /// _ 164 PyThreadState* PyEval_SaveThread(); 165 /// _ 166 void PyEval_RestoreThread(PyThreadState*); 167 168 // version(WITH_THREAD) assumed? 169 /// _ 170 int PyEval_ThreadsInitialized(); 171 /// _ 172 void PyEval_InitThreads(); 173 version(Python_3_0_Or_Later) { 174 /// Availability: 3.* 175 void _PyEval_FiniThreads(); 176 } 177 /// _ 178 void PyEval_AcquireLock(); 179 /// _ 180 void PyEval_ReleaseLock(); 181 /// _ 182 void PyEval_AcquireThread(PyThreadState* tstate); 183 /// _ 184 void PyEval_ReleaseThread(PyThreadState* tstate); 185 /// _ 186 void PyEval_ReInitThreads(); 187 188 version(Python_3_0_Or_Later) { 189 /// Availability: 3.* 190 void _PyEval_SetSwitchInterval(C_ulong microseconds); 191 /// Availability: 3.* 192 C_ulong _PyEval_GetSwitchInterval(); 193 } 194 195 /* ?? 196 #define Py_BLOCK_THREADS PyEval_RestoreThread(_save); 197 #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread(); 198 */ 199 200 /** 201 D's answer to C's 202 --- 203 Py_BEGIN_ALLOW_THREADS 204 ..code.. 205 Py_END_ALLOW_THREADS 206 --- 207 is 208 --- 209 mixin(Py_ALLOW_THREADS(q{ 210 ..code.. 211 })); 212 --- 213 */ 214 string Py_ALLOW_THREADS()(string inner_code) { 215 import std.array; 216 return replace(q{ 217 { 218 PyThreadState* _save = PyEval_SaveThread(); 219 $inner_code; 220 PyEval_RestoreThread(_save); 221 } 222 }, "$inner_code", inner_code); 223 } 224 225 ///_ 226 int _PyEval_SliceIndex(PyObject*, Py_ssize_t*); 227 version(Python_3_0_Or_Later) { 228 /// Availability: 3.* 229 void _PyEval_SignalAsyncExc(); 230 }