Mercurial > cpython-lru_cache-weakref
diff Modules/arraymodule.c @ 55115:a76b34cfc897
Fix array.extend and array.__iadd__ to handle the case where an array
is extended with itself.
This bug is specific the py3k version of arraymodule.c
| author | Alexandre Vassalotti <alexandre@peadrop.com> |
|---|---|
| date | Sun, 05 Jul 2009 06:25:14 +0000 |
| parents | 8e8157445a55 |
| children | 7bb7758e6d64 |
line wrap: on
line diff
--- a/Modules/arraymodule.c Sun Jul 05 05:47:28 2009 +0000 +++ b/Modules/arraymodule.c Sun Jul 05 06:25:14 2009 +0000 @@ -810,8 +810,8 @@ static int array_do_extend(arrayobject *self, PyObject *bb) { - Py_ssize_t size, oldsize; - + Py_ssize_t size, oldsize, bbsize; + if (!array_Check(bb)) return array_iter_extend(self, bb); #define b ((arrayobject *)bb) @@ -826,11 +826,13 @@ return -1; } oldsize = Py_SIZE(self); + /* Get the size of bb before resizing the array since bb could be self. */ + bbsize = Py_SIZE(bb); size = oldsize + Py_SIZE(b); if (array_resize(self, size) == -1) return -1; memcpy(self->ob_item + oldsize * self->ob_descr->itemsize, - b->ob_item, Py_SIZE(b) * b->ob_descr->itemsize); + b->ob_item, bbsize * b->ob_descr->itemsize); return 0; #undef b
