[cairo-commit] src/cairo-path.c test/copy-path.c
Chris Wilson
ickle at kemper.freedesktop.org
Mon Oct 1 10:02:30 PDT 2007
src/cairo-path.c | 36 ++++++++++++++++++++++++------------
test/copy-path.c | 17 +++++++++++++++++
2 files changed, 41 insertions(+), 12 deletions(-)
New commits:
diff-tree b4f86638cc4b87bfaf10568ae9beb89626e26613 (from 042c382c094d1ea6f9a5a162d4d1d9ac83413233)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon Oct 1 17:59:57 2007 +0100
[cairo-path] Don't raise an error when attempting to create an empty path.
Generate a real empty path structure instead of returning
_cairo_path_nil, if we have been asked to create an empty path.
(Also add a couple of missing _cairo_error()s and an appropriate test
case.)
Spotted by Fred Kiefer.
diff --git a/src/cairo-path.c b/src/cairo-path.c
index 0740ebc..b1ef44e 100644
--- a/src/cairo-path.c
+++ b/src/cairo-path.c
@@ -352,8 +352,10 @@ _cairo_path_create_in_error (cairo_statu
return (cairo_path_t*) &_cairo_path_nil;
path = malloc (sizeof (cairo_path_t));
- if (path == NULL)
+ if (path == NULL) {
+ _cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_path_t*) &_cairo_path_nil;
+ }
path->num_data = 0;
path->data = NULL;
@@ -370,25 +372,34 @@ _cairo_path_create_internal (cairo_path_
cairo_path_t *path;
path = malloc (sizeof (cairo_path_t));
- if (path == NULL)
+ if (path == NULL) {
+ _cairo_error (CAIRO_STATUS_NO_MEMORY);
return (cairo_path_t*) &_cairo_path_nil;
+ }
path->num_data = _cairo_path_count (path, path_fixed,
_cairo_gstate_get_tolerance (gstate),
flatten);
- if (path->num_data <= 0) {
+ if (path->num_data < 0) {
free (path);
return (cairo_path_t*) &_cairo_path_nil;
}
- path->data = _cairo_malloc_ab (path->num_data, sizeof (cairo_path_data_t));
- if (path->data == NULL) {
- free (path);
- return (cairo_path_t*) &_cairo_path_nil;
- }
+ if (path->num_data) {
+ path->data = _cairo_malloc_ab (path->num_data,
+ sizeof (cairo_path_data_t));
+ if (path->data == NULL) {
+ free (path);
+ _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ return (cairo_path_t*) &_cairo_path_nil;
+ }
- path->status = _cairo_path_populate (path, path_fixed,
- gstate, flatten);
+ path->status = _cairo_path_populate (path, path_fixed,
+ gstate, flatten);
+ } else {
+ path->data = NULL;
+ path->status = CAIRO_STATUS_SUCCESS;
+ }
return path;
}
@@ -413,8 +424,9 @@ cairo_path_destroy (cairo_path_t *path)
if (path == NULL || path == &_cairo_path_nil)
return;
- free (path->data);
- path->num_data = 0;
+ if (path->data)
+ free (path->data);
+
free (path);
}
diff --git a/test/copy-path.c b/test/copy-path.c
index 142bfa5..256f461 100644
--- a/test/copy-path.c
+++ b/test/copy-path.c
@@ -125,6 +125,23 @@ draw (cairo_t *cr, int width, int height
cairo_path_destroy (path);
cairo_destroy (cr_error);
+
+ /* first check that we can copy an empty path */
+ cairo_new_path (cr);
+ path = cairo_copy_path (cr);
+ if (path->status != CAIRO_STATUS_SUCCESS) {
+ cairo_test_log ("Error: cairo_copy_path returned status of %s\n",
+ cairo_status_to_string (path->status));
+ cairo_path_destroy (path);
+ return CAIRO_TEST_FAILURE;
+ }
+ if (path->num_data != 0) {
+ cairo_test_log ("Error: cairo_copy_path did not copy an empty path, returned path contains %d elements\n",
+ path->num_data);
+ cairo_path_destroy (path);
+ return CAIRO_TEST_FAILURE;
+ }
+ cairo_path_destroy (path);
/* We draw in the default black, so paint white first. */
cairo_save (cr);
More information about the cairo-commit
mailing list