[cairo] Better error return for cairo_pdf_surface_create

Nick Wellnhofer wellnhofer at aevum.de
Sun Jan 21 17:24:57 PST 2007


It seems that you can call cairo_surface_finish when you're done and 
then retrieve the surface status to check for this kind of errors.

Nick


Behdad Esfahbod wrote:
> On Sat, 2007-01-20 at 15:15 -0500, Nick Wellnhofer wrote:
>> Currently, cairo_pdf_surface_create always returns 
>> CAIRO_STATUS_NO_MEMORY if an error occurs. The attached patch makes it 
>> possible to distinguish at least between memory and file related errors.
> 
> There's also:
> 
>   https://bugs.freedesktop.org/show_bug.cgi?id=7049
> 
> that is about the status returned by stream write function being
> ignored.  Now fixing that one is harder because you may not get to know
> that there is an error condition until the last _destroy() on the
> surface.  Which leaves the case of changing return type of _destroy()
> functions from void to cairo_status_t.  Alas, Vlad has another proposal
> (hint, hint) to change the return type to int, returning the remaining
> ref counts...
> 
> behdad
> 
> 
>> Nick
>>
>> plain text document attachment (cairo-pdf-surface-error-return.diff)
>> --- mozilla-cvs/gfx/cairo/cairo/src/cairo-pdf-surface.c	2006-12-23 02:15:53.000000000 +0100
>> +++ mozilla/gfx/cairo/cairo/src/cairo-pdf-surface.c	2007-01-20 19:28:20.125237000 +0100
>> @@ -376,7 +376,15 @@ cairo_pdf_surface_create (const char		*f
>>      status = _cairo_output_stream_get_status (output);
>>      if (status) {
>>  	_cairo_error (status);
>> -	return (cairo_surface_t*) &_cairo_surface_nil;
>> +        switch (status) {
>> +        case CAIRO_STATUS_READ_ERROR:
>> +	    return (cairo_surface_t*) &_cairo_surface_nil_read_error;
>> +        case CAIRO_STATUS_WRITE_ERROR:
>> +        case CAIRO_STATUS_FILE_NOT_FOUND:
>> +	    return (cairo_surface_t*) &_cairo_surface_nil_file_not_found;
>> +        default:
>> +	    return (cairo_surface_t*) &_cairo_surface_nil;
>> +        }
>>      }
>>  
>>      return _cairo_pdf_surface_create_for_stream_internal (output,
>> _______________________________________________
>> cairo mailing list
>> cairo at cairographics.org
>> http://cairographics.org/cgi-bin/mailman/listinfo/cairo


More information about the cairo mailing list