[cairo] [PATCH 1/2] observer: Return status when printing the observed data

Andrea Canciani ranma42 at gmail.com
Sat Feb 11 06:11:16 PST 2012


Making cairo_surface_observer_print() and
cairo_device_observer_print() return the status of the observer or of
the stream makes it possible to correctly track what kind of error
happens if the print is not successful.

This makes the functions more consistent with existing API with a
similar signature like cairo_surface_write_to_png_stream().
---
 src/cairo-surface-observer.c |   24 ++++++++++++------------
 src/cairo.h                  |    4 ++--
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/cairo-surface-observer.c b/src/cairo-surface-observer.c
index e5d3371..3ac0892 100644
--- a/src/cairo-surface-observer.c
+++ b/src/cairo-surface-observer.c
@@ -1957,7 +1957,7 @@ _cairo_observation_print (cairo_output_stream_t *stream,
     cairo_device_destroy (script);
 }
 
-void
+cairo_status_t
 cairo_surface_observer_print (cairo_surface_t *abstract_surface,
 			      cairo_write_func_t write_func,
 			      void *closure)
@@ -1965,17 +1965,17 @@ cairo_surface_observer_print (cairo_surface_t *abstract_surface,
     cairo_output_stream_t *stream;
     cairo_surface_observer_t *surface;
 
-    if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_surface->ref_count)))
-	return;
+    if (unlikely (abstract_surface->status))
+	return abstract_surface->status;
 
-    if (! _cairo_surface_is_observer (abstract_surface))
-	return;
+    if (unlikely (! _cairo_surface_is_observer (abstract_surface)))
+	return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
 
     surface = (cairo_surface_observer_t *) abstract_surface;
 
     stream = _cairo_output_stream_create (write_func, NULL, closure);
     _cairo_observation_print (stream, &surface->log);
-    _cairo_output_stream_destroy (stream);
+    return _cairo_output_stream_destroy (stream);
 }
 
 double
@@ -1993,7 +1993,7 @@ cairo_surface_observer_elapsed (cairo_surface_t *abstract_surface)
     return _cairo_time_to_ns (_cairo_observation_total_elapsed (&surface->log));
 }
 
-void
+cairo_status_t
 cairo_device_observer_print (cairo_device_t *abstract_device,
 			     cairo_write_func_t write_func,
 			     void *closure)
@@ -2001,17 +2001,17 @@ cairo_device_observer_print (cairo_device_t *abstract_device,
     cairo_output_stream_t *stream;
     cairo_device_observer_t *device;
 
-    if (unlikely (CAIRO_REFERENCE_COUNT_IS_INVALID (&abstract_device->ref_count)))
-	return;
+    if (unlikely (abstract_device->status))
+	return abstract_device->status;
 
-    if (! _cairo_device_is_observer (abstract_device))
-	return;
+    if (unlikely (! _cairo_device_is_observer (abstract_device)))
+	return _cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH);
 
     device = (cairo_device_observer_t *) abstract_device;
 
     stream = _cairo_output_stream_create (write_func, NULL, closure);
     _cairo_observation_print (stream, &device->log);
-    _cairo_output_stream_destroy (stream);
+    return _cairo_output_stream_destroy (stream);
 }
 
 double
diff --git a/src/cairo.h b/src/cairo.h
index a64a8a0..0a004f3 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -2192,14 +2192,14 @@ cairo_surface_observer_add_finish_callback (cairo_surface_t *abstract_surface,
 					    cairo_surface_observer_callback_t func,
 					    void *data);
 
-cairo_public void
+cairo_public cairo_status_t
 cairo_surface_observer_print (cairo_surface_t *surface,
 			      cairo_write_func_t write_func,
 			      void *closure);
 cairo_public double
 cairo_surface_observer_elapsed (cairo_surface_t *surface);
 
-cairo_public void
+cairo_public cairo_status_t
 cairo_device_observer_print (cairo_device_t *device,
 			     cairo_write_func_t write_func,
 			     void *closure);
-- 
1.7.5.4



More information about the cairo mailing list