[cairo-commit] 8 commits - src/cairo.h src/cairo-misc.c src/cairo-region.c src/cairo-spans.c src/cairo-surface.c src/cairo-traps.c test/create-from-png.c

Chris Wilson ickle at kemper.freedesktop.org
Mon Mar 30 05:42:18 PDT 2009


 src/cairo-misc.c       |    5 
 src/cairo-region.c     |  268 ++++++++++++++++++++++++++-----------------------
 src/cairo-spans.c      |    2 
 src/cairo-surface.c    |   22 ++--
 src/cairo-traps.c      |   23 +---
 src/cairo.h            |    4 
 test/create-from-png.c |  164 ++++++++++++++++++++---------
 7 files changed, 286 insertions(+), 202 deletions(-)

New commits:
commit aee71e2063b1d6d23cd8dcef7789c9cf106af32a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Mar 30 13:41:00 2009 +0100

    [test] Memfault checks.
    
    Don't assume an error means the test failed, check for injected allocation
    errors.

diff --git a/test/create-from-png.c b/test/create-from-png.c
index d9d2e54..585fac2 100644
--- a/test/create-from-png.c
+++ b/test/create-from-png.c
@@ -54,13 +54,19 @@ draw (cairo_t *cr, int width, int height)
 
     surface = cairo_image_surface_create_from_png (filename);
     if (cairo_surface_status (surface)) {
-	cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
-			filename,
-			cairo_status_to_string (cairo_surface_status (surface)));
+	cairo_test_status_t result;
+
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
+			    filename,
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
+
 	free (filename);
-	return CAIRO_TEST_FAILURE;
+	return result;
     }
-    free (filename);
 
     cairo_set_source_surface (cr, surface, 0, 0);
     cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
@@ -68,6 +74,7 @@ draw (cairo_t *cr, int width, int height)
 
     cairo_surface_destroy (surface);
 
+    free (filename);
     return CAIRO_TEST_SUCCESS;
 }
 
@@ -81,27 +88,42 @@ preamble (cairo_test_context_t *ctx)
 
     surface = cairo_image_surface_create_from_png ("___THIS_FILE_DOES_NOT_EXIST___");
     if (cairo_surface_status (surface) != CAIRO_STATUS_FILE_NOT_FOUND) {
-	cairo_test_log (ctx, "Error: expected \"file not found\", but got: %s\n",
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error: expected \"file not found\", but got: %s\n",
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     }
     cairo_surface_destroy (surface);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     surface = cairo_image_surface_create_from_png_stream (no_memory_error, NULL);
     if (cairo_surface_status (surface) != CAIRO_STATUS_NO_MEMORY) {
-	cairo_test_log (ctx, "Error: expected \"out of memory\", but got: %s\n",
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error: expected \"out of memory\", but got: %s\n",
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     }
     cairo_surface_destroy (surface);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     surface = cairo_image_surface_create_from_png_stream (read_error, NULL);
     if (cairo_surface_status (surface) != CAIRO_STATUS_READ_ERROR) {
-	cairo_test_log (ctx, "Error: expected \"read error\", but got: %s\n",
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error: expected \"read error\", but got: %s\n",
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     }
     cairo_surface_destroy (surface);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     /* cheekily test error propagation from the user write funcs as well ... */
     xasprintf (&filename, "%s/%s", ctx->srcdir,
@@ -109,48 +131,63 @@ preamble (cairo_test_context_t *ctx)
 
     surface = cairo_image_surface_create_from_png (filename);
     if (cairo_surface_status (surface)) {
-	cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
-			filename,
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
+			    filename,
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     } else {
 	status = cairo_surface_write_to_png_stream (surface,
 					       (cairo_write_func_t) no_memory_error,
 					       NULL);
 	if (status != CAIRO_STATUS_NO_MEMORY) {
-	    cairo_test_log (ctx, "Error: expected \"out of memory\", but got: %s\n",
-			    cairo_status_to_string (status));
-	    result = CAIRO_TEST_FAILURE;
+	    result = cairo_test_status_from_status (ctx, status);
+	    if (result == CAIRO_TEST_FAILURE) {
+		cairo_test_log (ctx, "Error: expected \"out of memory\", but got: %s\n",
+				cairo_status_to_string (status));
+	    }
 	}
 
 	status = cairo_surface_write_to_png_stream (surface,
 						    (cairo_write_func_t) read_error,
 						    NULL);
 	if (status != CAIRO_STATUS_READ_ERROR) {
-	    cairo_test_log (ctx, "Error: expected \"read error\", but got: %s\n",
-			    cairo_status_to_string (status));
-	    result = CAIRO_TEST_FAILURE;
+	    result = cairo_test_status_from_status (ctx, status);
+	    if (result == CAIRO_TEST_FAILURE) {
+		cairo_test_log (ctx, "Error: expected \"read error\", but got: %s\n",
+				cairo_status_to_string (status));
+	    }
 	}
 
 	/* and check that error has not propagated to the surface */
 	if (cairo_surface_status (surface)) {
-	    cairo_test_log (ctx, "Error: user write error propagated to surface: %s",
-			    cairo_status_to_string (cairo_surface_status (surface)));
-	    result = CAIRO_TEST_FAILURE;
+	    result = cairo_test_status_from_status (ctx,
+						    cairo_surface_status (surface));
+	    if (result == CAIRO_TEST_FAILURE) {
+		cairo_test_log (ctx, "Error: user write error propagated to surface: %s",
+				cairo_status_to_string (cairo_surface_status (surface)));
+	    }
 	}
     }
     cairo_surface_destroy (surface);
     free (filename);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     /* check that loading alpha/opaque PNGs generate the correct surfaces */
     xasprintf (&filename, "%s/%s", ctx->srcdir,
 	       "create-from-png.alpha.ref.png");
     surface = cairo_image_surface_create_from_png (filename);
     if (cairo_surface_status (surface)) {
-	cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
-			filename,
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
+			    filename,
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     } else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
 	cairo_test_log (ctx, "Error reading PNG image %s: did not create an ARGB32 image\n",
 			filename);
@@ -158,15 +195,20 @@ preamble (cairo_test_context_t *ctx)
     }
     free (filename);
     cairo_surface_destroy (surface);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     xasprintf (&filename, "%s/%s", ctx->srcdir,
 	       "create-from-png.ref.png");
     surface = cairo_image_surface_create_from_png (filename);
     if (cairo_surface_status (surface)) {
-	cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
-			filename,
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
+			    filename,
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     } else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
 	cairo_test_log (ctx, "Error reading PNG image %s: did not create an RGB24 image\n",
 			filename);
@@ -174,16 +216,21 @@ preamble (cairo_test_context_t *ctx)
     }
     free (filename);
     cairo_surface_destroy (surface);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     /* check paletted PNGs */
     xasprintf (&filename, "%s/%s", ctx->srcdir,
 	       "create-from-png.indexed-alpha.ref.png");
     surface = cairo_image_surface_create_from_png (filename);
     if (cairo_surface_status (surface)) {
-	cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
-			filename,
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
+			    filename,
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     } else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
 	cairo_test_log (ctx, "Error reading PNG image %s: did not create an ARGB32 image\n",
 			filename);
@@ -191,15 +238,20 @@ preamble (cairo_test_context_t *ctx)
     }
     free (filename);
     cairo_surface_destroy (surface);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     xasprintf (&filename, "%s/%s", ctx->srcdir,
 	       "create-from-png.indexed.ref.png");
     surface = cairo_image_surface_create_from_png (filename);
     if (cairo_surface_status (surface)) {
-	cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
-			filename,
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
+			    filename,
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     } else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
 	cairo_test_log (ctx, "Error reading PNG image %s: did not create an RGB24 image\n",
 			filename);
@@ -207,16 +259,21 @@ preamble (cairo_test_context_t *ctx)
     }
     free (filename);
     cairo_surface_destroy (surface);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     /* check grayscale PNGs */
     xasprintf (&filename, "%s/%s", ctx->srcdir,
 	       "create-from-png.gray-alpha.ref.png");
     surface = cairo_image_surface_create_from_png (filename);
     if (cairo_surface_status (surface)) {
-	cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
-			filename,
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
+			    filename,
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     } else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) {
 	cairo_test_log (ctx, "Error reading PNG image %s: did not create an ARGB32 image\n",
 			filename);
@@ -224,15 +281,20 @@ preamble (cairo_test_context_t *ctx)
     }
     free (filename);
     cairo_surface_destroy (surface);
