[cairo-commit] cairo/src cairo-ft-font.c, 1.81, 1.82 cairo-glitz-surface.c, 1.53, 1.54 cairo-gstate.c, 1.150, 1.151 cairo-image-surface.c, 1.51, 1.52 cairo-path-data-private.h, 1.6, 1.7 cairo-path-data.c, 1.8, 1.9 cairo-pattern.c, 1.51, 1.52 cairo-png.c, 1.18, 1.19 cairo-ps-surface.c, 1.44, 1.45 cairo-quartz-surface.c, 1.15, 1.16 cairo-surface.c, 1.83, 1.84 cairo-win32-font.c, 1.29, 1.30 cairo-win32-surface.c, 1.30, 1.31 cairo-xcb-surface.c, 1.41, 1.42 cairo-xlib-surface.c, 1.98, 1.99 cairo.c, 1.115, 1.116 cairoint.h, 1.172, 1.173

Carl Worth commit at pdx.freedesktop.org
Thu Jul 28 09:46:41 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv30850/src

Modified Files:
	cairo-ft-font.c cairo-glitz-surface.c cairo-gstate.c 
	cairo-image-surface.c cairo-path-data-private.h 
	cairo-path-data.c cairo-pattern.c cairo-png.c 
	cairo-ps-surface.c cairo-quartz-surface.c cairo-surface.c 
	cairo-win32-font.c cairo-win32-surface.c cairo-xcb-surface.c 
	cairo-xlib-surface.c cairo.c cairoint.h 
Log Message:

        * src/cairoint.h:
        * src/cairo-path-data-private.h:
        * src/cairo-path-data.c:
        * src/cairo-pattern.c:
        * src/cairo-surface.c:
        Remove all create_in_error functions as they were just muddling up
        the memory management semantics:

                _cairo_path_data_create_in_error
                _cairo_pattern_create_in_error
                _cairo_surface_create_in_error

        * src/cairo-gstate.c: (_cairo_gstate_mask),
        (_composite_traps_intermediate_surface),
        (_cairo_gstate_intersect_clip_mask), (_cairo_gstate_show_glyphs):

        Don't bother with extra check of other->status to anticipate and
        try to prevent cairo_surface_create_similar from returning through
        cairo_surface_create_in_error.

        * src/cairo-glitz-surface.c: (cairo_glitz_surface_create):
        * src/cairo-image-surface.c: (cairo_image_surface_create),
        (cairo_image_surface_create_for_data):
        * src/cairo-png.c: (cairo_image_surface_create_from_png):
        * src/cairo-surface.c: (_cairo_surface_create_similar_scratch),
        (cairo_surface_create_similar),
        (_cairo_surface_create_similar_solid):
        * src/cairo-win32-surface.c: (_cairo_win32_surface_create_for_dc):
        * src/cairo-xlib-surface.c: (cairo_xlib_surface_create):
        * src/cairo.c: (cairo_get_source), (cairo_get_font_face):
        (cairo_get_target), (cairo_copy_path), (cairo_copy_path_flat):

        Just return &_cairo_surface|pattern|path_nil rather than
        _cairo_surface|pattern|path_create_in_error.

        * src/cairo-ft-font.c:
        * src/cairo-glitz-surface.c:
        * src/cairo-gstate.c:
        * src/cairo-pattern.c:
        * src/cairo-ps-surface.c:
        * src/cairo-win32-font.c:
        * src/cairo-win32-surface.c:
        * src/cairo-xcb-surface.c:
        * src/cairo-xlib-surface.c:
        After checking surface->status from a cairo_<foo>_surface_create
        function, just return CAIRO_STATUS_NO_MEMORY since that's the only
        error we'll get from one of these create functions.

        * src/cairo-gstate.c: (_cairo_gstate_get_target):
        Remove unnecessary check for gstate == NULL;

        * src/cairo-pattern.c:
        (_cairo_pattern_acquire_surface_for_gradient): Fix old check for
        image == NULL instead of image->base.status.

        * src/cairo-quartz-surface.c:
        (_cairo_quartz_surface_acquire_source_image):

        Add missing check of surface->image_base.status after creating
        surface->image.

        * src/cairo-xcb-surface.c: (_cairo_xcb_surface_create_similar):
        * src/cairo-xlib-surface.c: (_cairo_xlib_surface_create_similar):
        Add missing check of surface->base.status after creating surface.


