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...)>> {
5454 }
5555 }
5656
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 {
5869 gil_scoped_acquire acq;
59- object retval (func (std::forward<Args>(args)...));
70+ object retval (hfunc. f (std::forward<Args>(args)...));
6071 /* Visual studio 2015 parser issue: need parentheses around this expression */
6172 return (retval.template cast <Return>());
6273 };
You can’t perform that action at this time.
0 commit comments