[libvirt] [libvirt-glib] Prefer 'for' over 'while'

Christophe Fergeau cfergeau at redhat.com
Thu Jan 26 15:09:52 UTC 2012


On Thu, Jan 26, 2012 at 05:05:15PM +0200, Zeeshan Ali (Khattak) wrote:
> On Thu, Jan 26, 2012 at 11:19 AM, Christophe Fergeau
> <cfergeau at redhat.com> wrote:
> > On Thu, Jan 26, 2012 at 08:18:38AM +0100, Philipp Hahn wrote:
> >> Your changed version only has the same behaviour, if the user-passed-in
> >> function iter_func() never changes it->next, which you can't guarentee here.
> >> You need to keep the "next" copy.
> >
> > Yes, the for loop was changed to a while loop recently exactly for that
> > purpose:
> 
> I don't get it, your commit clearly introduced a hang in Boxes and my
> change fixes it back while also simplifying the code slightly. So I
> don't at all buy the 'while' being more 'reliable'.

The callback gets passed 'it', and the callback used in
gvir_config_object_delete_child can unlink/free 'it', so things won't work
as expected if you try to get it->next after calling the callback. Using a
while loop and getting it->next before calling the callback avoids this
problem.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120126/db2fcaff/attachment-0001.sig>


More information about the libvir-list mailing list