diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index f7ba896b7..5ee55c118 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -389,7 +389,7 @@ public: return true; } - static handle cast(void *ptr, return_value_policy /* policy */, handle /* parent */) { + static handle cast(const void *ptr, return_value_policy /* policy */, handle /* parent */) { if (ptr) return capsule(ptr).release(); else diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index a300dd5d1..c9eaa40ec 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -451,8 +451,8 @@ class capsule : public object { public: PYBIND11_OBJECT_DEFAULT(capsule, object, PyCapsule_CheckExact) capsule(PyObject *obj, bool borrowed) : object(obj, borrowed) { } - capsule(void *value, void (*destruct)(PyObject *) = nullptr) - : object(PyCapsule_New(value, nullptr, destruct), false) { + capsule(const void *value, void (*destruct)(PyObject *) = nullptr) + : object(PyCapsule_New(const_cast(value), nullptr, destruct), false) { if (!m_ptr) pybind11_fail("Could not allocate capsule object!"); } template operator T *() const {