}
}
- value = [func](Args... args) -> Return {
- gil_scoped_acquire acq;
- object retval(func(std::forward<Args>(args)...));
- /* Visual studio 2015 parser issue: need parentheses around this expression */
- return (retval.template cast<Return>());
+ // ensure GIL is held during functor destruction
+ struct func_handle {
+ function f;
+ func_handle(function&& f_) : f(std::move(f_)) {}
+ func_handle(const func_handle&) = default;
+ ~func_handle() {
+ gil_scoped_acquire acq;
+ function kill_f(std::move(f));
+ }
};
+
+ // to emulate 'move initialization capture' in C++11
+ struct func_wrapper {
+ func_handle hfunc;
+ func_wrapper(func_handle&& hf): hfunc(std::move(hf)) {}
+ Return operator()(Args... args) const {
+ gil_scoped_acquire acq;
+ object retval(hfunc.f(std::forward<Args>(args)...));
+ /* Visual studio 2015 parser issue: need parentheses around this expression */
+ return (retval.template cast<Return>());
+ }
+ };
+
+ value = func_wrapper(func_handle(std::move(func)));
return true;
}
return cpp_function(std::forward<Func>(f_), policy).release();
}
- PYBIND11_TYPE_CASTER(type, _("Callable[[") +
- argument_loader<Args...>::arg_names() + _("], ") +
- make_caster<retval_type>::name() +
- _("]"));
+ PYBIND11_TYPE_CASTER(type, _("Callable[[") + concat(make_caster<Args>::name...) + _("], ")
+ + make_caster<retval_type>::name + _("]"));
};
NAMESPACE_END(detail)