[cairo-commit] 7 commits - build/Makefile.win32.features configure.ac util/cairo-trace

M. Joonas Pihlaja joonas at kemper.freedesktop.org
Sun Sep 13 10:34:21 PDT 2009


 build/Makefile.win32.features |    4 
 configure.ac                  |    6 
 util/cairo-trace/trace.c      |  533 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 454 insertions(+), 89 deletions(-)

New commits:
commit 71c3b2888cc81e6d55782388d14bb8d806e77d07
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Sun Sep 13 20:24:29 2009 +0300

    [win32] Sync Makefile.win32.features.
    
    Ooops.. wasn't sure if I should commit this or not.

diff --git a/build/Makefile.win32.features b/build/Makefile.win32.features
index 18293b2..bd314e9 100644
--- a/build/Makefile.win32.features
+++ b/build/Makefile.win32.features
@@ -30,6 +30,6 @@ CAIRO_HAS_PDF_SURFACE=1
 CAIRO_HAS_SVG_SURFACE=1
 CAIRO_HAS_TEST_SURFACES=0
 CAIRO_HAS_XML_SURFACE=1
-CAIRO_HAS_TRACE=1
+CAIRO_HAS_TRACE=0
 CAIRO_HAS_INTERPRETER=1
-CAIRO_HAS_SYMBOL_LOOKUP=1
+CAIRO_HAS_SYMBOL_LOOKUP=0
commit ba21f213560fa239a02ae28af4eb1d3a6b7254e5
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Sun Sep 13 18:21:38 2009 +0100

    [trace] Don't trace internal cairo calls on Solaris.
    
    On various configurations of Solaris cairo-trace likes to trace
    internal calls to the API from within cairo and cairo-trace itself. On
    Linux the slim_hidden_proto stuff avoids this by name mangling and
    symbol alias magic, but on Solaris that doesn't work so we're left
    with either no hidden symbols at all or using normal ELF hidden symbol
    attributes, but neither of those prevent internal calls to cairo from
    being traced of course.
    
    This commit provides a per-thread entry/exit trace counter for use
    when we can't use name mangling to hide internal API calls.  As a
    side-effect it may hide actual client API calls from callback
    functions called by cairo, but such use cases ought to be rare.

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index a3615e3..a3b3697 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -179,13 +179,27 @@ static bool _line_info;
 static bool _mark_dirty;
 static const cairo_user_data_key_t destroy_key;
 static pthread_once_t once_control = PTHREAD_ONCE_INIT;
+static pthread_key_t counter_key;
 
 static void _init_trace (void);
-#define ENSURE_INIT_TRACE() pthread_once (&once_control, _init_trace);
+
+#define INIT_TRACE_ONCE() pthread_once (&once_control, _init_trace)
+
+#if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun)
+# define _enter_trace() INIT_TRACE_ONCE ()
+# define _exit_trace()  do { } while (0)
+# define _should_trace() 1
+# define USE_ENTER_EXIT 0
+#else
+static void _enter_trace (void);
+static void _exit_trace (void);
+static bool _should_trace (void);
+# define USE_ENTER_EXIT 1
+#endif
 
 #if HAVE_BUILTIN_RETURN_ADDRESS && CAIRO_HAS_SYMBOL_LOOKUP
 #define _emit_line_info() do { \
-    if (_line_info && _write_lock ()) { \
+    if (_line_info && _write_lock ()) {	\
 	void *addr = __builtin_return_address(0); \
 	char caller[1024]; \
 	_trace_printf ("%% %s() called by %s\n", __FUNCTION__, \
@@ -398,10 +412,43 @@ _object_create (Type *type, const void *ptr)
     return obj;
 }
 
+#if USE_ENTER_EXIT
+static int *
+_get_counter (void)
+{
+    int *counter = pthread_getspecific (counter_key);
+    if (counter == NULL) {
+	counter = calloc(1, sizeof(int));
+	pthread_setspecific (counter_key, counter);
+    }
+    return counter;
+}
+
+static void
+_enter_trace (void)
+{
+    INIT_TRACE_ONCE ();
+    _get_counter ()[0]++;
+}
+
+static void
+_exit_trace (void)
+{
+    _get_counter ()[0]--;
+}
+
+static bool
+_should_trace (void)
+{
+    return _get_counter ()[0] <= 1;
+}
+#endif /* USE_ENTER_EXIT */
+
 static void
 _init_trace (void)
 {
     pthread_mutex_init (&Types.mutex, NULL);
+    pthread_key_create (&counter_key, free);
 
     _type_create ("unclassed", NONE, "");
     _type_create ("cairo_t", CONTEXT, "c");
@@ -434,6 +481,7 @@ _fini_trace (void)
 	}
     }
 
+    pthread_key_delete (counter_key);
     pthread_mutex_destroy (&Types.mutex);
 }
 
@@ -546,6 +594,8 @@ _trace_vprintf (const char *fmt, va_list ap)
     cairo_bool_t var_width;
     int ret_ignored;
 
+    assert (_should_trace ());
+
     f = fmt;
     p = buffer;
     while (*f != '\0') {
@@ -778,6 +828,9 @@ _write_lock (void)
     if (_error)
 	return false;
 
+    if (! _should_trace ())
+	return false;
+
     if (! _init_logfile ())
 	return false;
 
@@ -1259,6 +1312,8 @@ _write_base85_data (struct _data_stream *stream,
     unsigned char five_tuple[5];
     int ret;
 
+    assert (_should_trace ());
+
     while (length--) {
 	stream->four_tuple[stream->base85_pending++] = *data++;
 	if (stream->base85_pending == 4) {
@@ -1342,6 +1397,8 @@ _write_base85_data_end (struct _data_stream *stream)
     unsigned char five_tuple[5];
     int ret;
 
+    assert (_should_trace ());
+
     if (stream->base85_pending) {
 	memset (stream->four_tuple + stream->base85_pending,
 		0, 4 - stream->base85_pending);
@@ -1799,7 +1856,7 @@ cairo_create (cairo_surface_t *target)
     long surface_id;
     long context_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_create, target);
     context_id = _create_context_id (ret);
@@ -1822,34 +1879,38 @@ cairo_create (cairo_surface_t *target)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_save (cairo_t *cr)
-{
-    ENSURE_INIT_TRACE ();
+{ 
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "save\n");
     DLCALL (cairo_save, cr);
+    _exit_trace ();
 }
 
 void
 cairo_restore (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "restore\n");
     DLCALL (cairo_restore, cr);
+    _exit_trace ();
 }
 
 void
 cairo_push_group (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "//COLOR_ALPHA push-group\n");
     DLCALL (cairo_push_group, cr);
+    _exit_trace ();
 }
 
 static const char *
@@ -1866,10 +1927,11 @@ _content_to_string (cairo_content_t content)
 void
 cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s push-group\n", _content_to_string (content));
     DLCALL (cairo_push_group_with_content, cr, content);
+    _exit_trace ();
 }
 
 cairo_pattern_t *
@@ -1877,7 +1939,7 @@ cairo_pop_group (cairo_t *cr)
 {
     cairo_pattern_t *ret;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_pop_group, cr);
 
@@ -1885,16 +1947,18 @@ cairo_pop_group (cairo_t *cr)
     _emit_cairo_op (cr, "pop-group %% p%ld\n", _create_pattern_id (ret));
     _push_operand (PATTERN, ret);
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_pop_group_to_source (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "pop-group set-source\n");
     DLCALL (cairo_pop_group_to_source, cr);
+    _exit_trace ();
 }
 
 static const char *
@@ -1939,29 +2003,32 @@ _operator_to_string (cairo_operator_t op)
 void
 cairo_set_operator (cairo_t *cr, cairo_operator_t op)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s set-operator\n", _operator_to_string (op));
     DLCALL (cairo_set_operator, cr, op);
+    _exit_trace ();
 }
 
 void
 cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g set-source-rgb\n", red, green, blue);
     DLCALL (cairo_set_source_rgb, cr, red, green, blue);
+    _exit_trace ();
 }
 
 void
 cairo_set_source_rgba (cairo_t *cr, double red, double green, double blue, double alpha)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g %g set-source-rgba\n",
 		    red, green, blue, alpha);
     DLCALL (cairo_set_source_rgba, cr, red, green, blue, alpha);
+    _exit_trace ();
 }
 
 static void
@@ -2027,7 +2094,7 @@ _emit_source_image_rectangle (cairo_surface_t *surface,
 void
 cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface, double x, double y)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && surface != NULL && _write_lock ()) {
 	if (_is_current (SURFACE, surface, 0) &&
@@ -2058,12 +2125,13 @@ cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface, double x, doubl
     }
 
     DLCALL (cairo_set_source_surface, cr, surface, x, y);
+    _exit_trace ();
 }
 
 void
 cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && source != NULL && _write_lock ()) {
 	Object *obj = _get_object (PATTERN, source);
@@ -2098,6 +2166,7 @@ cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
     }
 
     DLCALL (cairo_set_source, cr, source);
+    _exit_trace ();
 }
 
 cairo_pattern_t *
@@ -2105,7 +2174,7 @@ cairo_get_source (cairo_t *cr)
 {
     cairo_pattern_t *ret;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_get_source, cr);
 
@@ -2115,16 +2184,18 @@ cairo_get_source (cairo_t *cr)
 	_get_object (PATTERN, ret)->defined = true;
     }
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_set_tolerance (cairo_t *cr, double tolerance)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-tolerance\n", tolerance);
     DLCALL (cairo_set_tolerance, cr, tolerance);
+    _exit_trace ();
 }
 
 static const char *
@@ -2144,11 +2215,12 @@ _antialias_to_string (cairo_antialias_t antialias)
 void
 cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-antialias\n", _antialias_to_string (antialias));
     DLCALL (cairo_set_antialias, cr, antialias);
+    _exit_trace ();
 }
 
 static const char *
@@ -2166,20 +2238,22 @@ _fill_rule_to_string (cairo_fill_rule_t rule)
 void
 cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-fill-rule\n", _fill_rule_to_string (fill_rule));
     DLCALL (cairo_set_fill_rule, cr, fill_rule);
+    _exit_trace ();
 }
 
 void
 cairo_set_line_width (cairo_t *cr, double width)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-line-width\n", width);
     DLCALL (cairo_set_line_width, cr, width);
+    _exit_trace ();
 }
 
 static const char *
@@ -2198,10 +2272,11 @@ _line_cap_to_string (cairo_line_cap_t line_cap)
 void
 cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s set-line-cap\n", _line_cap_to_string (line_cap));
     DLCALL (cairo_set_line_cap, cr, line_cap);
+    _exit_trace ();
 }
 
 static const char *
@@ -2220,17 +2295,18 @@ _line_join_to_string (cairo_line_join_t line_join)
 void
 cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-line-join\n", _line_join_to_string (line_join));
     DLCALL (cairo_set_line_join, cr, line_join);
+    _exit_trace ();
 }
 
 void
 cairo_set_dash (cairo_t *cr, const double *dashes, int num_dashes, double offset)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && _write_lock ()) {
 	int n;
@@ -2249,60 +2325,66 @@ cairo_set_dash (cairo_t *cr, const double *dashes, int num_dashes, double offset
     }
 
     DLCALL (cairo_set_dash, cr, dashes, num_dashes, offset);
+    _exit_trace ();
 }
 
 void
 cairo_set_miter_limit (cairo_t *cr, double limit)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-miter-limit\n", limit);
     DLCALL (cairo_set_miter_limit, cr, limit);
+    _exit_trace ();
 }
 
 void
 cairo_translate (cairo_t *cr, double tx, double ty)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g translate\n", tx, ty);
     DLCALL (cairo_translate, cr, tx, ty);
+    _exit_trace ();
 }
 
 void
 cairo_scale (cairo_t *cr, double sx, double sy)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g scale\n", sx, sy);
     DLCALL (cairo_scale, cr, sx, sy);
+    _exit_trace ();
 }
 
 void
 cairo_rotate (cairo_t *cr, double angle)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g rotate\n", angle);
     DLCALL (cairo_rotate, cr, angle);
+    _exit_trace ();
 }
 
 void
 cairo_transform (cairo_t *cr, const cairo_matrix_t *matrix)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g %g %g %g matrix transform\n",
 		    matrix->xx, matrix->yx,
 		    matrix->xy, matrix->yy,
 		    matrix->x0, matrix->y0);
     DLCALL (cairo_transform, cr, matrix);
+    _exit_trace ();
 }
 
 void
 cairo_set_matrix (cairo_t *cr, const cairo_matrix_t *matrix)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (_matrix_is_identity (matrix)) {
 	_emit_cairo_op (cr, "identity set-matrix\n");
@@ -2313,6 +2395,7 @@ cairo_set_matrix (cairo_t *cr, const cairo_matrix_t *matrix)
 			matrix->x0, matrix->y0);
     }
     DLCALL (cairo_set_matrix, cr, matrix);
+    _exit_trace ();
 }
 
 cairo_surface_t *
@@ -2321,7 +2404,7 @@ cairo_get_target (cairo_t *cr)
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_get_target, cr);
     surface_id = _create_surface_id (ret);
@@ -2331,6 +2414,7 @@ cairo_get_target (cairo_t *cr)
 	_get_object (SURFACE, ret)->defined = true;
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -2340,7 +2424,7 @@ cairo_get_group_target (cairo_t *cr)
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_get_group_target, cr);
     surface_id = _create_surface_id (ret);
@@ -2350,139 +2434,155 @@ cairo_get_group_target (cairo_t *cr)
 	_get_object (SURFACE, ret)->defined = true;
     }
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_identity_matrix (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "identity set-matrix\n");
     DLCALL (cairo_identity_matrix, cr);
+    _exit_trace ();
 }
 
 void
 cairo_new_path (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "n ");
     DLCALL (cairo_new_path, cr);
+    _exit_trace ();
 }
 
 void
 cairo_move_to (cairo_t *cr, double x, double y)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g m ", x, y);
     DLCALL (cairo_move_to, cr, x, y);
+    _exit_trace ();
 }
 
 void
 cairo_new_sub_path (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "N ");
     DLCALL (cairo_new_sub_path, cr);
+    _exit_trace ();
 }
 
 void
 cairo_line_to (cairo_t *cr, double x, double y)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g l ", x, y);
     DLCALL (cairo_line_to, cr, x, y);
+    _exit_trace ();
 }
 
 void
 cairo_curve_to (cairo_t *cr, double x1, double y1, double x2, double y2, double x3, double y3)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g %g %g %g %g c ", x1, y1, x2, y2, x3, y3);
     DLCALL (cairo_curve_to, cr, x1, y1, x2, y2, x3, y3);
+    _exit_trace ();
 }
 
 void
 cairo_arc (cairo_t *cr, double xc, double yc, double radius, double angle1, double angle2)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g %g %g %g arc\n", xc, yc, radius, angle1, angle2);
     DLCALL (cairo_arc, cr, xc, yc, radius, angle1, angle2);
+    _exit_trace ();
 }
 
 void
 cairo_arc_negative (cairo_t *cr, double xc, double yc, double radius, double angle1, double angle2)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g %g %g %g arc-\n",
 		    xc, yc, radius, angle1, angle2);
     DLCALL (cairo_arc_negative, cr, xc, yc, radius, angle1, angle2);
+    _exit_trace ();
 }
 
 void
 cairo_rel_move_to (cairo_t *cr, double dx, double dy)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g M ", dx, dy);
     DLCALL (cairo_rel_move_to, cr, dx, dy);
+    _exit_trace ();
 }
 
 void
 cairo_rel_line_to (cairo_t *cr, double dx, double dy)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g L ", dx, dy);
     DLCALL (cairo_rel_line_to, cr, dx, dy);
+    _exit_trace ();
 }
 
 void
 cairo_rel_curve_to (cairo_t *cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g %g %g %g %g C ",
 		    dx1, dy1, dx2, dy2, dx3, dy3);
     DLCALL (cairo_rel_curve_to, cr, dx1, dy1, dx2, dy2, dx3, dy3);
+    _exit_trace ();
 }
 
 void
 cairo_rectangle (cairo_t *cr, double x, double y, double width, double height)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "%g %g %g %g rectangle\n", x, y, width, height);
     DLCALL (cairo_rectangle, cr, x, y, width, height);
+    _exit_trace ();
 }
 
 void
 cairo_close_path (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_cairo_op (cr, "h\n");
     DLCALL (cairo_close_path, cr);
+    _exit_trace ();
 }
 
 void
 cairo_paint (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "paint\n");
     DLCALL (cairo_paint, cr);
+    _exit_trace ();
 }
 
 void
 cairo_paint_with_alpha (cairo_t *cr, double alpha)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g paint-with-alpha\n", alpha);
     DLCALL (cairo_paint_with_alpha, cr, alpha);
+    _exit_trace ();
 }
 
 void
 cairo_mask (cairo_t *cr, cairo_pattern_t *pattern)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && pattern != NULL && _write_lock ()) {
 	Object *obj = _get_object (PATTERN, pattern);
@@ -2516,12 +2616,13 @@ cairo_mask (cairo_t *cr, cairo_pattern_t *pattern)
 	_write_unlock ();
     }
     DLCALL (cairo_mask, cr, pattern);
+    _exit_trace ();
 }
 
 void
 cairo_mask_surface (cairo_t *cr, cairo_surface_t *surface, double x, double y)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && surface != NULL && _write_lock ()) {
 	if (_is_current (SURFACE, surface, 0) &&
@@ -2549,87 +2650,97 @@ cairo_mask_surface (cairo_t *cr, cairo_surface_t *surface, double x, double y)
     }
 
     DLCALL (cairo_mask_surface, cr, surface, x, y);
+    _exit_trace ();
 }
 
 void
 cairo_stroke (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "stroke\n");
     DLCALL (cairo_stroke, cr);
+    _exit_trace ();
 }
 
 void
 cairo_stroke_preserve (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "stroke+\n");
     DLCALL (cairo_stroke_preserve, cr);
+    _exit_trace ();
 }
 
 void
 cairo_fill (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "fill\n");
     DLCALL (cairo_fill, cr);
+    _exit_trace ();
 }
 
 void
 cairo_fill_preserve (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "fill+\n");
     DLCALL (cairo_fill_preserve, cr);
+    _exit_trace ();
 }
 
 void
 cairo_copy_page (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "copy-page\n");
     DLCALL (cairo_copy_page, cr);
+    _exit_trace ();
 }
 
 void
 cairo_show_page (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "show-page\n");
     DLCALL (cairo_show_page, cr);
+    _exit_trace ();
 }
 
 void
 cairo_clip (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "clip\n");
     DLCALL (cairo_clip, cr);
+    _exit_trace ();
 }
 
 void
 cairo_clip_preserve (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "clip+\n");
     DLCALL (cairo_clip_preserve, cr);
+    _exit_trace ();
 }
 
 void
 cairo_reset_clip (cairo_t *cr)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "reset-clip\n");
     DLCALL (cairo_reset_clip, cr);
+    _exit_trace ();
 }
 
 
@@ -2661,7 +2772,7 @@ _weight_to_string (cairo_font_weight_t font_weight)
 void
 cairo_select_font_face (cairo_t *cr, const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && _write_lock ()) {
 	_emit_context (cr);
@@ -2672,6 +2783,7 @@ cairo_select_font_face (cairo_t *cr, const char *family, cairo_font_slant_t slan
 	_write_unlock ();
     }
     DLCALL (cairo_select_font_face, cr, family, slant, weight);
+    _exit_trace ();
 }
 
 cairo_font_face_t *
@@ -2680,7 +2792,7 @@ cairo_get_font_face (cairo_t *cr)
     cairo_font_face_t *ret;
     long font_face_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_get_font_face, cr);
     font_face_id = _create_font_face_id (ret);
@@ -2688,13 +2800,14 @@ cairo_get_font_face (cairo_t *cr)
     _emit_cairo_op (cr, "/font-face get %% f%ld\n", font_face_id);
     _push_operand (FONT_FACE, ret);
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && font_face != NULL && _write_lock ()) {
 	if (_is_current (FONT_FACE, font_face, 0) &&
@@ -2720,27 +2833,30 @@ cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face)
     }
 
     DLCALL (cairo_set_font_face, cr, font_face);
+    _exit_trace ();
 }
 
 void
 cairo_set_font_size (cairo_t *cr, double size)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-font-size\n", size);
     DLCALL (cairo_set_font_size, cr, size);
+    _exit_trace ();
 }
 
 void
 cairo_set_font_matrix (cairo_t *cr, const cairo_matrix_t *matrix)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g %g %g %g matrix set-font-matrix\n",
 		    matrix->xx, matrix->yx,
 		    matrix->xy, matrix->yy,
 		    matrix->x0, matrix->y0);
     DLCALL (cairo_set_font_matrix, cr, matrix);
+    _exit_trace ();
 }
 
 static const char *
@@ -2794,8 +2910,6 @@ _emit_font_options (const cairo_font_options_t *options)
     cairo_hint_style_t hint_style;
     cairo_hint_metrics_t hint_metrics;
 
-    ENSURE_INIT_TRACE ();
-
     _trace_printf ("<<");
 
     antialias = DLCALL (cairo_font_options_get_antialias, options);
@@ -2828,7 +2942,7 @@ _emit_font_options (const cairo_font_options_t *options)
 void
 cairo_set_font_options (cairo_t *cr, const cairo_font_options_t *options)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && options != NULL && _write_lock ()) {
 	_emit_context (cr);
@@ -2838,6 +2952,7 @@ cairo_set_font_options (cairo_t *cr, const cairo_font_options_t *options)
     }
 
     DLCALL (cairo_set_font_options, cr, options);
+    _exit_trace ();
 }
 
 cairo_scaled_font_t *
@@ -2845,7 +2960,7 @@ cairo_get_scaled_font (cairo_t *cr)
 {
     cairo_scaled_font_t *ret;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_get_scaled_font, cr);
 
@@ -2855,13 +2970,14 @@ cairo_get_scaled_font (cairo_t *cr)
 	_get_object (SCALED_FONT, ret)->defined = true;
     }
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && scaled_font != NULL) {
 	if (_pop_operands_to (SCALED_FONT, scaled_font)) {
@@ -2890,6 +3006,7 @@ cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font)
 	}
     }
     DLCALL (cairo_set_scaled_font, cr, scaled_font);
+    _exit_trace ();
 }
 
 static void
@@ -2917,7 +3034,7 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
     cairo_scaled_font_t *ret;
     long scaled_font_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_scaled_font_create, font_face, font_matrix, ctm, options);
     scaled_font_id = _create_scaled_font_id (ret);
@@ -2956,13 +3073,14 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_show_text (cairo_t *cr, const char *utf8)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && _write_lock ()) {
 	_emit_context (cr);
@@ -2971,6 +3089,7 @@ cairo_show_text (cairo_t *cr, const char *utf8)
 	_write_unlock ();
     }
     DLCALL (cairo_show_text, cr, utf8);
+    _exit_trace ();
 }
 
 static void
@@ -3066,7 +3185,7 @@ _emit_glyphs (cairo_scaled_font_t *font,
 void
 cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && glyphs != NULL && _write_lock ()) {
 	cairo_scaled_font_t *font;
@@ -3080,6 +3199,7 @@ cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
     }
 
     DLCALL (cairo_show_glyphs, cr, glyphs, num_glyphs);
+    _exit_trace ();
 }
 
 static const char *
@@ -3104,7 +3224,7 @@ cairo_show_text_glyphs (cairo_t			   *cr,
 {
     cairo_scaled_font_t *font;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     font = DLCALL (cairo_get_scaled_font, cr);
 
@@ -3134,12 +3254,13 @@ cairo_show_text_glyphs (cairo_t			   *cr,
 				    glyphs, num_glyphs,
 				    clusters, num_clusters,
 				    backward);
+    _exit_trace ();
 }
 
 void
 cairo_text_path (cairo_t *cr, const char *utf8)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (cr != NULL && _write_lock ()) {
 	_emit_context (cr);
@@ -3148,6 +3269,7 @@ cairo_text_path (cairo_t *cr, const char *utf8)
 	_write_unlock ();
     }
     DLCALL (cairo_text_path, cr, utf8);
+    _exit_trace ();
 }
 
 void
@@ -3155,7 +3277,7 @@ cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 {
     cairo_scaled_font_t *font;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     font = DLCALL (cairo_get_scaled_font, cr);
 
@@ -3169,6 +3291,7 @@ cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
     }
 
     DLCALL (cairo_glyph_path, cr, glyphs, num_glyphs);
+    _exit_trace ();
 }
 
 void
@@ -3178,11 +3301,12 @@ cairo_append_path (cairo_t *cr, const cairo_path_t *path)
     int i;
     cairo_path_data_t *p;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     _emit_line_info ();
     if (cr == NULL || path == NULL) {
 	DLCALL (cairo_append_path, cr, path);
+	_exit_trace ();
 	return;
     }
 
@@ -3212,6 +3336,7 @@ cairo_append_path (cairo_t *cr, const cairo_path_t *path)
 	    break;
 	}
     }
+    _exit_trace ();
 }
 
 cairo_surface_t *
@@ -3221,7 +3346,7 @@ cairo_image_surface_create (cairo_format_t format, int width, int height)
     long surface_id;
     const char *format_str;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_image_surface_create, format, width, height);
 
@@ -3243,6 +3368,7 @@ cairo_image_surface_create (cairo_format_t format, int width, int height)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3252,7 +3378,7 @@ cairo_image_surface_create_for_data (unsigned char *data, cairo_format_t format,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_image_surface_create_for_data, data, format, width, height, stride);
     surface_id = _create_surface_id (ret);
@@ -3292,6 +3418,7 @@ cairo_image_surface_create_for_data (unsigned char *data, cairo_format_t format,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3303,7 +3430,7 @@ cairo_surface_create_similar (cairo_surface_t *other,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_surface_create_similar, other, content, width, height);
     surface_id = _create_surface_id (ret);
@@ -3329,6 +3456,7 @@ cairo_surface_create_similar (cairo_surface_t *other,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3352,23 +3480,25 @@ _emit_surface_op (cairo_surface_t *surface, const char *fmt, ...)
 void
 cairo_surface_finish (cairo_surface_t *surface)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     DLCALL (cairo_surface_finish, surface);
+    _exit_trace ();
 }
 
 void
 cairo_surface_flush (cairo_surface_t *surface)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     DLCALL (cairo_surface_flush, surface);
+    _exit_trace ();
 }
 
 void
 cairo_surface_mark_dirty (cairo_surface_t *surface)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	if (_mark_dirty) {
@@ -3381,13 +3511,14 @@ cairo_surface_mark_dirty (cairo_surface_t *surface)
     }
 
     DLCALL (cairo_surface_mark_dirty, surface);
+    _exit_trace ();
 }
 
 void
 cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface,
 				    int x, int y, int width, int height)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	if (_mark_dirty) {
@@ -3402,44 +3533,49 @@ cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface,
     }
 
     DLCALL (cairo_surface_mark_dirty_rectangle, surface, x, y, width, height);
+    _exit_trace ();
 }
 
 void
 cairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, double y_offset)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_surface_op (surface, "%g %g set-device-offset\n",
 		      x_offset, y_offset);
     DLCALL (cairo_surface_set_device_offset, surface, x_offset, y_offset);
+    _exit_trace ();
 }
 
 void
 cairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels_per_inch, double y_pixels_per_inch)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_surface_op (surface, "%g %g set-fallback-resolution\n",
 		      x_pixels_per_inch, y_pixels_per_inch);
     DLCALL (cairo_surface_set_fallback_resolution, surface, x_pixels_per_inch, y_pixels_per_inch);
+    _exit_trace ();
 }
 
 void
 cairo_surface_copy_page (cairo_surface_t *surface)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_surface_op (surface, "copy-page\n");
     DLCALL (cairo_surface_copy_page, surface);
+    _exit_trace ();
 }
 
 void
 cairo_surface_show_page (cairo_surface_t *surface)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_surface_op (surface, "show-page\n");
     DLCALL (cairo_surface_show_page, surface);
+    _exit_trace ();
 }
 
 cairo_status_t
@@ -3450,7 +3586,8 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 			     cairo_destroy_func_t	 destroy,
 			     void			*closure)
 {
-    ENSURE_INIT_TRACE ();
+    cairo_status_t ret;
+    _enter_trace ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	_emit_surface (surface);
@@ -3462,19 +3599,22 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_surface_set_mime_data,
-		   surface,
-		   mime_type,
-		   data, length,
-		   destroy,
-		   closure);
+    ret = DLCALL (cairo_surface_set_mime_data,
+		  surface,
+		  mime_type,
+		  data, length,
+		  destroy,
+		  closure);
+    _exit_trace ();
+    return ret;
 }
 
 #if CAIRO_HAS_PNG_FUNCTIONS
 cairo_status_t
 cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename)
 {
-    ENSURE_INIT_TRACE ();
+    cairo_status_t ret;
+    _enter_trace ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	_trace_printf ("%% s%ld ", _get_surface_id (surface));
@@ -3482,7 +3622,9 @@ cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename)
 	_trace_printf (" write-to-png\n");
 	_write_unlock ();
     }
-    return DLCALL (cairo_surface_write_to_png, surface, filename);
+    ret = DLCALL (cairo_surface_write_to_png, surface, filename);
+    _exit_trace ();
+    return ret;
 }
 
 cairo_status_t
@@ -3490,7 +3632,8 @@ cairo_surface_write_to_png_stream (cairo_surface_t *surface,
 				   cairo_write_func_t write_func,
 				   void *data)
 {
-    ENSURE_INIT_TRACE ();
+    cairo_status_t ret;
+    _enter_trace ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	char symbol[1024];
@@ -3504,8 +3647,10 @@ cairo_surface_write_to_png_stream (cairo_surface_t *surface,
 	_trace_printf (" write-to-png-stream\n");
 	_write_unlock ();
     }
-    return DLCALL (cairo_surface_write_to_png_stream,
-		   surface, write_func, data);
+    ret = DLCALL (cairo_surface_write_to_png_stream,
+		  surface, write_func, data);
+    _exit_trace ();
+    return ret;
 }
 #endif
 
@@ -3532,7 +3677,7 @@ cairo_pattern_create_rgb (double red, double green, double blue)
     cairo_pattern_t *ret;
     long pattern_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_pattern_create_rgb, red, green, blue);
     pattern_id = _create_pattern_id (ret);
@@ -3545,6 +3690,7 @@ cairo_pattern_create_rgb (double red, double green, double blue)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3554,7 +3700,7 @@ cairo_pattern_create_rgba (double red, double green, double blue, double alpha)
     cairo_pattern_t *ret;
     long pattern_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_pattern_create_rgba, red, green, blue, alpha);
     pattern_id = _create_pattern_id (ret);
@@ -3567,6 +3713,7 @@ cairo_pattern_create_rgba (double red, double green, double blue, double alpha)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3577,7 +3724,7 @@ cairo_pattern_create_for_surface (cairo_surface_t *surface)
     long pattern_id;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_pattern_create_for_surface, surface);
     pattern_id = _create_pattern_id (ret);
@@ -3600,6 +3747,7 @@ cairo_pattern_create_for_surface (cairo_surface_t *surface)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3609,7 +3757,7 @@ cairo_pattern_create_linear (double x0, double y0, double x1, double y1)
     cairo_pattern_t *ret;
     long pattern_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_pattern_create_linear, x0, y0, x1, y1);
     pattern_id = _create_pattern_id (ret);
@@ -3622,6 +3770,7 @@ cairo_pattern_create_linear (double x0, double y0, double x1, double y1)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3631,7 +3780,7 @@ cairo_pattern_create_radial (double cx0, double cy0, double radius0, double cx1,
     cairo_pattern_t *ret;
     long pattern_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_pattern_create_radial,
 		  cx0, cy0, radius0,
@@ -3647,35 +3796,38 @@ cairo_pattern_create_radial (double cx0, double cy0, double radius0, double cx1,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, double offset, double red, double green, double blue)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_pattern_op (pattern,
 		      "%g %g %g %g 1 add-color-stop\n",
 		      offset, red, green, blue);
     DLCALL (cairo_pattern_add_color_stop_rgb, pattern, offset, red, green, blue);
+    _exit_trace ();
 }
 
 void
 cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, double offset, double red, double green, double blue, double alpha)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_pattern_op (pattern,
 		      "%g %g %g %g %g add-color-stop\n",
 		      offset, red, green, blue, alpha);
     DLCALL (cairo_pattern_add_color_stop_rgba, pattern, offset, red, green, blue, alpha);
+    _exit_trace ();
 }
 
 void
 cairo_pattern_set_matrix (cairo_pattern_t *pattern, const cairo_matrix_t *matrix)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     if (_matrix_is_identity (matrix)) {
 	_emit_pattern_op (pattern, "identity set-matrix\n");
@@ -3687,6 +3839,7 @@ cairo_pattern_set_matrix (cairo_pattern_t *pattern, const cairo_matrix_t *matrix
 			  matrix->x0, matrix->y0);
     }
     DLCALL (cairo_pattern_set_matrix, pattern, matrix);
+    _exit_trace ();
 }
 
 static const char *
@@ -3708,10 +3861,11 @@ _filter_to_string (cairo_filter_t filter)
 void
 cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_pattern_op (pattern, "//%s set-filter\n", _filter_to_string (filter));
     DLCALL (cairo_pattern_set_filter, pattern, filter);
+    _exit_trace ();
 }
 
 static const char *
@@ -3731,10 +3885,11 @@ _extend_to_string (cairo_extend_t extend)
 void
 cairo_pattern_set_extend (cairo_pattern_t *pattern, cairo_extend_t extend)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     _emit_pattern_op (pattern, "//%s set-extend\n", _extend_to_string (extend));
     DLCALL (cairo_pattern_set_extend, pattern, extend);
+    _exit_trace ();
 }
 
 #if CAIRO_HAS_FT_FONT
@@ -3745,7 +3900,7 @@ cairo_ft_font_face_create_for_pattern (FcPattern *pattern)
     cairo_font_face_t *ret;
     long font_face_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_ft_font_face_create_for_pattern, pattern);
     font_face_id = _create_font_face_id (ret);
@@ -3773,6 +3928,7 @@ cairo_ft_font_face_create_for_pattern (FcPattern *pattern)
 	free (parsed);
     }
 
+    _exit_trace ();
     return ret;
 }
 #endif /* CAIRO_HAS_FC_FONT*/
@@ -3799,18 +3955,22 @@ cairo_ft_font_face_create_for_ft_face (FT_Face face, int load_flags)
     FtFaceData *data;
     long font_face_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_ft_font_face_create_for_ft_face, face, load_flags);
     font_face_id = _create_font_face_id (ret);
 
-    if (face == NULL)
+    if (face == NULL) {
+	_exit_trace ();
 	return ret;
+    }
 
     obj = _get_object (NONE, face);
     data = obj->data;
