rmagick 2.14.0 → 2.15.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.

@@ -978,7 +978,7 @@ static VALUE
978
978
  auto_orient(int bang, VALUE self)
979
979
  {
980
980
  Image *image;
981
- volatile VALUE new_image;
981
+ VALUE new_image;
982
982
  VALUE degrees[1];
983
983
 
984
984
  Data_Get_Struct(self, Image, image);
@@ -1025,6 +1025,8 @@ auto_orient(int bang, VALUE self)
1025
1025
  Data_Get_Struct(new_image, Image, image);
1026
1026
  image->orientation = TopLeftOrientation;
1027
1027
 
1028
+ RB_GC_GUARD(new_image);
1029
+
1028
1030
  return new_image;
1029
1031
  }
1030
1032
 
@@ -1254,7 +1256,7 @@ Image_black_point_compensation(VALUE self)
1254
1256
  {
1255
1257
  Image *image;
1256
1258
  const char *attr;
1257
- volatile VALUE value;
1259
+ VALUE value;
1258
1260
 
1259
1261
  image = rm_check_destroyed(self);
1260
1262
 
@@ -1267,6 +1269,9 @@ Image_black_point_compensation(VALUE self)
1267
1269
  {
1268
1270
  value = Qfalse;
1269
1271
  }
1272
+
1273
+ RB_GC_GUARD(value);
1274
+
1270
1275
  return value;
1271
1276
  }
1272
1277
 
@@ -1658,7 +1663,7 @@ special_composite(Image *image, Image *overlay, double image_pct, double overlay
1658
1663
  VALUE
1659
1664
  Image_blend(int argc, VALUE *argv, VALUE self)
1660
1665
  {
1661
- volatile VALUE ovly;
1666
+ VALUE ovly;
1662
1667
  Image *image, *overlay;
1663
1668
  double src_percent, dst_percent;
1664
1669
  long x_offset = 0L, y_offset = 0L;
@@ -1695,6 +1700,8 @@ Image_blend(int argc, VALUE *argv, VALUE self)
1695
1700
  break;
1696
1701
  }
1697
1702
 
1703
+ RB_GC_GUARD(ovly);
1704
+
1698
1705
  return special_composite(image, overlay, src_percent, dst_percent
1699
1706
  , x_offset, y_offset, BlendCompositeOp);
1700
1707
 
@@ -2030,7 +2037,7 @@ Image_capture(int argc, VALUE *argv, VALUE self)
2030
2037
  {
2031
2038
  Image *image;
2032
2039
  ImageInfo *image_info;
2033
- volatile VALUE info_obj;
2040
+ VALUE info_obj;
2034
2041
  XImportInfo ximage_info;
2035
2042
 
2036
2043
  self = self; // Suppress "never referenced" message from icc
@@ -2070,6 +2077,8 @@ Image_capture(int argc, VALUE *argv, VALUE self)
2070
2077
 
2071
2078
  rm_set_user_artifact(image, image_info);
2072
2079
 
2080
+ RB_GC_GUARD(info_obj);
2081
+
2073
2082
  return rm_image_new(image);
2074
2083
  }
2075
2084
 
@@ -2089,10 +2098,10 @@ Image_change_geometry(VALUE self, VALUE geom_arg)
2089
2098
  {
2090
2099
  Image *image;
2091
2100
  RectangleInfo rect;
2092
- volatile VALUE geom_str;
2101
+ VALUE geom_str;
2093
2102
  char *geometry;
2094
2103
  unsigned int flags;
2095
- volatile VALUE ary;
2104
+ VALUE ary;
2096
2105
 
2097
2106
  image = rm_check_destroyed(self);
2098
2107
  geom_str = rm_to_s(geom_arg);
@@ -2113,6 +2122,9 @@ Image_change_geometry(VALUE self, VALUE geom_arg)
2113
2122
  rb_ary_store(ary, 1, ULONG2NUM(rect.height));
2114
2123
  rb_ary_store(ary, 2, self);
2115
2124
 
2125
+ RB_GC_GUARD(geom_str);
2126
+ RB_GC_GUARD(ary);
2127
+
2116
2128
  return rb_yield(ary);
2117
2129
  }
2118
2130
 
@@ -2239,7 +2251,7 @@ Image_channel_extrema(int argc, VALUE *argv, VALUE self)
2239
2251
  ChannelType channels;
2240
2252
  ExceptionInfo *exception;
2241
2253
  size_t min, max;
2242
- volatile VALUE ary;
2254
+ VALUE ary;
2243
2255
 
2244
2256
  image = rm_check_destroyed(self);
2245
2257
 
@@ -2261,6 +2273,8 @@ Image_channel_extrema(int argc, VALUE *argv, VALUE self)
2261
2273
  rb_ary_store(ary, 0, ULONG2NUM(min));
2262
2274
  rb_ary_store(ary, 1, ULONG2NUM(max));
2263
2275
 
2276
+ RB_GC_GUARD(ary);
2277
+
2264
2278
  return ary;
2265
2279
  }
2266
2280
 
@@ -2287,7 +2301,7 @@ Image_channel_mean(int argc, VALUE *argv, VALUE self)
2287
2301
  ChannelType channels;
2288
2302
  ExceptionInfo *exception;
2289
2303
  double mean, stddev;
2290
- volatile VALUE ary;
2304
+ VALUE ary;
2291
2305
 
2292
2306
  image = rm_check_destroyed(self);
2293
2307
 
@@ -2309,6 +2323,8 @@ Image_channel_mean(int argc, VALUE *argv, VALUE self)
2309
2323
  rb_ary_store(ary, 0, rb_float_new(mean));
2310
2324
  rb_ary_store(ary, 1, rb_float_new(stddev));
2311
2325
 
2326
+ RB_GC_GUARD(ary);
2327
+
2312
2328
  return ary;
2313
2329
  }
2314
2330
 
@@ -2428,7 +2444,7 @@ Image_chromaticity_eq(VALUE self, VALUE chroma)
2428
2444
  VALUE
2429
2445
  Image_clone(VALUE self)
2430
2446
  {
2431
- volatile VALUE clone;
2447
+ VALUE clone;
2432
2448
 
2433
2449
  clone = Image_dup(self);
2434
2450
  if (OBJ_FROZEN(self))
@@ -2436,6 +2452,8 @@ Image_clone(VALUE self)
2436
2452
  OBJ_FREEZE(clone);
2437
2453
  }
2438
2454
 
2455
+ RB_GC_GUARD(clone);
2456
+
2439
2457
  return clone;
2440
2458
  }
2441
2459
 
@@ -2505,7 +2523,7 @@ VALUE
2505
2523
  Image_color_histogram(VALUE self)
2506
2524
  {
2507
2525
  Image *image, *dc_copy = NULL;
2508
- volatile VALUE hash, pixel;
2526
+ VALUE hash, pixel;
2509
2527
  size_t x, colors;
2510
2528
  ColorPacket *histogram;
2511
2529
  ExceptionInfo *exception;
@@ -2560,6 +2578,9 @@ Image_color_histogram(VALUE self)
2560
2578
  (void) DestroyImage(dc_copy);
2561
2579
  }
2562
2580
 
2581
+ RB_GC_GUARD(hash);
2582
+ RB_GC_GUARD(pixel);
2583
+
2563
2584
  return hash;
2564
2585
  }
2565
2586
 
@@ -3126,7 +3147,7 @@ Image_compare_channel(int argc, VALUE *argv, VALUE self)
3126
3147
  {
3127
3148
  Image *image, *r_image, *difference_image;
3128
3149
  double distortion;
3129
- volatile VALUE ary, ref;
3150
+ VALUE ary, ref;
3130
3151
  MetricType metric_type;
3131
3152
  ChannelType channels;
3132
3153
  ExceptionInfo *exception;
@@ -3168,6 +3189,9 @@ Image_compare_channel(int argc, VALUE *argv, VALUE self)
3168
3189
  rb_ary_store(ary, 0, rm_image_new(difference_image));
3169
3190
  rb_ary_store(ary, 1, rb_float_new(distortion));
3170
3191
 
3192
+ RB_GC_GUARD(ary);
3193
+ RB_GC_GUARD(ref);
3194
+
3171
3195
  return ary;
3172
3196
  }
3173
3197
 
@@ -3235,7 +3259,7 @@ composite(int bang, int argc, VALUE *argv, VALUE self, ChannelType channels)
3235
3259
  Image *comp_image;
3236
3260
  CompositeOperator operator = UndefinedCompositeOp;
3237
3261
  GravityType gravity;
3238
- volatile VALUE comp;
3262
+ VALUE comp;
3239
3263
  signed long x_offset = 0;
3240
3264
  signed long y_offset = 0;
3241
3265
 
@@ -3253,6 +3277,7 @@ composite(int bang, int argc, VALUE *argv, VALUE self, ChannelType channels)
3253
3277
 
3254
3278
  comp = rm_cur_image(argv[0]);
3255
3279
  comp_image = rm_check_destroyed(comp);
3280
+ RB_GC_GUARD(comp);
3256
3281
 
3257
3282
  switch (argc)
