Index: Modules/cPickle.c =================================================================== --- Modules/cPickle.c (revision 64527) +++ Modules/cPickle.c (working copy) @@ -1630,7 +1630,9 @@ iter = PyObject_GetIter(args); if (iter == NULL) goto finally; + self->nesting++; res = batch_list(self, iter); + self->nesting--; Py_DECREF(iter); finally: @@ -1786,7 +1788,9 @@ iter = PyObject_CallMethod(args, "iteritems", "()"); if (iter == NULL) goto finally; + self->nesting++; res = batch_dict(self, iter); + self->nesting--; Py_DECREF(iter); finally: Index: Lib/test/test_cpickle.py =================================================================== --- Lib/test/test_cpickle.py (revision 64527) +++ Lib/test/test_cpickle.py (working copy) @@ -96,21 +96,19 @@ class cPickleDeepRecursive(unittest.TestCase): # I commented out, because the patch that fixes this was reverted, as # it broke the next test case. Check the issues for full history. -# def test_issue2702(self): -# '''This should raise a RecursionLimit but in some -# platforms (FreeBSD, win32) sometimes raises KeyError instead, -# or just silently terminates the interpreter (=crashes). -# ''' -# 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_issue2702(self): + # This should raise a RecursionLimit but in some + # platforms (FreeBSD, win32) sometimes raises KeyError instead, + # or just silently terminates the interpreter (=crashes). + 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_issue3179(self): - '''Safe test, because of I broken this case when fixing the - behaviour for the previous test. - ''' + # Safe test, because I broke this case when fixing the + # behaviour for the previous test. res=[] for x in range(1,2000): res.append(dict(doc=x, similar=[]))