Skip to content

Commit

Permalink
Add method to py_ref_t to copy the current reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
insertinterestingnamehere committed Jun 9, 2016
1 parent 8339b3e commit 6fd66d6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dynd/include/utility_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,16 @@ class py_ref_t {
return py_ref_t<true, not_null>(o, false);
}

// Copy the current reference.
py_ref_t<owns_ref, not_null> copy() noexcept
{
// Assert that the wrapped pointer is not null if it shouldn't be.
PYDYND_ASSERT_IF(not_null, o != nullptr);
// Assert that the wrapped reference is actually valid if it isn't null.
PYDYND_ASSERT_IF(o != nullptr, Py_REFCNT(o) > 0);
return py_ref_t<owns_ref, not_null>(o, false);
}

// Return a reference to the encapsulated PyObject as a raw pointer.
// Set the encapsulated pointer to NULL.
// If this is a type that owns its reference, an owned reference is returned.
Expand Down

0 comments on commit 6fd66d6

Please sign in to comment.