3258
3283
  {
@@ -3829,7 +3854,7 @@ Image_constitute(VALUE class, VALUE width_arg, VALUE height_arg
3829
3854
  {
3830
3855
  Image *image;
3831
3856
  ExceptionInfo *exception;
3832
- volatile VALUE pixel, pixel0;
3857
+ VALUE pixel, pixel0;
3833
3858
  unsigned long width, height;
3834
3859
  long x, npixels;
3835
3860
  char *map;
@@ -3840,7 +3865,7 @@ Image_constitute(VALUE class, VALUE width_arg, VALUE height_arg
3840
3865
  Quantum *i;
3841
3866
  void *v;
3842
3867
  } pixels;
3843
- volatile VALUE pixel_class;
3868
+ VALUE pixel_class;
3844
3869
  StorageType stg_type;
3845
3870
 
3846
3871
  class = class; // Suppress "never referenced" message from icc
@@ -3937,6 +3962,10 @@ Image_constitute(VALUE class, VALUE width_arg, VALUE height_arg
3937
3962
  DestroyConstitute();
3938
3963
  #endif
3939
3964
 
3965
+ RB_GC_GUARD(pixel);
3966
+ RB_GC_GUARD(pixel0);
3967
+ RB_GC_GUARD(pixel_class);
3968
+
3940
3969
  return rm_image_new(image);
3941
3970
  }
3942
3971
 
@@ -4156,7 +4185,7 @@ Image_convolve_channel(int argc, VALUE *argv, VALUE self)
4156
4185
  {
4157
4186
  Image *image, *new_image;
4158
4187
  double *kernel;
4159
- volatile VALUE ary;
4188
+ VALUE ary;
4160
4189
  unsigned int x, order;
4161
4190
  ChannelType channels;
4162
4191
  ExceptionInfo *exception;
@@ -4198,6 +4227,8 @@ Image_convolve_channel(int argc, VALUE *argv, VALUE self)
4198
4227
 
4199
4228
  rm_ensure_result(new_image);
4200
4229
 
4230
+ RB_GC_GUARD(ary);
4231
+
4201
4232
  return rm_image_new(new_image);
4202
4233
  }
4203
4234
 
@@ -4362,7 +4393,7 @@ Image_density_eq(VALUE self, VALUE density_arg)
4362
4393
  {
4363
4394
  Image *image;
4364
4395
  char *density;
4365
- volatile VALUE x_val, y_val;
4396
+ VALUE x_val, y_val;
4366
4397
  int count;
4367
4398
  double x_res, y_res;
4368
4399
 
@@ -4406,6 +4437,9 @@ Image_density_eq(VALUE self, VALUE density_arg)
4406
4437
 
4407
4438
  }
4408
4439
 
4440
+ RB_GC_GUARD(x_val);
4441
+ RB_GC_GUARD(y_val);
4442
+
4409
4443
  return self;
4410
4444
  }
4411
4445
 
@@ -4744,7 +4778,7 @@ Image_difference(VALUE self, VALUE other)
4744
4778
  {
4745
4779
  Image *image;
4746
4780
  Image *image2;
4747
- volatile VALUE mean, nmean, nmax;
4781
+ VALUE mean, nmean, nmax;
4748
4782
 
4749
4783
  image = rm_check_destroyed(self);
4750
4784
  other = rm_cur_image(other);
@@ -4756,6 +4790,11 @@ Image_difference(VALUE self, VALUE other)
4756
4790
  mean = rb_float_new(image->error.mean_error_per_pixel);
4757
4791
  nmean = rb_float_new(image->error.normalized_mean_error);
4758
4792
  nmax = rb_float_new(image->error.normalized_maximum_error);
4793
+
4794
+ RB_GC_GUARD(mean);
4795
+ RB_GC_GUARD(nmean);
4796
+ RB_GC_GUARD(nmax);
4797
+
4759
4798
  return rb_ary_new3(3, mean, nmean, nmax);
4760
4799
  }
4761
4800
 
@@ -4799,7 +4838,7 @@ VALUE
4799
4838
  Image_displace(int argc, VALUE *argv, VALUE self)
4800
4839
  {
4801
4840
  Image *image, *displacement_map;
4802
- volatile VALUE dmap;
4841
+ VALUE dmap;
4803
4842
  double x_amplitude = 0.0, y_amplitude = 0.0;
4804
4843
  long x_offset = 0L, y_offset = 0L;
4805
4844
 
@@ -4832,6 +4871,8 @@ Image_displace(int argc, VALUE *argv, VALUE self)
4832
4871
  break;
4833
4872
  }
4834
4873
 
4874
+ RB_GC_GUARD(dmap);
4875
+
4835
4876
  return special_composite(image, displacement_map, x_amplitude, y_amplitude
4836
4877
  , x_offset, y_offset, DisplaceCompositeOp);
4837
4878
  }
@@ -4863,7 +4904,7 @@ Image_dispatch(int argc, VALUE *argv, VALUE self)
4863
4904
  Image *image;
4864
4905
  long x, y;
4865
4906
  unsigned long columns, rows, n, npixels;
4866
- volatile VALUE pixels_ary;
4907
+ VALUE pixels_ary;
4867
4908
  StorageType stg_type = QuantumPixel;
4868
4909
  char *map;
4869
4910
  long mapL;
@@ -4933,6 +4974,9 @@ Image_dispatch(int argc, VALUE *argv, VALUE self)
4933
4974
 
4934
4975
  exit:
4935
4976
  xfree((void *)pixels.v);
4977
+
4978
+ RB_GC_GUARD(pixels_ary);
4979
+
4936
4980
  return pixels_ary;
4937
4981
  }
4938
4982
 
@@ -4951,7 +4995,7 @@ Image_display(VALUE self)
4951
4995
  {
4952
4996
  Image *image;
4953
4997
  Info *info;
4954
- volatile VALUE info_obj;
4998
+ VALUE info_obj;
4955
4999
 
4956
5000
  image = rm_check_destroyed(self);
4957
5001
 
@@ -4966,6 +5010,8 @@ Image_display(VALUE self)
4966
5010
  (void) DisplayImages(info, image);
4967
5011
  rm_check_image_exception(image, RetainOnError);
4968
5012
 
5013
+ RB_GC_GUARD(info_obj);
5014
+
4969
5015
  return self;
4970
5016
  }
4971
5017
 
@@ -5037,7 +5083,7 @@ Image_dissolve(int argc, VALUE *argv, VALUE self)
5037
5083
  Image *image, *overlay;
5038
5084
  double src_percent, dst_percent = -1.0;
5039
5085
  long x_offset = 0L, y_offset = 0L;
5040
- volatile VALUE composite_image, ovly;
5086
+ VALUE composite_image, ovly;
5041
5087
 
5042
5088
  image = rm_check_destroyed(self);
5043
5089
 
@@ -5071,6 +5117,9 @@ Image_dissolve(int argc, VALUE *argv, VALUE self)
5071
5117
  composite_image = special_composite(image, overlay, src_percent, dst_percent
5072
5118
  , x_offset, y_offset, DissolveCompositeOp);
5073
5119
 
5120
+ RB_GC_GUARD(composite_image);
5121
+ RB_GC_GUARD(ovly);
5122
+
5074
5123
  return composite_image;
5075
5124
  }
5076
5125
 
@@ -5099,7 +5148,7 @@ VALUE
5099
5148
  Image_distort(int argc, VALUE *argv, VALUE self)
5100
5149
  {
5101
5150
  Image *image, *new_image;
5102
- volatile VALUE pts;
5151
+ VALUE pts;
5103
5152
  unsigned long n, npoints;
5104
5153
  DistortImageMethod distortion_method;
5105
5154
  double *points;
@@ -5140,6 +5189,8 @@ Image_distort(int argc, VALUE *argv, VALUE self)
5140
5189
  (void) DestroyExceptionInfo(exception);
5141
5190
  rm_ensure_result(new_image);
5142
5191
 
5192
+ RB_GC_GUARD(pts);
5193
+
5143
5194
  return rm_image_new(new_image);
5144
5195
  }
5145
5196
 
@@ -5167,7 +5218,7 @@ Image_distortion_channel(int argc, VALUE *argv, VALUE self)
5167
5218
  ChannelType channels;
5168
5219
  ExceptionInfo *exception;
5169
5220
  MetricType metric;
5170
- volatile VALUE rec;
5221
+ VALUE rec;
5171
5222
  double distortion;
5172
5223
 
5173
5224
  image = rm_check_destroyed(self);
@@ -5191,6 +5242,8 @@ Image_distortion_channel(int argc, VALUE *argv, VALUE self)
5191
5242
 
5192
5243
  (void) DestroyExceptionInfo(exception);
5193
5244
 
5245
+ RB_GC_GUARD(rec);
5246
+
5194
5247
  return rb_float_new(distortion);
5195
5248
  }
5196
5249
 
@@ -5217,7 +5270,7 @@ Image__dump(VALUE self, VALUE depth)
5217
5270
  void *blob;
5218
5271
  size_t length;
5219
5272
  DumpedImage mi;
5220
- volatile VALUE str;
5273
+ VALUE str;
5221
5274
  ExceptionInfo *exception;
5222
5275
 
5223
5276
  depth = depth; // Suppress "never referenced" message from icc
@@ -5260,6 +5313,9 @@ Image__dump(VALUE self, VALUE depth)
5260
5313
  str = rb_str_new((char *)&mi, (long)(mi.len+offsetof(DumpedImage,magick)));
5261
5314
  str = rb_str_buf_cat(str, (char *)blob, (long)length);
5262
5315
  magick_free((void*)blob);
5316
+
5317
+ RB_GC_GUARD(str);
5318
+
5263
5319
  return str;
5264
5320
  }
5265
5321
 
@@ -5278,7 +5334,7 @@ Image__dump(VALUE self, VALUE depth)
5278
5334
  VALUE
5279
5335
  Image_dup(VALUE self)
5280
5336
  {
5281
- volatile VALUE dup;
5337
+ VALUE dup;
5282
5338
 
5283
5339
  (void) rm_check_destroyed(self);
5284
5340
  dup = Data_Wrap_Struct(CLASS_OF(self), NULL, rm_image_destroy, NULL);
@@ -5286,6 +5342,9 @@ Image_dup(VALUE self)
5286
5342
  {
5287
5343
  (void) rb_obj_taint(dup);
5288
5344
  }
5345
+
5346
+ RB_GC_GUARD(dup);
5347
+
5289
5348
  return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
5290
5349
  }
5291
5350
 
@@ -5306,7 +5365,7 @@ VALUE
5306
5365
  Image_each_profile(VALUE self)
5307
5366
  {
5308
5367
  Image *image;
5309
- volatile VALUE ary, val;
5368
+ VALUE ary, val;
5310
5369
  char *name;
5311
5370
  const StringInfo *profile;
5312
5371
 
@@ -5333,6 +5392,9 @@ Image_each_profile(VALUE self)
5333
5392
  name = GetNextImageProfile(image);
5334
5393
  }
5335
5394
 
5395
+ RB_GC_GUARD(ary);
5396
+ RB_GC_GUARD(val);
5397
+
5336
5398
  return val;
5337
5399
  }
5338
5400
 
@@ -5809,7 +5871,7 @@ Image_export_pixels(int argc, VALUE *argv, VALUE self)
5809
5871
  unsigned int okay;
5810
5872
  const char *map = "RGB";
5811
5873
  Quantum *pixels;
5812
- volatile VALUE ary;
5874
+ VALUE ary;
5813
5875
  ExceptionInfo *exception;
5814
5876
 
5815
5877
 
@@ -5873,6 +5935,8 @@ Image_export_pixels(int argc, VALUE *argv, VALUE self)
5873
5935
 
5874
5936
  xfree((void *)pixels);
5875
5937
 
5938
+ RB_GC_GUARD(ary);
5939
+
5876
5940
  return ary;
5877
5941
  }
5878
5942
 
@@ -5984,7 +6048,7 @@ Image_export_pixels_to_str(int argc, VALUE *argv, VALUE self)
5984
6048
  unsigned int okay;
5985
6049
  const char *map = "RGB";
5986
6050
  StorageType type = CharPixel;
5987
- volatile VALUE string;
6051
+ VALUE string;
5988
6052
  char *str;
5989
6053
  ExceptionInfo *exception;
5990
6054
 
@@ -6072,6 +6136,8 @@ Image_export_pixels_to_str(int argc, VALUE *argv, VALUE self)
6072
6136
 
6073
6137
  (void) DestroyExceptionInfo(exception);
6074
6138
 
6139
+ RB_GC_GUARD(string);
6140
+
6075
6141
  return string;
6076
6142
  }
6077
6143
 
@@ -6197,7 +6263,7 @@ VALUE
6197
6263
  Image_find_similar_region(int argc, VALUE *argv, VALUE self)
6198
6264
  {
6199
6265
  Image *image, *target;
6200
- volatile VALUE region, targ;
6266
+ VALUE region, targ;
6201
6267
  ssize_t x = 0L, y = 0L;
6202
6268
  ExceptionInfo *exception;
6203
6269
  unsigned int okay;
@@ -6233,6 +6299,9 @@ Image_find_similar_region(int argc, VALUE *argv, VALUE self)
6233
6299
  rb_ary_store(region, 0L, LONG2NUM(x));
6234
6300
  rb_ary_store(region, 1L, LONG2NUM(y));
6235
6301
 
6302
+ RB_GC_GUARD(region);
6303
+ RB_GC_GUARD(targ);
6304
+
6236
6305
  return region;
6237
6306
  }
6238
6307
 
@@ -6541,7 +6610,7 @@ Image_from_blob(VALUE class, VALUE blob_arg)
6541
6610
  {
6542
6611
  Image *images;
6543
6612
  Info *info;
6544
- volatile VALUE info_obj;
6613
+ VALUE info_obj;
6545
6614
  ExceptionInfo *exception;
6546
6615
  void *blob;
6547
6616
  long length;
@@ -6564,6 +6633,8 @@ Image_from_blob(VALUE class, VALUE blob_arg)
6564
6633
  rm_ensure_result(images);
6565
6634
  rm_set_user_artifact(images, info);
6566
6635
 
6636
+ RB_GC_GUARD(info_obj);
6637
+
6567
6638
  return array_from_images(images);
6568
6639
  }
6569
6640
 
@@ -6917,7 +6988,7 @@ Image_geometry_eq(
6917
6988
  VALUE geometry)
6918
6989
  {
6919
6990
  Image *image;
6920
- volatile VALUE geom_str;
6991
+ VALUE geom_str;
6921
6992
  char *geom;
6922
6993
 
6923
6994
  image = rm_check_frozen(self);
@@ -6937,6 +7008,9 @@ Image_geometry_eq(
6937
7008
  rb_raise(rb_eTypeError, "invalid geometry: %s", geom);
6938
7009
  }
6939
7010
  magick_clone_string(&image->geometry, geom);
7011
+
7012
+ RB_GC_GUARD(geom_str);
7013
+
6940
7014
  return self;
6941
7015
  }
6942
7016
 
@@ -7143,7 +7217,7 @@ Image_import_pixels(int argc, VALUE *argv, VALUE self)
7143
7217
  unsigned long n, npixels;
7144
7218
  long buffer_l;
7145
7219
  char *map;
7146
- volatile VALUE pixel_arg, pixel_ary;
7220
+ VALUE pixel_arg, pixel_ary;
7147
7221
  StorageType stg_type = CharPixel;
7148
7222
  size_t type_sz, map_l;
7149
7223
  Quantum *pixels = NULL;
@@ -7262,8 +7336,9 @@ Image_import_pixels(int argc, VALUE *argv, VALUE self)
7262
7336
  pixels = ALLOC_N(Quantum, npixels);
7263
7337
  for (n = 0; n < npixels; n++)
7264
7338
  {
7265
- volatile VALUE p = rb_ary_entry(pixel_ary, n);
7339
+ VALUE p = rb_ary_entry(pixel_ary, n);
7266
7340
  pixels[n] = NUM2QUANTUM(p);
7341
+ RB_GC_GUARD(p);
7267
7342
  }
7268
7343
  buffer = (void *) pixels;
7269
7344
  stg_type = QuantumPixel;
@@ -7290,6 +7365,9 @@ Image_import_pixels(int argc, VALUE *argv, VALUE self)
7290
7365
  rm_magick_error("ImportImagePixels failed with no explanation.", NULL);
7291
7366
  }
7292
7367
 
7368
+ RB_GC_GUARD(pixel_arg);
7369
+ RB_GC_GUARD(pixel_ary);
7370
+
7293
7371
  return self;
7294
7372
  }
7295
7373
 
@@ -8133,7 +8211,7 @@ Image_map(int argc, VALUE *argv, VALUE self)
8133
8211
  {
8134
8212
  Image *image, *new_image;
8135
8213
  Image *map;
8136
- volatile VALUE map_obj, map_arg;
8214
+ VALUE map_obj, map_arg;
8137
8215
  unsigned int dither = MagickFalse;
8138
8216
 
8139
8217
  #if defined(HAVE_REMAPIMAGE)
@@ -8168,6 +8246,9 @@ Image_map(int argc, VALUE *argv, VALUE self)
8168
8246
  #endif
8169
8247
  rm_check_image_exception(new_image, DestroyOnError);
8170
8248
 
8249
+ RB_GC_GUARD(map_obj);
8250
+ RB_GC_GUARD(map_arg);
8251
+
8171
8252
  return rm_image_new(new_image);
8172
8253
  }
8173
8254
 
@@ -8343,7 +8424,7 @@ Image_mask_eq(VALUE self, VALUE mask)
8343
8424
  VALUE
8344
8425
  Image_mask(int argc, VALUE *argv, VALUE self)
8345
8426
  {
8346
- volatile VALUE mask;
8427
+ VALUE mask;
8347
8428
  Image *image, *mask_image, *resized_image;
8348
8429
  Image *clip_mask;
8349
8430
  long x, y;
@@ -8439,6 +8520,8 @@ Image_mask(int argc, VALUE *argv, VALUE self)
8439
8520
  (void) SetImageClipMask(image, NULL);
8440
8521
  }
8441
8522
 
8523
+ RB_GC_GUARD(mask);
8524
+
8442
8525
  // Always return a copy of the mask!
8443
8526
  return get_image_mask(image);
8444
8527
  }
