238
238
import com .oracle .truffle .api .source .Source ;
239
239
import com .oracle .truffle .api .source .Source .SourceBuilder ;
240
240
import com .oracle .truffle .llvm .spi .NativeTypeLibrary ;
241
+ import com .oracle .truffle .nfi .api .SignatureLibrary ;
241
242
242
243
import sun .misc .Unsafe ;
243
244
@@ -1122,6 +1123,12 @@ private static long castLong(Object value) {
1122
1123
}
1123
1124
}
1124
1125
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
+
1125
1132
@ ExportMessage
1126
1133
final void toNative () {
1127
1134
if (!isPointer ()) {
@@ -1136,14 +1143,17 @@ final void toNative() {
1136
1143
}
1137
1144
if (useNativeFastPaths ) {
1138
1145
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 );
1141
1146
InteropLibrary interop = InteropLibrary .getUncached ();
1147
+ SignatureLibrary signatures = SignatureLibrary .getUncached ();
1142
1148
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" ));
1147
1157
1148
1158
/*
1149
1159
* Allocate a native array for the native space pointers of HPy objects and
0 commit comments