Skip to content

Commit 66d7532

Browse files
committed
Change type of option WithJavaStacktrace to int and use as engine option.
1 parent ab545d3 commit 66d7532

File tree

14 files changed

+174
-118
lines changed

14 files changed

+174
-118
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.regex.Matcher;
4444
import java.util.regex.Pattern;
4545

46-
import com.oracle.graal.python.runtime.PythonOptions;
4746
import org.graalvm.nativeimage.ImageInfo;
4847

4948
import com.oracle.graal.python.PythonLanguage;
@@ -182,6 +181,7 @@
182181
import com.oracle.graal.python.runtime.PythonCodeSerializer;
183182
import com.oracle.graal.python.runtime.PythonContext;
184183
import com.oracle.graal.python.runtime.PythonCore;
184+
import com.oracle.graal.python.runtime.PythonOptions;
185185
import com.oracle.graal.python.runtime.PythonParser;
186186
import com.oracle.graal.python.runtime.PythonParser.ParserMode;
187187
import com.oracle.graal.python.runtime.exception.PException;
@@ -560,7 +560,7 @@ public PException raise(PythonBuiltinClassType type, String format, Object... ar
560560
} else {
561561
instance = objectFactory.createBaseException(type);
562562
}
563-
throw PException.fromObject(instance, null, getContext().getOption(PythonOptions.WithJavaStacktrace));
563+
throw PException.fromObject(instance, null, PythonOptions.isPExceptionWithJavaStacktrace(getLanguage()));
564564
}
565565

566566
private void publishBuiltinModules() {
@@ -795,6 +795,6 @@ public RuntimeException raiseInvalidSyntax(PythonParser.ErrorType type, Node loc
795795
}
796796
}
797797
instance.setAttribute("msg", msg);
798-
throw PException.fromObject(instance, location, getContext().getOption(PythonOptions.WithJavaStacktrace));
798+
throw PException.fromObject(instance, location, PythonOptions.isPExceptionWithJavaStacktrace(getLanguage()));
799799
}
800800
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BinasciiModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ private int digitValue(PythonModule self, char b) {
204204
}
205205

206206
private PException oddLengthError(PythonModule self) {
207-
return raise(getAttrNode().execute(self, ERROR), ErrorMessages.ODD_LENGTH_STRING);
207+
throw getRaiseNode().execute(getAttrNode().execute(self, ERROR), PNone.NO_VALUE, ErrorMessages.ODD_LENGTH_STRING, new Object[0]);
208208
}
209209

210210
private PException nonHexError(PythonModule self) {
211-
return raise(getAttrNode().execute(self, ERROR), ErrorMessages.NON_HEX_DIGIT_FOUND);
211+
throw getRaiseNode().execute(getAttrNode().execute(self, ERROR), PNone.NO_VALUE, ErrorMessages.NON_HEX_DIGIT_FOUND, new Object[0]);
212212
}
213213

214214
private ReadAttributeFromObjectNode getAttrNode() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -587,16 +587,18 @@ Object run(PNone typ, PNone val, PNone tb) {
587587
}
588588