-    if (data == NULL)
+    if (data == NULL) {
+	_exit_trace ();
 	return ret;
+    }
 
     _emit_line_info ();
     if (_write_lock ()) {
@@ -3826,6 +3986,7 @@ cairo_ft_font_face_create_for_ft_face (FT_Face face, int load_flags)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3865,7 +4026,7 @@ FT_New_Face (FT_Library library, const char *pathname, FT_Long index, FT_Face *f
 {
     FT_Error ret;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (FT_New_Face, library, pathname, index, face);
     if (ret == 0) {
@@ -3879,6 +4040,7 @@ FT_New_Face (FT_Library library, const char *pathname, FT_Long index, FT_Face *f
 	obj->destroy = _ft_face_data_destroy;
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3887,7 +4049,7 @@ FT_New_Memory_Face (FT_Library library, const FT_Byte *mem, FT_Long size, FT_Lon
 {
     FT_Error ret;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (FT_New_Memory_Face, library, mem, size, index, face);
     if (ret == 0) {
@@ -3901,6 +4063,7 @@ FT_New_Memory_Face (FT_Library library, const FT_Byte *mem, FT_Long size, FT_Lon
 	obj->destroy = _ft_face_data_destroy;
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -3917,7 +4080,7 @@ FT_Open_Face (FT_Library library, const FT_Open_Args *args, FT_Long index, FT_Fa
 {
     FT_Error ret;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (FT_Open_Face, library, args, index, face);
     if (args->flags & FT_OPEN_MEMORY)
@@ -3931,6 +4094,7 @@ FT_Open_Face (FT_Library library, const FT_Open_Args *args, FT_Long index, FT_Fa
 	fprintf (stderr, "FT_Open_Face (path=%s, %ld) = %p\n",
 		args->pathname, index, *face);
 
+    _exit_trace ();
     return ret;
 }
 #endif
@@ -3938,11 +4102,14 @@ FT_Open_Face (FT_Library library, const FT_Open_Args *args, FT_Long index, FT_Fa
 FT_Error
 FT_Done_Face (FT_Face face)
 {
-    ENSURE_INIT_TRACE ();
+    FT_Error ret;
+    _enter_trace ();
 
     _object_destroy (_get_object (NONE, face));
 
-    return DLCALL (FT_Done_Face, face);
+    ret = DLCALL (FT_Done_Face, face);
+    _exit_trace ();
+    return ret;
 }
 #endif
 
@@ -3973,7 +4140,7 @@ cairo_ps_surface_create (const char *filename, double width_in_points, double he
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_ps_surface_create, filename, width_in_points, height_in_points);
     surface_id = _create_surface_id (ret);
@@ -3996,6 +4163,7 @@ cairo_ps_surface_create (const char *filename, double width_in_points, double he
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4005,7 +4173,7 @@ cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, void *closure
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_ps_surface_create_for_stream, write_func, closure, width_in_points, height_in_points);
     surface_id = _create_surface_id (ret);
@@ -4025,15 +4193,17 @@ cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, void *closure
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_ps_surface_set_size (cairo_surface_t *surface, double width_in_points, double height_in_points)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     DLCALL (cairo_ps_surface_set_size, surface, width_in_points, height_in_points);
+    _exit_trace ();
 }
 
 #endif
@@ -4047,7 +4217,7 @@ cairo_pdf_surface_create (const char *filename, double width_in_points, double h
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_pdf_surface_create, filename, width_in_points, height_in_points);
     surface_id = _create_surface_id (ret);
@@ -4070,6 +4240,7 @@ cairo_pdf_surface_create (const char *filename, double width_in_points, double h
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4079,7 +4250,7 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, void *closur
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_pdf_surface_create_for_stream, write_func, closure, width_in_points, height_in_points);
     surface_id = _create_surface_id (ret);
@@ -4098,15 +4269,17 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, void *closur
 	_push_operand (SURFACE, ret);
 	_write_unlock ();
     }
+    _exit_trace ();
     return ret;
 }
 
 void
 cairo_pdf_surface_set_size (cairo_surface_t *surface, double width_in_points, double height_in_points)
 {
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
     _emit_line_info ();
     DLCALL (cairo_pdf_surface_set_size, surface, width_in_points, height_in_points);
+    _exit_trace ();
 }
 #endif
 
@@ -4119,7 +4292,7 @@ cairo_svg_surface_create (const char *filename, double width, double height)
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_svg_surface_create, filename, width, height);
     surface_id = _create_surface_id (ret);
@@ -4142,6 +4315,7 @@ cairo_svg_surface_create (const char *filename, double width, double height)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4151,7 +4325,7 @@ cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, void *closur
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_svg_surface_create_for_stream, write_func, closure, width, height);
     surface_id = _create_surface_id (ret);
@@ -4171,6 +4345,7 @@ cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, void *closur
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4183,7 +4358,7 @@ cairo_image_surface_create_from_png (const char *filename)
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_image_surface_create_from_png, filename);
 
@@ -4204,6 +4379,7 @@ cairo_image_surface_create_from_png (const char *filename)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4213,7 +4389,7 @@ cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, void *c
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_image_surface_create_from_png_stream, read_func, closure);
     surface_id = _create_surface_id (ret);
@@ -4229,6 +4405,7 @@ cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, void *c
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 #endif
@@ -4251,7 +4428,7 @@ cairo_xlib_surface_create (Display *dpy,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_xlib_surface_create,
 	          dpy, drawable, visual, width, height);
@@ -4278,6 +4455,7 @@ cairo_xlib_surface_create (Display *dpy,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4290,7 +4468,7 @@ cairo_xlib_surface_create_for_bitmap (Display *dpy,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_xlib_surface_create_for_bitmap,
 	          dpy, bitmap, screen, width, height);
@@ -4318,6 +4496,7 @@ cairo_xlib_surface_create_for_bitmap (Display *dpy,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4333,7 +4512,7 @@ cairo_xlib_surface_create_with_xrender_format (Display *dpy,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_xlib_surface_create_with_xrender_format,
 	          dpy, drawable, screen, format, width, height);
@@ -4362,6 +4541,7 @@ cairo_xlib_surface_create_with_xrender_format (Display *dpy,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 #endif
@@ -4378,7 +4558,7 @@ cairo_script_surface_create (cairo_script_context_t *ctx,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_script_surface_create, ctx, content, width, height);
     surface_id = _create_surface_id (ret);
@@ -4400,6 +4580,7 @@ cairo_script_surface_create (cairo_script_context_t *ctx,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4410,7 +4591,7 @@ cairo_script_surface_create_for_target (cairo_script_context_t *ctx,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_script_surface_create_for_target, ctx, target);
     surface_id = _create_surface_id (ret);
@@ -4426,6 +4607,7 @@ cairo_script_surface_create_for_target (cairo_script_context_t *ctx,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 #endif
@@ -4440,7 +4622,7 @@ _cairo_test_fallback_surface_create (cairo_content_t	content,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (_cairo_test_fallback_surface_create, content, width, height);
     surface_id = _create_surface_id (ret);
@@ -4462,6 +4644,7 @@ _cairo_test_fallback_surface_create (cairo_content_t	content,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4472,7 +4655,7 @@ _cairo_test_paginated_surface_create (cairo_surface_t *surface)
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (_cairo_test_paginated_surface_create, surface);
     surface_id = _create_surface_id (ret);
@@ -4490,6 +4673,7 @@ _cairo_test_paginated_surface_create (cairo_surface_t *surface)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4501,7 +4685,7 @@ _cairo_test_null_surface_create (cairo_content_t	content)
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (_cairo_test_null_surface_create, content);
     surface_id = _create_surface_id (ret);
@@ -4519,6 +4703,7 @@ _cairo_test_null_surface_create (cairo_content_t	content)
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 #endif
@@ -4530,7 +4715,7 @@ cairo_meta_surface_create (cairo_content_t content,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_meta_surface_create, content, extents);
     surface_id = _create_surface_id (ret);
@@ -4561,6 +4746,7 @@ cairo_meta_surface_create (cairo_content_t content,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4569,7 +4755,7 @@ cairo_meta_surface_replay (cairo_surface_t *meta, cairo_surface_t *target)
 {
     cairo_status_t ret;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_meta_surface_replay, meta, target);
 
@@ -4582,6 +4768,7 @@ cairo_meta_surface_replay (cairo_surface_t *meta, cairo_surface_t *target)
 	_consume_operand ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4595,7 +4782,7 @@ cairo_vg_surface_create (cairo_vg_context_t *context,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_vg_surface_create, context, content, width, height);
     surface_id = _create_surface_id (ret);
@@ -4617,6 +4804,7 @@ cairo_vg_surface_create (cairo_vg_context_t *context,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 
@@ -4629,7 +4817,7 @@ cairo_vg_surface_create_for_image (cairo_vg_context_t *context,
     cairo_surface_t *ret;
     long surface_id;
 
-    ENSURE_INIT_TRACE ();
+    _enter_trace ();
 
     ret = DLCALL (cairo_vg_surface_create_for_image,
 		  context, image, format, width, height);
@@ -4655,6 +4843,7 @@ cairo_vg_surface_create_for_image (cairo_vg_context_t *context,
 	_write_unlock ();
     }
 
+    _exit_trace ();
     return ret;
 }
 #endif
commit f5bcb2f36e7dba9cfba5d697e1401dcd00603812
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Sun Sep 13 12:47:19 2009 +0100

    [build] Enable building cairo-trace on Solaris.
    
    Solaris supports LD_PRELOAD too!

diff --git a/configure.ac b/configure.ac
index 0ebce6d..18f0d40 100644
--- a/configure.ac
+++ b/configure.ac
@@ -636,7 +636,7 @@ dnl The tracing utility requires LD_PRELOAD, so only build it for systems
 dnl that are known to work.
 
 case $host in
-*-linux*|*-*bsd*)
+*-linux*|*-*bsd*|*-solaris*)
 	have_ld_preload="yes"
 	;;
 *)
commit ce8c842a70d3f23527dcbd889b022103483341f2
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Sun Sep 13 12:53:07 2009 +0100

    [trace] Make cairo-trace and its symbol-lookup automatically configured.
    
    The build shouldn't fail if we can't make our optional performance
    tools.

diff --git a/configure.ac b/configure.ac
index bc1d384..0ebce6d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -644,7 +644,7 @@ case $host in
 	;;
 esac
 
-CAIRO_ENABLE(trace, cairo-trace, yes, [
+CAIRO_ENABLE(trace, cairo-trace, auto, [
 	if test "x$have_ld_preload" != "xyes" -o \
 		"x$have_libz" != "xyes" -o \
 		"x$have_dl" != "xyes"; then
@@ -668,7 +668,7 @@ if test "x$have_bfd" = "xyes"; then
     AC_SUBST(BFD_LIBS)
 fi
 
-CAIRO_ENABLE(symbol_lookup, symbol-lookup, yes, [
+CAIRO_ENABLE(symbol_lookup, symbol-lookup, auto, [
 	if test "x$have_bfd" != "xyes"; then
 		use_symbol_lookup="no (requires bfd)"
 	fi
commit 2fb59a69f4509c2116f16bd6d376f35e3e2eb709
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Sun Sep 13 14:27:03 2009 +0100

    [trace] Don't rely on the constructor attribute to initialise the tracer.
    
    Use pthread_once() at cairo API entry points to initialise the library
    if required.  This side steps the issues with the __constructor__
    attribute vs _init()/_fini() on Solaris and different tracer/tracee
    runtimes which result in the constructors not being run in
    cairo-trace.so.

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index c2eec1f..a3615e3 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -178,6 +178,10 @@ static bool _error;
 static bool _line_info;
 static bool _mark_dirty;
 static const cairo_user_data_key_t destroy_key;
+static pthread_once_t once_control = PTHREAD_ONCE_INIT;
+
+static void _init_trace (void);
+#define ENSURE_INIT_TRACE() pthread_once (&once_control, _init_trace);
 
 #if HAVE_BUILTIN_RETURN_ADDRESS && CAIRO_HAS_SYMBOL_LOOKUP
 #define _emit_line_info() do { \
@@ -394,7 +398,7 @@ _object_create (Type *type, const void *ptr)
     return obj;
 }
 
-static void __attribute__ ((constructor))
+static void
 _init_trace (void)
 {
     pthread_mutex_init (&Types.mutex, NULL);
@@ -1795,6 +1799,8 @@ cairo_create (cairo_surface_t *target)
     long surface_id;
     long context_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_create, target);
     context_id = _create_context_id (ret);
 
@@ -1822,6 +1828,7 @@ cairo_create (cairo_surface_t *target)
 void
 cairo_save (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "save\n");
     DLCALL (cairo_save, cr);
@@ -1830,6 +1837,7 @@ cairo_save (cairo_t *cr)
 void
 cairo_restore (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "restore\n");
     DLCALL (cairo_restore, cr);
@@ -1838,6 +1846,7 @@ cairo_restore (cairo_t *cr)
 void
 cairo_push_group (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "//COLOR_ALPHA push-group\n");
     DLCALL (cairo_push_group, cr);
@@ -1857,6 +1866,7 @@ _content_to_string (cairo_content_t content)
 void
 cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s push-group\n", _content_to_string (content));
     DLCALL (cairo_push_group_with_content, cr, content);
@@ -1867,6 +1877,8 @@ cairo_pop_group (cairo_t *cr)
 {
     cairo_pattern_t *ret;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_pop_group, cr);
 
     _emit_line_info ();
@@ -1879,6 +1891,7 @@ cairo_pop_group (cairo_t *cr)
 void
 cairo_pop_group_to_source (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "pop-group set-source\n");
     DLCALL (cairo_pop_group_to_source, cr);
@@ -1926,6 +1939,7 @@ _operator_to_string (cairo_operator_t op)
 void
 cairo_set_operator (cairo_t *cr, cairo_operator_t op)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s set-operator\n", _operator_to_string (op));
     DLCALL (cairo_set_operator, cr, op);
@@ -1934,6 +1948,7 @@ cairo_set_operator (cairo_t *cr, cairo_operator_t op)
 void
 cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g set-source-rgb\n", red, green, blue);
     DLCALL (cairo_set_source_rgb, cr, red, green, blue);
@@ -1942,6 +1957,7 @@ cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
 void
 cairo_set_source_rgba (cairo_t *cr, double red, double green, double blue, double alpha)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g %g set-source-rgba\n",
 		    red, green, blue, alpha);
@@ -2011,6 +2027,7 @@ _emit_source_image_rectangle (cairo_surface_t *surface,
 void
 cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface, double x, double y)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && surface != NULL && _write_lock ()) {
 	if (_is_current (SURFACE, surface, 0) &&
@@ -2046,6 +2063,7 @@ cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface, double x, doubl
 void
 cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && source != NULL && _write_lock ()) {
 	Object *obj = _get_object (PATTERN, source);
@@ -2087,6 +2105,8 @@ cairo_get_source (cairo_t *cr)
 {
     cairo_pattern_t *ret;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_get_source, cr);
 
     if (! _has_pattern_id (ret)) {
@@ -2101,6 +2121,7 @@ cairo_get_source (cairo_t *cr)
 void
 cairo_set_tolerance (cairo_t *cr, double tolerance)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-tolerance\n", tolerance);
     DLCALL (cairo_set_tolerance, cr, tolerance);
@@ -2123,6 +2144,7 @@ _antialias_to_string (cairo_antialias_t antialias)
 void
 cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-antialias\n", _antialias_to_string (antialias));
@@ -2144,6 +2166,7 @@ _fill_rule_to_string (cairo_fill_rule_t rule)
 void
 cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-fill-rule\n", _fill_rule_to_string (fill_rule));
@@ -2153,6 +2176,7 @@ cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
 void
 cairo_set_line_width (cairo_t *cr, double width)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-line-width\n", width);
     DLCALL (cairo_set_line_width, cr, width);
@@ -2174,6 +2198,7 @@ _line_cap_to_string (cairo_line_cap_t line_cap)
 void
 cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s set-line-cap\n", _line_cap_to_string (line_cap));
     DLCALL (cairo_set_line_cap, cr, line_cap);
@@ -2195,6 +2220,7 @@ _line_join_to_string (cairo_line_join_t line_join)
 void
 cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-line-join\n", _line_join_to_string (line_join));
@@ -2204,6 +2230,7 @@ cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
 void
 cairo_set_dash (cairo_t *cr, const double *dashes, int num_dashes, double offset)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && _write_lock ()) {
 	int n;
@@ -2227,6 +2254,7 @@ cairo_set_dash (cairo_t *cr, const double *dashes, int num_dashes, double offset
 void
 cairo_set_miter_limit (cairo_t *cr, double limit)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-miter-limit\n", limit);
     DLCALL (cairo_set_miter_limit, cr, limit);
@@ -2235,6 +2263,7 @@ cairo_set_miter_limit (cairo_t *cr, double limit)
 void
 cairo_translate (cairo_t *cr, double tx, double ty)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g translate\n", tx, ty);
     DLCALL (cairo_translate, cr, tx, ty);
@@ -2243,6 +2272,7 @@ cairo_translate (cairo_t *cr, double tx, double ty)
 void
 cairo_scale (cairo_t *cr, double sx, double sy)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g scale\n", sx, sy);
     DLCALL (cairo_scale, cr, sx, sy);
@@ -2251,6 +2281,7 @@ cairo_scale (cairo_t *cr, double sx, double sy)
 void
 cairo_rotate (cairo_t *cr, double angle)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g rotate\n", angle);
     DLCALL (cairo_rotate, cr, angle);
@@ -2259,6 +2290,7 @@ cairo_rotate (cairo_t *cr, double angle)
 void
 cairo_transform (cairo_t *cr, const cairo_matrix_t *matrix)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g %g %g %g matrix transform\n",
 		    matrix->xx, matrix->yx,
@@ -2270,6 +2302,7 @@ cairo_transform (cairo_t *cr, const cairo_matrix_t *matrix)
 void
 cairo_set_matrix (cairo_t *cr, const cairo_matrix_t *matrix)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (_matrix_is_identity (matrix)) {
 	_emit_cairo_op (cr, "identity set-matrix\n");
@@ -2288,6 +2321,8 @@ cairo_get_target (cairo_t *cr)
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_get_target, cr);
     surface_id = _create_surface_id (ret);
 
@@ -2305,6 +2340,8 @@ cairo_get_group_target (cairo_t *cr)
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_get_group_target, cr);
     surface_id = _create_surface_id (ret);
 
@@ -2319,6 +2356,7 @@ cairo_get_group_target (cairo_t *cr)
 void
 cairo_identity_matrix (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "identity set-matrix\n");
     DLCALL (cairo_identity_matrix, cr);
@@ -2327,6 +2365,7 @@ cairo_identity_matrix (cairo_t *cr)
 void
 cairo_new_path (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "n ");
     DLCALL (cairo_new_path, cr);
@@ -2335,6 +2374,7 @@ cairo_new_path (cairo_t *cr)
 void
 cairo_move_to (cairo_t *cr, double x, double y)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g m ", x, y);
     DLCALL (cairo_move_to, cr, x, y);
 }
@@ -2342,6 +2382,7 @@ cairo_move_to (cairo_t *cr, double x, double y)
 void
 cairo_new_sub_path (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "N ");
     DLCALL (cairo_new_sub_path, cr);
 }
@@ -2349,6 +2390,7 @@ cairo_new_sub_path (cairo_t *cr)
 void
 cairo_line_to (cairo_t *cr, double x, double y)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g l ", x, y);
     DLCALL (cairo_line_to, cr, x, y);
 }
@@ -2356,6 +2398,7 @@ cairo_line_to (cairo_t *cr, double x, double y)
 void
 cairo_curve_to (cairo_t *cr, double x1, double y1, double x2, double y2, double x3, double y3)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g %g %g %g %g c ", x1, y1, x2, y2, x3, y3);
     DLCALL (cairo_curve_to, cr, x1, y1, x2, y2, x3, y3);
 }
@@ -2363,6 +2406,7 @@ cairo_curve_to (cairo_t *cr, double x1, double y1, double x2, double y2, double
 void
 cairo_arc (cairo_t *cr, double xc, double yc, double radius, double angle1, double angle2)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g %g %g %g arc\n", xc, yc, radius, angle1, angle2);
     DLCALL (cairo_arc, cr, xc, yc, radius, angle1, angle2);
 }
@@ -2370,6 +2414,7 @@ cairo_arc (cairo_t *cr, double xc, double yc, double radius, double angle1, doub
 void
 cairo_arc_negative (cairo_t *cr, double xc, double yc, double radius, double angle1, double angle2)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g %g %g %g arc-\n",
 		    xc, yc, radius, angle1, angle2);
     DLCALL (cairo_arc_negative, cr, xc, yc, radius, angle1, angle2);
@@ -2378,6 +2423,7 @@ cairo_arc_negative (cairo_t *cr, double xc, double yc, double radius, double ang
 void
 cairo_rel_move_to (cairo_t *cr, double dx, double dy)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g M ", dx, dy);
     DLCALL (cairo_rel_move_to, cr, dx, dy);
 }
@@ -2385,6 +2431,7 @@ cairo_rel_move_to (cairo_t *cr, double dx, double dy)
 void
 cairo_rel_line_to (cairo_t *cr, double dx, double dy)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g L ", dx, dy);
     DLCALL (cairo_rel_line_to, cr, dx, dy);
 }
@@ -2392,6 +2439,7 @@ cairo_rel_line_to (cairo_t *cr, double dx, double dy)
 void
 cairo_rel_curve_to (cairo_t *cr, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g %g %g %g %g C ",
 		    dx1, dy1, dx2, dy2, dx3, dy3);
     DLCALL (cairo_rel_curve_to, cr, dx1, dy1, dx2, dy2, dx3, dy3);
@@ -2400,6 +2448,7 @@ cairo_rel_curve_to (cairo_t *cr, double dx1, double dy1, double dx2, double dy2,
 void
 cairo_rectangle (cairo_t *cr, double x, double y, double width, double height)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "%g %g %g %g rectangle\n", x, y, width, height);
     DLCALL (cairo_rectangle, cr, x, y, width, height);
 }
@@ -2407,6 +2456,7 @@ cairo_rectangle (cairo_t *cr, double x, double y, double width, double height)
 void
 cairo_close_path (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_cairo_op (cr, "h\n");
     DLCALL (cairo_close_path, cr);
 }
@@ -2414,6 +2464,7 @@ cairo_close_path (cairo_t *cr)
 void
 cairo_paint (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "paint\n");
     DLCALL (cairo_paint, cr);
@@ -2422,6 +2473,7 @@ cairo_paint (cairo_t *cr)
 void
 cairo_paint_with_alpha (cairo_t *cr, double alpha)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g paint-with-alpha\n", alpha);
     DLCALL (cairo_paint_with_alpha, cr, alpha);
@@ -2430,6 +2482,7 @@ cairo_paint_with_alpha (cairo_t *cr, double alpha)
 void
 cairo_mask (cairo_t *cr, cairo_pattern_t *pattern)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && pattern != NULL && _write_lock ()) {
 	Object *obj = _get_object (PATTERN, pattern);
@@ -2468,6 +2521,7 @@ cairo_mask (cairo_t *cr, cairo_pattern_t *pattern)
 void
 cairo_mask_surface (cairo_t *cr, cairo_surface_t *surface, double x, double y)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && surface != NULL && _write_lock ()) {
 	if (_is_current (SURFACE, surface, 0) &&
@@ -2500,6 +2554,7 @@ cairo_mask_surface (cairo_t *cr, cairo_surface_t *surface, double x, double y)
 void
 cairo_stroke (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "stroke\n");
     DLCALL (cairo_stroke, cr);
@@ -2508,6 +2563,7 @@ cairo_stroke (cairo_t *cr)
 void
 cairo_stroke_preserve (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "stroke+\n");
     DLCALL (cairo_stroke_preserve, cr);
@@ -2516,6 +2572,7 @@ cairo_stroke_preserve (cairo_t *cr)
 void
 cairo_fill (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "fill\n");
     DLCALL (cairo_fill, cr);
@@ -2524,6 +2581,7 @@ cairo_fill (cairo_t *cr)
 void
 cairo_fill_preserve (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "fill+\n");
     DLCALL (cairo_fill_preserve, cr);
@@ -2532,6 +2590,7 @@ cairo_fill_preserve (cairo_t *cr)
 void
 cairo_copy_page (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "copy-page\n");
     DLCALL (cairo_copy_page, cr);
@@ -2540,6 +2599,7 @@ cairo_copy_page (cairo_t *cr)
 void
 cairo_show_page (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "show-page\n");
     DLCALL (cairo_show_page, cr);
@@ -2548,6 +2608,7 @@ cairo_show_page (cairo_t *cr)
 void
 cairo_clip (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "clip\n");
     DLCALL (cairo_clip, cr);
@@ -2556,6 +2617,7 @@ cairo_clip (cairo_t *cr)
 void
 cairo_clip_preserve (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "clip+\n");
     DLCALL (cairo_clip_preserve, cr);
@@ -2564,6 +2626,7 @@ cairo_clip_preserve (cairo_t *cr)
 void
 cairo_reset_clip (cairo_t *cr)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "reset-clip\n");
     DLCALL (cairo_reset_clip, cr);
@@ -2598,6 +2661,7 @@ _weight_to_string (cairo_font_weight_t font_weight)
 void
 cairo_select_font_face (cairo_t *cr, const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && _write_lock ()) {
 	_emit_context (cr);
@@ -2616,6 +2680,8 @@ cairo_get_font_face (cairo_t *cr)
     cairo_font_face_t *ret;
     long font_face_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_get_font_face, cr);
     font_face_id = _create_font_face_id (ret);
 
@@ -2628,6 +2694,7 @@ cairo_get_font_face (cairo_t *cr)
 void
 cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && font_face != NULL && _write_lock ()) {
 	if (_is_current (FONT_FACE, font_face, 0) &&
@@ -2658,6 +2725,7 @@ cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face)
 void
 cairo_set_font_size (cairo_t *cr, double size)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-font-size\n", size);
     DLCALL (cairo_set_font_size, cr, size);
@@ -2666,6 +2734,7 @@ cairo_set_font_size (cairo_t *cr, double size)
 void
 cairo_set_font_matrix (cairo_t *cr, const cairo_matrix_t *matrix)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g %g %g %g matrix set-font-matrix\n",
 		    matrix->xx, matrix->yx,
@@ -2725,6 +2794,8 @@ _emit_font_options (const cairo_font_options_t *options)
     cairo_hint_style_t hint_style;
     cairo_hint_metrics_t hint_metrics;
 
+    ENSURE_INIT_TRACE ();
+
     _trace_printf ("<<");
 
     antialias = DLCALL (cairo_font_options_get_antialias, options);
@@ -2757,6 +2828,7 @@ _emit_font_options (const cairo_font_options_t *options)
 void
 cairo_set_font_options (cairo_t *cr, const cairo_font_options_t *options)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && options != NULL && _write_lock ()) {
 	_emit_context (cr);
@@ -2773,6 +2845,8 @@ cairo_get_scaled_font (cairo_t *cr)
 {
     cairo_scaled_font_t *ret;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_get_scaled_font, cr);
 
     if (cr != NULL && ! _has_scaled_font_id (ret)) {
@@ -2787,6 +2861,7 @@ cairo_get_scaled_font (cairo_t *cr)
 void
 cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && scaled_font != NULL) {
 	if (_pop_operands_to (SCALED_FONT, scaled_font)) {
@@ -2842,6 +2917,8 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
     cairo_scaled_font_t *ret;
     long scaled_font_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_scaled_font_create, font_face, font_matrix, ctm, options);
     scaled_font_id = _create_scaled_font_id (ret);
 
@@ -2885,6 +2962,7 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
 void
 cairo_show_text (cairo_t *cr, const char *utf8)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && _write_lock ()) {
 	_emit_context (cr);
@@ -2988,6 +3066,7 @@ _emit_glyphs (cairo_scaled_font_t *font,
 void
 cairo_show_glyphs (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && glyphs != NULL && _write_lock ()) {
 	cairo_scaled_font_t *font;
@@ -3025,6 +3104,8 @@ cairo_show_text_glyphs (cairo_t			   *cr,
 {
     cairo_scaled_font_t *font;
 
+    ENSURE_INIT_TRACE ();
+
     font = DLCALL (cairo_get_scaled_font, cr);
 
     _emit_line_info ();
@@ -3058,6 +3139,7 @@ cairo_show_text_glyphs (cairo_t			   *cr,
 void
 cairo_text_path (cairo_t *cr, const char *utf8)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (cr != NULL && _write_lock ()) {
 	_emit_context (cr);
@@ -3073,6 +3155,8 @@ cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 {
     cairo_scaled_font_t *font;
 
+    ENSURE_INIT_TRACE ();
+
     font = DLCALL (cairo_get_scaled_font, cr);
 
     _emit_line_info ();
@@ -3094,6 +3178,8 @@ cairo_append_path (cairo_t *cr, const cairo_path_t *path)
     int i;
     cairo_path_data_t *p;
 
+    ENSURE_INIT_TRACE ();
+
     _emit_line_info ();
     if (cr == NULL || path == NULL) {
 	DLCALL (cairo_append_path, cr, path);
@@ -3135,6 +3221,8 @@ cairo_image_surface_create (cairo_format_t format, int width, int height)
     long surface_id;
     const char *format_str;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_image_surface_create, format, width, height);
 
     surface_id = _create_surface_id (ret);
@@ -3164,6 +3252,8 @@ cairo_image_surface_create_for_data (unsigned char *data, cairo_format_t format,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_image_surface_create_for_data, data, format, width, height, stride);
     surface_id = _create_surface_id (ret);
 
@@ -3213,6 +3303,8 @@ cairo_surface_create_similar (cairo_surface_t *other,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_surface_create_similar, other, content, width, height);
     surface_id = _create_surface_id (ret);
 
@@ -3260,6 +3352,7 @@ _emit_surface_op (cairo_surface_t *surface, const char *fmt, ...)
 void
 cairo_surface_finish (cairo_surface_t *surface)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     DLCALL (cairo_surface_finish, surface);
 }
@@ -3267,6 +3360,7 @@ cairo_surface_finish (cairo_surface_t *surface)
 void
 cairo_surface_flush (cairo_surface_t *surface)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     DLCALL (cairo_surface_flush, surface);
 }
@@ -3274,6 +3368,7 @@ cairo_surface_flush (cairo_surface_t *surface)
 void
 cairo_surface_mark_dirty (cairo_surface_t *surface)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	if (_mark_dirty) {
@@ -3292,6 +3387,7 @@ void
 cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface,
 				    int x, int y, int width, int height)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	if (_mark_dirty) {
@@ -3311,6 +3407,7 @@ cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface,
 void
 cairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, double y_offset)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_surface_op (surface, "%g %g set-device-offset\n",
 		      x_offset, y_offset);
@@ -3320,6 +3417,7 @@ cairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, doub
 void
 cairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels_per_inch, double y_pixels_per_inch)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_surface_op (surface, "%g %g set-fallback-resolution\n",
 		      x_pixels_per_inch, y_pixels_per_inch);
@@ -3329,6 +3427,7 @@ cairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels
 void
 cairo_surface_copy_page (cairo_surface_t *surface)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_surface_op (surface, "copy-page\n");
     DLCALL (cairo_surface_copy_page, surface);
@@ -3337,6 +3436,7 @@ cairo_surface_copy_page (cairo_surface_t *surface)
 void
 cairo_surface_show_page (cairo_surface_t *surface)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_surface_op (surface, "show-page\n");
     DLCALL (cairo_surface_show_page, surface);
@@ -3350,6 +3450,7 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 			     cairo_destroy_func_t	 destroy,
 			     void			*closure)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	_emit_surface (surface);
@@ -3373,6 +3474,7 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 cairo_status_t
 cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	_trace_printf ("%% s%ld ", _get_surface_id (surface));
@@ -3388,6 +3490,7 @@ cairo_surface_write_to_png_stream (cairo_surface_t *surface,
 				   cairo_write_func_t write_func,
 				   void *data)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (surface != NULL && _write_lock ()) {
 	char symbol[1024];
@@ -3429,6 +3532,8 @@ cairo_pattern_create_rgb (double red, double green, double blue)
     cairo_pattern_t *ret;
     long pattern_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_pattern_create_rgb, red, green, blue);
     pattern_id = _create_pattern_id (ret);
 
@@ -3449,6 +3554,8 @@ cairo_pattern_create_rgba (double red, double green, double blue, double alpha)
     cairo_pattern_t *ret;
     long pattern_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_pattern_create_rgba, red, green, blue, alpha);
     pattern_id = _create_pattern_id (ret);
 
@@ -3470,6 +3577,8 @@ cairo_pattern_create_for_surface (cairo_surface_t *surface)
     long pattern_id;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_pattern_create_for_surface, surface);
     pattern_id = _create_pattern_id (ret);
 
@@ -3500,6 +3609,8 @@ cairo_pattern_create_linear (double x0, double y0, double x1, double y1)
     cairo_pattern_t *ret;
     long pattern_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_pattern_create_linear, x0, y0, x1, y1);
     pattern_id = _create_pattern_id (ret);
 
@@ -3520,6 +3631,8 @@ cairo_pattern_create_radial (double cx0, double cy0, double radius0, double cx1,
     cairo_pattern_t *ret;
     long pattern_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_pattern_create_radial,
 		  cx0, cy0, radius0,
 		  cx1, cy1, radius1);
@@ -3540,6 +3653,7 @@ cairo_pattern_create_radial (double cx0, double cy0, double radius0, double cx1,
 void
 cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, double offset, double red, double green, double blue)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_pattern_op (pattern,
 		      "%g %g %g %g 1 add-color-stop\n",
@@ -3550,6 +3664,7 @@ cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, double offset, doubl
 void
 cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, double offset, double red, double green, double blue, double alpha)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_pattern_op (pattern,
 		      "%g %g %g %g %g add-color-stop\n",
@@ -3560,6 +3675,7 @@ cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, double offset, doub
 void
 cairo_pattern_set_matrix (cairo_pattern_t *pattern, const cairo_matrix_t *matrix)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     if (_matrix_is_identity (matrix)) {
 	_emit_pattern_op (pattern, "identity set-matrix\n");
@@ -3592,6 +3708,7 @@ _filter_to_string (cairo_filter_t filter)
 void
 cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_pattern_op (pattern, "//%s set-filter\n", _filter_to_string (filter));
     DLCALL (cairo_pattern_set_filter, pattern, filter);
@@ -3614,6 +3731,7 @@ _extend_to_string (cairo_extend_t extend)
 void
 cairo_pattern_set_extend (cairo_pattern_t *pattern, cairo_extend_t extend)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     _emit_pattern_op (pattern, "//%s set-extend\n", _extend_to_string (extend));
     DLCALL (cairo_pattern_set_extend, pattern, extend);
@@ -3627,6 +3745,8 @@ cairo_ft_font_face_create_for_pattern (FcPattern *pattern)
     cairo_font_face_t *ret;
     long font_face_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_ft_font_face_create_for_pattern, pattern);
     font_face_id = _create_font_face_id (ret);
 
@@ -3679,6 +3799,8 @@ cairo_ft_font_face_create_for_ft_face (FT_Face face, int load_flags)
     FtFaceData *data;
     long font_face_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_ft_font_face_create_for_ft_face, face, load_flags);
     font_face_id = _create_font_face_id (ret);
 
@@ -3743,6 +3865,8 @@ FT_New_Face (FT_Library library, const char *pathname, FT_Long index, FT_Face *f
 {
     FT_Error ret;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (FT_New_Face, library, pathname, index, face);
     if (ret == 0) {
 	Object *obj = _type_object_create (NONE, *face);
@@ -3763,6 +3887,8 @@ FT_New_Memory_Face (FT_Library library, const FT_Byte *mem, FT_Long size, FT_Lon
 {
     FT_Error ret;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (FT_New_Memory_Face, library, mem, size, index, face);
     if (ret == 0) {
 	Object *obj = _type_object_create (NONE, *face);
@@ -3791,6 +3917,8 @@ FT_Open_Face (FT_Library library, const FT_Open_Args *args, FT_Long index, FT_Fa
 {
     FT_Error ret;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (FT_Open_Face, library, args, index, face);
     if (args->flags & FT_OPEN_MEMORY)
 	fprintf (stderr, "FT_Open_Face (mem=%p, %ld, %ld) = %p\n",
@@ -3810,6 +3938,8 @@ FT_Open_Face (FT_Library library, const FT_Open_Args *args, FT_Long index, FT_Fa
 FT_Error
 FT_Done_Face (FT_Face face)
 {
+    ENSURE_INIT_TRACE ();
+
     _object_destroy (_get_object (NONE, face));
 
     return DLCALL (FT_Done_Face, face);
@@ -3843,6 +3973,8 @@ cairo_ps_surface_create (const char *filename, double width_in_points, double he
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_ps_surface_create, filename, width_in_points, height_in_points);
     surface_id = _create_surface_id (ret);
 
@@ -3873,6 +4005,8 @@ cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, void *closure
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_ps_surface_create_for_stream, write_func, closure, width_in_points, height_in_points);
     surface_id = _create_surface_id (ret);
 
@@ -3897,6 +4031,7 @@ cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, void *closure
 void
 cairo_ps_surface_set_size (cairo_surface_t *surface, double width_in_points, double height_in_points)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     DLCALL (cairo_ps_surface_set_size, surface, width_in_points, height_in_points);
 }
@@ -3912,6 +4047,8 @@ cairo_pdf_surface_create (const char *filename, double width_in_points, double h
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_pdf_surface_create, filename, width_in_points, height_in_points);
     surface_id = _create_surface_id (ret);
 
@@ -3942,6 +4079,8 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, void *closur
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_pdf_surface_create_for_stream, write_func, closure, width_in_points, height_in_points);
     surface_id = _create_surface_id (ret);
 
@@ -3965,6 +4104,7 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, void *closur
 void
 cairo_pdf_surface_set_size (cairo_surface_t *surface, double width_in_points, double height_in_points)
 {
+    ENSURE_INIT_TRACE ();
     _emit_line_info ();
     DLCALL (cairo_pdf_surface_set_size, surface, width_in_points, height_in_points);
 }
@@ -3979,6 +4119,8 @@ cairo_svg_surface_create (const char *filename, double width, double height)
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_svg_surface_create, filename, width, height);
     surface_id = _create_surface_id (ret);
 
@@ -4009,6 +4151,8 @@ cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, void *closur
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_svg_surface_create_for_stream, write_func, closure, width, height);
     surface_id = _create_surface_id (ret);
 
@@ -4039,6 +4183,8 @@ cairo_image_surface_create_from_png (const char *filename)
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_image_surface_create_from_png, filename);
 
     surface_id = _create_surface_id (ret);
@@ -4067,6 +4213,8 @@ cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, void *c
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_image_surface_create_from_png_stream, read_func, closure);
     surface_id = _create_surface_id (ret);
 
@@ -4103,6 +4251,8 @@ cairo_xlib_surface_create (Display *dpy,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_xlib_surface_create,
 	          dpy, drawable, visual, width, height);
     surface_id = _create_surface_id (ret);
@@ -4140,6 +4290,8 @@ cairo_xlib_surface_create_for_bitmap (Display *dpy,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_xlib_surface_create_for_bitmap,
 	          dpy, bitmap, screen, width, height);
     surface_id = _create_surface_id (ret);
@@ -4181,6 +4333,8 @@ cairo_xlib_surface_create_with_xrender_format (Display *dpy,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_xlib_surface_create_with_xrender_format,
 	          dpy, drawable, screen, format, width, height);
     surface_id = _create_surface_id (ret);
@@ -4224,6 +4378,8 @@ cairo_script_surface_create (cairo_script_context_t *ctx,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_script_surface_create, ctx, content, width, height);
     surface_id = _create_surface_id (ret);
 
@@ -4254,6 +4410,8 @@ cairo_script_surface_create_for_target (cairo_script_context_t *ctx,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_script_surface_create_for_target, ctx, target);
     surface_id = _create_surface_id (ret);
 
@@ -4282,6 +4440,8 @@ _cairo_test_fallback_surface_create (cairo_content_t	content,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (_cairo_test_fallback_surface_create, content, width, height);
     surface_id = _create_surface_id (ret);
 
@@ -4312,6 +4472,8 @@ _cairo_test_paginated_surface_create (cairo_surface_t *surface)
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (_cairo_test_paginated_surface_create, surface);
     surface_id = _create_surface_id (ret);
 
@@ -4339,6 +4501,8 @@ _cairo_test_null_surface_create (cairo_content_t	content)
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (_cairo_test_null_surface_create, content);
     surface_id = _create_surface_id (ret);
 
@@ -4366,6 +4530,8 @@ cairo_meta_surface_create (cairo_content_t content,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_meta_surface_create, content, extents);
     surface_id = _create_surface_id (ret);
 
@@ -4401,7 +4567,9 @@ cairo_meta_surface_create (cairo_content_t content,
 cairo_status_t
 cairo_meta_surface_replay (cairo_surface_t *meta, cairo_surface_t *target)
 {
-    cairo_status_t
+    cairo_status_t ret;
+
+    ENSURE_INIT_TRACE ();
 
     ret = DLCALL (cairo_meta_surface_replay, meta, target);
 
@@ -4427,6 +4595,8 @@ cairo_vg_surface_create (cairo_vg_context_t *context,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_vg_surface_create, context, content, width, height);
     surface_id = _create_surface_id (ret);
 
@@ -4459,6 +4629,8 @@ cairo_vg_surface_create_for_image (cairo_vg_context_t *context,
     cairo_surface_t *ret;
     long surface_id;
 
+    ENSURE_INIT_TRACE ();
+
     ret = DLCALL (cairo_vg_surface_create_for_image,
 		  context, image, format, width, height);
     surface_id = _create_surface_id (ret);
commit 18a441984b649f558c6478f24a7987941acadbe1
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Sun Sep 13 13:53:27 2009 +0100

    [trace] Don't try and propagate a void result.
    
    The pattern
    
    	return <function returning void>( ... );
    
    is a gccism not supported by Sun Studio.

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index c826ea2..c2eec1f 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -1824,7 +1824,7 @@ cairo_save (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "save\n");
-    return DLCALL (cairo_save, cr);
+    DLCALL (cairo_save, cr);
 }
 
 void
@@ -1832,7 +1832,7 @@ cairo_restore (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "restore\n");
-    return DLCALL (cairo_restore, cr);
+    DLCALL (cairo_restore, cr);
 }
 
 void
@@ -1840,7 +1840,7 @@ cairo_push_group (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "//COLOR_ALPHA push-group\n");
-    return DLCALL (cairo_push_group, cr);
+    DLCALL (cairo_push_group, cr);
 }
 
 static const char *
@@ -1859,7 +1859,7 @@ cairo_push_group_with_content (cairo_t *cr, cairo_content_t content)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s push-group\n", _content_to_string (content));
-    return DLCALL (cairo_push_group_with_content, cr, content);
+    DLCALL (cairo_push_group_with_content, cr, content);
 }
 
 cairo_pattern_t *
@@ -1881,7 +1881,7 @@ cairo_pop_group_to_source (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "pop-group set-source\n");
-    return DLCALL (cairo_pop_group_to_source, cr);
+    DLCALL (cairo_pop_group_to_source, cr);
 }
 
 static const char *
@@ -1928,7 +1928,7 @@ cairo_set_operator (cairo_t *cr, cairo_operator_t op)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s set-operator\n", _operator_to_string (op));
-    return DLCALL (cairo_set_operator, cr, op);
+    DLCALL (cairo_set_operator, cr, op);
 }
 
 void
@@ -1936,7 +1936,7 @@ cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g set-source-rgb\n", red, green, blue);
-    return DLCALL (cairo_set_source_rgb, cr, red, green, blue);
+    DLCALL (cairo_set_source_rgb, cr, red, green, blue);
 }
 
 void
@@ -1945,7 +1945,7 @@ cairo_set_source_rgba (cairo_t *cr, double red, double green, double blue, doubl
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g %g %g set-source-rgba\n",
 		    red, green, blue, alpha);
-    return DLCALL (cairo_set_source_rgba, cr, red, green, blue, alpha);
+    DLCALL (cairo_set_source_rgba, cr, red, green, blue, alpha);
 }
 
 static void
@@ -1988,8 +1988,10 @@ _emit_source_image_rectangle (cairo_surface_t *surface,
     if (obj == NULL)
 	return;
 
-    if (obj->foreign)
-	return _emit_source_image (surface);
+    if (obj->foreign) {
+	_emit_source_image (surface);
+	return;
+    }
 
     image = DLCALL (cairo_image_surface_create,
 		    CAIRO_FORMAT_ARGB32,
@@ -2038,7 +2040,7 @@ cairo_set_source_surface (cairo_t *cr, cairo_surface_t *surface, double x, doubl
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_set_source_surface, cr, surface, x, y);
+    DLCALL (cairo_set_source_surface, cr, surface, x, y);
 }
 
 void
@@ -2077,7 +2079,7 @@ cairo_set_source (cairo_t *cr, cairo_pattern_t *source)
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_set_source, cr, source);
+    DLCALL (cairo_set_source, cr, source);
 }
 
 cairo_pattern_t *
@@ -2101,7 +2103,7 @@ cairo_set_tolerance (cairo_t *cr, double tolerance)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-tolerance\n", tolerance);
-    return DLCALL (cairo_set_tolerance, cr, tolerance);
+    DLCALL (cairo_set_tolerance, cr, tolerance);
 }
 
 static const char *
@@ -2124,7 +2126,7 @@ cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-antialias\n", _antialias_to_string (antialias));
-    return DLCALL (cairo_set_antialias, cr, antialias);
+    DLCALL (cairo_set_antialias, cr, antialias);
 }
 
 static const char *
@@ -2145,7 +2147,7 @@ cairo_set_fill_rule (cairo_t *cr, cairo_fill_rule_t fill_rule)
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-fill-rule\n", _fill_rule_to_string (fill_rule));
-    return DLCALL (cairo_set_fill_rule, cr, fill_rule);
+    DLCALL (cairo_set_fill_rule, cr, fill_rule);
 }
 
 void
@@ -2153,7 +2155,7 @@ cairo_set_line_width (cairo_t *cr, double width)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-line-width\n", width);
-    return DLCALL (cairo_set_line_width, cr, width);
+    DLCALL (cairo_set_line_width, cr, width);
 }
 
 static const char *
@@ -2174,7 +2176,7 @@ cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "//%s set-line-cap\n", _line_cap_to_string (line_cap));
-    return DLCALL (cairo_set_line_cap, cr, line_cap);
+    DLCALL (cairo_set_line_cap, cr, line_cap);
 }
 
 static const char *
@@ -2196,7 +2198,7 @@ cairo_set_line_join (cairo_t *cr, cairo_line_join_t line_join)
     _emit_line_info ();
     _emit_cairo_op (cr,
 		    "//%s set-line-join\n", _line_join_to_string (line_join));
-    return DLCALL (cairo_set_line_join, cr, line_join);
+    DLCALL (cairo_set_line_join, cr, line_join);
 }
 
 void
@@ -2219,7 +2221,7 @@ cairo_set_dash (cairo_t *cr, const double *dashes, int num_dashes, double offset
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_set_dash, cr, dashes, num_dashes, offset);
+    DLCALL (cairo_set_dash, cr, dashes, num_dashes, offset);
 }
 
 void
@@ -2227,7 +2229,7 @@ cairo_set_miter_limit (cairo_t *cr, double limit)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-miter-limit\n", limit);
-    return DLCALL (cairo_set_miter_limit, cr, limit);
+    DLCALL (cairo_set_miter_limit, cr, limit);
 }
 
 void
@@ -2235,7 +2237,7 @@ cairo_translate (cairo_t *cr, double tx, double ty)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g translate\n", tx, ty);
-    return DLCALL (cairo_translate, cr, tx, ty);
+    DLCALL (cairo_translate, cr, tx, ty);
 }
 
 void
@@ -2243,7 +2245,7 @@ cairo_scale (cairo_t *cr, double sx, double sy)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "%g %g scale\n", sx, sy);
-    return DLCALL (cairo_scale, cr, sx, sy);
+    DLCALL (cairo_scale, cr, sx, sy);
 }
 
 void
@@ -2251,7 +2253,7 @@ cairo_rotate (cairo_t *cr, double angle)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "%g rotate\n", angle);
-    return DLCALL (cairo_rotate, cr, angle);
+    DLCALL (cairo_rotate, cr, angle);
 }
 
 void
