[Python-checkins] r64471 - in python/trunk: Lib/test/test_cpickle.py Modules/cPickle.c
facundo.batista
python-checkins at python.org
Mon Jun 23 01:20:54 CEST 2008
Author: facundo.batista
Date: Mon Jun 23 01:19:14 2008
New Revision: 64471
Log:
Fixing the problem stated in issue 2702 with the patch submitted
in the issue 3165. Now cPickle does not fails with uncontrolled
behaviour when pickling into a very deep nested structure.
Modified:
python/trunk/Lib/test/test_cpickle.py
python/trunk/Modules/cPickle.c
Modified: python/trunk/Lib/test/test_cpickle.py
==============================================================================
--- python/trunk/Lib/test/test_cpickle.py (original)
+++ python/trunk/Lib/test/test_cpickle.py Mon Jun 23 01:19:14 2008
@@ -1,4 +1,4 @@
-import cPickle
+import cPickle, unittest
from cStringIO import StringIO
from test.pickletester import AbstractPickleTests, AbstractPickleModuleTests
from test import test_support
@@ -90,12 +90,28 @@
b = self.loads(self.dumps(a))
self.assertEqual(a, b)
+class Node(object):
+ pass
+
+class cPickleDeepRecursive(unittest.TestCase):
+ '''Issue 2702. This should raise a RecursionLimit but in some
+ platforms (FreeBSD, win32) sometimes raises KeyError instead,
+ or just silently terminates the interpreter (=crashes).
+ '''
+ def test_deep_recursive(self):
+ nodes = [Node() for i in range(500)]
+ for n in nodes:
+ n.connections = list(nodes)
+ n.connections.remove(n)
+ self.assertRaises(RuntimeError, cPickle.dumps, n)
+
def test_main():
test_support.run_unittest(
cPickleTests,
cPicklePicklerTests,
cPickleListPicklerTests,
- cPickleFastPicklerTests
+ cPickleFastPicklerTests,
+ cPickleDeepRecursive,
)
if __name__ == "__main__":
Modified: python/trunk/Modules/cPickle.c
==============================================================================
--- python/trunk/Modules/cPickle.c (original)
+++ python/trunk/Modules/cPickle.c Mon Jun 23 01:19:14 2008
@@ -1519,6 +1519,7 @@
PyObject *obj;
PyObject *slice[BATCHSIZE];
int i, n;
+ self->nesting++;
static char append = APPEND;
static char appends = APPENDS;
@@ -1658,6 +1659,7 @@
PyObject *p;
PyObject *slice[BATCHSIZE];
int i, n;
+ self->nesting++;
static char setitem = SETITEM;
static char setitems = SETITEMS;
More information about the Python-checkins
mailing list