Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,18 @@ def test_copy_noncompact(self):
d2 = d.copy()
self.assertEqual(d2, d)

@support.nomemtest
def test_copy_empty_no_memory(self):
import _testcapi
d = {}
d_copy = d.copy
with self.assertRaises(MemoryError):
try:
_testcapi.set_nomemory(0)
d_copy()
finally:
_testcapi.remove_mem_hooks()

def test_get(self):
d = {}
self.assertIs(d.get('c'), None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in a debug build when copying an empty :class:`dict` fails with
:exc:`MemoryError`. Patch by Christian Aurich Zanettini Martins.
2 changes: 1 addition & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4448,7 +4448,7 @@ copy_lock_held_untracked(PyObject *o, int as_frozendict)
else {
d = dict_new_untracked(&PyDict_Type);
}
assert(!_PyObject_GC_IS_TRACKED(d));
assert(d == NULL || !_PyObject_GC_IS_TRACKED(d));
return d;
}

Expand Down
Loading