From 0772967ecfbc3c1cf6260bbc5277c7a2b801cec7 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sat, 26 Mar 2016 20:41:28 +0100 Subject: [PATCH] allow nullptr when passing void* values --- include/pybind11/cast.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 7835561cb..5bc1a679d 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -328,6 +328,10 @@ public: using type_caster::cast; bool load(handle h, bool) { + if (h.ptr() == Py_None) { + value = nullptr; + return true; + } capsule c(h, true); if (!c.check()) return false; @@ -336,8 +340,12 @@ public: } 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; } private: void *value;