Skip to content

Commit eb05f97

Browse files
committed
Remove SFINEA deleter assignment.
At the construction of the smart holder, it is either a del_fun, or a default constructed deleter, so this complexity is unnecessary.
1 parent a49a7ce commit eb05f97

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -464,29 +464,6 @@ struct shared_ptr_trampoline_self_life_support {
464464
}
465465
};
466466

467-
template <typename D, bool>
468-
struct delete_assigner {
469-
static void assign(D &, bool, std::function<void(void *)> &, void (*)(void *) &) {
470-
// Situation where the deleter cannot be assigned from either del_fun or del_ptr.
471-
// This covers the default deleters and the like.
472-
}
473-
};
474-
475-
template <typename D>
476-
struct delete_assigner<D, true> {
477-
static void assign(D &deleter,
478-
bool use_del_fun,
479-
std::function<void(void *)> &del_fun,
480-
void (*del_ptr)(void *) &) {
481-
// Situation where D is assignable from del_fun.
482-
if (use_del_fun) {
483-
deleter = std::move(del_fun);
484-
} else {
485-
deleter = del_ptr;
486-
}
487-
}
488-
};
489-
490467
template <typename T>
491468
struct smart_holder_type_caster_load {
492469
using holder_type = pybindit::memory::smart_holder;
@@ -639,18 +616,16 @@ struct smart_holder_type_caster_load {
639616
"instance cannot safely be transferred to C++.");
640617
}
641618

642-
// Need to extract the deleter from the holder such that it can be passed back to the
643-
// unique pointer.
644-
645-
// Temporary variable to store the extracted deleter in.
619+
// Default constructed temporary variable to store the extracted deleter in.
646620
D extracted_deleter;
647621

648-
// In smart_holder_poc, the deleter is always stored in a guarded delete.
649-
// The guarded delete's std::function<void(void*)> actually points at the custom_deleter
650-
// type, so we can verify it is of the custom deleter type and finally extract its deleter.
651622
auto *gd = std::get_deleter<pybindit::memory::guarded_delete>(holder().vptr);
652623
if (gd) {
653624
if (gd->use_del_fun) {
625+
// In smart_holder_poc, a custom deleter is always stored in a guarded delete.
626+
// The guarded delete's std::function<void(void*)> actually points at the
627+
// custom_deleter type, so we can verify it is of the custom deleter type and
628+
// finally extract its deleter.
654629
using custom_deleter_D = pybindit::memory::custom_deleter<T, D>;
655630
const auto &custom_deleter_ptr = gd->del_fun.template target<custom_deleter_D>();
656631
if (!custom_deleter_ptr) {
@@ -661,14 +636,9 @@ struct smart_holder_type_caster_load {
661636
// value we can extract the function.
662637
extracted_deleter = std::move(custom_deleter_ptr->deleter);
663638
} else {
664-
// The del_ptr attribute of the guarded deleter does not provide any type
665-
// information that can be used to confirm it is convertible to D. SFINEA here is
666-
// necessary to ensure that if D is not constructible from a void(void*) pointer,
667-
// it does not cause compilation failures. If this hits an non-convertible type at
668-
// compile time it throws.
669-
constexpr bool assignable = std::is_constructible<D, decltype(gd->del_fun)>::value;
670-
delete_assigner<D, assignable>::assign(
671-
extracted_deleter, gd->use_del_fun, gd->del_fun, gd->del_ptr);
639+
// Not sure if anything needs to be done here. In general, if the del function is
640+
// used a default destructor is used which should be accomodated by the type of the
641+
// deleter used in the returned unique ptr.
672642
}
673643
}
674644

0 commit comments

Comments
 (0)