Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_CEVAL_H |
| 2 | #define Py_CEVAL_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 8 | /* Interface to random parts in ceval.c */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 9 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 10 | PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords( |
| 11 | PyObject *, PyObject *, PyObject *); |
Guido van Rossum | a049031 | 1991-07-27 21:33:03 +0000 | [diff] [blame] | 12 | |
Guido van Rossum | 8368453 | 1999-03-17 18:44:39 +0000 | [diff] [blame] | 13 | /* DLL-level Backwards compatibility: */ |
| 14 | #undef PyEval_CallObject |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 15 | PyAPI_FUNC(PyObject *) PyEval_CallObject(PyObject *, PyObject *); |
Guido van Rossum | 8368453 | 1999-03-17 18:44:39 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d7ed683 | 1997-08-30 15:02:50 +0000 | [diff] [blame] | 17 | /* Inline this */ |
| 18 | #define PyEval_CallObject(func,arg) \ |
| 19 | PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL) |
| 20 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 21 | PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj, char *format, ...); |
| 22 | PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj, |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 23 | char *methodname, char *format, ...); |
Guido van Rossum | 3d109a0 | 1998-08-08 20:53:36 +0000 | [diff] [blame] | 24 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 25 | PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *); |
| 26 | PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *); |
Fred Drake | 55fb6e0 | 2001-06-27 19:18:03 +0000 | [diff] [blame] | 27 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 28 | PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void); |
| 29 | PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void); |
| 30 | PyAPI_FUNC(PyObject *) PyEval_GetLocals(void); |
| 31 | PyAPI_FUNC(PyObject *) PyEval_GetOwner(void); |
| 32 | PyAPI_FUNC(PyObject *) PyEval_GetFrame(void); |
| 33 | PyAPI_FUNC(int) PyEval_GetRestricted(void); |
Tim Peters | 5ba5866 | 2001-07-16 02:29:45 +0000 | [diff] [blame] | 34 | |
| 35 | /* Look at the current frame's (if any) code's co_flags, and turn on |
| 36 | the corresponding compiler flags in cf->cf_flags. Return 1 if any |
| 37 | flag was set, else return 0. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 38 | PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 39 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 40 | PyAPI_FUNC(int) Py_FlushLine(void); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 41 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 42 | PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg); |
| 43 | PyAPI_FUNC(int) Py_MakePendingCalls(void); |
Guido van Rossum | 9566408 | 1994-09-14 13:23:36 +0000 | [diff] [blame] | 44 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 45 | PyAPI_FUNC(void) Py_SetRecursionLimit(int); |
| 46 | PyAPI_FUNC(int) Py_GetRecursionLimit(void); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 47 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 48 | PyAPI_FUNC(char *) PyEval_GetFuncName(PyObject *); |
| 49 | PyAPI_FUNC(char *) PyEval_GetFuncDesc(PyObject *); |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 50 | |
Skip Montanaro | d581d77 | 2002-09-03 20:10:45 +0000 | [diff] [blame] | 51 | /* this used to be handled on a per-thread basis - now just two globals */ |
| 52 | PyAPI_DATA(volatile int) _Py_Ticker; |
| 53 | PyAPI_DATA(int) _Py_CheckInterval; |
| 54 | |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 55 | /* Interface for threads. |
| 56 | |
| 57 | A module that plans to do a blocking system call (or something else |
| 58 | that lasts a long time and doesn't touch Python data) can allow other |
| 59 | threads to run as follows: |
| 60 | |
| 61 | ...preparations here... |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 62 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 63 | ...blocking system call here... |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 64 | Py_END_ALLOW_THREADS |
Guido van Rossum | 66cb311 | 1994-12-30 15:33:50 +0000 | [diff] [blame] | 65 | ...interpret result here... |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 66 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 67 | The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a |
| 68 | {}-surrounded block. |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 69 | To leave the block in the middle (e.g., with return), you must insert |
Skip Montanaro | 682c25a | 2000-09-15 18:19:27 +0000 | [diff] [blame] | 70 | a line containing Py_BLOCK_THREADS before the return, e.g. |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 71 | |
| 72 | if (...premature_exit...) { |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 73 | Py_BLOCK_THREADS |
| 74 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 75 | return NULL; |
| 76 | } |
| 77 | |
| 78 | An alternative is: |
| 79 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 80 | Py_BLOCK_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 81 | if (...premature_exit...) { |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 82 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 83 | return NULL; |
| 84 | } |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 85 | Py_UNBLOCK_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 86 | |
| 87 | For convenience, that the value of 'errno' is restored across |
Skip Montanaro | 682c25a | 2000-09-15 18:19:27 +0000 | [diff] [blame] | 88 | Py_END_ALLOW_THREADS and Py_BLOCK_THREADS. |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 89 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 90 | WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND |
| 91 | Py_END_ALLOW_THREADS!!! |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 92 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 93 | The function PyEval_InitThreads() should be called only from |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 94 | initthread() in "threadmodule.c". |
| 95 | |
| 96 | Note that not yet all candidates have been converted to use this |
| 97 | mechanism! |
| 98 | */ |
| 99 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 100 | PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void); |
| 101 | PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 102 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 103 | #ifdef WITH_THREAD |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 104 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 105 | PyAPI_FUNC(void) PyEval_InitThreads(void); |
| 106 | PyAPI_FUNC(void) PyEval_AcquireLock(void); |
| 107 | PyAPI_FUNC(void) PyEval_ReleaseLock(void); |
| 108 | PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); |
| 109 | PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); |
| 110 | PyAPI_FUNC(void) PyEval_ReInitThreads(void); |
Guido van Rossum | 2fca21f7 | 1997-07-18 23:56:58 +0000 | [diff] [blame] | 111 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 112 | #define Py_BEGIN_ALLOW_THREADS { \ |
Guido van Rossum | 2fca21f7 | 1997-07-18 23:56:58 +0000 | [diff] [blame] | 113 | PyThreadState *_save; \ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 114 | _save = PyEval_SaveThread(); |
| 115 | #define Py_BLOCK_THREADS PyEval_RestoreThread(_save); |
| 116 | #define Py_UNBLOCK_THREADS _save = PyEval_SaveThread(); |
| 117 | #define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \ |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 120 | #else /* !WITH_THREAD */ |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 121 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 122 | #define Py_BEGIN_ALLOW_THREADS { |
| 123 | #define Py_BLOCK_THREADS |
| 124 | #define Py_UNBLOCK_THREADS |
| 125 | #define Py_END_ALLOW_THREADS } |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 126 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 127 | #endif /* !WITH_THREAD */ |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 128 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 129 | PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, int *); |
Guido van Rossum | 7c36ada | 2000-05-08 14:04:54 +0000 | [diff] [blame] | 130 | |
| 131 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 132 | #ifdef __cplusplus |
| 133 | } |
| 134 | #endif |
| 135 | #endif /* !Py_CEVAL_H */ |