added tp_traverse to _speedups module
authorArmin Ronacher <armin.ronacher@active-4.com>
Tue, 6 Nov 2007 17:50:54 +0000 (18:50 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Tue, 6 Nov 2007 17:50:54 +0000 (18:50 +0100)
--HG--
branch : trunk

jinja/_speedups.c
jinja/datastructure.py

index c3ee18ed323599e00e6b86e45b7df78ddea58353..f20530065f874363dde5fe8c932b86cb7d89ba90 100644 (file)
@@ -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 */
index 2408dd05fca0974ae9d03d58ee0596fc850374cf..56e07b3eb408258af2acf00a025787b3c6104207 100644 (file)
@@ -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: