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

Ensure compatibility with a single shared libvips library #390

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
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
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