Skip to content

Commit

Permalink
Have io_reader.match7 check io_reader.is_closed
Browse files Browse the repository at this point in the history
  • Loading branch information
nigeltao committed Feb 22, 2020
1 parent b1e3a15 commit b2dd7d9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
7 changes: 5 additions & 2 deletions internal/cgen/base/io-private.h
Expand Up @@ -176,7 +176,10 @@ wuffs_base__io_writer__copy_n32_from_slice(uint8_t** ptr_iop_w,
// - 1 means inconclusive, equivalent to "$short read".
// - 2 means failure.
static inline uint32_t //
wuffs_base__io_reader__match7(uint8_t* iop_r, uint8_t* io2_r, uint64_t a) {
wuffs_base__io_reader__match7(uint8_t* iop_r,
uint8_t* io2_r,
wuffs_base__io_buffer* r,
uint64_t a) {
uint32_t n = a & 7;
a >>= 8;
if ((io2_r - iop_r) >= 8) {
Expand All @@ -186,7 +189,7 @@ wuffs_base__io_reader__match7(uint8_t* iop_r, uint8_t* io2_r, uint64_t a) {
}
for (; n > 0; n--) {
if (iop_r >= io2_r) {
return 1;
return (r && r->meta.closed) ? 2 : 1;
} else if (*iop_r != ((uint8_t)(a))) {
return 2;
}
Expand Down
3 changes: 2 additions & 1 deletion internal/cgen/builtin.go
Expand Up @@ -169,7 +169,8 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
return nil

case t.IDMatch7:
b.printf("wuffs_base__io_reader__match7(%s%s, %s%s,", iopPrefix, name, io2Prefix, name)
b.printf("wuffs_base__io_reader__match7(%s%s, %s%s, %s,",
iopPrefix, name, io2Prefix, name, name)
if err := g.writeExpr(b, args[0].AsArg().Value(), depth); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cgen/data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions release/c/wuffs-unsupported-snapshot.c
Expand Up @@ -6347,7 +6347,10 @@ wuffs_base__io_writer__copy_n32_from_slice(uint8_t** ptr_iop_w,
// - 1 means inconclusive, equivalent to "$short read".
// - 2 means failure.
static inline uint32_t //
wuffs_base__io_reader__match7(uint8_t* iop_r, uint8_t* io2_r, uint64_t a) {
wuffs_base__io_reader__match7(uint8_t* iop_r,
uint8_t* io2_r,
wuffs_base__io_buffer* r,
uint64_t a) {
uint32_t n = a & 7;
a >>= 8;
if ((io2_r - iop_r) >= 8) {
Expand All @@ -6357,7 +6360,7 @@ wuffs_base__io_reader__match7(uint8_t* iop_r, uint8_t* io2_r, uint64_t a) {
}
for (; n > 0; n--) {
if (iop_r >= io2_r) {
return 1;
return (r && r->meta.closed) ? 2 : 1;
} else if (*iop_r != ((uint8_t)(a))) {
return 2;
}
Expand Down Expand Up @@ -19056,7 +19059,7 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
}
goto label_0_continue;
} else if (v_class == 9) {
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src,
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src, a_src,
111546413966853);
if (v_match == 0) {
*iop_a_dst++ = wuffs_base__make_token(
Expand All @@ -19076,8 +19079,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
goto label_0_continue;
}
} else if (v_class == 10) {
v_match =
wuffs_base__io_reader__match7(iop_a_src, io2_a_src, 435762131972);
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src, a_src,
435762131972);
if (v_match == 0) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(4194433)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
Expand All @@ -19096,8 +19099,8 @@ wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
goto label_0_continue;
}
} else if (v_class == 11) {
v_match =
wuffs_base__io_reader__match7(iop_a_src, io2_a_src, 465676103172);
v_match = wuffs_base__io_reader__match7(iop_a_src, io2_a_src, a_src,
465676103172);
if (v_match == 0) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(4194337)) << WUFFS_BASE__TOKEN__VALUE__SHIFT) |
Expand Down

0 comments on commit b2dd7d9

Please sign in to comment.