diff --git a/benchmark/parsingcompetition.cpp b/benchmark/parsingcompetition.cpp index 1e1e9fadc..d203f1421 100644 --- a/benchmark/parsingcompetition.cpp +++ b/benchmark/parsingcompetition.cpp @@ -108,9 +108,14 @@ bool bench(const char *filename, bool verbose, bool just_data, int repeat_multip repeat, volume, !just_data); } - if (!just_data) - BEST_TIME("simdjson (dynamic mem) ", simdjson::dom::parser().parse(p).error(), simdjson::SUCCESS, + if (!just_data) { + auto parse_dynamic=[](auto& str){ + simdjson::dom::parser parser; + return parser.parse(str).error(); + }; + BEST_TIME("simdjson (dynamic mem) ", parse_dynamic(p), simdjson::SUCCESS, , repeat, volume, !just_data); + } // (static alloc) simdjson::dom::parser parser; BEST_TIME("simdjson ", parser.parse(p).error(), simdjson::SUCCESS, , repeat, volume, diff --git a/include/simdjson/document.h b/include/simdjson/document.h index 1e0e7af59..2fc6a8fb2 100644 --- a/include/simdjson/document.h +++ b/include/simdjson/document.h @@ -680,8 +680,8 @@ public: * - CAPACITY if the parser does not have enough capacity and len > max_capacity. * - other json errors if parsing fails. */ - inline simdjson_result load(const std::string &path) noexcept; - + inline simdjson_result load(const std::string &path) & noexcept; + inline simdjson_result load(const std::string &path) && = delete ; /** * Parse a JSON document and return a temporary reference to it. * @@ -717,13 +717,17 @@ public: * - CAPACITY if the parser does not have enough capacity and len > max_capacity. * - other json errors if parsing fails. */ - inline simdjson_result parse(const uint8_t *buf, size_t len, bool realloc_if_needed = true) noexcept; + inline simdjson_result parse(const uint8_t *buf, size_t len, bool realloc_if_needed = true) & noexcept; + inline simdjson_result parse(const uint8_t *buf, size_t len, bool realloc_if_needed = true) && =delete; /** @overload parse(const uint8_t *buf, size_t len, bool realloc_if_needed) */ - really_inline simdjson_result parse(const char *buf, size_t len, bool realloc_if_needed = true) noexcept; + really_inline simdjson_result parse(const char *buf, size_t len, bool realloc_if_needed = true) & noexcept; + really_inline simdjson_result parse(const char *buf, size_t len, bool realloc_if_needed = true) && =delete; /** @overload parse(const uint8_t *buf, size_t len, bool realloc_if_needed) */ - really_inline simdjson_result parse(const std::string &s) noexcept; + really_inline simdjson_result parse(const std::string &s) & noexcept; + really_inline simdjson_result parse(const std::string &s) && =delete; /** @overload parse(const uint8_t *buf, size_t len, bool realloc_if_needed) */ - really_inline simdjson_result parse(const padded_string &s) noexcept; + really_inline simdjson_result parse(const padded_string &s) & noexcept; + really_inline simdjson_result parse(const padded_string &s) && =delete; /** @private We do not want to allow implicit conversion from C string to std::string. */ really_inline simdjson_result parse(const char *buf) noexcept = delete; @@ -1303,4 +1307,4 @@ public: } // namespace simdjson -#endif // SIMDJSON_DOCUMENT_H \ No newline at end of file +#endif // SIMDJSON_DOCUMENT_H diff --git a/include/simdjson/inline/document.h b/include/simdjson/inline/document.h index a9bd5f25f..e3432e3bf 100644 --- a/include/simdjson/inline/document.h +++ b/include/simdjson/inline/document.h @@ -366,7 +366,7 @@ inline simdjson_result parser::read_file(const std::string &path) noexce return bytes_read; } -inline simdjson_result parser::load(const std::string &path) noexcept { +inline simdjson_result parser::load(const std::string &path) & noexcept { size_t len; error_code code; read_file(path).tie(len, code); @@ -382,7 +382,7 @@ inline document_stream parser::load_many(const std::string &path, size_t batch_s return document_stream(*this, (const uint8_t*)loaded_bytes.get(), len, batch_size, code); } -inline simdjson_result parser::parse(const uint8_t *buf, size_t len, bool realloc_if_needed) noexcept { +inline simdjson_result parser::parse(const uint8_t *buf, size_t len, bool realloc_if_needed) & noexcept { error_code code = ensure_capacity(len); if (code) { return code; } @@ -405,13 +405,13 @@ inline simdjson_result parser::parse(const uint8_t *buf, size_t len, bo error = UNINITIALIZED; return doc.root(); } -really_inline simdjson_result parser::parse(const char *buf, size_t len, bool realloc_if_needed) noexcept { +really_inline simdjson_result parser::parse(const char *buf, size_t len, bool realloc_if_needed) & noexcept { return parse((const uint8_t *)buf, len, realloc_if_needed); } -really_inline simdjson_result parser::parse(const std::string &s) noexcept { +really_inline simdjson_result parser::parse(const std::string &s) & noexcept { return parse(s.data(), s.length(), s.capacity() - s.length() < SIMDJSON_PADDING); } -really_inline simdjson_result parser::parse(const padded_string &s) noexcept { +really_inline simdjson_result parser::parse(const padded_string &s) & noexcept { return parse(s.data(), s.length(), false); } diff --git a/jsonexamples/tree-pretty.json b/jsonexamples/tree-pretty.json new file mode 100644 index 000000000..12b9680cc --- /dev/null +++ b/jsonexamples/tree-pretty.json @@ -0,0 +1,1196 @@ +{ + "id" : 187650773514256, + "type" : "root", + "orientation" : "horizontal", + "scratchpad_state" : "none", + "percent" : null, + "urgent" : false, + "focused" : false, + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 0, + "width" : 1920, + "height" : 1080 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "root", + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773515776, + "type" : "output", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 0.5, + "urgent" : false, + "focused" : false, + "layout" : "output", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 0, + "width" : 1920, + "height" : 1080 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "__i3", + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773518880, + "type" : "con", + "orientation" : "horizontal", + "scratchpad_state" : "none", + "percent" : null, + "urgent" : false, + "focused" : false, + "output" : "__i3", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "content", + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773522016, + "type" : "workspace", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : null, + "urgent" : false, + "focused" : false, + "output" : "__i3", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "__i3_scratch", + "num" : -1, + "window" : null, + "window_type" : null, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 1, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773522016 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773518880 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + }, + { + "id" : 187650773525408, + "type" : "output", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 0.5, + "urgent" : false, + "focused" : false, + "layout" : "output", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 0, + "width" : 1920, + "height" : 1080 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "eDP-1", + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773528576, + "type" : "dockarea", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : null, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "dockarea", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 0, + "width" : 1920, + "height" : 20 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "topdock", + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773558400, + "type" : "con", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 1.0, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : 1, + "rect" : { + "x" : 0, + "y" : 0, + "width" : 1920, + "height" : 20 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 1920, + "height" : 20 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 1920, + "height" : 20 + }, + "name" : "polybar-top_eDP-1", + "window" : 35651586, + "window_type" : "unknown", + "window_properties" : { + "class" : "Polybar", + "instance" : "polybar", + "title" : "polybar-top_eDP-1", + "transient_for" : null + }, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 0, + "sticky" : true, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773558400 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + { + "dock" : 2, + "insert_where" : 2 + } + ] + }, + { + "id" : 187650773531824, + "type" : "con", + "orientation" : "horizontal", + "scratchpad_state" : "none", + "percent" : null, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "content", + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773677744, + "type" : "workspace", + "orientation" : "horizontal", + "scratchpad_state" : "none", + "percent" : 0.20000000000000001, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "1:doc", + "num" : 1, + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773571824, + "type" : "con", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 1.0, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : 1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 1, + "y" : 1, + "width" : 1918, + "height" : 1038 + }, + "geometry" : { + "x" : 6, + "y" : 58, + "width" : 1920, + "height" : 1051 + }, + "name" : "passwords - KeePassXC", + "window" : 29360134, + "window_type" : "normal", + "window_properties" : { + "class" : "KeePassXC", + "instance" : "keepassxc", + "title" : "passwords - KeePassXC", + "transient_for" : null + }, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773571824 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + }, + { + "id" : 187650773592880, + "type" : "workspace", + "orientation" : "horizontal", + "scratchpad_state" : "none", + "percent" : 0.20000000000000001, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "2:term", + "num" : 2, + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773600144, + "type" : "con", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 0.59999999999999998, + "urgent" : false, + "focused" : true, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : 1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1152, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 1, + "y" : 1, + "width" : 1150, + "height" : 1038 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 642, + "height" : 410 + }, + "name" : "jan@pine: ~/devel/i3-focus-last", + "window" : 52428806, + "window_type" : "normal", + "window_properties" : { + "class" : "Mate-terminal", + "instance" : "mate-terminal", + "window_role" : "mate-terminal-window-2758--1592505164-1586687519", + "title" : "jan@pine: ~/devel/i3-focus-last", + "transient_for" : null + }, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + }, + { + "id" : 187650772896320, + "type" : "con", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 0.40000000000000002, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : 1, + "rect" : { + "x" : 1152, + "y" : 20, + "width" : 768, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 1, + "y" : 1, + "width" : 766, + "height" : 1038 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 642, + "height" : 410 + }, + "name" : "man 3 exit", + "window" : 52441521, + "window_type" : "normal", + "window_properties" : { + "class" : "Mate-terminal", + "instance" : "mate-terminal", + "window_role" : "mate-terminal-window-2758--1883047782-1586692221", + "title" : "man 3 exit", + "transient_for" : null + }, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773600144, + 187650772896320 + ], + "fullscreen_mode" : 1, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + }, + { + "id" : 187650773582384, + "type" : "workspace", + "orientation" : "horizontal", + "scratchpad_state" : "none", + "percent" : 0.20000000000000001, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "5:web", + "num" : 5, + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773587792, + "type" : "con", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 1.0, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : 1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 1, + "y" : 1, + "width" : 1918, + "height" : 1038 + }, + "geometry" : { + "x" : 56, + "y" : 109, + "width" : 800, + "height" : 600 + }, + "name" : "Automatic Variables (GNU make) - qutebrowser", + "window" : 48234502, + "window_type" : "normal", + "window_properties" : { + "class" : "qutebrowser", + "instance" : "qutebrowser", + "title" : "Automatic Variables (GNU make) - qutebrowser", + "transient_for" : null + }, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773587792 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + }, + { + "id" : 187650773646832, + "type" : "workspace", + "orientation" : "horizontal", + "scratchpad_state" : "none", + "percent" : 0.20000000000000001, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "6:mail", + "num" : 6, + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773647296, + "type" : "con", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 1.0, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : 1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 1, + "y" : 1, + "width" : 1918, + "height" : 1038 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 642, + "height" : 410 + }, + "name" : "neomutt", + "window" : 52430645, + "window_type" : "normal", + "window_properties" : { + "class" : "Mate-terminal", + "instance" : "mate-terminal", + "window_role" : "mate-terminal-window-2758-1253773593-1586689113", + "title" : "neomutt", + "transient_for" : null + }, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773647296 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + }, + { + "id" : 187650773615600, + "type" : "workspace", + "orientation" : "horizontal", + "scratchpad_state" : "none", + "percent" : 0.20000000000000001, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "8:media", + "num" : 8, + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773407936, + "type" : "con", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 1.0, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : 1, + "rect" : { + "x" : 0, + "y" : 20, + "width" : 1920, + "height" : 1040 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 1, + "y" : 1, + "width" : 1918, + "height" : 1038 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 642, + "height" : 410 + }, + "name" : "ncmpcpp", + "window" : 52438228, + "window_type" : "normal", + "window_properties" : { + "class" : "Mate-terminal", + "instance" : "mate-terminal", + "window_role" : "mate-terminal-window-2758-281668681-1586691607", + "title" : "ncmpcpp", + "transient_for" : null + }, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773407936 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773592880, + 187650773582384, + 187650773615600, + 187650773677744, + 187650773646832 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + }, + { + "id" : 187650773535024, + "type" : "dockarea", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : null, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "dockarea", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : -1, + "rect" : { + "x" : 0, + "y" : 1060, + "width" : 1920, + "height" : 20 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "geometry" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "name" : "bottomdock", + "window" : null, + "window_type" : null, + "nodes" : [ + { + "id" : 187650773560672, + "type" : "con", + "orientation" : "none", + "scratchpad_state" : "none", + "percent" : 1.0, + "urgent" : false, + "focused" : false, + "output" : "eDP-1", + "layout" : "splith", + "workspace_layout" : "default", + "last_split_layout" : "splith", + "border" : "pixel", + "current_border_width" : 1, + "rect" : { + "x" : 0, + "y" : 1060, + "width" : 1920, + "height" : 20 + }, + "deco_rect" : { + "x" : 0, + "y" : 0, + "width" : 0, + "height" : 0 + }, + "window_rect" : { + "x" : 0, + "y" : 0, + "width" : 1920, + "height" : 20 + }, + "geometry" : { + "x" : 0, + "y" : 1060, + "width" : 1920, + "height" : 20 + }, + "name" : "polybar-bottom_eDP-1", + "window" : 31457282, + "window_type" : "unknown", + "window_properties" : { + "class" : "Polybar", + "instance" : "polybar", + "title" : "polybar-bottom_eDP-1", + "transient_for" : null + }, + "nodes" : [ + ], + "floating_nodes" : [ + ], + "focus" : [ + ], + "fullscreen_mode" : 0, + "sticky" : true, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773560672 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + { + "dock" : 3, + "insert_where" : 2 + } + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773531824, + 187650773528576, + 187650773535024 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] + } + ], + "floating_nodes" : [ + ], + "focus" : [ + 187650773525408, + 187650773515776 + ], + "fullscreen_mode" : 0, + "sticky" : false, + "floating" : "auto_off", + "swallows" : [ + ] +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c6273ae3e..bec6d859c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -77,7 +77,7 @@ if(NOT (MSVC AND MSVC_VERSION LESS 1920)) add_compile_test(readme_examples_noexceptions readme_examples_noexceptions.cpp quicktests) # Compile tests that *should fail* - add_compile_test(readme_examples_will_fail_with_exceptions_off readme_examples.cpp FALSE quicktests) + add_compile_test(readme_examples_will_fail_with_exceptions_off readme_examples.cpp) target_compile_definitions(readme_examples_will_fail_with_exceptions_off PRIVATE SIMDJSON_EXCEPTIONS=0) set_tests_properties(readme_examples_will_fail_with_exceptions_off PROPERTIES WILL_FAIL TRUE) @@ -108,3 +108,5 @@ endif() # add_executable(singleheader ./singleheadertest.cpp ${PROJECT_SOURCE_DIR}/singleheader/simdjson.cpp) # target_link_libraries(singleheader simdjson) # add_test(singleheader singleheader) + +add_subdirectory(compilation_failure_tests) diff --git a/tests/compilation_failure_tests/CMakeLists.txt b/tests/compilation_failure_tests/CMakeLists.txt new file mode 100644 index 000000000..0c053db01 --- /dev/null +++ b/tests/compilation_failure_tests/CMakeLists.txt @@ -0,0 +1,38 @@ +# +# This directory contains files aimed to verify that constructs that +# are supposed to fail at compile time, indeed do so. +# To prevent bit rot, the same source file is compiled twice with +# the macro COMPILATION_TEST_USE_FAILING_CODE set to 0 or 1. +# + +# internal function for add_dual_compile_test +# which adds a target and a test target trying to compile it +function(detail_add_dual_compile_test TEST_NAME TEST_FILE) + add_executable(${TEST_NAME} ${TEST_FILE}) + set_target_properties(${TEST_NAME} PROPERTIES + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE) + add_test(NAME ${TEST_NAME} + COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +endfunction(add_compile_test) + +# adds a compilation test. two targets are created, one expected to +# succeed compilation and one that is expected to fail. +function(add_dual_compile_test TEST_NAME TEST_FILE) + detail_add_dual_compile_test(${TEST_NAME}_should_compile ${TEST_FILE}) + detail_add_dual_compile_test(${TEST_NAME}_should_not_compile ${TEST_FILE}) + target_compile_definitions(${TEST_NAME}_should_compile PRIVATE COMPILATION_TEST_USE_FAILING_CODE=0) + target_compile_definitions(${TEST_NAME}_should_not_compile PRIVATE COMPILATION_TEST_USE_FAILING_CODE=1) + set_tests_properties(${TEST_NAME}_should_compile PROPERTIES WILL_FAIL FALSE) + set_tests_properties(${TEST_NAME}_should_not_compile PROPERTIES WILL_FAIL TRUE) +endfunction(add_compile_test) + + +add_dual_compile_test(example_compiletest example_compiletest.cpp) +add_dual_compile_test(dangling_parser_load dangling_parser_load.cpp) +add_dual_compile_test(dangling_parser_parse_uint8 dangling_parser_parse_uint8.cpp) +add_dual_compile_test(dangling_parser_parse_uchar dangling_parser_parse_uchar.cpp) +add_dual_compile_test(dangling_parser_parse_stdstring dangling_parser_parse_stdstring.cpp) +add_dual_compile_test(dangling_parser_parse_padstring dangling_parser_parse_padstring.cpp) + diff --git a/tests/compilation_failure_tests/dangling_parser_load.cpp b/tests/compilation_failure_tests/dangling_parser_load.cpp new file mode 100644 index 000000000..54801ad10 --- /dev/null +++ b/tests/compilation_failure_tests/dangling_parser_load.cpp @@ -0,0 +1,15 @@ + +// this tests https://github.com/simdjson/simdjson/issues/696 + +#include +#include "simdjson.h" + +int main() { +#if COMPILATION_TEST_USE_FAILING_CODE + simdjson::dom::element tree = simdjson::dom::parser().load("tree-pretty.json"); +#else + simdjson::dom::parser parser; + simdjson::dom::element tree = parser.load("tree-pretty.json"); +#endif + std::cout << tree["type"] << std::endl; +} diff --git a/tests/compilation_failure_tests/dangling_parser_parse_padstring.cpp b/tests/compilation_failure_tests/dangling_parser_parse_padstring.cpp new file mode 100644 index 000000000..498d2d119 --- /dev/null +++ b/tests/compilation_failure_tests/dangling_parser_parse_padstring.cpp @@ -0,0 +1,16 @@ + +// this tests https://github.com/simdjson/simdjson/issues/696 + +#include +#include "simdjson.h" + +int main() { + simdjson::padded_string buf; +#if COMPILATION_TEST_USE_FAILING_CODE + simdjson::dom::element tree = simdjson::dom::parser().parse(buf); +#else + simdjson::dom::parser parser; + simdjson::dom::element tree = parser.parse(buf); +#endif + std::cout << tree["type"] << std::endl; +} diff --git a/tests/compilation_failure_tests/dangling_parser_parse_stdstring.cpp b/tests/compilation_failure_tests/dangling_parser_parse_stdstring.cpp new file mode 100644 index 000000000..b36c9d3fa --- /dev/null +++ b/tests/compilation_failure_tests/dangling_parser_parse_stdstring.cpp @@ -0,0 +1,16 @@ + +// this tests https://github.com/simdjson/simdjson/issues/696 + +#include +#include "simdjson.h" + +int main() { + std::string buf; +#if COMPILATION_TEST_USE_FAILING_CODE + simdjson::dom::element tree = simdjson::dom::parser().parse(buf); +#else + simdjson::dom::parser parser; + simdjson::dom::element tree = parser.parse(buf); +#endif + std::cout << tree["type"] << std::endl; +} diff --git a/tests/compilation_failure_tests/dangling_parser_parse_uchar.cpp b/tests/compilation_failure_tests/dangling_parser_parse_uchar.cpp new file mode 100644 index 000000000..8b63301d5 --- /dev/null +++ b/tests/compilation_failure_tests/dangling_parser_parse_uchar.cpp @@ -0,0 +1,17 @@ + +// this tests https://github.com/simdjson/simdjson/issues/696 + +#include +#include "simdjson.h" + +int main() { + const char buf[128]={}; + const size_t len=sizeof(buf); +#if COMPILATION_TEST_USE_FAILING_CODE + simdjson::dom::element tree = simdjson::dom::parser().parse(buf,len); +#else + simdjson::dom::parser parser; + simdjson::dom::element tree = parser.parse(buf,len); +#endif + std::cout << tree["type"] << std::endl; +} diff --git a/tests/compilation_failure_tests/dangling_parser_parse_uint8.cpp b/tests/compilation_failure_tests/dangling_parser_parse_uint8.cpp new file mode 100644 index 000000000..6ef3c3e75 --- /dev/null +++ b/tests/compilation_failure_tests/dangling_parser_parse_uint8.cpp @@ -0,0 +1,17 @@ + +// this tests https://github.com/simdjson/simdjson/issues/696 + +#include +#include "simdjson.h" + +int main() { + const uint8_t buf[128]={}; + const size_t len=sizeof(buf); +#if COMPILATION_TEST_USE_FAILING_CODE + simdjson::dom::element tree = simdjson::dom::parser().parse(buf,len); +#else + simdjson::dom::parser parser; + simdjson::dom::element tree = parser.parse(buf,len); +#endif + std::cout << tree["type"] << std::endl; +} diff --git a/tests/compilation_failure_tests/example_compiletest.cpp b/tests/compilation_failure_tests/example_compiletest.cpp new file mode 100644 index 000000000..879d3f2ef --- /dev/null +++ b/tests/compilation_failure_tests/example_compiletest.cpp @@ -0,0 +1,20 @@ +//example for a compile test + +// keep as much code as possible outside of the conditional compilation +// so the thing that is to proven to not compile fails to compile because +// some unrelated thing (like forgetting to include a header) + +#include + +int main() { + +#if COMPILATION_TEST_USE_FAILING_CODE + // code that is supposed to fail compiling (keep it short!) + xxx +#else + // equivalent code that is supposed to compile (keep it short!) +#endif + + // common code + +}