[cairo-commit] pycairo/cairo cairomodule.c, 1.20, 1.21 pycairo-context.c, 1.32, 1.33 pycairo-pattern.c, 1.13, 1.14 pycairo.h, 1.18, 1.19 pycairo-private.h, 1.13, 1.14

Steve Chaplin commit at pdx.freedesktop.org
Wed Apr 13 07:14:20 PDT 2005


Committed by: stevech1097

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

Modified Files:
	cairomodule.c pycairo-context.c pycairo-pattern.c pycairo.h 
	pycairo-private.h 
Log Message:
SC 2005/04/13

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/cairomodule.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- cairomodule.c	13 Apr 2005 10:20:04 -0000	1.20
+++ cairomodule.c	13 Apr 2005 14:14:18 -0000	1.21
@@ -185,10 +185,10 @@
 static struct _PyCairo_FunctionStruct api = {
     pycairo_check_status,
     &PyCairoMatrix_Type,   PyCairoMatrix_FromMatrix,
+    &PyCairoPattern_Type,  PyCairoPattern_FromPattern,
     &PyCairoSurface_Type,  PyCairoSurface_FromSurface,
     &PyCairoFont_Type,     pycairo_font_wrap,
     &PyCairoContext_Type,  pycairo_context_wrap,
-    &PyCairoPattern_Type,  pycairo_pattern_wrap,
 };
 
 DL_EXPORT(void)

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- pycairo-context.c	13 Apr 2005 10:20:04 -0000	1.32
+++ pycairo-context.c	13 Apr 2005 14:14:18 -0000	1.33
@@ -992,10 +992,17 @@
 static PyObject *
 pycairo_get_pattern(PyCairoContext *self)
 {
-    /* TODO - change referencing to match Surface */
+    PyObject *py_pattern;
     cairo_pattern_t *pattern = cairo_get_pattern(self->ctx);
 
-    return pycairo_pattern_wrap(pattern);
+    if (!pattern)
+	return PyErr_NoMemory();
+
+    py_pattern = PyCairoPattern_FromPattern(pattern);
+    if (py_pattern)
+	cairo_pattern_reference(pattern);
+    return py_pattern;
+
 }
 
 /* struct and wrappers for cairo_get_path() */ 

Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- pycairo-pattern.c	10 Apr 2005 10:50:05 -0000	1.13
+++ pycairo-pattern.c	13 Apr 2005 14:14:18 -0000	1.14
@@ -38,101 +38,110 @@
 #include "pycairo-misc.h"
 
 
-/* wrap an existing cairo_pattern_t in a PyCairoPattern object */
+/* PyCairoPattern_FromPattern
+ * Create a new PyCairoPattern from a cairo_pattern_t
+ * Return value: New reference (NULL on failure)
+ */
 PyObject *
-pycairo_pattern_wrap(cairo_pattern_t *pattern)
+PyCairoPattern_FromPattern(cairo_pattern_t *pattern)
 {
-    PyCairoPattern *self;
-
-    self = PyObject_New(PyCairoPattern, &PyCairoPattern_Type);
-    if (self) {
-	cairo_pattern_reference(pattern);
-	self->pattern = pattern;
-    }
-    return (PyObject *)self;
+    PyCairoPattern *p = (PyCairoPattern *)PyCairoPattern_Type.tp_new
+	(&PyCairoPattern_Type, NULL, NULL);
+    if (p)
+	p->pattern = pattern;
+    return (PyObject *) p;
 }
 
 static void
-pycairo_pattern_dealloc(PyCairoPattern *self)
+pattern_dealloc(PyCairoPattern *p)
 {
 #ifdef DEBUG
     printf("pattern_dealloc start\n");
 #endif
-    if (self->pattern)
-	cairo_pattern_destroy(self->pattern);
-    self->pattern = NULL;
-
-    if (self->ob_type->tp_free)
-	self->ob_type->tp_free((PyObject *)self);
-    else
-	PyObject_Del(self);
+    if (p->pattern) {
+	cairo_pattern_destroy(p->pattern);
+	p->pattern = NULL;
+    }
+    p->ob_type->tp_free((PyObject *)p);
 #ifdef DEBUG
     printf("pattern_dealloc end\n");
 #endif
 }
 
