Deprecate parser error code methods
- Also make competitions compile without warnings
This commit is contained in:
parent
fff4f921e4
commit
e836c28008
|
@ -4,6 +4,9 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
|
|
||||||
|
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
|
||||||
|
|
||||||
// #define RAPIDJSON_SSE2 // bad for performance
|
// #define RAPIDJSON_SSE2 // bad for performance
|
||||||
// #define RAPIDJSON_SSE42 // bad for performance
|
// #define RAPIDJSON_SSE42 // bad for performance
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
@ -13,6 +16,8 @@
|
||||||
|
|
||||||
#include "sajson.h"
|
#include "sajson.h"
|
||||||
|
|
||||||
|
SIMDJSON_POP_DISABLE_WARNINGS
|
||||||
|
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
|
|
||||||
bool equals(const char *s1, const char *s2) { return strcmp(s1, s2) == 0; }
|
bool equals(const char *s1, const char *s2) { return strcmp(s1, s2) == 0; }
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
#include "simdjson.h"
|
#include "simdjson.h"
|
||||||
|
|
||||||
|
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
|
||||||
|
|
||||||
// #define RAPIDJSON_SSE2 // bad
|
// #define RAPIDJSON_SSE2 // bad
|
||||||
// #define RAPIDJSON_SSE42 // bad
|
// #define RAPIDJSON_SSE42 // bad
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
@ -12,8 +14,10 @@
|
||||||
#include "rapidjson/writer.h"
|
#include "rapidjson/writer.h"
|
||||||
#include "sajson.h"
|
#include "sajson.h"
|
||||||
|
|
||||||
using namespace simdjson;
|
SIMDJSON_POP_DISABLE_WARNINGS
|
||||||
|
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
|
using namespace simdjson;
|
||||||
|
|
||||||
std::string rapid_stringme_insitu(char *json) {
|
std::string rapid_stringme_insitu(char *json) {
|
||||||
Document d;
|
Document d;
|
||||||
|
@ -41,6 +45,7 @@ std::string rapid_stringme(char *json) {
|
||||||
return buffer.GetString();
|
return buffer.GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int c;
|
int c;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
|
@ -101,7 +106,7 @@ int main(int argc, char *argv[]) {
|
||||||
size_t outlength;
|
size_t outlength;
|
||||||
uint8_t *cbuffer = (uint8_t *)buffer;
|
uint8_t *cbuffer = (uint8_t *)buffer;
|
||||||
for (auto imple : simdjson::available_implementations) {
|
for (auto imple : simdjson::available_implementations) {
|
||||||
BEST_TIME((std::string("simdjson->minify+")+imple->name()).c_str(), (imple->minify(cbuffer, p.size(), cbuffer, outlength), outlength),
|
BEST_TIME((std::string("simdjson->minify+")+imple->name()).c_str(), (imple->minify(cbuffer, p.size(), cbuffer, outlength) ? outlength : -1),
|
||||||
outlength, memcpy(buffer, p.data(), p.size()), repeat, volume,
|
outlength, memcpy(buffer, p.data(), p.size()), repeat, volume,
|
||||||
!just_data);
|
!just_data);
|
||||||
}
|
}
|
||||||
|
@ -120,8 +125,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
char *mini_buffer = simdjson::internal::allocate_padded_buffer(p.size() + 1);
|
char *mini_buffer = simdjson::internal::allocate_padded_buffer(p.size() + 1);
|
||||||
size_t minisize;
|
size_t minisize;
|
||||||
simdjson::active_implementation->minify((const uint8_t *)p.data(), p.size(),
|
auto minierror = simdjson::active_implementation->minify((const uint8_t *)p.data(), p.size(),
|
||||||
(uint8_t *)mini_buffer, minisize);
|
(uint8_t *)mini_buffer, minisize);
|
||||||
|
if (!minierror) { std::cerr << minierror << std::endl; exit(1); }
|
||||||
mini_buffer[minisize] = '\0';
|
mini_buffer[minisize] = '\0';
|
||||||
|
|
||||||
BEST_TIME("RapidJSON Insitu despaced", d.ParseInsitu(buffer).HasParseError(),
|
BEST_TIME("RapidJSON Insitu despaced", d.ParseInsitu(buffer).HasParseError(),
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
|
|
||||||
|
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
|
||||||
|
|
||||||
// #define RAPIDJSON_SSE2 // bad for performance
|
// #define RAPIDJSON_SSE2 // bad for performance
|
||||||
// #define RAPIDJSON_SSE42 // bad for performance
|
// #define RAPIDJSON_SSE42 // bad for performance
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
@ -11,6 +14,8 @@
|
||||||
|
|
||||||
#include "sajson.h"
|
#include "sajson.h"
|
||||||
|
|
||||||
|
SIMDJSON_POP_DISABLE_WARNINGS
|
||||||
|
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
using namespace simdjson;
|
using namespace simdjson;
|
||||||
struct stat_s {
|
struct stat_s {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "simdjson.h"
|
#include "simdjson.h"
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include "linux-perf-events.h"
|
#include "linux-perf-events.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -11,6 +12,8 @@
|
||||||
|
|
||||||
#include "benchmark.h"
|
#include "benchmark.h"
|
||||||
|
|
||||||
|
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
|
||||||
|
|
||||||
// #define RAPIDJSON_SSE2 // bad for performance
|
// #define RAPIDJSON_SSE2 // bad for performance
|
||||||
// #define RAPIDJSON_SSE42 // bad for performance
|
// #define RAPIDJSON_SSE42 // bad for performance
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
@ -44,6 +47,8 @@ extern "C" {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SIMDJSON_POP_DISABLE_WARNINGS
|
||||||
|
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
|
|
||||||
#ifdef ALLPARSER
|
#ifdef ALLPARSER
|
||||||
|
@ -104,7 +109,7 @@ bool bench(const char *filename, bool verbose, bool just_data, int repeat_multip
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!just_data)
|
if (!just_data)
|
||||||
BEST_TIME("simdjson (dynamic mem) ", simdjson::build_parsed_json(p).is_valid(), true,
|
BEST_TIME("simdjson (dynamic mem) ", !simdjson::document::parser().parse(p).error(), true,
|
||||||
, repeat, volume, !just_data);
|
, repeat, volume, !just_data);
|
||||||
// (static alloc)
|
// (static alloc)
|
||||||
simdjson::document::parser parser;
|
simdjson::document::parser parser;
|
||||||
|
@ -161,6 +166,8 @@ bool bench(const char *filename, bool verbose, bool just_data, int repeat_multip
|
||||||
sajson::mutable_string_view(p.size(), buffer))
|
sajson::mutable_string_view(p.size(), buffer))
|
||||||
.is_valid(),
|
.is_valid(),
|
||||||
true, memcpy(buffer, p.data(), p.size()), repeat, volume, !just_data);
|
true, memcpy(buffer, p.data(), p.size()), repeat, volume, !just_data);
|
||||||
|
|
||||||
|
|
||||||
size_t expected = json::parse(p.data(), p.data() + p.size()).size();
|
size_t expected = json::parse(p.data(), p.data() + p.size()).size();
|
||||||
BEST_TIME("nlohmann-json", json::parse(buffer, buffer + p.size()).size(),
|
BEST_TIME("nlohmann-json", json::parse(buffer, buffer + p.size()).size(),
|
||||||
expected, memcpy(buffer, p.data(), p.size()), repeat, volume,
|
expected, memcpy(buffer, p.data(), p.size()), repeat, volume,
|
||||||
|
@ -291,6 +298,7 @@ bool bench(const char *filename, bool verbose, bool just_data, int repeat_multip
|
||||||
stats[2] * 1.0 / repeat, stats[3] * 1.0 / repeat,
|
stats[2] * 1.0 / repeat, stats[3] * 1.0 / repeat,
|
||||||
stats[4] * 1.0 / repeat, volume * repeat * 1.0 / stats[2],
|
stats[4] * 1.0 / repeat, volume * repeat * 1.0 / stats[2],
|
||||||
stats[1] * 1.0 / stats[0], stats[1] * 1.0 / (volume * repeat));
|
stats[1] * 1.0 / stats[0], stats[1] * 1.0 / (volume * repeat));
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push ))
|
#define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push ))
|
||||||
|
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
|
||||||
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
|
#define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
|
||||||
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
|
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
|
||||||
#define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
|
#define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
|
||||||
|
@ -95,6 +96,13 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SIMDJSON_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
|
#define SIMDJSON_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
|
||||||
|
// gcc doesn't seem to disable all warnings with all and extra, add warnings here as necessary
|
||||||
|
#define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
|
||||||
|
SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
|
||||||
|
SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
|
||||||
|
SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
|
||||||
|
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
|
||||||
|
SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough)
|
||||||
#define SIMDJSON_PRAGMA(P) _Pragma(#P)
|
#define SIMDJSON_PRAGMA(P) _Pragma(#P)
|
||||||
#define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
|
#define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
|
||||||
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
|
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
|
||||||
|
|
|
@ -1347,18 +1347,22 @@ public:
|
||||||
//
|
//
|
||||||
|
|
||||||
// returns true if the document parsed was valid
|
// returns true if the document parsed was valid
|
||||||
|
[[deprecated("Use the result of parser.parse() instead")]]
|
||||||
inline bool is_valid() const noexcept;
|
inline bool is_valid() const noexcept;
|
||||||
|
|
||||||
// return an error code corresponding to the last parsing attempt, see
|
// return an error code corresponding to the last parsing attempt, see
|
||||||
// simdjson.h will return UNITIALIZED if no parsing was attempted
|
// simdjson.h will return UNITIALIZED if no parsing was attempted
|
||||||
|
[[deprecated("Use the result of parser.parse() instead")]]
|
||||||
inline int get_error_code() const noexcept;
|
inline int get_error_code() const noexcept;
|
||||||
|
|
||||||
// return the string equivalent of "get_error_code"
|
// return the string equivalent of "get_error_code"
|
||||||
|
[[deprecated("Use error_message() on the result of parser.parse() instead, or cout << error")]]
|
||||||
inline std::string get_error_message() const noexcept;
|
inline std::string get_error_message() const noexcept;
|
||||||
|
|
||||||
// print the json to std::ostream (should be valid)
|
// print the json to std::ostream (should be valid)
|
||||||
// return false if the tape is likely wrong (e.g., you did not parse a valid
|
// return false if the tape is likely wrong (e.g., you did not parse a valid
|
||||||
// JSON).
|
// JSON).
|
||||||
|
[[deprecated("Use cout << on the result of parser.parse() instead")]]
|
||||||
inline bool print_json(std::ostream &os) const noexcept;
|
inline bool print_json(std::ostream &os) const noexcept;
|
||||||
inline bool dump_raw_tape(std::ostream &os) const noexcept;
|
inline bool dump_raw_tape(std::ostream &os) const noexcept;
|
||||||
|
|
||||||
|
|
|
@ -323,12 +323,12 @@ inline bool document::parser::is_valid() const noexcept { return valid; }
|
||||||
inline int document::parser::get_error_code() const noexcept { return error; }
|
inline int document::parser::get_error_code() const noexcept { return error; }
|
||||||
inline std::string document::parser::get_error_message() const noexcept { return error_message(int(error)); }
|
inline std::string document::parser::get_error_message() const noexcept { return error_message(int(error)); }
|
||||||
inline bool document::parser::print_json(std::ostream &os) const noexcept {
|
inline bool document::parser::print_json(std::ostream &os) const noexcept {
|
||||||
if (!is_valid()) { return false; }
|
if (!valid) { return false; }
|
||||||
os << doc.root();
|
os << doc.root();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
inline bool document::parser::dump_raw_tape(std::ostream &os) const noexcept {
|
inline bool document::parser::dump_raw_tape(std::ostream &os) const noexcept {
|
||||||
return is_valid() ? doc.dump_raw_tape(os) : false;
|
return valid ? doc.dump_raw_tape(os) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline simdjson_result<size_t> document::parser::read_file(const std::string &path) noexcept {
|
inline simdjson_result<size_t> document::parser::read_file(const std::string &path) noexcept {
|
||||||
|
|
|
@ -211,7 +211,7 @@ bool ParsedJson::Iterator::next() {
|
||||||
|
|
||||||
ParsedJson::Iterator::Iterator(const ParsedJson &pj) noexcept(false)
|
ParsedJson::Iterator::Iterator(const ParsedJson &pj) noexcept(false)
|
||||||
: doc(pj.doc), depth(0), location(0), tape_length(0) {
|
: doc(pj.doc), depth(0), location(0), tape_length(0) {
|
||||||
if (!pj.is_valid()) { throw simdjson_error(pj.error); }
|
if (!pj.valid) { throw simdjson_error(pj.error); }
|
||||||
|
|
||||||
max_depth = pj.max_depth();
|
max_depth = pj.max_depth();
|
||||||
depth_index = new scopeindex_t[max_depth + 1];
|
depth_index = new scopeindex_t[max_depth + 1];
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "simdjson.h"
|
#include "simdjson.h"
|
||||||
|
|
||||||
|
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
|
||||||
|
|
||||||
// #define RAPIDJSON_SSE2 // bad
|
// #define RAPIDJSON_SSE2 // bad
|
||||||
// #define RAPIDJSON_SSE42 // bad
|
// #define RAPIDJSON_SSE42 // bad
|
||||||
#include "fastjson.cpp"
|
#include "fastjson.cpp"
|
||||||
|
@ -24,8 +26,10 @@ extern "C" {
|
||||||
#include "jsoncpp.cpp"
|
#include "jsoncpp.cpp"
|
||||||
#include "json/json.h"
|
#include "json/json.h"
|
||||||
|
|
||||||
|
SIMDJSON_POP_DISABLE_WARNINGS
|
||||||
|
|
||||||
// fastjson has a tricky interface
|
// fastjson has a tricky interface
|
||||||
void on_json_error(void *, const fastjson::ErrorContext &ec) {
|
void on_json_error(void *, UNUSED const fastjson::ErrorContext &ec) {
|
||||||
// std::cerr<<"ERROR: "<<ec.mesg<<std::endl;
|
// std::cerr<<"ERROR: "<<ec.mesg<<std::endl;
|
||||||
}
|
}
|
||||||
bool fastjson_parse(const char *input) {
|
bool fastjson_parse(const char *input) {
|
||||||
|
@ -59,9 +63,9 @@ int main(int argc, char *argv[]) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
const char *filename = argv[optind];
|
const char *filename = argv[optind];
|
||||||
auto [p, error] = simdjson::padded_string::load(filename);
|
auto [p, loaderr] = simdjson::padded_string::load(filename);
|
||||||
if (error) {
|
if (loaderr) {
|
||||||
std::cerr << "Could not load the file " << filename << std::endl;
|
std::cerr << "Could not load the file " << filename << ": " << loaderr << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
|
|
|
@ -189,8 +189,8 @@ namespace document_tests {
|
||||||
std::cout << __func__ << std::endl;
|
std::cout << __func__ << std::endl;
|
||||||
simdjson::padded_string badjson = "[7,7,7,7,6,7,7,7,6,7,7,6,[7,7,7,7,6,7,7,7,6,7,7,6,7,7,7,7,7,7,6"_padded;
|
simdjson::padded_string badjson = "[7,7,7,7,6,7,7,7,6,7,7,6,[7,7,7,7,6,7,7,7,6,7,7,6,7,7,7,7,7,7,6"_padded;
|
||||||
simdjson::document::parser parser;
|
simdjson::document::parser parser;
|
||||||
parser.parse(badjson);
|
auto [doc, error] = parser.parse(badjson);
|
||||||
if(parser.is_valid()) {
|
if (!error) {
|
||||||
printf("This json should not be valid %s.\n", badjson.data());
|
printf("This json should not be valid %s.\n", badjson.data());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue