Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TProtocol.h: Be extra careful when including MSVC Windows-related headers #2862

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/cpp/src/thrift/protocol/TProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,26 @@
#define _THRIFT_PROTOCOL_TPROTOCOL_H_ 1

#ifdef _WIN32
// Including Winsock2.h adds problematic macros like min() and max().
// Try to work around:
#ifndef NOMINMAX
#define NOMINMAX
#define _THRIFT_UNDEF_NOMINMAX
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#define _THRIFT_UNDEF_WIN32_LEAN_AND_MEAN
#endif
// Need to come before any Windows.h includes
#include <winsock2.h>
#ifdef _THRIFT_UNDEF_NOMINMAX
#undef NOMINMAX
#undef _THRIFT_UNDEF_NOMINMAX
#endif
#ifdef _THRIFT_UNDEF_WIN32_LEAN_AND_MEAN
#undef WIN32_LEAN_AND_MEAN
#undef _THRIFT_UNDEF_WIN32_LEAN_AND_MEAN
#endif
#endif

#include <thrift/transport/TTransport.h>
Expand Down Expand Up @@ -558,14 +576,14 @@ class TProtocol {
void setRecurisionLimit(uint32_t depth) {recursion_limit_ = depth;}

// Returns the minimum amount of bytes needed to store the smallest possible instance of TType.
virtual int getMinSerializedSize(TType type) {
virtual int getMinSerializedSize(TType type) {
THRIFT_UNUSED_VARIABLE(type);
return 0;
}

protected:
TProtocol(std::shared_ptr<TTransport> ptrans)
: ptrans_(ptrans), input_recursion_depth_(0), output_recursion_depth_(0),
: ptrans_(ptrans), input_recursion_depth_(0), output_recursion_depth_(0),
recursion_limit_(ptrans->getConfiguration()->getRecursionLimit())
{}

Expand Down