rmagick 2.13.4 → 2.16.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.

Files changed (281) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +14 -0
  3. data/.hound.yml +2 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +340 -0
  6. data/.simplecov +27 -0
  7. data/.travis.yml +29 -12
  8. data/CHANGELOG.md +915 -0
  9. data/CODE_OF_CONDUCT.md +13 -0
  10. data/CONTRIBUTING.md +31 -3
  11. data/Gemfile +3 -0
  12. data/README.textile +94 -4
  13. data/Rakefile +57 -45
  14. data/before_install_linux.sh +26 -6
  15. data/deprecated/RMagick.rb +6 -0
  16. data/doc/comtasks.html +1 -1
  17. data/doc/draw.html +7 -4
  18. data/doc/ex/InitialCoords.rb +16 -17
  19. data/doc/ex/NewCoordSys.rb +21 -23
  20. data/doc/ex/OrigCoordSys.rb +8 -10
  21. data/doc/ex/PreserveAspectRatio.rb +182 -183
  22. data/doc/ex/RotateScale.rb +27 -28
  23. data/doc/ex/Skew.rb +27 -27
  24. data/doc/ex/Use01.rb +7 -8
  25. data/doc/ex/Use02.rb +11 -12
  26. data/doc/ex/Use03.rb +7 -7
  27. data/doc/ex/ViewBox.rb +16 -18
  28. data/doc/ex/adaptive_threshold.rb +4 -5
  29. data/doc/ex/add_noise.rb +4 -5
  30. data/doc/ex/affine.rb +4 -4
  31. data/doc/ex/affine_transform.rb +4 -4
  32. data/doc/ex/arc.rb +10 -10
  33. data/doc/ex/arcpath.rb +7 -8
  34. data/doc/ex/arcs01.rb +10 -10
  35. data/doc/ex/arcs02.rb +36 -38
  36. data/doc/ex/average.rb +5 -5
  37. data/doc/ex/axes.rb +4 -4
  38. data/doc/ex/baseline_shift01.rb +11 -12
  39. data/doc/ex/bilevel_channel.rb +2 -3
  40. data/doc/ex/blur_image.rb +2 -2
  41. data/doc/ex/border.rb +2 -2
  42. data/doc/ex/bounding_box.rb +9 -11
  43. data/doc/ex/cbezier1.rb +3 -4
  44. data/doc/ex/cbezier2.rb +3 -4
  45. data/doc/ex/cbezier3.rb +3 -4
  46. data/doc/ex/cbezier4.rb +3 -4
  47. data/doc/ex/cbezier5.rb +2 -3
  48. data/doc/ex/cbezier6.rb +3 -3
  49. data/doc/ex/channel.rb +10 -11
  50. data/doc/ex/charcoal.rb +2 -2
  51. data/doc/ex/chop.rb +2 -2
  52. data/doc/ex/circle.rb +3 -3
  53. data/doc/ex/circle01.rb +6 -7
  54. data/doc/ex/clip_path.rb +12 -12
  55. data/doc/ex/coalesce.rb +32 -35
  56. data/doc/ex/color_fill_to_border.rb +6 -6
  57. data/doc/ex/color_floodfill.rb +2 -2
  58. data/doc/ex/color_histogram.rb +17 -18
  59. data/doc/ex/color_reset.rb +2 -2
  60. data/doc/ex/colorize.rb +2 -2
  61. data/doc/ex/colors.rb +30 -30
  62. data/doc/ex/compose_mask.rb +8 -9
  63. data/doc/ex/composite.rb +14 -16
  64. data/doc/ex/composite_layers.rb +15 -15
  65. data/doc/ex/composite_tiled.rb +5 -7
  66. data/doc/ex/contrast.rb +12 -12
  67. data/doc/ex/crop.rb +3 -3
  68. data/doc/ex/crop_with_gravity.rb +13 -17
  69. data/doc/ex/cubic01.rb +18 -20
  70. data/doc/ex/cubic02.rb +64 -67
  71. data/doc/ex/cycle_colormap.rb +2 -2
  72. data/doc/ex/dissolve.rb +2 -3
  73. data/doc/ex/drawcomp.rb +34 -34
  74. data/doc/ex/drop_shadow.rb +8 -8
  75. data/doc/ex/edge.rb +2 -2
  76. data/doc/ex/ellipse.rb +4 -4
  77. data/doc/ex/ellipse01.rb +10 -11
  78. data/doc/ex/emboss.rb +2 -2
  79. data/doc/ex/enhance.rb +2 -2
  80. data/doc/ex/equalize.rb +2 -2
  81. data/doc/ex/evenodd.rb +31 -32
  82. data/doc/ex/fill_pattern.rb +12 -15
  83. data/doc/ex/flatten_images.rb +13 -13
  84. data/doc/ex/flip.rb +2 -2
  85. data/doc/ex/flop.rb +2 -2
  86. data/doc/ex/font_styles.rb +21 -23
  87. data/doc/ex/fonts.rb +14 -14
  88. data/doc/ex/frame.rb +3 -3
  89. data/doc/ex/gaussian_blur.rb +2 -2
  90. data/doc/ex/get_multiline_type_metrics.rb +6 -7
  91. data/doc/ex/get_pixels.rb +13 -14
  92. data/doc/ex/get_type_metrics.rb +26 -31
  93. data/doc/ex/gradientfill.rb +12 -12
  94. data/doc/ex/grav.rb +4 -5
  95. data/doc/ex/gravity.rb +61 -60
  96. data/doc/ex/group.rb +16 -16
  97. data/doc/ex/hatchfill.rb +10 -10
  98. data/doc/ex/image.rb +29 -31
  99. data/doc/ex/implode.rb +17 -17
  100. data/doc/ex/level.rb +2 -2
  101. data/doc/ex/level_colors.rb +4 -4
  102. data/doc/ex/line.rb +4 -5
  103. data/doc/ex/line01.rb +11 -13
  104. data/doc/ex/mask.rb +7 -8
  105. data/doc/ex/matte_fill_to_border.rb +2 -3
  106. data/doc/ex/matte_floodfill.rb +2 -3
  107. data/doc/ex/matte_replace.rb +2 -3
  108. data/doc/ex/median_filter.rb +2 -2
  109. data/doc/ex/modulate.rb +2 -2
  110. data/doc/ex/mono.rb +4 -4
  111. data/doc/ex/morph.rb +7 -8
  112. data/doc/ex/mosaic.rb +15 -15
  113. data/doc/ex/motion_blur.rb +2 -2
  114. data/doc/ex/negate.rb +2 -2
  115. data/doc/ex/negate_channel.rb +2 -2
  116. data/doc/ex/nested_rvg.rb +11 -11
  117. data/doc/ex/nonzero.rb +31 -32
  118. data/doc/ex/normalize.rb +2 -2
  119. data/doc/ex/oil_paint.rb +2 -2
  120. data/doc/ex/opacity.rb +3 -3
  121. data/doc/ex/ordered_dither.rb +2 -2
  122. data/doc/ex/path.rb +4 -5
  123. data/doc/ex/pattern1.rb +10 -10
  124. data/doc/ex/pattern2.rb +7 -7
  125. data/doc/ex/polaroid.rb +13 -14
  126. data/doc/ex/polygon.rb +6 -7
  127. data/doc/ex/polygon01.rb +10 -12
  128. data/doc/ex/polyline.rb +4 -5
  129. data/doc/ex/polyline01.rb +11 -13
  130. data/doc/ex/posterize.rb +2 -2
  131. data/doc/ex/preview.rb +3 -4
  132. data/doc/ex/qbezierpath.rb +5 -5
  133. data/doc/ex/quad01.rb +23 -25
  134. data/doc/ex/quantize-m.rb +5 -5
  135. data/doc/ex/radial_blur.rb +2 -2
  136. data/doc/ex/raise.rb +2 -2
  137. data/doc/ex/random_threshold_channel.rb +2 -2
  138. data/doc/ex/rect01.rb +6 -7
  139. data/doc/ex/rect02.rb +9 -11
  140. data/doc/ex/rectangle.rb +3 -4
  141. data/doc/ex/reduce_noise.rb +2 -2
  142. data/doc/ex/remap.rb +7 -8
  143. data/doc/ex/remap_images.rb +9 -11
  144. data/doc/ex/resize_to_fill.rb +3 -5
  145. data/doc/ex/resize_to_fit.rb +3 -5
  146. data/doc/ex/roll.rb +2 -2
  147. data/doc/ex/rotate.rb +6 -7
  148. data/doc/ex/rotate_f.rb +2 -2
  149. data/doc/ex/roundrect.rb +4 -5
  150. data/doc/ex/rubyname.rb +11 -11
  151. data/doc/ex/rvg_clippath.rb +5 -7
  152. data/doc/ex/rvg_linecap.rb +25 -26
  153. data/doc/ex/rvg_linejoin.rb +25 -26
  154. data/doc/ex/rvg_opacity.rb +10 -11
  155. data/doc/ex/rvg_pattern.rb +15 -15
  156. data/doc/ex/rvg_stroke_dasharray.rb +6 -7
  157. data/doc/ex/segment.rb +2 -2
  158. data/doc/ex/sepiatone.rb +2 -3
  159. data/doc/ex/shade.rb +2 -2
  160. data/doc/ex/shadow.rb +2 -3
  161. data/doc/ex/shave.rb +2 -2
  162. data/doc/ex/shear.rb +3 -3
  163. data/doc/ex/sketch.rb +2 -3
  164. data/doc/ex/skewx.rb +4 -5
  165. data/doc/ex/skewy.rb +3 -3
  166. data/doc/ex/smile.rb +113 -113
  167. data/doc/ex/solarize.rb +2 -2
  168. data/doc/ex/sparse_color.rb +29 -30
  169. data/doc/ex/splice.rb +2 -3
  170. data/doc/ex/spread.rb +2 -2
  171. data/doc/ex/stegano.rb +34 -34
  172. data/doc/ex/stroke_dasharray.rb +4 -5
  173. data/doc/ex/stroke_fill.rb +4 -5
  174. data/doc/ex/stroke_linecap.rb +3 -3
  175. data/doc/ex/stroke_linejoin.rb +3 -3
  176. data/doc/ex/stroke_width.rb +3 -3
  177. data/doc/ex/swirl.rb +2 -2
  178. data/doc/ex/text.rb +4 -4
  179. data/doc/ex/text01.rb +7 -8
  180. data/doc/ex/text_align.rb +2 -2
  181. data/doc/ex/text_antialias.rb +9 -10
  182. data/doc/ex/text_styles.rb +11 -13
  183. data/doc/ex/text_undercolor.rb +2 -2
  184. data/doc/ex/texture_fill_to_border.rb +6 -6
  185. data/doc/ex/texture_floodfill.rb +2 -2
  186. data/doc/ex/texturefill.rb +10 -11
  187. data/doc/ex/threshold.rb +2 -2
  188. data/doc/ex/to_blob.rb +4 -5
  189. data/doc/ex/translate.rb +6 -6
  190. data/doc/ex/transparent.rb +5 -5
  191. data/doc/ex/transpose.rb +2 -2
  192. data/doc/ex/transverse.rb +2 -2
  193. data/doc/ex/tref01.rb +11 -12
  194. data/doc/ex/triangle01.rb +5 -6
  195. data/doc/ex/trim.rb +1 -2
  196. data/doc/ex/tspan01.rb +8 -9
  197. data/doc/ex/tspan02.rb +9 -11
  198. data/doc/ex/tspan03.rb +9 -11
  199. data/doc/ex/unsharp_mask.rb +2 -2
  200. data/doc/ex/viewex.rb +19 -21
  201. data/doc/ex/vignette.rb +2 -2
  202. data/doc/ex/watermark.rb +15 -16
  203. data/doc/ex/wave.rb +2 -2
  204. data/doc/ex/wet_floor.rb +17 -18
  205. data/doc/ex/writing_mode01.rb +8 -9
  206. data/doc/ex/writing_mode02.rb +8 -8
  207. data/doc/ilist.html +1 -1
  208. data/doc/usage.html +8 -8
  209. data/examples/constitute.rb +6 -6
  210. data/examples/crop_with_gravity.rb +13 -17
  211. data/examples/demo.rb +305 -305
  212. data/examples/describe.rb +27 -28
  213. data/examples/find_similar_region.rb +16 -16
  214. data/examples/histogram.rb +228 -232
  215. data/examples/identify.rb +165 -167
  216. data/examples/image_opacity.rb +4 -4
  217. data/examples/import_export.rb +10 -10
  218. data/examples/pattern_fill.rb +9 -9
  219. data/examples/rotating_text.rb +13 -14
  220. data/examples/spinner.rb +18 -19
  221. data/examples/thumbnail.rb +13 -14
  222. data/examples/vignette.rb +8 -9
  223. data/ext/RMagick/extconf.rb +489 -367
  224. data/ext/RMagick/rmagick.c +11 -4
  225. data/ext/RMagick/rmagick.h +4 -0
  226. data/ext/RMagick/rmdraw.c +49 -18
  227. data/ext/RMagick/rmenum.c +18 -7
  228. data/ext/RMagick/rmfill.c +4 -1
  229. data/ext/RMagick/rmilist.c +49 -13
  230. data/ext/RMagick/rmimage.c +196 -59
  231. data/ext/RMagick/rminfo.c +33 -10
  232. data/ext/RMagick/rmmain.c +18 -6
  233. data/ext/RMagick/rmmontage.c +12 -4
  234. data/ext/RMagick/rmpixel.c +18 -5
  235. data/ext/RMagick/rmstruct.c +108 -31
  236. data/ext/RMagick/rmutil.c +50 -26
  237. data/lib/rmagick/version.rb +4 -3
  238. data/lib/rmagick_internal.rb +1159 -1176
  239. data/lib/rvg/clippath.rb +36 -39
  240. data/lib/rvg/container.rb +115 -124
  241. data/lib/rvg/deep_equal.rb +46 -50
  242. data/lib/rvg/describable.rb +41 -47
  243. data/lib/rvg/embellishable.rb +384 -410
  244. data/lib/rvg/misc.rb +697 -714
  245. data/lib/rvg/paint.rb +42 -47
  246. data/lib/rvg/pathdata.rb +120 -125
  247. data/lib/rvg/rvg.rb +213 -213
  248. data/lib/rvg/stretchable.rb +159 -162
  249. data/lib/rvg/stylable.rb +109 -117
  250. data/lib/rvg/text.rb +9 -24
  251. data/lib/rvg/transformable.rb +120 -127
  252. data/lib/rvg/units.rb +58 -61
  253. data/rmagick.gemspec +46 -15
  254. data/spec/rmagick/ImageList1_spec.rb +24 -0
  255. data/spec/rmagick/draw_spec.rb +156 -0
  256. data/spec/rmagick/image/blue_shift_spec.rb +16 -0
  257. data/spec/rmagick/image/composite_spec.rb +140 -0
  258. data/spec/rmagick/image/constitute_spec.rb +15 -0
  259. data/spec/rmagick/image/dispatch_spec.rb +18 -0
  260. data/spec/rmagick/image/from_blob_spec.rb +14 -0
  261. data/spec/rmagick/image/ping_spec.rb +14 -0
  262. data/spec/rmagick/image/properties_spec.rb +29 -0
  263. data/spec/spec_helper.rb +4 -0
  264. data/test/Image1.rb +529 -727
  265. data/test/Image2.rb +1291 -1299
  266. data/test/Image3.rb +978 -981
  267. data/test/ImageList1.rb +7 -9
  268. data/test/ImageList2.rb +346 -350
  269. data/test/Image_attributes.rb +683 -686
  270. data/test/Import_Export.rb +25 -30
  271. data/test/Info.rb +339 -343
  272. data/test/Magick.rb +250 -253
  273. data/test/Pixel.rb +107 -110
  274. data/test/Preview.rb +48 -53
  275. data/test/test_all_basic.rb +15 -11
  276. data/test/tmpnam_test.rb +3 -3
  277. data/wercker.yml +10 -0
  278. metadata +77 -10
  279. data/ChangeLog +0 -816
  280. data/lib/RMagick.rb +0 -1
  281. data/test/Draw.rb +0 -121
