[cairo-bugs] [Bug 14495] 'cairo_restore()' doesn't restore context in error case

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Fri Feb 15 01:06:57 PST 2008


--- Comment #2 from Iosif Haidu <iosif.haidu at gmail.com>  2008-02-15 01:06:50 PST ---
(In reply to comment #1)
> If those errors are not fatal, then cairo should be fixed.  What you propose
> however is against the design of cairo.  Moreover, when an object goes into an
> error state, all bets are off, the internal state of the object may not be
> consistent anymore.  It's hard to return it back to a sane state.

Well, actually the internal state of the cairo device context has nothing wrong
after one of the windows gdi functions returns with error. 
But let's analyse for a while the meaning of those two cairo functions:
'cairo_save()' and 'cairo_restore()'.
The first one will save a given cairo context on an internal stack while the
second one restore it. Now, shouldn't these two functions provide a transaction
like functionality ? And we know that the final result of any transaction is to
return to a stable state (even if commit or rollback has been issued). But this
doesn't happen with the 'cairo_restore()' function. It doesn't restore
(rollback) the previous state if something wrong happens between. And it
shouldn't be like that. If I would save the state of a variable on an internal
stack I expect also to restore it if something goes wrong between (otherwise
what's the point of those two functions ?).
Also the cairo documentation doesn't specifiy that 'cairo_restore()' will not
restore the previous cairo context if an error occurs between 'cairo_save()'
and 'cairo_restore()'.

Regarding clearing the error code in 'cairo_restore()': it's not necessary to
propagate the error code generated between 'cairo_save()' and 'cairo_restore()'
after the execution of 'cairo_restore()', because the developer can check in
any point for an error situation between these two functions. The
'cairo_restore()' should set the error code only if it's not able to restore
the previous context. If in some cases is necessary for 'cairo_restore()' to
indicate that an error occured between, then probably it shold return that
error code as result but internally should reset it, otherwise next time a new
'cairo_save()' - 'cairo_rstore()' block is executed, it will exit without
executing anything.
You could also let the developer to reset the error code, but then you must
provide a way to do it (currently there is no access to cairo context status
field and there is no method to reset the error code).
Recreating the cairo context in an error situation could be a solution but it's
not elegant. Why should I recreate a cairo context if there is nothing wrong
with it ?

Best regards,
Iosif Haidu

Configure bugmail: http://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the cairo-bugs mailing list