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 "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"
/* 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"},
{UTF8_ERROR, "The input is not valid UTF-8"},
{UNITIALIZED, "Unitialized"},
{EMPTY, "Empty"},
{EMPTY, "Empty: no JSON found"},
{UNESCAPED_CHARS, "Within strings, some characters must be escaped, we "
"found unescaped characters"},
{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);
}
Architecture find_best_supported_implementation() {
Architecture find_best_supported_architecture() {
constexpr uint32_t haswell_flags =
instruction_set::AVX2 | instruction_set::PCLMULQDQ |
instruction_set::BMI1 | instruction_set::BMI2;
@ -1077,13 +1077,20 @@ Architecture find_best_supported_implementation() {
if (supports & instruction_set::NEON)
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
int json_parse_dispatch(const uint8_t *buf, size_t len, ParsedJson &pj,
bool realloc) {
Architecture best_implementation = find_best_supported_implementation();
Architecture best_implementation = find_best_supported_architecture();
// Selecting the best implementation
switch (best_implementation) {
#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 */
// /include/simdjson/simdjson_version.h automatically generated by release.py,
// do not change by hand
@ -498,10 +498,10 @@ static inline void print_with_escapes(const char *src, std::ostream &os,
namespace simdjson {
// Represents the minimal architecture that would support an implementation
enum class Architecture {
UNSUPPORTED,
WESTMERE,
HASWELL,
ARM64,
NONE,
// TODO remove 'native' in favor of runtime dispatch?
// the 'native' enum class value should point at a good default on the current
// machine
@ -512,6 +512,9 @@ enum class Architecture {
#endif
};
Architecture find_best_supported_architecture();
Architecture parse_architecture(char *architecture);
enum ErrorValues {
SUCCESS = 0,
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"},
{UTF8_ERROR, "The input is not valid UTF-8"},
{UNITIALIZED, "Unitialized"},
{EMPTY, "Empty"},
{EMPTY, "Empty: no JSON found"},
{UNESCAPED_CHARS, "Within strings, some characters must be escaped, we "
"found unescaped characters"},
{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;
printf("warning: file %s should pass but it fails. Error is: %s\n",
name, simdjson::error_message(parse_res).data());
printf("size of file in bytes: %zu \n", p.size());
everything_fine = false;
} else if (starts_with("fail", name) && parse_res == 0) {
is_file_as_expected[i] = false;
printf("warning: file %s should fail but it passes.\n", name);
printf("size of file in bytes: %zu \n", p.size());
everything_fine = false;
}
free(fullpath);

View File

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