Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 5926:8d2194e22e67 legacy-trunk
The last of the mass checkins for separate (sub)interpreters.
Everything should now work again.
See the comments for the .h files mass checkin (e.g. pystate.h) for
more detail.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 02 Aug 1997 03:10:38 +0000 |
| parents | 0ac2c747053f |
| children | 1f2dfca52207 |
comparison
equal
deleted
inserted
replaced
| 5925:93304b2e14cb | 5926:8d2194e22e67 |
|---|---|
| 50 | 50 |
| 51 #ifdef HAVE_UNISTD_H | 51 #ifdef HAVE_UNISTD_H |
| 52 #include <unistd.h> | 52 #include <unistd.h> |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 static PyObject *sysdict; | |
| 56 | |
| 57 #ifdef MS_COREDLL | 55 #ifdef MS_COREDLL |
| 58 extern void *PyWin_DLLhModule; | 56 extern void *PyWin_DLLhModule; |
| 59 #endif | 57 #endif |
| 60 | 58 |
| 61 PyObject * | 59 PyObject * |
| 62 PySys_GetObject(name) | 60 PySys_GetObject(name) |
| 63 char *name; | 61 char *name; |
| 64 { | 62 { |
| 65 return PyDict_GetItemString(sysdict, name); | 63 PyThreadState *tstate = PyThreadState_Get(); |
| 64 PyObject *sd = tstate->interp->sysdict; | |
| 65 return PyDict_GetItemString(sd, name); | |
| 66 } | 66 } |
| 67 | 67 |
| 68 FILE * | 68 FILE * |
| 69 PySys_GetFile(name, def) | 69 PySys_GetFile(name, def) |
| 70 char *name; | 70 char *name; |
| 82 int | 82 int |
| 83 PySys_SetObject(name, v) | 83 PySys_SetObject(name, v) |
| 84 char *name; | 84 char *name; |
| 85 PyObject *v; | 85 PyObject *v; |
| 86 { | 86 { |
| 87 PyThreadState *tstate = PyThreadState_Get(); | |
| 88 PyObject *sd = tstate->interp->sysdict; | |
| 87 if (v == NULL) { | 89 if (v == NULL) { |
| 88 if (PyDict_GetItemString(sysdict, name) == NULL) | 90 if (PyDict_GetItemString(sd, name) == NULL) |
| 89 return 0; | 91 return 0; |
| 90 else | 92 else |
| 91 return PyDict_DelItemString(sysdict, name); | 93 return PyDict_DelItemString(sd, name); |
| 92 } | 94 } |
| 93 else | 95 else |
| 94 return PyDict_SetItemString(sysdict, name, v); | 96 return PyDict_SetItemString(sd, name, v); |
| 95 } | 97 } |
| 96 | 98 |
| 97 static PyObject * | 99 static PyObject * |
| 98 sys_exc_info(self, args) | 100 sys_exc_info(self, args) |
| 99 PyObject *self; | 101 PyObject *self; |
| 101 { | 103 { |
| 102 PyThreadState *tstate; | 104 PyThreadState *tstate; |
| 103 if (!PyArg_Parse(args, "")) | 105 if (!PyArg_Parse(args, "")) |
| 104 return NULL; | 106 return NULL; |
| 105 tstate = PyThreadState_Get(); | 107 tstate = PyThreadState_Get(); |
| 106 if (tstate == NULL) | |
| 107 Py_FatalError("sys.exc_info(): no thread state"); | |
| 108 return Py_BuildValue( | 108 return Py_BuildValue( |
| 109 "(OOO)", | 109 "(OOO)", |
| 110 tstate->exc_type != NULL ? tstate->exc_type : Py_None, | 110 tstate->exc_type != NULL ? tstate->exc_type : Py_None, |
| 111 tstate->exc_value != NULL ? tstate->exc_value : Py_None, | 111 tstate->exc_value != NULL ? tstate->exc_value : Py_None, |
| 112 tstate->exc_traceback != NULL ? | 112 tstate->exc_traceback != NULL ? |
| 159 sys_setcheckinterval(self, args) | 159 sys_setcheckinterval(self, args) |
| 160 PyObject *self; | 160 PyObject *self; |
| 161 PyObject *args; | 161 PyObject *args; |
| 162 { | 162 { |
| 163 PyThreadState *tstate = PyThreadState_Get(); | 163 PyThreadState *tstate = PyThreadState_Get(); |
| 164 if (!PyArg_ParseTuple(args, "i", &tstate->sys_checkinterval)) | 164 if (!PyArg_ParseTuple(args, "i", &tstate->interp->checkinterval)) |
| 165 return NULL; | 165 return NULL; |
| 166 Py_INCREF(Py_None); | 166 Py_INCREF(Py_None); |
| 167 return Py_None; | 167 return Py_None; |
| 168 } | 168 } |
| 169 | 169 |
| 239 {"setcheckinterval", sys_setcheckinterval, 1}, | 239 {"setcheckinterval", sys_setcheckinterval, 1}, |
| 240 {"setprofile", sys_setprofile, 0}, | 240 {"setprofile", sys_setprofile, 0}, |
| 241 {"settrace", sys_settrace, 0}, | 241 {"settrace", sys_settrace, 0}, |
| 242 {NULL, NULL} /* sentinel */ | 242 {NULL, NULL} /* sentinel */ |
| 243 }; | 243 }; |
| 244 | |
| 245 static PyObject *sysin, *sysout, *syserr; | |
| 246 | 244 |
| 247 static PyObject * | 245 static PyObject * |
| 248 list_builtin_module_names() | 246 list_builtin_module_names() |
| 249 { | 247 { |
| 250 PyObject *list = PyList_New(0); | 248 PyObject *list = PyList_New(0); |
| 269 list = v; | 267 list = v; |
| 270 } | 268 } |
| 271 return list; | 269 return list; |
| 272 } | 270 } |
| 273 | 271 |
| 274 void | 272 PyObject * |
| 275 PySys_Init() | 273 _PySys_Init() |
| 276 { | 274 { |
| 277 extern int fclose Py_PROTO((FILE *)); | 275 extern int fclose Py_PROTO((FILE *)); |
| 278 PyObject *m = Py_InitModule("sys", sys_methods); | 276 PyThreadState *tstate; |
| 279 PyObject *v; | 277 PyObject *m, *v, *sysdict; |
| 278 PyObject *sysin, *sysout, *syserr; | |
| 279 | |
| 280 m = Py_InitModule("sys", sys_methods); | |
| 280 sysdict = PyModule_GetDict(m); | 281 sysdict = PyModule_GetDict(m); |
| 281 Py_INCREF(sysdict); | 282 |
| 282 /* NB keep an extra ref to the std files to avoid closing them | 283 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL); |
| 283 when the user deletes them */ | 284 sysout = PyFile_FromFile(stdout, "<stdout>", "w", NULL); |
| 284 sysin = PyFile_FromFile(stdin, "<stdin>", "r", fclose); | 285 syserr = PyFile_FromFile(stderr, "<stderr>", "w", NULL); |
| 285 sysout = PyFile_FromFile(stdout, "<stdout>", "w", fclose); | |
| 286 syserr = PyFile_FromFile(stderr, "<stderr>", "w", fclose); | |
| 287 if (PyErr_Occurred()) | 286 if (PyErr_Occurred()) |
| 288 Py_FatalError("can't initialize sys.std{in,out,err}"); | 287 return NULL; |
| 289 PyDict_SetItemString(sysdict, "stdin", sysin); | 288 PyDict_SetItemString(sysdict, "stdin", sysin); |
| 290 PyDict_SetItemString(sysdict, "stdout", sysout); | 289 PyDict_SetItemString(sysdict, "stdout", sysout); |
| 291 PyDict_SetItemString(sysdict, "stderr", syserr); | 290 PyDict_SetItemString(sysdict, "stderr", syserr); |
| 291 Py_XDECREF(sysin); | |
| 292 Py_XDECREF(sysout); | |
| 293 Py_XDECREF(syserr); | |
| 292 PyDict_SetItemString(sysdict, "version", | 294 PyDict_SetItemString(sysdict, "version", |
| 293 v = PyString_FromString(Py_GetVersion())); | 295 v = PyString_FromString(Py_GetVersion())); |
| 294 Py_XDECREF(v); | 296 Py_XDECREF(v); |
| 295 PyDict_SetItemString(sysdict, "copyright", | 297 PyDict_SetItemString(sysdict, "copyright", |
| 296 v = PyString_FromString(Py_GetCopyright())); | 298 v = PyString_FromString(Py_GetCopyright())); |
| 308 v = PyString_FromString(Py_GetExecPrefix())); | 310 v = PyString_FromString(Py_GetExecPrefix())); |
| 309 Py_XDECREF(v); | 311 Py_XDECREF(v); |
| 310 PyDict_SetItemString(sysdict, "maxint", | 312 PyDict_SetItemString(sysdict, "maxint", |
| 311 v = PyInt_FromLong(PyInt_GetMax())); | 313 v = PyInt_FromLong(PyInt_GetMax())); |
| 312 Py_XDECREF(v); | 314 Py_XDECREF(v); |
| 313 PyDict_SetItemString(sysdict, "modules", PyImport_GetModuleDict()); | |
| 314 PyDict_SetItemString(sysdict, "builtin_module_names", | 315 PyDict_SetItemString(sysdict, "builtin_module_names", |
| 315 v = list_builtin_module_names()); | 316 v = list_builtin_module_names()); |
| 316 Py_XDECREF(v); | 317 Py_XDECREF(v); |
| 317 #ifdef MS_COREDLL | 318 #ifdef MS_COREDLL |
| 318 PyDict_SetItemString(sysdict, "dllhandle", | 319 PyDict_SetItemString(sysdict, "dllhandle", |
| 321 PyDict_SetItemString(sysdict, "winver", | 322 PyDict_SetItemString(sysdict, "winver", |
| 322 v = PyString_FromString(MS_DLL_ID)); | 323 v = PyString_FromString(MS_DLL_ID)); |
| 323 Py_XDECREF(v); | 324 Py_XDECREF(v); |
| 324 #endif | 325 #endif |
| 325 if (PyErr_Occurred()) | 326 if (PyErr_Occurred()) |
| 326 Py_FatalError("can't insert sys.* objects in sys dict"); | 327 return NULL; |
| 328 return m; | |
| 327 } | 329 } |
| 328 | 330 |
| 329 static PyObject * | 331 static PyObject * |
| 330 makepathobject(path, delim) | 332 makepathobject(path, delim) |
| 331 char *path; | 333 char *path; |