@@ -8702,7 +8785,7 @@ Image_mime_type(VALUE self)
8702
8785
  {
8703
8786
  Image *image;
8704
8787
  char *type;
8705
- volatile VALUE mime_type;
8788
+ VALUE mime_type;
8706
8789
 
8707
8790
  image = rm_check_destroyed(self);
8708
8791
  type = MagickToMime(image->magick);
@@ -8715,6 +8798,8 @@ Image_mime_type(VALUE self)
8715
8798
  // The returned string must be deallocated by the user.
8716
8799
  magick_free(type);
8717
8800
 
8801
+ RB_GC_GUARD(mime_type);
8802
+
8718
8803
  return mime_type;
8719
8804
  }
8720
8805
 
@@ -9076,9 +9161,12 @@ Image_negate_channel(int argc, VALUE *argv, VALUE self)
9076
9161
  VALUE
9077
9162
  Image_alloc(VALUE class)
9078
9163
  {
9079
- volatile VALUE image_obj;
9164
+ VALUE image_obj;
9080
9165
 
9081
9166
  image_obj = Data_Wrap_Struct(class, NULL, rm_image_destroy, NULL);
9167
+
9168
+ RB_GC_GUARD(image_obj);
9169
+
9082
9170
  return image_obj;
9083
9171
  }
9084
9172
 
@@ -9101,9 +9189,9 @@ Image_alloc(VALUE class)
9101
9189
  VALUE
9102
9190
  Image_initialize(int argc, VALUE *argv, VALUE self)
9103
9191
  {
9104
- volatile VALUE fill = 0;
9192
+ VALUE fill = 0;
9105
9193
  Info *info;
9106
- volatile VALUE info_obj;
9194
+ VALUE info_obj;
9107
9195
  Image *image;
9108
9196
  unsigned long cols, rows;
9109
9197
 
@@ -9150,6 +9238,9 @@ Image_initialize(int argc, VALUE *argv, VALUE self)
9150
9238
  (void) rb_funcall(fill, rm_ID_fill, 1, self);
9151
9239
  }
9152
9240
 
9241
+ RB_GC_GUARD(fill);
9242
+ RB_GC_GUARD(info_obj);
9243
+
9153
9244
  return self;
9154
9245
  }
9155
9246
 
@@ -9959,7 +10050,7 @@ VALUE
9959
10050
  Image_polaroid(int argc, VALUE *argv, VALUE self)
9960
10051
  {
9961
10052
  Image *image, *clone, *new_image;
9962
- volatile VALUE options;
10053
+ VALUE options;
9963
10054
  double angle = -5.0;
9964
10055
  Draw *draw;
9965
10056
  ExceptionInfo *exception;
@@ -9993,6 +10084,8 @@ Image_polaroid(int argc, VALUE *argv, VALUE self)
9993
10084
 
9994
10085
  rm_ensure_result(new_image);
9995
10086
 
10087
+ RB_GC_GUARD(options);
10088
+
9996
10089
  return rm_image_new(new_image);
9997
10090
  }
9998
10091
 
@@ -10495,7 +10588,7 @@ Image_random_threshold_channel(int argc, VALUE *argv, VALUE self)
10495
10588
  Image *image, *new_image;
10496
10589
  ChannelType channels;
10497
10590
  char *thresholds;
10498
- volatile VALUE geom_str;
10591
+ VALUE geom_str;
10499
10592
  ExceptionInfo *exception;
10500
10593
 
10501
10594
  image = rm_check_destroyed(self);
@@ -10525,6 +10618,8 @@ Image_random_threshold_channel(int argc, VALUE *argv, VALUE self)
10525
10618
 
10526
10619
  (void) DestroyExceptionInfo(exception);
10527
10620
 
10621
+ RB_GC_GUARD(geom_str);
10622
+
10528
10623
  return rm_image_new(new_image);
10529
10624
  }
10530
10625
 
@@ -10645,7 +10740,7 @@ rd_image(VALUE class, VALUE file, reader_t reader)
10645
10740
  char *filename;
10646
10741
  long filename_l;
10647
10742
  Info *info;
10648
- volatile VALUE info_obj;
10743
+ VALUE info_obj;
10649
10744
  Image *images;
10650
10745
  ExceptionInfo *exception;
10651
10746
 
@@ -10683,6 +10778,8 @@ rd_image(VALUE class, VALUE file, reader_t reader)
10683
10778
  rm_set_user_artifact(images, info);
10684
10779
  (void) DestroyExceptionInfo(exception);
10685
10780
 
10781
+ RB_GC_GUARD(info_obj);
10782
+
10686
10783
  return array_from_images(images);
10687
10784
  }
10688
10785
 
@@ -10766,7 +10863,7 @@ Image_recolor(VALUE self, VALUE color_matrix)
10766
10863
  VALUE
10767
10864
  Image_read_inline(VALUE self, VALUE content)
10768
10865
  {
10769
- volatile VALUE info_obj;
10866
+ VALUE info_obj;
10770
10867
  Image *images;
10771
10868
  ImageInfo *info;
10772
10869
  char *image_data;
@@ -10815,6 +10912,8 @@ Image_read_inline(VALUE self, VALUE content)
10815
10912
  (void) DestroyExceptionInfo(exception);
10816
10913
  rm_set_user_artifact(images, info);
10817
10914
 
10915
+ RB_GC_GUARD(info_obj);
10916
+
10818
10917
  return array_from_images(images);
10819
10918
  }
10820
10919
 
@@ -10830,7 +10929,7 @@ Image_read_inline(VALUE self, VALUE content)
10830
10929
  static VALUE
10831
10930
  array_from_images(Image *images)
10832
10931
  {
10833
- volatile VALUE image_obj, image_ary;
10932
+ VALUE image_obj, image_ary;
10834
10933
  Image *image;
10835
10934
 
10836
10935
  // Orphan the image, create an Image object, add it to the array.
@@ -10843,6 +10942,9 @@ array_from_images(Image *images)
10843
10942
  (void) rb_ary_push(image_ary, image_obj);
10844
10943
  }
