- Issue #1686386: Tuple's tp_repr did not take into account the possibility of
  having a self-referential tuple, which is possible from C code.  Nor did
  object's tp_str consider that a type's tp_str could do something that could
  lead to an inifinite recursion.  Py_ReprEnter() and Py_EnterRecursiveCall(),
  respectively, fixed the issues.  (Backport of r58288 from trunk to 2.5.)
diff --git a/Objects/object.c b/Objects/object.c
index 71e5641..af7be01 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -403,7 +403,12 @@
 	if (v->ob_type->tp_str == NULL)
 		return PyObject_Repr(v);
 
+	/* It is possible for a type to have a tp_str representation that loops
+	   infinitely. */
+	if (Py_EnterRecursiveCall(" while getting the str of an object"))
+		return NULL;
 	res = (*v->ob_type->tp_str)(v);
+	Py_LeaveRecursiveCall();
 	if (res == NULL)
 		return NULL;
 	type_ok = PyString_Check(res);
@@ -2141,4 +2146,3 @@
 #ifdef __cplusplus
 }
 #endif
-