comparison Modules/arraymodule.c @ 29163:2bb5ceef9ac3 legacy-trunk

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.
author Walter Dörwald <walter@livinglogic.de>
date Sun, 18 May 2003 03:15:10 +0000
parents 22d177682ae1
children 23ad8b5d7b4a
comparison
equal deleted inserted replaced
29162:384bda343725 29163:2bb5ceef9ac3
468 NRESIZE(items, char, (self->ob_size+1) * self->ob_descr->itemsize); 468 NRESIZE(items, char, (self->ob_size+1) * self->ob_descr->itemsize);
469 if (items == NULL) { 469 if (items == NULL) {
470 PyErr_NoMemory(); 470 PyErr_NoMemory();
471 return -1; 471 return -1;
472 } 472 }
473 if (where < 0) 473 if (where < 0) {
474 where = 0; 474 where += self->ob_size;
475 if (where < 0)
476 where = 0;
477 }
475 if (where > self->ob_size) 478 if (where > self->ob_size)
476 where = self->ob_size; 479 where = self->ob_size;
477 memmove(items + (where+1)*self->ob_descr->itemsize, 480 memmove(items + (where+1)*self->ob_descr->itemsize,
478 items + where*self->ob_descr->itemsize, 481 items + where*self->ob_descr->itemsize,
479 (self->ob_size-where)*self->ob_descr->itemsize); 482 (self->ob_size-where)*self->ob_descr->itemsize);