rmagick 4.3.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rmagick might be problematic. Click here for more details.

@@ -10,8 +10,28 @@
10
10
 
11
11
  #include "rmagick.h"
12
12
 
13
+ static void rm_kernel_info_destroy(void *kernel);
14
+ static size_t rm_kernel_info_memsize(const void *ptr);
15
+
16
+ const rb_data_type_t rm_kernel_info_data_type = {
17
+ "Magick::KernelInfo",
18
+ { NULL, rm_kernel_info_destroy, rm_kernel_info_memsize, },
19
+ 0, 0,
20
+ RUBY_TYPED_FROZEN_SHAREABLE,
21
+ };
22
+
23
+ /* UnityAddKernelInfo() was private function until IM 6.9 */
24
+ MagickExport void UnityAddKernelInfo(KernelInfo *kernel, const double scale);
25
+ /* ScaleKernelInfo() was private function until IM 6.9 */
26
+ MagickExport void ScaleKernelInfo(KernelInfo *kernel, const double scaling_factor, const GeometryFlags normalize_flags);
27
+
28
+ DEFINE_GVL_VOID_STUB2(UnityAddKernelInfo, KernelInfo *, const double);
29
+ DEFINE_GVL_VOID_STUB3(ScaleKernelInfo, KernelInfo *, const double, const GeometryFlags);
30
+ DEFINE_GVL_VOID_STUB2(ScaleGeometryKernelInfo, KernelInfo *, const char *);
31
+
32
+
13
33
  /**
14
- * If there's a kernel info, delete it before destroying the KernelInfo
34
+ * If there's a kernel info, delete it before destroying the KernelInfo
15
35
  *
16
36
  * No Ruby usage (internal function)
17
37
  *
@@ -25,6 +45,19 @@ rm_kernel_info_destroy(void *kernel)
25
45
  DestroyKernelInfo((KernelInfo*)kernel);
26
46
  }
27
47
 
48
+ /**
49
+ * Get KernelInfo object size.
50
+ *
51
+ * No Ruby usage (internal function)
52
+ *
53
+ * @param ptr pointer to the KernelInfo object
54
+ */
55
+ static size_t
56
+ rm_kernel_info_memsize(const void *ptr)
57
+ {
58
+ return sizeof(KernelInfo);
59
+ }
60
+
28
61
  /**
29
62
  * Create a KernelInfo object.
30
63
  *
@@ -33,7 +66,7 @@ rm_kernel_info_destroy(void *kernel)
33
66
  VALUE
34
67
  KernelInfo_alloc(VALUE class)
35
68
  {
36
- return Data_Wrap_Struct(class, NULL, rm_kernel_info_destroy, NULL);
69
+ return TypedData_Wrap_Struct(class, &rm_kernel_info_data_type, NULL);
37
70
  }
38
71
 
39
72
  /**
@@ -89,10 +122,8 @@ KernelInfo_unity_add(VALUE self, VALUE scale)
89
122
  if (!FIXNUM_P(scale))
90
123
  Check_Type(scale, T_FLOAT);
91
124
 
92
- /* UnityAddKernelInfo() was private function until IM 6.9 */
93
- MagickExport void UnityAddKernelInfo(KernelInfo *kernel, const double scale);
94
-
95
- UnityAddKernelInfo((KernelInfo*)DATA_PTR(self), NUM2DBL(scale));
125
+ GVL_STRUCT_TYPE(UnityAddKernelInfo) args = { (KernelInfo*)DATA_PTR(self), NUM2DBL(scale) };
126
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(UnityAddKernelInfo), &args);
96
127
  return Qnil;
97
128
  }
98
129
 
@@ -118,10 +149,8 @@ KernelInfo_scale(VALUE self, VALUE scale, VALUE flags)
118
149
  else
119
150
  rb_raise(rb_eArgError, "expected Integer or Magick::GeometryFlags to specify flags");
120
151
 
121
- /* ScaleKernelInfo() was private function until IM 6.9 */
122
- MagickExport void ScaleKernelInfo(KernelInfo *kernel, const double scaling_factor, const GeometryFlags normalize_flags);
123
-
124
- ScaleKernelInfo((KernelInfo*)DATA_PTR(self), NUM2DBL(scale), geoflags);
152
+ GVL_STRUCT_TYPE(ScaleKernelInfo) args = { (KernelInfo*)DATA_PTR(self), NUM2DBL(scale), geoflags };
153
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ScaleKernelInfo), &args);
125
154
  return Qnil;
126
155
  }
127
156
 
@@ -135,7 +164,8 @@ VALUE
135
164
  KernelInfo_scale_geometry(VALUE self, VALUE geometry)
