diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-01-16 16:29:19 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-01-16 16:40:01 +0000 |
commit | 5cbc45488e276cb6e6ecfa7bc7dd4fae342de85e (patch) | |
tree | 672c700de47687c25c68cb22743c0a058e4b06d1 /src/cairo-output-stream.c | |
parent | 2c10c7559db11ccf511e119f4d4fb2da97508786 (diff) | |
download | cairo-5cbc45488e276cb6e6ecfa7bc7dd4fae342de85e.tar.gz |
[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.
Diffstat (limited to 'src/cairo-output-stream.c')
-rw-r--r-- | src/cairo-output-stream.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/cairo-output-stream.c b/src/cairo-output-stream.c index 6451b0fe6..2cb9e03bc 100644 --- a/src/cairo-output-stream.c +++ b/src/cairo-output-stream.c @@ -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) |