From 423366b14fec676bcd13f04659f91ad7b6512724 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 11 Oct 2022 07:52:20 -0700 Subject: put-json: restore indent on unwinding. The following situation is observed in the listener. 1> (put-json #H(() (a 1))) {** print: invalid object a in JSON ** during evaluation at expr-1:1 of form (put-json #H(() (a 1))) 1> 1> An indent established in the aborted JSON print job has been left in the stream. * lib.c (put_json): Save the indent value also, not only the mode. Restore the indent mode and value on unwinding, not just on a normal exit from out_json_rec, similiarly to what obj_print does. --- lib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index 07cae971..5feb7901 100644 --- a/lib.c +++ b/lib.c @@ -14658,8 +14658,14 @@ val put_json(val obj, val stream_in, val flat) set_indent_mode(stream, num_fast(indent_foff)), test_set_indent_mode(stream, num_fast(indent_off), num_fast(indent_data))); + val isave = get_indent(stream); + uw_simple_catch_begin; out_json_rec(obj, stream, 0); - set_indent_mode(stream, imode); + uw_unwind { + set_indent_mode(stream, imode); + set_indent(stream, isave); + } + uw_catch_end; return t; } -- cgit v1.2.3