@@ -31,12 +31,13 @@ namespace Json {
31
31
#if defined(__ARMEL__)
32
32
#define ALIGNAS (byte_alignment ) __attribute__((aligned(byte_alignment)))
33
33
#else
34
+ // This exists for binary compatibility only. Use nullRef.
35
+ static const Value null;
34
36
#define ALIGNAS (byte_alignment )
35
37
#endif
36
38
static const unsigned char ALIGNAS (8 ) kNull [sizeof (Value)] = { 0 };
37
39
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 );
40
41
41
42
const Int Value::minInt = Int (~(UInt (-1 ) / 2 ));
42
43
const Int Value::maxInt = Int (UInt (-1 ) / 2 );
@@ -856,7 +857,7 @@ Value& Value::operator[](ArrayIndex index) {
856
857
if (it != value_.map_ ->end () && (*it).first == key)
857
858
return (*it).second ;
858
859
859
- ObjectValues::value_type defaultValue (key, null );
860
+ ObjectValues::value_type defaultValue (key, nullRef );
860
861
it = value_.map_ ->insert (it, defaultValue);
861
862
return (*it).second ;
862
863
#else
@@ -876,16 +877,16 @@ const Value& Value::operator[](ArrayIndex index) const {
876
877
type_ == nullValue || type_ == arrayValue,
877
878
" in Json::Value::operator[](ArrayIndex)const: requires arrayValue" );
878
879
if (type_ == nullValue)
879
- return null ;
880
+ return nullRef ;
880
881
#ifndef JSON_VALUE_USE_INTERNAL_MAP
881
882
CZString key (index );
882
883
ObjectValues::const_iterator it = value_.map_ ->find (key);
883
884
if (it == value_.map_ ->end ())
884
- return null ;
885
+ return nullRef ;
885
886
return (*it).second ;
886
887
#else
887
888
Value* value = value_.array_ ->find (index );
888
- return value ? *value : null ;
889
+ return value ? *value : nullRef ;
889
890
#endif
890
891
}
891
892
@@ -922,7 +923,7 @@ Value& Value::resolveReference(const char* key, bool isStatic) {
922
923
if (it != value_.map_ ->end () && (*it).first == actualKey)
923
924
return (*it).second ;
924
925
925
- ObjectValues::value_type defaultValue (actualKey, null );
926
+ ObjectValues::value_type defaultValue (actualKey, nullRef );
926
927
it = value_.map_ ->insert (it, defaultValue);
927
928
Value& value = (*it).second ;
928
929
return value;
@@ -933,7 +934,7 @@ Value& Value::resolveReference(const char* key, bool isStatic) {
933
934
934
935
Value Value::get (ArrayIndex index, const Value& defaultValue) const {
935
936
const Value* value = &((*this )[index ]);
936
- return value == &null ? defaultValue : *value;
937
+ return value == &nullRef ? defaultValue : *value;
937
938
}
938
939
939
940
bool Value::isValidIndex (ArrayIndex index) const { return index < size (); }
@@ -943,16 +944,16 @@ const Value& Value::operator[](const char* key) const {
943
944
type_ == nullValue || type_ == objectValue,
944
945
" in Json::Value::operator[](char const*)const: requires objectValue" );
945
946
if (type_ == nullValue)
946
- return null ;
947
+ return nullRef ;
947
948
#ifndef JSON_VALUE_USE_INTERNAL_MAP
948
949
CZString actualKey (key, CZString::noDuplication);
949
950
ObjectValues::const_iterator it = value_.map_ ->find (actualKey);
950
951
if (it == value_.map_ ->end ())
951
- return null ;
952
+ return nullRef ;
952
953
return (*it).second ;
953
954
#else
954
955
const Value* value = value_.map_ ->find (key);
955
- return value ? *value : null ;
956
+ return value ? *value : nullRef ;
956
957
#endif
957
958
}
958
959
@@ -982,7 +983,7 @@ Value& Value::append(const Value& value) { return (*this)[size()] = value; }
982
983
983
984
Value Value::get (const char * key, const Value& defaultValue) const {
984
985
const Value* value = &((*this )[key]);
985
- return value == &null ? defaultValue : *value;
986
+ return value == &nullRef ? defaultValue : *value;
986
987
}
987
988
988
989
Value Value::get (const std::string& key, const Value& defaultValue) const {
@@ -1018,7 +1019,7 @@ Value Value::removeMember(const char* key) {
1018
1019
JSON_ASSERT_MESSAGE (type_ == nullValue || type_ == objectValue,
1019
1020
" in Json::Value::removeMember(): requires objectValue" );
1020
1021
if (type_ == nullValue)
1021
- return null ;
1022
+ return nullRef ;
1022
1023
1023
1024
Value removed; // null
1024
1025
removeMember (key, &removed);
@@ -1066,7 +1067,7 @@ Value Value::get(const CppTL::ConstString& key,
1066
1067
1067
1068
bool Value::isMember (const char * key) const {
1068
1069
const Value* value = &((*this )[key]);
1069
- return value != &null ;
1070
+ return value != &nullRef ;
1070
1071
}
1071
1072
1072
1073
bool Value::isMember (const std::string& key) const {
@@ -1472,7 +1473,7 @@ const Value& Path::resolve(const Value& root) const {
1472
1473
// Error: unable to resolve path (object value expected at position...)
1473
1474
}
1474
1475
node = &((*node)[arg.key_ ]);
1475
- if (node == &Value::null ) {
1476
+ if (node == &Value::nullRef ) {
1476
1477
// Error: unable to resolve path (object has no member named '' at
1477
1478
// position...)
1478
1479
}
@@ -1493,7 +1494,7 @@ Value Path::resolve(const Value& root, const Value& defaultValue) const {
1493
1494
if (!node->isObject ())
1494
1495
return defaultValue;
1495
1496
node = &((*node)[arg.key_ ]);
1496
- if (node == &Value::null )
1497
+ if (node == &Value::nullRef )
1497
1498
return defaultValue;
1498
1499
}
1499
1500
}
0 commit comments