42
42
43
43
import java .util .List ;
44
44
45
+ import com .oracle .graal .python .PythonLanguage ;
45
46
import com .oracle .graal .python .builtins .Builtin ;
46
47
import com .oracle .graal .python .builtins .CoreFunctions ;
47
48
import com .oracle .graal .python .builtins .PythonBuiltins ;
48
49
import com .oracle .graal .python .builtins .objects .PNone ;
49
50
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
51
+ import com .oracle .graal .python .nodes .PNodeWithGlobalState ;
52
+ import com .oracle .graal .python .nodes .PNodeWithGlobalState .DefaultContextManager ;
50
53
import com .oracle .graal .python .nodes .call .CallNode ;
51
54
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
52
55
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
53
56
import com .oracle .graal .python .nodes .function .builtins .PythonVarargsBuiltinNode ;
57
+ import com .oracle .graal .python .runtime .PythonContext ;
58
+ import com .oracle .graal .python .runtime .exception .PException ;
54
59
import com .oracle .truffle .api .Truffle ;
55
60
import com .oracle .truffle .api .TruffleLanguage ;
61
+ import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
56
62
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
57
63
import com .oracle .truffle .api .dsl .NodeFactory ;
58
64
import com .oracle .truffle .api .dsl .Specialization ;
@@ -70,7 +76,10 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
70
76
@ GenerateNodeFactory
71
77
abstract static class RegisterNode extends PythonVarargsBuiltinNode {
72
78
private static class AtExitCallTarget extends RootNode {
73
- @ Child CallNode callNode = CallNode .create ();
79
+ @ Child private CallNode callNode = CallNode .create ();
80
+
81
+ private final ContextReference <PythonContext > contextRef = lookupContextReference (PythonLanguage .class );
82
+
74
83
private Object callable ;
75
84
private Object [] arguments ;
76
85
private PKeyword [] keywords ;
@@ -83,8 +92,12 @@ protected AtExitCallTarget(TruffleLanguage<?> language, Object callable, Object[
83
92
}
84
93
85
94
@ Override
95
+ @ SuppressWarnings ("try" )
86
96
public Object execute (VirtualFrame frame ) {
87
- return callNode .execute (frame , callable , arguments , keywords );
97
+ // we deliberately pass 'null' frame here
98
+ try (DefaultContextManager cm = PNodeWithGlobalState .transferToContext (contextRef , PException .NO_EXCEPTION )) {
99
+ return callNode .execute (null , callable , arguments , keywords );
100
+ }
88
101
}
89
102
}
90
103
0 commit comments