Skip to content

Commit 964c499

Browse files
authored
Minor py::capsule cleanup. No functional change. (#4238)
Use `PyCapsule_Destructor` (part of the stable Python ABI) instead of spelling out the C `typedef`. The deprecation message is misleading. Replace with a message pointing to another existing ctor. Background: According to @wjakob the original motivation for deprecating the ctor (in PR #752) was to hide Python C API details, but PR #902 brought those back with a new ctor, it cannot be avoided. Having a `PyCapsule_Destructor` or a `void (*destructor)(void *)` are two separate and valid use cases.
1 parent 8781daf commit 964c499

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/pybind11/pytypes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,16 +1809,16 @@ class capsule : public object {
18091809

18101810
explicit capsule(const void *value,
18111811
const char *name = nullptr,
1812-
void (*destructor)(PyObject *) = nullptr)
1812+
PyCapsule_Destructor destructor = nullptr)
18131813
: object(PyCapsule_New(const_cast<void *>(value), name, destructor), stolen_t{}) {
18141814
if (!m_ptr) {
18151815
throw error_already_set();
18161816
}
18171817
}
18181818

1819-
PYBIND11_DEPRECATED("Please pass a destructor that takes a void pointer as input")
1820-
capsule(const void *value, void (*destruct)(PyObject *))
1821-
: object(PyCapsule_New(const_cast<void *>(value), nullptr, destruct), stolen_t{}) {
1819+
PYBIND11_DEPRECATED("Please use the ctor with value, name, destructor args")
1820+
capsule(const void *value, PyCapsule_Destructor destructor)
1821+
: object(PyCapsule_New(const_cast<void *>(value), nullptr, destructor), stolen_t{}) {
18221822
if (!m_ptr) {
18231823
throw error_already_set();
18241824
}

0 commit comments

Comments
 (0)