Index: cairo-ft-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ft-font.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- cairo-ft-font.c	28 Jul 2005 16:29:46 -0000	1.81
+++ cairo-ft-font.c	28 Jul 2005 16:46:38 -0000	1.82
@@ -797,7 +797,7 @@
 						 width, height, stride);
 	if (val->image->base.status) {
 	    free (data);
-	    return val->image->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 	}
 	
 	if (subpixel)
@@ -867,6 +867,8 @@
 
 	val->image = (cairo_image_surface_t *)
 	    cairo_image_surface_create_for_data (NULL, format, 0, 0, 0);
+	if (val->image->base.status)
+	    return CAIRO_STATUS_NO_MEMORY;
     } else  {
 
 	matrix.xx = matrix.yy = 0x10000L;
@@ -1062,7 +1064,7 @@
     width = (width + 3) & ~3;
     image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
     if (image->status)
-	return image->status;
+	return CAIRO_STATUS_NO_MEMORY;
 
     /* Initialize it to empty
      */

Index: cairo-glitz-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-glitz-surface.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- cairo-glitz-surface.c	27 Jul 2005 22:39:35 -0000	1.53
+++ cairo-glitz-surface.c	28 Jul 2005 16:46:38 -0000	1.54
@@ -213,7 +213,7 @@
     if (image->base.status)
     {
 	free (pixels);
-	return image->base.status;
+	return CAIRO_STATUS_NO_MEMORY;
     }
 
     _cairo_image_surface_assume_ownership_of_data (image);
@@ -364,7 +364,7 @@
 						 image_src->width,
 						 image_src->height);
 	if (clone->base.status)
-	    return clone->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 
 	_cairo_glitz_surface_set_image (clone, image_src, 0, 0);
 	
@@ -580,7 +580,7 @@
 	{
 	    glitz_buffer_destroy (buffer);
 	    free (data);
-	    return src->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 	}
 
 	for (i = 0; i < gradient->n_stops; i++)
@@ -907,7 +907,7 @@
 						 1, 1,
 						 (cairo_color_t *) color);
 	if (src->base.status)
-	    return src->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 
 	glitz_surface_set_fill (src->surface, GLITZ_FILL_REPEAT);
 	
@@ -1017,7 +1017,7 @@
 	    if (src_pattern == &tmp_src_pattern.base)
 		_cairo_pattern_fini (&tmp_src_pattern.base);
 
-	    return mask->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 	}
 
 	color.red = color.green = color.blue = color.alpha = 0xffff;
@@ -1110,7 +1110,7 @@
 	{
 	    cairo_surface_destroy (&src->base);
 	    free (data);
-	    return image->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 	}
 
 	pixman_add_trapezoids (image->pixman_image, -dst_x, -dst_y,
@@ -1125,7 +1125,7 @@
 	    _cairo_glitz_pattern_release_surface (src_pattern, src, &attributes);
 	    free (data);
 	    cairo_surface_destroy (&image->base);
-	    return mask->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 	}
 
 	_cairo_glitz_surface_set_image (mask, image, 0, 0);
@@ -2135,7 +2135,7 @@
     cairo_glitz_surface_t *crsurface;
 
     if (surface == NULL)
