[Python-3000-checkins] r59335 - python/branches/py3k/Python/traceback.c
christian.heimes
python-3000-checkins at python.org
Tue Dec 4 22:55:19 CET 2007
Author: christian.heimes
Date: Tue Dec 4 22:55:18 2007
New Revision: 59335
Modified:
python/branches/py3k/Python/traceback.c
Log:
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.
Modified: python/branches/py3k/Python/traceback.c
==============================================================================
--- python/branches/py3k/Python/traceback.c (original)
+++ python/branches/py3k/Python/traceback.c Tue Dec 4 22:55:18 2007
@@ -242,12 +242,15 @@
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 @@
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)
More information about the Python-3000-checkins
mailing list