summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-10-11 07:52:20 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-10-11 07:52:20 -0700
commit423366b14fec676bcd13f04659f91ad7b6512724 (patch)
treecaaa8168dddb08df6e4203aafec77340c47ae5ee
parentf747dab7d4a90b6370faee33290df27dd03f863e (diff)
downloadtxr-423366b14fec676bcd13f04659f91ad7b6512724.tar.gz
txr-423366b14fec676bcd13f04659f91ad7b6512724.tar.bz2
txr-423366b14fec676bcd13f04659f91ad7b6512724.zip
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.
-rw-r--r--lib.c8
1 files changed, 7 insertions, 1 deletions
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;
}