mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-26 18:51:04 +08:00
fix bug for static init
Ugh! Static initialization of instance variables is a very bad idea. This fix is taken from the Chromium code-base. It includes their double-fix for ARM. * https://codereview.chromium.org/24984004 * https://src.chromium.org/viewvc/chrome?revision=226099&view=revision * https://code.google.com/p/webrtc/issues/detail?id=1777
This commit is contained in:
parent
47f1577fd3
commit
28836b8acc
@ -133,7 +133,7 @@ public:
|
||||
typedef Json::LargestUInt LargestUInt;
|
||||
typedef Json::ArrayIndex ArrayIndex;
|
||||
|
||||
static const Value null;
|
||||
static const Value& null;
|
||||
/// Minimum signed integer value that can be stored in a Json::Value.
|
||||
static const LargestInt minLargestInt;
|
||||
/// Maximum signed integer value that can be stored in a Json::Value.
|
||||
|
@ -25,7 +25,17 @@
|
||||
|
||||
namespace Json {
|
||||
|
||||
const Value Value::null;
|
||||
// This is a walkaround to avoid the static initialization of Value::null.
|
||||
// kNull must be word-aligned to avoid crashing on ARM. We use an alignment of
|
||||
// 8 (instead of 4) as a bit of future-proofing.
|
||||
#if defined(__ARMEL__)
|
||||
#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
|
||||
#else
|
||||
#define ALIGNAS(byte_alignment)
|
||||
#endif
|
||||
static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = {0};
|
||||
const Value& Value::null = reinterpret_cast<const Value&>(kNull);
|
||||
|
||||
const Int Value::minInt = Int(~(UInt(-1) / 2));
|
||||
const Int Value::maxInt = Int(UInt(-1) / 2);
|
||||
const UInt Value::maxUInt = UInt(-1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user