mirror of
https://github.com/python/cpython.git
synced 2024-11-26 03:14:27 +08:00
Plug the most annoying recursive printing problem -- reset '_' to None
before printing and set it to the printed variable *after* printing (and only when printing is successful).
This commit is contained in:
parent
81e84c95c5
commit
aa06b0ede5
@ -1008,11 +1008,12 @@ eval_code2(co, globals, locals,
|
|||||||
|
|
||||||
case PRINT_EXPR:
|
case PRINT_EXPR:
|
||||||
v = POP();
|
v = POP();
|
||||||
/* Print value except if procedure result */
|
/* Print value except if None */
|
||||||
/* Before printing, also assign to '_' */
|
/* After printing, also assign to '_' */
|
||||||
|
/* Before, set '_' to None to avoid recursion */
|
||||||
if (v != Py_None &&
|
if (v != Py_None &&
|
||||||
(err = PyDict_SetItemString(
|
(err = PyDict_SetItemString(
|
||||||
f->f_builtins, "_", v)) == 0) {
|
f->f_builtins, "_", Py_None)) == 0) {
|
||||||
err = Py_FlushLine();
|
err = Py_FlushLine();
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
x = PySys_GetObject("stdout");
|
x = PySys_GetObject("stdout");
|
||||||
@ -1025,6 +1026,10 @@ eval_code2(co, globals, locals,
|
|||||||
PyFile_SoftSpace(x, 1);
|
PyFile_SoftSpace(x, 1);
|
||||||
err = Py_FlushLine();
|
err = Py_FlushLine();
|
||||||
}
|
}
|
||||||
|
if (err == 0) {
|
||||||
|
err = PyDict_SetItemString(
|
||||||
|
f->f_builtins, "_", v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user