ext/RMagick/rmutil.c in rmagick-2.14.0 vs ext/RMagick/rmutil.c in rmagick-2.15.0
- old
+ new
@@ -583,17 +583,19 @@
* @return a Quantum
*/
Quantum
rm_app2quantum(VALUE obj)
{
- volatile VALUE v = obj;
+ VALUE v = obj;
if (TYPE(obj) == T_FLOAT)
{
v = rb_funcall(obj, rm_ID_to_i, 0);
}
+ RB_GC_GUARD(v);
+
return NUM2QUANTUM(v);
}
/**
@@ -659,11 +661,11 @@
VALUE
rm_pixelpacket_to_color_name_info(Info *info, PixelPacket *color)
{
Image *image;
Info *my_info;
- volatile VALUE color_name;
+ VALUE color_name;
my_info = info ? info : CloneImageInfo(NULL);
image = AcquireImage(info);
image->matte = MagickFalse;
@@ -672,10 +674,12 @@
if (!info)
{
(void) DestroyImageInfo(my_info);
}
+ RB_GC_GUARD(color_name);
+
return color_name;
}
/**
@@ -697,11 +701,11 @@
#define TMPNAM_CLASS_VAR "@@_tmpnam_"
MagickBooleanType okay;
ExceptionInfo *exception;
- volatile VALUE id_value;
+ VALUE id_value;
int id;
exception = AcquireExceptionInfo();
@@ -728,10 +732,11 @@
if (!okay)
{
rb_raise(rb_eRuntimeError, "SetImageRegistry failed.");
}
+ RB_GC_GUARD(id_value);
}
/**
* Delete the temporary image from the registry.
@@ -787,17 +792,21 @@
* @see www.ruby_talk.org/36408.
*/
void
rm_magick_error(const char *msg, const char *loc)
{
- volatile VALUE exc, mesg, extra;
+ VALUE exc, mesg, extra;
mesg = rb_str_new2(msg);
extra = loc ? rb_str_new2(loc) : Qnil;
exc = rb_funcall(Class_ImageMagickError, rm_ID_new, 2, mesg, extra);
(void) rb_funcall(rb_cObject, rb_intern("raise"), 1, exc);
+
+ RB_GC_GUARD(exc);
+ RB_GC_GUARD(mesg);
+ RB_GC_GUARD(extra);
}
/**
* Initialize a new ImageMagickError object - store the "loc" string in the
@@ -818,11 +827,11 @@
VALUE
ImageMagickError_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE super_argv[1] = {(VALUE)0};
int super_argc = 0;
- volatile VALUE extra = Qnil;
+ VALUE extra = Qnil;
switch(argc)
{
case 2:
extra = argv[1];
@@ -836,10 +845,11 @@
}
(void) rb_call_super(super_argc, (const VALUE *)super_argv);
(void) rb_iv_set(self, "@"MAGICK_LOC, extra);
+ RB_GC_GUARD(extra);
return self;
}
@@ -920,25 +930,28 @@
* @param img the image
*/
void
rm_get_optional_arguments(VALUE img)
{
- volatile VALUE OptionalMethodArguments;
- volatile VALUE opt_args;
- VALUE argv[1];
+ VALUE optional_method_arguments;
+ VALUE opt_args;
+ VALUE argv[1];
- // opt_args = Magick::OptionalMethodArguments.new(img)
- // opt_args.instance_eval { block }
- if (rb_block_given_p())
- {
- OptionalMethodArguments = rb_const_get_from(Module_Magick, rb_intern("OptionalMethodArguments"));
- argv[0] = img;
- opt_args = rb_class_new_instance(1, argv, OptionalMethodArguments);
- (void) rb_obj_instance_eval(0, NULL, opt_args);
- }
+ // opt_args = Magick::OptionalMethodArguments.new(img)
+ // opt_args.instance_eval { block }
+ if (rb_block_given_p())
+ {
+ optional_method_arguments = rb_const_get_from(Module_Magick, rb_intern("OptionalMethodArguments"));
+ argv[0] = img;
+ opt_args = rb_class_new_instance(1, argv, optional_method_arguments);
+ (void) rb_obj_instance_eval(0, NULL, opt_args);
+ }
- return;
+ RB_GC_GUARD(optional_method_arguments);
+ RB_GC_GUARD(opt_args);
+
+ return;
}
#if defined(HAVE_SETIMAGEARTIFACT)
/**
@@ -1157,11 +1170,11 @@
rm_exif_by_entry(Image *image)
{
const char *property, *value;
char *str;
size_t len = 0, property_l, value_l;
- volatile VALUE v;
+ VALUE v;
(void) GetImageProperty(image, "exif:*");
ResetImagePropertyIterator(image);
property = GetNextImageProperty(image);
@@ -1221,10 +1234,13 @@
property = GetNextImageProperty(image);
}
v = rb_str_new(str, len);
xfree(str);
+
+ RB_GC_GUARD(v);
+
return v;
}
/**
@@ -1243,11 +1259,11 @@
rm_exif_by_number(Image *image)
{
const char *property, *value;
char *str;
size_t len = 0, property_l, value_l;
- volatile VALUE v;
+ VALUE v;
(void) GetImageProperty(image, "exif:!");
ResetImagePropertyIterator(image);
property = GetNextImageProperty(image);
@@ -1307,10 +1323,13 @@
property = GetNextImageProperty(image);
}
v = rb_str_new(str, len);
xfree(str);
+
+ RB_GC_GUARD(v);
+
return v;
}
/**
@@ -1424,12 +1443,12 @@
const char *tag,
const MagickOffsetType of,
const MagickSizeType sp,
void *client_data)
{
- volatile VALUE rval;
- volatile VALUE method, offset, span;
+ VALUE rval;
+ VALUE method, offset, span;
tag = tag; // defeat gcc message
#if defined(HAVE_LONG_LONG) // defined in Ruby's defines.h
offset = rb_ll2inum(of);
@@ -1440,9 +1459,14 @@
#endif
method = rb_str_new2(rb_id2name(THIS_FUNC()));
rval = rb_funcall((VALUE)client_data, rm_ID_call, 3, method, offset, span);
+
+ RB_GC_GUARD(rval);
+ RB_GC_GUARD(method);
+ RB_GC_GUARD(offset);
+ RB_GC_GUARD(span);
return RTEST(rval) ? MagickTrue : MagickFalse;
}