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

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

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
January 13, 2012 14:11
Subject:
[perl #47948] [documentation] Hash::Util::FieldHash
Message ID:
rt-3.6.HEAD-14510-1326492658-1447.47948-15-0@perl.org
On Thu Jan 12 18:38:38 2012, xdaveg@gmail.com wrote:
> On Thu, Jan 12, 2012 at 9:08 PM, Father Chrysostomos via RT
> <perlbug-followup@perl.org> 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:
> http://blog.plover.com/prog/perl/undefined.html#3
> 
> > 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
details.)

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
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47948

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About