[bugfix] port should be closed properly

This commit is contained in:
Yuichi Nishiwaki 2015-06-26 15:13:12 +09:00
parent fccb4b16ea
commit 8e90517224
1 changed files with 12 additions and 9 deletions

View File

@ -601,6 +601,7 @@ pic_port_read_line(pic_state *pic)
int c; int c;
struct pic_port *port = pic_stdin(pic), *buf; struct pic_port *port = pic_stdin(pic), *buf;
struct pic_string *str; struct pic_string *str;
pic_value res = pic_eof_object();
pic_get_args(pic, "|p", &port); pic_get_args(pic, "|p", &port);
@ -613,11 +614,12 @@ pic_port_read_line(pic_state *pic)
str = pic_get_output_string(pic, buf); str = pic_get_output_string(pic, buf);
if (pic_str_len(str) == 0 && c == EOF) { if (pic_str_len(str) == 0 && c == EOF) {
return pic_eof_object(); /* EOF */
} } else {
else { res = pic_obj_value(str);
return pic_obj_value(str);
} }
pic_close_port(pic, buf);
return res;
} }
static pic_value static pic_value
@ -638,6 +640,7 @@ pic_port_read_string(pic_state *pic){
pic_str *str; pic_str *str;
int k, i; int k, i;
int c; int c;
pic_value res = pic_eof_object();
pic_get_args(pic, "i|p", &k, &port); pic_get_args(pic, "i|p", &k, &port);
@ -654,12 +657,12 @@ pic_port_read_string(pic_state *pic){
str = pic_get_output_string(pic, buf); str = pic_get_output_string(pic, buf);
if (pic_str_len(str) == 0 && c == EOF) { if (pic_str_len(str) == 0 && c == EOF) {
return pic_eof_object(); /* EOF */
} else {
res = pic_obj_value(str);
} }
else { pic_close_port(pic, buf);
return pic_obj_value(str); return res;
}
} }
static pic_value static pic_value