mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Add a buf1.closed field.
This commit is contained in:
1 parent
84e999c14e
commit
b3c12e05cf
9 files changed
+44
-29
No files matched your search
@@ -38,6 +38,7 @@ typedef struct {
|
||||
size_t len; // Length.
|
||||
size_t wi; // Write index. Invariant: wi <= len.
|
||||
size_t ri; // Read index. Invariant: ri <= wi.
|
||||
bool closed; // No further writes are expected.
|
||||
} puffs_base_buf1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
@@ -7,7 +7,7 @@ package main
|
||||
|
||||
const baseHeader = "" +
|
||||
"#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\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#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 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_buf1 is a 1-dimensional buffer (a pointer and length) plus\n// additional indexes into that buffer.\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} puffs_base_buf1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
||||
"\n\n// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length) plus\n// additional indexes into that buffer.\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#endif // PUFFS_BASE_HEADER_H\n" +
|
||||
""
|
||||
|
||||
const baseImpl = "" +
|
||||
|
||||
+13
-7
@@ -77,9 +77,10 @@ var builtInStatuses = [...]string{
|
||||
"error bad receiver",
|
||||
"error bad argument",
|
||||
"error constructor not called",
|
||||
"error unexpected EOF", // Used if read_foo passed final == true.
|
||||
"status short read", // Used if read_foo passed final == false.
|
||||
"error unexpected EOF", // Used if reading when closed == true.
|
||||
"status short read", // Used if reading when closed == false.
|
||||
"status short write",
|
||||
"error closed for writes",
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -945,11 +946,9 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
// TODO: delete these hacks that only matches "in.src.read_u8?()" etc.
|
||||
if isInSrcReadU8(g.tm, n) {
|
||||
// TODO: suspend coroutine state.
|
||||
//
|
||||
// TODO: choose error_unexpected_eof versus status_short_read based on
|
||||
// src_final.
|
||||
g.printf("if (%ssrc->ri >= %ssrc->wi) { status = puffs_%s_status_short_read;",
|
||||
aPrefix, aPrefix, g.pkgName)
|
||||
g.printf("if (%ssrc->ri >= %ssrc->wi) { status = "+
|
||||
"%ssrc->closed ? puffs_%s_error_unexpected_eof : puffs_%s_status_short_read;",
|
||||
aPrefix, aPrefix, aPrefix, g.pkgName, g.pkgName)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto cleanup0;")
|
||||
} else {
|
||||
@@ -965,6 +964,13 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
// TODO: suspend coroutine state.
|
||||
//
|
||||
// TODO: don't assume that the argument is "this.stack[s:]".
|
||||
g.printf("if (%sdst->closed) { status = puffs_%s_error_closed_for_writes;", aPrefix, g.pkgName)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto cleanup0;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
g.writes("}\n")
|
||||
g.printf("if ((%sdst->len - %sdst->wi) < (sizeof(self->private_impl.f_stack) - v_s)) {", aPrefix, aPrefix)
|
||||
g.printf("status = puffs_%s_status_short_write;", g.pkgName)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
|
||||
Reference in new issue
Block a user