From 8f3ddd3a73d4a6da7656552d531bfa4261742a66 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Thu, 26 Mar 2020 17:15:33 -0400 Subject: [PATCH] Updating allparserscheckfile --- tests/allparserscheckfile.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/allparserscheckfile.cpp b/tests/allparserscheckfile.cpp index 1f430a31..ca464f87 100644 --- a/tests/allparserscheckfile.cpp +++ b/tests/allparserscheckfile.cpp @@ -74,15 +74,8 @@ int main(int argc, char *argv[]) { std::cout << p.size() << " B "; std::cout << std::endl; } - simdjson::ParsedJson pj; - size_t max_depth = 1024 * 4; - bool allocok = pj.allocate_capacity(p.size(), max_depth); - if (!allocok) { - std::cerr << "can't allocate memory" << std::endl; - return EXIT_FAILURE; - } - int oursreturn = json_parse(p, pj); - bool ours_correct = (oursreturn == 0); // returns 0 on success + simdjson::document::parser parser; + auto [doc, err] = parser.parse(p); rapidjson::Document d; @@ -98,19 +91,19 @@ int main(int argc, char *argv[]) { .is_valid(); if (just_favorites) { printf("our parser : %s \n", - ours_correct ? "correct" : "invalid"); + (err == simdjson::error_code::SUCCESS) ? "correct" : "invalid"); printf("rapid (check encoding) : %s \n", rapid_correct_checkencoding ? "correct" : "invalid"); printf("sajson : %s \n", sajson_correct ? "correct" : "invalid"); - if (oursreturn == simdjson::DEPTH_ERROR) { + if (err == simdjson::DEPTH_ERROR) { printf("simdjson encountered a DEPTH_ERROR, it was parametrized to " "reject documents with depth exceeding %zu.\n", - max_depth); + parser.max_depth()); } - if ((ours_correct != rapid_correct_checkencoding) || + if (((err == simdjson::error_code::SUCCESS) != rapid_correct_checkencoding) || (rapid_correct_checkencoding != sajson_correct) || - (ours_correct != sajson_correct)) { + ((err == simdjson::SUCCESS) != sajson_correct)) { printf("WARNING: THEY DISAGREE\n\n"); return EXIT_FAILURE; } @@ -137,11 +130,11 @@ int main(int argc, char *argv[]) { if (tokens == nullptr) { printf("Failed to alloc memory for jsmn\n"); } else { - jsmn_parser parser; - jsmn_init(&parser); + jsmn_parser jsmnparser; + jsmn_init(&jsmnparser); memcpy(buffer, p.data(), p.size()); buffer[p.size()] = '\0'; - int r = jsmn_parse(&parser, buffer, p.size(), tokens.get(), p.size()); + int r = jsmn_parse(&jsmnparser, buffer, p.size(), tokens.get(), p.size()); tokens = nullptr; jsmn_correct = (r > 0); } @@ -163,7 +156,7 @@ int main(int argc, char *argv[]) { delete json_cpp_reader; printf("our parser : %s \n", - ours_correct ? "correct" : "invalid"); + (err == simdjson::error_code::SUCCESS) ? "correct" : "invalid"); printf("rapid : %s \n", rapid_correct ? "correct" : "invalid"); printf("rapid (check encoding) : %s \n",