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);
break;
}
case PIC_TYPE_PORT: {
pic_fflush(pic, pic_obj_value(obj)); /* FIXME */
break;
}
case PIC_TYPE_PAIR:
case PIC_TYPE_CXT:
case PIC_TYPE_PORT:
case PIC_TYPE_ERROR:
case PIC_TYPE_ID:
case PIC_TYPE_RECORD:

View File

@ -166,37 +166,19 @@ flushbuf(pic_state *pic, int x, struct file *fp)
}
}
static int
fflush_(pic_state *pic, struct file *fp)
{
int retval;
int i;
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)
return -1;
flushbuf(pic, EOF, fp);
if (fp->flag & FILE_ERR)
retval = -1;
}
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);
}
struct file *fp = pic_port_ptr(pic, port)->file;
int retval;
retval = 0;
if ((fp->flag & FILE_WRITE) == 0)
return -1;
flushbuf(pic, EOF, fp);
if (fp->flag & FILE_ERR)
retval = -1;
return retval;
}
#define getc_(pic, p) \
@ -675,9 +657,11 @@ pic_port_get_output_bytevector(pic_state *pic)
}
static pic_value
pic_port_read_u8(pic_state *pic){
pic_port_read_u8(pic_state *pic)
{
pic_value port = pic_stdin(pic);
int c;
pic_get_args(pic, "|p", &port);
assert_port_profile(port, FILE_READ, "read-u8");

View File

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