Commit e414f7a7 authored by Hartmut Goebel's avatar Hartmut Goebel
Browse files

Fix crash on win32 for Python >= 3.12.

parent 28acabe8
Loading
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -499,12 +499,22 @@ def set_display_callback(instance, callback):


def __win32_finddll():

    from distutils.version import LooseVersion
    import os
    import re
    from winreg import OpenKey, CloseKey, EnumKey, QueryValueEx, \
        QueryInfoKey, HKEY_LOCAL_MACHINE

    def looseVersion(vstring):
        # Taken from distutils.LooseVersion.parse()
        component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)
        components = [x for x in component_re.split(vstring) if x and x != '.']
        for i, obj in enumerate(components):
            try:
                components[i] = int(obj)
            except ValueError:
                pass
        return components

    dlls = []
    # Look up different variants of Ghostscript and take the highest
    # version for which the DLL is to be found in the filesystem.
@@ -519,7 +529,7 @@ def __win32_finddll():
                    dll_path = QueryValueEx(k2, 'GS_DLL')[0]
                    CloseKey(k2)
                    if os.path.exists(dll_path):
                        dlls.append((LooseVersion(version), dll_path))
                        dlls.append((looseVersion(version), dll_path))
                except WindowsError:
                    pass
            CloseKey(k1)