Being more explicit about EMPTY errors.

This commit is contained in:
Daniel Lemire 2019-12-18 14:39:48 +00:00
parent e2f349e7bd
commit 1d621bba37
6 changed files with 23 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/* auto-generated on Mon Dec 16 19:07:18 EST 2019. Do not edit! */ /* auto-generated on Wed Dec 18 14:39:04 UTC 2019. Do not edit! */
#include <iostream> #include <iostream>
#include "simdjson.h" #include "simdjson.h"

View File

@ -1,4 +1,4 @@
/* auto-generated on Mon Dec 16 19:07:18 EST 2019. Do not edit! */ /* auto-generated on Wed Dec 18 14:39:04 UTC 2019. Do not edit! */
#include "simdjson.h" #include "simdjson.h"
/* used for http://dmalloc.com/ Dmalloc - Debug Malloc Library */ /* used for http://dmalloc.com/ Dmalloc - Debug Malloc Library */
@ -497,7 +497,7 @@ const std::map<int, const std::string> error_strings = {
{NUMBER_ERROR, "Problem while parsing a number"}, {NUMBER_ERROR, "Problem while parsing a number"},
{UTF8_ERROR, "The input is not valid UTF-8"}, {UTF8_ERROR, "The input is not valid UTF-8"},
{UNITIALIZED, "Unitialized"}, {UNITIALIZED, "Unitialized"},
{EMPTY, "Empty"}, {EMPTY, "Empty: no JSON found"},
{UNESCAPED_CHARS, "Within strings, some characters must be escaped, we " {UNESCAPED_CHARS, "Within strings, some characters must be escaped, we "
"found unescaped characters"}, "found unescaped characters"},
{UNCLOSED_STRING, "A string is opened, but never closed."}, {UNCLOSED_STRING, "A string is opened, but never closed."},
@ -1061,7 +1061,7 @@ int json_parse(const char *buf, size_t len, ParsedJson &pj,
realloc); realloc);
} }
Architecture find_best_supported_implementation() { Architecture find_best_supported_architecture() {
constexpr uint32_t haswell_flags = constexpr uint32_t haswell_flags =
instruction_set::AVX2 | instruction_set::PCLMULQDQ | instruction_set::AVX2 | instruction_set::PCLMULQDQ |
instruction_set::BMI1 | instruction_set::BMI2; instruction_set::BMI1 | instruction_set::BMI2;
@ -1077,13 +1077,20 @@ Architecture find_best_supported_implementation() {
if (supports & instruction_set::NEON) if (supports & instruction_set::NEON)
return Architecture::ARM64; return Architecture::ARM64;
return Architecture::NONE; return Architecture::UNSUPPORTED;
}
Architecture parse_architecture(char *architecture) {
if (!strcmp(architecture, "HASWELL")) { return Architecture::HASWELL; }
if (!strcmp(architecture, "WESTMERE")) { return Architecture::WESTMERE; }
if (!strcmp(architecture, "ARM64")) { return Architecture::ARM64; }
return Architecture::UNSUPPORTED;
} }
// Responsible to select the best json_parse implementation // Responsible to select the best json_parse implementation
int json_parse_dispatch(const uint8_t *buf, size_t len, ParsedJson &pj, int json_parse_dispatch(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc) { bool realloc) {
Architecture best_implementation = find_best_supported_implementation(); Architecture best_implementation = find_best_supported_architecture();
// Selecting the best implementation // Selecting the best implementation
switch (best_implementation) { switch (best_implementation) {
#ifdef IS_X86_64 #ifdef IS_X86_64

View File

@ -1,4 +1,4 @@
/* auto-generated on Mon Dec 16 19:07:18 EST 2019. Do not edit! */ /* auto-generated on Wed Dec 18 14:39:04 UTC 2019. Do not edit! */
/* begin file include/simdjson/simdjson_version.h */ /* begin file include/simdjson/simdjson_version.h */
// /include/simdjson/simdjson_version.h automatically generated by release.py, // /include/simdjson/simdjson_version.h automatically generated by release.py,
// do not change by hand // do not change by hand
@ -498,10 +498,10 @@ static inline void print_with_escapes(const char *src, std::ostream &os,
namespace simdjson { namespace simdjson {
// Represents the minimal architecture that would support an implementation // Represents the minimal architecture that would support an implementation
enum class Architecture { enum class Architecture {
UNSUPPORTED,
WESTMERE, WESTMERE,
HASWELL, HASWELL,
ARM64, ARM64,
NONE,
// TODO remove 'native' in favor of runtime dispatch? // TODO remove 'native' in favor of runtime dispatch?
// the 'native' enum class value should point at a good default on the current // the 'native' enum class value should point at a good default on the current
// machine // machine
@ -512,6 +512,9 @@ enum class Architecture {
#endif #endif
}; };
Architecture find_best_supported_architecture();
Architecture parse_architecture(char *architecture);
enum ErrorValues { enum ErrorValues {
SUCCESS = 0, SUCCESS = 0,
SUCCESS_AND_HAS_MORE, //No errors and buffer still has more data SUCCESS_AND_HAS_MORE, //No errors and buffer still has more data

View File

@ -18,7 +18,7 @@ const std::map<int, const std::string> error_strings = {
{NUMBER_ERROR, "Problem while parsing a number"}, {NUMBER_ERROR, "Problem while parsing a number"},
{UTF8_ERROR, "The input is not valid UTF-8"}, {UTF8_ERROR, "The input is not valid UTF-8"},
{UNITIALIZED, "Unitialized"}, {UNITIALIZED, "Unitialized"},
{EMPTY, "Empty"}, {EMPTY, "Empty: no JSON found"},
{UNESCAPED_CHARS, "Within strings, some characters must be escaped, we " {UNESCAPED_CHARS, "Within strings, some characters must be escaped, we "
"found unescaped characters"}, "found unescaped characters"},
{UNCLOSED_STRING, "A string is opened, but never closed."}, {UNCLOSED_STRING, "A string is opened, but never closed."},

View File

@ -88,10 +88,12 @@ bool validate(const char *dirname) {
is_file_as_expected[i] = false; is_file_as_expected[i] = false;
printf("warning: file %s should pass but it fails. Error is: %s\n", printf("warning: file %s should pass but it fails. Error is: %s\n",
name, simdjson::error_message(parse_res).data()); name, simdjson::error_message(parse_res).data());
printf("size of file in bytes: %zu \n", p.size());
everything_fine = false; everything_fine = false;
} else if (starts_with("fail", name) && parse_res == 0) { } else if (starts_with("fail", name) && parse_res == 0) {
is_file_as_expected[i] = false; is_file_as_expected[i] = false;
printf("warning: file %s should fail but it passes.\n", name); printf("warning: file %s should fail but it passes.\n", name);
printf("size of file in bytes: %zu \n", p.size());
everything_fine = false; everything_fine = false;
} }
free(fullpath); free(fullpath);

View File

@ -104,10 +104,12 @@ bool validate(const char *dirname) {
is_file_as_expected[i] = false; is_file_as_expected[i] = false;
printf("warning: file %s should pass but it fails. Error is: %s\n", printf("warning: file %s should pass but it fails. Error is: %s\n",
name, simdjson::error_message(parse_res).data()); name, simdjson::error_message(parse_res).data());
printf("size of file in bytes: %zu \n", p.size());
everything_fine = false; everything_fine = false;
} else if (starts_with("fail", name) && parse_res == 0) { } else if (starts_with("fail", name) && parse_res == 0) {
is_file_as_expected[i] = false; is_file_as_expected[i] = false;
printf("warning: file %s should fail but it passes.\n", name); printf("warning: file %s should fail but it passes.\n", name);
printf("size of file in bytes: %zu \n", p.size());
everything_fine = false; everything_fine = false;
} }
free(fullpath); free(fullpath);