Staging
v0.5.1
https://github.com/python/cpython
Revision a4dd011259fa6f3079bd0efd95b3a136c0e3c190 authored by Guido van Rossum on 15 April 2001, 22:16:26 UTC, committed by Guido van Rossum on 15 April 2001, 22:16:26 UTC
and reported to python-dev: because we were calling dict_resize() in
PyDict_Next(), and because GC's dict_traverse() uses PyDict_Next(),
and because PyTuple_New() can cause GC, and because dict_items() calls
PyTuple_New(), it was possible for dict_items() to have the dict
resized right under its nose.

The solution is convoluted, and touches several places: keys(),
values(), items(), popitem(), PyDict_Next(), and PyDict_SetItem().

There are two parts to it. First, we no longer call dict_resize() in
PyDict_Next(), which seems to solve the immediate problem.  But then
PyDict_SetItem() must have a different policy about when *it* calls
dict_resize(), because we want to guarantee (e.g. for an algorithm
that Jeremy uses in the compiler) that you can loop over a dict using
PyDict_Next() and make changes to the dict as long as those changes
are only value replacements for existing keys using PyDict_SetItem().
This is done by resizing *after* the insertion instead of before, and
by remembering the size before we insert the item, and if the size is
still the same, we don't bother to even check if we might need to
resize.  An additional detail is that if the dict starts out empty, we
must still resize it before the insertion.

That was the first part. :-)

The second part is to make keys(), values(), items(), and popitem()
safe against side effects on the dict caused by allocations, under the
assumption that if the GC can cause arbitrary Python code to run, it
can cause other threads to run, and it's not inconceivable that our
dict could be resized -- it would be insane to write code that relies
on this, but not all code is sane.

