Skip to content

Commit

Permalink
Deduce template argument of pgm_read()
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Jan 26, 2023
1 parent 1ec16ca commit 34b38e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/ArduinoJson/Deserialization/DeserializationError.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class DeserializationError : public SafeBoolIdom<DeserializationError> {
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(char, s5, "TooDeep");
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(
const char*, messages, ARDUINOJSON_EXPAND6({s0, s1, s2, s3, s4, s5}));
return pgm_read<const __FlashStringHelper*>(messages + _code);
return reinterpret_cast<const __FlashStringHelper*>(
pgm_read(messages + _code));
}
#endif

Expand Down
18 changes: 9 additions & 9 deletions src/ArduinoJson/Numbers/FloatTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ struct FloatTraits<T, 8 /*64bits*/> {
0x5A827748, 0xF9301D32, // 1e128
0x75154FDD, 0x7F73BF3C // 1e256
}));
return forge(pgm_read<uint32_t>(factors + 2 * index),
pgm_read<uint32_t>(factors + 2 * index + 1));
return forge(pgm_read(factors + 2 * index),
pgm_read(factors + 2 * index + 1));
}

static T negativeBinaryPowerOfTen(int index) {
Expand All @@ -80,8 +80,8 @@ struct FloatTraits<T, 8 /*64bits*/> {
0x255BBA08, 0xCF8C979D, // 1e-128
0x0AC80628, 0x64AC6F43 // 1e-256
}));
return forge(pgm_read<uint32_t>(factors + 2 * index),
pgm_read<uint32_t>(factors + 2 * index + 1));
return forge(pgm_read(factors + 2 * index),
pgm_read(factors + 2 * index + 1));
}

static T negativeBinaryPowerOfTenPlusOne(int index) {
Expand All @@ -98,8 +98,8 @@ struct FloatTraits<T, 8 /*64bits*/> {
0x25915445, 0x81B7DEC2, // 1e-127
0x0AFE07B2, 0x7DD78B14 // 1e-255
}));
return forge(pgm_read<uint32_t>(factors + 2 * index),
pgm_read<uint32_t>(factors + 2 * index + 1));
return forge(pgm_read(factors + 2 * index),
pgm_read(factors + 2 * index + 1));
}

static T nan() {
Expand Down Expand Up @@ -181,7 +181,7 @@ struct FloatTraits<T, 4 /*32bits*/> {
0x5a0e1bca, // 1e16f
0x749dc5ae // 1e32f
}));
return forge(pgm_read<uint32_t>(factors + index));
return forge(pgm_read(factors + index));
}

static T negativeBinaryPowerOfTen(int index) {
Expand All @@ -194,7 +194,7 @@ struct FloatTraits<T, 4 /*32bits*/> {
0x24e69595, // 1e-16f
0x0a4fb11f // 1e-32f
}));
return forge(pgm_read<uint32_t>(factors + index));
return forge(pgm_read(factors + index));
}

static T negativeBinaryPowerOfTenPlusOne(int index) {
Expand All @@ -207,7 +207,7 @@ struct FloatTraits<T, 4 /*32bits*/> {
0x26901d7d, // 1e-15f
0x0c01ceb3 // 1e-31f
}));
return forge(pgm_read<uint32_t>(factors + index));
return forge(pgm_read(factors + index));
}

static T forge(uint32_t bits) {
Expand Down
12 changes: 5 additions & 7 deletions src/ArduinoJson/Polyfills/pgmspace_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ namespace ARDUINOJSON_NAMESPACE {
# endif

template <typename T>
typename enable_if<is_pointer<T>::value, T>::type pgm_read(const void* p) {
return reinterpret_cast<T>(pgm_read_ptr(p));
inline const T* pgm_read(const T* const* p) {
return reinterpret_cast<const T*>(pgm_read_ptr(p));
}

template <typename T>
typename enable_if<is_same<T, uint32_t>::value, T>::type pgm_read(
const void* p) {
inline uint32_t pgm_read(const uint32_t* p) {
return pgm_read_dword(p);
}
#else
Expand All @@ -38,8 +36,8 @@ typename enable_if<is_same<T, uint32_t>::value, T>::type pgm_read(
# endif

template <typename T>
inline T pgm_read(const void* p) {
return *reinterpret_cast<const T*>(p);
inline T pgm_read(const T* p) {
return *p;
}

#endif
Expand Down

0 comments on commit 34b38e0

Please sign in to comment.