[issue11350] __setitem__()'s problem of dbm.dumb object pointed out by comments

Ray.Allen report at bugs.python.org
Wed Mar 2 05:28:52 CET 2011


Ray.Allen <ysj.ray at gmail.com> added the comment:

Here is a test case.

First here is a patch which implements a simple builtin function "abort()" that calls exit(0) directly, it simulates the cases that Py_FatalError occurred or segment fault.

Then run the following:

import dbm.dumb as dumb

db = dumb.open('test_db', 'c')
db.clear()
db['a'] = 'a'
db.sync()
db['a'] = 'aa'
abort()


Now the database 'test_db' is corrupt because .dat file and .dir file are out of sync:

db = dumb.open('test_db', 'c')
print(db['a'])
db.close()

prints:
b'a'

But the value of key 'a' in .dat file are: 'aa':
cat test_db.dat
aa

----------
keywords: +patch
Added file: http://bugs.python.org/file20969/builtin_abort.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11350>
_______________________________________


More information about the Python-bugs-list mailing list