Default SIMDJSON_PRODUCTION to OFF for bare header usage
This commit is contained in:
parent
0f10fc9ad9
commit
14315ec5cd
|
@ -175,9 +175,9 @@ endif()
|
|||
option(SIMDJSON_PRODUCTION "Optimize for production by disabling development-time aids, such as checks for incorrect API usage." OFF)
|
||||
if(SIMDJSON_PRODUCTION)
|
||||
message(STATUS "SIMDJSON_PRODUCTION is ON: optimizing for production by disabling development-time aids, such as checks for incorrect API usage.")
|
||||
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_PRODUCTION)
|
||||
else()
|
||||
message(STATUS "Development-time aids enabled. Use cmake -DSIMDJSON_PRODUCTION=ON to disable development-time aids, such as checks for incorrect API usage.")
|
||||
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_API_USAGE_CHECKS=1)
|
||||
endif()
|
||||
|
||||
option(SIMDJSON_BASH "Allow usage of bash within CMake" ON)
|
||||
|
|
|
@ -56,7 +56,7 @@ simdjson_really_inline array array::started(value_iterator &iter) noexcept {
|
|||
}
|
||||
|
||||
simdjson_really_inline simdjson_result<array_iterator> array::begin() noexcept {
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
if (!iter.is_at_container_start()) { return OUT_OF_ORDER_ITERATION; }
|
||||
#endif
|
||||
return array_iterator(iter);
|
||||
|
|
|
@ -178,14 +178,14 @@ simdjson_really_inline token_position json_iterator::position() const noexcept {
|
|||
simdjson_really_inline void json_iterator::reenter_child(token_position position, depth_t child_depth) noexcept {
|
||||
SIMDJSON_ASSUME(child_depth >= 1 && child_depth < INT32_MAX);
|
||||
SIMDJSON_ASSUME(_depth == child_depth - 1);
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
SIMDJSON_ASSUME(position >= parser->start_positions.get()[child_depth]);
|
||||
#endif
|
||||
token.set_position(position);
|
||||
_depth = child_depth;
|
||||
}
|
||||
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
simdjson_really_inline token_position json_iterator::start_position(depth_t depth) const noexcept {
|
||||
return parser->start_positions[depth];
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ public:
|
|||
|
||||
simdjson_really_inline token_position position() const noexcept;
|
||||
simdjson_really_inline void reenter_child(token_position position, depth_t child_depth) noexcept;
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
simdjson_really_inline token_position start_position(depth_t depth) const noexcept;
|
||||
simdjson_really_inline void set_start_position(depth_t depth, token_position position) noexcept;
|
||||
#endif
|
||||
|
|
|
@ -52,7 +52,7 @@ simdjson_really_inline object::object(const value_iterator &_iter) noexcept
|
|||
}
|
||||
|
||||
simdjson_really_inline simdjson_result<object_iterator> object::begin() noexcept {
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
if (!iter.is_at_container_start()) { return OUT_OF_ORDER_ITERATION; }
|
||||
#endif
|
||||
return object_iterator(iter);
|
||||
|
|
|
@ -9,7 +9,7 @@ simdjson_warn_unused simdjson_really_inline error_code parser::allocate(size_t n
|
|||
_capacity = 0;
|
||||
size_t string_capacity = SIMDJSON_ROUNDUP_N(5 * new_capacity / 3 + SIMDJSON_PADDING, 64);
|
||||
string_buf.reset(new (std::nothrow) uint8_t[string_capacity]);
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
start_positions.reset(new (std::nothrow) token_position[new_max_depth]);
|
||||
#endif
|
||||
if (implementation) {
|
||||
|
|
|
@ -112,7 +112,7 @@ private:
|
|||
size_t _capacity{0};
|
||||
size_t _max_depth{DEFAULT_MAX_DEPTH};
|
||||
std::unique_ptr<uint8_t[]> string_buf{};
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
std::unique_ptr<token_position[]> start_positions{};
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ simdjson_warn_unused simdjson_really_inline bool value_iterator::started_object(
|
|||
return false;
|
||||
}
|
||||
logger::log_start_value(*_json_iter, "object");
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
_json_iter->set_start_position(_depth, _start_position);
|
||||
#endif
|
||||
return true;
|
||||
|
@ -74,7 +74,7 @@ simdjson_warn_unused simdjson_really_inline simdjson_result<bool> value_iterator
|
|||
// ```
|
||||
//
|
||||
} else if (!is_open()) {
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
// If we're past the end of the object, we're being iterated out of order.
|
||||
// Note: this isn't perfect detection. It's possible the user is inside some other object; if so,
|
||||
// this object iterator will blithely scan that object for fields.
|
||||
|
@ -99,7 +99,7 @@ simdjson_warn_unused simdjson_really_inline simdjson_result<bool> value_iterator
|
|||
} else {
|
||||
if ((error = skip_child() )) { abandon(); return error; }
|
||||
if ((error = has_next_field().get(has_value) )) { abandon(); return error; }
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
if (_json_iter->start_position(_depth) != _start_position) { return OUT_OF_ORDER_ITERATION; }
|
||||
#endif
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ simdjson_warn_unused simdjson_really_inline simdjson_result<bool> value_iterator
|
|||
// ```
|
||||
//
|
||||
} else if (!is_open()) {
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
// If we're past the end of the object, we're being iterated out of order.
|
||||
// Note: this isn't perfect detection. It's possible the user is inside some other object; if so,
|
||||
// this object iterator will blithely scan that object for fields.
|
||||
|
@ -179,7 +179,7 @@ simdjson_warn_unused simdjson_really_inline simdjson_result<bool> value_iterator
|
|||
// Finish the previous value and see if , or } is next
|
||||
if ((error = skip_child() )) { abandon(); return error; }
|
||||
if ((error = has_next_field().get(has_value) )) { abandon(); return error; }
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
if (_json_iter->start_position(_depth) != _start_position) { return OUT_OF_ORDER_ITERATION; }
|
||||
#endif
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ simdjson_warn_unused simdjson_really_inline bool value_iterator::started_array()
|
|||
}
|
||||
logger::log_start_value(*_json_iter, "array");
|
||||
_json_iter->descend_to(depth()+1);
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
_json_iter->set_start_position(_depth, _start_position);
|
||||
#endif
|
||||
return true;
|
||||
|
@ -462,7 +462,7 @@ simdjson_really_inline error_code value_iterator::advance_container_start(const
|
|||
|
||||
// If we're not at the position anymore, we don't want to advance the cursor.
|
||||
if (!is_at_start()) {
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
if (!is_at_container_start()) { return OUT_OF_ORDER_ITERATION; }
|
||||
#endif
|
||||
json = peek_start();
|
||||
|
|
|
@ -565,7 +565,7 @@ namespace error_tests {
|
|||
TEST_SUCCEED();
|
||||
}
|
||||
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
bool out_of_order_array_iteration_error() {
|
||||
TEST_START();
|
||||
auto json = R"([ [ 1, 2 ] ])"_padded;
|
||||
|
@ -1011,7 +1011,7 @@ namespace error_tests {
|
|||
object_lookup_miss_next_error() &&
|
||||
get_fail_then_succeed_bool() &&
|
||||
get_fail_then_succeed_null() &&
|
||||
#if SIMDJSON_API_USAGE_CHECKS
|
||||
#ifndef SIMDJSON_PRODUCTION
|
||||
out_of_order_array_iteration_error() &&
|
||||
out_of_order_object_iteration_error() &&
|
||||
out_of_order_object_index_child_error() &&
|
||||
|
|
Loading…
Reference in New Issue