mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
Compare commits
4 Commits
37c22653f1
...
51ce483c48
Author | SHA1 | Date | |
---|---|---|---|
|
51ce483c48 | ||
|
f803a7eca6 | ||
|
8d0e304ecd | ||
|
901cf714a2 |
@ -10,7 +10,7 @@ struct capsule {
|
|||||||
void* ptr;
|
void* ptr;
|
||||||
void (*destructor)(void*);
|
void (*destructor)(void*);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename = std::enable_if_t<!(std::is_same_v<remove_cvref_t<T>, capsule>)>>
|
||||||
capsule(T&& value) :
|
capsule(T&& value) :
|
||||||
ptr(new auto(std::forward<T>(value))), destructor([](void* ptr) {
|
ptr(new auto(std::forward<T>(value))), destructor([](void* ptr) {
|
||||||
delete static_cast<std::decay_t<T>*>(ptr);
|
delete static_cast<std::decay_t<T>*>(ptr);
|
||||||
@ -26,7 +26,7 @@ struct capsule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
~capsule() {
|
~capsule() {
|
||||||
if(ptr != nullptr && destructor != nullptr) destructor(ptr);
|
if(ptr && destructor) destructor(ptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace pybind11::impl
|
} // namespace pybind11::impl
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
static type of() {
|
static type of() {
|
||||||
return type_visitor::type<T>();
|
return type_visitor::type<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static type of(const handle& obj) { return type(vm->_t(obj.ptr())); }
|
static type of(const handle& obj) { return type(vm->_t(obj.ptr())); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -365,8 +365,9 @@ class capsule : public object {
|
|||||||
PYBIND11_TYPE_IMPLEMENT(object, impl::capsule, handle(vm->builtins->attr("capsule"))._as<pkpy::Type>());
|
PYBIND11_TYPE_IMPLEMENT(object, impl::capsule, handle(vm->builtins->attr("capsule"))._as<pkpy::Type>());
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
capsule(void* ptr, void (*destructor)(void*) = nullptr) : object(create(ptr, destructor)) {}
|
||||||
capsule(T&& value) : object(create(std::forward<T>(value))) {}
|
|
||||||
|
void* data() const { return self().ptr; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T& cast() const {
|
T& cast() const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user