Commit 9b3fb053 by Nathan Committed by Wenzel Jakob

Allow Windows.h min/max to coexist with pybind11 (#1847)

* Protect std::min/max functions from windows.h min/max
Removed check for windows min/max
parent b2c4ff60
...@@ -995,9 +995,11 @@ public: ...@@ -995,9 +995,11 @@ public:
} }
bool py_err = py_value == (py_type) -1 && PyErr_Occurred(); bool py_err = py_value == (py_type) -1 && PyErr_Occurred();
// Protect std::numeric_limits::min/max with parentheses
if (py_err || (std::is_integral<T>::value && sizeof(py_type) != sizeof(T) && if (py_err || (std::is_integral<T>::value && sizeof(py_type) != sizeof(T) &&
(py_value < (py_type) std::numeric_limits<T>::min() || (py_value < (py_type) (std::numeric_limits<T>::min)() ||
py_value > (py_type) std::numeric_limits<T>::max()))) { py_value > (py_type) (std::numeric_limits<T>::max)()))) {
bool type_error = py_err && PyErr_ExceptionMatches( bool type_error = py_err && PyErr_ExceptionMatches(
#if PY_VERSION_HEX < 0x03000000 && !defined(PYPY_VERSION) #if PY_VERSION_HEX < 0x03000000 && !defined(PYPY_VERSION)
PyExc_SystemError PyExc_SystemError
......
...@@ -113,10 +113,6 @@ ...@@ -113,10 +113,6 @@
#include <frameobject.h> #include <frameobject.h>
#include <pythread.h> #include <pythread.h>
#if defined(_WIN32) && (defined(min) || defined(max))
# error Macro clash with min and max -- define NOMINMAX when compiling your program on Windows
#endif
#if defined(isalnum) #if defined(isalnum)
# undef isalnum # undef isalnum
# undef isalpha # undef isalpha
......
...@@ -495,7 +495,7 @@ protected: ...@@ -495,7 +495,7 @@ protected:
function_call call(func, parent); function_call call(func, parent);
size_t args_to_copy = std::min(pos_args, n_args_in); size_t args_to_copy = (std::min)(pos_args, n_args_in); // Protect std::min with parentheses
size_t args_copied = 0; size_t args_copied = 0;
// 0. Inject new-style `self` argument // 0. Inject new-style `self` argument
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment