Compare commits

..

No commits in common. "51ce483c486ac687171ada5049e8f64aa852eb80" and "37c22653f1de692e4a5f4e5021a7588140a990fb" have entirely different histories.

2 changed files with 5 additions and 6 deletions

View File

@ -10,7 +10,7 @@ struct capsule {
void* ptr;
void (*destructor)(void*);
template <typename T, typename = std::enable_if_t<!(std::is_same_v<remove_cvref_t<T>, capsule>)>>
template <typename T>
capsule(T&& value) :
ptr(new auto(std::forward<T>(value))), destructor([](void* ptr) {
delete static_cast<std::decay_t<T>*>(ptr);
@ -26,7 +26,7 @@ struct capsule {
}
~capsule() {
if(ptr && destructor) destructor(ptr);
if(ptr != nullptr && destructor != nullptr) destructor(ptr);
}
};
} // namespace pybind11::impl

View File

@ -53,7 +53,7 @@ public:
static type of() {
return type_visitor::type<T>();
}
static type of(const handle& obj) { return type(vm->_t(obj.ptr())); }
};
@ -365,9 +365,8 @@ class capsule : public object {
PYBIND11_TYPE_IMPLEMENT(object, impl::capsule, handle(vm->builtins->attr("capsule"))._as<pkpy::Type>());
public:
capsule(void* ptr, void (*destructor)(void*) = nullptr) : object(create(ptr, destructor)) {}
void* data() const { return self().ptr; }
template <typename T>
capsule(T&& value) : object(create(std::forward<T>(value))) {}
template <typename T>
T& cast() const {