File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1721,6 +1721,24 @@ struct move_only_holder_caster : type_caster_base<type> {
17211721 }
17221722
17231723 holder_type holder;
1724+
1725+ // N.B. We have to use this weird `holder_transaction` struct because
1726+ // trying to introduce a destructor in `move_only_holder_caster` confuses
1727+ // the compiler, and makes it think it's copying the caster...
1728+ struct holder_transaction {
1729+ holder_type& holder;
1730+ holder_transaction () = default ;
1731+ ~holder_transaction () {
1732+ if (holder) {
1733+ // If the argument was loaded into C++, but not transferred out,
1734+ // then this was most likely part of a failed overload in
1735+ // `argument_loader`. Transfer ownership back to Python.
1736+ move_only_holder_caster::cast (
1737+ std::move (holder), return_value_policy{}, handle{});
1738+ }
1739+ }
1740+ };
1741+ holder_transaction transaction{holder};
17241742};
17251743
17261744template <typename type, typename deleter>
You can’t perform that action at this time.
0 commit comments