Skip to content

Commit

Permalink
modified destructors to query capsules's Name
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-pavlyk committed Apr 12, 2022
1 parent df3775b commit cefbd50
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ class capsule : public object {
}
pybind11_fail("Unable to get capsule context");
}
void *ptr = PyCapsule_GetPointer(o, nullptr);
void *ptr = PyCapsule_GetPointer(o, PyCapsule_GetName(o));
if (ptr == nullptr) {
throw error_already_set();
}
Expand All @@ -1602,7 +1602,7 @@ class capsule : public object {

explicit capsule(void (*destructor)()) {
m_ptr = PyCapsule_New(reinterpret_cast<void *>(destructor), nullptr, [](PyObject *o) {
auto destructor = reinterpret_cast<void (*)()>(PyCapsule_GetPointer(o, nullptr));
auto destructor = reinterpret_cast<void (*)()>(PyCapsule_GetPointer(o, PyCapsule_GetName(o)));
if (destructor == nullptr) {
throw error_already_set();
}
Expand Down Expand Up @@ -1640,7 +1640,7 @@ class capsule : public object {
const char *name() const { return PyCapsule_GetName(m_ptr); }

/// Replaces a capsule's name *without* calling the destructor on the existing one.
void set_name(const char * &new_name) {
void set_name(const char *&new_name) {
if (PyCapsule_SetName(m_ptr, new_name) != 0) {
throw error_already_set();
}
Expand Down

0 comments on commit cefbd50

Please sign in to comment.