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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:`collections.deque` no longer suppresses :exc:`MemoryError` in certain cases.
21 changes: 11 additions & 10 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,11 @@ struct dequeobject {

static inline block *
newblock(dequeobject *deque) {
block *b;
if (deque->numfreeblocks) {
deque->numfreeblocks--;
return deque->freeblocks[deque->numfreeblocks];
}
b = PyMem_Malloc(sizeof(block));
if (b != NULL) {
return b;
}
PyErr_NoMemory();
return NULL;
return PyMem_Malloc(sizeof(block));
}

static inline void
Expand All @@ -212,6 +206,7 @@ deque_new(PyTypeObject *type, PyObject *args, PyObject *kwds)

b = newblock(deque);
if (b == NULL) {
PyErr_NoMemory();
Py_DECREF(deque);
return NULL;
}
Expand Down Expand Up @@ -343,6 +338,7 @@ deque_append_lock_held(dequeobject *deque, PyObject *item, Py_ssize_t maxlen)
if (deque->rightindex == BLOCKLEN - 1) {
block *b = newblock(deque);
if (b == NULL) {
PyErr_NoMemory();
Py_DECREF(item);
return -1;
}
Expand Down Expand Up @@ -392,6 +388,7 @@ deque_appendleft_lock_held(dequeobject *deque, PyObject *item,
if (deque->leftindex == 0) {
block *b = newblock(deque);
if (b == NULL) {
PyErr_NoMemory();
Py_DECREF(item);
return -1;
}
Expand Down Expand Up @@ -746,7 +743,6 @@ deque_clear(PyObject *self)

b = newblock(deque);
if (b == NULL) {
PyErr_Clear();
goto alternate_method;
}

Expand Down Expand Up @@ -857,6 +853,7 @@ deque_inplace_repeat_impl(dequeobject *deque, Py_ssize_t n)
if (deque->rightindex == BLOCKLEN - 1) {
block *b = newblock(deque);
if (b == NULL) {
PyErr_NoMemory();
Py_SET_SIZE(deque, Py_SIZE(deque) + i);
return NULL;
}
Expand Down Expand Up @@ -977,8 +974,10 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
if (leftindex == 0) {
if (b == NULL) {
b = newblock(deque);
if (b == NULL)
if (b == NULL) {
PyErr_NoMemory();
goto done;
}
}
b->rightlink = leftblock;
CHECK_END(leftblock->leftlink);
Expand Down Expand Up @@ -1021,8 +1020,10 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
if (rightindex == BLOCKLEN - 1) {
if (b == NULL) {
b = newblock(deque);
if (b == NULL)
if (b == NULL) {
PyErr_NoMemory();
goto done;
}
}
b->leftlink = rightblock;
CHECK_END(rightblock->rightlink);
Expand Down
Loading