Skip to content

Commit 1d621bb

Browse files
committed
Being more explicit about EMPTY errors.
1 parent e2f349e commit 1d621bb

6 files changed

Lines changed: 23 additions & 9 deletions

File tree

singleheader/amalgamation_demo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Mon Dec 16 19:07:18 EST 2019. Do not edit! */
1+
/* auto-generated on Wed Dec 18 14:39:04 UTC 2019. Do not edit! */
22

33
#include <iostream>
44
#include "simdjson.h"

singleheader/simdjson.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Mon Dec 16 19:07:18 EST 2019. Do not edit! */
1+
/* auto-generated on Wed Dec 18 14:39:04 UTC 2019. Do not edit! */
22
#include "simdjson.h"
33

44
/* used for http://dmalloc.com/ Dmalloc - Debug Malloc Library */
@@ -497,7 +497,7 @@ const std::map<int, const std::string> error_strings = {
497497
{NUMBER_ERROR, "Problem while parsing a number"},
498498
{UTF8_ERROR, "The input is not valid UTF-8"},
499499
{UNITIALIZED, "Unitialized"},
500-
{EMPTY, "Empty"},
500+
{EMPTY, "Empty: no JSON found"},
501501
{UNESCAPED_CHARS, "Within strings, some characters must be escaped, we "
502502
"found unescaped characters"},
503503
{UNCLOSED_STRING, "A string is opened, but never closed."},
@@ -1061,7 +1061,7 @@ int json_parse(const char *buf, size_t len, ParsedJson &pj,
10611061
realloc);
10621062
}
10631063

1064-
Architecture find_best_supported_implementation() {
1064+
Architecture find_best_supported_architecture() {
10651065
constexpr uint32_t haswell_flags =
10661066
instruction_set::AVX2 | instruction_set::PCLMULQDQ |
10671067
instruction_set::BMI1 | instruction_set::BMI2;
@@ -1077,13 +1077,20 @@ Architecture find_best_supported_implementation() {
10771077
if (supports & instruction_set::NEON)
10781078
return Architecture::ARM64;
10791079

1080-
return Architecture::NONE;
1080+
return Architecture::UNSUPPORTED;
1081+
}
1082+
1083+
Architecture parse_architecture(char *architecture) {
1084+
if (!strcmp(architecture, "HASWELL")) { return Architecture::HASWELL; }
1085+
if (!strcmp(architecture, "WESTMERE")) { return Architecture::WESTMERE; }
1086+
if (!strcmp(architecture, "ARM64")) { return Architecture::ARM64; }
1087+
return Architecture::UNSUPPORTED;
10811088
}
10821089

10831090
// Responsible to select the best json_parse implementation
10841091
int json_parse_dispatch(const uint8_t *buf, size_t len, ParsedJson &pj,
10851092
bool realloc) {
1086-
Architecture best_implementation = find_best_supported_implementation();
1093+
Architecture best_implementation = find_best_supported_architecture();
10871094
// Selecting the best implementation
10881095
switch (best_implementation) {
10891096
#ifdef IS_X86_64

singleheader/simdjson.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* auto-generated on Mon Dec 16 19:07:18 EST 2019. Do not edit! */
1+
/* auto-generated on Wed Dec 18 14:39:04 UTC 2019. Do not edit! */
22
/* begin file include/simdjson/simdjson_version.h */
33
// /include/simdjson/simdjson_version.h automatically generated by release.py,
44
// do not change by hand
@@ -498,10 +498,10 @@ static inline void print_with_escapes(const char *src, std::ostream &os,
498498
namespace simdjson {
499499
// Represents the minimal architecture that would support an implementation
500500
enum class Architecture {
501+
UNSUPPORTED,
501502
WESTMERE,
502503
HASWELL,
503504
ARM64,
504-
NONE,
505505
// TODO remove 'native' in favor of runtime dispatch?
506506
// the 'native' enum class value should point at a good default on the current
507507
// machine
@@ -512,6 +512,9 @@ enum class Architecture {
512512
#endif
513513
};
514514

515+
Architecture find_best_supported_architecture();
516+
Architecture parse_architecture(char *architecture);
517+
515518
enum ErrorValues {
516519
SUCCESS = 0,
517520
SUCCESS_AND_HAS_MORE, //No errors and buffer still has more data

src/simdjson.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const std::map<int, const std::string> error_strings = {
1818
{NUMBER_ERROR, "Problem while parsing a number"},
1919
{UTF8_ERROR, "The input is not valid UTF-8"},
2020
{UNITIALIZED, "Unitialized"},
21-
{EMPTY, "Empty"},
21+
{EMPTY, "Empty: no JSON found"},
2222
{UNESCAPED_CHARS, "Within strings, some characters must be escaped, we "
2323
"found unescaped characters"},
2424
{UNCLOSED_STRING, "A string is opened, but never closed."},

tests/jsoncheck.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ bool validate(const char *dirname) {
8888
is_file_as_expected[i] = false;
8989
printf("warning: file %s should pass but it fails. Error is: %s\n",
9090
name, simdjson::error_message(parse_res).data());
91+
printf("size of file in bytes: %zu \n", p.size());
9192
everything_fine = false;
9293
} else if (starts_with("fail", name) && parse_res == 0) {
9394
is_file_as_expected[i] = false;
9495
printf("warning: file %s should fail but it passes.\n", name);
96+
printf("size of file in bytes: %zu \n", p.size());
9597
everything_fine = false;
9698
}
9799
free(fullpath);

tests/jsonstream_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ bool validate(const char *dirname) {
104104
is_file_as_expected[i] = false;
105105
printf("warning: file %s should pass but it fails. Error is: %s\n",
106106
name, simdjson::error_message(parse_res).data());
107+
printf("size of file in bytes: %zu \n", p.size());
107108
everything_fine = false;
108109
} else if (starts_with("fail", name) && parse_res == 0) {
109110
is_file_as_expected[i] = false;
110111
printf("warning: file %s should fail but it passes.\n", name);
112+
printf("size of file in bytes: %zu \n", p.size());
111113
everything_fine = false;
112114
}
113115
free(fullpath);

0 commit comments

Comments
 (0)