mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Implementation of PEP-0217.
This closes the PEP, and patch 103170
This commit is contained in:
parent
5ac97957f7
commit
f68f2fec7d
3 changed files with 72 additions and 27 deletions
|
@ -1245,36 +1245,26 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
|
|||
|
||||
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);
|
||||
}
|
||||
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();
|
||||
/* fall through to PRINT_ITEM */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue