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