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

Set explicit flags when loading DLLs on Windows #2238

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading