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 <cstdio>
|
||||
#include <cstdlib>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include <cassert>
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
#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;
|
||||
|
||||
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};
|
||||
auto json = build_parsed_json(pstr);
|
||||
|
||||
assert(json.is_valid());
|
||||
ASSERT(json.is_valid());
|
||||
ParsedJson::Iterator it{json};
|
||||
assert(it.down());
|
||||
assert(it.next());
|
||||
ASSERT(it.down());
|
||||
ASSERT(it.next());
|
||||
bool result;
|
||||
if constexpr (std::is_same<int64_t, T>::value) {
|
||||
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};
|
||||
auto json = build_parsed_json(pstr);
|
||||
|
||||
assert(json.is_valid());
|
||||
ASSERT(json.is_valid());
|
||||
document::iterator it{json};
|
||||
assert(it.down());
|
||||
assert(it.next());
|
||||
ASSERT(it.down());
|
||||
ASSERT(it.next());
|
||||
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};
|
||||
auto json = build_parsed_json(pstr);
|
||||
|
||||
assert(json.is_valid());
|
||||
ASSERT(json.is_valid());
|
||||
document::iterator it{json};
|
||||
assert(it.down());
|
||||
assert(it.next());
|
||||
ASSERT(it.down());
|
||||
ASSERT(it.next());
|
||||
return it.is_unsigned_integer() && it.is_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include <cassert>
|
||||
#include <cstring>
|
||||
#ifndef _MSC_VER
|
||||
#include <dirent.h>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include <assert.h>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <inttypes.h>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include <cassert>
|
||||
#include <cstring>
|
||||
#ifndef _MSC_VER
|
||||
#include <dirent.h>
|
||||
|
|
|
@ -2,35 +2,47 @@
|
|||
|
||||
#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() {
|
||||
// {"/~01abc": [0, {"\\\" 0": ["value0", "value1"]}]}"
|
||||
std::string json =
|
||||
"{\"/~01abc\": [0, {\"\\\\\\\" 0\": [\"value0\", \"value1\"]}]}";
|
||||
simdjson::ParsedJson pj;
|
||||
simdjson::json_parse(json.c_str(), json.length(), pj);
|
||||
assert(pj.is_valid());
|
||||
ASSERT(pj.is_valid());
|
||||
simdjson::ParsedJson::Iterator it(pj);
|
||||
|
||||
// valid JSON String Representation pointer
|
||||
std::string pointer1("/~1~001abc/1/\\\\\\\" 0/0");
|
||||
assert(it.move_to(pointer1.c_str(), pointer1.length()));
|
||||
assert(it.is_string());
|
||||
assert(it.get_string() == std::string("value0"));
|
||||
ASSERT(it.move_to(pointer1.c_str(), pointer1.length()));
|
||||
ASSERT(it.is_string());
|
||||
ASSERT(it.get_string() == std::string("value0"));
|
||||
|
||||
// valid URI Fragment Identifier Representation pointer
|
||||
std::string pointer2("#/~1~001abc/1/%x5C%x22%x200/1");
|
||||
assert(it.move_to(pointer2.c_str(), pointer2.length()));
|
||||
assert(it.is_string());
|
||||
assert(it.get_string() == std::string("value1"));
|
||||
ASSERT(it.move_to(pointer2.c_str(), pointer2.length()));
|
||||
ASSERT(it.is_string());
|
||||
ASSERT(it.get_string() == std::string("value1"));
|
||||
|
||||
// invalid pointer with leading 0 in index
|
||||
std::string pointer3("#/~1~001abc/01");
|
||||
assert(!it.move_to(pointer3.c_str(), pointer3.length())); // failed
|
||||
assert(it.is_string()); // has probably not moved
|
||||
assert(it.get_string() == std::string("value1")); // has not move
|
||||
ASSERT(!it.move_to(pointer3.c_str(), pointer3.length())); // failed
|
||||
ASSERT(it.is_string()); // has probably not moved
|
||||
ASSERT(it.get_string() == std::string("value1")); // has not move
|
||||
|
||||
// "the (nonexistent) member after the last array element"
|
||||
std::string pointer4("/~1~001abc/-");
|
||||
assert(it.move_to(pointer4.c_str(), pointer4.length()));
|
||||
assert(it.get_type() == ']');
|
||||
ASSERT(it.move_to(pointer4.c_str(), pointer4.length()));
|
||||
ASSERT(it.get_type() == ']');
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include <cassert>
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
|
|
|
@ -43,14 +43,14 @@ set(WARNING_FLAGS "-Wall")
|
|||
if(NOT MSVC)
|
||||
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_RELEASE "-O3")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SIMDJSON_SANITIZE_FLAGS} ")
|
||||
|
||||
if(NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXSTD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SIMDJSON_SANITIZE_FLAGS} ")
|
||||
|
||||
|
|
Loading…
Reference in New Issue