Skip to content

Commit 3c92b9f

Browse files
committed
Return None for nullptr
1 parent ba2e131 commit 3c92b9f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
623623
static constexpr auto name = _<std::shared_ptr<T>>();
624624

625625
static handle cast(const std::shared_ptr<T> &src, return_value_policy policy, handle parent) {
626+
if (!src)
627+
return none().release();
628+
626629
auto src_raw_ptr = src.get();
627630
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);
628631
if (st.second == nullptr)
@@ -687,6 +690,8 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
687690
// SMART_HOLDER_WIP: IMPROVABLE: Error message.
688691
throw cast_error("Invalid return_value_policy for unique_ptr.");
689692
}
693+
if (!src)
694+
return none().release();
690695

691696
auto src_raw_ptr = src.get();
692697
auto st = type_caster_base<T>::src_and_type(src_raw_ptr);

0 commit comments

Comments
 (0)