From 954428e34177a7500392811ec07537dc33099d93 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Wed, 4 Jul 2018 12:07:03 +0200 Subject: [PATCH 1/6] Improved float serialization when `-fsingle-precision-constant` is used --- CHANGELOG.md | 5 +++ src/ArduinoJson/TypeTraits/FloatTraits.hpp | 45 ++++++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e512038..c73313e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Improved float serialization when `-fsingle-precision-constant` is used + v5.13.2 ------- diff --git a/src/ArduinoJson/TypeTraits/FloatTraits.hpp b/src/ArduinoJson/TypeTraits/FloatTraits.hpp index 5044807a..648cc82f 100644 --- a/src/ArduinoJson/TypeTraits/FloatTraits.hpp +++ b/src/ArduinoJson/TypeTraits/FloatTraits.hpp @@ -44,28 +44,46 @@ struct FloatTraits { static T positiveBinaryPowerOfTen(int index) { static T factors[] = { - 1e1, 1e2, 1e4, 1e8, 1e16, 1e32, - // workaround to support platforms with single precision literals - forge(0x4D384F03, 0xE93FF9F5), forge(0x5A827748, 0xF9301D32), - forge(0x75154FDD, 0x7F73BF3C)}; + 1e1, + 1e2, + 1e4, + 1e8, + 1e16, + forge(0x4693B8B5, 0xB5056E17), // 1e32 + forge(0x4D384F03, 0xE93FF9F5), // 1e64 + forge(0x5A827748, 0xF9301D32), // 1e128 + forge(0x75154FDD, 0x7F73BF3C) // 1e256 + }; return factors[index]; } static T negativeBinaryPowerOfTen(int index) { static T factors[] = { - 1e-1, 1e-2, 1e-4, 1e-8, 1e-16, 1e-32, - // workaround to support platforms with single precision literals - forge(0x32A50FFD, 0x44F4A73D), forge(0x255BBA08, 0xCF8C979D), - forge(0x0AC80628, 0x64AC6F43)}; + forge(0x3FB99999, 0x9999999A), // 1e-1 + forge(0x3F847AE1, 0x47AE147B), // 1e-2 + forge(0x3F1A36E2, 0xEB1C432D), // 1e-4 + forge(0x3E45798E, 0xE2308C3A), // 1e-8 + forge(0x3C9CD2B2, 0x97D889BC), // 1e-16 + forge(0x3949F623, 0xD5A8A733), // 1e-32 + forge(0x32A50FFD, 0x44F4A73D), // 1e-64 + forge(0x255BBA08, 0xCF8C979D), // 1e-128 + forge(0x0AC80628, 0x64AC6F43) // 1e-256 + }; return factors[index]; } static T negativeBinaryPowerOfTenPlusOne(int index) { static T factors[] = { - 1e0, 1e-1, 1e-3, 1e-7, 1e-15, 1e-31, - // workaround to support platforms with single precision literals - forge(0x32DA53FC, 0x9631D10D), forge(0x25915445, 0x81B7DEC2), - forge(0x0AFE07B2, 0x7DD78B14)}; + 1e0, + forge(0x3FB99999, 0x9999999A), // 1e-1 + forge(0x3F50624D, 0xD2F1A9FC), // 1e-3 + forge(0x3E7AD7F2, 0x9ABCAF48), // 1e-7 + forge(0x3CD203AF, 0x9EE75616), // 1e-15 + forge(0x398039D6, 0x65896880), // 1e-31 + forge(0x32DA53FC, 0x9631D10D), // 1e-63 + forge(0x25915445, 0x81B7DEC2), // 1e-127 + forge(0x0AFE07B2, 0x7DD78B14) // 1e-255 + }; return factors[index]; } @@ -77,6 +95,9 @@ struct FloatTraits { return forge(0x7ff00000, 0x00000000); } + // constructs a double floating point values from its binary representation + // we use this function to workaround platforms with single precision literals + // (for example, when -fsingle-precision-constant is passed to GCC) static T forge(uint32_t msb, uint32_t lsb) { union { uint64_t integerBits; From fa1a40ac6e63c18583540806d4fc63297ab5f99e Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 5 Jul 2018 09:53:11 +0200 Subject: [PATCH 2/6] Fixed `JsonVariant::is()` that returned true for empty strings --- CHANGELOG.md | 1 + src/ArduinoJson/Polyfills/isInteger.hpp | 6 +++--- test/Polyfills/isInteger.cpp | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c73313e0..feb2b888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ HEAD ---- * Improved float serialization when `-fsingle-precision-constant` is used +* Fixed `JsonVariant::is()` that returned true for empty strings v5.13.2 ------- diff --git a/src/ArduinoJson/Polyfills/isInteger.hpp b/src/ArduinoJson/Polyfills/isInteger.hpp index 21f16689..8049079a 100644 --- a/src/ArduinoJson/Polyfills/isInteger.hpp +++ b/src/ArduinoJson/Polyfills/isInteger.hpp @@ -10,10 +10,10 @@ namespace ArduinoJson { namespace Internals { inline bool isInteger(const char* s) { - if (!s) return false; + if (!s || !*s) return false; if (issign(*s)) s++; while (isdigit(*s)) s++; return *s == '\0'; } -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/test/Polyfills/isInteger.cpp b/test/Polyfills/isInteger.cpp index f0bec4ae..ec6d020d 100644 --- a/test/Polyfills/isInteger.cpp +++ b/test/Polyfills/isInteger.cpp @@ -12,6 +12,10 @@ TEST_CASE("isInteger()") { REQUIRE_FALSE(isInteger(NULL)); } + SECTION("Empty String") { + REQUIRE_FALSE(isInteger("")); + } + SECTION("FloatNotInteger") { REQUIRE_FALSE(isInteger("3.14")); REQUIRE_FALSE(isInteger("-3.14")); From 0b3af166ae069d8c29dd25b49bc7b738a28f02f9 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 6 Oct 2018 17:20:28 +0200 Subject: [PATCH 3/6] Fixed `JsonVariant::is()` (closes #763) --- CHANGELOG.md | 1 + src/ArduinoJson/JsonVariant.hpp | 6 ++++-- test/JsonVariant/is.cpp | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index feb2b888..4c11d228 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ HEAD * Improved float serialization when `-fsingle-precision-constant` is used * Fixed `JsonVariant::is()` that returned true for empty strings +* Fixed `JsonVariant::is()` (closes #763) v5.13.2 ------- diff --git a/src/ArduinoJson/JsonVariant.hpp b/src/ArduinoJson/JsonVariant.hpp index 8326cbe8..43c51b77 100644 --- a/src/ArduinoJson/JsonVariant.hpp +++ b/src/ArduinoJson/JsonVariant.hpp @@ -274,9 +274,11 @@ class JsonVariant : public Internals::JsonVariantBase { // // bool is() const; // bool is() const; + // bool is() const; template typename Internals::EnableIf::value || - Internals::IsSame::value, + Internals::IsSame::value || + Internals::StringTraits::has_append, bool>::type is() const { return variantIsString(); @@ -352,4 +354,4 @@ DEPRECATED("Decimal places are ignored, use the double value instead") inline JsonVariant double_with_n_digits(double value, uint8_t) { return JsonVariant(value); } -} +} // namespace ArduinoJson diff --git a/test/JsonVariant/is.cpp b/test/JsonVariant/is.cpp index 1bb03cbb..c9837e2f 100644 --- a/test/JsonVariant/is.cpp +++ b/test/JsonVariant/is.cpp @@ -58,6 +58,7 @@ void checkIsInteger(JsonVariant var) { void checkIsString(JsonVariant var) { REQUIRE(var.is()); + REQUIRE(var.is()); REQUIRE_FALSE(var.is()); REQUIRE_FALSE(var.is()); From ce607196d14ccf6f22c39a91d7b5a0a57eae5829 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 6 Oct 2018 17:24:54 +0200 Subject: [PATCH 4/6] Travis: update osx images --- .travis.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13ddd354..a78ae840 100644 --- a/.travis.yml +++ b/.travis.yml @@ -103,11 +103,19 @@ matrix: - compiler: gcc env: SCRIPT=coverage - os: osx - osx_image: xcode6.4 + osx_image: xcode7.3 compiler: clang env: SCRIPT=cmake - os: osx - osx_image: xcode7.3 + osx_image: xcode8.3 + compiler: clang + env: SCRIPT=cmake + - os: osx + osx_image: xcode9.4 + compiler: clang + env: SCRIPT=cmake + - os: osx + osx_image: xcode10 compiler: clang env: SCRIPT=cmake SANITIZE=address - env: SCRIPT=arduino VERSION=1.6.7 BOARD=arduino:avr:uno From 3ca40db9f828576f536f8b1f74ecb38246cae8e9 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 6 Oct 2018 17:42:01 +0200 Subject: [PATCH 5/6] Added a coupon code for the book --- examples/JsonConfigFile/JsonConfigFile.ino | 6 +++--- examples/JsonGeneratorExample/JsonGeneratorExample.ino | 6 +++--- examples/JsonHttpClient/JsonHttpClient.ino | 6 +++--- examples/JsonParserExample/JsonParserExample.ino | 6 +++--- examples/JsonServer/JsonServer.ino | 6 +++--- examples/JsonUdpBeacon/JsonUdpBeacon.ino | 6 +++--- examples/ProgmemExample/ProgmemExample.ino | 6 +++--- examples/StringExample/StringExample.ino | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/JsonConfigFile/JsonConfigFile.ino b/examples/JsonConfigFile/JsonConfigFile.ino index ce6dca3e..2ccf7d67 100644 --- a/examples/JsonConfigFile/JsonConfigFile.ino +++ b/examples/JsonConfigFile/JsonConfigFile.ino @@ -133,12 +133,12 @@ void loop() { // See also // -------- // -// The website arduinojson.org contains the documentation for all the functions +// https://arduinojson.org/ contains the documentation for all the functions // used above. It also includes an FAQ that will help you solve any // serialization or deserialization problem. -// Please check it out at: https://arduinojson.org/ // // The book "Mastering ArduinoJson" contains a case study of a project that has // a complex configuration with nested members. // Contrary to this example, the project in the book uses the SPIFFS filesystem. -// Please check it out at: https://arduinojson.org/book/ \ No newline at end of file +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/examples/JsonGeneratorExample/JsonGeneratorExample.ino b/examples/JsonGeneratorExample/JsonGeneratorExample.ino index fad41ef2..07e05fab 100644 --- a/examples/JsonGeneratorExample/JsonGeneratorExample.ino +++ b/examples/JsonGeneratorExample/JsonGeneratorExample.ino @@ -70,12 +70,12 @@ void loop() { // See also // -------- // -// The website arduinojson.org contains the documentation for all the functions +// https://arduinojson.org/ contains the documentation for all the functions // used above. It also includes an FAQ that will help you solve any // serialization problem. -// Please check it out at: https://arduinojson.org/ // // The book "Mastering ArduinoJson" contains a tutorial on serialization. // It begins with a simple example, like the one above, and then adds more // features like serializing directly to a file or an HTTP request. -// Please check it out at: https://arduinojson.org/book/ \ No newline at end of file +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/examples/JsonHttpClient/JsonHttpClient.ino b/examples/JsonHttpClient/JsonHttpClient.ino index 6e5c05ef..4ce1c20d 100644 --- a/examples/JsonHttpClient/JsonHttpClient.ino +++ b/examples/JsonHttpClient/JsonHttpClient.ino @@ -100,13 +100,13 @@ void loop() { // See also // -------- // -// The website arduinojson.org contains the documentation for all the functions +// https://arduinojson.org/ contains the documentation for all the functions // used above. It also includes an FAQ that will help you solve any // serialization problem. -// Please check it out at: https://arduinojson.org/ // // The book "Mastering ArduinoJson" contains a tutorial on deserialization // showing how to parse the response from Yahoo Weather. In the last chapter, // it shows how to parse the huge documents from OpenWeatherMap // and Weather Underground. -// Please check it out at: https://arduinojson.org/book/ \ No newline at end of file +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/examples/JsonParserExample/JsonParserExample.ino b/examples/JsonParserExample/JsonParserExample.ino index a9b3ee91..57529963 100644 --- a/examples/JsonParserExample/JsonParserExample.ino +++ b/examples/JsonParserExample/JsonParserExample.ino @@ -67,12 +67,12 @@ void loop() { // See also // -------- // -// The website arduinojson.org contains the documentation for all the functions +// https://arduinojson.org/ contains the documentation for all the functions // used above. It also includes an FAQ that will help you solve any // deserialization problem. -// Please check it out at: https://arduinojson.org/ // // The book "Mastering ArduinoJson" contains a tutorial on deserialization. // It begins with a simple example, like the one above, and then adds more // features like deserializing directly from a file or an HTTP request. -// Please check it out at: https://arduinojson.org/book/ \ No newline at end of file +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/examples/JsonServer/JsonServer.ino b/examples/JsonServer/JsonServer.ino index 229e289a..e693ae17 100644 --- a/examples/JsonServer/JsonServer.ino +++ b/examples/JsonServer/JsonServer.ino @@ -98,12 +98,12 @@ void loop() { // See also // -------- // -// The website arduinojson.org contains the documentation for all the functions +// https://arduinojson.org/ contains the documentation for all the functions // used above. It also includes an FAQ that will help you solve any // serialization problem. -// Please check it out at: https://arduinojson.org/ // // The book "Mastering ArduinoJson" contains a tutorial on serialization. // It begins with a simple example, then adds more features like serializing // directly to a file or an HTTP client. -// Please check it out at: https://arduinojson.org/book/ \ No newline at end of file +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/examples/JsonUdpBeacon/JsonUdpBeacon.ino b/examples/JsonUdpBeacon/JsonUdpBeacon.ino index eb9f19a6..b2328a62 100644 --- a/examples/JsonUdpBeacon/JsonUdpBeacon.ino +++ b/examples/JsonUdpBeacon/JsonUdpBeacon.ino @@ -90,12 +90,12 @@ void loop() { // See also // -------- // -// The website arduinojson.org contains the documentation for all the functions +// https://arduinojson.org/ contains the documentation for all the functions // used above. It also includes an FAQ that will help you solve any // serialization problem. -// Please check it out at: https://arduinojson.org/ // // The book "Mastering ArduinoJson" contains a tutorial on serialization. // It begins with a simple example, then adds more features like serializing // directly to a file or any stream. -// Please check it out at: https://arduinojson.org/book/ \ No newline at end of file +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/examples/ProgmemExample/ProgmemExample.ino b/examples/ProgmemExample/ProgmemExample.ino index 15be8ed1..ddde8fd1 100644 --- a/examples/ProgmemExample/ProgmemExample.ino +++ b/examples/ProgmemExample/ProgmemExample.ino @@ -59,12 +59,12 @@ void loop() { // See also // -------- // -// The website arduinojson.org contains the documentation for all the functions +// https://arduinojson.org/ contains the documentation for all the functions // used above. It also includes an FAQ that will help you solve any memory // problem. -// Please check it out at: https://arduinojson.org/ // // The book "Mastering ArduinoJson" contains a quick C++ course that explains // how your microcontroller stores strings in memory. It also tells why you // should not abuse Flash strings with ArduinoJson. -// Please check it out at: https://arduinojson.org/book/ \ No newline at end of file +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/examples/StringExample/StringExample.ino b/examples/StringExample/StringExample.ino index d5994ffb..fc7503d0 100644 --- a/examples/StringExample/StringExample.ino +++ b/examples/StringExample/StringExample.ino @@ -64,11 +64,11 @@ void loop() { // See also // -------- // -// The website arduinojson.org contains the documentation for all the functions +// https://arduinojson.org/ contains the documentation for all the functions // used above. It also includes an FAQ that will help you solve any problem. -// Please check it out at: https://arduinojson.org/ // // The book "Mastering ArduinoJson" contains a quick C++ course that explains // how your microcontroller stores strings in memory. On several occasions, it // shows how you can avoid String in your program. -// Please check it out at: https://arduinojson.org/book/ \ No newline at end of file +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ From 0d4a93018b061ce20238a9d81c17913cb0e7bfe4 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 6 Oct 2018 17:50:41 +0200 Subject: [PATCH 6/6] Set version to 5.13.3 --- CHANGELOG.md | 4 ++-- appveyor.yml | 2 +- library.json | 2 +- library.properties | 2 +- src/ArduinoJson/version.hpp | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c11d228..b2a62624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ ArduinoJson: change log ======================= -HEAD ----- +v5.13.3 +------- * Improved float serialization when `-fsingle-precision-constant` is used * Fixed `JsonVariant::is()` that returned true for empty strings diff --git a/appveyor.yml b/appveyor.yml index c864cfda..cbb7447f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 5.13.2.{build} +version: 5.13.3.{build} environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 diff --git a/library.json b/library.json index 6b87f062..bc4997a7 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/bblanchon/ArduinoJson.git" }, - "version": "5.13.2", + "version": "5.13.3", "authors": { "name": "Benoit Blanchon", "url": "https://blog.benoitblanchon.fr" diff --git a/library.properties b/library.properties index abf6cfc6..f9dd1dd1 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoJson -version=5.13.2 +version=5.13.3 author=Benoit Blanchon maintainer=Benoit Blanchon sentence=An efficient and elegant JSON library for Arduino. diff --git a/src/ArduinoJson/version.hpp b/src/ArduinoJson/version.hpp index a71c3ab4..e5fa1e2e 100644 --- a/src/ArduinoJson/version.hpp +++ b/src/ArduinoJson/version.hpp @@ -4,7 +4,7 @@ #pragma once -#define ARDUINOJSON_VERSION "5.13.2" +#define ARDUINOJSON_VERSION "5.13.3" #define ARDUINOJSON_VERSION_MAJOR 5 #define ARDUINOJSON_VERSION_MINOR 13 -#define ARDUINOJSON_VERSION_REVISION 2 +#define ARDUINOJSON_VERSION_REVISION 3