@@ -34,7 +34,7 @@ Magick_colors(VALUE class)
34
34
  {
35
35
  const ColorInfo **color_info_list;
36
36
  size_t number_colors, x;
37
- volatile VALUE ary;
37
+ VALUE ary;
38
38
  ExceptionInfo *exception;
39
39
 
40
40
  exception = AcquireExceptionInfo();
@@ -62,6 +62,7 @@ Magick_colors(VALUE class)
62
62
  }
63
63
 
64
64
  magick_free((void *)color_info_list);
65
+ RB_GC_GUARD(ary);
65
66
  return ary;
66
67
  }
67
68
  }
@@ -83,7 +84,7 @@ Magick_fonts(VALUE class)
83
84
  {
84
85
  const TypeInfo **type_info;
85
86
  size_t number_types, x;
86
- volatile VALUE ary;
87
+ VALUE ary;
87
88
  ExceptionInfo *exception;
88
89
 
89
90
  exception = AcquireExceptionInfo();
@@ -108,6 +109,7 @@ Magick_fonts(VALUE class)
108
109
  (void) rb_ary_push(ary, Import_TypeInfo((const TypeInfo *)type_info[x]));
109
110
  }
110
111
  magick_free((void *)type_info);
112
+ RB_GC_GUARD(ary);
111
113
  return ary;
112
114
  }
113
115
 
@@ -167,7 +169,7 @@ Magick_init_formats(VALUE class)
167
169
  {
168
170
  const MagickInfo **magick_info;
169
171
  size_t number_formats, x;
170
- volatile VALUE formats;
172
+ VALUE formats;
171
173
  ExceptionInfo *exception;
172
174
 
173
175
  class = class; // defeat "never referenced" message from icc
@@ -186,6 +188,7 @@ Magick_init_formats(VALUE class)
186
188
  , rb_str_new2(magick_info[x]->name)
187
189
  , MagickInfo_to_format((const MagickInfo *)magick_info[x]));
188
190
  }
191
+ RB_GC_GUARD(formats);
189
192
  return formats;
190
193
  }
191
194
 
@@ -206,7 +209,7 @@ Magick_init_formats(VALUE class)
206
209
  VALUE
207
210
  Magick_limit_resource(int argc, VALUE *argv, VALUE class)
208
211
  {
209
- volatile VALUE resource, limit;
212
+ VALUE resource, limit;
210
213
  ResourceType res = UndefinedResource;
211
214
  char *str;
212
215
  ID id;
@@ -280,6 +283,8 @@ Magick_limit_resource(int argc, VALUE *argv, VALUE class)
280
283
  break;
281
284
  }
282
285
 
286
+ RB_GC_GUARD(resource);
287
+
283
288
  cur_limit = GetMagickResourceLimit(res);
284
289
 
285
290
  if (argc > 1)
@@ -287,6 +292,8 @@ Magick_limit_resource(int argc, VALUE *argv, VALUE class)
287
292
  (void) SetMagickResourceLimit(res, (MagickSizeType)NUM2ULONG(limit));
288
293
  }
289
294
 
295
+ RB_GC_GUARD(limit);
296
+
290
297
  return ULONG2NUM(cur_limit);
291
298
  }
292
299
 
@@ -139,6 +139,10 @@
139
139
  #define RARRAY_PTR(a) RARRAY((a))->ptr /**< Ruby array pointer */
140
140
  #endif
141
141
 
142
+ // Backport this macro to 1.8.6
143
+ #if !defined(RB_GC_GUARD)
144
+ #define RB_GC_GUARD(x) (x)
145
+ #endif
142
146
 
143
147
  //! Convert a C string to a Ruby symbol. Used in marshal_dump/marshal_load methods
144
148
  #define CSTR2SYM(s) ID2SYM(rb_intern(s))
data/ext/RMagick/rmdraw.c CHANGED
@@ -497,7 +497,7 @@ Draw_interword_spacing_eq(VALUE self, VALUE spacing)
497
497
  static VALUE
498
498
  image_to_str(Image *image)
499
499
  {
500
- volatile VALUE dimg = Qnil;
500
+ VALUE dimg = Qnil;
501
501
  unsigned char *blob;
502
502
  size_t length;
503
503
  Info *info;
@@ -515,6 +515,8 @@ image_to_str(Image *image)
515
515
  magick_free((void*)blob);
516
516
  }
517
517
 
518
+ RB_GC_GUARD(dimg);
519
+
518
520
  return dimg;
519
521
  }
520
522
 
@@ -664,7 +666,7 @@ Draw_marshal_load(VALUE self, VALUE ddraw)
664
666
  {
665
667
  Draw *draw;
666
668
  Pixel *pixel;
667
- volatile VALUE val;
669
+ VALUE val;
668
670
 
669
671
  Data_Get_Struct(self, Draw, draw);
670
672
 
@@ -725,6 +727,8 @@ Draw_marshal_load(VALUE self, VALUE ddraw)
725
727
 
726
728
  draw->primitives = rb_hash_aref(ddraw, CSTR2SYM("primitives"));
727
729
 
730
+ RB_GC_GUARD(val);
731
+
728
732
  return self;
729
733
  }
730
734
 
@@ -1051,7 +1055,7 @@ VALUE Draw_annotate(
1051
1055
  VALUE
1052
1056
  Draw_clone(VALUE self)
1053
1057
  {
1054
- volatile VALUE clone;
1058
+ VALUE clone;
1055
1059
 
1056
1060
  clone = Draw_dup(self);
1057
1061
  if (OBJ_FROZEN(self))
@@ -1059,6 +1063,8 @@ Draw_clone(VALUE self)
1059
1063
  OBJ_FREEZE(clone);
1060
1064
  }
1061
1065
 
1066
+ RB_GC_GUARD(clone);
1067
+
1062
1068
  return clone;
1063
1069
  }
1064
1070
 
@@ -1087,7 +1093,7 @@ Draw_composite(int argc, VALUE *argv, VALUE self)
1087
1093
  const char *op = "Over";
1088
1094
  double x, y, width, height;
1089
1095
  CompositeOperator cop = OverCompositeOp;
1090
- volatile VALUE image;
1096
+ VALUE image;
1091
1097
  Image *comp_img;
1092
1098
  struct TmpFile_Name *tmpfile_name;
1093
1099
  char name[MaxTextExtent];
@@ -1339,6 +1345,8 @@ Draw_composite(int argc, VALUE *argv, VALUE self)
1339
1345
  // Send "primitive" to self.
1340
1346
  (void) rb_funcall(self, rb_intern("primitive"), 1, rb_str_new2(primitive));
1341
1347
 
1348
+ RB_GC_GUARD(image);
1349
+
1342
1350
  return self;
1343
1351
  }
1344
1352
 
@@ -1399,7 +1407,7 @@ VALUE
1399
1407
  Draw_dup(VALUE self)
1400
1408
  {
1401
1409
  Draw *draw;
1402
- volatile VALUE dup;
1410
+ VALUE dup;
1403
1411
 
1404
1412
  draw = ALLOC(Draw);
1405
1413
  memset(draw, 0, sizeof(Draw));
@@ -1408,6 +1416,9 @@ Draw_dup(VALUE self)
1408
1416
  {
1409
1417
  (void)rb_obj_taint(dup);
1410
1418
  }
1419
+
1420
+ RB_GC_GUARD(dup);
1421
+
1411
1422
  return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
1412
1423
  }
1413
1424
 
@@ -1513,7 +1524,7 @@ VALUE
1513
1524
  Draw_initialize(VALUE self)
1514
1525
  {
1515
1526
  Draw *draw, *draw_options;
1516
- volatile VALUE options;
1527
+ VALUE options;
1517
1528
 
1518
1529
  Data_Get_Struct(self, Draw, draw);
1519
1530
 
@@ -1522,6 +1533,8 @@ Draw_initialize(VALUE self)
1522
1533
  draw->info = draw_options->info;
1523
1534
  draw_options->info = NULL;
1524
1535
 
1536
+ RB_GC_GUARD(options);
1537
+
1525
1538
  return self;
1526
1539
  }
1527
1540
 
@@ -1560,12 +1573,14 @@ Draw_inspect(VALUE self)
1560
1573
  VALUE Draw_alloc(VALUE class)
1561
1574
  {
1562
1575
  Draw *draw;
1563
- volatile VALUE draw_obj;
1576
+ VALUE draw_obj;
1564
1577
 
1565
1578
  draw = ALLOC(Draw);
1566
1579
  memset(draw, 0, sizeof(Draw));
1567
1580
  draw_obj = Data_Wrap_Struct(class, mark_Draw, destroy_Draw, draw);
1568
1581
 
1582
+ RB_GC_GUARD(draw_obj);
1583
+
1569
1584
  return draw_obj;
1570
1585
  }
1571
1586
 
@@ -1685,12 +1700,14 @@ VALUE
1685
1700
  DrawOptions_alloc(VALUE class)
1686
1701
  {
1687
1702
  Draw *draw_options;
1688
- volatile VALUE draw_options_obj;
1703
+ VALUE draw_options_obj;
1689
1704
 
1690
1705
  draw_options = ALLOC(Draw);
1691
1706
  memset(draw_options, 0, sizeof(Draw));
1692
1707
  draw_options_obj = Data_Wrap_Struct(class, mark_Draw, destroy_Draw, draw_options);
1693
1708
 
1709
+ RB_GC_GUARD(draw_options_obj);
1710
+
1694
1711
  return draw_options_obj;
1695
1712
  }
1696
1713
 
@@ -1745,7 +1762,7 @@ DrawOptions_initialize(VALUE self)
1745
1762
  VALUE
1746
1763
  PolaroidOptions_alloc(VALUE class)
1747
1764
  {
1748
- volatile VALUE polaroid_obj;
1765
+ VALUE polaroid_obj;
1749
1766
  ImageInfo *image_info;
1750
1767
  Draw *draw;
1751
1768
 
@@ -1759,6 +1776,8 @@ PolaroidOptions_alloc(VALUE class)
1759
1776
 
1760
1777
  polaroid_obj = Data_Wrap_Struct(class, NULL, destroy_Draw, draw);
1761
1778
 
1779
+ RB_GC_GUARD(polaroid_obj);
1780
+
1762
1781
  return polaroid_obj;
1763
1782
  }
