diff --git a/CHANGELOG.md b/CHANGELOG.md index a6fa85ba..c3612675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ HEAD ---- * Fix compatibility with the Zephyr Project (issue #1905) +* Allow using PROGMEM outside of Arduino (issue #1903) v6.21.1 (2023-03-27) ------- diff --git a/extras/tests/Helpers/Arduino.h b/extras/tests/Helpers/Arduino.h index 5f6f3fe3..ef3640d9 100644 --- a/extras/tests/Helpers/Arduino.h +++ b/extras/tests/Helpers/Arduino.h @@ -7,5 +7,7 @@ #include "api/Print.h" #include "api/Stream.h" #include "api/String.h" +#include "avr/pgmspace.h" +#define ARDUINO #define ARDUINO_H_INCLUDED 1 diff --git a/extras/tests/Helpers/progmem_emulation.hpp b/extras/tests/Helpers/avr/pgmspace.h similarity index 98% rename from extras/tests/Helpers/progmem_emulation.hpp rename to extras/tests/Helpers/avr/pgmspace.h index ecb9f509..378065da 100644 --- a/extras/tests/Helpers/progmem_emulation.hpp +++ b/extras/tests/Helpers/avr/pgmspace.h @@ -2,6 +2,8 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License +#pragma once + #include // uint8_t #define PROGMEM diff --git a/extras/tests/Misc/StringAdapters.cpp b/extras/tests/Misc/StringAdapters.cpp index cc6d681b..1c77e08b 100644 --- a/extras/tests/Misc/StringAdapters.cpp +++ b/extras/tests/Misc/StringAdapters.cpp @@ -2,17 +2,16 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#define ARDUINOJSON_ENABLE_PROGMEM 1 - -#include "custom_string.hpp" -#include "progmem_emulation.hpp" -#include "weird_strcmp.hpp" +#include #include #include #include +#include "custom_string.hpp" +#include "weird_strcmp.hpp" + using namespace ArduinoJson::detail; TEST_CASE("ZeroTerminatedRamString") { diff --git a/extras/tests/Misc/StringWriter.cpp b/extras/tests/Misc/StringWriter.cpp index 3cc1333f..81cb88e9 100644 --- a/extras/tests/Misc/StringWriter.cpp +++ b/extras/tests/Misc/StringWriter.cpp @@ -2,10 +2,13 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 +#include + #define ARDUINOJSON_STRING_BUFFER_SIZE 5 #include + #include + #include "custom_string.hpp" using namespace ArduinoJson::detail; diff --git a/extras/tests/MixedConfiguration/enable_progmem_1.cpp b/extras/tests/MixedConfiguration/enable_progmem_1.cpp index 92a3cbf1..2cc683d7 100644 --- a/extras/tests/MixedConfiguration/enable_progmem_1.cpp +++ b/extras/tests/MixedConfiguration/enable_progmem_1.cpp @@ -2,8 +2,6 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#include "progmem_emulation.hpp" - #define ARDUINOJSON_ENABLE_PROGMEM 1 #include diff --git a/extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp b/extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp index d763eec1..7277af94 100644 --- a/extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp +++ b/extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp @@ -2,8 +2,6 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#include "progmem_emulation.hpp" - #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 #define ARDUINOJSON_ENABLE_PROGMEM 1 #define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 0 diff --git a/extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp b/extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp index a8388a96..d3b2285e 100644 --- a/extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp +++ b/extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp @@ -2,8 +2,6 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#include "progmem_emulation.hpp" - #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 #define ARDUINOJSON_ENABLE_PROGMEM 1 #define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1 diff --git a/extras/tests/MixedConfiguration/issue1707.cpp b/extras/tests/MixedConfiguration/issue1707.cpp index f3ab7f9f..f8ca566b 100644 --- a/extras/tests/MixedConfiguration/issue1707.cpp +++ b/extras/tests/MixedConfiguration/issue1707.cpp @@ -5,8 +5,6 @@ #define ARDUINO #define memcpy_P(dest, src, n) memcpy((dest), (src), (n)) -#include "progmem_emulation.hpp" - #include #include diff --git a/src/ArduinoJson.hpp b/src/ArduinoJson.hpp index 0c8832a1..2d1b0be1 100644 --- a/src/ArduinoJson.hpp +++ b/src/ArduinoJson.hpp @@ -13,7 +13,8 @@ // Include Arduino.h before stdlib.h to avoid conflict with atexit() // https://github.com/bblanchon/ArduinoJson/pull/1693#issuecomment-1001060240 #if ARDUINOJSON_ENABLE_ARDUINO_STRING || ARDUINOJSON_ENABLE_ARDUINO_STREAM || \ - ARDUINOJSON_ENABLE_ARDUINO_PRINT || ARDUINOJSON_ENABLE_PROGMEM + ARDUINOJSON_ENABLE_ARDUINO_PRINT || \ + (ARDUINOJSON_ENABLE_PROGMEM && defined(ARDUINO)) # include #endif diff --git a/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp b/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp index df2314ef..97714afb 100644 --- a/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp +++ b/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp @@ -4,7 +4,7 @@ #pragma once -#include +#include ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE diff --git a/src/ArduinoJson/Polyfills/pgmspace.hpp b/src/ArduinoJson/Polyfills/pgmspace.hpp index 03adc6f1..9e66f96a 100644 --- a/src/ArduinoJson/Polyfills/pgmspace.hpp +++ b/src/ArduinoJson/Polyfills/pgmspace.hpp @@ -4,7 +4,13 @@ #pragma once -#include +#ifdef ARDUINO +# include +#else +// Allow using PROGMEM outside of Arduino (issue #1903) +class __FlashStringHelper; +# include +#endif #include #include diff --git a/src/ArduinoJson/Strings/Adapters/FlashString.hpp b/src/ArduinoJson/Strings/Adapters/FlashString.hpp index eaffe7e3..4989315a 100644 --- a/src/ArduinoJson/Strings/Adapters/FlashString.hpp +++ b/src/ArduinoJson/Strings/Adapters/FlashString.hpp @@ -4,8 +4,6 @@ #pragma once -#include - #include #include