[cairo-commit] 10 commits - boilerplate/make-cairo-boilerplate-constructors.sh build/aclocal.cairo.m4 build/configure.ac.analysis build/configure.ac.system build/configure.ac.warnings NEWS test/make-cairo-test-constructors.sh util/cairo-trace

M. Joonas Pihlaja joonas at kemper.freedesktop.org
Tue Sep 1 20:54:31 PDT 2009


 NEWS                                               |    5 
 boilerplate/make-cairo-boilerplate-constructors.sh |    7 
 build/aclocal.cairo.m4                             |   63 +++
 build/configure.ac.analysis                        |    2 
 build/configure.ac.system                          |   12 
 build/configure.ac.warnings                        |   18 -
 test/make-cairo-test-constructors.sh               |    7 
 util/cairo-trace/cairo-trace.in                    |    3 
 util/cairo-trace/trace.c                           |  377 ++++++++++++---------
 9 files changed, 316 insertions(+), 178 deletions(-)

New commits:
commit f5df38ca5efcbc0cd3cc18d9fb67df49ec4859f8
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Wed Sep 2 04:38:52 2009 +0100

    [build] Fix typos in prototype warnings.
    
    The -Wstrict-prototypes and -Wmissing-prototypes warnings
    weren't actually in use due to typos.

diff --git a/build/configure.ac.warnings b/build/configure.ac.warnings
index 53eacb1..212f8a0 100644
--- a/build/configure.ac.warnings
+++ b/build/configure.ac.warnings
@@ -12,7 +12,7 @@ MAYBE_WARN="-Wall -Wextra \
 -Wold-style-definition \
 -Wmissing-declarations -Werror-implicit-function-declaration \
 -Wnested-externs -Wpointer-arith -Wwrite-strings \
--Wsign-compare -Wstrict-prototpes -Wmissig-prototyess \
+-Wsign-compare -Wstrict-prototypes -Wmissing-prototypes \
 -Wpacked -Wswitch-enum -Wmissing-format-attribute \
 -Wbad-function-cast -Wvolatile-register-var \
 -Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \
commit c086b40a93057a6fd47d23c85c5026d6fe2f524a
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Wed Sep 2 04:29:18 2009 +0100

    [build] Hush the Solaris compiler about enum abuse.
    
    Sun Studio 12 doesn't like it when we mix our
    enum values and types.  We do that a lot on purpose
    so the warnings from compiles were very verbose.

diff --git a/build/aclocal.cairo.m4 b/build/aclocal.cairo.m4
index 021c22f..5eec262 100644
--- a/build/aclocal.cairo.m4
+++ b/build/aclocal.cairo.m4
@@ -111,21 +111,40 @@ AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT],
 	fi
 ])
 
+dnl find a -Werror equivalent
+AC_DEFUN([CAIRO_CC_CHECK_WERROR],
+[dnl
+	_test_WERROR=${WERROR+set}
+	if test "z$_test_WERROR" != zset; then
+		WERROR=""
+		for _werror in -Werror -errwarn; do
+			AC_MSG_CHECKING([whether $CC supports $_werror])
+			CAIRO_CC_TRY_FLAG_SILENT(
+				[$_werror],,
+				[WERROR="$WERROR $_werror"],
+				[:])
+			AC_MSG_RESULT($cairo_cc_flag)
+		done
+	fi
+])
+
 dnl check compiler flags possibly using -Werror if available.
 AC_DEFUN([CAIRO_CC_TRY_FLAG],
 [dnl     (flags..., optional program, true-action, false-action)
+	CAIRO_CC_CHECK_WERROR
 	AC_MSG_CHECKING([whether $CC supports $1])
-	CAIRO_CC_TRY_FLAG_SILENT([-Werror $1], [$2], [$3], [$4])
+	CAIRO_CC_TRY_FLAG_SILENT([$WERROR $1], [$2], [$3], [$4])
 	AC_MSG_RESULT([$cairo_cc_flag])
 ])
 
 dnl check compiler/ld flags
 AC_DEFUN([CAIRO_CC_TRY_LINK_FLAG],
 [dnl
+	CAIRO_CC_CHECK_WERROR
 	AC_MSG_CHECKING([whether $CC supports $1])
 
 	_save_cflags="$CFLAGS"
-	CFLAGS="$CFLAGS -Werror $1"
+	CFLAGS="$CFLAGS $WERROR $1"
 	AC_LINK_IFELSE([int main(void){ return 0;} ],
                        [cairo_cc_flag=yes],
                        [cairo_cc_flag=no])
diff --git a/build/configure.ac.warnings b/build/configure.ac.warnings
index 7bd4144..53eacb1 100644
--- a/build/configure.ac.warnings
+++ b/build/configure.ac.warnings
@@ -19,6 +19,12 @@ MAYBE_WARN="-Wall -Wextra \
 -Wno-missing-field-initializers -Wno-unused-parameter \
 -Wno-attributes -Wno-long-long -Winline"
 
+dnl Sun Studio 12 likes to rag at us for abusing enums like
+dnl having cairo_status_t variables hold cairo_int_status_t
+dnl values.  It's bad, we know.  Now please be quiet.
+MAYBE_WARN="$MAYBE_WARN -erroff=E_ENUM_TYPE_MISMATCH_ARG \
+			-erroff=E_ENUM_TYPE_MISMATCH_OP"
+
 dnl We also abuse the warning-flag facility to enable other compiler
 dnl options.  Namely, the following:
 MAYBE_WARN="$MAYBE_WARN -fno-strict-aliasing -fno-common"
commit f081a5ff554267eebecea4652bb483eea11d1484
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Wed Sep 2 04:10:39 2009 +0100

    [build] Refine the -Wno-attribute test to check our use cases.
    
    We don't actually check that -Wno-attribute does what
    we think it does.  On clang it doesn't since it happily
    seems to recognize but ignore the attribute.
    
    This patch factors out a silent version of CAIRO_CC_TRY_FLAG
    which accepts an optional program argument and actually tests
    that the compiler doesn't produce any warning messages.  It
    is then used to check that -Wno-attribute doesn't complain
    when the __warn_unused_result__ attribute is applied to
    void functions or variables.

diff --git a/build/aclocal.cairo.m4 b/build/aclocal.cairo.m4
index 1c898b9..021c22f 100644
--- a/build/aclocal.cairo.m4
+++ b/build/aclocal.cairo.m4
@@ -75,21 +75,47 @@ AC_DEFUN([CAIRO_CONFIG_COMMANDS],
 	], $3)
 ])
 
