comparison Python/sysmodule.c @ 5405:b7871ca930ad legacy-trunk

Massive changes for separate thread state management. All per-thread globals are moved into a struct which is manipulated separately.
author Guido van Rossum <guido@python.org>
date Mon, 05 May 1997 20:56:21 +0000
parents 09597a423227
children 43822e4fc27d
comparison
equal deleted inserted replaced
5404:3780cce14f7d 5405:b7871ca930ad
46 46
47 #include "Python.h" 47 #include "Python.h"
48 48
49 #include "osdefs.h" 49 #include "osdefs.h"
50 50
51 PyObject *_PySys_TraceFunc, *_PySys_ProfileFunc;
52 int _PySys_CheckInterval = 10;
53
54 #if HAVE_UNISTD_H 51 #if HAVE_UNISTD_H
55 #include <unistd.h> 52 #include <unistd.h>
56 #endif 53 #endif
57 54
58 static PyObject *sysdict; 55 static PyObject *sysdict;
96 else 93 else
97 return PyDict_SetItemString(sysdict, name, v); 94 return PyDict_SetItemString(sysdict, name, v);
98 } 95 }
99 96
100 static PyObject * 97 static PyObject *
98 sys_exc_info(self, args)
99 PyObject *self;
100 PyObject *args;
101 {
102 PyThreadState *tstate;
103 if (!PyArg_Parse(args, ""))
104 return NULL;
105 tstate = PyThreadState_Get();
106 if (tstate == NULL)
107 Py_FatalError("sys.exc_info(): no thread state");
108 return Py_BuildValue(
109 "(OOO)",
110 tstate->exc_type != NULL ? tstate->exc_type : Py_None,
111 tstate->exc_value != NULL ? tstate->exc_value : Py_None,
112 tstate->exc_traceback != NULL ?
113 tstate->exc_traceback : Py_None);
114 }
115
116 static PyObject *
101 sys_exit(self, args) 117 sys_exit(self, args)
102 PyObject *self; 118 PyObject *self;
103 PyObject *args; 119 PyObject *args;
104 { 120 {
105 /* Raise SystemExit so callers may catch it or clean up. */ 121 /* Raise SystemExit so callers may catch it or clean up. */
110 static PyObject * 126 static PyObject *
111 sys_settrace(self, args) 127 sys_settrace(self, args)
112 PyObject *self; 128 PyObject *self;
113 PyObject *args; 129 PyObject *args;
114 { 130 {
131 PyThreadState *tstate = PyThreadState_Get();
115 if (args == Py_None) 132 if (args == Py_None)
116 args = NULL; 133 args = NULL;
117 else 134 else
118 Py_XINCREF(args); 135 Py_XINCREF(args);
119 Py_XDECREF(_PySys_TraceFunc); 136 Py_XDECREF(tstate->sys_tracefunc);
120 _PySys_TraceFunc = args; 137 tstate->sys_tracefunc = args;
121 Py_INCREF(Py_None); 138 Py_INCREF(Py_None);
122 return Py_None; 139 return Py_None;
123 } 140 }
124 141
125 static PyObject * 142 static PyObject *
126 sys_setprofile(self, args) 143 sys_setprofile(self, args)
127 PyObject *self; 144 PyObject *self;
128 PyObject *args; 145 PyObject *args;
129 { 146 {
147 PyThreadState *tstate = PyThreadState_Get();
130 if (args == Py_None) 148 if (args == Py_None)
131 args = NULL; 149 args = NULL;
132 else 150 else
133 Py_XINCREF(args); 151 Py_XINCREF(args);
134 Py_XDECREF(_PySys_ProfileFunc); 152 Py_XDECREF(tstate->sys_profilefunc);
135 _PySys_ProfileFunc = args; 153 tstate->sys_profilefunc = args;
136 Py_INCREF(Py_None); 154 Py_INCREF(Py_None);
137 return Py_None; 155 return Py_None;
138 } 156 }
139 157
140 static PyObject * 158 static PyObject *
141 sys_setcheckinterval(self, args) 159 sys_setcheckinterval(self, args)
142 PyObject *self; 160 PyObject *self;
143 PyObject *args; 161 PyObject *args;
144 { 162 {
145 if (!PyArg_ParseTuple(args, "i", &_PySys_CheckInterval)) 163 PyThreadState *tstate = PyThreadState_Get();
164 if (!PyArg_ParseTuple(args, "i", &tstate->sys_checkinterval))
146 return NULL; 165 return NULL;
147 Py_INCREF(Py_None); 166 Py_INCREF(Py_None);
148 return Py_None; 167 return Py_None;
149 } 168 }
150 169
200 extern PyObject *_Py_GetDXProfile Py_PROTO((PyObject *, PyObject *)); 219 extern PyObject *_Py_GetDXProfile Py_PROTO((PyObject *, PyObject *));
201 #endif 220 #endif
202 221
203 static PyMethodDef sys_methods[] = { 222 static PyMethodDef sys_methods[] = {
204 /* Might as well keep this in alphabetic order */ 223 /* Might as well keep this in alphabetic order */
224 {"exc_info", sys_exc_info, 0},
205 {"exit", sys_exit, 0}, 225 {"exit", sys_exit, 0},
206 #ifdef COUNT_ALLOCS 226 #ifdef COUNT_ALLOCS
207 {"getcounts", sys_getcounts, 0}, 227 {"getcounts", sys_getcounts, 0},
208 #endif 228 #endif
209 #ifdef DYNAMIC_EXECUTION_PROFILE 229 #ifdef DYNAMIC_EXECUTION_PROFILE
230 PyObject *list = PyList_New(0); 250 PyObject *list = PyList_New(0);
231 int i; 251 int i;
232 if (list == NULL) 252 if (list == NULL)
233 return NULL; 253 return NULL;
234 for (i = 0; _PyImport_Inittab[i].name != NULL; i++) { 254 for (i = 0; _PyImport_Inittab[i].name != NULL; i++) {
235 PyObject *name = PyString_FromString(_PyImport_Inittab[i].name); 255 PyObject *name = PyString_FromString(
256 _PyImport_Inittab[i].name);
236 if (name == NULL) 257 if (name == NULL)
237 break; 258 break;
238 PyList_Append(list, name); 259 PyList_Append(list, name);
239 Py_DECREF(name); 260 Py_DECREF(name);
240 } 261 }