This is an automated email from the ASF dual-hosted git repository.

emmenlau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 49c6ec702 TProtocol.h: Be extra careful when including MSVC 
Windows-related headers to not pollute the c++ namespace
     new 2810fd207 Merge pull request #2862 from 
BioDataAnalysis/emmenlau_fix_windows_header_include
49c6ec702 is described below

commit 49c6ec702d963c05fa83470e71a486780ef825bc
Author: Mario Emmenlauer <memmenla...@biodataanalysis.de>
AuthorDate: Tue Oct 10 10:46:09 2023 +0200

    TProtocol.h: Be extra careful when including MSVC Windows-related headers 
to not pollute the c++ namespace
---
 lib/cpp/src/thrift/protocol/TProtocol.h | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/cpp/src/thrift/protocol/TProtocol.h 
b/lib/cpp/src/thrift/protocol/TProtocol.h
index c6ff36049..237c1e568 100644
--- a/lib/cpp/src/thrift/protocol/TProtocol.h
+++ b/lib/cpp/src/thrift/protocol/TProtocol.h
@@ -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>
@@ -558,14 +576,14 @@ public:
   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())
   {}
 

Reply via email to