-dnl check compiler flags
-AC_DEFUN([CAIRO_CC_TRY_FLAG],
-[dnl
-	AC_MSG_CHECKING([whether $CC supports $1])
+dnl check compiler flags with a program and no muttering.
+AC_DEFUN([CAIRO_CC_TRY_FLAG_SILENT],
+[dnl     (flags..., optional program, true-action, false-action)
+
+	_compile_program='$2'
+	if test "x$_compile_program" = "x"; then
+		# AC_LANG_PROGRAM() produces a main() w/o args,
+		# but -Wold-style-definition doesn't like that.
+		# We need _some_ program so that we don't get
+		# warnings about empty compilation units.
+		_compile_program='
+			int main(int c, char **v) {
+			    (void)c; (void)v; return 0; }'
+	fi
 
 	_save_cflags="$CFLAGS"
-	CFLAGS="$CFLAGS -Werror $1"
-	AC_COMPILE_IFELSE([ ], [cairo_cc_flag=yes], [cairo_cc_flag=no])
+	CFLAGS="$CFLAGS $1"
+	AC_COMPILE_IFELSE(
+		[$_compile_program],
+		[cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
+		 cairo_cc_flag=yes],
+		[cairo_cc_stderr=`test -f conftest.err && cat conftest.err`
+		 cairo_cc_flag=no])
 	CFLAGS="$_save_cflags"
 
+	if test "x$cairo_cc_stderr" != "x"; then
+		cairo_cc_flag=no
+	fi
+
 	if test "x$cairo_cc_flag" = "xyes"; then
-		ifelse([$2], , :, [$2])
-	else
 		ifelse([$3], , :, [$3])
+	else
+		ifelse([$4], , :, [$4])
 	fi
+])
+
+dnl check compiler flags possibly using -Werror if available.
+AC_DEFUN([CAIRO_CC_TRY_FLAG],
+[dnl     (flags..., optional program, true-action, false-action)
+	AC_MSG_CHECKING([whether $CC supports $1])
+	CAIRO_CC_TRY_FLAG_SILENT([-Werror $1], [$2], [$3], [$4])
 	AC_MSG_RESULT([$cairo_cc_flag])
 ])
 
diff --git a/build/configure.ac.analysis b/build/configure.ac.analysis
index 4e8a02d..11c52e7 100644
--- a/build/configure.ac.analysis
+++ b/build/configure.ac.analysis
@@ -72,7 +72,7 @@ dnl  PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/Makefile.gcov, $abs_srcdir)
   dnl In order to workaround a debian bug in libtool where they strip
   dnl $dependency_libs from the link line and CFLAGS, we need to pass
   dnl --coverage via LDFLAGS.
-  CAIRO_CC_TRY_FLAG([--coverage],
+  CAIRO_CC_TRY_FLAG([--coverage],,
 		    [
 		    CAIRO_CFLAGS="$CAIRO_CFLAGS -O0 --coverage"
 		    CAIRO_LDFLAGS="$CAIRO_LDFLAGS -O0 --coverage"
diff --git a/build/configure.ac.warnings b/build/configure.ac.warnings
index b7d6eab..7bd4144 100644
--- a/build/configure.ac.warnings
+++ b/build/configure.ac.warnings
@@ -46,7 +46,7 @@ AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [
 	# last.
 
 	for W in $MAYBE_WARN; do
-		CAIRO_CC_TRY_FLAG([$W], [WARN_CFLAGS="$WARN_CFLAGS $W"])
+		CAIRO_CC_TRY_FLAG([$W],, [WARN_CFLAGS="$WARN_CFLAGS $W"])
 	done
 
 	cairo_cv_warn_cflags=$WARN_CFLAGS
@@ -63,9 +63,11 @@ CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS"
 AC_CACHE_CHECK([how to enable unused result warnings], cairo_cv_warn_unused_result, [
 	cairo_cv_warn_unused_result=""
 	if echo $WARN_CFLAGS | grep -e '-Wno-attributes' >/dev/null; then
-	    AC_TRY_COMPILE([__attribute__((__warn_unused_result__))
-		int f (int i) { return i; }], [],
-		[cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"])
+	    CAIRO_CC_TRY_FLAG_SILENT(
+			[-Wno-attributes],
+			[__attribute__((__warn_unused_result__)) void f (void) {}
+			 __attribute__((__warn_unused_result__)) int g;],
+			[cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"])
 	fi
 ])
 AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result],
commit c87b366bfec4eeda2646b33cb8a33822a301456c
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Wed Sep 2 04:09:46 2009 +0100

    [constructors] Guard against being called without any input files.
    
    The make-cairo-(test|boilerplate)-constructors scripts ought
    never to be called without arguments lest we are left constructorless.

diff --git a/boilerplate/make-cairo-boilerplate-constructors.sh b/boilerplate/make-cairo-boilerplate-constructors.sh
index 2c7fc85..dd63111 100644
--- a/boilerplate/make-cairo-boilerplate-constructors.sh
+++ b/boilerplate/make-cairo-boilerplate-constructors.sh
@@ -1,4 +1,9 @@
-#!/bin/sh
+#! /bin/sh
+
+if test $# == 0; then
+    echo "$0: no input files." >&2
+    exit 0
+fi
 
 cat <<HERE
 /* WARNING: Autogenerated file - see $0! */
diff --git a/test/make-cairo-test-constructors.sh b/test/make-cairo-test-constructors.sh
index d0325e8..fdb84e9 100644
--- a/test/make-cairo-test-constructors.sh
+++ b/test/make-cairo-test-constructors.sh
@@ -1,4 +1,9 @@
-#!/bin/sh
+#! /bin/sh
+
+if test $# == 0; then
+    echo "$0: no input files." >&2
+    exit 0
+fi
 
 cat <<HERE
 /* WARNING: Autogenerated file - see $0! */
commit b509b548b1e3ac5a9e3de2f9652cd1973d295fa3
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Fri Jul 24 09:12:10 2009 +0300

    [trace] Check for __builtin_return_address explicitly.
    
    Some other compilers such as clang and icc support the
    __builtin_return_address() intrinsic as well, so we don't
    need to check for __GNUC__ >= 3 only.

diff --git a/build/configure.ac.system b/build/configure.ac.system
index 09d2e30..3fffb94 100644
--- a/build/configure.ac.system
+++ b/build/configure.ac.system
@@ -73,6 +73,18 @@ dnl ====================================================================
 dnl Header/function checks
 dnl ====================================================================
 
+dnl check if we have a __builtin_return_address for the cairo-trace
+dnl utility.
+AC_MSG_CHECKING([for __builtin_return_address(0)])
+AC_TRY_COMPILE([],[__builtin_return_address(0);],
+		[have_builtin_return_address=yes],
+		[have_builtin_return_address=no])
+AC_MSG_RESULT($have_builtin_return_address)
+if test "x$have_builtin_return_address" = "xyes"; then
+    AC_DEFINE(HAVE_BUILTIN_RETURN_ADDRESS, 1,
+	[Define to 1 if your compiler supports the __builtin_return_address() intrinsic.])
+fi
+
 dnl Checks for precise integer types
 AC_CHECK_HEADERS([stdint.h inttypes.h sys/int_types.h])
 AC_CHECK_TYPES([uint64_t, uint128_t])
diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index 626a81e..9a1c54e 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -177,7 +177,7 @@ static bool _line_info;
 static bool _mark_dirty;
 static const cairo_user_data_key_t destroy_key;
 
-#if __GNUC__ >= 3
+#if HAVE_BUILTIN_RETURN_ADDRESS
 #define _emit_line_info() do { \
     if (_line_info && _write_lock ()) { \
 	void *addr = __builtin_return_address(0); \
commit 2b0e070f6a6bee415b1036fd149f0c41bcf87abb
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Fri Jul 24 07:48:57 2009 +0300

    [trace] Replace an open coded test for matrix identity.
    
    The code has a _matrix_is_identity() function we can use
    instead of open coding the same test.

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index cbdc961..626a81e 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -2320,7 +2320,6 @@ cairo_identity_matrix (cairo_t *cr)
     return DLCALL (cairo_identity_matrix, cr);
 }
 
-
 void
 cairo_new_path (cairo_t *cr)
 {
@@ -2817,9 +2816,7 @@ cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font)
 static void
 _emit_matrix (const cairo_matrix_t *m)
 {
-    if (m->xx == 1.0 && m->yx == 0.0 &&
-	m->xy == 0.0 && m->yy == 1.0 &&
-	m->x0 == 0.0 && m->y0 == 0.0)
+    if (_matrix_is_identity(m))
     {
 	_trace_printf ("identity");
     }
commit 70ea9e3ce1b0037999340e484e62d3a1484da41a
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Fri Jul 24 07:46:20 2009 +0300

    [trace] Don't crash on unknown enums values.
    
    If the tracer encounters an unknown enum value it
    ought not to crash. Theis patch replaces the idiom
    of looking up a name for an enumerated value directly
    from a table by a switch statement. As a bonus we get
    warnings from the compiler when the enums are updated
    in cairo.

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index beeec20..cbdc961 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -1366,53 +1366,61 @@ _emit_data (const void *data, unsigned int length)
 static const char *
 _format_to_string (cairo_format_t format)
 {
-    const char *names[] = {
-	"ARGB32",	/* CAIRO_FORMAT_ARGB32 */
-	"RGB24",	/* CAIRO_FORMAT_RGB24 */
-	"A8",		/* CAIRO_FORMAT_A8 */
-	"A1"		/* CAIRO_FORMAT_A1 */
-    };
-    return names[format];
+#define f(name) case CAIRO_FORMAT_ ## name: return #name
+    switch (format) {
+	f(ARGB32);
+	f(RGB24);
+	f(A8);
+	f(A1);
+    }
+#undef f
+    return "UNKNOWN_FORMAT";
 }
 
 static const char *
 _status_to_string (cairo_status_t status)
 {
-    const char *names[] = {
-	"STATUS_SUCCESS",
-	"STATUS_NO_MEMORY",
-	"STATUS_INVALID_RESTORE",
-	"STATUS_INVALID_POP_GROUP",
-	"STATUS_NO_CURRENT_POINT",
-	"STATUS_INVALID_MATRIX",
-	"STATUS_INVALID_STATUS",
-	"STATUS_NULL_POINTER",
-	"STATUS_INVALID_STRING",
-	"STATUS_INVALID_PATH_DATA",
-	"STATUS_READ_ERROR",
-	"STATUS_WRITE_ERROR",
-	"STATUS_SURFACE_FINISHED",
-	"STATUS_SURFACE_TYPE_MISMATCH",
-	"STATUS_PATTERN_TYPE_MISMATCH",
-	"STATUS_INVALID_CONTENT",
-	"STATUS_INVALID_FORMAT",
-	"STATUS_INVALID_VISUAL",
-	"STATUS_FILE_NOT_FOUND",
-	"STATUS_INVALID_DASH",
-	"STATUS_INVALID_DSC_COMMENT",
-	"STATUS_INVALID_INDEX",
-	"STATUS_CLIP_NOT_REPRESENTABLE",
-	"STATUS_TEMP_FILE_ERROR",
-	"STATUS_INVALID_STRIDE",
-	"STATUS_FONT_TYPE_MISMATCH",
-	"STATUS_USER_FONT_IMMUTABLE",
-	"STATUS_USER_FONT_ERROR",
-	"STATUS_NEGATIVE_COUNT",
-	"STATUS_INVALID_CLUSTERS",
-	"STATUS_INVALID_SLANT",
-	"STATUS_INVALID_WEIGHT"
-    };
-    return names[status];
+#define f(name) case CAIRO_STATUS_ ## name: return "STATUS_" #name
+    switch (status) {
+	f(SUCCESS);
+	f(NO_MEMORY);
+	f(INVALID_RESTORE);
+	f(INVALID_POP_GROUP);
+	f(NO_CURRENT_POINT);
+	f(INVALID_MATRIX);
+	f(INVALID_STATUS);
+	f(NULL_POINTER);
+	f(INVALID_STRING);
+	f(INVALID_PATH_DATA);
+	f(READ_ERROR);
+	f(WRITE_ERROR);
+	f(SURFACE_FINISHED);
+	f(SURFACE_TYPE_MISMATCH);
+	f(PATTERN_TYPE_MISMATCH);
+	f(INVALID_CONTENT);
+	f(INVALID_FORMAT);
+	f(INVALID_VISUAL);
+	f(FILE_NOT_FOUND);
+	f(INVALID_DASH);
+	f(INVALID_DSC_COMMENT);
+	f(INVALID_INDEX);
+	f(CLIP_NOT_REPRESENTABLE);
+	f(TEMP_FILE_ERROR);
+	f(INVALID_STRIDE);
+	f(FONT_TYPE_MISMATCH);
+	f(USER_FONT_IMMUTABLE);
+	f(USER_FONT_ERROR);
+	f(NEGATIVE_COUNT);
+	f(INVALID_CLUSTERS);
+	f(INVALID_SLANT);
+	f(INVALID_WEIGHT);
+	f(INVALID_SIZE);
+	f(USER_FONT_NOT_IMPLEMENTED);
+    case CAIRO_STATUS_LAST_STATUS:
+	break;
+    }
+    return "UNKNOWN_STATUS";
+#undef f
 }
 
 static void CAIRO_PRINTF_FORMAT(2, 3)
@@ -1877,42 +1885,40 @@ cairo_pop_group_to_source (cairo_t *cr)
 static const char *
 _operator_to_string (cairo_operator_t op)
 {
-    const char *names[] = {
-	"CLEAR",	/* CAIRO_OPERATOR_CLEAR */
-
-	"SOURCE",	/* CAIRO_OPERATOR_SOURCE */
-	"OVER",		/* CAIRO_OPERATOR_OVER */
-	"IN",		/* CAIRO_OPERATOR_IN */
-	"OUT",		/* CAIRO_OPERATOR_OUT */
-	"ATOP",		/* CAIRO_OPERATOR_ATOP */
-
-	"DEST",		/* CAIRO_OPERATOR_DEST */
-	"DEST_OVER",	/* CAIRO_OPERATOR_DEST_OVER */
-	"DEST_IN",	/* CAIRO_OPERATOR_DEST_IN */
-	"DEST_OUT",	/* CAIRO_OPERATOR_DEST_OUT */
-	"DEST_ATOP",	/* CAIRO_OPERATOR_DEST_ATOP */
-
-	"XOR",		/* CAIRO_OPERATOR_XOR */
-	"ADD",		/* CAIRO_OPERATOR_ADD */
-	"SATURATE",	/* CAIRO_OPERATOR_SATURATE */
-
-	"MULTIPLY",	/* CAIRO_OPERATOR_MULTIPLY */
-	"SCREEN",	/* CAIRO_OPERATOR_SCREEN */
-	"OVERLAY",	/* CAIRO_OPERATOR_OVERLAY */
-	"DARKEN",	/* CAIRO_OPERATOR_DARKEN */
-	"LIGHTEN",	/* CAIRO_OPERATOR_LIGHTEN */
-	"DODGE",	/* CAIRO_OPERATOR_COLOR_DODGE */
-	"BURN",		/* CAIRO_OPERATOR_COLOR_BURN */
-	"HARD_LIGHT",	/* CAIRO_OPERATOR_HARD_LIGHT */
-	"SOFT_LIGHT",	/* CAIRO_OPERATOR_SOFT_LIGHT */
-	"DIFFERENCE",	/* CAIRO_OPERATOR_DIFFERENCE */
-	"EXCLUSION",	/* CAIRO_OPERATOR_EXCLUSION */
-	"HSL_HUE",	/* CAIRO_OPERATOR_HSL_HUE */
-	"HSL_SATURATION", /* CAIRO_OPERATOR_HSL_SATURATION */
-	"HSL_COLOR",	/* CAIRO_OPERATOR_HSL_COLOR */
-	"HSL_LUMINOSITY" /* CAIRO_OPERATOR_HSL_LUMINOSITY */
-    };
-    return names[op];
+#define f(name) case CAIRO_OPERATOR_ ## name: return #name
+    switch (op) {
+	f(OVER);
+	f(SOURCE);
+	f(CLEAR);
+	f(IN);
+	f(OUT);
+	f(ATOP);
+	f(DEST);
+	f(DEST_OVER);
+	f(DEST_IN);
+	f(DEST_OUT);
+	f(DEST_ATOP);
+	f(XOR);
+	f(ADD);
+	f(SATURATE);
+	f(MULTIPLY);
+	f(SCREEN);
+	f(OVERLAY);
+	f(DARKEN);
+	f(LIGHTEN);
+        case CAIRO_OPERATOR_COLOR_DODGE: return "DODGE";
+        case CAIRO_OPERATOR_COLOR_BURN: return "BURN";
+	f(HARD_LIGHT);
+	f(SOFT_LIGHT);
+	f(DIFFERENCE);
+	f(EXCLUSION);
+	f(HSL_HUE);
+	f(HSL_SATURATION);
+	f(HSL_COLOR);
+	f(HSL_LUMINOSITY);
+    }
+#undef f
+    return "UNKNOWN_OPERATOR";
 }
 
 void
@@ -2099,13 +2105,15 @@ cairo_set_tolerance (cairo_t *cr, double tolerance)
 static const char *
 _antialias_to_string (cairo_antialias_t antialias)
 {
-    const char *names[] = {
-	"ANTIALIAS_DEFAULT",	/* CAIRO_ANTIALIAS_DEFAULT */
-	"ANTIALIAS_NONE",	/* CAIRO_ANTIALIAS_NONE */
-	"ANTIALIAS_GRAY",	/* CAIRO_ANTIALIAS_GRAY */
-	"ANTIALIAS_SUBPIXEL"	/* CAIRO_ANTIALIAS_SUBPIXEL */
+#define f(name) case CAIRO_ANTIALIAS_ ## name: return "ANTIALIAS_" #name
+    switch (antialias) {
+	f(DEFAULT);
+	f(NONE);
+	f(GRAY);
+	f(SUBPIXEL);
     };
-    return names[antialias];
+#undef f
+    return "UNKNOWN_ANTIALIAS";
 }
 
 void
@@ -2120,11 +2128,13 @@ cairo_set_antialias (cairo_t *cr, cairo_antialias_t antialias)
 static const char *
 _fill_rule_to_string (cairo_fill_rule_t rule)
 {
-    const char *names[] = {
-	"WINDING",	/* CAIRO_FILL_RULE_WINDING */
-	"EVEN_ODD"	/* CAIRO_FILL_RILE_EVEN_ODD */
+#define f(name) case CAIRO_FILL_RULE_ ## name: return #name
+    switch (rule) {
+	f(WINDING);
+	f(EVEN_ODD);
     };
-    return names[rule];
+#undef f
+    return "UNKNOWN_FILL_RULE";
 }
 
 void
@@ -2147,12 +2157,14 @@ cairo_set_line_width (cairo_t *cr, double width)
 static const char *
 _line_cap_to_string (cairo_line_cap_t line_cap)
 {
-    const char *names[] = {
-	"LINE_CAP_BUTT",	/* CAIRO_LINE_CAP_BUTT */
-	"LINE_CAP_ROUND",	/* CAIRO_LINE_CAP_ROUND */
-	"LINE_CAP_SQUARE"	/* CAIRO_LINE_CAP_SQUARE */
+#define f(name) case CAIRO_LINE_CAP_ ## name: return "LINE_CAP_" #name
+    switch (line_cap) {
+	f(BUTT);
+	f(ROUND);
+	f(SQUARE);
     };
-    return names[line_cap];
+#undef f
+    return "UNKNOWN_LINE_CAP";
 }
 
 void
@@ -2166,12 +2178,14 @@ cairo_set_line_cap (cairo_t *cr, cairo_line_cap_t line_cap)
 static const char *
 _line_join_to_string (cairo_line_join_t line_join)
 {
-    const char *names[] = {
-	"LINE_JOIN_MITER",	/* CAIRO_LINE_JOIN_MITER */
-	"LINE_JOIN_ROUND",	/* CAIRO_LINE_JOIN_ROUND */
-	"LINE_JOIN_BEVEL",	/* CAIRO_LINE_JOIN_BEVEL */
+#define f(name) case CAIRO_LINE_JOIN_ ## name: return "LINE_JOIN_" #name
+    switch (line_join) {
+	f(MITER);
+	f(ROUND);
+	f(BEVEL);
     };
-    return names[line_join];
+#undef f
+    return "UNKNOWN_LINE_JOIN";
 }
 
 void
@@ -2556,22 +2570,26 @@ cairo_reset_clip (cairo_t *cr)
 static const char *
 _slant_to_string (cairo_font_slant_t font_slant)
 {
-    const char *names[] = {
-	"SLANT_NORMAL",		/* CAIRO_FONT_SLANT_NORMAL */
-	"SLANT_ITALIC",		/* CAIRO_FONT_SLANT_ITALIC */
-	"SLANT_OBLIQUE"		/* CAIRO_FONT_SLANT_OBLIQUE */
+#define f(name) case CAIRO_FONT_SLANT_ ## name: return "SLANT_" #name
+    switch (font_slant) {
+	f(NORMAL);
+	f(ITALIC);
+	f(OBLIQUE);
     };
-    return names[font_slant];
+#undef f
+    return "UNKNOWN_SLANT";
 }
 
 static const char *
 _weight_to_string (cairo_font_weight_t font_weight)
 {
-    const char *names[] = {
-	"WEIGHT_NORMAL",	/* CAIRO_FONT_WEIGHT_NORMAL */
-	"WEIGHT_BOLD",		/* CAIRO_FONT_WEIGHT_BOLD */
+#define f(name) case CAIRO_FONT_WEIGHT_ ## name: return "WEIGHT_" #name
+    switch (font_weight) {
+	f(NORMAL);
+	f(BOLD);
     };
-    return names[font_weight];
+#undef f
+    return "UNKNOWN_WEIGHT";
 }
 
 void
@@ -2656,37 +2674,46 @@ cairo_set_font_matrix (cairo_t *cr, const cairo_matrix_t *matrix)
 static const char *
 _subpixel_order_to_string (cairo_subpixel_order_t subpixel_order)
 {
-    const char *names[] = {
-	"SUBPIXEL_ORDER_DEFAULT",	/* CAIRO_SUBPIXEL_ORDER_DEFAULT */
-	"SUBPIXEL_ORDER_RGB",		/* CAIRO_SUBPIXEL_ORDER_RGB */
-	"SUBPIXEL_ORDER_BGR",		/* CAIRO_SUBPIXEL_ORDER_BGR */
-	"SUBPIXEL_ORDER_VRGB",		/* CAIRO_SUBPIXEL_ORDER_VRGB */
-	"SUBPIXEL_ORDER_VBGR"		/* CAIRO_SUBPIXEL_ORDER_VBGR */
+#define f(name) case CAIRO_SUBPIXEL_ORDER_ ## name: return "SUBPIXEL_ORDER_" #name
+    switch (subpixel_order) {
+	f(DEFAULT);
+	f(RGB);
+	f(BGR);
+	f(VRGB);
+	f(VBGR);
     };
-    return names[subpixel_order];
+#undef f
+    return "UNKNOWN_SUBPIXEL_ORDER";
 }
+
 static const char *
 _hint_style_to_string (cairo_hint_style_t hint_style)
 {
-    const char *names[] = {
-	"HINT_STYLE_DEFAULT",	/* CAIRO_HINT_STYLE_DEFAULT */
-	"HINT_STYLE_NONE",	/* CAIRO_HINT_STYLE_NONE */
-	"HINT_STYLE_SLIGHT",	/* CAIRO_HINT_STYLE_SLIGHT */
-	"HINT_STYLE_MEDIUM",	/* CAIRO_HINT_STYLE_MEDIUM */
-	"HINT_STYLE_FULL"	/* CAIRO_HINT_STYLE_FULL */
+#define f(name) case CAIRO_HINT_STYLE_ ## name: return "HINT_STYLE_" #name
+    switch (hint_style) {
+	f(DEFAULT);
+	f(NONE);
+	f(SLIGHT);
+	f(MEDIUM);
+	f(FULL);
     };
-    return names[hint_style];
+#undef f
+    return "UNKNOWN_HINT_STYLE";
 }
+
 static const char *
 _hint_metrics_to_string (cairo_hint_metrics_t hint_metrics)
 {
-    const char *names[] = {
-	 "HINT_METRICS_DEFAULT",	/* CAIRO_HINT_METRICS_DEFAULT */
-	 "HINT_METRICS_OFF",		/* CAIRO_HINT_METRICS_OFF */
-	 "HINT_METRICS_ON"		/* CAIRO_HINT_METRICS_ON */
+#define f(name) case CAIRO_HINT_METRICS_ ## name: return "HINT_METRICS_" #name
+    switch (hint_metrics) {
+	f(DEFAULT);
+	f(OFF);
+	f(ON);
     };
-    return names[hint_metrics];
+#undef f
+    return "UNKNOWN_HINT_METRICS";
 }
+
 static void
 _emit_font_options (const cairo_font_options_t *options)
 {
@@ -2982,7 +3009,7 @@ _direction_to_string (cairo_bool_t backward)
 	"FORWARD",
 	"BACKWARD"
     };
-    return names[backward];
+    return names[!!backward];
 }
 
 void
@@ -3544,15 +3571,17 @@ cairo_pattern_set_matrix (cairo_pattern_t *pattern, const cairo_matrix_t *matrix
 static const char *
 _filter_to_string (cairo_filter_t filter)
 {
-    const char *names[] = {
-	"FILTER_FAST",		/* CAIRO_FILTER_FAST */
-	"FILTER_GOOD",		/* CAIRO_FILTER_GOOD */
-	"FILTER_BEST",		/* CAIRO_FILTER_BEST */
-	"FILTER_NEAREST",	/* CAIRO_FILTER_NEAREST */
-	"FILTER_BILINEAR",	/* CAIRO_FILTER_BILINEAR */
-	"FILTER_GAUSSIAN",	/* CAIRO_FILTER_GAUSSIAN */
+#define f(name) case CAIRO_FILTER_ ## name: return "FILTER_" #name
+    switch (filter) {
+	f(FAST);
+	f(GOOD);
+	f(BEST);
+	f(NEAREST);
+	f(BILINEAR);
+	f(GAUSSIAN);
     };
-    return names[filter];
+#undef f
+    return "UNKNOWN_FILTER";
 }
 
 void
@@ -3566,13 +3595,15 @@ cairo_pattern_set_filter (cairo_pattern_t *pattern, cairo_filter_t filter)
 static const char *
 _extend_to_string (cairo_extend_t extend)
 {
-    const char *names[] = {
-	"EXTEND_NONE",		/* CAIRO_EXTEND_NONE */
-	"EXTEND_REPEAT",	/* CAIRO_EXTEND_REPEAT */
-	"EXTEND_REFLECT",	/* CAIRO_EXTEND_REFLECT */
-	"EXTEND_PAD"		/* CAIRO_EXTEND_PAD */
+#define f(name) case CAIRO_EXTEND_ ## name: return "EXTEND_" #name
+    switch (extend) {
+	f(NONE);
+	f(REPEAT);
+	f(REFLECT);
+	f(PAD);
     };
-    return names[extend];
+#undef f
+    return "UNKNOWN_EXTEND";
 }
 
 void
commit 174c2620c82a47d067ec7b5062a4f513155a0b1f
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Fri Jul 24 07:42:57 2009 +0300

    [trace] Check for object stack underflow.
    
    If the tracer's object stack underflows we want to
    know about is as soon as possible. This patch adds
    checks against the stack overflowing and aborts the
    program with an object stack dump if it does.

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index 3c47aaf..beeec20 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -829,10 +829,30 @@ static Object *current_object[2048]; /* XXX limit operand stack */
 static int current_stack_depth;
 
 static void
+ensure_operands (int num_operands)
+{
+    if (current_stack_depth < num_operands)
+    {
+	int n;
+
+	fprintf (stderr, "Operand stack underflow!\n");
+	for (n = 0; n < current_stack_depth; n++) {
+	    Object *obj = current_object[n];
+
+	    fprintf (stderr, "  [%3d] = %s%ld\n",
+		     n, obj->type->op_code, obj->token);
+	}
+
+	abort ();
+    }
+}
+
+static void
 _consume_operand (void)
 {
     Object *obj;
 
+    ensure_operands (1);
     obj = current_object[--current_stack_depth];
     if (! obj->defined) {
 	_trace_printf ("dup /%s%ld exch def\n",
@@ -848,6 +868,7 @@ _exch_operands (void)
 {
     Object *tmp;
 
+    ensure_operands (2);
     tmp = current_object[current_stack_depth-1];
     tmp->operand--;
     current_object[current_stack_depth-1] = current_object[current_stack_depth-2];
@@ -871,6 +892,7 @@ _pop_operands_to_object (Object *obj)
     while (current_stack_depth > obj->operand + 1) {
 	Object *c_obj;
 
+	ensure_operands (1);
 	c_obj = current_object[--current_stack_depth];
 	c_obj->operand = -1;
 	if (! c_obj->defined) {
@@ -912,8 +934,7 @@ _push_operand (enum operand_type t, const void *ptr)
 {
     Object *obj = _get_object (t, ptr);
 
-    if (current_stack_depth ==
-	sizeof (current_object) / sizeof (current_object[0]))
+    if (current_stack_depth == ARRAY_LENGTH (current_object))
     {
 	int n;
 
@@ -936,6 +957,7 @@ static void
 _object_remove (Object *obj)
 {
     if (obj->operand != -1) {
+	ensure_operands (1);
 	if (obj->operand == current_stack_depth - 1) {
 	    _trace_printf ("pop %% %s%ld destroyed\n",
 			   obj->type->op_code, obj->token);
commit bb480d235882d8e7d5748a3837f9b274a8b8ac86
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Tue Jul 21 21:18:36 2009 +0300

    [NEWS] Thank the AuroraUX team for facilitating Solaris testing.

diff --git a/NEWS b/NEWS
index a4a2c83..0acb77d 100644
--- a/NEWS
+++ b/NEWS
@@ -87,6 +87,11 @@ Long standing bugs fixed:
     cairo-trace and submitting it to us for analysis and inclusion into
     our performance suite.
 
+Special thanks:
+
+   To the AuroraUX team for providing access to one of their OpenSolaris
+   machines for cairo and pixman development.  http://www.auroraux.org/
+
 
 Snapshot 1.9.2 (2009-06-12)
 ===========================
commit c64f6f8a15306cdcf5dd02480049b0f9112fd6ac
Author: M Joonas Pihlaja <jpihlaja at cc.helsinki.fi>
Date:   Fri Jun 26 16:54:11 2009 +0300

    [trace] Get the tracee program name from the environment.
    
    Support non-Linux systems which don't have a /proc/self/cmdline
    by transferring the application name given to cairo-trace via
    an environment variable CAIRO_TRACE_PROG_NAME.

diff --git a/util/cairo-trace/cairo-trace.in b/util/cairo-trace/cairo-trace.in
index 3e54d4e..f2a5b8f 100644
--- a/util/cairo-trace/cairo-trace.in
+++ b/util/cairo-trace/cairo-trace.in
@@ -85,7 +85,8 @@ if test $# -eq 0; then
     usage
 fi
 
-#echo $*
+CAIRO_TRACE_PROG_NAME="$1"
+export CAIRO_TRACE_PROG_NAME
 
 LD_PRELOAD=@libdir@/cairo/cairo-trace.so 
 export LD_PRELOAD
diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index f8275a6..3c47aaf 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -651,22 +651,29 @@ _trace_printf (const char *fmt, ...)
 static void
 get_prog_name (char *buf, int length)
 {
-    FILE *file = fopen ("/proc/self/cmdline", "rb");
-    *buf = '\0';
-    if (file != NULL) {
-	char *slash;
+    char *slash;
+    FILE *file;
 
-	slash = fgets (buf, length, file);
-	fclose (file);
-	if (slash == NULL)
-	    return;
+    memset (buf, 0, length);
+    if (length == 0)
+	return;
 
-	slash = strrchr (buf, '/');
-	if (slash != NULL) {
-	    int len = strlen (slash+1);
-	    memmove (buf, slash+1, len+1);
+    file = fopen ("/proc/self/cmdline", "rb");
+    if (file != NULL) {
+	fgets (buf, length, file);
+	fclose (file);
+    } else {
+	char const *name = getenv ("CAIRO_TRACE_PROG_NAME");
+	if (name != NULL) {
+	    strncpy (buf, name, length-1);
 	}
     }
+
+    slash = strrchr (buf, '/');
+    if (slash != NULL) {
+	size_t len = strlen (slash+1);
+	memmove (buf, slash+1, len+1);
+    }
 }
 
 static void


More information about the cairo-commit mailing list