49
49
import static com .oracle .graal .python .nodes .BuiltinNames .STDERR ;
50
50
import static com .oracle .graal .python .nodes .BuiltinNames .STDIN ;
51
51
import static com .oracle .graal .python .nodes .BuiltinNames .STDOUT ;
52
+ import static com .oracle .graal .python .nodes .BuiltinNames .TRACEBACKLIMIT ;
52
53
import static com .oracle .graal .python .nodes .BuiltinNames .__EXCEPTHOOK__ ;
53
54
import static com .oracle .graal .python .nodes .BuiltinNames .__STDERR__ ;
54
55
import static com .oracle .graal .python .nodes .BuiltinNames .__STDIN__ ;
106
107
import com .oracle .graal .python .builtins .objects .traceback .LazyTraceback ;
107
108
import com .oracle .graal .python .builtins .objects .traceback .PTraceback ;
108
109
import com .oracle .graal .python .builtins .objects .traceback .TracebackBuiltins ;
110
+ import com .oracle .graal .python .builtins .objects .traceback .TracebackBuiltinsFactory ;
109
111
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
110
112
import com .oracle .graal .python .builtins .objects .tuple .StructSequence ;
111
113
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
@@ -829,7 +831,6 @@ abstract static class ExceptHookNode extends PythonBuiltinNode {
829
831
static final String CONTEXT_MESSAGE = "\n During handling of the above exception, another exception occurred:\n \n " ;
830
832
static final int TRACEBACK_LIMIT = 1000 ;
831
833
static final int TB_RECURSIVE_CUTOFF = 3 ;
832
- static final String ATTR_TB_LIMIT = "tracebacklimit" ;
833
834
static final String ATTR_PRINT_FILE_AND_LINE = "print_file_and_line" ;
834
835
static final String ATTR_MSG = "msg" ;
835
836
static final String ATTR_FILENAME = "filename" ;
@@ -852,6 +853,7 @@ abstract static class ExceptHookNode extends PythonBuiltinNode {
852
853
@ Child private PyObjectStrAsObjectNode strAsObjNode ;
853
854
@ Child private TracebackBuiltins .GetTracebackFrameNode getTracebackFrameNode ;
854
855
@ Child private PyObjectCallMethodObjArgs callMethod ;
856
+ @ Child private TracebackBuiltins .MaterializeTruffleStacktraceNode truffleStacktraceNode ;
855
857
856
858
@ CompilerDirectives .ValueType
857
859
static final class SyntaxErrData {
@@ -870,6 +872,15 @@ static final class SyntaxErrData {
870
872
}
871
873
}
872
874
875
+ private PTraceback getNextTb (PTraceback traceback ) {
876
+ if (truffleStacktraceNode == null ) {
877
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
878
+ truffleStacktraceNode = insert (TracebackBuiltinsFactory .MaterializeTruffleStacktraceNodeGen .create ());
879
+ }
880
+ truffleStacktraceNode .execute (traceback );
881
+ return traceback .getNext ();
882
+ }
883
+
873
884
private PyObjectCallMethodObjArgs ensureCallMethodNode () {
874
885
if (callMethod == null ) {
875
886
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -990,9 +1001,11 @@ private long asLongAndOverflow(VirtualFrame frame, Object object, long overflowV
990
1001
pyLongAsLongAndOverflowNode = insert (PyLongAsLongAndOverflowNodeGen .create ());
991
1002
}
992
1003
try {
993
- final long val = pyLongAsLongAndOverflowNode .execute (frame , object );
994
- return Math .min (val , overflowValue );
1004
+ return pyLongAsLongAndOverflowNode .execute (frame , object );
995
1005
} catch (OverflowException e ) {
1006
+ if (object instanceof PInt ) {
1007
+ return ((PInt ) object ).isZeroOrNegative () ? 0 : overflowValue ;
1008
+ }
996
1009
return overflowValue ;
997
1010
}
998
1011
}
@@ -1007,7 +1020,7 @@ private Object readAttr(Object object, String attribute) {
1007
1020
1008
1021
void printTraceBack (VirtualFrame frame , PythonModule sys , Object out , PTraceback tb ) {
1009
1022
long limit = TRACEBACK_LIMIT ;
1010
- final Object limitv = readAttr (sys , ATTR_TB_LIMIT );
1023
+ final Object limitv = readAttr (sys , TRACEBACKLIMIT );
1011
1024
if (checkLong (limitv )) {
1012
1025
limit = asLongAndOverflow (frame , limitv , MAXSIZE );
1013
1026
if (limit <= 0 ) {
@@ -1093,11 +1106,11 @@ void printInternal(VirtualFrame frame, Object out, PTraceback traceback, long li
1093
1106
PTraceback tb = traceback ;
1094
1107
while (tb1 != null ) {
1095
1108
depth ++;
1096
- tb1 = tb1 . getNext ( );
1109
+ tb1 = getNextTb ( tb1 );
1097
1110
}
1098
1111
while (tb != null && depth > limit ) {
1099
1112
depth --;
1100
- tb = tb . getNext ( );
1113
+ tb = getNextTb ( tb );
1101
1114
}
1102
1115
while (tb != null ) {
1103
1116
final PCode code = getCode (frame , tb );
@@ -1117,7 +1130,7 @@ void printInternal(VirtualFrame frame, Object out, PTraceback traceback, long li
1117
1130
if (cnt <= TB_RECURSIVE_CUTOFF ) {
1118
1131
displayLine (frame , out , code .getFilename (), tb .getLineno (), code .getName ());
1119
1132
}
1120
- tb = tb . getNext ( );
1133
+ tb = getNextTb ( tb );
1121
1134
}
1122
1135
if (cnt > TB_RECURSIVE_CUTOFF ) {
1123
1136
printLineRepeated (frame , out , cnt );
0 commit comments