blob: b660ff881b5863898872486ea5df7b821ce5b746 [file] [log] [blame]
Guido van Rossuma027efa1997-05-05 20:56:21 +00001#ifndef Py_PYSTATE_H
2#define Py_PYSTATE_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7/***********************************************************
8Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The Netherlands.
10
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 or Corporation for National Research Initiatives or
19CNRI not be used in advertising or publicity pertaining to
20distribution of the software without specific, written prior
21permission.
22
23While CWI is the initial source for this software, a modified version
24is made available by the Corporation for National Research Initiatives
25(CNRI) at the Internet address ftp://ftp.python.org.
26
27STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
28REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
29MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
30CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
31DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
32PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
33TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34PERFORMANCE OF THIS SOFTWARE.
35
36******************************************************************/
37
38/* Thread and interpreter state structures and their interfaces */
39
40
41/* State shared between threads */
42
43#define NEXITFUNCS 32
44
45typedef struct _is {
46
47 PyObject *import_modules;
48 PyObject *sysdict;
49
50 int nthreads;
51
52 void (*exitfuncs[NEXITFUNCS])();
53 int nexitfuncs;
54
55} PyInterpreterState;
56
57
58/* State unique per thread */
59
60struct _frame; /* Avoid including frameobject.h */
61
62typedef struct _ts {
63
64 PyInterpreterState *interpreter_state;
65
66 struct _frame *frame;
67 int recursion_depth;
68 int ticker;
69 int tracing;
70
71 PyObject *sys_profilefunc;
72 PyObject *sys_tracefunc;
73 int sys_checkinterval;
74
75 PyObject *curexc_type;
76 PyObject *curexc_value;
77 PyObject *curexc_traceback;
78
79 PyObject *exc_type;
80 PyObject *exc_value;
81 PyObject *exc_traceback;
82
83 /* XXX Other state that should be here:
84 - signal handlers
85 - low-level "pending calls"
86 Problem with both is that they may be referenced from
87 interrupt handlers where there is no clear concept of a
88 "current thread"???
89 */
90
91} PyThreadState;
92
93
Guido van Rossum59943ba1997-05-20 22:07:46 +000094PyInterpreterState *PyInterpreterState_New Py_PROTO((void));
95void PyInterpreterState_Delete Py_PROTO((PyInterpreterState *));
Guido van Rossuma027efa1997-05-05 20:56:21 +000096
Guido van Rossum59943ba1997-05-20 22:07:46 +000097PyThreadState *PyThreadState_New Py_PROTO((PyInterpreterState *));
98void PyThreadState_Delete Py_PROTO((PyThreadState *));
Guido van Rossuma027efa1997-05-05 20:56:21 +000099
Guido van Rossum59943ba1997-05-20 22:07:46 +0000100PyThreadState *PyThreadState_Get Py_PROTO((void));
101PyThreadState *PyThreadState_Swap Py_PROTO((PyThreadState *));
Guido van Rossuma027efa1997-05-05 20:56:21 +0000102
103/* Some background.
104
105 There are lots of issues here.
106
107 First, we can build Python without threads, with threads, or (when
108 Greg Stein's mods are out of beta, on some platforms) with free
109 threading.
110
111 Next, assuming some form of threading is used, there can be several
112 kinds of threads. Python code can create threads with the thread
113 module. C code can create threads with the interface defined in
114 python's "thread.h". Or C code can create threads directly with
115 the OS threads interface (e.g. Solaris threads, SGI threads or
116 pthreads, whatever is being used, as long as it's the same that
117 Python is configured for).
118
119 Next, let's discuss sharing of interpreter state between threads.
120 The exception state (sys.exc_* currently) should never be shared
121 between threads, because it is stack frame specific. The contents
122 of the sys module, in particular sys.modules and sys.path, are
123 generally shared between threads. But occasionally it is useful to
124 have separate module collections, e.g. when threads originate in C
125 code and are used to execute unrelated Python scripts.
126 (Traditionally, one would use separate processes for this, but
127 there are lots of reasons why threads are attractive.)
128
129*/
130
131#ifdef __cplusplus
132}
133#endif
134#endif /* !Py_PYSTATE_H */