ext/RMagick/rmstruct.c in rmagick-4.1.0.rc2 vs ext/RMagick/rmstruct.c in rmagick-4.1.0

- old
+ new

@@ -80,11 +80,11 @@ RB_GC_GUARD(v); } /** - * Create a Magick::ChromaticityInfo object from a ChromaticityInfo structure. + * Create a {Magick::ChromaticityInfo} object from a ChromaticityInfo structure. * * No Ruby usage (internal function) * * @param ci the C ChromaticityInfo * @return a Ruby Magick::ChromaticityInfo object @@ -105,12 +105,12 @@ 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); + return rb_funcall(Class_Chromaticity, rm_ID_new, 4, + red_primary, green_primary, blue_primary, white_point); } /** * Extract the elements from a Magick::ChromaticityInfo and store in a @@ -125,52 +125,50 @@ Export_ChromaticityInfo(ChromaticityInfo *ci, VALUE chrom) { 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", rb_class2name(CLASS_OF(chrom))); } - values_id = rm_ID_values; // Get the struct members in an array - chrom_members = rb_funcall(chrom, values_id, 0); + chrom_members = rb_funcall(chrom, rm_ID_values, 0); red_primary = rb_ary_entry(chrom_members, 0); green_primary = rb_ary_entry(chrom_members, 1); blue_primary = rb_ary_entry(chrom_members, 2); white_point = rb_ary_entry(chrom_members, 3); // Get the red_primary PrimaryInfo members in an array - entry_members = rb_funcall(red_primary, values_id, 0); + entry_members = rb_funcall(red_primary, rm_ID_values, 0); x = rb_ary_entry(entry_members, 0); // red_primary.x ci->red_primary.x = x == Qnil ? 0.0 : NUM2DBL(x); y = rb_ary_entry(entry_members, 1); // red_primary.y ci->red_primary.y = y == Qnil ? 0.0 : NUM2DBL(y); ci->red_primary.z = 0.0; // Get the green_primary PrimaryInfo members in an array - entry_members = rb_funcall(green_primary, values_id, 0); + entry_members = rb_funcall(green_primary, rm_ID_values, 0); x = rb_ary_entry(entry_members, 0); // green_primary.x ci->green_primary.x = x == Qnil ? 0.0 : NUM2DBL(x); y = rb_ary_entry(entry_members, 1); // green_primary.y ci->green_primary.y = y == Qnil ? 0.0 : NUM2DBL(y); ci->green_primary.z = 0.0; // Get the blue_primary PrimaryInfo members in an array - entry_members = rb_funcall(blue_primary, values_id, 0); + entry_members = rb_funcall(blue_primary, rm_ID_values, 0); x = rb_ary_entry(entry_members, 0); // blue_primary.x ci->blue_primary.x = x == Qnil ? 0.0 : NUM2DBL(x); y = rb_ary_entry(entry_members, 1); // blue_primary.y ci->blue_primary.y = y == Qnil ? 0.0 : NUM2DBL(y); ci->blue_primary.z = 0.0; // Get the white_point PrimaryInfo members in an array - entry_members = rb_funcall(white_point, values_id, 0); + entry_members = rb_funcall(white_point, rm_ID_values, 0); 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; @@ -185,26 +183,23 @@ RB_GC_GUARD(y); } /** - * Create a string representation of a Magick::Chromaticity. + * Return a string representation of a {Magick::Chromaticity} object. * - * Ruby usage: - * - @verbatim Magick::Chromaticity#to_s @endverbatim - * - * @param self this object - * @return the string + * @return [String] the string */ VALUE ChromaticityInfo_to_s(VALUE self) { ChromaticityInfo ci; char buff[200]; Export_ChromaticityInfo(&ci, self); - sprintf(buff, "red_primary=(x=%g,y=%g) " + snprintf(buff, sizeof(buff), + "red_primary=(x=%g,y=%g) " "green_primary=(x=%g,y=%g) " "blue_primary=(x=%g,y=%g) " "white_point=(x=%g,y=%g) ", ci.red_primary.x, ci.red_primary.y, ci.green_primary.x, ci.green_primary.y, @@ -238,12 +233,12 @@ RB_GC_GUARD(name); RB_GC_GUARD(compliance); RB_GC_GUARD(color); - return rb_funcall(Class_Color, rm_ID_new, 3 - , name, compliance, color); + return rb_funcall(Class_Color, rm_ID_new, 3, + name, compliance, color); } /** * Convert a Magick::Color to a ColorInfo structure. @@ -270,11 +265,11 @@ members = rb_funcall(st, rm_ID_values, 0); m = rb_ary_entry(members, 0); if (m != Qnil) { - (void) CloneString((char **)&(ci->name), StringValuePtr(m)); + CloneString((char **)&(ci->name), StringValueCStr(m)); } m = rb_ary_entry(members, 1); if (m != Qnil) { VALUE_TO_ENUM(m, ci->compliance, ComplianceType); @@ -349,27 +344,24 @@ ci->name = NULL; } /** - * Return a string representation of a Magick::Color object. + * Return a string representation of a {Magick::Color} object. * - * Ruby usage: - * - @verbatim Color#to_s @endverbatim - * - * @param self this object - * @return the string + * @return [String] the string */ VALUE Color_to_s(VALUE self) { ColorInfo ci; char buff[1024]; Export_ColorInfo(&ci, self); - sprintf(buff, "name=%s, compliance=%s, " + snprintf(buff, sizeof(buff), + "name=%s, compliance=%s, " #if (MAGICKCORE_QUANTUM_DEPTH == 32 || MAGICKCORE_QUANTUM_DEPTH == 64) && defined(HAVE_TYPE_LONG_DOUBLE) "color.red=%Lg, color.green=%Lg, color.blue=%Lg, color.alpha=%Lg ", #else "color.red=%g, color.green=%g, color.blue=%g, color.alpha=%g ", #endif @@ -419,13 +411,13 @@ 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); + return rb_funcall(Class_Font, rm_ID_new, 9, + name, description, family, style, + stretch, weight, encoding, foundry, format); } /** * Convert a Magick::Font to a TypeInfo structure. @@ -450,35 +442,35 @@ members = rb_funcall(st, rm_ID_values, 0); m = rb_ary_entry(members, 0); if (m != Qnil) { - (void) CloneString((char **)&(ti->name), StringValuePtr(m)); + CloneString((char **)&(ti->name), StringValueCStr(m)); } m = rb_ary_entry(members, 1); if (m != Qnil) { - (void) CloneString((char **)&(ti->description), StringValuePtr(m)); + CloneString((char **)&(ti->description), StringValueCStr(m)); } m = rb_ary_entry(members, 2); if (m != Qnil) { - (void) CloneString((char **)&(ti->family), StringValuePtr(m)); + CloneString((char **)&(ti->family), StringValueCStr(m)); } m = rb_ary_entry(members, 3); ti->style = m == Qnil ? 0 : FIX2INT(Enum_to_i(m)); m = rb_ary_entry(members, 4); ti->stretch = m == Qnil ? 0 : FIX2INT(Enum_to_i(m)); m = rb_ary_entry(members, 5); ti->weight = m == Qnil ? 0 : FIX2INT(m); m = rb_ary_entry(members, 6); if (m != Qnil) - (void) CloneString((char **)&(ti->encoding), StringValuePtr(m)); + CloneString((char **)&(ti->encoding), StringValueCStr(m)); m = rb_ary_entry(members, 7); if (m != Qnil) - (void) CloneString((char **)&(ti->foundry), StringValuePtr(m)); + CloneString((char **)&(ti->foundry), StringValueCStr(m)); m = rb_ary_entry(members, 8); if (m != Qnil) - (void) CloneString((char **)&(ti->format), StringValuePtr(m)); + CloneString((char **)&(ti->format), StringValueCStr(m)); RB_GC_GUARD(members); RB_GC_GUARD(m); } @@ -508,16 +500,13 @@ ti->format = NULL; } /** - * Implement the Font#to_s method. + * Return a string representation of a {Magick::Font} object. * - * No Ruby usage (internal function) - * - * @param self this object - * @return the string + * @return [String] the string */ VALUE Font_to_s(VALUE self) { TypeInfo ti; @@ -533,15 +522,16 @@ break; case 700: strcpy(weight, "BoldWeight"); break; default: - sprintf(weight, "%lu", ti.weight); + snprintf(weight, sizeof(weight), "%"RMIuSIZE"", ti.weight); break; } - sprintf(buff, "name=%s, description=%s, " + snprintf(buff, sizeof(buff), + "name=%s, description=%s, " "family=%s, style=%s, stretch=%s, weight=%s, " "encoding=%s, foundry=%s, format=%s", ti.name, ti.description, ti.family, @@ -567,12 +557,12 @@ * @return a Ruby Magick::Point object */ VALUE Import_PointInfo(PointInfo *p) { - return rb_funcall(Class_Point, rm_ID_new, 2 - , INT2FIX(p->x), INT2FIX(p->y)); + return rb_funcall(Class_Point, rm_ID_new, 2, + INT2FIX(p->x), INT2FIX(p->y)); } /** * Convert a Magick::Point object to a PointInfo structure. @@ -612,12 +602,12 @@ * @return a Ruby Magick::PrimaryInfo object */ VALUE Import_PrimaryInfo(PrimaryInfo *p) { - return rb_funcall(Class_Primary, rm_ID_new, 3 - , INT2FIX(p->x), INT2FIX(p->y), INT2FIX(p->z)); + return rb_funcall(Class_Primary, rm_ID_new, 3, + INT2FIX(p->x), INT2FIX(p->y), INT2FIX(p->z)); } /** * Convert a Magick::PrimaryInfo object to a PrimaryInfo structure. @@ -649,26 +639,22 @@ RB_GC_GUARD(m); } /** - * Create a string representation of a Magick::PrimaryInfo. + * Return a string representation of a {Magick::PrimaryInfo} object. * - * Ruby usage: - * - @verbatim Magick::PrimaryInfo#to_s @endverbatim - * - * @param self this object - * @return the string + * @return [String] the string */ VALUE PrimaryInfo_to_s(VALUE self) { PrimaryInfo pi; char buff[100]; Export_PrimaryInfo(&pi, self); - sprintf(buff, "x=%g, y=%g, z=%g", pi.x, pi.y, pi.z); + snprintf(buff, sizeof(buff), "x=%g, y=%g, z=%g", pi.x, pi.y, pi.z); return rb_str_new2(buff); } /** @@ -694,12 +680,12 @@ 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); + return rb_funcall(Class_Rectangle, rm_ID_new, 4, + width, height, x, y); } /** * Convert a Magick::Rectangle to a RectangleInfo structure. @@ -733,27 +719,23 @@ RB_GC_GUARD(m); } /** - * Create a string representation of a Magick::Rectangle. + * Return a string representation of a {Magick::Rectangle} object. * - * Ruby usage: - * - @verbatim Magick::Rectangle#to_s @endverbatim - * - * @param self this object - * @return the string + * @return [String] the string */ VALUE RectangleInfo_to_s(VALUE self) { RectangleInfo rect; char buff[100]; Export_RectangleInfo(&rect, self); - sprintf(buff, "width=%lu, height=%lu, x=%ld, y=%ld" - , rect.width, rect.height, rect.x, rect.y); + snprintf(buff, sizeof(buff), "width=%"RMIuSIZE", height=%"RMIuSIZE", x=%"RMIdSIZE", y=%"RMIdSIZE"", + rect.width, rect.height, rect.x, rect.y); return rb_str_new2(buff); } /** @@ -816,27 +798,23 @@ RB_GC_GUARD(m); } /** - * Create a string representation of a Magick::Segment. + * Return a string representation of a {Magick::Segment} object. * - * Ruby usage: - * - @verbatim Magick::SegmentInfo#to_s @endverbatim - * - * @param self this object - * @return the string + * @return [String] the string */ VALUE SegmentInfo_to_s(VALUE self) { SegmentInfo segment; char buff[100]; Export_SegmentInfo(&segment, self); - sprintf(buff, "x1=%g, y1=%g, x2=%g, y2=%g" - , segment.x1, segment.y1, segment.x2, segment.y2); + snprintf(buff, sizeof(buff), "x1=%g, y1=%g, x2=%g, y2=%g", + segment.x1, segment.y1, segment.x2, segment.y2); return rb_str_new2(buff); } /** @@ -873,14 +851,14 @@ 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); + return rb_funcall(Class_TypeMetric, rm_ID_new, 9, + pixels_per_em, ascent, descent, width, + height, max_advance, bounds, + underline_position, underline_thickness); } /** * Convert a Magick::TypeMetric to a TypeMetric structure. @@ -930,17 +908,13 @@ RB_GC_GUARD(pixels_per_em); } /** - * Create a string representation of a Magick::TypeMetric. + * Return a string representation of a {Magick::TypeMetric} object. * - * Ruby usage: - * - @verbatim Magick::TypeMetric#to_s @endverbatim - * - * @param self this object - * @return the string + * @return [String] the string */ VALUE TypeMetric_to_s(VALUE self) { VALUE str; @@ -948,20 +922,20 @@ char temp[200]; int len; Export_TypeMetric(&tm, self); - len = sprintf(temp, "pixels_per_em=(x=%g,y=%g) ", tm.pixels_per_em.x, tm.pixels_per_em.y); + len = snprintf(temp, sizeof(temp), "pixels_per_em=(x=%g,y=%g) ", tm.pixels_per_em.x, tm.pixels_per_em.y); str = rb_str_new(temp, len); - len = sprintf(temp, "ascent=%g descent=%g ",tm.ascent, tm.descent); + len = snprintf(temp, sizeof(temp), "ascent=%g descent=%g ",tm.ascent, tm.descent); rb_str_cat(str, temp, len); - len = sprintf(temp, "width=%g height=%g max_advance=%g ", tm.width, tm.height, tm.max_advance); + len = snprintf(temp, sizeof(temp), "width=%g height=%g max_advance=%g ", tm.width, tm.height, tm.max_advance); rb_str_cat(str, temp, len); - len = sprintf(temp, "bounds.x1=%g bounds.y1=%g ", tm.bounds.x1, tm.bounds.y1); + len = snprintf(temp, sizeof(temp), "bounds.x1=%g bounds.y1=%g ", tm.bounds.x1, tm.bounds.y1); rb_str_cat(str, temp, len); - len = sprintf(temp, "bounds.x2=%g bounds.y2=%g ", tm.bounds.x2, tm.bounds.y2); + len = snprintf(temp, sizeof(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); + len = snprintf(temp, sizeof(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;