Add std/bzip2 package

This is just a placeholder decoder implementation.
This commit is contained in:
Nigel Tao committed 2022-05-12 23:52:12 +10:00
1 parent 4c56f5bdb2
commit ce8d08598d
5 files changed
+939

No files matched your search

+431
View File
@@ -6789,6 +6789,205 @@ struct wuffs_bmp__decoder__struct {
// ---------------- Status Codes
// ---------------- Public Consts
#define WUFFS_BZIP2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
// ---------------- Struct Declarations
typedef struct wuffs_bzip2__decoder__struct wuffs_bzip2__decoder;
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_bzip2__decoder__initialize(
wuffs_bzip2__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_bzip2__decoder();
// ---------------- Allocs
// These functions allocate and initialize Wuffs structs. They return NULL if
// memory allocation fails. If they return non-NULL, there is no need to call
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, decltype(&free)>.
wuffs_bzip2__decoder*
wuffs_bzip2__decoder__alloc();
static inline wuffs_base__io_transformer*
wuffs_bzip2__decoder__alloc_as__wuffs_base__io_transformer() {
return (wuffs_base__io_transformer*)(wuffs_bzip2__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__io_transformer*
wuffs_bzip2__decoder__upcast_as__wuffs_base__io_transformer(
wuffs_bzip2__decoder* p) {
return (wuffs_base__io_transformer*)p;
}
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_bzip2__decoder__set_quirk_enabled(
wuffs_bzip2__decoder* self,
uint32_t a_quirk,
bool a_enabled);
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_bzip2__decoder__workbuf_len(
const wuffs_bzip2__decoder* self);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_bzip2__decoder__transform_io(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
#ifdef __cplusplus
} // extern "C"
#endif
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
// details that aren't guaranteed to be stable across Wuffs versions.
//
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_bzip2__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
//
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
struct {
uint32_t magic;
uint32_t active_coroutine;
wuffs_base__vtable vtable_for__wuffs_base__io_transformer;
wuffs_base__vtable null_vtable;
uint32_t p_transform_io[1];
} private_impl;
struct {
struct {
uint64_t scratch;
} s_transform_io[1];
} private_data;
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_bzip2__decoder, decltype(&free)>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_bzip2__decoder__alloc(), &free);
}
static inline wuffs_base__io_transformer::unique_ptr
alloc_as__wuffs_base__io_transformer() {
return wuffs_base__io_transformer::unique_ptr(
wuffs_bzip2__decoder__alloc_as__wuffs_base__io_transformer(), &free);
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
// Disallow constructing or copying an object via standard C++ mechanisms,
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
// size and field layout is not part of the public, stable, memory-safe API.
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
// their first argument) rather than tweaking bar.private_impl.qux fields.
//
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_bzip2__decoder__struct() = delete;
wuffs_bzip2__decoder__struct(const wuffs_bzip2__decoder__struct&) = delete;
wuffs_bzip2__decoder__struct& operator=(
const wuffs_bzip2__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
// As above, the size of the struct is not part of the public API, and unless
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
// allocated, not stack allocated. Its size is not intended to be known at
// compile time, but it is unfortunately divulged as a side effect of
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
// instead of "sizeof T", invoking the operator. To make the two values
// different, so that passing the latter will be rejected by the initialize
// function, we add an arbitrary amount of dead weight.
uint8_t dead_weight[123000000]; // 123 MB.
#endif // !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
initialize(
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_bzip2__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
inline wuffs_base__io_transformer*
upcast_as__wuffs_base__io_transformer() {
return (wuffs_base__io_transformer*)this;
}
inline wuffs_base__empty_struct
set_quirk_enabled(
uint32_t a_quirk,
bool a_enabled) {
return wuffs_bzip2__decoder__set_quirk_enabled(this, a_quirk, a_enabled);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_bzip2__decoder__workbuf_len(this);
}
inline wuffs_base__status
transform_io(
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
return wuffs_bzip2__decoder__transform_io(this, a_dst, a_src, a_workbuf);
}
#endif // __cplusplus
}; // struct wuffs_bzip2__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
// ---------------- Status Codes
extern const char wuffs_cbor__error__bad_input[];
extern const char wuffs_cbor__error__unsupported_recursion_depth[];
@@ -24553,6 +24752,238 @@ wuffs_bmp__decoder__process_masks(
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2)
// ---------------- Status Codes Implementations
// ---------------- Private Consts
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
// ---------------- VTables
const wuffs_base__io_transformer__func_ptrs
wuffs_bzip2__decoder__func_ptrs_for__wuffs_base__io_transformer = {
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_bzip2__decoder__set_quirk_enabled),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__io_buffer*,
wuffs_base__slice_u8))(&wuffs_bzip2__decoder__transform_io),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_bzip2__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_bzip2__decoder__initialize(
wuffs_bzip2__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (sizeof(*self) != sizeof_star_self) {
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
}
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
}
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
// The whole point of this if-check is to detect an uninitialized *self.
// We disable the warning on GCC. Clang-5.0 does not have this warning.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (self->private_impl.magic != 0) {
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
}
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.vtable_for__wuffs_base__io_transformer.vtable_name =
wuffs_base__io_transformer__vtable_name;
self->private_impl.vtable_for__wuffs_base__io_transformer.function_pointers =
(const void*)(&wuffs_bzip2__decoder__func_ptrs_for__wuffs_base__io_transformer);
return wuffs_base__make_status(NULL);
}
wuffs_bzip2__decoder*
wuffs_bzip2__decoder__alloc() {
wuffs_bzip2__decoder* x =
(wuffs_bzip2__decoder*)(calloc(sizeof(wuffs_bzip2__decoder), 1));
if (!x) {
return NULL;
}
if (wuffs_bzip2__decoder__initialize(
x, sizeof(wuffs_bzip2__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
return x;
}
size_t
sizeof__wuffs_bzip2__decoder() {
return sizeof(wuffs_bzip2__decoder);
}
// ---------------- Function Implementations
// -------- func bzip2.decoder.set_quirk_enabled
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_bzip2__decoder__set_quirk_enabled(
wuffs_bzip2__decoder* self,
uint32_t a_quirk,
bool a_enabled) {
return wuffs_base__make_empty_struct();
}
// -------- func bzip2.decoder.workbuf_len
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_bzip2__decoder__workbuf_len(
const wuffs_bzip2__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_range_ii_u64();
}
return wuffs_base__utility__make_range_ii_u64(0, 0);
}
// -------- func bzip2.decoder.transform_io
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_bzip2__decoder__transform_io(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t* iop_a_dst = NULL;
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
io2_a_dst = io0_a_dst + a_dst->data.len;
if (a_dst->meta.closed) {
io2_a_dst = iop_a_dst;
}
}
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
if (((uint64_t)(io2_a_src - iop_a_src)) > 0) {
self->private_data.s_transform_io[0].scratch = ((uint64_t)(io2_a_src - iop_a_src));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (self->private_data.s_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_transform_io[0].scratch;
}
if (a_src && a_src->meta.closed) {
goto label__0__break;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
}
label__0__break:;
self->private_data.s_transform_io[0].scratch = 66;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (iop_a_dst == io2_a_dst) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
goto suspend;
}
*iop_a_dst++ = ((uint8_t)(self->private_data.s_transform_io[0].scratch));
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (a_dst) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CBOR)
// ---------------- Status Codes Implementations