char** to {'':('',)}

Ignacio Vazquez-Abrams ignacio at openservices.net
Fri Aug 31 13:27:36 EDT 2001


On Fri, 31 Aug 2001, Tim Peters wrote:

> Ignacio is hung up on a four-letter word, and is thereby doomed to write
> code that's needlessly brittle.  The way goto is used in Python's
> implementation is usually a simple by-hand compilation of the higher-level
> construct (which can't be coded *directly* in C):

Well, I've released this needlessly brittle code, so now you can critique it
in it's entirety:

  http://ignacio.openservices.net/devel/vorbis-0.0a.tar.bz2

Specifically, the code is in the Vorbis_read.getcomments() method.

> It's not the gotos that make this more robust, it's the higher-level
> construct they're *implementing*, and that construct is exactly on-target
> for preventing "stupid mistakes" in letting temps leak, or letting a partial
> result leak in an error case.  If you suffer KFG (Kneejerk Fear of Goto), I
> suppose you could do
>
>     initialize temps and result to NULL
>     int erroneous = 0;
>     do {
>         # normal stuff, but when an error occurs, do
>         erroneous = 1;
>         break;  /* and hope we're breaking out of the 'do'! */
>
>         # more stuff
>
>     } while(0);
>
>     if (erroneous) {
>         Py_XDECREF(result);
>         result = NULL;
>     }
>     Py_XDECREF(temp1);
>     ...
>     Py_XDECREF(tempn);
>     return result;
>
> but that's no improvement by any rational measure ...

Ugh. Returning from within the do as soon as the error occurs would probably
be better anyways.

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list