Skip to content

Commit 6771000

Browse files
committed
Make sure sys.dllhandle points to the right libpython-native.so in multi-context
1 parent 4bb091c commit 6771000

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/objects/cext/CExtContextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void testGetBaseName() {
8181

8282
private static class TestCExtContext extends CExtContext {
8383
public TestCExtContext(PythonContext context, Object library) {
84-
super(context, library);
84+
super(context, library, null);
8585
}
8686

8787
public static TruffleString getBN(TruffleString s) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,10 @@ private static Object[] convertToObjectArray(TruffleString[] arr) {
726726
public void postInitialize(Python3Core core) {
727727
postInitialize0(core);
728728
initStd(core);
729+
PythonModule sys = core.lookupBuiltinModule(T_SYS);
730+
core.getContext().registerCApiHook(() -> {
731+
sys.setAttribute(toTruffleStringUncached("_dllhandle_name"), toTruffleStringUncached(core.getContext().getCApiContext().getLibraryName()));
732+
});
729733
}
730734

731735
@TruffleBoundary

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public static TruffleLogger getLogger(Class<?> clazz) {
317317
}
318318

319319
public CApiContext(PythonContext context, Object library, NativeLibraryLocator locator) {
320-
super(context, library);
320+
super(context, library, locator.getCapiLibrary());
321321
this.nativeSymbolCache = new Object[NativeCAPISymbol.values().length];
322322
this.nativeLibraryLocator = locator;
323323

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtContext.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ public abstract class CExtContext {
7979

8080
/** The library object representing 'libpython.*.so' or similar. */
8181
private final Object library;
82+
private final String libraryName;
8283

83-
public CExtContext(PythonContext context, Object library) {
84+
public CExtContext(PythonContext context, Object library, String libraryName) {
8485
this.context = context;
8586
this.library = library;
87+
this.libraryName = libraryName;
8688
}
8789

8890
public final PythonContext getContext() {
@@ -93,6 +95,10 @@ public final Object getLibrary() {
9395
return library;
9496
}
9597

98+
public final String getLibraryName() {
99+
return libraryName;
100+
}
101+
96102
public static boolean isMethVarargs(int flags) {
97103
return (flags & CALL_CONVENTION_MASK) == METH_VARARGS;
98104
}

graalpython/lib-python/3/ctypes/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ def LoadLibrary(self, name):
465465
pydll = LibraryLoader(PyDLL)
466466

467467
if _os.name == "nt":
468-
# GraalPy change: we set the dllhandle here
469-
_sys.dllhandle = _dlopen("python-native.dll", 0)
468+
# GraalPy change: we set the dllhandle here, it may be different per context
469+
_sys.dllhandle = _dlopen(_sys._dllhandle_name, 0)
470470
# End GraalPy change
471471
pythonapi = PyDLL("python dll", None, _sys.dllhandle)
472472
elif _sys.platform == "cygwin":

0 commit comments

Comments
 (0)