[cairo-commit] pycairo/cairo cairogtkmodule.c, 1.14, 1.15 cairomodule.c, 1.19, 1.20 caironumpymodule.c, 1.6, 1.7 pycairo-context.c, 1.31, 1.32 pycairo.h, 1.17, 1.18 pycairo-private.h, 1.12, 1.13 pycairo-surface.c, 1.21, 1.22 pycairo-matrix.c, 1.9, 1.10

Steve Chaplin commit at pdx.freedesktop.org
Wed Apr 13 03:20:06 PDT 2005


Committed by: stevech1097

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

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

Index: cairogtkmodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairogtkmodule.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cairogtkmodule.c	10 Apr 2005 10:50:05 -0000	1.14
+++ cairogtkmodule.c	13 Apr 2005 10:20:04 -0000	1.15
@@ -128,7 +128,7 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_drawable);
+    py_surface = PyCairoSurface_FromSurface(surface, (PyObject *)py_drawable);
     if (!py_surface)
 	cairo_surface_destroy(surface);
     return py_surface;
@@ -168,7 +168,7 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_pixbuf);
+    py_surface = PyCairoSurface_FromSurface(surface, (PyObject *)py_pixbuf);
     if (!py_surface)
 	cairo_surface_destroy(surface);
     return py_surface;
@@ -202,7 +202,7 @@
     gdk_drawable_get_size (gdk_pixmap, &width, &height);
     cairo_xlib_surface_set_size (surface, width, height);
 
-    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_pixmap);
+    py_surface = PyCairoSurface_FromSurface(surface, (PyObject *)py_pixmap);
     if (!py_surface)
 	cairo_surface_destroy(surface);
     return py_surface;
@@ -236,7 +236,7 @@
     gdk_drawable_get_size (gdk_pixmap, &width, &height);
     cairo_xlib_surface_set_size (surface, width, height);
 
-    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_pixmap);
+    py_surface = PyCairoSurface_FromSurface(surface, (PyObject *)py_pixmap);
     if (!py_surface)
 	cairo_surface_destroy(surface);
     return py_surface;
@@ -270,7 +270,7 @@
     gdk_drawable_get_size (gdk_window, &width, &height);
     cairo_xlib_surface_set_size (surface, width, height);
 
-    py_surface = pycairo_surface_wrap(surface, (PyObject *)py_window);
+    py_surface = PyCairoSurface_FromSurface(surface, (PyObject *)py_window);
     if (!py_surface)
 	cairo_surface_destroy(surface);
     return (PyObject *)py_surface;

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cairomodule.c	12 Apr 2005 13:19:40 -0000	1.19
+++ cairomodule.c	13 Apr 2005 10:20:04 -0000	1.20
@@ -119,7 +119,7 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    py_surface = pycairo_surface_wrap(surface, file_object);
+    py_surface = PyCairoSurface_FromSurface(surface, file_object);
     if (!py_surface)
 	cairo_surface_destroy(surface);
     return py_surface;
@@ -163,7 +163,7 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    py_surface = pycairo_surface_wrap(surface, file_object);
+    py_surface = PyCairoSurface_FromSurface(surface, file_object);
     if (!py_surface)
 	cairo_surface_destroy(surface);
     return py_surface;
