[cairo-commit] pycairo/cairo pycairo-surface.c,1.96,1.97

Steve Chaplin commit at pdx.freedesktop.org
Fri Mar 20 20:33:49 PDT 2009


Committed by: stevech1097

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

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

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- pycairo-surface.c	3 Mar 2009 12:40:23 -0000	1.96
+++ pycairo-surface.c	21 Mar 2009 03:33:47 -0000	1.97
@@ -468,26 +468,29 @@
 static cairo_status_t
 _read_func (void *closure, unsigned char *data, unsigned int length)
 {
-    char *str;
+    char *buffer;
+    Py_ssize_t str_length;
+    cairo_status_t status = CAIRO_STATUS_READ_ERROR;
     PyGILState_STATE gstate = PyGILState_Ensure();
     PyObject *pystr = PyObject_CallMethod ((PyObject *)closure, "read", "(i)",
 					   length);
-    if (pystr == NULL){
+    if (pystr == NULL) {
 	/* an exception has occurred, it will be picked up later by
 	 * Pycairo_Check_Status()
 	 */
-	PyGILState_Release(gstate);
-	return CAIRO_STATUS_READ_ERROR;
+	goto end;
+    }
+    int ret = PyString_AsStringAndSize(pystr, &buffer, &str_length);
+    if (ret == -1 || str_length < length) {
+	goto end;
     }
-    str = PyString_AsString(pystr);
-    Py_DECREF(pystr);
-    PyGILState_Release(gstate);
-
-    if (str == NULL)
-	return CAIRO_STATUS_READ_ERROR;
     /* don't use strncpy() since png data may contain NUL bytes */
-    memcpy (data, str, length);
-    return CAIRO_STATUS_SUCCESS;
+    memcpy (data, buffer, str_length);
+    status = CAIRO_STATUS_SUCCESS;
+ end:
+    Py_XDECREF(pystr);
+    PyGILState_Release(gstate);
+    return status;
 }
 
 /* METH_O | METH_CLASS */



More information about the cairo-commit mailing list