Skip to content

Commit 8339b3e

Browse files
Add method to py_ref_t to create a new owned reference from a given
reference.
1 parent 7b74b17 commit 8339b3e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

dynd/include/utility_functions.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,18 @@ class py_ref_t {
387387
// Return a wrapped borrowed reference to the wrapped reference.
388388
py_ref_t<false, not_null> borrow() noexcept
389389
{
390+
// Assert that the wrapped pointer is not null if it shouldn't be.
391+
PYDYND_ASSERT_IF(not_null, o != nullptr);
390392
// Assert that the wrapped reference is actually valid if it isn't null.
391393
PYDYND_ASSERT_IF(o != nullptr, Py_REFCNT(o) > 0);
392394
return py_ref_t<false, not_null>(o, false);
393395
}
394396

395397
// Return a wrapped owned reference referring to the currently wrapped reference.
396-
py_ref_t<true, not_null> borrow() noexcept
398+
py_ref_t<true, not_null> new_ownref() noexcept
397399
{
400+
// Assert that the wrapped pointer is not null if it shouldn't be.
401+
PYDYND_ASSERT_IF(not_null, o != nullptr);
398402
// Assert that the wrapped reference is actually valid if it isn't null.
399403
PYDYND_ASSERT_IF(o != nullptr, Py_REFCNT(o) > 0);
400404
return py_ref_t<true, not_null>(o, false);

0 commit comments

Comments
 (0)