Skip to content

Commit

Permalink
Ensure compatibility with a single shared libvips library (#444)
Browse files Browse the repository at this point in the history
See: #443
  • Loading branch information
kleisauke committed Jan 4, 2024
1 parent a9688b9 commit c380493
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions pyvips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,35 @@

# yuk
if _is_windows:
_glib_libname = 'libglib-2.0-0.dll'
_gobject_libname = 'libgobject-2.0-0.dll'
_vips_libname = 'libvips-42.dll'
vips_lib = ffi.dlopen('libvips-42.dll')
elif _is_mac:
_glib_libname = None
_vips_libname = 'libvips.42.dylib'
_gobject_libname = 'libgobject-2.0.dylib'
vips_lib = ffi.dlopen('libvips.42.dylib')
else:
_glib_libname = None
_vips_libname = 'libvips.so.42'
_gobject_libname = 'libgobject-2.0.so.0'

# possibly use ctypes.util.find_library() to locate the lib?
gobject_lib = ffi.dlopen(_gobject_libname)
vips_lib = ffi.dlopen(_vips_libname)
if _glib_libname:
glib_lib = ffi.dlopen(_glib_libname)
else:
glib_lib = gobject_lib
vips_lib = ffi.dlopen('libvips.so.42')

logger.debug('Loaded lib %s', vips_lib)
logger.debug('Loaded lib %s', gobject_lib)

if _is_windows:
# On Windows, `GetProcAddress()` can only search in a specified DLL and
# doesn't look into its dependent libraries for symbols. Therefore, we
# check if the GLib DLLs are available. If these can not be found, we
# assume that GLib is statically linked into libvips.
try:
glib_lib = ffi.dlopen('libglib-2.0-0.dll')
gobject_lib = ffi.dlopen('libgobject-2.0-0.dll')

logger.debug('Loaded lib %s', glib_lib)
logger.debug('Loaded lib %s', gobject_lib)
except Exception:
glib_lib = vips_lib
gobject_lib = vips_lib
else:
# macOS and *nix uses `dlsym()`, which also searches for named symbols
# in the dependencies of the shared library. Therefore, we can support
# a single shared libvips library with all dependencies statically
# linked.
glib_lib = vips_lib
gobject_lib = vips_lib

ffi.cdef('''
int vips_init (const char* argv0);
Expand Down

0 comments on commit c380493

Please sign in to comment.