Skip to content

Commit 689cb12

Browse files
committed
better?
1 parent b4e4ada commit 689cb12

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

include/pybind11/cast.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,7 @@ template <typename... Ts> class type_caster<std::tuple<Ts...>>
13711371
template <typename T>
13721372
struct holder_helper {
13731373
static auto get(const T &p) -> decltype(p.get()) { return p.get(); }
1374+
static void release(T &p) { p.release(); }
13741375
};
13751376

13761377
/// Type caster for holder types like std::shared_ptr, etc.

include/pybind11/pybind11.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,15 +1516,18 @@ inline void consume_impl(handle consumed) {
15161516
if (consumed.is_none())
15171517
return; /* Nothing to consume */
15181518

1519-
// auto tinfo = all_type_info(Py_TYPE(consumed.ptr())); // ???
1519+
auto inst = reinterpret_cast<detail::instance *>(consumed.ptr());
1520+
auto value_and_holder = values_and_holders(inst).begin();
15201521

1521-
//consumed.dec_ref(); ???
15221522

1523-
// del the name of consumed from the Python scope somehow ...
15241523

1525-
auto inst = reinterpret_cast<detail::instance *>(consumed.ptr());
1526-
auto &holder = values_and_holders(inst).begin()->holder< std::unique_ptr <void*> >(); // holder_type ???
1527-
holder.release();
1524+
auto &holder = value_and_holder->holder< std::unique_ptr<void*> >(); // holder_type ???
1525+
1526+
1527+
holder_helper<std::unique_ptr<void*>>::release(holder);
1528+
1529+
value_and_holder->set_holder_constructed(false);
1530+
inst->owned = false;
15281531
}
15291532

15301533
PYBIND11_NOINLINE inline void consume_impl(size_t Consumed, function_call &call) {

0 commit comments

Comments
 (0)