mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Use pgm_read_dword() instead of pgm_read_float() (issue #1433)
				
					
				
			This commit is contained in:
		| @@ -27,10 +27,6 @@ inline void* pgm_read_ptr(const void* p) { | |||||||
|   return *reinterpret_cast<void* const*>(convertFlashToPtr(p)); |   return *reinterpret_cast<void* const*>(convertFlashToPtr(p)); | ||||||
| } | } | ||||||
|  |  | ||||||
| inline float pgm_read_float(const void* p) { |  | ||||||
|   return *reinterpret_cast<const float*>(convertFlashToPtr(p)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| #define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value)        \ | #define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value)        \ | ||||||
|   static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \ |   static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \ | ||||||
|   static type const* name = reinterpret_cast<type const*>(         \ |   static type const* name = reinterpret_cast<type const*>(         \ | ||||||
|   | |||||||
| @@ -50,6 +50,14 @@ TEST_CASE("Flash strings") { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | TEST_CASE("parseNumber()") {  // tables are in Flash | ||||||
|  |   using ARDUINOJSON_NAMESPACE::parseNumber; | ||||||
|  |  | ||||||
|  |   CHECK(parseNumber<float>("1") == 1.f); | ||||||
|  |   CHECK(parseNumber<float>("1.23") == 1.23f); | ||||||
|  |   CHECK(parseNumber<float>("-1.23e34") == -1.23e34f); | ||||||
|  | } | ||||||
|  |  | ||||||
| TEST_CASE("strlen_P") { | TEST_CASE("strlen_P") { | ||||||
|   CHECK(strlen_P(PSTR("")) == 0); |   CHECK(strlen_P(PSTR("")) == 0); | ||||||
|   CHECK(strlen_P(PSTR("a")) == 1); |   CHECK(strlen_P(PSTR("a")) == 1); | ||||||
|   | |||||||
| @@ -158,24 +158,42 @@ struct FloatTraits<T, 4 /*32bits*/> { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   static T positiveBinaryPowerOfTen(int index) { |   static T positiveBinaryPowerOfTen(int index) { | ||||||
|     ARDUINOJSON_DEFINE_STATIC_ARRAY( |     ARDUINOJSON_DEFINE_STATIC_ARRAY(uint32_t, factors, | ||||||
|         T, factors, |                                     ARDUINOJSON_EXPAND6({ | ||||||
|         ARDUINOJSON_EXPAND6({1e1f, 1e2f, 1e4f, 1e8f, 1e16f, 1e32f})); |                                         0x41200000,  // 1e1f | ||||||
|     return ARDUINOJSON_READ_STATIC_ARRAY(T, factors, index); |                                         0x42c80000,  // 1e2f | ||||||
|  |                                         0x461c4000,  // 1e4f | ||||||
|  |                                         0x4cbebc20,  // 1e8f | ||||||
|  |                                         0x5a0e1bca,  // 1e16f | ||||||
|  |                                         0x749dc5ae   // 1e32f | ||||||
|  |                                     })); | ||||||
|  |     return forge(ARDUINOJSON_READ_STATIC_ARRAY(uint32_t, factors, index)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   static T negativeBinaryPowerOfTen(int index) { |   static T negativeBinaryPowerOfTen(int index) { | ||||||
|     ARDUINOJSON_DEFINE_STATIC_ARRAY( |     ARDUINOJSON_DEFINE_STATIC_ARRAY(uint32_t, factors, | ||||||
|         T, factors, |                                     ARDUINOJSON_EXPAND6({ | ||||||
|         ARDUINOJSON_EXPAND6({1e-1f, 1e-2f, 1e-4f, 1e-8f, 1e-16f, 1e-32f})); |                                         0x3dcccccd,  // 1e-1f | ||||||
|     return ARDUINOJSON_READ_STATIC_ARRAY(T, factors, index); |                                         0x3c23d70a,  // 1e-2f | ||||||
|  |                                         0x38d1b717,  // 1e-4f | ||||||
|  |                                         0x322bcc77,  // 1e-8f | ||||||
|  |                                         0x24e69595,  // 1e-16f | ||||||
|  |                                         0x0a4fb11f   // 1e-32f | ||||||
|  |                                     })); | ||||||
|  |     return forge(ARDUINOJSON_READ_STATIC_ARRAY(uint32_t, factors, index)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   static T negativeBinaryPowerOfTenPlusOne(int index) { |   static T negativeBinaryPowerOfTenPlusOne(int index) { | ||||||
|     ARDUINOJSON_DEFINE_STATIC_ARRAY( |     ARDUINOJSON_DEFINE_STATIC_ARRAY(uint32_t, factors, | ||||||
|         T, factors, |                                     ARDUINOJSON_EXPAND6({ | ||||||
|         ARDUINOJSON_EXPAND6({1e0f, 1e-1f, 1e-3f, 1e-7f, 1e-15f, 1e-31f})); |                                         0x3f800000,  // 1e0f | ||||||
|     return ARDUINOJSON_READ_STATIC_ARRAY(T, factors, index); |                                         0x3dcccccd,  // 1e-1f | ||||||
|  |                                         0x3a83126f,  // 1e-3f | ||||||
|  |                                         0x33d6bf95,  // 1e-7f | ||||||
|  |                                         0x26901d7d,  // 1e-15f | ||||||
|  |                                         0x0c01ceb3   // 1e-31f | ||||||
|  |                                     })); | ||||||
|  |     return forge(ARDUINOJSON_READ_STATIC_ARRAY(uint32_t, factors, index)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   static T forge(uint32_t bits) { |   static T forge(uint32_t bits) { | ||||||
|   | |||||||
| @@ -15,15 +15,6 @@ typename enable_if<is_pointer<T>::value, T>::type pgm_read(const void* p) { | |||||||
|   return reinterpret_cast<T>(pgm_read_ptr(p)); |   return reinterpret_cast<T>(pgm_read_ptr(p)); | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> |  | ||||||
| typename enable_if<is_floating_point<T>::value && |  | ||||||
|                        sizeof(T) == sizeof(float),  // on AVR sizeof(double) == |  | ||||||
|                                                     // sizeof(float) |  | ||||||
|                    T>::type |  | ||||||
| pgm_read(const void* p) { |  | ||||||
|   return pgm_read_float(p); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| template <typename T> | template <typename T> | ||||||
| typename enable_if<is_same<T, uint32_t>::value, T>::type pgm_read( | typename enable_if<is_same<T, uint32_t>::value, T>::type pgm_read( | ||||||
|     const void* p) { |     const void* p) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user