Skip to content

Commit 4a6b5a3

Browse files
committed
partially revert 'fix bug for static init'
re: 28836b8 A global instance of a Value (viz. 'null') was a mistake, but dropping it breaks binary-compatibility. So we will keep it everywhere except the one platform where it was crashing, ARM.
1 parent 37ea604 commit 4a6b5a3

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Diff for: include/json/value.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ class JSON_API Value {
133133
typedef Json::LargestUInt LargestUInt;
134134
typedef Json::ArrayIndex ArrayIndex;
135135

136-
static const Value& null; ///! We regret this reference to a global instance; prefer the simpler Value().
137-
static const Value& nullRef; ///! just a kludge for binary-compatibility; same as null
136+
static const Value& nullRef;
137+
#if !defined(__ARMEL__)
138+
/// \deprecated This exists for binary compatibility only. Use nullRef.
139+
static const Value null;
140+
#endif
138141
/// Minimum signed integer value that can be stored in a Json::Value.
139142
static const LargestInt minLargestInt;
140143
/// Maximum signed integer value that can be stored in a Json::Value.

Diff for: src/lib_json/json_value.cpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ namespace Json {
3131
#if defined(__ARMEL__)
3232
#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
3333
#else
34+
// This exists for binary compatibility only. Use nullRef.
35+
static const Value null;
3436
#define ALIGNAS(byte_alignment)
3537
#endif
3638
static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
3739
const unsigned char& kNullRef = kNull[0];
38-
const Value& Value::null = reinterpret_cast<const Value&>(kNullRef);
39-
const Value& Value::nullRef = null;
40+
const Value& Value::nullRef = reinterpret_cast<const Value&>(kNullRef);
4041

4142
const Int Value::minInt = Int(~(UInt(-1) / 2));
4243
const Int Value::maxInt = Int(UInt(-1) / 2);
@@ -856,7 +857,7 @@ Value& Value::operator[](ArrayIndex index) {
856857
if (it != value_.map_->end() && (*it).first == key)
857858
return (*it).second;
858859

859-
ObjectValues::value_type defaultValue(key, null);
860+
ObjectValues::value_type defaultValue(key, nullRef);
860861
it = value_.map_->insert(it, defaultValue);
861862
return (*it).second;
862863
#else
@@ -876,16 +877,16 @@ const Value& Value::operator[](ArrayIndex index) const {
876877
type_ == nullValue || type_ == arrayValue,
877878
"in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
878879
if (type_ == nullValue)
879-
return null;
880+
return nullRef;
880881
#ifndef JSON_VALUE_USE_INTERNAL_MAP
881882
CZString key(index);
882883
ObjectValues::const_iterator it = value_.map_->find(key);
883884
if (it == value_.map_->end())
884-
return null;
885+
return nullRef;
885886
return (*it).second;
886887
#else
887888
Value* value = value_.array_->find(index);
888-
return value ? *value : null;
889+
return value ? *value : nullRef;
889890
#endif
890891
}
891892

@@ -922,7 +923,7 @@ Value& Value::resolveReference(const char* key, bool isStatic) {
922923
if (it != value_.map_->end() && (*it).first == actualKey)
923924
return (*it).second;
924925

925-
ObjectValues::value_type defaultValue(actualKey, null);
926+
ObjectValues::value_type defaultValue(actualKey, nullRef);
926927
it = value_.map_->insert(it, defaultValue);
927928
Value& value = (*it).second;
928929
return value;
@@ -933,7 +934,7 @@ Value& Value::resolveReference(const char* key, bool isStatic) {
933934

934935
Value Value::get(ArrayIndex index, const Value& defaultValue) const {
935936
const Value* value = &((*this)[index]);
936-
return value == &null ? defaultValue : *value;
937+
return value == &nullRef ? defaultValue : *value;
937938
}
938939

939940
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
@@ -943,16 +944,16 @@ const Value& Value::operator[](const char* key) const {
943944
type_ == nullValue || type_ == objectValue,
944945
"in Json::Value::operator[](char const*)const: requires objectValue");
945946
if (type_ == nullValue)
946-
return null;
947+
return nullRef;
947948
#ifndef JSON_VALUE_USE_INTERNAL_MAP
948949
CZString actualKey(key, CZString::noDuplication);
949950
ObjectValues::const_iterator it = value_.map_->find(actualKey);
950951
if (it == value_.map_->end())
951-
return null;
952+
return nullRef;
952953
return (*it).second;
953954
#else
954955
const Value* value = value_.map_->find(key);
955-
return value ? *value : null;
956+
return value ? *value : nullRef;
956957
#endif
957958
}
958959

@@ -982,7 +983,7 @@ Value& Value::append(const Value& value) { return (*this)[size()] = value; }
982983

983984
Value Value::get(const char* key, const Value& defaultValue) const {
984985
const Value* value = &((*this)[key]);
985-
return value == &null ? defaultValue : *value;
986+
return value == &nullRef ? defaultValue : *value;
986987
}
987988

988989
Value Value::get(const std::string& key, const Value& defaultValue) const {
@@ -1018,7 +1019,7 @@ Value Value::removeMember(const char* key) {
10181019
JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue,
10191020
"in Json::Value::removeMember(): requires objectValue");
10201021
if (type_ == nullValue)
1021-
return null;
1022+
return nullRef;
10221023

10231024
Value removed; // null
10241025
removeMember(key, &removed);
@@ -1066,7 +1067,7 @@ Value Value::get(const CppTL::ConstString& key,
10661067

10671068
bool Value::isMember(const char* key) const {
10681069
const Value* value = &((*this)[key]);
1069-
return value != &null;
1070+
return value != &nullRef;
10701071
}
10711072

10721073
bool Value::isMember(const std::string& key) const {
@@ -1472,7 +1473,7 @@ const Value& Path::resolve(const Value& root) const {
14721473
// Error: unable to resolve path (object value expected at position...)
14731474
}
14741475
node = &((*node)[arg.key_]);
1475-
if (node == &Value::null) {
1476+
if (node == &Value::nullRef) {
14761477
// Error: unable to resolve path (object has no member named '' at
14771478
// position...)
14781479
}
@@ -1493,7 +1494,7 @@ Value Path::resolve(const Value& root, const Value& defaultValue) const {
14931494
if (!node->isObject())
14941495
return defaultValue;
14951496
node = &((*node)[arg.key_]);
1496-
if (node == &Value::null)
1497+
if (node == &Value::nullRef)
14971498
return defaultValue;
14981499
}
14991500
}

0 commit comments

Comments
 (0)