45
45
import static com .oracle .graal .python .builtins .modules .io .IONodes .FLUSH ;
46
46
import static com .oracle .graal .python .builtins .modules .io .IONodes .WRITE ;
47
47
import static com .oracle .graal .python .nodes .BuiltinNames .BUILTINS ;
48
- import static com .oracle .graal .python .nodes .SpecialAttributeNames .STDERR ;
49
- import static com .oracle .graal .python .nodes .SpecialAttributeNames .STDIN ;
50
- import static com .oracle .graal .python .nodes .SpecialAttributeNames .STDOUT ;
51
- import static com .oracle .graal .python .nodes .SpecialAttributeNames .__EXCEPTHOOK__ ;
48
+ import static com .oracle .graal .python .nodes .BuiltinNames .EXCEPTHOOK ;
49
+ import static com .oracle .graal .python .nodes .BuiltinNames .STDERR ;
50
+ import static com .oracle .graal .python .nodes .BuiltinNames .STDIN ;
51
+ import static com .oracle .graal .python .nodes .BuiltinNames .STDOUT ;
52
+ import static com .oracle .graal .python .nodes .BuiltinNames .__EXCEPTHOOK__ ;
53
+ import static com .oracle .graal .python .nodes .BuiltinNames .__STDERR__ ;
54
+ import static com .oracle .graal .python .nodes .BuiltinNames .__STDIN__ ;
55
+ import static com .oracle .graal .python .nodes .BuiltinNames .__STDOUT__ ;
52
56
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__MODULE__ ;
53
- import static com .oracle .graal .python .nodes .SpecialAttributeNames .__STDERR__ ;
54
- import static com .oracle .graal .python .nodes .SpecialAttributeNames .__STDIN__ ;
55
- import static com .oracle .graal .python .nodes .SpecialAttributeNames .__STDOUT__ ;
56
57
import static com .oracle .graal .python .nodes .SpecialMethodNames .__SIZEOF__ ;
57
58
58
59
import java .io .BufferedReader ;
153
154
import com .oracle .truffle .api .dsl .GenerateUncached ;
154
155
import com .oracle .truffle .api .dsl .NodeFactory ;
155
156
import com .oracle .truffle .api .dsl .Specialization ;
157
+ import com .oracle .truffle .api .frame .MaterializedFrame ;
156
158
import com .oracle .truffle .api .frame .VirtualFrame ;
157
159
import com .oracle .truffle .api .nodes .Node ;
158
160
import com .oracle .truffle .api .profiles .ConditionProfile ;
@@ -530,7 +532,7 @@ public void postInitialize0(Python3Core core) {
530
532
false , // dev_mode
531
533
0 // utf8_mode
532
534
));
533
- sys .setAttribute (__EXCEPTHOOK__ , sys .getAttribute ("excepthook" ));
535
+ sys .setAttribute (__EXCEPTHOOK__ , sys .getAttribute (EXCEPTHOOK ));
534
536
}
535
537
536
538
@ Override
@@ -817,7 +819,7 @@ static Object gettrace() {
817
819
}
818
820
}
819
821
820
- @ Builtin (name = "excepthook" , minNumOfPositionalArgs = 4 , maxNumOfPositionalArgs = 4 , declaresExplicitSelf = true , doc = "excepthook($module, exctype, value, traceback, /)\n " +
822
+ @ Builtin (name = EXCEPTHOOK , minNumOfPositionalArgs = 4 , maxNumOfPositionalArgs = 4 , declaresExplicitSelf = true , doc = "excepthook($module, exctype, value, traceback, /)\n " +
821
823
"--\n " +
822
824
"\n " +
823
825
"Handle an exception by displaying it with a traceback on sys.stderr." )
@@ -1298,7 +1300,8 @@ void printException(VirtualFrame frame, PythonModule sys, Object out, Object exc
1298
1300
print (frame , out , NL );
1299
1301
}
1300
1302
1301
- void printExceptionRecursive (VirtualFrame frame , PythonModule sys , Object out , Object value , Set <Object > seen ) {
1303
+ @ TruffleBoundary
1304
+ void printExceptionRecursive (MaterializedFrame frame , PythonModule sys , Object out , Object value , Set <Object > seen ) {
1302
1305
if (seen != null ) {
1303
1306
// Exception chaining
1304
1307
add (seen , value );
@@ -1338,15 +1341,6 @@ static Set<Object> createSet() {
1338
1341
return new HashSet <>();
1339
1342
}
1340
1343
1341
- @ Specialization
1342
- Object doWithoutTb (VirtualFrame frame , PythonModule sys , @ SuppressWarnings ("unused" ) Object excType , Object value , @ SuppressWarnings ("unused" ) PNone traceBack ) {
1343
- Object stdErr = lookupAttr (frame , sys , STDERR );
1344
- printExceptionRecursive (frame , sys , stdErr , value , createSet ());
1345
- flush (frame , stdErr );
1346
-
1347
- return PNone .NONE ;
1348
- }
1349
-
1350
1344
@ Specialization
1351
1345
Object doWithTb (VirtualFrame frame , PythonModule sys , @ SuppressWarnings ("unused" ) Object excType , Object value , PTraceback traceBack ) {
1352
1346
if (PGuards .isPBaseException (value )) {
@@ -1358,7 +1352,16 @@ Object doWithTb(VirtualFrame frame, PythonModule sys, @SuppressWarnings("unused"
1358
1352
}
1359
1353
1360
1354
Object stdErr = lookupAttr (frame , sys , STDERR );
1361
- printExceptionRecursive (frame , sys , stdErr , value , createSet ());
1355
+ printExceptionRecursive (frame .materialize (), sys , stdErr , value , createSet ());
1356
+ flush (frame , stdErr );
1357
+
1358
+ return PNone .NONE ;
1359
+ }
1360
+
1361
+ @ Specialization (guards = "!isPTraceback(traceBack)" )
1362
+ Object doWithoutTb (VirtualFrame frame , PythonModule sys , @ SuppressWarnings ("unused" ) Object excType , Object value , @ SuppressWarnings ("unused" ) Object traceBack ) {
1363
+ Object stdErr = lookupAttr (frame , sys , STDERR );
1364
+ printExceptionRecursive (frame .materialize (), sys , stdErr , value , createSet ());
1362
1365
flush (frame , stdErr );
1363
1366
1364
1367
return PNone .NONE ;
0 commit comments