diff --git a/dynd/include/utility_functions.hpp b/dynd/include/utility_functions.hpp index f3b1e8b1..d17d69b1 100644 --- a/dynd/include/utility_functions.hpp +++ b/dynd/include/utility_functions.hpp @@ -404,6 +404,16 @@ class py_ref_t { return py_ref_t(o, false); } + // Copy the current reference. + py_ref_t 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(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.