Commit c6249a62 authored by Raymond Hettinger's avatar Raymond Hettinger

Defer deleted item decref until after the deque is restored to a consistent state.

parent 1dd8e71e
...@@ -45,6 +45,10 @@ Library ...@@ -45,6 +45,10 @@ Library
- Issues #24099, #24100, and #24101: Fix free-after-use bug in heapq's siftup - Issues #24099, #24100, and #24101: Fix free-after-use bug in heapq's siftup
and siftdown functions. and siftdown functions.
- Backport collections.deque fixes from Python 3.5. Prevents reentrant badness
during deletion by deferring the decref until the container has been restored
to a consistent state.
- Issue #23008: Fixed resolving attributes with boolean value is False in pydoc. - Issue #23008: Fixed resolving attributes with boolean value is False in pydoc.
- Fix asyncio issue 235: LifoQueue and PriorityQueue's put didn't - Fix asyncio issue 235: LifoQueue and PriorityQueue's put didn't
......
...@@ -698,9 +698,9 @@ deque_remove(dequeobject *deque, PyObject *value) ...@@ -698,9 +698,9 @@ deque_remove(dequeobject *deque, PyObject *value)
if (cmp > 0) { if (cmp > 0) {
PyObject *tgt = deque_popleft(deque, NULL); PyObject *tgt = deque_popleft(deque, NULL);
assert (tgt != NULL); assert (tgt != NULL);
Py_DECREF(tgt); if (_deque_rotate(deque, i))
if (_deque_rotate(deque, i) == -1)
return NULL; return NULL;
Py_DECREF(tgt);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
else if (cmp < 0) { else if (cmp < 0) {
...@@ -781,16 +781,16 @@ static int ...@@ -781,16 +781,16 @@ static int
deque_del_item(dequeobject *deque, Py_ssize_t i) deque_del_item(dequeobject *deque, Py_ssize_t i)
{ {
PyObject *item; PyObject *item;
int rv;
assert (i >= 0 && i < Py_SIZE(deque)); assert (i >= 0 && i < Py_SIZE(deque));
if (_deque_rotate(deque, -i) == -1) if (_deque_rotate(deque, -i))
return -1; return -1;
item = deque_popleft(deque, NULL); item = deque_popleft(deque, NULL);
rv = _deque_rotate(deque, i);
assert (item != NULL); assert (item != NULL);
Py_DECREF(item); Py_DECREF(item);
return rv;
return _deque_rotate(deque, i);
} }
static int static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment