Skip to content

Commit 5b6135d

Browse files
timfelmsimacek
authored andcommitted
Add CompressionModulesBackend context option to be able to prefer java impls
1 parent 5720e12 commit 5b6135d

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIBz2Support.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public String signature() {
153153
@CompilerDirectives.CompilationFinal private boolean available;
154154

155155
private NFIBz2Support(PythonContext context, NativeLibrary.NFIBackend backend, String noNativeAccessHelp) {
156-
if (context.isNativeAccessAllowed()) {
156+
if (context.useNativeCompressionModules()) {
157157
this.pythonContext = context;
158158
this.typedNativeLib = NativeLibrary.create(PythonContext.getSupportLibName(SUPPORTING_NATIVE_LIB_NAME), Bz2NativeFunctions.values(),
159159
backend, noNativeAccessHelp, false);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFILZMASupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public String signature() {
293293
@CompilerDirectives.CompilationFinal private boolean available;
294294

295295
private NFILZMASupport(PythonContext context, NativeLibrary.NFIBackend backend, String noNativeAccessHelp) {
296-
if (context.isNativeAccessAllowed()) {
296+
if (context.useNativeCompressionModules()) {
297297
this.pythonContext = context;
298298
this.typedNativeLib = NativeLibrary.create(PythonContext.getSupportLibName(SUPPORTING_NATIVE_LIB_NAME), LZMANativeFunctions.values(),
299299
backend, noNativeAccessHelp, true);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NFIZlibSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public String signature() {
269269
@CompilerDirectives.CompilationFinal private boolean available;
270270

271271
private NFIZlibSupport(PythonContext context, NativeLibrary.NFIBackend backend, String noNativeAccessHelp) {
272-
if (context.isNativeAccessAllowed()) {
272+
if (context.useNativeCompressionModules()) {
273273
this.pythonContext = context;
274274
this.typedNativeLib = NativeLibrary.create(PythonContext.getSupportLibName(SUPPORTING_NATIVE_LIB_NAME),
275275
ZlibNativeFunctions.values(), backend, noNativeAccessHelp, true);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,15 @@ public boolean isExecutableAccessAllowed() {
23372337
return getEnv().isHostLookupAllowed() || isNativeAccessAllowed();
23382338
}
23392339

2340+
public boolean useNativeCompressionModules() {
2341+
if (isNativeAccessAllowed()) {
2342+
TruffleString option = getLanguage().getEngineOption(PythonOptions.CompressionModulesBackend);
2343+
TruffleString.EqualNode eqNode = TruffleString.EqualNode.getUncached();
2344+
return !eqNode.execute(T_JAVA, option, TS_ENCODING);
2345+
}
2346+
return false;
2347+
}
2348+
23402349
/**
23412350
* Trigger any pending asynchronous actions
23422351
*/

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,15 @@ public static void checkBytecodeDSLEnv() {
195195
}
196196
}));
197197

198-
@EngineOption @Option(category = OptionCategory.USER, help = "Choose the backend for the POSIX module.", usageSyntax = "java|native|llvm", stability = OptionStability.STABLE) //
198+
@EngineOption @Option(category = OptionCategory.USER, help = "Choose the backend for the POSIX module.", usageSyntax = "java|native", stability = OptionStability.STABLE) //
199199
public static final OptionKey<TruffleString> PosixModuleBackend = new OptionKey<>(T_JAVA, TS_OPTION_TYPE);
200200

201201
@EngineOption @Option(category = OptionCategory.USER, help = "Choose the backend for the Sha3 module.", usageSyntax = "java|native", stability = OptionStability.STABLE) //
202202
public static final OptionKey<TruffleString> Sha3ModuleBackend = new OptionKey<>(T_JAVA, TS_OPTION_TYPE);
203203

204+
@EngineOption @Option(category = OptionCategory.USER, help = "Choose the backend for the Zlib, Bz2, and LZMA modules.", usageSyntax = "java|native", stability = OptionStability.STABLE) //
205+
public static final OptionKey<TruffleString> CompressionModulesBackend = new OptionKey<>(T_JAVA, TS_OPTION_TYPE);
206+
204207
@Option(category = OptionCategory.USER, help = "Install default signal handlers on startup", usageSyntax = "true|false", stability = OptionStability.STABLE) //
205208
public static final OptionKey<Boolean> InstallSignalHandlers = new OptionKey<>(false);
206209

0 commit comments

Comments
 (0)