annotate Python/pystate.c @ 10072:ecebcd84df37 legacy-trunk

put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
author Just van Rossum <just@lettererror.com>
date Tue, 02 Feb 1999 15:49:03 +0000
parents 914f83e7fa0a
children 3b3c7b8ade7f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 The Netherlands.
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 distribution of the software without specific, written prior
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 permission.
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 While CWI is the initial source for this software, a modified version
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 is made available by the Corporation for National Research Initiatives
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 ******************************************************************/
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* Thread and interpreter state structures and their interfaces */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include "Python.h"
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
36 #define ZAP(x) { \
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
37 PyObject *tmp = (PyObject *)(x); \
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
38 (x) = NULL; \
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
39 Py_XDECREF(tmp); \
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
40 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
41
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
42
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
43 static PyInterpreterState *interp_head = NULL;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
9667
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
45 PyThreadState *_PyThreadState_Current = NULL;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 PyInterpreterState *
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 PyInterpreterState_New()
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 PyInterpreterState *interp = PyMem_NEW(PyInterpreterState, 1);
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
52
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 if (interp != NULL) {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
54 interp->modules = NULL;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 interp->sysdict = NULL;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
56 interp->builtins = NULL;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
57 interp->checkinterval = 10;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
58 interp->tstate_head = NULL;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
59
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
60 interp->next = interp_head;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
61 interp_head = interp;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 }
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
63
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 return interp;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 void
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
69 PyInterpreterState_Clear(interp)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
70 PyInterpreterState *interp;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
71 {
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
72 PyThreadState *p;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
73 for (p = interp->tstate_head; p != NULL; p = p->next)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
74 PyThreadState_Clear(p);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
75 ZAP(interp->modules);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
76 ZAP(interp->sysdict);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
77 ZAP(interp->builtins);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
78 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
79
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
80
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
81 static void
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
82 zapthreads(interp)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
83 PyInterpreterState *interp;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
84 {
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
85 PyThreadState *p, *q;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
86 p = interp->tstate_head;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
87 while (p != NULL) {
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
88 q = p->next;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
89 PyThreadState_Delete(p);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
90 p = q;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
91 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
92 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
93
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
94
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
95 void
5567
932cfc5fc104 Don't use function prototypes in function definition headers.
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
96 PyInterpreterState_Delete(interp)
932cfc5fc104 Don't use function prototypes in function definition headers.
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
97 PyInterpreterState *interp;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
99 PyInterpreterState **p;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
100 zapthreads(interp);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
101 for (p = &interp_head; ; p = &(*p)->next) {
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
102 if (*p == NULL)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
103 Py_FatalError(
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
104 "PyInterpreterState_Delete: invalid interp");
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
105 if (*p == interp)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
106 break;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
107 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
108 if (interp->tstate_head != NULL)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
109 Py_FatalError("PyInterpreterState_Delete: remaining threads");
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
110 *p = interp->next;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 PyMem_DEL(interp);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 PyThreadState *
5567
932cfc5fc104 Don't use function prototypes in function definition headers.
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
116 PyThreadState_New(interp)
932cfc5fc104 Don't use function prototypes in function definition headers.
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
117 PyInterpreterState *interp;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 PyThreadState *tstate = PyMem_NEW(PyThreadState, 1);
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
120
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 if (tstate != NULL) {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
122 tstate->interp = interp;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 tstate->frame = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 tstate->recursion_depth = 0;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 tstate->ticker = 0;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 tstate->tracing = 0;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128
7970
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
129 tstate->dict = NULL;
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
130
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 tstate->curexc_type = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 tstate->curexc_value = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 tstate->curexc_traceback = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 tstate->exc_type = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 tstate->exc_value = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 tstate->exc_traceback = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 tstate->sys_profilefunc = NULL;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 tstate->sys_tracefunc = NULL;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
141
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
142 tstate->next = interp->tstate_head;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
143 interp->tstate_head = tstate;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
144 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
145
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
146 return tstate;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
147 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
148
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
150 void
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
151 PyThreadState_Clear(tstate)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
152 PyThreadState *tstate;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
153 {
6549
a8e3b2e9f5d2 The warning about thread still having a frame now only happens in
Guido van Rossum <guido@python.org>
parents: 6124
diff changeset
154 if (Py_VerboseFlag && tstate->frame != NULL)
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
155 fprintf(stderr,
6124
cc2c84769636 Added missing newline to warning msg
Guido van Rossum <guido@python.org>
parents: 5926
diff changeset
156 "PyThreadState_Clear: warning: thread still has a frame\n");
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
157
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
158 ZAP(tstate->frame);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
159
7970
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
160 ZAP(tstate->dict);
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
161
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
162 ZAP(tstate->curexc_type);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
163 ZAP(tstate->curexc_value);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
164 ZAP(tstate->curexc_traceback);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
165
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
166 ZAP(tstate->exc_type);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
167 ZAP(tstate->exc_value);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
168 ZAP(tstate->exc_traceback);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
169
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
170 ZAP(tstate->sys_profilefunc);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
171 ZAP(tstate->sys_tracefunc);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 void
5567
932cfc5fc104 Don't use function prototypes in function definition headers.
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
176 PyThreadState_Delete(tstate)
932cfc5fc104 Don't use function prototypes in function definition headers.
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
177 PyThreadState *tstate;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
179 PyInterpreterState *interp;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
180 PyThreadState **p;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
181 if (tstate == NULL)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
182 Py_FatalError("PyThreadState_Delete: NULL tstate");
9667
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
183 if (tstate == _PyThreadState_Current)
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
184 Py_FatalError("PyThreadState_Delete: tstate is still current");
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
185 interp = tstate->interp;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
186 if (interp == NULL)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
187 Py_FatalError("PyThreadState_Delete: NULL interp");
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
188 for (p = &interp->tstate_head; ; p = &(*p)->next) {
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
189 if (*p == NULL)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
190 Py_FatalError(
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
191 "PyThreadState_Delete: invalid tstate");
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
192 if (*p == tstate)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
193 break;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
194 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
195 *p = tstate->next;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 PyMem_DEL(tstate);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 PyThreadState *
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 PyThreadState_Get()
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 {
9667
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
203 if (_PyThreadState_Current == NULL)
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
204 Py_FatalError("PyThreadState_Get: no current thread");
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
205
9667
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
206 return _PyThreadState_Current;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 PyThreadState *
5567
932cfc5fc104 Don't use function prototypes in function definition headers.
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
211 PyThreadState_Swap(new)
932cfc5fc104 Don't use function prototypes in function definition headers.
Guido van Rossum <guido@python.org>
parents: 5405
diff changeset
212 PyThreadState *new;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 {
9667
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
214 PyThreadState *old = _PyThreadState_Current;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
215
9667
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
216 _PyThreadState_Current = new;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5849
diff changeset
217
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 return old;
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 }
7970
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
220
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
221 /* An extension mechanism to store arbitrary additional per-thread state.
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
222 PyThreadState_GetDict() returns a dictionary that can be used to hold such
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
223 state; the caller should pick a unique key and store its state there. If
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
224 PyThreadState_GetDict() returns NULL, an exception has been raised (most
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
225 likely MemoryError) and the caller should pass on the exception. */
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
226
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
227 PyObject *
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
228 PyThreadState_GetDict()
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
229 {
9667
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
230 if (_PyThreadState_Current == NULL)
7970
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
231 Py_FatalError("PyThreadState_GetDict: no current thread");
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
232
9667
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
233 if (_PyThreadState_Current->dict == NULL)
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
234 _PyThreadState_Current->dict = PyDict_New();
914f83e7fa0a Make current_tstate a global, _PyThreadState_Current. This is to
Guido van Rossum <guido@python.org>
parents: 7970
diff changeset
235 return _PyThreadState_Current->dict;
7970
4ceee1ef99b0 /* An extension mechanism to store arbitrary additional per-thread state.
Guido van Rossum <guido@python.org>
parents: 6549
diff changeset
236 }