[cairo] Add attribute(warn_unused_result)

Chris Wilson chris at chris-wilson.co.uk
Mon Apr 2 03:56:11 PDT 2007


A couple more incorrect error paths.
-------------- next part --------------
>From 25c8a89c94d3593618a98d72d9cce15704904552 Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri, 30 Mar 2007 11:24:18 +0100
Subject: [PATCH] Do not overwrite cr->status

The idiom for cairo.c is to do
    cr->status = _cairo_op ();
    if (cr->status) _cairo_set_error (cr, cr->status);

Unfortunately a trivial mistake for a _cairo_op () is to call a cairo_op ()
and forget to check cr->status but return CAIRO_STATUS_SUCCESS which will
mask the earlier error.

Obviously this is a bug in the lower level but the impact can be reduced
by chaning cairo.c to use a local status variable for its return:
    cairo_status_t status = _cairo_op ();
    if (status) _cairo_set_error (cr, cr->status);
---
 src/cairo.c |  516 +++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 308 insertions(+), 208 deletions(-)

diff --git a/src/cairo.c b/src/cairo.c
index 56b799e..4455e8f 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -579,7 +579,7 @@ cairo_pop_group (cairo_t *cr)
 
     group_pattern = cairo_pattern_create_for_surface (group_surface);
     if (!group_pattern) {
-        cr->status = CAIRO_STATUS_NO_MEMORY;
+	_cairo_set_error (cr, CAIRO_STATUS_NO_MEMORY);
         goto done;
     }
 
@@ -646,12 +646,14 @@ slim_hidden_def(cairo_pop_group_to_source);
 void
 cairo_set_operator (cairo_t *cr, cairo_operator_t op)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_operator (cr->gstate, op);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_operator (cr->gstate, op);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_operator);
 
@@ -790,6 +792,8 @@ slim_hidden_def (cairo_set_source_surface);
 void
 cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
@@ -803,9 +807,9 @@ cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
 	return;
     }
 
-    cr->status = _cairo_gstate_set_source (cr->gstate, source);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_source (cr->gstate, source);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_set_source);
 
@@ -844,14 +848,16 @@ cairo_get_source (cairo_t *cr)
 void
 cairo_set_tolerance (cairo_t *cr, double tolerance)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
     _cairo_restrict_value (&tolerance, CAIRO_TOLERANCE_MINIMUM, tolerance);
 
-    cr->status = _cairo_gstate_set_tolerance (cr->gstate, tolerance);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_tolerance (cr->gstate, tolerance);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -870,12 +876,14 @@ cairo_set_tolerance (cairo_t *cr, double tolerance)
 void
 cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_antialias (cr->gstate, antialias);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_antialias (cr->gstate, antialias);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -892,12 +900,14 @@ cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
 void
 cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_fill_rule (cr->gstate, fill_rule);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_fill_rule (cr->gstate, fill_rule);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -929,14 +939,16 @@ cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
 void
 cairo_set_line_width (cairo_t *cr, double width)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
     _cairo_restrict_value (&width, 0.0, width);
 
-    cr->status = _cairo_gstate_set_line_width (cr->gstate, width);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_line_width (cr->gstate, width);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -956,12 +968,14 @@ cairo_set_line_width (cairo_t *cr, double width)
 void
 cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_line_cap (cr->gstate, line_cap);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_line_cap (cr->gstate, line_cap);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -981,12 +995,14 @@ cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
 void
 cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_line_join (cr->gstate, line_join);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_line_join (cr->gstate, line_join);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1027,13 +1043,15 @@ cairo_set_dash (cairo_t	     *cr,
 		int	      num_dashes,
 		double	      offset)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_dash (cr->gstate,
-					 dashes, num_dashes, offset);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_dash (cr->gstate,
+				     dashes, num_dashes, offset);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1101,12 +1119,14 @@ cairo_get_dash (cairo_t *cr,
 void
 cairo_set_miter_limit (cairo_t *cr, double limit)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_miter_limit (cr->gstate, limit);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_miter_limit (cr->gstate, limit);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1124,12 +1144,14 @@ cairo_set_miter_limit (cairo_t *cr, double limit)
 void
 cairo_translate (cairo_t *cr, double tx, double ty)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_translate (cr->gstate, tx, ty);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_translate (cr->gstate, tx, ty);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1146,12 +1168,14 @@ cairo_translate (cairo_t *cr, double tx, double ty)
 void
 cairo_scale (cairo_t *cr, double sx, double sy)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_scale (cr->gstate, sx, sy);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_scale (cr->gstate, sx, sy);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_scale);
 
