8000 Allow using PROGMEM outside of Arduino (fixes #1903) · smartcoder00/ArduinoJson@40daf56 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40daf56

Browse files
committed
Allow using PROGMEM outside of Arduino (fixes bblanchon#1903)
1 parent 31ce648 commit 40daf56

File tree

13 files changed

+23
-19
lines changed

13 files changed

+23
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ HEAD
55
----
66

77
* Fix compatibility with the Zephyr Project (issue #1905)
8+
* Allow using PROGMEM outside of Arduino (issue #1903)
89

910
v6.21.1 (2023-03-27)
1011
-------

extras/tests/Helpers/Arduino.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
#include "api/Print.h"
88
#include "api/Stream.h"
99
#include "api/String.h"
10+
#include "avr/pgmspace.h"
1011

12+
#define ARDUINO
1113
#define ARDUINO_H_INCLUDED 1

extras/tests/Helpers/progmem_emulation.hpp renamed to extras/tests/Helpers/avr/pgmspace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright © 2014-2023, Benoit BLANCHON
33
// MIT License
44

5+
#pragma once
6+
57
#include <stdint.h> // uint8_t
68

79
#define PROGMEM

extras/tests/Misc/StringAdapters.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
// Copyright © 2014-2023, Benoit BLANCHON
33
// MIT License
44

5-
#define ARDUINOJSON_ENABLE_PROGMEM 1
6-
7-
#include "custom_string.hpp"
8-
#include "progmem_emulation.hpp"
9-
#include "weird_strcmp.hpp"
5+
#include <Arduino.h>
106

117
#include <ArduinoJson/Strings/IsString.hpp>
128
#include <ArduinoJson/Strings/StringAdapters.hpp>
139

1410
#include <catch.hpp>
1511

12+
#include "custom_string.hpp"
13+
#include "weird_strcmp.hpp"
14+
1615
using namespace ArduinoJson::detail;
1716

1817
TEST_CASE("ZeroTerminatedRamString") {

extras/tests/Misc/StringWriter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
// Copyright © 2014-2023, Benoit BLANCHON
33
// MIT License
44

5-
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
5+
#include <Arduino.h>
6+
67
#define ARDUINOJSON_STRING_BUFFER_SIZE 5
78
#include <ArduinoJson.h>
9+
810
#include <catch.hpp>
11+
912
#include "custom_string.hpp"
1013

1114
using namespace ArduinoJson::detail;

extras/tests/MixedConfiguration/enable_progmem_1.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Copyright © 2014-2023, Benoit BLANCHON
33
// MIT License
44

5-
#include "progmem_emulation.hpp"
6-
75
#define ARDUINOJSON_ENABLE_PROGMEM 1
86
#include <ArduinoJson.h>
97

extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Copyright © 2014-2023, Benoit BLANCHON
33
// MIT License
44

5-
#include "progmem_emulation.hpp"
6-
75
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
86
#define ARDUINOJSON_ENABLE_PROGMEM 1
97
#define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 0

extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Copyright © 2014-2023, Benoit BLANCHON
33
// MIT License
44

5-
#include "progmem_emulation.hpp"
6-
75
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
86
#define ARDUINOJSON_ENABLE_PROGMEM 1
97
#define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1

extras/tests/MixedConfiguration/issue1707.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#define ARDUINO
66
#define memcpy_P(dest, src, n) memcpy((dest), (src), (n))
77

8-
#include "progmem_emulation.hpp"
9-
108
#include <ArduinoJson.h>
119

1210
#include <catch.hpp>

src/ArduinoJson.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
// Include Arduino.h before stdlib.h to avoid conflict with atexit()
1414
// https://github.com/bblanchon/ArduinoJson/pull/1693#issuecomment-1001060240
1515
#if ARDUINOJSON_ENABLE_ARDUINO_STRING || ARDUINOJSON_ENABLE_ARDUINO_STREAM || \
16-
ARDUINOJSON_ENABLE_ARDUINO_PRINT || ARDUINOJSON_ENABLE_PROGMEM
16+
ARDUINOJSON_ENABLE_ARDUINO_PRINT || \
17+
(ARDUINOJSON_ENABLE_PROGMEM && defined(ARDUINO))
1718
# include <Arduino.h>
1819
#endif
1920

src/ArduinoJson/Deserialization/Readers/FlashReader.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#pragma once
66

7-
#include <Arduino.h>
7+
#include <ArduinoJson/Polyfills/pgmspace.hpp>
88

99
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1010

src/ArduinoJson/Polyfills/pgmspace.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
#pragma once
66

7-
#include <Arduino.h>
7+
#ifdef ARDUINO
8+
# include <Arduino.h>
9+
#else
10+
// Allow using PROGMEM outside of Arduino (issue #1903)
11+
class __FlashStringHelper;
12+
# include <avr/pgmspace.h>
13+
#endif
814

915
#include <ArduinoJson/Configuration.hpp>
1016
#include <ArduinoJson/Namespace.hpp>

src/ArduinoJson/Strings/Adapters/FlashString.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#pragma once
66

7-
#include <Arduino.h>
8-
97
#include <ArduinoJson/Polyfills/pgmspace.hpp>
108
#include <ArduinoJson/Strings/StringAdapter.hpp>
119

0 commit comments

Comments
 (0)
0