blob: 70abbb4c28a7b16c8a801d8b917b69611cea20d6 [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 Rossum5799b521995-01-04 19:06:22 +00008Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The 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 Rossumcaa63801995-01-12 11:45:45 +000033PyObject *PyEval_CallObject Py_PROTO((PyObject *, PyObject *));
Guido van Rossum884afd61995-07-18 14:21:06 +000034PyObject *PyEval_CallObjectWithKeywords
35 Py_PROTO((PyObject *, PyObject *, PyObject *));
Guido van Rossuma0490311991-07-27 21:33:03 +000036
Guido van Rossumcaa63801995-01-12 11:45:45 +000037PyObject *PyEval_GetBuiltins Py_PROTO((void));
38PyObject *PyEval_GetGlobals Py_PROTO((void));
39PyObject *PyEval_GetLocals Py_PROTO((void));
40PyObject *PyEval_GetOwner Py_PROTO((void));
41PyObject *PyEval_GetFrame Py_PROTO((void));
42int PyEval_GetRestricted Py_PROTO((void));
Guido van Rossum3f5da241990-12-20 15:06:42 +000043
Guido van Rossumcaa63801995-01-12 11:45:45 +000044void Py_FlushLine Py_PROTO((void));
Guido van Rossumff4949e1992-08-05 19:58:53 +000045
Guido van Rossumcaa63801995-01-12 11:45:45 +000046int Py_AddPendingCall Py_PROTO((int (*func) Py_PROTO((ANY *)), ANY *arg));
47int Py_MakePendingCalls Py_PROTO((void));
Guido van Rossum95664081994-09-14 13:23:36 +000048
Guido van Rossumff4949e1992-08-05 19:58:53 +000049
50/* Interface for threads.
51
52 A module that plans to do a blocking system call (or something else
53 that lasts a long time and doesn't touch Python data) can allow other
54 threads to run as follows:
55
56 ...preparations here...
Guido van Rossumcaa63801995-01-12 11:45:45 +000057 Py_BEGIN_ALLOW_THREADS
Guido van Rossumff4949e1992-08-05 19:58:53 +000058 ...blocking system call here...
Guido van Rossumcaa63801995-01-12 11:45:45 +000059 Py_END_ALLOW_THREADS
Guido van Rossum66cb3111994-12-30 15:33:50 +000060 ...interpret result here...
Guido van Rossumff4949e1992-08-05 19:58:53 +000061
Guido van Rossumcaa63801995-01-12 11:45:45 +000062 The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
63 {}-surrounded block.
Guido van Rossumff4949e1992-08-05 19:58:53 +000064 To leave the block in the middle (e.g., with return), you must insert
65 a line containing RET_SAVE before the return, e.g.
66
67 if (...premature_exit...) {
Guido van Rossumcaa63801995-01-12 11:45:45 +000068 Py_BLOCK_THREADS
69 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossumff4949e1992-08-05 19:58:53 +000070 return NULL;
71 }
72
73 An alternative is:
74
Guido van Rossumcaa63801995-01-12 11:45:45 +000075 Py_BLOCK_THREADS
Guido van Rossumff4949e1992-08-05 19:58:53 +000076 if (...premature_exit...) {
Guido van Rossumcaa63801995-01-12 11:45:45 +000077 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossumff4949e1992-08-05 19:58:53 +000078 return NULL;
79 }
Guido van Rossumcaa63801995-01-12 11:45:45 +000080 Py_UNBLOCK_THREADS
Guido van Rossumff4949e1992-08-05 19:58:53 +000081
82 For convenience, that the value of 'errno' is restored across
Guido van Rossumcaa63801995-01-12 11:45:45 +000083 Py_END_ALLOW_THREADS and RET_SAVE.
Guido van Rossumff4949e1992-08-05 19:58:53 +000084
Guido van Rossumcaa63801995-01-12 11:45:45 +000085 WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
86 Py_END_ALLOW_THREADS!!!
Guido van Rossumff4949e1992-08-05 19:58:53 +000087
Guido van Rossumcaa63801995-01-12 11:45:45 +000088 The function PyEval_InitThreads() should be called only from
Guido van Rossumff4949e1992-08-05 19:58:53 +000089 initthread() in "threadmodule.c".
90
91 Note that not yet all candidates have been converted to use this
92 mechanism!
93*/
94
Guido van Rossumcaa63801995-01-12 11:45:45 +000095extern void PyEval_InitThreads Py_PROTO((void));
96extern PyObject *PyEval_SaveThread Py_PROTO((void));
97extern void PyEval_RestoreThread Py_PROTO((PyObject *));
Guido van Rossumff4949e1992-08-05 19:58:53 +000098
Guido van Rossumb6775db1994-08-01 11:34:53 +000099#ifdef WITH_THREAD
Guido van Rossumff4949e1992-08-05 19:58:53 +0000100
Guido van Rossumcaa63801995-01-12 11:45:45 +0000101#define Py_BEGIN_ALLOW_THREADS { \
102 PyObject *_save; \
103 _save = PyEval_SaveThread();
104#define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
105#define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
106#define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
Guido van Rossumff4949e1992-08-05 19:58:53 +0000107 }
108
Guido van Rossumb6775db1994-08-01 11:34:53 +0000109#else /* !WITH_THREAD */
Guido van Rossumff4949e1992-08-05 19:58:53 +0000110
Guido van Rossumcaa63801995-01-12 11:45:45 +0000111#define Py_BEGIN_ALLOW_THREADS {
112#define Py_BLOCK_THREADS
113#define Py_UNBLOCK_THREADS
114#define Py_END_ALLOW_THREADS }
Guido van Rossumff4949e1992-08-05 19:58:53 +0000115
Guido van Rossumb6775db1994-08-01 11:34:53 +0000116#endif /* !WITH_THREAD */
Guido van Rossuma3309961993-07-28 09:05:47 +0000117
118#ifdef __cplusplus
119}
120#endif
121#endif /* !Py_CEVAL_H */