| 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 | PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
|
|---|
| 11 | PyObject *, PyObject *, PyObject *);
|
|---|
| 12 |
|
|---|
| 13 | /* Inline this */
|
|---|
| 14 | #define PyEval_CallObject(func,arg) \
|
|---|
| 15 | PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
|
|---|
| 16 |
|
|---|
| 17 | PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj,
|
|---|
| 18 | const char *format, ...);
|
|---|
| 19 | PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,
|
|---|
| 20 | const char *methodname,
|
|---|
| 21 | const char *format, ...);
|
|---|
| 22 |
|
|---|
| 23 | PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
|
|---|
| 24 | PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
|
|---|
| 25 |
|
|---|
| 26 | struct _frame; /* Avoid including frameobject.h */
|
|---|
| 27 |
|
|---|
| 28 | PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
|
|---|
| 29 | PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
|
|---|
| 30 | PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
|
|---|
| 31 | PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void);
|
|---|
| 32 | PyAPI_FUNC(int) PyEval_GetRestricted(void);
|
|---|
| 33 |
|
|---|
| 34 | /* Look at the current frame's (if any) code's co_flags, and turn on
|
|---|
| 35 | the corresponding compiler flags in cf->cf_flags. Return 1 if any
|
|---|
| 36 | flag was set, else return 0. */
|
|---|
| 37 | PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
|
|---|
| 38 |
|
|---|
| 39 | PyAPI_FUNC(int) Py_FlushLine(void);
|
|---|
| 40 |
|
|---|
| 41 | PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
|
|---|
| 42 | PyAPI_FUNC(int) Py_MakePendingCalls(void);
|
|---|
| 43 |
|
|---|
| 44 | /* Protection against deeply nested recursive calls */
|
|---|
| 45 | PyAPI_FUNC(void) Py_SetRecursionLimit(int);
|
|---|
| 46 | PyAPI_FUNC(int) Py_GetRecursionLimit(void);
|
|---|
| 47 |
|
|---|
| 48 | #define Py_EnterRecursiveCall(where) \
|
|---|
| 49 | (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
|
|---|
| 50 | _Py_CheckRecursiveCall(where))
|
|---|
| 51 | #define Py_LeaveRecursiveCall() \
|
|---|
| 52 | (--PyThreadState_GET()->recursion_depth)
|
|---|
| 53 | PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);
|
|---|
| 54 | PyAPI_DATA(int) _Py_CheckRecursionLimit;
|
|---|
| 55 | #ifdef USE_STACKCHECK
|
|---|
| 56 | # define _Py_MakeRecCheck(x) (++(x) > --_Py_CheckRecursionLimit)
|
|---|
| 57 | #else
|
|---|
| 58 | # define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
|
|---|
| 62 | PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
|
|---|
| 63 |
|
|---|
| 64 | PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
|
|---|
| 65 | PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
|
|---|
| 66 | PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
|
|---|
| 67 |
|
|---|
| 68 | /* this used to be handled on a per-thread basis - now just two globals */
|
|---|
| 69 | PyAPI_DATA(volatile int) _Py_Ticker;
|
|---|
| 70 | PyAPI_DATA(int) _Py_CheckInterval;
|
|---|
| 71 |
|
|---|
| 72 | /* Interface for threads.
|
|---|
| 73 |
|
|---|
| 74 | A module that plans to do a blocking system call (or something else
|
|---|
| 75 | that lasts a long time and doesn't touch Python data) can allow other
|
|---|
| 76 | threads to run as follows:
|
|---|
| 77 |
|
|---|
| 78 | ...preparations here...
|
|---|
| 79 | Py_BEGIN_ALLOW_THREADS
|
|---|
| 80 | ...blocking system call here...
|
|---|
| 81 | Py_END_ALLOW_THREADS
|
|---|
| 82 | ...interpret result here...
|
|---|
| 83 |
|
|---|
| 84 | The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
|
|---|
| 85 | {}-surrounded block.
|
|---|
| 86 | To leave the block in the middle (e.g., with return), you must insert
|
|---|
| 87 | a line containing Py_BLOCK_THREADS before the return, e.g.
|
|---|
| 88 |
|
|---|
| 89 | if (...premature_exit...) {
|
|---|
| 90 | Py_BLOCK_THREADS
|
|---|
| 91 | PyErr_SetFromErrno(PyExc_IOError);
|
|---|
| 92 | return NULL;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | An alternative is:
|
|---|
| 96 |
|
|---|
| 97 | Py_BLOCK_THREADS
|
|---|
| 98 | if (...premature_exit...) {
|
|---|
| 99 | PyErr_SetFromErrno(PyExc_IOError);
|
|---|
| 100 | return NULL;
|
|---|
| 101 | }
|
|---|
| 102 | Py_UNBLOCK_THREADS
|
|---|
| 103 |
|
|---|
| 104 | For convenience, that the value of 'errno' is restored across
|
|---|
| 105 | Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
|
|---|
| 106 |
|
|---|
| 107 | WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
|
|---|
| 108 | Py_END_ALLOW_THREADS!!!
|
|---|
| 109 |
|
|---|
| 110 | The function PyEval_InitThreads() should be called only from
|
|---|
| 111 | initthread() in "threadmodule.c".
|
|---|
| 112 |
|
|---|
| 113 | Note that not yet all candidates have been converted to use this
|
|---|
| 114 | mechanism!
|
|---|
| 115 | */
|
|---|
| 116 |
|
|---|
| 117 | PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
|
|---|
| 118 | PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
|
|---|
| 119 |
|
|---|
| 120 | #ifdef WITH_THREAD
|
|---|
| 121 |
|
|---|
| 122 | PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
|
|---|
| 123 | PyAPI_FUNC(void) PyEval_InitThreads(void);
|
|---|
| 124 | PyAPI_FUNC(void) PyEval_AcquireLock(void);
|
|---|
| 125 | PyAPI_FUNC(void) PyEval_ReleaseLock(void);
|
|---|
| 126 | PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
|
|---|
| 127 | PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
|
|---|
| 128 | PyAPI_FUNC(void) PyEval_ReInitThreads(void);
|
|---|
| 129 |
|
|---|
| 130 | #define Py_BEGIN_ALLOW_THREADS { \
|
|---|
| 131 | PyThreadState *_save; \
|
|---|
| 132 | _save = PyEval_SaveThread();
|
|---|
| 133 | #define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
|
|---|
| 134 | #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
|
|---|
| 135 | #define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | #else /* !WITH_THREAD */
|
|---|
| 139 |
|
|---|
| 140 | #define Py_BEGIN_ALLOW_THREADS {
|
|---|
| 141 | #define Py_BLOCK_THREADS
|
|---|
| 142 | #define Py_UNBLOCK_THREADS
|
|---|
| 143 | #define Py_END_ALLOW_THREADS }
|
|---|
| 144 |
|
|---|
| 145 | #endif /* !WITH_THREAD */
|
|---|
| 146 |
|
|---|
| 147 | PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | #ifdef __cplusplus
|
|---|
| 151 | }
|
|---|
| 152 | #endif
|
|---|
| 153 | #endif /* !Py_CEVAL_H */
|
|---|