Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hardbyte/python-can
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: davidva-ecco/python-can
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Apr 16, 2025

  1. Rework loading vxlapi/vxlapi64.dll so locations added with os.add_dll…

    …_directory() are searched
    
    In Python 3.8, DLL loading changed, and the recommended way to add arbitrary directories to the search locations is with os.add_dll_directory(), see https://docs.python.org/3/library/os.html#os.add_dll_directory
    
    can/interfaces/vector/xldriver.py used ctypes.util.find_library() to first get a path to the vxlapi/vxlapi64 for the DLLs; if a path was found, the DLL was loaded with ctypes.windll.LoadLibrary(<DLL path>), if not, a FileNotFoundError exception was manually raised.
    
    find_library() only searches paths in os.environ['PATH'], which does not include directories added with os.add_dll_directory(), so find_library() fails if the vxlapi DLLs are located in an arbitrary (non-standard) directory, whether or not the directory was first added with add_dll_directory().
    
    LoadLibrary() raises a FileNotFoundError if the DLL cannot be located, and it will look in the standard locations and arbitrary locations added with add_dll_directory().  So, rather than trying to find the DLL first with find_library(), simply wrap the LoadLibrary() call in a try/except block and raise any exceptions.
    
    This has two benefits: first, it allows the vxlapi DLLs to be located in an arbitrary directory that can be added in an end-user script with os.add_dll_directory(); second, it catches other exceptions raised by LoadLibrary().
    davidva-ecco committed Apr 16, 2025
    Configuration menu
    Copy the full SHA
    9a22c05 View commit details
    Browse the repository at this point in the history
Loading