Re: Possible GHashTable bug?



Derek Simkowiak <dereks realloc net> writes:

> 	What happens is this: The first entity is found with no problem
> (and subsequently removed), but by the time I look up the second
> entity--after removing the first entity--the foreach() calls
> 'unref_entity' with garbage.
> 
> 	In short: Calling g_hash_table_remove() from within a
> g_hash_table_foreach() causes the next iteration of your GHFunc to get
> called with a garbage value.
> 
> 	I'm guessing there's a missing freeze/thaw in
> g_hash_table_foreach()....?
> 
> 	In any event, using g_hash_table_foreach_remove() and turning
> 'unref_entity' into a GHRFunc that returns TRUE solved my problem.  If
> anybody's interested I can put together a simplified demo program and post
> it.

Not a bug, that's the way it works. Trying to handle modifications
from a "foreach" function is quite hard and likely slows things down
significantly.

Freeze/thaw has been removed in Glib-2.0 - but if we still had it,
(internally at least) could we use it to make removal of the currently
iterated element safe? Yes, probably. Not beyond that however,
so you'd have to be careful about what happened in response
to your foreach function in any case.

Regards,
                                        Owen




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