Skip to content

Commit

Permalink
Merge pull request #390 from kleisauke/single-shared-vips-compat
Browse files Browse the repository at this point in the history
Ensure compatibility with a single shared libvips library
  • Loading branch information
jcupitt authored Mar 7, 2024
2 parents 866f509 + 2cb995d commit 74c20e6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 35 additions & 5 deletions lib/vips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 74c20e6

Please sign in to comment.