8000 Replace `ARDUINOJSON_EXPANDX` with variadic macros (#1820) · smartcoder00/ArduinoJson@0f8698e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f8698e

Browse files
committed
Replace ARDUINOJSON_EXPANDX with variadic macros (#1820)
1 parent b2b995e commit 0f8698e

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

extras/tests/Helpers/progmem_emulation.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ inline uint8_t pgm_read_byte(const void* p) {
2323
return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p));
2424
}
2525

26-
#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
27-
static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \
28-
static type const* name = reinterpret_cast<type const*>( \
26+
#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, ...) \
27+
static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = __VA_ARGS__; \
28+
static type const* name = reinterpret_cast<type const*>( \
2929
convertPtrToFlash(ARDUINOJSON_CONCAT2(name, _progmem)));

src/ArduinoJson/Deserialization/DeserializationError.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class DeserializationError {
7979
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s3, "InvalidInput");
8080
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s4, "NoMemory");
8181
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s5, "TooDeep");
82-
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(
83-
const char*, messages, ARDUINOJSON_EXPAND6({s0, s1, s2, s3, s4, s5}));
82+
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(const char*, messages,
83+
{s0, s1, s2, s3, s4, s5});
8484
return reinterpret_cast<const __FlashStringHelper*>(
8585
detail::pgm_read(messages + _code));
8686
}

src/ArduinoJson/Numbers/FloatTraits.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct FloatTraits<T, 8 /*64bits*/> {
5151
static T positiveBinaryPowerOfTen(int index) {
5252
ARDUINOJSON_DEFINE_PROGMEM_ARRAY( //
5353
uint32_t, factors,
54-
ARDUINOJSON_EXPAND18({
54+
{
5555
0x40240000, 0x00000000, // 1e1
5656
0x40590000, 0x00000000, // 1e2
5757
0x40C38800, 0x00000000, // 1e4
@@ -61,15 +61,15 @@ struct FloatTraits<T, 8 /*64bits*/> {
6161
0x4D384F03, 0xE93FF9F5, // 1e64
6262
0x5A827748, 0xF9301D32, // 1e128
6363
0x75154FDD, 0x7F73BF3C // 1e256
64-
}));
64+
});
6565
return forge(pgm_read(factors + 2 * index),
6666
pgm_read(factors + 2 * index + 1));
6767
}
6868

6969
static T negativeBinaryPowerOfTen(int index) {
7070
ARDUINOJSON_DEFINE_PROGMEM_ARRAY( //
7171
uint32_t, factors,
72-
ARDUINOJSON_EXPAND18({
72+
{
7373
0x3FB99999, 0x9999999A, // 1e-1
7474
0x3F847AE1, 0x47AE147B, // 1e-2
7575
0x3F1A36E2, 0xEB1C432D, // 1e-4
@@ -79,15 +79,15 @@ struct FloatTraits<T, 8 /*64bits*/> {
7979
0x32A50FFD, 0x44F4A73D, // 1e-64
8080
0x255BBA08, 0xCF8C979D, // 1e-128
8181
0x0AC80628, 0x64AC6F43 // 1e-256
82-
}));
82+
});
8383
return forge(pgm_read(factors + 2 * index),
8484
pgm_read(factors + 2 * index + 1));
8585
}
8686

8787
static T negativeBinaryPowerOfTenPlusOne(int index) {
8888
ARDUINOJSON_DEFINE_PROGMEM_ARRAY( //
8989
uint32_t, factors,
90-
ARDUINOJSON_EXPAND18({
90+
{
9191
0x3FF00000, 0x00000000, // 1e0
9292
0x3FB99999, 0x9999999A, // 1e-1
9393
0x3F50624D, 0xD2F1A9FC, // 1e-3
@@ -97,7 +97,7 @@ struct FloatTraits<T, 8 /*64bits*/> {
9797
0x32DA53FC, 0x9631D10D, // 1e-63
9898
0x25915445, 0x81B7DEC2, // 1e-127
9999
0x0AFE07B2, 0x7DD78B14 // 1e-255
100-
}));
100+
});
101101
return forge(pgm_read(factors + 2 * index),
102102
pgm_read(factors + 2 * index + 1));
103103
}
@@ -173,40 +173,40 @@ struct FloatTraits<T, 4 /*32bits*/> {
173173

174174
static T positiveBinaryPowerOfTen(int index) {
175175
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(uint32_t, factors,
176-
ARDUINOJSON_EXPAND6({
176+
{
177177
0x41200000, // 1e1f
178178
0x42c80000, // 1e2f
179179
0x461c4000, // 1e4f
180180
0x4cbebc20, // 1e8f
181181
0x5a0e1bca, // 1e16f
182182
0x749dc5ae // 1e32f
183-
}));
183+
});
184184
return forge(pgm_read(factors + index));
185185
}
186186

187187
static T negativeBinaryPowerOfTen(int index) {
188188
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(uint32_t, factors,
189-
ARDUINOJSON_EXPAND6({
189+
{
190190
0x3dcccccd, // 1e-1f
191191
0x3c23d70a, // 1e-2f
192192
0x38d1b717, // 1e-4f
193193
0x322bcc77, // 1e-8f
194194
0x24e69595, // 1e-16f
195195
0x0a4fb11f // 1e-32f
196-
}));
196+
});
197197
return forge(pgm_read(factors + index));
198198
}
199199

200200
static T negativeBinaryPowerOfTenPlusOne(int index) {
201201
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(uint32_t, factors,
202-
ARDUINOJSON_EXPAND6({
202+
{
203203
0x3f800000, // 1e0f
204204
0x3dcccccd, // 1e-1f
205205
0x3a83126f, // 1e-3f
206206
0x33d6bf95, // 1e-7f
207207
0x26901d7d, // 1e-15f
208208
0x0c01ceb3 // 1e-31f
209-
}));
209+
});
210210
return forge(pgm_read(factors + index));
211211
}
212212

src/ArduinoJson/Polyfills/pgmspace_generic.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
1616
#if ARDUINOJSON_ENABLE_PROGMEM
1717

1818
# ifndef ARDUINOJSON_DEFINE_PROGMEM_ARRAY
19-
# define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
20-
static type const name[] PROGMEM = value;
19+
# define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, ...) \
20+
static type const name[] PROGMEM = __VA_ARGS__;
2121
# endif
2222

2323
template <typename T>
@@ -31,8 +31,8 @@ inline uint32_t pgm_read(const uint32_t* p) {
3131
#else
3232

3333
# ifndef ARDUINOJSON_DEFINE_PROGMEM_ARRAY
34-
# define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
35-
static type const name[] = value;
34+
# define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, ...) \
35+
static type const name[] = __VA_ARGS__;
3636
# endif
3737

3838
template <typename T>

src/ArduinoJson/Polyfills/preprocessor.hpp

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

55
#pragma once
66

7-
#define ARDUINOJSON_EXPAND6(a, b, c, d, e, f) a, b, c, d, e, f
8-
#define ARDUINOJSON_EXPAND9(a, b, c, d, e, f, g, h, i) a, b, c, d, e, f, g, h, i
9-
#define ARDUINOJSON_EXPAND18(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, \
10-
q, r) \
11-
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r
12-
137
#define ARDUINOJSON_CONCAT_(A, B) A##B
148
#define ARDUINOJSON_CONCAT2(A, B) ARDUINOJSON_CONCAT_(A, B)
159
#define ARDUINOJSON_CONCAT3(A, B, C) \

0 commit comments

Comments
 (0)
0