Skip to content

Commit a9eede1

Browse files
committed
fix off-by-one in sys.path initialization
1 parent 6721396 commit a9eede1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,18 @@ public void postInitialize(PythonCore core) {
220220
LanguageInfo llvmInfo = env.getInternalLanguages().get(LLVM_LANGUAGE);
221221
Toolchain toolchain = env.lookup(llvmInfo, Toolchain.class);
222222

223+
boolean isIsolated = PythonOptions.getOption(context, PythonOptions.IsolateFlag);
224+
boolean capiSeparate = !capiHome.equals(coreHome);
225+
223226
Object[] path;
224227
int pathIdx = 0;
225-
boolean doIsolate = PythonOptions.getOption(context, PythonOptions.IsolateFlag);
226-
boolean capiSeparate = !capiHome.equals(coreHome);
227-
int defaultPathsLen = (doIsolate ? 3 : 4) + (capiSeparate ? 1 : 0);
228+
int defaultPathsLen = 2;
229+
if (!isIsolated) {
230+
defaultPathsLen++;
231+
}
232+
if (capiSeparate) {
233+
defaultPathsLen++;
234+
}
228235
if (option.length() > 0) {
229236
String[] split = option.split(context.getEnv().getPathSeparator());
230237
path = new Object[split.length + defaultPathsLen];
@@ -233,7 +240,7 @@ public void postInitialize(PythonCore core) {
233240
} else {
234241
path = new Object[defaultPathsLen];
235242
}
236-
if (!doIsolate) {
243+
if (!isIsolated) {
237244
path[pathIdx++] = getScriptPath(env, args);
238245
}
239246
path[pathIdx++] = stdlibHome;

0 commit comments

Comments
 (0)