diff Python/pythonrun.c @ 1073:2c0432fcc270 legacy-trunk

Modified most (but not yet all) I/O to always go through sys.stdout or sys.stderr or sys.stdin, and to work with any object as long as it has a write() (respectively readline()) methods. Some functions that took a FILE* argument now take an object* argument.
author Guido van Rossum <guido@python.org>
date Fri, 25 Sep 1992 21:59:05 +0000
parents f3d5e2c3b9a3
children e4c6a0dd5c2b
line wrap: on
line diff
--- a/Python/pythonrun.c	Fri Sep 25 21:54:05 1992 +0000
+++ b/Python/pythonrun.c	Fri Sep 25 21:59:05 1992 +0000
@@ -214,7 +214,7 @@
 void
 print_error()
 {
-	object *exception, *v;
+	object *exception, *v, *f;
 	err_get(&exception, &v);
 	if (exception == SystemExit) {
 		if (v == NULL || v == None)
@@ -222,6 +222,7 @@
 		if (is_intobject(v))
 			goaway((int)getintvalue(v));
 		else {
+			/* OK to use real stderr here */
 			printobject(v, stderr, PRINT_RAW);
 			fprintf(stderr, "\n");
 			goaway(1);
@@ -229,17 +230,22 @@
 	}
 	sysset("last_type", exception);
 	sysset("last_value", v);
-	if (printobject(exception, stderr, PRINT_RAW) != 0)
-		err_clear();
-	if (v != NULL && v != None) {
-		fprintf(stderr, ": ");
-		if (printobject(v, stderr, PRINT_RAW) != 0)
+	f = sysget("stderr");
+	if (f == NULL)
+		fprintf(stderr, "lost sys.stderr\n");
+	else {
+		if (writeobject(exception, f, PRINT_RAW) != 0)
 			err_clear();
+		if (v != NULL && v != None) {
+			writestring(": ", f);
+			if (writeobject(v, f, PRINT_RAW) != 0)
+				err_clear();
+		}
+		writestring("\n", f);
+		printtraceback(f);
 	}
-	fprintf(stderr, "\n");
 	XDECREF(exception);
 	XDECREF(v);
-	printtraceback(stderr);
 }
 
 object *