[cairo-commit] 9 commits - src/cairo-array.c src/cairoint.h src/cairo-output-stream.c src/cairo-output-stream-private.h src/cairo-pdf-surface.c src/cairo-ps-surface.c src/cairo-svg-surface.c src/cairo-type1-fallback.c

Carl Worth cworth at kemper.freedesktop.org
Thu Sep 7 17:46:25 PDT 2006


 src/cairo-array.c                 |   12 ++
 src/cairo-output-stream-private.h |   12 +-
 src/cairo-output-stream.c         |   26 +++-
 src/cairo-pdf-surface.c           |    3 
 src/cairo-ps-surface.c            |    2 
 src/cairo-svg-surface.c           |    3 
 src/cairo-type1-fallback.c        |  200 +++++++++++++++++++++++++-------------
 src/cairoint.h                    |    3 
 8 files changed, 176 insertions(+), 85 deletions(-)

New commits:
diff-tree c475d2ca69fa8fbdf1c50f1d5d1b6b558b8fd6cd (from f6bd76a4b26848fb5cc8e40e65f4393d3bd684ae)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 17:46:21 2006 -0700

    Fix bitmap-font test failure by not generating a type1 font for a bitmap font.
    
    This was simply a matter of ensuring that the UNSUPPORTED
    return value was checked for and propagated all the way
    out of cairo-type1-fallback.c

diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 3c8b6f0..ea4826b 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -281,6 +281,8 @@ _charstring_close_path (void *closure)
 	return status;
 
     charstring_encode_command (path_info->data, CHARSTRING_closepath);
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static void
@@ -325,17 +327,18 @@ create_notdef_charstring (cairo_array_t 
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static cairo_int_status_t
 cairo_type1_font_create_charstring (cairo_type1_font_t *font,
                                     int                 subset_index,
                                     int                 glyph_index,
                                     cairo_array_t      *data)
 {
-    cairo_status_t status;
+    cairo_int_status_t status;
     cairo_scaled_glyph_t *scaled_glyph;
     t1_path_info_t path_info;
     cairo_text_extents_t *metrics;
 
+    /* This call may return CAIRO_INT_STATUS_UNSUPPORTED for bitmap fonts. */
     status = _cairo_scaled_glyph_lookup (font->type1_scaled_font,
 					 glyph_index,
 					 CAIRO_SCALED_GLYPH_INFO_METRICS|
@@ -566,7 +569,9 @@ cairo_type1_font_write_private_dict (cai
                                  "/lenIV 4 def\n"
                                  "/password 5839 def\n");
 
-    cairo_type1_font_write_charstrings (font, encrypted_output);
+    status = cairo_type1_font_write_charstrings (font, encrypted_output);
+    if (status)
+	goto fail;
 
     _cairo_output_stream_printf (encrypted_output,
                                  "end\n"
@@ -609,14 +614,19 @@ cairo_type1_write_stream (void *closure,
     return _cairo_array_append_multiple (&font->contents, data, length);
 }
 
-static cairo_status_t
+static cairo_int_status_t
 cairo_type1_font_write (cairo_type1_font_t *font,
                         const char *name)
 {
+    cairo_int_status_t status;
+
     cairo_type1_font_write_header (font, name);
     font->header_size = _cairo_output_stream_get_position (font->output);
 
-    cairo_type1_font_write_private_dict (font, name);
+    status = cairo_type1_font_write_private_dict (font, name);
+    if (status)
+	return status;
+
     font->data_size = _cairo_output_stream_get_position (font->output) -
 	font->header_size;
 
@@ -628,21 +638,24 @@ cairo_type1_font_write (cairo_type1_font
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static cairo_int_status_t
 cairo_type1_font_generate (cairo_type1_font_t *font, const char *name)
 {
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
+    cairo_int_status_t status;
 
     status = _cairo_array_grow_by (&font->contents, 4096);
     if (status)
-        goto fail;
+	return status;
 
     font->output = _cairo_output_stream_create (cairo_type1_write_stream, NULL, font);
-    cairo_type1_font_write (font, name);
+
+    status = cairo_type1_font_write (font, name);
+    if (status)
+	return status;
+
     font->data = _cairo_array_index (&font->contents, 0);
 
- fail:
-    return status;
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static void
diff-tree f6bd76a4b26848fb5cc8e40e65f4393d3bd684ae (from 942cd2e026431bd5ae347c264fb3a0469eb53cf4)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 17:36:36 2006 -0700

    type1: Enforce pre-allocation usage and fail-proof behavior of charstring_encode functions
    
    These functions were previously returning a status value that
    was almost never being checked. Instead we now make these
    functions void and enforce a usage pattern that the destination
    array must be pre-grown to accomodate the results. This is
    verified with a couple of assert statements.
    
    The pre-allocation was already happening with all but one call.
    That call is now also fixed up.

diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 0ce0b41..3c8b6f0 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -120,21 +120,40 @@ static const unsigned short charstring_k
 #define CHARSTRING_closepath  0x0009
 #define CHARSTRING_endchar    0x000e
 
-static cairo_status_t
+/* Before calling this function, the caller must allocate sufficient
+ * space in data (see _cairo_array_grow_by). The maxium number of
+ * bytes that will be used is 2.
+ */
+static void
 charstring_encode_command (cairo_array_t *data, int command)
 {
+    cairo_status_t status;
+    int orig_size;
     unsigned char buf[5];
     unsigned char *p = buf;
 
     if (command & 0xff00)
         *p++ = command >> 8;
     *p++ = command & 0x00ff;
-    return _cairo_array_append_multiple (data, buf, p - buf);
+
+    /* Ensure the array doesn't grow, which allows this function to
+     * have no possibility of failure. */
+    orig_size = _cairo_array_size (data);
+    status = _cairo_array_append_multiple (data, buf, p - buf);
+
+    assert (status == CAIRO_STATUS_SUCCESS);
+    assert (_cairo_array_size (data) == orig_size);
 }
 
-static cairo_status_t
+/* Before calling this function, the caller must allocate sufficient
+ * space in data (see _cairo_array_grow_by). The maxium number of
+ * bytes that will be used is 5.
+ */
+static void
 charstring_encode_integer (cairo_array_t *data, int i)
 {
+    cairo_status_t status;
+    int orig_size;
     unsigned char buf[10];
     unsigned char *p = buf;
 
@@ -155,7 +174,14 @@ charstring_encode_integer (cairo_array_t
         *p++ = (i >> 8)  & 0xff;
         *p++ = i & 0xff;
     }
-    return _cairo_array_append_multiple (data, buf, p - buf);
+
+    /* Ensure the array doesn't grow, which allows this function to
+     * have no possibility of failure. */
+    orig_size = _cairo_array_size (data);
+    status = _cairo_array_append_multiple (data, buf, p - buf);
+
+    assert (status == CAIRO_STATUS_SUCCESS);
+    assert (_cairo_array_size (data) == orig_size);
 }
 
 typedef struct _ps_path_info {
@@ -247,9 +273,14 @@ _charstring_curve_to (void	    *closure,
 static cairo_status_t
 _charstring_close_path (void *closure)
 {
+    cairo_status_t status;
     t1_path_info_t *path_info = (t1_path_info_t *) closure;
 
-    return charstring_encode_command (path_info->data, CHARSTRING_closepath);
+    status = _cairo_array_grow_by (path_info->data, 2);
+    if (status)
+	return status;
+
+    charstring_encode_command (path_info->data, CHARSTRING_closepath);
 }
 
 static void
@@ -274,6 +305,9 @@ create_notdef_charstring (cairo_array_t 
 {
     cairo_status_t status;
 
+    /* We're passing constants below, so we know the 0 values will
+     * only use 1 byte each, and the 500 values will use 2 bytes
+     * each. Then 2 more for each of the commands is 10 total. */
     status = _cairo_array_grow_by (data, 10);
     if (status)
         return status;
@@ -331,6 +365,7 @@ cairo_type1_font_create_charstring (cair
     status = _cairo_array_grow_by (data, 30);
     if (status)
         return status;
+
     charstring_encode_integer (data, (int) scaled_glyph->metrics.x_bearing);
     charstring_encode_integer (data, (int) scaled_glyph->metrics.y_bearing);
     charstring_encode_integer (data, (int) scaled_glyph->metrics.width);
@@ -348,9 +383,9 @@ cairo_type1_font_create_charstring (cair
                                  _charstring_close_path,
                                  &path_info);
 
-    status = charstring_encode_command (path_info.data, CHARSTRING_endchar);
+    charstring_encode_command (path_info.data, CHARSTRING_endchar);
 
-    return status;
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_int_status_t
diff-tree 942cd2e026431bd5ae347c264fb3a0469eb53cf4 (from 8796b19b5d2e203f5f8724cef1d3ae8d2d02fc85)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 17:33:35 2006 -0700

    Add _cairo_array_size to allow querying the allocated size

diff --git a/src/cairo-array.c b/src/cairo-array.c
index 9d07f56..1d9354a 100644
--- a/src/cairo-array.c
+++ b/src/cairo-array.c
@@ -318,6 +318,18 @@ _cairo_array_num_elements (cairo_array_t
     return array->num_elements;
 }
 
+/**
+ * _cairo_array_size:
+ *
+ * Return value: The number of elements for which there is currently
+ * space allocated in array.
+ **/
+int
+_cairo_array_size (cairo_array_t *array)
+{
+    return array->size;
+}
+
 /* cairo_user_data_array_t */
 
 typedef struct {
diff --git a/src/cairoint.h b/src/cairoint.h
index f17be94..255ac1e 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -433,6 +433,9 @@ _cairo_array_copy_element (cairo_array_t
 cairo_private int
 _cairo_array_num_elements (cairo_array_t *array);
 
+cairo_private int
+_cairo_array_size (cairo_array_t *array);
+
 typedef cairo_array_t cairo_user_data_array_t;
 
 cairo_private void
diff-tree 8796b19b5d2e203f5f8724cef1d3ae8d2d02fc85 (from 8364251db55c2451eca9b8162aa32ae00f433251)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 17:09:37 2006 -0700

    cairo-type1-fallback.c: Regularize some whitespace.

diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index df59c2a..0ce0b41 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -106,7 +106,6 @@ cairo_type1_font_create (cairo_scaled_fo
     return CAIRO_STATUS_SUCCESS;
 }
 
-
 /* Magic constants for the type1 eexec encryption */
 static const unsigned short encrypt_c1 = 52845, encrypt_c2 = 22719;
 static const unsigned short private_dict_key = 55665;
@@ -121,7 +120,6 @@ static const unsigned short charstring_k
 #define CHARSTRING_closepath  0x0009
 #define CHARSTRING_endchar    0x000e
 
-
 static cairo_status_t
 charstring_encode_command (cairo_array_t *data, int command)
 {
@@ -160,7 +158,6 @@ charstring_encode_integer (cairo_array_t
     return _cairo_array_append_multiple (data, buf, p - buf);
 }
 
-
 typedef struct _ps_path_info {
     cairo_array_t *data;
     int current_x, current_y;
@@ -186,6 +183,7 @@ _charstring_move_to (void          *clos
     path_info->current_y += dy;
 
     charstring_encode_command (path_info->data, CHARSTRING_rmoveto);
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -209,6 +207,7 @@ _charstring_line_to (void          *clos
     path_info->current_y += dy;
 
     charstring_encode_command (path_info->data, CHARSTRING_rlineto);
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -241,6 +240,7 @@ _charstring_curve_to (void	    *closure,
     path_info->current_x += dx1 + dx2 + dx3;
     path_info->current_y += dy1 + dy2 + dy3;
     charstring_encode_command (path_info->data, CHARSTRING_rcurveto);
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -287,6 +287,7 @@ create_notdef_charstring (cairo_array_t 
     charstring_encode_command (data, CHARSTRING_sbw);
 
     charstring_encode_command (data, CHARSTRING_endchar);
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -456,6 +457,7 @@ cairo_type1_font_write_header (cairo_typ
                                  "readonly def\n"
                                  "currentdict end\n"
                                  "currentfile eexec\n");
+
     return CAIRO_STATUS_SUCCESS;
 }
 
diff-tree 8364251db55c2451eca9b8162aa32ae00f433251 (from 75ac7ee171d4bbe2b590e444bde9eb95138a2452)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 17:07:54 2006 -0700

    cairo_type1_font_create: Fix missing NO_MEMORY check and cleanup style.

diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index a07d101..df59c2a 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -39,11 +39,14 @@
 #include "cairo-output-stream-private.h"
 
 typedef struct _cairo_type1_font {
+    int *widths;
+
     cairo_scaled_font_subset_t *scaled_font_subset;
     cairo_scaled_font_t        *type1_scaled_font;
 
+    cairo_array_t contents;
+
     double x_min, y_min, x_max, y_max;
-    int *widths;
 
     const char    *data;
     unsigned long  header_size;
@@ -53,7 +56,6 @@ typedef struct _cairo_type1_font {
     int            bbox_max_chars;
 
     cairo_output_stream_t *output;
-    cairo_array_t contents;
 
     unsigned short eexec_key;
     cairo_bool_t hex_encode;
@@ -65,32 +67,42 @@ cairo_type1_font_create (cairo_scaled_fo
                          cairo_type1_font_t         **subset_return)
 {
     cairo_type1_font_t *font;
+    cairo_font_face_t *font_face;
     cairo_matrix_t font_matrix;
     cairo_matrix_t ctm;
-    cairo_font_options_t *font_options;
+    cairo_font_options_t font_options;
 
     font = calloc (1, sizeof (cairo_type1_font_t));
     if (font == NULL)
 	return CAIRO_STATUS_NO_MEMORY;
 
+    font->widths = calloc (scaled_font_subset->num_glyphs,
+                           sizeof (int));
+    if (font->widths == NULL) {
+	free (font);
+	return CAIRO_STATUS_NO_MEMORY;
+    }
+
+    font->scaled_font_subset = scaled_font_subset;
+
+    font_face = cairo_scaled_font_get_font_face (scaled_font_subset->scaled_font);
+
     cairo_matrix_init_scale (&font_matrix, 1000, 1000);
     cairo_matrix_init_identity (&ctm);
-    font_options = cairo_font_options_create ();
-    cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
-    cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
-    font->type1_scaled_font = cairo_scaled_font_create (
-        cairo_scaled_font_get_font_face (scaled_font_subset->scaled_font),
-        &font_matrix,
-        &ctm,
-        font_options);
-    cairo_font_options_destroy (font_options);
 
-    font->scaled_font_subset = scaled_font_subset;
-    font->widths = calloc (font->scaled_font_subset->num_glyphs,
-                           sizeof (int));
+    _cairo_font_options_init_default (&font_options);
+    cairo_font_options_set_hint_style (&font_options, CAIRO_HINT_STYLE_NONE);
+    cairo_font_options_set_hint_metrics (&font_options, CAIRO_HINT_METRICS_OFF);
+
+    font->type1_scaled_font = cairo_scaled_font_create (font_face,
+							&font_matrix,
+							&ctm,
+							&font_options);
 
     _cairo_array_init (&font->contents, sizeof (unsigned char));
+
     *subset_return = font;
+
     return CAIRO_STATUS_SUCCESS;
 }
 
diff-tree 75ac7ee171d4bbe2b590e444bde9eb95138a2452 (from c28c33a5888bc1ec4ce2067a7215b7f74d4323d1)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 16:54:31 2006 -0700

    Remove font->status from cairo_type1_font_t
    
    This object doesn't act like a status-holding object, (there are no
    "if (status) return;" inertness-enforcing statements for example),
    so it shouldn't pretend like it is.

diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 6c859d4..a07d101 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -58,11 +58,8 @@ typedef struct _cairo_type1_font {
     unsigned short eexec_key;
     cairo_bool_t hex_encode;
     int hex_column;
-
-    cairo_status_t status;
 } cairo_type1_font_t;
 
-
 static cairo_status_t
 cairo_type1_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
                          cairo_type1_font_t         **subset_return)
@@ -287,17 +284,18 @@ cairo_type1_font_create_charstring (cair
                                     int                 glyph_index,
                                     cairo_array_t      *data)
 {
+    cairo_status_t status;
     cairo_scaled_glyph_t *scaled_glyph;
     t1_path_info_t path_info;
     cairo_text_extents_t *metrics;
 
-    font->status = _cairo_scaled_glyph_lookup (font->type1_scaled_font,
-                                               glyph_index,
-                                               CAIRO_SCALED_GLYPH_INFO_METRICS|
-                                               CAIRO_SCALED_GLYPH_INFO_PATH,
-                                               &scaled_glyph);
-    if (font->status)
-        return font->status;
+    status = _cairo_scaled_glyph_lookup (font->type1_scaled_font,
+					 glyph_index,
+					 CAIRO_SCALED_GLYPH_INFO_METRICS|
+					 CAIRO_SCALED_GLYPH_INFO_PATH,
+					 &scaled_glyph);
+    if (status)
+        return status;
 
     metrics = &scaled_glyph->metrics;
     if (subset_index == 0) {
@@ -317,9 +315,9 @@ cairo_type1_font_create_charstring (cair
     }
     font->widths[subset_index] = metrics->width;
 
-    font->status = _cairo_array_grow_by (data, 30);
-    if (font->status)
-        return font->status;
+    status = _cairo_array_grow_by (data, 30);
+    if (status)
+        return status;
     charstring_encode_integer (data, (int) scaled_glyph->metrics.x_bearing);
     charstring_encode_integer (data, (int) scaled_glyph->metrics.y_bearing);
     charstring_encode_integer (data, (int) scaled_glyph->metrics.width);
@@ -337,23 +335,24 @@ cairo_type1_font_create_charstring (cair
                                  _charstring_close_path,
                                  &path_info);
 
-    font->status = charstring_encode_command (path_info.data, CHARSTRING_endchar);
+    status = charstring_encode_command (path_info.data, CHARSTRING_endchar);
 
-    return font->status;
+    return status;
 }
 
-static cairo_status_t
+static cairo_int_status_t
 cairo_type1_font_write_charstrings (cairo_type1_font_t    *font,
                                     cairo_output_stream_t *encrypted_output)
 {
+    cairo_status_t status = CAIRO_STATUS_SUCCESS;
     unsigned char zeros[] = { 0, 0, 0, 0 };
     cairo_array_t data;
     unsigned int i;
     int length;
 
     _cairo_array_init (&data, sizeof (unsigned char));
-    font->status = _cairo_array_grow_by (&data, 1024);
-    if (font->status)
+    status = _cairo_array_grow_by (&data, 1024);
+    if (status)
         goto fail;
 
     _cairo_output_stream_printf (encrypted_output,
@@ -364,10 +363,10 @@ cairo_type1_font_write_charstrings (cair
         _cairo_array_truncate (&data, 0);
         /* four "random" bytes required by encryption algorithm */
         _cairo_array_append_multiple (&data, zeros, 4);
-        font->status = cairo_type1_font_create_charstring (font, i,
-                                                           font->scaled_font_subset->glyphs[i],
-                                                           &data);
-        if (font->status)
+        status = cairo_type1_font_create_charstring (font, i,
+						     font->scaled_font_subset->glyphs[i],
+						     &data);
+        if (status)
             goto fail;
         charstring_encrypt (&data);
         length = _cairo_array_num_elements (&data);
@@ -394,7 +393,7 @@ cairo_type1_font_write_charstrings (cair
 
 fail:
     _cairo_array_fini (&data);
-    return font->status;
+    return status;
 }
 
 static cairo_status_t
@@ -445,7 +444,7 @@ cairo_type1_font_write_header (cairo_typ
                                  "readonly def\n"
                                  "currentdict end\n"
                                  "currentfile eexec\n");
-    return font->status;
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_status_t
@@ -483,13 +482,15 @@ cairo_type1_write_stream_encrypted (void
 	    _cairo_output_stream_write (font->output, digits, 1);
 	}
     }
-    return font->status;
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static cairo_int_status_t
 cairo_type1_font_write_private_dict (cairo_type1_font_t *font,
                                      const char         *name)
 {
+    cairo_int_status_t status;
     cairo_output_stream_t *encrypted_output;
 
     font->eexec_key = private_dict_key;
@@ -526,12 +527,12 @@ cairo_type1_font_write_private_dict (cai
                                  "dup /FontName get exch definefont pop\n"
                                  "mark currentfile closefile\n");
 
-    if (font->status == CAIRO_STATUS_SUCCESS)
-	font->status = _cairo_output_stream_get_status (encrypted_output);
+    if (status == CAIRO_STATUS_SUCCESS)
+	status = _cairo_output_stream_get_status (encrypted_output);
   fail:
     _cairo_output_stream_destroy (encrypted_output);
 
-    return font->status;
+    return status;
 }
 
 static cairo_status_t
@@ -546,7 +547,7 @@ cairo_type1_font_write_trailer(cairo_typ
 
     _cairo_output_stream_printf (font->output, "cleartomark\n");
 
-    return font->status;
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_status_t
@@ -556,10 +557,7 @@ cairo_type1_write_stream (void *closure,
 {
     cairo_type1_font_t *font = closure;
 
-    font->status =
-	_cairo_array_append_multiple (&font->contents, data, length);
-
-    return font->status;
+    return _cairo_array_append_multiple (&font->contents, data, length);
 }
 
 static cairo_status_t
@@ -578,14 +576,16 @@ cairo_type1_font_write (cairo_type1_font
 	_cairo_output_stream_get_position (font->output) -
 	font->header_size - font->data_size;
 
-    return font->status;
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_status_t
 cairo_type1_font_generate (cairo_type1_font_t *font, const char *name)
 {
-    font->status = _cairo_array_grow_by (&font->contents, 4096);
-    if (font->status)
+    cairo_status_t status = CAIRO_STATUS_SUCCESS;
+
+    status = _cairo_array_grow_by (&font->contents, 4096);
+    if (status)
         goto fail;
 
     font->output = _cairo_output_stream_create (cairo_type1_write_stream, NULL, font);
@@ -593,7 +593,7 @@ cairo_type1_font_generate (cairo_type1_f
     font->data = _cairo_array_index (&font->contents, 0);
 
  fail:
-    return font->status;
+    return status;
 }
 
 static void
diff-tree c28c33a5888bc1ec4ce2067a7215b7f74d4323d1 (from 179f7defdffb254936592a02208c338c13466253)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 16:42:04 2006 -0700

    Check status value of output_stream object at time of destroy

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 994d922..7403b0e 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -313,6 +313,8 @@ _cairo_ps_surface_emit_path (cairo_ps_su
 					  _cairo_ps_surface_path_close_path,
 					  &path_info);
 
+    if (status == CAIRO_STATUS_SUCCESS)
+	status = _cairo_output_stream_get_status (word_wrap);
     _cairo_output_stream_destroy (word_wrap);
 
     return status;
diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 04337e3..6c859d4 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -526,7 +526,9 @@ cairo_type1_font_write_private_dict (cai
                                  "dup /FontName get exch definefont pop\n"
                                  "mark currentfile closefile\n");
 
-fail:
+    if (font->status == CAIRO_STATUS_SUCCESS)
+	font->status = _cairo_output_stream_get_status (encrypted_output);
+  fail:
     _cairo_output_stream_destroy (encrypted_output);
 
     return font->status;
diff-tree 179f7defdffb254936592a02208c338c13466253 (from 89e7d5d4208bd943c884d4261dc7484ac654132c)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 16:10:40 2006 -0700

    Use new return value from _cairo_output_stream_destroy
    
    This is a little simpler than the old idiom of calling
    _cairo_output_stream_get_status just before calling
    _cairo_output_stream_destroy.
    
    I had hoped this technique would apply in more cases, but
    many cases want to separate the two actions anyway to do
    conditional assignment of the status value, (in order to
    not overwrite an earlier error value).

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 4ae8c6a..6106284 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -546,8 +546,7 @@ _cairo_pdf_surface_finish (void *abstrac
 				 "%%%%EOF\r\n",
 				 offset);
 
-    status = _cairo_output_stream_get_status (surface->output);
-    _cairo_output_stream_destroy (surface->output);
+    status = _cairo_output_stream_destroy (surface->output);
 
     _cairo_array_fini (&surface->objects);
     _cairo_array_fini (&surface->pages);
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 2b24bf2..d4c60b6 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -1803,8 +1803,7 @@ _cairo_svg_document_finish (cairo_svg_do
     _cairo_output_stream_destroy (document->xml_node_glyphs);
     _cairo_output_stream_destroy (document->xml_node_defs);
 
-    status = _cairo_output_stream_get_status (output);
-    _cairo_output_stream_destroy (output);
+    status = _cairo_output_stream_destroy (output);
 
     for (i = 0; i < document->meta_snapshots.num_elements; i++) {
 	snapshot = _cairo_array_index (&document->meta_snapshots, i);
diff-tree 89e7d5d4208bd943c884d4261dc7484ac654132c (from 3a92ab69c89d227bdfbb1bd5d609b83a59fc013f)
Author: Carl Worth <cworth at cworth.org>
Date:   Thu Sep 7 16:01:07 2006 -0700

    Make _cairo_output_stream_destroy return the stream's status as a last gasp.

diff --git a/src/cairo-output-stream-private.h b/src/cairo-output-stream-private.h
index d1eeeeb..913fb60 100644
--- a/src/cairo-output-stream-private.h
+++ b/src/cairo-output-stream-private.h
@@ -60,7 +60,7 @@ _cairo_output_stream_init (cairo_output_
 			   cairo_output_stream_write_func_t  write_func,
 			   cairo_output_stream_close_func_t  close_func);
 
-cairo_private void
+cairo_private cairo_status_t
 _cairo_output_stream_fini (cairo_output_stream_t *stream);
 
 
@@ -86,10 +86,16 @@ _cairo_output_stream_create (cairo_write
 			     cairo_close_func_t		close_func,
 			     void			*closure);
 
-cairo_private void
+/* Returns the final status value associated with this object, just
+ * before its last gasp. This final status value will capture any
+ * status failure returned by the stream's close_func as well. */
+cairo_private cairo_status_t
 _cairo_output_stream_close (cairo_output_stream_t *stream);
 
-cairo_private void
+/* Returns the final status value associated with this object, just
+ * before its last gasp. This final status value will capture any
+ * status failure returned by the stream's close_func as well. */
+cairo_private cairo_status_t
 _cairo_output_stream_destroy (cairo_output_stream_t *stream);
 
 cairo_private void
diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c
index ad52d3d..f9e527f 100644
--- a/src/cairo-output-stream.c
+++ b/src/cairo-output-stream.c
@@ -57,13 +57,12 @@ _cairo_output_stream_init (cairo_output_
     stream->closed = FALSE;
 }
 
-cairo_private void
+cairo_private cairo_status_t
 _cairo_output_stream_fini (cairo_output_stream_t *stream)
 {
-    _cairo_output_stream_close (stream);
+    return _cairo_output_stream_close (stream);
 }
 
-
 const cairo_output_stream_t cairo_output_stream_nil = {
     NULL, /* write_func */
     NULL, /* close_func */
@@ -130,37 +129,44 @@ _cairo_output_stream_create (cairo_write
     return &stream->base;
 }
 
-void
+cairo_status_t
 _cairo_output_stream_close (cairo_output_stream_t *stream)
 {
     cairo_status_t status;
 
     if (stream->closed)
-	return;
+	return stream->status;
 
     if (stream == &cairo_output_stream_nil ||
 	stream == &cairo_output_stream_nil_write_error)
     {
-	return;
+	return stream->status;
     }
 
     if (stream->close_func) {
 	status = stream->close_func (stream);
-	if (status)
+	/* Don't overwrite a pre-existing status failure. */
+	if (stream->status == CAIRO_STATUS_SUCCESS)
 	    stream->status = status;
     }
 
     stream->closed = TRUE;
+
+    return stream->status;
 }
 
-void
+cairo_status_t
 _cairo_output_stream_destroy (cairo_output_stream_t *stream)
 {
+    cairo_status_t status;
+
     if (stream == NULL)
-	return;
+	return CAIRO_STATUS_NULL_POINTER;
 
-    _cairo_output_stream_fini (stream);
+    status = _cairo_output_stream_fini (stream);
     free (stream);
+
+    return status;
 }
 
 void


More information about the cairo-commit mailing list