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.
This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-10-12 15:43:43 -07:00 committed by GitHub
parent 8781daf6e6
commit 964c49978f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1809,16 +1809,16 @@ public:
explicit capsule(const void *value, explicit capsule(const void *value,
const char *name = nullptr, const char *name = nullptr,
void (*destructor)(PyObject *) = nullptr) PyCapsule_Destructor destructor = nullptr)
: object(PyCapsule_New(const_cast<void *>(value), name, destructor), stolen_t{}) { : object(PyCapsule_New(const_cast<void *>(value), name, destructor), stolen_t{}) {
if (!m_ptr) { if (!m_ptr) {
throw error_already_set(); throw error_already_set();
} }
} }
PYBIND11_DEPRECATED("Please pass a destructor that takes a void pointer as input") PYBIND11_DEPRECATED("Please use the ctor with value, name, destructor args")
capsule(const void *value, void (*destruct)(PyObject *)) capsule(const void *value, PyCapsule_Destructor destructor)
: object(PyCapsule_New(const_cast<void *>(value), nullptr, destruct), stolen_t{}) { : object(PyCapsule_New(const_cast<void *>(value), nullptr, destructor), stolen_t{}) {
if (!m_ptr) { if (!m_ptr) {
throw error_already_set(); throw error_already_set();
} }