rmagick 7.2.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 765ab71db74f8e2497d857f4041b604abbf848bdcc49d91ae9eb83c13c8dc130
4
- data.tar.gz: 1466fca25cf24eb504a197f5db46f1a2ae36e5750d4bc82b2e08836efc6fc3b1
3
+ metadata.gz: '09372c7698fc80c0ea619f2b566dd9e8ba7813d533619229ae20decc4313d819'
4
+ data.tar.gz: d4a17a4be2d9238ab0956a8131ecad8eef4b7a1a504f45befaea2d621cc0e578
5
5
  SHA512:
6
- metadata.gz: e5f6bc440331557b902c94cf9665f572bb50f48242f1760c5cec131d9b86af2d6a92592d43077429ad90cd11171000be3e8c9ba9fb848ed11be515a431e1ee3b
7
- data.tar.gz: e8cc721b925f6ff4217870ad1234b7e2eb59573a3e951056bf494d50c9855230e80f4564270e0aea067782adacdb3d202b91cbafd8318fff711919c4138751b8
6
+ metadata.gz: b94b7fcc8e70efe73fcc3f3487a61a413425ee0d2b62dde6b57eb5bc2beef2aea85c46d9d5f4531a54aa3c222302fdc8b21fe3e01606839a40bc35e67e2576de
7
+ data.tar.gz: 880da906677f1362ee31ae2e51675e85c142741a6a32083f4077e4ea581dfc5ed6a8e5a26844f6a7a6177009e49968ab2b4bafea04ceddfe884242d1a9d10c38
data/CHANGELOG.md CHANGED
@@ -3,6 +3,130 @@
3
3
  All notable changes to this project are documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## RMagick 7.3.0
