summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-07-10 23:32:26 (GMT)
committerGuido van Rossum <guido@python.org>1995-07-10 23:32:26 (GMT)
commitd3f9a1ad837fcb68f2c025d17ab04ce2224d3a47 (patch)
tree5719002bb055795dfb65fc223d86b2089e47440c
parent32120311ed8f167f841249d8fd7799ba517f2a44 (diff)
downloadcpython-d3f9a1ad837fcb68f2c025d17ab04ce2224d3a47.zip
cpython-d3f9a1ad837fcb68f2c025d17ab04ce2224d3a47.tar.gz
cpython-d3f9a1ad837fcb68f2c025d17ab04ce2224d3a47.tar.bz2
fix read(0), readline(0); make tuple for call_object args
-rw-r--r--Objects/fileobject.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index d833527..0a03c47 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -376,16 +376,12 @@ file_read(f, args)
if (f->f_fp == NULL)
return err_closed();
if (args == NULL)
- n = 0;
+ n = -1;
else {
if (!getargs(args, "i", &n))
return NULL;
- if (n < 0) {
- err_setstr(ValueError, "negative read count");
- return NULL;
- }
}
- n2 = n != 0 ? n : BUFSIZ;
+ n2 = n >= 0 ? n : BUFSIZ;
v = newsizedstringobject((char *)NULL, n2);
if (v == NULL)
return NULL;
@@ -399,7 +395,7 @@ file_read(f, args)
n1 += n3;
if (n1 == n)
break;
- if (n == 0) {
+ if (n < 0) {
n2 = n1 + BUFSIZ;
RET_SAVE
if (resizestring(&v, n2) < 0)
@@ -561,10 +557,10 @@ file_readline(f, args)
else {
if (!getintarg(args, &n))
return NULL;
- if (n < 0) {
- err_setstr(ValueError, "negative readline count");
- return NULL;
- }
+ if (n == 0)
+ return newstringobject("");
+ if (n < 0)
+ n = 0;
}
return getline(f, n);
@@ -783,7 +779,7 @@ writeobject(v, f, flags)
object *f;
int flags;
{
- object *writer, *value, *result;
+ object *writer, *value, *args, *result;
if (f == NULL) {
err_setstr(TypeError, "writeobject with NULL file");
return -1;
@@ -807,9 +803,16 @@ writeobject(v, f, flags)
DECREF(writer);
return -1;
}
- result = call_object(writer, value);
- DECREF(writer);
+ args = mkvalue("(O)", value);
+ if (value == NULL) {
+ DECREF(value);
+ DECREF(writer);
+ return -1;
+ }
+ result = call_object(writer, args);
+ DECREF(args);
DECREF(value);
+ DECREF(writer);
if (result == NULL)
return -1;
DECREF(result);