Skip to content

Commit

Permalink
Merge pull request #2238 from Kozea/windows-flags
Browse files Browse the repository at this point in the history
Set explicit flags when loading DLLs on Windows
  • Loading branch information
liZe authored Aug 23, 2024
2 parents 176bd71 + 57cbd29 commit 95a4253
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions weasyprint/text/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,13 @@

def _dlopen(ffi, *names, allow_fail=False):
"""Try various names for the same library, for different platforms."""
if os.name == 'nt':
flags = 0x00001000 # LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
else:
flags = ffi.RTLD_NOW # default
for name in names:
with suppress(OSError):
return ffi.dlopen(name)
return ffi.dlopen(name, flags)
if allow_fail:
return
# Re-raise the exception.
Expand All @@ -468,37 +472,36 @@ def _dlopen(ffi, *names, allow_fail=False):
'https://doc.courtbouillon.org/weasyprint/stable/'
'first_steps.html#troubleshooting',
'\n\n-----\n') # pragma: no cover
return ffi.dlopen(names[0]) # pragma: no cover
return ffi.dlopen(names[0], flags) # pragma: no cover


if hasattr(os, 'add_dll_directory'): # pragma: no cover
dll_directories = os.getenv(
'WEASYPRINT_DLL_DIRECTORIES',
'C:\\Program Files\\GTK3-Runtime Win64\\bin;'
'C:\\msys64\\mingw64\\bin').split(';')
'C:\\msys64\\mingw64\\bin;'
'C:\\Program Files\\GTK3-Runtime Win64\\bin').split(';')
for dll_directory in dll_directories:
with suppress((OSError, FileNotFoundError)):
os.add_dll_directory(dll_directory)

gobject = _dlopen(
ffi, 'gobject-2.0-0', 'gobject-2.0', 'libgobject-2.0-0',
ffi, 'libgobject-2.0-0', 'gobject-2.0-0', 'gobject-2.0',
'libgobject-2.0.so.0', 'libgobject-2.0.dylib', 'libgobject-2.0-0.dll')
pango = _dlopen(
ffi, 'pango-1.0-0', 'pango-1.0', 'libpango-1.0-0', 'libpango-1.0.so.0',
ffi, 'libpango-1.0-0', 'pango-1.0-0', 'pango-1.0', 'libpango-1.0.so.0',
'libpango-1.0.dylib', 'libpango-1.0-0.dll')
harfbuzz = _dlopen(
ffi, 'harfbuzz', 'harfbuzz-0.0', 'libharfbuzz-0',
'libharfbuzz.so.0', 'libharfbuzz.so.0', 'libharfbuzz.0.dylib',
'libharfbuzz-0.dll')
ffi, 'libharfbuzz-0', 'harfbuzz', 'harfbuzz-0.0',
'libharfbuzz.so.0', 'libharfbuzz.0.dylib', 'libharfbuzz-0.dll')
harfbuzz_subset = _dlopen(
ffi, 'harfbuzz-subset', 'harfbuzz-subset-0.0', 'libharfbuzz-subset-0',
'libharfbuzz-subset.so.0', 'libharfbuzz-subset.so.0', 'libharfbuzz-subset.0.dylib',
'libharfbuzz-subset-0.dll', allow_fail=True)
ffi, 'libharfbuzz-subset-0', 'harfbuzz-subset', 'harfbuzz-subset-0.0',
'libharfbuzz-subset.so.0', 'libharfbuzz-subset.0.dylib', 'libharfbuzz-subset-0.dll',
allow_fail=True)
fontconfig = _dlopen(
ffi, 'fontconfig-1', 'fontconfig', 'libfontconfig', 'libfontconfig.so.1',
'libfontconfig.1.dylib', 'libfontconfig-1.dll')
ffi, 'libfontconfig-1', 'fontconfig-1', 'fontconfig',
'libfontconfig.so.1', 'libfontconfig.1.dylib', 'libfontconfig-1.dll')
pangoft2 = _dlopen(
ffi, 'pangoft2-1.0-0', 'pangoft2-1.0', 'libpangoft2-1.0-0',
ffi, 'libpangoft2-1.0-0', 'pangoft2-1.0-0', 'pangoft2-1.0',
'libpangoft2-1.0.so.0', 'libpangoft2-1.0.dylib', 'libpangoft2-1.0-0.dll')

gobject.g_type_init()
Expand Down

0 comments on commit 95a4253

Please sign in to comment.