From adf66292232e8458410325c721bd4be5f0a21738 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 25 Jun 2014 22:38:18 +0800 Subject: [PATCH] Fixed VC which doesn't have INT64_C()/UINT64_C macros. --- include/rapidjson/document.h | 12 ++++++------ include/rapidjson/rapidjson.h | 18 ++++++++++++++++-- include/rapidjson/reader.h | 8 ++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 31a7225..62d3828 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -91,23 +91,23 @@ public: data_.n.i64 = i64; if (i64 >= 0) { flags_ |= kNumberUint64Flag; - if (!(static_cast(i64) & UINT64_C(0xFFFFFFFF00000000))) + if (!(static_cast(i64) & RAPIDJSON_UINT64_C(0xFFFFFFFF00000000))) flags_ |= kUintFlag; - if (!(static_cast(i64) & UINT64_C(0xFFFFFFFF80000000))) + if (!(static_cast(i64) & RAPIDJSON_UINT64_C(0xFFFFFFFF80000000))) flags_ |= kIntFlag; } - else if (i64 >= INT64_C(-2147483648)) + else if (i64 >= RAPIDJSON_INT64_C(-2147483648)) flags_ |= kIntFlag; } //! Constructor for uint64_t value. GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) { data_.n.u64 = u64; - if (!(u64 & UINT64_C(0x8000000000000000))) + if (!(u64 & RAPIDJSON_UINT64_C(0x8000000000000000))) flags_ |= kInt64Flag; - if (!(u64 & UINT64_C(0xFFFFFFFF00000000))) + if (!(u64 & RAPIDJSON_UINT64_C(0xFFFFFFFF00000000))) flags_ |= kUintFlag; - if (!(u64 & UINT64_C(0xFFFFFFFF80000000))) + if (!(u64 & RAPIDJSON_UINT64_C(0xFFFFFFFF80000000))) flags_ |= kIntFlag; } diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 6939e8d..fb1cbc5 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -13,12 +13,26 @@ // Here defines int64_t and uint64_t types in global namespace. // If user have their own definition, can define RAPIDJSON_NO_INT64DEFINE to disable this. #ifndef RAPIDJSON_NO_INT64DEFINE +// Old Visual C++ does not have standard integer types, typedef our own. #ifdef _MSC_VER typedef __int64 int64_t; typedef unsigned __int64 uint64_t; -#else -#include +#ifndef RAPIDJSON_INT64_C +#define RAPIDJSON_INT64_C(x) x##LL #endif +#ifndef RAPIDJSON_UINT64_C +#define RAPIDJSON_UINT64_C(x) x##uLL +#endif +#else +// Other compilers should have this. +#include +#ifndef RAPIDJSON_INT64_C +#define RAPIDJSON_INT64_C(x) INT64_C(x) +#endif +#ifndef RAPIDJSON_UINT64_C +#define RAPIDJSON_UINT64_C(x) UINT64_C(x) +#endif +#endif // _MSC_VER #endif // RAPIDJSON_NO_INT64TYPEDEF /////////////////////////////////////////////////////////////////////////////// diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index d58702f..de4deb6 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -527,8 +527,8 @@ private: i64 = i; if (minus) while (s.Peek() >= '0' && s.Peek() <= '9') { - if (i64 >= UINT64_C(922337203685477580)) // 2^63 = 9223372036854775808 - if (i64 != UINT64_C(922337203685477580) || s.Peek() > '8') { + if (i64 >= RAPIDJSON_UINT64_C(922337203685477580)) // 2^63 = 9223372036854775808 + if (i64 != RAPIDJSON_UINT64_C(922337203685477580) || s.Peek() > '8') { useDouble = true; break; } @@ -536,8 +536,8 @@ private: } else while (s.Peek() >= '0' && s.Peek() <= '9') { - if (i64 >= UINT64_C(1844674407370955161)) // 2^64 - 1 = 18446744073709551615 - if (i64 != UINT64_C(1844674407370955161) || s.Peek() > '5') { + if (i64 >= RAPIDJSON_UINT64_C(1844674407370955161)) // 2^64 - 1 = 18446744073709551615 + if (i64 != RAPIDJSON_UINT64_C(1844674407370955161) || s.Peek() > '5') { useDouble = true; break; }