summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-12-04 21:55:18 (GMT)
committerChristian Heimes <christian@cheimes.de>2007-12-04 21:55:18 (GMT)
commit0fbab7ff8d2efd92e222fcc13c0aff0998c3c158 (patch)
treed778d9b9c8bcc2b7486f36faa2b388459d2dafb5 /Python
parent3267f8725a9ce338b331ee083a09d4ce12384fc2 (diff)
downloadcpython-0fbab7ff8d2efd92e222fcc13c0aff0998c3c158.zip
cpython-0fbab7ff8d2efd92e222fcc13c0aff0998c3c158.tar.gz
cpython-0fbab7ff8d2efd92e222fcc13c0aff0998c3c158.tar.bz2
Removed another occurrence of PyInt_ExactCheck()
I've modified the semantic of PyTraceBack_Print and sys.tracebacklimit slightly. Overfloats or values <= 0 are replaced with a default value to avoid infinite recursion and other issues.
Diffstat (limited to 'Python')
-rw-r--r--Python/traceback.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/Python/traceback.c b/Python/traceback.c
index df2a3a3..1a4ec1f 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -242,12 +242,15 @@ tb_printinternal(PyTracebackObject *tb, PyObject *f, int limit)
return err;
}
+#define PyTraceBack_LIMIT 1000
+
int
PyTraceBack_Print(PyObject *v, PyObject *f)
{
int err;
PyObject *limitv;
- int limit = 1000;
+ int limit = PyTraceBack_LIMIT;
+
if (v == NULL)
return 0;
if (!PyTraceBack_Check(v)) {
@@ -255,10 +258,26 @@ PyTraceBack_Print(PyObject *v, PyObject *f)
return -1;
}
limitv = PySys_GetObject("tracebacklimit");
- if (limitv && PyInt_CheckExact(limitv)) {
+ if (limitv) {
+ PyObject *exc_type, *exc_value, *exc_tb;
+
+ PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
limit = PyLong_AsLong(limitv);
- if (limit <= 0)
- return 0;
+ if (limit == -1 && PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
+ limit = PyTraceBack_LIMIT;
+ }
+ else {
+ Py_XDECREF(exc_type);
+ Py_XDECREF(exc_value);
+ Py_XDECREF(exc_tb);
+ return 0;
+ }
+ }
+ else if (limit <= 0) {
+ limit = PyTraceBack_LIMIT;
+ }
+ PyErr_Restore(exc_type, exc_value, exc_tb);
}
err = PyFile_WriteString("Traceback (most recent call last):\n", f);
if (!err)