Adding NDEBUG to release (#557)
* Adding NDEBUG to release * Asserts are deleted with NDEBUG. We want hard asserts.
This commit is contained in:
parent
89d9de2353
commit
06c1dc3a29
|
@ -1,4 +1,3 @@
|
||||||
#include <cassert>
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <cassert>
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
|
@ -1,10 +1,21 @@
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "simdjson.h"
|
#include "simdjson.h"
|
||||||
|
|
||||||
|
// we define our own asserts to get around NDEBUG
|
||||||
|
#ifndef ASSERT
|
||||||
|
#define ASSERT(x) \
|
||||||
|
{ if (!(x)) { \
|
||||||
|
char buf[4096]; \
|
||||||
|
snprintf (buf, 4096, "Failure in \"%s\", line %d\n", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
abort (); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace simdjson;
|
using namespace simdjson;
|
||||||
|
|
||||||
static const std::string make_json(const std::string value) {
|
static const std::string make_json(const std::string value) {
|
||||||
|
@ -23,10 +34,10 @@ static void parse_and_validate(const std::string src, T expected) {
|
||||||
const padded_string pstr{src};
|
const padded_string pstr{src};
|
||||||
auto json = build_parsed_json(pstr);
|
auto json = build_parsed_json(pstr);
|
||||||
|
|
||||||
assert(json.is_valid());
|
ASSERT(json.is_valid());
|
||||||
ParsedJson::Iterator it{json};
|
ParsedJson::Iterator it{json};
|
||||||
assert(it.down());
|
ASSERT(it.down());
|
||||||
assert(it.next());
|
ASSERT(it.next());
|
||||||
bool result;
|
bool result;
|
||||||
if constexpr (std::is_same<int64_t, T>::value) {
|
if constexpr (std::is_same<int64_t, T>::value) {
|
||||||
const auto actual = it.get_integer();
|
const auto actual = it.get_integer();
|
||||||
|
@ -47,10 +58,10 @@ static bool parse_and_check_signed(const std::string src) {
|
||||||
const padded_string pstr{src};
|
const padded_string pstr{src};
|
||||||
auto json = build_parsed_json(pstr);
|
auto json = build_parsed_json(pstr);
|
||||||
|
|
||||||
assert(json.is_valid());
|
ASSERT(json.is_valid());
|
||||||
document::iterator it{json};
|
document::iterator it{json};
|
||||||
assert(it.down());
|
ASSERT(it.down());
|
||||||
assert(it.next());
|
ASSERT(it.next());
|
||||||
return it.is_integer() && it.is_number();
|
return it.is_integer() && it.is_number();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,10 +70,10 @@ static bool parse_and_check_unsigned(const std::string src) {
|
||||||
const padded_string pstr{src};
|
const padded_string pstr{src};
|
||||||
auto json = build_parsed_json(pstr);
|
auto json = build_parsed_json(pstr);
|
||||||
|
|
||||||
assert(json.is_valid());
|
ASSERT(json.is_valid());
|
||||||
document::iterator it{json};
|
document::iterator it{json};
|
||||||
assert(it.down());
|
ASSERT(it.down());
|
||||||
assert(it.next());
|
ASSERT(it.next());
|
||||||
return it.is_unsigned_integer() && it.is_number();
|
return it.is_unsigned_integer() && it.is_number();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <cassert>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <assert.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <cassert>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
|
@ -2,35 +2,47 @@
|
||||||
|
|
||||||
#include "simdjson.h"
|
#include "simdjson.h"
|
||||||
|
|
||||||
|
// we define our own asserts to get around NDEBUG
|
||||||
|
#ifndef ASSERT
|
||||||
|
#define ASSERT(x) \
|
||||||
|
{ if (!(x)) { \
|
||||||
|
char buf[4096]; \
|
||||||
|
snprintf (buf, 4096, "Failure in \"%s\", line %d\n", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
abort (); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// {"/~01abc": [0, {"\\\" 0": ["value0", "value1"]}]}"
|
// {"/~01abc": [0, {"\\\" 0": ["value0", "value1"]}]}"
|
||||||
std::string json =
|
std::string json =
|
||||||
"{\"/~01abc\": [0, {\"\\\\\\\" 0\": [\"value0\", \"value1\"]}]}";
|
"{\"/~01abc\": [0, {\"\\\\\\\" 0\": [\"value0\", \"value1\"]}]}";
|
||||||
simdjson::ParsedJson pj;
|
simdjson::ParsedJson pj;
|
||||||
simdjson::json_parse(json.c_str(), json.length(), pj);
|
simdjson::json_parse(json.c_str(), json.length(), pj);
|
||||||
assert(pj.is_valid());
|
ASSERT(pj.is_valid());
|
||||||
simdjson::ParsedJson::Iterator it(pj);
|
simdjson::ParsedJson::Iterator it(pj);
|
||||||
|
|
||||||
// valid JSON String Representation pointer
|
// valid JSON String Representation pointer
|
||||||
std::string pointer1("/~1~001abc/1/\\\\\\\" 0/0");
|
std::string pointer1("/~1~001abc/1/\\\\\\\" 0/0");
|
||||||
assert(it.move_to(pointer1.c_str(), pointer1.length()));
|
ASSERT(it.move_to(pointer1.c_str(), pointer1.length()));
|
||||||
assert(it.is_string());
|
ASSERT(it.is_string());
|
||||||
assert(it.get_string() == std::string("value0"));
|
ASSERT(it.get_string() == std::string("value0"));
|
||||||
|
|
||||||
// valid URI Fragment Identifier Representation pointer
|
// valid URI Fragment Identifier Representation pointer
|
||||||
std::string pointer2("#/~1~001abc/1/%x5C%x22%x200/1");
|
std::string pointer2("#/~1~001abc/1/%x5C%x22%x200/1");
|
||||||
assert(it.move_to(pointer2.c_str(), pointer2.length()));
|
ASSERT(it.move_to(pointer2.c_str(), pointer2.length()));
|
||||||
assert(it.is_string());
|
ASSERT(it.is_string());
|
||||||
assert(it.get_string() == std::string("value1"));
|
ASSERT(it.get_string() == std::string("value1"));
|
||||||
|
|
||||||
// invalid pointer with leading 0 in index
|
// invalid pointer with leading 0 in index
|
||||||
std::string pointer3("#/~1~001abc/01");
|
std::string pointer3("#/~1~001abc/01");
|
||||||
assert(!it.move_to(pointer3.c_str(), pointer3.length())); // failed
|
ASSERT(!it.move_to(pointer3.c_str(), pointer3.length())); // failed
|
||||||
assert(it.is_string()); // has probably not moved
|
ASSERT(it.is_string()); // has probably not moved
|
||||||
assert(it.get_string() == std::string("value1")); // has not move
|
ASSERT(it.get_string() == std::string("value1")); // has not move
|
||||||
|
|
||||||
// "the (nonexistent) member after the last array element"
|
// "the (nonexistent) member after the last array element"
|
||||||
std::string pointer4("/~1~001abc/-");
|
std::string pointer4("/~1~001abc/-");
|
||||||
assert(it.move_to(pointer4.c_str(), pointer4.length()));
|
ASSERT(it.move_to(pointer4.c_str(), pointer4.length()));
|
||||||
assert(it.get_type() == ']');
|
ASSERT(it.get_type() == ']');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include <assert.h>
|
#include <cassert>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
|
@ -43,14 +43,14 @@ set(WARNING_FLAGS "-Wall")
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
set(WARNING_FLAGS "${WARNING_FLAGS} -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self")
|
set(WARNING_FLAGS "${WARNING_FLAGS} -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self")
|
||||||
set(CMAKE_C_FLAGS_DEBUG "-ggdb")
|
set(CMAKE_C_FLAGS_DEBUG "-ggdb")
|
||||||
set(CMAKE_C_FLAGS_RELEASE "-O3")
|
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SIMDJSON_SANITIZE_FLAGS} ")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SIMDJSON_SANITIZE_FLAGS} ")
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb")
|
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||||
endif()
|
endif()
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXSTD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SIMDJSON_SANITIZE_FLAGS} ")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXSTD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SIMDJSON_SANITIZE_FLAGS} ")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue