Skip to content

Commit 04487f0

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 python#151
1 parent 1be1bd3 commit 04487f0

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
@@ -233,10 +233,22 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
233233
_Py_CheckPython3();
234234
#endif /* _MSC_VER */
235235

236+
// So we can adjust the separators in the path below
237+
#define USE_UNICODE_WCHAR_CACHE 0
238+
236239
wchar_t *wpathname = PyUnicode_AsWideCharString(pathname, NULL);
237240
if (wpathname == NULL)
238241
return NULL;
239242

243+
// LoadLibraryExW only considers paths using backslashes as "fully qualified",
244+
// and for example LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR doesn't work with forward slashes.
245+
// https://github.com/msys2-contrib/cpython-mingw/issues/151
246+
for (size_t i = 0; wpathname[i] != L'\0'; ++i) {
247+
if (wpathname[i] == L'/') {
248+
wpathname[i] = L'\\';
249+
}
250+
}
251+
240252
PyOS_snprintf(funcname, sizeof(funcname), "%.20s_%.200s", prefix, shortname);
241253

242254
{

0 commit comments

Comments
 (0)