Now, I have this nagging feeling that the loops in lookdict probably
are blissfully assuming that doing a simple key comparison does not
change the dict's size.  This is not necessarily true (the keys could
be class instances after all).  But that's a battle for another day.
1 parent 0aa30b0
History
Tip revision: a4dd011259fa6f3079bd0efd95b3a136c0e3c190 authored by Guido van Rossum on 15 April 2001, 22:16:26 UTC
Tentative fix for a problem that Tim discovered at the last moment,
Tip revision: a4dd011
File Mode Size
compiler
curses
distutils
encodings
idlelib
lib-old
lib-tk
plat-aix3
plat-aix4
plat-beos5
plat-freebsd2
plat-freebsd3
plat-freebsd4
plat-freebsd5
plat-generic
plat-irix5
plat-irix6
plat-linux1
plat-linux2
plat-netbsd1
plat-next3
plat-riscos
plat-sunos4
plat-sunos5
plat-unixware7
site-packages
test
xml
BaseHTTPServer.py -rw-r--r-- 16.0 KB
Bastion.py -rw-r--r-- 5.4 KB
CGIHTTPServer.py -rw-r--r-- 9.9 KB
ConfigParser.py -rw-r--r-- 16.8 KB
Cookie.py -rw-r--r-- 24.3 KB
MimeWriter.py -rw-r--r-- 3.7 KB
Queue.py -rw-r--r-- 3.8 KB
SimpleHTTPServer.py -rw-r--r-- 6.2 KB
SocketServer.py -rw-r--r-- 17.0 KB
StringIO.py -rw-r--r-- 6.0 KB
TERMIOS.py -rw-r--r-- 416 bytes
UserDict.py -rw-r--r-- 1.5 KB
UserList.py -rw-r--r-- 3.4 KB
UserString.py -rwxr-xr-x 7.4 KB
__future__.py -rw-r--r-- 2.1 KB
aifc.py -rw-r--r-- 32.6 KB
anydbm.py -rw-r--r-- 2.6 KB
asynchat.py -rw-r--r-- 10.4 KB
asyncore.py -rw-r--r-- 16.3 KB
atexit.py -rw-r--r-- 1.3 KB
audiodev.py -rw-r--r-- 7.2 KB
base64.py -rwxr-xr-x 2.0 KB
bdb.py -rw-r--r-- 17.7 KB
binhex.py -rw-r--r-- 14.7 KB
bisect.py -rw-r--r-- 2.1 KB
builtin.py -rwxr-xr-x 140 bytes
calendar.py -rw-r--r-- 7.1 KB
cgi.py -rwxr-xr-x 31.8 KB
chunk.py -rw-r--r-- 5.2 KB
cmd.py -rw-r--r-- 6.6 KB
code.py -rw-r--r-- 9.8 KB
codecs.py -rw-r--r-- 17.4 KB
codeop.py -rw-r--r-- 2.8 KB
colorsys.py -rw-r--r-- 3.1 KB
commands.py -rw-r--r-- 2.2 KB
compileall.py -rw-r--r-- 4.2 KB
copy.py -rw-r--r-- 8.1 KB
copy_reg.py -rw-r--r-- 1000 bytes
dbhash.py -rw-r--r-- 400 bytes
difflib.py -rw-r--r-- 28.5 KB
dircache.py -rw-r--r-- 1.1 KB
dis.py -rw-r--r-- 8.7 KB
doctest.py -rw-r--r-- 35.7 KB
dospath.py -rw-r--r-- 9.4 KB
dumbdbm.py -rw-r--r-- 4.1 KB
filecmp.py -rw-r--r-- 10.1 KB
fileinput.py -rw-r--r-- 9.7 KB
fnmatch.py -rw-r--r-- 2.4 KB
formatter.py -rw-r--r-- 13.7 KB
fpformat.py -rw-r--r-- 4.5 KB
ftplib.py -rw-r--r-- 23.8 KB
getopt.py -rw-r--r-- 5.1 KB
getpass.py -rw-r--r-- 2.8 KB
gettext.py -rw-r--r-- 9.4 KB
glob.py -rw-r--r-- 1.4 KB
gopherlib.py -rw-r--r-- 5.5 KB
gzip.py -rw-r--r-- 11.7 KB
htmlentitydefs.py -rw-r--r-- 19.1 KB
htmllib.py -rw-r--r-- 10.4 KB
httplib.py -rw-r--r-- 27.2 KB
ihooks.py -rw-r--r-- 16.7 KB
imaplib.py -rw-r--r-- 33.2 KB
imghdr.py -rw-r--r-- 3.3 KB
imputil.py -rw-r--r-- 24.4 KB
inspect.py -rw-r--r-- 26.1 KB
keyword.py -rwxr-xr-x 2.0 KB
knee.py -rw-r--r-- 3.4 KB
linecache.py -rw-r--r-- 2.3 KB
locale.py -rw-r--r-- 27.5 KB
macpath.py -rw-r--r-- 5.9 KB
macstat.py -rwxr-xr-x 1.5 KB
macurl2path.py -rw-r--r-- 3.0 KB
mailbox.py -rwxr-xr-x 8.8 KB
mailcap.py -rw-r--r-- 7.3 KB
mhlib.py -rw-r--r-- 32.5 KB
mimetools.py -rw-r--r-- 6.3 KB
mimetypes.py -rw-r--r-- 7.2 KB
mimify.py -rwxr-xr-x 14.6 KB
multifile.py -rw-r--r-- 4.7 KB
mutex.py -rw-r--r-- 1.7 KB
netrc.py -rw-r--r-- 4.1 KB
nntplib.py -rw-r--r-- 17.7 KB
ntpath.py -rw-r--r-- 12.6 KB
nturl2path.py -rw-r--r-- 2.0 KB
os.py -rw-r--r-- 17.0 KB
pdb.doc -rw-r--r-- 7.3 KB
pdb.py -rwxr-xr-x 29.5 KB
persist.py -rwxr-xr-x 7.6 KB
pickle.py -rw-r--r-- 25.9 KB
pipes.py -rw-r--r-- 9.7 KB
popen2.py -rw-r--r-- 6.6 KB
poplib.py -rw-r--r-- 8.8 KB
posixfile.py -rw-r--r-- 7.5 KB
posixpath.py -rw-r--r-- 10.9 KB
pprint.py -rw-r--r-- 8.3 KB
pre.py -rw-r--r-- 23.5 KB
profile.doc -rw-r--r-- 27.7 KB
profile.py -rwxr-xr-x 20.2 KB
pstats.py -rw-r--r-- 22.2 KB
pty.py -rw-r--r-- 4.2 KB
py_compile.py -rw-r--r-- 2.9 KB
pyclbr.py -rw-r--r-- 11.3 KB
pydoc.py -rwxr-xr-x 74.1 KB
quopri.py -rwxr-xr-x 4.2 KB
random.py -rw-r--r-- 21.3 KB
re.py -rw-r--r-- 817 bytes
reconvert.py -rwxr-xr-x 5.1 KB
regex_syntax.py -rw-r--r-- 1.8 KB
regsub.py -rw-r--r-- 6.1 KB
repr.py -rw-r--r-- 3.1 KB
rexec.py -rw-r--r-- 12.7 KB
rfc822.py -rw-r--r-- 30.5 KB
rlcompleter.py -rw-r--r-- 4.0 KB
robotparser.py -rw-r--r-- 9.2 KB
sched.py -rw-r--r-- 4.0 KB
sgmllib.py -rw-r--r-- 17.0 KB
shelve.py -rw-r--r-- 4.4 KB
shlex.py -rw-r--r-- 7.6 KB
shutil.py -rw-r--r-- 3.8 KB
site.py -rw-r--r-- 8.7 KB
smtpd.py -rwxr-xr-x 17.1 KB
smtplib.py -rwxr-xr-x 18.1 KB
sndhdr.py -rw-r--r-- 5.8 KB
socket.py -rw-r--r-- 7.4 KB
sre.py -rw-r--r-- 8.0 KB
sre_compile.py -rw-r--r-- 11.5 KB
sre_constants.py -rw-r--r-- 6.8 KB
sre_parse.py -rw-r--r-- 23.8 KB
stat.py -rw-r--r-- 1.6 KB
statcache.py -rw-r--r-- 2.3 KB
statvfs.py -rw-r--r-- 779 bytes
string.py -rw-r--r-- 10.7 KB
stringold.py -rw-r--r-- 12.1 KB
sunau.py -rw-r--r-- 16.1 KB
sunaudio.py -rw-r--r-- 1.2 KB
symbol.py -rwxr-xr-x 1.6 KB
symtable.py -rw-r--r-- 7.3 KB
tabnanny.py -rwxr-xr-x 12.2 KB
telnetlib.py -rw-r--r-- 15.1 KB
tempfile.py -rw-r--r-- 6.2 KB
threading.py -rw-r--r-- 17.6 KB
toaiff.py -rw-r--r-- 2.9 KB
token.py -rwxr-xr-x 2.8 KB
tokenize.py -rw-r--r-- 10.0 KB
traceback.py -rw-r--r-- 10.3 KB
tty.py -rw-r--r-- 879 bytes
types.py -rw-r--r-- 1.3 KB
tzparse.py -rw-r--r-- 3.4 KB
unittest.py -rw-r--r-- 24.3 KB
urllib.py -rw-r--r-- 46.5 KB
urllib2.py -rw-r--r-- 36.6 KB
urlparse.py -rw-r--r-- 8.5 KB
user.py -rw-r--r-- 1.4 KB
uu.py -rwxr-xr-x 5.5 KB
warnings.py -rw-r--r-- 7.9 KB
wave.py -rw-r--r-- 17.3 KB
weakref.py -rw-r--r-- 4.3 KB
webbrowser.py -rw-r--r-- 11.3 KB
whichdb.py -rw-r--r-- 2.0 KB
whrandom.py -rw-r--r-- 4.7 KB
xdrlib.py -rw-r--r-- 7.1 KB
xmllib.py -rw-r--r-- 34.1 KB
zipfile.py -rw-r--r-- 23.3 KB

back to top