Skip to content

Commit

Permalink
Merge pull request open-source-parsers#6 from cdunn2001/fix-static-init
Browse files Browse the repository at this point in the history
I will try to pull the other changes from Chromium as well.

This passed Travis.
  • Loading branch information
cdunn2001 committed Jul 6, 2014
2 parents 47f1577 + 28836b8 commit 8050d8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class JSON_API Value {
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.
Expand Down
12 changes: 11 additions & 1 deletion src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8050d8b

Please sign in to comment.