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 | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 8 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 9 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 10 | |
| 11 | All Rights Reserved |
| 12 | |
| 13 | Permission to use, copy, modify, and distribute this software and its |
| 14 | documentation for any purpose and without fee is hereby granted, |
| 15 | provided that the above copyright notice appear in all copies and that |
| 16 | both that copyright notice and this permission notice appear in |
| 17 | supporting documentation, and that the names of Stichting Mathematisch |
| 18 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 19 | distribution of the software without specific, written prior permission. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 22 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 23 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 24 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 25 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 26 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 27 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 28 | |
| 29 | ******************************************************************/ |
| 30 | |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 31 | /* Interface to random parts in ceval.c */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 32 | |
Guido van Rossum | a049031 | 1991-07-27 21:33:03 +0000 | [diff] [blame] | 33 | object *call_object PROTO((object *, object *)); |
| 34 | |
Guido van Rossum | 6135a87 | 1995-01-09 17:53:26 +0000 | [diff] [blame] | 35 | object *getbuiltins PROTO((void)); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 36 | object *getglobals PROTO((void)); |
| 37 | object *getlocals PROTO((void)); |
Guido van Rossum | eb6b33a | 1993-05-25 09:38:27 +0000 | [diff] [blame] | 38 | object *getowner PROTO((void)); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 39 | object *getframe PROTO((void)); |
Guido van Rossum | 6135a87 | 1995-01-09 17:53:26 +0000 | [diff] [blame] | 40 | int getrestricted PROTO((void)); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 41 | |
Guido van Rossum | 704a26c | 1992-03-27 17:29:31 +0000 | [diff] [blame] | 42 | void flushline PROTO((void)); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 43 | |
Guido van Rossum | 9566408 | 1994-09-14 13:23:36 +0000 | [diff] [blame] | 44 | int Py_AddPendingCall PROTO((int (*func) PROTO((ANY *)), ANY *arg)); |
Guido van Rossum | c5d92e1 | 1994-09-28 15:44:39 +0000 | [diff] [blame] | 45 | int Py_MakePendingCalls PROTO((void)); |
Guido van Rossum | 9566408 | 1994-09-14 13:23:36 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 47 | |
| 48 | /* Interface for threads. |
| 49 | |
| 50 | A module that plans to do a blocking system call (or something else |
| 51 | that lasts a long time and doesn't touch Python data) can allow other |
| 52 | threads to run as follows: |
| 53 | |
| 54 | ...preparations here... |
| 55 | BGN_SAVE |
| 56 | ...blocking system call here... |
| 57 | END_SAVE |
Guido van Rossum | 66cb311 | 1994-12-30 15:33:50 +0000 | [diff] [blame] | 58 | ...interpret result here... |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 59 | |
| 60 | The BGN_SAVE/END_SAVE pair expands to a {}-surrounded block. |
| 61 | To leave the block in the middle (e.g., with return), you must insert |
| 62 | a line containing RET_SAVE before the return, e.g. |
| 63 | |
| 64 | if (...premature_exit...) { |
| 65 | RET_SAVE |
| 66 | err_errno(IOError); |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | An alternative is: |
| 71 | |
| 72 | RET_SAVE |
| 73 | if (...premature_exit...) { |
| 74 | err_errno(IOError); |
| 75 | return NULL; |
| 76 | } |
| 77 | RES_SAVE |
| 78 | |
| 79 | For convenience, that the value of 'errno' is restored across |
| 80 | END_SAVE and RET_SAVE. |
| 81 | |
| 82 | WARNING: NEVER NEST CALLS TO BGN_SAVE AND END_SAVE!!! |
| 83 | |
| 84 | The function init_save_thread() should be called only from |
| 85 | initthread() in "threadmodule.c". |
| 86 | |
| 87 | Note that not yet all candidates have been converted to use this |
| 88 | mechanism! |
| 89 | */ |
| 90 | |
| 91 | extern void init_save_thread PROTO((void)); |
Guido van Rossum | 04691fc | 1992-08-12 15:35:34 +0000 | [diff] [blame] | 92 | extern object *save_thread PROTO((void)); |
| 93 | extern void restore_thread PROTO((object *)); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 94 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 95 | #ifdef WITH_THREAD |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 96 | |
| 97 | #define BGN_SAVE { \ |
Guido van Rossum | 04691fc | 1992-08-12 15:35:34 +0000 | [diff] [blame] | 98 | object *_save; \ |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 99 | _save = save_thread(); |
| 100 | #define RET_SAVE restore_thread(_save); |
| 101 | #define RES_SAVE _save = save_thread(); |
| 102 | #define END_SAVE restore_thread(_save); \ |
| 103 | } |
| 104 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 105 | #else /* !WITH_THREAD */ |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 106 | |
| 107 | #define BGN_SAVE { |
| 108 | #define RET_SAVE |
| 109 | #define RES_SAVE |
| 110 | #define END_SAVE } |
| 111 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 112 | #endif /* !WITH_THREAD */ |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 113 | |
| 114 | #ifdef __cplusplus |
| 115 | } |
| 116 | #endif |
| 117 | #endif /* !Py_CEVAL_H */ |