develooper Front page | perl.perl5.porters | Postings from January 2012

[perl #47948] [documentation] Hash::Util::FieldHash

Thread Previous | Thread Next
Father Chrysostomos via RT
January 13, 2012 14:11
[perl #47948] [documentation] Hash::Util::FieldHash
Message ID:
On Thu Jan 12 18:38:38 2012, wrote:
> On Thu, Jan 12, 2012 at 9:08 PM, Father Chrysostomos via RT
> <> wrote:
> > My question is: Why is it unsafe at all to create or delete things from
> > a hash that is being iterated?
> Here is the relevant MJD post, I think:
> > There have been at least three fixes to the deletion code since 5.14.
> > Could it have anything to do with those?
> MJD looks like it was legacy Larry code that had the problem.
> I think it's all to avoid requiring two passes.
> Should it be (now or in the future) safe to delete arbitrary keys
> during iteration, then the same would apply to inside-out object
> destruction.

It has been safe, for as long as I’ve been familiar with the code,
except for two fairly obscure bugs, which are now fixed.  (In one case,
keys() on a empty hash would not reset the iterator after the last item
was deleted during iteration; in the other, deleting the current
iterator could leak memory in certain cases, but I don’t remember the

Now (and previously, most of the time), deleting an element will just
stop it from being iterated over if it has not already been iterated
over.  An element added during iteration may or may not be iterated over
in the current iteration.


Father Chrysostomos

via perlbug:  queue: perl5 status: open

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About