Commit 9cea4f0a authored by Chris Toshok's avatar Chris Toshok

add a simple_destructor for file objects

parent 4afb0656
......@@ -1065,7 +1065,18 @@ PyMethodDef file_methods[] = {
{ "readlines", (PyCFunction)file_readlines, METH_VARARGS, readlines_doc },
};
void fileDestructor(Box* b) {
assert(isSubclass(b->cls, file_cls));
BoxedFile* self = static_cast<BoxedFile*>(b);
if (self->f_fp)
fclose(self->f_fp);
self->f_fp = NULL;
}
void setupFile() {
file_cls->simple_destructor = fileDestructor;
file_cls->giveAttr("read",
new BoxedFunction(boxRTFunction((void*)fileRead, STR, 2, 1, false, false), { boxInt(-1) }));
......
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