File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -54,9 +54,20 @@ struct type_caster<std::function<Return(Args...)>> {
54
54
}
55
55
}
56
56
57
- value = [func](Args... args) -> Return {
57
+ // 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 {
58
69
gil_scoped_acquire acq;
59
- object retval (func (std::forward<Args>(args)...));
70
+ object retval (hfunc. f (std::forward<Args>(args)...));
60
71
/* Visual studio 2015 parser issue: need parentheses around this expression */
61
72
return (retval.template cast <Return>());
62
73
};
You can’t perform that action at this time.
0 commit comments