From 9f3e2f6163ba7aaca807d0d1ff1f5e32356f65b9 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 6 Nov 2007 19:16:12 +0100 Subject: [PATCH] BaseContext should be garbage collected properly now --HG-- branch : trunk --- jinja/_speedups.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/jinja/_speedups.c b/jinja/_speedups.c index dfabf1d..eba129b 100644 --- a/jinja/_speedups.c +++ b/jinja/_speedups.c @@ -57,12 +57,10 @@ init_constants(void) } /** - * Deallocator for BaseContext. - * - * Frees the memory for the stack layers before freeing the object. + * GC Helper */ -static void -BaseContext_dealloc(BaseContext *self) +static int +BaseContext_clear(BaseContext *self) { struct StackLayer *current = self->current, *tmp; while (current) { @@ -72,6 +70,18 @@ BaseContext_dealloc(BaseContext *self) current = tmp->prev; PyMem_Free(tmp); } + return 0; +} + +/** + * Deallocator for BaseContext. + * + * Frees the memory for the stack layers before freeing the object. + */ +static void +BaseContext_dealloc(BaseContext *self) +{ + BaseContext_clear(self); self->ob_type->tp_free((PyObject*)self); } @@ -438,10 +448,11 @@ static PyTypeObject BaseContextType = { 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, + /*tp_flags*/ "", /* tp_doc */ (traverseproc)BaseContext_traverse, /* tp_traverse */ - 0, /* tp_clear */ + (inquiry)BaseContext_clear, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ -- 2.26.2