rmagick 5.0.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.

data/ext/RMagick/rmdraw.c CHANGED
@@ -13,17 +13,33 @@
13
13
  #include "rmagick.h"
14
14
  #include "float.h"
15
15
 
16
- static void mark_Draw(void *);
17
- static void destroy_Draw(void *);
16
+ static void Draw_mark(void *);
17
+ static void Draw_destroy(void *);
18
+ static size_t Draw_memsize(const void *);
18
19
  static VALUE new_DrawOptions(void);
20
+ static VALUE get_type_metrics(int, VALUE *, VALUE, gvl_function_t);
19
21
 
20
- /** Method that gets type metrics */
22
+ const rb_data_type_t rm_draw_data_type = {
23
+ "Magick::Draw",
24
+ { Draw_mark, Draw_destroy, Draw_memsize, },
25
+ 0, 0,
26
+ RUBY_TYPED_FROZEN_SHAREABLE,
27
+ };
28
+
29
+
30
+ DEFINE_GVL_STUB4(BlobToImage, const ImageInfo *, const void *, const size_t, ExceptionInfo *);
31
+ DEFINE_GVL_STUB4(ImageToBlob, const ImageInfo *, Image *, size_t *, ExceptionInfo *);
21
32
  #if defined(IMAGEMAGICK_7)
22
- typedef MagickBooleanType (get_type_metrics_func_t)(Image *, const DrawInfo *, TypeMetric *, ExceptionInfo *);
33
+ DEFINE_GVL_STUB3(AnnotateImage, Image *, const DrawInfo *, ExceptionInfo *);
34
+ DEFINE_GVL_STUB3(DrawImage, Image *, const DrawInfo *, ExceptionInfo *);
35
+ DEFINE_GVL_STUB4(GetMultilineTypeMetrics, Image *, const DrawInfo *, TypeMetric *, ExceptionInfo *);
36
+ DEFINE_GVL_STUB4(GetTypeMetrics, Image *, const DrawInfo *, TypeMetric *, ExceptionInfo *);
23
37
  #else
24
- typedef MagickBooleanType (get_type_metrics_func_t)(Image *, const DrawInfo *, TypeMetric *);
38
+ DEFINE_GVL_STUB2(AnnotateImage, Image *, const DrawInfo *);
39
+ DEFINE_GVL_STUB2(DrawImage, Image *, const DrawInfo *);
40
+ DEFINE_GVL_STUB3(GetMultilineTypeMetrics, Image *, const DrawInfo *, TypeMetric *);
41
+ DEFINE_GVL_STUB3(GetTypeMetrics, Image *, const DrawInfo *, TypeMetric *);
25
42
  #endif
26
- static VALUE get_type_metrics(int, VALUE *, VALUE, get_type_metrics_func_t);
27
43
 
28
44
 
29
45
  /**
@@ -38,7 +54,7 @@ Draw_affine_eq(VALUE self, VALUE matrix)
38
54
  Draw *draw;
39
55
 
40
56
  rb_check_frozen(self);
41
- Data_Get_Struct(self, Draw, draw);
57
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
42
58
  Export_AffineMatrix(&draw->info->affine, matrix);
43
59
  return matrix;
44
60
  }
@@ -56,7 +72,7 @@ Draw_align_eq(VALUE self, VALUE align)
56
72
  Draw *draw;
57
73
 
58
74
  rb_check_frozen(self);
59
- Data_Get_Struct(self, Draw, draw);
75
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
60
76
  VALUE_TO_ENUM(align, draw->info->align, AlignType);
61
77
  return align;
62
78
  }
@@ -74,7 +90,7 @@ Draw_decorate_eq(VALUE self, VALUE decorate)
74
90
  Draw *draw;
75
91
 
76
92
  rb_check_frozen(self);
77
- Data_Get_Struct(self, Draw, draw);
93
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
78
94
  VALUE_TO_ENUM(decorate, draw->info->decorate, DecorationType);
79
95
  return decorate;
80
96
  }
@@ -92,7 +108,7 @@ Draw_density_eq(VALUE self, VALUE density)
92
108
  Draw *draw;
93
109
 
94
110
  rb_check_frozen(self);
95
- Data_Get_Struct(self, Draw, draw);
111
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
96
112
  magick_clone_string(&draw->info->density, StringValueCStr(density));
97
113
 
98
114
  return density;
@@ -111,7 +127,7 @@ Draw_encoding_eq(VALUE self, VALUE encoding)
111
127
  Draw *draw;
112
128
 
113
129
  rb_check_frozen(self);
114
- Data_Get_Struct(self, Draw, draw);
130
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
115
131
  magick_clone_string(&draw->info->encoding, StringValueCStr(encoding));
116
132
 
117
133
  return encoding;
@@ -130,7 +146,7 @@ Draw_fill_eq(VALUE self, VALUE fill)
130
146
  Draw *draw;
131
147
 
132
148
  rb_check_frozen(self);
133
- Data_Get_Struct(self, Draw, draw);
149
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
134
150
  Color_to_PixelColor(&draw->info->fill, fill);
135
151
  return fill;
136
152
  }
@@ -151,7 +167,7 @@ Draw_fill_pattern_eq(VALUE self, VALUE pattern)
151
167
  Draw *draw;
152
168
 
153
169
  rb_check_frozen(self);
154
- Data_Get_Struct(self, Draw, draw);
170
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
155
171
 
156
172
  if (draw->info->fill_pattern != NULL)
157
173
  {
@@ -186,7 +202,7 @@ Draw_font_eq(VALUE self, VALUE font)
186
202
  Draw *draw;
187
203
 
188
204
  rb_check_frozen(self);
189
- Data_Get_Struct(self, Draw, draw);
205
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
190
206
  magick_clone_string(&draw->info->font, StringValueCStr(font));
191
207
 
192
208
  return font;
@@ -205,7 +221,7 @@ Draw_font_family_eq(VALUE self, VALUE family)
205
221
  Draw *draw;
206
222
 
207
223
  rb_check_frozen(self);
208
- Data_Get_Struct(self, Draw, draw);
224
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
209
225
  magick_clone_string(&draw->info->family, StringValueCStr(family));
210
226
 
211
227
  return family;
@@ -224,7 +240,7 @@ Draw_font_stretch_eq(VALUE self, VALUE stretch)
224
240
  Draw *draw;
225
241
 
226
242
  rb_check_frozen(self);
227
- Data_Get_Struct(self, Draw, draw);
243
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
228
244
  VALUE_TO_ENUM(stretch, draw->info->stretch, StretchType);
229
245
  return stretch;
230
246
  }
@@ -242,7 +258,7 @@ Draw_font_style_eq(VALUE self, VALUE style)
242
258
  Draw *draw;
243
259
 
244
260
  rb_check_frozen(self);
245
- Data_Get_Struct(self, Draw, draw);
261
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
246
262
  VALUE_TO_ENUM(style, draw->info->style, StyleType);
247
263
  return style;
248
264
  }
@@ -262,7 +278,7 @@ Draw_font_weight_eq(VALUE self, VALUE weight)
262
278
  size_t w;
263
279
 
264
280
  rb_check_frozen(self);
265
- Data_Get_Struct(self, Draw, draw);
281
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
266
282
 
267
283
  if (FIXNUM_P(weight))
268
284
  {
@@ -328,7 +344,7 @@ Draw_gravity_eq(VALUE self, VALUE grav)
328
344
  Draw *draw;
329
345
 
330
346
  rb_check_frozen(self);
331
- Data_Get_Struct(self, Draw, draw);
347
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
332
348
  VALUE_TO_ENUM(grav, draw->info->gravity, GravityType);
333
349
 
334
350
  return grav;
@@ -347,7 +363,7 @@ Draw_kerning_eq(VALUE self, VALUE kerning)
347
363
  Draw *draw;
348
364
 
349
365
  rb_check_frozen(self);
350
- Data_Get_Struct(self, Draw, draw);
366
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
351
367
  draw->info->kerning = NUM2DBL(kerning);
352
368
  return kerning;
353
369
  }
@@ -365,7 +381,7 @@ Draw_interline_spacing_eq(VALUE self, VALUE spacing)
365
381
  Draw *draw;
366
382
 
367
383
  rb_check_frozen(self);
368
- Data_Get_Struct(self, Draw, draw);
384
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
369
385
  draw->info->interline_spacing = NUM2DBL(spacing);
370
386
  return spacing;
371
387
  }
@@ -383,7 +399,7 @@ Draw_interword_spacing_eq(VALUE self, VALUE spacing)
383
399
  Draw *draw;
384
400
 
385
401
  rb_check_frozen(self);
386
- Data_Get_Struct(self, Draw, draw);
402
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
387
403
  draw->info->interword_spacing = NUM2DBL(spacing);
388
404
  return spacing;
389
405
  }
@@ -415,7 +431,8 @@ image_to_str(Image *image)
415
431
 
416
432
  info = CloneImageInfo(NULL);
417
433
  exception = AcquireExceptionInfo();
418
- blob = ImageToBlob(info, image, &length, exception);
434
+ GVL_STRUCT_TYPE(ImageToBlob) args = { info, image, &length, exception };
435
+ blob = (unsigned char *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImageToBlob), &args);
419
436
  DestroyImageInfo(info);
420
437
  CHECK_EXCEPTION();
421
438
  DestroyExceptionInfo(exception);
@@ -453,7 +470,8 @@ Image *str_to_image(VALUE str)
453
470
 
454
471
  info = CloneImageInfo(NULL);
455
472
  exception = AcquireExceptionInfo();
456
- image = BlobToImage(info, RSTRING_PTR(str), RSTRING_LEN(str), exception);
473
+ GVL_STRUCT_TYPE(BlobToImage) args = { info, RSTRING_PTR(str), RSTRING_LEN(str), exception };
474
+ image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args);
457
475
  DestroyImageInfo(info);
458
476
  CHECK_EXCEPTION();
459
477
  DestroyExceptionInfo(exception);
@@ -482,7 +500,7 @@ Draw_marshal_dump(VALUE self)
482
500
  Draw *draw;
483
501
  VALUE ddraw;
484
502
 
485
- Data_Get_Struct(self, Draw, draw);
503
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
486
504
 
487
505
  // Raise an exception if the Draw has a non-NULL gradient or element_reference field
488
506
  if (draw->info->element_reference.type != UndefinedReference
@@ -541,7 +559,7 @@ Draw_marshal_load(VALUE self, VALUE ddraw)
541
559
  Draw *draw;
542
560
  VALUE val;
543
561
 
544
- Data_Get_Struct(self, Draw, draw);
562
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
545
563
 
546
564
  if (draw->info == NULL)
547
565
  {
@@ -613,7 +631,7 @@ Draw_pointsize_eq(VALUE self, VALUE pointsize)
613
631
  Draw *draw;
614
632
 
615
633
  rb_check_frozen(self);
616
- Data_Get_Struct(self, Draw, draw);
634
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
617
635
  draw->info->pointsize = NUM2DBL(pointsize);
618
636
  return pointsize;
619
637
  }
@@ -633,7 +651,7 @@ Draw_rotation_eq(VALUE self, VALUE deg)
633
651
  AffineMatrix affine, current;
634
652
 
635
653
  rb_check_frozen(self);
636
- Data_Get_Struct(self, Draw, draw);
654
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
637
655
 
638
656
  degrees = NUM2DBL(deg);
639
657
  if (fabs(degrees) > DBL_EPSILON)
@@ -669,7 +687,7 @@ Draw_stroke_eq(VALUE self, VALUE stroke)
669
687
  Draw *draw;
670
688
 
671
689
  rb_check_frozen(self);
672
- Data_Get_Struct(self, Draw, draw);
690
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
673
691
  Color_to_PixelColor(&draw->info->stroke, stroke);
674
692
  return stroke;
675
693
  }
@@ -689,7 +707,7 @@ Draw_stroke_pattern_eq(VALUE self, VALUE pattern)
689
707
  Draw *draw;
690
708
 
691
709
  rb_check_frozen(self);
692
- Data_Get_Struct(self, Draw, draw);
710
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
693
711
 
694
712
  if (draw->info->stroke_pattern != NULL)
695
713
  {
@@ -725,7 +743,7 @@ Draw_stroke_width_eq(VALUE self, VALUE stroke_width)
725
743
  Draw *draw;
726
744
 
727
745
  rb_check_frozen(self);
728
- Data_Get_Struct(self, Draw, draw);
746
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
729
747
  draw->info->stroke_width = NUM2DBL(stroke_width);
730
748
  return stroke_width;
731
749
  }
@@ -743,7 +761,7 @@ Draw_text_antialias_eq(VALUE self, VALUE text_antialias)
743
761
  Draw *draw;
744
762
 
745
763
  rb_check_frozen(self);
746
- Data_Get_Struct(self, Draw, draw);
764
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
747
765
  draw->info->text_antialias = (MagickBooleanType) RTEST(text_antialias);
748
766
  return text_antialias;
749
767
  }
@@ -774,7 +792,7 @@ Draw_undercolor_eq(VALUE self, VALUE undercolor)
774
792
  Draw *draw;
775
793
 
776
794
  rb_check_frozen(self);
777
- Data_Get_Struct(self, Draw, draw);
795
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
778
796
  Color_to_PixelColor(&draw->info->undercolor, undercolor);
779
797
  return undercolor;
780
798
  }
@@ -817,7 +835,7 @@ VALUE Draw_annotate(
817
835
 
818
836
  // Save the affine matrix in case it is modified by
819
837
  // Draw#rotation=
820
- Data_Get_Struct(self, Draw, draw);
838
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
821
839
  keep = draw->info->affine;
822
840
 
823
841
  image_arg = rm_cur_image(image_arg);
@@ -875,10 +893,11 @@ VALUE Draw_annotate(
875
893
  magick_clone_string(&draw->info->geometry, geometry_str);
876
894
 
877
895
  #if defined(IMAGEMAGICK_7)
878
- AnnotateImage(image, draw->info, exception);
896
+ GVL_STRUCT_TYPE(AnnotateImage) args = { image, draw->info, exception };
879
897
  #else
880
- AnnotateImage(image, draw->info);
898
+ GVL_STRUCT_TYPE(AnnotateImage) args = { image, draw->info };
881
899
  #endif
900
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AnnotateImage), &args);
882
901
 
883
902
  magick_free(draw->info->text);
884
903
  draw->info->text = NULL;
@@ -981,7 +1000,7 @@ Draw_composite(int argc, VALUE *argv, VALUE self)
981
1000
  rb_raise(rb_eArgError, "unknown composite operator (%d)", cop);
982
1001
  }
983
1002
 
984
- Data_Get_Struct(self, Draw, draw);
1003
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
985
1004
 
986
1005
  // Create a temp copy of the composite image
987
1006
  rm_write_temp_image(comp_img, name, sizeof(name));
@@ -1026,7 +1045,7 @@ Draw_draw(VALUE self, VALUE image_arg)
1026
1045
  image_arg = rm_cur_image(image_arg);
1027
1046
  image = rm_check_frozen(image_arg);
1028
1047
 
1029
- Data_Get_Struct(self, Draw, draw);
1048
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1030
1049
  if (draw->primitives == 0)
1031
1050
  {
1032
1051
  rb_raise(rb_eArgError, "nothing to draw");
@@ -1037,10 +1056,11 @@ Draw_draw(VALUE self, VALUE image_arg)
1037
1056
 
1038
1057
  #if defined(IMAGEMAGICK_7)
1039
1058
  exception = AcquireExceptionInfo();
1040
- DrawImage(image, draw->info, exception);
1059
+ GVL_STRUCT_TYPE(DrawImage) args = { image, draw->info, exception };
1041
1060
  #else
1042
- DrawImage(image, draw->info);
1061
+ GVL_STRUCT_TYPE(DrawImage) args = { image, draw->info };
1043
1062
  #endif
1063
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DrawImage), &args);
1044
1064
 
1045
1065
  magick_free(draw->info->primitive);
1046
1066
  draw->info->primitive = NULL;
@@ -1071,7 +1091,7 @@ Draw_dup(VALUE self)
1071
1091
 
1072
1092
  draw = ALLOC(Draw);
1073
1093
  memset(draw, 0, sizeof(Draw));
1074
- dup = Data_Wrap_Struct(CLASS_OF(self), mark_Draw, destroy_Draw, draw);
1094
+ dup = TypedData_Wrap_Struct(CLASS_OF(self), &rm_draw_data_type, draw);
1075
1095
  RB_GC_GUARD(dup);
1076
1096
 
1077
1097
  return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
@@ -1101,7 +1121,7 @@ Draw_get_type_metrics(
1101
1121
  VALUE *argv,
1102
1122
  VALUE self)
1103
1123
  {
1104
- return get_type_metrics(argc, argv, self, GetTypeMetrics);
1124
+ return get_type_metrics(argc, argv, self, GVL_FUNC(GetTypeMetrics));
1105
1125
  }
1106
1126
 
1107
1127
 
@@ -1128,7 +1148,7 @@ Draw_get_multiline_type_metrics(
1128
1148
  VALUE *argv,
1129
1149
  VALUE self)
1130
1150
  {
1131
- return get_type_metrics(argc, argv, self, GetMultilineTypeMetrics);
1151
+ return get_type_metrics(argc, argv, self, GVL_FUNC(GetMultilineTypeMetrics));
1132
1152
  }
1133
1153
 
1134
1154
 
@@ -1142,8 +1162,8 @@ VALUE Draw_init_copy(VALUE self, VALUE orig)
1142
1162
  {
1143
1163
  Draw *copy, *original;
1144
1164
 
1145
- Data_Get_Struct(orig, Draw, original);
1146
- Data_Get_Struct(self, Draw, copy);
1165
+ TypedData_Get_Struct(orig, Draw, &rm_draw_data_type, original);
1166
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, copy);
1147
1167
 
1148
1168
  copy->info = CloneDrawInfo(NULL, original->info);
1149
1169
  if (!copy->info)
@@ -1171,10 +1191,10 @@ Draw_initialize(VALUE self)
1171
1191
  Draw *draw, *draw_options;
1172
1192
  VALUE options;
1173
1193
 
1174
- Data_Get_Struct(self, Draw, draw);
1194
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1175
1195
 
1176
1196
  options = new_DrawOptions();
1177
- Data_Get_Struct(options, Draw, draw_options);
1197
+ TypedData_Get_Struct(options, Draw, &rm_draw_data_type, draw_options);
1178
1198
  draw->info = draw_options->info;
1179
1199
  draw_options->info = NULL;
1180
1200
 
@@ -1195,7 +1215,7 @@ Draw_inspect(VALUE self)
1195
1215
  {
1196
1216
  Draw *draw;
1197
1217
 
1198
- Data_Get_Struct(self, Draw, draw);
1218
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1199
1219
  return draw->primitives ? draw->primitives : rb_str_new2("(no primitives defined)");
1200
1220
  }
1201
1221
 
@@ -1212,7 +1232,7 @@ VALUE Draw_alloc(VALUE class)
1212
1232
 
1213
1233
  draw = ALLOC(Draw);
1214
1234
  memset(draw, 0, sizeof(Draw));
1215
- draw_obj = Data_Wrap_Struct(class, mark_Draw, destroy_Draw, draw);
1235
+ draw_obj = TypedData_Wrap_Struct(class, &rm_draw_data_type, draw);
1216
1236
 
1217
1237
  RB_GC_GUARD(draw_obj);
1218
1238
 
@@ -1232,7 +1252,7 @@ Draw_primitive(VALUE self, VALUE primitive)
1232
1252
  Draw *draw;
1233
1253
 
1234
1254
  rb_check_frozen(self);
1235
- Data_Get_Struct(self, Draw, draw);
1255
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1236
1256
 
1237
1257
  if (draw->primitives == (VALUE)0)
1238
1258
  {
@@ -1240,7 +1260,7 @@ Draw_primitive(VALUE self, VALUE primitive)
1240
1260
  }
1241
1261
  else
1242
1262
  {
1243
- draw->primitives = rb_str_concat(draw->primitives, rb_str_new2("\n"));
1263
+ draw->primitives = rb_str_plus(draw->primitives, rb_str_new2("\n"));
1244
1264
  draw->primitives = rb_str_concat(draw->primitives, primitive);
1245
1265
  }
1246
1266
 
@@ -1256,7 +1276,7 @@ Draw_primitive(VALUE self, VALUE primitive)
1256
1276
  * @param drawptr pointer to a Draw object
1257
1277
  */
