From 45cecca79a95013e74a4eeccafaa06e5e316963f Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 6 Jun 2017 17:29:50 +1000 Subject: [PATCH] Rename buf1's cap to len. --- cmd/puffs-gen-c/base-header.h | 6 +++--- cmd/puffs-gen-c/data.go | 2 +- gen/c/gif.c | 6 +++--- gen/h/gif.h | 6 +++--- test/c/gif/lzw.c | 4 ++-- test/c/testlib/testlib.c | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/puffs-gen-c/base-header.h b/cmd/puffs-gen-c/base-header.h index bb30de11..2c65e9fc 100644 --- a/cmd/puffs-gen-c/base-header.h +++ b/cmd/puffs-gen-c/base-header.h @@ -29,14 +29,14 @@ // TODO: don't hard code this in base-header.h. #define PUFFS_VERSION (0x00001) -// puffs_base_buf1 is a 1-dimensional buffer (a pointer and capacity) plus +// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length) plus // additional indexes into that buffer. // // A value with all fields NULL or zero is a valid, empty buffer. typedef struct { uint8_t* ptr; // Pointer. - size_t cap; // Capacity. - size_t wi; // Write index. Invariant: wi <= cap. + size_t len; // Length. + size_t wi; // Write index. Invariant: wi <= len. size_t ri; // Read index. Invariant: ri <= wi. } puffs_base_buf1; diff --git a/cmd/puffs-gen-c/data.go b/cmd/puffs-gen-c/data.go index 1924b0b4..3fd347a1 100644 --- a/cmd/puffs-gen-c/data.go +++ b/cmd/puffs-gen-c/data.go @@ -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 \n#include \n#include \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 capacity) 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 cap; // Capacity.\n size_t wi; // Write index. Invariant: wi <= cap.\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} puffs_base_buf1;\n\n#endif // PUFFS_BASE_HEADER_H\n" + "" const baseImpl = "" + diff --git a/gen/c/gif.c b/gen/c/gif.c index b7582877..69ce5a1b 100644 --- a/gen/c/gif.c +++ b/gen/c/gif.c @@ -32,14 +32,14 @@ // TODO: don't hard code this in base-header.h. #define PUFFS_VERSION (0x00001) -// puffs_base_buf1 is a 1-dimensional buffer (a pointer and capacity) plus +// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length) plus // additional indexes into that buffer. // // A value with all fields NULL or zero is a valid, empty buffer. typedef struct { uint8_t* ptr; // Pointer. - size_t cap; // Capacity. - size_t wi; // Write index. Invariant: wi <= cap. + size_t len; // Length. + size_t wi; // Write index. Invariant: wi <= len. size_t ri; // Read index. Invariant: ri <= wi. } puffs_base_buf1; diff --git a/gen/h/gif.h b/gen/h/gif.h index 58607698..e8e6cae3 100644 --- a/gen/h/gif.h +++ b/gen/h/gif.h @@ -32,14 +32,14 @@ // TODO: don't hard code this in base-header.h. #define PUFFS_VERSION (0x00001) -// puffs_base_buf1 is a 1-dimensional buffer (a pointer and capacity) plus +// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length) plus // additional indexes into that buffer. // // A value with all fields NULL or zero is a valid, empty buffer. typedef struct { uint8_t* ptr; // Pointer. - size_t cap; // Capacity. - size_t wi; // Write index. Invariant: wi <= cap. + size_t len; // Length. + size_t wi; // Write index. Invariant: wi <= len. size_t ri; // Read index. Invariant: ri <= wi. } puffs_base_buf1; diff --git a/test/c/gif/lzw.c b/test/c/gif/lzw.c index 5bc97860..4529da57 100644 --- a/test/c/gif/lzw.c +++ b/test/c/gif/lzw.c @@ -23,8 +23,8 @@ uint8_t global_dst_buffer[BUFFER_SIZE]; uint8_t global_src_buffer[BUFFER_SIZE]; void test_lzw_decode() { - puffs_base_buf1 dst = {.ptr = global_dst_buffer, .cap = BUFFER_SIZE}; - puffs_base_buf1 src = {.ptr = global_src_buffer, .cap = BUFFER_SIZE}; + puffs_base_buf1 dst = {.ptr = global_dst_buffer, .len = BUFFER_SIZE}; + puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE}; if (!read_file(&src, "../../testdata/bricks-nodither.giflzw")) { goto cleanup0; } diff --git a/test/c/testlib/testlib.c b/test/c/testlib/testlib.c index 9b63c597..8a018f3d 100644 --- a/test/c/testlib/testlib.c +++ b/test/c/testlib/testlib.c @@ -50,11 +50,11 @@ bool read_file(puffs_base_buf1* dst, const char* path) { return false; } uint8_t* ptr = dst->ptr + dst->wi; - size_t cap = dst->cap - dst->wi; + size_t len = dst->len - dst->wi; while (true) { - size_t n = fread(ptr, 1, cap, f); + size_t n = fread(ptr, 1, len, f); ptr += n; - cap -= n; + len -= n; dst->wi += n; if (feof(f)) { break;