mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-09 17:00:43 +01:00
[cairo-output-stream] Introduce _cairo_output_stream_create_in_error()
Use a utility function to wrap an incoming error status into a new error stream. As a side-effect, all error streams must be destroyed as in the general case the caller can not distinguish between a static error object and one allocated to hold an unusual error status.
This commit is contained in:
parent
2c10c7559d
commit
5cbc45488e
7 changed files with 46 additions and 16 deletions
|
|
@ -113,6 +113,9 @@ _cairo_base85_stream_create (cairo_output_stream_t *output)
|
|||
{
|
||||
cairo_base85_stream_t *stream;
|
||||
|
||||
if (output->status)
|
||||
return _cairo_output_stream_create_in_error (output->status);
|
||||
|
||||
stream = malloc (sizeof (cairo_base85_stream_t));
|
||||
if (stream == NULL) {
|
||||
_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
|
||||
|
|
|
|||
|
|
@ -117,11 +117,8 @@ _cairo_deflate_stream_create (cairo_output_stream_t *output)
|
|||
{
|
||||
cairo_deflate_stream_t *stream;
|
||||
|
||||
if (output->status) {
|
||||
_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
|
||||
return (cairo_output_stream_t *) &_cairo_output_stream_nil;
|
||||
}
|
||||
|
||||
if (output->status)
|
||||
return _cairo_output_stream_create_in_error (output->status);
|
||||
|
||||
stream = malloc (sizeof (cairo_deflate_stream_t));
|
||||
if (stream == NULL) {
|
||||
|
|
|
|||
|
|
@ -87,6 +87,9 @@ _cairo_output_stream_create (cairo_write_func_t write_func,
|
|||
cairo_close_func_t close_func,
|
||||
void *closure);
|
||||
|
||||
cairo_private cairo_output_stream_t *
|
||||
_cairo_output_stream_create_in_error (cairo_status_t status);
|
||||
|
||||
/* 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. */
|
||||
|
|
|
|||
|
|
@ -134,6 +134,29 @@ _cairo_output_stream_create (cairo_write_func_t write_func,
|
|||
return &stream->base;
|
||||
}
|
||||
|
||||
cairo_output_stream_t *
|
||||
_cairo_output_stream_create_in_error (cairo_status_t status)
|
||||
{
|
||||
cairo_output_stream_t *stream;
|
||||
|
||||
/* check for the common ones */
|
||||
if (status == CAIRO_STATUS_NO_MEMORY)
|
||||
return (cairo_output_stream_t *) &_cairo_output_stream_nil;
|
||||
if (status == CAIRO_STATUS_WRITE_ERROR)
|
||||
return (cairo_output_stream_t *) &_cairo_output_stream_nil_write_error;
|
||||
|
||||
stream = malloc (sizeof (cairo_output_stream_t));
|
||||
if (stream == NULL) {
|
||||
_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
|
||||
return (cairo_output_stream_t *) &_cairo_output_stream_nil;
|
||||
}
|
||||
|
||||
_cairo_output_stream_init (stream, NULL, NULL);
|
||||
stream->status = status;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
_cairo_output_stream_close (cairo_output_stream_t *stream)
|
||||
{
|
||||
|
|
@ -165,8 +188,7 @@ _cairo_output_stream_destroy (cairo_output_stream_t *stream)
|
|||
{
|
||||
cairo_status_t status;
|
||||
|
||||
if (stream == NULL)
|
||||
return _cairo_error (CAIRO_STATUS_NULL_POINTER);
|
||||
assert (stream != NULL);
|
||||
|
||||
if (stream == &_cairo_output_stream_nil ||
|
||||
stream == &_cairo_output_stream_nil_write_error)
|
||||
|
|
|
|||
|
|
@ -176,6 +176,9 @@ _word_wrap_stream_create (cairo_output_stream_t *output, int max_column)
|
|||
{
|
||||
word_wrap_stream_t *stream;
|
||||
|
||||
if (output->status)
|
||||
return _cairo_output_stream_create_in_error (output->status);
|
||||
|
||||
stream = malloc (sizeof (word_wrap_stream_t));
|
||||
if (stream == NULL) {
|
||||
_cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
|
||||
|
|
@ -301,7 +304,7 @@ _cairo_ps_surface_emit_path (cairo_ps_surface_t *surface,
|
|||
word_wrap = _word_wrap_stream_create (stream, 79);
|
||||
status = _cairo_output_stream_get_status (word_wrap);
|
||||
if (status)
|
||||
return status;
|
||||
return _cairo_output_stream_destroy (word_wrap);
|
||||
|
||||
path_info.surface = surface;
|
||||
path_info.stream = word_wrap;
|
||||
|
|
@ -3255,9 +3258,10 @@ _cairo_ps_surface_show_glyphs (void *abstract_surface,
|
|||
_cairo_output_stream_printf (surface->stream, "<%02x> S\n", glyph_ids[i].glyph_id);
|
||||
} else {
|
||||
word_wrap = _word_wrap_stream_create (surface->stream, 79);
|
||||
status = _cairo_output_stream_get_status (word_wrap);
|
||||
if (status)
|
||||
if (_cairo_output_stream_get_status (word_wrap)) {
|
||||
status = _cairo_output_stream_destroy (word_wrap);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
_cairo_output_stream_printf (word_wrap, "<");
|
||||
for (j = i; j < last+1; j++)
|
||||
|
|
|
|||
|
|
@ -601,10 +601,8 @@ cairo_type1_font_write_private_dict (cairo_type1_font_t *font,
|
|||
cairo_type1_write_stream_encrypted,
|
||||
NULL,
|
||||
font);
|
||||
if (encrypted_output == NULL) {
|
||||
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
goto fail;
|
||||
}
|
||||
if (_cairo_output_stream_get_status (encrypted_output))
|
||||
return _cairo_output_stream_destroy (encrypted_output);
|
||||
|
||||
/* Note: the first four spaces at the start of this private dict
|
||||
* are the four "random" bytes of plaintext required by the
|
||||
|
|
@ -697,6 +695,8 @@ cairo_type1_font_generate (cairo_type1_font_t *font, const char *name)
|
|||
return status;
|
||||
|
||||
font->output = _cairo_output_stream_create (cairo_type1_write_stream, NULL, font);
|
||||
if (_cairo_output_stream_get_status (font->output))
|
||||
return _cairo_output_stream_destroy (font->output);
|
||||
|
||||
status = cairo_type1_font_write (font, name);
|
||||
if (status)
|
||||
|
|
|
|||
|
|
@ -1126,9 +1126,10 @@ cairo_type1_font_subset_generate (void *abstract_font,
|
|||
goto fail;
|
||||
|
||||
font->output = _cairo_output_stream_create (type1_font_write, NULL, font);
|
||||
status = _cairo_output_stream_get_status (font->output);
|
||||
if (status)
|
||||
if (_cairo_output_stream_get_status (font->output)) {
|
||||
status = _cairo_output_stream_destroy (font->output);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
status = cairo_type1_font_subset_write (font, name);
|
||||
if (status)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue