make sure we always close intermediate memory streams on exit.

This commit is contained in:
Vitor Santos Costa 2008-08-25 15:19:00 +01:00
parent 7a94144ccb
commit a6b9d096a6
2 changed files with 5 additions and 2 deletions

View File

@ -5371,6 +5371,8 @@ p_format2(void)
CloseStream(stream);
if (!Yap_unify(tat,ArgOfTerm(1,ARG1)))
return FALSE;
} else {
CloseStream(stream);
}
} else {
Yap_c_output_stream = old_c_stream;

View File

@ -1055,15 +1055,16 @@ current_stream(File, Opts, Stream) :-
catch(Goal, Exception, '$handle_exception'(Exception,Stream,SO)),
!,
set_output(SO),
charsio:peek_mem_write_stream(Stream, L0, Chars).
charsio:peek_mem_write_stream(Stream, L0, Chars),
close(Stream).
'$do_output_to_chars'(_Goal, Stream, _L0, _Chars, SO) :-
set_output(SO),
close(Stream),
fail.
'$handle_exception'(Exception, Stream, SO) :-
set_output(SO),
close(Stream),
current_output(SO),
throw(Exception).
write_depth(T,L) :- write_depth(T,L,_).