Skip to content

Commit 2c55d8b

Browse files
committed
fix compat with semistatic libvips
we must fetch `g_*()` funcs from libvips if we can
1 parent badc358 commit 2c55d8b

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## master
44

5+
* fix compat with unified (semistatic) libvips binaries [kleisauke]
6+
57
## Version 2.2.1 (2024-02-21)
68

79
* add `Vips.block_untrusted` method to block all untrusted operations. Only for libvips >= 8.13. [Docs](https://www.libvips.org/API/current/libvips-vips.html#vips-block-untrusted-set). [#382](https://github.com/libvips/ruby-vips/pull/382) [aglushkov](https://github.com/aglushkov)

lib/vips.rb

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ def library_name(name, abi_number)
3333
end
3434
end
3535

36+
# we can sometimes get dependent libraries from libvips -- either the platform
37+
# will open dependencies for us automatically, or the libvips binary has been
38+
# built to includes all main dependencies (common on windows, can happen
39+
# elsewhere)
40+
#
41+
# we must get glib functions from libvips if we can, since it will be the
42+
# one that libvips itself is using, and they will share runtime types
43+
module Vips
44+
extend FFI::Library
45+
46+
ffi_lib library_name("vips", 42)
47+
48+
begin
49+
attach_function :g_malloc, [:size_t], :pointer
50+
@@is_unified = true
51+
rescue => e
52+
@@is_unified = false
53+
end
54+
55+
def self.unified?
56+
@@is_unified
57+
end
58+
end
59+
3660
module GLib
3761
class << self
3862
attr_accessor :logger
@@ -42,18 +66,10 @@ class << self
4266

4367
extend FFI::Library
4468

45-
if FFI::Platform.windows?
46-
# On Windows, `GetProcAddress()` can only search in a specified DLL and
47-
# doesn't look into its dependent libraries for symbols. Therefore, we
48-
# check if the GLib DLLs are available. If these can not be found, we
49-
# assume that GLib is statically linked into libvips.
50-
ffi_lib ["libglib-2.0-0.dll", "libvips-42.dll"]
51-
else
52-
# macOS and *nix uses `dlsym()`, which also searches for named symbols
53-
# in the dependencies of the shared library. Therefore, we can support
54-
# a single shared libvips library with all dependencies statically
55-
# linked.
69+
if Vips::unified?
5670
ffi_lib library_name("vips", 42)
71+
else
72+
ffi_lib library_name("glib-2.0", 0)
5773
end
5874

5975
attach_function :g_malloc, [:size_t], :pointer
@@ -146,10 +162,10 @@ def self.set_log_domain domain
146162
module GObject
147163
extend FFI::Library
148164

149-
if FFI::Platform.windows?
150-
ffi_lib ["libgobject-2.0-0.dll", "libvips-42.dll"]
151-
else
165+
if Vips::unified?
152166
ffi_lib library_name("vips", 42)
167+
else
168+
ffi_lib library_name("gobject-2.0", 0)
153169
end
154170

155171
# we can't just use ulong, windows has different int sizing rules
@@ -584,10 +600,8 @@ module GObject
584600
# {Image#median}.
585601

586602
module Vips
587-
extend FFI::Library
588-
589-
ffi_lib library_name("vips", 42)
590-
603+
# we've already opened the libvips library
604+
591605
LOG_DOMAIN = "VIPS"
592606
GLib.set_log_domain LOG_DOMAIN
593607

0 commit comments

Comments
 (0)