[cairo-commit] pycairo/cairo pycairo-surface.c,1.94,1.95

Steve Chaplin commit at pdx.freedesktop.org
Mon Feb 16 04:09:13 PST 2009


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory kemper:/tmp/cvs-serv9536/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.94
retrieving revision 1.95
diff -u -d -r1.94 -r1.95
--- pycairo-surface.c	1 Jan 2009 06:12:39 -0000	1.94
+++ pycairo-surface.c	16 Feb 2009 12:09:11 -0000	1.95
@@ -103,7 +103,6 @@
 	type = &PycairoSurface_Type;
 	break;
     }
-
     o = type->tp_alloc (type, 0);
     if (o == NULL) {
 	cairo_surface_destroy (surface);
@@ -122,15 +121,18 @@
 static cairo_status_t
 _write_func (void *closure, const unsigned char *data, unsigned int length)
 {
+    PyGILState_STATE gstate = PyGILState_Ensure();
     PyObject *res = PyObject_CallMethod ((PyObject *)closure, "write", "(s#)",
 					 data, (Py_ssize_t)length);
     if (res == NULL) {
 	/* an exception has occurred, it will be picked up later by
 	 * Pycairo_Check_Status()
 	 */
+	PyGILState_Release(gstate);
 	return CAIRO_STATUS_WRITE_ERROR;
     }
     Py_DECREF(res);
+    PyGILState_Release(gstate);
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -310,10 +312,10 @@
 	    return NULL;
 	}
 	Py_DECREF(writer);
-	/*Py_BEGIN_ALLOW_THREADS*/ /*seg faults reported*/
+	Py_BEGIN_ALLOW_THREADS
 	status = cairo_surface_write_to_png_stream (o->surface, _write_func,
 						    file);
-	/*Py_END_ALLOW_THREADS*/
+	Py_END_ALLOW_THREADS
     }
     RETURN_NULL_IF_CAIRO_ERROR(status);
     Py_RETURN_NONE;
@@ -467,12 +469,20 @@
 _read_func (void *closure, unsigned char *data, unsigned int length)
 {
     char *str;
+    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;
+    }
     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 */
@@ -505,9 +515,9 @@
     }
     Py_DECREF(reader);
 
-    /*Py_BEGIN_ALLOW_THREADS*/ /*seg faults reported*/
+    Py_BEGIN_ALLOW_THREADS
     is = cairo_image_surface_create_from_png_stream (_read_func, file);
-    /*Py_END_ALLOW_THREADS*/
+    Py_END_ALLOW_THREADS
     return PycairoSurface_FromSurface (is, NULL);
 }
 #endif /* CAIRO_HAS_PNG_FUNCTIONS */
@@ -712,10 +722,10 @@
     }
     Py_DECREF(writer);
 
-    /*Py_BEGIN_ALLOW_THREADS*/ /*seg faults reported*/
+    Py_BEGIN_ALLOW_THREADS
     sfc = cairo_pdf_surface_create_for_stream (_write_func, file,
 					       width_in_points, height_in_points);
-    /*Py_END_ALLOW_THREADS*/
+    Py_END_ALLOW_THREADS
     return PycairoSurface_FromSurface (sfc, file);
 }
 
@@ -818,10 +828,10 @@
     }
     Py_DECREF(writer);
 
-    /*Py_BEGIN_ALLOW_THREADS*/ /*seg faults reported*/
+    Py_BEGIN_ALLOW_THREADS
     sfc = cairo_ps_surface_create_for_stream (_write_func, file,
 					width_in_points, height_in_points);
-    /*Py_END_ALLOW_THREADS*/
+    Py_END_ALLOW_THREADS
     return PycairoSurface_FromSurface (sfc, file);
 }
 
@@ -1010,10 +1020,10 @@
     }
     Py_DECREF(writer);
 
-    /*Py_BEGIN_ALLOW_THREADS*/ /*seg faults reported*/
+    Py_BEGIN_ALLOW_THREADS
     sfc = cairo_svg_surface_create_for_stream (_write_func, file,
 					 width_in_points, height_in_points);
-    /*Py_END_ALLOW_THREADS*/
+    Py_END_ALLOW_THREADS
     return PycairoSurface_FromSurface (sfc, file);
 }
 



More information about the cairo-commit mailing list