Skip to content

Commit 4cdd8bb

Browse files
committed
fix(smart_holder): Use pybind11_fail instead of assert.
1 parent 13105d5 commit 4cdd8bb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,17 +468,20 @@ template <typename T,
468468
typename D,
469469
typename std::enable_if<std::is_default_constructible<D>::value, int>::type = 0>
470470
inline std::unique_ptr<T, D> unique_with_deleter(T *raw_ptr, std::unique_ptr<D> &&deleter) {
471-
if (deleter != nullptr) {
472-
return std::unique_ptr<T, D>(raw_ptr, std::move(*deleter));
471+
if (deleter == nullptr) {
472+
return std::unique_ptr<T, D>(raw_ptr);
473473
}
474-
return std::unique_ptr<T, D>(raw_ptr);
474+
return std::unique_ptr<T, D>(raw_ptr, std::move(*deleter));
475475
}
476476

477477
template <typename T,
478478
typename D,
479479
typename std::enable_if<!std::is_default_constructible<D>::value, int>::type = 0>
480480
inline std::unique_ptr<T, D> unique_with_deleter(T *raw_ptr, std::unique_ptr<D> &&deleter) {
481-
assert(deleter != nullptr);
481+
if (deleter == nullptr) {
482+
pybind11_fail("smart_holder_type_casters: deleter is not default constructible and no"
483+
" instance available to return.");
484+
}
482485
return std::unique_ptr<T, D>(raw_ptr, std::move(*deleter));
483486
}
484487

0 commit comments

Comments
 (0)