Re: g_slist_foreach and g_list_foreach functions



on 9/13/00 12:00 PM, Kuykendall, PR Paul (8807) at KUYKENDAPR raytheon com
wrote:

> I ran across a situation where the g_*list_foreach() functions quit
> processing before finishing through the list.
> 
> In the case of a function being called by g_*list_foreach() that removes the
> current list element (via g_slist_remove() ), processing stops, due to the
> node being freed.  The small fix below seems to fix that problem, with a
> minimal of effort.  Sorry it isn't in diff format, but my that machine isn't
> networked.
> 
> Any reason why this type of fix couldn't be added?

Your fix replaces one kind of anomaly (can't remove current element) with
another kind of anomaly (can't remove subsequent element). So it's not a
good idea to make this change -- it can break existing programs.

When you need to make changes to the list as you go, you can

    1) write the iterating loop yourself -- that's what we do in some places
in Nautilus
    2) make your own foreach that does what you suggested -- that's what we
do in other places in Nautilus
    3) make your own foreach that makes a copy of the list -- this is even
safer, but more costly

    -- Darin





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]