Fix unsafe deletion of a dictionary item during iteration.
authorZac Medico <zmedico@gentoo.org>
Wed, 26 Jul 2006 22:26:55 +0000 (22:26 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 26 Jul 2006 22:26:55 +0000 (22:26 -0000)
svn path=/main/trunk/; revision=4026

pym/portage_util.py

index b1974b543865f97e660081ba689fd5cb40a45fbe..a0385323d52c0960a25d6966975e0e7de2bfaa88 100644 (file)
@@ -166,7 +166,10 @@ def grabdict(myfilename, juststrings=0, empty=0, recursive=0):
 
 def grabdict_package(myfilename, juststrings=0, recursive=0):
        pkgs=grabdict(myfilename, juststrings, empty=1, recursive=recursive)
-       for x in pkgs:
+       # We need to call keys() here in order to avoid the possibility of
+       # "RuntimeError: dictionary changed size during iteration"
+       # when an invalid atom is deleted.
+       for x in pkgs.keys():
                if not isvalidatom(x):
                        del(pkgs[x])
                        writemsg("--- Invalid atom in %s: %s\n" % (myfilename, x),