diff --git a/CMakeLists.txt b/CMakeLists.txt index ece14241..0c80733f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(ArduinoJson) enable_testing() -add_definitions(-DARDUINOJSON_DEBUG) +add_definitions(-DARDUINOJSON_DEBUG=1) if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") add_compile_options(-g -O0) endif() diff --git a/extras/fuzzing/Makefile b/extras/fuzzing/Makefile index 7789e88b..d3c574e1 100644 --- a/extras/fuzzing/Makefile +++ b/extras/fuzzing/Makefile @@ -1,6 +1,6 @@ # CAUTION: this file is invoked by https://github.com/google/oss-fuzz -CXXFLAGS += -I../../src -DARDUINOJSON_DEBUG +CXXFLAGS += -I../../src -DARDUINOJSON_DEBUG=1 all: \ $(OUT)/json_fuzzer \ diff --git a/src/ArduinoJson.hpp b/src/ArduinoJson.hpp index d142bb91..a1592f5c 100644 --- a/src/ArduinoJson.hpp +++ b/src/ArduinoJson.hpp @@ -4,7 +4,9 @@ #pragma once -#ifndef ARDUINOJSON_DEBUG +#include "ArduinoJson/Configuration.hpp" + +#if ARDUINOJSON_DEBUG #ifdef __clang__ #pragma clang system_header #elif defined __GNUC__ @@ -12,8 +14,6 @@ #endif #endif -#include "ArduinoJson/Namespace.hpp" - #include "ArduinoJson/Array/ArrayRef.hpp" #include "ArduinoJson/Object/ObjectRef.hpp" #include "ArduinoJson/Variant/VariantRef.hpp" diff --git a/src/ArduinoJson/Configuration.hpp b/src/ArduinoJson/Configuration.hpp index 74ef2e1f..e6c01a2f 100644 --- a/src/ArduinoJson/Configuration.hpp +++ b/src/ArduinoJson/Configuration.hpp @@ -210,3 +210,11 @@ #ifndef ARDUINOJSON_STRING_BUFFER_SIZE #define ARDUINOJSON_STRING_BUFFER_SIZE 32 #endif + +#ifndef ARDUINOJSON_DEBUG +#ifdef __PLATFORMIO_BUILD_DEBUG__ +#define ARDUINOJSON_DEBUG 1 +#else +#define ARDUINOJSON_DEBUG 0 +#endif +#endif diff --git a/src/ArduinoJson/Json/Latch.hpp b/src/ArduinoJson/Json/Latch.hpp index 1e46c913..030e93f2 100644 --- a/src/ArduinoJson/Json/Latch.hpp +++ b/src/ArduinoJson/Json/Latch.hpp @@ -12,7 +12,7 @@ template class Latch { public: Latch(TReader reader) : _reader(reader), _loaded(false) { -#ifdef ARDUINOJSON_DEBUG +#if ARDUINOJSON_DEBUG _ended = false; #endif } @@ -36,7 +36,7 @@ class Latch { void load() { ARDUINOJSON_ASSERT(!_ended); int c = _reader.read(); -#ifdef ARDUINOJSON_DEBUG +#if ARDUINOJSON_DEBUG if (c <= 0) _ended = true; #endif @@ -47,7 +47,7 @@ class Latch { TReader _reader; char _current; bool _loaded; -#ifdef ARDUINOJSON_DEBUG +#if ARDUINOJSON_DEBUG bool _ended; #endif }; diff --git a/src/ArduinoJson/Polyfills/assert.hpp b/src/ArduinoJson/Polyfills/assert.hpp index ea0647cd..33e73cf9 100644 --- a/src/ArduinoJson/Polyfills/assert.hpp +++ b/src/ArduinoJson/Polyfills/assert.hpp @@ -4,7 +4,9 @@ #pragma once -#ifdef ARDUINOJSON_DEBUG +#include + +#if ARDUINOJSON_DEBUG #include #define ARDUINOJSON_ASSERT(X) assert(X) #else