Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f61f7a7

Browse files
authored
Merge pull request #385 from libvips/add-ref-to-new-from-source
new_from_source should ref the source object
2 parents dde924b + aaf7e33 commit f61f7a7

File tree

10 files changed

+37
-22
lines changed

10 files changed

+37
-22
lines changed

‎CHANGELOG.md‎

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

33
## master
44

5+
* `new_from_source` keeps a ref to the source object [taylorthurlow]
6+
* some fixes to object references system
7+
58
## Version 2.2.0 (2023年10月18日)
69

710
* add `draw_point!` [jcupitt]

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.0
1+
2.2.1

‎lib/vips/image.rb‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,14 @@ def self.new_from_source source, option_string, **opts
458458
loader = Vips.vips_foreign_find_load_source source
459459
raise Vips::Error if loader.nil?
460460

461-
Vips::Operation.call loader, [source], opts, option_string
461+
image = Vips::Operation.call loader, [source], opts, option_string
462+
463+
# keep a secret ref to the source object ... the libvips loader will
464+
# keep a ref to the C source object, but we need the ruby wrapper object
465+
# to stay alive too
466+
image.references << source
467+
468+
image
462469
end
463470

464471
def self.matrix_from_array width, height, array

‎lib/vips/interpolate.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class ManagedStruct < Vips::Object::ManagedStruct
4949

5050
def initialize name
5151
name = name.to_s if name.is_a? Symbol
52-
ptr = Vips.vips_interpolate_new name
53-
raise Vips::Error if ptr.nil?
52+
pointer = Vips.vips_interpolate_new name
53+
raise Vips::Error if pointer.nil?
5454

55-
superptr
55+
super(pointer)
5656
end
5757
end
5858
end

‎lib/vips/mutableimage.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def initialize(image)
5858
# See also the comment on set_type! before changing this.
5959
pointer = copy_image.ptr
6060
::GObject.g_object_ref pointer
61-
superpointer
61+
super(pointer)
6262

6363
# and save the copy ready for when we finish mutating
6464
@image = copy_image

‎lib/vips/operation.rb‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def initialize value
218218
raise Vips::Error if value.null?
219219
end
220220

221-
supervalue
221+
super(value)
222222
end
223223

224224
def build
@@ -283,7 +283,7 @@ def set name, value, match_image, flags, gtype, destructive
283283
value = value.map { |x| Operation.imageize match_image, x }
284284
end
285285

286-
supername, value
286+
super(name, value)
287287
end
288288

289289
public
@@ -440,14 +440,12 @@ def self.call name, supplied, optional = {}, option_string = ""
440440
end
441441
end
442442

443-
# collect a list of all input references here
444-
references = Set.new
443+
# dedupe all input references here
444+
deduped_references = Set.new
445445

446446
add_reference = lambda do |x|
447447
if x.is_a?(Vips::Image)
448-
x.references.each do |i|
449-
references << i
450-
end
448+
deduped_references.merge x.references
451449
end
452450
false
453451
end
@@ -482,20 +480,27 @@ def self.call name, supplied, optional = {}, option_string = ""
482480

483481
op = op.build
484482

483+
# we need an array of references for output objects
484+
references = deduped_references.to_a
485+
485486
# attach all input refs to output x
486487
set_reference = lambda do |x|
488+
# stop early if there are no refs to attach
489+
return true if references == []
490+
487491
if x.is_a? Vips::Image
488-
x.references += references
492+
references.each{ |i| x.references << i}
489493
end
494+
490495
false
491496
end
492497

493498
# get all required results
494499
result = []
495500
required_output.each do |details|
496-
value = details[:arg_name]
501+
value = op.get(details[:arg_name])
497502
flat_find value, &set_reference
498-
result << op.get(value)
503+
result << value
499504
end
500505

501506
# fetch all optional ones

‎lib/vips/region.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ class ManagedStruct < Vips::Object::ManagedStruct
4444
end
4545

4646
def initialize(name)
47-
ptr = Vips.vips_region_new name
48-
raise Vips::Error if ptr.null?
47+
pointer = Vips.vips_region_new name
48+
raise Vips::Error if pointer.null?
4949

50-
superptr
50+
super(pointer)
5151
end
5252

5353
def width

‎lib/vips/sourcecustom.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def initialize
4747
pointer = Vips.vips_source_custom_new
4848
raise Vips::Error if pointer.null?
4949

50-
superpointer
50+
super(pointer)
5151
end
5252

5353
# The block is executed to read data from the source. The interface is

‎lib/vips/targetcustom.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def initialize
4747
pointer = Vips.vips_target_custom_new
4848
raise Vips::Error if pointer.null?
4949

50-
superpointer
50+
super(pointer)
5151
end
5252

5353
# The block is executed to write data to the source. The interface is

‎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.2.0"
2+
VERSION = "2.2.1"
33
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /