comparison 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
comparison
equal deleted inserted replaced
1072:767ef7370d33 1073:2c0432fcc270
212 } 212 }
213 213
214 void 214 void
215 print_error() 215 print_error()
216 { 216 {
217 object *exception, *v; 217 object *exception, *v, *f;
218 err_get(&exception, &v); 218 err_get(&exception, &v);
219 if (exception == SystemExit) { 219 if (exception == SystemExit) {
220 if (v == NULL || v == None) 220 if (v == NULL || v == None)
221 goaway(0); 221 goaway(0);
222 if (is_intobject(v)) 222 if (is_intobject(v))
223 goaway((int)getintvalue(v)); 223 goaway((int)getintvalue(v));
224 else { 224 else {
225 /* OK to use real stderr here */
225 printobject(v, stderr, PRINT_RAW); 226 printobject(v, stderr, PRINT_RAW);
226 fprintf(stderr, "\n"); 227 fprintf(stderr, "\n");
227 goaway(1); 228 goaway(1);
228 } 229 }
229 } 230 }
230 sysset("last_type", exception); 231 sysset("last_type", exception);
231 sysset("last_value", v); 232 sysset("last_value", v);
232 if (printobject(exception, stderr, PRINT_RAW) != 0) 233 f = sysget("stderr");
233 err_clear(); 234 if (f == NULL)
234 if (v != NULL && v != None) { 235 fprintf(stderr, "lost sys.stderr\n");
235 fprintf(stderr, ": "); 236 else {
236 if (printobject(v, stderr, PRINT_RAW) != 0) 237 if (writeobject(exception, f, PRINT_RAW) != 0)
237 err_clear(); 238 err_clear();
238 } 239 if (v != NULL && v != None) {
239 fprintf(stderr, "\n"); 240 writestring(": ", f);
241 if (writeobject(v, f, PRINT_RAW) != 0)
242 err_clear();
243 }
244 writestring("\n", f);
245 printtraceback(f);
246 }
240 XDECREF(exception); 247 XDECREF(exception);
241 XDECREF(v); 248 XDECREF(v);
242 printtraceback(stderr);
243 } 249 }
244 250
245 object * 251 object *
246 run_string(str, start, globals, locals) 252 run_string(str, start, globals, locals)
247 char *str; 253 char *str;