136
165
  {
137
166
  Check_Type(geometry, T_STRING);
138
- ScaleGeometryKernelInfo((KernelInfo*)DATA_PTR(self), StringValueCStr(geometry));
167
+ GVL_STRUCT_TYPE(ScaleGeometryKernelInfo) args = { (KernelInfo*)DATA_PTR(self), StringValueCStr(geometry) };
168
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ScaleGeometryKernelInfo), &args);
139
169
  return Qnil;
140
170
  }
141
171
 
@@ -148,7 +178,7 @@ VALUE
148
178
  KernelInfo_clone(VALUE self)
149
179
  {
150
180
  KernelInfo *kernel = CloneKernelInfo((KernelInfo*)DATA_PTR(self));
151
- return Data_Wrap_Struct(Class_KernelInfo, NULL, rm_kernel_info_destroy, kernel);
181
+ return TypedData_Wrap_Struct(Class_KernelInfo, &rm_kernel_info_data_type, kernel);
152
182
  }
153
183
 
154
184
  /**
@@ -194,5 +224,5 @@ KernelInfo_builtin(VALUE self, VALUE what, VALUE geometry)
194
224
  rb_raise(rb_eRuntimeError, "failed to acquire builtin kernel");
195
225
  }
196
226
 
197
- return Data_Wrap_Struct(self, NULL, rm_kernel_info_destroy, kernel);
227
+ return TypedData_Wrap_Struct(self, &rm_kernel_info_data_type, kernel);
198
228
  }
data/ext/RMagick/rmmain.c CHANGED
@@ -234,6 +234,10 @@ static void set_managed_memory(void)
234
234
  void
235
235
  Init_RMagick2(void)
236
236
  {
237
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
238
+ rb_ext_ractor_safe(true);
239
+ #endif
240
+
237
241
  Module_Magick = rb_define_module("Magick");
238
242
 
239
243
  set_managed_memory();
@@ -242,13 +246,10 @@ Init_RMagick2(void)
242
246
 
243
247
  test_Magick_version();
244
248
 
245
- rm_main_thread_id = rm_current_thread_id();
246
-
247
249
  /*-----------------------------------------------------------------------*/
248
250
  /* Create IDs for frequently used methods, etc. */
249
251
  /*-----------------------------------------------------------------------*/
250
252
 
251
- rm_ID_trace_proc = rb_intern("@trace_proc");
252
253
  rm_ID_call = rb_intern("call");
253
254
  rm_ID_changed = rb_intern("changed");
254
255
  rm_ID_cur_image = rb_intern("cur_image");
@@ -358,7 +359,6 @@ Init_RMagick2(void)
358
359
  rb_define_method(Class_Image, "matte_color=", Image_matte_color_eq, 1);
359
360
  rb_define_method(Class_Image, "mean_error_per_pixel", Image_mean_error_per_pixel, 0);
360
361
  rb_define_method(Class_Image, "mime_type", Image_mime_type, 0);
361
- rb_define_method(Class_Image, "monitor=", Image_monitor_eq, 1);
362
362
  rb_define_method(Class_Image, "montage", Image_montage, 0);
363
363
  rb_define_method(Class_Image, "normalized_mean_error", Image_normalized_mean_error, 0);
364
364
  rb_define_method(Class_Image, "normalized_maximum_error", Image_normalized_maximum_error, 0);
@@ -620,7 +620,7 @@ Init_RMagick2(void)
620
620
  rb_define_method(Class_Image, "write", Image_write, 1);
621
621
 
622
622
  /*-----------------------------------------------------------------------*/
623
- /* Class Magick::ImageList methods (see also RMagick.rb) */
623
+ /* Class Magick::ImageList methods */
624
624
  /*-----------------------------------------------------------------------*/
625
625
 
626
626
  Class_ImageList = rb_define_class_under(Module_Magick, "ImageList", rb_cObject);
@@ -735,8 +735,7 @@ Init_RMagick2(void)
735
735
  // include Comparable
736
736
  rb_include_module(Class_Pixel, rb_mComparable);
737
737
 
738
- // Magick::Pixel has 4 constructors: "new" "from_color", "from_hsla",
739
- // and the deprecated "from_HSL".
738
+ // Magick::Pixel has 3 constructors: "new" "from_color", "from_hsla"
740
739
  rb_define_alloc_func(Class_Pixel, Pixel_alloc);
741
740
  rb_define_singleton_method(Class_Pixel, "from_color", Pixel_from_color, 1);
742
741
  rb_define_singleton_method(Class_Pixel, "from_hsla", Pixel_from_hsla, -1);
