[cairo-commit] pycairo/cairo pycairo-context.c,1.75,1.76

Steve Chaplin commit at pdx.freedesktop.org
Wed Dec 27 18:44:25 PST 2006


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory kemper:/tmp/cvs-serv26296/cairo

Modified Files:
	pycairo-context.c 
Log Message:
'SC'

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-context.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- pycairo-context.c	27 Dec 2006 10:32:21 -0000	1.75
+++ pycairo-context.c	28 Dec 2006 02:44:21 -0000	1.76
@@ -44,6 +44,14 @@
 	}                                     \
     } while (0)
 
+#define RETURN_NULL_IF_STATUS_ERROR(status)   \
+    do {                                      \
+	if (status != CAIRO_STATUS_SUCCESS) { \
+	    Pycairo_Check_Status (status);    \
+            return NULL;		      \
+	}                                     \
+    } while (0)
+
 
 /* Take a PyBaseString (str or unicode) object and return a pointer to the
  * UTF-8 encoded string.
@@ -331,6 +339,45 @@
 }
 
 static PyObject *
+pycairo_get_dash (PycairoContext *o)
+{
+    double *dashes = NULL, offset;
+    int count, i;
+    PyObject *py_dashes = NULL, *rv = NULL;
+    cairo_status_t status;
+
+    status = cairo_get_dash_count (o->ctx, &count);
+    RETURN_NULL_IF_STATUS_ERROR(status);
+
+    dashes = PyMem_Malloc (count * sizeof(double));
+    if (dashes == NULL)
+	return PyErr_NoMemory();
+
+    status = cairo_get_dash (o->ctx, dashes, &offset);
+    if (status != CAIRO_STATUS_SUCCESS) {
+	Pycairo_Check_Status (status);
+	goto exit;
+    }
+
+    py_dashes = PyTuple_New(count);
+    if (py_dashes == NULL)
+	goto exit;
+
+    for (i = 0; i < count; i++) {
+	PyObject *dash = PyFloat_FromDouble(dashes[i]);
+	if (dash == NULL)
+	    goto exit;
+	PyTuple_SET_ITEM (py_dashes, i, dash);
+    }
+    rv = Py_BuildValue("(Od)", py_dashes, offset);
+
+ exit:
+    PyMem_Free (dashes);
+    Py_XDECREF(py_dashes);
+    return rv;
+}
+
+static PyObject *
 pycairo_get_dash_count (PycairoContext *o)
 {
     int count;
@@ -745,7 +792,7 @@
 pycairo_set_dash (PycairoContext *o, PyObject *args)
 {
     double *dashes, offset = 0;
-    int ndash, i;
+    int num_dashes, i;
     PyObject *py_dashes;
 
     if (!PyArg_ParseTuple (args, "O|d:Context.set_dash", &py_dashes, &offset))
@@ -753,25 +800,27 @@
 
     py_dashes = PySequence_Fast (py_dashes,
 				 "first argument must be a sequence");
-    if (!py_dashes)
+    if (py_dashes == NULL)
 	return NULL;
 
-    ndash = PySequence_Fast_GET_SIZE(py_dashes);
-    dashes = malloc (ndash * sizeof(double));
-    for (i = 0; i < ndash; i++) {
-	PyObject *item = PySequence_Fast_GET_ITEM(py_dashes, i);
+    num_dashes = PySequence_Fast_GET_SIZE(py_dashes);
+    dashes = PyMem_Malloc (num_dashes * sizeof(double));
+    if (dashes == NULL) {
+	Py_DECREF(py_dashes);
+	return PyErr_NoMemory();
+    }
 
-	dashes[i] = PyFloat_AsDouble(item);
+    for (i = 0; i < num_dashes; i++) {
+	dashes[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(py_dashes, i));
 	if (PyErr_Occurred()) {
-	    free (dashes);
+	    PyMem_Free (dashes);
 	    Py_DECREF(py_dashes);
 	    return NULL;
 	}
     }
+    cairo_set_dash (o->ctx, dashes, num_dashes, offset);
+    PyMem_Free (dashes);
     Py_DECREF(py_dashes);
-
-    cairo_set_dash (o->ctx, dashes, ndash, offset);
-    free (dashes);
     RETURN_NULL_IF_CONTEXT_STATUS_ERROR(o);
     Py_RETURN_NONE;
 }
@@ -1166,6 +1215,7 @@
     {"font_extents",    (PyCFunction)pycairo_font_extents,    METH_NOARGS},
     {"get_antialias",   (PyCFunction)pycairo_get_antialias,   METH_NOARGS},
     {"get_current_point",(PyCFunction)pycairo_get_current_point,METH_NOARGS},
+    {"get_dash",        (PyCFunction)pycairo_get_dash,        METH_NOARGS},
     {"get_dash_count",  (PyCFunction)pycairo_get_dash_count,  METH_NOARGS},
     {"get_fill_rule",   (PyCFunction)pycairo_get_fill_rule,   METH_NOARGS},
     {"get_font_face",   (PyCFunction)pycairo_get_font_face,   METH_NOARGS},



More information about the cairo-commit mailing list