Skip to content

Commit f6b379d

Browse files
[GR-47050] Use asPointer instead of parsing the display string in loadNFILibrary.
PullRequest: graalpython/2859
2 parents 349135f + c9c211f commit f6b379d

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,6 @@ protected abstract static class DlOpenNode extends PythonTernaryClinicBuiltinNod
638638

639639
private static final TruffleString MACOS_Security_LIB = tsLiteral("/System/Library/Frameworks/Security.framework/Security");
640640
private static final TruffleString MACOS_CoreFoundation_LIB = tsLiteral("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation");
641-
// "LibFFILibrary(" + handle + ")"
642-
private static final int LIBFFI_ADR_FORMAT_START = "LibFFILibrary".length() + 1;
643641

644642
private static final String T_RTLD_LOCAL = "RTLD_LOCAL|RTLD_NOW";
645643
private static final String T_RTLD_GLOBAL = "RTLD_GLOBAL|RTLD_NOW";
@@ -668,19 +666,10 @@ protected static DLHandler loadNFILibrary(PythonContext context, NFIBackend back
668666
}
669667
Object handler = load(context, src, name);
670668
InteropLibrary lib = InteropLibrary.getUncached();
671-
String handleStr;
672669
try {
673-
handleStr = lib.asString(lib.toDisplayString(handler));
670+
return new DLHandler(handler, lib.asPointer(handler), name, false);
674671
} catch (UnsupportedMessageException e) {
675-
throw CompilerDirectives.shouldNotReachHere("toDisplayString result not convertible to String");
676-
}
677-
String adrStr = handleStr.substring(LIBFFI_ADR_FORMAT_START, handleStr.length() - 1);
678-
try {
679-
long adr = Long.parseLong(adrStr, 10);
680-
return new DLHandler(handler, adr, name, false);
681-
} catch (NumberFormatException e) {
682-
// TODO handle exception [GR-38101]
683-
throw CompilerDirectives.shouldNotReachHere();
672+
throw CompilerDirectives.shouldNotReachHere("Cannot convert NFI library to pointer", e);
684673
}
685674
}
686675

0 commit comments

Comments
 (0)