-	return _cairo_surface_create_in_error (CAIRO_STATUS_NULL_POINTER);
+	return (cairo_surface_t*) &_cairo_surface_nil;
 
     crsurface = malloc (sizeof (cairo_glitz_surface_t));
     if (crsurface == NULL) {

Index: cairo-gstate.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-gstate.c,v
retrieving revision 1.150
retrieving revision 1.151
diff -u -d -r1.150 -r1.151
--- cairo-gstate.c	28 Jul 2005 16:29:46 -0000	1.150
+++ cairo-gstate.c	28 Jul 2005 16:46:38 -0000	1.151
@@ -401,9 +401,6 @@
 cairo_surface_t *
 _cairo_gstate_get_target (cairo_gstate_t *gstate)
 {
-    if (gstate == NULL)
-	return NULL;
-
     return gstate->target;
 }
 
@@ -904,15 +901,12 @@
 	 */
 	cairo_surface_t *intermediate;
 
-	if (gstate->clip.surface->status)
-	    return gstate->clip.surface->status;
-
 	intermediate = cairo_surface_create_similar (gstate->clip.surface,
 						     CAIRO_CONTENT_ALPHA,
 						     extents.width,
 						     extents.height);
 	if (intermediate->status)
-	    return intermediate->status;
+	    return CAIRO_STATUS_NO_MEMORY;
 
 	status = _cairo_surface_composite (CAIRO_OPERATOR_SOURCE,
 					   mask, NULL, intermediate,
@@ -1247,16 +1241,13 @@
 
     translate_traps (traps, -extents->x, -extents->y);
 
-    if (gstate->clip.surface->status)
-	return gstate->clip.surface->status;
-
     intermediate = _cairo_surface_create_similar_solid (gstate->clip.surface,
 							CAIRO_CONTENT_ALPHA,
 							extents->width,
 							extents->height,
 							CAIRO_COLOR_TRANSPARENT);
     if (intermediate->status)
-	return intermediate->status;
+	return CAIRO_STATUS_NO_MEMORY;
     
     _cairo_pattern_init_solid (&pattern.solid, CAIRO_COLOR_WHITE);
     
@@ -1726,16 +1717,13 @@
     if (gstate->clip.surface != NULL)
 	_cairo_rectangle_intersect (&surface_rect, &gstate->clip.surface_rect);
 
-    if (gstate->target->status)
-	return gstate->target->status;
-    
     surface = _cairo_surface_create_similar_solid (gstate->target,
 						   CAIRO_CONTENT_ALPHA,
 						   surface_rect.width,
 						   surface_rect.height,
 						   CAIRO_COLOR_WHITE);
     if (surface->status)
-	return surface->status;
+	return CAIRO_STATUS_NO_MEMORY;
 
     /* Render the new clipping path into the new mask surface. */
 
@@ -2174,18 +2162,13 @@
 	    goto BAIL1;
 	}
 
-	if (gstate->clip.surface->status) {
-	    status = gstate->clip.surface->status;
-	    goto BAIL1;
-	}
-
 	intermediate = _cairo_surface_create_similar_solid (gstate->clip.surface,
 							    CAIRO_CONTENT_ALPHA,
 							    extents.width,
 							    extents.height,
 							    CAIRO_COLOR_TRANSPARENT);
 	if (intermediate->status) {
-	    status = intermediate->status;
+	    status = CAIRO_STATUS_NO_MEMORY;
 	    goto BAIL1;
 	}
 

Index: cairo-image-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-image-surface.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- cairo-image-surface.c	27 Jul 2005 22:39:35 -0000	1.51
+++ cairo-image-surface.c	28 Jul 2005 16:46:38 -0000	1.52
@@ -161,7 +161,7 @@
     pixman_image_t *pixman_image;
 
     if (! CAIRO_FORMAT_VALID (format))
-	return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_FORMAT);
+	return (cairo_surface_t*) &_cairo_surface_nil;
 
     pixman_format = _create_pixman_format (format);
     if (pixman_format == NULL) {
@@ -217,7 +217,7 @@
     pixman_image_t *pixman_image;
 
     if (! CAIRO_FORMAT_VALID (format))
-	return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_FORMAT);
+	return (cairo_surface_t*) &_cairo_surface_nil;
 
     pixman_format = _create_pixman_format (format);
     if (pixman_format == NULL) {

Index: cairo-path-data-private.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-path-data-private.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cairo-path-data-private.h	13 Jun 2005 23:29:26 -0000	1.6
+++ cairo-path-data-private.h	28 Jul 2005 16:46:38 -0000	1.7
@@ -38,6 +38,8 @@
 
 #include "cairoint.h"
 
+extern cairo_path_t cairo_path_nil;
+
 cairo_private cairo_path_t *
 _cairo_path_data_create (cairo_path_fixed_t *path,
 			 cairo_gstate_t     *gstate);
@@ -46,9 +48,6 @@
 _cairo_path_data_create_flat (cairo_path_fixed_t *path,
 			      cairo_gstate_t     *gstate);
 
-cairo_private cairo_path_t *
-_cairo_path_data_create_in_error (cairo_status_t status);
-
 cairo_private cairo_status_t
 _cairo_path_data_append_to_context (cairo_path_t *path,
 				    cairo_t	 *cr);

Index: cairo-path-data.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-path-data.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- cairo-path-data.c	27 Jul 2005 22:39:35 -0000	1.8
+++ cairo-path-data.c	28 Jul 2005 16:46:38 -0000	1.9
@@ -37,8 +37,7 @@
 #include "cairo-path-fixed-private.h"
 #include "cairo-gstate-private.h"
 
-static cairo_path_t
-cairo_path_nil = { CAIRO_STATUS_NO_MEMORY, NULL, 0 };
+cairo_path_t cairo_path_nil = { CAIRO_STATUS_NO_MEMORY, NULL, 0 };
 
 /* Closure for path interpretation. */
 typedef struct cairo_path_data_count {
@@ -435,37 +434,6 @@
 }
 
 /**
- * _cairo_path_data_create_in_error:
- * @status: an error status
- * 
- * Create an empty #cairo_path_t object to hold an error status. This
- * is useful for propagating status values from an existing object to
- * a new #cairo_path_t.
- * 
- * Return value: a #cairo_path_t object with status of @status, NULL
- * data, and 0 num_data. If there is insufficient memory a pointer to
- * a special static cairo_path_nil will be returned instead with
- * status==CAIRO_STATUS_NO_MEMORY rather than @status.
- **/
-cairo_path_t *
-_cairo_path_data_create_in_error (cairo_status_t status)
-{
-    cairo_path_t *path;
-
-    path = malloc (sizeof (cairo_path_t));
-    if (path == NULL)
-	return &cairo_path_nil;
-
-    path->status = status;
-    path->data = NULL;
-    path->num_data = 0;
-
-    _cairo_error (status);
-
-    return path;
-}
-
-/**
  * _cairo_path_data_append_to_context:
  * @path: the path data to be appended
  * @cr: a cairo context

Index: cairo-pattern.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-pattern.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- cairo-pattern.c	27 Jul 2005 22:39:35 -0000	1.51
+++ cairo-pattern.c	28 Jul 2005 16:46:38 -0000	1.52
@@ -50,7 +50,7 @@
     ((unsigned char) \
      ((((unsigned char) (c1)) * (int) ((unsigned char) (c2))) / 0xff))
 
-static const cairo_solid_pattern_t cairo_solid_pattern_nil = {
+const cairo_solid_pattern_t cairo_solid_pattern_nil = {
     { CAIRO_PATTERN_SOLID, 	/* type */
       (unsigned int)-1,		/* ref_count */
       CAIRO_STATUS_NO_MEMORY,	/* status */
@@ -292,37 +292,6 @@
 }
 
 /**
- * _cairo_pattern_create_in_error:
- * @status: an error status
- * 
- * Create an empty #cairo_pattern_t object to hold an error
- * status. This is useful for propagating status values from an
- * existing object to a new #cairo_pattern_t.
- *
- * Return value: a (solid, black) #cairo_pattern_t object with status
- * of @status. If there is insufficient memory a pointer to a special,
- * static cairo_solid_pattern_nil will be returned instead with a
- * status of CAIRO_STATUS_NO_MEMORY rather than @status.
- * 
- * Return value: 
- **/
-cairo_pattern_t *
-_cairo_pattern_create_in_error (cairo_status_t status)
-{
-    cairo_solid_pattern_t *pattern;
-
-    pattern = malloc (sizeof (cairo_solid_pattern_t));
-    if (pattern == NULL)
-	return (cairo_pattern_t *) &cairo_solid_pattern_nil.base;
-
-    _cairo_pattern_init_solid (pattern, CAIRO_COLOR_BLACK);
-
-    _cairo_pattern_set_error (&pattern->base, status);
-
-    return &pattern->base;
-}
-
-/**
  * cairo_pattern_create_rgb:
  * @red: red component of the color
  * @green: green component of the color
@@ -1243,7 +1212,7 @@
 					     width, height,
 					     width * 4);
     
-    if (image == NULL) {
+    if (image->base.status) {
 	free (data);
 	return CAIRO_STATUS_NO_MEMORY;
     }
@@ -1279,7 +1248,7 @@
 						1, 1,
 						&pattern->color);
     if ((*out)->status)
-	return (*out)->status;
+	return CAIRO_STATUS_NO_MEMORY;
 
     attribs->x_offset = attribs->y_offset = 0;
     cairo_matrix_init_identity (&attribs->matrix);

Index: cairo-png.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-png.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- cairo-png.c	27 Jul 2005 22:39:35 -0000	1.18
+++ cairo-png.c	28 Jul 2005 16:46:38 -0000	1.19
@@ -437,8 +437,16 @@
  * given PNG file.
  * 
  * Return value: a new #cairo_surface_t initialized with the contents
- * of the PNG file or %NULL if the file is not a valid PNG file or
- * memory could not be allocated for the operation.
+ * of the PNG file, or a "nil" surface if any error occured. A nil
+ * surface can be checked for with cairo_surface_status(surface) which
+ * may return one of the following values: 
+ *
+ *	CAIRO_STATUS_NO_MEMORY
+ *
+ * XXX: We may want to add a few more error values here, (file not
+ * found? permission denied? file not png?). One way to do this would
+ * be to create several variations on cairo_surface_nil to house the
+ * status values we care about.
  **/
 cairo_surface_t *
 cairo_image_surface_create_from_png (const char *filename)
