THRIFT-4680: fix up std::min, std::max, and numeric limits min/max on Windows; remove NOMINMAX from cmake build

This commit is contained in:
James E. King III 2018-12-17 16:21:14 -05:00
parent 56ac72e74a
commit 9b75e4fe74
11 changed files with 25 additions and 29 deletions

View File

@ -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")

View File

@ -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;
}

View File

@ -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) {

View File

@ -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);

View File

@ -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_,

View File

@ -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");
}

View File

@ -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)

View File

@ -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;

View File

@ -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();

View File

@ -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;
}

View File

@ -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