@@ -2262,7 +2264,7 @@ cairo_transform (cairo_t *cr, const cairo_matrix_t *matrix)
 		    matrix->xx, matrix->yx,
 		    matrix->xy, matrix->yy,
 		    matrix->x0, matrix->y0);
-    return DLCALL (cairo_transform, cr, matrix);
+    DLCALL (cairo_transform, cr, matrix);
 }
 
 void
@@ -2277,7 +2279,7 @@ cairo_set_matrix (cairo_t *cr, const cairo_matrix_t *matrix)
 			matrix->xy, matrix->yy,
 			matrix->x0, matrix->y0);
     }
-    return DLCALL (cairo_set_matrix, cr, matrix);
+    DLCALL (cairo_set_matrix, cr, matrix);
 }
 
 cairo_surface_t *
@@ -2319,7 +2321,7 @@ cairo_identity_matrix (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "identity set-matrix\n");
-    return DLCALL (cairo_identity_matrix, cr);
+    DLCALL (cairo_identity_matrix, cr);
 }
 
 void
@@ -2327,42 +2329,42 @@ cairo_new_path (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "n ");
-    return DLCALL (cairo_new_path, cr);
+    DLCALL (cairo_new_path, cr);
 }
 
 void
 cairo_move_to (cairo_t *cr, double x, double y)
 {
     _emit_cairo_op (cr, "%g %g m ", x, y);
-    return DLCALL (cairo_move_to, cr, x, y);
+    DLCALL (cairo_move_to, cr, x, y);
 }
 
 void
 cairo_new_sub_path (cairo_t *cr)
 {
     _emit_cairo_op (cr, "N ");
-    return DLCALL (cairo_new_sub_path, cr);
+    DLCALL (cairo_new_sub_path, cr);
 }
 
 void
 cairo_line_to (cairo_t *cr, double x, double y)
 {
     _emit_cairo_op (cr, "%g %g l ", x, y);
-    return DLCALL (cairo_line_to, cr, x, y);
+    DLCALL (cairo_line_to, cr, x, y);
 }
 
 void
 cairo_curve_to (cairo_t *cr, double x1, double y1, double x2, double y2, double x3, double y3)
 {
     _emit_cairo_op (cr, "%g %g %g %g %g %g c ", x1, y1, x2, y2, x3, y3);
-    return DLCALL (cairo_curve_to, cr, x1, y1, x2, y2, x3, y3);
+    DLCALL (cairo_curve_to, cr, x1, y1, x2, y2, x3, y3);
 }
 
 void
 cairo_arc (cairo_t *cr, double xc, double yc, double radius, double angle1, double angle2)
 {
     _emit_cairo_op (cr, "%g %g %g %g %g arc\n", xc, yc, radius, angle1, angle2);
-    return DLCALL (cairo_arc, cr, xc, yc, radius, angle1, angle2);
+    DLCALL (cairo_arc, cr, xc, yc, radius, angle1, angle2);
 }
 
 void
