automatically close ports on gc
This commit is contained in:
parent
9d30573bc6
commit
8f4e07d185
|
@ -587,9 +587,7 @@ gc_finalize_object(pic_state *pic, struct object *obj)
|
|||
break;
|
||||
}
|
||||
case PIC_TYPE_PORT: {
|
||||
if (obj->u.port.file.flag != 0) {
|
||||
pic_fflush(pic, pic_obj_value(obj)); /* FIXME */
|
||||
}
|
||||
pic_fclose(pic, pic_obj_value(obj)); /* FIXME */
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ pic_fclose(pic_state *pic, pic_value port)
|
|||
{
|
||||
struct file *fp = &pic_port_ptr(pic, port)->file;
|
||||
|
||||
if (fp->flag == 0)
|
||||
return 0;
|
||||
pic_fflush(pic, port);
|
||||
fp->flag = 0;
|
||||
if (fp->base != fp->buf)
|
||||
|
|
Loading…
Reference in New Issue