@@ -1170,12 +1194,14 @@ slim_hidden_def (cairo_scale);
 void
 cairo_rotate (cairo_t *cr, double angle)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_rotate (cr->gstate, angle);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_rotate (cr->gstate, angle);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1191,12 +1217,14 @@ void
 cairo_transform (cairo_t	      *cr,
 		 const cairo_matrix_t *matrix)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_transform (cr->gstate, matrix);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_transform (cr->gstate, matrix);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1211,12 +1239,14 @@ void
 cairo_set_matrix (cairo_t	       *cr,
 		  const cairo_matrix_t *matrix)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_matrix (cr->gstate, matrix);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_matrix (cr->gstate, matrix);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1231,12 +1261,14 @@ cairo_set_matrix (cairo_t	       *cr,
 void
 cairo_identity_matrix (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_identity_matrix (cr->gstate);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_identity_matrix (cr->gstate);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1252,12 +1284,14 @@ cairo_identity_matrix (cairo_t *cr)
 void
 cairo_user_to_device (cairo_t *cr, double *x, double *y)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_user_to_device (cr->gstate, x, y);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_user_to_device (cr->gstate, x, y);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1274,12 +1308,14 @@ cairo_user_to_device (cairo_t *cr, double *x, double *y)
 void
 cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_user_to_device_distance (cr->gstate, dx, dy);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_user_to_device_distance (cr->gstate, dx, dy);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1295,12 +1331,14 @@ cairo_user_to_device_distance (cairo_t *cr, double *dx, double *dy)
 void
 cairo_device_to_user (cairo_t *cr, double *x, double *y)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_device_to_user (cr->gstate, x, y);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_device_to_user (cr->gstate, x, y);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1317,12 +1355,14 @@ cairo_device_to_user (cairo_t *cr, double *x, double *y)
 void
 cairo_device_to_user_distance (cairo_t *cr, double *dx, double *dy)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_device_to_user_distance (cr->gstate, dx, dy);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_device_to_user_distance (cr->gstate, dx, dy);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -1354,6 +1394,7 @@ slim_hidden_def(cairo_new_path);
 void
 cairo_move_to (cairo_t *cr, double x, double y)
 {
+    cairo_status_t status;
     cairo_fixed_t x_fixed, y_fixed;
 
     if (cr->status)
@@ -1363,9 +1404,9 @@ cairo_move_to (cairo_t *cr, double x, double y)
     x_fixed = _cairo_fixed_from_double (x);
     y_fixed = _cairo_fixed_from_double (y);
 
-    cr->status = _cairo_path_fixed_move_to (cr->path, x_fixed, y_fixed);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_path_fixed_move_to (cr->path, x_fixed, y_fixed);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_move_to);
 
@@ -1412,6 +1453,7 @@ cairo_new_sub_path (cairo_t *cr)
 void
 cairo_line_to (cairo_t *cr, double x, double y)
 {
+    cairo_status_t status;
     cairo_fixed_t x_fixed, y_fixed;
 
     if (cr->status)
@@ -1421,9 +1463,9 @@ cairo_line_to (cairo_t *cr, double x, double y)
     x_fixed = _cairo_fixed_from_double (x);
     y_fixed = _cairo_fixed_from_double (y);
 
-    cr->status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_path_fixed_line_to (cr->path, x_fixed, y_fixed);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_line_to);
 
@@ -1452,6 +1494,7 @@ cairo_curve_to (cairo_t *cr,
 		double x2, double y2,
 		double x3, double y3)
 {
+    cairo_status_t status;
     cairo_fixed_t x1_fixed, y1_fixed;
     cairo_fixed_t x2_fixed, y2_fixed;
     cairo_fixed_t x3_fixed, y3_fixed;
@@ -1472,12 +1515,12 @@ cairo_curve_to (cairo_t *cr,
     x3_fixed = _cairo_fixed_from_double (x3);
     y3_fixed = _cairo_fixed_from_double (y3);
 
-    cr->status = _cairo_path_fixed_curve_to (cr->path,
-					     x1_fixed, y1_fixed,
-					     x2_fixed, y2_fixed,
-					     x3_fixed, y3_fixed);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_path_fixed_curve_to (cr->path,
+					 x1_fixed, y1_fixed,
+					 x2_fixed, y2_fixed,
+					 x3_fixed, y3_fixed);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_curve_to);
 
@@ -1600,13 +1643,17 @@ cairo_arc_to (cairo_t *cr,
 	      double x2, double y2,
 	      double radius)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_arc_to (cr->gstate,
-				       x1, y1,
-				       x2, y2,
-				       radius);
+    status = _cairo_gstate_arc_to (cr->gstate,
+				   x1, y1,
+				   x2, y2,
+				   radius);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 */
 
@@ -1793,12 +1840,14 @@ cairo_rectangle (cairo_t *cr,
 void
 cairo_stroke_to_path (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_stroke_path (cr->gstate);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_stroke_path (cr->gstate);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 */
 
@@ -1831,12 +1880,14 @@ cairo_stroke_to_path (cairo_t *cr)
 void
 cairo_close_path (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_path_fixed_close_path (cr->path);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_path_fixed_close_path (cr->path);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_close_path);
 
@@ -1850,12 +1901,14 @@ slim_hidden_def(cairo_close_path);
 void
 cairo_paint (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_paint (cr->gstate);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_paint (cr->gstate);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_paint);
 
@@ -1873,6 +1926,7 @@ void
 cairo_paint_with_alpha (cairo_t *cr,
 			double   alpha)
 {
+    cairo_status_t status;
     cairo_color_t color;
     cairo_pattern_union_t pattern;
 
@@ -1891,9 +1945,9 @@ cairo_paint_with_alpha (cairo_t *cr,
     _cairo_color_init_rgba (&color, 1., 1., 1., alpha);
     _cairo_pattern_init_solid (&pattern.solid, &color);
 
-    cr->status = _cairo_gstate_mask (cr->gstate, &pattern.base);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_mask (cr->gstate, &pattern.base);
+    if (status)
+	_cairo_set_error (cr, status);
 
     _cairo_pattern_fini (&pattern.base);
 }
@@ -1912,6 +1966,8 @@ void
 cairo_mask (cairo_t         *cr,
 	    cairo_pattern_t *pattern)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
@@ -1925,9 +1981,9 @@ cairo_mask (cairo_t         *cr,
 	return;
     }
 
-    cr->status = _cairo_gstate_mask (cr->gstate, pattern);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_mask (cr->gstate, pattern);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def (cairo_mask);
 
@@ -2021,12 +2077,14 @@ cairo_stroke (cairo_t *cr)
 void
 cairo_stroke_preserve (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_stroke (cr->gstate, cr->path);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_stroke (cr->gstate, cr->path);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_stroke_preserve);
 
@@ -2062,12 +2120,14 @@ cairo_fill (cairo_t *cr)
 void
 cairo_fill_preserve (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_fill (cr->gstate, cr->path);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_fill (cr->gstate, cr->path);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_fill_preserve);
 
@@ -2083,12 +2143,14 @@ slim_hidden_def(cairo_fill_preserve);
 void
 cairo_copy_page (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_copy_page (cr->gstate);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_copy_page (cr->gstate);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2101,12 +2163,14 @@ cairo_copy_page (cairo_t *cr)
 void
 cairo_show_page (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_show_page (cr->gstate);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_show_page (cr->gstate);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2129,16 +2193,17 @@ cairo_show_page (cairo_t *cr)
 cairo_bool_t
 cairo_in_stroke (cairo_t *cr, double x, double y)
 {
-    cairo_bool_t inside;
+    cairo_status_t status;
+    cairo_bool_t inside = 0;
 
     if (cr->status)
 	return 0;
 
-    cr->status = _cairo_gstate_in_stroke (cr->gstate,
-					  cr->path,
-					  x, y, &inside);
-    if (cr->status)
-	return 0;
+    status = _cairo_gstate_in_stroke (cr->gstate,
+				      cr->path,
+				      x, y, &inside);
+    if (status)
+	_cairo_set_error (cr, status);
 
     return inside;
 }
@@ -2161,18 +2226,17 @@ cairo_in_stroke (cairo_t *cr, double x, double y)
 cairo_bool_t
 cairo_in_fill (cairo_t *cr, double x, double y)
 {
-    cairo_bool_t inside;
+    cairo_status_t status;
+    cairo_bool_t inside = 0;
 
     if (cr->status)
 	return 0;
 
-    cr->status = _cairo_gstate_in_fill (cr->gstate,
-					cr->path,
-					x, y, &inside);
-    if (cr->status) {
-	_cairo_set_error (cr, cr->status);
-	return 0;
-    }
+    status = _cairo_gstate_in_fill (cr->gstate,
+				    cr->path,
+				    x, y, &inside);
+    if (status)
+	_cairo_set_error (cr, status);
 
     return inside;
 }
@@ -2199,14 +2263,16 @@ void
 cairo_stroke_extents (cairo_t *cr,
                       double *x1, double *y1, double *x2, double *y2)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_stroke_extents (cr->gstate,
-					       cr->path,
-					       x1, y1, x2, y2);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_stroke_extents (cr->gstate,
+					   cr->path,
+					   x1, y1, x2, y2);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2229,14 +2295,16 @@ void
 cairo_fill_extents (cairo_t *cr,
                     double *x1, double *y1, double *x2, double *y2)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_fill_extents (cr->gstate,
-					     cr->path,
-					     x1, y1, x2, y2);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_fill_extents (cr->gstate,
+					 cr->path,
+					 x1, y1, x2, y2);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2294,12 +2362,14 @@ cairo_clip (cairo_t *cr)
 void
 cairo_clip_preserve (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_clip (cr->gstate, cr->path);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_clip (cr->gstate, cr->path);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 slim_hidden_def(cairo_clip_preserve);
 
@@ -2322,12 +2392,14 @@ slim_hidden_def(cairo_clip_preserve);
 void
 cairo_reset_clip (cairo_t *cr)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_reset_clip (cr->gstate);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_reset_clip (cr->gstate);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2348,12 +2420,14 @@ cairo_clip_extents (cairo_t *cr,
 		    double *x1, double *y1,
 		    double *x2, double *y2)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 static cairo_rectangle_list_t *
@@ -2419,12 +2493,14 @@ cairo_select_font_face (cairo_t              *cr,
 			cairo_font_slant_t    slant,
 			cairo_font_weight_t   weight)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_select_font_face (cr->gstate, family, slant, weight);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_select_font_face (cr->gstate, family, slant, weight);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2439,12 +2515,14 @@ void
 cairo_font_extents (cairo_t              *cr,
 		    cairo_font_extents_t *extents)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_get_font_extents (cr->gstate, extents);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_get_font_extents (cr->gstate, extents);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2460,12 +2538,14 @@ void
 cairo_set_font_face (cairo_t           *cr,
 		     cairo_font_face_t *font_face)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_font_face (cr->gstate, font_face);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_font_face (cr->gstate, font_face);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2489,14 +2569,15 @@ cairo_set_font_face (cairo_t           *cr,
 cairo_font_face_t *
 cairo_get_font_face (cairo_t *cr)
 {
+    cairo_status_t status;
     cairo_font_face_t *font_face;
 
     if (cr->status)
 	return (cairo_font_face_t*) &_cairo_font_face_nil;
 
-    cr->status = _cairo_gstate_get_font_face (cr->gstate, &font_face);
-    if (cr->status) {
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_get_font_face (cr->gstate, &font_face);
+    if (status) {
+	_cairo_set_error (cr, status);
 	return (cairo_font_face_t*) &_cairo_font_face_nil;
     }
 
@@ -2517,12 +2598,14 @@ cairo_get_font_face (cairo_t *cr)
 void
 cairo_set_font_size (cairo_t *cr, double size)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_font_size (cr->gstate, size);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_font_size (cr->gstate, size);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2542,12 +2625,14 @@ void
 cairo_set_font_matrix (cairo_t		    *cr,
 		       const cairo_matrix_t *matrix)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_font_matrix (cr->gstate, matrix);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_font_matrix (cr->gstate, matrix);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2579,12 +2664,14 @@ void
 cairo_set_font_options (cairo_t                    *cr,
 			const cairo_font_options_t *options)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_set_font_options (cr->gstate, options);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_set_font_options (cr->gstate, options);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2622,29 +2709,31 @@ void
 cairo_set_scaled_font (cairo_t                   *cr,
 		       const cairo_scaled_font_t *scaled_font)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = scaled_font->status;
-    if (cr->status)
+    status = scaled_font->status;
+    if (status)
         goto BAIL;
 
-    cr->status = _cairo_gstate_set_font_face (cr->gstate, scaled_font->font_face);
-    if (cr->status)
+    status = _cairo_gstate_set_font_face (cr->gstate, scaled_font->font_face);
+    if (status)
         goto BAIL;
 
-    cr->status = _cairo_gstate_set_font_matrix (cr->gstate, &scaled_font->font_matrix);
-    if (cr->status)
+    status = _cairo_gstate_set_font_matrix (cr->gstate, &scaled_font->font_matrix);
+    if (status)
         goto BAIL;
 
-    cr->status = _cairo_gstate_set_font_options (cr->gstate, &scaled_font->options);
-    if (cr->status)
+    status = _cairo_gstate_set_font_options (cr->gstate, &scaled_font->options);
+    if (status)
         goto BAIL;
 
     return;
 
 BAIL:
-    _cairo_set_error (cr, cr->status);
+    _cairo_set_error (cr, status);
 }
 
 /**
@@ -2670,14 +2759,15 @@ BAIL:
 cairo_scaled_font_t *
 cairo_get_scaled_font (cairo_t *cr)
 {
+    cairo_status_t status;
     cairo_scaled_font_t *scaled_font;
 
     if (cr->status)
 	return (cairo_scaled_font_t *)&_cairo_scaled_font_nil;
 
-    cr->status = _cairo_gstate_get_scaled_font (cr->gstate, &scaled_font);
-    if (cr->status) {
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_get_scaled_font (cr->gstate, &scaled_font);
+    if (status) {
+	_cairo_set_error (cr, status);
 	return (cairo_scaled_font_t *)&_cairo_scaled_font_nil;
     }
 
@@ -2709,6 +2799,7 @@ cairo_text_extents (cairo_t              *cr,
 		    const char		 *utf8,
 		    cairo_text_extents_t *extents)
 {
+    cairo_status_t status;
     cairo_glyph_t *glyphs = NULL;
     int num_glyphs;
     double x, y;
@@ -2728,23 +2819,23 @@ cairo_text_extents (cairo_t              *cr,
 
     cairo_get_current_point (cr, &x, &y);
 
-    cr->status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8,
-					       x, y,
-					       &glyphs, &num_glyphs);
+    status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8,
+					   x, y,
+					   &glyphs, &num_glyphs);
 
-    if (cr->status) {
+    if (status) {
 	if (glyphs)
 	    free (glyphs);
-	_cairo_set_error (cr, cr->status);
+	_cairo_set_error (cr, status);
 	return;
     }
 
-    cr->status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, extents);
+    status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs, extents);
     if (glyphs)
 	free (glyphs);
 
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2771,13 +2862,15 @@ cairo_glyph_extents (cairo_t                *cr,
 		     int                    num_glyphs,
 		     cairo_text_extents_t   *extents)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs,
-					      extents);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_glyph_extents (cr->gstate, glyphs, num_glyphs,
+					  extents);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2869,15 +2962,17 @@ cairo_show_text (cairo_t *cr, const char *utf8)
 void
 cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
     if (num_glyphs == 0)
 	return;
 
-    cr->status = _cairo_gstate_show_glyphs (cr->gstate, glyphs, num_glyphs);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_show_glyphs (cr->gstate, glyphs, num_glyphs);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2907,6 +3002,7 @@ cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 void
 cairo_text_path  (cairo_t *cr, const char *utf8)
 {
+    cairo_status_t status;
     cairo_text_extents_t extents;
     cairo_glyph_t *glyphs = NULL, *last_glyph;
     int num_glyphs;
@@ -2917,29 +3013,29 @@ cairo_text_path  (cairo_t *cr, const char *utf8)
 
     cairo_get_current_point (cr, &x, &y);
 
-    cr->status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8,
-					       x, y,
-					       &glyphs, &num_glyphs);
+    status = _cairo_gstate_text_to_glyphs (cr->gstate, utf8,
+					   x, y,
+					   &glyphs, &num_glyphs);
 
-    if (cr->status)
+    if (status)
 	goto BAIL;
 
     if (num_glyphs == 0)
 	return;
 
-    cr->status = _cairo_gstate_glyph_path (cr->gstate,
-					   glyphs, num_glyphs,
-					   cr->path);
+    status = _cairo_gstate_glyph_path (cr->gstate,
+				       glyphs, num_glyphs,
+				       cr->path);
 
-    if (cr->status)
+    if (status)
 	goto BAIL;
 
     last_glyph = &glyphs[num_glyphs - 1];
-    cr->status = _cairo_gstate_glyph_extents (cr->gstate,
-					      last_glyph, 1,
-					      &extents);
+    status = _cairo_gstate_glyph_extents (cr->gstate,
+					  last_glyph, 1,
+					  &extents);
 
-    if (cr->status)
+    if (status)
 	goto BAIL;
 
     x = last_glyph->x + extents.x_advance;
@@ -2950,8 +3046,8 @@ cairo_text_path  (cairo_t *cr, const char *utf8)
     if (glyphs)
 	free (glyphs);
 
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -2967,14 +3063,16 @@ cairo_text_path  (cairo_t *cr, const char *utf8)
 void
 cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
-    cr->status = _cairo_gstate_glyph_path (cr->gstate,
-					   glyphs, num_glyphs,
-					   cr->path);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_gstate_glyph_path (cr->gstate,
+				       glyphs, num_glyphs,
+				       cr->path);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
@@ -3301,6 +3399,8 @@ void
 cairo_append_path (cairo_t		*cr,
 		   const cairo_path_t	*path)
 {
+    cairo_status_t status;
+
     if (cr->status)
 	return;
 
@@ -3323,9 +3423,9 @@ cairo_append_path (cairo_t		*cr,
 	return;
     }
 
-    cr->status = _cairo_path_append_to_context (path, cr);
-    if (cr->status)
-	_cairo_set_error (cr, cr->status);
+    status = _cairo_path_append_to_context (path, cr);
+    if (status)
+	_cairo_set_error (cr, status);
 }
 
 /**
-- 
1.4.4.2

-------------- next part --------------
>From 930540081d45582a8fee224f1f4c3cbfd0cf5550 Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri, 30 Mar 2007 11:34:38 +0100
Subject: [PATCH] cairo-path.c - return the correct status

Even though cairo_move_to() and friends return void they do set the
cr->status - so check it before returning CAIRO_STATUS_SUCCESS.
---
 src/cairo-path.c |   37 ++++++++++++++++++++++---------------
 1 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/cairo-path.c b/src/cairo-path.c
index 95fe99c..06d1111 100644
--- a/src/cairo-path.c
+++ b/src/cairo-path.c
@@ -306,12 +306,13 @@ _cpp_close_path (void *closure)
     return CAIRO_STATUS_SUCCESS;
 }
 
-static void
+static cairo_status_t
 _cairo_path_populate (cairo_path_t		*path,
 		      cairo_path_fixed_t	*path_fixed,
 		      cairo_gstate_t		*gstate,
 		      cairo_bool_t		 flatten)
 {
+    cairo_status_t status;
     cpp_t cpp;
 
     cpp.data = path->data;
@@ -319,19 +320,22 @@ _cairo_path_populate (cairo_path_t		*path,
     cpp.current_point.x = 0;
     cpp.current_point.y = 0;
 
-    if (_cairo_path_fixed_interpret (path_fixed,
-				     CAIRO_DIRECTION_FORWARD,
-				     _cpp_move_to,
-				     _cpp_line_to,
-				     flatten ?
-				     _cpp_curve_to_flatten :
-				     _cpp_curve_to,
-				     _cpp_close_path,
-				     &cpp) != CAIRO_STATUS_SUCCESS)
-	return; /* XXX propagate status */
+    status = _cairo_path_fixed_interpret (path_fixed,
+				          CAIRO_DIRECTION_FORWARD,
+					  _cpp_move_to,
+					  _cpp_line_to,
+					  flatten ?
+					  _cpp_curve_to_flatten :
+					  _cpp_curve_to,
+					  _cpp_close_path,
+					  &cpp);
+    if (status)
+	return status;
 
     /* Sanity check the count */
     assert (cpp.data - path->data == path->num_data);
+
+    return status;
 }
 
 cairo_path_t *
@@ -371,10 +375,8 @@ _cairo_path_create_internal (cairo_path_fixed_t *path_fixed,
 	return (cairo_path_t*) &_cairo_path_nil;
     }
 
-    path->status = CAIRO_STATUS_SUCCESS;
-
-    _cairo_path_populate (path, path_fixed,
-			  gstate, flatten);
+    path->status = _cairo_path_populate (path, path_fixed,
+			                 gstate, flatten);
 
     return path;
 }
@@ -463,6 +465,7 @@ _cairo_path_append_to_context (const cairo_path_t	*path,
 {
     int i;
     cairo_path_data_t *p;
+    cairo_status_t status;
 
     for (i=0; i < path->num_data; i += path->data[i].header.length) {
 	p = &path->data[i];
@@ -495,6 +498,10 @@ _cairo_path_append_to_context (const cairo_path_t	*path,
 	default:
 	    return CAIRO_STATUS_INVALID_PATH_DATA;
 	}
+
+	status = cairo_status (cr);
+	if (status)
+	    return status;
     }
 
     return CAIRO_STATUS_SUCCESS;
-- 
1.4.4.2

-------------- next part --------------
>From 9c1bd9a6e0be5cf07a384732077f035b3d01e85a Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris at chris-wilson.co.uk>
Date: Fri, 30 Mar 2007 14:00:50 +0100
Subject: [PATCH] Initialise cairo_spline_t to use its embedded buffer.

Currently the code defaults to setting its points to NULL and fixing it up
on the first add_point() to use the embedded buffer. Skip this extra step
by initialising points to the embedded buffer.
---
 src/cairo-spline.c |   24 +++++++-----------------
 1 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/src/cairo-spline.c b/src/cairo-spline.c
index 42151aa..b63ac57 100644
--- a/src/cairo-spline.c
+++ b/src/cairo-spline.c
@@ -80,9 +80,9 @@ _cairo_spline_init (cairo_spline_t *spline,
     else
 	_cairo_slope_init (&spline->final_slope, &spline->a, &spline->d);
 
+    spline->points = spline->points_embedded;
+    spline->points_size = ARRAY_LEN (spline->points_embedded);
     spline->num_points = 0;
-    spline->points_size = 0;
-    spline->points = NULL;
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -90,11 +90,11 @@ _cairo_spline_init (cairo_spline_t *spline,
 void
 _cairo_spline_fini (cairo_spline_t *spline)
 {
-    if (spline->points && spline->points != spline->points_embedded)
+    if (spline->points != spline->points_embedded)
 	free (spline->points);
 
-    spline->points = NULL;
-    spline->points_size = 0;
+    spline->points = spline->points_embedded;
+    spline->points_size = ARRAY_LEN (spline->points_embedded);
     spline->num_points = 0;
 }
 
@@ -104,17 +104,8 @@ _cairo_spline_grow (cairo_spline_t *spline)
 {
     cairo_point_t *new_points;
     int old_size = spline->points_size;
-    int embedded_size = ARRAY_LEN (spline->points_embedded);
     int new_size = 2 * MAX (old_size, 16);
 
-    /* we have a local buffer at spline->points_embedded.  try to fulfill the request
-     * from there. */
-    if (old_size < embedded_size) {
-	spline->points = spline->points_embedded;
-	spline->points_size = embedded_size;
-	return CAIRO_STATUS_SUCCESS;
-    }
-
     assert (spline->num_points <= spline->points_size);
 
     if (spline->points == spline->points_embedded) {
@@ -284,9 +275,8 @@ _cairo_spline_decompose (cairo_spline_t *spline, double tolerance)
 {
     cairo_status_t status;
 
-    if (spline->points_size) {
-	_cairo_spline_fini (spline);
-    }
+    /* reset the spline, but keep the buffer */
+    spline->num_points = 0;
 
     status = _cairo_spline_decompose_into (spline, tolerance * tolerance, spline);
     if (status)
-- 
1.4.4.2



More information about the cairo mailing list