summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Chaplin <stevech1097@yahoo.com.au>2010-05-06 10:02:24 +0800
committerSteve Chaplin <stevech1097@yahoo.com.au>2010-05-06 10:02:24 +0800
commit4a36f79a26e84cbd16e75f7cebee574472226878 (patch)
tree2ed9ba3770cfbef7b96fe44c2992c0093869b93d
parentda0b9ea7438b1501e90c3e79b8e5a045459cc792 (diff)
downloadpy2cairo-4a36f79a26e84cbd16e75f7cebee574472226878.tar.gz
Modify matrix_new to use PycairoMatrix_FromMatrix.
-rw-r--r--src/matrix.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/matrix.c b/src/matrix.c
index 2ec5e2d..59e177a 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -37,16 +37,16 @@
/* PycairoMatrix_FromMatrix
* Create a new PycairoMatrix from a cairo_matrix_t
- * matrix - a cairo_matrix_t to 'wrap' into a Python object
+ * matrix - a cairo_matrix_t to 'wrap' into a Python object.
+ * the cairo_matrix_t values are copied.
* Return value: New reference or NULL on failure
*/
PyObject *
PycairoMatrix_FromMatrix (const cairo_matrix_t *matrix) {
- PyObject *o;
assert (matrix != NULL);
- o = PycairoMatrix_Type.tp_alloc (&PycairoMatrix_Type, 0);
+ PyObject *o = PycairoMatrix_Type.tp_alloc (&PycairoMatrix_Type, 0);
if (o != NULL)
- ((PycairoMatrix *)o)->matrix = *matrix;
+ ((PycairoMatrix *)o)->matrix = *matrix; // copy struct
return o;
}
@@ -57,7 +57,6 @@ matrix_dealloc (PycairoMatrix *o) {
static PyObject *
matrix_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
- PyObject *o;
static char *kwlist[] = { "xx", "yx", "xy", "yy", "x0", "y0", NULL };
double xx = 1.0, yx = 0.0, xy = 0.0, yy = 1.0, x0 = 0.0, y0 = 0.0;
@@ -66,11 +65,9 @@ matrix_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
&xx, &yx, &xy, &yy, &x0, &y0))
return NULL;
- o = type->tp_alloc(type, 0);
- if (o)
- cairo_matrix_init (&((PycairoMatrix *)o)->matrix,
- xx, yx, xy, yy, x0, y0);
- return o;
+ cairo_matrix_t mx;
+ cairo_matrix_init (&mx, xx, yx, xy, yy, x0, y0);
+ return PycairoMatrix_FromMatrix (&mx);
}
static PyObject *