8000 try to patch around mutate + libvips 8.9.1 · libvips/ruby-vips@ce8ba1c · GitHub
[go: up one dir, main page]

Skip to content

Commit ce8ba1c

Browse files
committed
try to patch around mutate + libvips 8.9.1
libvips 8.9.1 had a terrible misfeature which would block metadata changes unless the object had a ref_count of 1. MutableImage will always have a ref_count of at least 2 (the parent gobject keeps a ref, and we keep a ref to the copy ready to return to our caller), so we must temporarily drop the refs to 1 around metadata changes. See #291
1 parent d0f2c22 commit ce8ba1c

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

CHANGELOG.md

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

33
## master
44

5+
## Version 2.1.1 (2021-5-3)
6+
7+
* fix "mutate" with libvips 8.9 [jcupitt]
8+
59
## Version 2.1.0 (2021-3-8)
610

711
* add "mutate" system [jcupitt]

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.0
1+
2.1.1

lib/vips/mutableimage.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,21 @@ def set_type! gtype, name, value
115115
gvalue = GObject::GValue.alloc
116116
gvalue.init gtype
117117
gvalue.set value
118-
Vips.vips_image_set self, name, gvalue
118+
119+
# libvips 8.9.1 had a terrible misfeature which would block metadata
120+
# modification unless the object had a ref_count of 1. MutableImage
121+
# will always have a ref_count of at least 2 (the parent gobject keeps a
122+
# ref, and we keep a ref to the copy ready to return to our caller),
123+
# so we must temporarily drop the refs to 1 around metadata changes.
124+
#
125+
# See https://github.com/libvips/ruby-vips/issues/291
126+
begin
127+
::GObject.g_object_unref self.ptr
128+
Vips.vips_image_set self, name, gvalue
129+
ensure
130+
::GObject.g_object_ref self.ptr
131+
end
132+
119133
gvalue.unset
120134
end
121135

@@ -148,7 +162,13 @@ def set! name, value
148162
#
149163
# @param name [String] Metadata field to remove
150164
def remove! name
151-
Vips.vips_image_remove self, name
165+
# see set_type! for an explanation
166+
begin
167+
::GObject.g_object_unref self.ptr
168+
Vips.vips_image_remove self, name
169+
ensure
170+
::GObject.g_object_ref self.ptr
171+
end
152172
end
153173
end
154174
end

lib/vips/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Vips
2-
VERSION = "2.1.0"
2+
VERSION = "2.1.1"
33
end

spec/image_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def has_jpeg?
115115
expect(im.bands).to eq(3)
116116
end
117117

118-
it "can set scale and offset on a convolution mask", version: [8, 10] do
118+
it "can set scale and offset on a convolution mask" do
119119
image = Vips::Image.new_from_array [1, 2], 8, 2
120120
expect(image.width).to eq(2)
121121
expect(image.height).to eq(1)

spec/mutate_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "spec_helper"
22

33
RSpec.describe Vips::MutableImage do
4-
it "can set! metadata in mutate", version: [8, 10] do
4+
it "can set! metadata in mutate" do
55
image = Vips::Image.black(16, 16)
66
image = image.mutate { |x|
77
x.set_type! GObject::GINT_TYPE, "banana", 12

0 commit comments

Comments
 (0)
0