diff -r 913d1fa61398 -r 28bb4daf070c mercurial/parsers.c --- a/mercurial/parsers.c Thu Apr 05 23:52:55 2012 +0900 +++ b/mercurial/parsers.c Fri Apr 06 00:28:36 2012 -0700 @@ -412,6 +412,30 @@ Py_RETURN_NONE; } +static void _index_clearcaches(indexObject *self) +{ + if (self->cache) { + Py_ssize_t i; + + for (i = 0; i < self->raw_length; i++) { + Py_XDECREF(self->cache[i]); + self->cache[i] = NULL; + } + free(self->cache); + self->cache = NULL; + } + if (self->offsets) { + free(self->offsets); + self->offsets = NULL; + } +} + +static PyObject *index_clearcaches(indexObject *self) +{ + _index_clearcaches(self); + Py_RETURN_NONE; +} + static int index_assign_subscript(indexObject *self, PyObject *item, PyObject *value) { @@ -546,15 +570,9 @@ static void index_dealloc(indexObject *self) { + _index_clearcaches(self); Py_DECREF(self->data); - if (self->cache) { - Py_ssize_t i; - - for (i = 0; i < self->raw_length; i++) - Py_XDECREF(self->cache[i]); - } Py_XDECREF(self->added); - free(self->offsets); PyObject_Del(self); } @@ -572,6 +590,8 @@ }; static PyMethodDef index_methods[] = { + {"clearcaches", (PyCFunction)index_clearcaches, METH_NOARGS, + "clear the index caches"}, {"insert", (PyCFunction)index_insert, METH_VARARGS, "insert an index entry"}, {NULL} /* Sentinel */