@@ -447,12 +455,8 @@
     cairo_surface_t *surface;
 
     fp = fopen (filename, "rb");
-    if (fp == NULL) {
-	if (errno == ENOMEM)
-	    return (cairo_surface_t*) &_cairo_surface_nil;
-	else
-	    return _cairo_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
-    }
+    if (fp == NULL)
+	return (cairo_surface_t*) &_cairo_surface_nil;
   
     surface = read_png (stdio_read_func, fp);
 

Index: cairo-ps-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-ps-surface.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- cairo-ps-surface.c	27 Jul 2005 22:39:35 -0000	1.44
+++ cairo-ps-surface.c	28 Jul 2005 16:46:38 -0000	1.45
@@ -315,7 +315,7 @@
     surface->current_page = _cairo_meta_surface_create (surface->width,
 							surface->height);
     if (surface->current_page->status)
-	return surface->current_page->status;
+	return CAIRO_STATUS_NO_MEMORY;
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -670,7 +670,7 @@
 						  image->height, 
 						  CAIRO_COLOR_WHITE);
     if (opaque->status) {
-	status = opaque->status;
+	status = CAIRO_STATUS_NO_MEMORY;
 	goto bail0;
     }
 
@@ -1250,7 +1250,7 @@
 
     image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
     if (image->status)
