Compare commits

..
Author SHA1 Message Date
Nigel Tao e88e28259e wuffs gen -version=0.3.0-beta.7 2021-07-18 11:36:39 +10:00
Nigel Tao 6a30c1ede0 Inline wuffs_aux::DecodeJson work_buf variable 2021-07-18 11:25:46 +10:00
Nigel Tao 9c07523a84 Have wuffs_aux::DecodeJson consume trailing filler
Prior to this commit, wuffs_aux::DecodeJson would almost always consume
(optional) trailing filler, but in rare coincidences, it might not if a
wuffs_base__suspension__short_write coroutine suspension was needed
between the last token of the actual JSON value and the first token of
the filler after that JSON value.

This commit should change behavior only if the wuffs_aux::DecodeJson
caller had opted into WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or
WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF.

Also remove an unnecessary std::move on a size_t typed value.
2021-07-18 11:12:41 +10:00
Nigel Tao 816475b285 Add "b" (for "binary") to fopen calls
Updates #50
2021-07-07 20:28:35 +10:00
Nigel Tao d0451190ca wuffs gen -version=0.3.0-beta.6 2021-07-05 21:51:37 +10:00
Nigel Tao 3842c519c9 Delete the WUFFS_BASE__FALLTHROUGH macro
Getting it to work on various compilers has been more trouble than it's
worth. The previous commit ignores "-Wimplicit-fallthrough" instead.
2021-07-05 21:40:25 +10:00
Nigel Tao ea50956b5a Ignore "-Wimplicit-fallthrough" 2021-07-05 21:40:25 +10:00
Nigel Tao fd90553a8f Tweak the WUFFS_BASE__FALLTHROUGH macro
When compiling with "-Werror,-Wimplicit-fallthrough", commit c90cc7b6
tweaked WUFFS_BASE__FALLTHROUGH to work with newer clang compilers, when
defined(__cplusplus) is false, but inadvertently broke older clang
compilers, when __has_attribute(fallthrough) is false.

This commit reverts some of c90cc7b6 to handle more cases. The next two
commits will delete the WUFFS_BASE__FALLTHROUGH macro entirely and
render this commit redundant, as the whole business is proving more
trouble than it's worth. But it's checked into the commit history in
case somebody in the future wants to revive WUFFS_BASE__FALLTHROUGH.
2021-07-05 21:40:18 +10:00
12 changed files with 238 additions and 226 deletions

No files matched your search

