summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-01-27 05:46:03 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-01-27 05:46:03 (GMT)
commit0ef0423cb2af178022991e9f3bfc276a2c3e1358 (patch)
treedce25256aa3199c9ecf63ecb5a5ba300f57a0a4c /Modules
parentbe59d1489bdf150e05e67a89cc772628af7e8fd6 (diff)
parent3743432302e9b31d4fe0db31485543a306057fc8 (diff)
downloadcpython-0ef0423cb2af178022991e9f3bfc276a2c3e1358.zip
cpython-0ef0423cb2af178022991e9f3bfc276a2c3e1358.tar.gz
cpython-0ef0423cb2af178022991e9f3bfc276a2c3e1358.tar.bz2
merge
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_collectionsmodule.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index b77ea65..69acc64 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1085,10 +1085,17 @@ deque_insert(dequeobject *deque, PyObject *args)
Py_ssize_t index;
Py_ssize_t n = Py_SIZE(deque);
PyObject *value;
+ PyObject *oldvalue;
PyObject *rv;
if (!PyArg_ParseTuple(args, "nO:insert", &index, &value))
return NULL;
+ if (deque->maxlen == Py_SIZE(deque)) {
+ if (index >= deque->maxlen || Py_SIZE(deque) == 0)
+ Py_RETURN_NONE;
+ oldvalue = deque_pop(deque, NULL);
+ Py_DECREF(oldvalue);
+ }
if (index >= n)
return deque_append(deque, value);
if (index <= -n || index == 0)