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

Re: dangerous hash usage?

From: Benjamin Pflugmann <benjamin-svn-dev_at_pflugmann.de>
Date: 2003-09-25 09:26:27 CEST

On Wed 2003-09-24 at 23:37:00 +0100, Julian Foad wrote:
> Ben Collins-Sussman wrote:
> >Ben Collins-Sussman <sussman@collab.net> writes:
> >
> >>Working on #1075, I noticed this:
> >>
> >>I see code in svn which loops over an apr_hash_t, yet code within the
> >>loop potentially removes an item from the hash. Isn't this
> >>dangrerous? Can't this mess up the hash iterator (apr_hash_index_t)?
> >>
> >>In particular, I'm looking at libsvn_wc/adm_ops.c:121.
> >
> >Hm, I shoulda checked the APR docs. They say:
> >
> > * @remark There is no restriction on adding or deleting hash entries
> > during
> > * an iteration (although the results may be unpredictable unless all you
> > do
> > * is delete the current entry) and multiple iterations can be in
> > * progress at the same time.
>
> That's a confusing @remark. I would suggest it be changed to one of these
> if one of these is correct:
>
> * @remark During an iteration it is safe to delete the current hash entry,
> * but not to delete any other entry or to add an entry.
> * Multiple iterations may be in progress at the same time if none of them
> * adds or deletes hash entries.
>
> * @remark During an iteration it is safe to delete the current hash entry,
> * and to add entries.
> * Multiple iterations may be in progress at the same time if none of them
> * deletes hash entries.

May I join? May I join? *jumps around* :-)

> I.e. the remark should say what is guaranteed to be safe, not "you may do
> this but the results may be unpredictable".

My reading is a bit different. There are two kinds of possible "safe"
here, IMHO. Whether it is safe in a "don't do bad stuff" sense,
i.e. you get no dangling pointers or such. And whether it is safe
regarding the algorithm ("predictable"), i.e. if the items-before and
items-after lists stay the same.

My reading of the comment is: adding or deleting entries during an
iteration will not do bad stuff, but it is undefined what is in the
"items to come" list, except if all you do is deleting the current
entry.
Or in other words: asking for the next items afterwards, is guaranteed
to return a valid item (or maybe list-end), but it is not defined,
which item, except blabla...

Regards,

        Benjamin.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Sep 25 09:28:29 2003

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.