diff Python/ceval.c @ 6945:f14e4459fb94 legacy-trunk

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).
author Guido van Rossum <guido@python.org>
date Fri, 26 Dec 1997 22:15:57 +0000
parents 6d6fec2eeef6
children c75d899e666f
line wrap: on
line diff
--- a/Python/ceval.c	Thu Dec 25 04:51:41 1997 +0000
+++ b/Python/ceval.c	Fri Dec 26 22:15:57 1997 +0000
@@ -1008,11 +1008,12 @@
 		
 		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 @@
 					PyFile_SoftSpace(x, 1);
 					err = Py_FlushLine();
 				}
+				if (err == 0) {
+					err = PyDict_SetItemString(
+						f->f_builtins, "_", v);
+				}
 			}
 			Py_DECREF(v);
 			break;