Showing content from http://mail.python.org/pipermail/python-dev/attachments/20150311/56ceb6dd/attachment.html below:
<div dir="ltr">Hi,<div><br></div><div>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).</div><div><br></div><div>In python 2.7, the full path existence was even checked before calling into LoadLibraryEx (<a href="https://github.com/python/cpython/blob/2.7/Python/dynload_win.c#L189">https://github.com/python/cpython/blob/2.7/Python/dynload_win.c#L189</a>), but it looks like this check was removed in python 3.x branch.</div><div><br></div><div>Is there any defined behaviour that depends on this path to be relative ?</div><div><br></div><div>Context</div><div>-----------</div><div><br></div><div>The reason why I am interested in this is the potential use of SetDllDirectory to share dlls between multiple python extensions. Currently, the only solutions I am aware of are:</div><div><br></div><div>1. putting the dlls in the PATH</div><div>2. bundling the dlls side by side the .pyd</div><div>3. patching packages to use preloading (using e.g. ctypes)</div><div><br></div><div>I am investigating a solution 4, where the dlls would be put in a separate "private" directory only known of python itself, without the need to modify PATH.</div><div><br></div><div>Patching python to use SetDllDirectory("some private paths specific to a python interpreter") works perfectly, except that it slightly changes the semantics of LoadLibraryEx not to look for dlls in the current directory. This breaks importing extensions built in place, unless I modify the call in ;<a href="https://github.com/python/cpython/blob/2.7/Python/dynload_win.c#L195">https://github.com/python/cpython/blob/2.7/Python/dynload_win.c#L195</a> from:</div><div><br></div><div>  hDLL = LoadLibraryEx(pathname, NULL LOAD_WITH_ALTERED_SEARCH_PATH)</div><div><br></div><div>to</div><div><br></div><div><div>  hDLL = LoadLibraryEx(pathbuf, NULL LOAD_WITH_ALTERED_SEARCH_PATH)</div></div><div><br></div><div>That seems to work, but I am quite worried about changing any import semantics by accident.</div><div><br></div><div>David</div></div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4