Re: g_slist_foreach and g_list_foreach functions
- From: Darin Adler <darin eazel com>
- To: "Kuykendall, PR Paul (8807)" <KUYKENDAPR raytheon com>, "'gtk-devel-list gnome org'" <gtk-devel-list gnome org>
- Cc: "Ray, TD Travis (8878)" <RAYTD raytheon com>
- Subject: Re: g_slist_foreach and g_list_foreach functions
- Date: Wed, 13 Sep 2000 12:18:48 -0700
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]