diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-04-15 20:03:56 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-04-15 20:03:56 -0700 |
commit | f200086eff39c729cbdbb5dbdcb97b134f3fdd0d (patch) | |
tree | 66d1853e84c8ed28a6fff176eb401db8cb6d5372 | |
parent | 50b5651649f71c7f1e4c480504b61cea04d8f789 (diff) | |
download | txr-f200086eff39c729cbdbb5dbdcb97b134f3fdd0d.tar.gz txr-f200086eff39c729cbdbb5dbdcb97b134f3fdd0d.tar.bz2 txr-f200086eff39c729cbdbb5dbdcb97b134f3fdd0d.zip |
Close source files after parsing.
* eval.c (sys_load): close stream in all cases.
* match.c (v_load): Likewise.
* parser.c (load_rcfile): Close stream in unwind
block, if open.
* txr.c (txr_main): Close stream after parsing
in all cases. If stream is std_input, or a string stream,
close_stream does nothing.
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | match.c | 7 | ||||
-rw-r--r-- | parser.c | 5 | ||||
-rw-r--r-- | txr.c | 4 |
4 files changed, 17 insertions, 2 deletions
@@ -3261,15 +3261,18 @@ static val sys_load(val target, val sloc) open_txr_file(path, &txr_lisp_p, &name, &stream); if (!txr_lisp_p) { + close_stream(stream, nil); rlset(sloc, sloc); eval_error(sloc, lit("load doesn't process .txr files"), nao); } if (!read_eval_stream(stream, std_error, nil)) { rlset(sloc, sloc); + close_stream(stream, nil); eval_error(sloc, lit("load: ~s contains errors"), path, nao); } + close_stream(stream, nil); return nil; } @@ -3739,6 +3739,8 @@ static val v_load(match_files_ctx *c) parse_once(stream, name, &parser); gc_state(gc); + close_stream(stream, nil); + if (parser.errors) sem_error(specline, lit("~s: errors encountered in ~s"), sym, path, nao); @@ -3773,8 +3775,11 @@ static val v_load(match_files_ctx *c) } } } else { - if (!read_eval_stream(stream, std_error, nil)) + if (!read_eval_stream(stream, std_error, nil)){ + close_stream(stream, nil); sem_error(specline, lit("load: ~s contains errors"), path, nao); + } + close_stream(stream, nil); return (sym == include_s) ? nil : next_spec_k; } } @@ -426,7 +426,10 @@ static void load_rcfile(val name) format(std_output, lit("** details: ~a\n"), car(va), nao); } - uw_unwind; + uw_unwind { + if (stream) + close_stream(stream, nil); + } uw_catch_end; } @@ -831,6 +831,8 @@ int txr_main(int argc, char **argv) parse_once(parse_stream, spec_file_str, &parser); gc_state(gc); + close_stream(parse_stream, nil); + if (parser.errors) return EXIT_FAILURE; @@ -861,6 +863,8 @@ int txr_main(int argc, char **argv) { val result = read_eval_stream(parse_stream, std_error, t); + close_stream(parse_stream, nil); + if (!enter_repl) return result ? 0 : EXIT_FAILURE; } |