[cairo-commit] cairo/src cairo.c,1.101,1.102

Carl Worth commit at pdx.freedesktop.org
Mon Jun 13 16:35:05 PDT 2005


Committed by: cworth

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

Modified Files:
	cairo.c 
Log Message:

        Originally 2005-05-08  Owen Taylor  <otaylor at redhat.com>:

        * src/cairo.c (cairo_create): If cairo_create() fails, return
        a special static object, cairo_nil.

        * src/cairo.c (cairo_reference): Don't return early if
        cr->status is set. cr->status should not affect reference
        counting.

        * src/cairo.c: (cairo_reference), (cairo_destroy): Ignore any
        magic object with a reference count of -1.


Index: cairo.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- cairo.c	13 Jun 2005 23:29:26 -0000	1.101
+++ cairo.c	13 Jun 2005 23:35:03 -0000	1.102
@@ -43,6 +43,19 @@
 
 #define CAIRO_TOLERANCE_MINIMUM	0.0002 /* We're limited by 16 bits of sub-pixel precision */
 
+static const cairo_t cairo_nil = {
+  (unsigned int)-1,		/* ref_count */
+  NULL,				/* gstate */
+  { 				/* path */
+    NULL, NULL,			/* op_buf_head, op_buf_tail */
+    NULL, NULL,			/* arg_buf_head, arg_buf_tail */
+    { 0, 0 },			/* last_move_point */
+    { 0, 0 },			/* current point */
+    FALSE,			/* has_current_point */
+  },
+  CAIRO_STATUS_NO_MEMORY	/* status */
+};
+
 #include <assert.h>
 #ifdef NDEBUG
 #define CAIRO_CHECK_SANITY(cr) 
@@ -100,6 +113,11 @@
  * Return value: a newly allocated #cairo_t with a reference
  *  count of 1. The initial reference count should be released
  *  with cairo_destroy() when you are done using the #cairo_t.
+ *  This function never returns %NULL. If memory cannot be
+ *  allocated, a special #cairo_t object will be returned on
+ *  which cairo_status() returns %CAIRO_STATUS_NO_MEMORY.
+ *  You can use this object normally, but no drawing will
+ *  be done.
  **/
 cairo_t *
 cairo_create (cairo_surface_t *target)
@@ -108,7 +126,7 @@
 
     cr = malloc (sizeof (cairo_t));
     if (cr == NULL)
-	return NULL;
+	return (cairo_t *) &cairo_nil;
 
     cr->status = CAIRO_STATUS_SUCCESS;
     cr->ref_count = 1;
@@ -141,7 +159,8 @@
 cairo_reference (cairo_t *cr)
 {
     CAIRO_CHECK_SANITY (cr);
-    if (cr->status)
+
+    if (cr->ref_count == (unsigned int)-1)
 	return;
     
     cr->ref_count++;
@@ -160,6 +179,9 @@
 cairo_destroy (cairo_t *cr)
 {
     CAIRO_CHECK_SANITY (cr);
+
+    if (cr->ref_count == (unsigned int)-1)
+	return;
     
     cr->ref_count--;
     if (cr->ref_count)




More information about the cairo-commit mailing list