diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 0adb0758b3c..77a69b6f304 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -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(); } @@ -1602,7 +1602,7 @@ class capsule : public object { explicit capsule(void (*destructor)()) { m_ptr = PyCapsule_New(reinterpret_cast(destructor), nullptr, [](PyObject *o) { - auto destructor = reinterpret_cast(PyCapsule_GetPointer(o, nullptr)); + auto destructor = reinterpret_cast(PyCapsule_GetPointer(o, PyCapsule_GetName(o))); if (destructor == nullptr) { throw error_already_set(); } @@ -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(); }