@@ -2370,21 +2372,21 @@ cairo_arc_negative (cairo_t *cr, double xc, double yc, double radius, double ang
 {
     _emit_cairo_op (cr, "%g %g %g %g %g arc-\n",
 		    xc, yc, radius, angle1, angle2);
-    return DLCALL (cairo_arc_negative, cr, xc, yc, radius, angle1, angle2);
+    DLCALL (cairo_arc_negative, cr, xc, yc, radius, angle1, angle2);
 }
 
 void
 cairo_rel_move_to (cairo_t *cr, double dx, double dy)
 {
     _emit_cairo_op (cr, "%g %g M ", dx, dy);
-    return DLCALL (cairo_rel_move_to, cr, dx, dy);
+    DLCALL (cairo_rel_move_to, cr, dx, dy);
 }
 
 void
 cairo_rel_line_to (cairo_t *cr, double dx, double dy)
 {
     _emit_cairo_op (cr, "%g %g L ", dx, dy);
-    return DLCALL (cairo_rel_line_to, cr, dx, dy);
+    DLCALL (cairo_rel_line_to, cr, dx, dy);
 }
 
 void
@@ -2392,21 +2394,21 @@ cairo_rel_curve_to (cairo_t *cr, double dx1, double dy1, double dx2, double dy2,
 {
     _emit_cairo_op (cr, "%g %g %g %g %g %g C ",
 		    dx1, dy1, dx2, dy2, dx3, dy3);
-    return DLCALL (cairo_rel_curve_to, cr, dx1, dy1, dx2, dy2, dx3, dy3);
+    DLCALL (cairo_rel_curve_to, cr, dx1, dy1, dx2, dy2, dx3, dy3);
 }
 
 void
 cairo_rectangle (cairo_t *cr, double x, double y, double width, double height)
 {
     _emit_cairo_op (cr, "%g %g %g %g rectangle\n", x, y, width, height);
-    return DLCALL (cairo_rectangle, cr, x, y, width, height);
+    DLCALL (cairo_rectangle, cr, x, y, width, height);
 }
 
 void
 cairo_close_path (cairo_t *cr)
 {
     _emit_cairo_op (cr, "h\n");
-    return DLCALL (cairo_close_path, cr);
+    DLCALL (cairo_close_path, cr);
 }
 
 void
@@ -2532,7 +2534,7 @@ cairo_copy_page (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "copy-page\n");
-    return DLCALL (cairo_copy_page, cr);
+    DLCALL (cairo_copy_page, cr);
 }
 
 void
@@ -2540,7 +2542,7 @@ cairo_show_page (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "show-page\n");
-    return DLCALL (cairo_show_page, cr);
+    DLCALL (cairo_show_page, cr);
 }
 
 void