589589
@Specialization
590-
Object run(@SuppressWarnings("unused") Object typ, PBaseException val, @SuppressWarnings("unused") PNone tb) {
590+
Object run(@SuppressWarnings("unused") Object typ, PBaseException val, @SuppressWarnings("unused") PNone tb,
591+
@Shared("language") @CachedLanguage PythonLanguage language) {
591592
PythonContext context = getContext();
592-
context.setCurrentException(PException.fromExceptionInfo(val, (LazyTraceback) null, context.getOption(PythonOptions.WithJavaStacktrace)));
593+
context.setCurrentException(PException.fromExceptionInfo(val, (LazyTraceback) null, PythonOptions.isPExceptionWithJavaStacktrace(language)));
593594
return PNone.NONE;
594595
}
595596

596597
@Specialization
597-
Object run(@SuppressWarnings("unused") Object typ, PBaseException val, PTraceback tb) {
598+
Object run(@SuppressWarnings("unused") Object typ, PBaseException val, PTraceback tb,
599+
@Shared("language") @CachedLanguage PythonLanguage language) {
598600
PythonContext context = getContext();
599-
context.setCurrentException(PException.fromExceptionInfo(val, tb, context.getOption(PythonOptions.WithJavaStacktrace)));
601+
context.setCurrentException(PException.fromExceptionInfo(val, tb, PythonOptions.isPExceptionWithJavaStacktrace(language)));
600602
return PNone.NONE;
601603
}
602604
}
@@ -656,15 +658,17 @@ Object doClear(PNone typ, PNone val, PNone tb) {
656658
}
657659

658660
@Specialization
659-
Object doFull(@SuppressWarnings("unused") Object typ, PBaseException val, PTraceback tb) {
661+
Object doFull(@SuppressWarnings("unused") Object typ, PBaseException val, PTraceback tb,
662+
@Shared("language") @CachedLanguage PythonLanguage language) {
660663
PythonContext context = getContext();
661-
context.setCaughtException(PException.fromExceptionInfo(val, tb, context.getOption(PythonOptions.WithJavaStacktrace)));
664+
context.setCaughtException(PException.fromExceptionInfo(val, tb, PythonOptions.isPExceptionWithJavaStacktrace(language)));
662665
return PNone.NONE;
663666
}
664667

665668
@Specialization
666-
Object doWithoutTraceback(@SuppressWarnings("unused") Object typ, PBaseException val, @SuppressWarnings("unused") PNone tb) {
667-
return doFull(typ, val, null);
669+
Object doWithoutTraceback(@SuppressWarnings("unused") Object typ, PBaseException val, @SuppressWarnings("unused") PNone tb,
670+
@Shared("language") @CachedLanguage PythonLanguage language) {
671+
return doFull(typ, val, null, language);
668672
}
669673

670674
@Fallback
@@ -867,59 +871,65 @@ Object doNativeWrapper(String name, DynamicObjectNativeWrapper.PythonObjectNativ
867871

868872
@Specialization(guards = "!isPythonObjectNativeWrapper(result)")
869873
Object doPrimitiveWrapper(String name, @SuppressWarnings("unused") PythonNativeWrapper result,
874+
@Shared("language") @CachedLanguage PythonLanguage language,
870875
@Shared("ctxt") @CachedContext(PythonLanguage.class) PythonContext context,
871876
@Shared("fact") @Cached PythonObjectFactory factory,
872877
@Shared("raise") @Cached PRaiseNode raise) {
873-
checkFunctionResult(name, false, false, context, raise, factory);
878+
checkFunctionResult(name, false, false, language, context, raise, factory);
874879
return result;
875880
}
876881

877882
@Specialization(guards = "isNoValue(result)")
878883
Object doNoValue(String name, @SuppressWarnings("unused") PNone result,
884+
@Shared("language") @CachedLanguage PythonLanguage language,
879885
@Shared("ctxt") @CachedContext(PythonLanguage.class) PythonContext context,
880886
@Shared("fact") @Cached PythonObjectFactory factory,
881887
@Shared("raise") @Cached PRaiseNode raise) {
882-
checkFunctionResult(name, true, false, context, raise, factory);
888+
checkFunctionResult(name, true, false, language, context, raise, factory);
883889
return PNone.NO_VALUE;
884890
}
885891

886892
@Specialization(guards = "!isNoValue(result)")
887893
Object doPythonObject(String name, @SuppressWarnings("unused") PythonAbstractObject result,
894+
@Shared("language") @CachedLanguage PythonLanguage language,
888895
@Shared("ctxt") @CachedContext(PythonLanguage.class) PythonContext context,
889896
@Shared("fact") @Cached PythonObjectFactory factory,
890897
@Shared("raise") @Cached PRaiseNode raise) {
891-
checkFunctionResult(name, false, false, context, raise, factory);
898+
checkFunctionResult(name, false, false, language, context, raise, factory);
892899
return result;
893900
}
894901

895902
@Specialization
896903
Object doPythonNativeNull(String name, @SuppressWarnings("unused") PythonNativeNull result,
904+
@Shared("language") @CachedLanguage PythonLanguage language,
897905
@Shared("ctxt") @CachedContext(PythonLanguage.class) PythonContext context,
898906
@Shared("fact") @Cached PythonObjectFactory factory,
899907
@Shared("raise") @Cached PRaiseNode raise) {
900-
checkFunctionResult(name, true, false, context, raise, factory);
908+
checkFunctionResult(name, true, false, language, context, raise, factory);
901909
return result;
902910
}
903911

904912
@Specialization
905913
int doInteger(String name, int result,
914+
@Shared("language") @CachedLanguage PythonLanguage language,
906915
@Shared("ctxt") @CachedContext(PythonLanguage.class) PythonContext context,
907916
@Shared("fact") @Cached PythonObjectFactory factory,
908917
@Shared("raise") @Cached PRaiseNode raise) {
909918
// If the native functions returns a primitive int, only a value '-1' indicates an
910919
// error.
911-
checkFunctionResult(name, result == -1, true, context, raise, factory);
920+
checkFunctionResult(name, result == -1, true, language, context, raise, factory);
912921
return result;
913922
}
914923

915924
@Specialization
916925
long doLong(String name, long result,
926+
@Shared("language") @CachedLanguage PythonLanguage language,
917927
@Shared("ctxt") @CachedContext(PythonLanguage.class) PythonContext context,
918928
@Shared("fact") @Cached PythonObjectFactory factory,
919929
@Shared("raise") @Cached PRaiseNode raise) {
920930
// If the native functions returns a primitive int, only a value '-1' indicates an
921931
// error.
922-
checkFunctionResult(name, result == -1, true, context, raise, factory);
932+
checkFunctionResult(name, result == -1, true, language, context, raise, factory);
923933
return result;
924934
}
925935

@@ -933,14 +943,16 @@ long doLong(String name, long result,
933943
Object doForeign(String name, Object result,
934944
@Exclusive @Cached("createBinaryProfile()") ConditionProfile isNullProfile,
935945
@Exclusive @CachedLibrary(limit = "3") InteropLibrary lib,
946+
@Shared("language") @CachedLanguage PythonLanguage language,
936947
@Shared("ctxt") @CachedContext(PythonLanguage.class) PythonContext context,
937948
@Shared("fact") @Cached PythonObjectFactory factory,
938949
@Shared("raise") @Cached PRaiseNode raise) {
939-
checkFunctionResult(name, isNullProfile.profile(lib.isNull(result)), false, context, raise, factory);
950+
checkFunctionResult(name, isNullProfile.profile(lib.isNull(result)), false, language, context, raise, factory);
940951
return result;
941952
}
942953

943-
private void checkFunctionResult(String name, boolean indicatesError, boolean isPrimitiveResult, PythonContext context, PRaiseNode raise, PythonObjectFactory factory) {
954+
private void checkFunctionResult(String name, boolean indicatesError, boolean isPrimitiveResult, PythonLanguage language, PythonContext context, PRaiseNode raise,
955+
PythonObjectFactory factory) {
944956
PException currentException = context.getCurrentException();
945957
boolean errOccurred = currentException != null;
946958
if (indicatesError) {
@@ -956,7 +968,7 @@ private void checkFunctionResult(String name, boolean indicatesError, boolean is
956968
context.setCurrentException(null);
957969
PBaseException sysExc = factory.createBaseException(PythonErrorType.SystemError, ErrorMessages.RETURNED_RESULT_WITH_ERROR_SET, new Object[]{name});
958970
sysExc.setCause(currentException.getEscapedException());
959-
throw PException.fromObject(sysExc, this, context.getOption(PythonOptions.WithJavaStacktrace));
971+
throw PException.fromObject(sysExc, this, PythonOptions.isPExceptionWithJavaStacktrace(language));
960972
}
961973
}
962974

@@ -1573,7 +1585,8 @@ Object newFrame(Object threadState, PCode code, PythonObject globals, Object loc
15731585
abstract static class PyTraceBackHereNode extends PythonUnaryBuiltinNode {
15741586
@Specialization
15751587
int tbHere(PFrame frame,
1576-
@Cached GetTracebackNode getTracebackNode) {
1588+
@Cached GetTracebackNode getTracebackNode,
1589+
@CachedLanguage PythonLanguage language) {
15771590
PythonContext context = getContext();
15781591
PException currentException = context.getCurrentException();
15791592
if (currentException != null) {
@@ -1582,7 +1595,8 @@ int tbHere(PFrame frame,
15821595
traceback = getTracebackNode.execute(currentException.getTraceback());
15831596
}
15841597
PTraceback newTraceback = factory().createTraceback(frame, frame.getLine(), traceback);
1585-
context.setCurrentException(PException.fromExceptionInfo(currentException.getExceptionObject(), newTraceback, context.getOption(PythonOptions.WithJavaStacktrace)));
1598+
boolean withJavaStacktrace = PythonOptions.isPExceptionWithJavaStacktrace(language);
1599+
context.setCurrentException(PException.fromExceptionInfo(currentException.getExceptionObject(), newTraceback, withJavaStacktrace));
15861600
}
15871601

15881602
return 0;

0 commit comments

Comments
 (0)