mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bfaf0f008 | ||
|
|
b9a10d051a | ||
|
|
7f93a94e7a | ||
|
|
a0698fc1a2 | ||
|
|
d8796aa6d9 | ||
|
|
a12771373e | ||
|
|
c90cc7b657 | ||
|
|
b2b8961126 | ||
|
|
f6945c0612 | ||
|
|
76e6872498 |
No files matched your search
@@ -39,3 +39,4 @@ Leo Neat <lneat@google.com>
|
||||
Mike Kaufman <mkaufman@microsoft.com>
|
||||
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
|
||||
Nigel Tao <nigeltao@golang.org>
|
||||
Peter Kasting <pkasting@chromium.org>
|
||||
@@ -167,6 +167,9 @@ const grSingleFileGuidance = `
|
||||
const grPragmaPush = `
|
||||
// Wuffs' C code is generated automatically, not hand-written. These warnings'
|
||||
// costs outweigh the benefits.
|
||||
//
|
||||
// The "elif defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
@@ -176,6 +179,15 @@ const grPragmaPush = `
|
||||
#if defined(__cplusplus)
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma clang diagnostic ignored "-Wunreachable-code"
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#if defined(__cplusplus)
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
`
|
||||
@@ -183,6 +195,8 @@ const grPragmaPush = `
|
||||
const grPragmaPop = `
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
`
|
||||
|
||||
@@ -66,7 +66,7 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_base__status status = wuffs_bmp__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
hash >>= 1;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
+12
-11
@@ -221,12 +221,13 @@ fuzz_one_token(wuffs_base__token t,
|
||||
}
|
||||
|
||||
uint64_t //
|
||||
buffer_limit(uint64_t hash_6_bits, uint64_t min, uint64_t max) {
|
||||
buffer_limit(uint64_t hash, uint64_t min, uint64_t max) {
|
||||
hash &= 0x3F;
|
||||
uint64_t n;
|
||||
if (hash_6_bits < 0x20) {
|
||||
n = min + hash_6_bits;
|
||||
if (hash < 0x20) {
|
||||
n = min + hash;
|
||||
} else {
|
||||
n = max - (0x3F - hash_6_bits);
|
||||
n = max - (0x3F - hash);
|
||||
}
|
||||
if (n < min) {
|
||||
return min;
|
||||
@@ -237,15 +238,15 @@ buffer_limit(uint64_t hash_6_bits, uint64_t min, uint64_t max) {
|
||||
}
|
||||
|
||||
const char* //
|
||||
fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash_56_bits) {
|
||||
fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
uint64_t tok_limit = buffer_limit(
|
||||
hash_56_bits & 0x3F, WUFFS_CBOR__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL,
|
||||
hash & 0x3F, WUFFS_CBOR__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL,
|
||||
TOK_BUFFER_ARRAY_SIZE);
|
||||
uint64_t hash_50_bits = hash_56_bits >> 6;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 6);
|
||||
|
||||
uint64_t src_limit =
|
||||
buffer_limit(hash_50_bits & 0x3F,
|
||||
WUFFS_CBOR__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL, 4096);
|
||||
uint64_t src_limit = buffer_limit(
|
||||
hash & 0x3F, WUFFS_CBOR__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL, 4096);
|
||||
hash = wuffs_base__u64__rotate_right(hash, 6);
|
||||
|
||||
// ----
|
||||
|
||||
@@ -407,7 +408,7 @@ fuzz(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
// The fuzz_complex implementation adds many more Wuffs API specific checks
|
||||
// (e.g. that the sum of the tokens' lengths do not exceed the input length).
|
||||
if ((hash & 0xFF) != 0xA5) {
|
||||
return fuzz_complex(full_src, hash >> 8);
|
||||
return fuzz_complex(full_src, wuffs_base__u64__rotate_right(hash, 8));
|
||||
}
|
||||
return fuzz_simple(full_src);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ It should print "PASS", amongst other information, and exit(0).
|
||||
#include "../fuzzlib/fuzzlib.c"
|
||||
#include "../fuzzlib/fuzzlib_image_decoder.c"
|
||||
|
||||
void set_quirks(wuffs_gif__decoder* dec, uint64_t hash_55_bits) {
|
||||
void set_quirks(wuffs_gif__decoder* dec, uint64_t hash) {
|
||||
uint32_t quirks[] = {
|
||||
WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES,
|
||||
WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND,
|
||||
@@ -75,8 +75,8 @@ void set_quirks(wuffs_gif__decoder* dec, uint64_t hash_55_bits) {
|
||||
|
||||
uint32_t i;
|
||||
for (i = 0; quirks[i]; i++) {
|
||||
uint64_t bit = 1 << (i % 55);
|
||||
if (hash_55_bits & bit) {
|
||||
uint64_t bit = 1 << (i & 63);
|
||||
if (hash & bit) {
|
||||
wuffs_gif__decoder__set_quirk_enabled(dec, quirks[i], true);
|
||||
}
|
||||
}
|
||||
@@ -88,13 +88,13 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_base__status status = wuffs_gif__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
hash >>= 1;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||
uint64_t hash_8_bits = hash & 0xFF;
|
||||
uint64_t hash_55_bits = hash >> 8;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 8);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
set_quirks(&dec, hash_55_bits);
|
||||
set_quirks(&dec, hash);
|
||||
return fuzz_image_decoder(
|
||||
src, hash_8_bits,
|
||||
wuffs_gif__decoder__upcast_as__wuffs_base__image_decoder(&dec));
|
||||
|
||||
+16
-16
@@ -209,12 +209,13 @@ fuzz_one_token(wuffs_base__token t,
|
||||
}
|
||||
|
||||
uint64_t //
|
||||
buffer_limit(uint64_t hash_6_bits, uint64_t min, uint64_t max) {
|
||||
buffer_limit(uint64_t hash, uint64_t min, uint64_t max) {
|
||||
hash &= 0x3F;
|
||||
uint64_t n;
|
||||
if (hash_6_bits < 0x20) {
|
||||
n = min + hash_6_bits;
|
||||
if (hash < 0x20) {
|
||||
n = min + hash;
|
||||
} else {
|
||||
n = max - (0x3F - hash_6_bits);
|
||||
n = max - (0x3F - hash);
|
||||
}
|
||||
if (n < min) {
|
||||
return min;
|
||||
@@ -224,7 +225,7 @@ buffer_limit(uint64_t hash_6_bits, uint64_t min, uint64_t max) {
|
||||
return n;
|
||||
}
|
||||
|
||||
void set_quirks(wuffs_json__decoder* dec, uint64_t hash_44_bits) {
|
||||
void set_quirks(wuffs_json__decoder* dec, uint64_t hash) {
|
||||
uint32_t quirks[] = {
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U,
|
||||
@@ -247,24 +248,23 @@ void set_quirks(wuffs_json__decoder* dec, uint64_t hash_44_bits) {
|
||||
|
||||
uint32_t i;
|
||||
for (i = 0; quirks[i]; i++) {
|
||||
uint64_t bit = 1 << (i % 44);
|
||||
if (hash_44_bits & bit) {
|
||||
uint64_t bit = 1 << (i & 63);
|
||||
if (hash & bit) {
|
||||
wuffs_json__decoder__set_quirk_enabled(dec, quirks[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash_56_bits) {
|
||||
fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
uint64_t tok_limit = buffer_limit(
|
||||
hash_56_bits & 0x3F, WUFFS_JSON__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL,
|
||||
hash & 0x3F, WUFFS_JSON__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL,
|
||||
TOK_BUFFER_ARRAY_SIZE);
|
||||
uint64_t hash_50_bits = hash_56_bits >> 6;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 6);
|
||||
|
||||
uint64_t src_limit =
|
||||
buffer_limit(hash_50_bits & 0x3F,
|
||||
WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL, 4096);
|
||||
uint64_t hash_44_bits = hash_50_bits >> 6;
|
||||
uint64_t src_limit = buffer_limit(
|
||||
hash & 0x3F, WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL, 4096);
|
||||
hash = wuffs_base__u64__rotate_right(hash, 6);
|
||||
|
||||
// ----
|
||||
|
||||
@@ -275,7 +275,7 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash_56_bits) {
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
set_quirks(&dec, hash_44_bits);
|
||||
set_quirks(&dec, hash);
|
||||
|
||||
wuffs_base__token tok_array[TOK_BUFFER_ARRAY_SIZE];
|
||||
wuffs_base__token_buffer tok = ((wuffs_base__token_buffer){
|
||||
@@ -427,7 +427,7 @@ fuzz(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
// The fuzz_complex implementation adds many more Wuffs API specific checks
|
||||
// (e.g. that the sum of the tokens' lengths do not exceed the input length).
|
||||
if ((hash & 0xFF) != 0xA5) {
|
||||
return fuzz_complex(full_src, hash >> 8);
|
||||
return fuzz_complex(full_src, wuffs_base__u64__rotate_right(hash, 8));
|
||||
}
|
||||
return fuzz_simple(full_src);
|
||||
}
|
||||
@@ -70,7 +70,7 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_base__status status = wuffs_png__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
hash >>= 1;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
@@ -31,14 +31,18 @@
|
||||
|
||||
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
|
||||
//
|
||||
// The order matters here. Clang also defines "__GNUC__".
|
||||
#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
|
||||
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
// The two #if lines are deliberately separate. Combining the two conditions
|
||||
// into a single "#if foo && bar" line would not be portable. See
|
||||
// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
|
||||
#if defined(__has_attribute)
|
||||
#if __has_attribute(fallthrough)
|
||||
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
|
||||
@@ -581,6 +581,56 @@ wuffs_base__u64__max(uint64_t x, uint64_t y) {
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x << n)) | ((uint8_t)(x >> (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x >> n)) | ((uint8_t)(x << (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x << n)) | ((uint16_t)(x >> (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x >> n)) | ((uint16_t)(x << (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x << n)) | ((uint32_t)(x >> (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x >> n)) | ((uint32_t)(x << (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_left(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x << n)) | ((uint64_t)(x >> (64 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x >> n)) | ((uint64_t)(x << (64 - n)));
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms
|
||||
// are per https://locklessinc.com/articles/sat_arithmetic/
|
||||
//
|
||||
|
||||
@@ -29,9 +29,9 @@ const BaseAllImplC = "" +
|
||||
""
|
||||
|
||||
const BaseFundamentalPrivateH = "" +
|
||||
"// ---------------- Fundamentals\n\n// WUFFS_BASE__MAGIC is a magic number to check that initializers are called.\n// It's not foolproof, given C doesn't automatically zero memory before use,\n// but it should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// WUFFS_BASE__DISABLED is a magic number to indicate that a non-recoverable\n// error was previously encountered.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"disabled\").\n#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)\n\n// Denote intentional fallthroughs for -Wimplicit-fallthrough.\n//\n// The order matters here. Clang also defines \"__GNUC__\".\n#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)\n#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]\n#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)\n#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))\n#else\n#define WUFFS_BASE__FALLTHROUGH\n#endif\n\n// Use switch " +
|
||||
"cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use trivial macros instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n WUFFS_BASE__FALLTHROUGH; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (!status.repr) { \\\n goto ok; \\\n } else if (*status.repr != '$') { \\\n goto exit; \\\n } \\\n coro_susp_point = n; \\\n goto suspend; " +
|
||||
" \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n" +
|
||||
"// ---------------- Fundamentals\n\n// WUFFS_BASE__MAGIC is a magic number to check that initializers are called.\n// It's not foolproof, given C doesn't automatically zero memory before use,\n// but it should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// WUFFS_BASE__DISABLED is a magic number to indicate that a non-recoverable\n// error was previously encountered.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"disabled\").\n#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)\n\n// Denote intentional fallthroughs for -Wimplicit-fallthrough.\n//\n// The two #if lines are deliberately separate. Combining the two conditions\n// into a single \"#if foo && bar\" line would not be portable. See\n// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html\n#if defined(__has_attribute)\n#if __has_attribute(fallthrough)\n#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))\n#else\n#define WUFFS_BASE__FALLTHROUGH\n" +
|
||||
"#endif\n#else\n#define WUFFS_BASE__FALLTHROUGH\n#endif\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use trivial macros instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n WUFFS_BASE__FALLTHROUGH; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (!status.repr) { \\\n goto ok; \\\n } else if (*status.repr != '$') { \\\n goto exit; \\\n } \\\n coro_susp_point = n; " +
|
||||
" \\\n goto suspend; \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__ignore_status(wuffs_base__status z) {\n return wuffs_base__make_empty_struct();\n}\n\nstatic inline wuffs_base__status //\nwuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) {\n if (z.repr && (*z.repr == '$')) {\n z.repr = wuffs_base__error__cannot_return_a_suspension;\n }\n return z;\n}\n\n" +
|
||||
"" +
|
||||
@@ -91,6 +91,9 @@ const BaseFundamentalPublicH = "" +
|
||||
"int32_t //\nwuffs_base__i32__max(int32_t x, int32_t y) {\n return x > y ? x : y;\n}\n\nstatic inline int64_t //\nwuffs_base__i64__min(int64_t x, int64_t y) {\n return x < y ? x : y;\n}\n\nstatic inline int64_t //\nwuffs_base__i64__max(int64_t x, int64_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__min(uint8_t x, uint8_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__max(uint8_t x, uint8_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__min(uint16_t x, uint16_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__max(uint16_t x, uint16_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__min(uint32_t x, uint32_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__max(uint32_t x, uint32_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__min(uint64_t x, uint64_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__m" +
|
||||
"ax(uint64_t x, uint64_t y) {\n return x > y ? x : y;\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic inline uint8_t //\nwuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {\n n &= 7;\n return ((uint8_t)(x << n)) | ((uint8_t)(x >> (8 - n)));\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {\n n &= 7;\n return ((uint8_t)(x >> n)) | ((uint8_t)(x << (8 - n)));\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {\n n &= 15;\n return ((uint16_t)(x << n)) | ((uint16_t)(x >> (16 - n)));\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {\n n &= 15;\n return ((uint16_t)(x >> n)) | ((uint16_t)(x << (16 - n)));\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {\n n &= 31;\n return ((uint32_t)(x << n)) | ((uint32_t)(x >> (32 - n)));\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {\n n &= 31;\n return ((uint32_t)(x >> n)) | ((uint32_t)(x << (32 - n)));\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__rotate_left(uint64_t x, uint32_t n) " +
|
||||
"{\n n &= 63;\n return ((uint64_t)(x << n)) | ((uint64_t)(x >> (64 - n)));\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {\n n &= 63;\n return ((uint64_t)(x >> n)) | ((uint64_t)(x << (64 - n)));\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms\n// are per https://locklessinc.com/articles/sat_arithmetic/\n//\n// It is important that the underlying types are unsigned integers, as signed\n// integer arithmetic overflow is undefined behavior in C.\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_add(uint8_t x, uint8_t y) {\n uint8_t res = (uint8_t)(x + y);\n res |= (uint8_t)(-(res < x));\n return res;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_sub(uint8_t x, uint8_t y) {\n uint8_t res = (uint8_t)(x - y);\n res &= (uint8_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_add(uint16_t x, uint16_t y) {\n uint16_t res = (uint16_t)(x + y);\n res |= (uint16_t)(-(res < x));\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_sub(uint16_t x, uint16_t y) {\n uint16_t res = (uint16_t)(x - y);\n res &= (uint16_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_add(uint32_t x, uint32_t y) {\n uint32" +
|
||||
"_t res = (uint32_t)(x + y);\n res |= (uint32_t)(-(res < x));\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_sub(uint32_t x, uint32_t y) {\n uint32_t res = (uint32_t)(x - y);\n res &= (uint32_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_add(uint64_t x, uint64_t y) {\n uint64_t res = (uint64_t)(x + y);\n res |= (uint64_t)(-(res < x));\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_sub(uint64_t x, uint64_t y) {\n uint64_t res = (uint64_t)(x - y);\n res &= (uint64_t)(-(res <= x));\n return res;\n}\n\n" +
|
||||
"" +
|
||||
|
||||
@@ -271,7 +271,7 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error {
|
||||
if n.Effect().Coroutine() {
|
||||
b.writex(k.bBodySuspend)
|
||||
} else if k.hasGotoOK {
|
||||
b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning.
|
||||
b.writes("\nok:\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,11 +501,17 @@ func (g *gen) writeFuncImplBody(b *buffer) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
if (g.currFunk.coroSuspPoint > 0) || g.currFunk.astFunc.Effect().Coroutine() {
|
||||
if !g.currFunk.hasGotoOK {
|
||||
b.writes("\ngoto ok;") // Avoid the "unused label" warning.
|
||||
}
|
||||
b.writes("\nok:\n")
|
||||
}
|
||||
|
||||
if g.currFunk.coroSuspPoint > 0 {
|
||||
// We've reached the end of the function body. Reset the coroutine
|
||||
// suspension point so that the next call to this function starts at
|
||||
// the top.
|
||||
b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning.
|
||||
b.printf("self->private_impl.%s%s[0] = 0;\n",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
b.writes("goto exit;\n}\n\n") // Close the coroutine switch.
|
||||
@@ -523,9 +529,6 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
return err
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
} else if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -678,6 +678,7 @@ func (g *gen) writeCoroSuspPoint(b *buffer, maybeSuspend bool) error {
|
||||
macro := ""
|
||||
if maybeSuspend {
|
||||
macro = "_MAYBE_SUSPEND"
|
||||
g.currFunk.hasGotoOK = true
|
||||
}
|
||||
b.printf("WUFFS_BASE__COROUTINE_SUSPENSION_POINT%s(%d);\n", macro, g.currFunk.coroSuspPoint)
|
||||
return nil
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
// Wuffs' C code is generated automatically, not hand-written. These warnings'
|
||||
// costs outweigh the benefits.
|
||||
//
|
||||
// The "elif defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
@@ -19,6 +22,15 @@
|
||||
#if defined(__cplusplus)
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma clang diagnostic ignored "-Wunreachable-code"
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#if defined(__cplusplus)
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
@@ -792,6 +804,56 @@ wuffs_base__u64__max(uint64_t x, uint64_t y) {
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x << n)) | ((uint8_t)(x >> (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x >> n)) | ((uint8_t)(x << (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x << n)) | ((uint16_t)(x >> (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x >> n)) | ((uint16_t)(x << (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x << n)) | ((uint32_t)(x >> (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x >> n)) | ((uint32_t)(x << (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_left(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x << n)) | ((uint64_t)(x >> (64 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x >> n)) | ((uint64_t)(x << (64 - n)));
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms
|
||||
// are per https://locklessinc.com/articles/sat_arithmetic/
|
||||
//
|
||||
@@ -10049,14 +10111,18 @@ extern "C" {
|
||||
|
||||
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
|
||||
//
|
||||
// The order matters here. Clang also defines "__GNUC__".
|
||||
#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
|
||||
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
// The two #if lines are deliberately separate. Combining the two conditions
|
||||
// into a single "#if foo && bar" line would not be portable. See
|
||||
// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
|
||||
#if defined(__has_attribute)
|
||||
#if __has_attribute(fallthrough)
|
||||
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
@@ -22085,7 +22151,6 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -22194,7 +22259,6 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -22382,7 +22446,6 @@ wuffs_bmp__decoder__decode_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -22496,7 +22559,6 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22759,7 +22821,6 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22900,7 +22961,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -23069,7 +23129,6 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -24155,7 +24214,6 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
label__outer__break:;
|
||||
self->private_impl.f_end_of_data = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_tokens[0] = 0;
|
||||
goto exit;
|
||||
@@ -25716,7 +25774,6 @@ wuffs_deflate__decoder__transform_io(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -25874,7 +25931,6 @@ wuffs_deflate__decoder__decode_blocks(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_blocks[0] = 0;
|
||||
goto exit;
|
||||
@@ -25994,7 +26050,6 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_uncompressed[0] = 0;
|
||||
goto exit;
|
||||
@@ -27585,7 +27640,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_huffman_slow[0] = 0;
|
||||
goto exit;
|
||||
@@ -27857,7 +27911,6 @@ wuffs_lzw__decoder__transform_io(
|
||||
}
|
||||
label__0__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -28101,7 +28154,6 @@ wuffs_lzw__decoder__write_to(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_write_to[0] = 0;
|
||||
goto exit;
|
||||
@@ -28657,7 +28709,6 @@ wuffs_gif__decoder__tell_me_more(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_tell_me_more[0] = 0;
|
||||
goto exit;
|
||||
@@ -28925,7 +28976,6 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -29591,7 +29641,6 @@ wuffs_gif__decoder__decode_extension(
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_extension[0] = 0;
|
||||
goto exit;
|
||||
@@ -29660,7 +29709,6 @@ wuffs_gif__decoder__skip_blocks(
|
||||
iop_a_src += self->private_data.s_skip_blocks[0].scratch;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_skip_blocks[0] = 0;
|
||||
goto exit;
|
||||
@@ -29879,7 +29927,6 @@ wuffs_gif__decoder__decode_ae(
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_ae[0] = 0;
|
||||
goto exit;
|
||||
@@ -30349,7 +30396,6 @@ wuffs_gif__decoder__decode_id_part1(
|
||||
wuffs_lzw__decoder__set_literal_width(&self->private_data.f_lzw, ((uint32_t)(v_lw)));
|
||||
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_id_part1[0] = 0;
|
||||
goto exit;
|
||||
@@ -30556,7 +30602,6 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_id_part2[0] = 0;
|
||||
goto exit;
|
||||
@@ -31166,7 +31211,6 @@ wuffs_gzip__decoder__transform_io(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -32623,7 +32667,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
self->private_impl.f_end_of_data = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_tokens[0] = 0;
|
||||
goto exit;
|
||||
@@ -32925,7 +32968,6 @@ wuffs_json__decoder__decode_leading(
|
||||
}
|
||||
label__0__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_leading[0] = 0;
|
||||
goto exit;
|
||||
@@ -33106,7 +33148,6 @@ wuffs_json__decoder__decode_comment(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_comment[0] = 0;
|
||||
goto exit;
|
||||
@@ -33267,7 +33308,6 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_inf_nan[0] = 0;
|
||||
goto exit;
|
||||
@@ -33413,7 +33453,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
}
|
||||
label__outer__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_trailer[0] = 0;
|
||||
goto exit;
|
||||
@@ -33888,7 +33927,6 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -33997,7 +34035,6 @@ wuffs_nie__decoder__decode_frame(
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -34087,7 +34124,6 @@ wuffs_nie__decoder__swizzle(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -34687,7 +34723,6 @@ wuffs_zlib__decoder__transform_io(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -36839,7 +36874,6 @@ wuffs_png__decoder__decode_image_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -37565,7 +37599,6 @@ wuffs_png__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -37692,7 +37725,6 @@ wuffs_png__decoder__decode_frame(
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -37991,7 +38023,6 @@ wuffs_png__decoder__decode_pass(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_pass[0] = 0;
|
||||
goto exit;
|
||||
@@ -38795,7 +38826,6 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -38960,7 +38990,6 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -40546,6 +40575,8 @@ done:
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // WUFFS_INCLUDE_GUARD
|
||||
+77
-46
@@ -10,6 +10,9 @@
|
||||
|
||||
// Wuffs' C code is generated automatically, not hand-written. These warnings'
|
||||
// costs outweigh the benefits.
|
||||
//
|
||||
// The "elif defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
@@ -19,6 +22,15 @@
|
||||
#if defined(__cplusplus)
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma clang diagnostic ignored "-Wunreachable-code"
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#if defined(__cplusplus)
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
@@ -70,15 +82,15 @@ extern "C" {
|
||||
// each major.minor branch, the commit count should increase monotonically.
|
||||
//
|
||||
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
|
||||
// 91857f4c4b827a2dcac7982ef03db1767ef72e23 committed on 2021-06-24.
|
||||
// b9a10d051a05c5749d54e2db8d0bd1848dd57181 committed on 2021-06-28.
|
||||
#define WUFFS_VERSION 0x000030000
|
||||
#define WUFFS_VERSION_MAJOR 0
|
||||
#define WUFFS_VERSION_MINOR 3
|
||||
#define WUFFS_VERSION_PATCH 0
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.2"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3048
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20210624
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.2+3048.20210624"
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.4"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3058
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20210628
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.4+3058.20210628"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
@@ -793,6 +805,56 @@ wuffs_base__u64__max(uint64_t x, uint64_t y) {
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x << n)) | ((uint8_t)(x >> (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x >> n)) | ((uint8_t)(x << (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x << n)) | ((uint16_t)(x >> (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x >> n)) | ((uint16_t)(x << (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x << n)) | ((uint32_t)(x >> (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x >> n)) | ((uint32_t)(x << (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_left(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x << n)) | ((uint64_t)(x >> (64 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x >> n)) | ((uint64_t)(x << (64 - n)));
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms
|
||||
// are per https://locklessinc.com/articles/sat_arithmetic/
|
||||
//
|
||||
@@ -10050,14 +10112,18 @@ extern "C" {
|
||||
|
||||
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
|
||||
//
|
||||
// The order matters here. Clang also defines "__GNUC__".
|
||||
#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
|
||||
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
// The two #if lines are deliberately separate. Combining the two conditions
|
||||
// into a single "#if foo && bar" line would not be portable. See
|
||||
// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
|
||||
#if defined(__has_attribute)
|
||||
#if __has_attribute(fallthrough)
|
||||
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
@@ -22086,7 +22152,6 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -22195,7 +22260,6 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -22383,7 +22447,6 @@ wuffs_bmp__decoder__decode_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -22497,7 +22560,6 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22760,7 +22822,6 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22901,7 +22962,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -23070,7 +23130,6 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -24156,7 +24215,6 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
label__outer__break:;
|
||||
self->private_impl.f_end_of_data = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_tokens[0] = 0;
|
||||
goto exit;
|
||||
@@ -25717,7 +25775,6 @@ wuffs_deflate__decoder__transform_io(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -25875,7 +25932,6 @@ wuffs_deflate__decoder__decode_blocks(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_blocks[0] = 0;
|
||||
goto exit;
|
||||
@@ -25995,7 +26051,6 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_uncompressed[0] = 0;
|
||||
goto exit;
|
||||
@@ -27586,7 +27641,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_huffman_slow[0] = 0;
|
||||
goto exit;
|
||||
@@ -27858,7 +27912,6 @@ wuffs_lzw__decoder__transform_io(
|
||||
}
|
||||
label__0__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -28102,7 +28155,6 @@ wuffs_lzw__decoder__write_to(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_write_to[0] = 0;
|
||||
goto exit;
|
||||
@@ -28658,7 +28710,6 @@ wuffs_gif__decoder__tell_me_more(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_tell_me_more[0] = 0;
|
||||
goto exit;
|
||||
@@ -28926,7 +28977,6 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -29592,7 +29642,6 @@ wuffs_gif__decoder__decode_extension(
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_extension[0] = 0;
|
||||
goto exit;
|
||||
@@ -29661,7 +29710,6 @@ wuffs_gif__decoder__skip_blocks(
|
||||
iop_a_src += self->private_data.s_skip_blocks[0].scratch;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_skip_blocks[0] = 0;
|
||||
goto exit;
|
||||
@@ -29880,7 +29928,6 @@ wuffs_gif__decoder__decode_ae(
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_ae[0] = 0;
|
||||
goto exit;
|
||||
@@ -30350,7 +30397,6 @@ wuffs_gif__decoder__decode_id_part1(
|
||||
wuffs_lzw__decoder__set_literal_width(&self->private_data.f_lzw, ((uint32_t)(v_lw)));
|
||||
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_id_part1[0] = 0;
|
||||
goto exit;
|
||||
@@ -30557,7 +30603,6 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_id_part2[0] = 0;
|
||||
goto exit;
|
||||
@@ -31167,7 +31212,6 @@ wuffs_gzip__decoder__transform_io(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -32624,7 +32668,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
self->private_impl.f_end_of_data = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_tokens[0] = 0;
|
||||
goto exit;
|
||||
@@ -32926,7 +32969,6 @@ wuffs_json__decoder__decode_leading(
|
||||
}
|
||||
label__0__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_leading[0] = 0;
|
||||
goto exit;
|
||||
@@ -33107,7 +33149,6 @@ wuffs_json__decoder__decode_comment(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_comment[0] = 0;
|
||||
goto exit;
|
||||
@@ -33268,7 +33309,6 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_inf_nan[0] = 0;
|
||||
goto exit;
|
||||
@@ -33414,7 +33454,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
}
|
||||
label__outer__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_trailer[0] = 0;
|
||||
goto exit;
|
||||
@@ -33889,7 +33928,6 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -33998,7 +34036,6 @@ wuffs_nie__decoder__decode_frame(
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -34088,7 +34125,6 @@ wuffs_nie__decoder__swizzle(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -34688,7 +34724,6 @@ wuffs_zlib__decoder__transform_io(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -36840,7 +36875,6 @@ wuffs_png__decoder__decode_image_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -37566,7 +37600,6 @@ wuffs_png__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -37693,7 +37726,6 @@ wuffs_png__decoder__decode_frame(
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -37992,7 +38024,6 @@ wuffs_png__decoder__decode_pass(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_pass[0] = 0;
|
||||
goto exit;
|
||||
@@ -38796,7 +38827,6 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -38961,7 +38991,6 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -40547,6 +40576,8 @@ done:
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // WUFFS_INCLUDE_GUARD
|
||||
Reference in new issue
Block a user