[Python-Dev] Nested scopes core dump

Jeremy Hylton jeremy@alum.mit.edu
Mon, 19 Mar 2001 18:48:42 -0500 (EST)


>>>>> "MH" == Michael Hudson <mwh21@cam.ac.uk> writes:

  MH> Jeremy Hylton <jeremy@alum.mit.edu> writes:
  >> >>>>> "MWH" == Michael Hudson <mwh21@cam.ac.uk> writes:
  >>
  MWH> [*] I thought that if you used the same keys when you were
  MWH> iterating over a dict you were safe.  It seems not, at least as
  MWH> far as I could tell with mounds of debugging printf's.
  >>
  >> I did, too.  Anyone know what the problems is?

  MH> The dict's resizing, it turns out.

So a hack to make the iteration safe would be to assign and element
and then delete it?

  MH> I note that in PyDict_SetItem, the check to see if the dict
  MH> needs resizing occurs *before* it is known whether the key is
  MH> already in the dict.  But if this is the problem, how come we
  MH> haven't been bitten by this before?

It's probably unusual for a dictionary to be in this state when the
compiler decides to update the values.

Jeremy