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