Skip to content

Commit 04afce1

Browse files
committed
mingw-w64: Add path of executable/dll to system path.
This is so that the correct module DLL dependencies (for example tcl*.dll and tk*.dll) are found when embedding Python.
1 parent 4a9bbd0 commit 04afce1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Modules/getpath.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,32 @@ calculate_path(void)
872872
else
873873
wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN);
874874

875+
#ifdef MS_WINDOWS
876+
if (_path) {
877+
wchar_t *module_path, *new_path;
878+
/* Add path of executable/dll to system path. This
879+
* is so that the correct tcl??.dll and tk??.dll get used. */
880+
path_buffer = _Py_char2wchar(_path, NULL);
881+
module_path = dllpath[0] ? dllpath : progpath;
882+
new_path = (wchar_t *)alloca(sizeof(wchar_t)*(wcslen(L"PATH=")+wcslen(module_path)+1+wcslen(path_buffer)+1));
883+
if (new_path) {
884+
wchar_t *slashes, *end;
885+
wcscpy( new_path, L"PATH=" );
886+
wcscat( new_path, module_path );
887+
slashes = wcschr( new_path, L'/' );
888+
while (slashes) {
889+
*slashes = '\\';
890+
slashes = wcschr( slashes+1, L'/' );
891+
}
892+
end = wcsrchr(new_path, L'\\') ? wcsrchr(new_path, L'\\') : new_path + wcslen(new_path);
893+
end[0] = L';';
894+
end[1] = L'\0';
895+
wcscat( new_path, path_buffer );
896+
_wputenv( new_path );
897+
PyMem_RawFree(path_buffer);
898+
}
899+
}
900+
#endif
875901
PyMem_RawFree(_pythonpath);
876902
PyMem_RawFree(_prefix);
877903
PyMem_RawFree(_exec_prefix);

0 commit comments

Comments
 (0)