Skip to content

Commit 7b18204

Browse files
lazkanaveen521kk
authored andcommitted
LoadLibraryExW: make sure to only use backslashes for paths
It seems like in case the path passed to it is absolute, but contains forward slashes then LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR does not work and DLLs in the same directory as the extension are not considered. This occurs in our fork because in MSYS2-mode the extension loader will normalize to forward slashes before. Normalize everything to backslashes again before passing it to LoadLibraryExW. Fixes #151
1 parent 72a36e8 commit 7b18204

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Python/dynload_win.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,22 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
252252
_Py_CheckPython3();
253253
#endif /* _MSC_VER */
254254

255+
// So we can adjust the separators in the path below
256+
#define USE_UNICODE_WCHAR_CACHE 0
257+
255258
wchar_t *wpathname = PyUnicode_AsWideCharString(pathname, NULL);
256259
if (wpathname == NULL)
257260
return NULL;
258261

262+
// LoadLibraryExW only considers paths using backslashes as "fully qualified",
263+
// and for example LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR doesn't work with forward slashes.
264+
// https://github.com/msys2-contrib/cpython-mingw/issues/151
265+
for (size_t i = 0; wpathname[i] != L'\0'; ++i) {
266+
if (wpathname[i] == L'/') {
267+
wpathname[i] = L'\\';
268+
}
269+
}
270+
259271
PyOS_snprintf(funcname, sizeof(funcname), "%.20s_%.200s", prefix, shortname);
260272

261273
{

0 commit comments

Comments
 (0)