Просмотр исходного кода

Enabled debug mode when PlatformIO builds in debug

Benoit Blanchon 6 лет назад
Родитель
Сommit
5b812522fa

+ 1 - 1
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()

+ 1 - 1
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 \

+ 3 - 3
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"

+ 8 - 0
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

+ 3 - 3
src/ArduinoJson/Json/Latch.hpp

@@ -12,7 +12,7 @@ template <typename TReader>
 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
 };

+ 3 - 1
src/ArduinoJson/Polyfills/assert.hpp

@@ -4,7 +4,9 @@
 
 #pragma once
 
-#ifdef ARDUINOJSON_DEBUG
+#include <ArduinoJson/Configuration.hpp>
+
+#if ARDUINOJSON_DEBUG
 #include <assert.h>
 #define ARDUINOJSON_ASSERT(X) assert(X)
 #else