Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lowlevel.py #247

Closed
wants to merge 1 commit into from
Closed

Update lowlevel.py #247

wants to merge 1 commit into from

Conversation

garnetri
Copy link

Adding in ctypes.util.find_library to enable cdll to find and load in the DLLs that were stored in windows environment variables. Apparently after Python 3.8 your environment variable's path is not searched for DLLs. This allows people to have the bin path added to environment variables for importing openslide without having to use the hacky os.add_dll_directory() method. Also enables sub-processes initiated by Python's multiprocessing package to properly import openslide.

Adding in ctypes.util.find_library to enable cdll to find and load in the DLLs that were stored in windows environment variables. Apparently after Python 3.8 your environment variable's path is not searched for DLLs. This allows people to have the bin path added to environment variables for importing openslide without having to use the hacky os.add_dll_directory() method. Also enables sub-processes initiated by Python's multiprocessing package to properly import openslide.

Signed-off-by: Richard Garnett <[email protected]>
@openslide-bot
Copy link

DCO signed off ✔️

All commits have been signed off. You have certified to the terms of the Developer Certificate of Origin, version 1.1. In particular, you certify that this contribution has not been developed using information obtained under a non-disclosure agreement or other license terms that forbid you from contributing it under the GNU Lesser General Public License, version 2.1.

@bgilbert
Copy link
Member

Thanks for the PR! Loading libraries from unintended locations can have security consequences, so it's important that we use a search path that doesn't surprise users. find_library() searches for libraries the way a linker would do at compile time, not the way a runtime loader would, so it's not an appropriate function to use here. os.add_dll_directory() is the function specifically provided by Python for managing the runtime DLL search path.

If you want to fetch the OpenSlide installation directory from an environment variable, you can use something like:

with os.add_dll_directory(os.environ['OPENSLIDE_INSTALL_PATH']):
    import openslide

@bgilbert bgilbert closed this Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants