Skip to content

Commit df3775b

Browse files
Adds set_name method of pybind11::capsule class
This calls PyCapsule_SetName on the underlying capsule object.
1 parent ad0de0f commit df3775b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

include/pybind11/pytypes.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,13 @@ class capsule : public object {
16381638
}
16391639

16401640
const char *name() const { return PyCapsule_GetName(m_ptr); }
1641+
1642+
/// Replaces a capsule's name *without* calling the destructor on the existing one.
1643+
void set_name(const char * &new_name) {
1644+
if (PyCapsule_SetName(m_ptr, new_name) != 0) {
1645+
throw error_already_set();
1646+
}
1647+
}
16411648
};
16421649

16431650
class tuple : public object {

0 commit comments

Comments
 (0)