mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Add reader1.mark and reader1.since_mark methods.
This commit is contained in:
1 parent
15ded0a6d0
commit
b886e3a1ea
7 files changed
+73
-17
No files matched your search
@@ -168,10 +168,14 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
|||||||
b.writes(")")
|
b.writes(")")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if isInDst(g.tm, n, t.KeySinceMark, 0) {
|
if isInSrc(g.tm, n, t.KeyMark, 0) {
|
||||||
|
b.printf("puffs_base__reader1__mark(&%ssrc, %srptr_src)", aPrefix, bPrefix)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if isInSrc(g.tm, n, t.KeySinceMark, 0) {
|
||||||
b.printf("((puffs_base__slice_u8){ "+
|
b.printf("((puffs_base__slice_u8){ "+
|
||||||
".ptr = %sdst.private_impl.mark, "+
|
".ptr = %ssrc.private_impl.mark, "+
|
||||||
".len = %sdst.private_impl.mark ? %swptr_dst - %sdst.private_impl.mark : 0, })",
|
".len = %ssrc.private_impl.mark ? %srptr_src - %ssrc.private_impl.mark : 0, })",
|
||||||
aPrefix, aPrefix, bPrefix, aPrefix)
|
aPrefix, aPrefix, bPrefix, aPrefix)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -183,6 +187,13 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
|||||||
b.printf("puffs_base__writer1__mark(&%sdst, %swptr_dst)", aPrefix, bPrefix)
|
b.printf("puffs_base__writer1__mark(&%sdst, %swptr_dst)", aPrefix, bPrefix)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if isInDst(g.tm, n, t.KeySinceMark, 0) {
|
||||||
|
b.printf("((puffs_base__slice_u8){ "+
|
||||||
|
".ptr = %sdst.private_impl.mark, "+
|
||||||
|
".len = %sdst.private_impl.mark ? %swptr_dst - %sdst.private_impl.mark : 0, })",
|
||||||
|
aPrefix, aPrefix, bPrefix, aPrefix)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if isInDst(g.tm, n, t.KeyCopyFromReader32, 2) {
|
if isInDst(g.tm, n, t.KeyCopyFromReader32, 2) {
|
||||||
b.printf("puffs_base__writer1__copy_from_reader32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
b.printf("puffs_base__writer1__copy_from_reader32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
||||||
// TODO: don't assume that the first argument is "in.src".
|
// TODO: don't assume that the first argument is "in.src".
|
||||||
|
|||||||
@@ -675,7 +675,9 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != nArgs {
|
callSuspendible := methodName != t.KeySinceMark &&
|
||||||
|
methodName != t.KeyMark
|
||||||
|
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
|
|||||||
+30
-5
@@ -133,10 +133,12 @@ typedef int32_t puffs_gif__status;
|
|||||||
#define PUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
|
#define PUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
|
||||||
#define PUFFS_GIF__ERROR_BAD_GIF_HEADER -1105848318 // 0xbe161802
|
#define PUFFS_GIF__ERROR_BAD_GIF_HEADER -1105848318 // 0xbe161802
|
||||||
#define PUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH -1105848317 // 0xbe161803
|
#define PUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH -1105848317 // 0xbe161803
|
||||||
|
#define PUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ \
|
||||||
|
-1105848316 // 0xbe161804
|
||||||
#define PUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE \
|
#define PUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE \
|
||||||
-1105848316 // 0xbe161804
|
-1105848315 // 0xbe161805
|
||||||
#define PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE -1105848315 // 0xbe161805
|
#define PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE -1105848314 // 0xbe161806
|
||||||
#define PUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL -1105848314 // 0xbe161806
|
#define PUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL -1105848313 // 0xbe161807
|
||||||
|
|
||||||
bool puffs_gif__status__is_error(puffs_gif__status s);
|
bool puffs_gif__status__is_error(puffs_gif__status s);
|
||||||
|
|
||||||
@@ -581,11 +583,12 @@ const char* puffs_gif__status__strings0[9] = {
|
|||||||
"gif: short write",
|
"gif: short write",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* puffs_gif__status__strings1[7] = {
|
const char* puffs_gif__status__strings1[8] = {
|
||||||
"gif: bad GIF block",
|
"gif: bad GIF block",
|
||||||
"gif: bad GIF extension label",
|
"gif: bad GIF extension label",
|
||||||
"gif: bad GIF header",
|
"gif: bad GIF header",
|
||||||
"gif: bad LZW literal width",
|
"gif: bad LZW literal width",
|
||||||
|
"gif: internal error: inconsistent limited read",
|
||||||
"gif: TODO: unsupported Local Color Table",
|
"gif: TODO: unsupported Local Color Table",
|
||||||
"gif: LZW code is out of range",
|
"gif: LZW code is out of range",
|
||||||
"gif: LZW prefix chain is cyclical",
|
"gif: LZW prefix chain is cyclical",
|
||||||
@@ -601,7 +604,7 @@ const char* puffs_gif__status__string(puffs_gif__status s) {
|
|||||||
break;
|
break;
|
||||||
case puffs_gif__packageid:
|
case puffs_gif__packageid:
|
||||||
a = puffs_gif__status__strings1;
|
a = puffs_gif__status__strings1;
|
||||||
n = 7;
|
n = 8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint32_t i = s & 0xff;
|
uint32_t i = s & 0xff;
|
||||||
@@ -1242,6 +1245,7 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
|||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
|
puffs_base__reader1__mark(&a_src, b_rptr_src);
|
||||||
l_lzw_src = v_block_size;
|
l_lzw_src = v_block_size;
|
||||||
v_lzw_src = (puffs_base__reader1){.buf = a_src.buf,
|
v_lzw_src = (puffs_base__reader1){.buf = a_src.buf,
|
||||||
.limit = (puffs_base__limit1){
|
.limit = (puffs_base__limit1){
|
||||||
@@ -1275,6 +1279,27 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
|||||||
if (l_lzw_src && status) {
|
if (l_lzw_src && status) {
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
if (v_block_size <
|
||||||
|
((uint64_t)(((puffs_base__slice_u8){
|
||||||
|
.ptr = a_src.private_impl.mark,
|
||||||
|
.len = a_src.private_impl.mark
|
||||||
|
? b_rptr_src - a_src.private_impl.mark
|
||||||
|
: 0,
|
||||||
|
})
|
||||||
|
.len))) {
|
||||||
|
status = PUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
v_block_size -=
|
||||||
|
((uint64_t)(((puffs_base__slice_u8){
|
||||||
|
.ptr = a_src.private_impl.mark,
|
||||||
|
.len = a_src.private_impl.mark
|
||||||
|
? b_rptr_src - a_src.private_impl.mark
|
||||||
|
: 0,
|
||||||
|
})
|
||||||
|
.len));
|
||||||
|
if (v_block_size == 0) {
|
||||||
|
}
|
||||||
goto label_1_break;
|
goto label_1_break;
|
||||||
}
|
}
|
||||||
label_1_break:;
|
label_1_break:;
|
||||||
|
|||||||
+5
-3
@@ -133,10 +133,12 @@ typedef int32_t puffs_gif__status;
|
|||||||
#define PUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
|
#define PUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
|
||||||
#define PUFFS_GIF__ERROR_BAD_GIF_HEADER -1105848318 // 0xbe161802
|
#define PUFFS_GIF__ERROR_BAD_GIF_HEADER -1105848318 // 0xbe161802
|
||||||
#define PUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH -1105848317 // 0xbe161803
|
#define PUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH -1105848317 // 0xbe161803
|
||||||
|
#define PUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ \
|
||||||
|
-1105848316 // 0xbe161804
|
||||||
#define PUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE \
|
#define PUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE \
|
||||||
-1105848316 // 0xbe161804
|
-1105848315 // 0xbe161805
|
||||||
#define PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE -1105848315 // 0xbe161805
|
#define PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE -1105848314 // 0xbe161806
|
||||||
#define PUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL -1105848314 // 0xbe161806
|
#define PUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL -1105848313 // 0xbe161807
|
||||||
|
|
||||||
bool puffs_gif__status__is_error(puffs_gif__status s);
|
bool puffs_gif__status__is_error(puffs_gif__status s);
|
||||||
|
|
||||||
|
|||||||
@@ -720,7 +720,8 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
|||||||
if isInSrc(q.tm, n, t.KeyReadU8, 0) ||
|
if isInSrc(q.tm, n, t.KeyReadU8, 0) ||
|
||||||
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
|
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
|
||||||
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
|
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
|
||||||
isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
isInSrc(q.tm, n, t.KeySkip32, 1) || isInSrc(q.tm, n, t.KeySinceMark, 0) ||
|
||||||
|
isInSrc(q.tm, n, t.KeyMark, 0) ||
|
||||||
isInDst(q.tm, n, t.KeyCopyFromSlice, 1) || isInDst(q.tm, n, t.KeyCopyFromSlice32, 2) ||
|
isInDst(q.tm, n, t.KeyCopyFromSlice, 1) || isInDst(q.tm, n, t.KeyCopyFromSlice32, 2) ||
|
||||||
isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) ||
|
isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) ||
|
||||||
isInDst(q.tm, n, t.KeyWriteU8, 1) || isInDst(q.tm, n, t.KeySinceMark, 0) ||
|
isInDst(q.tm, n, t.KeyWriteU8, 1) || isInDst(q.tm, n, t.KeySinceMark, 0) ||
|
||||||
|
|||||||
+6
-3
@@ -438,7 +438,8 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
if isInSrc(q.tm, n, t.KeyReadU8, 0) ||
|
if isInSrc(q.tm, n, t.KeyReadU8, 0) ||
|
||||||
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
|
isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU32BE, 0) ||
|
||||||
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
|
isInSrc(q.tm, n, t.KeyReadU32BE, 0) || isInSrc(q.tm, n, t.KeyReadU32LE, 0) ||
|
||||||
isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
isInSrc(q.tm, n, t.KeySkip32, 1) || isInSrc(q.tm, n, t.KeySinceMark, 0) ||
|
||||||
|
isInSrc(q.tm, n, t.KeyMark, 0) ||
|
||||||
isInDst(q.tm, n, t.KeyCopyFromSlice, 1) || isInDst(q.tm, n, t.KeyCopyFromSlice32, 2) ||
|
isInDst(q.tm, n, t.KeyCopyFromSlice, 1) || isInDst(q.tm, n, t.KeyCopyFromSlice32, 2) ||
|
||||||
isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) ||
|
isInDst(q.tm, n, t.KeyCopyFromReader32, 2) || isInDst(q.tm, n, t.KeyCopyFromHistory32, 2) ||
|
||||||
isInDst(q.tm, n, t.KeyWriteU8, 1) || isInDst(q.tm, n, t.KeySinceMark, 0) ||
|
isInDst(q.tm, n, t.KeyWriteU8, 1) || isInDst(q.tm, n, t.KeySinceMark, 0) ||
|
||||||
@@ -464,7 +465,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
n.SetMType(typeExprPlaceholder32) // HACK.
|
n.SetMType(typeExprPlaceholder32) // HACK.
|
||||||
} else if isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU16LE, 0) {
|
} else if isInSrc(q.tm, n, t.KeyReadU16BE, 0) || isInSrc(q.tm, n, t.KeyReadU16LE, 0) {
|
||||||
n.SetMType(typeExprPlaceholder16) // HACK.
|
n.SetMType(typeExprPlaceholder16) // HACK.
|
||||||
} else if isInDst(q.tm, n, t.KeySinceMark, 0) {
|
} else if isInSrc(q.tm, n, t.KeySinceMark, 0) || isInDst(q.tm, n, t.KeySinceMark, 0) {
|
||||||
n.SetMType(typeExprSliceU8) // HACK.
|
n.SetMType(typeExprSliceU8) // HACK.
|
||||||
} else if isInDst(q.tm, n, t.KeyCopyFromSlice, 1) {
|
} else if isInDst(q.tm, n, t.KeyCopyFromSlice, 1) {
|
||||||
n.SetMType(typeExprU64) // HACK.
|
n.SetMType(typeExprU64) // HACK.
|
||||||
@@ -692,7 +693,9 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != nArgs {
|
callSuspendible := methodName != t.KeySinceMark &&
|
||||||
|
methodName != t.KeyMark
|
||||||
|
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ pub error "bad GIF extension label"
|
|||||||
pub error "bad GIF header"
|
pub error "bad GIF header"
|
||||||
pub error "bad LZW literal width"
|
pub error "bad LZW literal width"
|
||||||
|
|
||||||
|
pub error "internal error: inconsistent limited read"
|
||||||
|
|
||||||
pub error "TODO: unsupported Local Color Table"
|
pub error "TODO: unsupported Local Color Table"
|
||||||
|
|
||||||
pub struct decoder?(
|
pub struct decoder?(
|
||||||
@@ -161,13 +163,23 @@ pri func decoder.decode_id?(dst writer1, src reader1)() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
while true {
|
while true {
|
||||||
|
in.src.mark()
|
||||||
// TODO: how should this reader1-typed variable (which is implemented
|
// TODO: how should this reader1-typed variable (which is implemented
|
||||||
// by containing pointers) work across resume/suspend? We don't want to
|
// by containing pointers) work across resume/suspend? We don't want to
|
||||||
// have a dangling pointer to an earlier src buffer.
|
// have a dangling pointer to an earlier src buffer.
|
||||||
var lzw_src reader1 = limit (block_size) in.src
|
var lzw_src reader1 = limit (block_size) in.src
|
||||||
this.lzw.decode?(dst:in.dst, src:lzw_src)
|
this.lzw.decode?(dst:in.dst, src:lzw_src)
|
||||||
|
|
||||||
// TODO: add a "try" to the line above, and break *conditionally*.
|
if block_size < in.src.since_mark().length() {
|
||||||
|
return error "internal error: inconsistent limited read"
|
||||||
|
}
|
||||||
|
block_size -= in.src.since_mark().length()
|
||||||
|
if block_size == 0 {
|
||||||
|
// TODO: examine the this.lzw.decode? status.
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add a "try" to the this.lzw.decode? line above, and break
|
||||||
|
// *conditionally*.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user