10845
10944
 
10945
+ RB_GC_GUARD(image_obj);
10946
+ RB_GC_GUARD(image_ary);
10947
+
10846
10948
  return image_ary;
10847
10949
  }
10848
10950
 
@@ -10904,8 +11006,9 @@ Image_remap(int argc, VALUE *argv, VALUE self)
10904
11006
  image = rm_check_frozen(self);
10905
11007
  if (argc > 0)
10906
11008
  {
10907
- volatile VALUE t = rm_cur_image(argv[0]);
11009
+ VALUE t = rm_cur_image(argv[0]);
10908
11010
  remap_image = rm_check_destroyed(t);
11011
+ RB_GC_GUARD(t);
10909
11012
  }
10910
11013
 
10911
11014
  GetQuantizeInfo(&quantize_info);
@@ -11889,8 +11992,8 @@ VALUE
11889
11992
  Image_properties(VALUE self)
11890
11993
  {
11891
11994
  Image *image;
11892
- volatile VALUE attr_hash;
11893
- volatile VALUE ary;
11995
+ VALUE attr_hash;
11996
+ VALUE ary;
11894
11997
  char *property;
11895
11998
  const char *value;
11896
11999
 
@@ -11911,6 +12014,9 @@ Image_properties(VALUE self)
11911
12014
  property = GetNextImageProperty(image);
11912
12015
  }
11913
12016
  rm_check_image_exception(image, RetainOnError);
12017
+
12018
+ RB_GC_GUARD(ary);
12019
+
11914
12020
  return self;
11915
12021
  }
11916
12022
 
@@ -11927,6 +12033,9 @@ Image_properties(VALUE self)
11927
12033
  property = GetNextImageProperty(image);
11928
12034
  }
11929
12035
  rm_check_image_exception(image, RetainOnError);
12036
+
12037
+ RB_GC_GUARD(attr_hash);
12038
+
11930
12039
  return attr_hash;
11931
12040
  }
11932
12041
 
@@ -12578,6 +12687,8 @@ Image_sparse_color(int argc, VALUE *argv, VALUE self)
12578
12687
  CHECK_EXCEPTION();
12579
12688
  rm_ensure_result(new_image);
12580
12689
 
12690
+ RB_GC_GUARD(args);
12691
+
12581
12692
  return rm_image_new(new_image);
12582
12693
 
12583
12694
  #else
@@ -12721,7 +12832,7 @@ VALUE
12721
12832
  Image_stegano(VALUE self, VALUE watermark_image, VALUE offset)
12722
12833
  {
12723
12834
  Image *image, *new_image;
12724
- volatile VALUE wm_image;
12835
+ VALUE wm_image;
12725
12836
  Image *watermark;
12726
12837
  ExceptionInfo *exception;
12727
12838
 
@@ -12740,6 +12851,8 @@ Image_stegano(VALUE self, VALUE watermark_image, VALUE offset)
12740
12851
 
12741
12852
  rm_ensure_result(new_image);
12742
12853
 
12854
+ RB_GC_GUARD(wm_image);
12855
+
12743
12856
  return rm_image_new(new_image);
12744
12857
  }
12745
12858
 
@@ -12760,7 +12873,7 @@ VALUE
12760
12873
  Image_stereo(VALUE self, VALUE offset_image_arg)
12761
12874
  {
12762
12875
  Image *image, *new_image;
12763
- volatile VALUE offset_image;
12876
+ VALUE offset_image;
12764
12877
  Image *offset;
12765
12878
  ExceptionInfo *exception;
12766
12879
 
@@ -12777,6 +12890,8 @@ Image_stereo(VALUE self, VALUE offset_image_arg)
12777
12890
 
12778
12891
  rm_ensure_result(new_image);
12779
12892
 
12893
+ RB_GC_GUARD(offset_image);
12894
+
12780
12895
  return rm_image_new(new_image);
12781
12896
  }
12782
12897
 
@@ -12868,7 +12983,7 @@ Image_store_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg
12868
12983
  {
12869
12984
  Image *image;
12870
12985
  Pixel *pixels, *pixel;
12871
- volatile VALUE new_pixel;
12986
+ VALUE new_pixel;
12872
12987
  long n, size;
12873
12988
  long x, y;
12874
12989
  unsigned long cols, rows;
@@ -12934,6 +13049,8 @@ Image_store_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg
12934
13049
  #endif
12935
13050
  }
12936
13051
 
13052
+ RB_GC_GUARD(new_pixel);
13053
+
12937
13054
  return self;
12938
13055
  }
12939
13056
 
@@ -13002,8 +13119,11 @@ VALUE
13002
13119
  Image_sync_profiles(VALUE self)
13003
13120
  {
13004
13121
  Image *image = rm_check_destroyed(self);
13005
- volatile VALUE okay = SyncImageProfiles(image) ? Qtrue : Qfalse;
13122
+ VALUE okay = SyncImageProfiles(image) ? Qtrue : Qfalse;
13006
13123
  rm_check_image_exception(image, RetainOnError);
13124
+
13125
+ RB_GC_GUARD(okay);
13126
+
13007
13127
  return okay;
13008
13128
  }
13009
13129
 