@@ -2564,7 +2566,7 @@ cairo_reset_clip (cairo_t *cr)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "reset-clip\n");
-    return DLCALL (cairo_reset_clip, cr);
+    DLCALL (cairo_reset_clip, cr);
 }
 
 
@@ -2605,7 +2607,7 @@ cairo_select_font_face (cairo_t *cr, const char *family, cairo_font_slant_t slan
 		       _weight_to_string (weight));
 	_write_unlock ();
     }
-    return DLCALL (cairo_select_font_face, cr, family, slant, weight);
+    DLCALL (cairo_select_font_face, cr, family, slant, weight);
 }
 
 cairo_font_face_t *
@@ -2650,7 +2652,7 @@ cairo_set_font_face (cairo_t *cr, cairo_font_face_t *font_face)
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_set_font_face, cr, font_face);
+    DLCALL (cairo_set_font_face, cr, font_face);
 }
 
 void
@@ -2658,7 +2660,7 @@ cairo_set_font_size (cairo_t *cr, double size)
 {
     _emit_line_info ();
     _emit_cairo_op (cr, "%g set-font-size\n", size);
-    return DLCALL (cairo_set_font_size, cr, size);
+    DLCALL (cairo_set_font_size, cr, size);
 }
 
 void
@@ -2669,7 +2671,7 @@ cairo_set_font_matrix (cairo_t *cr, const cairo_matrix_t *matrix)
 		    matrix->xx, matrix->yx,
 		    matrix->xy, matrix->yy,
 		    matrix->x0, matrix->y0);
