45
45
import com .oracle .graal .python .PythonLanguage ;
46
46
import com .oracle .graal .python .builtins .Builtin ;
47
47
import com .oracle .graal .python .builtins .CoreFunctions ;
48
+ import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
48
49
import com .oracle .graal .python .builtins .PythonBuiltins ;
49
50
import com .oracle .graal .python .builtins .objects .PNone ;
51
+ import com .oracle .graal .python .builtins .objects .exception .PBaseException ;
50
52
import com .oracle .graal .python .builtins .objects .frame .PFrame ;
51
53
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
54
+ import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
52
55
import com .oracle .graal .python .nodes .call .CallNode ;
53
56
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
54
57
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
55
58
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
56
59
import com .oracle .graal .python .nodes .function .builtins .PythonVarargsBuiltinNode ;
60
+ import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
57
61
import com .oracle .graal .python .runtime .PythonContext ;
62
+ import com .oracle .graal .python .runtime .exception .ExceptionUtils ;
58
63
import com .oracle .graal .python .runtime .exception .PException ;
59
64
import com .oracle .graal .python .util .PythonUtils ;
60
65
import com .oracle .truffle .api .CompilerDirectives ;
@@ -76,12 +81,12 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
76
81
@ Builtin (name = "register" , minNumOfPositionalArgs = 1 , takesVarArgs = true , takesVarKeywordArgs = true )
77
82
@ GenerateNodeFactory
78
83
abstract static class RegisterNode extends PythonVarargsBuiltinNode {
79
- private static class AtExitCallTarget extends RootNode {
84
+ private static class AtExitRootNode extends RootNode {
80
85
@ Child private CallNode callNode = CallNode .create ();
81
86
82
87
private final ContextReference <PythonContext > contextRef = lookupContextReference (PythonLanguage .class );
83
88
84
- protected AtExitCallTarget (TruffleLanguage <?> language ) {
89
+ protected AtExitRootNode (TruffleLanguage <?> language ) {
85
90
super (language );
86
91
}
87
92
@@ -100,6 +105,14 @@ public Object execute(VirtualFrame frame) {
100
105
// from the context.
101
106
try {
102
107
return callNode .execute (null , callable , arguments , keywords );
108
+ } catch (PException e ) {
109
+ PBaseException pythonException = e .getEscapedException ();
110
+ PythonObjectLibrary lib = PythonObjectLibrary .getUncached ();
111
+ if (!IsBuiltinClassProfile .profileClassSlowPath (lib .getLazyPythonClass (pythonException ), PythonBuiltinClassType .SystemExit )) {
112
+ lib .lookupAndCallRegularMethod (context .getCore ().getStderr (), null , "write" , "Error in atexit._run_exitfuncs:\n " );
113
+ ExceptionUtils .printExceptionTraceback (context , pythonException );
114
+ }
115
+ throw e ;
103
116
} finally {
104
117
context .popTopFrameInfo ();
105
118
context .setCaughtException (null );
@@ -110,8 +123,8 @@ public Object execute(VirtualFrame frame) {
110
123
@ Specialization
111
124
Object register (Object callable , Object [] arguments , PKeyword [] keywords ) {
112
125
CompilerDirectives .transferToInterpreter ();
113
- AtExitCallTarget atExitCallTarget = new AtExitCallTarget (getContext ().getLanguage ());
114
- getContext ().registerAtexitHook (callable , arguments , keywords , PythonUtils .getOrCreateCallTarget (atExitCallTarget ));
126
+ AtExitRootNode atExitRootNode = new AtExitRootNode (getContext ().getLanguage ());
127
+ getContext ().registerAtexitHook (callable , arguments , keywords , PythonUtils .getOrCreateCallTarget (atExitRootNode ));
115
128
return callable ;
116
129
}
117
130
}
0 commit comments