Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
building: collect built-in extensions into lib-dynload sub-directory (#…
…5604) * tests: add test for ctypes.CDLL incorrectly picking up builtin extension libraries On linux and macOS, some of the built-ins are provided as extensions (e.g., _sha1.cpython-39-x86_64-linux-gnu.so) that originally reside in python3.X/lib-dynload directory. This directory is not in the ctypes' library search path, therefore running ctypes.CDLL('_sha1.cpython-39-x86_64-linux-gnu.so') in python interpreter will come up empty. In a frozen application, however, these extensions end up collected directly in the _MEIPASS, which is searched by ctypes (because search behavior is explicitly overriden by the hook). Therefore, trying to load the extension's library file via ctypes.CDLL() will succeed, resulting in inconsistent behavior between unfrozen and frozen program. On macOS, this causes issues with `pycryptodomex` (#5583), which, due to its library search implementation, ends up with handle of `_sha1` extension module instead of its private extension/library with the same name prefix. * building: collect built-in extensions into lib-dynload sub-directory On macOS and linux, some of the python's built-ins have extension modules that originally reside in python3.X/lib-dynload directory. This directory is in sys.path, therefore the collected extensions have no parent directory and end up directly in the _MEIPASS. This commit explicitly diverts such extensions into lib-dynload sub-directory in the _MEIPASS. In addition to decluttering the _MEIPASS on linux and macOS, this also prevents ctypes.CDLL() from picking up the extensions' shared libraries and causing inconsistent behavior between frozen and unfrozen application, which in some corner cases leads to issues with shadowing, such as in #5583. * bootloader: add _MEIPASS/lib-dynload to the initial sys.path * bootloader: ensure pypath and pypath_w buffers are of same size Having pypath with greater size than pypath_w invites potential trouble when path to executable is long enough that length of pypath string exceeds PATH_MAX. And it makes little sense for the two buffers to be of differently sized, anyway. * rebuild bootloaders Co-authored-by: Legorooj <legorooj@protonmail.com>
- Loading branch information
Showing
22 changed files
with
63 additions
and
10 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(OSX) Fix issues with ``pycryptodomex`` on macOS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Collect python extension modules that correspond to built-ins into | ||
``lib-dynload`` sub-directory instead of directly into bundle's root | ||
directory. This prevents them from shadowing shared libraries with the | ||
same basename that are located in a package and loaded via ``ctypes`` or | ||
``cffi``, and also declutters the bundle's root directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters