diff options
author | James E. King III <jking@apache.org> | 2018-12-17 16:21:14 -0500 |
---|---|---|
committer | James E. King III <jking@apache.org> | 2018-12-18 10:17:57 -0500 |
commit | 9b75e4fe745a9b08e6ccdc0998ec7a69272f5b4c (patch) | |
tree | 747d56c669ceafbea6dc5955e8622cc39e6fa1cf | |
parent | 56ac72e74ae354c286c41f5d5a3c0b8723feb587 (diff) | |
download | thrift-9b75e4fe745a9b08e6ccdc0998ec7a69272f5b4c.tar.gz |
THRIFT-4680: fix up std::min, std::max, and numeric limits min/max on Windows; remove NOMINMAX from cmake build
-rw-r--r-- | build/cmake/DefinePlatformSpecifc.cmake | 3 | ||||
-rw-r--r-- | compiler/cpp/src/thrift/generate/t_go_generator.cc | 2 | ||||
-rw-r--r-- | lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp | 2 | ||||
-rw-r--r-- | lib/cpp/src/thrift/transport/TBufferTransports.h | 2 | ||||
-rw-r--r-- | lib/cpp/src/thrift/transport/TFileTransport.cpp | 5 | ||||
-rw-r--r-- | lib/cpp/src/thrift/transport/THeaderTransport.cpp | 2 | ||||
-rw-r--r-- | lib/cpp/test/TMemoryBufferTest.cpp | 2 | ||||
-rw-r--r-- | lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp | 4 | ||||
-rw-r--r-- | lib/py/src/ext/protocol.h | 4 | ||||
-rw-r--r-- | lib/py/src/ext/protocol.tcc | 20 | ||||
-rw-r--r-- | test/cpp/src/TestClient.cpp | 8 |
11 files changed, 25 insertions, 29 deletions
diff --git a/build/cmake/DefinePlatformSpecifc.cmake b/build/cmake/DefinePlatformSpecifc.cmake index 8af4b6c91..a809c0723 100644 --- a/build/cmake/DefinePlatformSpecifc.cmake +++ b/build/cmake/DefinePlatformSpecifc.cmake @@ -61,9 +61,6 @@ if(MSVC) set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE) endif(WITH_MT) - # Disable Windows.h definition of macros for min and max - add_definitions("-DNOMINMAX") - # Disable boost auto linking pragmas - cmake includes the right files add_definitions("-DBOOST_ALL_NO_LIB") diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc index 235a0b759..5ada4fa81 100644 --- a/compiler/cpp/src/thrift/generate/t_go_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc @@ -1323,7 +1323,7 @@ void t_go_generator::generate_go_struct_definition(ostream& out, if (tstruct->is_union()) (*m_iter)->set_req(t_field::T_OPTIONAL); if (sorted_keys_pos != (*m_iter)->get_key()) { - int first_unused = std::max(1, sorted_keys_pos++); + int first_unused = (std::max)(1, sorted_keys_pos++); while (sorted_keys_pos != (*m_iter)->get_key()) { ++sorted_keys_pos; } diff --git a/lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp b/lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp index cd38b0125..0e46f11fa 100644 --- a/lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp +++ b/lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp @@ -91,7 +91,7 @@ uint32_t TQIODeviceTransport::read(uint8_t* buf, uint32_t len) { "read(): underlying QIODevice is not open"); } - actualSize = (uint32_t)std::min((qint64)len, dev_->bytesAvailable()); + actualSize = (uint32_t)(std::min)((qint64)len, dev_->bytesAvailable()); readSize = dev_->read(reinterpret_cast<char*>(buf), actualSize); if (readSize < 0) { diff --git a/lib/cpp/src/thrift/transport/TBufferTransports.h b/lib/cpp/src/thrift/transport/TBufferTransports.h index 53d895fa8..79aace625 100644 --- a/lib/cpp/src/thrift/transport/TBufferTransports.h +++ b/lib/cpp/src/thrift/transport/TBufferTransports.h @@ -449,7 +449,7 @@ private: // Common initialization done by all constructors. void initCommon(uint8_t* buf, uint32_t size, bool owner, uint32_t wPos) { - maxBufferSize_ = std::numeric_limits<uint32_t>::max(); + maxBufferSize_ = (std::numeric_limits<uint32_t>::max)(); if (buf == NULL && size != 0) { assert(owner); diff --git a/lib/cpp/src/thrift/transport/TFileTransport.cpp b/lib/cpp/src/thrift/transport/TFileTransport.cpp index 9c408ac9d..b08a5f16f 100644 --- a/lib/cpp/src/thrift/transport/TFileTransport.cpp +++ b/lib/cpp/src/thrift/transport/TFileTransport.cpp @@ -65,7 +65,6 @@ using stdcxx::shared_ptr; using std::cerr; using std::cout; using std::endl; -using std::min; using std::string; using namespace apache::thrift::protocol; using namespace apache::thrift::concurrency; @@ -705,8 +704,8 @@ eventInfo* TFileTransport::readEvent() { readState_.event_->eventBuffPos_ = 0; } // take either the entire event or the remaining bytes in the buffer - int reclaimBuffer = min((uint32_t)(readState_.bufferLen_ - readState_.bufferPtr_), - readState_.event_->eventSize_ - readState_.event_->eventBuffPos_); + int reclaimBuffer = (std::min)((uint32_t)(readState_.bufferLen_ - readState_.bufferPtr_), + readState_.event_->eventSize_ - readState_.event_->eventBuffPos_); // copy data from read buffer into event buffer memcpy(readState_.event_->eventBuff_ + readState_.event_->eventBuffPos_, diff --git a/lib/cpp/src/thrift/transport/THeaderTransport.cpp b/lib/cpp/src/thrift/transport/THeaderTransport.cpp index 1a687da88..ea16591a9 100644 --- a/lib/cpp/src/thrift/transport/THeaderTransport.cpp +++ b/lib/cpp/src/thrift/transport/THeaderTransport.cpp @@ -511,7 +511,7 @@ void THeaderTransport::flush() { // Pkt size ptrdiff_t szHbp = (headerStart - pktStart - 4); - if (static_cast<uint64_t>(szHbp) > static_cast<uint64_t>(std::numeric_limits<uint32_t>().max()) - (headerSize + haveBytes)) { + if (static_cast<uint64_t>(szHbp) > static_cast<uint64_t>((std::numeric_limits<uint32_t>().max)()) - (headerSize + haveBytes)) { throw TTransportException(TTransportException::CORRUPTED_DATA, "Header section size is unreasonable"); } diff --git a/lib/cpp/test/TMemoryBufferTest.cpp b/lib/cpp/test/TMemoryBufferTest.cpp index 9492f6961..d81b1d804 100644 --- a/lib/cpp/test/TMemoryBufferTest.cpp +++ b/lib/cpp/test/TMemoryBufferTest.cpp @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(test_exceptions) { BOOST_AUTO_TEST_CASE(test_default_maximum_buffer_size) { - BOOST_CHECK_EQUAL(std::numeric_limits<uint32_t>::max(), TMemoryBuffer().getMaxBufferSize()); + BOOST_CHECK_EQUAL((std::numeric_limits<uint32_t>::max)(), TMemoryBuffer().getMaxBufferSize()); } BOOST_AUTO_TEST_CASE(test_default_buffer_size) diff --git a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp index 5ac557ffd..63c8905a5 100644 --- a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp +++ b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp @@ -305,7 +305,7 @@ public: void skip(size_t len) { while (len) { - size_t chunk_size = std::min(len, buffer_used); + size_t chunk_size = (std::min)(len, buffer_used); if (chunk_size) { buffer_ptr = reinterpret_cast<char*>(buffer_ptr) + chunk_size; buffer_used -= chunk_size; @@ -318,7 +318,7 @@ public: void readBytes(void* buf, size_t len) { while (len) { - size_t chunk_size = std::min(len, buffer_used); + size_t chunk_size = (std::min)(len, buffer_used); if (chunk_size) { memcpy(buf, buffer_ptr, chunk_size); buffer_ptr = reinterpret_cast<char*>(buffer_ptr) + chunk_size; diff --git a/lib/py/src/ext/protocol.h b/lib/py/src/ext/protocol.h index 126dbc377..521b7ee92 100644 --- a/lib/py/src/ext/protocol.h +++ b/lib/py/src/ext/protocol.h @@ -33,8 +33,8 @@ class ProtocolBase { public: ProtocolBase() - : stringLimit_(std::numeric_limits<int32_t>::max()), - containerLimit_(std::numeric_limits<int32_t>::max()), + : stringLimit_((std::numeric_limits<int32_t>::max)()), + containerLimit_((std::numeric_limits<int32_t>::max)()), output_(NULL) {} inline virtual ~ProtocolBase(); diff --git a/lib/py/src/ext/protocol.tcc b/lib/py/src/ext/protocol.tcc index c025d0c96..e15df7ea0 100644 --- a/lib/py/src/ext/protocol.tcc +++ b/lib/py/src/ext/protocol.tcc @@ -144,7 +144,7 @@ inline int read_buffer(PyObject* buf, char** output, int len) { *output = PyBytes_AS_STRING(buf2->buf) + buf2->pos; #endif Py_ssize_t pos0 = buf2->pos; - buf2->pos = std::min(buf2->pos + static_cast<Py_ssize_t>(len), buf2->string_size); + buf2->pos = (std::min)(buf2->pos + static_cast<Py_ssize_t>(len), buf2->string_size); return static_cast<int>(buf2->pos - pos0); } } @@ -212,7 +212,7 @@ inline bool check_ssize_t_32(Py_ssize_t len) { if (INT_CONV_ERROR_OCCURRED(len)) { return false; } - if (!CHECK_RANGE(len, 0, std::numeric_limits<int32_t>::max())) { + if (!CHECK_RANGE(len, 0, (std::numeric_limits<int32_t>::max)())) { PyErr_SetString(PyExc_OverflowError, "size out of range: exceeded INT32_MAX"); return false; } @@ -360,8 +360,8 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type case T_I08: { int8_t val; - if (!parse_pyint(value, &val, std::numeric_limits<int8_t>::min(), - std::numeric_limits<int8_t>::max())) { + if (!parse_pyint(value, &val, (std::numeric_limits<int8_t>::min)(), + (std::numeric_limits<int8_t>::max)())) { return false; } @@ -371,8 +371,8 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type case T_I16: { int16_t val; - if (!parse_pyint(value, &val, std::numeric_limits<int16_t>::min(), - std::numeric_limits<int16_t>::max())) { + if (!parse_pyint(value, &val, (std::numeric_limits<int16_t>::min)(), + (std::numeric_limits<int16_t>::max)())) { return false; } @@ -382,8 +382,8 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type case T_I32: { int32_t val; - if (!parse_pyint(value, &val, std::numeric_limits<int32_t>::min(), - std::numeric_limits<int32_t>::max())) { + if (!parse_pyint(value, &val, (std::numeric_limits<int32_t>::min)(), + (std::numeric_limits<int32_t>::max)())) { return false; } @@ -397,8 +397,8 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type return false; } - if (!CHECK_RANGE(nval, std::numeric_limits<int64_t>::min(), - std::numeric_limits<int64_t>::max())) { + if (!CHECK_RANGE(nval, (std::numeric_limits<int64_t>::min)(), + (std::numeric_limits<int64_t>::max)())) { PyErr_SetString(PyExc_OverflowError, "int out of range"); return false; } diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp index 54b43dba8..ca213260e 100644 --- a/test/cpp/src/TestClient.cpp +++ b/test/cpp/src/TestClient.cpp @@ -516,8 +516,8 @@ int main(int argc, char** argv) { BASETYPE_IDENTITY_TEST(testI32, -1); BASETYPE_IDENTITY_TEST(testI32, 190000013); BASETYPE_IDENTITY_TEST(testI32, -190000013); - BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max()); - BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min()); + BASETYPE_IDENTITY_TEST(testI32, (numeric_limits<int32_t>::max)()); + BASETYPE_IDENTITY_TEST(testI32, (numeric_limits<int32_t>::min)()); /** * I64 TEST @@ -530,8 +530,8 @@ int main(int argc, char** argv) { BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32)); BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1); BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1); - BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max()); - BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min()); + BASETYPE_IDENTITY_TEST(testI64, (numeric_limits<int64_t>::max)()); + BASETYPE_IDENTITY_TEST(testI64, (numeric_limits<int64_t>::min)()); /** * DOUBLE TEST |