+2
View File
@@ -172,6 +172,7 @@ const grPragmaPush = `
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC diagnostic ignored "-Wunreachable-code"
#pragma GCC diagnostic ignored "-Wunused-function"
@@ -181,6 +182,7 @@ const grPragmaPush = `
#endif
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunused-function"
+1 -1
View File
@@ -747,7 +747,7 @@ main1(int argc, char** argv) {
if (g_flags.remaining_argc > 1) {
return g_usage;
} else if (g_flags.remaining_argc == 1) {
in = fopen(g_flags.remaining_argv[0], "r");
in = fopen(g_flags.remaining_argv[0], "rb");
if (!in) {
return std::string("main: cannot read input file");
}
+1 -1
View File
@@ -94,7 +94,7 @@ load_image(const char* filename) {
FILE* file = stdin;
const char* adj_filename = "<stdin>";
if (filename) {
FILE* f = fopen(filename, "r");
FILE* f = fopen(filename, "rb");
if (f == NULL) {
printf("%s: could not open file\n", filename);
return false;
+1 -1
View File
@@ -339,7 +339,7 @@ main1(int argc, char** argv) {
if (g_flags.remaining_argc > 1) {
return g_usage;
} else if (g_flags.remaining_argc == 1) {
in = fopen(g_flags.remaining_argv[0], "r");
in = fopen(g_flags.remaining_argv[0], "rb");
if (!in) {
return std::string("main: cannot read input file");
}
+1 -1
View File
@@ -548,7 +548,7 @@ main1(int argc, char** argv) {
if (g_flags.remaining_argc > 1) {
return g_usage;
} else if (g_flags.remaining_argc == 1) {
in = fopen(g_flags.remaining_argv[0], "r");
in = fopen(g_flags.remaining_argv[0], "rb");
if (!in) {
return std::string("main: cannot read input file");
}
+67 -51
View File
@@ -40,54 +40,50 @@ const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
// --------
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
if (tok_status.repr == nullptr) { \
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
tok_buf.compact(); \
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
if (!io_error_message.empty()) { \
ret_error_message = std::move(io_error_message); \
goto done; \
} else if (cursor_index != io_buf->meta.ri) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
goto done; \
} else if (io_buf->meta.closed) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
goto done; \
} \
io_buf->compact(); \
if (io_buf->meta.wi >= io_buf->data.len) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
goto done; \
} \
cursor_index = io_buf->meta.ri; \
io_error_message = input.CopyIn(io_buf); \
} else { \
ret_error_message = tok_status.message(); \
goto done; \
} \
if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN"; \
goto done; \
} \
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(); \
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf); \
} \
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
uint64_t token_len = token.length(); \
if ((io_buf->meta.ri < cursor_index) || \
((io_buf->meta.ri - cursor_index) < token_len)) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
goto done; \
} \
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
(void)(token_ptr); \
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
if (tok_status.repr == nullptr) { \
goto done; \
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
tok_buf.compact(); \
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
if (!io_error_message.empty()) { \
ret_error_message = std::move(io_error_message); \
goto done; \
} else if (cursor_index != io_buf->meta.ri) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
goto done; \
} else if (io_buf->meta.closed) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
goto done; \
} \
io_buf->compact(); \
if (io_buf->meta.wi >= io_buf->data.len) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
goto done; \
} \
cursor_index = io_buf->meta.ri; \
io_error_message = input.CopyIn(io_buf); \
} else { \
ret_error_message = tok_status.message(); \
goto done; \
} \
tok_status = \
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \
} \
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
uint64_t token_len = token.length(); \
if ((io_buf->meta.ri < cursor_index) || \
((io_buf->meta.ri - cursor_index) < token_len)) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
goto done; \
} \
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
(void)(token_ptr); \
cursor_index += static_cast<size_t>(token_len)
// --------
@@ -358,6 +354,10 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
if (!dec) {
ret_error_message = "wuffs_aux::DecodeJson: out of memory";
goto done;
} else if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
ret_error_message =
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN";
goto done;
}
bool allow_tilde_n_tilde_r_tilde_t = false;
for (size_t i = 0; i < quirks.len; i++) {
@@ -373,7 +373,8 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
wuffs_base__token_buffer tok_buf =
wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
&tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
wuffs_base__status tok_status =
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8());
// Prepare other state.
uint32_t depth = 0;
@@ -387,7 +388,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
}
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
i = std::move(split.second);
i = split.second;
if (i == 0) {
ret_error_message = DecodeJson_BadJsonPointer;
goto done;
@@ -522,7 +523,22 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
goto done;
parsed_a_value:
if (!ret_error_message.empty() || (depth == 0)) {
// If an error was encountered, we are done. Otherwise, (depth == 0)
// after parsing a value is equivalent to having decoded the entire JSON
// value (for an empty json_pointer query) or having decoded the
// pointed-to JSON value (for a non-empty json_pointer query). In the
// latter case, we are also done.
//
// However, if quirks like WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or
// WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF are passed, decoding
// the entire JSON value should also consume any trailing filler, in case
// the DecodeJson caller wants to subsequently check that the input is
// completely exhausted (and otherwise raise "valid JSON followed by
// further (unexpected) data"). We aren't done yet. Instead, keep the
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
// decode_tokens returns an ok status.
if (!ret_error_message.empty() ||
((depth == 0) && !json_pointer.empty())) {
goto done;
}
}
+2 -16
View File
@@ -29,30 +29,16 @@
// Its (non-zero) value is arbitrary, based on md5sum("disabled").
#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
//
// The two #if lines are deliberately separate. Combining the two conditions
// into a single "#if foo && bar" line would not be portable. See
// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
#if defined(__has_attribute)
#if __has_attribute(fallthrough)
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
#else
#define WUFFS_BASE__FALLTHROUGH
#endif
#else
#define WUFFS_BASE__FALLTHROUGH
#endif
// Use switch cases for coroutine suspension points, similar to the technique
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
//
// The implicit fallthrough is intentional.
//
// We use trivial macros instead of an explicit assignment and case statement
// so that clang-format doesn't get confused by the unusual "case"s.
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
coro_susp_point = n; \
WUFFS_BASE__FALLTHROUGH; \
case n:;
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
+14 -14
View File
@@ -29,9 +29,8 @@ const BaseAllImplC = "" +
""
const BaseFundamentalPrivateH = "" +
"// ---------------- Fundamentals\n\n// WUFFS_BASE__MAGIC is a magic number to check that initializers are called.\n// It's not foolproof, given C doesn't automatically zero memory before use,\n// but it should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// WUFFS_BASE__DISABLED is a magic number to indicate that a non-recoverable\n// error was previously encountered.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"disabled\").\n#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)\n\n// Denote intentional fallthroughs for -Wimplicit-fallthrough.\n//\n// The two #if lines are deliberately separate. Combining the two conditions\n// into a single \"#if foo && bar\" line would not be portable. See\n// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html\n#if defined(__has_attribute)\n#if __has_attribute(fallthrough)\n#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))\n#else\n#define WUFFS_BASE__FALLTHROUGH\n" +
"#endif\n#else\n#define WUFFS_BASE__FALLTHROUGH\n#endif\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use trivial macros instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n WUFFS_BASE__FALLTHROUGH; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (!status.repr) { \\\n goto ok; \\\n } else if (*status.repr != '$') { \\\n goto exit; \\\n } \\\n coro_susp_point = n; " +
" \\\n goto suspend; \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n" +
"// ---------------- Fundamentals\n\n// WUFFS_BASE__MAGIC is a magic number to check that initializers are called.\n// It's not foolproof, given C doesn't automatically zero memory before use,\n// but it should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// WUFFS_BASE__DISABLED is a magic number to indicate that a non-recoverable\n// error was previously encountered.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"disabled\").\n#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// The implicit fallthrough is intentional.\n//\n// We use trivial macros instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;\n#define WUFFS_BASE__COROUTINE_SUSPENSION_" +
"POINT(n) \\\n coro_susp_point = n; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (!status.repr) { \\\n goto ok; \\\n } else if (*status.repr != '$') { \\\n goto exit; \\\n } \\\n coro_susp_point = n; \\\n goto suspend; \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n" +
"" +
"// --------\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__ignore_status(wuffs_base__status z) {\n return wuffs_base__make_empty_struct();\n}\n\nstatic inline wuffs_base__status //\nwuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) {\n if (z.repr && (*z.repr == '$')) {\n z.repr = wuffs_base__error__cannot_return_a_suspension;\n }\n return z;\n}\n\n" +
"" +
@@ -858,10 +857,10 @@ const AuxImageHh = "" +
const AuxJsonCc = "" +
"// ---------------- Auxiliary - JSON\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n\n#include <utility>\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_" +
"error_message = tok_status.message(); \\\n goto done; \\\n } \\\n if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: 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 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::DecodeJson: internal error: bad token indexes\"; \\\n goto done; \\\n } \\\n uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \\\n (void)(token_ptr); \\\n cursor_index += static_cast<size_t>(token_len)\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 goto done; \\\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 i" +
"o_error_message = input.CopyIn(io_buf); \\\n } else { \\\n ret_error_message = tok_status.message(); \\\n goto done; \\\n } \\\n tok_status = \\\n dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \\\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_au" +
"x::DecodeJson: internal error: bad token indexes\"; \\\n goto done; \\\n } \\\n uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \\\n (void)(token_ptr); \\\n cursor_index += static_cast<size_t>(token_len)\n\n" +
"" +
"// --------\n\nnamespace {\n\n// DecodeJson_SplitJsonPointer returns (\"bar\", 8) for (\"/foo/bar/b~1z/qux\", 5,\n// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax.\n//\n// The string returned is unescaped. If calling it again, this time with i=8,\n// the \"b~1z\" substring would be returned as \"b/z\".\nstd::pair<std::string, size_t> //\nDecodeJson_SplitJsonPointer(std::string& s,\n size_t i,\n bool allow_tilde_n_tilde_r_tilde_t) {\n std::string fragment;\n while (i < s.size()) {\n char c = s[i];\n if (c == '/') {\n break;\n } else if (c != '~') {\n fragment.push_back(c);\n i++;\n continue;\n }\n i++;\n if (i >= s.size()) {\n return std::make_pair(std::string(), 0);\n }\n c = s[i];\n if (c == '0') {\n fragment.push_back('~');\n i++;\n continue;\n } else if (c == '1') {\n fragment.push_back('/');\n i++;\n continue;\n } else if (allow_tilde_n_tilde_r_tilde_t) {\n if (c == 'n') {\n " +
"fragment.push_back('\\n');\n i++;\n continue;\n } else if (c == 'r') {\n fragment.push_back('\\r');\n i++;\n continue;\n } else if (c == 't') {\n fragment.push_back('\\t');\n i++;\n continue;\n }\n }\n return std::make_pair(std::string(), 0);\n }\n return std::make_pair(std::move(fragment), i);\n}\n\n" +
@@ -874,13 +873,14 @@ const AuxJsonCc = "" +
"__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n if (vbc == WUFFS_BASE__TOKEN__VBC__FILLER) {\n continue;\n }\n\n // Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so that\n // we're only peeking at the next token.\n tok_buf.meta.ri--;\n cursor_index -= static_cast<size_t>(token_len);\n\n if ((vbc == WUFFS_BASE__TOKEN__VBC__STRUCTURE) &&\n (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__POP)) {\n return DecodeJson_NoMatch;\n }\n return \"\";\n } // check_that_a_value_follows\n\nfail:\n return \"wuffs_aux::DecodeJson: internal error: unexpected token\";\ndone:\n return ret_error_message;\n}\n\n} // namespace\n\n" +
"" +
"// --------\n\nDecodeJsonResult //\nDecodeJson(DecodeJsonCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks,\n std::string json_pointer) {\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<uint8_t[]> fallback_io_array(nullptr);\n if (!io_buf) {\n fallback_io_array = std::unique_ptr<uint8_t[]>(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 JSON decoder.\n wuffs_json__decoder::unique_ptr dec = wuffs_json__decoder::alloc();\n if (!dec) {\n ret_error_message = " +
"\"wuffs_aux::DecodeJson: out of memory\";\n goto done;\n }\n bool allow_tilde_n_tilde_r_tilde_t = false;\n for (size_t i = 0; i < quirks.len; i++) {\n dec->set_quirk_enabled(quirks.ptr[i], true);\n if (quirks.ptr[i] ==\n WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {\n allow_tilde_n_tilde_r_tilde_t = true;\n }\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\n // Walk the (optional) JSON Pointer.\n for (size_t i = 0; i < json_pointer.size();) {\n if (json_pointer[i] != '/') {\n ret_error_message = DecodeJson_BadJsonPointer;\n goto done;\n }\n std::pair<" +
"std::string, size_t> split = DecodeJson_SplitJsonPointer(\n json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);\n i = std::move(split.second);\n if (i == 0) {\n ret_error_message = DecodeJson_BadJsonPointer;\n goto done;\n }\n ret_error_message = DecodeJson_WalkJsonPointerFragment(\n tok_buf, tok_status, dec, io_buf, io_error_message, cursor_index,\n input, split.first);\n if (!ret_error_message.empty()) {\n goto done;\n }\n }\n\n // Loop, doing these two things:\n // 1. Get the next token.\n // 2. Process that token.\n while (true) {\n WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n switch (vbc) {\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_cas" +
"t<uint32_t>(vbd));\n if (!ret_error_message.empty()) {\n goto done;\n }\n depth++;\n continue;\n }\n ret_error_message = callbacks.Pop(static_cast<uint32_t>(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<const char*>(static_cast<void*>(token_ptr));\n str.append(ptr, static_cast<size_t>(token_len));\n } else {\n goto fail;\n }\n if (token.continued()) {\n continue;\n }\n ret_error_message = callbacks.AppendTextString(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<uint32_t>(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(&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 ret_error_message =\n (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__NULL)\n ? callbacks.AppendNull()\n : callbacks.AppendBool(vbd &\n WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE);\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__NUMBER: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_TEXT) {\n " +
" if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED) {\n wuffs_base__result_i64 r = wuffs_base__parse_number_i64(\n wuffs_base__make_slice_u8(token_ptr,\n static_cast<size_t>(token_len)),\n WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);\n if (r.status.is_ok()) {\n ret_error_message = callbacks.AppendI64(r.value);\n goto parsed_a_value;\n }\n }\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT) {\n wuffs_base__result_f64 r = wuffs_base__parse_number_f64(\n wuffs_base__make_slice_u8(token_ptr,\n static_cast<size_t>(token_len)),\n WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);\n if (r.status.is_ok()) {\n ret_error_message = callbacks.AppendF64(r.value);\n goto parsed_a_value;\n }" +
"\n }\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_INF) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0xFFF0000000000000ul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_POS_INF) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0x7FF0000000000000ul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_NAN) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0xFFFFFFFFFFFFFFFFul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_POS_NAN) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee" +
"_754_bit_representation__from_u64_to_f64(\n 0x7FFFFFFFFFFFFFFFul));\n goto parsed_a_value;\n }\n goto fail;\n }\n }\n\n fail:\n ret_error_message =\n \"wuffs_aux::DecodeJson: 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 DecodeJsonResult 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#undef WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n" +
"\"wuffs_aux::DecodeJson: out of memory\";\n goto done;\n } else if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {\n ret_error_message =\n \"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN\";\n goto done;\n }\n bool allow_tilde_n_tilde_r_tilde_t = false;\n for (size_t i = 0; i < quirks.len; i++) {\n dec->set_quirk_enabled(quirks.ptr[i], true);\n if (quirks.ptr[i] ==\n WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {\n allow_tilde_n_tilde_r_tilde_t = true;\n }\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 =\n dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8());\n\n // Prepare other state.\n uint32_t depth = 0;\n std::string str;" +
"\n\n // Walk the (optional) JSON Pointer.\n for (size_t i = 0; i < json_pointer.size();) {\n if (json_pointer[i] != '/') {\n ret_error_message = DecodeJson_BadJsonPointer;\n goto done;\n }\n std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(\n json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);\n i = split.second;\n if (i == 0) {\n ret_error_message = DecodeJson_BadJsonPointer;\n goto done;\n }\n ret_error_message = DecodeJson_WalkJsonPointerFragment(\n tok_buf, tok_status, dec, io_buf, io_error_message, cursor_index,\n input, split.first);\n if (!ret_error_message.empty()) {\n goto done;\n }\n }\n\n // Loop, doing these two things:\n // 1. Get the next token.\n // 2. Process that token.\n while (true) {\n WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n switch (vbc) {\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<uint32_t>(vbd));\n if (!ret_error_message.empty()) {\n goto done;\n }\n depth++;\n continue;\n }\n ret_error_message = callbacks.Pop(static_cast<uint32_t>(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<const char*>(static_cast<void*>(token_ptr));\n str.append(ptr, static_cast<size_t>(token_len));\n } else {\n goto fail;\n }\n " +
"if (token.continued()) {\n continue;\n }\n ret_error_message = callbacks.AppendTextString(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<uint32_t>(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(&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 ret_error_message =\n (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__NULL)\n ? callbacks.AppendNull()\n : callbacks.AppendBool(vbd &\n " +
" WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE);\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__NUMBER: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_TEXT) {\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED) {\n wuffs_base__result_i64 r = wuffs_base__parse_number_i64(\n wuffs_base__make_slice_u8(token_ptr,\n static_cast<size_t>(token_len)),\n WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);\n if (r.status.is_ok()) {\n ret_error_message = callbacks.AppendI64(r.value);\n goto parsed_a_value;\n }\n }\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT) {\n wuffs_base__result_f64 r = wuffs_base__parse_number_f64(\n wuffs_base__make_slice_u8(token_ptr,\n static_cast<size_t>(token_len)),\n " +
" WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);\n if (r.status.is_ok()) {\n ret_error_message = callbacks.AppendF64(r.value);\n goto parsed_a_value;\n }\n }\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_INF) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0xFFF0000000000000ul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_POS_INF) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0x7FF0000000000000ul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_NAN) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0xF" +
"FFFFFFFFFFFFFFFul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_POS_NAN) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0x7FFFFFFFFFFFFFFFul));\n goto parsed_a_value;\n }\n goto fail;\n }\n }\n\n fail:\n ret_error_message =\n \"wuffs_aux::DecodeJson: internal error: unexpected token\";\n goto done;\n\n parsed_a_value:\n // If an error was encountered, we are done. Otherwise, (depth == 0)\n // after parsing a value is equivalent to having decoded the entire JSON\n // value (for an empty json_pointer query) or having decoded the\n // pointed-to JSON value (for a non-empty json_pointer query). In the\n // latter case, we are also done.\n //\n // However, if quirks like WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or\n // WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF are pass" +
"ed, decoding\n // the entire JSON value should also consume any trailing filler, in case\n // the DecodeJson caller wants to subsequently check that the input is\n // completely exhausted (and otherwise raise \"valid JSON followed by\n // further (unexpected) data\"). We aren't done yet. Instead, keep the\n // loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's\n // decode_tokens returns an ok status.\n if (!ret_error_message.empty() ||\n ((depth == 0) && !json_pointer.empty())) {\n goto done;\n }\n }\n } while (false);\n\ndone:\n DecodeJsonResult 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#undef WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n" +
""
const AuxJsonHh = "" +
+71 -67
View File
@@ -15,6 +15,7 @@
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC diagnostic ignored "-Wunreachable-code"
#pragma GCC diagnostic ignored "-Wunused-function"
@@ -24,6 +25,7 @@
#endif
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunused-function"
@@ -10109,30 +10111,16 @@ extern "C" {
// Its (non-zero) value is arbitrary, based on md5sum("disabled").
#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
//
// The two #if lines are deliberately separate. Combining the two conditions
// into a single "#if foo && bar" line would not be portable. See
// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
#if defined(__has_attribute)
#if __has_attribute(fallthrough)
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
#else
#define WUFFS_BASE__FALLTHROUGH
#endif
#else
#define WUFFS_BASE__FALLTHROUGH
#endif
// Use switch cases for coroutine suspension points, similar to the technique
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
//
// The implicit fallthrough is intentional.
//
// We use trivial macros instead of an explicit assignment and case statement
// so that clang-format doesn't get confused by the unusual "case"s.
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
coro_susp_point = n; \
WUFFS_BASE__FALLTHROUGH; \
case n:;
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
@@ -40065,54 +40053,50 @@ const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
// --------
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
if (tok_status.repr == nullptr) { \
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
tok_buf.compact(); \
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
if (!io_error_message.empty()) { \
ret_error_message = std::move(io_error_message); \
goto done; \
} else if (cursor_index != io_buf->meta.ri) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
goto done; \
} else if (io_buf->meta.closed) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
goto done; \
} \
io_buf->compact(); \
if (io_buf->meta.wi >= io_buf->data.len) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
goto done; \
} \
cursor_index = io_buf->meta.ri; \
io_error_message = input.CopyIn(io_buf); \
} else { \
ret_error_message = tok_status.message(); \
goto done; \
} \
if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN"; \
goto done; \
} \
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(); \
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf); \
} \
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
uint64_t token_len = token.length(); \
if ((io_buf->meta.ri < cursor_index) || \
((io_buf->meta.ri - cursor_index) < token_len)) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
goto done; \
} \
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
(void)(token_ptr); \
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
if (tok_status.repr == nullptr) { \
goto done; \
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
tok_buf.compact(); \
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
if (!io_error_message.empty()) { \
ret_error_message = std::move(io_error_message); \
goto done; \
} else if (cursor_index != io_buf->meta.ri) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
goto done; \
} else if (io_buf->meta.closed) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
goto done; \
} \
io_buf->compact(); \
if (io_buf->meta.wi >= io_buf->data.len) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
goto done; \
} \
cursor_index = io_buf->meta.ri; \
io_error_message = input.CopyIn(io_buf); \
} else { \
ret_error_message = tok_status.message(); \
goto done; \
} \
tok_status = \
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \
} \
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
uint64_t token_len = token.length(); \
if ((io_buf->meta.ri < cursor_index) || \
((io_buf->meta.ri - cursor_index) < token_len)) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
goto done; \
} \
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
(void)(token_ptr); \
cursor_index += static_cast<size_t>(token_len)
// --------
@@ -40383,6 +40367,10 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
if (!dec) {
ret_error_message = "wuffs_aux::DecodeJson: out of memory";
goto done;
} else if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
ret_error_message =
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN";
goto done;
}
bool allow_tilde_n_tilde_r_tilde_t = false;
for (size_t i = 0; i < quirks.len; i++) {
@@ -40398,7 +40386,8 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
wuffs_base__token_buffer tok_buf =
wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
&tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
wuffs_base__status tok_status =
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8());
// Prepare other state.
uint32_t depth = 0;
@@ -40412,7 +40401,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
}
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
i = std::move(split.second);
i = split.second;
if (i == 0) {
ret_error_message = DecodeJson_BadJsonPointer;
goto done;
@@ -40547,7 +40536,22 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
goto done;
parsed_a_value:
if (!ret_error_message.empty() || (depth == 0)) {
// If an error was encountered, we are done. Otherwise, (depth == 0)
// after parsing a value is equivalent to having decoded the entire JSON
// value (for an empty json_pointer query) or having decoded the
// pointed-to JSON value (for a non-empty json_pointer query). In the
// latter case, we are also done.
//
// However, if quirks like WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or
// WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF are passed, decoding
// the entire JSON value should also consume any trailing filler, in case
// the DecodeJson caller wants to subsequently check that the input is
// completely exhausted (and otherwise raise "valid JSON followed by
// further (unexpected) data"). We aren't done yet. Instead, keep the
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
// decode_tokens returns an ok status.
if (!ret_error_message.empty() ||
((depth == 0) && !json_pointer.empty())) {
goto done;
}
}
+76 -72
View File
@@ -15,6 +15,7 @@
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#pragma GCC diagnostic ignored "-Wunreachable-code"
#pragma GCC diagnostic ignored "-Wunused-function"
@@ -24,6 +25,7 @@
#endif
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wunreachable-code"
#pragma clang diagnostic ignored "-Wunused-function"
@@ -82,15 +84,15 @@ extern "C" {
// each major.minor branch, the commit count should increase monotonically.
//
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
// 3a516e512c9236c72deaf3fe65b03d377796767e committed on 2021-07-02.
// 6a30c1ede0dc765fbbc443b2536b7691485be9fb committed on 2021-07-18.
#define WUFFS_VERSION 0x000030000
#define WUFFS_VERSION_MAJOR 0
#define WUFFS_VERSION_MINOR 3
#define WUFFS_VERSION_PATCH 0
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.5"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3062
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20210702
#define WUFFS_VERSION_STRING "0.3.0-beta.5+3062.20210702"
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.7"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3069
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20210718
#define WUFFS_VERSION_STRING "0.3.0-beta.7+3069.20210718"
// ---------------- Configuration
@@ -10110,30 +10112,16 @@ extern "C" {
// Its (non-zero) value is arbitrary, based on md5sum("disabled").
#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
//
// The two #if lines are deliberately separate. Combining the two conditions
// into a single "#if foo && bar" line would not be portable. See
// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
#if defined(__has_attribute)
#if __has_attribute(fallthrough)
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
#else
#define WUFFS_BASE__FALLTHROUGH
#endif
#else
#define WUFFS_BASE__FALLTHROUGH
#endif
// Use switch cases for coroutine suspension points, similar to the technique
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
//
// The implicit fallthrough is intentional.
//
// We use trivial macros instead of an explicit assignment and case statement
// so that clang-format doesn't get confused by the unusual "case"s.
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
coro_susp_point = n; \
WUFFS_BASE__FALLTHROUGH; \
case n:;
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
@@ -40066,54 +40054,50 @@ const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
// --------
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
if (tok_status.repr == nullptr) { \
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
tok_buf.compact(); \
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
if (!io_error_message.empty()) { \
ret_error_message = std::move(io_error_message); \
goto done; \
} else if (cursor_index != io_buf->meta.ri) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
goto done; \
} else if (io_buf->meta.closed) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
goto done; \
} \
io_buf->compact(); \
if (io_buf->meta.wi >= io_buf->data.len) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
goto done; \
} \
cursor_index = io_buf->meta.ri; \
io_error_message = input.CopyIn(io_buf); \
} else { \
ret_error_message = tok_status.message(); \
goto done; \
} \
if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN"; \
goto done; \
} \
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(); \
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf); \
} \
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
uint64_t token_len = token.length(); \
if ((io_buf->meta.ri < cursor_index) || \
((io_buf->meta.ri - cursor_index) < token_len)) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
goto done; \
} \
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
(void)(token_ptr); \
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
if (tok_status.repr == nullptr) { \
goto done; \
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
tok_buf.compact(); \
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
if (!io_error_message.empty()) { \
ret_error_message = std::move(io_error_message); \
goto done; \
} else if (cursor_index != io_buf->meta.ri) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
goto done; \
} else if (io_buf->meta.closed) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
goto done; \
} \
io_buf->compact(); \
if (io_buf->meta.wi >= io_buf->data.len) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
goto done; \
} \
cursor_index = io_buf->meta.ri; \
io_error_message = input.CopyIn(io_buf); \
} else { \
ret_error_message = tok_status.message(); \
goto done; \
} \
tok_status = \
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \
} \
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
uint64_t token_len = token.length(); \
if ((io_buf->meta.ri < cursor_index) || \
((io_buf->meta.ri - cursor_index) < token_len)) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
goto done; \
} \
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
(void)(token_ptr); \
cursor_index += static_cast<size_t>(token_len)
// --------
@@ -40384,6 +40368,10 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
if (!dec) {
ret_error_message = "wuffs_aux::DecodeJson: out of memory";
goto done;
} else if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
ret_error_message =
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN";
goto done;
}
bool allow_tilde_n_tilde_r_tilde_t = false;
for (size_t i = 0; i < quirks.len; i++) {
@@ -40399,7 +40387,8 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
wuffs_base__token_buffer tok_buf =
wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
&tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
wuffs_base__status tok_status =
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8());
// Prepare other state.
uint32_t depth = 0;
@@ -40413,7 +40402,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
}
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
i = std::move(split.second);
i = split.second;
if (i == 0) {
ret_error_message = DecodeJson_BadJsonPointer;
goto done;
@@ -40548,7 +40537,22 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
goto done;
parsed_a_value:
if (!ret_error_message.empty() || (depth == 0)) {
// If an error was encountered, we are done. Otherwise, (depth == 0)
// after parsing a value is equivalent to having decoded the entire JSON
// value (for an empty json_pointer query) or having decoded the
// pointed-to JSON value (for a non-empty json_pointer query). In the
// latter case, we are also done.
//
// However, if quirks like WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or
// WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF are passed, decoding
// the entire JSON value should also consume any trailing filler, in case
// the DecodeJson caller wants to subsequently check that the input is
// completely exhausted (and otherwise raise "valid JSON followed by
// further (unexpected) data"). We aren't done yet. Instead, keep the
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
// decode_tokens returns an ok status.
if (!ret_error_message.empty() ||
((depth == 0) && !json_pointer.empty())) {
goto done;
}
}
+1 -1
View File
@@ -261,7 +261,7 @@ process_file(char* filename) {
g_file = NULL;
}
g_filename = filename;
g_file = fopen(g_filename, "r");
g_file = fopen(g_filename, "rb");
if (!g_file) {
fprintf(stderr, "main: could not open %s\n", g_filename);
return false;
+1 -1
View File
@@ -671,7 +671,7 @@ read_file(wuffs_base__io_buffer* dst, const char* path) {
original_path);
}
FILE* f = fopen(path, "r");
FILE* f = fopen(path, "rb");
if (!f) {
RETURN_FAIL("read_file(\"%s\"): %s (errno=%d)", path, strerror(errno),
errno);