[cairo-commit] pycairo/cairo cairogtkmodule.c, 1.22, 1.23 pycairo-context.c, 1.52, 1.53 pycairo-font.c, 1.17, 1.18 pycairo-matrix.c, 1.18, 1.19 pycairo-path.c, 1.4, 1.5 pycairo-pattern.c, 1.21, 1.22 pycairo-surface.c, 1.39, 1.40

Steve Chaplin commit at pdx.freedesktop.org
Mon May 16 18:36:59 PDT 2005


Committed by: stevech1097

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

Modified Files:
	cairogtkmodule.c pycairo-context.c pycairo-font.c 
	pycairo-matrix.c pycairo-path.c pycairo-pattern.c 
	pycairo-surface.c 
Log Message:
SC

Index: cairogtkmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairogtkmodule.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- cairogtkmodule.c	16 May 2005 01:04:34 -0000	1.22
+++ cairogtkmodule.c	17 May 2005 01:36:57 -0000	1.23
@@ -55,7 +55,6 @@
 static PyObject *
 surface_create_for_pixbuf(PyObject *self, PyObject *args)
 {
-    PyObject *py_surface;
     PyGObject *py_pixbuf;
     GdkPixbuf *gdk_pixbuf;
     cairo_surface_t *surface;
@@ -85,12 +84,8 @@
 	 gdk_pixbuf_get_rowstride(gdk_pixbuf));
     if (!surface)
 	return PyErr_NoMemory();
-
-    py_surface = PycairoImageSurface_FromImageSurface(surface, 
-						      (PyObject *)py_pixbuf);
-    if (!py_surface)
-	cairo_surface_destroy(surface);
-    return py_surface;
+    return PycairoImageSurface_FromImageSurface (surface, 
+						 (PyObject *)py_pixbuf);
 }
 
 /* copied from gtk+/gdk/gdkcairo.c and gtk+/gdk/x11/gdkdrawable-x11.c
@@ -136,7 +131,6 @@
 gdk_cairo_create(PyObject *self, PyObject *args)
 {
     cairo_t *cr;
-    PyObject *c;
     PyGObject *py_drawable;
 
     if (!PyArg_ParseTuple(args, "O!:gdk_cairo_create",
@@ -148,11 +142,7 @@
 	PyErr_SetString(PyExc_RuntimeError, "could not create context");
 	return NULL;
     }
-
-    c = PycairoContext_FromContext(cr, (PyObject *)py_drawable);
-    if (!c)
-	cairo_destroy(cr);
-    return c;
+    return PycairoContext_FromContext (cr, (PyObject *)py_drawable);
 }
 
 

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- pycairo-context.c	14 May 2005 01:15:06 -0000	1.52
+++ pycairo-context.c	17 May 2005 01:36:57 -0000	1.53
@@ -37,23 +37,27 @@
 
 /* PycairoContext_FromContext
  * Create a new PycairoContext from a cairo_t
- * Return value: New reference (NULL on failure)
- *
+ * ctx  - a cairo_t to 'wrap' into a Python object.
+ *        it is unreferenced if the PycairoContext creation fails
  * base - the base object used to create the context, or NULL.
- *        it is referenced to keep it alive while the context
- *        is being used
+ *        it is referenced to keep it alive while the cairo_t is being used
+ * Return value: New reference or NULL on failure
  */
 PyObject *
 PycairoContext_FromContext(cairo_t *ctx, PyObject *base)
 {
-    PycairoContext *c = (PycairoContext *)PycairoContext_Type.tp_new
-	(&PycairoContext_Type, NULL, NULL);
+    PyObject *c;
+
+    assert (ctx != NULL);
+    c = PycairoContext_Type.tp_alloc (&PycairoContext_Type, 0);
     if (c) {
-	c->ctx = ctx;
+	((PycairoContext *)c)->ctx = ctx;
 	Py_XINCREF(base);
-	c->base = base;
+	((PycairoContext *)c)->base = base;
+    } else {
+	cairo_destroy (ctx);
     }
-    return (PyObject *) c;
+    return c;
 }
 
 static void
@@ -187,29 +191,19 @@
 static PyObject *
 pycairo_copy_path(PycairoContext *c)
 {
-    PyObject *p;
-    cairo_path_t *path = cairo_copy_path(c->ctx);
-    if (Pycairo_check_status(cairo_status(c->ctx)))
+    cairo_path_t *path = cairo_copy_path (c->ctx);
+    if (Pycairo_check_status (cairo_status (c->ctx)))
 	return NULL;
-
-    p = PycairoPath_FromPath(path);
-    if (!p)
-	cairo_path_destroy(path);
-    return p;
+    return PycairoPath_FromPath (path);
 }
 
 static PyObject *
 pycairo_copy_path_flat(PycairoContext *c)
 {
-    PyObject *p;
-    cairo_path_t *path = cairo_copy_path_flat(c->ctx);
-    if (Pycairo_check_status(cairo_status(c->ctx)))
+    cairo_path_t *path = cairo_copy_path_flat (c->ctx);
+    if (Pycairo_check_status (cairo_status (c->ctx)))
 	return NULL;
-
-    p = PycairoPath_FromPath(path);
-    if (!p)
-	cairo_path_destroy(path);
-    return p;
+    return PycairoPath_FromPath (path);
 }
 
 static PyObject *
@@ -314,18 +308,13 @@
 static PyObject *
 pycairo_get_font_face(PycairoContext *c)
 {
-    PyObject *f;
-    cairo_font_face_t *font_face;
-
-    font_face = cairo_get_font_face(c->ctx);
+    cairo_font_face_t *font_face = cairo_get_font_face(c->ctx);
     if (!font_face){
 	Pycairo_check_status(cairo_status(c->ctx));
 	return NULL;
     }
-    f = PycairoFontFace_FromFontFace(font_face);
-    if (f)
-	cairo_font_face_reference(font_face);
-    return f;
+    cairo_font_face_reference (font_face);
+    return PycairoFontFace_FromFontFace (font_face);
 }
 
 static PyObject *
@@ -377,34 +366,25 @@
 static PyObject *
 pycairo_get_source(PycairoContext *c)
 {
-    PyObject *p;
     cairo_pattern_t *pattern = cairo_get_source(c->ctx);
-
     if (!pattern) {
 	Pycairo_check_status(cairo_status(c->ctx));
 	return NULL;
     }
-
-    p = PycairoPattern_FromPattern(pattern);
-    if (p)
-	cairo_pattern_reference(pattern);
-    return p;
+    cairo_pattern_reference (pattern);
+    return PycairoPattern_FromPattern (pattern);
 }
 
 static PyObject *
 pycairo_get_target(PycairoContext *c)
 {
-    PyObject *s;
     cairo_surface_t *surface = cairo_get_target(c->ctx);
     if (!surface) {
 	Pycairo_check_status(cairo_status(c->ctx));
 	return NULL;
     }
-
-    s = PycairoSurface_FromSurface(surface, NULL);
-    if (s)
-	cairo_surface_reference(surface);
-    return s;
+    cairo_surface_reference(surface);
+    return PycairoSurface_FromSurface (surface, NULL);
 }
 
 static PyObject *

Index: pycairo-font.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-font.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- pycairo-font.c	14 May 2005 01:26:31 -0000	1.17
+++ pycairo-font.c	17 May 2005 01:36:57 -0000	1.18
@@ -40,17 +40,22 @@
 
 /* PycairoFontFace_FromFontFace
  * Create a new PycairoFontFace from a cairo_font_face_t
- * Return value: New reference (NULL on failure)
+ * font_face - a cairo_font_face_t to 'wrap' into a Python object.
+ *             it is unreferenced if the PycairoFontFace creation fails
+ * Return value: New reference or NULL on failure
  */
 PyObject *
 PycairoFontFace_FromFontFace(cairo_font_face_t *font_face)
 {
-    PycairoFontFace *f = (PycairoFontFace *)PycairoFontFace_Type.tp_new
-	(&PycairoFontFace_Type, NULL, NULL);
-    if (f)
-	f->font_face = font_face;
+    PyObject *f;
 
-    return (PyObject *) f;
+    assert (font_face != NULL);	
+    f = PycairoFontFace_Type.tp_alloc (&PycairoFontFace_Type, 0);
+    if (f)
+	((PycairoFontFace *)f)->font_face = font_face;
+    else
+	cairo_font_face_destroy (font_face);
+    return f;
 }
 
 static void

Index: pycairo-matrix.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-matrix.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- pycairo-matrix.c	14 May 2005 01:26:31 -0000	1.18
+++ pycairo-matrix.c	17 May 2005 01:36:57 -0000	1.19
@@ -38,18 +38,21 @@
 
 /* PycairoMatrix_FromMatrix
  * Create a new PycairoMatrix from a cairo_matrix_t
- * Return value: New reference (NULL on failure)
+ * matrix - a cairo_matrix_t to 'wrap' into a Python object
+ * Return value: New reference or NULL on failure
  *
  * takes a copy of cairo_matrix_t
  */
 PyObject *
 PycairoMatrix_FromMatrix(const cairo_matrix_t *matrix)
 {
-    PycairoMatrix *m = (PycairoMatrix *)PycairoMatrix_Type.tp_new
-	(&PycairoMatrix_Type, NULL, NULL);
+    PyObject *m;
+
+    assert (matrix != NULL);
+    m = PycairoMatrix_Type.tp_alloc (&PycairoMatrix_Type, 0);
     if (m)
-	m->matrix = *matrix;
-    return (PyObject *) m;
+	((PycairoMatrix *)m)->matrix = *matrix;
+    return m;
 }
 
 static void

Index: pycairo-path.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-path.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pycairo-path.c	14 May 2005 01:15:06 -0000	1.4
+++ pycairo-path.c	17 May 2005 01:36:57 -0000	1.5
@@ -42,17 +42,22 @@
 
 /* PycairoPath_FromPath
  * Create a new PycairoPath from a cairo_path_t
- * Return value: New reference (NULL on failure)
+ * path - a cairo_path_t to 'wrap' into a Python object.
+ *        it is unreferenced if the PycairoPath creation fails
+ * Return value: New reference or NULL on failure
  */
 PyObject *
 PycairoPath_FromPath(cairo_path_t *path)
 {
-    PycairoPath *p = (PycairoPath *)PycairoPath_Type.tp_new
-	(&PycairoPath_Type, NULL, NULL);
-    if (p)
-	p->path = path;
+    PyObject *p;
 
-    return (PyObject *) p;
+    assert (path != NULL);
+    p = PycairoPath_Type.tp_alloc (&PycairoPath_Type, 0);
+    if (p)
+	((PycairoPath *)p)->path = path;
+    else
+	cairo_path_destroy(path);
+    return p;
 }
 
 static void

Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- pycairo-pattern.c	14 May 2005 01:26:31 -0000	1.21
+++ pycairo-pattern.c	17 May 2005 01:36:57 -0000	1.22
@@ -38,16 +38,22 @@
 
 /* PycairoPattern_FromPattern
  * Create a new PycairoPattern from a cairo_pattern_t
- * Return value: New reference (NULL on failure)
+ * pattern - a cairo_pattern_t to 'wrap' into a Python object.
+ *           it is unreferenced if the PycairoPattern creation fails
+ * Return value: New reference or NULL on failure
  */
 PyObject *
 PycairoPattern_FromPattern(cairo_pattern_t *pattern)
 {
-    PycairoPattern *p = (PycairoPattern *)PycairoPattern_Type.tp_new
-	(&PycairoPattern_Type, NULL, NULL);
+    PyObject *p;
+
+    assert (pattern != NULL);
+    p = PycairoPattern_Type.tp_alloc (&PycairoPattern_Type, 0);
     if (p)
-	p->pattern = pattern;
-    return (PyObject *) p;
+	((PycairoPattern *)p)->pattern = pattern;
+    else
+	cairo_pattern_destroy (pattern);
+    return p;
 }
 
 static void
@@ -78,7 +84,6 @@
 static PyObject *
 pattern_create_for_surface(PyTypeObject *type, PyObject *args)
 {
-    PyObject *p;
     PycairoSurface *s;
     cairo_pattern_t *pattern;
 
@@ -89,17 +94,13 @@
     pattern = cairo_pattern_create_for_surface (s->surface);
     if (!pattern)
 	return PyErr_NoMemory();
-    p = PycairoPattern_FromPattern(pattern);
-    if (!p)
-	cairo_pattern_destroy(pattern);
-    return p;
+    return PycairoPattern_FromPattern (pattern);
 }
 
 /* alternative constructor */
 static PyObject *
 pattern_create_linear(PyTypeObject *type, PyObject *args)
 {
-    PyObject *p;
     double x0, y0, x1, y1;
     cairo_pattern_t *pattern;
     
@@ -110,17 +111,13 @@
     pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
     if (!pattern)
 	return PyErr_NoMemory();
-    p = PycairoPattern_FromPattern(pattern);
-    if (!p)
-	cairo_pattern_destroy(pattern);
-    return p;
+    return PycairoPattern_FromPattern (pattern);
 }
 
 /* alternative constructor */
 static PyObject *
 pattern_create_radial(PyTypeObject *type, PyObject *args)
 {
-    PyObject *p;
     cairo_pattern_t *pattern;
     double cx0, cy0, radius0, cx1, cy1, radius1;
 
@@ -128,14 +125,11 @@
 			  &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
 	return NULL;
 
-    pattern = cairo_pattern_create_radial (cx0, cy0, radius0,
+    pattern = cairo_pattern_create_radial (cx0, cy0, radius0, 
 					   cx1, cy1, radius1);
     if (!pattern)
 	return PyErr_NoMemory();
-    p = PycairoPattern_FromPattern(pattern);
-    if (!p)
-	cairo_pattern_destroy(pattern);
-    return p;
+    return PycairoPattern_FromPattern (pattern);
 }
 
 static PyObject *

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- pycairo-surface.c	16 May 2005 01:05:28 -0000	1.39
+++ pycairo-surface.c	17 May 2005 01:36:57 -0000	1.40
@@ -55,23 +55,28 @@
 
 /* PycairoSurface_FromSurface
  * Create a new PycairoSurface from a cairo_surface_t
- * Return value: New reference (NULL on failure)
- *
- * base - the base object used to create the surface, or NULL.
- *        it is referenced to keep it alive while the surface
- *        is being used
+ * surface - a cairo_surface_t to 'wrap' into a Python object.
+ *           it is unreferenced if the PycairoSurface creation fails
+ * base - the base object used to create the context, or NULL.
+ *        it is referenced to keep it alive while the cairo_surface_t is 
+ *        being used
+ * Return value: New reference or NULL on failure
  */
 PyObject *
 PycairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base)
 {
-    PycairoSurface *s = (PycairoSurface *)PycairoSurface_Type.tp_new
-	(&PycairoSurface_Type, NULL, NULL);
+    PyObject *s;
+
+    assert (surface != NULL);
+    s = PycairoSurface_Type.tp_alloc (&PycairoSurface_Type, 0);
     if (s) {
-	s->surface = surface;
+	((PycairoSurface *)s)->surface = surface;
 	Py_XINCREF(base);
-	s->base = base;
+	((PycairoSurface *)s)->base = base;
+    } else {
+	cairo_surface_destroy (surface);
     }
-    return (PyObject *) s;
+    return s;
 }
 
 static void
@@ -110,7 +115,6 @@
 static PyObject *
 surface_create_similar(PycairoSurface *s, PyObject *args)
 {
-    PyObject *s2;
     cairo_surface_t *surface;
     cairo_format_t format;
     int width, height;
@@ -124,12 +128,10 @@
 	return PyErr_NoMemory();
 
     /* bug #2765 - "How do we identify surface types?"
-     * determine surface type and use PycairoImageSurface_FromImageSurface() etc
+     * determine surface type and use PycairoImageSurface_FromImageSurface() 
+     * etc
      */
-    s2 = PycairoSurface_FromSurface(surface, NULL);
-    if (!s2)
-	cairo_surface_destroy(surface);
-    return s2;
+    return PycairoSurface_FromSurface (surface, NULL);
 }
 
 static PyObject *
@@ -244,14 +246,18 @@
 PyObject *
 PycairoImageSurface_FromImageSurface(cairo_surface_t *surface, PyObject *base)
 {
-    PycairoImageSurface *s = (PycairoImageSurface *)PycairoImageSurface_Type.tp_new
-	(&PycairoImageSurface_Type, NULL, NULL);
+    PyObject *s;
+
+    assert (surface != NULL);
+    s = PycairoImageSurface_Type.tp_alloc (&PycairoImageSurface_Type, 0);
     if (s) {
-	s->surface = surface;
+	((PycairoImageSurface *)s)->surface = surface;
 	Py_XINCREF(base);
-	s->base = base;
+	((PycairoImageSurface *)s)->base = base;
+    } else {
+	cairo_surface_destroy (surface);
     }
-    return (PyObject *) s;
+    return s;
 }
 
 static int
@@ -277,7 +283,6 @@
 static PyObject *
 image_surface_create_for_array(PyTypeObject *type, PyObject *args)
 {
-    PyObject *s;
     PyArrayObject *array;
     cairo_format_t format;
     cairo_surface_t *surface;
@@ -331,11 +336,7 @@
 						  array->strides[0]);
     if (!surface)
 	return PyErr_NoMemory();
-
-    s = PycairoImageSurface_FromImageSurface(surface, (PyObject *)array);
-    if (!s)
-	cairo_surface_destroy(surface);
-    return s;
+    return PycairoImageSurface_FromImageSurface(surface, (PyObject *)array);
 }
 #endif /* HAVE_NUMPY */
 
@@ -344,7 +345,6 @@
 static PyObject *
 image_surface_create_for_data(PyTypeObject *type, PyObject *args)
 {
-    PyObject *s;
     cairo_surface_t *surface;
     char *data;
     cairo_format_t format;
@@ -388,10 +388,7 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    s = PycairoImageSurface_FromImageSurface(surface, NULL);
-    if (!s)
-	cairo_surface_destroy(surface);
-    return s;
+    return PycairoImageSurface_FromImageSurface (surface, NULL);
     /* FIXME: get surface to hold a reference to buffer */
 }
 #endif
@@ -401,7 +398,6 @@
 static PyObject *
 image_surface_create_from_png(PyTypeObject *type, PyObject *args)
 {
-    PyObject *s;
     const char *filename;
     cairo_surface_t *surface;
 
@@ -414,10 +410,7 @@
 			"not be allocated for operation");
 	return NULL;
     }
-    s = PycairoImageSurface_FromImageSurface(surface, NULL);
-    if (!s)
-	cairo_surface_destroy(surface);
-    return s;
+    return PycairoImageSurface_FromImageSurface (surface, NULL);
 }
 #endif /* CAIRO_HAS_PNG_FUNCTIONS */
 
@@ -507,14 +500,16 @@
 PyObject *
 PycairoPDFSurface_FromPDFSurface(cairo_surface_t *surface, PyObject *base)
 {
-    PycairoPDFSurface *s = (PycairoPDFSurface *)PycairoPDFSurface_Type.tp_new
-	(&PycairoPDFSurface_Type, NULL, NULL);
+    PyObject *s;
+
+    assert (surface != NULL);
+    s = PycairoPDFSurface_Type.tp_alloc (&PycairoPDFSurface_Type, 0);
     if (s) {
-	s->surface = surface;
+	((PycairoPDFSurface *)s)->surface = surface;
 	Py_XINCREF(base);
-	s->base = base;
+	((PycairoPDFSurface *)s)->base = base;
     }
-    return (PyObject *) s;
+    return s;
 }
 
 static int




More information about the cairo-commit mailing list