fflush during gc

This commit is contained in:
Yuichi Nishiwaki 2016-07-10 23:20:21 +09:00
parent e792d9ffd1
commit cede377e11
3 changed files with 17 additions and 33 deletions

View File

@ -586,10 +586,13 @@ gc_finalize_object(pic_state *pic, struct object *obj)
pic_irep_decref(pic, obj->u.proc.u.i.irep); pic_irep_decref(pic, obj->u.proc.u.i.irep);
break; break;
} }
case PIC_TYPE_PORT: {
pic_fflush(pic, pic_obj_value(obj)); /* FIXME */
break;
}
case PIC_TYPE_PAIR: case PIC_TYPE_PAIR:
case PIC_TYPE_CXT: case PIC_TYPE_CXT:
case PIC_TYPE_PORT:
case PIC_TYPE_ERROR: case PIC_TYPE_ERROR:
case PIC_TYPE_ID: case PIC_TYPE_ID:
case PIC_TYPE_RECORD: case PIC_TYPE_RECORD:

View File

@ -166,39 +166,21 @@ flushbuf(pic_state *pic, int x, struct file *fp)
} }
} }
static int int
fflush_(pic_state *pic, struct file *fp) pic_fflush(pic_state *pic, pic_value port)
{ {
struct file *fp = pic_port_ptr(pic, port)->file;
int retval; int retval;
int i;
retval = 0; retval = 0;
if (fp == NULL) {
/* flush all output streams */
for (i = 0; i < PIC_OPEN_MAX; i++) {
if ((pic->files[i].flag & FILE_WRITE) && (fflush_(pic, &pic->files[i]) == -1))
retval = -1;
}
} else {
if ((fp->flag & FILE_WRITE) == 0) if ((fp->flag & FILE_WRITE) == 0)
return -1; return -1;
flushbuf(pic, EOF, fp); flushbuf(pic, EOF, fp);
if (fp->flag & FILE_ERR) if (fp->flag & FILE_ERR)
retval = -1; retval = -1;
}
return retval; return retval;
} }
int
pic_fflush(pic_state *pic, pic_value port)
{
if (! pic_port_p(pic, port)) {
return fflush_(pic, NULL);
} else {
return fflush_(pic, pic_port_ptr(pic, port)->file);
}
}
#define getc_(pic, p) \ #define getc_(pic, p) \
((--(p)->cnt >= 0) \ ((--(p)->cnt >= 0) \
? (unsigned char) *(p)->ptr++ \ ? (unsigned char) *(p)->ptr++ \
@ -675,9 +657,11 @@ pic_port_get_output_bytevector(pic_state *pic)
} }
static pic_value static pic_value
pic_port_read_u8(pic_state *pic){ pic_port_read_u8(pic_state *pic)
{
pic_value port = pic_stdin(pic); pic_value port = pic_stdin(pic);
int c; int c;
pic_get_args(pic, "|p", &port); pic_get_args(pic, "|p", &port);
assert_port_profile(port, FILE_READ, "read-u8"); assert_port_profile(port, FILE_READ, "read-u8");

View File

@ -297,9 +297,6 @@ pic_close(pic_state *pic)
/* free all heap objects */ /* free all heap objects */
pic_gc(pic); pic_gc(pic);
/* flush all files */
pic_fflush(pic, pic_false_value(pic));
/* free heaps */ /* free heaps */
pic_heap_close(pic, pic->heap); pic_heap_close(pic, pic->heap);