@@ -878,7 +877,6 @@ Init_RMagick2(void)
878
877
  rb_define_method(Class_Info, "label=", Info_label_eq, 1);
879
878
  rb_define_method(Class_Info, "matte_color", Info_matte_color, 0);
880
879
  rb_define_method(Class_Info, "matte_color=", Info_matte_color_eq, 1);
881
- rb_define_method(Class_Info, "monitor=", Info_monitor_eq, 1);
882
880
  rb_define_method(Class_Info, "monochrome", Info_monochrome, 0);
883
881
  rb_define_method(Class_Info, "monochrome=", Info_monochrome_eq, 1);
884
882
  rb_define_method(Class_Info, "number_scenes", Info_number_scenes, 0);
@@ -1852,7 +1850,7 @@ Init_RMagick2(void)
1852
1850
  *
1853
1851
  * Notes:
1854
1852
  * - Bypass the test by defining the constant RMAGICK_BYPASS_VERSION_TEST to
1855
- * 'true' at the top level, before requiring 'RMagick'
1853
+ * 'true' at the top level, before requiring 'rmagick'
1856
1854
  */
1857
1855
  static void
1858
1856
  test_Magick_version(void)
@@ -12,8 +12,15 @@
12
12
 
13
13
  #include "rmagick.h"
14
14
 
15
+ static void Montage_destroy(void *obj);
16
+ static size_t Montage_memsize(const void *obj);
15
17
 
16
-
18
+ const rb_data_type_t rm_montage_data_type = {
19
+ "Magick::ImageList::Montage",
20
+ { NULL, Montage_destroy, Montage_memsize, },
21
+ 0, 0,
22
+ RUBY_TYPED_FROZEN_SHAREABLE,
23
+ };
17
24
 
18
25
 
19
26
  /**
@@ -28,7 +35,7 @@
28
35
  * @param obj the montage object
29
36
  */
30
37
  static void
31
- destroy_Montage(void *obj)
38
+ Montage_destroy(void *obj)
32
39
  {
33
40
  Montage *montage = obj;
34
41
 
@@ -48,6 +55,20 @@ destroy_Montage(void *obj)
48
55
  }
49
56
 
50
57
 
