automatically close ports on gc

This commit is contained in:
Yuichi Nishiwaki 2016-07-11 00:40:58 +09:00
parent 9d30573bc6
commit 8f4e07d185
2 changed files with 3 additions and 3 deletions

View File

@ -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;
}

View File

@ -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)