diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-01-16 16:23:23 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-01-16 16:51:32 +0000 |
commit | 7111b18c27d7ee0439339a6aa72f0e4244f883f9 (patch) | |
tree | 162d5cf10b629ded2a44f8bb1cc64e4671a58cc7 | |
parent | 5cbc45488e276cb6e6ecfa7bc7dd4fae342de85e (diff) |
[cairo-surface] Introduce _cairo_surface_create_in_error().
Unexport all the static error surfaces and use a function to select
the appropriate error surface for the status.
-rw-r--r-- | src/cairo-array.c | 3 | ||||
-rw-r--r-- | src/cairo-glitz-surface.c | 20 | ||||
-rw-r--r-- | src/cairo-image-surface.c | 136 | ||||
-rw-r--r-- | src/cairo-meta-surface.c | 12 | ||||
-rw-r--r-- | src/cairo-os2-surface.c | 22 | ||||
-rw-r--r-- | src/cairo-paginated-surface.c | 8 | ||||
-rw-r--r-- | src/cairo-pdf-surface.c | 11 | ||||
-rw-r--r-- | src/cairo-png.c | 38 | ||||
-rw-r--r-- | src/cairo-ps-surface.c | 9 | ||||
-rw-r--r-- | src/cairo-quartz-surface.c | 32 | ||||
-rw-r--r-- | src/cairo-surface-fallback.c | 6 | ||||
-rw-r--r-- | src/cairo-surface.c | 62 | ||||
-rw-r--r-- | src/cairo-svg-surface.c | 20 | ||||
-rw-r--r-- | src/cairo-win32-printing-surface.c | 10 | ||||
-rw-r--r-- | src/cairo-win32-surface.c | 37 | ||||
-rw-r--r-- | src/cairo-xcb-surface.c | 18 | ||||
-rw-r--r-- | src/cairo-xlib-surface.c | 26 | ||||
-rw-r--r-- | src/cairo.c | 4 | ||||
-rw-r--r-- | src/cairoint.h | 6 | ||||
-rw-r--r-- | src/test-fallback-surface.c | 5 | ||||
-rw-r--r-- | src/test-meta-surface.c | 18 | ||||
-rw-r--r-- | src/test-paginated-surface.c | 5 |
22 files changed, 185 insertions, 323 deletions
diff --git a/src/cairo-array.c b/src/cairo-array.c index 0313caa9..470b327c 100644 --- a/src/cairo-array.c +++ b/src/cairo-array.c @@ -396,8 +396,7 @@ _cairo_user_data_array_get_data (cairo_user_data_array_t *array, int i, num_slots; cairo_user_data_slot_t *slots; - /* We allow this to support degenerate objects such as - * cairo_image_surface_nil. */ + /* We allow this to support degenerate objects such as cairo_surface_nil. */ if (array == NULL) return NULL; diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c index 05e80dbf..04084e14 100644 --- a/src/cairo-glitz-surface.c +++ b/src/cairo-glitz-surface.c @@ -88,20 +88,16 @@ _cairo_glitz_surface_create_similar (void *abstract_src, gformat = glitz_find_standard_format (drawable, _glitz_format_from_content (content)); - if (!gformat) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (!gformat) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); surface = glitz_surface_create (drawable, gformat, width <= 0 ? 1 : width, height <= 0 ? 1 : height, 0, NULL); - if (surface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); crsurface = cairo_glitz_surface_create (surface); @@ -2456,13 +2452,11 @@ cairo_glitz_surface_create (glitz_surface_t *surface) glitz_format_t *format; if (surface == NULL) - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NULL_POINTER)); crsurface = malloc (sizeof (cairo_glitz_surface_t)); - if (crsurface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (crsurface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); format = glitz_surface_get_format (surface); _cairo_surface_init (&crsurface->base, &cairo_glitz_surface_backend, diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index cf19a8fc..8787185b 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -37,101 +37,6 @@ #include "cairoint.h" -static const cairo_image_surface_t _cairo_image_surface_nil_invalid_format = { - { - &cairo_image_surface_backend, /* backend */ - CAIRO_SURFACE_TYPE_IMAGE, - CAIRO_CONTENT_COLOR, - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_INVALID_FORMAT, /* status */ - FALSE, /* finished */ - { 0, /* size */ - 0, /* num_elements */ - 0, /* element_size */ - NULL, /* elements */ - }, /* user_data */ - { 1.0, 0.0, - 0.0, 1.0, - 0.0, 0.0 - }, /* device_transform */ - { 1.0, 0.0, - 0.0, 1.0, - 0.0, 0.0 - }, /* device_transform_inverse */ - 0.0, /* x_resolution */ - 0.0, /* y_resolution */ - 0.0, /* x_fallback_resolution */ - 0.0, /* y_fallback_resolution */ - NULL, /* clip */ - 0, /* next_clip_serial */ - 0, /* current_clip_serial */ - FALSE, /* is_snapshot */ - FALSE, /* has_font_options */ - { CAIRO_ANTIALIAS_DEFAULT, - CAIRO_SUBPIXEL_ORDER_DEFAULT, - CAIRO_HINT_STYLE_DEFAULT, - CAIRO_HINT_METRICS_DEFAULT - } /* font_options */ - }, /* base */ - PIXMAN_a8r8g8b8, /* pixman_format */ - CAIRO_FORMAT_ARGB32, /* format */ - NULL, /* data */ - FALSE, /* owns_data */ - FALSE, /* has_clip */ - 0, /* width */ - 0, /* height */ - 0, /* stride */ - 0, /* depth */ - NULL /* pixman_image */ -}; -static const cairo_image_surface_t _cairo_image_surface_nil_invalid_content = { - { - &cairo_image_surface_backend, /* backend */ - CAIRO_SURFACE_TYPE_IMAGE, - CAIRO_CONTENT_COLOR, - CAIRO_REFERENCE_COUNT_INVALID, /* ref_count */ - CAIRO_STATUS_INVALID_CONTENT, /* status */ - FALSE, /* finished */ - { 0, /* size */ - 0, /* num_elements */ - 0, /* element_size */ - NULL, /* elements */ - }, /* user_data */ - { 1.0, 0.0, - 0.0, 1.0, - 0.0, 0.0 - }, /* device_transform */ - { 1.0, 0.0, - 0.0, 1.0, - 0.0, 0.0 - }, /* device_transform_inverse */ - 0.0, /* x_resolution */ - 0.0, /* y_resolution */ - 0.0, /* x_fallback_resolution */ - 0.0, /* y_fallback_resolution */ - NULL, /* clip */ - 0, /* next_clip_serial */ - 0, /* current_clip_serial */ - FALSE, /* is_snapshot */ - FALSE, /* has_font_options */ - { CAIRO_ANTIALIAS_DEFAULT, - CAIRO_SUBPIXEL_ORDER_DEFAULT, - CAIRO_HINT_STYLE_DEFAULT, - CAIRO_HINT_METRICS_DEFAULT - } /* font_options */ - }, /* base */ - PIXMAN_a8r8g8b8, /* pixman_format */ - CAIRO_FORMAT_ARGB32, /* format */ - NULL, /* data */ - FALSE, /* owns_data */ - FALSE, /* has_clip */ - 0, /* width */ - 0, /* height */ - 0, /* stride */ - 0, /* depth */ - NULL /* pixman_image */ -}; - static cairo_format_t _cairo_format_from_pixman_format (pixman_format_code_t pixman_format) { @@ -213,10 +118,8 @@ _cairo_image_surface_create_for_pixman_image (pixman_image_t *pixman_image, cairo_image_surface_t *surface; surface = malloc (sizeof (cairo_image_surface_t)); - if (surface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); _cairo_surface_init (&surface->base, &cairo_image_surface_backend, _cairo_content_from_pixman_format (pixman_format)); @@ -432,16 +335,13 @@ _cairo_image_surface_create_with_pixman_format (unsigned char *data, pixman_image = pixman_image_create_bits (pixman_format, width, height, (uint32_t *) data, stride); - if (pixman_image == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (pixman_image == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); surface = _cairo_image_surface_create_for_pixman_image (pixman_image, pixman_format); - if (cairo_surface_status (surface)) { + if (cairo_surface_status (surface)) pixman_image_unref (pixman_image); - } return surface; } @@ -473,10 +373,8 @@ cairo_image_surface_create (cairo_format_t format, { pixman_format_code_t pixman_format; - if (! CAIRO_FORMAT_VALID (format)) { - _cairo_error_throw (CAIRO_STATUS_INVALID_FORMAT); - return (cairo_surface_t*) &_cairo_image_surface_nil_invalid_format; - } + if (! CAIRO_FORMAT_VALID (format)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); pixman_format = _cairo_format_to_pixman_format_code (format); @@ -490,10 +388,8 @@ _cairo_image_surface_create_with_content (cairo_content_t content, int width, int height) { - if (! CAIRO_CONTENT_VALID (content)) { - _cairo_error_throw (CAIRO_STATUS_INVALID_CONTENT); - return (cairo_surface_t*) &_cairo_image_surface_nil_invalid_content; - } + if (! CAIRO_CONTENT_VALID (content)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); return cairo_image_surface_create (_cairo_format_from_content (content), width, height); @@ -541,10 +437,8 @@ cairo_image_surface_create_for_data (unsigned char *data, /* XXX pixman does not support images with arbitrary strides and * attempting to create such surfaces will failure but we will interpret * such failure as CAIRO_STATUS_NO_MEMORY. */ - if (! CAIRO_FORMAT_VALID (format) || stride % sizeof (uint32_t) != 0) { - _cairo_error_throw (CAIRO_STATUS_INVALID_FORMAT); - return (cairo_surface_t*) &_cairo_image_surface_nil_invalid_format; - } + if (! CAIRO_FORMAT_VALID (format) || stride % sizeof (uint32_t) != 0) + return _cairo_surface_create_in_error (_cairo_error(CAIRO_STATUS_INVALID_FORMAT)); pixman_format = _cairo_format_to_pixman_format_code (format); @@ -560,10 +454,8 @@ _cairo_image_surface_create_for_data_with_content (unsigned char *data, int height, int stride) { - if (! CAIRO_CONTENT_VALID (content)) { - _cairo_error_throw (CAIRO_STATUS_INVALID_CONTENT); - return (cairo_surface_t*) &_cairo_image_surface_nil_invalid_content; - } + if (! CAIRO_CONTENT_VALID (content)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); return cairo_image_surface_create_for_data (data, _cairo_format_from_content (content), @@ -1382,7 +1274,7 @@ _cairo_image_surface_clone (cairo_image_surface_t *surface, if (status) { cairo_surface_destroy (&clone->base); - return (cairo_image_surface_t *) &_cairo_surface_nil; + return (cairo_image_surface_t *) _cairo_surface_create_in_error (status); } return clone; diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c index 5b4f4ffa..51ed3829 100644 --- a/src/cairo-meta-surface.c +++ b/src/cairo-meta-surface.c @@ -83,10 +83,8 @@ _cairo_meta_surface_create (cairo_content_t content, cairo_meta_surface_t *meta; meta = malloc (sizeof (cairo_meta_surface_t)); - if (meta == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (meta == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); _cairo_surface_init (&meta->base, &cairo_meta_surface_backend, content); @@ -498,10 +496,8 @@ _cairo_meta_surface_snapshot (void *abstract_other) cairo_meta_surface_t *meta; meta = malloc (sizeof (cairo_meta_surface_t)); - if (meta == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (meta == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); _cairo_surface_init (&meta->base, &cairo_meta_surface_backend, other->base.content); diff --git a/src/cairo-os2-surface.c b/src/cairo-os2-surface.c index 86ab82c2..f3824849 100644 --- a/src/cairo-os2-surface.c +++ b/src/cairo-os2-surface.c @@ -722,6 +722,7 @@ cairo_os2_surface_create (HPS hps_client_window, int height) { cairo_os2_surface_t *local_os2_surface; + cairo_status_t status; int rc; /* Check the size of the window */ @@ -729,15 +730,13 @@ cairo_os2_surface_create (HPS hps_client_window, (height <= 0)) { /* Invalid window size! */ - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } local_os2_surface = (cairo_os2_surface_t *) malloc (sizeof (cairo_os2_surface_t)); if (!local_os2_surface) { /* Not enough memory! */ - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Initialize the OS/2 specific parts of the surface! */ @@ -749,8 +748,7 @@ cairo_os2_surface_create (HPS hps_client_window, FALSE); if (rc != NO_ERROR) { /* Could not create mutex semaphore! */ - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Save PS handle */ @@ -769,8 +767,7 @@ cairo_os2_surface_create (HPS hps_client_window, /* Could not create event semaphore! */ DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); free (local_os2_surface); - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Prepare BITMAPINFO2 structure for our buffer */ @@ -788,8 +785,7 @@ cairo_os2_surface_create (HPS hps_client_window, DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); free (local_os2_surface); - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Create image surface from pixel array */ @@ -800,14 +796,14 @@ cairo_os2_surface_create (HPS hps_client_window, height, /* Height */ width * 4); /* Rowstride */ - if (local_os2_surface->image_surface->base.status) { + status = local_os2_surface->image_surface->base.status; + if (status) { /* Could not create image surface! */ _buffer_free (local_os2_surface->pixels); DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back); DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields); free (local_os2_surface); - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); } /* Initialize base surface */ diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c index 6af4be6e..98ec061c 100644 --- a/src/cairo-paginated-surface.c +++ b/src/cairo-paginated-surface.c @@ -74,10 +74,11 @@ _cairo_paginated_surface_create (cairo_surface_t *target, const cairo_paginated_surface_backend_t *backend) { cairo_paginated_surface_t *surface; + cairo_status_t status; surface = malloc (sizeof (cairo_paginated_surface_t)); if (surface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto FAIL; } @@ -97,7 +98,8 @@ _cairo_paginated_surface_create (cairo_surface_t *target, surface->backend = backend; surface->meta = _cairo_meta_surface_create (content, width, height); - if (cairo_surface_status (surface->meta)) + status = cairo_surface_status (surface->meta); + if (status) goto FAIL_CLEANUP_SURFACE; surface->page_num = 1; @@ -108,7 +110,7 @@ _cairo_paginated_surface_create (cairo_surface_t *target, FAIL_CLEANUP_SURFACE: free (surface); FAIL: - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); } cairo_bool_t diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index 29c2c419..9ad9e1a1 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -240,8 +240,7 @@ _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *output, if (surface == NULL) { /* destroy stream on behalf of caller */ status = _cairo_output_stream_destroy (output); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } _cairo_surface_init (&surface->base, &cairo_pdf_surface_backend, @@ -316,7 +315,7 @@ BAIL0: /* destroy stream on behalf of caller */ status = _cairo_output_stream_destroy (output); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY); } /** @@ -351,7 +350,7 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, output = _cairo_output_stream_create (write_func, NULL, closure); status = _cairo_output_stream_get_status (output); if (status) - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); return _cairo_pdf_surface_create_for_stream_internal (output, width_in_points, @@ -388,9 +387,7 @@ cairo_pdf_surface_create (const char *filename, output = _cairo_output_stream_create_for_filename (filename); status = _cairo_output_stream_get_status (output); if (status) - return (status == CAIRO_STATUS_WRITE_ERROR) ? - (cairo_surface_t*) &_cairo_surface_nil_write_error : - (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); return _cairo_pdf_surface_create_for_stream_internal (output, width_in_points, diff --git a/src/cairo-png.c b/src/cairo-png.c index b76b525b..a78da3f8 100644 --- a/src/cairo-png.c +++ b/src/cairo-png.c @@ -382,7 +382,7 @@ static cairo_surface_t * read_png (png_rw_ptr read_func, void *closure) { - cairo_surface_t *surface = (cairo_surface_t*) &_cairo_surface_nil; + cairo_surface_t *surface; png_struct *png = NULL; png_info *info; png_byte *data = NULL; @@ -398,20 +398,23 @@ read_png (png_rw_ptr read_func, &status, png_simple_error_callback, png_simple_warning_callback); - if (png == NULL) + if (png == NULL) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); goto BAIL; + } info = png_create_info_struct (png); - if (info == NULL) + if (info == NULL) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); goto BAIL; + } png_set_read_fn (png, closure, read_func); status = CAIRO_STATUS_SUCCESS; #ifdef PNG_SETJMP_SUPPORTED if (setjmp (png_jmpbuf (png))) { - if (status != CAIRO_STATUS_NO_MEMORY) - surface = (cairo_surface_t*) &_cairo_surface_nil_read_error; + surface = _cairo_surface_create_in_error (status); goto BAIL; } #endif @@ -460,12 +463,16 @@ read_png (png_rw_ptr read_func, pixel_size = 4; data = _cairo_malloc_abc (png_height, png_width, pixel_size); - if (data == NULL) + if (data == NULL) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); goto BAIL; + } row_pointers = _cairo_malloc_ab (png_height, sizeof (char *)); - if (row_pointers == NULL) + if (row_pointers == NULL) { + surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); goto BAIL; + } for (i = 0; i < png_height; i++) row_pointers[i] = &data[i * png_width * pixel_size]; @@ -490,9 +497,6 @@ read_png (png_rw_ptr read_func, if (png) png_destroy_read_struct (&png, &info, NULL); - if (surface->status) - _cairo_error_throw (surface->status); - return surface; } @@ -538,17 +542,19 @@ cairo_image_surface_create_from_png (const char *filename) fp = fopen (filename, "rb"); if (fp == NULL) { + cairo_status_t status; switch (errno) { case ENOMEM: - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + break; case ENOENT: - _cairo_error_throw (CAIRO_STATUS_FILE_NOT_FOUND); - return (cairo_surface_t*) &_cairo_surface_nil_file_not_found; + status = _cairo_error (CAIRO_STATUS_FILE_NOT_FOUND); + break; default: - _cairo_error_throw (CAIRO_STATUS_READ_ERROR); - return (cairo_surface_t*) &_cairo_surface_nil_read_error; + status = _cairo_error (CAIRO_STATUS_READ_ERROR); + break; } + return _cairo_surface_create_in_error (status); } surface = read_png (stdio_read_func, fp); diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index 93c90555..f8c3f8cf 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -1012,8 +1012,7 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream, CLEANUP: /* destroy stream on behalf of caller */ status = _cairo_output_stream_destroy (stream); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /** @@ -1051,9 +1050,7 @@ cairo_ps_surface_create (const char *filename, stream = _cairo_output_stream_create_for_filename (filename); status = _cairo_output_stream_get_status (stream); if (status) - return (status == CAIRO_STATUS_WRITE_ERROR) ? - (cairo_surface_t*) &_cairo_surface_nil_write_error : - (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); return _cairo_ps_surface_create_for_stream_internal (stream, width_in_points, @@ -1097,7 +1094,7 @@ cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, stream = _cairo_output_stream_create (write_func, NULL, closure); status = _cairo_output_stream_get_status (stream); if (status) - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); return _cairo_ps_surface_create_for_stream_internal (stream, width_in_points, diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c index 1990062a..3cb63898 100644 --- a/src/cairo-quartz-surface.c +++ b/src/cairo-quartz-surface.c @@ -1865,10 +1865,8 @@ _cairo_quartz_surface_create_internal (CGContextRef cgContext, /* Init the base surface */ surface = malloc(sizeof(cairo_quartz_surface_t)); - if (surface == NULL) { - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return NULL; - } + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); memset(surface, 0, sizeof(cairo_quartz_surface_t)); @@ -1940,10 +1938,10 @@ cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext, surf = _cairo_quartz_surface_create_internal (cgContext, CAIRO_CONTENT_COLOR_ALPHA, width, height); - if (!surf) { + if (surf->base.status) { CGContextRelease (cgContext); // create_internal will have set an error - return (cairo_surface_t*) &_cairo_surface_nil; + return surf; } return (cairo_surface_t *) surf; @@ -1978,10 +1976,8 @@ cairo_quartz_surface_create (cairo_format_t format, int bitsPerComponent; // verify width and height of surface - if (!verify_surface_size(width, height)) { - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (!verify_surface_size(width, height)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); if (width == 0 || height == 0) { return (cairo_surface_t*) _cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format), @@ -2011,18 +2007,15 @@ cairo_quartz_surface_create (cairo_format_t format, * cairo_format_t -- these are 1-bit pixels stored in 32-bit * quantities. */ - _cairo_error (CAIRO_STATUS_INVALID_FORMAT); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); } else { - _cairo_error (CAIRO_STATUS_INVALID_FORMAT); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); } imageData = _cairo_malloc_ab (height, stride); if (!imageData) { CGColorSpaceRelease (cgColorspace); - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* zero the memory to match the image surface behaviour */ memset (imageData, 0, height * stride); @@ -2037,9 +2030,8 @@ cairo_quartz_surface_create (cairo_format_t format, CGColorSpaceRelease (cgColorspace); if (!cgc) { - _cairo_error (CAIRO_STATUS_NO_MEMORY); free (imageData); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* flip the Y axis */ @@ -2048,11 +2040,11 @@ cairo_quartz_surface_create (cairo_format_t format, surf = _cairo_quartz_surface_create_internal (cgc, _cairo_content_from_format (format), width, height); - if (!surf) { + if (surf->base.status) { CGContextRelease (cgc); free (imageData); // create_internal will have set an error - return (cairo_surface_t*) &_cairo_surface_nil; + return surf; } surf->imageData = imageData; diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c index ef28d9d8..02a2e9d9 100644 --- a/src/cairo-surface-fallback.c +++ b/src/cairo-surface-fallback.c @@ -1043,8 +1043,8 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface) status = _cairo_surface_acquire_source_image (surface, &image, &image_extra); - if (status != CAIRO_STATUS_SUCCESS) - return (cairo_surface_t *) &_cairo_surface_nil; + if (status) + return _cairo_surface_create_in_error (status); snapshot = cairo_image_surface_create (image->format, image->width, @@ -1073,7 +1073,7 @@ _cairo_surface_fallback_snapshot (cairo_surface_t *surface) if (status) { cairo_surface_destroy (snapshot); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); } snapshot->device_transform = surface->device_transform; diff --git a/src/cairo-surface.c b/src/cairo-surface.c index f6f26c77..8860c953 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -78,10 +78,14 @@ const cairo_surface_t name = { \ } /* font_options */ \ } -DEFINE_NIL_SURFACE(CAIRO_STATUS_NO_MEMORY, _cairo_surface_nil); -DEFINE_NIL_SURFACE(CAIRO_STATUS_FILE_NOT_FOUND, _cairo_surface_nil_file_not_found); -DEFINE_NIL_SURFACE(CAIRO_STATUS_READ_ERROR, _cairo_surface_nil_read_error); -DEFINE_NIL_SURFACE(CAIRO_STATUS_WRITE_ERROR, _cairo_surface_nil_write_error); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_NO_MEMORY, _cairo_surface_nil); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_CONTENT, _cairo_surface_nil_invalid_content); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_FORMAT, _cairo_surface_nil_invalid_format); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_VISUAL, _cairo_surface_nil_invalid_visual); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_FILE_NOT_FOUND, _cairo_surface_nil_file_not_found); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_TEMP_FILE_ERROR, _cairo_surface_nil_temp_file_error); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_READ_ERROR, _cairo_surface_nil_read_error); +static DEFINE_NIL_SURFACE(CAIRO_STATUS_WRITE_ERROR, _cairo_surface_nil_write_error); static cairo_status_t _cairo_surface_copy_pattern_for_destination (const cairo_pattern_t *pattern, @@ -228,7 +232,7 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other, cairo_format_t format = _cairo_format_from_content (content); if (other->status) - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (other->status); if (other->backend->create_similar) { surface = other->backend->create_similar (other, content, width, height); @@ -289,12 +293,10 @@ cairo_surface_create_similar (cairo_surface_t *other, int height) { if (other->status) - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (other->status); - if (! CAIRO_CONTENT_VALID (content)) { - _cairo_error_throw (CAIRO_STATUS_INVALID_CONTENT); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (! CAIRO_CONTENT_VALID (content)) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT)); return _cairo_surface_create_similar_solid (other, content, width, height, @@ -317,17 +319,14 @@ _cairo_surface_create_similar_solid (cairo_surface_t *other, surface = _cairo_surface_create_similar_scratch (other, content, width, height); - if (surface->status) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (surface->status) + return surface; if (pattern == NULL) { source = _cairo_pattern_create_solid (color, content); if (source->status) { cairo_surface_destroy (surface); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (source->status); } } else source = pattern; @@ -342,8 +341,7 @@ _cairo_surface_create_similar_solid (cairo_surface_t *other, if (status) { cairo_surface_destroy (surface); - _cairo_error_throw (status); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); } return surface; @@ -1141,7 +1139,7 @@ cairo_surface_t * _cairo_surface_snapshot (cairo_surface_t *surface) { if (surface->finished) - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_FINISHED)); if (surface->backend->snapshot) return surface->backend->snapshot (surface); @@ -2412,5 +2410,31 @@ _cairo_surface_set_resolution (cairo_surface_t *surface, surface->y_resolution = y_res; } +cairo_surface_t * +_cairo_surface_create_in_error (cairo_status_t status) +{ + switch (status) { + case CAIRO_STATUS_NO_MEMORY: + return (cairo_surface_t *) &_cairo_surface_nil; + case CAIRO_STATUS_INVALID_CONTENT: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_content; + case CAIRO_STATUS_INVALID_FORMAT: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_format; + case CAIRO_STATUS_INVALID_VISUAL: + return (cairo_surface_t *) &_cairo_surface_nil_invalid_visual; + case CAIRO_STATUS_READ_ERROR: + return (cairo_surface_t *) &_cairo_surface_nil_read_error; + case CAIRO_STATUS_WRITE_ERROR: + return (cairo_surface_t *) &_cairo_surface_nil_write_error; + case CAIRO_STATUS_FILE_NOT_FOUND: + return (cairo_surface_t *) &_cairo_surface_nil_file_not_found; + case CAIRO_STATUS_TEMP_FILE_ERROR: + return (cairo_surface_t *) &_cairo_surface_nil_temp_file_error; + default: + _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); + return (cairo_surface_t *) &_cairo_surface_nil; + } +} + /* LocalWords: rasterized */ diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c index acddb161..df59ef74 100644 --- a/src/cairo-svg-surface.c +++ b/src/cairo-svg-surface.c @@ -179,7 +179,7 @@ cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, stream = _cairo_output_stream_create (write_func, NULL, closure); status = _cairo_output_stream_get_status (stream); if (status) - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); return _cairo_svg_surface_create_for_stream_internal (stream, width, height, CAIRO_SVG_VERSION_1_1); } @@ -214,9 +214,7 @@ cairo_svg_surface_create (const char *filename, stream = _cairo_output_stream_create_for_filename (filename); status = _cairo_output_stream_get_status (stream); if (status) - return (status == CAIRO_STATUS_WRITE_ERROR) ? - (cairo_surface_t *) &_cairo_surface_nil_write_error : - (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); return _cairo_svg_surface_create_for_stream_internal (stream, width, height, CAIRO_SVG_VERSION_1_1); } @@ -335,10 +333,8 @@ _cairo_svg_surface_create_for_document (cairo_svg_document_t *document, cairo_status_t status; surface = malloc (sizeof (cairo_svg_surface_t)); - if (surface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); _cairo_surface_init (&surface->base, &cairo_svg_surface_backend, content); @@ -389,8 +385,7 @@ CLEANUP_DOCUMENT: status = _cairo_svg_document_destroy (document); free (surface); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } static cairo_surface_t * @@ -407,15 +402,14 @@ _cairo_svg_surface_create_for_stream_internal (cairo_output_stream_t *stream, if (document == NULL) { /* consume the output stream on behalf of caller */ status = _cairo_output_stream_destroy (stream); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } surface = _cairo_svg_surface_create_for_document (document, CAIRO_CONTENT_COLOR_ALPHA, width, height); if (surface->status) { status = _cairo_svg_document_destroy (document); - return (cairo_surface_t *) &_cairo_surface_nil; + return surface; } document->owner = surface; diff --git a/src/cairo-win32-printing-surface.c b/src/cairo-win32-printing-surface.c index 3a5a3b88..d589f236 100644 --- a/src/cairo-win32-printing-surface.c +++ b/src/cairo-win32-printing-surface.c @@ -71,7 +71,6 @@ #endif #define PELS_72DPI ((LONG)(72. / 0.0254)) -#define NIL_SURFACE ((cairo_surface_t*)&_cairo_surface_nil) static const cairo_surface_backend_t cairo_win32_printing_surface_backend; static const cairo_paginated_surface_backend_t cairo_win32_surface_paginated_backend; @@ -1467,15 +1466,12 @@ cairo_win32_printing_surface_create (HDC hdc) if (GetClipBox (hdc, &rect) == ERROR) { _cairo_win32_print_gdi_error ("cairo_win32_surface_create"); /* XXX: Can we make a more reasonable guess at the error cause here? */ - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NIL_SURFACE; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } surface = malloc (sizeof (cairo_win32_surface_t)); - if (surface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NIL_SURFACE; - } + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); surface->image = NULL; surface->format = CAIRO_FORMAT_RGB24; diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c index 2342230d..881532b6 100644 --- a/src/cairo-win32-surface.c +++ b/src/cairo-win32-surface.c @@ -67,7 +67,6 @@ #endif #define PELS_72DPI ((LONG)(72. / 0.0254)) -#define NIL_SURFACE ((cairo_surface_t*)&_cairo_surface_nil) static const cairo_surface_backend_t cairo_win32_surface_backend; @@ -333,10 +332,8 @@ _cairo_win32_surface_create_for_dc (HDC original_dc, int rowstride; surface = malloc (sizeof (cairo_win32_surface_t)); - if (surface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NIL_SURFACE; - } + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); status = _create_dc_and_bitmap (surface, original_dc, format, width, height, @@ -346,10 +343,9 @@ _cairo_win32_surface_create_for_dc (HDC original_dc, surface->image = cairo_image_surface_create_for_data (bits, format, width, height, rowstride); - if (surface->image->status) { - status = _cairo_error (CAIRO_STATUS_NO_MEMORY); + status = surface->image->status; + if (status) goto FAIL; - } surface->format = format; @@ -365,7 +361,7 @@ _cairo_win32_surface_create_for_dc (HDC original_dc, _cairo_surface_init (&surface->base, &cairo_win32_surface_backend, _cairo_content_from_format (format)); - return (cairo_surface_t *)surface; + return &surface->base; FAIL: if (surface->bitmap) { @@ -373,10 +369,9 @@ _cairo_win32_surface_create_for_dc (HDC original_dc, DeleteObject (surface->bitmap); DeleteDC (surface->dc); } - if (surface) - free (surface); + free (surface); - return NIL_SURFACE; + return _cairo_surface_create_in_error (status); } static cairo_surface_t * @@ -1720,8 +1715,7 @@ cairo_win32_surface_create (HDC hdc) if (clipBoxType == ERROR) { _cairo_win32_print_gdi_error ("cairo_win32_surface_create"); /* XXX: Can we make a more reasonable guess at the error cause here? */ - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NIL_SURFACE; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } if (GetDeviceCaps(hdc, TECHNOLOGY) == DT_RASDISPLAY) { @@ -1738,18 +1732,15 @@ cairo_win32_surface_create (HDC hdc) format = CAIRO_FORMAT_A1; else { _cairo_win32_print_gdi_error("cairo_win32_surface_create(bad BITSPIXEL)"); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NIL_SURFACE; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); } } else { format = CAIRO_FORMAT_RGB24; } surface = malloc (sizeof (cairo_win32_surface_t)); - if (surface == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return NIL_SURFACE; - } + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); surface->image = NULL; surface->format = format; @@ -1837,7 +1828,7 @@ cairo_win32_surface_create_with_ddb (HDC hdc, HBITMAP saved_dc_bitmap; if (format != CAIRO_FORMAT_RGB24) - return NIL_SURFACE; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); /* XXX handle these eventually format != CAIRO_FORMAT_A8 || format != CAIRO_FORMAT_A1) @@ -1853,7 +1844,7 @@ cairo_win32_surface_create_with_ddb (HDC hdc, ddb_dc = CreateCompatibleDC (hdc); if (ddb_dc == NULL) { _cairo_win32_print_gdi_error("CreateCompatibleDC"); - new_surf = (cairo_win32_surface_t*) NIL_SURFACE; + new_surf = (cairo_win32_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); goto FINISH; } @@ -1866,7 +1857,7 @@ cairo_win32_surface_create_with_ddb (HDC hdc, * video memory is probably exhausted. */ _cairo_win32_print_gdi_error("CreateCompatibleBitmap"); - new_surf = (cairo_win32_surface_t*) NIL_SURFACE; + new_surf = (cairo_win32_surface_t*) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); goto FINISH; } diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c index 451cc8f4..2b1f888a 100644 --- a/src/cairo-xcb-surface.c +++ b/src/cairo-xcb-surface.c @@ -196,10 +196,8 @@ _cairo_xcb_surface_create_similar (void *abstract_src, cairo_xcb_surface_create_with_xrender_format (dpy, pixmap, src->screen, xrender_format, width, height); - if (surface->base.status) { - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (surface->base.status) + return surface; surface->owns_pixmap = TRUE; @@ -1730,10 +1728,8 @@ _cairo_xcb_surface_create_internal (xcb_connection_t *dpy, const xcb_render_query_version_reply_t *r; surface = malloc (sizeof (cairo_xcb_surface_t)); - if (surface == NULL) { - _cairo_error (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (surface == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); if (xrender_format) { depth = xrender_format->depth; @@ -1873,10 +1869,8 @@ cairo_xcb_surface_create (xcb_connection_t *c, { xcb_screen_t *screen = _cairo_xcb_screen_from_visual (c, visual); - if (screen == NULL) { - _cairo_error (CAIRO_STATUS_INVALID_VISUAL); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (screen == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); return _cairo_xcb_surface_create_internal (c, drawable, screen, visual, NULL, diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index bd1a3e8e..93cd6f8b 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -176,10 +176,9 @@ _cairo_xlib_surface_create_similar_with_format (void *abstract_src, cairo_xlib_surface_create_with_xrender_format (dpy, pix, src->screen, xrender_format, width, height); - if (surface->base.status != CAIRO_STATUS_SUCCESS) { + if (surface->base.status) { XFreePixmap (dpy, pix); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return &surface->base; } surface->owns_pixmap = TRUE; @@ -258,8 +257,7 @@ _cairo_xlib_surface_create_similar (void *abstract_src, width, height); if (surface->base.status != CAIRO_STATUS_SUCCESS) { XFreePixmap (src->dpy, pix); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return &surface->base; } surface->owns_pixmap = TRUE; @@ -1949,24 +1947,20 @@ _cairo_xlib_surface_create_internal (Display *dpy, cairo_xlib_screen_info_t *screen_info; screen_info = _cairo_xlib_screen_info_get (dpy, screen); - if (screen_info == NULL) { - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (screen_info == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); surface = malloc (sizeof (cairo_xlib_surface_t)); if (surface == NULL) { _cairo_xlib_screen_info_destroy (screen_info); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } if (! _cairo_xlib_add_close_display_hook (dpy, _cairo_xlib_surface_detach_display, surface, surface)) { free (surface); _cairo_xlib_screen_info_destroy (screen_info); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } if (xrender_format) { @@ -2096,10 +2090,8 @@ cairo_xlib_surface_create (Display *dpy, { Screen *screen = _cairo_xlib_screen_from_visual (dpy, visual); - if (screen == NULL) { - _cairo_error_throw (CAIRO_STATUS_INVALID_VISUAL); - return (cairo_surface_t*) &_cairo_surface_nil; - } + if (screen == NULL) + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_VISUAL)); CAIRO_MUTEX_INITIALIZE (); diff --git a/src/cairo.c b/src/cairo.c index 61365975..676aeb1f 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -3323,7 +3323,7 @@ cairo_surface_t * cairo_get_target (cairo_t *cr) { if (cr->status) - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (cr->status); return _cairo_gstate_get_original_target (cr->gstate); } @@ -3352,7 +3352,7 @@ cairo_surface_t * cairo_get_group_target (cairo_t *cr) { if (cr->status) - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (cr->status); return _cairo_gstate_get_target (cr->gstate); } diff --git a/src/cairoint.h b/src/cairoint.h index c2847795..889862df 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -1476,10 +1476,8 @@ _cairo_stroke_style_fini (cairo_stroke_style_t *style); /* cairo-surface.c */ -extern const cairo_private cairo_surface_t _cairo_surface_nil; -extern const cairo_private cairo_surface_t _cairo_surface_nil_read_error; -extern const cairo_private cairo_surface_t _cairo_surface_nil_write_error; -extern const cairo_private cairo_surface_t _cairo_surface_nil_file_not_found; +cairo_private cairo_surface_t * +_cairo_surface_create_in_error (cairo_status_t status); cairo_private cairo_status_t _cairo_surface_set_error (cairo_surface_t *surface, diff --git a/src/test-fallback-surface.c b/src/test-fallback-surface.c index f56db45f..0bac87e0 100644 --- a/src/test-fallback-surface.c +++ b/src/test-fallback-surface.c @@ -76,13 +76,12 @@ _cairo_test_fallback_surface_create (cairo_content_t content, backing = _cairo_image_surface_create_with_content (content, width, height); if (cairo_surface_status (backing)) - return (cairo_surface_t*) &_cairo_surface_nil; + return backing; surface = malloc (sizeof (test_fallback_surface_t)); if (surface == NULL) { cairo_surface_destroy (backing); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } _cairo_surface_init (&surface->base, &test_fallback_surface_backend, diff --git a/src/test-meta-surface.c b/src/test-meta-surface.c index 4c08601e..e56efccc 100644 --- a/src/test-meta-surface.c +++ b/src/test-meta-surface.c @@ -74,21 +74,26 @@ _cairo_test_meta_surface_create (cairo_content_t content, int height) { test_meta_surface_t *surface; + cairo_status_t status; surface = malloc (sizeof (test_meta_surface_t)); - if (surface == NULL) + if (surface == NULL) { + status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto FAIL; + } _cairo_surface_init (&surface->base, &test_meta_surface_backend, content); surface->meta = _cairo_meta_surface_create (content, width, height); - if (cairo_surface_status (surface->meta)) + status = cairo_surface_status (surface->meta); + if (status) goto FAIL_CLEANUP_SURFACE; surface->image = _cairo_image_surface_create_with_content (content, width, height); - if (cairo_surface_status (surface->image)) + status = cairo_surface_status (surface->image); + if (status) goto FAIL_CLEANUP_META; surface->image_reflects_meta = FALSE; @@ -100,8 +105,7 @@ _cairo_test_meta_surface_create (cairo_content_t content, FAIL_CLEANUP_SURFACE: free (surface); FAIL: - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); } static cairo_status_t @@ -309,7 +313,7 @@ _test_meta_surface_snapshot (void *abstract_other) status = _cairo_surface_get_extents (other->image, &extents); if (status) - return (cairo_surface_t*) &_cairo_surface_nil; + return _cairo_surface_create_in_error (status); surface = cairo_surface_create_similar (other->image, CAIRO_CONTENT_COLOR_ALPHA, @@ -319,7 +323,7 @@ _test_meta_surface_snapshot (void *abstract_other) status = _cairo_meta_surface_replay (other->meta, surface); if (status) { cairo_surface_destroy (surface); - surface = (cairo_surface_t*) &_cairo_surface_nil; + surface = _cairo_surface_create_in_error (status); } return surface; diff --git a/src/test-paginated-surface.c b/src/test-paginated-surface.c index 7d341ad7..f640b606 100644 --- a/src/test-paginated-surface.c +++ b/src/test-paginated-surface.c @@ -77,13 +77,12 @@ _cairo_test_paginated_surface_create_for_data (unsigned char *data, stride); status = cairo_surface_status (target); if (status) - return (cairo_surface_t *) &_cairo_surface_nil; + return target; surface = malloc (sizeof (test_paginated_surface_t)); if (surface == NULL) { cairo_surface_destroy (target); - _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); - return (cairo_surface_t *) &_cairo_surface_nil; + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } _cairo_surface_init (&surface->base, &test_paginated_surface_backend, |