[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn_stream_copy3() in svn_io.h

From: Stefan Sperling <stsp_at_elego.de>
Date: Wed, 8 Apr 2009 12:02:04 +0100

On Wed, Apr 08, 2009 at 12:35:42PM +0800, Edmund Wong wrote:
> Greg Stein wrote:
> >
> > Proper use of goto can greatly simplify a function. Bending over
> > backwards to create if/else sequences or flags or whatever... just in
> > order to note "cleanup" status ... can be much more complicated than a
> > simple goto.
>
> Then I'll need to rethink my patch then because it does use quite
> a bit of if ... else ... constructs. It probably might look better
> with gotos.

You'll find the same pattern in countless operating system
device driver initialisation routines, because they often
have to allocate multiple resources, and each allocation can fail.

        m1 = allocate_some_memory();
        if (m1 == NULL)
                return FAILURE;

        irq = register_interrupt();
        if (irq == NULL)
                goto fail1;
        
        m2 = allocate_some_more_memory();
        if (m2 == NULL)
                goto fail2;

        ...

        return SUCCESS;

fail2:
        unregister_interrupt(irq);
fail1:
        free_memory(m1);

        return FAILURE;

Stefan
Received on 2009-04-08 13:02:30 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.