Skip to content
Open
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
17 changes: 17 additions & 0 deletions Lib/test/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from test.support.import_helper import import_fresh_module
import types
import unittest
import _testcapi

from collections import namedtuple, Counter, OrderedDict, _count_elements
from collections import UserDict, UserString, UserList
Expand Down Expand Up @@ -2475,6 +2476,22 @@ def test_symmetric_difference(self):
pp ^= qq
self.assertEqual(pp, r)

################################################################################
### Deque
################################################################################

class TestDeque(unittest.TestCase):

def test_deque_oom(self):
for n in range(1, 80):
d = deque(range(200))
_testcapi.set_nomemory(n, 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are too troublesome so we generally avoid them (e.g., _testcapi is not always available or when Py_TRACE_REFS is set it conflicts).

try:
d.copy()
_testcapi.remove_mem_hooks()
break
except MemoryError:
_testcapi.remove_mem_hooks()

def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite(collections))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:`collections.deque` no longer suppresses :exc:`MemoryError` in certain cases.
3 changes: 2 additions & 1 deletion Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,10 @@ deque_clear(PyObject *self)
adversary could cause it to never terminate).
*/

PyObject *old_exc = PyErr_GetRaisedException();
b = newblock(deque);
PyErr_SetRaisedException(old_exc);
if (b == NULL) {
PyErr_Clear();
goto alternate_method;
}

Expand Down
Loading