[Python-checkins] CVS: python/dist/src/Python ceval.c,2.216,2.217 sysmodule.c,2.80,2.81
Moshe Zadka
python-dev@python.org
Wed, 10 Jan 2001 21:41:29 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv21213/Python
Modified Files:
ceval.c sysmodule.c
Log Message:
Implementation of PEP-0217.
This closes the PEP, and patch 103170
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.216
retrieving revision 2.217
diff -C2 -r2.216 -r2.217
*** ceval.c 2001/01/10 22:11:59 2.216
--- ceval.c 2001/01/11 05:41:27 2.217
***************
*** 1246,1279 ****
case PRINT_EXPR:
v = POP();
! /* Print value except if None */
! /* After printing, also assign to '_' */
! /* Before, set '_' to None to avoid recursion */
! if (v != Py_None &&
! (err = PyDict_SetItemString(
! f->f_builtins, "_", Py_None)) == 0) {
! err = Py_FlushLine();
! if (err == 0) {
! x = PySys_GetObject("stdout");
! if (x == NULL) {
! PyErr_SetString(
! PyExc_RuntimeError,
! "lost sys.stdout");
! err = -1;
! }
! }
! if (err == 0)
! err = PyFile_WriteObject(v, x, 0);
! if (err == 0) {
! PyFile_SoftSpace(x, 1);
! err = Py_FlushLine();
! }
! if (err == 0) {
! err = PyDict_SetItemString(
! f->f_builtins, "_", v);
! }
}
Py_DECREF(v);
break;
!
case PRINT_ITEM_TO:
w = stream = POP();
--- 1246,1269 ----
case PRINT_EXPR:
v = POP();
! w = PySys_GetObject("displayhook");
! if (w == NULL) {
! PyErr_SetString(PyExc_RuntimeError,
! "lost sys.displayhook");
! err = -1;
}
+ if (err == 0) {
+ x = Py_BuildValue("(O)", v);
+ if (x == NULL)
+ err = -1;
+ }
+ if (err == 0) {
+ w = PyEval_CallObject(w, x);
+ if (w == NULL)
+ err = -1;
+ }
Py_DECREF(v);
+ Py_XDECREF(x);
break;
!
case PRINT_ITEM_TO:
w = stream = POP();
Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.80
retrieving revision 2.81
diff -C2 -r2.80 -r2.81
*** sysmodule.c 2000/12/15 22:02:05 2.80
--- sysmodule.c 2001/01/11 05:41:27 2.81
***************
*** 69,72 ****
--- 69,116 ----
static PyObject *
+ sys_displayhook(PyObject *self, PyObject *args)
+ {
+ PyObject *o, *stdout;
+ PyInterpreterState *interp = PyThreadState_Get()->interp;
+ PyObject *modules = interp->modules;
+ PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");
+
+ /* parse arguments */
+ if (!PyArg_ParseTuple(args, "O:displayhook", &o))
+ return NULL;
+
+ /* Print value except if None */
+ /* After printing, also assign to '_' */
+ /* Before, set '_' to None to avoid recursion */
+ if (o == Py_None) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
+ return NULL;
+ if (Py_FlushLine() != 0)
+ return NULL;
+ stdout = PySys_GetObject("stdout");
+ if (stdout == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
+ return NULL;
+ }
+ if (PyFile_WriteObject(o, stdout, 0) != 0)
+ return NULL;
+ PyFile_SoftSpace(stdout, 1);
+ if (Py_FlushLine() != 0)
+ return NULL;
+ if (PyObject_SetAttrString(builtins, "_", o) != 0)
+ return NULL;
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ static char displayhook_doc[] =
+ "displayhook(o) -> None\n"
+ "\n"
+ "Print o to the stdout, and save it in __builtin__._\n";
+
+ static PyObject *
sys_exc_info(PyObject *self, PyObject *args)
{
***************
*** 333,336 ****
--- 377,381 ----
static PyMethodDef sys_methods[] = {
/* Might as well keep this in alphabetic order */
+ {"displayhook", sys_displayhook, 1, displayhook_doc},
{"exc_info", sys_exc_info, 1, exc_info_doc},
{"exit", sys_exit, 0, exit_doc},
***************
*** 476,479 ****
--- 521,525 ----
Functions:\n\
\n\
+ displayhook() -- print an object to the screen, and save it in __builtin__._\n\
exc_info() -- return thread-safe information about the current exception\n\
exit() -- exit the interpreter by raising SystemExit\n\