Skip to content

Commit d179fac

Browse files
committed
don't let the GetObject macro rewrite the GetObject method, add a GetObj alias
1 parent 3168d7c commit d179fac

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/rapidjson/document.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible lo
4242
RAPIDJSON_DIAG_OFF(effc++)
4343
#endif // __GNUC__
4444

45+
#ifdef GetObject
46+
// see https://github.com/Tencent/rapidjson/issues/1448
47+
// a former included windows.h might have defined a macro called GetObject, which affects
48+
// GetObject defined here. This ensures the macro does not get applied
49+
#pragma push_macro("GetObject")
50+
#define RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
51+
#undef GetObject
52+
#endif
53+
4554
#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
4655
#include <iterator> // std::random_access_iterator_tag
4756
#endif
@@ -1602,7 +1611,9 @@ class GenericValue {
16021611
}
16031612

16041613
Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
1614+
Object GetObj() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
16051615
ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); }
1616+
ConstObject GetObj() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); }
16061617

16071618
//@}
16081619

@@ -3008,4 +3019,9 @@ class GenericObject {
30083019
RAPIDJSON_NAMESPACE_END
30093020
RAPIDJSON_DIAG_POP
30103021

3022+
#ifdef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
3023+
#pragma pop_macro("GetObject")
3024+
#undef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
3025+
#endif
3026+
30113027
#endif // RAPIDJSON_DOCUMENT_H_

test/unittest/platformtest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#endif
2323

2424
#include "rapidjson/document.h"
25+
#undef GetObject
2526

2627
using namespace rapidjson;
2728

@@ -34,4 +35,6 @@ TEST(Platform, GetObject) {
3435
EXPECT_TRUE(o.IsObject());
3536
auto sub = o.GetObject();
3637
EXPECT_TRUE(sub.HasMember("pi"));
38+
auto sub2 = o.GetObj();
39+
EXPECT_TRUE(sub2.HasMember("pi"));
3740
}

0 commit comments

Comments
 (0)