58
+ /**
59
+ * Get Montage object size.
60
+ *
61
+ * No Ruby usage (internal function)
62
+ *
63
+ * @param ptr pointer to the Montage object
64
+ */
65
+ static size_t
66
+ Montage_memsize(const void *ptr)
67
+ {
68
+ return sizeof(Montage);
69
+ }
70
+
71
+
51
72
  /**
52
73
  * Create a new Montage object.
53
74
  *
@@ -79,7 +100,7 @@ Montage_alloc(VALUE class)
79
100
  montage = ALLOC(Montage);
80
101
  montage->info = montage_info;
81
102
  montage->compose = OverCompositeOp;
82
- montage_obj = Data_Wrap_Struct(class, NULL, destroy_Montage, montage);
103
+ montage_obj = TypedData_Wrap_Struct(class, &rm_montage_data_type, montage);
83
104
 
84
105
  RB_GC_GUARD(montage_obj);
85
106
 
@@ -98,7 +119,7 @@ Montage_background_color_eq(VALUE self, VALUE color)
98
119
  {
99
120
  Montage *montage;
100
121
 
101
- Data_Get_Struct(self, Montage, montage);
122
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
102
123
  Color_to_PixelColor(&montage->info->background_color, color);
103
124
  return color;
104
125
  }
@@ -115,7 +136,7 @@ Montage_border_color_eq(VALUE self, VALUE color)
115
136
  {
116
137
  Montage *montage;
117
138
 
118
- Data_Get_Struct(self, Montage, montage);
139
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
119
140
  Color_to_PixelColor(&montage->info->border_color, color);
120
141
  return color;
121
142
  }
@@ -132,7 +153,7 @@ Montage_border_width_eq(VALUE self, VALUE width)
132
153
  {
133
154
  Montage *montage;
134
155
 
135
- Data_Get_Struct(self, Montage, montage);
156
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
136
157
  montage->info->border_width = NUM2ULONG(width);
137
158
  return width;
138
159
  }
@@ -149,7 +170,7 @@ Montage_compose_eq(VALUE self, VALUE compose)
149
170
  {
150
171
  Montage *montage;
151
172
 
152
- Data_Get_Struct(self, Montage, montage);
173
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
153
174
  VALUE_TO_ENUM(compose, montage->compose, CompositeOperator);
154
175
  return compose;
155
176
  }
@@ -166,7 +187,7 @@ Montage_filename_eq(VALUE self, VALUE filename)
166
187
  {
167
188
  Montage *montage;
168
189
 
169
- Data_Get_Struct(self, Montage, montage);
190
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
170
191
  strlcpy(montage->info->filename, StringValueCStr(filename), sizeof(montage->info->filename));
171
192
  return filename;
172
193
  }
@@ -183,7 +204,7 @@ Montage_fill_eq(VALUE self, VALUE color)
183
204
  {
184
205
  Montage *montage;
185
206
 
186
- Data_Get_Struct(self, Montage, montage);
207
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
187
208
  Color_to_PixelColor(&montage->info->fill, color);
188
209
  return color;
189
210
  }
@@ -200,7 +221,7 @@ Montage_font_eq(VALUE self, VALUE font)
200
221
  {
201
222
  Montage *montage;
202
223
 
203
- Data_Get_Struct(self, Montage, montage);
224
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
204
225
  magick_clone_string(&montage->info->font, StringValueCStr(font));
205
226
 
206
227
  return font;
@@ -223,7 +244,7 @@ Montage_frame_eq(VALUE self, VALUE frame_arg)
223
244
  Montage *montage;
224
245
  VALUE frame;
225
246
 
226
- Data_Get_Struct(self, Montage, montage);
247
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
227
248
  frame = rb_String(frame_arg);
228
249
  magick_clone_string(&montage->info->frame, StringValueCStr(frame));
229
250
 
@@ -250,7 +271,7 @@ Montage_geometry_eq(VALUE self, VALUE geometry_arg)
250
271
  Montage *montage;
251
272
  VALUE geometry;
252
273
 
253
- Data_Get_Struct(self, Montage, montage);
274
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
254
275
  geometry = rb_String(geometry_arg);
255
276
  magick_clone_string(&montage->info->geometry, StringValueCStr(geometry));
256
277
 
@@ -271,7 +292,7 @@ Montage_gravity_eq(VALUE self, VALUE gravity)
271
292
  {
272
293
  Montage *montage;
273
294
 
274
- Data_Get_Struct(self, Montage, montage);
295
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
275
296
  VALUE_TO_ENUM(gravity, montage->info->gravity, GravityType);
276
297
  return gravity;
277
298
  }
@@ -301,7 +322,7 @@ Montage_matte_color_eq(VALUE self, VALUE color)
301
322
  {
302
323
  Montage *montage;
303
324
 
304
- Data_Get_Struct(self, Montage, montage);
325
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
305
326
  Color_to_PixelColor(&montage->info->matte_color, color);
306
327
  return color;
307
328
  }
@@ -318,7 +339,7 @@ Montage_pointsize_eq(VALUE self, VALUE size)
318
339
  {
319
340
  Montage *montage;
320
341
 
321
- Data_Get_Struct(self, Montage, montage);
342
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
322
343
  montage->info->pointsize = NUM2DBL(size);
323
344
  return size;
324
345
  }
@@ -335,7 +356,7 @@ Montage_shadow_eq(VALUE self, VALUE shadow)
335
356
  {
336
357
  Montage *montage;
337
358
 
338
- Data_Get_Struct(self, Montage, montage);
359
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
339
360
  montage->info->shadow = (MagickBooleanType) RTEST(shadow);
340
361
  return shadow;
341
362
  }
@@ -352,7 +373,7 @@ Montage_stroke_eq(VALUE self, VALUE color)
352
373
  {
353
374
  Montage *montage;
354
375
 
355
- Data_Get_Struct(self, Montage, montage);
376
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
356
377
  Color_to_PixelColor(&montage->info->stroke, color);
357
378
  return color;
358
379
  }
@@ -372,7 +393,7 @@ Montage_texture_eq(VALUE self, VALUE texture)
372
393
  Image *texture_image;
373
394
  char temp_name[MaxTextExtent];
374
395
 
375
- Data_Get_Struct(self, Montage, montage);
396
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
376
397
 
377
398
  // If we had a previously defined temp texture image,
378
399
  // remove it now in preparation for this new one.
@@ -411,7 +432,7 @@ Montage_tile_eq(VALUE self, VALUE tile_arg)
411
432
  Montage *montage;
412
433
  VALUE tile;
413
434
 
414
- Data_Get_Struct(self, Montage, montage);
435
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
415
436
  tile = rb_String(tile_arg);
416
437
  magick_clone_string(&montage->info->tile, StringValueCStr(tile));
417
438
 
@@ -432,7 +453,7 @@ Montage_title_eq(VALUE self, VALUE title)
432
453
  {
433
454
  Montage *montage;
434
455
 
435
- Data_Get_Struct(self, Montage, montage);
456
+ TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
436
457
  magick_clone_string(&montage->info->title, StringValueCStr(title));
437
458
  return title;
438
459
  }