blob: 8de2fc04ce1ca44adf9d170bd07917f11a9a19be [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_CEVAL_H
2#define Py_CEVAL_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007/***********************************************************
Guido van Rossumb6775db1994-08-01 11:34:53 +00008Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Guido van Rossum9bfef441993-03-29 10:43:31 +00009Amsterdam, The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000010
11 All Rights Reserved
12
13Permission to use, copy, modify, and distribute this software and its
14documentation for any purpose and without fee is hereby granted,
15provided that the above copyright notice appear in all copies and that
16both that copyright notice and this permission notice appear in
17supporting documentation, and that the names of Stichting Mathematisch
18Centrum or CWI not be used in advertising or publicity pertaining to
19distribution of the software without specific, written prior permission.
20
21STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
22THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
23FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
24FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
27OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
29******************************************************************/
30
Guido van Rossumff4949e1992-08-05 19:58:53 +000031/* Interface to random parts in ceval.c */
Guido van Rossum3f5da241990-12-20 15:06:42 +000032
Guido van Rossuma0490311991-07-27 21:33:03 +000033object *call_object PROTO((object *, object *));
34
Guido van Rossum3f5da241990-12-20 15:06:42 +000035object *getglobals PROTO((void));
36object *getlocals PROTO((void));
Guido van Rossumeb6b33a1993-05-25 09:38:27 +000037object *getowner PROTO((void));
Guido van Rossumb6775db1994-08-01 11:34:53 +000038object *getframe PROTO((void));
Guido van Rossum3f5da241990-12-20 15:06:42 +000039
Guido van Rossum704a26c1992-03-27 17:29:31 +000040void flushline PROTO((void));
Guido van Rossumff4949e1992-08-05 19:58:53 +000041
Guido van Rossum95664081994-09-14 13:23:36 +000042int Py_AddPendingCall PROTO((int (*func) PROTO((ANY *)), ANY *arg));
Guido van Rossumc5d92e11994-09-28 15:44:39 +000043int Py_MakePendingCalls PROTO((void));
Guido van Rossum95664081994-09-14 13:23:36 +000044
Guido van Rossumff4949e1992-08-05 19:58:53 +000045
46/* Interface for threads.
47
48 A module that plans to do a blocking system call (or something else
49 that lasts a long time and doesn't touch Python data) can allow other
50 threads to run as follows:
51
52 ...preparations here...
53 BGN_SAVE
54 ...blocking system call here...
55 END_SAVE
Guido van Rossum66cb3111994-12-30 15:33:50 +000056 ...interpret result here...
Guido van Rossumff4949e1992-08-05 19:58:53 +000057
58 The BGN_SAVE/END_SAVE pair expands to a {}-surrounded block.
59 To leave the block in the middle (e.g., with return), you must insert
60 a line containing RET_SAVE before the return, e.g.
61
62 if (...premature_exit...) {
63 RET_SAVE
64 err_errno(IOError);
65 return NULL;
66 }
67
68 An alternative is:
69
70 RET_SAVE
71 if (...premature_exit...) {
72 err_errno(IOError);
73 return NULL;
74 }
75 RES_SAVE
76
77 For convenience, that the value of 'errno' is restored across
78 END_SAVE and RET_SAVE.
79
80 WARNING: NEVER NEST CALLS TO BGN_SAVE AND END_SAVE!!!
81
82 The function init_save_thread() should be called only from
83 initthread() in "threadmodule.c".
84
85 Note that not yet all candidates have been converted to use this
86 mechanism!
87*/
88
89extern void init_save_thread PROTO((void));
Guido van Rossum04691fc1992-08-12 15:35:34 +000090extern object *save_thread PROTO((void));
91extern void restore_thread PROTO((object *));
Guido van Rossumff4949e1992-08-05 19:58:53 +000092
Guido van Rossumb6775db1994-08-01 11:34:53 +000093#ifdef WITH_THREAD
Guido van Rossumff4949e1992-08-05 19:58:53 +000094
95#define BGN_SAVE { \
Guido van Rossum04691fc1992-08-12 15:35:34 +000096 object *_save; \
Guido van Rossumff4949e1992-08-05 19:58:53 +000097 _save = save_thread();
98#define RET_SAVE restore_thread(_save);
99#define RES_SAVE _save = save_thread();
100#define END_SAVE restore_thread(_save); \
101 }
102
Guido van Rossumb6775db1994-08-01 11:34:53 +0000103#else /* !WITH_THREAD */
Guido van Rossumff4949e1992-08-05 19:58:53 +0000104
105#define BGN_SAVE {
106#define RET_SAVE
107#define RES_SAVE
108#define END_SAVE }
109
Guido van Rossumb6775db1994-08-01 11:34:53 +0000110#endif /* !WITH_THREAD */
Guido van Rossuma3309961993-07-28 09:05:47 +0000111
112#ifdef __cplusplus
113}
114#endif
115#endif /* !Py_CEVAL_H */