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