[cairo-commit] pycairo/cairo cairomodule.c, 1.17, 1.18 cairogtkmodule.c, 1.13, 1.14 caironumpymodule.c, 1.5, 1.6 pycairo-pattern.c, 1.12, 1.13 pycairo-surface.c, 1.18, 1.19 pycairo-private.h, 1.10, 1.11 pycairo.h, 1.15, 1.16 pycairo-context.c, 1.30, 1.31

Steve Chaplin commit at pdx.freedesktop.org
Sun Apr 10 03:50:07 PDT 2005


Committed by: stevech1097

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

Modified Files:
	cairomodule.c cairogtkmodule.c caironumpymodule.c 
	pycairo-pattern.c pycairo-surface.c pycairo-private.h 
	pycairo.h pycairo-context.c 
Log Message:
SC 2005/04/10

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cairomodule.c	4 Apr 2005 16:16:49 -0000	1.17
+++ cairomodule.c	10 Apr 2005 10:50:05 -0000	1.18
@@ -86,15 +86,17 @@
     }
 }
 
-#ifdef CAIRO_HAS_PS_SURFACE
+#if 0
+#ifdef CAIRO_HAS_PDF_SURFACE
 static PyObject *
-pycairo_ps_surface_create(PyObject *self, PyObject *args)
+pycairo_pdf_surface_create(PyObject *self, PyObject *args)
 {
+    PyObject *py_surface;
     PyObject *file_object;
     int width_inches, height_inches, x_pixels_per_inch, y_pixels_per_inch;
     cairo_surface_t *surface;
 
-    if (!PyArg_ParseTuple(args, "O!iiii:ps_surface_create",
+    if (!PyArg_ParseTuple(args, "O!iiii:pdf_surface_create",
 			  &PyFile_Type, &file_object, &width_inches, &height_inches, &x_pixels_per_inch, &y_pixels_per_inch))
 	return NULL;
     if (width_inches <= 0) {
@@ -113,25 +115,31 @@
 	PyErr_SetString(PyExc_ValueError, "y_pixels_per_inch must be positive");
 	return NULL;
     }
-    surface = cairo_ps_surface_create(PyFile_AsFile(file_object), width_inches, height_inches, x_pixels_per_inch, y_pixels_per_inch);
+    surface = cairo_pdf_surface_create(PyFile_AsFile(file_object), width_inches, height_inches, x_pixels_per_inch, y_pixels_per_inch);
     if (!surface)
 	return PyErr_NoMemory();
 
-    return pycairo_surface_wrap(surface);
+    py_surface = pycairo_surface_wrap(surface, file_object);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return py_surface;
 }
-#endif /* CAIRO_HAS_PS_SURFACE */
+#endif /* CAIRO_HAS_PDF_SURFACE */
+#endif
 
-#if 0
-#ifdef CAIRO_HAS_PDF_SURFACE
+#ifdef CAIRO_HAS_PS_SURFACE
 static PyObject *
-pycairo_pdf_surface_create(PyObject *self, PyObject *args)
+pycairo_ps_surface_create(PyObject *self, PyObject *args)
 {
+    PyObject *py_surface;
     PyObject *file_object;
     int width_inches, height_inches, x_pixels_per_inch, y_pixels_per_inch;
     cairo_surface_t *surface;
 
-    if (!PyArg_ParseTuple(args, "O!iiii:pdf_surface_create",
-			  &PyFile_Type, &file_object, &width_inches, &height_inches, &x_pixels_per_inch, &y_pixels_per_inch))
+    if (!PyArg_ParseTuple(args, "O!iiii:ps_surface_create",
+			  &PyFile_Type, &file_object, &width_inches, 
+			  &height_inches, &x_pixels_per_inch, 
+			  &y_pixels_per_inch))
 	return NULL;
     if (width_inches <= 0) {
 	PyErr_SetString(PyExc_ValueError, "width_inches must be positive");
@@ -149,45 +157,18 @@
 	PyErr_SetString(PyExc_ValueError, "y_pixels_per_inch must be positive");
 	return NULL;
     }
-    surface = cairo_pdf_surface_create(PyFile_AsFile(file_object), width_inches, height_inches, x_pixels_per_inch, y_pixels_per_inch);
-    if (!surface)
-	return PyErr_NoMemory();
-
-    return pycairo_surface_wrap(surface);
-}
-#endif /* CAIRO_HAS_PDF_SURFACE */
-#endif
-
-#ifdef CAIRO_HAS_PNG_SURFACE
-static PyObject *
-pycairo_png_surface_create(PyObject *self, PyObject *args)
-{
-    PyObject *file_object;
-    cairo_format_t format;
-    int width, height;
-    cairo_surface_t *surface;
-
-    if (!PyArg_ParseTuple(args, "O!iii:png_surface_create",
-			  &PyFile_Type, &file_object, &format, &width, &height))
-	return NULL;
-
-    if (width <= 0) {
-	PyErr_SetString(PyExc_ValueError, "width must be positive");
-	return NULL;
-    }
-    if (height <= 0) {
-	PyErr_SetString(PyExc_ValueError, "height must be positive");
-	return NULL;
-    }
-
-    surface = cairo_png_surface_create(PyFile_AsFile(file_object), format, width, height);
+    surface = cairo_ps_surface_create(PyFile_AsFile(file_object), width_inches,
+				      height_inches, x_pixels_per_inch, 
+				      y_pixels_per_inch);
     if (!surface)
 	return PyErr_NoMemory();
 
-    return pycairo_surface_wrap(surface);
+    py_surface = pycairo_surface_wrap(surface, file_object);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return py_surface;
 }
-#endif /* CAIRO_HAS_PNG_SURFACE */
-
+#endif /* CAIRO_HAS_PS_SURFACE */
 
 static PyMethodDef cairo_functions[] = {
 #if 0
@@ -195,9 +176,6 @@
     { "pdf_surface_create", (PyCFunction)pycairo_pdf_surface_create, METH_VARARGS, "" },
 #endif
 #endif
-#ifdef CAIRO_HAS_PNG_SURFACE
-    { "png_surface_create", (PyCFunction)pycairo_png_surface_create, METH_VARARGS, "" },
-#endif
 #ifdef CAIRO_HAS_PS_SURFACE
     { "ps_surface_create", (PyCFunction)pycairo_ps_surface_create, METH_VARARGS, "" },
 #endif

Index: cairogtkmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairogtkmodule.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- cairogtkmodule.c	19 Mar 2005 04:51:39 -0000	1.13
+++ cairogtkmodule.c	10 Apr 2005 10:50:05 -0000	1.14
@@ -28,7 +28,7 @@
  * the specific language governing rights and limitations.
  *
  * Contributor(s):
- *
+ *                 Steve Chaplin
  */
 
 #ifdef HAVE_CONFIG_H
@@ -108,6 +108,7 @@
 static PyObject *
 surface_create_for_drawable(PyObject *self, PyObject *args)
 {
+    PyObject *py_surface;
     PyGObject *py_drawable;
     GdkDrawable *gdk_drawable;
     cairo_format_t format = CAIRO_FORMAT_ARGB32;
@@ -127,12 +128,56 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    return pycairo_surface_wrap(surface);
+    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_drawable);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return py_surface;
+}
+
+static PyObject *
+surface_create_for_pixbuf(PyObject *self, PyObject *args)
+{
+    PyObject *py_surface;
+    PyGObject *py_pixbuf;
+    GdkPixbuf *gdk_pixbuf;
+    cairo_surface_t *surface;
+
+    if (!PyArg_ParseTuple(args, "O!:surface_create_for_pixbuf",
+			  &PyGdkPixbuf_Type, &py_pixbuf))
+	return NULL;
+
+    gdk_pixbuf = GDK_PIXBUF(py_pixbuf->obj);
+
+    /* this is the only format that matches cairo's image format.
+     * GdkPixbuf uses RGBA, while Cairo uses ARGB, so we can't handle
+     * pixbufs with alpha. */
+    if (gdk_pixbuf_get_colorspace(gdk_pixbuf) != GDK_COLORSPACE_RGB ||
+	gdk_pixbuf_get_bits_per_sample(gdk_pixbuf) != 8 ||
+	gdk_pixbuf_get_n_channels(gdk_pixbuf) != 4) {
+	PyErr_SetString(PyExc_ValueError,
+			"can only create a surface from a 24-bit RGB pixbuf "
+			"(ie. no alpha)");
+	return NULL;
+    }
+    surface = cairo_image_surface_create_for_data
+	(gdk_pixbuf_get_pixels(gdk_pixbuf),
+	 CAIRO_FORMAT_RGB24,
+	 gdk_pixbuf_get_width(gdk_pixbuf),
+	 gdk_pixbuf_get_height(gdk_pixbuf),
+	 gdk_pixbuf_get_rowstride(gdk_pixbuf));
+    if (!surface)
+	return PyErr_NoMemory();
+
+    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_pixbuf);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return py_surface;
 }
 
 static PyObject *
 surface_create_for_pixmap(PyObject *self, PyObject *args)
 {
+    PyObject *py_surface;
     PyGObject *py_pixmap;
     GdkDrawable *gdk_pixmap;
     cairo_surface_t *surface;
@@ -157,12 +202,16 @@
     gdk_drawable_get_size (gdk_pixmap, &width, &height);
     cairo_xlib_surface_set_size (surface, width, height);
 
-    return pycairo_surface_wrap(surface);
+    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_pixmap);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return py_surface;
 }
 
 static PyObject *
 surface_create_for_pixmap_with_visual(PyObject *self, PyObject *args)
 {
+    PyObject *py_surface;
     PyGObject *py_pixmap, *py_visual;
     GdkDrawable *gdk_pixmap;
     GdkVisual *gdk_visual;
@@ -187,12 +236,16 @@
     gdk_drawable_get_size (gdk_pixmap, &width, &height);
     cairo_xlib_surface_set_size (surface, width, height);
 
-    return pycairo_surface_wrap(surface);
+    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_pixmap);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return py_surface;
 }
 
 static PyObject *
 surface_create_for_window_with_visual(PyObject *self, PyObject *args)
 {
+    PyObject *py_surface;
     PyGObject *py_window, *py_visual;
     GdkVisual *gdk_visual;
     GdkWindow *gdk_window;
@@ -217,49 +270,10 @@
     gdk_drawable_get_size (gdk_window, &width, &height);
     cairo_xlib_surface_set_size (surface, width, height);
 
-    return pycairo_surface_wrap(surface);
-}
-
-static PyObject *
-surface_create_for_pixbuf(PyObject *self, PyObject *args)
-{
-    PyGObject *py_pixbuf;
-    GdkPixbuf *gdk_pixbuf;
-    cairo_surface_t *surface;
-
-    if (!PyArg_ParseTuple(args, "O!:surface_create_for_pixbuf",
-			  &PyGdkPixbuf_Type, &py_pixbuf))
-	return NULL;
-
-    gdk_pixbuf = GDK_PIXBUF(py_pixbuf->obj);
-
-    /* this is the only format that matches cairo's image format.
-     * GdkPixbuf uses RGBA, while Cairo uses ARGB, so we can't handle
-     * pixbufs with alpha. */
-    if (gdk_pixbuf_get_colorspace(gdk_pixbuf) != GDK_COLORSPACE_RGB ||
-	gdk_pixbuf_get_bits_per_sample(gdk_pixbuf) != 8 ||
-	gdk_pixbuf_get_n_channels(gdk_pixbuf) != 4) {
-	PyErr_SetString(PyExc_ValueError,
-			"can only create a surface from a 24-bit RGB pixbuf "
-			"(ie. no alpha)");
-	return NULL;
-    }
-    surface = cairo_image_surface_create_for_data
-	(gdk_pixbuf_get_pixels(gdk_pixbuf),
-	 CAIRO_FORMAT_RGB24,
-	 gdk_pixbuf_get_width(gdk_pixbuf),
-	 gdk_pixbuf_get_height(gdk_pixbuf),
-	 gdk_pixbuf_get_rowstride(gdk_pixbuf));
-    if (!surface)
-	return PyErr_NoMemory();
-
-    /* The output buffer (the pixbuf) must be kept around until the
-       cairo_surface_t is destroyed or cairo_surface_finish() is called on the
-       surface.  
-       TODO: surface should reference the pixbuf to keep it alive.
-             and unref when surface destroyed/finished
-     */
-    return pycairo_surface_wrap(surface);
+    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_window);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return (PyObject *)py_surface;
 }
 
 static PyMethodDef cairogtk_functions[] = {

Index: caironumpymodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/caironumpymodule.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- caironumpymodule.c	11 Mar 2005 17:03:05 -0000	1.5
+++ caironumpymodule.c	10 Apr 2005 10:50:05 -0000	1.6
@@ -40,6 +40,7 @@
 static PyObject *
 surface_create_for_array(PyObject *self, PyObject *args)
 {
+    PyObject *py_surface;
     PyArrayObject *array;
     cairo_format_t format;
     int nd;
@@ -91,12 +92,10 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    /* The output buffer (data) must be kept around until the cairo_surface_t is
-       destroyed or cairo_surface_finish() is called on the surface.
-       TODO: surface should reference the array to keep it alive.
-             and unref when surface destroyed/finished
-     */
-    return pycairo_surface_wrap(surface);
+    py_surface = pycairo_surface_wrap(surface, (PyObject *)array);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return py_surface;
 }
 
 static PyMethodDef caironumpy_functions[] = {

Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pycairo-pattern.c	9 Apr 2005 07:33:17 -0000	1.12
+++ pycairo-pattern.c	10 Apr 2005 10:50:05 -0000	1.13
@@ -55,6 +55,9 @@
 static void
 pycairo_pattern_dealloc(PyCairoPattern *self)
 {
+#ifdef DEBUG
+    printf("pattern_dealloc start\n");
+#endif
     if (self->pattern)
 	cairo_pattern_destroy(self->pattern);
     self->pattern = NULL;
@@ -63,6 +66,9 @@
 	self->ob_type->tp_free((PyObject *)self);
     else
 	PyObject_Del(self);
+#ifdef DEBUG
+    printf("pattern_dealloc end\n");
+#endif
 }
 
 /* pycairo_pattern_new()
@@ -185,15 +191,10 @@
 static PyObject *
 pycairo_pattern_get_matrix(PyCairoPattern *self)
 {
-    cairo_matrix_t *matrix;
-
-    matrix = cairo_matrix_create();
-    if (!matrix)
-	return PyErr_NoMemory();
+    cairo_matrix_t matrix;
 
-    /* always returns status = success */
-    cairo_pattern_get_matrix(self->pattern, matrix);
-    return pycairo_matrix_wrap(matrix);
+    cairo_pattern_get_matrix(self->pattern, &matrix);
+    return pycairo_matrix_wrap(&matrix);
 }
 
 static PyObject *

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- pycairo-surface.c	9 Apr 2005 07:28:15 -0000	1.18
+++ pycairo-surface.c	10 Apr 2005 10:50:05 -0000	1.19
@@ -38,35 +38,48 @@
 #include "pycairo-private.h"
 #include "pycairo-misc.h"
 
+/* pycairo_surface_wrap
+ * take a cairo_surface_t and return a PyCairoSurface
+ * which holds the cairo_surface_t
+ *
+ * base - the base object used to create the surface, or NULL.
+ *        it is referenced to keep it alive while the surface
+ *        is being used
+ */
 PyObject *
-pycairo_surface_wrap(cairo_surface_t *surface)
+pycairo_surface_wrap(cairo_surface_t *surface, PyObject *base)
 {
-    PyCairoSurface *self;
+    // TODO - check base is actually a PyObject* or NULL
 
-    self = PyObject_New(PyCairoSurface, &PyCairoSurface_Type);
-    if (!self) {
-	cairo_surface_destroy(surface);
-	return NULL;
+    PyCairoSurface *self = PyObject_New(PyCairoSurface, &PyCairoSurface_Type);
+    if (self) {
+	self->surface = surface;
+	self->base = base;
+	Py_XINCREF(base);
     }
-
-    self->surface = surface;
-
     return (PyObject *)self;
 }
 
 static void
 pycairo_surface_dealloc(PyCairoSurface *self)
 {
-    /*printf("surface_dealloc start\n");*/
-    if (self->surface)
+#ifdef DEBUG
+    printf("surface_dealloc start\n");
+#endif
+    if (self->surface) {
 	cairo_surface_destroy(self->surface);
-    self->surface = NULL;
+	self->surface = NULL;
+    }
+
+    Py_CLEAR(self->base);
 
     if (self->ob_type->tp_free)
 	self->ob_type->tp_free((PyObject *)self);
     else
 	PyObject_Del(self);
-    /*printf("surface_dealloc end\n");*/
+#ifdef DEBUG
+    printf("surface_dealloc end\n");
+#endif
 }
 
 static PyObject *
@@ -83,6 +96,7 @@
     self = (PyCairoSurface *)type->tp_alloc(type, 0);
     if (self){
 	self->surface = cairo_image_surface_create (format, width, height);
+	self->base = NULL;
 	if (!self->surface){
 	    Py_DECREF(self);
 	    return PyErr_NoMemory();
@@ -137,6 +151,7 @@
     if (py_surface){
 	py_surface->surface = cairo_image_surface_create_for_data
 	    ((unsigned char *)data, format, width, height, stride);
+	py_surface->base = NULL;
 	if (!py_surface->surface) {
 	    Py_DECREF(py_surface);
 	    return PyErr_NoMemory();
@@ -162,6 +177,7 @@
     if (py_surface){
 	py_surface->surface = cairo_image_surface_create_for_png
 	    (PyFile_AsFile(file_object), &width, &height);
+	py_surface->base = NULL;
 	if (!py_surface->surface) {
 	    Py_DECREF(py_surface);
 	    PyErr_SetString(PyExc_ValueError, "invalid PNG file or memory could not be allocated for operation");
@@ -184,6 +200,7 @@
 static PyObject *
 pycairo_surface_create_similar(PyCairoSurface *self, PyObject *args)
 {
+    PyObject *py_surface;
     cairo_surface_t *surface;
     cairo_format_t format;
     int width, height;
@@ -196,7 +213,25 @@
 					   width, height);
     if (!surface)
 	return PyErr_NoMemory();
-    return pycairo_surface_wrap(surface);
+
+    py_surface = pycairo_surface_wrap(surface, NULL);
+    if (!py_surface)
+	cairo_surface_destroy(surface);
+    return py_surface;
+}
+
+static PyObject *
+pycairo_surface_finish(PyCairoSurface *self)
+{
+    cairo_status_t status = cairo_surface_finish(self->surface);
+    Py_CLEAR(self->base);
+
+    if (pycairo_check_status(status))
+	return NULL;
+    Py_RETURN_NONE;
+    /* Segmentation fault when call surface.finish() twice
+     * https://bugs.freedesktop.org  bug #2950 Apr 10 2005
+    */
 }
 
 static PyObject *
@@ -289,7 +324,7 @@
 	return NULL;
     Py_RETURN_NONE;
 }
-#endif  /* CAIRO_HAS_PDF_FUNCTIONS */
+#endif  /* CAIRO_HAS_PNG_FUNCTIONS */
 
 static PyMethodDef pycairo_surface_methods[] = {
     { "create_for_data", (PyCFunction)pycairo_surface_create_for_data, 
@@ -300,7 +335,7 @@
 #endif
     { "create_similar", (PyCFunction)pycairo_surface_create_similar,
       METH_VARARGS },
-    /* (image_)surface_create_for_png */
+    { "finish",     (PyCFunction)pycairo_surface_finish,     METH_NOARGS },
     { "set_device_offset", (PyCFunction)pycairo_surface_set_device_offset, 
       METH_VARARGS },
     { "set_filter", (PyCFunction)pycairo_surface_set_filter, METH_VARARGS },
@@ -341,7 +376,7 @@
     (setattrofunc)0,                    /* tp_setattro */
     0,                                  /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT,                 /* tp_flags */
-    NULL, /* Documentation string */
+    NULL,                               /* Documentation string */
     (traverseproc)0,                    /* tp_traverse */
     (inquiry)0,                         /* tp_clear */
     (richcmpfunc)0,                     /* tp_richcompare */
@@ -356,7 +391,6 @@
     0,                                  /* tp_descr_get */
     0,                                  /* tp_descr_set */
     0,                                  /* tp_dictoffset */
-    //(initproc)pycairo_surface_init,     /* tp_init */
     (initproc)0,                        /* tp_init */
     (allocfunc)0,                       /* tp_alloc */
     pycairo_surface_new,                /* tp_new */

Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- pycairo-private.h	8 Apr 2005 03:24:49 -0000	1.10
+++ pycairo-private.h	10 Apr 2005 10:50:05 -0000	1.11
@@ -42,19 +42,19 @@
 #include "pycairo.h"
 
 
-extern PyTypeObject PyCairoMatrix_Type;
 extern PyTypeObject PyCairoContext_Type;
-extern PyTypeObject PyCairoSurface_Type;
-extern PyTypeObject PyCairoPattern_Type;
 extern PyTypeObject PyCairoFont_Type;
+extern PyTypeObject PyCairoMatrix_Type;
+extern PyTypeObject PyCairoPattern_Type;
+extern PyTypeObject PyCairoSurface_Type;
 
 int       pycairo_check_status(cairo_status_t status);
 
 /* takes ownership of reference */
-PyObject *pycairo_matrix_wrap(cairo_matrix_t *matrix);
 PyObject *pycairo_context_wrap(cairo_t *ctx);
-PyObject *pycairo_surface_wrap(cairo_surface_t *surface);
-PyObject *pycairo_pattern_wrap(cairo_pattern_t *pattern);
 PyObject *pycairo_font_wrap(cairo_font_face_t *font);
+PyObject *pycairo_matrix_wrap(cairo_matrix_t *matrix);
+PyObject *pycairo_pattern_wrap(cairo_pattern_t *pattern);
+PyObject *pycairo_surface_wrap(cairo_surface_t *surface, PyObject *base);
 
 #endif /* _PYCAIRO_PRIVATE_H_ */

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- pycairo.h	8 Apr 2005 08:51:17 -0000	1.15
+++ pycairo.h	10 Apr 2005 10:50:05 -0000	1.16
@@ -42,18 +42,13 @@
 
 typedef struct {
     PyObject_HEAD
-    cairo_matrix_t matrix;
-} PyCairoMatrix;
-
-typedef struct {
-    PyObject_HEAD
     cairo_t *ctx;
 } PyCairoContext;
 
 typedef struct {
     PyObject_HEAD
-    cairo_surface_t *surface;
-} PyCairoSurface;
+    cairo_font_face_t *font;
+} PyCairoFont;
 
 typedef struct {
     PyObject_HEAD
@@ -62,15 +57,21 @@
 
 typedef struct {
     PyObject_HEAD
-    cairo_font_face_t *font;
-} PyCairoFont;
+    cairo_matrix_t matrix;
+} PyCairoMatrix;
+
+typedef struct {
+    PyObject_HEAD
+    cairo_surface_t *surface;
+    PyObject *base; /* base object used to create surface, or NULL */
+} PyCairoSurface;
 
 struct _PyCairo_FunctionStruct {
     int (* check_status)(cairo_status_t status);
     PyTypeObject *matrix_type;
     PyObject *(* matrix_wrap)(cairo_matrix_t *matrix);
     PyTypeObject *surface_type;
-    PyObject *(* surface_wrap)(cairo_surface_t *surface);
+    PyObject *(* surface_wrap)(cairo_surface_t *surface, PyObject *base);
     PyTypeObject *font_type;
     PyObject *(* font_wrap)(cairo_font_face_t *font);
     PyTypeObject *context_type;

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- pycairo-context.c	9 Apr 2005 07:28:15 -0000	1.30
+++ pycairo-context.c	10 Apr 2005 10:50:05 -0000	1.31
@@ -55,7 +55,9 @@
 static void
 pycairo_dealloc(PyCairoContext *self)
 {
-    /*printf("context_dealloc start\n");*/
+#ifdef DEBUG
+    printf("context_dealloc start\n");
+#endif
     if (self->ctx)
 	cairo_destroy(self->ctx);
     self->ctx = NULL;
@@ -64,7 +66,9 @@
 	self->ob_type->tp_free((PyObject *)self);
     else
 	PyObject_Del(self);
-    /*printf("context_dealloc end\n");*/
+#ifdef DEBUG
+    printf("context_dealloc end\n");
+#endif
 }
 
 static PyObject *
@@ -899,7 +903,6 @@
 	pycairo_check_status(cairo_status(self->ctx));
 	return NULL;
     }
-    /*cairo_font_reference(font);*/
     cairo_font_face_reference(font);
     return pycairo_font_wrap(font);
 }
@@ -973,20 +976,26 @@
 static PyObject *
 pycairo_get_target_surface(PyCairoContext *self)
 {
-    cairo_surface_t *surface;
-
-    surface = cairo_get_target_surface(self->ctx);
+    PyObject *py_surface;
+    /* This function is scheduled to be removed as part of the upcoming API 
+       Shakeup.*/
+    cairo_surface_t *surface = cairo_get_target_surface(self->ctx);
     if (!surface)
-	Py_RETURN_NONE;
+	return PyErr_NoMemory();
 
-    cairo_surface_reference(surface);
-    return pycairo_surface_wrap(surface);
+    py_surface = pycairo_surface_wrap(surface, NULL);
+    if (py_surface)
+	cairo_surface_reference(surface);
+    return py_surface;
 }
 
 static PyObject *
 pycairo_get_pattern(PyCairoContext *self)
 {
-    return pycairo_pattern_wrap(cairo_get_pattern(self->ctx));
+    /* TODO - change referencing to match Surface */
+    cairo_pattern_t *pattern = cairo_get_pattern(self->ctx);
+
+    return pycairo_pattern_wrap(pattern);
 }
 
 /* struct and wrappers for cairo_get_path() */ 




More information about the cairo-commit mailing list