forked from bblanchon/ArduinoJson
Made JsonBuffer destructor protected
This commit is contained in:
@ -16,16 +16,6 @@
|
|||||||
#include "TypeTraits/EnableIf.hpp"
|
#include "TypeTraits/EnableIf.hpp"
|
||||||
#include "TypeTraits/IsArray.hpp"
|
#include "TypeTraits/IsArray.hpp"
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#endif
|
|
||||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace ArduinoJson {
|
namespace ArduinoJson {
|
||||||
class JsonArray;
|
class JsonArray;
|
||||||
class JsonObject;
|
class JsonObject;
|
||||||
@ -37,11 +27,6 @@ class JsonObject;
|
|||||||
// fixed memory allocation.
|
// fixed memory allocation.
|
||||||
class JsonBuffer : Internals::NonCopyable {
|
class JsonBuffer : Internals::NonCopyable {
|
||||||
public:
|
public:
|
||||||
// CAUTION: NO VIRTUAL DESTRUCTOR!
|
|
||||||
// If we add a virtual constructor the Arduino compiler will add malloc() and
|
|
||||||
// free() to the binary, adding 706 useless bytes.
|
|
||||||
// virtual ~JsonBuffer() {}
|
|
||||||
|
|
||||||
// Allocates an empty JsonArray.
|
// Allocates an empty JsonArray.
|
||||||
//
|
//
|
||||||
// Returns a reference to the new JsonArray or JsonArray::invalid() if the
|
// Returns a reference to the new JsonArray or JsonArray::invalid() if the
|
||||||
@ -77,6 +62,11 @@ class JsonBuffer : Internals::NonCopyable {
|
|||||||
virtual void *alloc(size_t size) = 0;
|
virtual void *alloc(size_t size) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// CAUTION: NO VIRTUAL DESTRUCTOR!
|
||||||
|
// If we add a virtual constructor the Arduino compiler will add malloc()
|
||||||
|
// and free() to the binary, adding 706 useless bytes.
|
||||||
|
~JsonBuffer() {}
|
||||||
|
|
||||||
// Preserve aligment if necessary
|
// Preserve aligment if necessary
|
||||||
static FORCE_INLINE size_t round_size_up(size_t bytes) {
|
static FORCE_INLINE size_t round_size_up(size_t bytes) {
|
||||||
#if ARDUINOJSON_ENABLE_ALIGNMENT
|
#if ARDUINOJSON_ENABLE_ALIGNMENT
|
||||||
@ -88,11 +78,3 @@ class JsonBuffer : Internals::NonCopyable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
@ -9,16 +9,6 @@
|
|||||||
|
|
||||||
#include "Deserialization/JsonParser.hpp"
|
#include "Deserialization/JsonParser.hpp"
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#endif
|
|
||||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace ArduinoJson {
|
namespace ArduinoJson {
|
||||||
template <typename TDerived>
|
template <typename TDerived>
|
||||||
class JsonBufferBase : public JsonBuffer {
|
class JsonBufferBase : public JsonBuffer {
|
||||||
@ -127,17 +117,12 @@ class JsonBufferBase : public JsonBuffer {
|
|||||||
return Internals::makeParser(that(), json, nestingLimit).parseVariant();
|
return Internals::makeParser(that(), json, nestingLimit).parseVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
~JsonBufferBase() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TDerived *that() {
|
TDerived *that() {
|
||||||
return static_cast<TDerived *>(this);
|
return static_cast<TDerived *>(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
@ -9,16 +9,6 @@
|
|||||||
|
|
||||||
#include "JsonBufferBase.hpp"
|
#include "JsonBufferBase.hpp"
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#endif
|
|
||||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace ArduinoJson {
|
namespace ArduinoJson {
|
||||||
|
|
||||||
class StaticJsonBufferBase : public JsonBufferBase<StaticJsonBufferBase> {
|
class StaticJsonBufferBase : public JsonBufferBase<StaticJsonBufferBase> {
|
||||||
@ -81,6 +71,9 @@ class StaticJsonBufferBase : public JsonBufferBase<StaticJsonBufferBase> {
|
|||||||
return String(this);
|
return String(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
~StaticJsonBufferBase() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void alignNextAlloc() {
|
void alignNextAlloc() {
|
||||||
_size = round_size_up(_size);
|
_size = round_size_up(_size);
|
||||||
@ -101,6 +94,16 @@ class StaticJsonBufferBase : public JsonBufferBase<StaticJsonBufferBase> {
|
|||||||
size_t _size;
|
size_t _size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#endif
|
||||||
|
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Implements a JsonBuffer with fixed memory allocation.
|
// Implements a JsonBuffer with fixed memory allocation.
|
||||||
// The template paramenter CAPACITY specifies the capacity of the buffer in
|
// The template paramenter CAPACITY specifies the capacity of the buffer in
|
||||||
// bytes.
|
// bytes.
|
||||||
|
Reference in New Issue
Block a user