@@ -185,7 +185,7 @@
 static struct _PyCairo_FunctionStruct api = {
     pycairo_check_status,
     &PyCairoMatrix_Type,   PyCairoMatrix_FromMatrix,
-    &PyCairoSurface_Type,  pycairo_surface_wrap,
+    &PyCairoSurface_Type,  PyCairoSurface_FromSurface,
     &PyCairoFont_Type,     pycairo_font_wrap,
     &PyCairoContext_Type,  pycairo_context_wrap,
     &PyCairoPattern_Type,  pycairo_pattern_wrap,

Index: caironumpymodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/caironumpymodule.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- caironumpymodule.c	10 Apr 2005 10:50:05 -0000	1.6
+++ caironumpymodule.c	13 Apr 2005 10:20:04 -0000	1.7
@@ -92,7 +92,7 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    py_surface = pycairo_surface_wrap(surface, (PyObject *)array);
+    py_surface = PyCairoSurface_FromSurface(surface, (PyObject *)array);
     if (!py_surface)
 	cairo_surface_destroy(surface);
     return py_surface;

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- pycairo-context.c	10 Apr 2005 10:50:05 -0000	1.31
+++ pycairo-context.c	13 Apr 2005 10:20:04 -0000	1.32
@@ -983,7 +983,7 @@
     if (!surface)
 	return PyErr_NoMemory();
 
-    py_surface = pycairo_surface_wrap(surface, NULL);
+    py_surface = PyCairoSurface_FromSurface(surface, NULL);
     if (py_surface)
 	cairo_surface_reference(surface);
     return py_surface;

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- pycairo.h	12 Apr 2005 13:19:40 -0000	1.17
+++ pycairo.h	13 Apr 2005 10:20:04 -0000	1.18
@@ -92,7 +92,7 @@
 #define PyCairoMatrix_Type  *(_PyCairo_API->matrix_type)
 #define PyCairoMatrix_FromMatrix (_PyCairo_API->matrix_wrap)
 #define PyCairoSurface_Type *(_PyCairo_API->surface_type)
-#define pycairo_surface_wrap (_PyCairo_API->surface_wrap)
+#define PyCairoSurface_FromSurface (_PyCairo_API->surface_wrap)
 #define PyCairoFont_Type    *(_PyCairo_API->font_type)
 #define pycairo_font_wrap    (_PyCairo_API->font_wrap)
 #define PyCairoContext_Type *(_PyCairo_API->context_type)

Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pycairo-private.h	12 Apr 2005 13:19:40 -0000	1.12
+++ pycairo-private.h	13 Apr 2005 10:20:04 -0000	1.13
@@ -53,8 +53,8 @@
 /* takes ownership of reference */
 PyObject *pycairo_context_wrap(cairo_t *ctx);
 PyObject *pycairo_font_wrap(cairo_font_face_t *font);
-PyObject *PyCairoMatrix_FromMatrix(cairo_matrix_t *matrix);
+PyObject *PyCairoMatrix_FromMatrix(const cairo_matrix_t *matrix);
 PyObject *pycairo_pattern_wrap(cairo_pattern_t *pattern);
-PyObject *pycairo_surface_wrap(cairo_surface_t *surface, PyObject *base);
+PyObject *PyCairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base);
 
 #endif /* _PYCAIRO_PRIVATE_H_ */

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- pycairo-surface.c	12 Apr 2005 13:19:40 -0000	1.21
+++ pycairo-surface.c	13 Apr 2005 10:20:04 -0000	1.22
@@ -38,20 +38,19 @@
 #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
+/* 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
  */
 PyObject *
