mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-66234: Add flag to disable the use of mmap in dbm.gnu (GH-135005)
This may harm performance, but improve crash tolerance.
This commit is contained in:
parent
44fb7c361c
commit
0cec424af5
5 changed files with 43 additions and 2 deletions
|
@ -74,12 +74,12 @@ class TestGdbm(unittest.TestCase):
|
|||
# Test the flag parameter open() by trying all supported flag modes.
|
||||
all = set(gdbm.open_flags)
|
||||
# Test standard flags (presumably "crwn").
|
||||
modes = all - set('fsu')
|
||||
modes = all - set('fsum')
|
||||
for mode in sorted(modes): # put "c" mode first
|
||||
self.g = gdbm.open(filename, mode)
|
||||
self.g.close()
|
||||
|
||||
# Test additional flags (presumably "fsu").
|
||||
# Test additional flags (presumably "fsum").
|
||||
flags = all - set('crwn')
|
||||
for mode in modes:
|
||||
for flag in flags:
|
||||
|
@ -217,6 +217,29 @@ class TestGdbm(unittest.TestCase):
|
|||
create_empty_file(os.path.join(d, 'test'))
|
||||
self.assertRaises(gdbm.error, gdbm.open, filename, 'r')
|
||||
|
||||
@unittest.skipUnless('m' in gdbm.open_flags, "requires 'm' in open_flags")
|
||||
def test_nommap_no_crash(self):
|
||||
self.g = g = gdbm.open(filename, 'nm')
|
||||
os.truncate(filename, 0)
|
||||
|
||||
g.get(b'a', b'c')
|
||||
g.keys()
|
||||
g.firstkey()
|
||||
g.nextkey(b'a')
|
||||
with self.assertRaises(KeyError):
|
||||
g[b'a']
|
||||
with self.assertRaises(gdbm.error):
|
||||
len(g)
|
||||
|
||||
with self.assertRaises(gdbm.error):
|
||||
g[b'a'] = b'c'
|
||||
with self.assertRaises(gdbm.error):
|
||||
del g[b'a']
|
||||
with self.assertRaises(gdbm.error):
|
||||
g.setdefault(b'a', b'c')
|
||||
with self.assertRaises(gdbm.error):
|
||||
g.reorganize()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue