Skip to content

Commit

Permalink
fix(smart_holder): Use pybind11_fail instead of assert.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanders committed Nov 7, 2023
1 parent 13105d5 commit 4cdd8bb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions include/pybind11/detail/smart_holder_type_casters.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,20 @@ template <typename T,
typename D,
typename std::enable_if<std::is_default_constructible<D>::value, int>::type = 0>
inline std::unique_ptr<T, D> unique_with_deleter(T *raw_ptr, std::unique_ptr<D> &&deleter) {
if (deleter != nullptr) {
return std::unique_ptr<T, D>(raw_ptr, std::move(*deleter));
if (deleter == nullptr) {
return std::unique_ptr<T, D>(raw_ptr);
}
return std::unique_ptr<T, D>(raw_ptr);
return std::unique_ptr<T, D>(raw_ptr, std::move(*deleter));
}

template <typename T,
typename D,
typename std::enable_if<!std::is_default_constructible<D>::value, int>::type = 0>
inline std::unique_ptr<T, D> unique_with_deleter(T *raw_ptr, std::unique_ptr<D> &&deleter) {
assert(deleter != nullptr);
if (deleter == nullptr) {
pybind11_fail("smart_holder_type_casters: deleter is not default constructible and no"
" instance available to return.");
}
return std::unique_ptr<T, D>(raw_ptr, std::move(*deleter));
}

Expand Down

0 comments on commit 4cdd8bb

Please sign in to comment.