Skip to content

Commit 03fdbb7

Browse files
committed
Fix: only init native fast paths for JNI backend
1 parent 8f3669f commit 03fdbb7

File tree

1 file changed

+26
-21
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy

1 file changed

+26
-21
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,30 +1140,35 @@ final void toNative() {
11401140
if (initJNI(this, castLong(nativePointer)) != 0) {
11411141
throw new RuntimeException("Could not initialize HPy JNI backend.");
11421142
}
1143-
}
1144-
if (useNativeFastPaths) {
1145-
PythonContext context = getContext();
1146-
InteropLibrary interop = InteropLibrary.getUncached();
1147-
SignatureLibrary signatures = SignatureLibrary.getUncached();
1148-
try {
1149-
Object rlib = evalNFI(context, "load \"" + getJNILibrary() + "\"", "load " + PythonContext.PYTHON_JNI_LIBRARY_NAME);
1143+
/*
1144+
* Currently, the native fast path functions are only available if the JNI backend
1145+
* is used because they rely on 'initJNI' being called. In future, we might also
1146+
* want to use the native fast path functions for the NFI backend.
1147+
*/
1148+
if (useNativeFastPaths) {
1149+
PythonContext context = getContext();
1150+
InteropLibrary interop = InteropLibrary.getUncached();
1151+
SignatureLibrary signatures = SignatureLibrary.getUncached();
1152+
try {
1153+
Object rlib = evalNFI(context, "load \"" + getJNILibrary() + "\"", "load " + PythonContext.PYTHON_JNI_LIBRARY_NAME);
11501154

1151-
Object augmentSignature = evalNFI(context, "(POINTER):VOID", "hpy-nfi-signature");
1152-
Object augmentFunction = interop.readMember(rlib, "initDirectFastPaths");
1153-
signatures.call(augmentSignature, augmentFunction, nativePointer);
1155+
Object augmentSignature = evalNFI(context, "(POINTER):VOID", "hpy-nfi-signature");
1156+
Object augmentFunction = interop.readMember(rlib, "initDirectFastPaths");
1157+
signatures.call(augmentSignature, augmentFunction, nativePointer);
11541158

1155-
Object setNativeSpaceSignature = evalNFI(context, "(POINTER, SINT64):VOID", "hpy-nfi-signature");
1156-
setNativeSpaceFunction = signatures.bind(setNativeSpaceSignature, interop.readMember(rlib, "setHPyContextNativeSpace"));
1159+
Object setNativeSpaceSignature = evalNFI(context, "(POINTER, SINT64):VOID", "hpy-nfi-signature");
1160+
setNativeSpaceFunction = signatures.bind(setNativeSpaceSignature, interop.readMember(rlib, "setHPyContextNativeSpace"));
11571161

1158-
/*
1159-
* Allocate a native array for the native space pointers of HPy objects and
1160-
* initialize it.
1161-
*/
1162-
allocateNativeSpacePointersMirror();
1162+
/*
1163+
* Allocate a native array for the native space pointers of HPy objects and
1164+
* initialize it.
1165+
*/
1166+
allocateNativeSpacePointersMirror();
11631167

1164-
interop.execute(setNativeSpaceFunction, nativePointer, nativeSpacePointers);
1165-
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException | UnknownIdentifierException e) {
1166-
throw CompilerDirectives.shouldNotReachHere();
1168+
interop.execute(setNativeSpaceFunction, nativePointer, nativeSpacePointers);
1169+
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException | UnknownIdentifierException e) {
1170+
throw CompilerDirectives.shouldNotReachHere();
1171+
}
11671172
}
11681173
}
11691174
}
@@ -1489,7 +1494,7 @@ public final long ctxGetItemi(long hCollection, long lidx) {
14891494

14901495
/**
14911496
* HPy signature: {@code HPy_SetItem(HPyContext ctx, HPy obj, HPy key, HPy value)}
1492-
*
1497+
*
14931498
* @param hSequence
14941499
* @param hKey
14951500
* @param hValue

0 commit comments

Comments
 (0)