-    return DLCALL (cairo_set_font_matrix, cr, matrix);
+    DLCALL (cairo_set_font_matrix, cr, matrix);
 }
 
 static const char *
@@ -2763,7 +2765,7 @@ cairo_set_font_options (cairo_t *cr, const cairo_font_options_t *options)
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_set_font_options, cr, options);
+    DLCALL (cairo_set_font_options, cr, options);
 }
 
 cairo_scaled_font_t *
@@ -2812,7 +2814,7 @@ cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font)
 			    _get_scaled_font_id (scaled_font));
 	}
     }
-    return DLCALL (cairo_set_scaled_font, cr, scaled_font);
+    DLCALL (cairo_set_scaled_font, cr, scaled_font);
 }
 
 static void
@@ -3063,7 +3065,7 @@ cairo_text_path (cairo_t *cr, const char *utf8)
 	_trace_printf (" text-path\n");
 	_write_unlock ();
     }
-    return DLCALL (cairo_text_path, cr, utf8);
+    DLCALL (cairo_text_path, cr, utf8);
 }
 
 void
@@ -3082,7 +3084,7 @@ cairo_glyph_path (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs)
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_glyph_path, cr, glyphs, num_glyphs);
+    DLCALL (cairo_glyph_path, cr, glyphs, num_glyphs);
 }
 
 void
@@ -3093,8 +3095,10 @@ cairo_append_path (cairo_t *cr, const cairo_path_t *path)
     cairo_path_data_t *p;
 
     _emit_line_info ();
-    if (cr == NULL || path == NULL)
-	return DLCALL (cairo_append_path, cr, path);
+    if (cr == NULL || path == NULL) {
+	DLCALL (cairo_append_path, cr, path);
+	return;
+    }
 
     for (i=0; i < path->num_data; i += path->data[i].header.length) {
 	p = &path->data[i];
@@ -3257,14 +3261,14 @@ void
 cairo_surface_finish (cairo_surface_t *surface)
 {
     _emit_line_info ();
-    return DLCALL (cairo_surface_finish, surface);
+    DLCALL (cairo_surface_finish, surface);
 }
 
 void
 cairo_surface_flush (cairo_surface_t *surface)
 {
     _emit_line_info ();
-    return DLCALL (cairo_surface_flush, surface);
+    DLCALL (cairo_surface_flush, surface);
 }
 
 void
@@ -3281,7 +3285,7 @@ cairo_surface_mark_dirty (cairo_surface_t *surface)
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_surface_mark_dirty, surface);
+    DLCALL (cairo_surface_mark_dirty, surface);
 }
 
 void
@@ -3301,7 +3305,7 @@ cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface,
 	_write_unlock ();
     }
 
-    return DLCALL (cairo_surface_mark_dirty_rectangle, surface, x, y, width, height);
+    DLCALL (cairo_surface_mark_dirty_rectangle, surface, x, y, width, height);
 }
 
 void
@@ -3310,7 +3314,7 @@ cairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, doub
     _emit_line_info ();
     _emit_surface_op (surface, "%g %g set-device-offset\n",
 		      x_offset, y_offset);
-    return DLCALL (cairo_surface_set_device_offset, surface, x_offset, y_offset);
+    DLCALL (cairo_surface_set_device_offset, surface, x_offset, y_offset);
 }
 
 void
@@ -3319,7 +3323,7 @@ cairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels
     _emit_line_info ();
     _emit_surface_op (surface, "%g %g set-fallback-resolution\n",
 		      x_pixels_per_inch, y_pixels_per_inch);
-    return DLCALL (cairo_surface_set_fallback_resolution, surface, x_pixels_per_inch, y_pixels_per_inch);
+    DLCALL (cairo_surface_set_fallback_resolution, surface, x_pixels_per_inch, y_pixels_per_inch);
 }
 
 void
@@ -3327,7 +3331,7 @@ cairo_surface_copy_page (cairo_surface_t *surface)
 {
     _emit_line_info ();
     _emit_surface_op (surface, "copy-page\n");
-    return DLCALL (cairo_surface_copy_page, surface);
+    DLCALL (cairo_surface_copy_page, surface);
 }
 
 void
@@ -3335,7 +3339,7 @@ cairo_surface_show_page (cairo_surface_t *surface)
 {
     _emit_line_info ();
     _emit_surface_op (surface, "show-page\n");
-    return DLCALL (cairo_surface_show_page, surface);
+    DLCALL (cairo_surface_show_page, surface);
 }
 
 cairo_status_t
@@ -3540,7 +3544,7 @@ cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, double offset, doubl
     _emit_pattern_op (pattern,
 		      "%g %g %g %g 1 add-color-stop\n",
 		      offset, red, green, blue);
-    return DLCALL (cairo_pattern_add_color_stop_rgb, pattern, offset, red, green, blue);
+    DLCALL (cairo_pattern_add_color_stop_rgb, pattern, offset, red, green, blue);
 }
 
 void
@@ -3550,7 +3554,7 @@ cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, double offset, doub
     _emit_pattern_op (pattern,
 		      "%g %g %g %g %g add-color-stop\n",
 		      offset, red, green, blue, alpha);
-    return DLCALL (cairo_pattern_add_color_stop_rgba, pattern, offset, red, green, blue, alpha);
+    DLCALL (cairo_pattern_add_color_stop_rgba, pattern, offset, red, green, blue, alpha);
 }
 
 void
@@ -3566,7 +3570,7 @@ cairo_pattern_set_matrix (cairo_pattern_t *pattern, const cairo_matrix_t *matrix
 			  matrix->xy, matrix->yy,
 			  matrix->x0, matrix->y0);
     }
-    return DLCALL (cairo_pattern_set_matrix, pattern, matrix);
+    DLCALL (cairo_pattern_set_matrix, pattern, matrix);
 }
 
 static const char *
@@ -3590,7 +3594,7 @@ cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter)
 {
     _emit_line_info ();
     _emit_pattern_op (pattern, "//%s set-filter\n", _filter_to_string (filter));
-    return DLCALL (cairo_pattern_set_filter, pattern, filter);
+    DLCALL (cairo_pattern_set_filter, pattern, filter);
 }
 
 static const char *
@@ -3612,7 +3616,7 @@ cairo_pattern_set_extend (cairo_pattern_t *pattern, cairo_extend_t extend)
 {
     _emit_line_info ();
     _emit_pattern_op (pattern, "//%s set-extend\n", _extend_to_string (extend));
-    return DLCALL (cairo_pattern_set_extend, pattern, extend);
+    DLCALL (cairo_pattern_set_extend, pattern, extend);
 }
 
 #if CAIRO_HAS_FT_FONT
@@ -3894,7 +3898,7 @@ void
 cairo_ps_surface_set_size (cairo_surface_t *surface, double width_in_points, double height_in_points)
 {
     _emit_line_info ();
-    return DLCALL (cairo_ps_surface_set_size, surface, width_in_points, height_in_points);
+    DLCALL (cairo_ps_surface_set_size, surface, width_in_points, height_in_points);
 }
 
 #endif
@@ -3962,7 +3966,7 @@ void
 cairo_pdf_surface_set_size (cairo_surface_t *surface, double width_in_points, double height_in_points)
 {
     _emit_line_info ();
-    return DLCALL (cairo_pdf_surface_set_size, surface, width_in_points, height_in_points);
+    DLCALL (cairo_pdf_surface_set_size, surface, width_in_points, height_in_points);
 }
 #endif
 
commit fee5c58c6caecdbdb387fe39bd6ed94faf7f6ae9
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Sun Sep 13 13:09:47 2009 +0100

    [trace] Avoid warnings from assigning a void pointer to a function pointer.
    
    The Sun Studio compiler complains a *lot* when assigning the result
    of dlsym to a function pointer.  Cast the result to the proper
    type first.:w

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index 5a1f908..c826ea2 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -87,10 +87,10 @@ static void *_dlhandle = RTLD_NEXT;
 #define DLCALL(name, args...) ({ \
     static typeof (&name) name##_real; \
     if (name##_real == NULL) { \
-	name##_real = dlsym (_dlhandle, #name); \
+	name##_real = (typeof (&name))(dlsym (_dlhandle, #name));	\
 	if (name##_real == NULL && _dlhandle == RTLD_NEXT) { \
 	    _dlhandle = dlopen ("libcairo.so", RTLD_LAZY); \
-	    name##_real = dlsym (_dlhandle, #name); \
+	    name##_real = (typeof (&name))(dlsym (_dlhandle, #name));	\
 	    assert (name##_real != NULL); \
 	} \
     } \


More information about the cairo-commit mailing list