54
54
import java .io .IOException ;
55
55
import java .nio .file .LinkOption ;
56
56
57
- import com .oracle .truffle .api .TruffleFile ;
58
57
import org .graalvm .shadowed .com .ibm .icu .impl .Punycode ;
59
58
import org .graalvm .shadowed .com .ibm .icu .text .StringPrepParseException ;
60
59
82
81
import com .oracle .truffle .api .CompilerDirectives ;
83
82
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
84
83
import com .oracle .truffle .api .CompilerDirectives .ValueType ;
84
+ import com .oracle .truffle .api .TruffleFile ;
85
85
import com .oracle .truffle .api .TruffleLanguage .Env ;
86
86
import com .oracle .truffle .api .TruffleLogger ;
87
87
import com .oracle .truffle .api .exception .AbstractTruffleException ;
@@ -319,8 +319,8 @@ public static Object loadCExtModule(Node location, PythonContext context, Module
319
319
320
320
// we always need to load the CPython C API (even for HPy modules)
321
321
CApiContext cApiContext = CApiContext .ensureCapiWasLoaded (location , context , spec .name , spec .path );
322
- Object library = null ;
323
-
322
+ Object library ;
323
+ InteropLibrary interopLib ;
324
324
325
325
if (cApiContext .useNativeBackend ) {
326
326
GraalHPyJNIContext .loadJNIBackend ();
@@ -333,27 +333,26 @@ public static Object loadCExtModule(Node location, PythonContext context, Module
333
333
try {
334
334
Source librarySource = Source .newBuilder (J_NFI_LANGUAGE , loadExpr , "load " + spec .name ).build ();
335
335
library = context .getEnv ().parseInternal (librarySource ).call ();
336
+ interopLib = InteropLibrary .getUncached (library );
336
337
} catch (PException e ) {
337
338
throw e ;
338
339
} catch (AbstractTruffleException e ) {
339
340
throw new ImportException (CExtContext .wrapJavaException (e , location ), spec .name , spec .path , ErrorMessages .CANNOT_LOAD_M , spec .path , e );
340
341
}
341
342
} else {
342
343
library = loadLLVMLibrary (location , context , spec .name , spec .path );
344
+ interopLib = InteropLibrary .getUncached (library );
343
345
try {
344
- if (InteropLibrary . getUncached ( library ) .getLanguage (library ).toString ().startsWith ("class com.oracle.truffle.nfi" )) {
346
+ if (interopLib .getLanguage (library ).toString ().startsWith ("class com.oracle.truffle.nfi" )) {
345
347
throw PRaiseNode .raiseUncached (null , SystemError , ErrorMessages .NO_BITCODE_FOUND , spec .path );
346
348
}
347
349
} catch (UnsupportedMessageException e ) {
348
350
throw CompilerDirectives .shouldNotReachHere (e );
349
351
}
350
352
}
351
- InteropLibrary llvmInteropLib = InteropLibrary .getUncached (library );
352
353
353
- // Now, try to detect the C extension's API by looking for the appropriate init
354
- // functions.
355
354
try {
356
- return cApiContext .initCApiModule (location , library , spec .getInitFunctionName (), spec , llvmInteropLib , checkFunctionResultNode );
355
+ return cApiContext .initCApiModule (location , library , spec .getInitFunctionName (), spec , interopLib , checkFunctionResultNode );
357
356
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e ) {
358
357
throw new ImportException (CExtContext .wrapJavaException (e , location ), spec .name , spec .path , ErrorMessages .CANNOT_INITIALIZE_WITH , spec .path , spec .getEncodedName (), "" );
359
358
}
0 commit comments