Compare commits

...

10 Commits

Author SHA1 Message Date
Daniel Lemire 4b13020d65 Patch release 2023-03-13 21:44:34 -04:00
Daniel Lemire 75c6c950e5 Ok. 2023-03-13 21:26:32 -04:00
Daniel Lemire 5ad7698af1 ... 2023-03-13 17:07:25 -04:00
Daniel Lemire f6f359d3eb Very silly. 2023-03-13 17:05:53 -04:00
Daniel Lemire 185e157e0c Silencing the stupid compiler warnings. 2023-03-13 16:06:10 -04:00
Daniel Lemire 3f3f6cde7c Bad compiler 2023-03-13 13:33:20 -04:00
Daniel Lemire 005054916d Bad compiler 2023-03-13 13:02:01 -04:00
Daniel Lemire 338224849d Disabling memory sanitizer with one function. Might help with issue 1965 (#1966)
* Might help with issue 1965

* Fix macro

* Adding test.

* Stupid compiler

* Silly compiler

* Stupid compilers

* Unnecessary fixes

* Update developer-options.cmake
2023-03-13 12:34:47 -04:00
Ashot Vardanian ada52641b4 Fix: Defining maximal DOM capacity (#1970) 2023-03-13 12:33:37 -04:00
Daniel Lemire ede9d57f22 Adding tests with _GLIBCXX_ASSERTIONS (#1969)
* Allowing users to specify -D_GLIBCXX_ASSERTIONS

* Adding CI tests for GLIBCXX_ASSERTIONS

* Adding curly brackets.
2023-03-13 12:32:43 -04:00
29 changed files with 190 additions and 55 deletions
@@ -0,0 +1,24 @@
name: Ubuntu 22.04 CI GCC 12 with GLIBCXX_ASSERTIONS
on: [push, pull_request]
jobs:
ubuntu-build:
if: >-
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
! contains(toJSON(github.event.commits.*.message), '[skip github]')
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: dependencies/.cache
key: ${{ hashFiles('dependencies/CMakeLists.txt') }}
- name: Install gcc12
run: sudo apt-get install -y g++-12
- name: Use cmake
run: |
mkdir build &&
cd build &&
CXX=g++-12 cmake -DCMAKE_BUILD_TYPE=Debug -DSIMDJSON_GLIBCXX_ASSERTIONS=ON -DSIMDJSON_GOOGLE_BENCHMARKS=OFF -DSIMDJSON_DEVELOPER_MODE=ON .. &&
cmake --build . &&
ctest . -E avoid_
+1 -1
View File
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
project(
simdjson
# The version number is modified by tools/release.py
VERSION 3.1.5
VERSION 3.1.6
DESCRIPTION "Parsing gigabytes of JSON per second"
HOMEPAGE_URL "https://simdjson.org/"
LANGUAGES CXX C
+1 -1
View File
@@ -38,7 +38,7 @@ PROJECT_NAME = simdjson
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = "3.1.5"
PROJECT_NUMBER = "3.1.6"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
+1 -1
View File
@@ -564,7 +564,7 @@ static void error_code_twitter_default_profile(State& state) noexcept {
for (dom::element tweet : tweets) {
dom::object user;
if ((error = tweet["user"].get(user))) { return; }
bool default_profile;
bool default_profile{};
if ((error = user["default_profile"].get(default_profile))) { return; }
if (default_profile) {
std::string_view screen_name;
+22
View File
@@ -50,6 +50,23 @@ undefined behavior.")
endif()
endif()
option(SIMDJSON_SANITIZE_MEMORY "Sanitize memory" OFF)
if(SIMDJSON_SANITIZE_MEMORY)
message(STATUS "Setting the memory sanitizer.")
add_compile_options(
-fsanitize=memory -fno-sanitize-recover=all
)
link_libraries(
-fsanitize=memory -fno-sanitize-recover=all
)
# Ubuntu bug for GCC 5.0+ (safe for all versions)
if(CMAKE_COMPILER_IS_GNUCC)
link_libraries(-fuse-ld=gold)
endif()
endif()
if(SIMDJSON_SANITIZE_THREADS)
message(STATUS "Setting both the thread sanitizer \
and the undefined-behavior sanitizer.")
@@ -144,6 +161,11 @@ else()
)
endif()
option(SIMDJSON_GLIBCXX_ASSERTIONS "Set _GLIBCXX_ASSERTIONS" OFF)
if (SIMDJSON_GLIBCXX_ASSERTIONS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_ASSERTIONS")
endif()
#
# Other optional flags
#
+1 -1
View File
@@ -1023,7 +1023,7 @@ bool parse() {
cout << "Make/Model: " << make << "/" << model << endl;
// Casting a JSON element to an integer
uint64_t year;
uint64_t year{};
error = car["year"].get(year);
if(error) { std::cerr << error << std::endl; return false; }
cout << "- This car is " << 2020 - year << " years old." << endl;
+4
View File
@@ -9,6 +9,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
unsigned long ret;
+1 -1
View File
@@ -226,7 +226,7 @@ inline error_code parser::ensure_capacity(document& target_document, size_t desi
}
simdjson_inline void parser::set_max_capacity(size_t max_capacity) noexcept {
if(max_capacity < MINIMAL_DOCUMENT_CAPACITY) {
if(max_capacity > MINIMAL_DOCUMENT_CAPACITY) {
_max_capacity = max_capacity;
} else {
_max_capacity = MINIMAL_DOCUMENT_CAPACITY;
@@ -9,6 +9,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#if SIMDJSON_REGULAR_VISUAL_STUDIO
return (int)_tzcnt_u64(input_num);
@@ -9,6 +9,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#if SIMDJSON_REGULAR_VISUAL_STUDIO
return (int)_tzcnt_u64(input_num);
+13
View File
@@ -148,6 +148,19 @@ use a 64-bit target such as x64, 64-bit ARM or 64-bit PPC.")
#define SIMDJSON_NO_SANITIZE_UNDEFINED
#endif
#if defined(__clang__) || defined(__GNUC__)
#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
#define SIMDJSON_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
# endif // if __has_feature(memory_sanitizer)
#endif // defined(__has_feature)
#endif
// make sure it is defined as 'nothing' if it is unapplicable.
#ifndef SIMDJSON_NO_SANITIZE_MEMORY
#define SIMDJSON_NO_SANITIZE_MEMORY
#endif
#if SIMDJSON_VISUAL_STUDIO
// This is one case where we do not distinguish between
// regular visual studio and clang under visual studio.
+4
View File
@@ -9,6 +9,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#if SIMDJSON_REGULAR_VISUAL_STUDIO
unsigned long ret;
+2 -2
View File
@@ -4,7 +4,7 @@
#define SIMDJSON_SIMDJSON_VERSION_H
/** The version of simdjson being used (major.minor.revision) */
#define SIMDJSON_VERSION "3.1.5"
#define SIMDJSON_VERSION "3.1.6"
namespace simdjson {
enum {
@@ -19,7 +19,7 @@ enum {
/**
* The revision (major.minor.REVISION) of simdjson being used.
*/
SIMDJSON_VERSION_REVISION = 5
SIMDJSON_VERSION_REVISION = 6
};
} // namespace simdjson
@@ -9,6 +9,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#if SIMDJSON_REGULAR_VISUAL_STUDIO
unsigned long ret;
+1 -1
View File
@@ -1,4 +1,4 @@
/* auto-generated on 2023-03-09 11:14:42 -0500. Do not edit! */
/* auto-generated on 2023-03-13 21:26:32 -0400. Do not edit! */
/* begin file src/simdjson.cpp */
#include "simdjson.h"
+37 -4
View File
@@ -1,4 +1,4 @@
/* auto-generated on 2023-03-09 11:14:42 -0500. Do not edit! */
/* auto-generated on 2023-03-13 21:26:32 -0400. Do not edit! */
/* begin file include/simdjson.h */
#ifndef SIMDJSON_H
#define SIMDJSON_H
@@ -43,7 +43,7 @@
#define SIMDJSON_SIMDJSON_VERSION_H
/** The version of simdjson being used (major.minor.revision) */
#define SIMDJSON_VERSION "3.1.5"
#define SIMDJSON_VERSION "3.1.6"
namespace simdjson {
enum {
@@ -58,7 +58,7 @@ enum {
/**
* The revision (major.minor.REVISION) of simdjson being used.
*/
SIMDJSON_VERSION_REVISION = 5
SIMDJSON_VERSION_REVISION = 6
};
} // namespace simdjson
@@ -265,6 +265,19 @@ use a 64-bit target such as x64, 64-bit ARM or 64-bit PPC.")
#define SIMDJSON_NO_SANITIZE_UNDEFINED
#endif
#if defined(__clang__) || defined(__GNUC__)
#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
#define SIMDJSON_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
# endif // if __has_feature(memory_sanitizer)
#endif // defined(__has_feature)
#endif
// make sure it is defined as 'nothing' if it is unapplicable.
#ifndef SIMDJSON_NO_SANITIZE_MEMORY
#define SIMDJSON_NO_SANITIZE_MEMORY
#endif
#if SIMDJSON_VISUAL_STUDIO
// This is one case where we do not distinguish between
// regular visual studio and clang under visual studio.
@@ -8896,7 +8909,7 @@ inline error_code parser::ensure_capacity(document& target_document, size_t desi
}
simdjson_inline void parser::set_max_capacity(size_t max_capacity) noexcept {
if(max_capacity < MINIMAL_DOCUMENT_CAPACITY) {
if(max_capacity > MINIMAL_DOCUMENT_CAPACITY) {
_max_capacity = max_capacity;
} else {
_max_capacity = MINIMAL_DOCUMENT_CAPACITY;
@@ -9845,6 +9858,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
unsigned long ret;
@@ -13956,6 +13973,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#if SIMDJSON_REGULAR_VISUAL_STUDIO
return (int)_tzcnt_u64(input_num);
@@ -16146,6 +16167,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#if SIMDJSON_REGULAR_VISUAL_STUDIO
return (int)_tzcnt_u64(input_num);
@@ -18292,6 +18317,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#if SIMDJSON_REGULAR_VISUAL_STUDIO
unsigned long ret;
@@ -20609,6 +20638,10 @@ namespace {
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
SIMDJSON_NO_SANITIZE_UNDEFINED
// This function can be used safely even if not all bytes have been
// initialized.
// See issue https://github.com/simdjson/simdjson/issues/1965
SIMDJSON_NO_SANITIZE_MEMORY
simdjson_inline int trailing_zeroes(uint64_t input_num) {
#if SIMDJSON_REGULAR_VISUAL_STUDIO
unsigned long ret;
+12 -12
View File
@@ -59,28 +59,28 @@ private:
template<typename T>
bool cast_tester<T>::test_get(element element, T expected) {
T actual;
T actual{};
ASSERT_SUCCESS(element.get(actual));
return assert_equal(actual, expected);
}
template<typename T>
bool cast_tester<T>::test_get(simdjson_result<element> element, T expected) {
T actual;
T actual{};
ASSERT_SUCCESS(element.get(actual));
return assert_equal(actual, expected);
}
template<typename T>
bool cast_tester<T>::test_get_error(element element, error_code expected_error) {
T actual;
T actual{};
ASSERT_EQUAL(element.get(actual), expected_error);
return true;
}
template<typename T>
bool cast_tester<T>::test_get_error(simdjson_result<element> element, error_code expected_error) {
T actual;
T actual{};
ASSERT_EQUAL(element.get(actual), expected_error);
return true;
}
@@ -113,28 +113,28 @@ bool cast_tester<T>::test_get_t_error(simdjson_result<element> element, error_co
template<typename T>
bool cast_tester<T>::test_named_get(element element, T expected) {
T actual;
T actual{};
ASSERT_SUCCESS(named_get(element).get(actual));
return assert_equal(actual, expected);
}
template<typename T>
bool cast_tester<T>::test_named_get(simdjson_result<element> element, T expected) {
T actual;
T actual{};
ASSERT_SUCCESS(named_get(element).get(actual));
return assert_equal(actual, expected);
}
template<typename T>
bool cast_tester<T>::test_named_get_error(element element, error_code expected_error) {
T actual;
T actual{};
ASSERT_EQUAL(named_get(element).get(actual), expected_error);
return true;
}
template<typename T>
bool cast_tester<T>::test_named_get_error(simdjson_result<element> element, error_code expected_error) {
T actual;
T actual{};
ASSERT_EQUAL(named_get(element).get(actual), expected_error);
return true;
}
@@ -143,7 +143,7 @@ bool cast_tester<T>::test_named_get_error(simdjson_result<element> element, erro
template<typename T>
bool cast_tester<T>::test_implicit_cast(element element, T expected) {
T actual;
T actual{};
try {
actual = element;
} catch(simdjson_error &e) {
@@ -155,7 +155,7 @@ bool cast_tester<T>::test_implicit_cast(element element, T expected) {
template<typename T>
bool cast_tester<T>::test_implicit_cast(simdjson_result<element> element, T expected) {
T actual;
T actual{};
try {
actual = element;
} catch(simdjson_error &e) {
@@ -168,7 +168,7 @@ bool cast_tester<T>::test_implicit_cast(simdjson_result<element> element, T expe
template<typename T>
bool cast_tester<T>::test_implicit_cast_error(element element, error_code expected_error) {
try {
simdjson_unused T actual;
simdjson_unused T actual{};
actual = element;
return false;
} catch(simdjson_error &e) {
@@ -180,7 +180,7 @@ bool cast_tester<T>::test_implicit_cast_error(element element, error_code expect
template<typename T>
bool cast_tester<T>::test_implicit_cast_error(simdjson_result<element> element, error_code expected_error) {
try {
simdjson_unused T actual;
simdjson_unused T actual{};
actual = element;
return false;
} catch(simdjson_error &e) {
+1 -1
View File
@@ -74,7 +74,7 @@ namespace number_tests {
for (int m = 10; m < 20; m++) {
for (int i = -1024; i < 1024; i++) {
auto str = std::to_string(i);
int64_t actual;
int64_t actual{};
ASSERT_SUCCESS(parser.parse(str).get(actual));
if (actual != i) {
std::cerr << "JSON '" << str << "' parsed to " << actual << " instead of " << i << std::endl;
+1 -1
View File
@@ -634,7 +634,7 @@ namespace document_stream_tests {
ASSERT_SUCCESS( odparser.parse_many(json.data(), json.length(), 50).get(odstream) );
for (auto doc: odstream) {
if(counter < 6) {
int64_t val;
int64_t val{};
ASSERT_SUCCESS(doc.at_pointer("/4").get(val));
ASSERT_EQUAL(val, 5);
} else {
+2 -2
View File
@@ -41,7 +41,7 @@ void basics_error_2() {
cout << "Make/Model: " << make << "/" << model << endl;
// Casting a JSON element to an integer
uint64_t year;
uint64_t year{};
if ((error = car["year"].get(year))) { cerr << error << endl; exit(1); }
cout << "- This car is " << 2020 - year << "years old." << endl;
@@ -132,7 +132,7 @@ void basics_error_2_cpp17() {
cout << "Make/Model: " << make << "/" << model << endl;
// Casting a JSON element to an integer
uint64_t year;
uint64_t year{};
if ((error = car["year"].get(year))) { cerr << error << endl; exit(1); }
cout << "- This car is " << 2020 - year << "years old." << endl;
+11 -11
View File
@@ -134,7 +134,7 @@ namespace array_tests {
ondemand::parser parser;
ondemand::document doc;
ASSERT_SUCCESS(parser.iterate(json).get(doc));
size_t count;
size_t count{};
ASSERT_SUCCESS(doc.count_elements().get(count));
ondemand::array arr;
ASSERT_SUCCESS(doc.get_array().get(arr));
@@ -182,7 +182,7 @@ namespace array_tests {
ASSERT_SUCCESS(doc.get_object().get(obj));
ondemand::value v;
ASSERT_SUCCESS(doc.find_field("test").get(v));
size_t count;
size_t count{};
ASSERT_SUCCESS(v.count_elements().get(count));
ASSERT_EQUAL(count, 3);
ASSERT_SUCCESS(doc.find_field("joe").get(v));
@@ -200,7 +200,7 @@ namespace array_tests {
ondemand::array array;
ASSERT_RESULT( doc_result.type(), json_type::array );
ASSERT_SUCCESS( doc_result.get_array().get(array) );
size_t count;
size_t count{};
ASSERT_SUCCESS( array.count_elements().get(count) );
ASSERT_EQUAL(count, expected_value.size());
return true;
@@ -209,7 +209,7 @@ namespace array_tests {
ondemand::array array;
ASSERT_RESULT( doc_result.type(), json_type::array );
ASSERT_SUCCESS( doc_result.get(array) );
size_t count;
size_t count{};
ASSERT_SUCCESS( array.count_elements().get(count) );
ASSERT_EQUAL(count, expected_value.size());
size_t i = 0;
@@ -235,7 +235,7 @@ namespace array_tests {
ondemand::array array;
ASSERT_RESULT( doc_result.type(), json_type::array );
ASSERT_SUCCESS( doc_result.get_array().get(array) );
size_t count;
size_t count{};
ASSERT_SUCCESS( array.count_elements().get(count) );
ASSERT_EQUAL(count, 0);
return true;
@@ -244,7 +244,7 @@ namespace array_tests {
ondemand::array array;
ASSERT_RESULT( doc_result.type(), json_type::array );
ASSERT_SUCCESS( doc_result.get(array) );
size_t count;
size_t count{};
ASSERT_SUCCESS( array.count_elements().get(count) );
ASSERT_EQUAL(count, 0);
size_t i = 0;
@@ -269,7 +269,7 @@ namespace array_tests {
ondemand::array array;
ASSERT_RESULT( doc_result.type(), json_type::array );
ASSERT_SUCCESS( doc_result.get(array) );
size_t count;
size_t count{};
auto e = array.count_elements().get(count);
if( e != TAPE_ERROR) {
std::cout << e << "\n";
@@ -285,7 +285,7 @@ namespace array_tests {
TEST_START();
auto empty = R"( [] )"_padded;
SUBTEST("ondemand::empty_doc_array", test_ondemand_doc(empty, [&](auto doc_result) {
size_t count;
size_t count{};
ASSERT_RESULT( doc_result.type(), json_type::array );
ASSERT_SUCCESS( doc_result.count_elements().get(count) );
ASSERT_EQUAL( count, 0 );
@@ -293,7 +293,7 @@ namespace array_tests {
}));
auto basic = R"( [-1.234, 100000000000000, null, [1,2,3], {"t":true, "f":false}] )"_padded;
SUBTEST("ondemand::basic_doc_array", test_ondemand_doc(basic, [&](auto doc_result) {
size_t count;
size_t count{};
ASSERT_RESULT( doc_result.type(), json_type::array );
ASSERT_SUCCESS( doc_result.count_elements().get(count) );
ASSERT_EQUAL( count, 5 );
@@ -435,7 +435,7 @@ namespace array_tests {
TEST_SUCCEED();
}
bool count_empty(simdjson::ondemand::array arr) {
size_t count;
size_t count{};
ASSERT_SUCCESS(arr.count_elements().get(count));
ASSERT_EQUAL(count, 0);
bool is_empty;
@@ -466,7 +466,7 @@ namespace array_tests {
for (auto d : data) {
simdjson::ondemand::array arr;
ASSERT_SUCCESS(d.get_array().get(arr));
size_t count;
size_t count{};
ASSERT_SUCCESS(arr.count_elements().get(count));
ASSERT_EQUAL(count, 4);
}
@@ -7,7 +7,7 @@ namespace document_stream_tests {
template <typename T>
bool process_doc(T &docref) {
int64_t val;
int64_t val{};
ASSERT_SUCCESS(docref.at_pointer("/4").get(val));
ASSERT_EQUAL(val, 5);
return true;
@@ -604,7 +604,7 @@ namespace document_stream_tests {
ASSERT_SUCCESS( odparser.iterate_many(json.data(), json.length(), 50).get(odstream) );
for (auto doc: odstream) {
if(counter < 6) {
int64_t val;
int64_t val{};
ASSERT_SUCCESS(doc.at_pointer("/4").get(val));
ASSERT_EQUAL(val, 5);
} else {
+1 -1
View File
@@ -67,7 +67,7 @@ namespace misc_tests {
ASSERT_SUCCESS(val.get_object().get(obj));
ondemand::array arr;
ASSERT_SUCCESS(obj["a"].get_array().get(arr));
size_t count;
size_t count{};
ASSERT_SUCCESS(arr.count_elements().get(count));
ASSERT_EQUAL(3,count);
TEST_SUCCEED();
+2 -2
View File
@@ -232,7 +232,7 @@ namespace number_tests {
for(simdjson_result<ondemand::value> valr : arr) {
ondemand::value val;
ASSERT_SUCCESS(valr.get(val));
ondemand::number_type nt;
ondemand::number_type nt{};
ASSERT_SUCCESS(val.get_number_type().get(nt));
ASSERT_EQUAL(expectedtypes[counter], nt);
ondemand::number num;
@@ -339,7 +339,7 @@ namespace number_tests {
ondemand::document doc;
padded_string docdata;
ondemand::number number;
ondemand::number_type nt;
ondemand::number_type nt{};
bool intvalue{};
@@ -10,7 +10,7 @@ namespace object_error_tests {
bool assert_iterate_object(T &&object, const char **expected_key, V *expected, size_t N, simdjson::error_code *expected_error, size_t N2) {
size_t count = 0;
for (auto field : object) {
V actual;
V actual{};
auto actual_error = field.value().get(actual);
if (count >= N) {
ASSERT((count - N) < N2, "Extra error reported");
+23
View File
@@ -6,6 +6,7 @@ using namespace simdjson;
namespace object_tests {
using namespace std;
using simdjson::ondemand::json_type;
bool issue1745() {
TEST_START();
auto json = R"({
@@ -225,6 +226,25 @@ namespace object_tests {
}
#if SIMDJSON_EXCEPTIONS
bool issue1965() {
TEST_START();
std::string str = "{\"query\":\"ah\"}";
std::unique_ptr<char[]> buffer(new char[str.size() + simdjson::SIMDJSON_PADDING]);
memcpy(buffer.get(), str.data(), str.size());
simdjson::padded_string_view view(buffer.get(), str.size(), str.size() + simdjson::SIMDJSON_PADDING);
simdjson::ondemand::parser parser;
simdjson::ondemand::document doc = parser.iterate(view);
simdjson::ondemand::object root = doc.get_object();
simdjson::ondemand::value query = root.find_field("query");
simdjson::ondemand::raw_json_string raw = query.get_raw_json_string();
std::unique_ptr<uint8_t[]> dst_buffer(new uint8_t[3 + simdjson::SIMDJSON_PADDING]);
uint8_t * dst = dst_buffer.get();
std::string_view fieldstring = parser.unescape(raw, dst);
std::cout << fieldstring << std::endl;
TEST_SUCCEED();
}
bool issue1745_with_exceptions() {
TEST_START();
auto json = R"({
@@ -1221,6 +1241,9 @@ namespace object_tests {
bool run() {
return
#if SIMDJSON_EXCEPTIONS
issue1965() &&
#endif
issue1876a() &&
issue1876() &&
test_strager() &&
+1 -1
View File
@@ -576,7 +576,7 @@ bool using_the_parsed_json_no_exceptions() {
cout << "Make/Model: " << make << "/" << model << endl;
// Casting a JSON element to an integer
uint64_t year;
uint64_t year{};
error = car["year"].get(year);
if(error) { std::cerr << error << std::endl; return false; }
cout << "- This car is " << 2020 - year << " years old." << endl;
+8 -8
View File
@@ -18,7 +18,7 @@ namespace scalar_tests {
bool test_scalar_value(const padded_string &json, const T &expected, bool test_twice=true) {
std::cout << "- JSON: " << json << endl;
SUBTEST( "simdjson_result<document>", test_ondemand_doc(json, [&](auto doc_result) {
T actual;
T actual{};
ASSERT_RESULT( doc_result.type(), expected_json_type<T>() );
ASSERT_SUCCESS( doc_result.get(actual) );
ASSERT_EQUAL( actual, expected );
@@ -33,7 +33,7 @@ namespace scalar_tests {
SUBTEST( "document", test_ondemand_doc(json, [&](auto doc_result) {
ondemand::document doc;
ASSERT_SUCCESS( std::move(doc_result).get(doc) );
T actual;
T actual{};
ASSERT_RESULT( doc.type(), expected_json_type<T>() );
ASSERT_SUCCESS( doc.get(actual) );
ASSERT_EQUAL( actual, expected );
@@ -50,7 +50,7 @@ namespace scalar_tests {
padded_string whitespace_json = std::string(json) + " ";
std::cout << "- JSON: " << whitespace_json << endl;
SUBTEST( "simdjson_result<document>", test_ondemand_doc(whitespace_json, [&](auto doc_result) {
T actual;
T actual{};
ASSERT_RESULT( doc_result.type(), expected_json_type<T>() );
ASSERT_SUCCESS( doc_result.get(actual) );
ASSERT_EQUAL( actual, expected );
@@ -65,7 +65,7 @@ namespace scalar_tests {
SUBTEST( "document", test_ondemand_doc(whitespace_json, [&](auto doc_result) {
ondemand::document doc;
ASSERT_SUCCESS( std::move(doc_result).get(doc) );
T actual;
T actual{};
ASSERT_RESULT( doc.type(), expected_json_type<T>() );
ASSERT_SUCCESS( doc.get(actual) );
ASSERT_EQUAL( actual, expected );
@@ -85,7 +85,7 @@ namespace scalar_tests {
SUBTEST( "simdjson_result<value>", test_ondemand_doc(array_json, [&](auto doc_result) {
int count = 0;
for (simdjson_result<ondemand::value> val_result : doc_result) {
T actual;
T actual{};
ASSERT_RESULT( val_result.type(), expected_json_type<T>() );
ASSERT_SUCCESS( val_result.get(actual) );
ASSERT_EQUAL(actual, expected);
@@ -105,7 +105,7 @@ namespace scalar_tests {
for (simdjson_result<ondemand::value> val_result : doc_result) {
ondemand::value val;
ASSERT_SUCCESS( val_result.get(val) );
T actual;
T actual{};
ASSERT_RESULT( val.type(), expected_json_type<T>() );
ASSERT_SUCCESS( val.get(actual) );
ASSERT_EQUAL(actual, expected);
@@ -129,7 +129,7 @@ namespace scalar_tests {
SUBTEST( "simdjson_result<value>", test_ondemand_doc(whitespace_array_json, [&](auto doc_result) {
int count = 0;
for (simdjson_result<ondemand::value> val_result : doc_result) {
T actual;
T actual{};
ASSERT_RESULT( val_result.type(), expected_json_type<T>() );
ASSERT_SUCCESS( val_result.get(actual) );
ASSERT_EQUAL(actual, expected);
@@ -150,7 +150,7 @@ namespace scalar_tests {
for (simdjson_result<ondemand::value> val_result : doc_result) {
ondemand::value val;
ASSERT_SUCCESS( val_result.get(val) );
T actual;
T actual{};
ASSERT_RESULT( val.type(), expected_json_type<T>() );
ASSERT_SUCCESS( val.get(actual) );
ASSERT_EQUAL(actual, expected);
+1 -1
View File
@@ -56,7 +56,7 @@ namespace twitter_tests {
std::string_view screen_name;
ASSERT_SUCCESS( user["screen_name"].get(screen_name) );
bool default_profile;
bool default_profile{};
ASSERT_SUCCESS( user["default_profile"].get(default_profile) );
if (default_profile) {
default_users.insert(screen_name);