[Python-Dev] Why does python use relative instead of absolute path when calling LoadLibrary*
Stefano Borini
stefano.borini at ferrara.linux.it
Fri Mar 13 19:25:36 CET 2015
On 3/11/15 9:36 PM, David Cournapeau wrote:
> Hi,
>
> While looking at the import code of python for C extensions, I was
> wondering why we pass a relative path instead of an absolute path to
> LoadLibraryEx (see bottom for some context).
>
> In python 2.7, the full path existence was even checked before calling
> into LoadLibraryEx
> (https://github.com/python/cpython/blob/2.7/Python/dynload_win.c#L189),
> but it looks like this check was removed in python 3.x branch.
>
> Is there any defined behaviour that depends on this path to be relative ?
My two cents. According to the MSDN documentation, passing a relative
path is actually undefined
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684179%28v=vs.85%29.aspx
----------------------------
LOAD_WITH_ALTERED_SEARCH_PATH
0x00000008
If this value is used and lpFileName specifies an absolute path, the
system uses the alternate file search strategy discussed in the Remarks
section to find associated executable modules that the specified module
causes to be loaded. If this value is used and lpFileName specifies a
relative path, the behavior is undefined.
---------------------------
meaning that wpathname _must_ be absolute.
https://github.com/python/cpython/blob/master/Python/dynload_win.c#L222
More information about the Python-Dev
mailing list