We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bdc79fc commit 296627bCopy full SHA for 296627b
include/pybind11/functional.h
@@ -54,9 +54,20 @@ struct type_caster<std::function<Return(Args...)>> {
54
}
55
56
57
- value = [func](Args... args) -> Return {
+ // ensure GIL is held during functor destruction
58
+ struct func_handle {
59
+ function f;
60
+ func_handle(function&& f_) : f(std::move(f_)) {}
61
+ func_handle(const func_handle&) = default;
62
+ ~func_handle() {
63
+ gil_scoped_acquire acq;
64
+ function kill_f(std::move(f));
65
+ }
66
+ };
67
+
68
+ value = [hfunc = func_handle(std::move(func))](Args... args) -> Return {
69
gil_scoped_acquire acq;
- object retval(func(std::forward<Args>(args)...));
70
+ object retval(hfunc.f(std::forward<Args>(args)...));
71
/* Visual studio 2015 parser issue: need parentheses around this expression */
72
return (retval.template cast<Return>());
73
};
0 commit comments