diff --git a/CHANGELOG.md b/CHANGELOG.md index de6f0831..cdd02587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Fixed build when another lib does `#undef isnan` (issue #284) + v5.6.1 ------ diff --git a/include/ArduinoJson/Internals/JsonWriter.hpp b/include/ArduinoJson/Internals/JsonWriter.hpp index ba6da82f..5df2e68f 100644 --- a/include/ArduinoJson/Internals/JsonWriter.hpp +++ b/include/ArduinoJson/Internals/JsonWriter.hpp @@ -8,8 +8,7 @@ #pragma once #include "../Polyfills/attributes.hpp" -#include "../Polyfills/isInfinity.hpp" -#include "../Polyfills/isNaN.hpp" +#include "../Polyfills/math.hpp" #include "../Polyfills/normalize.hpp" #include "../Print.hpp" #include "Encoding.hpp" @@ -33,18 +32,34 @@ class JsonWriter { // Returns the number of bytes sent to the Print implementation. // This is very handy for implementations of printTo() that must return the // number of bytes written. - size_t bytesWritten() const { return _length; } + size_t bytesWritten() const { + return _length; + } - void beginArray() { writeRaw('['); } - void endArray() { writeRaw(']'); } + void beginArray() { + writeRaw('['); + } + void endArray() { + writeRaw(']'); + } - void beginObject() { writeRaw('{'); } - void endObject() { writeRaw('}'); } + void beginObject() { + writeRaw('{'); + } + void endObject() { + writeRaw('}'); + } - void writeColon() { writeRaw(':'); } - void writeComma() { writeRaw(','); } + void writeColon() { + writeRaw(':'); + } + void writeComma() { + writeRaw(','); + } - void writeBoolean(bool value) { writeRaw(value ? "true" : "false"); } + void writeBoolean(bool value) { + writeRaw(value ? "true" : "false"); + } void writeString(const char *value) { if (!value) { @@ -132,8 +147,12 @@ class JsonWriter { } } - void writeRaw(const char *s) { _length += _sink.print(s); } - void writeRaw(char c) { _length += _sink.write(c); } + void writeRaw(const char *s) { + _length += _sink.print(s); + } + void writeRaw(char c) { + _length += _sink.write(c); + } protected: Print &_sink; diff --git a/include/ArduinoJson/Polyfills/isNaN.hpp b/include/ArduinoJson/Polyfills/isNaN.hpp deleted file mode 100644 index cc378143..00000000 --- a/include/ArduinoJson/Polyfills/isNaN.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -// If Visual Studo <= 2012 -#if defined(_MSC_VER) && _MSC_VER <= 1700 -#include -#else -#include -#endif - -// GCC warning: "conversion to 'float' from 'double' may alter its value" -#ifdef __GNUC__ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) -#pragma GCC diagnostic ignored "-Wfloat-conversion" -#else -#pragma GCC diagnostic ignored "-Wconversion" -#endif -#endif - -namespace ArduinoJson { -namespace Polyfills { - -// If Visual Studo <= 2012 -#if defined(_MSC_VER) && _MSC_VER <= 1700 - -template -bool isNaN(T x) { - return _isnan(x) != 0; -} -#else - -template -bool isNaN(T x) { - return isnan(x); -} - -#endif -} -} - -#if defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif diff --git a/include/ArduinoJson/Polyfills/isInfinity.hpp b/include/ArduinoJson/Polyfills/math.hpp similarity index 62% rename from include/ArduinoJson/Polyfills/isInfinity.hpp rename to include/ArduinoJson/Polyfills/math.hpp index be1f9fa8..b26f6a48 100644 --- a/include/ArduinoJson/Polyfills/isInfinity.hpp +++ b/include/ArduinoJson/Polyfills/math.hpp @@ -9,10 +9,26 @@ // If Visual Studo <= 2012 #if defined(_MSC_VER) && _MSC_VER <= 1700 + #include + +namespace ArduinoJson { +namespace Polyfills { +template +bool isNaN(T x) { + return _isnan(x) != 0; +} + +template +bool isInfinity(T x) { + return !_finite(x); +} +} +} + #else + #include -#endif // GCC warning: "conversion to 'float' from 'double' may alter its value" #ifdef __GNUC__ @@ -26,40 +42,42 @@ #endif #endif +// Workaround for libs that #undef isnan or isinf +// https://github.com/bblanchon/ArduinoJson/issues/284 +#if !defined(isnan) || !defined(isinf) +namespace std {} +#endif + namespace ArduinoJson { namespace Polyfills { -// If Visual Studo <= 2012 -#if defined(_MSC_VER) && _MSC_VER <= 1700 template -bool isInfinity(T x) { - return !_finite(x); +bool isNaN(T x) { +// Workaround for libs that #undef isnan +// https://github.com/bblanchon/ArduinoJson/issues/284 +#ifndef isnan + using namespace std; +#endif + + return isnan(x); } -#else + template bool isInfinity(T x) { +// Workaround for libs that #undef isinf +// https://github.com/bblanchon/ArduinoJson/issues/284 +#ifndef isinf + using namespace std; +#endif + return isinf(x); } -#if defined(_GLIBCXX_HAVE_ISINFL) && _GLIBCXX_HAVE_ISINFL -template <> -inline bool isInfinity(double x) { - return isinfl(x); -} -#endif - -#if defined(_GLIBCXX_HAVE_ISINFF) && _GLIBCXX_HAVE_ISINFF -template <> -inline bool isInfinity(float x) { - return isinff(x); -} -#endif -#endif -} -} - #if defined(__GNUC__) #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) #pragma GCC diagnostic pop #endif #endif +} +} +#endif