@@ -13036,7 +13156,7 @@ Image_texture_flood_fill(VALUE self, VALUE color_obj, VALUE texture_obj
13036
13156
  Image *image, *new_image;
13037
13157
  Image *texture_image;
13038
13158
  PixelPacket color;
13039
- volatile VALUE texture;
13159
+ VALUE texture;
13040
13160
  DrawInfo *draw_info;
13041
13161
  long x, y;
13042
13162
  PaintMethod method;
@@ -13104,6 +13224,7 @@ Image_texture_flood_fill(VALUE self, VALUE color_obj, VALUE texture_obj
13104
13224
  (void) DestroyDrawInfo(draw_info);
13105
13225
  rm_check_image_exception(new_image, DestroyOnError);
13106
13226
 
13227
+ RB_GC_GUARD(texture);
13107
13228
 
13108
13229
  return rm_image_new(new_image);
13109
13230
  }
@@ -13453,8 +13574,8 @@ Image_to_blob(VALUE self)
13453
13574
  Image *image;
13454
13575
  Info *info;
13455
13576
  const MagickInfo *magick_info;
13456
- volatile VALUE info_obj;
13457
- volatile VALUE blob_str;
13577
+ VALUE info_obj;
13578
+ VALUE blob_str;
13458
13579
  void *blob = NULL;
13459
13580
  size_t length = 2048; // Do what Magick++ does
13460
13581
  ExceptionInfo *exception;
@@ -13518,6 +13639,9 @@ Image_to_blob(VALUE self)
13518
13639
 
13519
13640
  magick_free((void*)blob);
13520
13641
 
13642
+ RB_GC_GUARD(info_obj);
13643
+ RB_GC_GUARD(blob_str);
13644
+
13521
13645
  return blob_str;
13522
13646
  }
13523
13647
 
@@ -14472,7 +14596,7 @@ Image_watermark(int argc, VALUE *argv, VALUE self)
14472
14596
  double src_percent = 100.0, dst_percent = 100.0;
14473
14597
  long x_offset = 0L, y_offset = 0L;
14474
14598
  char geometry[20];
14475
- volatile VALUE ovly;
14599
+ VALUE ovly;
14476
14600
 
14477
14601
  image = rm_check_destroyed(self);
14478
14602
 
@@ -14515,6 +14639,8 @@ Image_watermark(int argc, VALUE *argv, VALUE self)
14515
14639
 
14516
14640
  rm_check_image_exception(new_image, DestroyOnError);
14517
14641
 
14642
+ RB_GC_GUARD(ovly);
14643
+
14518
14644
  return rm_image_new(new_image);
14519
14645
  }
14520
14646
 
@@ -14865,7 +14991,7 @@ Image_write(VALUE self, VALUE file)
14865
14991
  {
14866
14992
  Image *image;
14867
14993
  Info *info;
14868
- volatile VALUE info_obj;
14994
+ VALUE info_obj;
14869
14995
 
14870
14996
  image = rm_check_destroyed(self);
14871
14997
 
@@ -14901,6 +15027,8 @@ Image_write(VALUE self, VALUE file)
14901
15027
  (void) WriteImage(info, image);
14902
15028
  rm_check_image_exception(image, RetainOnError);
14903
15029
 
15030
+ RB_GC_GUARD(info_obj);
15031
+
14904
15032
  return self;
14905
15033
  }
14906
15034
 
@@ -14937,7 +15065,7 @@ DEF_ATTR_ACCESSOR(Image, y_resolution, dbl)
14937
15065
  static VALUE
14938
15066
  cropper(int bang, int argc, VALUE *argv, VALUE self)
14939
15067
  {
14940
- volatile VALUE x, y, width, height;
15068
+ VALUE x, y, width, height;
14941
15069
  unsigned long nx = 0, ny = 0;
14942
15070
  unsigned long columns, rows;
14943
15071
  int reset_page = 0;
@@ -15098,6 +15226,12 @@ cropper(int bang, int argc, VALUE *argv, VALUE self)
15098
15226
  Data_Get_Struct(cropped, Image, image);
15099
15227
  ResetImagePage(image, "0x0+0+0");
15100
15228
  }
15229
+
15230
+ RB_GC_GUARD(x);
15231
+ RB_GC_GUARD(y);
15232
+ RB_GC_GUARD(width);
15233
+ RB_GC_GUARD(height);
15234
+
15101
15235
  return cropped;
15102
15236
  }
15103
15237
 
@@ -15168,7 +15302,7 @@ xform_image(int bang, VALUE self, VALUE x, VALUE y, VALUE width, VALUE height, x
15168
15302
  */
15169
15303
  ChannelType extract_channels(int *argc, VALUE *argv)
15170
15304
  {
15171
- volatile VALUE arg;
15305
+ VALUE arg;
15172
15306
  ChannelType channels, ch_arg;
15173
15307
 
15174
15308
  channels = 0;
@@ -15191,6 +15325,8 @@ ChannelType extract_channels(int *argc, VALUE *argv)
15191
15325
  channels = DefaultChannels;
15192
15326
  }
15193
15327
 
15328
+ RB_GC_GUARD(arg);
15329
+
15194
15330
  return channels;
15195
15331
  }
15196
15332
 
@@ -15221,7 +15357,7 @@ raise_ChannelType_error(VALUE arg)
15221
15357
  */
15222
15358
  static void call_trace_proc(Image *image, const char *which)
15223
15359
  {
15224
- volatile VALUE trace;
15360
+ VALUE trace;
15225
15361
  VALUE trace_args[4];
15226
15362
 
15227
15363
  if (rb_ivar_defined(Module_Magick, rm_ID_trace_proc) == Qtrue)
@@ -15246,6 +15382,7 @@ static void call_trace_proc(Image *image, const char *which)
15246
15382
  }
15247
15383
  }
15248
15384
 
15385
+ RB_GC_GUARD(trace);
15249
15386
  }
15250
15387
 
15251
15388