-/* pycairo_pattern_new()
- * pycairo_pattern_init()
- * not used, use alternative constructors instead
- */
+static PyObject *
+pattern_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    return type->tp_alloc(type, 0);
+}
+
+/* pattern_init() - not used, use alternative constructors instead */
 
 /* alternative constructor */
 static PyObject *
-pycairo_pattern_create_for_surface(PyTypeObject *type, PyObject *args)
+pattern_create_for_surface(PyTypeObject *type, PyObject *args)
 {
-    PyCairoPattern *py_pattern;
-    PyCairoSurface *py_surface;
+    PyObject *p;
+    PyCairoSurface *s;
+    cairo_pattern_t *pattern;
 
     if (!PyArg_ParseTuple(args, "O!:Pattern.create_for_surface", 
-			  &PyCairoSurface_Type, &py_surface))
+			  &PyCairoSurface_Type, &s))
 	return NULL;
 
-    py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
-    if (py_pattern)
-	py_pattern->pattern = 
-	    cairo_pattern_create_for_surface (py_surface->surface);
-    return (PyObject *)py_pattern;
+    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;
 }
 
 /* alternative constructor */
 static PyObject *
-pycairo_pattern_create_linear(PyTypeObject *type, PyObject *args)
+pattern_create_linear(PyTypeObject *type, PyObject *args)
 {
-    PyCairoPattern *py_pattern;
+    PyObject *p;
     double x0, y0, x1, y1;
+    cairo_pattern_t *pattern;
     
     if (!PyArg_ParseTuple(args, "dddd:Pattern.create_linear", 
 			  &x0, &y0, &x1, &y1))
 	return NULL;
 
-    py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
-    if (py_pattern)
-	py_pattern->pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
-
-    return (PyObject *)py_pattern;
+    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;
 }
 
 /* alternative constructor */
 static PyObject *
