Skip to content

Commit 770c4f7

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 770c4f7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/pybind11/detail/smart_holder_type_casters.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
626626
auto src_raw_ptr = src.get();
627627
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
628628
if (st.first == nullptr)
629-
return none().release(); // PyErr was set already.
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)