summaryrefslogtreecommitdiffstats
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorŽiga Seilnacht <ziga.seilnacht@gmail.com>2007-03-15 11:44:55 (GMT)
committerŽiga Seilnacht <ziga.seilnacht@gmail.com>2007-03-15 11:44:55 (GMT)
commit20f43d3018e3ff474f761d1a03c18cec3291042b (patch)
treeccbf1abbe0648b419b1f6d88975764b998802bea /Lib/test/pickletester.py
parentab1f4674ad14eb1430489a458c7654aa1ac9c51e (diff)
downloadcpython-20f43d3018e3ff474f761d1a03c18cec3291042b.zip
cpython-20f43d3018e3ff474f761d1a03c18cec3291042b.tar.gz
cpython-20f43d3018e3ff474f761d1a03c18cec3291042b.tar.bz2
Patch #1462488: prevent a segfault in object_reduce_ex() by splitting
the implementation for __reduce__ and __reduce_ex__ into two separate functions. Fixes bug #931877. Will backport.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 5b9da56..e1bc078 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -831,6 +831,24 @@ class AbstractPickleTests(unittest.TestCase):
y = self.loads(s)
self.assertEqual(y._proto, None)
+ def test_reduce_ex_calls_base(self):
+ for proto in 0, 1, 2:
+ x = REX_four()
+ self.assertEqual(x._proto, None)
+ s = self.dumps(x, proto)
+ self.assertEqual(x._proto, proto)
+ y = self.loads(s)
+ self.assertEqual(y._proto, proto)
+
+ def test_reduce_calls_base(self):
+ for proto in 0, 1, 2:
+ x = REX_five()
+ self.assertEqual(x._reduce_called, 0)
+ s = self.dumps(x, proto)
+ self.assertEqual(x._reduce_called, 1)
+ y = self.loads(s)
+ self.assertEqual(y._reduce_called, 1)
+
# Test classes for reduce_ex
class REX_one(object):
@@ -855,6 +873,20 @@ class REX_three(object):
def __reduce__(self):
raise TestFailed, "This __reduce__ shouldn't be called"
+class REX_four(object):
+ _proto = None
+ def __reduce_ex__(self, proto):
+ self._proto = proto
+ return object.__reduce_ex__(self, proto)
+ # Calling base class method should succeed
+
+class REX_five(object):
+ _reduce_called = 0
+ def __reduce__(self):
+ self._reduce_called = 1
+ return object.__reduce__(self)
+ # This one used to fail with infinite recursion
+
# Test classes for newobj
class MyInt(int):