diff options
author | Guido van Rossum <guido@python.org> | 1997-12-26 22:15:57 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-12-26 22:15:57 (GMT) |
commit | aa06b0ede584324ea2a509b344ef07d619d0827f (patch) | |
tree | 9e0769847850fb1d0d3bea4ad1e43b92c493e53b /Python | |
parent | 81e84c95c5c3701fb3ede3b67d21004500387faf (diff) | |
download | cpython-aa06b0ede584324ea2a509b344ef07d619d0827f.zip cpython-aa06b0ede584324ea2a509b344ef07d619d0827f.tar.gz cpython-aa06b0ede584324ea2a509b344ef07d619d0827f.tar.bz2 |
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).
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index fad8c2b..8b7447c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1008,11 +1008,12 @@ eval_code2(co, globals, locals, case PRINT_EXPR: v = POP(); - /* Print value except if procedure result */ - /* Before printing, also assign to '_' */ + /* 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, "_", v)) == 0) { + f->f_builtins, "_", Py_None)) == 0) { err = Py_FlushLine(); if (err == 0) { x = PySys_GetObject("stdout"); @@ -1025,6 +1026,10 @@ eval_code2(co, globals, locals, PyFile_SoftSpace(x, 1); err = Py_FlushLine(); } + if (err == 0) { + err = PyDict_SetItemString( + f->f_builtins, "_", v); + } } Py_DECREF(v); break; |