Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 15811:1a00d21910c8 legacy-trunk
Implementation of PEP-0217.
This closes the PEP, and patch 103170
| author | Moshe Zadka <moshez@math.huji.ac.il> |
|---|---|
| date | Thu, 11 Jan 2001 05:41:27 +0000 |
| parents | 0f42f6669e80 |
| children | a563eec46c1a |
comparison
equal
deleted
inserted
replaced
| 15810:954611fd35e1 | 15811:1a00d21910c8 |
|---|---|
| 66 else | 66 else |
| 67 return PyDict_SetItemString(sd, name, v); | 67 return PyDict_SetItemString(sd, name, v); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static PyObject * | 70 static PyObject * |
| 71 sys_displayhook(PyObject *self, PyObject *args) | |
| 72 { | |
| 73 PyObject *o, *stdout; | |
| 74 PyInterpreterState *interp = PyThreadState_Get()->interp; | |
| 75 PyObject *modules = interp->modules; | |
| 76 PyObject *builtins = PyDict_GetItemString(modules, "__builtin__"); | |
| 77 | |
| 78 /* parse arguments */ | |
| 79 if (!PyArg_ParseTuple(args, "O:displayhook", &o)) | |
| 80 return NULL; | |
| 81 | |
| 82 /* Print value except if None */ | |
| 83 /* After printing, also assign to '_' */ | |
| 84 /* Before, set '_' to None to avoid recursion */ | |
| 85 if (o == Py_None) { | |
| 86 Py_INCREF(Py_None); | |
| 87 return Py_None; | |
| 88 } | |
| 89 if (PyObject_SetAttrString(builtins, "_", Py_None) != 0) | |
| 90 return NULL; | |
| 91 if (Py_FlushLine() != 0) | |
| 92 return NULL; | |
| 93 stdout = PySys_GetObject("stdout"); | |
| 94 if (stdout == NULL) { | |
| 95 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); | |
| 96 return NULL; | |
| 97 } | |
| 98 if (PyFile_WriteObject(o, stdout, 0) != 0) | |
| 99 return NULL; | |
| 100 PyFile_SoftSpace(stdout, 1); | |
| 101 if (Py_FlushLine() != 0) | |
| 102 return NULL; | |
| 103 if (PyObject_SetAttrString(builtins, "_", o) != 0) | |
| 104 return NULL; | |
| 105 Py_INCREF(Py_None); | |
| 106 return Py_None; | |
| 107 } | |
| 108 | |
| 109 static char displayhook_doc[] = | |
| 110 "displayhook(o) -> None\n" | |
| 111 "\n" | |
| 112 "Print o to the stdout, and save it in __builtin__._\n"; | |
| 113 | |
| 114 static PyObject * | |
| 71 sys_exc_info(PyObject *self, PyObject *args) | 115 sys_exc_info(PyObject *self, PyObject *args) |
| 72 { | 116 { |
| 73 PyThreadState *tstate; | 117 PyThreadState *tstate; |
| 74 if (!PyArg_ParseTuple(args, ":exc_info")) | 118 if (!PyArg_ParseTuple(args, ":exc_info")) |
| 75 return NULL; | 119 return NULL; |
| 330 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); | 374 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); |
| 331 #endif | 375 #endif |
| 332 | 376 |
| 333 static PyMethodDef sys_methods[] = { | 377 static PyMethodDef sys_methods[] = { |
| 334 /* Might as well keep this in alphabetic order */ | 378 /* Might as well keep this in alphabetic order */ |
| 379 {"displayhook", sys_displayhook, 1, displayhook_doc}, | |
| 335 {"exc_info", sys_exc_info, 1, exc_info_doc}, | 380 {"exc_info", sys_exc_info, 1, exc_info_doc}, |
| 336 {"exit", sys_exit, 0, exit_doc}, | 381 {"exit", sys_exit, 0, exit_doc}, |
| 337 {"getdefaultencoding", sys_getdefaultencoding, 1, | 382 {"getdefaultencoding", sys_getdefaultencoding, 1, |
| 338 getdefaultencoding_doc}, | 383 getdefaultencoding_doc}, |
| 339 #ifdef COUNT_ALLOCS | 384 #ifdef COUNT_ALLOCS |
| 473 __stdout__ -- the original stdout; don't use!\n\ | 518 __stdout__ -- the original stdout; don't use!\n\ |
| 474 __stderr__ -- the original stderr; don't use!\n\ | 519 __stderr__ -- the original stderr; don't use!\n\ |
| 475 \n\ | 520 \n\ |
| 476 Functions:\n\ | 521 Functions:\n\ |
| 477 \n\ | 522 \n\ |
| 523 displayhook() -- print an object to the screen, and save it in __builtin__._\n\ | |
| 478 exc_info() -- return thread-safe information about the current exception\n\ | 524 exc_info() -- return thread-safe information about the current exception\n\ |
| 479 exit() -- exit the interpreter by raising SystemExit\n\ | 525 exit() -- exit the interpreter by raising SystemExit\n\ |
| 480 getrefcount() -- return the reference count for an object (plus one :-)\n\ | 526 getrefcount() -- return the reference count for an object (plus one :-)\n\ |
| 481 getrecursionlimit() -- return the max recursion depth for the interpreter\n\ | 527 getrecursionlimit() -- return the max recursion depth for the interpreter\n\ |
| 482 setcheckinterval() -- control how often the interpreter checks for events\n\ | 528 setcheckinterval() -- control how often the interpreter checks for events\n\ |
