Have check_wuffs_version take the sizeof receiver

Also rename foo__initialize to foo__check_wuffs_version.
This commit is contained in:
Nigel Tao committed 2018-05-29 14:20:27 +10:00
1 parent d59eec7936
commit 87ab36f8c4
28 files changed
+354 -361

No files matched your search

+26 -34
View File
@@ -1218,14 +1218,15 @@ typedef struct {
// ---------------- Public Initializer Prototypes
// wuffs_crc32__ieee_hasher__initialize is an initializer function.
// wuffs_crc32__ieee_hasher__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_crc32__ieee_hasher__* function.
//
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
void wuffs_crc32__ieee_hasher__initialize(wuffs_crc32__ieee_hasher* self,
uint32_t wuffs_version,
uint32_t for_internal_use_only);
// Pass WUFFS_VERSION and sizeof(*self) for wuffs_version and sizeof_star_self.
void wuffs_crc32__ieee_hasher__check_wuffs_version(
wuffs_crc32__ieee_hasher* self,
uint32_t wuffs_version,
size_t sizeof_star_self);
// ---------------- Public Function Prototypes
@@ -1398,14 +1399,14 @@ typedef struct {
// ---------------- Public Initializer Prototypes
// wuffs_deflate__decoder__initialize is an initializer function.
// wuffs_deflate__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_deflate__decoder__* function.
//
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
void wuffs_deflate__decoder__initialize(wuffs_deflate__decoder* self,
uint32_t wuffs_version,
uint32_t for_internal_use_only);
// Pass WUFFS_VERSION and sizeof(*self) for wuffs_version and sizeof_star_self.
void wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self,
uint32_t wuffs_version,
size_t sizeof_star_self);
// ---------------- Public Function Prototypes
@@ -1500,14 +1501,14 @@ typedef struct {
// ---------------- Public Initializer Prototypes
// wuffs_gzip__decoder__initialize is an initializer function.
// wuffs_gzip__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_gzip__decoder__* function.
//
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
void wuffs_gzip__decoder__initialize(wuffs_gzip__decoder* self,
uint32_t wuffs_version,
uint32_t for_internal_use_only);
// Pass WUFFS_VERSION and sizeof(*self) for wuffs_version and sizeof_star_self.
void wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self,
uint32_t wuffs_version,
size_t sizeof_star_self);
// ---------------- Public Function Prototypes
@@ -1552,13 +1553,6 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self,
// Its (non-zero) value is arbitrary, based on md5sum("wuffs").
#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)
// WUFFS_BASE__ALREADY_ZEROED is passed from a container struct's initializer
// to a containee struct's initializer when the container has already zeroed
// the containee's memory.
//
// Its (non-zero) value is arbitrary, based on md5sum("zeroed").
#define WUFFS_BASE__ALREADY_ZEROED ((uint32_t)0x68602EF1)
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
//
// The order matters here. Clang also defines "__GNUC__".
@@ -2098,25 +2092,23 @@ const char* wuffs_gzip__status__string(wuffs_gzip__status s) {
// ---------------- Initializer Implementations
void wuffs_gzip__decoder__initialize(wuffs_gzip__decoder* self,
uint32_t wuffs_version,
uint32_t for_internal_use_only) {
void wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self,
uint32_t wuffs_version,
size_t sizeof_star_self) {
if (!self) {
return;
}
if (wuffs_version != WUFFS_VERSION) {
if ((wuffs_version != WUFFS_VERSION) || (sizeof(*self) != sizeof_star_self)) {
self->private_impl.status = WUFFS_GZIP__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;
wuffs_deflate__decoder__initialize(&self->private_impl.f_flate, WUFFS_VERSION,
WUFFS_BASE__ALREADY_ZEROED);
wuffs_crc32__ieee_hasher__initialize(&self->private_impl.f_checksum,
WUFFS_VERSION,
WUFFS_BASE__ALREADY_ZEROED);
wuffs_deflate__decoder__check_wuffs_version(
&self->private_impl.f_flate, WUFFS_VERSION,
sizeof(self->private_impl.f_flate));
wuffs_crc32__ieee_hasher__check_wuffs_version(
&self->private_impl.f_checksum, WUFFS_VERSION,
sizeof(self->private_impl.f_checksum));
}
// ---------------- Function Implementations