Skip to content

Commit

Permalink
Fixed a GetObject() function colliding with WinAPI macro
Browse files Browse the repository at this point in the history
  • Loading branch information
kobalicek authored and balamurugana committed May 15, 2024
1 parent 8c64ac2 commit 43c4768
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions include/miniocpp/baseclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#include "response.h"
#include "utils.h"

#if defined(_WIN32) && defined(GetObject)
#pragma push_macro("GetObject")
#undef GetObject
#define MINIO_CPP_GET_OBJECT_DEFINED
#endif

namespace minio::s3 {

utils::Multimap GetCommonListObjectsQueryParams(
Expand Down Expand Up @@ -150,8 +156,31 @@ class BaseClient {
StatObjectResponse StatObject(StatObjectArgs args);
UploadPartResponse UploadPart(UploadPartArgs args);
UploadPartCopyResponse UploadPartCopy(UploadPartCopyArgs args);

// Windows API fix:
//
// Windows API headers define `GetObject()` as a macro that expands to either
// `GetObjectA()` or `GetObjectW()`. This means that users can get link errors
// in case that one compilation unit used `GetObject()` macro and other
// didn't. This fixes the issue by providing both functions `GetObject()` can
// expand to as inline wrappers.
#if defined(_WIN32)
inline GetObjectResponse GetObjectA(const GetObjectArgs& args) {
return GetObject(args);
}

inline GetObjectResponse GetObjectW(const GetObjectArgs& args) {
return GetObject(args);
}
#endif // _WIN32

}; // class BaseClient

} // namespace minio::s3

#if defined(_WIN32) && defined(MINIO_CPP_GET_OBJECT_DEFINED)
#undef MINIO_CPP_GET_OBJECT_DEFINED
#pragma pop_macro("GetObject")
#endif

#endif // MINIO_CPP_BASECLIENT_H_INCLUDED
5 changes: 5 additions & 0 deletions src/baseclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
#include "miniocpp/types.h"
#include "miniocpp/utils.h"

// We want exactly `minio::s3::BaseClient::GetObject()` symbol and nothing else.
#if defined(GetObject)
#undef GetObject
#endif

namespace minio::s3 {

utils::Multimap GetCommonListObjectsQueryParams(
Expand Down

0 comments on commit 43c4768

Please sign in to comment.