Add std/json

This commit is contained in:
Nigel Tao committed 2020-02-11 10:05:53 +11:00
1 parent f6f2ac4206
commit 7a142168be
4 files changed
+391

No files matched your search

+222
View File
@@ -4814,6 +4814,120 @@ extern "C" {
// ---------------- Status Codes
// ---------------- Public Consts
// ---------------- Struct Declarations
typedef struct wuffs_json__decoder__struct wuffs_json__decoder;
// ---------------- 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 initialize_flags.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_json__decoder__initialize(wuffs_json__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t initialize_flags);
size_t //
sizeof__wuffs_json__decoder();
// ---------------- Upcasts
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src);
// ---------------- 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_json__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 null_vtable;
} private_impl;
#ifdef __cplusplus
#if (__cplusplus >= 201103L) && !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_json__decoder__struct() = delete;
wuffs_json__decoder__struct(const wuffs_json__decoder__struct&) = delete;
wuffs_json__decoder__struct& operator=(const wuffs_json__decoder__struct&) =
delete;
// 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 // (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
initialize(size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t initialize_flags) {
return wuffs_json__decoder__initialize(this, sizeof_star_self,
wuffs_version, initialize_flags);
}
inline wuffs_base__status //
decode_tokens(wuffs_base__io_buffer* a_dst, wuffs_base__io_buffer* a_src) {
return wuffs_json__decoder__decode_tokens(this, a_dst, a_src);
}
#endif // __cplusplus
}; // struct wuffs_json__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Status Codes
extern const char* wuffs_wbmp__error__bad_header;
// ---------------- Public Consts
@@ -17723,6 +17837,114 @@ exit:
#endif // !defined(WUFFS_CONFIG__MODULES) ||
// defined(WUFFS_CONFIG__MODULE__GZIP)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JSON)
// ---------------- Status Codes Implementations
// ---------------- Private Consts
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
// ---------------- VTables
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_json__decoder__initialize(wuffs_json__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t initialize_flags) {
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 ((initialize_flags & 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 ((initialize_flags &
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
return wuffs_base__make_status(NULL);
}
size_t //
sizeof__wuffs_json__decoder() {
return sizeof(wuffs_json__decoder);
}
// ---------------- Function Implementations
// -------- func json.decoder.decode_tokens
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_json__decoder__decode_tokens(wuffs_json__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src) {
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);
status = wuffs_base__make_status(NULL);
goto ok;
goto ok;
ok:
goto exit;
exit:
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__JSON)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
// ---------------- Status Codes Implementations