[cairo-commit] 6 commits - boilerplate/cairo-boilerplate.c build/aclocal.compare.m4 configure.ac src/cairo-path-bounds.c src/cairo-toy-font-face.c test/cairo-test.c test/pdf-mime-data.c

Chris Wilson ickle at kemper.freedesktop.org
Fri Jan 2 07:44:59 PST 2009


 boilerplate/cairo-boilerplate.c |    2 
 build/aclocal.compare.m4        |  162 ++++++++++++++++++++++++++++++++++++++++
 configure.ac                    |   18 +---
 src/cairo-path-bounds.c         |    6 -
 src/cairo-toy-font-face.c       |   28 +++++-
 test/cairo-test.c               |    3 
 test/pdf-mime-data.c            |    4 
 7 files changed, 203 insertions(+), 20 deletions(-)

New commits:
commit 333158ec85cf3c610cc8965fc3f99d72b534cc2e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jan 2 15:36:39 2009 +0000

    [configure] Replace awk comparator with an aclocal version
    
    As reported in https://bugs.freedesktop.org/show_bug.cgi?id=19283, the
    fallback freetype version compare is broken inside the configure script as
    the $1-$3 arguments are interpreted as the script is constructed. To avoid
    making that awk comparison any more complicated, we import a version compare
    from the autoconf archives - such that we have a reusable macro for the
    furture.

