diff --git a/internal/cgen/auxiliary/base.cc b/internal/cgen/auxiliary/base.cc index 5e097624..3ab746d9 100644 --- a/internal/cgen/auxiliary/base.cc +++ b/internal/cgen/auxiliary/base.cc @@ -27,6 +27,8 @@ namespace sync_io { // -------- +Input::~Input() {} + IOBuffer* // Input::BringsItsOwnIOBuffer() { return nullptr; diff --git a/internal/cgen/auxiliary/base.hh b/internal/cgen/auxiliary/base.hh index 68e1af35..c1f9d544 100644 --- a/internal/cgen/auxiliary/base.hh +++ b/internal/cgen/auxiliary/base.hh @@ -40,6 +40,8 @@ namespace sync_io { class Input { public: + virtual ~Input(); + virtual IOBuffer* BringsItsOwnIOBuffer(); virtual std::string CopyIn(IOBuffer* dst) = 0; }; diff --git a/internal/cgen/auxiliary/cbor.cc b/internal/cgen/auxiliary/cbor.cc index 42705eae..3beba20e 100644 --- a/internal/cgen/auxiliary/cbor.cc +++ b/internal/cgen/auxiliary/cbor.cc @@ -27,6 +27,8 @@ DecodeCborResult::DecodeCborResult(std::string&& error_message0, : error_message(std::move(error_message0)), cursor_position(cursor_position0) {} +DecodeCborCallbacks::~DecodeCborCallbacks() {} + void // DecodeCborCallbacks::Done(DecodeCborResult& result, sync_io::Input& input, diff --git a/internal/cgen/auxiliary/cbor.hh b/internal/cgen/auxiliary/cbor.hh index 79ebe8d3..d1a9b9dd 100644 --- a/internal/cgen/auxiliary/cbor.hh +++ b/internal/cgen/auxiliary/cbor.hh @@ -27,6 +27,8 @@ struct DecodeCborResult { class DecodeCborCallbacks { public: + virtual ~DecodeCborCallbacks(); + // AppendXxx are called for leaf nodes: literals, numbers, strings, etc. virtual std::string AppendNull() = 0; diff --git a/internal/cgen/auxiliary/image.cc b/internal/cgen/auxiliary/image.cc index 6661383c..545bd550 100644 --- a/internal/cgen/auxiliary/image.cc +++ b/internal/cgen/auxiliary/image.cc @@ -37,6 +37,8 @@ DecodeImageResult::DecodeImageResult(std::string&& error_message0) pixbuf(wuffs_base__null_pixel_buffer()), error_message(std::move(error_message0)) {} +DecodeImageCallbacks::~DecodeImageCallbacks() {} + DecodeImageCallbacks::AllocResult::AllocResult(MemOwner&& mem_owner0, wuffs_base__slice_u8 mem_slice0) : mem_owner(std::move(mem_owner0)), diff --git a/internal/cgen/auxiliary/image.hh b/internal/cgen/auxiliary/image.hh index 266f276b..db905ec8 100644 --- a/internal/cgen/auxiliary/image.hh +++ b/internal/cgen/auxiliary/image.hh @@ -55,6 +55,8 @@ class DecodeImageCallbacks { std::string error_message; }; + virtual ~DecodeImageCallbacks(); + // SelectDecoder returns the image decoder for the input data's file format. // Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat). // diff --git a/internal/cgen/auxiliary/json.cc b/internal/cgen/auxiliary/json.cc index fe64fa6e..c56a91a9 100644 --- a/internal/cgen/auxiliary/json.cc +++ b/internal/cgen/auxiliary/json.cc @@ -27,6 +27,8 @@ DecodeJsonResult::DecodeJsonResult(std::string&& error_message0, : error_message(std::move(error_message0)), cursor_position(cursor_position0) {} +DecodeJsonCallbacks::~DecodeJsonCallbacks() {} + void // DecodeJsonCallbacks::Done(DecodeJsonResult& result, sync_io::Input& input, diff --git a/internal/cgen/auxiliary/json.hh b/internal/cgen/auxiliary/json.hh index 64f60ecb..3758ecb5 100644 --- a/internal/cgen/auxiliary/json.hh +++ b/internal/cgen/auxiliary/json.hh @@ -27,6 +27,8 @@ struct DecodeJsonResult { class DecodeJsonCallbacks { public: + virtual ~DecodeJsonCallbacks(); + // AppendXxx are called for leaf nodes: literals, numbers and strings. For // strings, the Callbacks implementation is responsible for tracking map keys // versus other values. diff --git a/internal/cgen/data/data.go b/internal/cgen/data/data.go index 1adf4381..7b7dbec3 100644 --- a/internal/cgen/data/data.go +++ b/internal/cgen/data/data.go @@ -758,7 +758,7 @@ const BaseUTF8SubmoduleC = "" + const AuxBaseCc = "" + "// ---------------- Auxiliary - Base\n\n// Auxiliary code is discussed at\n// https://github.com/google/wuffs/blob/main/doc/note/auxiliary-code.md\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__BASE)\n\nnamespace wuffs_aux {\n\nnamespace sync_io {\n\n" + "" + - "// --------\n\nIOBuffer* //\nInput::BringsItsOwnIOBuffer() {\n return nullptr;\n}\n\n" + + "// --------\n\nInput::~Input() {}\n\nIOBuffer* //\nInput::BringsItsOwnIOBuffer() {\n return nullptr;\n}\n\n" + "" + "// --------\n\nFileInput::FileInput(FILE* f) : m_f(f) {}\n\nstd::string //\nFileInput::CopyIn(IOBuffer* dst) {\n if (!m_f) {\n return \"wuffs_aux::sync_io::FileInput: nullptr file\";\n } else if (!dst) {\n return \"wuffs_aux::sync_io::FileInput: nullptr IOBuffer\";\n } else if (dst->meta.closed) {\n return \"wuffs_aux::sync_io::FileInput: end of file\";\n } else {\n dst->compact();\n size_t n = fread(dst->writer_pointer(), 1, dst->writer_length(), m_f);\n dst->meta.wi += n;\n dst->meta.closed = feof(m_f);\n if (ferror(m_f)) {\n return \"wuffs_aux::sync_io::FileInput: error reading file\";\n }\n }\n return \"\";\n}\n\n" + "" + @@ -771,7 +771,7 @@ const AuxBaseCc = "" + const AuxBaseHh = "" + "// ---------------- Auxiliary - Base\n\n// Auxiliary code is discussed at\n// https://github.com/google/wuffs/blob/main/doc/note/auxiliary-code.md\n\n#include \n\n#include \n\nnamespace wuffs_aux {\n\nusing IOBuffer = wuffs_base__io_buffer;\n\n// MemOwner represents ownership of some memory. Dynamically allocated memory\n// (e.g. from malloc or new) is typically paired with free or delete, invoked\n// when the std::unique_ptr is destroyed. Statically allocated memory might use\n// MemOwner(nullptr, &free), even if that statically allocated memory is not\n// nullptr, since calling free(nullptr) is a no-op.\nusing MemOwner = std::unique_ptr;\n\nnamespace sync_io {\n\n" + "" + - "// --------\n\nclass Input {\n public:\n virtual IOBuffer* BringsItsOwnIOBuffer();\n virtual std::string CopyIn(IOBuffer* dst) = 0;\n};\n\n" + + "// --------\n\nclass Input {\n public:\n virtual ~Input();\n\n virtual IOBuffer* BringsItsOwnIOBuffer();\n virtual std::string CopyIn(IOBuffer* dst) = 0;\n};\n\n" + "" + "// --------\n\n// FileInput is an Input that reads from a file source.\n//\n// It does not take responsibility for closing the file when done.\nclass FileInput : public Input {\n public:\n FileInput(FILE* f);\n\n virtual std::string CopyIn(IOBuffer* dst);\n\n private:\n FILE* m_f;\n\n // Delete the copy and assign constructors.\n FileInput(const FileInput&) = delete;\n FileInput& operator=(const FileInput&) = delete;\n};\n\n" + "" + @@ -781,33 +781,34 @@ const AuxBaseHh = "" + "" const AuxCborCc = "" + - "// ---------------- Auxiliary - CBOR\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__CBOR)\n\n#include \n\nnamespace wuffs_aux {\n\nDecodeCborResult::DecodeCborResult(std::string&& error_message0,\n uint64_t cursor_position0)\n : error_message(std::move(error_message0)),\n cursor_position(cursor_position0) {}\n\nvoid //\nDecodeCborCallbacks::Done(DecodeCborResult& result,\n sync_io::Input& input,\n IOBuffer& buffer) {}\n\nDecodeCborResult //\nDecodeCbor(DecodeCborCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks) {\n // Prepare the wuffs_base__io_buffer and the resultant error_message.\n wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();\n wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();\n std::unique_ptr fallback_io_array(nullptr);\n if (!io_buf) {\n fallback_io_array = std::unique_ptr(new uint8_" + - "t[4096]);\n fallback_io_buf = wuffs_base__ptr_u8__writer(fallback_io_array.get(), 4096);\n io_buf = &fallback_io_buf;\n }\n // cursor_index is discussed at\n // https://nigeltao.github.io/blog/2020/jsonptr.html#the-cursor-index\n size_t cursor_index = 0;\n std::string ret_error_message;\n std::string io_error_message;\n\n do {\n // Prepare the low-level CBOR decoder.\n wuffs_cbor__decoder::unique_ptr dec = wuffs_cbor__decoder::alloc();\n if (!dec) {\n ret_error_message = \"wuffs_aux::CborDecoder: out of memory\";\n goto done;\n }\n for (size_t i = 0; i < quirks.len; i++) {\n dec->set_quirk_enabled(quirks.ptr[i], true);\n }\n\n // Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.\n wuffs_base__token tok_array[256];\n wuffs_base__token_buffer tok_buf =\n wuffs_base__slice_token__writer(wuffs_base__make_slice_token(\n &tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));\n wuffs_base__status tok_status = wuffs_base__make_status(nullptr);\n\n // Prepar" + - "e other state.\n uint32_t depth = 0;\n std::string str;\n int64_t extension_category = 0;\n uint64_t extension_detail = 0;\n\n // Valid token's VBCs range in 0 ..= 15. Values over that are for tokens\n // from outside of the base package, such as the CBOR package.\n constexpr int64_t EXT_CAT__CBOR_TAG = 16;\n\n // Loop, doing these two things:\n // 1. Get the next token.\n // 2. Process that token.\n while (true) {\n // 1. Get the next token.\n\n while (tok_buf.meta.ri >= tok_buf.meta.wi) {\n if (tok_status.repr == nullptr) {\n // No-op.\n } else if (tok_status.repr == wuffs_base__suspension__short_write) {\n tok_buf.compact();\n } else if (tok_status.repr == wuffs_base__suspension__short_read) {\n // Read from input to io_buf.\n if (!io_error_message.empty()) {\n ret_error_message = std::move(io_error_message);\n goto done;\n } else if (cursor_index != io_buf->meta.ri) {\n ret_error_message =\n" + - " \"wuffs_aux::CborDecoder: internal error: bad cursor_index\";\n goto done;\n } else if (io_buf->meta.closed) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: io_buf is closed\";\n goto done;\n }\n io_buf->compact();\n if (io_buf->meta.wi >= io_buf->data.len) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: io_buf is full\";\n goto done;\n }\n cursor_index = io_buf->meta.ri;\n io_error_message = input.CopyIn(io_buf);\n } else {\n ret_error_message = tok_status.message();\n goto done;\n }\n\n if (WUFFS_CBOR__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad WORKBUF_LEN\";\n goto done;\n }\n wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8();\n tok_status = dec->decode_tokens(&tok_" + - "buf, io_buf, work_buf);\n }\n\n wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++];\n uint64_t token_len = token.length();\n if ((io_buf->meta.ri < cursor_index) ||\n ((io_buf->meta.ri - cursor_index) < token_len)) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad token indexes\";\n goto done;\n }\n uint8_t* token_ptr = io_buf->data.ptr + cursor_index;\n cursor_index += static_cast(token_len);\n\n // 2. Process that token.\n\n uint64_t vbd = token.value_base_detail();\n\n if (extension_category != 0) {\n int64_t ext = token.value_extension();\n if ((ext >= 0) && !token.continued()) {\n extension_detail = (extension_detail\n << WUFFS_BASE__TOKEN__VALUE_EXTENSION__NUM_BITS) |\n static_cast(ext);\n switch (extension_category) {\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED:\n extension_cat" + - "egory = 0;\n ret_error_message =\n callbacks.AppendI64(static_cast(extension_detail));\n goto parsed_a_value;\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED:\n extension_category = 0;\n ret_error_message = callbacks.AppendU64(extension_detail);\n goto parsed_a_value;\n case EXT_CAT__CBOR_TAG:\n extension_category = 0;\n ret_error_message = callbacks.AppendCborTag(extension_detail);\n if (!ret_error_message.empty()) {\n goto done;\n }\n continue;\n }\n }\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad extended token\";\n goto done;\n }\n\n switch (token.value_base_category()) {\n case WUFFS_BASE__TOKEN__VBC__FILLER:\n continue;\n\n case WUFFS_BASE__TOKEN__VBC__STRUCTURE: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n " + - " ret_error_message = callbacks.Push(static_cast(vbd));\n if (!ret_error_message.empty()) {\n goto done;\n }\n depth++;\n continue;\n }\n ret_error_message = callbacks.Pop(static_cast(vbd));\n depth--;\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__STRING: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP) {\n // No-op.\n } else if (vbd &\n WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY) {\n const char* ptr = // Convert from (uint8_t*).\n static_cast(static_cast(token_ptr));\n str.append(ptr, static_cast(token_len));\n } else {\n goto fail;\n }\n if (token.continued()) {\n continue;\n }\n ret_error_message =\n (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8)\n " + - " ? callbacks.AppendTextString(std::move(str))\n : callbacks.AppendByteString(std::move(str));\n str.clear();\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT: {\n uint8_t u[WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL];\n size_t n = wuffs_base__utf_8__encode(\n wuffs_base__make_slice_u8(\n &u[0], WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL),\n static_cast(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast(static_cast(&u[0]));\n str.append(ptr, n);\n if (token.continued()) {\n continue;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__LITERAL: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__NULL) {\n ret_error_message = callbacks.AppendNull();\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__UNDEFINED) {\n ret_error_mes" + - "sage = callbacks.AppendUndefined();\n } else {\n ret_error_message = callbacks.AppendBool(\n vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE);\n }\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__NUMBER: {\n const uint64_t cfp_fbbe_fifb =\n WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT |\n WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_BINARY_BIG_ENDIAN |\n WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_IGNORE_FIRST_BYTE;\n if ((vbd & cfp_fbbe_fifb) == cfp_fbbe_fifb) {\n double f;\n switch (token_len) {\n case 3:\n f = wuffs_base__ieee_754_bit_representation__from_u16_to_f64(\n wuffs_base__peek_u16be__no_bounds_check(token_ptr + 1));\n break;\n case 5:\n f = wuffs_base__ieee_754_bit_representation__from_u32_to_f64(\n wuffs_base__peek_u32be__no_bounds_check(token_ptr + 1));\n " + - " break;\n case 9:\n f = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n wuffs_base__peek_u64be__no_bounds_check(token_ptr + 1));\n break;\n default:\n goto fail;\n }\n ret_error_message = callbacks.AppendF64(f);\n goto parsed_a_value;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED: {\n if (token.continued()) {\n extension_category = WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED;\n extension_detail =\n static_cast(token.value_base_detail__sign_extended());\n continue;\n }\n ret_error_message =\n callbacks.AppendI64(token.value_base_detail__sign_extended());\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED: {\n if (token.continued()) {\n extension_category =\n " + - " WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED;\n extension_detail = vbd;\n continue;\n }\n ret_error_message = callbacks.AppendU64(vbd);\n goto parsed_a_value;\n }\n }\n\n if (token.value_major() == WUFFS_CBOR__TOKEN_VALUE_MAJOR) {\n uint64_t value_minor = token.value_minor();\n if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__MINUS_1_MINUS_X) {\n if (token_len == 9) {\n ret_error_message = callbacks.AppendMinus1MinusX(\n wuffs_base__peek_u64be__no_bounds_check(token_ptr + 1));\n goto parsed_a_value;\n }\n } else if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__SIMPLE_VALUE) {\n ret_error_message =\n callbacks.AppendCborSimpleValue(static_cast(\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK));\n goto parsed_a_value;\n } else if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__TAG) {\n if (token.contin" + - "ued()) {\n extension_category = EXT_CAT__CBOR_TAG;\n extension_detail =\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK;\n continue;\n }\n ret_error_message = callbacks.AppendCborTag(\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK);\n if (!ret_error_message.empty()) {\n goto done;\n }\n continue;\n }\n }\n\n fail:\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: unexpected token\";\n goto done;\n\n parsed_a_value:\n if (!ret_error_message.empty() || (depth == 0)) {\n goto done;\n }\n }\n } while (false);\n\ndone:\n DecodeCborResult result(\n std::move(ret_error_message),\n wuffs_base__u64__sat_add(io_buf->meta.pos, cursor_index));\n callbacks.Done(result, input, *io_buf);\n return result;\n}\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__AUX__CBOR)\n" + + "// ---------------- Auxiliary - CBOR\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__CBOR)\n\n#include \n\nnamespace wuffs_aux {\n\nDecodeCborResult::DecodeCborResult(std::string&& error_message0,\n uint64_t cursor_position0)\n : error_message(std::move(error_message0)),\n cursor_position(cursor_position0) {}\n\nDecodeCborCallbacks::~DecodeCborCallbacks() {}\n\nvoid //\nDecodeCborCallbacks::Done(DecodeCborResult& result,\n sync_io::Input& input,\n IOBuffer& buffer) {}\n\nDecodeCborResult //\nDecodeCbor(DecodeCborCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks) {\n // Prepare the wuffs_base__io_buffer and the resultant error_message.\n wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();\n wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();\n std::unique_ptr fallback_io_array(nullptr);\n if (!io_buf) {\n fallback_" + + "io_array = std::unique_ptr(new uint8_t[4096]);\n fallback_io_buf = wuffs_base__ptr_u8__writer(fallback_io_array.get(), 4096);\n io_buf = &fallback_io_buf;\n }\n // cursor_index is discussed at\n // https://nigeltao.github.io/blog/2020/jsonptr.html#the-cursor-index\n size_t cursor_index = 0;\n std::string ret_error_message;\n std::string io_error_message;\n\n do {\n // Prepare the low-level CBOR decoder.\n wuffs_cbor__decoder::unique_ptr dec = wuffs_cbor__decoder::alloc();\n if (!dec) {\n ret_error_message = \"wuffs_aux::CborDecoder: out of memory\";\n goto done;\n }\n for (size_t i = 0; i < quirks.len; i++) {\n dec->set_quirk_enabled(quirks.ptr[i], true);\n }\n\n // Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.\n wuffs_base__token tok_array[256];\n wuffs_base__token_buffer tok_buf =\n wuffs_base__slice_token__writer(wuffs_base__make_slice_token(\n &tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));\n wuffs_base__status tok_status = " + + "wuffs_base__make_status(nullptr);\n\n // Prepare other state.\n uint32_t depth = 0;\n std::string str;\n int64_t extension_category = 0;\n uint64_t extension_detail = 0;\n\n // Valid token's VBCs range in 0 ..= 15. Values over that are for tokens\n // from outside of the base package, such as the CBOR package.\n constexpr int64_t EXT_CAT__CBOR_TAG = 16;\n\n // Loop, doing these two things:\n // 1. Get the next token.\n // 2. Process that token.\n while (true) {\n // 1. Get the next token.\n\n while (tok_buf.meta.ri >= tok_buf.meta.wi) {\n if (tok_status.repr == nullptr) {\n // No-op.\n } else if (tok_status.repr == wuffs_base__suspension__short_write) {\n tok_buf.compact();\n } else if (tok_status.repr == wuffs_base__suspension__short_read) {\n // Read from input to io_buf.\n if (!io_error_message.empty()) {\n ret_error_message = std::move(io_error_message);\n goto done;\n } else if (cursor_index != io_" + + "buf->meta.ri) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad cursor_index\";\n goto done;\n } else if (io_buf->meta.closed) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: io_buf is closed\";\n goto done;\n }\n io_buf->compact();\n if (io_buf->meta.wi >= io_buf->data.len) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: io_buf is full\";\n goto done;\n }\n cursor_index = io_buf->meta.ri;\n io_error_message = input.CopyIn(io_buf);\n } else {\n ret_error_message = tok_status.message();\n goto done;\n }\n\n if (WUFFS_CBOR__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad WORKBUF_LEN\";\n goto done;\n }\n wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(" + + ");\n tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf);\n }\n\n wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++];\n uint64_t token_len = token.length();\n if ((io_buf->meta.ri < cursor_index) ||\n ((io_buf->meta.ri - cursor_index) < token_len)) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad token indexes\";\n goto done;\n }\n uint8_t* token_ptr = io_buf->data.ptr + cursor_index;\n cursor_index += static_cast(token_len);\n\n // 2. Process that token.\n\n uint64_t vbd = token.value_base_detail();\n\n if (extension_category != 0) {\n int64_t ext = token.value_extension();\n if ((ext >= 0) && !token.continued()) {\n extension_detail = (extension_detail\n << WUFFS_BASE__TOKEN__VALUE_EXTENSION__NUM_BITS) |\n static_cast(ext);\n switch (extension_category) {\n case WUFFS_BASE__TOKEN__VBC__IN" + + "LINE_INTEGER_SIGNED:\n extension_category = 0;\n ret_error_message =\n callbacks.AppendI64(static_cast(extension_detail));\n goto parsed_a_value;\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED:\n extension_category = 0;\n ret_error_message = callbacks.AppendU64(extension_detail);\n goto parsed_a_value;\n case EXT_CAT__CBOR_TAG:\n extension_category = 0;\n ret_error_message = callbacks.AppendCborTag(extension_detail);\n if (!ret_error_message.empty()) {\n goto done;\n }\n continue;\n }\n }\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad extended token\";\n goto done;\n }\n\n switch (token.value_base_category()) {\n case WUFFS_BASE__TOKEN__VBC__FILLER:\n continue;\n\n case WUFFS_BASE__TOKEN__VBC__STRUCTURE: {\n if (vbd & WUFFS_" + + "BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n ret_error_message = callbacks.Push(static_cast(vbd));\n if (!ret_error_message.empty()) {\n goto done;\n }\n depth++;\n continue;\n }\n ret_error_message = callbacks.Pop(static_cast(vbd));\n depth--;\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__STRING: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP) {\n // No-op.\n } else if (vbd &\n WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY) {\n const char* ptr = // Convert from (uint8_t*).\n static_cast(static_cast(token_ptr));\n str.append(ptr, static_cast(token_len));\n } else {\n goto fail;\n }\n if (token.continued()) {\n continue;\n }\n ret_error_message =\n (vbd & WUFFS_BASE__T" + + "OKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8)\n ? callbacks.AppendTextString(std::move(str))\n : callbacks.AppendByteString(std::move(str));\n str.clear();\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT: {\n uint8_t u[WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL];\n size_t n = wuffs_base__utf_8__encode(\n wuffs_base__make_slice_u8(\n &u[0], WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL),\n static_cast(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast(static_cast(&u[0]));\n str.append(ptr, n);\n if (token.continued()) {\n continue;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__LITERAL: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__NULL) {\n ret_error_message = callbacks.AppendNull();\n } else if (vbd & WUFFS_BASE__TOKEN__VBD_" + + "_LITERAL__UNDEFINED) {\n ret_error_message = callbacks.AppendUndefined();\n } else {\n ret_error_message = callbacks.AppendBool(\n vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE);\n }\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__NUMBER: {\n const uint64_t cfp_fbbe_fifb =\n WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT |\n WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_BINARY_BIG_ENDIAN |\n WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_IGNORE_FIRST_BYTE;\n if ((vbd & cfp_fbbe_fifb) == cfp_fbbe_fifb) {\n double f;\n switch (token_len) {\n case 3:\n f = wuffs_base__ieee_754_bit_representation__from_u16_to_f64(\n wuffs_base__peek_u16be__no_bounds_check(token_ptr + 1));\n break;\n case 5:\n f = wuffs_base__ieee_754_bit_representation__from_u32_to_f64(\n wuffs_base__peek" + + "_u32be__no_bounds_check(token_ptr + 1));\n break;\n case 9:\n f = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n wuffs_base__peek_u64be__no_bounds_check(token_ptr + 1));\n break;\n default:\n goto fail;\n }\n ret_error_message = callbacks.AppendF64(f);\n goto parsed_a_value;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED: {\n if (token.continued()) {\n extension_category = WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED;\n extension_detail =\n static_cast(token.value_base_detail__sign_extended());\n continue;\n }\n ret_error_message =\n callbacks.AppendI64(token.value_base_detail__sign_extended());\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED: {\n if (token.continu" + + "ed()) {\n extension_category =\n WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED;\n extension_detail = vbd;\n continue;\n }\n ret_error_message = callbacks.AppendU64(vbd);\n goto parsed_a_value;\n }\n }\n\n if (token.value_major() == WUFFS_CBOR__TOKEN_VALUE_MAJOR) {\n uint64_t value_minor = token.value_minor();\n if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__MINUS_1_MINUS_X) {\n if (token_len == 9) {\n ret_error_message = callbacks.AppendMinus1MinusX(\n wuffs_base__peek_u64be__no_bounds_check(token_ptr + 1));\n goto parsed_a_value;\n }\n } else if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__SIMPLE_VALUE) {\n ret_error_message =\n callbacks.AppendCborSimpleValue(static_cast(\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK));\n goto parsed_a_value;\n } else if (value_minor & WUFFS_CBOR__TOKE" + + "N_VALUE_MINOR__TAG) {\n if (token.continued()) {\n extension_category = EXT_CAT__CBOR_TAG;\n extension_detail =\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK;\n continue;\n }\n ret_error_message = callbacks.AppendCborTag(\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK);\n if (!ret_error_message.empty()) {\n goto done;\n }\n continue;\n }\n }\n\n fail:\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: unexpected token\";\n goto done;\n\n parsed_a_value:\n if (!ret_error_message.empty() || (depth == 0)) {\n goto done;\n }\n }\n } while (false);\n\ndone:\n DecodeCborResult result(\n std::move(ret_error_message),\n wuffs_base__u64__sat_add(io_buf->meta.pos, cursor_index));\n callbacks.Done(result, input, *io_buf);\n return result;\n}\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n " + + "// defined(WUFFS_CONFIG__MODULE__AUX__CBOR)\n" + "" const AuxCborHh = "" + - "// ---------------- Auxiliary - CBOR\n\nnamespace wuffs_aux {\n\nstruct DecodeCborResult {\n DecodeCborResult(std::string&& error_message0, uint64_t cursor_position0);\n\n std::string error_message;\n uint64_t cursor_position;\n};\n\nclass DecodeCborCallbacks {\n public:\n // AppendXxx are called for leaf nodes: literals, numbers, strings, etc.\n\n virtual std::string AppendNull() = 0;\n virtual std::string AppendUndefined() = 0;\n virtual std::string AppendBool(bool val) = 0;\n virtual std::string AppendF64(double val) = 0;\n virtual std::string AppendI64(int64_t val) = 0;\n virtual std::string AppendU64(uint64_t val) = 0;\n virtual std::string AppendByteString(std::string&& val) = 0;\n virtual std::string AppendTextString(std::string&& val) = 0;\n virtual std::string AppendMinus1MinusX(uint64_t val) = 0;\n virtual std::string AppendCborSimpleValue(uint8_t val) = 0;\n virtual std::string AppendCborTag(uint64_t val) = 0;\n\n // Push and Pop are called for container nodes: CBOR arrays (lists) and CBOR\n // maps (dictiona" + - "ries).\n //\n // The flags bits combine exactly one of:\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_NONE\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_LIST\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_DICT\n // and exactly one of:\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_NONE\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_LIST\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT\n\n virtual std::string Push(uint32_t flags) = 0;\n virtual std::string Pop(uint32_t flags) = 0;\n\n // Done is always the last Callback method called by DecodeCbor, whether or\n // not parsing the input as CBOR encountered an error. Even when successful,\n // trailing data may remain in input and buffer.\n //\n // Do not keep a reference to buffer or buffer.data.ptr after Done returns,\n // as DecodeCbor may then de-allocate the backing array.\n //\n // The default Done implementation is a no-op.\n virtual void //\n Done(DecodeCborResult& result, sync_io::Input& input, IOBuffer& buffer);\n};\n\n// DecodeCbor calls callbacks ba" + - "sed on the CBOR-formatted data in input.\n//\n// On success, the returned error_message is empty and cursor_position counts\n// the number of bytes consumed. On failure, error_message is non-empty and\n// cursor_position is the location of the error. That error may be a content\n// error (invalid CBOR) or an input error (e.g. network failure).\nDecodeCborResult //\nDecodeCbor(DecodeCborCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32());\n\n} // namespace wuffs_aux\n" + + "// ---------------- Auxiliary - CBOR\n\nnamespace wuffs_aux {\n\nstruct DecodeCborResult {\n DecodeCborResult(std::string&& error_message0, uint64_t cursor_position0);\n\n std::string error_message;\n uint64_t cursor_position;\n};\n\nclass DecodeCborCallbacks {\n public:\n virtual ~DecodeCborCallbacks();\n\n // AppendXxx are called for leaf nodes: literals, numbers, strings, etc.\n\n virtual std::string AppendNull() = 0;\n virtual std::string AppendUndefined() = 0;\n virtual std::string AppendBool(bool val) = 0;\n virtual std::string AppendF64(double val) = 0;\n virtual std::string AppendI64(int64_t val) = 0;\n virtual std::string AppendU64(uint64_t val) = 0;\n virtual std::string AppendByteString(std::string&& val) = 0;\n virtual std::string AppendTextString(std::string&& val) = 0;\n virtual std::string AppendMinus1MinusX(uint64_t val) = 0;\n virtual std::string AppendCborSimpleValue(uint8_t val) = 0;\n virtual std::string AppendCborTag(uint64_t val) = 0;\n\n // Push and Pop are called for container nodes: CBOR arrays (" + + "lists) and CBOR\n // maps (dictionaries).\n //\n // The flags bits combine exactly one of:\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_NONE\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_LIST\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_DICT\n // and exactly one of:\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_NONE\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_LIST\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT\n\n virtual std::string Push(uint32_t flags) = 0;\n virtual std::string Pop(uint32_t flags) = 0;\n\n // Done is always the last Callback method called by DecodeCbor, whether or\n // not parsing the input as CBOR encountered an error. Even when successful,\n // trailing data may remain in input and buffer.\n //\n // Do not keep a reference to buffer or buffer.data.ptr after Done returns,\n // as DecodeCbor may then de-allocate the backing array.\n //\n // The default Done implementation is a no-op.\n virtual void //\n Done(DecodeCborResult& result, sync_io::Input& input, IOBuffer& buffer);\n}" + + ";\n\n// DecodeCbor calls callbacks based on the CBOR-formatted data in input.\n//\n// On success, the returned error_message is empty and cursor_position counts\n// the number of bytes consumed. On failure, error_message is non-empty and\n// cursor_position is the location of the error. That error may be a content\n// error (invalid CBOR) or an input error (e.g. network failure).\nDecodeCborResult //\nDecodeCbor(DecodeCborCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32());\n\n} // namespace wuffs_aux\n" + "" const AuxImageCc = "" + - "// ---------------- Auxiliary - Image\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__IMAGE)\n\n#include \n\nnamespace wuffs_aux {\n\nDecodeImageResult::DecodeImageResult(MemOwner&& pixbuf_mem_owner0,\n wuffs_base__slice_u8 pixbuf_mem_slice0,\n wuffs_base__pixel_buffer pixbuf0,\n std::string&& error_message0)\n : pixbuf_mem_owner(std::move(pixbuf_mem_owner0)),\n pixbuf_mem_slice(pixbuf_mem_slice0),\n pixbuf(pixbuf0),\n error_message(std::move(error_message0)) {}\n\nDecodeImageResult::DecodeImageResult(std::string&& error_message0)\n : pixbuf_mem_owner(nullptr, &free),\n pixbuf_mem_slice(wuffs_base__empty_slice_u8()),\n pixbuf(wuffs_base__null_pixel_buffer()),\n error_message(std::move(error_message0)) {}\n\nDecodeImageCallbacks::AllocResult::AllocResult(MemOwner&& mem_owner0,\n wuffs_base__slice_u8 mem_slice0" + - ")\n : mem_owner(std::move(mem_owner0)),\n mem_slice(mem_slice0),\n error_message(\"\") {}\n\nDecodeImageCallbacks::AllocResult::AllocResult(std::string&& error_message0)\n : mem_owner(nullptr, &free),\n mem_slice(wuffs_base__empty_slice_u8()),\n error_message(std::move(error_message0)) {}\n\nwuffs_base__image_decoder::unique_ptr //\nDecodeImageCallbacks::SelectDecoder(uint32_t fourcc,\n wuffs_base__slice_u8 prefix) {\n switch (fourcc) {\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)\n case WUFFS_BASE__FOURCC__BMP:\n return wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();\n#endif\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)\n case WUFFS_BASE__FOURCC__GIF:\n return wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();\n#endif\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE)\n case WUFFS_BASE__FOURCC__NIE:\n return wuffs_nie__decoder::alloc_as__wuffs_ba" + - "se__image_decoder();\n#endif\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)\n case WUFFS_BASE__FOURCC__PNG: {\n auto dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();\n // Favor faster decodes over rejecting invalid checksums.\n dec->set_quirk_enabled(WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, true);\n return dec;\n }\n#endif\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)\n case WUFFS_BASE__FOURCC__WBMP:\n return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();\n#endif\n }\n\n return wuffs_base__image_decoder::unique_ptr(nullptr, &free);\n}\n\nwuffs_base__pixel_format //\nDecodeImageCallbacks::SelectPixfmt(\n const wuffs_base__image_config& image_config) {\n return wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL);\n}\n\nDecodeImageCallbacks::AllocResult //\nDecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config,\n bool allow_uninitialized_memo" + - "ry) {\n uint32_t w = image_config.pixcfg.width();\n uint32_t h = image_config.pixcfg.height();\n if ((w == 0) || (h == 0)) {\n return AllocResult(\"\");\n }\n uint64_t len = image_config.pixcfg.pixbuf_len();\n if ((len == 0) || (SIZE_MAX < len)) {\n return AllocResult(DecodeImage_UnsupportedPixelConfiguration);\n }\n void* ptr =\n allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);\n return ptr ? AllocResult(\n MemOwner(ptr, &free),\n wuffs_base__make_slice_u8((uint8_t*)ptr, (size_t)len))\n : AllocResult(DecodeImage_OutOfMemory);\n}\n\nDecodeImageCallbacks::AllocResult //\nDecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range,\n bool allow_uninitialized_memory) {\n uint64_t len = len_range.max_incl;\n if (len == 0) {\n return AllocResult(\"\");\n } else if (SIZE_MAX < len) {\n return AllocResult(DecodeImage_OutOfMemory);\n }\n void* ptr =\n allow_uninitialized_memory ? malloc((size_t)l" + - "en) : calloc((size_t)len, 1);\n return ptr ? AllocResult(\n MemOwner(ptr, &free),\n wuffs_base__make_slice_u8((uint8_t*)ptr, (size_t)len))\n : AllocResult(DecodeImage_OutOfMemory);\n}\n\nvoid //\nDecodeImageCallbacks::Done(\n DecodeImageResult& result,\n sync_io::Input& input,\n IOBuffer& buffer,\n wuffs_base__image_decoder::unique_ptr image_decoder) {}\n\nconst char DecodeImage_BufferIsTooShort[] = //\n \"wuffs_aux::DecodeImage: buffer is too short\";\nconst char DecodeImage_MaxInclDimensionExceeded[] = //\n \"wuffs_aux::DecodeImage: max_incl_dimension exceeded\";\nconst char DecodeImage_OutOfMemory[] = //\n \"wuffs_aux::DecodeImage: out of memory\";\nconst char DecodeImage_UnexpectedEndOfFile[] = //\n \"wuffs_aux::DecodeImage: unexpected end of file\";\nconst char DecodeImage_UnsupportedImageFormat[] = //\n \"wuffs_aux::DecodeImage: unsupported image format\";\nconst char DecodeImage_UnsupportedPixelBlend[] = //\n \"wuffs_aux::DecodeImage: unsupported pixel " + - "blend\";\nconst char DecodeImage_UnsupportedPixelConfiguration[] = //\n \"wuffs_aux::DecodeImage: unsupported pixel configuration\";\nconst char DecodeImage_UnsupportedPixelFormat[] = //\n \"wuffs_aux::DecodeImage: unsupported pixel format\";\n\n" + + "// ---------------- Auxiliary - Image\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__IMAGE)\n\n#include \n\nnamespace wuffs_aux {\n\nDecodeImageResult::DecodeImageResult(MemOwner&& pixbuf_mem_owner0,\n wuffs_base__slice_u8 pixbuf_mem_slice0,\n wuffs_base__pixel_buffer pixbuf0,\n std::string&& error_message0)\n : pixbuf_mem_owner(std::move(pixbuf_mem_owner0)),\n pixbuf_mem_slice(pixbuf_mem_slice0),\n pixbuf(pixbuf0),\n error_message(std::move(error_message0)) {}\n\nDecodeImageResult::DecodeImageResult(std::string&& error_message0)\n : pixbuf_mem_owner(nullptr, &free),\n pixbuf_mem_slice(wuffs_base__empty_slice_u8()),\n pixbuf(wuffs_base__null_pixel_buffer()),\n error_message(std::move(error_message0)) {}\n\nDecodeImageCallbacks::~DecodeImageCallbacks() {}\n\nDecodeImageCallbacks::AllocResult::AllocResult(MemOwner&& mem_owner0,\n " + + " wuffs_base__slice_u8 mem_slice0)\n : mem_owner(std::move(mem_owner0)),\n mem_slice(mem_slice0),\n error_message(\"\") {}\n\nDecodeImageCallbacks::AllocResult::AllocResult(std::string&& error_message0)\n : mem_owner(nullptr, &free),\n mem_slice(wuffs_base__empty_slice_u8()),\n error_message(std::move(error_message0)) {}\n\nwuffs_base__image_decoder::unique_ptr //\nDecodeImageCallbacks::SelectDecoder(uint32_t fourcc,\n wuffs_base__slice_u8 prefix) {\n switch (fourcc) {\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)\n case WUFFS_BASE__FOURCC__BMP:\n return wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();\n#endif\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)\n case WUFFS_BASE__FOURCC__GIF:\n return wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();\n#endif\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE)\n case WUFFS_BASE__FOURCC__NIE:\n " + + " return wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();\n#endif\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)\n case WUFFS_BASE__FOURCC__PNG: {\n auto dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();\n // Favor faster decodes over rejecting invalid checksums.\n dec->set_quirk_enabled(WUFFS_BASE__QUIRK_IGNORE_CHECKSUM, true);\n return dec;\n }\n#endif\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)\n case WUFFS_BASE__FOURCC__WBMP:\n return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();\n#endif\n }\n\n return wuffs_base__image_decoder::unique_ptr(nullptr, &free);\n}\n\nwuffs_base__pixel_format //\nDecodeImageCallbacks::SelectPixfmt(\n const wuffs_base__image_config& image_config) {\n return wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL);\n}\n\nDecodeImageCallbacks::AllocResult //\nDecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config,\n " + + " bool allow_uninitialized_memory) {\n uint32_t w = image_config.pixcfg.width();\n uint32_t h = image_config.pixcfg.height();\n if ((w == 0) || (h == 0)) {\n return AllocResult(\"\");\n }\n uint64_t len = image_config.pixcfg.pixbuf_len();\n if ((len == 0) || (SIZE_MAX < len)) {\n return AllocResult(DecodeImage_UnsupportedPixelConfiguration);\n }\n void* ptr =\n allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);\n return ptr ? AllocResult(\n MemOwner(ptr, &free),\n wuffs_base__make_slice_u8((uint8_t*)ptr, (size_t)len))\n : AllocResult(DecodeImage_OutOfMemory);\n}\n\nDecodeImageCallbacks::AllocResult //\nDecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range,\n bool allow_uninitialized_memory) {\n uint64_t len = len_range.max_incl;\n if (len == 0) {\n return AllocResult(\"\");\n } else if (SIZE_MAX < len) {\n return AllocResult(DecodeImage_OutOfMemory);\n }\n void* ptr =\n " + + " allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);\n return ptr ? AllocResult(\n MemOwner(ptr, &free),\n wuffs_base__make_slice_u8((uint8_t*)ptr, (size_t)len))\n : AllocResult(DecodeImage_OutOfMemory);\n}\n\nvoid //\nDecodeImageCallbacks::Done(\n DecodeImageResult& result,\n sync_io::Input& input,\n IOBuffer& buffer,\n wuffs_base__image_decoder::unique_ptr image_decoder) {}\n\nconst char DecodeImage_BufferIsTooShort[] = //\n \"wuffs_aux::DecodeImage: buffer is too short\";\nconst char DecodeImage_MaxInclDimensionExceeded[] = //\n \"wuffs_aux::DecodeImage: max_incl_dimension exceeded\";\nconst char DecodeImage_OutOfMemory[] = //\n \"wuffs_aux::DecodeImage: out of memory\";\nconst char DecodeImage_UnexpectedEndOfFile[] = //\n \"wuffs_aux::DecodeImage: unexpected end of file\";\nconst char DecodeImage_UnsupportedImageFormat[] = //\n \"wuffs_aux::DecodeImage: unsupported image format\";\nconst char DecodeImage_UnsupportedPixelBlend[] = " + + "//\n \"wuffs_aux::DecodeImage: unsupported pixel blend\";\nconst char DecodeImage_UnsupportedPixelConfiguration[] = //\n \"wuffs_aux::DecodeImage: unsupported pixel configuration\";\nconst char DecodeImage_UnsupportedPixelFormat[] = //\n \"wuffs_aux::DecodeImage: unsupported pixel format\";\n\n" + "" + "// --------\n\nnamespace {\n\nstd::string //\nDecodeImageAdvanceIOBuf(sync_io::Input& input,\n wuffs_base__io_buffer& io_buf,\n bool compactable,\n uint64_t min_excl_pos,\n uint64_t pos) {\n if ((pos <= min_excl_pos) || (pos < io_buf.reader_position())) {\n // Redirects must go forward.\n return DecodeImage_UnsupportedImageFormat;\n }\n while (true) {\n uint64_t relative_pos = pos - io_buf.reader_position();\n if (relative_pos <= io_buf.reader_length()) {\n io_buf.meta.ri += (size_t)relative_pos;\n break;\n } else if (io_buf.meta.closed) {\n return DecodeImage_UnexpectedEndOfFile;\n }\n io_buf.meta.ri = io_buf.meta.wi;\n if (compactable) {\n io_buf.compact();\n }\n std::string error_message = input.CopyIn(&io_buf);\n if (!error_message.empty()) {\n return error_message;\n }\n }\n return \"\";\n}\n\nDecodeImageResult //\nDecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,\n " + " DecodeImageCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__io_buffer& io_buf,\n wuffs_base__pixel_blend pixel_blend,\n wuffs_base__color_u32_argb_premul background_color,\n uint32_t max_incl_dimension) {\n // Check args.\n switch (pixel_blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n break;\n default:\n return DecodeImageResult(DecodeImage_UnsupportedPixelBlend);\n }\n\n wuffs_base__image_config image_config = wuffs_base__null_image_config();\n uint64_t start_pos = io_buf.reader_position();\n bool redirected = false;\n int32_t fourcc = 0;\nredirect:\n do {\n // Determine the image format.\n if (!redirected) {\n while (true) {\n fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice());\n if (fourcc > 0) {\n break;\n } else if ((fourcc == 0) && (io_buf.reader_length() >= 64)) {\n break;\n } else if (io_buf.meta.closed ||" + @@ -824,18 +825,18 @@ const AuxImageCc = "" + const AuxImageHh = "" + "// ---------------- Auxiliary - Image\n\nnamespace wuffs_aux {\n\nstruct DecodeImageResult {\n DecodeImageResult(MemOwner&& pixbuf_mem_owner0,\n wuffs_base__slice_u8 pixbuf_mem_slice0,\n wuffs_base__pixel_buffer pixbuf0,\n std::string&& error_message0);\n DecodeImageResult(std::string&& error_message0);\n\n MemOwner pixbuf_mem_owner;\n wuffs_base__slice_u8 pixbuf_mem_slice;\n wuffs_base__pixel_buffer pixbuf;\n std::string error_message;\n};\n\n// DecodeImageCallbacks are the callbacks given to DecodeImage. They are always\n// called in this order:\n// 1. SelectDecoder\n// 2. SelectPixfmt\n// 3. AllocPixbuf\n// 4. AllocWorkbuf\n// 5. Done\n//\n// It may return early - the third callback might not be invoked if the second\n// one fails - but the final callback (Done) is always invoked.\nclass DecodeImageCallbacks {\n public:\n // AllocResult holds a memory allocation (the result of malloc or new, a\n // statically allocated pointer, etc), or an error message. The memory i" + - "s\n // de-allocated when mem_owner goes out of scope and is destroyed.\n struct AllocResult {\n AllocResult(MemOwner&& mem_owner0, wuffs_base__slice_u8 mem_slice0);\n AllocResult(std::string&& error_message0);\n\n MemOwner mem_owner;\n wuffs_base__slice_u8 mem_slice;\n std::string error_message;\n };\n\n // SelectDecoder returns the image decoder for the input data's file format.\n // Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).\n //\n // Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],\n // such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the\n // caller is responsible for examining the opening bytes (a prefix) of the\n // input data. SelectDecoder implementations should not modify those bytes.\n //\n // SelectDecoder might be called more than once, since some image file\n // formats can wrap others. For example, a nominal BMP file can actually\n // contain a JPEG or a PNG.\n //\n // The default SelectDecoder accepts the FOURCC codes" + - " listed below. For\n // modular builds (i.e. when #define'ing WUFFS_CONFIG__MODULES), acceptance\n // of the ETC file format is optional (for each value of ETC) and depends on\n // the corresponding module to be enabled at compile time (i.e. #define'ing\n // WUFFS_CONFIG__MODULE__ETC).\n // - WUFFS_BASE__FOURCC__BMP\n // - WUFFS_BASE__FOURCC__GIF\n // - WUFFS_BASE__FOURCC__NIE\n // - WUFFS_BASE__FOURCC__PNG\n // - WUFFS_BASE__FOURCC__WBMP\n virtual wuffs_base__image_decoder::unique_ptr //\n SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);\n\n // SelectPixfmt returns the destination pixel format for AllocPixbuf. It\n // should return wuffs_base__make_pixel_format(etc) called with one of:\n // - WUFFS_BASE__PIXEL_FORMAT__BGR_565\n // - WUFFS_BASE__PIXEL_FORMAT__BGR\n // - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL\n // - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE\n // - WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL\n // - WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL\n // - WUFFS_BASE__PIXEL_FORMA" + - "T__RGBA_PREMUL\n // or return image_config.pixcfg.pixel_format(). The latter means to use the\n // image file's natural pixel format. For example, GIF images' natural pixel\n // format is an indexed one.\n //\n // Returning otherwise means failure (DecodeImage_UnsupportedPixelFormat).\n //\n // The default SelectPixfmt implementation returns\n // wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL) which\n // is 4 bytes per pixel (8 bits per channel × 4 channels).\n virtual wuffs_base__pixel_format //\n SelectPixfmt(const wuffs_base__image_config& image_config);\n\n // AllocPixbuf allocates the pixel buffer.\n //\n // allow_uninitialized_memory will be true if a valid background_color was\n // passed to DecodeImage, since the pixel buffer's contents will be\n // overwritten with that color after AllocPixbuf returns.\n //\n // The default AllocPixbuf implementation allocates either uninitialized or\n // zeroed memory. Zeroed memory typically corresponds to filling with opaque\n // black or tra" + - "nsparent black, depending on the pixel format.\n virtual AllocResult //\n AllocPixbuf(const wuffs_base__image_config& image_config,\n bool allow_uninitialized_memory);\n\n // AllocWorkbuf allocates the work buffer. The allocated buffer's length\n // should be at least len_range.min_incl, but larger allocations (up to\n // len_range.max_incl) may have better performance (by using more memory).\n //\n // The default AllocWorkbuf implementation allocates len_range.max_incl bytes\n // of either uninitialized or zeroed memory.\n virtual AllocResult //\n AllocWorkbuf(wuffs_base__range_ii_u64 len_range,\n bool allow_uninitialized_memory);\n\n // Done is always the last Callback method called by DecodeImage, whether or\n // not parsing the input encountered an error. Even when successful, trailing\n // data may remain in input and buffer.\n //\n // The image_decoder is the one returned by SelectDecoder (if SelectDecoder\n // was successful), or a no-op unique_ptr otherwise. Like any unique_pt" + - "r,\n // ownership moves to the Done implementation.\n //\n // Do not keep a reference to buffer or buffer.data.ptr after Done returns,\n // as DecodeImage may then de-allocate the backing array.\n //\n // The default Done implementation is a no-op, other than running the\n // image_decoder unique_ptr destructor.\n virtual void //\n Done(DecodeImageResult& result,\n sync_io::Input& input,\n IOBuffer& buffer,\n wuffs_base__image_decoder::unique_ptr image_decoder);\n};\n\nextern const char DecodeImage_BufferIsTooShort[];\nextern const char DecodeImage_MaxInclDimensionExceeded[];\nextern const char DecodeImage_OutOfMemory[];\nextern const char DecodeImage_UnexpectedEndOfFile[];\nextern const char DecodeImage_UnsupportedImageFormat[];\nextern const char DecodeImage_UnsupportedPixelBlend[];\nextern const char DecodeImage_UnsupportedPixelConfiguration[];\nextern const char DecodeImage_UnsupportedPixelFormat[];\n\n// DecodeImage decodes the image data in input. A variety of image file formats\n// can be decoded, d" + - "epending on what callbacks.SelectDecoder returns.\n//\n// For animated formats, only the first frame is returned, since the API is\n// simpler for synchronous I/O and having DecodeImage only return when\n// completely done, but rendering animation often involves handling other\n// events in between animation frames. To decode multiple frames of animated\n// images, or for asynchronous I/O (e.g. when decoding an image streamed over\n// the network), use Wuffs' lower level C API instead of its higher level,\n// simplified C++ API (the wuffs_aux API).\n//\n// The DecodeImageResult's fields depend on whether decoding succeeded:\n// - On total success, the error_message is empty and pixbuf.pixcfg.is_valid()\n// is true.\n// - On partial success (e.g. the input file was truncated but we are still\n// able to decode some of the pixels), error_message is non-empty but\n// pixbuf.pixcfg.is_valid() is still true. It is up to the caller whether to\n// accept or reject partial success.\n// - On failure, the error_message i" + - "s non_empty and pixbuf.pixcfg.is_valid()\n// is false.\n//\n// The callbacks allocate the pixel buffer memory and work buffer memory. On\n// success, pixel buffer memory ownership is passed to the DecodeImage caller\n// as the returned pixbuf_mem_owner. Regardless of success or failure, the work\n// buffer memory is deleted.\n//\n// The pixel_blend (one of the constants listed below) determines how to\n// composite the decoded image over the pixel buffer's original pixels (as\n// returned by callbacks.AllocPixbuf):\n// - WUFFS_BASE__PIXEL_BLEND__SRC\n// - WUFFS_BASE__PIXEL_BLEND__SRC_OVER\n//\n// The background_color is used to fill the pixel buffer after\n// callbacks.AllocPixbuf returns, if it is valid in the\n// wuffs_base__color_u32_argb_premul__is_valid sense. The default value,\n// 0x0000_0001, is not valid since its Blue channel value (0x01) is greater\n// than its Alpha channel value (0x00). A valid background_color will typically\n// be overwritten when pixel_blend is WUFFS_BASE__PIXEL_BLEND__SRC, but might\n// sti" + - "ll be visible on partial (not total) success or when pixel_blend is\n// WUFFS_BASE__PIXEL_BLEND__SRC_OVER and the decoded image is not fully opaque.\n//\n// Decoding fails (with DecodeImage_MaxInclDimensionExceeded) if the image's\n// width or height is greater than max_incl_dimension.\nDecodeImageResult //\nDecodeImage(DecodeImageCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__pixel_blend pixel_blend = WUFFS_BASE__PIXEL_BLEND__SRC,\n wuffs_base__color_u32_argb_premul background_color = 1, // Invalid.\n uint32_t max_incl_dimension = 1048575); // 0x000F_FFFF\n\n} // namespace wuffs_aux\n" + + "s\n // de-allocated when mem_owner goes out of scope and is destroyed.\n struct AllocResult {\n AllocResult(MemOwner&& mem_owner0, wuffs_base__slice_u8 mem_slice0);\n AllocResult(std::string&& error_message0);\n\n MemOwner mem_owner;\n wuffs_base__slice_u8 mem_slice;\n std::string error_message;\n };\n\n virtual ~DecodeImageCallbacks();\n\n // SelectDecoder returns the image decoder for the input data's file format.\n // Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).\n //\n // Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],\n // such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the\n // caller is responsible for examining the opening bytes (a prefix) of the\n // input data. SelectDecoder implementations should not modify those bytes.\n //\n // SelectDecoder might be called more than once, since some image file\n // formats can wrap others. For example, a nominal BMP file can actually\n // contain a JPEG or a PNG.\n //\n // The default Se" + + "lectDecoder accepts the FOURCC codes listed below. For\n // modular builds (i.e. when #define'ing WUFFS_CONFIG__MODULES), acceptance\n // of the ETC file format is optional (for each value of ETC) and depends on\n // the corresponding module to be enabled at compile time (i.e. #define'ing\n // WUFFS_CONFIG__MODULE__ETC).\n // - WUFFS_BASE__FOURCC__BMP\n // - WUFFS_BASE__FOURCC__GIF\n // - WUFFS_BASE__FOURCC__NIE\n // - WUFFS_BASE__FOURCC__PNG\n // - WUFFS_BASE__FOURCC__WBMP\n virtual wuffs_base__image_decoder::unique_ptr //\n SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);\n\n // SelectPixfmt returns the destination pixel format for AllocPixbuf. It\n // should return wuffs_base__make_pixel_format(etc) called with one of:\n // - WUFFS_BASE__PIXEL_FORMAT__BGR_565\n // - WUFFS_BASE__PIXEL_FORMAT__BGR\n // - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL\n // - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE\n // - WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL\n // - WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPR" + + "EMUL\n // - WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL\n // or return image_config.pixcfg.pixel_format(). The latter means to use the\n // image file's natural pixel format. For example, GIF images' natural pixel\n // format is an indexed one.\n //\n // Returning otherwise means failure (DecodeImage_UnsupportedPixelFormat).\n //\n // The default SelectPixfmt implementation returns\n // wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL) which\n // is 4 bytes per pixel (8 bits per channel × 4 channels).\n virtual wuffs_base__pixel_format //\n SelectPixfmt(const wuffs_base__image_config& image_config);\n\n // AllocPixbuf allocates the pixel buffer.\n //\n // allow_uninitialized_memory will be true if a valid background_color was\n // passed to DecodeImage, since the pixel buffer's contents will be\n // overwritten with that color after AllocPixbuf returns.\n //\n // The default AllocPixbuf implementation allocates either uninitialized or\n // zeroed memory. Zeroed memory typically corresponds to f" + + "illing with opaque\n // black or transparent black, depending on the pixel format.\n virtual AllocResult //\n AllocPixbuf(const wuffs_base__image_config& image_config,\n bool allow_uninitialized_memory);\n\n // AllocWorkbuf allocates the work buffer. The allocated buffer's length\n // should be at least len_range.min_incl, but larger allocations (up to\n // len_range.max_incl) may have better performance (by using more memory).\n //\n // The default AllocWorkbuf implementation allocates len_range.max_incl bytes\n // of either uninitialized or zeroed memory.\n virtual AllocResult //\n AllocWorkbuf(wuffs_base__range_ii_u64 len_range,\n bool allow_uninitialized_memory);\n\n // Done is always the last Callback method called by DecodeImage, whether or\n // not parsing the input encountered an error. Even when successful, trailing\n // data may remain in input and buffer.\n //\n // The image_decoder is the one returned by SelectDecoder (if SelectDecoder\n // was successful), or a no-op uniq" + + "ue_ptr otherwise. Like any unique_ptr,\n // ownership moves to the Done implementation.\n //\n // Do not keep a reference to buffer or buffer.data.ptr after Done returns,\n // as DecodeImage may then de-allocate the backing array.\n //\n // The default Done implementation is a no-op, other than running the\n // image_decoder unique_ptr destructor.\n virtual void //\n Done(DecodeImageResult& result,\n sync_io::Input& input,\n IOBuffer& buffer,\n wuffs_base__image_decoder::unique_ptr image_decoder);\n};\n\nextern const char DecodeImage_BufferIsTooShort[];\nextern const char DecodeImage_MaxInclDimensionExceeded[];\nextern const char DecodeImage_OutOfMemory[];\nextern const char DecodeImage_UnexpectedEndOfFile[];\nextern const char DecodeImage_UnsupportedImageFormat[];\nextern const char DecodeImage_UnsupportedPixelBlend[];\nextern const char DecodeImage_UnsupportedPixelConfiguration[];\nextern const char DecodeImage_UnsupportedPixelFormat[];\n\n// DecodeImage decodes the image data in input. A variety of ima" + + "ge file formats\n// can be decoded, depending on what callbacks.SelectDecoder returns.\n//\n// For animated formats, only the first frame is returned, since the API is\n// simpler for synchronous I/O and having DecodeImage only return when\n// completely done, but rendering animation often involves handling other\n// events in between animation frames. To decode multiple frames of animated\n// images, or for asynchronous I/O (e.g. when decoding an image streamed over\n// the network), use Wuffs' lower level C API instead of its higher level,\n// simplified C++ API (the wuffs_aux API).\n//\n// The DecodeImageResult's fields depend on whether decoding succeeded:\n// - On total success, the error_message is empty and pixbuf.pixcfg.is_valid()\n// is true.\n// - On partial success (e.g. the input file was truncated but we are still\n// able to decode some of the pixels), error_message is non-empty but\n// pixbuf.pixcfg.is_valid() is still true. It is up to the caller whether to\n// accept or reject partial success.\n/" + + "/ - On failure, the error_message is non_empty and pixbuf.pixcfg.is_valid()\n// is false.\n//\n// The callbacks allocate the pixel buffer memory and work buffer memory. On\n// success, pixel buffer memory ownership is passed to the DecodeImage caller\n// as the returned pixbuf_mem_owner. Regardless of success or failure, the work\n// buffer memory is deleted.\n//\n// The pixel_blend (one of the constants listed below) determines how to\n// composite the decoded image over the pixel buffer's original pixels (as\n// returned by callbacks.AllocPixbuf):\n// - WUFFS_BASE__PIXEL_BLEND__SRC\n// - WUFFS_BASE__PIXEL_BLEND__SRC_OVER\n//\n// The background_color is used to fill the pixel buffer after\n// callbacks.AllocPixbuf returns, if it is valid in the\n// wuffs_base__color_u32_argb_premul__is_valid sense. The default value,\n// 0x0000_0001, is not valid since its Blue channel value (0x01) is greater\n// than its Alpha channel value (0x00). A valid background_color will typically\n// be overwritten when pixel_blend is WUFFS_BASE" + + "__PIXEL_BLEND__SRC, but might\n// still be visible on partial (not total) success or when pixel_blend is\n// WUFFS_BASE__PIXEL_BLEND__SRC_OVER and the decoded image is not fully opaque.\n//\n// Decoding fails (with DecodeImage_MaxInclDimensionExceeded) if the image's\n// width or height is greater than max_incl_dimension.\nDecodeImageResult //\nDecodeImage(DecodeImageCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__pixel_blend pixel_blend = WUFFS_BASE__PIXEL_BLEND__SRC,\n wuffs_base__color_u32_argb_premul background_color = 1, // Invalid.\n uint32_t max_incl_dimension = 1048575); // 0x000F_FFFF\n\n} // namespace wuffs_aux\n" + "" const AuxJsonCc = "" + - "// ---------------- Auxiliary - JSON\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n\n#include \n\nnamespace wuffs_aux {\n\nDecodeJsonResult::DecodeJsonResult(std::string&& error_message0,\n uint64_t cursor_position0)\n : error_message(std::move(error_message0)),\n cursor_position(cursor_position0) {}\n\nvoid //\nDecodeJsonCallbacks::Done(DecodeJsonResult& result,\n sync_io::Input& input,\n IOBuffer& buffer) {}\n\nconst char DecodeJson_BadJsonPointer[] =\n \"wuffs_aux::DecodeJson: bad JSON Pointer\";\nconst char DecodeJson_NoMatch[] = \"wuffs_aux::DecodeJson: no match\";\n\n" + + "// ---------------- Auxiliary - JSON\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n\n#include \n\nnamespace wuffs_aux {\n\nDecodeJsonResult::DecodeJsonResult(std::string&& error_message0,\n uint64_t cursor_position0)\n : error_message(std::move(error_message0)),\n cursor_position(cursor_position0) {}\n\nDecodeJsonCallbacks::~DecodeJsonCallbacks() {}\n\nvoid //\nDecodeJsonCallbacks::Done(DecodeJsonResult& result,\n sync_io::Input& input,\n IOBuffer& buffer) {}\n\nconst char DecodeJson_BadJsonPointer[] =\n \"wuffs_aux::DecodeJson: bad JSON Pointer\";\nconst char DecodeJson_NoMatch[] = \"wuffs_aux::DecodeJson: no match\";\n\n" + "" + "// --------\n\n#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \\\n while (tok_buf.meta.ri >= tok_buf.meta.wi) { \\\n if (tok_status.repr == nullptr) { \\\n } else if (tok_status.repr == wuffs_base__suspension__short_write) { \\\n tok_buf.compact(); \\\n } else if (tok_status.repr == wuffs_base__suspension__short_read) { \\\n if (!io_error_message.empty()) { \\\n ret_error_message = std::move(io_error_message); \\\n goto done; \\\n } else if (cursor_index != io_buf->meta.ri) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: bad cursor_index\"; \\\n goto done; \\\n } else if (io_buf->meta.closed" + ") { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: io_buf is closed\"; \\\n goto done; \\\n } \\\n io_buf->compact(); \\\n if (io_buf->meta.wi >= io_buf->data.len) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: io_buf is full\"; \\\n goto done; \\\n } \\\n cursor_index = io_buf->meta.ri; \\\n io_error_message = input.CopyIn(io_buf); \\\n } else { \\\n ret_" + @@ -863,10 +864,10 @@ const AuxJsonCc = "" + "" const AuxJsonHh = "" + - "// ---------------- Auxiliary - JSON\n\nnamespace wuffs_aux {\n\nstruct DecodeJsonResult {\n DecodeJsonResult(std::string&& error_message0, uint64_t cursor_position0);\n\n std::string error_message;\n uint64_t cursor_position;\n};\n\nclass DecodeJsonCallbacks {\n public:\n // AppendXxx are called for leaf nodes: literals, numbers and strings. For\n // strings, the Callbacks implementation is responsible for tracking map keys\n // versus other values.\n\n virtual std::string AppendNull() = 0;\n virtual std::string AppendBool(bool val) = 0;\n virtual std::string AppendF64(double val) = 0;\n virtual std::string AppendI64(int64_t val) = 0;\n virtual std::string AppendTextString(std::string&& val) = 0;\n\n // Push and Pop are called for container nodes: JSON arrays (lists) and JSON\n // objects (dictionaries).\n //\n // The flags bits combine exactly one of:\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_NONE\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_LIST\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_DICT\n // and e" + - "xactly one of:\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_NONE\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_LIST\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT\n\n virtual std::string Push(uint32_t flags) = 0;\n virtual std::string Pop(uint32_t flags) = 0;\n\n // Done is always the last Callback method called by DecodeJson, whether or\n // not parsing the input as JSON encountered an error. Even when successful,\n // trailing data may remain in input and buffer. See \"Unintuitive JSON\n // Parsing\" (https://nullprogram.com/blog/2019/12/28/) which discusses JSON\n // parsing and when it stops.\n //\n // Do not keep a reference to buffer or buffer.data.ptr after Done returns,\n // as DecodeJson may then de-allocate the backing array.\n //\n // The default Done implementation is a no-op.\n virtual void //\n Done(DecodeJsonResult& result, sync_io::Input& input, IOBuffer& buffer);\n};\n\nextern const char DecodeJson_BadJsonPointer[];\nextern const char DecodeJson_NoMatch[];\n\n// DecodeJson calls callbacks based o" + - "n the JSON-formatted data in input.\n//\n// On success, the returned error_message is empty and cursor_position counts\n// the number of bytes consumed. On failure, error_message is non-empty and\n// cursor_position is the location of the error. That error may be a content\n// error (invalid JSON) or an input error (e.g. network failure).\n//\n// json_pointer is a query in the JSON Pointer (RFC 6901) syntax. The callbacks\n// run for the input's sub-node that matches the query. DecodeJson_NoMatch is\n// returned if no matching sub-node was found. The empty query matches the\n// input's root node, consistent with JSON Pointer semantics.\n//\n// The JSON Pointer implementation is greedy: duplicate keys are not rejected\n// but only the first match for each '/'-separated fragment is followed.\nDecodeJsonResult //\nDecodeJson(DecodeJsonCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32(),\n std::string json_pointer = std::string());\n\n} // name" + - "space wuffs_aux\n" + + "// ---------------- Auxiliary - JSON\n\nnamespace wuffs_aux {\n\nstruct DecodeJsonResult {\n DecodeJsonResult(std::string&& error_message0, uint64_t cursor_position0);\n\n std::string error_message;\n uint64_t cursor_position;\n};\n\nclass DecodeJsonCallbacks {\n public:\n virtual ~DecodeJsonCallbacks();\n\n // AppendXxx are called for leaf nodes: literals, numbers and strings. For\n // strings, the Callbacks implementation is responsible for tracking map keys\n // versus other values.\n\n virtual std::string AppendNull() = 0;\n virtual std::string AppendBool(bool val) = 0;\n virtual std::string AppendF64(double val) = 0;\n virtual std::string AppendI64(int64_t val) = 0;\n virtual std::string AppendTextString(std::string&& val) = 0;\n\n // Push and Pop are called for container nodes: JSON arrays (lists) and JSON\n // objects (dictionaries).\n //\n // The flags bits combine exactly one of:\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_NONE\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__FROM_LIST\n // - WUFFS_BASE__TOKEN__V" + + "BD__STRUCTURE__FROM_DICT\n // and exactly one of:\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_NONE\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_LIST\n // - WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT\n\n virtual std::string Push(uint32_t flags) = 0;\n virtual std::string Pop(uint32_t flags) = 0;\n\n // Done is always the last Callback method called by DecodeJson, whether or\n // not parsing the input as JSON encountered an error. Even when successful,\n // trailing data may remain in input and buffer. See \"Unintuitive JSON\n // Parsing\" (https://nullprogram.com/blog/2019/12/28/) which discusses JSON\n // parsing and when it stops.\n //\n // Do not keep a reference to buffer or buffer.data.ptr after Done returns,\n // as DecodeJson may then de-allocate the backing array.\n //\n // The default Done implementation is a no-op.\n virtual void //\n Done(DecodeJsonResult& result, sync_io::Input& input, IOBuffer& buffer);\n};\n\nextern const char DecodeJson_BadJsonPointer[];\nextern const char DecodeJson_NoMatch[];\n\n//" + + " DecodeJson calls callbacks based on the JSON-formatted data in input.\n//\n// On success, the returned error_message is empty and cursor_position counts\n// the number of bytes consumed. On failure, error_message is non-empty and\n// cursor_position is the location of the error. That error may be a content\n// error (invalid JSON) or an input error (e.g. network failure).\n//\n// json_pointer is a query in the JSON Pointer (RFC 6901) syntax. The callbacks\n// run for the input's sub-node that matches the query. DecodeJson_NoMatch is\n// returned if no matching sub-node was found. The empty query matches the\n// input's root node, consistent with JSON Pointer semantics.\n//\n// The JSON Pointer implementation is greedy: duplicate keys are not rejected\n// but only the first match for each '/'-separated fragment is followed.\nDecodeJsonResult //\nDecodeJson(DecodeJsonCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32(),\n std::string json_po" + + "inter = std::string());\n\n} // namespace wuffs_aux\n" + "" var AuxNonBaseCcFiles = []string{ diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 89b06f6a..263fa8ab 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -9368,6 +9368,8 @@ namespace sync_io { class Input { public: + virtual ~Input(); + virtual IOBuffer* BringsItsOwnIOBuffer(); virtual std::string CopyIn(IOBuffer* dst) = 0; }; @@ -9431,6 +9433,8 @@ struct DecodeCborResult { class DecodeCborCallbacks { public: + virtual ~DecodeCborCallbacks(); + // AppendXxx are called for leaf nodes: literals, numbers, strings, etc. virtual std::string AppendNull() = 0; @@ -9526,6 +9530,8 @@ class DecodeImageCallbacks { std::string error_message; }; + virtual ~DecodeImageCallbacks(); + // SelectDecoder returns the image decoder for the input data's file format. // Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat). // @@ -9689,6 +9695,8 @@ struct DecodeJsonResult { class DecodeJsonCallbacks { public: + virtual ~DecodeJsonCallbacks(); + // AppendXxx are called for leaf nodes: literals, numbers and strings. For // strings, the Callbacks implementation is responsible for tracking map keys // versus other values. @@ -38438,6 +38446,8 @@ namespace sync_io { // -------- +Input::~Input() {} + IOBuffer* // Input::BringsItsOwnIOBuffer() { return nullptr; @@ -38528,6 +38538,8 @@ DecodeCborResult::DecodeCborResult(std::string&& error_message0, : error_message(std::move(error_message0)), cursor_position(cursor_position0) {} +DecodeCborCallbacks::~DecodeCborCallbacks() {} + void // DecodeCborCallbacks::Done(DecodeCborResult& result, sync_io::Input& input, @@ -38869,6 +38881,8 @@ DecodeImageResult::DecodeImageResult(std::string&& error_message0) pixbuf(wuffs_base__null_pixel_buffer()), error_message(std::move(error_message0)) {} +DecodeImageCallbacks::~DecodeImageCallbacks() {} + DecodeImageCallbacks::AllocResult::AllocResult(MemOwner&& mem_owner0, wuffs_base__slice_u8 mem_slice0) : mem_owner(std::move(mem_owner0)), @@ -39278,6 +39292,8 @@ DecodeJsonResult::DecodeJsonResult(std::string&& error_message0, : error_message(std::move(error_message0)), cursor_position(cursor_position0) {} +DecodeJsonCallbacks::~DecodeJsonCallbacks() {} + void // DecodeJsonCallbacks::Done(DecodeJsonResult& result, sync_io::Input& input,