1764
1783
 
@@ -1863,7 +1882,7 @@ static VALUE
1863
1882
  get_dummy_tm_img(VALUE klass)
1864
1883
  {
1865
1884
  #define DUMMY_IMG_CLASS_VAR "@@_dummy_img_"
1866
- volatile VALUE dummy_img = 0;
1885
+ VALUE dummy_img = 0;
1867
1886
  Info *info;
1868
1887
  Image *image;
1869
1888
 
@@ -1887,6 +1906,8 @@ get_dummy_tm_img(VALUE klass)
1887
1906
  }
1888
1907
  dummy_img = rb_cv_get(klass, DUMMY_IMG_CLASS_VAR);
1889
1908
 
1909
+ RB_GC_GUARD(dummy_img);
1910
+
1890
1911
  return dummy_img;
1891
1912
  }
1892
1913
 
@@ -1918,7 +1939,7 @@ get_type_metrics(
1918
1939
  #define ATTRS_L ((int)(sizeof(attrs)-1))
1919
1940
  Image *image;
1920
1941
  Draw *draw;
1921
- volatile VALUE t;
1942
+ VALUE t;
1922
1943
  TypeMetric metrics;
1923
1944
  char *text = NULL;
1924
1945
  long text_l;
@@ -1930,21 +1951,28 @@ get_type_metrics(
1930
1951
  case 1: // use default image
1931
1952
  text = rm_str2cstr(argv[0], &text_l);
1932
1953
 
1933
- for (x = 0; x < text_l; x++)
1954
+ for (x = 0; x < text_l-1; x++)
1934
1955
  {
1935
1956
  // Ensure text string doesn't refer to image attributes.
1936
- if (text[x] == '%' && x < text_l-1)
1957
+ if (text[x] == '%')
1937
1958
  {
1938
1959
  int y;
1939
1960
  char spec = text[x+1];
1940
1961
 
1941
- for (y = 0; y < ATTRS_L; y++)
1962
+ if (spec == '%')
1942
1963
  {
1943
- if (spec == attrs[y])
1964
+ x++;
1965
+ }
1966
+ else
1967
+ {
1968
+ for (y = 0; y < ATTRS_L; y++)
1944
1969
  {
1945
- rb_raise(rb_eArgError,
1946
- "text string contains image attribute reference `%%%c'",
1947
- spec);
1970
+ if (spec == attrs[y])
1971
+ {
1972
+ rb_raise(rb_eArgError,
1973
+ "text string contains image attribute reference `%%%c'",
1974
+ spec);
1975
+ }
1948
1976
  }
1949
1977
  }
1950
1978
  }
@@ -1987,5 +2015,8 @@ get_type_metrics(
1987
2015
  rb_raise(rb_eRuntimeError, "Can't measure text. Are the fonts installed? "
1988
2016
  "Is the FreeType library installed?");
1989
2017
  }
2018
+
2019
+ RB_GC_GUARD(t);
2020
+
1990
2021
  return Import_TypeMetric(&metrics);
1991
2022
  }
data/ext/RMagick/rmenum.c CHANGED
@@ -78,10 +78,13 @@ VALUE
78
78
  Enum_alloc(VALUE class)
79
79
  {
80
80
  MagickEnum *magick_enum;
81
- volatile VALUE enumr;
81
+ VALUE enumr;
82
82
 
83
83
  enumr = Data_Make_Struct(class, MagickEnum, NULL, NULL, magick_enum);
84
84
  rb_obj_freeze(enumr);
85
+
86
+ RB_GC_GUARD(enumr);
87
+
85
88
  return enumr;
86
89
  }
87
90
 
@@ -176,6 +179,10 @@ Enum_spaceship(VALUE self, VALUE other)
176
179
  {
177
180
  MagickEnum *this, *that;
178
181
 
182
+ if(CLASS_OF(self) != CLASS_OF(other)) {
183
+ return Qnil;
184
+ }
185
+
179
186
  Data_Get_Struct(self, MagickEnum, this);
180
187
  Data_Get_Struct(other, MagickEnum, that);
181
188
 
@@ -188,9 +195,7 @@ Enum_spaceship(VALUE self, VALUE other)
188
195
  return INT2FIX(-1);
189
196
  }
190
197
 
191
- // Values are equal, check class.
192
-
193
- return rb_funcall(CLASS_OF(self), rm_ID_spaceship, 1, CLASS_OF(other));
198
+ return INT2FIX(0);
194
199
  }
195
200
 
196
201
 
@@ -228,7 +233,7 @@ VALUE
228
233
  Enum_type_initialize(VALUE self, VALUE sym, VALUE val)
229
234
  {
230
235
  VALUE super_argv[2];
231
- volatile VALUE enumerators;
236
+ VALUE enumerators;
232
237
 
233
238
  super_argv[0] = sym;
234
239
  super_argv[1] = val;
@@ -242,6 +247,8 @@ Enum_type_initialize(VALUE self, VALUE sym, VALUE val)
242
247
  enumerators = rb_cv_get(CLASS_OF(self), ENUMERATORS_CLASS_VAR);
243
248
  (void) rb_ary_push(enumerators, self);
244
249
 
250
+ RB_GC_GUARD(enumerators);
251
+
245
252
  return self;
246
253
  }
247
254
 
@@ -284,8 +291,8 @@ Enum_type_inspect(VALUE self)
284
291
  static VALUE
285
292
  Enum_type_values(VALUE class)
286
293
  {
287
- volatile VALUE enumerators, copy;
288
- volatile VALUE rv;
294
+ VALUE enumerators, copy;
295
+ VALUE rv;
289
296
  int x;
290
297
 
291
298
  enumerators = rb_cv_get(class, ENUMERATORS_CLASS_VAR);
@@ -309,6 +316,10 @@ Enum_type_values(VALUE class)
309
316
  rv = copy;
310
317
  }
311
318
 
319
+ RB_GC_GUARD(enumerators);
320
+ RB_GC_GUARD(copy);
321
+ RB_GC_GUARD(rv);
322
+
312
323
  return rv;
313
324
  }
