Skip to content

Commit b63cf46

Browse files
committed
Fix _add_dll_directory
Fixes #533
1 parent dc0d033 commit b63cf46

File tree

2 files changed

+16
-3
lines changed
  • graalpython
    • com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi
    • lib-graalpython

2 files changed

+16
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import org.graalvm.shadowed.com.ibm.icu.text.StringPrepParseException;
7474

7575
import com.oracle.graal.python.PythonLanguage;
76+
import com.oracle.graal.python.annotations.PythonOS;
7677
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
7778
import com.oracle.graal.python.builtins.modules.cext.PythonCApiAssertions;
7879
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltinRegistry;
@@ -1078,7 +1079,11 @@ public static Object loadCExtModule(Node location, PythonContext context, Module
10781079
}
10791080
dlopenFlags |= PosixConstants.RTLD_LOCAL.value;
10801081
}
1081-
String loadExpr = String.format("load(%s) \"%s\"", dlopenFlagsToString(dlopenFlags), loadPath);
1082+
String dlopenFlagsString = dlopenFlagsToString(dlopenFlags);
1083+
if (PythonLanguage.getPythonOS() == PythonOS.PLATFORM_WIN32) {
1084+
dlopenFlagsString += "| LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR";
1085+
}
1086+
String loadExpr = String.format("load(%s) \"%s\"", dlopenFlagsString, loadPath);
10821087
if (PythonOptions.UsePanama.getValue(context.getEnv().getOptions())) {
10831088
loadExpr = "with panama " + loadExpr;
10841089
}

graalpython/lib-graalpython/_nt.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,21 @@
4141

4242

4343
def _add_dll_directory(path):
44+
# TODO error handling
4445
import ctypes
45-
return ctypes.windll.kernel32.AddDllDirectory(path)
46+
AddDllDirectory = ctypes.windll.kernel32['AddDllDirectory']
47+
AddDllDirectory.argtypes = [ctypes.c_wchar_p]
48+
AddDllDirectory.restype = ctypes.c_void_p
49+
return AddDllDirectory(path)
4650

4751

4852
def _remove_dll_directory(cookie):
53+
# TODO error handling
4954
import ctypes
50-
return ctypes.windll.kernel32.RemoveDllDirectory(cookie)
55+
RemoveDllDirectory = ctypes.windll.kernel32['RemoveDllDirectory']
56+
RemoveDllDirectory.argtypes = [ctypes.c_void_p]
57+
RemoveDllDirectory.restype = ctypes.c_int
58+
RemoveDllDirectory(cookie)
5159

5260

5361
nt._add_dll_directory = _add_dll_directory

0 commit comments

Comments
 (0)