From 52f4c3aef37d4a053cc6d0e26678af360c03d58a Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Thu, 3 Mar 2016 14:05:06 +0100 Subject: [PATCH] handle nullptr arguments with custom holder types (fixes #124) --- include/pybind11/cast.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index a9202f6b7..8547f283a 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -500,10 +500,12 @@ public: using type_caster::copy_constructor; bool load(handle src, bool convert) { - if (!src || !typeinfo) + if (!src || !typeinfo) { return false; - - if (PyType_IsSubtype(Py_TYPE(src.ptr()), typeinfo->type)) { + } else if (src.ptr() == Py_None) { + value = nullptr; + return true; + } else if (PyType_IsSubtype(Py_TYPE(src.ptr()), typeinfo->type)) { auto inst = (instance *) src.ptr(); value = inst->value; holder = inst->holder;