summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-07-15 19:17:14 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-07-15 19:17:14 (GMT)
commitff35050493edd0c738ab69f14ee2fb5db11bb5ec (patch)
tree68dcbb0f2be971f3d24f47505681ad6af6deef5b
parent8391cf4e1d73683795e51ac5ce8ee9e61eea389d (diff)
parent8cdc40e3b0622ea4eeb8b2c9b0e6796be685d16d (diff)
downloadcpython-ff35050493edd0c738ab69f14ee2fb5db11bb5ec.zip
cpython-ff35050493edd0c738ab69f14ee2fb5db11bb5ec.tar.gz
cpython-ff35050493edd0c738ab69f14ee2fb5db11bb5ec.tar.bz2
Issue #11603: Fix a crash when __str__ is rebound as __repr__.
Patch by Andreas Stührk.
-rw-r--r--Lib/test/test_descr.py8
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/typeobject.c2
3 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index e90e0b9..587d792 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4252,6 +4252,14 @@ order (MRO) for bases """
with self.assertRaises(TypeError):
str.__add__(fake_str, "abc")
+ def test_repr_as_str(self):
+ # Issue #11603: crash or infinite loop when rebinding __str__ as
+ # __repr__.
+ class Foo:
+ pass
+ Foo.__repr__ = Foo.__str__
+ foo = Foo()
+ str(foo)
class DictProxyTests(unittest.TestCase):
def setUp(self):
diff --git a/Misc/NEWS b/Misc/NEWS
index 2154393..fdf4498 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@ Core and Builtins
Library
-------
+- Issue #11603: Fix a crash when __str__ is rebound as __repr__. Patch by
+ Andreas Stührk.
+
- Issue #11321: Fix a crash with multiple imports of the _pickle module when
embedding Python. Patch by Andreas Stührk.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 97ccf01..97a94a7 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2890,7 +2890,7 @@ object_str(PyObject *self)
unaryfunc f;
f = Py_TYPE(self)->tp_repr;
- if (f == NULL)
+ if (f == NULL || f == object_str)
f = object_repr;
return f(self);
}