Skip to content

Commit cd4ef14

Browse files
authored
Fixed a GetObject() function colliding with WinAPI macro (#139)
1 parent 0352bb3 commit cd4ef14

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

include/miniocpp/baseclient.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
#include "response.h"
3232
#include "utils.h"
3333

34+
#if defined(_WIN32) && defined(GetObject)
35+
#pragma push_macro("GetObject")
36+
#undef GetObject
37+
#define MINIO_CPP_GET_OBJECT_DEFINED
38+
#endif
39+
3440
namespace minio::s3 {
3541

3642
utils::Multimap GetCommonListObjectsQueryParams(
@@ -150,8 +156,31 @@ class BaseClient {
150156
StatObjectResponse StatObject(StatObjectArgs args);
151157
UploadPartResponse UploadPart(UploadPartArgs args);
152158
UploadPartCopyResponse UploadPartCopy(UploadPartCopyArgs args);
159+
160+
// Windows API fix:
161+
//
162+
// Windows API headers define `GetObject()` as a macro that expands to either
163+
// `GetObjectA()` or `GetObjectW()`. This means that users can get link errors
164+
// in case that one compilation unit used `GetObject()` macro and other
165+
// didn't. This fixes the issue by providing both functions `GetObject()` can
166+
// expand to as inline wrappers.
167+
#if defined(_WIN32)
168+
inline GetObjectResponse GetObjectA(const GetObjectArgs& args) {
169+
return GetObject(args);
170+
}
171+
172+
inline GetObjectResponse GetObjectW(const GetObjectArgs& args) {
173+
return GetObject(args);
174+
}
175+
#endif // _WIN32
176+
153177
}; // class BaseClient
154178

155179
} // namespace minio::s3
156180

181+
#if defined(_WIN32) && defined(MINIO_CPP_GET_OBJECT_DEFINED)
182+
#undef MINIO_CPP_GET_OBJECT_DEFINED
183+
#pragma pop_macro("GetObject")
184+
#endif
185+
157186
#endif // MINIO_CPP_BASECLIENT_H_INCLUDED

src/baseclient.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
#include "miniocpp/types.h"
4444
#include "miniocpp/utils.h"
4545

46+
// We want exactly `minio::s3::BaseClient::GetObject()` symbol and nothing else.
47+
#if defined(GetObject)
48+
#undef GetObject
49+
#endif
50+
4651
namespace minio::s3 {
4752

4853
utils::Multimap GetCommonListObjectsQueryParams(

0 commit comments

Comments
 (0)