-pycairo_surface_wrap(cairo_surface_t *surface, PyObject *base)
+PyCairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base)
 {
-    // TODO - check base is actually a PyObject* or NULL
-
-    PyCairoSurface *s = PyObject_New(PyCairoSurface, &PyCairoSurface_Type);
+    PyCairoSurface *s = (PyCairoSurface *)PyCairoSurface_Type.tp_new
+	(&PyCairoSurface_Type, NULL, NULL);
     if (s) {
 	s->surface = surface;
 	s->base = base;
@@ -73,10 +72,7 @@
 
     Py_CLEAR(s->base);
 
-    if (s->ob_type->tp_free)
-	s->ob_type->tp_free((PyObject *)s);
-    else
-	PyObject_Del(s);
+    s->ob_type->tp_free((PyObject *)s);
 #ifdef DEBUG
     printf("surface_dealloc end\n");
 #endif
@@ -85,31 +81,36 @@
 static PyObject *
 surface_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-    PyCairoSurface *s;
+    return type->tp_alloc(type, 0);
+    /* initializes memory to zeros */
+}
+
+static int
+surface_init(PyCairoSurface *s, PyObject *args, PyObject *kwds)
+{
     cairo_format_t format;
     int width, height;
 
-    if (!PyArg_ParseTuple(args, "iii:Surface.__new__",
+    if (!PyArg_ParseTuple(args, "iii:Surface.__init__",
 			  &format, &width, &height))
-	return NULL;
+	return -1;
 
-    s = (PyCairoSurface *)type->tp_alloc(type, 0);
-    if (s) {
-	s->surface = cairo_image_surface_create (format, width, height);
-	s->base = NULL;
-	if (!s->surface){
-	    Py_DECREF(s);
-	    return PyErr_NoMemory();
-	}
+    s->surface = cairo_image_surface_create (format, width, height);
+    if (!s->surface){
+	Py_DECREF(s);
+	PyErr_NoMemory();
+	return -1;
     }
-    return (PyObject *)s;
+    return 0;
 }
 
+#if 0 /* disable until a reference to the buffer is added to the surface */
 /* alternative constructor */
 static PyObject *
 surface_create_for_data(PyTypeObject *type, PyObject *args)
 {
-    PyCairoSurface *s;
+    PyObject *s;
+    cairo_surface_t *surface;
     char *data;
     cairo_format_t format;
     int length, width, height, stride = -1;
@@ -147,53 +148,50 @@
 	return NULL;
     }
 
-    s = (PyCairoSurface *)type->tp_alloc(type, 0);
-    if (s) {
-	s->surface = cairo_image_surface_create_for_data
-	    ((unsigned char *)data, format, width, height, stride);
-	s->base = NULL;
-	if (!s->surface) {
-	    Py_DECREF(s);
-	    return PyErr_NoMemory();
-	}
-	/* TODO get surface to hold reference to buffer ... */
-    }
-    return (PyObject *)s;
+    surface = cairo_image_surface_create_for_data
+	((unsigned char *)data, format, width, height, stride);
+    if (!surface)
+	return PyErr_NoMemory();
+
+    s = PyCairoSurface_FromSurface(surface, NULL);
+    if (!s)
+	cairo_surface_destroy(surface);
+    return s;
+    /* FIXME: get surface to hold a reference to buffer */
 }
+#endif
 
 /* alternative constructor */
 static PyObject *
 surface_create_for_png(PyTypeObject *type, PyObject *args)
 {
-    PyCairoSurface *s;
+    PyObject *s;
     PyObject *file_object;
-    int width, height;
+    cairo_surface_t *surface;
+    int width=0, height=0;
 
     if (!PyArg_ParseTuple(args, "O!:Surface.create_for_png",
 			  &PyFile_Type, &file_object))
 	return NULL;
 
-    s = (PyCairoSurface *)type->tp_alloc(type, 0);
-    if (s) {
-	s->surface = cairo_image_surface_create_for_png
-	    (PyFile_AsFile(file_object), &width, &height);
-	s->base = NULL;
-	if (!s->surface) {
-	    Py_DECREF(s);
-	    PyErr_SetString(PyExc_ValueError, "invalid PNG file or memory could not be allocated for operation");
-	    return NULL;
-	}
+    surface = cairo_image_surface_create_for_png
+	(PyFile_AsFile(file_object), &width, &height);
+    if (!surface) {
+	PyErr_SetString(PyExc_ValueError, "invalid PNG file or memory could not be allocated for operation");
+	return NULL;
     }
+    s = PyCairoSurface_FromSurface(surface, NULL);
+    if (!s)
+	cairo_surface_destroy(surface);
+
     return Py_BuildValue("O(ii)", s, width, height);
     /*return (PyObject *)s;*/
 
     /* Py_BuildValue increments object ref count, which we don't want
      * proposed solution of returning object only (with getter for width,height) is better 
-     */
-
-    /* wrapping cairo_image_surface_create_for_png() gives a seg fault
-     * since cairo_image_surface_create_for_png() calls fclose(file)
      *
+     * wrapping cairo_image_surface_create_for_png() gives a seg fault
+     * since cairo_image_surface_create_for_png() calls fclose(file)
      */
 }
 
@@ -209,12 +207,11 @@
 			  &format, &width, &height))
 	return NULL;
 
-    surface = cairo_surface_create_similar(s->surface, format,
-					   width, height);
+    surface = cairo_surface_create_similar(s->surface, format, width, height);
     if (!surface)
 	return PyErr_NoMemory();
 
-    s2 = pycairo_surface_wrap(surface, NULL);
+    s2 = PyCairoSurface_FromSurface(surface, NULL);
     if (!s2)
 	cairo_surface_destroy(surface);
     return s2;
@@ -328,8 +325,10 @@
 
 
 static PyMethodDef surface_methods[] = {
+#if 0
     { "create_for_data",(PyCFunction)surface_create_for_data, 
                                                    METH_VARARGS | METH_CLASS },
+#endif
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
     { "create_for_png", (PyCFunction)surface_create_for_png, 
                                                    METH_VARARGS | METH_CLASS },
@@ -385,14 +384,14 @@
     surface_methods,                    /* tp_methods */
     0,                                  /* tp_members */
     surface_getsets,                    /* tp_getset */
-    0,                                  /* tp_base */
+    &PyBaseObject_Type,                 /* tp_base */
     0,                                  /* tp_dict */
     0,                                  /* tp_descr_get */
     0,                                  /* tp_descr_set */
     0,                                  /* tp_dictoffset */
-    0,                                  /* tp_init */
+    (initproc)surface_init,             /* tp_init */
     0,                                  /* tp_alloc */
-    surface_new,                        /* tp_new */
+    (newfunc)surface_new,               /* tp_new */
     0,                                  /* tp_free */
     0,                                  /* tp_is_gc */
     0,                                  /* tp_bases */

Index: pycairo-matrix.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-matrix.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- pycairo-matrix.c	12 Apr 2005 13:19:40 -0000	1.9
+++ pycairo-matrix.c	13 Apr 2005 10:20:04 -0000	1.10
@@ -45,18 +45,12 @@
  * takes a copy of cairo_matrix_t
  */
 PyObject *
-PyCairoMatrix_FromMatrix(cairo_matrix_t *matrix)
+PyCairoMatrix_FromMatrix(const cairo_matrix_t *matrix)
 {
     PyCairoMatrix *m = (PyCairoMatrix *)PyCairoMatrix_Type.tp_new
 	(&PyCairoMatrix_Type, NULL, NULL);
-    if (m) {
-	m->matrix.xx = matrix->xx;
-	m->matrix.yx = matrix->yx;
-	m->matrix.xy = matrix->xy;
-	m->matrix.yy = matrix->yy;
-	m->matrix.x0 = matrix->x0;
-	m->matrix.y0 = matrix->y0;
-    }
+    if (m)
+	*(&m->matrix) = *matrix;
     return (PyObject *) m;
 }
 




More information about the cairo-commit mailing list