Skip to content

Commit ba2e131

Browse files
committed
Correctly report casting error
It is important to return an empty handle. Simply returning None, would skip the error handling in simple_collector / unpacking_collector, although a python exception is set. A function call would then be processed with a (wrong) None argument!
1 parent 7cf53ae commit ba2e131

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
625625
static handle cast(const std::shared_ptr<T> &src, return_value_policy policy, handle parent) {
626626
auto src_raw_ptr = src.get();
627627
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
628-
if (st.first == nullptr)
629-
return none().release(); // PyErr was set already.
628+
if (st.second == nullptr)
629+
return handle(); // no type info: error will be set already
630630

631631
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
632632
const detail::type_info *tinfo = st.second;
@@ -690,8 +690,8 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
690690

691691
auto src_raw_ptr = src.get();
692692
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
693-
if (st.first == nullptr)
694-
return none().release(); // PyErr was set already.
693+
if (st.second == nullptr)
694+
return handle(); // no type info: error will be set already
695695

696696
void *src_raw_void_ptr = static_cast<void *>(src_raw_ptr);
697697
const detail::type_info *tinfo = st.second;

0 commit comments

Comments
 (0)