-	return image->status;
+	return CAIRO_STATUS_NO_MEMORY;
 
     status = _cairo_surface_fill_rectangle (image,
 					    CAIRO_OPERATOR_SOURCE,
@@ -1311,7 +1311,7 @@
 
     ps_output = _ps_output_surface_create (surface);
     if (ps_output->status)
-	return ps_output->status;
+	return CAIRO_STATUS_NO_MEMORY;
 
     status = _cairo_meta_surface_replay (page, ps_output);
 

Index: cairo-quartz-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-quartz-surface.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cairo-quartz-surface.c	27 Jul 2005 22:39:35 -0000	1.15
+++ cairo-quartz-surface.c	28 Jul 2005 16:46:38 -0000	1.16
@@ -124,6 +124,11 @@
                                             CAIRO_FORMAT_ARGB32,
                                             surface->width,
                                             surface->height, rowBytes);
+    if (surface->image->base.status) {
+	/* XXX: I assume we're leaking memory here, but I don't know
+	 * the right call to use to clean up from CGImageCreate. */
+	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     *image_out = surface->image;
     *image_extra = NULL;

Index: cairo-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-surface.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- cairo-surface.c	28 Jul 2005 16:29:46 -0000	1.83
+++ cairo-surface.c	28 Jul 2005 16:46:38 -0000	1.84
@@ -127,7 +127,7 @@
     cairo_format_t format = _cairo_format_from_content (content);
 
     if (other->status)
-	return _cairo_surface_create_in_error (other->status);
+	return (cairo_surface_t*) &_cairo_surface_nil;
 
     if (other->backend->create_similar)
 	return other->backend->create_similar (other, content, width, height);
@@ -146,9 +146,13 @@
  * existing surface. The new surface will use the same backend as
  * @other unless that is not possible for some reason.
  * 
- * Return value: a pointer to the newly allocated surface, or NULL in
- * the case of errors. The caller owns the surface and should call
- * cairo_surface_destroy when done with it.
+ * Return value: a pointer to the newly allocated surface. The caller
+ * owns the surface and should call cairo_surface_destroy when done
+ * with it.
+ *
+ * This function always returns a valid pointer, but it will return a
+ * pointer to a "nil" surface if @other is already in an error state
+ * or any other error occurs.
  **/
 cairo_surface_t *
 cairo_surface_create_similar (cairo_surface_t  *other,
@@ -157,10 +161,12 @@
 			      int		height)
 {
     if (other->status)
-	return _cairo_surface_create_in_error (other->status);
+	return (cairo_surface_t*) &_cairo_surface_nil;
 
-    if (! CAIRO_CONTENT_VALID (content))
-	return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_CONTENT);
+    if (! CAIRO_CONTENT_VALID (content)) {
+	_cairo_error (CAIRO_STATUS_INVALID_CONTENT);
+	return (cairo_surface_t*) &_cairo_surface_nil;
+    }
 
     return _cairo_surface_create_similar_solid (other, content,
 						width, height,
@@ -179,37 +185,23 @@
 
     surface = _cairo_surface_create_similar_scratch (other, content,
 						     width, height);
+    if (surface->status) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_surface_t*) &_cairo_surface_nil;
+    }
     
     status = _cairo_surface_fill_rectangle (surface,
 					    CAIRO_OPERATOR_SOURCE, color,
 					    0, 0, width, height);
     if (status) {
 	cairo_surface_destroy (surface);
-	return _cairo_surface_create_in_error (status);
+	_cairo_error (status);
+	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
     return surface;
 }
 
-cairo_surface_t *
-_cairo_surface_create_in_error (cairo_status_t status)
-{
-    cairo_surface_t *surface;
-
-    /* The format here is totally arbitrary. */
-    surface = cairo_image_surface_create_for_data (NULL, CAIRO_FORMAT_ARGB32,
-						   0, 0, 0);
-    /* If that failed, then there are bigger problems than the error
-     * we want to stash here. */
-    if (surface->ref_count == -1)
-	return surface;
-
-    _cairo_surface_set_error (surface, status);
-
-    return surface;
-}
-
-
 cairo_clip_mode_t
 _cairo_surface_get_clip_mode (cairo_surface_t *surface)
 {

Index: cairo-win32-font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-win32-font.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- cairo-win32-font.c	28 Jul 2005 16:29:46 -0000	1.29
+++ cairo-win32-font.c	28 Jul 2005 16:46:38 -0000	1.30
@@ -1083,7 +1083,7 @@
 
 	tmp_surface = (cairo_win32_surface_t *)_cairo_win32_surface_create_dib (CAIRO_FORMAT_ARGB32, width, height);
 	if (tmp_surface->status)
-	    return tmp_surface->status;
+	    return CAIRO_STATUS_NO_MEMORY;
 
 	r.left = 0;
 	r.top = 0;

Index: cairo-win32-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-win32-surface.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- cairo-win32-surface.c	27 Jul 2005 22:39:35 -0000	1.30
+++ cairo-win32-surface.c	28 Jul 2005 16:46:38 -0000	1.31
@@ -263,7 +263,7 @@
     surface->image = cairo_image_surface_create_for_data (bits, format,
 							  width, height, rowstride);
     if (surface->image->status) {
-	status = surface->image->status;
+	status = CAIRO_STATUS_NO_MEMORY;
 	goto FAIL;
     }
     
@@ -294,7 +294,8 @@
 	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return &_cairo_surface_nil;
     } else {
-	return _cairo_surface_create_in_error (status);
+	_cairo_error (status);
+	return &_cairo_surface_nil;
     }
 }
 
