Spin out a std/adler32 package

This commit is contained in:
Nigel Tao committed 2018-04-27 17:20:10 +10:00
1 parent 977f1fe64d
commit 035b138cb1
13 files changed
+3189 -319

No files matched your search

+100 -107
View File
@@ -1023,10 +1023,10 @@ static inline uint8_t* wuffs_base__image_buffer__palette(
// ---------------- Use Declarations
// ---------------- BEGIN USE "std/deflate"
// ---------------- BEGIN USE "std/adler32"
#ifndef WUFFS_DEFLATE_H
#define WUFFS_DEFLATE_H
#ifndef WUFFS_ADLER32_H
#define WUFFS_ADLER32_H
// Code generated by wuffs-c. DO NOT EDIT.
@@ -1038,6 +1038,97 @@ extern "C" {
// ---------------- Status Codes
// Status codes are int32_t values. Its bits:
// - bit 31 (the sign bit) indicates unrecoverable-ness: an error.
// - bits 30 .. 10 are the packageid: a namespace.
// - bits 9 .. 8 are reserved.
// - bits 7 .. 0 are a package-namespaced numeric code.
//
// Do not manipulate these bits directly; they are private implementation
// details. Use methods such as wuffs_adler32__status__is_error instead.
typedef int32_t wuffs_adler32__status;
#define wuffs_adler32__packageid 681002 // 0x000A642A
#define WUFFS_ADLER32__STATUS_OK 0 // 0x00000000
#define WUFFS_ADLER32__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
#define WUFFS_ADLER32__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
#define WUFFS_ADLER32__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
#define WUFFS_ADLER32__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
#define WUFFS_ADLER32__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
#define WUFFS_ADLER32__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
#define WUFFS_ADLER32__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
#define WUFFS_ADLER32__SUSPENSION_SHORT_READ 8 // 0x00000008
#define WUFFS_ADLER32__SUSPENSION_SHORT_WRITE 9 // 0x00000009
#define WUFFS_ADLER32__ERROR_CANNOT_RETURN_A_SUSPENSION \
-2147483638 // 0x8000000A
#define WUFFS_ADLER32__ERROR_INVALID_CALL_SEQUENCE -2147483637 // 0x8000000B
#define WUFFS_ADLER32__SUSPENSION_END_OF_DATA 12 // 0x0000000C
bool wuffs_adler32__status__is_error(wuffs_adler32__status s);
const char* wuffs_adler32__status__string(wuffs_adler32__status s);
// ---------------- Public Consts
// ---------------- Structs
typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
// wuffs_adler32__hasher__etc functions.
//
// In C++, these fields would be "private", but C does not support that.
//
// It is a struct, not a struct*, so that it can be stack allocated.
struct {
wuffs_adler32__status status;
uint32_t magic;
uint32_t f_state;
} private_impl;
} wuffs_adler32__hasher;
// ---------------- Public Initializer Prototypes
// wuffs_adler32__hasher__initialize is an initializer function.
//
// It should be called before any other wuffs_adler32__hasher__* function.
//
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
void wuffs_adler32__hasher__initialize(wuffs_adler32__hasher* self,
uint32_t wuffs_version,
uint32_t for_internal_use_only);
// ---------------- Public Function Prototypes
uint32_t wuffs_adler32__hasher__update(wuffs_adler32__hasher* self,
wuffs_base__slice_u8 a_x);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // WUFFS_ADLER32_H
// ---------------- END USE "std/adler32"
// ---------------- BEGIN USE "std/deflate"
#ifndef WUFFS_DEFLATE_H
#define WUFFS_DEFLATE_H
// Code generated by wuffs-c. DO NOT EDIT.
// ---------------- Use Declarations
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Status Codes
// Status codes are int32_t values. Its bits:
// - bit 31 (the sign bit) indicates unrecoverable-ness: an error.
// - bits 30 .. 10 are the packageid: a namespace.
@@ -1254,23 +1345,6 @@ const char* wuffs_zlib__status__string(wuffs_zlib__status s);
// ---------------- Structs
typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
// wuffs_zlib__adler32__etc functions.
//
// In C++, these fields would be "private", but C does not support that.
//
// It is a struct, not a struct*, so that it can be stack allocated.
struct {
wuffs_zlib__status status;
uint32_t magic;
uint32_t f_state;
} private_impl;
} wuffs_zlib__adler32;
typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
@@ -1284,7 +1358,7 @@ typedef struct {
uint32_t magic;
wuffs_deflate__decoder f_flate;
wuffs_zlib__adler32 f_checksum;
wuffs_adler32__hasher f_checksum;
bool f_ignore_checksum;
struct {
@@ -1735,6 +1809,8 @@ const char* wuffs_zlib__status__string(wuffs_zlib__status s) {
a = wuffs_zlib__status__strings;
n = 5;
break;
case wuffs_adler32__packageid:
return wuffs_adler32__status__string(s);
case wuffs_deflate__packageid:
return wuffs_deflate__status__string(s);
}
@@ -1746,34 +1822,10 @@ const char* wuffs_zlib__status__string(wuffs_zlib__status s) {
// ---------------- Private Initializer Prototypes
void wuffs_zlib__adler32__initialize(wuffs_zlib__adler32* self,
uint32_t wuffs_version,
uint32_t for_internal_use_only);
// ---------------- Private Function Prototypes
static uint32_t wuffs_zlib__adler32__update(wuffs_zlib__adler32* self,
wuffs_base__slice_u8 a_x);
// ---------------- Initializer Implementations
void wuffs_zlib__adler32__initialize(wuffs_zlib__adler32* self,
uint32_t wuffs_version,
uint32_t for_internal_use_only) {
if (!self) {
return;
}
if (wuffs_version != WUFFS_VERSION) {
self->private_impl.status = WUFFS_ZLIB__ERROR_BAD_WUFFS_VERSION;
return;
}
if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {
memset(self, 0, sizeof(*self));
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.f_state = 1;
}
void wuffs_zlib__decoder__initialize(wuffs_zlib__decoder* self,
uint32_t wuffs_version,
uint32_t for_internal_use_only) {
@@ -1790,71 +1842,12 @@ void wuffs_zlib__decoder__initialize(wuffs_zlib__decoder* self,
self->private_impl.magic = WUFFS_BASE__MAGIC;
wuffs_deflate__decoder__initialize(&self->private_impl.f_flate, WUFFS_VERSION,
WUFFS_BASE__ALREADY_ZEROED);
wuffs_zlib__adler32__initialize(&self->private_impl.f_checksum, WUFFS_VERSION,
WUFFS_BASE__ALREADY_ZEROED);
wuffs_adler32__hasher__initialize(&self->private_impl.f_checksum,
WUFFS_VERSION, WUFFS_BASE__ALREADY_ZEROED);
}
// ---------------- Function Implementations
static uint32_t wuffs_zlib__adler32__update(wuffs_zlib__adler32* self,
wuffs_base__slice_u8 a_x) {
uint32_t v_s1;
uint32_t v_s2;
wuffs_base__slice_u8 v_remaining;
v_s1 = ((self->private_impl.f_state) & ((1 << (16)) - 1));
v_s2 = ((self->private_impl.f_state) >> (32 - (16)));
while (((uint64_t)(a_x.len)) > 0) {
v_remaining = ((wuffs_base__slice_u8){});
if (((uint64_t)(a_x.len)) > 5552) {
v_remaining = wuffs_base__slice_u8__subslice_i(a_x, 5552);
a_x = wuffs_base__slice_u8__subslice_j(a_x, 5552);
}
{
wuffs_base__slice_u8 i_slice_p = a_x;
uint8_t* v_p = i_slice_p.ptr;
uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 8) * 8;
while (v_p < i_end0_p) {
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
}
uint8_t* i_end1_p = i_slice_p.ptr + i_slice_p.len;
while (v_p < i_end1_p) {
v_s1 += ((uint32_t)(*v_p));
v_s2 += v_s1;
v_p++;
}
}
v_s1 %= 65521;
v_s2 %= 65521;
a_x = v_remaining;
}
self->private_impl.f_state = (((v_s2 & 65535) << 16) | (v_s1 & 65535));
return self->private_impl.f_state;
}
void wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self,
bool a_ic) {
if (!self) {
@@ -2014,7 +2007,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
v_z = t_2;
}
if (!self->private_impl.f_ignore_checksum) {
v_checksum_got = wuffs_zlib__adler32__update(
v_checksum_got = wuffs_adler32__hasher__update(
&self->private_impl.f_checksum,
((wuffs_base__slice_u8){
.ptr = a_dst.private_impl.mark,