From 294a5aca8f7d84c0bf982c0bf59ffee08acc7ff9 Mon Sep 17 00:00:00 2001 From: MaximeBF Date: Tue, 6 Mar 2018 11:17:04 -0500 Subject: [PATCH 1/3] Support long and unsined long as int and unsigned on Microsft platforms --- include/rapidjson/document.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index f28d8ca6..a6acc242 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -451,6 +451,26 @@ struct TypeHelper { static ValueType& Set(ValueType& v, unsigned data, typename ValueType::AllocatorType&) { return v.SetUint(data); } }; +#ifdef _MSC_VER +RAPIDJSON_STATIC_ASSERT(sizeof(long) == sizeof(int)); +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsInt(); } + static long Get(const ValueType& v) { return v.GetInt(); } + static ValueType& Set(ValueType& v, long data) { return v.SetInt(data); } + static ValueType& Set(ValueType& v, long data, typename ValueType::AllocatorType&) { return v.SetInt(data); } +}; + +RAPIDJSON_STATIC_ASSERT(sizeof(unsigned long) == sizeof(unsigned)); +template +struct TypeHelper { + static bool Is(const ValueType& v) { return v.IsUint(); } + static unsigned long Get(const ValueType& v) { return v.GetUint(); } + static ValueType& Set(ValueType& v, unsigned long data) { return v.SetUint(data); } + static ValueType& Set(ValueType& v, unsigned long data, typename ValueType::AllocatorType&) { return v.SetUint(data); } +}; +#endif + template struct TypeHelper { static bool Is(const ValueType& v) { return v.IsInt64(); } From a040fc3347f2ffeca7e4e3c71aefeaa37840af56 Mon Sep 17 00:00:00 2001 From: MaximeBF Date: Thu, 8 Mar 2018 07:28:51 -0500 Subject: [PATCH 2/3] Add unittest for long as int in MSC platforms --- test/unittest/valuetest.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index 307e1b06..d59ec1b6 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -439,6 +439,14 @@ TEST(Value, Int) { EXPECT_EQ(5678, z.Get()); EXPECT_EQ(5679, z.Set(5679).Get()); EXPECT_EQ(5680, z.Set(5680).Get()); + +#ifdef _MSC_VER + // long as int on MSC platforms + RAPIDJSON_STATIC_ASSERT(sizeof(long) == sizeof(int)); + z.SetInt(1234); + EXPECT_TRUE(z.Is()); + EXPECT_EQ(1234l, z.Get()); +#endif } TEST(Value, Uint) { @@ -485,6 +493,14 @@ TEST(Value, Uint) { EXPECT_EQ(2147483648u, z.Get()); EXPECT_EQ(2147483649u, z.Set(2147483649u).Get()); EXPECT_EQ(2147483650u, z.Set(2147483650u).Get()); + +#ifdef _MSC_VER + // unsigned long as unsigned on MSC platforms + RAPIDJSON_STATIC_ASSERT(sizeof(unsigned long) == sizeof(unsigned)); + z.SetUint(1234); + EXPECT_TRUE(z.Is()); + EXPECT_EQ(1234ul, z.Get()); +#endif } TEST(Value, Int64) { From a37f9d1ecd62e65cc5b9b0a9d04d223c6cd76429 Mon Sep 17 00:00:00 2001 From: MaximeBF Date: Thu, 8 Mar 2018 07:33:26 -0500 Subject: [PATCH 3/3] Fix unsigned long as unsigned unit test --- test/unittest/valuetest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index d59ec1b6..0e2cf8eb 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -499,7 +499,7 @@ TEST(Value, Uint) { RAPIDJSON_STATIC_ASSERT(sizeof(unsigned long) == sizeof(unsigned)); z.SetUint(1234); EXPECT_TRUE(z.Is()); - EXPECT_EQ(1234ul, z.Get()); + EXPECT_EQ(1234ul, z.Get()); #endif }