Commits

Mark Shannon  committed 1290a55 Draft

Fix ref leak in DOC

  • Participants
  • Parent commits 5cf089b

Comments (0)

Files changed (1)

File Python/trace_D_O_C.c

     x->next->comment(x->next, buf);
 }
 
+static char*
+show_item(PyObject *item, char *buf)
+{
+    if (KIND(item) == DK_TUPLE) {
+        PyObject *t = VALUE(item);
+        int i, size = Py_SIZE(t);
+        buf += sprintf(buf, "(");
+        for (i = 0; i < size; i++) {
+            PyObject *x = PyTuple_GET_ITEM(t, i);
+            buf += sprintf(buf, "%s %d, ", kind_names[KIND(x)], INDEX(x));
+        }
+        return buf += sprintf(buf, ") ");
+    }
+    else {
+        return buf += sprintf(buf, "%s %d ", kind_names[KIND(item)], INDEX(item));
+    }
+}
+
 static void
 show_stack(HotPyOptimiser *x)
 {
-    char buf[200];
+    char buf[400];
+    char *out = buf;
     HotPy_DOC *opt = (HotPy_DOC *)x;
     DeferredFrame *f = opt->top_frame;
-    int d = STACK_DEPTH();
-    if (d == 0)
-        sprintf(buf, "Stack: depth=%d", d);
-    else if (d == 1)
-        sprintf(buf, "Stack: depth=%d [ %s %d ]", d,
-                kind_names[KIND(f->stack_pointer[-1])], INDEX(f->stack_pointer[-1]));
-    else if (d == 2)
-        sprintf(buf, "Stack: depth=%d [ %s %d, %s %d ]", d,
-                kind_names[KIND(f->stack_pointer[-2])], INDEX(f->stack_pointer[-2]),
-                kind_names[KIND(f->stack_pointer[-1])], INDEX(f->stack_pointer[-1]));
-    else
-        sprintf(buf, "Stack: depth=%d [ %s%s %d, %s %d, %s %d ]", d,
-                d > 3 ? "... " : "",
-                kind_names[KIND(f->stack_pointer[-3])], INDEX(f->stack_pointer[-3]),
-                kind_names[KIND(f->stack_pointer[-2])], INDEX(f->stack_pointer[-2]),
-                kind_names[KIND(f->stack_pointer[-1])], INDEX(f->stack_pointer[-1]));
-
+    int i, d = STACK_DEPTH();
+    out += sprintf(buf, "Stack: depth=%d", d);
+    if (d > 0) {
+        out += sprintf(out, " [ ");
+        for (i = d; i > 0; i--) {
+            out = show_item(f->stack_pointer[-i], out);
+        }
+        if (d > 3)
+            out += sprintf(out, "... ");
+        out += sprintf(out, " ] ");
+    }
     x->next->comment(x->next, buf);
 }
 
     if (f) {
         PUSH(new_deferred(DK_FRAME, 0, (PyObject *)f));
         SHOW_STACK();
+        Py_DECREF(u);
+        Py_DECREF(v);
+        Py_DECREF(w);
         return;
     }
 fail: