From 34b38e07c7836273e3730a9338bc4848ca9894a4 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 26 Jan 2023 18:10:41 +0100 Subject: [PATCH] Deduce template argument of `pgm_read()` --- .../Deserialization/DeserializationError.hpp | 3 ++- src/ArduinoJson/Numbers/FloatTraits.hpp | 18 +++++++++--------- src/ArduinoJson/Polyfills/pgmspace_generic.hpp | 12 +++++------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/ArduinoJson/Deserialization/DeserializationError.hpp b/src/ArduinoJson/Deserialization/DeserializationError.hpp index 9720096f..16c52ffd 100644 --- a/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -82,7 +82,8 @@ class DeserializationError : public SafeBoolIdom { 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(messages + _code); + return reinterpret_cast( + pgm_read(messages + _code)); } #endif diff --git a/src/ArduinoJson/Numbers/FloatTraits.hpp b/src/ArduinoJson/Numbers/FloatTraits.hpp index be15108d..08aa3d66 100644 --- a/src/ArduinoJson/Numbers/FloatTraits.hpp +++ b/src/ArduinoJson/Numbers/FloatTraits.hpp @@ -62,8 +62,8 @@ struct FloatTraits { 0x5A827748, 0xF9301D32, // 1e128 0x75154FDD, 0x7F73BF3C // 1e256 })); - return forge(pgm_read(factors + 2 * index), - pgm_read(factors + 2 * index + 1)); + return forge(pgm_read(factors + 2 * index), + pgm_read(factors + 2 * index + 1)); } static T negativeBinaryPowerOfTen(int index) { @@ -80,8 +80,8 @@ struct FloatTraits { 0x255BBA08, 0xCF8C979D, // 1e-128 0x0AC80628, 0x64AC6F43 // 1e-256 })); - return forge(pgm_read(factors + 2 * index), - pgm_read(factors + 2 * index + 1)); + return forge(pgm_read(factors + 2 * index), + pgm_read(factors + 2 * index + 1)); } static T negativeBinaryPowerOfTenPlusOne(int index) { @@ -98,8 +98,8 @@ struct FloatTraits { 0x25915445, 0x81B7DEC2, // 1e-127 0x0AFE07B2, 0x7DD78B14 // 1e-255 })); - return forge(pgm_read(factors + 2 * index), - pgm_read(factors + 2 * index + 1)); + return forge(pgm_read(factors + 2 * index), + pgm_read(factors + 2 * index + 1)); } static T nan() { @@ -181,7 +181,7 @@ struct FloatTraits { 0x5a0e1bca, // 1e16f 0x749dc5ae // 1e32f })); - return forge(pgm_read(factors + index)); + return forge(pgm_read(factors + index)); } static T negativeBinaryPowerOfTen(int index) { @@ -194,7 +194,7 @@ struct FloatTraits { 0x24e69595, // 1e-16f 0x0a4fb11f // 1e-32f })); - return forge(pgm_read(factors + index)); + return forge(pgm_read(factors + index)); } static T negativeBinaryPowerOfTenPlusOne(int index) { @@ -207,7 +207,7 @@ struct FloatTraits { 0x26901d7d, // 1e-15f 0x0c01ceb3 // 1e-31f })); - return forge(pgm_read(factors + index)); + return forge(pgm_read(factors + index)); } static T forge(uint32_t bits) { diff --git a/src/ArduinoJson/Polyfills/pgmspace_generic.hpp b/src/ArduinoJson/Polyfills/pgmspace_generic.hpp index 826827fb..106e0145 100644 --- a/src/ArduinoJson/Polyfills/pgmspace_generic.hpp +++ b/src/ArduinoJson/Polyfills/pgmspace_generic.hpp @@ -21,13 +21,11 @@ namespace ARDUINOJSON_NAMESPACE { # endif template -typename enable_if::value, T>::type pgm_read(const void* p) { - return reinterpret_cast(pgm_read_ptr(p)); +inline const T* pgm_read(const T* const* p) { + return reinterpret_cast(pgm_read_ptr(p)); } -template -typename enable_if::value, T>::type pgm_read( - const void* p) { +inline uint32_t pgm_read(const uint32_t* p) { return pgm_read_dword(p); } #else @@ -38,8 +36,8 @@ typename enable_if::value, T>::type pgm_read( # endif template -inline T pgm_read(const void* p) { - return *reinterpret_cast(p); +inline T pgm_read(const T* p) { + return *p; } #endif