diff --git a/build/aclocal.compare.m4 b/build/aclocal.compare.m4
new file mode 100644
index 0000000..bd6c51b
--- /dev/null
+++ b/build/aclocal.compare.m4
@@ -0,0 +1,162 @@
+dnl @synopsis AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+dnl
+dnl This macro compares two version strings. It is used heavily in the
+dnl macro _AX_PATH_BDB for library checking. Due to the various number
+dnl of minor-version numbers that can exist, and the fact that string
+dnl comparisons are not compatible with numeric comparisons, this is
+dnl not necessarily trivial to do in a autoconf script. This macro
+dnl makes doing these comparisons easy.
+dnl
+dnl The six basic comparisons are available, as well as checking
+dnl equality limited to a certain number of minor-version levels.
+dnl
+dnl The operator OP determines what type of comparison to do, and can
+dnl be one of:
+dnl
+dnl  eq  - equal (test A == B)
+dnl  ne  - not equal (test A != B)
+dnl  le  - less than or equal (test A <= B)
+dnl  ge  - greater than or equal (test A >= B)
+dnl  lt  - less than (test A < B)
+dnl  gt  - greater than (test A > B)
+dnl
+dnl Additionally, the eq and ne operator can have a number after it to
+dnl limit the test to that number of minor versions.
+dnl
+dnl  eq0 - equal up to the length of the shorter version
+dnl  ne0 - not equal up to the length of the shorter version
+dnl  eqN - equal up to N sub-version levels
+dnl  neN - not equal up to N sub-version levels
+dnl
+dnl When the condition is true, shell commands ACTION-IF-TRUE are run,
+dnl otherwise shell commands ACTION-IF-FALSE are run. The environment
+dnl variable 'ax_compare_version' is always set to either 'true' or
+dnl 'false' as well.
+dnl
+dnl Examples:
+dnl
+dnl   AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8])
+dnl   AX_COMPARE_VERSION([3.15],[lt],[3.15.8])
+dnl
+dnl would both be true.
+dnl
+dnl   AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8])
+dnl   AX_COMPARE_VERSION([3.15],[gt],[3.15.8])
+dnl
+dnl would both be false.
+dnl
+dnl   AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8])
+dnl
+dnl would be true because it is only comparing two minor versions.
+dnl
+dnl   AX_COMPARE_VERSION([3.15.7],[eq0],[3.15])
+dnl
+dnl would be true because it is only comparing the lesser number of
+dnl minor versions of the two values.
+dnl
+dnl Note: The characters that separate the version numbers do not
+dnl matter. An empty string is the same as version 0. OP is evaluated
+dnl by autoconf, not configure, so must be a string, not a variable.
+dnl
+dnl The author would like to acknowledge Guido Draheim whose advice
+dnl about the m4_case and m4_ifvaln functions make this macro only
+dnl include the portions necessary to perform the specific comparison
+dnl specified by the OP argument in the final configure script.
+dnl
+dnl @category Misc
+dnl @author Tim Toolan <toolan at ele.uri.edu>
+dnl @version 2004-03-01
+dnl @license GPLWithACException
+
+dnl #########################################################################
+AC_DEFUN([AX_COMPARE_VERSION], [
+  # Used to indicate true or false condition
+  ax_compare_version=false
+
+  # Convert the two version strings to be compared into a format that
+  # allows a simple string comparison.  The end result is that a version
+  # string of the form 1.12.5-r617 will be converted to the form
+  # 0001001200050617.  In other words, each number is zero padded to four
+  # digits, and non digits are removed.
+  AS_VAR_PUSHDEF([A],[ax_compare_version_A])
+  A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
+                     -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/[[^0-9]]//g'`
+
+  AS_VAR_PUSHDEF([B],[ax_compare_version_B])
+  B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \
+                     -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \
+                     -e 's/[[^0-9]]//g'`
+
+  dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary
+  dnl # then the first line is used to determine if the condition is true.
+  dnl # The sed right after the echo is to remove any indented white space.
+  m4_case(m4_tolower($2),
+  [lt],[
+    ax_compare_version=`echo "x$A
+x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"`
+  ],
+  [gt],[
+    ax_compare_version=`echo "x$A
+x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"`
+  ],
+  [le],[
+    ax_compare_version=`echo "x$A
+x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"`
+  ],
+  [ge],[
+    ax_compare_version=`echo "x$A
+x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"`
+  ],[
+    dnl Split the operator from the subversion count if present.
+    m4_bmatch(m4_substr($2,2),
+    [0],[
+      # A count of zero means use the length of the shorter version.
+      # Determine the number of characters in A and B.
+      ax_compare_version_len_A=`echo "$A" | awk '{print(length)}'`
+      ax_compare_version_len_B=`echo "$B" | awk '{print(length)}'`
+
+      # Set A to no more than B's length and B to no more than A's length.
+      A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"`
+      B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"`
+    ],
+    [[0-9]+],[
+      # A count greater than zero means use only that many subversions
+      A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
+      B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"`
+    ],
+    [.+],[
+      AC_WARNING(
+        [illegal OP numeric parameter: $2])
+    ],[])
+
+    # Pad zeros at end of numbers to make same length.
+    ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`"
+    B="$B`echo $A | sed 's/./0/g'`"
+    A="$ax_compare_version_tmp_A"
+
+    # Check for equality or inequality as necessary.
+    m4_case(m4_tolower(m4_substr($2,0,2)),
+    [eq],[
+      test "x$A" = "x$B" && ax_compare_version=true
+    ],
+    [ne],[
+      test "x$A" != "x$B" && ax_compare_version=true
+    ],[
+      AC_WARNING([illegal OP parameter: $2])
+    ])
+  ])
+
+  AS_VAR_POPDEF([A])dnl
+  AS_VAR_POPDEF([B])dnl
+
+  dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE.
+  if test "$ax_compare_version" = "true" ; then
+    m4_ifvaln([$4],[$4],[:])dnl
+    m4_ifvaln([$5],[else $5])dnl
+  fi
+]) dnl AX_COMPARE_VERSION
diff --git a/configure.ac b/configure.ac
index ab2d376..d3ed703 100644
--- a/configure.ac
+++ b/configure.ac
@@ -293,18 +293,12 @@ CAIRO_ENABLE_FONT_BACKEND(ft, FreeType, auto, [
         AC_MSG_CHECKING(freetype2 libtool version)
 
         FREETYPE_VERSION=`$FREETYPE_CONFIG --version`
-
-        VERSION_DEC=`echo $FREETYPE_VERSION | awk -F. '{printf("%d\n", 10000*$1 + 100*$2 + $3)};'`
-        MIN_VERSION_DEC=`echo $FREETYPE_MIN_VERSION | awk -F. '{printf("%d\n", 10000*$1 + 100*$2 + $3)};'`
-        if test $VERSION_DEC -lt $MIN_VERSION_DEC; then
-          AC_MSG_RESULT($FREETYPE_VERSION - Too old)
-          use_ft="no ($FREETYPE_VERSION found; version $FREETYPE_MIN_VERSION from release $FREETYPE_MIN_RELEASE required)"
-        else
-          AC_MSG_RESULT($FREETYPE_VERSION - OK)
-
-	  ft_NONPKGCONFIG_CFLAGS=`$FREETYPE_CONFIG --cflags`
-	  ft_NONPKGCONFIG_LIBS=`$FREETYPE_CONFIG --libs`
-        fi
+	AX_COMPARE_VERSION([$FREETYPE_VERSION], [gt], [$FREETYPE_MIN_VERSION],
+			   [AC_MSG_RESULT($FREETYPE_VERSION - OK)
+			   ft_NONPKGCONFIG_CFLAGS=`$FREETYPE_CONFIG --cflags`
+			   ft_NONPKGCONFIG_LIBS=`$FREETYPE_CONFIG --libs`],
+			   [AC_MSG_RESULT($FREETYPE_VERSION - Too old)
+			   use_ft="no ($FREETYPE_VERSION found; version $FREETYPE_MIN_VERSION from release $FREETYPE_MIN_RELEASE required)"])
       fi
     fi
   fi
commit dc33ae24619f4602c23716e9e407f8dd4f1b4a1d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jan 2 14:29:53 2009 +0000

    [boilerplate] Use pclose() after popen
    
    Joonas pointed out that we should be using pclose() on a stream returned
    by popen().

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 0f37451..1f06b19 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -1038,7 +1038,7 @@ cairo_boilerplate_convert_to_image (const char *filename, int page)
 	return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
 
     image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
-    fclose (file);
+    pclose (file);
 
     if (cairo_surface_status (image) == CAIRO_STATUS_READ_ERROR) {
 	if (flags == 0) {
commit f230ce7658910c7f4f8feb722b77a2141824f963
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jan 2 14:03:35 2009 +0000

    [path] Fix typo in bounds for empty path.
    
    We set the width to be zero, twice, and the height not even once!

diff --git a/src/cairo-path-bounds.c b/src/cairo-path-bounds.c
index 705170c..7047ca8 100644
--- a/src/cairo-path-bounds.c
+++ b/src/cairo-path-bounds.c
@@ -176,7 +176,7 @@ _cairo_path_fixed_approximate_extents (cairo_path_fixed_t *path,
 	_cairo_box_round_to_rectangle (&bounder.extents, extents);
     } else {
 	extents->x = extents->y = 0;
-	extents->width = extents->width = 0;
+	extents->width = extents->height = 0;
     }
 
     _cairo_path_bounder_fini (&bounder);
@@ -206,7 +206,7 @@ _cairo_path_fixed_approximate_fill_extents (cairo_path_fixed_t *path,
 	_cairo_box_round_to_rectangle (&bounder.extents, extents);
     } else {
 	extents->x = extents->y = 0;
-	extents->width = extents->width = 0;
+	extents->width = extents->height = 0;
     }
 
     _cairo_path_bounder_fini (&bounder);
@@ -245,7 +245,7 @@ _cairo_path_fixed_approximate_stroke_extents (cairo_path_fixed_t *path,
 	_cairo_box_round_to_rectangle (&bounder.extents, extents);
     } else {
 	extents->x = extents->y = 0;
-	extents->width = extents->width = 0;
+	extents->width = extents->height = 0;
     }
 
     _cairo_path_bounder_fini (&bounder);
commit 163c326c82a45c1f3ee84bbfaee2cc2e6dc1fafc
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jan 2 13:46:16 2009 +0000

    [test] Free test name
    
    Adding the missing free for the converted test name.

diff --git a/test/cairo-test.c b/test/cairo-test.c
index 24d693d..6dca6f8 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -246,6 +246,9 @@ cairo_test_fini (cairo_test_context_t *ctx)
     cairo_surface_destroy (ctx->ref_image);
     cairo_surface_destroy (ctx->ref_image_flattened);
 
+    if (ctx->test_name != NULL)
+	free (ctx->test_name);
+
     if (ctx->own_targets)
 	cairo_boilerplate_free_targets (ctx->targets_to_test);
 
commit dd65be740c475daf75c602fc79ff25977674d9cf
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jan 2 13:42:53 2009 +0000

    [test/pdf-mime-data] Free data on error paths.
    
    Cleanup the allocated buffers on error.

diff --git a/test/pdf-mime-data.c b/test/pdf-mime-data.c
index 233374d..00cde9d 100644
--- a/test/pdf-mime-data.c
+++ b/test/pdf-mime-data.c
@@ -149,6 +149,7 @@ preamble (cairo_test_context_t *ctx)
 
     test_status = read_file (ctx, "pdf-mime-data.out-000.jpg", &out_data, &out_len);
     if (test_status) {
+	free (data);
 	cairo_test_log (ctx,
 			"Could not read input jpeg file %s\n",
 			"pdf-mime-data.out-000.jpg");
@@ -156,9 +157,12 @@ preamble (cairo_test_context_t *ctx)
     }
 
     if (len != out_len || memcmp(data, out_data, len) != 0) {
+	free (data);
+	free (out_data);
 	cairo_test_log (ctx, "output mime data does not match source mime data\n");
 	return CAIRO_TEST_FAILURE;
     }
+
     free (data);
     free (out_data);
 
commit 65f9760d661a0eb2edf9e53fb1b74666ce0ba3b9
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jan 2 13:43:33 2009 +0000

    [toy-font-face] Return defaults for error objects.
    
    Similar to the behaviour of the other objects, we return the default
    conditions if the object is in any error (and not just a nil object).

diff --git a/src/cairo-toy-font-face.c b/src/cairo-toy-font-face.c
index f51ea25..fb9b909 100644
--- a/src/cairo-toy-font-face.c
+++ b/src/cairo-toy-font-face.c
@@ -394,7 +394,12 @@ _cairo_font_face_is_toy (cairo_font_face_t *font_face)
 cairo_font_face_t *
 _cairo_toy_font_face_get_implementation (cairo_font_face_t *font_face)
 {
-    cairo_toy_font_face_t *toy_font_face = (cairo_toy_font_face_t *) font_face;
+    cairo_toy_font_face_t *toy_font_face;
+
+    if (font_face->status)
+	return NULL;
+
+    toy_font_face = (cairo_toy_font_face_t *) font_face;
     if (! _cairo_font_face_is_toy (font_face)) {
 	if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH))
 	    return NULL;
@@ -416,7 +421,12 @@ _cairo_toy_font_face_get_implementation (cairo_font_face_t *font_face)
 const char *
 cairo_toy_font_face_get_family (cairo_font_face_t *font_face)
 {
-    cairo_toy_font_face_t *toy_font_face = (cairo_toy_font_face_t *) font_face;
+    cairo_toy_font_face_t *toy_font_face;
+
+    if (font_face->status)
+	return CAIRO_FONT_FAMILY_DEFAULT;
+
+    toy_font_face = (cairo_toy_font_face_t *) font_face;
     if (! _cairo_font_face_is_toy (font_face)) {
 	if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH))
 	    return CAIRO_FONT_FAMILY_DEFAULT;
@@ -438,7 +448,12 @@ cairo_toy_font_face_get_family (cairo_font_face_t *font_face)
 cairo_font_slant_t
 cairo_toy_font_face_get_slant (cairo_font_face_t *font_face)
 {
-    cairo_toy_font_face_t *toy_font_face = (cairo_toy_font_face_t *) font_face;
+    cairo_toy_font_face_t *toy_font_face;
+
+    if (font_face->status)
+	return CAIRO_FONT_SLANT_DEFAULT;
+
+    toy_font_face = (cairo_toy_font_face_t *) font_face;
     if (! _cairo_font_face_is_toy (font_face)) {
 	if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH))
 	    return CAIRO_FONT_SLANT_DEFAULT;
@@ -460,7 +475,12 @@ slim_hidden_def (cairo_toy_font_face_get_slant);
 cairo_font_weight_t
 cairo_toy_font_face_get_weight (cairo_font_face_t *font_face)
 {
-    cairo_toy_font_face_t *toy_font_face = (cairo_toy_font_face_t *) font_face;
+    cairo_toy_font_face_t *toy_font_face;
+
+    if (font_face->status)
+	return CAIRO_FONT_WEIGHT_DEFAULT;
+
+    toy_font_face = (cairo_toy_font_face_t *) font_face;
     if (! _cairo_font_face_is_toy (font_face)) {
 	if (_cairo_font_face_set_error (font_face, CAIRO_STATUS_FONT_TYPE_MISMATCH))
 	    return CAIRO_FONT_WEIGHT_DEFAULT;


More information about the cairo-commit mailing list