diff Python/traceback.c @ 1425:72bddfad351a legacy-trunk

* mpzmodule.c: cast some methods to the proper type. * traceback.c (tb_print): use sys.tracebacklimit as a maximum number of traceback entries to print (default 1000). * ceval.c (printtraceback): Don't print stack trace header -- this is now done by tb_print().
author Guido van Rossum <guido@python.org>
date Fri, 17 Dec 1993 12:09:14 +0000
parents 1cabc2b6c970
children 216b755515e6
line wrap: on
line diff
--- a/Python/traceback.c	Thu Dec 16 14:02:44 1993 +0000
+++ b/Python/traceback.c	Fri Dec 17 12:09:14 1993 +0000
@@ -219,14 +219,23 @@
 }
 
 static void
-tb_printinternal(tb, f)
+tb_printinternal(tb, f, limit)
 	tracebackobject *tb;
 	object *f;
+	int limit;
 {
+	int depth = 0;
+	tracebackobject *tb1 = tb;
+	while (tb1 != NULL) {
+		depth++;
+		tb1 = tb1->tb_next;
+	}
 	while (tb != NULL && !intrcheck()) {
-		tb_displayline(f,
-		     getstringvalue(tb->tb_frame->f_code->co_filename),
-							tb->tb_lineno);
+		if (depth <= limit)
+			tb_displayline(f,
+			    getstringvalue(tb->tb_frame->f_code->co_filename),
+			    tb->tb_lineno);
+		depth--;
 		tb = tb->tb_next;
 	}
 }
@@ -236,6 +245,8 @@
 	object *v;
 	object *f;
 {
+	object *limitv;
+	int limit = 1000;
 	if (v == NULL)
 		return 0;
 	if (!is_tracebackobject(v)) {
@@ -243,6 +254,13 @@
 		return -1;
 	}
 	sysset("last_traceback", v);
-	tb_printinternal((tracebackobject *)v, f);
+	limitv = sysget("tracebacklimit");
+	if (limitv && is_intobject(limitv)) {
+		limit = getintvalue(limitv);
+		if (limit <= 0)
+			return 0;
+	}
+	writestring("Traceback (innermost last):\n", f);
+	tb_printinternal((tracebackobject *)v, f, limit);
 	return 0;
 }