diff options
author | Carl Worth <cworth@cworth.org> | 2006-10-04 14:58:06 -0700 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2006-10-31 21:17:30 -0500 |
commit | 405d5b7dcabb33c94b648460c7196bd188690cea (patch) | |
tree | 4a35f87f2c3dcba5459959ac561a0758fa11de88 | |
parent | 20d7a556cef03405f57d1380370682a3579eb729 (diff) |
Add new _cairo_pattern_create_for_status so that patterns properly propagate errors.
In particular, many possible error values on a surface provided
to cairo_pattern_create_for_surface were previously being swallowed
and a nil pattern was returned that erroneously reported
CAIRO_STATUS_NO_MEMORY.
(cherry picked from 01502471e31aa28a910039a918ff2aec3810d3c1 commit)
-rw-r--r-- | src/cairo-pattern.c | 52 |
1 files changed, 16 insertions, 36 deletions
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index a859e5267..5bb906d18 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -47,40 +47,6 @@ static const cairo_solid_pattern_t cairo_pattern_nil_null_pointer = { CAIRO_EXTEND_GRADIENT_DEFAULT }, /* extend */ }; -static const cairo_solid_pattern_t cairo_pattern_nil_file_not_found = { - { CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_REF_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_FILE_NOT_FOUND, /* status */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - CAIRO_FILTER_DEFAULT, /* filter */ - CAIRO_EXTEND_GRADIENT_DEFAULT }, /* extend */ -}; - -static const cairo_solid_pattern_t cairo_pattern_nil_read_error = { - { CAIRO_PATTERN_TYPE_SOLID, /* type */ - CAIRO_REF_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_READ_ERROR, /* status */ - { 1., 0., 0., 1., 0., 0., }, /* matrix */ - CAIRO_FILTER_DEFAULT, /* filter */ - CAIRO_EXTEND_GRADIENT_DEFAULT }, /* extend */ -}; - -static const cairo_pattern_t * -_cairo_pattern_nil_for_status (cairo_status_t status) -{ - /* A switch statement would be more natural here, but we're - * avoiding that to prevent a "false positive" warning from - * -Wswitch-enum, (and I don't want to maintain a list of all - * status values here). */ - if (status == CAIRO_STATUS_NULL_POINTER) - return &cairo_pattern_nil_null_pointer.base; - if (status == CAIRO_STATUS_FILE_NOT_FOUND) - return &cairo_pattern_nil_file_not_found.base; - if (status == CAIRO_STATUS_READ_ERROR) - return &cairo_pattern_nil_read_error.base; - return &cairo_pattern_nil.base; -} - /** * _cairo_pattern_set_error: * @pattern: a pattern @@ -293,6 +259,20 @@ _cairo_pattern_create_solid (const cairo_color_t *color) return &pattern->base; } +static const cairo_pattern_t * +_cairo_pattern_create_for_status (cairo_status_t status) +{ + cairo_pattern_t *pattern; + + pattern = _cairo_pattern_create_solid (_cairo_stock_color (CAIRO_STOCK_BLACK)); + if (cairo_pattern_status (pattern)) + return pattern; + + _cairo_pattern_set_error (pattern, status); + + return pattern; +} + /** * cairo_pattern_create_rgb: * @red: red component of the color @@ -397,10 +377,10 @@ cairo_pattern_create_for_surface (cairo_surface_t *surface) cairo_surface_pattern_t *pattern; if (surface == NULL) - return (cairo_pattern_t*) _cairo_pattern_nil_for_status (CAIRO_STATUS_NULL_POINTER); + return (cairo_pattern_t*) &cairo_pattern_nil_null_pointer; if (surface->status) - return (cairo_pattern_t*) _cairo_pattern_nil_for_status (surface->status); + return (cairo_pattern_t*) _cairo_pattern_create_for_status (surface->status); pattern = malloc (sizeof (cairo_surface_pattern_t)); if (pattern == NULL) { |