[cairo] Error checking in language bindings

chris nuernberger cnuernber at gmail.com
Fri Dec 14 10:29:14 PST 2007


It seems to me that the error checking should be automatic in the
bindings itself.  Why should you write this repeated
call..if..call..if pattern if the language supports exceptions?  That
looks to me like a waste of time.  And checking it in the bindings
itself should be quicker than the scripting language doing the same
thing in script land.

Chris

On Dec 14, 2007 11:17 AM, Carl Worth <cworth at cworth.org> wrote:
> [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.
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>



-- 
The major difference between a thing that might go wrong and a thing
that cannot possibly go wrong is that when a thing that cannot
possibly go wrong goes wrong it usually turns out to be impossible to
get at and repair - Douglas Adams


More information about the cairo mailing list