7
+
8
+ > [!IMPORTANT]
9
+ > Some results change for CMYK colors, `Image#get_pixels` rejects a negative offset, and more calls raise for an object that is frozen or in use, or for an invalid argument.
10
+ >
11
+ > `Pixel#<=>`, `#==`, `#eql?` and `#hash` now include the black channel, so CMYK pixels that differ only in black are no longer equal. With ImageMagick 7, `Pixel.from_color` converts a `cmyk()` color name to RGB as ImageMagick 6 does, so the black of that pixel is 0. For a CMYK image, `Image#background_color`, `#border_color`, `#matte_color`, `#transparent_color` and `#colormap` return the color name in sRGB instead of a 20-digit hex name that no method could parse. With ImageMagick 7, the color attributes of `Image::Info` name a `cmyk()` color by its sRGB value instead of reading its CMYK values as RGB.
12
+ >
13
+ > `Image#get_pixels` now raises `RangeError` for a negative `x` or `y`, as `Image#store_pixels` does. It used to return the virtual pixels left of or above the image.
14
+ >
15
+ > `Image#freeze` and `KernelInfo#freeze`, which `Ractor.make_shareable` also calls, now raise `RuntimeError` while a call is changing the object. Destroying, replacing or changing an object that ImageMagick is using, from a trap handler, a finalizer or another thread, raises `RuntimeError` ("object is in use by another fiber") where it could crash before. Calling `initialize` or `marshal_load` again on a frozen object, and `GradientFill#fill` or `TextureFill#fill` on a frozen image, raise `FrozenError`, as does `initialize` on an existing `Magick::Enum` value. `clone(freeze: true)` on an `Info` or a `Montage` raises `TypeError`, as their `#freeze` does.
16
+ >
17
+ > Some arguments that were accepted silently now raise. `Image#chromaticity=` raises `TypeError` for a `Chromaticity` whose member is not a `Primary`, such as a Hash. `Image#paint_transparent` raises `ArgumentError` for a negative fuzz, as `opaque_channel` does. `Font#to_s` raises `TypeError` for a weight that is not a number or a style or stretch of the wrong class, and `ArgumentError` for a negative weight.
18
+
19
+ Breaking Changes
20
+
21
+ * Fix Image#get_pixels reading outside the image with a negative offset (#2060)
22
+ * Prevent freezing an image while a call is changing it (#2051)
23
+ * Fix the names of CMYK colors in Image::Info on ImageMagick 7 (#2040)
24
+ * Fix the names of the background, matte and transparent colors of a CMYK image (#2039)
25
+ * Fix Pixel.from_color with a CMYK color name on ImageMagick 7 (#2038)
26
+ * Fix reading and setting colormap colors of a CMYK image (#2037)
27
+ * Fix filling to the border color of a CMYK image (#2035)
28
+ * Fix Color#to_s and Font#to_s with nil names, a wrong member type or a raising member (#2021)
29
+ * Prevent changing a frozen Info or Montage (#2017)
30
+ * Prevent re-initializing an Enum value (#2016)
31
+ * Fix opaque_channel and paint_transparent ignoring a fuzz smaller than the image's fuzz (#2015)
32
+ * Fix crash when a Struct's #values does not return an Array (#2014)
33
+ * Fix Pixel comparison treating CMYK pixels that differ only in black as equal (#1984)
34
+
35
+ Improvements
36
+
37
+ * Document the offset that Image#frame needs and fix its default arguments in the API reference (#2043)
38
+ * Reduce the memory of Magick::Pixel by embedding it in its object on Ruby 4.1 (#1976)
39
+ * Let fibers use copies of an image at once (#1947)
40
+ * Reduce peak memory by freeing unused images as soon as the GC finds them (#1935)
41
+
42
+ Bug Fixes
43
+
44
+ * Keep a SIGCHLD trap that is set while an image is read on macOS and FreeBSD (#2069)
45
+ * Keep the user's SIGCHLD handler when Ractors read images at the same time on macOS and FreeBSD (#2068)
46
+ * Fix ImageList methods crashing when `@images` is not an Array (#2066)
47
+ * Fix Image#colormap leaving a freed colormap after a failed growth (#2065)
48
+ * Fix KernelInfo#initialize destroying a kernel that another Ractor is using (#2064)
49
+ * Fix Image#dispatch and other pixel methods reading a moved String when the GC compacts (#2063)
50
+ * Fix Info#[], #[]= and #define using a corrupted option name when the GC compacts (#2062)
51
+ * Fix Draw losing interline_spacing through Marshal (#2059)
52
+ * Fix Marshal.load with freeze: true failing for an Image or ImageList (#2058)
53
+ * Fix leaking the extra images of multi-image dumps and profile files (#2057)
54
+ * Fix GradientFill#fill and TextureFill#fill writing to a frozen image (#2056)
55
+ * Fix calls on an image reading the other images of an ImageList method in flight (#2055)
56
+ * Fix optimize_layers with TrimBoundsLayer raising an error and changing the list (#2054)
57
+ * Fix ImageList calls crashing when another thread links the same image (#2053)
58
+ * Fix ImageList methods using images that are frozen or destroyed while they run (#2052)
59
+ * Fix bang methods replacing an image that was frozen while they ran (#2050)
60
+ * Fix Image#marshal_load changing a frozen image and crashing other Ractors (#2049)
61
+ * Fix marshal_load leaking patterns and leaving Draw and Pixel half loaded (#2048)
62
+ * Fix Image#frame crashing when the image and the bevels do not fit in the frame (#2042)
63
+ * Fix Image#frame changing the matte color of the image (#2041)
64
+ * Fix Magick::Enum#to_s and #inspect on an enum created with allocate (#2031)
65
+ * Fix a NUL byte in an Info option name silently selecting a different option (#2030)
66
+ * Fix MVG injection when a Draw text or style value is not UTF-8 (#2029)
67
+ * Fix crash and hang when the process exits while another Ractor uses ImageMagick (#2027)
68
+ * Fix use-after-free when an object is destroyed or replaced while ImageMagick uses it (#2026)
69
+ * Fix Magick.fonts and Magick.colors raising for an entry with a missing attribute, and leaking their lists (#2025)
70
+ * Fix Draw#composite, Info#texture= and Montage#texture= clashing with images written to mpr: (#2023)
71
+ * Fix Info#define reading an uninitialized variable with two arguments (#2022)
72
+ * Fix memory leak in Image#color_histogram when building the Hash raises (#2020)
73
+ * Fix a subclass or an object with singleton methods being rejected as a Pixel, Struct or Geometry (#2019)
74
+ * Fix memory leak in Image#sparse_color when a color argument is invalid (#2018)
75
+ * Fix changing a Draw, even a frozen one, by appending to the result of #inspect or #marshal_dump (#2013)
76
+ * Fix ImageList#quantize returning unquantized images when quantizing fails on IM6 (#2012)
77
+ * Fix Draw setters and initialize_copy writing to a Draw that became frozen or in use (#2011)
78
+ * Fix reading freed memory in Image#[]=, #define, #chromaticity, ._load, Draw#annotate and Info options (#2010)
79
+ * Fix leaks when blue_shift, to_blob, mask and other methods fail (#2009)
80
+ * Fix leaks when Thread#raise interrupts Image.read, texture_flood_fill and other methods (#2008)
81
+ * Fix ImageList methods leaving their images linked when Thread#raise interrupts them (#2007)
82
+ * Fix leaks and a stuck channel mask when Thread#raise interrupts composite_tiled and others (#2006)
83
+ * Fix a crash in composite_tiled and GradientFill#fill when #cur_image returns a new image (#2005)
84
+ * Fix crashes when converting an argument destroys or replaces the image (#2004)
85
+ * Fix dup and clone of Enum, Info, Montage, DrawOptions and PolaroidOptions (#2003)
86
+ * Fix dup and clone of TextureFill and GradientFill losing their settings (#2002)
87
+ * Fix TextureFill#initialize leaking the texture it replaces (#2001)
88
+ * Fix Draw#initialize leaking the DrawInfo it replaces (#2000)
89
+ * Fix a copy of a Draw losing its composited images when the original is freed (#1996)
90
+ * Fix Draw#initialize_copy leaking the DrawInfo it replaces (#1997)
91
+ * Fix Draw#composite, Info#texture= and Montage#texture= raising in a Ractor (#1995)
92
+ * Fix methods that return an enum value raising in a Ractor (#1994)
93
+ * Fix undefined symbol rb_ractor_local_storage_value_newkey when loading RMagick on TruffleRuby (#1993)
94
+ * Fix undefined symbol rb_ractor_make_shareable when loading RMagick on TruffleRuby (#1992)
95
+ * Fix TruffleRuby aborting when ImageMagick allocates memory on its OpenMP threads (#1991)
96
+ * Fix Draw#get_type_metrics raising in a Ractor when no image is given (#1990)
97
+ * Fix color names matching and painting the wrong colors on a CMYK image (#1989)
98
+ * Fix Image#initialize leaking memory and changing a frozen image when called again (#1988)
99
+ * Fix Image#opaque and others ignoring black of a CMYK color (#1987)
100
+ * Fix Marshal dropping the black channel of a Pixel (#1985)
101
+ * Fix wrong results for negative, NaN and huge HDRI pixel values (#1983)
102
+ * Fix memory leak in Image#import_pixels when converting a pixel array raises (#1982)
103
+ * Fix Image#import_pixels wrapping an out-of-range value in an array (#1981)
104
+ * Fix Pixel#<=> returning a wrong order for values less than 1 apart with HDRI (#1980)
105
+ * Fix Image#get_pixels reading a pixel 1 lower than pixel_color does with HDRI (#1979)
106
+ * Fix Pixel#marshal_load, #initialize and #initialize_copy changing a frozen Pixel (#1978)
107
+ * Fix a GC left in progress after ImageMagick allocates a lot (#1977)
108
+ * Fix Image.constitute wrapping an out-of-range integer pixel value (#1974)
109
+ * Fix Image#pixel_color writing a color name as the wrong color on a CMYK image (#1973)
110
+ * Fix Image#store_pixels and #get_pixels accepting a negative or huge size (#1972)
111
+ * Fix Image#composite_mathematics and #watermark ignoring their arguments (#1970)
112
+ * Fix block options of Image#compare_channel and #distort staying on the image (#1969)
113
+ * Fix Image#deskew ignoring auto_crop_width (#1968)
114
+ * Fix Image.new and Image#add_compose_mask ignoring errors on ImageMagick 6 (#1966)
115
+ * Fix Image#class_type= and #image_type= silently failing on ImageMagick 6 (#1965)
116
+ * Fix crash in Image#morphology with a KernelInfo that is not initialized (#1964)
117
+ * Fix memory leak in Image#polaroid when ImageMagick reports an error (#1963)
118
+ * Fix another fiber changing the options of a running Image#polaroid (#1960)
119
+ * Fix crash in Image#chop and #shave when an earlier error is left on the image (#1959)
120
+ * Fix crash in Image#distortion_channel when ImageMagick runs out of resources (#1958)
121
+ * Fix wrong results when Ractors call Image#difference on a shared frozen image (#1956)
122
+ * Fix heap corruption when Ractors read the properties of a frozen image (#1955)
123
+ * Fix wrong signatures when Ractors share a frozen image (#1954)
124
+ * Fix crash when Ractors draw with a frozen pattern that they share (#1953)
125
+ * Fix crash when Ractors write a frozen image that they share (#1952)
126
+ * Fix a crash when Ractors use a shared frozen ImageList at the same time (#1945)
127
+ * Keep a frozen image or Draw unchanged while a method uses it (#1944)
128
+ * Raise when another Ractor uses an object that an offloaded call is using (#1942)
129
+
6
130
  ## RMagick 7.2.0
7
131
 
8
132
  > [!IMPORTANT]
data/README.md CHANGED
@@ -197,7 +197,8 @@ See <https://rmagick.github.io/usage.html> for links to more information.
197
197
  RMagick releases the GVL while ImageMagick works, so calls on different images run in parallel.
198
198
 
199
199
  - Use each image from one thread at a time. To work in parallel, give each thread its own images.
200
- - On Ruby 4.0 and later, a Fiber scheduler with a worker pool, such as `Async::Scheduler.new(worker_pool: IO::Event::WorkerPool.new)`, runs heavy calls on its workers, and the other fibers keep running. While such a call uses an image, using that image from another fiber raises `RuntimeError` ("object is in use by another fiber").
200
+ - Freezing an image or a `KernelInfo`, for example with `Ractor.make_shareable`, raises `RuntimeError` ("object is in use by another fiber") while a call in another thread or fiber is changing it. `to_blob`, `write` and `Marshal.dump` change the image too.
201
+ - On Ruby 4.0 and later, a Fiber scheduler with a worker pool, such as `Async::Scheduler.new(worker_pool: IO::Event::WorkerPool.new)`, runs heavy calls on its workers, and the other fibers keep running. While such a call uses an image, using that image from another fiber, or from another Ractor that shares it frozen, raises `RuntimeError` ("object is in use by another fiber").
201
202
  - Each call in flight holds its images in memory, so memory use grows with the number of workers. Limit the calls that run at once, for example with `Async::Semaphore`.
202
203
  - `Thread#raise`, `Timeout` and Ctrl-C reach a thread after the ImageMagick call returns. An exception raised in a `trap` handler can unwind through ImageMagick instead.
203
204
  - Do not fork while other threads or workers are running ImageMagick. The child can hang on a lock that they held.
@@ -81,7 +81,7 @@ module RMagick
81
81
  end
82
82
 
83
83
  def configure_headers
84
- @headers = %w[assert.h ctype.h stdio.h stdlib.h math.h time.h sys/types.h ruby.h ruby/io.h ruby/fiber/scheduler.h]
84
+ @headers = %w[assert.h ctype.h stdio.h stdlib.h math.h time.h sys/types.h ruby.h ruby/io.h ruby/fiber/scheduler.h ruby/ractor.h]
85
85
 
86
86
  if have_header('MagickCore/MagickCore.h')
87
87
  headers << 'MagickCore/MagickCore.h'
@@ -276,12 +276,15 @@ module RMagick
276
276
  def create_header_file
277
277
  ruby_api = [
278
278
  'rb_io_path', # Ruby 3.3.0
279
- 'rb_fiber_scheduler_blocking_operation_extract' # Ruby 4.0.0
279
+ 'rb_fiber_scheduler_blocking_operation_extract', # Ruby 4.0.0
280
+ 'rb_ractor_make_shareable', # Not in TruffleRuby
281
+ 'rb_ractor_local_storage_value_newkey' # Not in TruffleRuby
280
282
  ]
281
283
  memory_api = %w[
282
284
  posix_memalign
283
285
  malloc_usable_size
284
286
  malloc_size
287
+ _msize
285
288
  _aligned_msize
286
289
  ]
287
290
  imagemagick_api = [
@@ -13,17 +13,62 @@
13
13
 
14
14
 
15
15
 
16
+ template <typename Info>
17
+ struct InfoList
18
+ {
19
+ const Info **list;
20
+ size_t count;
21
+ };
22
+
23
+ template <typename Info, VALUE (*import)(const Info *)>
16
24
  static VALUE
17
- rm_yield_body(VALUE object)
25
+ info_list_to_ary(VALUE arg)
18
26
  {
19
- return rb_yield(object);
27
+ InfoList<Info> *infos = (InfoList<Info> *)arg;
28
+ VALUE ary = rb_ary_new2((long)infos->count);
29
+
30
+ for (size_t x = 0; x < infos->count; x++)
31
+ {
32
+ rb_ary_push(ary, import(infos->list[x]));
33
+ }
34
+
35
+ return ary;
20
36
  }
21
37
 
38
+ template <typename Info>
22
39
  static VALUE
23
- rm_yield_handle_exception(VALUE allocated_area, VALUE exc)
40
+ free_info_list(VALUE arg)
24
41
  {
25
- magick_free((void *)allocated_area);
26
- rb_exc_raise(exc);
42
+ magick_free((void *)((InfoList<Info> *)arg)->list);
43
+ return Qnil;
44
+ }
45
+
46
+ // Free the list before yielding, since Ruby never runs the ensure of an
47
+ // enumerator that is abandoned part way.
48
+ template <typename Info, VALUE (*import)(const Info *)>
49
+ static VALUE
50
+ each_info(VALUE klass, const Info **list, size_t count, ExceptionInfo *exception)
51
+ {
52
+ if (rm_should_raise_exception(exception, DestroyExceptionRetention))
53
+ {
54
+ magick_free((void *)list);
55
+ rm_raise_exception(exception);
56
+ }
57
+
58
+ InfoList<Info> infos = { list, count };
59
+ VALUE ary = rb_ensure(info_list_to_ary<Info, import>, (VALUE)&infos, free_info_list<Info>, (VALUE)&infos);
60
+
61
+ if (!rb_block_given_p())
62
+ {
63
+ return ary;
64
+ }
65
+ for (long x = 0; x < RARRAY_LEN(ary); x++)
66
+ {
67
+ rb_yield(RARRAY_AREF(ary, x));
68
+ }
69
+
70
+ RB_GC_GUARD(ary);
71
+ return klass;
27
72
  }
28
73
 
29
74
  /**
@@ -42,38 +87,13 @@ VALUE
42
87
  Magick_colors(VALUE klass)
43
88
  {
44
89
  const ColorInfo **color_info_list;
45
- size_t number_colors, x;
46
- VALUE ary;
90
+ size_t number_colors;
47
91
  ExceptionInfo *exception;
48
92
 
49
93
  exception = AcquireExceptionInfo();
50
-
51
94
  color_info_list = GetColorInfoList("*", &number_colors, exception);
52
- CHECK_EXCEPTION();
53
- DestroyExceptionInfo(exception);
54
-
55
95
 
56
- if (rb_block_given_p())
57
- {
58
- for (x = 0; x < number_colors; x++)
59
- {
60
- rb_rescue(RESCUE_FUNC(rm_yield_body), Import_ColorInfo(color_info_list[x]), RESCUE_EXCEPTION_HANDLER_FUNC(rm_yield_handle_exception), (VALUE)color_info_list);
61
- }
62
- magick_free((void *)color_info_list);
63
- return klass;
64
- }
65
- else
66
- {
67
- ary = rb_ary_new2((long) number_colors);
68
- for (x = 0; x < number_colors; x++)
69
- {
70
- rb_ary_push(ary, Import_ColorInfo(color_info_list[x]));
71
- }
72
-
73
- magick_free((void *)color_info_list);
74
- RB_GC_GUARD(ary);
75
- return ary;
76
- }
96
+ return each_info<ColorInfo, Import_ColorInfo>(klass, color_info_list, number_colors, exception);
77
97
  }
78
98
 
79
99
 
@@ -93,36 +113,13 @@ VALUE
93
113
  Magick_fonts(VALUE klass)
94
114
  {
95
115
  const TypeInfo **type_info;
96
- size_t number_types, x;
97
- VALUE ary;
116
+ size_t number_types;
98
117
  ExceptionInfo *exception;
99
118
 
100
119
  exception = AcquireExceptionInfo();
101
120
  type_info = GetTypeInfoList("*", &number_types, exception);
102
- CHECK_EXCEPTION();
103
- DestroyExceptionInfo(exception);
104
-
105
- if (rb_block_given_p())
106
- {
107
- for (x = 0; x < number_types; x++)
108
- {
109
- rb_rescue(RESCUE_FUNC(rm_yield_body), Import_TypeInfo((const TypeInfo *)type_info[x]), RESCUE_EXCEPTION_HANDLER_FUNC(rm_yield_handle_exception), (VALUE)type_info);
110
- }
111
- magick_free((void *)type_info);
112
- return klass;
113
- }
114
- else
115
- {
116
- ary = rb_ary_new2((long)number_types);
117
- for (x = 0; x < number_types; x++)
118
- {
119
- rb_ary_push(ary, Import_TypeInfo((const TypeInfo *)type_info[x]));
120
- }
121
- magick_free((void *)type_info);
122
- RB_GC_GUARD(ary);
123
- return ary;
124
- }
125
121
 
122
+ return each_info<TypeInfo, Import_TypeInfo>(klass, type_info, number_types, exception);
126
123
  }
127
124
 
128
125
 
@@ -423,7 +420,7 @@ Magick_set_log_event_mask(int argc, VALUE *argv, VALUE klass)
423
420
  const char *event = StringValueCStr(argv[x]);
424
421
  if (ParseCommandOption(MagickLogEventOptions, MagickTrue, event) == -1)
425
422
  {
426
- rb_raise(rb_eArgError, "invalid log event type: %s", event);
423
+ rb_raise(rb_eArgError, "invalid log event type: %" PRIsVALUE, argv[x]);
427
424
  }
428
425
  }
429
426