1258
1278
  static void
1259
- mark_Draw(void *drawptr)
1279
+ Draw_mark(void *drawptr)
1260
1280
  {
1261
1281
  Draw *draw = (Draw *)drawptr;
1262
1282
 
@@ -1275,7 +1295,7 @@ mark_Draw(void *drawptr)
1275
1295
  * @param drawptr pointer to a Draw object
1276
1296
  */
1277
1297
  static void
1278
- destroy_Draw(void *drawptr)
1298
+ Draw_destroy(void *drawptr)
1279
1299
  {
1280
1300
  Draw *draw = (Draw *)drawptr;
1281
1301
 
@@ -1299,6 +1319,18 @@ destroy_Draw(void *drawptr)
1299
1319
  xfree(drawptr);
1300
1320
  }
1301
1321
 
1322
+ /**
1323
+ * Get Draw object size.
1324
+ *
1325
+ * No Ruby usage (internal function)
1326
+ *
1327
+ * @param infoptr pointer to the Draw object
1328
+ */
1329
+ static size_t
1330
+ Draw_memsize(const void *drawptr)
1331
+ {
1332
+ return sizeof(Draw);
1333
+ }
1302
1334
 
1303
1335
  /**
1304
1336
  * Allocate & initialize a DrawOptions object.
@@ -1330,7 +1362,7 @@ DrawOptions_alloc(VALUE class)
1330
1362
 
1331
1363
  draw_options = ALLOC(Draw);
1332
1364
  memset(draw_options, 0, sizeof(Draw));
1333
- draw_options_obj = Data_Wrap_Struct(class, mark_Draw, destroy_Draw, draw_options);
1365
+ draw_options_obj = TypedData_Wrap_Struct(class, &rm_draw_data_type, draw_options);
1334
1366
 
1335
1367
  RB_GC_GUARD(draw_options_obj);
1336
1368
 
@@ -1348,7 +1380,7 @@ DrawOptions_initialize(VALUE self)
1348
1380
  {
1349
1381
  Draw *draw_options;
1350
1382
 
1351
- Data_Get_Struct(self, Draw, draw_options);
1383
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw_options);
1352
1384
  draw_options->info = AcquireDrawInfo();
1353
1385
  if (!draw_options->info)
1354
1386
  {
@@ -1389,7 +1421,7 @@ PolaroidOptions_alloc(VALUE class)
1389
1421
  draw->info = CloneDrawInfo(image_info, (DrawInfo *) NULL);
1390
1422
  (void) DestroyImageInfo(image_info);
1391
1423
 
1392
- polaroid_obj = Data_Wrap_Struct(class, NULL, destroy_Draw, draw);
1424
+ polaroid_obj = TypedData_Wrap_Struct(class, &rm_draw_data_type, draw);
1393
1425
 
1394
1426
  RB_GC_GUARD(polaroid_obj);
1395
1427
 
@@ -1411,7 +1443,7 @@ PolaroidOptions_initialize(VALUE self)
1411
1443
  ExceptionInfo *exception;
1412
1444
 
1413
1445
  // Default shadow color
1414
- Data_Get_Struct(self, Draw, draw);
1446
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1415
1447
 
1416
1448
  exception = AcquireExceptionInfo();
1417
1449
  QueryColorCompliance("gray75", AllCompliance, &draw->shadow_color, exception);
@@ -1455,7 +1487,7 @@ PolaroidOptions_shadow_color_eq(VALUE self, VALUE shadow)
1455
1487
  Draw *draw;
1456
1488
 
1457
1489
  rb_check_frozen(self);
1458
- Data_Get_Struct(self, Draw, draw);
1490
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1459
1491
  Color_to_PixelColor(&draw->shadow_color, shadow);
1460
1492
  return shadow;
1461
1493
  }
@@ -1473,7 +1505,7 @@ PolaroidOptions_border_color_eq(VALUE self, VALUE border)
1473
1505
  Draw *draw;
1474
1506
 
1475
1507
  rb_check_frozen(self);
1476
- Data_Get_Struct(self, Draw, draw);
1508
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1477
1509
  Color_to_PixelColor(&draw->info->border_color, border);
1478
1510
  return border;
1479
1511
  }
@@ -1522,6 +1554,9 @@ get_dummy_tm_img(VALUE klass)
1522
1554
  }
1523
1555
 
1524
1556
 
1557
+ // aliases for common use of structure types; GetMultilineTypeMetrics, GetTypeMetrics
1558
+ typedef GVL_STRUCT_TYPE(GetTypeMetrics) GVL_STRUCT_TYPE(get_type_metrics);
1559
+
1525
1560
  /**
1526
1561
  * Call a get-type-metrics function.
1527
1562
  *
@@ -1539,11 +1574,7 @@ get_dummy_tm_img(VALUE klass)
1539
1574
  * @see Draw_get_multiline_type_metrics
1540
1575
  */
1541
1576
  static VALUE
1542
- get_type_metrics(
1543
- int argc,
1544
- VALUE *argv,
1545
- VALUE self,
1546
- get_type_metrics_func_t getter)
1577
+ get_type_metrics(int argc, VALUE *argv, VALUE self, gvl_function_t fp)
1547
1578
  {
1548
1579
  Image *image;
1549
1580
  Draw *draw;
@@ -1551,7 +1582,7 @@ get_type_metrics(
1551
1582
  TypeMetric metrics;
1552
1583
  char *text = NULL;
1553
1584
  long text_l;
1554
- unsigned int okay;
1585
+ MagickBooleanType okay;
1555
1586
  #if defined(IMAGEMAGICK_7)
1556
1587
  ExceptionInfo *exception;
1557
1588
  #endif
@@ -1560,7 +1591,7 @@ get_type_metrics(
1560
1591
  {
1561
1592
  case 1: // use default image
1562
1593
  text = rm_str2cstr(argv[0], &text_l);
1563
- Data_Get_Struct(get_dummy_tm_img(CLASS_OF(self)), Image, image);
1594
+ TypedData_Get_Struct(get_dummy_tm_img(CLASS_OF(self)), Image, &rm_image_data_type, image);
1564
1595
  break;
1565
1596
  case 2:
1566
1597
  t = rm_cur_image(argv[0]);
@@ -1577,7 +1608,7 @@ get_type_metrics(
1577
1608
  rb_raise(rb_eArgError, "no text to measure");
1578
1609
  }
1579
1610
 
1580
- Data_Get_Struct(self, Draw, draw);
1611
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1581
1612
  #if defined(IMAGEMAGICK_7)
1582
1613
  exception = AcquireExceptionInfo();
1583
1614
  draw->info->text = InterpretImageProperties(NULL, image, text, exception);
@@ -1601,10 +1632,11 @@ get_type_metrics(
1601
1632
  }
1602
1633
 
1603
1634
  #if defined(IMAGEMAGICK_7)
1604
- okay = (*getter)(image, draw->info, &metrics, exception);
1635
+ GVL_STRUCT_TYPE(get_type_metrics) args = { image, draw->info, &metrics, exception };
1605
1636
  #else
1606
- okay = (*getter)(image, draw->info, &metrics);
1637
+ GVL_STRUCT_TYPE(get_type_metrics) args = { image, draw->info, &metrics };
1607
1638
  #endif
1639
+ okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(fp, &args);
1608
1640
 
1609
1641
  magick_free(draw->info->text);
1610
1642
  draw->info->text = NULL;
data/ext/RMagick/rmenum.c CHANGED
@@ -18,9 +18,15 @@
18
18
 
19
19
  static VALUE Enum_type_values(VALUE);
20
20
  static VALUE Enum_type_inspect(VALUE);
21
+ static void rm_enum_free(void *magick_enum);
22
+ static size_t rm_enum_memsize(const void *magick_enum);
21
23
 
22
-
23
-
24
+ const rb_data_type_t rm_enum_data_type = {
25
+ "Magick::Enum",
26
+ { NULL, rm_enum_free, rm_enum_memsize, },
27
+ 0, 0,
28
+ RUBY_TYPED_FROZEN_SHAREABLE,
29
+ };
24
30
 
25
31
 
26
32
  /**
@@ -78,7 +84,7 @@ rm_enum_to_cstr(VALUE enum_type)
78
84
  {
79
85
  MagickEnum *magick_enum;
80
86
 
81
- Data_Get_Struct(enum_type, MagickEnum, magick_enum);
87
+ TypedData_Get_Struct(enum_type, MagickEnum, &rm_enum_data_type, magick_enum);
82
88
  return rb_id2name(magick_enum->id);
83
89
  }
84
90
 
@@ -93,6 +99,19 @@ static void rm_enum_free(void *magick_enum)
93
99
  {
94
100
  xfree(magick_enum);
95
101
  }
102
+
103
+ /**
104
+ * Get Enum object size.
105
+ *
106
+ * No Ruby usage (internal function)
107
+ *
108
+ * @param magick_enum the enum
109
+ */
110
+ static size_t rm_enum_memsize(const void *magick_enum)
111
+ {
112
+ return sizeof(MagickEnum);
113
+ }
114
+
96
115
  /**
97
116
  * Enum class alloc function.
98
117
  *
@@ -104,7 +123,7 @@ Enum_alloc(VALUE class)
104
123
  MagickEnum *magick_enum;
105
124
  VALUE enumr;
106
125
 
107
- enumr = Data_Make_Struct(class, MagickEnum, NULL, rm_enum_free, magick_enum);
126
+ enumr = TypedData_Make_Struct(class, MagickEnum, &rm_enum_data_type, magick_enum);
108
127
  rb_obj_freeze(enumr);
109
128
 
110
129
  return enumr;
@@ -124,8 +143,8 @@ Enum_case_eq(VALUE self, VALUE other)
124
143
  {
125
144
  MagickEnum *this, *that;
126
145
 
127
- Data_Get_Struct(self, MagickEnum, this);
128
- Data_Get_Struct(other, MagickEnum, that);
146
+ TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, this);
147
+ TypedData_Get_Struct(other, MagickEnum, &rm_enum_data_type, that);
129
148
  return this->val == that->val ? Qtrue : Qfalse;
130
149
  }
131
150
 
@@ -145,7 +164,7 @@ Enum_initialize(VALUE self, VALUE sym, VALUE val)
145
164
  {
146
165
  MagickEnum *magick_enum;
147
166
 
148
- Data_Get_Struct(self, MagickEnum, magick_enum);
167
+ TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, magick_enum);
149
168
  magick_enum->id = rb_to_id(sym); /* convert symbol to ID */
150
169
  magick_enum->val = NUM2INT(val);
151
170
 
@@ -163,7 +182,7 @@ Enum_to_i(VALUE self)
163
182
  {
164
183
  MagickEnum *magick_enum;
165
184
 
166
- Data_Get_Struct(self, MagickEnum, magick_enum);
185
+ TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, magick_enum);
167
186
  return INT2NUM(magick_enum->val);
168
187
  }
169
188
 
@@ -183,8 +202,8 @@ Enum_spaceship(VALUE self, VALUE other)
183
202
  return Qnil;
184
203
  }
185
204
 
186
- Data_Get_Struct(self, MagickEnum, this);
187
- Data_Get_Struct(other, MagickEnum, that);
205
+ TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, this);
206
+ TypedData_Get_Struct(other, MagickEnum, &rm_enum_data_type, that);
188
207
 
189
208
  if (this->val > that->val)
190
209
  {
@@ -218,9 +237,9 @@ Enum_bitwise_or(VALUE self, VALUE another)
218
237
 
219
238
  new_enum = Enum_alloc(cls);
220
239
 
221
- Data_Get_Struct(self, MagickEnum, this);
222
- Data_Get_Struct(another, MagickEnum, that);
223
- Data_Get_Struct(new_enum, MagickEnum, new_enum_data);
240
+ TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, this);
241
+ TypedData_Get_Struct(another, MagickEnum, &rm_enum_data_type, that);
242
+ TypedData_Get_Struct(new_enum, MagickEnum, &rm_enum_data_type, new_enum_data);
224
243
 
225
244
  new_enum_data->id = rb_to_id(rb_sprintf("%s|%s", rb_id2name(this->id), rb_id2name(that->id)));
226
245
  new_enum_data->val = this->val | that->val;
@@ -282,7 +301,7 @@ Enum_type_inspect(VALUE self)
282
301
  char str[100];
283
302
  MagickEnum *magick_enum;
284
303
 
285
- Data_Get_Struct(self, MagickEnum, magick_enum);
304
+ TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, magick_enum);
286
305
  snprintf(str, sizeof(str), "%.48s=%d", rb_id2name(magick_enum->id), magick_enum->val);
287
306
 
288
307
  return rb_str_new2(str);
@@ -359,7 +378,7 @@ Enum_find(VALUE class, int val)
359
378
  for (x = 0; x < RARRAY_LEN(enumerators); x++)
360
379
  {
361
380
  VALUE enumerator = rb_ary_entry(enumerators, x);
362
- Data_Get_Struct(enumerator, MagickEnum, magick_enum);
381
+ TypedData_Get_Struct(enumerator, MagickEnum, &rm_enum_data_type, magick_enum);
363
382
  if (magick_enum->val == val)
364
383
  {
365
384
  return enumerator;