[cairo-commit] pycairo/cairo pycairo-surface.c,1.71,1.72

Steve Chaplin commit at pdx.freedesktop.org
Fri May 26 08:32:16 PDT 2006


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory kemper:/tmp/cvs-serv25931/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.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- pycairo-surface.c	26 May 2006 04:55:58 -0000	1.71
+++ pycairo-surface.c	26 May 2006 15:32:14 -0000	1.72
@@ -226,29 +226,18 @@
 
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
 static cairo_status_t
-_write_func1 (void *closure, const unsigned char *data, unsigned int length)
-{
-    if (fwrite (data, 1, (size_t) length, (FILE *)closure) != length)
-	return CAIRO_STATUS_WRITE_ERROR;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-_write_func2 (void *closure, const unsigned char *data, unsigned int length)
+_write_func (void *closure, const unsigned char *data, unsigned int length)
 {
     PyObject *res = PyObject_CallMethod ((PyObject *)closure, "write", "(s#)",
 					 data, length);
-    if (res == NULL) {
-	printf ("res==NUL error\n\n");
+    if (res == NULL)
 	return CAIRO_STATUS_WRITE_ERROR;
-
-    }
     Py_DECREF(res);
     return CAIRO_STATUS_SUCCESS;
 }
 
 static PyObject *
-err_closed (void)
+_err_closed (void)
 {
     PyErr_SetString(PyExc_ValueError, "I/O operation on closed file");
     return NULL;
@@ -258,33 +247,14 @@
 static PyObject *
 surface_write_to_png (PycairoSurface *o, PyObject *file)
 {
-    FILE *fp = NULL;
     cairo_status_t status;
 
     if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
-	fp = fopen (PyString_AsString(file), "wb");
-	if (fp == NULL) {
-	    PyErr_SetString(PyExc_IOError, "unable to open file for writing");
-	    return NULL;
-	}
-	status = cairo_surface_write_to_png_stream (o->surface, _write_func1,
-						    fp);
-    	fclose (fp);
-
-    } else if (PyObject_TypeCheck (file, &PyFile_Type)) {
-	fp = PyFile_AsFile(file);
-
-	/* check file.closed is False */
-	PyObject* closed = PyObject_GetAttrString (file, "closed");
-	if (closed == Py_True) {
-	    Py_DECREF(closed);
-	    return err_closed();
-	}
-	Py_DECREF(closed);
-	status = cairo_surface_write_to_png_stream (o->surface, _write_func1,
-						    fp);
+	/* string (filename) argument */
+	status = cairo_surface_write_to_png (o->surface,
+					     PyString_AsString(file));
 
-    } else {
+    } else {  /* file or file-like object argument */
 	PyObject* writer = PyObject_GetAttrString (file, "write");
 	if (writer == NULL || !PyCallable_Check (writer)) {
 	    Py_XDECREF(writer);
@@ -303,10 +273,10 @@
 	    return NULL;
 	} else if (closed == Py_True) {
 	    Py_DECREF(closed);
-	    return err_closed();
+	    return _err_closed();
 	}
 	Py_DECREF(closed);
-	status = cairo_surface_write_to_png_stream (o->surface, _write_func2,
+	status = cairo_surface_write_to_png_stream (o->surface, _write_func,
 						    file);
     }
 



More information about the cairo-commit mailing list