From d50f9c4d135c2101786fcf6158427ef6990d07a2 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 6 Nov 2007 18:50:54 +0100 Subject: [PATCH] added tp_traverse to _speedups module --HG-- branch : trunk --- jinja/_speedups.c | 23 +++++++++++++++++++++-- jinja/datastructure.py | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/jinja/_speedups.c b/jinja/_speedups.c index c3ee18e..f205300 100644 --- a/jinja/_speedups.c +++ b/jinja/_speedups.c @@ -75,6 +75,25 @@ BaseContext_dealloc(BaseContext *self) self->ob_type->tp_free((PyObject*)self); } +/** + * GC Helper + */ +static int +BaseContext_traverse(BaseContext *self, visitproc visit, void *args) +{ + int vret; + struct StackLayer *layer = self->current; + + while (layer) { + vret = visit(layer->dict, args); + if (vret != 0) + return vret; + layer = layer->prev; + } + + return 0; +} + /** * Initializes the BaseContext. * @@ -387,7 +406,7 @@ static PySequenceMethods BaseContext_as_sequence[] = { 0, /* sq_slice */ 0, /* sq_ass_item */ 0, /* sq_ass_slice */ - (objobjproc)BaseContext_contains, /* sq_contains */ + (objobjproc)BaseContext_contains,/* sq_contains */ 0, /* sq_inplace_concat */ 0 /* sq_inplace_repeat */ }; @@ -421,7 +440,7 @@ static PyTypeObject BaseContextType = { 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ "", /* tp_doc */ - 0, /* tp_traverse */ + BaseContext_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ diff --git a/jinja/datastructure.py b/jinja/datastructure.py index 2408dd0..56e07b3 100644 --- a/jinja/datastructure.py +++ b/jinja/datastructure.py @@ -314,6 +314,8 @@ class Context(BaseContext): return 'Context(%r)' % self.to_dict() def __pretty__(self, p, cycle): + if cycle: + return p.text('Context({...})') p.begin_group(9, 'Context({') for idx, (key, value) in enumerate(self.to_dict().iteritems()): if idx: -- 2.26.2