[cairo] Error checking in language bindings
Carl Worth
cworth at cworth.org
Fri Dec 14 10:17:17 PST 2007
[Repeating some of what Owen said for emphasis.]
On Fri, 14 Dec 2007 10:33:42 +0900, Steven Chaplin wrote:
> This was originally necessary to stop making cairo calls as soon as a
> cairo context or surface went into an error state, to prevent the
> binding crashing with a segmentation fault or other similar fatal
> error.
I _think_ that misstates history. The cairo error-handling strategy is
really quite old, and I'm quite sure it predates the existing of
python bindings.
> Would it be better to strip out all the error checking and exception
> raising and allow the programmer to decide when to check the error
> status, like you do in C?
No, I don't think so. I consider cairo's error-handling in C to be a
workaround (a pretty clever workaround I think[*]) for the fact that C
doesn't have anything nice like exceptions. If you're working with a
language that *does* have exceptions, then doesn't that already give
you a nice flexible way to decide when to deal with the errors?
So I think it's definitely best for a language binding that can to
check all error status values and raise exceptions.
> I think using cairo-style error checking and being able to call smaller
> and faster drawing operations is something than many graphics
> application programmers would prefer.
What's smaller and faster here? Avoiding "if (cairo_status (cr)):
raise" on each function call? Isn't that kind of overhead in the same
ballpark as using python bindings for C functions in the first place?
Or do you have measurements to show there would be a benefit here?
-Carl
[*] And I can say this since this was all Keith's idea originally, not
mine.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071214/2a237387/attachment.pgp
More information about the cairo
mailing list