-pycairo_pattern_create_radial(PyTypeObject *type, PyObject *args)
+pattern_create_radial(PyTypeObject *type, PyObject *args)
 {
-    PyCairoPattern *py_pattern;
+    PyObject *p;
+    cairo_pattern_t *pattern;
     double cx0, cy0, radius0, cx1, cy1, radius1;
 
     if (!PyArg_ParseTuple(args, "dddddd:Pattern.create_radial", 
 			  &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
 	return NULL;
 
-    py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
-    if (py_pattern)
-	py_pattern->pattern = cairo_pattern_create_radial (cx0, cy0, radius0,
-							   cx1, cy1, radius1);
-
-    return (PyObject *)py_pattern;
+    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;
 }
 
 static PyObject *
-pycairo_pattern_add_color_stop(PyCairoPattern *self, PyObject *args)
+pattern_add_color_stop(PyCairoPattern *p, PyObject *args)
 {
     double offset, red, green, blue, alpha;
     cairo_status_t status;
@@ -141,7 +150,7 @@
 			  &offset, &red, &green, &blue, &alpha))
 	return NULL;
 
-    status = cairo_pattern_add_color_stop (self->pattern, offset, red, green, 
+    status = cairo_pattern_add_color_stop (p->pattern, offset, red, green, 
 					   blue, alpha);
     if (pycairo_check_status(status))
 	return NULL;
@@ -149,7 +158,7 @@
 }
 
 static PyObject *
-pycairo_pattern_set_matrix(PyCairoPattern *self, PyObject *args)
+pattern_set_matrix(PyCairoPattern *p, PyObject *args)
 {
     PyCairoMatrix *matrix;
 
@@ -158,12 +167,12 @@
 	return NULL;
 
     /* always returns status = success */
-    cairo_pattern_set_matrix(self->pattern, &matrix->matrix);
+    cairo_pattern_set_matrix(p->pattern, &matrix->matrix);
     Py_RETURN_NONE;
 }
 
 static PyObject *
-pycairo_pattern_set_extend(PyCairoPattern *self, PyObject *args)
+pattern_set_extend(PyCairoPattern *p, PyObject *args)
 {
     int extend;
 
@@ -171,12 +180,12 @@
  	return NULL;
  
     /* always returns status = success */
-    cairo_pattern_set_extend(self->pattern, extend);
+    cairo_pattern_set_extend(p->pattern, extend);
     Py_RETURN_NONE;
 }
  
 static PyObject *
-pycairo_pattern_set_filter(PyCairoPattern *self, PyObject *args)
+pattern_set_filter(PyCairoPattern *p, PyObject *args)
 {
     int filter;
 
@@ -184,95 +193,94 @@
 	return NULL;
 
     /* always returns status = success */
-    cairo_pattern_set_filter(self->pattern, filter);
+    cairo_pattern_set_filter(p->pattern, filter);
     Py_RETURN_NONE;
 }
  
 static PyObject *
-pycairo_pattern_get_matrix(PyCairoPattern *self)
+pattern_get_matrix(PyCairoPattern *p)
 {
     cairo_matrix_t matrix;
 
-    cairo_pattern_get_matrix(self->pattern, &matrix);
-    return pycairo_matrix_wrap(&matrix);
+    cairo_pattern_get_matrix(p->pattern, &matrix);
+    return PyCairoMatrix_FromMatrix(&matrix);
 }
 
 static PyObject *
-pycairo_pattern_get_extend(PyCairoPattern *self)
+pattern_get_extend(PyCairoPattern *p)
 {
-    return PyInt_FromLong(cairo_pattern_get_extend(self->pattern));
+    return PyInt_FromLong(cairo_pattern_get_extend(p->pattern));
 }
 
 static PyObject *
-pycairo_pattern_get_filter(PyCairoPattern *self)
+pattern_get_filter(PyCairoPattern *p)
 {
-    return PyInt_FromLong(cairo_pattern_get_filter(self->pattern));
+    return PyInt_FromLong(cairo_pattern_get_filter(p->pattern));
 }
 
  
-static PyMethodDef pycairo_pattern_methods[] = {
-    { "add_color_stop", (PyCFunction)pycairo_pattern_add_color_stop, 
-                                                             METH_VARARGS },
-    { "create_for_surface", (PyCFunction)pycairo_pattern_create_for_surface, 
-                                                METH_VARARGS | METH_CLASS },
-    { "create_linear", (PyCFunction)pycairo_pattern_create_linear, 
-                                                METH_VARARGS | METH_CLASS },
-    { "create_radial", (PyCFunction)pycairo_pattern_create_radial, 
-                                                METH_VARARGS | METH_CLASS },
-    { "set_extend", (PyCFunction)pycairo_pattern_set_extend, METH_VARARGS },
-    { "set_filter", (PyCFunction)pycairo_pattern_set_filter, METH_VARARGS },
-    { "set_matrix", (PyCFunction)pycairo_pattern_set_matrix, METH_VARARGS },
+static PyMethodDef pattern_methods[] = {
+    { "add_color_stop",   (PyCFunction)pattern_add_color_stop,  METH_VARARGS },
+    { "create_for_surface",(PyCFunction)pattern_create_for_surface, 
+                                                   METH_VARARGS | METH_CLASS },
+    { "create_linear",    (PyCFunction)pattern_create_linear, 
+                                                   METH_VARARGS | METH_CLASS },
+    { "create_radial",    (PyCFunction)pattern_create_radial, 
+                                                   METH_VARARGS | METH_CLASS },
+    { "set_extend",       (PyCFunction)pattern_set_extend,      METH_VARARGS },
+    { "set_filter",       (PyCFunction)pattern_set_filter,      METH_VARARGS },
+    { "set_matrix",       (PyCFunction)pattern_set_matrix,      METH_VARARGS },
     { NULL, NULL, 0 }
 };
 
-static PyGetSetDef pycairo_pattern_getsets[] = {
-    { "extend", (getter)pycairo_pattern_get_extend, (setter)0 },
-    { "filter", (getter)pycairo_pattern_get_filter, (setter)0 },
-    { "matrix", (getter)pycairo_pattern_get_matrix, (setter)0 },
+static PyGetSetDef pattern_getsets[] = {
+    { "extend", (getter)pattern_get_extend, (setter)0 },
+    { "filter", (getter)pattern_get_filter, (setter)0 },
+    { "matrix", (getter)pattern_get_matrix, (setter)0 },
     { NULL, (getter)0, (setter)0 }
 };
 
 PyTypeObject PyCairoPattern_Type = {
-    PyObject_HEAD_INIT(NULL)
+    PyObject_HEAD_INIT(&PyType_Type)
     0,                                  /* ob_size */
     "cairo.Pattern",                    /* tp_name */
     sizeof(PyCairoPattern),             /* tp_basicsize */
     0,                                  /* tp_itemsize */
-    (destructor)pycairo_pattern_dealloc, /* tp_dealloc */
-    (printfunc)0,                       /* tp_print */
-    (getattrfunc)0,                     /* tp_getattr */
-    (setattrfunc)0,                     /* tp_setattr */
-    (cmpfunc)0,                         /* tp_compare */
-    (reprfunc)0,                        /* tp_repr */
+    (destructor)pattern_dealloc,        /* tp_dealloc */
+    0,                                  /* tp_print */
+    0,                                  /* tp_getattr */
+    0,                                  /* tp_setattr */
+    0,                                  /* tp_compare */
+    0,                                  /* tp_repr */
     0,                                  /* tp_as_number */
     0,                                  /* tp_as_sequence */
     0,                                  /* tp_as_mapping */
-    (hashfunc)0,                        /* tp_hash */
-    (ternaryfunc)0,                     /* tp_call */
-    (reprfunc)0,                        /* tp_str */
-    (getattrofunc)0,                    /* tp_getattro */
-    (setattrofunc)0,                    /* tp_setattro */
+    0,                                  /* tp_hash */
+    0,                                  /* tp_call */
+    0,                                  /* tp_str */
+    0,                                  /* tp_getattro */
+    0,                                  /* tp_setattro */
     0,                                  /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
     "Pattern objects",                  /* tp_doc */
-    (traverseproc)0,                    /* tp_traverse */
-    (inquiry)0,                         /* tp_clear */
-    (richcmpfunc)0,                     /* tp_richcompare */
+    0,                                  /* tp_traverse */
+    0,                                  /* tp_clear */
+    0,                                  /* tp_richcompare */
     0,                                  /* tp_weaklistoffset */
-    (getiterfunc)0,                     /* tp_iter */
-    (iternextfunc)0,                    /* tp_iternext */
-    pycairo_pattern_methods,            /* tp_methods */
+    0,                                  /* tp_iter */
+    0,                                  /* tp_iternext */
+    pattern_methods,                    /* tp_methods */
     0,                                  /* tp_members */
-    pycairo_pattern_getsets,            /* tp_getset */
-    (PyTypeObject *)0,                  /* tp_base */
-    (PyObject *)0,                      /* tp_dict */
+    pattern_getsets,                    /* tp_getset */
+    &PyBaseObject_Type,                 /* tp_base */
+    0,                                  /* tp_dict */
     0,                                  /* tp_descr_get */
     0,                                  /* tp_descr_set */
     0,                                  /* tp_dictoffset */
-    (initproc)0,                        /* tp_init */
-    (allocfunc)0,                       /* tp_alloc */
-    0,                                  /* tp_new */
+    0,                                  /* tp_init */
+    0,                                  /* tp_alloc */
+    (newfunc)pattern_new,               /* tp_new */
     0,                                  /* tp_free */
-    (inquiry)0,                         /* tp_is_gc */
-    (PyObject *)0,                      /* tp_bases */
+    0,                                  /* tp_is_gc */
+    0,                                  /* tp_bases */
 };

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- pycairo.h	13 Apr 2005 10:20:04 -0000	1.18
+++ pycairo.h	13 Apr 2005 14:14:18 -0000	1.19
@@ -70,14 +70,14 @@
     int (* check_status)(cairo_status_t status);
     PyTypeObject *matrix_type;
     PyObject *(* matrix_wrap)(cairo_matrix_t *matrix);
+    PyTypeObject *pattern_type;
+    PyObject *(* pattern_wrap)(cairo_pattern_t *pattern);
     PyTypeObject *surface_type;
     PyObject *(* surface_wrap)(cairo_surface_t *surface, PyObject *base);
     PyTypeObject *font_type;
     PyObject *(* font_wrap)(cairo_font_face_t *font);
     PyTypeObject *context_type;
     PyObject *(* context_wrap)(cairo_t *ctx);
-    PyTypeObject *pattern_type;
-    PyObject *(* pattern_wrap)(cairo_pattern_t *pattern);
 };
 
 #ifndef _INSIDE_PYCAIRO_
@@ -88,17 +88,17 @@
 struct _PyCairo_FunctionStruct *_PyCairo_API;
 #endif
 
-#define pycairo_check_status (_PyCairo_API->check_status)
-#define PyCairoMatrix_Type  *(_PyCairo_API->matrix_type)
-#define PyCairoMatrix_FromMatrix (_PyCairo_API->matrix_wrap)
-#define PyCairoSurface_Type *(_PyCairo_API->surface_type)
+#define pycairo_check_status       (_PyCairo_API->check_status)
+#define PyCairoMatrix_Type        *(_PyCairo_API->matrix_type)
+#define PyCairoMatrix_FromMatrix   (_PyCairo_API->matrix_wrap)
+#define PyCairoPattern_Type       *(_PyCairo_API->pattern_type)
+#define PyCairoPattern_FromPattern (_PyCairo_API->pattern_wrap)
+#define PyCairoSurface_Type       *(_PyCairo_API->surface_type)
 #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)
-#define pycairo_context_wrap (_PyCairo_API->context_wrap)
-#define PyCairoPattern_Type *(_PyCairo_API->pattern_type)
-#define pycairo_pattern_wrap (_PyCairo_API->pattern_wrap)
+#define PyCairoFont_Type          *(_PyCairo_API->font_type)
+#define pycairo_font_wrap          (_PyCairo_API->font_wrap)
+#define PyCairoContext_Type       *(_PyCairo_API->context_type)
+#define pycairo_context_wrap       (_PyCairo_API->context_wrap)
 
 #define init_pycairo() { \
     PyObject *pycairo = PyImport_ImportModule("cairo._cairo"); \

Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-private.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- pycairo-private.h	13 Apr 2005 10:20:04 -0000	1.13
+++ pycairo-private.h	13 Apr 2005 14:14:18 -0000	1.14
@@ -54,7 +54,7 @@
 PyObject *pycairo_context_wrap(cairo_t *ctx);
 PyObject *pycairo_font_wrap(cairo_font_face_t *font);
 PyObject *PyCairoMatrix_FromMatrix(const cairo_matrix_t *matrix);
-PyObject *pycairo_pattern_wrap(cairo_pattern_t *pattern);
+PyObject *PyCairoPattern_FromPattern(cairo_pattern_t *pattern);
 PyObject *PyCairoSurface_FromSurface(cairo_surface_t *surface, PyObject *base);
 
 #endif /* _PYCAIRO_PRIVATE_H_ */




More information about the cairo-commit mailing list