[cairo-commit] 3 commits - src/cairo.c src/cairo-surface-fallback.c test/copy-path.c
Chris Wilson
ickle at kemper.freedesktop.org
Fri May 7 14:36:50 PDT 2010
src/cairo-surface-fallback.c | 7 ++--
src/cairo.c | 24 ++++++++++++++++
test/copy-path.c | 61 ++++++++++++++++++++++++++-----------------
3 files changed, 65 insertions(+), 27 deletions(-)
New commits:
commit 81f4dd65a32efae645b826b84e8382f7bf7a9b2d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri May 7 22:35:18 2010 +0100
cairo: Special case cairo_t with NULL_POINTER
Avoid allocation for the potential user error of attempting to use
cairo_create(NULL).
diff --git a/src/cairo.c b/src/cairo.c
index b417f55..0070f98 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -70,6 +70,26 @@ static const cairo_t _cairo_nil = {
}}
};
+static const cairo_t _cairo_nil__null_pointer = {
+ CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */
+ CAIRO_STATUS_NULL_POINTER, /* status */
+ { 0, 0, 0, NULL }, /* user_data */
+ NULL, /* gstate */
+ {{ 0 }, { 0 }}, /* gstate_tail */
+ NULL, /* gstate_freelist */
+ {{ /* path */
+ { 0, 0 }, /* last_move_point */
+ { 0, 0 }, /* current point */
+ FALSE, /* has_current_point */
+ FALSE, /* has_last_move_point */
+ FALSE, /* has_curve_to */
+ FALSE, /* is_box */
+ FALSE, /* maybe_fill_region */
+ TRUE, /* is_empty_fill */
+ { {0, 0}, {0, 0}}, /* extents */
+ {{{NULL,NULL}}} /* link */
+ }}
+};
#include <assert.h>
/**
@@ -231,7 +251,9 @@ cairo_create (cairo_surface_t *target)
cairo_status_t status;
/* special case OOM in order to avoid another allocation */
- if (target && target->status == CAIRO_STATUS_NO_MEMORY)
+ if (target == NULL)
+ return (cairo_t *) &_cairo_nil__null_pointer;
+ if (target->status == CAIRO_STATUS_NO_MEMORY)
return (cairo_t *) &_cairo_nil;
cr = _context_get ();
commit a61570a55e70040ffcf8ff3cb2c7943e71a5e2a0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri May 7 22:18:52 2010 +0100
test/copy-path: memfault status checks.
diff --git a/test/copy-path.c b/test/copy-path.c
index 0ea5b4b..c5f9398 100644
--- a/test/copy-path.c
+++ b/test/copy-path.c
@@ -100,25 +100,25 @@ draw (cairo_t *cr, int width, int height)
* propagate the error. */
cr_error = cairo_create (NULL);
path = cairo_copy_path (cr_error);
- if (path->status == CAIRO_STATUS_SUCCESS ||
- path->status != cairo_status (cr_error)) {
+ if (path->status != CAIRO_STATUS_NULL_POINTER) {
cairo_test_log (ctx,
"Error: cairo_copy_path returned status of %s rather than propagating %s\n",
cairo_status_to_string (path->status),
- cairo_status_to_string (cairo_status (cr_error)));
+ cairo_status_to_string (CAIRO_STATUS_NULL_POINTER));
cairo_path_destroy (path);
+ cairo_destroy (cr_error);
return CAIRO_TEST_FAILURE;
}
cairo_path_destroy (path);
path = cairo_copy_path_flat (cr_error);
- if (path->status == CAIRO_STATUS_SUCCESS ||
- path->status != cairo_status (cr_error)) {
+ if (path->status != CAIRO_STATUS_NULL_POINTER) {
cairo_test_log (ctx,
"Error: cairo_copy_path_flat returned status of %s rather than propagating %s\n",
cairo_status_to_string (path->status),
- cairo_status_to_string (cairo_status (cr_error)));
+ cairo_status_to_string (CAIRO_STATUS_NULL_POINTER));
cairo_path_destroy (path);
+ cairo_destroy (cr_error);
return CAIRO_TEST_FAILURE;
}
cairo_path_destroy (path);
@@ -129,11 +129,12 @@ draw (cairo_t *cr, int width, int height)
cairo_new_path (cr);
path = cairo_copy_path (cr);
if (path->status != CAIRO_STATUS_SUCCESS) {
+ cairo_status_t status = path->status;
cairo_test_log (ctx,
"Error: cairo_copy_path returned status of %s\n",
- cairo_status_to_string (path->status));
+ cairo_status_to_string (status));
cairo_path_destroy (path);
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, status);
}
if (path->num_data != 0) {
cairo_test_log (ctx,
@@ -148,7 +149,7 @@ draw (cairo_t *cr, int width, int height)
cairo_test_log (ctx,
"Error: cairo_append_path failed with a copy of an empty path, returned status of %s\n",
cairo_status_to_string (cairo_status (cr)));
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, cairo_status (cr));
}
/* We draw in the default black, so paint white first. */
@@ -206,38 +207,52 @@ preamble (cairo_test_context_t *ctx)
cairo_status_t status;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
+ status = cairo_surface_status (surface);
+ if (status) {
+ cairo_surface_destroy (surface);
+ return cairo_test_status_from_status (ctx, status);
+ }
/* Test a few error cases for cairo_append_path_data */
- cr = cairo_create (surface);
+#define CAIRO_CREATE() do {\
+ cr = cairo_create (surface); \
+ status = cairo_status (cr); \
+ if (status) { \
+ cairo_destroy (cr); \
+ cairo_surface_destroy (surface); \
+ return cairo_test_status_from_status (ctx, status); \
+ } \
+} while (0)
+ CAIRO_CREATE ();
cairo_append_path (cr, NULL);
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_NULL_POINTER) {
cairo_surface_destroy (surface);
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, status);
}
- cr = cairo_create (surface);
+ CAIRO_CREATE ();
path.status = -1;
cairo_append_path (cr, &path);
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_INVALID_STATUS) {
cairo_surface_destroy (surface);
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, status);
}
- cr = cairo_create (surface);
+ CAIRO_CREATE ();
path.status = CAIRO_STATUS_NO_MEMORY;
cairo_append_path (cr, &path);
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_NO_MEMORY) {
cairo_surface_destroy (surface);
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, status);
}
- cr = cairo_create (surface);
+ CAIRO_CREATE ();
path.data = NULL;
path.num_data = 0;
path.status = CAIRO_STATUS_SUCCESS;
@@ -246,10 +261,10 @@ preamble (cairo_test_context_t *ctx)
cairo_destroy (cr);
if (status != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy (surface);
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, status);
}
- cr = cairo_create (surface);
+ CAIRO_CREATE ();
path.data = NULL;
path.num_data = 1;
path.status = CAIRO_STATUS_SUCCESS;
@@ -258,10 +273,10 @@ preamble (cairo_test_context_t *ctx)
cairo_destroy (cr);
if (status != CAIRO_STATUS_NULL_POINTER) {
cairo_surface_destroy (surface);
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, status);
}
- cr = cairo_create (surface);
+ CAIRO_CREATE ();
/* Intentionally insert bogus header.length value (otherwise would be 2) */
data.header.type = CAIRO_PATH_MOVE_TO;
data.header.length = 1;
@@ -272,18 +287,18 @@ preamble (cairo_test_context_t *ctx)
cairo_destroy (cr);
if (status != CAIRO_STATUS_INVALID_PATH_DATA) {
cairo_surface_destroy (surface);
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, status);
}
/* And test the degnerate case */
- cr = cairo_create (surface);
+ CAIRO_CREATE ();
path.num_data = 0;
cairo_append_path (cr, &path);
status = cairo_status (cr);
cairo_destroy (cr);
if (status != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy (surface);
- return CAIRO_TEST_FAILURE;
+ return cairo_test_status_from_status (ctx, status);
}
cairo_surface_destroy (surface);
commit e6180d1d5e29a91f1bfc20956bb017ab74fb8b8e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri May 7 22:18:10 2010 +0100
surface-fallback: Only destroy the clip after it has been initialized.
More memfault detected error path errors.
diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c
index 25d03e6..07ab60d 100644
--- a/src/cairo-surface-fallback.c
+++ b/src/cairo-surface-fallback.c
@@ -298,7 +298,7 @@ _clip_and_composite_combine (cairo_clip_t *clip,
extents->width, extents->height,
NULL);
if (unlikely (status))
- goto CLEANUP_SURFACE;
+ goto CLEANUP_CLIP;
/* Punch the clip out of the destination */
status = _cairo_surface_composite (CAIRO_OPERATOR_DEST_OUT,
@@ -310,7 +310,7 @@ _clip_and_composite_combine (cairo_clip_t *clip,
extents->width, extents->height,
NULL);
if (unlikely (status))
- goto CLEANUP_SURFACE;
+ goto CLEANUP_CLIP;
/* Now add the two results together */
_cairo_pattern_init_for_surface (&pattern, intermediate);
@@ -323,8 +323,9 @@ _clip_and_composite_combine (cairo_clip_t *clip,
NULL);
_cairo_pattern_fini (&pattern.base);
- CLEANUP_SURFACE:
+ CLEANUP_CLIP:
_cairo_pattern_fini (&clip_pattern.base);
+ CLEANUP_SURFACE:
cairo_surface_destroy (intermediate);
return status;
More information about the cairo-commit
mailing list