ext/RMagick/rmstruct.c in rmagick-2.14.0 vs ext/RMagick/rmstruct.c in rmagick-2.15.0

- old
+ new

@@ -63,11 +63,11 @@ * @param st the Ruby AffineMatrix object */ void Export_AffineMatrix(AffineMatrix *am, VALUE st) { - volatile VALUE values, v; + VALUE values, v; if (CLASS_OF(st) != Class_AffineMatrix) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(st))); @@ -83,10 +83,13 @@ am->sy = v == Qnil ? 1.0 : NUM2DBL(v); v = rb_ary_entry(values, 4); am->tx = v == Qnil ? 0.0 : NUM2DBL(v); v = rb_ary_entry(values, 5); am->ty = v == Qnil ? 0.0 : NUM2DBL(v); + + RB_GC_GUARD(values); + RB_GC_GUARD(v); } /** * Create a Magick::ChromaticityInfo object from a ChromaticityInfo structure. @@ -97,20 +100,25 @@ * @return a Ruby Magick::ChromaticityInfo object */ VALUE ChromaticityInfo_new(ChromaticityInfo *ci) { - volatile VALUE red_primary; - volatile VALUE green_primary; - volatile VALUE blue_primary; - volatile VALUE white_point; + VALUE red_primary; + VALUE green_primary; + VALUE blue_primary; + VALUE white_point; red_primary = Import_PrimaryInfo(&ci->red_primary); green_primary = Import_PrimaryInfo(&ci->green_primary); blue_primary = Import_PrimaryInfo(&ci->blue_primary); white_point = Import_PrimaryInfo(&ci->white_point); + RB_GC_GUARD(red_primary); + RB_GC_GUARD(green_primary); + RB_GC_GUARD(blue_primary); + RB_GC_GUARD(white_point); + return rb_funcall(Class_Chromaticity, rm_ID_new, 4 , red_primary, green_primary, blue_primary, white_point); } @@ -124,13 +132,13 @@ * @param chrom the Ruby Magick::ChromaticityInfo object */ void Export_ChromaticityInfo(ChromaticityInfo *ci, VALUE chrom) { - volatile VALUE chrom_members; - volatile VALUE red_primary, green_primary, blue_primary, white_point; - volatile VALUE entry_members, x, y; + VALUE chrom_members; + VALUE red_primary, green_primary, blue_primary, white_point; + VALUE entry_members, x, y; ID values_id; if (CLASS_OF(chrom) != Class_Chromaticity) { rb_raise(rb_eTypeError, "type mismatch: %s given", @@ -174,10 +182,19 @@ x = rb_ary_entry(entry_members, 0); // white_point.x ci->white_point.x = x == Qnil ? 0.0 : NUM2DBL(x); y = rb_ary_entry(entry_members, 1); // white_point.y ci->white_point.y = y == Qnil ? 0.0 : NUM2DBL(y); ci->white_point.z = 0.0; + + RB_GC_GUARD(chrom_members); + RB_GC_GUARD(red_primary); + RB_GC_GUARD(green_primary); + RB_GC_GUARD(blue_primary); + RB_GC_GUARD(white_point); + RB_GC_GUARD(entry_members); + RB_GC_GUARD(x); + RB_GC_GUARD(y); } /** * Create a string representation of a Magick::Chromaticity. @@ -217,20 +234,24 @@ */ VALUE Import_ColorInfo(const ColorInfo *ci) { ComplianceType compliance_type; - volatile VALUE name; - volatile VALUE compliance; - volatile VALUE color; + VALUE name; + VALUE compliance; + VALUE color; name = rb_str_new2(ci->name); compliance_type = ci->compliance; compliance = ComplianceType_new(compliance_type); color = Pixel_from_MagickPixelPacket(&(ci->color)); + RB_GC_GUARD(name); + RB_GC_GUARD(compliance); + RB_GC_GUARD(color); + return rb_funcall(Class_Color, rm_ID_new, 3 , name, compliance, color); } @@ -244,11 +265,11 @@ */ void Export_ColorInfo(ColorInfo *ci, VALUE st) { Pixel *pixel; - volatile VALUE members, m; + VALUE members, m; if (CLASS_OF(st) != Class_Color) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(st))); @@ -279,10 +300,13 @@ ci->color.green = (MagickRealType) pixel->green; ci->color.blue = (MagickRealType) pixel->blue; ci->color.opacity = (MagickRealType) OpaqueOpacity; ci->color.index = (MagickRealType) 0; } + + RB_GC_GUARD(members); + RB_GC_GUARD(m); } /** * Convert either a String color name or a Magick::Pixel to a MagickPixelPacket. @@ -439,13 +463,13 @@ * @return a Ruby Magick::Font object */ VALUE Import_TypeInfo(const TypeInfo *ti) { - volatile VALUE name, description, family; - volatile VALUE style, stretch, weight; - volatile VALUE encoding, foundry, format; + VALUE name, description, family; + VALUE style, stretch, weight; + VALUE encoding, foundry, format; name = rb_str_new2(ti->name); family = rb_str_new2(ti->family); style = StyleType_new(ti->style); stretch = StretchType_new(ti->stretch); @@ -453,10 +477,20 @@ description = ti->description ? rb_str_new2(ti->description) : Qnil; encoding = ti->encoding ? rb_str_new2(ti->encoding) : Qnil; foundry = ti->foundry ? rb_str_new2(ti->foundry) : Qnil; format = ti->format ? rb_str_new2(ti->format) : Qnil; + RB_GC_GUARD(name); + RB_GC_GUARD(description); + RB_GC_GUARD(family); + RB_GC_GUARD(style); + RB_GC_GUARD(stretch); + RB_GC_GUARD(weight); + RB_GC_GUARD(encoding); + RB_GC_GUARD(foundry); + RB_GC_GUARD(format); + return rb_funcall(Class_Font, rm_ID_new, 9 , name, description, family, style , stretch, weight, encoding, foundry, format); } @@ -470,11 +504,11 @@ * @param st the Ruby Magick::Font object */ void Export_TypeInfo(TypeInfo *ti, VALUE st) { - volatile VALUE members, m; + VALUE members, m; if (CLASS_OF(st) != Class_Font) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(st))); @@ -509,10 +543,13 @@ if (m != Qnil) (void) CloneString((char **)&(ti->foundry), StringValuePtr(m)); m = rb_ary_entry(members, 8); if (m != Qnil) (void) CloneString((char **)&(ti->format), StringValuePtr(m)); + + RB_GC_GUARD(members); + RB_GC_GUARD(m); } /** * Free the storage allocated by Export_TypeInfo. @@ -614,11 +651,11 @@ * @param sp the Ruby Magick::Point object */ void Export_PointInfo(PointInfo *pi, VALUE sp) { - volatile VALUE members, m; + VALUE members, m; if (CLASS_OF(sp) != Class_Point) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(sp))); @@ -626,10 +663,13 @@ members = rb_funcall(sp, rm_ID_values, 0); m = rb_ary_entry(members, 0); pi->x = m == Qnil ? 0.0 : NUM2DBL(m); m = rb_ary_entry(members, 1); pi->y = m == Qnil ? 0.0 : NUM2DBL(m); + + RB_GC_GUARD(members); + RB_GC_GUARD(m); } /** * Create a Magick::PrimaryInfo object from a PrimaryInfo structure. @@ -656,11 +696,11 @@ * @param sp the Ruby Magick::PrimaryInfo object */ void Export_PrimaryInfo(PrimaryInfo *pi, VALUE sp) { - volatile VALUE members, m; + VALUE members, m; if (CLASS_OF(sp) != Class_Primary) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(sp))); @@ -670,10 +710,13 @@ pi->x = m == Qnil ? 0.0 : NUM2DBL(m); m = rb_ary_entry(members, 1); pi->y = m == Qnil ? 0.0 : NUM2DBL(m); m = rb_ary_entry(members, 2); pi->z = m == Qnil ? 0.0 : NUM2DBL(m); + + RB_GC_GUARD(members); + RB_GC_GUARD(m); } /** * Create a string representation of a Magick::PrimaryInfo. @@ -705,18 +748,24 @@ * @return a Ruby Magick::Rectangle object */ VALUE Import_RectangleInfo(RectangleInfo *rect) { - volatile VALUE width; - volatile VALUE height; - volatile VALUE x, y; + VALUE width; + VALUE height; + VALUE x, y; width = UINT2NUM(rect->width); height = UINT2NUM(rect->height); x = INT2NUM(rect->x); y = INT2NUM(rect->y); + + RB_GC_GUARD(width); + RB_GC_GUARD(height); + RB_GC_GUARD(x); + RB_GC_GUARD(y); + return rb_funcall(Class_Rectangle, rm_ID_new, 4 , width, height, x, y); } @@ -729,11 +778,11 @@ * @param sr the Ruby Magick::Rectangle object */ void Export_RectangleInfo(RectangleInfo *rect, VALUE sr) { - volatile VALUE members, m; + VALUE members, m; if (CLASS_OF(sr) != Class_Rectangle) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(sr))); @@ -745,10 +794,13 @@ rect->height = m == Qnil ? 0 : NUM2ULONG(m); m = rb_ary_entry(members, 2); rect->x = m == Qnil ? 0 : NUM2LONG (m); m = rb_ary_entry(members, 3); rect->y = m == Qnil ? 0 : NUM2LONG (m); + + RB_GC_GUARD(members); + RB_GC_GUARD(m); } /** * Create a string representation of a Magick::Rectangle. @@ -781,16 +833,22 @@ * @return a Ruby Magick::Segment object */ VALUE Import_SegmentInfo(SegmentInfo *segment) { - volatile VALUE x1, y1, x2, y2; + VALUE x1, y1, x2, y2; x1 = rb_float_new(segment->x1); y1 = rb_float_new(segment->y1); x2 = rb_float_new(segment->x2); y2 = rb_float_new(segment->y2); + + RB_GC_GUARD(x1); + RB_GC_GUARD(y1); + RB_GC_GUARD(x2); + RB_GC_GUARD(y2); + return rb_funcall(Class_Segment, rm_ID_new, 4, x1, y1, x2, y2); } /** @@ -802,11 +860,11 @@ * @param s the Ruby Magick::Segment object */ void Export_SegmentInfo(SegmentInfo *segment, VALUE s) { - volatile VALUE members, m; + VALUE members, m; if (CLASS_OF(s) != Class_Segment) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(s))); @@ -819,10 +877,13 @@ segment->y1 = m == Qnil ? 0.0 : NUM2DBL(m); m = rb_ary_entry(members, 2); segment->x2 = m == Qnil ? 0.0 : NUM2DBL(m); m = rb_ary_entry(members, 3); segment->y2 = m == Qnil ? 0.0 : NUM2DBL(m); + + RB_GC_GUARD(members); + RB_GC_GUARD(m); } /** * Create a string representation of a Magick::Segment. @@ -941,14 +1002,14 @@ * @return a Ruby Magick::TypeMetric object */ VALUE Import_TypeMetric(TypeMetric *tm) { - volatile VALUE pixels_per_em; - volatile VALUE ascent, descent; - volatile VALUE width, height, max_advance; - volatile VALUE bounds, underline_position, underline_thickness; + VALUE pixels_per_em; + VALUE ascent, descent; + VALUE width, height, max_advance; + VALUE bounds, underline_position, underline_thickness; pixels_per_em = Import_PointInfo(&tm->pixels_per_em); ascent = rb_float_new(tm->ascent); descent = rb_float_new(tm->descent); width = rb_float_new(tm->width); @@ -956,10 +1017,20 @@ max_advance = rb_float_new(tm->max_advance); bounds = Import_SegmentInfo(&tm->bounds); underline_position = rb_float_new(tm->underline_position); underline_thickness = rb_float_new(tm->underline_position); + RB_GC_GUARD(pixels_per_em); + RB_GC_GUARD(ascent); + RB_GC_GUARD(descent); + RB_GC_GUARD(width); + RB_GC_GUARD(height); + RB_GC_GUARD(max_advance); + RB_GC_GUARD(bounds); + RB_GC_GUARD(underline_position); + RB_GC_GUARD(underline_thickness); + return rb_funcall(Class_TypeMetric, rm_ID_new, 9 , pixels_per_em, ascent, descent, width , height, max_advance, bounds , underline_position, underline_thickness); } @@ -974,12 +1045,12 @@ * @param st the Ruby Magick::TypeMetric object */ void Export_TypeMetric(TypeMetric *tm, VALUE st) { - volatile VALUE members, m; - volatile VALUE pixels_per_em; + VALUE members, m; + VALUE pixels_per_em; if (CLASS_OF(st) != Class_TypeMetric) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(st))); @@ -1005,10 +1076,14 @@ m = rb_ary_entry(members, 7); tm->underline_position = m == Qnil ? 0.0 : NUM2DBL(m); m = rb_ary_entry(members, 8); tm->underline_thickness = m == Qnil ? 0.0 : NUM2DBL(m); + + RB_GC_GUARD(members); + RB_GC_GUARD(m); + RB_GC_GUARD(pixels_per_em); } /** * Create a string representation of a Magick::TypeMetric. @@ -1020,11 +1095,11 @@ * @return the string */ VALUE TypeMetric_to_s(VALUE self) { - volatile VALUE str; + VALUE str; TypeMetric tm; char temp[200]; int len; Export_TypeMetric(&tm, self); @@ -1039,9 +1114,11 @@ rb_str_cat(str, temp, len); len = sprintf(temp, "bounds.x2=%g bounds.y2=%g ", tm.bounds.x2, tm.bounds.y2); rb_str_cat(str, temp, len); len = sprintf(temp, "underline_position=%g underline_thickness=%g", tm.underline_position, tm.underline_thickness); rb_str_cat(str, temp, len); + + RB_GC_GUARD(str); return str; }