finalize port objects when collected
This commit is contained in:
parent
d2e09fa2c7
commit
6245ec7e05
|
@ -17,7 +17,7 @@ struct pic_port {
|
|||
PIC_OBJECT_HEADER
|
||||
FILE *file;
|
||||
short flags;
|
||||
char status;
|
||||
enum pic_port_status status;
|
||||
};
|
||||
|
||||
#define pic_port_ptr(v) ((struct pic_port_t *)v.u.data)
|
||||
|
|
8
src/gc.c
8
src/gc.c
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue