finalize port objects when collected

This commit is contained in:
Yuichi Nishiwaki
2013-10-22 15:40:36 +09:00
parent d2e09fa2c7
commit 6245ec7e05
2 changed files with 9 additions and 1 deletions
+8
View File
@@ -5,6 +5,7 @@
#include "picrin/irep.h"
#include "picrin/proc.h"
#include "picrin/symbol.h"
#include "picrin/port.h"
#if GC_DEBUG
# include <stdio.h>
@@ -265,6 +266,13 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
pic_free(pic, (void*)((struct pic_string *)obj)->str);
break;
}
case PIC_TT_PORT: {
struct pic_port *port = (struct pic_port *)obj;
if (port->status == PIC_OPEN) {
fclose(port->file);
}
break;
}
case PIC_TT_NIL:
case PIC_TT_BOOL:
case PIC_TT_FLOAT: