Skip to content

Commit dfc5014

Browse files
committed
Use SignatureLibrary in GraalHPyContext.toNative.
1 parent 190d9af commit dfc5014

File tree

1 file changed

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

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
import com.oracle.truffle.api.source.Source;
239239
import com.oracle.truffle.api.source.Source.SourceBuilder;
240240
import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
241+
import com.oracle.truffle.nfi.api.SignatureLibrary;
241242

242243
import sun.misc.Unsafe;
243244

@@ -1122,6 +1123,12 @@ private static long castLong(Object value) {
11221123
}
11231124
}
11241125

1126+
private static Object evalNFI(PythonContext context, String source, String name) {
1127+
Source src = Source.newBuilder("nfi", source, name).build();
1128+
CallTarget ct = context.getEnv().parseInternal(src);
1129+
return ct.call();
1130+
}
1131+
11251132
@ExportMessage
11261133
final void toNative() {
11271134
if (!isPointer()) {
@@ -1136,14 +1143,17 @@ final void toNative() {
11361143
}
11371144
if (useNativeFastPaths) {
11381145
PythonContext context = getContext();
1139-
Source src = Source.newBuilder("nfi", "load \"" + getJNILibrary() + "\"", "load " + PythonContext.PYTHON_JNI_LIBRARY_NAME).build();
1140-
CallTarget lib = context.getEnv().parseInternal(src);
11411146
InteropLibrary interop = InteropLibrary.getUncached();
1147+
SignatureLibrary signatures = SignatureLibrary.getUncached();
11421148
try {
1143-
Object rlib = lib.call();
1144-
Object augmentFunction = interop.invokeMember(interop.readMember(rlib, "initDirectFastPaths"), "bind", "(POINTER):VOID");
1145-
interop.execute(augmentFunction, nativePointer);
1146-
setNativeSpaceFunction = interop.invokeMember(interop.readMember(rlib, "setHPyContextNativeSpace"), "bind", "(POINTER, SINT64):VOID");
1149+
Object rlib = evalNFI(context, "load \"" + getJNILibrary() + "\"", "load " + PythonContext.PYTHON_JNI_LIBRARY_NAME);
1150+
1151+
Object augmentSignature = evalNFI(context, "(POINTER):VOID", "hpy-nfi-signature");
1152+
Object augmentFunction = interop.readMember(rlib, "initDirectFastPaths");
1153+
signatures.call(augmentSignature, augmentFunction, nativePointer);
1154+
1155+
Object setNativeSpaceSignature = evalNFI(context, "(POINTER, SINT64):VOID", "hpy-nfi-signature");
1156+
setNativeSpaceFunction = signatures.bind(setNativeSpaceSignature, interop.readMember(rlib, "setHPyContextNativeSpace"));
11471157

11481158
/*
11491159
* Allocate a native array for the native space pointers of HPy objects and

0 commit comments

Comments
 (0)