From 5a93c63f0a63689076f24844aae6326470a60f06 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 25 Jan 2022 21:24:54 +1100 Subject: [PATCH] Tweak json.decoder.decode_comment --- release/c/wuffs-unsupported-snapshot.c | 30 ++++++++++--------- std/json/decode_json.wuffs | 40 +++++++++++++++++--------- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 2683704c..eaaae5fe 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -34094,12 +34094,6 @@ wuffs_json__decoder__decode_comment( v_length = 2; label__comment_block__continue:; while (true) { - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); - v_length = 0; - goto label__comment_block__continue; - } while (true) { if (((uint64_t)(io2_a_src - iop_a_src)) <= 1) { if (v_length > 0) { @@ -34113,7 +34107,11 @@ wuffs_json__decoder__decode_comment( goto exit; } status = wuffs_base__make_status(wuffs_base__suspension__short_read); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); + while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4); + } v_length = 0; goto label__comment_block__continue; } @@ -34133,6 +34131,10 @@ wuffs_json__decoder__decode_comment( (((uint64_t)(2)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | (((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); + } v_length = 0; goto label__comment_block__continue; } @@ -34144,12 +34146,6 @@ wuffs_json__decoder__decode_comment( v_length = 2; label__comment_line__continue:; while (true) { - if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) { - status = wuffs_base__make_status(wuffs_base__suspension__short_write); - WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5); - v_length = 0; - goto label__comment_line__continue; - } while (true) { if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) { if (a_src && a_src->meta.closed) { @@ -34167,6 +34163,10 @@ wuffs_json__decoder__decode_comment( } status = wuffs_base__make_status(wuffs_base__suspension__short_read); WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); + while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7); + } v_length = 0; goto label__comment_line__continue; } @@ -34185,6 +34185,10 @@ wuffs_json__decoder__decode_comment( (((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) | (((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) | (((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT)); + while (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) { + status = wuffs_base__make_status(wuffs_base__suspension__short_write); + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); + } v_length = 0; goto label__comment_line__continue; } diff --git a/std/json/decode_json.wuffs b/std/json/decode_json.wuffs index 8cf70374..f7b38916 100644 --- a/std/json/decode_json.wuffs +++ b/std/json/decode_json.wuffs @@ -1441,13 +1441,9 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) { args.src.skip_u32_fast!(actual: 2, worst_case: 2) length = 2 - while.comment_block true { - if args.dst.length() <= 0 { - yield? base."$short write" - length = 0 - continue.comment_block - } - + while.comment_block true, + pre args.dst.length() > 0, + { while true, pre args.dst.length() > 0, { @@ -1464,6 +1460,11 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) { return "#bad input" } yield? base."$short read" + while args.dst.length() <= 0, + post args.dst.length() > 0, + { + yield? base."$short write" + } endwhile length = 0 continue.comment_block } @@ -1489,6 +1490,11 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) { base.TOKEN__VBD__FILLER__COMMENT_BLOCK, continued: 1, length: length + 1) + while args.dst.length() <= 0, + post args.dst.length() > 0, + { + yield? base."$short write" + } endwhile length = 0 continue.comment_block } @@ -1500,13 +1506,9 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) { args.src.skip_u32_fast!(actual: 2, worst_case: 2) length = 2 - while.comment_line true { - if args.dst.length() <= 0 { - yield? base."$short write" - length = 0 - continue.comment_line - } - + while.comment_line true, + pre args.dst.length() > 0, + { while true, pre args.dst.length() > 0, { @@ -1529,6 +1531,11 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) { length: length) } yield? base."$short read" + while args.dst.length() <= 0, + post args.dst.length() > 0, + { + yield? base."$short write" + } endwhile length = 0 continue.comment_line } @@ -1553,6 +1560,11 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) { base.TOKEN__VBD__FILLER__COMMENT_LINE, continued: 1, length: length + 1) + while args.dst.length() <= 0, + post args.dst.length() > 0, + { + yield? base."$short write" + } endwhile length = 0 continue.comment_line }