mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 00:38:14 +01:00
Remove the obsolete puffs_base__limit1 concept.
This commit is contained in:
1 parent
e0836d73a8
commit
3485950a3f
10 files changed
+17
-443
No files matched your search
@@ -65,20 +65,8 @@ typedef struct {
|
||||
bool closed; // No further writes are expected.
|
||||
} puffs_base__buf1;
|
||||
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// its first N bytes. That N can be greater than a buffer's current read or
|
||||
// write capacity. N decreases naturally over time as bytes are read from or
|
||||
// written to the stream.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, unlimited view.
|
||||
typedef struct puffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit; // TODO: delete.
|
||||
uint64_t limitt; // TODO: should this be uint8_t*, not (uint64_t + bool)?
|
||||
bool use_limitt;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
@@ -90,7 +78,6 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit; // TODO: delete.
|
||||
uint64_t limitt; // TODO: should this be uint8_t*, not (uint64_t + bool)?
|
||||
bool use_limitt;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
|
||||
@@ -19,8 +19,8 @@ package cgen
|
||||
const baseHeader = "" +
|
||||
"#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Copyright 2017 The Puffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <string.h>\n\n// Puffs requires a word size of at least 32 bits because it assumes that\n// converting a u32 to usize will never overflow. For example, the size of a\n// decoded image is often represented, explicitly or implicitly in an image\n// file, as a u32, and it is convenient to compare that to a buffer size.\n//\n// Si" +
|
||||
"milarly, the word size is at most 64 bits because it assumes that\n// converting a usize to u64 will never overflow.\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#elif __WORDSIZE > 64\n#error \"Puffs requires a word size of at most 64 bits\"\n#endif\n\n// PUFFS_VERSION is the major.minor version number as a uint32. The major\n// number is the high 16 bits. The minor number is the low 16 bits.\n//\n// The intention is to bump the version number at least on every API / ABI\n// backwards incompatible change.\n//\n// For now, the API and ABI are simply unstable and can change at any time.\n//\n// TODO: don't hard code this in base-header.h.\n#define PUFFS_VERSION (0x00001)\n\n// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).\n//\n// A value with all fields NULL or zero is a valid, empty slice.\ntypedef struct {\n uint8_t* ptr;\n size_t len;\n} puffs_base__slice_u8;\n\n// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, p" +
|
||||
"lus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} puffs_base__buf1;\n\n// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:\n// its first N bytes. That N can be greater than a buffer's current read or\n// write capacity. N decreases naturally over time as bytes are read from or\n// written to the stream.\n//\n// A value with all fields NULL or zero is a valid, unlimited view.\ntypedef struct puffs_base__limit1 {\n uint64_t* ptr_to_len; // Pointer to N.\n struct puffs_base__limit1* next; // Linked list of limits.\n} puffs_base__limit1;\n\ntypedef struct {\n puffs_base__buf1* buf;\n puffs_base__limit1 limit; // TODO: delete.\n uint64_t limitt; // TODO: should this be uint8_t*, not (uint64_t + bool)?\n b" +
|
||||
"ool use_limitt;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* mark;\n } private_impl;\n} puffs_base__reader1;\n\ntypedef struct {\n puffs_base__buf1* buf;\n puffs_base__limit1 limit; // TODO: delete.\n uint64_t limitt; // TODO: should this be uint8_t*, not (uint64_t + bool)?\n bool use_limitt;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* mark;\n } private_impl;\n} puffs_base__writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
||||
"lus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} puffs_base__buf1;\n\ntypedef struct {\n puffs_base__buf1* buf;\n uint64_t limitt; // TODO: should this be uint8_t*, not (uint64_t + bool)?\n bool use_limitt;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* mark;\n } private_impl;\n} puffs_base__reader1;\n\ntypedef struct {\n puffs_base__buf1* buf;\n uint64_t limitt; // TODO: should this be uint8_t*, not (uint64_t + bool)?\n bool use_limitt;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* mark;\n } private_impl;\n} puffs_base__writ" +
|
||||
"er1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
||||
""
|
||||
|
||||
const baseImpl = "" +
|
||||
@@ -42,8 +42,7 @@ type template_args_short_read struct {
|
||||
}
|
||||
|
||||
func template_short_read(b *buffer, args template_args_short_read) error {
|
||||
b.printf("short_read_%s:\nif (a_%s.buf && a_%s.buf->closed && !a_%s.limit.ptr_to_len &&\n!a_%s.use_limitt) {\nstatus = %sERROR_UNEXPECTED_EOF;\ngoto exit;\n}\nstatus = %sSUSPENSION_SHORT_READ;\ngoto suspend;\n",
|
||||
args.name,
|
||||
b.printf("short_read_%s:\nif (a_%s.buf && a_%s.buf->closed && !a_%s.use_limitt) {\nstatus = %sERROR_UNEXPECTED_EOF;\ngoto exit;\n}\nstatus = %sSUSPENSION_SHORT_READ;\ngoto suspend;\n",
|
||||
args.name,
|
||||
args.name,
|
||||
args.name,
|
||||
|
||||
@@ -416,15 +416,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
|
||||
case t.KeyLimit:
|
||||
// TODO: don't hard code so much detail.
|
||||
b.writes("(puffs_base__reader1) {")
|
||||
b.writes(".buf = a_src.buf,")
|
||||
b.writes(".limit = (puffs_base__limit1) {")
|
||||
b.printf(".ptr_to_len = &%s%s,", lPrefix, g.currFunk.limitVarName)
|
||||
b.writes(".next = &a_src.limit,")
|
||||
b.writes("}}")
|
||||
g.currFunk.limitVarName = ""
|
||||
return nil
|
||||
panic("TODO: delete t.KeyLimit")
|
||||
}
|
||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther", n.ID0().Key())
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ type funk struct {
|
||||
public bool
|
||||
suspendible bool
|
||||
usesScratch bool
|
||||
limitVarName string
|
||||
limitVarName string // TODO: delete.
|
||||
shortReads []string
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
|
||||
template short_read(string qPKGPREFIXq, string qnameq) {
|
||||
short_read_qnameq:
|
||||
if (a_qnameq.buf && a_qnameq.buf->closed && !a_qnameq.limit.ptr_to_len &&
|
||||
!a_qnameq.use_limitt) {
|
||||
if (a_qnameq.buf && a_qnameq.buf->closed && !a_qnameq.use_limitt) {
|
||||
status = qPKGPREFIXqERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -103,10 +103,6 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
|
||||
b.printf("uint64_t len = %s%s.buf->wi - %s%s.buf->ri;", aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("if (%s%s.use_limitt && (len > %s%s.limitt)) { len = %s%s.limitt; }",
|
||||
aPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("puffs_base__limit1* lim;")
|
||||
b.printf("for (lim = &%s%s.limit; lim; lim = lim->next) {", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len && (len > *lim->ptr_to_len)) { len = *lim->ptr_to_len; }")
|
||||
b.printf("}")
|
||||
b.printf("%srend_%s = %srptr_%s + len;", bPrefix, nameStr, bPrefix, nameStr)
|
||||
|
||||
b.printf("}\n")
|
||||
@@ -125,10 +121,6 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
|
||||
b.printf("uint64_t len = %s%s.buf->len - %s%s.buf->wi;", aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("if (%s%s.use_limitt && (len > %s%s.limitt)) { len = %s%s.limitt; }",
|
||||
aPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("puffs_base__limit1* lim;")
|
||||
b.printf("for (lim = &%s%s.limit; lim; lim = lim->next) {", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len && (len > *lim->ptr_to_len)) { len = *lim->ptr_to_len; }")
|
||||
b.printf("}")
|
||||
b.printf("%swend_%s += len;", bPrefix, nameStr)
|
||||
b.printf("}\n")
|
||||
|
||||
@@ -160,10 +152,6 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
b.printf("%s%s.buf->ri += n;", aPrefix, nameStr)
|
||||
// TODO: Should limitt be a uint8_t*, not a uint64_t?
|
||||
b.printf("if (%s%s.use_limitt) { %s%s.limitt -= n; }", aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("puffs_base__limit1* lim;")
|
||||
b.printf("for (lim = &%s%s.limit; lim; lim = lim->next) {", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len) { *lim->ptr_to_len -= n; }")
|
||||
b.printf("}")
|
||||
|
||||
if footer {
|
||||
b.printf("PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%srend_%s);", bPrefix, nameStr)
|
||||
@@ -179,10 +167,6 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
b.printf("%s%s.buf->wi += n;", aPrefix, nameStr)
|
||||
// TODO: Should limitt be a uint8_t*, not a uint64_t?
|
||||
b.printf("if (%s%s.use_limitt) { %s%s.limitt -= n; }", aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("puffs_base__limit1* lim;")
|
||||
b.printf("for (lim = &%s%s.limit; lim; lim = lim->next) {", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len) { *lim->ptr_to_len -= n; }")
|
||||
b.printf("}")
|
||||
|
||||
if footer {
|
||||
b.printf("PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%swend_%s);", bPrefix, nameStr)
|
||||
|
||||
Reference in new issue
Block a user