Skip to content

Commit 94a5e53

Browse files
committed
Make sure source is never null
1 parent a34fcec commit 94a5e53

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,8 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, Object wMod
12101210
}
12111211
if (AstModuleBuiltins.isAst(getContext(), wSource)) {
12121212
ModTy mod = AstModuleBuiltins.obj2sst(getContext(), wSource);
1213-
Source source = createFakeSource();
1213+
// TODO _PyAST_Validate
1214+
Source source = PythonUtils.createFakeSource();
12141215
RootCallTarget rootCallTarget = getLanguage().compileForBytecodeInterpreter(getContext(), mod, source, false, optimize, null, null);
12151216
return wrapRootCallTarget(rootCallTarget);
12161217
}
@@ -1219,11 +1220,6 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, Object wMod
12191220
return compile(source, filename, mode, flags, kwDontInherit, optimize);
12201221
}
12211222

1222-
@TruffleBoundary
1223-
private Source createFakeSource() {
1224-
return Source.newBuilder(PythonLanguage.ID, "", "").build();
1225-
}
1226-
12271223
private PCode wrapRootCallTarget(RootCallTarget rootCallTarget) {
12281224
RootNode rootNode = rootCallTarget.getRootNode();
12291225
if (rootNode instanceof PBytecodeRootNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private RootCallTarget deserializeForBytecodeInterpreter(PythonLanguage language
152152
code.outputCanQuicken, code.variableShouldUnbox,
153153
code.generalizeInputsMap, code.generalizeVarsMap);
154154
}
155-
RootNode rootNode = PBytecodeRootNode.create(language, code, null);
155+
RootNode rootNode = PBytecodeRootNode.create(language, code, PythonUtils.createFakeSource());
156156
if (code.isGeneratorOrCoroutine()) {
157157
rootNode = new PBytecodeGeneratorFunctionRootNode(language, rootNode.getFrameDescriptor(), (PBytecodeRootNode) rootNode, code.name);
158158
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/SourceMap.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ private static int readNum(ByteArrayInputStream offsets) {
120120
}
121121

122122
public static SourceSection getSourceSection(Source source, int startLine, int startColumn, int endLine, int endColumn) {
123-
if (source == null) {
124-
return null;
125-
} else if (!source.hasCharacters()) {
123+
if (!source.hasCharacters()) {
126124
return source.createUnavailableSection();
127125
}
128126
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ public static PBytecodeRootNode create(PythonLanguage language, CodeUnit co, Sou
597597
@TruffleBoundary
598598
private PBytecodeRootNode(PythonLanguage language, FrameDescriptor fd, Signature sign, CodeUnit co, Source source, RaisePythonExceptionErrorCallback parserErrorCallback) {
599599
super(language, fd);
600+
assert source != null;
600601
this.celloffset = co.varnames.length;
601602
this.freeoffset = celloffset + co.cellvars.length;
602603
this.stackoffset = freeoffset + co.freevars.length;
@@ -4987,8 +4988,6 @@ public int getFirstLineno() {
49874988
public SourceSection getSourceSection() {
49884989
if (sourceSection != null) {
49894990
return sourceSection;
4990-
} else if (source == null) {
4991-
return null;
49924991
} else if (!source.hasCharacters()) {
49934992
/*
49944993
* TODO We could still expose the disassembled bytecode for a debugger to have something

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
import javax.management.ObjectName;
6161
import javax.management.ReflectionException;
6262

63-
import com.oracle.truffle.api.nodes.Node;
64-
import com.oracle.truffle.api.nodes.NodeVisitor;
6563
import org.graalvm.nativeimage.ImageInfo;
6664

6765
import com.oracle.graal.python.PythonLanguage;
@@ -86,9 +84,12 @@
8684
import com.oracle.truffle.api.frame.Frame;
8785
import com.oracle.truffle.api.frame.MaterializedFrame;
8886
import com.oracle.truffle.api.memory.ByteArraySupport;
87+
import com.oracle.truffle.api.nodes.Node;
88+
import com.oracle.truffle.api.nodes.NodeVisitor;
8989
import com.oracle.truffle.api.nodes.RootNode;
9090
import com.oracle.truffle.api.profiles.ConditionProfile;
9191
import com.oracle.truffle.api.profiles.ValueProfile;
92+
import com.oracle.truffle.api.source.Source;
9293
import com.oracle.truffle.api.strings.TruffleString;
9394
import com.oracle.truffle.api.strings.TruffleString.Encoding;
9495

@@ -689,6 +690,11 @@ public static TruffleString[] objectArrayToTruffleStringArray(Object[] array, Ca
689690
return result;
690691
}
691692

693+
@TruffleBoundary
694+
public static Source createFakeSource() {
695+
return Source.newBuilder(PythonLanguage.ID, "", "").build();
696+
}
697+
692698
public static final class NodeCounterWithLimit implements NodeVisitor {
693699
private int count;
694700
private final int limit;

0 commit comments

Comments
 (0)