summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-05-02 17:44:17 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-05-02 17:44:17 (GMT)
commitc6249a6268ed4f191c01b28fa5c04417454d6625 (patch)
treefd8b9b9f2a191510bc1a0360ebeb2e7552cb52b1 /Modules/_collectionsmodule.c
parent1dd8e71eb3207a841844ee35520b0e5b458916db (diff)
downloadcpython-c6249a6268ed4f191c01b28fa5c04417454d6625.zip
cpython-c6249a6268ed4f191c01b28fa5c04417454d6625.tar.gz
cpython-c6249a6268ed4f191c01b28fa5c04417454d6625.tar.bz2
Defer deleted item decref until after the deque is restored to a consistent state.
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index c1aa9a3..627fad5 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -698,9 +698,9 @@ deque_remove(dequeobject *deque, PyObject *value)
if (cmp > 0) {
PyObject *tgt = deque_popleft(deque, NULL);
assert (tgt != NULL);
- Py_DECREF(tgt);
- if (_deque_rotate(deque, i) == -1)
+ if (_deque_rotate(deque, i))
return NULL;
+ Py_DECREF(tgt);
Py_RETURN_NONE;
}
else if (cmp < 0) {
@@ -781,16 +781,16 @@ static int
deque_del_item(dequeobject *deque, Py_ssize_t i)
{
PyObject *item;
+ int rv;
assert (i >= 0 && i < Py_SIZE(deque));
- if (_deque_rotate(deque, -i) == -1)
+ if (_deque_rotate(deque, -i))
return -1;
-
item = deque_popleft(deque, NULL);
+ rv = _deque_rotate(deque, i);
assert (item != NULL);
Py_DECREF(item);
-
- return _deque_rotate(deque, i);
+ return rv;
}
static int