Skip to content

Commit 6fb4849

Browse files
author
Wenzel Jakob
committed
fix crash when None is passed to enum::operator==
1 parent 9059bd8 commit 6fb4849

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/pybind11/pybind11.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ class cpp_function : public function {
409409
}
410410
}
411411
}
412-
413412
if (kwargs_consumed == nkwargs)
414413
result = it->impl(it, args_, parent);
415414

@@ -937,10 +936,11 @@ template <typename Type> class enum_ : public class_<Type> {
937936
((it == entries->end()) ? std::string("???")
938937
: std::string(it->second));
939938
});
940-
this->def("__init__", [](Type& value, int i) { value = (Type) i; });
939+
this->def("__init__", [](Type& value, int i) { value = (Type)i; });
940+
this->def("__init__", [](Type& value, int i) { new (&value) Type((Type) i); });
941941
this->def("__int__", [](Type value) { return (int) value; });
942-
this->def("__eq__", [](const Type &value, Type value2) { return value == value2; });
943-
this->def("__ne__", [](const Type &value, Type value2) { return value != value2; });
942+
this->def("__eq__", [](const Type &value, Type *value2) { return value2 && value == *value2; });
943+
this->def("__ne__", [](const Type &value, Type *value2) { return !value2 || value != *value2; });
944944
this->def("__hash__", [](const Type &value) { return (int) value; });
945945
m_entries = entries;
946946
}

0 commit comments

Comments
 (0)