Skip to content

Commit

Permalink
THRIFT-4680: fix up std::min, std::max, and numeric limits min/max on…
Browse files Browse the repository at this point in the history
… Windows; remove NOMINMAX from cmake build
  • Loading branch information
jeking3 committed Dec 18, 2018
1 parent 56ac72e commit 9b75e4f
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 29 deletions.
3 changes: 0 additions & 3 deletions build/cmake/DefinePlatformSpecifc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion compiler/cpp/src/thrift/generate/t_go_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/cpp/src/thrift/transport/TBufferTransports.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class TMemoryBuffer : public TVirtualTransport<TMemoryBuffer, TBufferBase> {
// 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);
Expand Down
5 changes: 2 additions & 3 deletions lib/cpp/src/thrift/transport/TFileTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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_,
Expand Down
2 changes: 1 addition & 1 deletion lib/cpp/src/thrift/transport/THeaderTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cpp/test/TMemoryBufferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class PHPInputTransport : public PHPTransport {

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;
Expand All @@ -318,7 +318,7 @@ class PHPInputTransport : public PHPTransport {

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;
Expand Down
4 changes: 2 additions & 2 deletions lib/py/src/ext/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
20 changes: 10 additions & 10 deletions lib/py/src/ext/protocol.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

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

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

Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions test/cpp/src/TestClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9b75e4f

Please sign in to comment.