summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-09-25 21:59:05 (GMT)
committerGuido van Rossum <guido@python.org>1992-09-25 21:59:05 (GMT)
commit3165fe6a56c07f4f85f4ea54b69f5b1f243e2463 (patch)
treee4721159db6fc00c4267e03c035b58b73c854fd5 /Python/bltinmodule.c
parent3a40ae4ef3b3dd7f2967a63acceabb0d0ae251d7 (diff)
downloadcpython-3165fe6a56c07f4f85f4ea54b69f5b1f243e2463.zip
cpython-3165fe6a56c07f4f85f4ea54b69f5b1f243e2463.tar.gz
cpython-3165fe6a56c07f4f85f4ea54b69f5b1f243e2463.tar.bz2
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.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 2f46931..9ba07af 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -308,28 +308,19 @@ builtin_hex(self, v)
return (*nb->nb_hex)(v);
}
+static object *builtin_raw_input PROTO((object *, object *));
+
static object *
builtin_input(self, v)
object *self;
object *v;
{
- FILE *in = sysgetfile("stdin", stdin);
- FILE *out = sysgetfile("stdout", stdout);
- int c;
- object *m, *d;
- flushline();
- if (v != NULL) {
- if (printobject(v, out, PRINT_RAW) != 0)
- return NULL;
- }
- m = add_module("__main__");
- d = getmoduledict(m);
- BGN_SAVE
- while ((c = getc(in)) != EOF && (c == ' ' || c == '\t'))
- ;
- ungetc(c, in);
- END_SAVE
- return run_file(in, "<stdin>", expr_input, d, d);
+ object *line = builtin_raw_input(self, v);
+ if (line == NULL)
+ return line;
+ v = exec_eval(line, eval_input);
+ DECREF(line);
+ return v;
}
static object *
@@ -578,10 +569,14 @@ builtin_raw_input(self, v)
object *self;
object *v;
{
- FILE *out = sysgetfile("stdout", stdout);
+ object *f = sysget("stdout");
+ if (f == NULL) {
+ err_setstr(RuntimeError, "lost sys.stdout");
+ return NULL;
+ }
flushline();
if (v != NULL) {
- if (printobject(v, out, PRINT_RAW) != 0)
+ if (writeobject(v, f, PRINT_RAW) != 0)
return NULL;
}
return filegetline(sysget("stdin"), -1);