+    if (result != CAIRO_TEST_SUCCESS)
+	return result;
 
     xasprintf (&filename, "%s/%s", ctx->srcdir,
 	       "create-from-png.gray.ref.png");
     surface = cairo_image_surface_create_from_png (filename);
     if (cairo_surface_status (surface)) {
-	cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
-			filename,
-			cairo_status_to_string (cairo_surface_status (surface)));
-	result = CAIRO_TEST_FAILURE;
+	result = cairo_test_status_from_status (ctx,
+						cairo_surface_status (surface));
+	if (result == CAIRO_TEST_FAILURE) {
+	    cairo_test_log (ctx, "Error reading PNG image %s: %s\n",
+			    filename,
+			    cairo_status_to_string (cairo_surface_status (surface)));
+	}
     } else if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) {
 	cairo_test_log (ctx, "Error reading PNG image %s: did not create an RGB24 image\n",
 			filename);
commit ea6197c2f5f04d5e8e8035a330c5199b37beb702
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Mar 30 10:54:26 2009 +0100

    [surface] Propagate region allocation failure.
    
    Propagate the error status from failing to allocate the region.

diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 3df8c7a..a4a7084 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -2678,12 +2678,11 @@ _cairo_surface_composite_fixup_unbounded_internal (cairo_surface_t         *dst,
 						   unsigned int		    height)
 {
     cairo_rectangle_int_t dst_rectangle;
-    cairo_rectangle_int_t drawn_rectangle;
-    cairo_region_t *clear_region = NULL;
+    cairo_region_t *clear_region;
     cairo_status_t status;
 
-    /* The area that was drawn is the area in the destination rectangle but not within
-     * the source or the mask.
+    /* The area that was drawn is the area in the destination rectangle but
+     * not within the source or the mask.
      */
     dst_rectangle.x = dst_x;
     dst_rectangle.y = dst_y;
@@ -2691,22 +2690,22 @@ _cairo_surface_composite_fixup_unbounded_internal (cairo_surface_t         *dst,
     dst_rectangle.height = height;
 
     clear_region = cairo_region_create_rectangle (&dst_rectangle);
-
-    drawn_rectangle = dst_rectangle;
+    status = clear_region->status;
+    if (unlikely (status))
+        goto CLEANUP_REGIONS;
 
     if (src_rectangle) {
-        if (! _cairo_rectangle_intersect (&drawn_rectangle, src_rectangle))
+        if (! _cairo_rectangle_intersect (&dst_rectangle, src_rectangle))
 	    goto EMPTY;
     }
 
     if (mask_rectangle) {
-        if (! _cairo_rectangle_intersect (&drawn_rectangle, mask_rectangle))
+        if (! _cairo_rectangle_intersect (&dst_rectangle, mask_rectangle))
 	    goto EMPTY;
     }
 
-    /* Now compute the area that is in dst_rectangle but not in drawn_rectangle
-     */
-    status = cairo_region_subtract_rectangle (clear_region, &drawn_rectangle);
+    /* Now compute the area that is in dst but not drawn */
+    status = cairo_region_subtract_rectangle (clear_region, &dst_rectangle);
     if (unlikely (status))
         goto CLEANUP_REGIONS;
 
commit c35d226f7d3654b312e18068b8ccb47a51002a39
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Mar 30 10:46:37 2009 +0100

    [traps] Propagate allocation failure.
    
    Report failure to allocation region.

diff --git a/src/cairo-traps.c b/src/cairo-traps.c
index d91e0d8..faf7722 100644
--- a/src/cairo-traps.c
+++ b/src/cairo-traps.c
@@ -610,12 +610,11 @@ cairo_int_status_t
 _cairo_traps_extract_region (const cairo_traps_t  *traps,
 			     cairo_region_t      **region)
 {
-    cairo_int_status_t status = CAIRO_STATUS_SUCCESS;
+    cairo_int_status_t status;
     cairo_region_t *r;
     int i;
 
-    for (i = 0; i < traps->num_traps; i++)
-    {
+    for (i = 0; i < traps->num_traps; i++) {
 	if (traps->traps[i].left.p1.x != traps->traps[i].left.p2.x   ||
 	    traps->traps[i].right.p1.x != traps->traps[i].right.p2.x ||
 	    ! _cairo_fixed_is_integer (traps->traps[i].top)          ||
@@ -628,11 +627,12 @@ _cairo_traps_extract_region (const cairo_traps_t  *traps,
     }
 
     r = cairo_region_create ();
-    
-    for (i = 0; i < traps->num_traps; i++)
-    {
+    if (unlikely (r->status))
+	return r->status;
+
+    for (i = 0; i < traps->num_traps; i++) {
 	cairo_rectangle_int_t rect;
-	
+
 	int x1 = _cairo_fixed_integer_part (traps->traps[i].left.p1.x);
 	int y1 = _cairo_fixed_integer_part (traps->traps[i].top);
 	int x2 = _cairo_fixed_integer_part (traps->traps[i].right.p1.x);
@@ -650,17 +650,14 @@ _cairo_traps_extract_region (const cairo_traps_t  *traps,
 	rect.height = y2 - y1;
 
 	status = cairo_region_union_rectangle (r, &rect);
-	if (unlikely (status))
-	{
+	if (unlikely (status)) {
 	    cairo_region_destroy (r);
-	    r = NULL;
-	    break;
+	    return status;
 	}
     }
 
     *region = r;
-    
-    return status;
+    return CAIRO_STATUS_SUCCESS;
 }
 
 /* moves trap points such that they become the actual corners of the trapezoid */
commit e238d10b30e18084bf07eb1643fdf48ef35467ab
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Mar 30 10:22:18 2009 +0100

    [region] Use const cairo_rectangle_int_t consistently.
    
    Add the const declaration to a couple of functions.

diff --git a/src/cairo-region.c b/src/cairo-region.c
index 2ec3941..3f2b978 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -121,7 +121,7 @@ slim_hidden_def (cairo_region_create);
  * Since: 1.10
  **/
 cairo_region_t *
-cairo_region_create_rectangle (cairo_rectangle_int_t *rectangle)
+cairo_region_create_rectangle (const cairo_rectangle_int_t *rectangle)
 {
     cairo_region_t *region;
 
@@ -335,7 +335,7 @@ slim_hidden_def (cairo_region_subtract);
  **/
 cairo_status_t
 cairo_region_subtract_rectangle (cairo_region_t *dst,
-				 cairo_rectangle_int_t *rectangle)
+				 const cairo_rectangle_int_t *rectangle)
 {
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
     pixman_region32_t region;
diff --git a/src/cairo.h b/src/cairo.h
index 025ca6c..917d364 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -2368,7 +2368,7 @@ cairo_public cairo_region_t *
 cairo_region_create (void);
 
 cairo_public cairo_region_t *
-cairo_region_create_rectangle (cairo_rectangle_int_t *rectangle);
+cairo_region_create_rectangle (const cairo_rectangle_int_t *rectangle);
 
 cairo_public cairo_region_t *
 cairo_region_copy (cairo_region_t *original);
@@ -2409,7 +2409,7 @@ cairo_region_subtract (cairo_region_t *dst, cairo_region_t *other);
 
 cairo_public cairo_status_t
 cairo_region_subtract_rectangle (cairo_region_t *dst,
-				 cairo_rectangle_int_t *rectangle);
+				 const cairo_rectangle_int_t *rectangle);
 
 cairo_public cairo_status_t
 cairo_region_intersect (cairo_region_t *dst, cairo_region_t *other);
commit de1612bdd767ca37e01938f8e41d9699531a49d9
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Mar 30 10:17:49 2009 +0100

    [region] Use _cairo_status_is_error
    
    Replace the open-coded version with the more readable macro.

diff --git a/src/cairo-region.c b/src/cairo-region.c
index e61e441..2ec3941 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -66,7 +66,7 @@ static cairo_status_t
 _cairo_region_set_error (cairo_region_t *region,
 			cairo_status_t status)
 {
-    if (status == CAIRO_STATUS_SUCCESS || status >= CAIRO_INT_STATUS_UNSUPPORTED)
+    if (! _cairo_status_is_error (status))
 	return status;
 
     /* Don't overwrite an existing error. This preserves the first
commit f027405429d0133b2840c4b82bc553355fa5f3d2
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Mar 30 10:12:41 2009 +0100

    [region] Add leading underscore to private _cairo_region_set_error()
    
    Differentiate the private _cairo_region_set_error() function by using a
    leading underscore.

diff --git a/src/cairo-region.c b/src/cairo-region.c
index 2eab334..e61e441 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -43,7 +43,7 @@ static const cairo_region_t _cairo_region_nil = {
 };
 
 /**
- * cairo_region_set_error:
+ * _cairo_region_set_error:
  * @region: a region
  * @status: a status value indicating an error
  *
@@ -52,7 +52,7 @@ static const cairo_region_t _cairo_region_nil = {
  * status values.
  *
  * All assignments of an error status to region->status should happen
- * through cairo_region_set_error(). Note that due to the nature of
+ * through _cairo_region_set_error(). Note that due to the nature of
  * the atomic operation, it is not safe to call this function on the
  * nil objects.
  *
@@ -63,7 +63,7 @@ static const cairo_region_t _cairo_region_nil = {
  * Return value: the error status.
  **/
 static cairo_status_t
-cairo_region_set_error (cairo_region_t *region,
+_cairo_region_set_error (cairo_region_t *region,
 			cairo_status_t status)
 {
     if (status == CAIRO_STATUS_SUCCESS || status >= CAIRO_INT_STATUS_UNSUPPORTED)
@@ -313,10 +313,10 @@ cairo_region_subtract (cairo_region_t *dst, cairo_region_t *other)
 	return dst->status;
 
     if (other->status)
-	return cairo_region_set_error (dst, other->status);
+	return _cairo_region_set_error (dst, other->status);
 
     if (! pixman_region32_subtract (&dst->rgn, &dst->rgn, &other->rgn))
-	return cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
+	return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -348,7 +348,7 @@ cairo_region_subtract_rectangle (cairo_region_t *dst,
 			       rectangle->width, rectangle->height);
 
     if (! pixman_region32_subtract (&dst->rgn, &dst->rgn, &region))
-	status = cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
+	status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     pixman_region32_fini (&region);
 
@@ -374,10 +374,10 @@ cairo_region_intersect (cairo_region_t *dst, cairo_region_t *other)
 	return dst->status;
 
     if (other->status)
-	return cairo_region_set_error (dst, other->status);
+	return _cairo_region_set_error (dst, other->status);
 
     if (! pixman_region32_intersect (&dst->rgn, &dst->rgn, &other->rgn))
-	return cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
+	return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -410,7 +410,7 @@ cairo_region_intersect_rectangle (cairo_region_t *dst,
 			       rectangle->width, rectangle->height);
 
     if (! pixman_region32_intersect (&dst->rgn, &dst->rgn, &region))
-	status = cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
+	status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     pixman_region32_fini (&region);
 
@@ -437,10 +437,10 @@ cairo_region_union (cairo_region_t *dst,
 	return dst->status;
 
     if (other->status)
-	return cairo_region_set_error (dst, other->status);
+	return _cairo_region_set_error (dst, other->status);
 
     if (! pixman_region32_union (&dst->rgn, &dst->rgn, &other->rgn))
-	return cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
+	return _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -472,7 +472,7 @@ cairo_region_union_rectangle (cairo_region_t *dst,
 			       rectangle->width, rectangle->height);
 
     if (! pixman_region32_union (&dst->rgn, &dst->rgn, &region))
-	status = cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
+	status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     pixman_region32_fini (&region);
 
commit ed7188a471f73abcc4ca3e2a92685088134391c7
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Mar 30 10:07:48 2009 +0100

    [region] Add slim_hidden_def.
    
    Fixes for check-plt.sh (and a few adjacent whitespace).

diff --git a/src/cairo-region.c b/src/cairo-region.c
index e162321..2eab334 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -38,7 +38,7 @@
 
 #include "cairoint.h"
 
-const cairo_region_t _cairo_region_nil = {
+static const cairo_region_t _cairo_region_nil = {
     CAIRO_STATUS_NO_MEMORY,		/* status */
 };
 
@@ -80,22 +80,23 @@ cairo_region_set_error (cairo_region_t *region,
  * cairo_region_create:
  *
  * Allocates a new empty region object.
- * 
+ *
  * Return value: A newly allocated #cairo_region_t. Free with
  *   cairo_region_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_region_status().
- * 
+ *
  * Since: 1.10
  **/
 cairo_region_t *
 cairo_region_create (void)
 {
-    cairo_region_t *region = _cairo_malloc (sizeof (cairo_region_t));
+    cairo_region_t *region;
 
-    if (!region)
-	return (cairo_region_t *)&_cairo_region_nil;
+    region = _cairo_malloc (sizeof (cairo_region_t));
+    if (region == NULL)
+	return (cairo_region_t *) &_cairo_region_nil;
 
     region->status = CAIRO_STATUS_SUCCESS;
 
@@ -103,101 +104,105 @@ cairo_region_create (void)
 
     return region;
 }
+slim_hidden_def (cairo_region_create);
 
 /**
  * cairo_region_create_rectangle:
  * @rectangle: a #cairo_rectangle_int_t
  *
  * Allocates a new region object containing @rectangle.
- * 
+ *
  * Return value: A newly allocated #cairo_region_t. Free with
  *   cairo_region_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_region_status().
- * 
+ *
  * Since: 1.10
  **/
 cairo_region_t *
 cairo_region_create_rectangle (cairo_rectangle_int_t *rectangle)
 {
-    cairo_region_t *region = _cairo_malloc (sizeof (cairo_region_t));
+    cairo_region_t *region;
+
+    region = _cairo_malloc (sizeof (cairo_region_t));
+    if (region == NULL)
+	return (cairo_region_t *) &_cairo_region_nil;
 
-    if (!region)
-	return (cairo_region_t *)&_cairo_region_nil;
-    
     region->status = CAIRO_STATUS_SUCCESS;
-    
+
     pixman_region32_init_rect (&region->rgn,
 			       rectangle->x, rectangle->y,
 			       rectangle->width, rectangle->height);
 
     return region;
 }
+slim_hidden_def (cairo_region_create_rectangle);
 
 /**
  * cairo_region_copy:
  * @original: a #cairo_region_t
- * 
+ *
  * Allocates a new region object copying the area from @original.
- * 
+ *
  * Return value: A newly allocated #cairo_region_t. Free with
  *   cairo_region_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_region_status().
- * 
+ *
  * Since: 1.10
  **/
 cairo_region_t *
 cairo_region_copy (cairo_region_t *original)
 {
     cairo_region_t *copy;
-    
+
     if (original->status)
-	return (cairo_region_t *)&_cairo_region_nil;
+	return (cairo_region_t *) &_cairo_region_nil;
 
     copy = cairo_region_create ();
-    if (!copy)
-	return (cairo_region_t *)&_cairo_region_nil;
+    if (copy->status)
+	return copy;
 
-    if (!pixman_region32_copy (&copy->rgn, &original->rgn)) {
+    if (! pixman_region32_copy (&copy->rgn, &original->rgn)) {
 	cairo_region_destroy (copy);
-
-	return (cairo_region_t *)&_cairo_region_nil;
+	return (cairo_region_t *) &_cairo_region_nil;
     }
 
     return copy;
 }
+slim_hidden_def (cairo_region_copy);
 
 /**
  * cairo_region_destroy:
  * @region: a #cairo_region_t
- * 
+ *
  * Destroys a #cairo_region_t object created with
  * cairo_region_create(), cairo_region_copy(), or
  * or cairo_region_create_rectangle().
- * 
+ *
  * Since: 1.10
  **/
 void
 cairo_region_destroy (cairo_region_t *region)
 {
-    if (region->status)
+    if (region == (cairo_region_t *) &_cairo_region_nil)
 	return;
-    
+
     pixman_region32_fini (&region->rgn);
     free (region);
 }
+slim_hidden_def (cairo_region_destroy);
 
 /**
  * cairo_region_num_rectangles:
  * @region: a #cairo_region_t
- * 
+ *
  * Returns the number of rectangles contained in @region.
- * 
+ *
  * Return value: The number of rectangles contained in @region.
- * 
+ *
  * Since: 1.10
  **/
 int
@@ -205,18 +210,19 @@ cairo_region_num_rectangles (cairo_region_t *region)
 {
     if (region->status)
 	return 0;
-    
+
     return pixman_region32_n_rects (&region->rgn);
 }
+slim_hidden_def (cairo_region_num_rectangles);
 
 /**
  * cairo_region_get_rectangle:
  * @region: a #cairo_region_t
  * @nth: a number indicating which rectangle should be returned
  * @rectangle: return location for a #cairo_rectangle_int_t
- * 
+ *
  * Stores the @nth rectangle from the region in @rectangle.
- * 
+ *
  * Since: 1.10
  **/
 void
@@ -226,9 +232,12 @@ cairo_region_get_rectangle (cairo_region_t *region,
 {
     pixman_box32_t *pbox;
 
-    if (region->status)
+    if (region->status) {
+	rectangle->x = rectangle->y = 0;
+	rectangle->width = rectangle->height = 0;
 	return;
-    
+    }
+
     pbox = pixman_region32_rectangles (&region->rgn, NULL) + nth;
 
     rectangle->x = pbox->x1;
@@ -236,6 +245,7 @@ cairo_region_get_rectangle (cairo_region_t *region,
     rectangle->width = pbox->x2 - pbox->x1;
     rectangle->height = pbox->y2 - pbox->y1;
 }
+slim_hidden_def (cairo_region_get_rectangle);
 
 /**
  * cairo_region_get_extents:
@@ -252,8 +262,11 @@ cairo_region_get_extents (cairo_region_t *region,
 {
     pixman_box32_t *pextents;
 
-    if (region->status || !extents)
+    if (region->status) {
+	extents->x = extents->y = 0;
+	extents->width = extents->height = 0;
 	return;
+    }
 
     pextents = pixman_region32_extents (&region->rgn);
 
@@ -262,16 +275,17 @@ cairo_region_get_extents (cairo_region_t *region,
     extents->width = pextents->x2 - pextents->x1;
     extents->height = pextents->y2 - pextents->y1;
 }
+slim_hidden_def (cairo_region_get_extents);
 
 /**
  * cairo_region_status:
  * @region: a #cairo_region_t
- * 
+ *
  * Checks whether an error has previous occured for this
  * region object.
- * 
+ *
  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
- * 
+ *
  * Since: 1.10
  **/
 cairo_status_t
@@ -279,16 +293,17 @@ cairo_region_status (cairo_region_t *region)
 {
     return region->status;
 }
+slim_hidden_def (cairo_region_status);
 
 /**
  * cairo_region_subtract:
- * @dst: a #cairo_region_t 
+ * @dst: a #cairo_region_t
  * @other: another #cairo_region_t
- * 
+ *
  * Subtracts @other from @dst and places the result in @dst
- * 
+ *
  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
- * 
+ *
  * Since: 1.10
  **/
 cairo_status_t
@@ -298,13 +313,14 @@ cairo_region_subtract (cairo_region_t *dst, cairo_region_t *other)
 	return dst->status;
 
     if (other->status)
-	return other->status;
-    
-    if (!pixman_region32_subtract (&dst->rgn, &dst->rgn, &other->rgn))
+	return cairo_region_set_error (dst, other->status);
+
+    if (! pixman_region32_subtract (&dst->rgn, &dst->rgn, &other->rgn))
 	return cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
 }
+slim_hidden_def (cairo_region_subtract);
 
 /**
  * cairo_region_subtract_rectangle:
@@ -312,9 +328,9 @@ cairo_region_subtract (cairo_region_t *dst, cairo_region_t *other)
  * @rectangle: a #cairo_rectangle_int_t
  *
  * Subtracts @rectangle from @dst and places the result in @dst
- * 
+ *
  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
- * 
+ *
  * Since: 1.10
  **/
 cairo_status_t
@@ -326,28 +342,29 @@ cairo_region_subtract_rectangle (cairo_region_t *dst,
 
     if (dst->status)
 	return dst->status;
-    
+
     pixman_region32_init_rect (&region,
 			       rectangle->x, rectangle->y,
 			       rectangle->width, rectangle->height);
 
-    if (!pixman_region32_subtract (&dst->rgn, &dst->rgn, &region))
+    if (! pixman_region32_subtract (&dst->rgn, &dst->rgn, &region))
 	status = cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     pixman_region32_fini (&region);
-    
+
     return status;
 }
+slim_hidden_def (cairo_region_subtract_rectangle);
 
 /**
  * cairo_region_intersect:
  * @dst: a #cairo_region_t
  * @other: another #cairo_region_t
- * 
+ *
  * Computes the intersection of @dst with @other and places the result in @dst
- * 
+ *
  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
- * 
+ *
  * Since: 1.10
  **/
 cairo_status_t
@@ -357,23 +374,25 @@ cairo_region_intersect (cairo_region_t *dst, cairo_region_t *other)
 	return dst->status;
 
     if (other->status)
-	return other->status;
+	return cairo_region_set_error (dst, other->status);
 
-    if (!pixman_region32_intersect (&dst->rgn, &dst->rgn, &other->rgn))
+    if (! pixman_region32_intersect (&dst->rgn, &dst->rgn, &other->rgn))
 	return cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
 }
+slim_hidden_def (cairo_region_intersect);
 
 /**
  * cairo_region_intersect_rectangle:
  * @dst: a #cairo_region_t
  * @rectangle: a #cairo_rectangle_int_t
- * 
- * Computes the intersection of @dst with @rectangle and places the result in @dst
- * 
+ *
+ * Computes the intersection of @dst with @rectangle and places the
+ * result in @dst
+ *
  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
- * 
+ *
  * Since: 1.10
  **/
 cairo_status_t
@@ -385,28 +404,29 @@ cairo_region_intersect_rectangle (cairo_region_t *dst,
 
     if (dst->status)
 	return dst->status;
-    
+
     pixman_region32_init_rect (&region,
 			       rectangle->x, rectangle->y,
 			       rectangle->width, rectangle->height);
 
-    if (!pixman_region32_intersect (&dst->rgn, &dst->rgn, &region))
+    if (! pixman_region32_intersect (&dst->rgn, &dst->rgn, &region))
 	status = cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     pixman_region32_fini (&region);
-    
+
     return status;
 }
+slim_hidden_def (cairo_region_intersect_rectangle);
 
 /**
  * cairo_region_union:
  * @dst: a #cairo_region_t
  * @other: another #cairo_region_t
- * 
+ *
  * Computes the union of @dst with @other and places the result in @dst
- * 
+ *
  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
- * 
+ *
  * Since: 1.10
  **/
 cairo_status_t
@@ -417,23 +437,24 @@ cairo_region_union (cairo_region_t *dst,
 	return dst->status;
 
     if (other->status)
-	return other->status;
+	return cairo_region_set_error (dst, other->status);
 
-    if (!pixman_region32_union (&dst->rgn, &dst->rgn, &other->rgn))
+    if (! pixman_region32_union (&dst->rgn, &dst->rgn, &other->rgn))
 	return cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     return CAIRO_STATUS_SUCCESS;
 }
+slim_hidden_def (cairo_region_union);
 
 /**
  * cairo_region_union_rectangle:
  * @dst: a #cairo_region_t
  * @rectangle: a #cairo_rectangle_int_t
- * 
+ *
  * Computes the union of @dst with @rectangle and places the result in @dst.
- * 
+ *
  * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
- * 
+ *
  * Since: 1.10
  **/
 cairo_status_t
@@ -443,26 +464,30 @@ cairo_region_union_rectangle (cairo_region_t *dst,
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
     pixman_region32_t region;
 
+    if (dst->status)
+	return dst->status;
+
     pixman_region32_init_rect (&region,
 			       rectangle->x, rectangle->y,
 			       rectangle->width, rectangle->height);
-    
-    if (!pixman_region32_union (&dst->rgn, &dst->rgn, &region))
+
+    if (! pixman_region32_union (&dst->rgn, &dst->rgn, &region))
 	status = cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
 
     pixman_region32_fini (&region);
-    
+
     return status;
 }
+slim_hidden_def (cairo_region_union_rectangle);
 
 /**
  * cairo_region_empty:
  * @region: a #cairo_region_t
- * 
+ *
  * Checks whether @region is empty.
- * 
+ *
  * Return value: %TRUE if @region is empty, %FALSE if it isn't.
- * 
+ *
  * Since: 1.10
  **/
 cairo_bool_t
@@ -470,18 +495,19 @@ cairo_region_empty (cairo_region_t *region)
 {
     if (region->status)
 	return TRUE;
-    
-    return !pixman_region32_not_empty (&region->rgn);
+
+    return ! pixman_region32_not_empty (&region->rgn);
 }
+slim_hidden_def (cairo_region_empty);
 
 /**
  * cairo_region_translate:
  * @region: a #cairo_region_t
  * @dx: Amount to translate in the x direction
  * @dy: Amount to translate in the y direction
- * 
+ *
  * Translates @region by (@dx, @dy).
- * 
+ *
  * Since: 1.10
  **/
 void
@@ -490,22 +516,24 @@ cairo_region_translate (cairo_region_t *region,
 {
     if (region->status)
 	return;
-    
+
     pixman_region32_translate (&region->rgn, dx, dy);
 }
+slim_hidden_def (cairo_region_translate);
 
 /**
  * cairo_region_contains_rectangle:
  * @region: a #cairo_region_t
  * @rectangle: a #cairo_rectangle_int_t
- * 
- * Checks whether @rectangle is inside, outside or partially contained in @region
- * 
+ *
+ * Checks whether @rectangle is inside, outside or partially contained
+ * in @region
+ *
  * Return value:
  *   %CAIRO_REGION_OVERLAP_IN if @rectangle is entirely inside @region,
  *   %CAIRO_REGION_OVERLAP_OUT if @rectangle is entirely outside @region, or
  *   %CAIRO_REGION_OVERLAP_PART if @rectangle is partially inside and partially outside @region.
- * 
+ *
  * Since: 1.10
  **/
 cairo_region_overlap_t
@@ -515,41 +543,34 @@ cairo_region_contains_rectangle (cairo_region_t *region,
     pixman_box32_t pbox;
     pixman_region_overlap_t poverlap;
 
-    if (!region->status)
-    {
-	pbox.x1 = rectangle->x;
-	pbox.y1 = rectangle->y;
-	pbox.x2 = rectangle->x + rectangle->width;
-	pbox.y2 = rectangle->y + rectangle->height;
-	
-	poverlap = pixman_region32_contains_rectangle (&region->rgn, &pbox);
-	
-	switch (poverlap)
-	{
-	case PIXMAN_REGION_OUT:
-	    return CAIRO_REGION_OVERLAP_OUT;
-	    
-	case PIXMAN_REGION_IN:
-	    return CAIRO_REGION_OVERLAP_IN;
-	    
-	case PIXMAN_REGION_PART:
-	    return CAIRO_REGION_OVERLAP_PART;
-	}
+    if (region->status)
+	return CAIRO_REGION_OVERLAP_OUT;
+
+    pbox.x1 = rectangle->x;
+    pbox.y1 = rectangle->y;
+    pbox.x2 = rectangle->x + rectangle->width;
+    pbox.y2 = rectangle->y + rectangle->height;
+
+    poverlap = pixman_region32_contains_rectangle (&region->rgn, &pbox);
+    switch (poverlap) {
+    default:
+    case PIXMAN_REGION_OUT:  return CAIRO_REGION_OVERLAP_OUT;
+    case PIXMAN_REGION_IN:   return CAIRO_REGION_OVERLAP_IN;
+    case PIXMAN_REGION_PART: return CAIRO_REGION_OVERLAP_PART;
     }
-
-    return CAIRO_REGION_OVERLAP_OUT;
 }
+slim_hidden_def (cairo_region_contains_rectangle);
 
 /**
  * cairo_region_contains_point:
  * @region: a #cairo_region_t
  * @x: the x coordinate of a point
  * @y: the y coordinate of a point
- * 
+ *
  * Checks whether (@x, @y) is contained in @region.
- * 
+ *
  * Return value: %TRUE if (@x, @y) is contained in @region, %FALSE if it is not.
- * 
+ *
  * Since: 1.10
  **/
 cairo_bool_t
@@ -561,3 +582,4 @@ cairo_region_contains_point (cairo_region_t *region,
 
     return pixman_region32_contains_point (&region->rgn, x, y, NULL);
 }
+slim_hidden_def (cairo_region_contains_point);
commit f31c6548f818e1d4e257d94d623705284bcc4274
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sat Mar 28 19:26:03 2009 +0000

    Silence compiler warnings for CAIRO_STATUS_LAST_STATUS
    
    Add ASSERT_NOT_REACHED (or similar) cases to the error handling switches
    to silence the compiler.

diff --git a/src/cairo-misc.c b/src/cairo-misc.c
index a6d4ffa..aaf849b 100644
--- a/src/cairo-misc.c
+++ b/src/cairo-misc.c
@@ -123,9 +123,10 @@ cairo_status_to_string (cairo_status_t status)
 	return "invalid value for an input #cairo_font_weight_t";
     case CAIRO_STATUS_INVALID_SIZE:
 	return "invalid value for the size of the input (surface, pattern, etc.)";
+    default:
+    case CAIRO_STATUS_LAST_STATUS:
+	return "<unknown error status>";
     }
-
-    return "<unknown error status>";
 }
 
 
diff --git a/src/cairo-spans.c b/src/cairo-spans.c
index b6ac2c5..625f83f 100644
--- a/src/cairo-spans.c
+++ b/src/cairo-spans.c
@@ -255,6 +255,7 @@ _cairo_scan_converter_create_in_error (cairo_status_t status)
 	}
     switch (status) {
     case CAIRO_STATUS_SUCCESS:
+    case CAIRO_STATUS_LAST_STATUS:
 	ASSERT_NOT_REACHED;
 	break;
     case CAIRO_STATUS_INVALID_RESTORE: RETURN_NIL;
@@ -359,6 +360,7 @@ _cairo_span_renderer_create_in_error (cairo_status_t status)
 	}
     switch (status) {
     case CAIRO_STATUS_SUCCESS:
+    case CAIRO_STATUS_LAST_STATUS:
 	ASSERT_NOT_REACHED;
 	break;
     case CAIRO_STATUS_INVALID_RESTORE: RETURN_NIL;
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 1c8445f..3df8c7a 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -2950,6 +2950,7 @@ _cairo_surface_create_in_error (cairo_status_t status)
     case CAIRO_STATUS_INVALID_STRIDE:
 	return (cairo_surface_t *) &_cairo_surface_nil_invalid_stride;
     case CAIRO_STATUS_SUCCESS:
+    case CAIRO_STATUS_LAST_STATUS:
 	ASSERT_NOT_REACHED;
 	/* fall-through */
     case CAIRO_STATUS_INVALID_RESTORE:


More information about the cairo-commit mailing list