314
325
 
data/ext/RMagick/rmfill.c CHANGED
@@ -675,7 +675,7 @@ TextureFill_initialize(VALUE self, VALUE texture_arg)
675
675
  {
676
676
  rm_TextureFill *fill;
677
677
  Image *texture;
678
- volatile VALUE texture_image;
678
+ VALUE texture_image;
679
679
 
680
680
  Data_Get_Struct(self, rm_TextureFill, fill);
681
681
 
@@ -686,6 +686,9 @@ TextureFill_initialize(VALUE self, VALUE texture_arg)
686
686
  (void) ReferenceImage(texture);
687
687
 
688
688
  fill->texture = texture;
689
+
690
+ RB_GC_GUARD(texture_image);
691
+
689
692
  return self;
690
693
  }
691
694
 
@@ -44,7 +44,7 @@ ImageList_animate(int argc, VALUE *argv, VALUE self)
44
44
  {
45
45
  Image *images;
46
46
  Info *info;
47
- volatile VALUE info_obj;
47
+ VALUE info_obj;
48
48
 
49
49
  if (argc > 1)
50
50
  {
@@ -74,6 +74,8 @@ ImageList_animate(int argc, VALUE *argv, VALUE self)
74
74
  rm_check_image_exception(images, RetainOnError);
75
75
  rm_split(images);
76
76
 
77
+ RB_GC_GUARD(info_obj);
78
+
77
79
  return self;
78
80
  }
79
81
 
@@ -202,7 +204,7 @@ ImageList_coalesce(VALUE self)
202
204
  VALUE
203
205
  ImageList_composite_layers(int argc, VALUE *argv, VALUE self)
204
206
  {
205
- volatile VALUE source_images;
207
+ VALUE source_images;
206
208
  Image *dest, *source, *new_images;
207
209
  RectangleInfo geometry;
208
210
  CompositeOperator operator = OverCompositeOp;
@@ -242,6 +244,8 @@ ImageList_composite_layers(int argc, VALUE *argv, VALUE self)
242
244
  rm_check_exception(exception, new_images, DestroyOnError);
243
245
  (void) DestroyExceptionInfo(exception);
244
246
 
247
+ RB_GC_GUARD(source_images);
248
+
245
249
  return rm_imagelist_from_images(new_images);
246
250
  }
247
251
 
@@ -289,7 +293,7 @@ ImageList_display(VALUE self)
289
293
  {
290
294
  Image *images;
291
295
  Info *info;
292
- volatile VALUE info_obj;
296
+ VALUE info_obj;
293
297
 
294
298
  // Create a new Info object to use with this call
295
299
  info_obj = rm_info_new();
@@ -302,6 +306,8 @@ ImageList_display(VALUE self)
302
306
  rm_split(images);
303
307
  rm_check_image_exception(images, RetainOnError);
304
308
 
309
+ RB_GC_GUARD(info_obj);
310
+
305
311
  return self;
306
312
  }
307
313
 
@@ -417,7 +423,7 @@ ImageList_map(int argc, VALUE *argv, VALUE self)
417
423
  Image *images, *new_images = NULL;
418
424
  Image *map;
419
425
  unsigned int dither = MagickFalse;
420
- volatile VALUE scene, new_imagelist, t;
426
+ VALUE scene, new_imagelist, t;
421
427
  ExceptionInfo *exception;
422
428
 
423
429
  #if defined(HAVE_REMAPIMAGES)
@@ -465,6 +471,10 @@ ImageList_map(int argc, VALUE *argv, VALUE self)
465
471
  scene = rb_iv_get(self, "@scene");
466
472
  (void) imagelist_scene_eq(new_imagelist, scene);
467
473
 
474
+ RB_GC_GUARD(scene);
475
+ RB_GC_GUARD(new_imagelist);
476
+ RB_GC_GUARD(t);
477
+
468
478
  return new_imagelist;
469
479
  }
470
480
 
@@ -485,7 +495,7 @@ ImageList_map(int argc, VALUE *argv, VALUE self)
485
495
  VALUE
486
496
  ImageList_montage(VALUE self)
487
497
  {
488
- volatile VALUE montage_obj;
498
+ VALUE montage_obj;
489
499
  Montage *montage;
490
500
  Image *new_images, *images;
491
501
  ExceptionInfo *exception;
@@ -523,6 +533,8 @@ ImageList_montage(VALUE self)
523
533
 
524
534
  rm_ensure_result(new_images);
525
535
 
536
+ RB_GC_GUARD(montage_obj);
537
+
526
538
  return rm_imagelist_from_images(new_images);
527
539
  }
