diff --git a/include/simdjson/common_defs.h b/include/simdjson/common_defs.h index d50bde06..bea4f833 100644 --- a/include/simdjson/common_defs.h +++ b/include/simdjson/common_defs.h @@ -100,6 +100,7 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024; #endif #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996) + #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING #define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop )) #else // SIMDJSON_REGULAR_VISUAL_STUDIO @@ -139,6 +140,7 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024; #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS #endif #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations) + #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wstrict-overflow) #define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop") diff --git a/include/simdjson/generic/ondemand/json_iterator-inl.h b/include/simdjson/generic/ondemand/json_iterator-inl.h index 0d4caf5c..447373fc 100644 --- a/include/simdjson/generic/ondemand/json_iterator-inl.h +++ b/include/simdjson/generic/ondemand/json_iterator-inl.h @@ -29,6 +29,11 @@ simdjson_really_inline json_iterator::json_iterator(ondemand::parser *_parser) n logger::log_headers(); } +// GCC 7 warns when the first line of this function is inlined away into oblivion due to the caller +// relating depth and parent_depth, which is a desired effect. The warning does not show up if the +// skip_child() function is not marked inline). +SIMDJSON_PUSH_DISABLE_WARNINGS +SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING simdjson_warn_unused simdjson_really_inline error_code json_iterator::skip_child(depth_t parent_depth) noexcept { if (depth() <= parent_depth) { return SUCCESS; } @@ -90,6 +95,8 @@ simdjson_warn_unused simdjson_really_inline error_code json_iterator::skip_child return report_error(TAPE_ERROR, "not enough close braces"); } +SIMDJSON_POP_DISABLE_WARNINGS + simdjson_really_inline bool json_iterator::at_root() const noexcept { return token.checkpoint() == root_checkpoint(); } diff --git a/tests/ondemand/ondemand_basictests.cpp b/tests/ondemand/ondemand_basictests.cpp index 14ff71df..8cc19374 100644 --- a/tests/ondemand/ondemand_basictests.cpp +++ b/tests/ondemand/ondemand_basictests.cpp @@ -1215,7 +1215,7 @@ namespace dom_api_tests { ASSERT_ERROR( object["d"], NO_SUCH_FIELD ); return true; })); - SUBTEST("ondemand::value", test_ondemand_doc(json, [&](auto doc_result) { + SUBTEST("simdjson_result", test_ondemand_doc(json, [&](auto doc_result) { simdjson_result object = doc_result["outer"]; ASSERT_EQUAL( object["a"].get_uint64().first, 1 ); ASSERT_EQUAL( object["b"].get_uint64().first, 2 ); @@ -1690,7 +1690,7 @@ namespace ordering_tests { } return (x == 1.1) && (y == 2.2) && (z == 3.3); } -#endif +#endif // SIMDJSON_EXCEPTIONS bool run() { return @@ -1725,6 +1725,7 @@ namespace twitter_tests { })); TEST_SUCCEED(); } + #if SIMDJSON_EXCEPTIONS bool twitter_example() { TEST_START(); @@ -1746,7 +1747,7 @@ namespace twitter_tests { } TEST_SUCCEED(); } -#endif +#endif // SIMDJSON_EXCEPTIONS bool twitter_default_profile() { TEST_START(); @@ -1785,11 +1786,21 @@ namespace twitter_tests { auto media = tweet["entities"]["media"]; if (!media.error()) { for (auto image : media) { + uint64_t id_val; + std::string_view id_string; + ASSERT_SUCCESS( image["id"].get(id_val) ); + ASSERT_SUCCESS( image["id_str"].get(id_string) ); + std::cout << "id = " << id_val << std::endl; + std::cout << "id_string = " << id_string << std::endl; + for (auto size : image["sizes"].get_object()) { - auto size_value = size.value().get_object(); + std::string_view size_key; + ASSERT_SUCCESS( size.unescaped_key().get(size_key) ); + std::cout << "Type of image size = " << size_key << std::endl; + uint64_t width, height; - ASSERT_SUCCESS( size_value["w"].get(width) ); - ASSERT_SUCCESS( size_value["h"].get(height) ); + ASSERT_SUCCESS( size.value()["w"].get(width) ); + ASSERT_SUCCESS( size.value()["h"].get(height) ); image_sizes.insert(make_pair(width, height)); } } @@ -1836,6 +1847,14 @@ namespace twitter_tests { TEST_SUCCEED(); } + /* + * Fun fact: id and id_str can differ: + * 505866668485386240 and 505866668485386241. + * Presumably, it is because doubles are used + * at some point in the process and the number + * 505866668485386241 cannot be represented as a double. + * (not our fault) + */ bool twitter_image_sizes_exception() { TEST_START(); padded_string json = padded_string::load(TWITTER_JSON); @@ -1845,30 +1864,13 @@ namespace twitter_tests { for (auto tweet : doc_result["statuses"]) { auto media = tweet["entities"]["media"]; if (!media.error()) { - for (ondemand::object image : media) { - /** - * Fun fact: id and id_str can differ: - * 505866668485386240 and 505866668485386241. - * Presumably, it is because doubles are used - * at some point in the process and the number - * 505866668485386241 cannot be represented as a double. - * (not our fault) - */ - uint64_t id_val = image["id"]; - std::cout << "id = " << id_val << std::endl; - std::string_view id_string = image["id_str"]; - std::cout << "id_string = " << id_string << std::endl; + for (auto image : media) { + std::cout << "id = " << uint64_t(image["id"]) << std::endl; + std::cout << "id_string = " << std::string_view(image["id_str"]) << std::endl; for (auto size : image["sizes"].get_object()) { - /** - * We want to know the key that describes the size. - */ - std::string_view raw_size_key_v = size.unescaped_key(); - std::cout << "Type of image size = " << raw_size_key_v << std::endl; - ondemand::object size_value = size.value(); - int64_t width = size_value["w"]; - int64_t height = size_value["h"]; - std::cout << width << " x " << height << std::endl; - image_sizes.insert(make_pair(width, height)); + std::cout << "Type of image size = " << std::string_view(size.unescaped_key()) << std::endl; + // NOTE: the uint64_t is required so that each value is actually parsed before the pair is created + image_sizes.insert(make_pair(size.value()["w"], size.value()["h"])); } } } @@ -1879,7 +1881,7 @@ namespace twitter_tests { TEST_SUCCEED(); } -#endif +#endif // SIMDJSON_EXCEPTIONS bool run() { return