Skip to content

Commit ab947cb

Browse files
committed
Fail loudly on SVM when frozen module cannot be loaded
1 parent f8a7f82 commit ab947cb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ enum FrozenStatus {
174174
FROZEN_NOT_FOUND, // It wasn't in frozen modules.
175175
FROZEN_DISABLED, // -X frozen_modules=off (and not essential)
176176
FROZEN_EXCLUDED, // Frozen module has no code. We don't use this in our frozen modules
177-
FROZEN_INVALID, // Frozen module has empty code. We don't use this our frozen modules
177+
FROZEN_INVALID, // Frozen module has empty code
178178
}
179179

180180
@Override
@@ -656,7 +656,9 @@ private static FrozenResult findFrozen(PythonContext context, TruffleString name
656656
module.getOriginalName(),
657657
!isAlias);
658658

659-
// CPython checks for invalid/empty modules here, but we don't generate those
659+
if (info.code == null) {
660+
return new FrozenResult(FROZEN_INVALID, info);
661+
}
660662

661663
return new FrozenResult(FROZEN_OKAY, info);
662664
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
4545
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
4646

47-
import java.io.IOException;
4847
import java.io.InputStream;
4948

5049
import org.graalvm.nativeimage.ImageInfo;
@@ -65,11 +64,13 @@ private void initCode() {
6564
InputStream resourceAsStream = PythonFrozenModule.class.getResourceAsStream("Frozen" + symbol + "." + getSuffix());
6665
if (resourceAsStream != null) {
6766
byte[] bytes = resourceAsStream.readAllBytes();
68-
// TODO exception handling
6967
code = MarshalModuleBuiltins.deserializeCodeUnit(null, null, bytes);
7068
}
71-
} catch (IOException e) {
72-
// fall-through
69+
} catch (Exception e) {
70+
// Fail loudly on SVM. On JVM, just fall back to normal import silently
71+
if (ImageInfo.inImageBuildtimeCode()) {
72+
throw new IllegalStateException("Failed to load frozen module");
73+
}
7374
}
7475
}
7576

0 commit comments

Comments
 (0)