From 7046c38c843a2aa2fd23ca681cefc5597d7b1e78 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 18 Oct 2021 15:24:45 +0200 Subject: [PATCH] Remove `ARDUINOJSON_EMBEDDED_MODE` --- .github/workflows/ci.yml | 6 +- CHANGELOG.md | 6 + CMakeLists.txt | 1 - extras/conf_test/x86-windows.cpp | 15 -- extras/conf_test/{x86-linux.cpp => x86.cpp} | 4 +- src/ArduinoJson/Configuration.hpp | 148 +++++++------------- 6 files changed, 63 insertions(+), 117 deletions(-) delete mode 100644 extras/conf_test/x86-windows.cpp rename extras/conf_test/{x86-linux.cpp => x86.cpp} (75%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8c4c890..f9e89c25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -135,11 +135,11 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: GCC 32-bit - run: g++ -std=c++11 -m32 -Isrc extras/conf_test/x86-linux.cpp + run: g++ -std=c++11 -m32 -Isrc extras/conf_test/x86.cpp - name: GCC 64-bit run: g++ -std=c++11 -m64 -Isrc extras/conf_test/x64.cpp - name: Clang 32-bit - run: clang++ -std=c++11 -m32 -Isrc extras/conf_test/x86-linux.cpp + run: clang++ -std=c++11 -m32 -Isrc extras/conf_test/x86.cpp - name: Clang 64-bit run: clang++ -std=c++11 -m64 -Isrc extras/conf_test/x64.cpp @@ -153,7 +153,7 @@ jobs: - name: 32-bit run: | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat" - cl /Isrc extras/conf_test/x86-windows.cpp + cl /Isrc extras/conf_test/x86.cpp shell: cmd - name: 64-bit run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d910d2f..e3e460e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Remove `ARDUINOJSON_EMBEDDED_MODE` and assume we run on an embedded platform. + Dependent settings (like `ARDUINOJSON_DEFAULT_NESTING_LIMIT`) must be set individually. + v6.18.5 (2021-09-28) ------- diff --git a/CMakeLists.txt b/CMakeLists.txt index b14cb0ee..a01e73d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ cmake_minimum_required(VERSION 3.3) if(ESP_PLATFORM) # Build ArduinoJson as an ESP-IDF component idf_component_register(INCLUDE_DIRS src) - target_compile_definitions(${COMPONENT_LIB} INTERFACE ARDUINOJSON_EMBEDDED_MODE=1) return() endif() diff --git a/extras/conf_test/x86-windows.cpp b/extras/conf_test/x86-windows.cpp deleted file mode 100644 index 15360417..00000000 --- a/extras/conf_test/x86-windows.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG"); - -static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 4, - "ARDUINOJSON_SLOT_OFFSET_SIZE"); - -static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); - -static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); - -static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 24, - "sizeof(VariantSlot)"); - -int main() {} diff --git a/extras/conf_test/x86-linux.cpp b/extras/conf_test/x86.cpp similarity index 75% rename from extras/conf_test/x86-linux.cpp rename to extras/conf_test/x86.cpp index 78ab6cc0..dab9da61 100644 --- a/extras/conf_test/x86-linux.cpp +++ b/extras/conf_test/x86.cpp @@ -2,14 +2,14 @@ static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG"); -static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 4, +static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 2, "ARDUINOJSON_SLOT_OFFSET_SIZE"); static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); -static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 20, +static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 16, "sizeof(VariantSlot)"); int main() {} diff --git a/src/ArduinoJson/Configuration.hpp b/src/ArduinoJson/Configuration.hpp index 8e2c7d81..12c177ea 100644 --- a/src/ArduinoJson/Configuration.hpp +++ b/src/ArduinoJson/Configuration.hpp @@ -26,130 +26,86 @@ # define ARDUINOJSON_HAS_INT64 0 #endif -// Small or big machine? -#ifndef ARDUINOJSON_EMBEDDED_MODE -# if defined(ARDUINO) /* Arduino*/ \ - || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \ - || defined(__XC) /* MPLAB XC compiler */ \ - || defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \ - || defined(__NIOS2__) /* Altera Nios II EDS */ \ - || defined(__AVR) /* Atmel AVR8/GNU C Compiler */ -# define ARDUINOJSON_EMBEDDED_MODE 1 -# else -# define ARDUINOJSON_EMBEDDED_MODE 0 -# endif -#endif - -// Auto enable std::stream if the right headers are here and no conflicting -// macro is defined -#if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include) -# if __has_include() && \ +// Support std::istream and std::ostream +#ifndef ARDUINOJSON_ENABLE_STD_STREAM +# ifdef __has_include +# if __has_include() && \ __has_include() && \ !defined(min) && \ !defined(max) -# define ARDUINOJSON_ENABLE_STD_STREAM 1 +# define ARDUINOJSON_ENABLE_STD_STREAM 1 +# else +# define ARDUINOJSON_ENABLE_STD_STREAM 0 +# endif # else -# define ARDUINOJSON_ENABLE_STD_STREAM 0 +# ifdef ARDUINO +# define ARDUINOJSON_ENABLE_STD_STREAM 0 +# else +# define ARDUINOJSON_ENABLE_STD_STREAM 1 +# endif # endif #endif -// Auto enable std::string if the right header is here and no conflicting -// macro is defined -#if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include) -# if __has_include() && !defined(min) && !defined(max) -# define ARDUINOJSON_ENABLE_STD_STRING 1 +// Support std::string +#ifndef ARDUINOJSON_ENABLE_STD_STRING +# ifdef __has_include +# if __has_include() && !defined(min) && !defined(max) +# define ARDUINOJSON_ENABLE_STD_STRING 1 +# else +# define ARDUINOJSON_ENABLE_STD_STRING 0 +# endif # else -# define ARDUINOJSON_ENABLE_STD_STRING 0 +# ifdef ARDUINO +# define ARDUINOJSON_ENABLE_STD_STRING 0 +# else +# define ARDUINOJSON_ENABLE_STD_STRING 1 +# endif # endif #endif +// Support for std::string_view #ifndef ARDUINOJSON_ENABLE_STRING_VIEW # ifdef __has_include # if __has_include() && __cplusplus >= 201703L # define ARDUINOJSON_ENABLE_STRING_VIEW 1 +# else +# define ARDUINOJSON_ENABLE_STRING_VIEW 0 # endif +# else +# define ARDUINOJSON_ENABLE_STRING_VIEW 0 # endif #endif -#ifndef ARDUINOJSON_ENABLE_STRING_VIEW -# define ARDUINOJSON_ENABLE_STRING_VIEW 0 + +// Store floating-point values with float (0) or double (1) +#ifndef ARDUINOJSON_USE_DOUBLE +# define ARDUINOJSON_USE_DOUBLE 0 #endif -#if ARDUINOJSON_EMBEDDED_MODE - -// Store floats by default to reduce the memory usage (issue #134) -# ifndef ARDUINOJSON_USE_DOUBLE -# define ARDUINOJSON_USE_DOUBLE 0 -# endif - -// Store longs by default, because they usually match the size of a float. -# ifndef ARDUINOJSON_USE_LONG_LONG -# define ARDUINOJSON_USE_LONG_LONG 0 -# endif - -// Embedded systems usually don't have std::string -# ifndef ARDUINOJSON_ENABLE_STD_STRING -# define ARDUINOJSON_ENABLE_STD_STRING 0 -# endif - -// Embedded systems usually don't have std::stream -# ifndef ARDUINOJSON_ENABLE_STD_STREAM -# define ARDUINOJSON_ENABLE_STD_STREAM 0 -# endif +// Store integral values with long (0) or long long (1) +#ifndef ARDUINOJSON_USE_LONG_LONG +# define ARDUINOJSON_USE_LONG_LONG 0 +#endif // Limit nesting as the stack is likely to be small -# ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT -# define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 -# endif +#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT +# define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 +#endif // Number of bits to store the pointer to next node // (saves RAM but limits the number of values in a document) -# ifndef ARDUINOJSON_SLOT_OFFSET_SIZE -# if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 2 +#ifndef ARDUINOJSON_SLOT_OFFSET_SIZE +# if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ <= 2 // Address space == 16-bit => max 127 values -# define ARDUINOJSON_SLOT_OFFSET_SIZE 1 -# else -// Address space > 16-bit => max 32767 values -# define ARDUINOJSON_SLOT_OFFSET_SIZE 2 -# endif -# endif - -#else // ARDUINOJSON_EMBEDDED_MODE - -// On a computer we have plenty of memory so we can use doubles -# ifndef ARDUINOJSON_USE_DOUBLE -# define ARDUINOJSON_USE_DOUBLE 1 -# endif - -// Use long long when available -# ifndef ARDUINOJSON_USE_LONG_LONG -# if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 -# define ARDUINOJSON_USE_LONG_LONG 1 -# else -# define ARDUINOJSON_USE_LONG_LONG 0 -# endif -# endif - -// On a computer, we can use std::string -# ifndef ARDUINOJSON_ENABLE_STD_STRING -# define ARDUINOJSON_ENABLE_STD_STRING 1 -# endif - -// On a computer, we can assume std::stream -# ifndef ARDUINOJSON_ENABLE_STD_STREAM -# define ARDUINOJSON_ENABLE_STD_STREAM 1 -# endif - -// On a computer, the stack is large so we can increase nesting limit -# ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT -# define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 -# endif - -// Number of bits to store the pointer to next node -# ifndef ARDUINOJSON_SLOT_OFFSET_SIZE +# define ARDUINOJSON_SLOT_OFFSET_SIZE 1 +# elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ >= 8 || \ + defined(_WIN64) && _WIN64 +// Address space == 64-bit => max 2147483647 values # define ARDUINOJSON_SLOT_OFFSET_SIZE 4 +# else +// Address space == 32-bit => max 32767 values +# define ARDUINOJSON_SLOT_OFFSET_SIZE 2 # endif - -#endif // ARDUINOJSON_EMBEDDED_MODE +#endif #ifdef ARDUINO