From fae9f1b52f7dcbba3ee751cb4add4560620bebd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 16 May 2020 17:37:41 +0200 Subject: [PATCH] Allow None value from python in functor converter. --- src/runner/converters.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/runner/converters.h b/src/runner/converters.h index b5fe206..9eba894 100644 --- a/src/runner/converters.h +++ b/src/runner/converters.h @@ -368,6 +368,12 @@ namespace utils { static void* convertible(PyObject* object) { + // We allow None here, we will just default-construct a std::function: + if (object == Py_None) { + return object; + } + + // Otherwize we check that we have a callable object: if (!PyCallable_Check(object) || !has_arity(object, sizeof...(PARAMS))) { return nullptr; } @@ -377,12 +383,19 @@ namespace utils { static void construct(PyObject* object, bpy::converter::rvalue_from_python_stage1_data* data) { bpy::object callable(bpy::handle<>(bpy::borrowed(object))); - void* storage = ((bpy::converter::rvalue_from_python_storage>*)data)->storage.bytes; - new (storage) std::function(FunctorWrapper(callable)); + void* storage =((bpy::converter::rvalue_from_python_storage>*)data)->storage.bytes; + if (callable.is_none()) { + new (storage) std::function{}; + } + else { + new (storage) std::function(FunctorWrapper(callable)); + } data->convertible = storage; } }; + + /** * @brief Call policy that automatically downcast shared pointer of type FromType * to shared pointer of type ToType.