##// END OF EJS Templates
parsers: fix a memleak, and add a clearcaches method to the index...
Bryan O'Sullivan -
r16370:28bb4daf default
parent child Browse files
Show More
@@ -412,6 +412,30 b' static PyObject *index_insert(indexObjec'
412 Py_RETURN_NONE;
412 Py_RETURN_NONE;
413 }
413 }
414
414
415 static void _index_clearcaches(indexObject *self)
416 {
417 if (self->cache) {
418 Py_ssize_t i;
419
420 for (i = 0; i < self->raw_length; i++) {
421 Py_XDECREF(self->cache[i]);
422 self->cache[i] = NULL;
423 }
424 free(self->cache);
425 self->cache = NULL;
426 }
427 if (self->offsets) {
428 free(self->offsets);
429 self->offsets = NULL;
430 }
431 }
432
433 static PyObject *index_clearcaches(indexObject *self)
434 {
435 _index_clearcaches(self);
436 Py_RETURN_NONE;
437 }
438
415 static int index_assign_subscript(indexObject *self, PyObject *item,
439 static int index_assign_subscript(indexObject *self, PyObject *item,
416 PyObject *value)
440 PyObject *value)
417 {
441 {
@@ -546,15 +570,9 b' static int index_init(indexObject *self,'
546
570
547 static void index_dealloc(indexObject *self)
571 static void index_dealloc(indexObject *self)
548 {
572 {
573 _index_clearcaches(self);
549 Py_DECREF(self->data);
574 Py_DECREF(self->data);
550 if (self->cache) {
551 Py_ssize_t i;
552
553 for (i = 0; i < self->raw_length; i++)
554 Py_XDECREF(self->cache[i]);
555 }
556 Py_XDECREF(self->added);
575 Py_XDECREF(self->added);
557 free(self->offsets);
558 PyObject_Del(self);
576 PyObject_Del(self);
559 }
577 }
560
578
@@ -572,6 +590,8 b' static PyMappingMethods index_mapping_me'
572 };
590 };
573
591
574 static PyMethodDef index_methods[] = {
592 static PyMethodDef index_methods[] = {
593 {"clearcaches", (PyCFunction)index_clearcaches, METH_NOARGS,
594 "clear the index caches"},
575 {"insert", (PyCFunction)index_insert, METH_VARARGS,
595 {"insert", (PyCFunction)index_insert, METH_VARARGS,
576 "insert an index entry"},
596 "insert an index entry"},
577 {NULL} /* Sentinel */
597 {NULL} /* Sentinel */
General Comments 0
You need to be logged in to leave comments. Login now