Commit 67a8482a authored by Kevin Modzelewski's avatar Kevin Modzelewski

file.flush

parent 72bde9a5
......@@ -94,8 +94,7 @@ Box* fileWrite(BoxedFile* self, Box* val) {
assert(self->cls == file_cls);
if (self->closed) {
fprintf(stderr, "IOError: file is closed\n");
raiseExcHelper(IOError, "");
raiseExcHelper(IOError, "file is closed");
}
......@@ -129,6 +128,16 @@ Box* fileWrite(BoxedFile* self, Box* val) {
}
}
Box* fileFlush(BoxedFile* self) {
RELEASE_ASSERT(self->cls == file_cls, "");
if (self->closed)
raiseExcHelper(IOError, "file is closed");
fflush(self->f);
return None;
}
Box* fileClose(BoxedFile* self) {
assert(self->cls == file_cls);
if (self->closed) {
......@@ -199,6 +208,7 @@ void setupFile() {
CLFunction* readline = boxRTFunction((void*)fileReadline1, STR, 1);
file_cls->giveAttr("readline", new BoxedFunction(readline));
file_cls->giveAttr("flush", new BoxedFunction(boxRTFunction((void*)fileFlush, NONE, 1)));
file_cls->giveAttr("write", new BoxedFunction(boxRTFunction((void*)fileWrite, NONE, 2)));
file_cls->giveAttr("close", new BoxedFunction(boxRTFunction((void*)fileClose, NONE, 1)));
......
......@@ -34,7 +34,7 @@ f = open('/dev/null')
print iter(f) is f
f.close()
with open('../README.md') as f:
with open('README.md') as f:
lines = list(f)
print lines[:5]
print lines[-5:]
......@@ -44,3 +44,8 @@ try:
f = open('this-should-definitely-not-exist.txt')
except IOError as e:
print str(e)
f = open("/dev/null", "w")
f.write("hello world")
print f.flush()
f.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment