handle nullptr arguments with custom holder types (fixes #124)

This commit is contained in:
Wenzel Jakob 2016-03-03 14:05:06 +01:00
parent c769fce280
commit 52f4c3aef3

View File

@ -500,10 +500,12 @@ public:
using type_caster<type>::copy_constructor; using type_caster<type>::copy_constructor;
bool load(handle src, bool convert) { bool load(handle src, bool convert) {
if (!src || !typeinfo) if (!src || !typeinfo) {
return false; return false;
} else if (src.ptr() == Py_None) {
if (PyType_IsSubtype(Py_TYPE(src.ptr()), typeinfo->type)) { value = nullptr;
return true;
} else if (PyType_IsSubtype(Py_TYPE(src.ptr()), typeinfo->type)) {
auto inst = (instance<type, holder_type> *) src.ptr(); auto inst = (instance<type, holder_type> *) src.ptr();
value = inst->value; value = inst->value;
holder = inst->holder; holder = inst->holder;