New submission from Raymond Hettinger <raymond.hettin...@gmail.com>:

A dialog on python-dev suggests that dict.setdefault() was intended to be 
atomic and that a number of experienced developers have deployed code relying 
on its atomicity:  
http://mail.python.org/pipermail/python-3000/2007-July/008693.html

The actual implementation shows a second call to PyDict_Setitem() which can 
call PyObject_Hash() which can call arbitrary Python code.   
http://hg.python.org/cpython/file/2.7/Objects/dictobject.c#l1937

This fix is straight-forward, use the results of the initial lookup to insert 
the default object.  This will make the operation atomic and it will make it 
faster.

----------
components: Interpreter Core
messages: 148782
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Make dict.setdefault() atomic
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13521>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to