Skip to content

Commit eecd3dd

Browse files
committed
Replacing PYBIND11_COMPAT_BOOL_CAST with simpler != 0
1 parent 9db1da9 commit eecd3dd

File tree

5 files changed

+5
-10
lines changed

5 files changed

+5
-10
lines changed

include/pybind11/buffer_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct buffer_info {
8383
view->strides
8484
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
8585
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
86-
PYBIND11_COMPAT_BOOL_CAST(view->readonly)) {
86+
(view->readonly != 0)) {
8787
this->m_view = view;
8888
this->ownview = ownview;
8989
}

include/pybind11/cast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ template <> class type_caster<bool> {
322322
}
323323
#endif
324324
if (res == 0 || res == 1) {
325-
value = PYBIND11_COMPAT_BOOL_CAST(res);
325+
value = (res != 0);
326326
return true;
327327
}
328328
PyErr_Clear();

include/pybind11/detail/common.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ extern "C" {
265265
#define PYBIND11_ENSURE_INTERNALS_READY \
266266
pybind11::detail::get_internals();
267267

268-
// Paying tribute to MSVC 2015 warning
269-
// C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
270-
#define PYBIND11_COMPAT_BOOL_CAST(...) ((__VA_ARGS__) ? true : false)
271-
272268
#define PYBIND11_CHECK_PYTHON_VERSION \
273269
{ \
274270
const char *compiled_ver = PYBIND11_TOSTRING(PY_MAJOR_VERSION) \

include/pybind11/detail/type_caster_base.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ struct value_and_holder {
252252
bool instance_registered() const {
253253
return inst->simple_layout
254254
? inst->simple_instance_registered
255-
: PYBIND11_COMPAT_BOOL_CAST(
256-
inst->nonsimple.status[index] & instance::status_instance_registered);
255+
: (inst->nonsimple.status[index] & instance::status_instance_registered != 0);
257256
}
258257
void set_instance_registered(bool v = true) const {
259258
if (inst->simple_layout)

include/pybind11/pytypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class PYBIND11_EXPORT error_already_set : public std::runtime_error {
368368
/// subclass thereof). May also be passed a tuple to search for any exception class matches in
369369
/// the given tuple.
370370
bool matches(handle exc) const {
371-
return PYBIND11_COMPAT_BOOL_CAST(PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()));
371+
return (PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()) != 0);
372372
}
373373

374374
const object& type() const { return m_type; }
@@ -855,7 +855,7 @@ PYBIND11_NAMESPACE_END(detail)
855855
Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) { } \
856856
Name(handle h, stolen_t) : Parent(h, stolen_t{}) { } \
857857
PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \
858-
bool check() const { return m_ptr != nullptr && PYBIND11_COMPAT_BOOL_CAST(CheckFun(m_ptr)); } \
858+
bool check() const { return m_ptr != nullptr && (CheckFun(m_ptr) != 0); } \
859859
static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } \
860860
template <typename Policy_> \
861861
Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) { }

0 commit comments

Comments
 (0)