@@ -370,7 +371,7 @@
 								       width,
 								       height);
     if (local->status)
-	return local->status;
+	return CAIRO_STATUS_NO_MEMORY;
     
     if (!BitBlt (local->dc, 
 		 0, 0,

Index: cairo-xcb-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-xcb-surface.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- cairo-xcb-surface.c	27 Jul 2005 22:39:35 -0000	1.41
+++ cairo-xcb-surface.c	28 Jul 2005 16:46:38 -0000	1.42
@@ -256,6 +256,10 @@
 	cairo_xcb_surface_create_with_xrender_format (dpy, d,
 						      &xrender_format,
 						      width, height);
+    if (surface->base.status) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_surface_t*) &_cairo_surface_nil;
+    }
 
     surface->owns_pixmap = TRUE;
 
@@ -653,7 +657,7 @@
 	    _cairo_xcb_surface_create_similar (surface, content,
 					       image_src->width, image_src->height);
 	if (clone->base.status)
-	    return clone->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 	
 	_draw_image_surface (clone, image_src, 0, 0);
 	

Index: cairo-xlib-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-xlib-surface.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- cairo-xlib-surface.c	27 Jul 2005 22:39:35 -0000	1.98
+++ cairo-xlib-surface.c	28 Jul 2005 16:46:39 -0000	1.99
@@ -213,6 +213,10 @@
 	cairo_xlib_surface_create_with_xrender_format (dpy, pix, src->screen,
 						       xrender_format,
 						       width, height);
+    if (surface->base.status) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	return (cairo_surface_t*) &_cairo_surface_nil;
+    }
 				 
     surface->owns_pixmap = TRUE;
 
@@ -669,7 +673,7 @@
 	    _cairo_xlib_surface_create_similar (surface, content,
 						image_src->width, image_src->height);
 	if (clone->base.status)
-	    return clone->base.status;
+	    return CAIRO_STATUS_NO_MEMORY;
 	
 	_draw_image_surface (clone, image_src, 0, 0);
 	
@@ -1547,8 +1551,10 @@
 {
     Screen *screen = _cairo_xlib_screen_from_visual (dpy, visual);
 
-    if (screen == NULL)
-	return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_VISUAL);
+    if (screen == NULL) {
+	_cairo_error (CAIRO_STATUS_INVALID_VISUAL);
+	return (cairo_surface_t*) &_cairo_surface_nil;
+    }
     
     return _cairo_xlib_surface_create_internal (dpy, drawable, screen,
 						visual, NULL, width, height, 0);

Index: cairo.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- cairo.c	27 Jul 2005 22:39:35 -0000	1.115
+++ cairo.c	28 Jul 2005 16:46:39 -0000	1.116
@@ -497,12 +497,8 @@
 cairo_pattern_t *
 cairo_get_source (cairo_t *cr)
 {
-    if (cr->status) {
-	cairo_pattern_t *pattern;
-	pattern = _cairo_pattern_create_in_error (cr->status);
-	_cairo_set_error (cr, cr->status);
-	return pattern;
-    }
+    if (cr->status)
+	return (cairo_pattern_t*) &cairo_solid_pattern_nil.base;
 
     return _cairo_gstate_get_source (cr->gstate);
 }
