Christian Heimes avatar Christian Heimes committed 565012d

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.

Comments (0)

Files changed (1)

Python/traceback.c

 	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)) {
 		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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.