Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 67a5fdb

Browse files
committed
* 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().
1 parent ad7324c commit 67a5fdb

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

Modules/mpzmodule.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,9 @@ mpz_mpzcoerce(z)
993993
err_setstr(TypeError, "number coercion (to mpzobject) failed");
994994
return NULL;
995995
} /* mpz_mpzcoerce() */
996-
996+
997+
static void mpz_divm();
998+
997999
static object *
9981000
MPZ_powm(self, args)
9991001
object *self;
@@ -1181,7 +1183,7 @@ MPZ_sqrtrem(self, args)
11811183
} /* MPZ_sqrtrem() */
11821184

11831185

1184-
void
1186+
static void
11851187
#if __STDC__
11861188
mpz_divm(MP_INT *res, const MP_INT *num, const MP_INT *den, const MP_INT *mod)
11871189
#else
@@ -1544,7 +1546,7 @@ static struct methodlist mpz_methods[] = {
15441546
{"hex", mpz_hex},
15451547
{"oct", mpz_oct},
15461548
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
1547-
{"binary", mpz_binary},
1549+
{"binary", (object * (*) (object *, object *)) mpz_binary},
15481550
{NULL, NULL} /* sentinel */
15491551
};
15501552

@@ -1639,11 +1641,11 @@ static typeobject MPZtype = {
16391641
sizeof(mpzobject), /*tp_size*/
16401642
0, /*tp_itemsize*/
16411643
/* methods */
1642-
mpz_dealloc, /*tp_dealloc*/
1644+
(void (*) (object *)) mpz_dealloc, /*tp_dealloc*/
16431645
0, /*tp_print*/
1644-
mpz_getattr, /*tp_getattr*/
1646+
(object * (*)(object *, char *)) mpz_getattr, /*tp_getattr*/
16451647
0, /*tp_setattr*/
1646-
mpz_compare, /*tp_compare*/
1648+
(int (*) (object *, object *)) mpz_compare, /*tp_compare*/
16471649
mpz_repr, /*tp_repr*/
16481650
&mpz_as_number, /*tp_as_number*/
16491651
};

Python/ceval.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,6 @@ printtraceback(f)
17101710
{
17111711
object *v = tb_fetch();
17121712
if (v != NULL) {
1713-
writestring("Stack backtrace (innermost last):\n", f);
17141713
tb_print(v, f);
17151714
DECREF(v);
17161715
}

Python/traceback.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,23 @@ tb_displayline(f, filename, lineno)
219219
}
220220

221221
static void
222-
tb_printinternal(tb, f)
222+
tb_printinternal(tb, f, limit)
223223
tracebackobject *tb;
224224
object *f;
225+
int limit;
225226
{
227+
int depth = 0;
228+
tracebackobject *tb1 = tb;
229+
while (tb1 != NULL) {
230+
depth++;
231+
tb1 = tb1->tb_next;
232+
}
226233
while (tb != NULL && !intrcheck()) {
227-
tb_displayline(f,
228-
getstringvalue(tb->tb_frame->f_code->co_filename),
229-
tb->tb_lineno);
234+
if (depth <= limit)
235+
tb_displayline(f,
236+
getstringvalue(tb->tb_frame->f_code->co_filename),
237+
tb->tb_lineno);
238+
depth--;
230239
tb = tb->tb_next;
231240
}
232241
}
@@ -236,13 +245,22 @@ tb_print(v, f)
236245
object *v;
237246
object *f;
238247
{
248+
object *limitv;
249+
int limit = 1000;
239250
if (v == NULL)
240251
return 0;
241252
if (!is_tracebackobject(v)) {
242253
err_badcall();
243254
return -1;
244255
}
245256
sysset("last_traceback", v);
246-
tb_printinternal((tracebackobject *)v, f);
257+
limitv = sysget("tracebacklimit");
258+
if (limitv && is_intobject(limitv)) {
259+
limit = getintvalue(limitv);
260+
if (limit <= 0)
261+
return 0;
262+
}
263+
writestring("Traceback (innermost last):\n", f);
264+
tb_printinternal((tracebackobject *)v, f, limit);
247265
return 0;
248266
}

0 commit comments

Comments
 (0)