Commit a8ff0670 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #300 from toshok/file-simple-destructor

add a simple_destructor for file objects
parents 012d6d50 eeabb498
......@@ -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) }));
......
import gc
def open_lots_of_files():
for x in range(0, 10000):
f = open("/dev/null")
if x % 80 == 0:
gc.collect();
open_lots_of_files()
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