Eryk Sun <eryk...@gmail.com> added the comment:

> Proposal #1: CPython calls SetDefaultDllDirectories() [2] on startup 

SetDefaultDllDirectories() affects the entire process, so it would needlessly 
break the world -- especially for embedding applications and ctypes users that 
have relied on adding directories to PATH. When loading an extension module, we 
can simply replace LOAD_WITH_ALTERED_SEARCH_PATH in the LoadLibraryExW flags 
with LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR and LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 
(application directory, System32 directory, and directories added via 
SetDllDirectoryW and AddDllDirectory). Writers of extension modules are 
constrained by our API. We'll simply mandate that PATH is no longer searched.

It's cumbersome to require packages to have to manually call AddDllDirectory 
before being able to import an extension module with dependencies. We could 
create a protocol to store relative paths as an embedded resource in the 
extension module, which would be similar to the RPATH/RUNPATH $ORIGIN field in 
POSIX. We'd first map the extension module as a data file via 
LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE. Load and resolve the 
relative paths, add them via AddDllDirectory. Call LoadLibraryExW with the 
above-mentioned flags. Then remove the directories via RemoveDllDirectory.

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36085>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to