Mercurial > cpython-lru_cache-weakref
diff Python/ceval.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 | a41e3ba5b47d |
| children | e4c6a0dd5c2b |
line wrap: on
line diff
--- a/Python/ceval.c Fri Sep 25 21:54:05 1992 +0000 +++ b/Python/ceval.c Fri Sep 25 21:59:05 1992 +0000 @@ -176,7 +176,6 @@ object *trace = NULL; /* Trace function or NULL */ object *retval; /* Return value iff why == WHY_RETURN */ char *name; /* Name used by some instructions */ - FILE *fp; /* Used by print operations */ #ifdef LLTRACE int lltrace = dictlookup(globals, "__lltrace__") != NULL; #endif @@ -598,12 +597,12 @@ case PRINT_EXPR: v = POP(); - fp = sysgetfile("stdout", stdout); /* Print value except if procedure result */ if (v != None) { flushline(); - softspace(sysget("stdout"), 1); - err = printobject(v, fp, 0); + x = sysget("stdout"); + softspace(x, 1); + err = writeobject(v, x, 0); flushline(); } DECREF(v); @@ -611,30 +610,30 @@ case PRINT_ITEM: v = POP(); - fp = sysgetfile("stdout", stdout); - if (softspace(sysget("stdout"), 1)) - fprintf(fp, " "); + w = sysget("stdout"); + if (softspace(w, 1)) + writestring(" ", w); if (is_stringobject(v)) { char *s = getstringvalue(v); int len = getstringsize(v); - fwrite(s, 1, len, fp); - if (ferror(fp)) { - err_errno(IOError); - err = -1; - } - else if (len > 0 && s[len-1] == '\n') - softspace(sysget("stdout"), 0); + err = writeobject(v, w, PRINT_RAW); + if (err == 0 && len > 0 && s[len-1] == '\n') + softspace(w, 0); } else { - err = printobject(v, fp, 0); + err = writeobject(v, w, 0); } DECREF(v); break; case PRINT_NEWLINE: - fp = sysgetfile("stdout", stdout); - fprintf(fp, "\n"); - softspace(sysget("stdout"), 0); + x = sysget("stdout"); + if (x == NULL) + err_setstr(RuntimeError, "lost sys.stdout"); + else { + writestring("\n", x); + softspace(x, 0); + } break; case BREAK_LOOP: @@ -1395,13 +1394,13 @@ } void -printtraceback(fp) - FILE *fp; +printtraceback(f) + object *f; { object *v = tb_fetch(); if (v != NULL) { - fprintf(fp, "Stack backtrace (innermost last):\n"); - tb_print(v, fp); + writestring("Stack backtrace (innermost last):\n", f); + tb_print(v, f); DECREF(v); } } @@ -1410,8 +1409,9 @@ void flushline() { - if (softspace(sysget("stdout"), 0)) - fprintf(sysgetfile("stdout", stdout), "\n"); + object *f = sysget("stdout"); + if (softspace(f, 0)) + writestring("\n", f); }
