[cairo-commit] pycairo/cairo pycairo-pattern.c, 1.24, 1.25 pycairo-context.c, 1.57, 1.58 pycairo-path.c, 1.5, 1.6

Steve Chaplin commit at pdx.freedesktop.org
Mon Jun 13 21:03:00 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv26786/cairo

Modified Files:
	pycairo-pattern.c pycairo-context.c pycairo-path.c 
Log Message:
SC

Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- pycairo-pattern.c	20 May 2005 08:57:44 -0000	1.24
+++ pycairo-pattern.c	14 Jun 2005 04:02:58 -0000	1.25
@@ -39,7 +39,8 @@
 /* PycairoPattern_FromPattern
  * Create a new PycairoPattern from a cairo_pattern_t
  * pattern - a cairo_pattern_t to 'wrap' into a Python object.
- *           it is unreferenced if the PycairoPattern creation fails
+ *           pattern is unreferenced if the PycairoPattern creation fails, or
+ *           if the pattern is in an error status.
  * Return value: New reference or NULL on failure
  */
 PyObject *
@@ -48,6 +49,12 @@
     PyObject *o;
 
     assert (pattern != NULL);
+
+    if (Pycairo_Check_Status (cairo_pattern_status (pattern))) {
+	cairo_pattern_destroy (pattern);
+	return NULL;
+    }
+
     o = PycairoPattern_Type.tp_alloc (&PycairoPattern_Type, 0);
     if (o)
 	((PycairoPattern *)o)->pattern = pattern;
@@ -92,8 +99,6 @@
 	return NULL;
 
     pattern = cairo_pattern_create_for_surface (s->surface);
-    if (!pattern)
-	return PyErr_NoMemory();
     return PycairoPattern_FromPattern (pattern);
 }
 
@@ -108,8 +113,6 @@
 	return NULL;
 
     pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
-    if (!pattern)
-	return PyErr_NoMemory();
     return PycairoPattern_FromPattern (pattern);
 }
 
@@ -125,8 +128,6 @@
 
     pattern = cairo_pattern_create_radial (cx0, cy0, radius0, 
 					   cx1, cy1, radius1);
-    if (!pattern)
-	return PyErr_NoMemory();
     return PycairoPattern_FromPattern (pattern);
 }
 
@@ -134,15 +135,13 @@
 pattern_add_color_stop_rgb (PycairoPattern *o, PyObject *args)
 {
     double offset, red, green, blue;
-    cairo_status_t status;
 
     if (!PyArg_ParseTuple(args, "dddd:Pattern.add_color_stop_rgb",
 			  &offset, &red, &green, &blue))
 	return NULL;
 
-    status = cairo_pattern_add_color_stop_rgb (o->pattern, offset, red, green, 
-					       blue);
-    if (Pycairo_Check_Status(status))
+    cairo_pattern_add_color_stop_rgb (o->pattern, offset, red, green, blue);
+    if (Pycairo_Check_Status (cairo_pattern_status (o->pattern)))
 	return NULL;
     Py_RETURN_NONE;
 }
@@ -151,15 +150,14 @@
 pattern_add_color_stop_rgba (PycairoPattern *o, PyObject *args)
 {
     double offset, red, green, blue, alpha;
-    cairo_status_t status;
 
     if (!PyArg_ParseTuple(args, "ddddd:Pattern.add_color_stop_rgba",
 			  &offset, &red, &green, &blue, &alpha))
 	return NULL;
 
-    status = cairo_pattern_add_color_stop_rgba (o->pattern, offset, red, 
-						green, blue, alpha);
-    if (Pycairo_Check_Status(status))
+    cairo_pattern_add_color_stop_rgba (o->pattern, offset, red, 
+				       green, blue, alpha);
+    if (Pycairo_Check_Status (cairo_pattern_status (o->pattern)))
 	return NULL;
     Py_RETURN_NONE;
 }
@@ -167,13 +165,13 @@
 static PyObject *
 pattern_get_extend (PycairoPattern *o)
 {
-    return PyInt_FromLong(cairo_pattern_get_extend (o->pattern));
+    return PyInt_FromLong (cairo_pattern_get_extend (o->pattern));
 }
 
 static PyObject *
 pattern_get_filter (PycairoPattern *o)
 {
-    return PyInt_FromLong(cairo_pattern_get_filter (o->pattern));
+    return PyInt_FromLong (cairo_pattern_get_filter (o->pattern));
 }
 
 static PyObject *
@@ -192,7 +190,6 @@
     if (!PyArg_ParseTuple(args, "i:Pattern.set_extend", &extend))
  	return NULL;
  
-    /* always returns status = success */
     cairo_pattern_set_extend (o->pattern, extend);
     Py_RETURN_NONE;
 }
@@ -205,7 +202,6 @@
     if (!PyArg_ParseTuple (args, "i:Pattern.set_filter", &filter))
 	return NULL;
 
-    /* always returns status = success */
     cairo_pattern_set_filter (o->pattern, filter);
     Py_RETURN_NONE;
 }
@@ -219,7 +215,6 @@
 			   &PycairoMatrix_Type, &m))
 	return NULL;
 
-    /* always returns status = success */
     cairo_pattern_set_matrix (o->pattern, &m->matrix);
     Py_RETURN_NONE;
 }
@@ -228,6 +223,9 @@
     /* methods never exposed in a language binding:
      * cairo_pattern_destroy()
      * cairo_pattern_reference()
+     *
+     * cairo_pattern_status()
+     * - not needed since Pycairo handles status checking
      */
     {"add_color_stop_rgb",(PyCFunction)pattern_add_color_stop_rgb,  
                                                                METH_VARARGS },

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- pycairo-context.c	1 Jun 2005 12:29:02 -0000	1.57
+++ pycairo-context.c	14 Jun 2005 04:02:58 -0000	1.58
@@ -194,19 +194,13 @@
 static PyObject *
 pycairo_copy_path (PycairoContext *o)
 {
-    cairo_path_t *path = cairo_copy_path (o->ctx);
-    if (Pycairo_Check_Status (cairo_status (o->ctx)))
-	return NULL;
-    return PycairoPath_FromPath (path);
+    return PycairoPath_FromPath (cairo_copy_path (o->ctx));
 }
 
 static PyObject *
 pycairo_copy_path_flat (PycairoContext *o)
 {
-    cairo_path_t *path = cairo_copy_path_flat (o->ctx);
-    if (Pycairo_Check_Status (cairo_status (o->ctx)))
-	return NULL;
-    return PycairoPath_FromPath (path);
+    return PycairoPath_FromPath (cairo_copy_path_flat (o->ctx));
 }
 
 static PyObject *
@@ -369,10 +363,6 @@
 pycairo_get_source (PycairoContext *o)
 {
     cairo_pattern_t *pattern = cairo_get_source (o->ctx);
-    if (!pattern) {
-	Pycairo_Check_Status (cairo_status (o->ctx));
-	return NULL;
-    }
     cairo_pattern_reference (pattern);
     return PycairoPattern_FromPattern (pattern);
 }

Index: pycairo-path.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-path.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- pycairo-path.c	17 May 2005 01:36:57 -0000	1.5
+++ pycairo-path.c	14 Jun 2005 04:02:58 -0000	1.6
@@ -43,21 +43,28 @@
 /* PycairoPath_FromPath
  * Create a new PycairoPath from a cairo_path_t
  * path - a cairo_path_t to 'wrap' into a Python object.
- *        it is unreferenced if the PycairoPath creation fails
+ *        path is unreferenced if the PycairoPath creation fails, or if path
+ *        is in an error status.
  * Return value: New reference or NULL on failure
  */
 PyObject *
-PycairoPath_FromPath(cairo_path_t *path)
+PycairoPath_FromPath (cairo_path_t *path)
 {
-    PyObject *p;
+    PyObject *o;
 
     assert (path != NULL);
-    p = PycairoPath_Type.tp_alloc (&PycairoPath_Type, 0);
-    if (p)
-	((PycairoPath *)p)->path = path;
+
+    if (Pycairo_Check_Status (path->status)) {
+	cairo_path_destroy (path);
+	return NULL;
+    }
+
+    o = PycairoPath_Type.tp_alloc (&PycairoPath_Type, 0);
+    if (o)
+	((PycairoPath *)o)->path = path;
     else
-	cairo_path_destroy(path);
-    return p;
+	cairo_path_destroy (path);
+    return o;
 }
 
 static void




More information about the cairo-commit mailing list