@@ -1692,7 +1688,7 @@
     if (cr->status) {
 	_cairo_set_error (cr, cr->status);
 	/* XXX: When available:
-	return _cairo_font_face_create_in_error (cr->status);
+	return _cairo_font_face_nil;
 	*/
 	return NULL;
     }
@@ -2217,17 +2213,19 @@
  * Gets the target surface for the cairo context as passed to
  * cairo_create().
  * 
- * Return value: the target surface, (or NULL if @cr is in an error
- * state). This object is owned by cairo. To keep a reference to it,
- * you must call cairo_surface_reference().
+ * Return value: the target surface. This object is owned by cairo. To
+ * keep a reference to it, you must call cairo_surface_reference().
+ *
+ * This function will always return a valid pointer, but the result
+ * can be a "nil" surface if @cr is already in an error state,
+ * (ie. cairo_status(cr) != CAIRO_STATUS_SUCCESS). A nil surface is
+ * indicated by cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS.
  **/
 cairo_surface_t *
 cairo_get_target (cairo_t *cr)
 {
-    if (cr->status) {
-	_cairo_set_error (cr, cr->status);
-	return _cairo_surface_create_in_error (cr->status);
-    }
+    if (cr->status)
+	return (cairo_surface_t*) &_cairo_surface_nil;
 
     return _cairo_gstate_get_target (cr->gstate);
 }
@@ -2248,20 +2246,18 @@
  * will have no data, (data==NULL and num_data==0), if either of the
  * following conditions hold:
  *
- * 1) If there is insufficient memory to copy the path. In this case
- *    path->status will be set to CAIRO_STATUS_NO_MEMORY.
+ * 1) If there is insufficient memory to copy the path.
  *
- * 2) If @cr is already in an error state. In this case path->status
- *    will contain the same status that would be returned by
- *    cairo_status(cr).
+ * 2) If @cr is already in an error state.
+ *
+ * In either case, path->status will be set to CAIRO_STATUS_NO_MEMORY,
+ * (regardless of what the error status in @cr might have been).
  **/
 cairo_path_t *
 cairo_copy_path (cairo_t *cr)
 {
-    if (cr->status) {
-	_cairo_set_error (cr, cr->status);
-	return _cairo_path_data_create_in_error (cr->status);
-    } 
+    if (cr->status)
+	return &cairo_path_nil;
 
     return _cairo_path_data_create (&cr->path, cr->gstate);
 }
@@ -2300,7 +2296,7 @@
 cairo_copy_path_flat (cairo_t *cr)
 {
     if (cr->status)
-	return _cairo_path_data_create_in_error (cr->status);
+	return &cairo_path_nil;
     else
 	return _cairo_path_data_create_flat (&cr->path, cr->gstate);
 }

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -d -r1.172 -r1.173
--- cairoint.h	28 Jul 2005 16:29:47 -0000	1.172
+++ cairoint.h	28 Jul 2005 16:46:39 -0000	1.173
@@ -892,6 +892,8 @@
     cairo_color_t color;
 } cairo_solid_pattern_t;
 
+extern const cairo_solid_pattern_t cairo_solid_pattern_nil;
+
 typedef struct _cairo_surface_pattern {
     cairo_pattern_t base;
     
@@ -1496,9 +1498,6 @@
 				     int		  height,
 				     const cairo_color_t *color);
 
-cairo_surface_t *
-_cairo_surface_create_in_error (cairo_status_t status);
-
 cairo_private void
 _cairo_surface_init (cairo_surface_t			*surface,
 		     const cairo_surface_backend_t	*backend);
@@ -1835,9 +1834,6 @@
 cairo_private cairo_pattern_t *
 _cairo_pattern_create_solid (const cairo_color_t *color);
 
-cairo_pattern_t *
-_cairo_pattern_create_in_error (cairo_status_t status);
-
 cairo_private void
 _cairo_pattern_transform (cairo_pattern_t      *pattern,
 			  const cairo_matrix_t *ctm_inverse);




More information about the cairo-commit mailing list