diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c3c1d6..38a12a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master +* fix compat with unified (semistatic) libvips binaries [kleisauke] + ## Version 2.2.1 (2024-02-21) * 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) diff --git a/lib/vips.rb b/lib/vips.rb index f0e7461..92af2e2 100644 --- a/lib/vips.rb +++ b/lib/vips.rb @@ -33,6 +33,30 @@ def library_name(name, abi_number) end end +# we can sometimes get dependent libraries from libvips -- either the platform +# will open dependencies for us automatically, or the libvips binary has been +# built to includes all main dependencies (common on windows, can happen +# elsewhere) +# +# we must get glib functions from libvips if we can, since it will be the +# one that libvips itself is using, and they will share runtime types +module Vips + extend FFI::Library + + ffi_lib library_name("vips", 42) + + begin + attach_function :g_malloc, [:size_t], :pointer + @@is_unified = true + rescue FFI::NotFoundError + @@is_unified = false + end + + def self.unified? + @@is_unified + end +end + module GLib class << self attr_accessor :logger @@ -42,7 +66,11 @@ class << self extend FFI::Library - ffi_lib library_name("glib-2.0", 0) + if Vips.unified? + ffi_lib library_name("vips", 42) + else + ffi_lib library_name("glib-2.0", 0) + end attach_function :g_malloc, [:size_t], :pointer @@ -134,7 +162,11 @@ def self.set_log_domain domain module GObject extend FFI::Library - ffi_lib library_name("gobject-2.0", 0) + if Vips.unified? + ffi_lib library_name("vips", 42) + else + ffi_lib library_name("gobject-2.0", 0) + end # we can't just use ulong, windows has different int sizing rules if FFI::Platform::ADDRESS_SIZE == 64 @@ -568,9 +600,7 @@ module GObject # {Image#median}. module Vips - extend FFI::Library - - ffi_lib library_name("vips", 42) + # we've already opened the libvips library LOG_DOMAIN = "VIPS" GLib.set_log_domain LOG_DOMAIN