diff options
author | Walter Dörwald <walter@livinglogic.de> | 2003-05-18 03:15:10 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2003-05-18 03:15:10 (GMT) |
commit | 9e46abed5061729915ed39d7bb8c4d014369380e (patch) | |
tree | cffba6082397e0470ed2d2e90fd5babf9b654289 /Modules | |
parent | df0d87a922ea29f7a410e8b634ae8730caa4438e (diff) | |
download | cpython-9e46abed5061729915ed39d7bb8c4d014369380e.zip cpython-9e46abed5061729915ed39d7bb8c4d014369380e.tar.gz cpython-9e46abed5061729915ed39d7bb8c4d014369380e.tar.bz2 |
Fix array.array.insert(), so that it treats negative indices as
being relative to the end of the array, just like list.insert() does.
This closes SF bug #739313.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/arraymodule.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index c03160e..dcb66cf 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -470,8 +470,11 @@ ins1(arrayobject *self, int where, PyObject *v) PyErr_NoMemory(); return -1; } - if (where < 0) - where = 0; + if (where < 0) { + where += self->ob_size; + if (where < 0) + where = 0; + } if (where > self->ob_size) where = self->ob_size; memmove(items + (where+1)*self->ob_descr->itemsize, |