/* Create an ErrorInfo object describing a particular error. The ErrorInfo object can be printed with error_info_print(), and must be freed when done with error_info_destroy(). This function never fails (OOM triggers an exit()); the caller can be confident the returned object is valid. */ ErrorInfo* error_info_create( const ASMLine *line, ASMErrorType err_type, ASMErrorDesc err_desc) { ErrorInfo *einfo = cr_malloc(sizeof(ErrorInfo)); einfo->type = err_type; einfo->desc = err_desc; einfo->line = line ? create_error_line(line) : NULL; return einfo; }
/* Create an ASMErrorLine object from an ASMLine. */ static ASMErrorLine* create_error_line(const ASMLine *line) { ASMErrorLine *el = cr_malloc(sizeof(ASMErrorLine)); const char *source = line->original->data; size_t length = line->original->length; // Ignore spaces at beginning: while (length > 0 && (*source == ' ' || *source == '\t')) source++, length--; el->data = cr_malloc(sizeof(char) * length); memcpy(el->data, source, length); el->length = length; el->lineno = line->original->lineno; el->filename = cr_strdup(line->filename); el->next = NULL; return el; }
/** * cairo_font_options_create: * * Allocates a new font options object with all options initialized * to default values. * * Return value: a newly allocated #cairo_font_options_t. Free with * cairo_font_options_destroy(). This function always returns a * valid pointer; if memory cannot be allocated, then a special * error object is returned where all operations on the object do nothing. * You can check for this with cairo_font_options_status(). * * Since: 1.0 **/ cairo_font_options_t * cairo_font_options_create (void) { cairo_font_options_t *options; options = cr_malloc (sizeof (cairo_font_options_t)); if (!options) { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); return (cairo_font_options_t *) &_cairo_font_options_nil; } _cairo_font_options_init_default (options); return options; }
static cairo_status_t twin_scaled_font_compute_properties (cairo_scaled_font_t *scaled_font, cairo_t *cr) { cairo_status_t status; twin_scaled_properties_t *props; props = cr_malloc (sizeof (twin_scaled_properties_t)); if (unlikely (props == NULL)) return _cairo_error (CAIRO_STATUS_NO_MEMORY); props->face_props = cairo_font_face_get_user_data (cairo_scaled_font_get_font_face (scaled_font), &twin_properties_key); props->snap = scaled_font->options.hint_style > CAIRO_HINT_STYLE_NONE; /* weight */ props->weight = props->face_props->weight * (F (4) / TWIN_WEIGHT_NORMAL); /* pen & margins */ props->penx = props->peny = props->weight; props->marginl = props->marginr = F (4); if (scaled_font->options.hint_style > CAIRO_HINT_STYLE_SLIGHT) twin_hint_pen_and_margins(cr, &props->penx, &props->peny, &props->marginl, &props->marginr); /* stretch */ props->stretch = 1 + .1 * ((int) props->face_props->stretch - (int) TWIN_STRETCH_NORMAL); /* Save it */ status = cairo_scaled_font_set_user_data (scaled_font, &twin_properties_key, props, cr_free); if (unlikely (status)) goto FREE_PROPS; return CAIRO_STATUS_SUCCESS; FREE_PROPS: cr_free (props); return status; }
/** * cairo_font_options_copy: * @original: a #cairo_font_options_t * * Allocates a new font options object copying the option values from * @original. * * Return value: a newly allocated #cairo_font_options_t. Free with * cairo_font_options_destroy(). This function always returns a * valid pointer; if memory cannot be allocated, then a special * error object is returned where all operations on the object do nothing. * You can check for this with cairo_font_options_status(). * * Since: 1.0 **/ cairo_font_options_t * cairo_font_options_copy (const cairo_font_options_t *original) { cairo_font_options_t *options; if (cairo_font_options_status ((cairo_font_options_t *) original)) return (cairo_font_options_t *) &_cairo_font_options_nil; options = cr_malloc (sizeof (cairo_font_options_t)); if (!options) { _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); return (cairo_font_options_t *) &_cairo_font_options_nil; } _cairo_font_options_init_copy (options, original); return options; }
static twin_face_properties_t * twin_font_face_create_properties (cairo_font_face_t *twin_face) { twin_face_properties_t *props; props = cr_malloc (sizeof (twin_face_properties_t)); if (unlikely (props == NULL)) return NULL; props->stretch = TWIN_STRETCH_NORMAL; props->slant = CAIRO_FONT_SLANT_NORMAL; props->weight = TWIN_WEIGHT_NORMAL; props->monospace = FALSE; props->smallcaps = FALSE; if (unlikely (cairo_font_face_set_user_data (twin_face, &twin_properties_key, props, cr_free))) { cr_free (props); return NULL; } return props; }