Skip to content

Commit

Permalink
Merge pull request #4 from EricCousineau-TRI/feature/unique_ptr_none
Browse files Browse the repository at this point in the history
Handle case if unique_ptr is None / nullptr.
  • Loading branch information
EricCousineau-TRI authored Jan 4, 2018
2 parents 48999b6 + a7df943 commit 012273b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,10 @@ struct move_only_holder_caster : type_caster_base<type> {
}

bool load(handle src, bool /*convert*/) {
if (src.is(none())) {
holder.reset();
return true;
}
// Allow loose reference management (if it's just a plain object) or require tighter reference
// management if it's a move container.
object obj = extract_obj(src);
Expand Down
3 changes: 3 additions & 0 deletions tests/test_smart_ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def test_unique_ptr_arg():
m.unique_ptr_terminal(m.UniquePtrHeld(2))
assert stats.alive() == 0

assert m.unique_ptr_pass_through(None) is None
m.unique_ptr_terminal(None)


def test_unique_ptr_to_shared_ptr():
obj = m.shared_ptr_held_in_unique_ptr()
Expand Down

0 comments on commit 012273b

Please sign in to comment.