528
540
 
@@ -754,7 +766,7 @@ ImageList_new(void)
754
766
  VALUE
755
767
  rm_imagelist_from_images(Image *images)
756
768
  {
757
- volatile VALUE new_imagelist;
769
+ VALUE new_imagelist;
758
770
  Image *image;
759
771
 
760
772
  if (!images)
@@ -771,6 +783,9 @@ rm_imagelist_from_images(Image *images)
771
783
  }
772
784
 
773
785
  (void) rb_iv_set(new_imagelist, "@scene", INT2FIX(0));
786
+
787
+ RB_GC_GUARD(new_imagelist);
788
+
774
789
  return new_imagelist;
775
790
  }
776
791
 
@@ -790,7 +805,7 @@ images_from_imagelist(VALUE imagelist)
790
805
  {
791
806
  long x, len;
792
807
  Image *head = NULL;
793
- volatile VALUE images, t;
808
+ VALUE images, t;
794
809
 
795
810
  len = check_imagelist_length(imagelist);
796
811
 
@@ -801,9 +816,17 @@ images_from_imagelist(VALUE imagelist)
801
816
 
802
817
  t = rb_ary_entry(images, x);
803
818
  image = rm_check_destroyed(t);
819
+ // avoid a loop in this linked imagelist, issue #202
820
+ if (head == image || GetPreviousImageInList(image) != NULL)
821
+ {
822
+ image = rm_clone_image(image);
823
+ }
804
824
  AppendImageToList(&head, image);
805
825
  }
806
826
 
827
+ RB_GC_GUARD(images);
828
+ RB_GC_GUARD(t);
829
+
807
830
  return head;
808
831
  }
809
832
 
@@ -837,7 +860,10 @@ imagelist_scene_eq(VALUE imagelist, VALUE scene)
837
860
  static long
838
861
  imagelist_length(VALUE imagelist)
839
862
  {
840
- volatile VALUE images = rb_iv_get(imagelist, "@images");
863
+ VALUE images = rb_iv_get(imagelist, "@images");
864
+
865
+ RB_GC_GUARD(images);
866
+
841
867
  return RARRAY_LEN(images);
842
868
  }
843
869
 
@@ -942,7 +968,7 @@ ImageList_quantize(int argc, VALUE *argv, VALUE self)
942
968
  Image *new_image;
943
969
  QuantizeInfo quantize_info;
944
970
  ExceptionInfo *exception;
945
- volatile VALUE new_imagelist, scene;
971
+ VALUE new_imagelist, scene;
946
972
 
947
973
  GetQuantizeInfo(&quantize_info);
948
974
 
@@ -1000,6 +1026,9 @@ ImageList_quantize(int argc, VALUE *argv, VALUE self)
1000
1026
  scene = rb_iv_get(self, "@scene");
1001
1027
  (void) rb_iv_set(new_imagelist, "@scene", scene);
1002
1028
 
1029
+ RB_GC_GUARD(new_imagelist);
1030
+ RB_GC_GUARD(scene);
1031
+
1003
1032
  return new_imagelist;
1004
1033
  }
1005
1034
 
@@ -1032,8 +1061,9 @@ ImageList_remap(int argc, VALUE *argv, VALUE self)
1032
1061
 
1033
1062
  if (argc > 0 && argv[0] != Qnil)
1034
1063
  {
1035
- volatile VALUE t = rm_cur_image(argv[0]);
1064
+ VALUE t = rm_cur_image(argv[0]);
1036
1065
  remap_image = rm_check_destroyed(t);
1066
+ RB_GC_GUARD(t);
1037
1067
  }
1038
1068
 
1039
1069
  GetQuantizeInfo(&quantize_info);
@@ -1087,8 +1117,8 @@ ImageList_to_blob(VALUE self)
1087
1117
  {
1088
1118
  Image *images, *image;
1089
1119
  Info *info;
1090
- volatile VALUE info_obj;
1091
- volatile VALUE blob_str;
1120
+ VALUE info_obj;
1121
+ VALUE blob_str;
1092
1122
  void *blob = NULL;
1093
1123
  size_t length = 0;
1094
1124
  ExceptionInfo *exception;
@@ -1141,6 +1171,9 @@ ImageList_to_blob(VALUE self)
1141
1171
  blob_str = rb_str_new(blob, (long)length);
1142
1172
  magick_free((void*)blob);
1143
1173
 
1174
+ RB_GC_GUARD(info_obj);
1175
+ RB_GC_GUARD(blob_str);
1176
+
1144
1177
  return blob_str;
1145
1178
  }
1146
1179
 
@@ -1164,7 +1197,7 @@ ImageList_write(VALUE self, VALUE file)
1164
1197
  Image *images, *img;
1165
1198
  Info *info;
1166
1199
  const MagickInfo *m;
1167
- volatile VALUE info_obj;
1200
+ VALUE info_obj;
1168
1201
  unsigned long scene;
1169
1202
  ExceptionInfo *exception;
1170
1203
 
@@ -1230,5 +1263,8 @@ ImageList_write(VALUE self, VALUE file)
1230
1263
  }
1231
1264
 
1232
1265
  rm_split(images);
1266
+
1267
+ RB_GC_GUARD(info_obj);
1268
+
1233
1269
  return self;
1234
1270
  }