mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 15:20:34 +00:00
allow nullptr when passing void* values
This commit is contained in:
parent
de1bca864e
commit
0772967ecf
@ -328,6 +328,10 @@ public:
|
|||||||
using type_caster<void_type>::cast;
|
using type_caster<void_type>::cast;
|
||||||
|
|
||||||
bool load(handle h, bool) {
|
bool load(handle h, bool) {
|
||||||
|
if (h.ptr() == Py_None) {
|
||||||
|
value = nullptr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
capsule c(h, true);
|
capsule c(h, true);
|
||||||
if (!c.check())
|
if (!c.check())
|
||||||
return false;
|
return false;
|
||||||
@ -336,8 +340,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static handle cast(void *ptr, return_value_policy /* policy */, handle /* parent */) {
|
static handle cast(void *ptr, return_value_policy /* policy */, handle /* parent */) {
|
||||||
return capsule(ptr).inc_ref();
|
if (ptr)
|
||||||
|
return capsule(ptr).release();
|
||||||
|
else
|
||||||
|
return handle(Py_None).inc_ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
operator void *() { return value; }
|
operator void *() { return value; }
|
||||||
private:
|
private:
|
||||||
void *value;
|
void *value;
|
||||||
|
Loading…
Reference in New Issue
Block a user