[Python-checkins] r88147 - in python/branches/py3k: Misc/NEWS Modules/_pickle.c Tools/scripts/find_recursionlimit.py

antoine.pitrou python-checkins at python.org
Sun Jan 23 18:12:26 CET 2011


Author: antoine.pitrou
Date: Sun Jan 23 18:12:25 2011
New Revision: 88147

Log:
Issue #10987: Fix the recursion limit handling in the _pickle module.



Modified:
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/_pickle.c
   python/branches/py3k/Tools/scripts/find_recursionlimit.py

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sun Jan 23 18:12:25 2011
@@ -16,6 +16,8 @@
 Library
 -------
 
+- Issue #10987: Fix the recursion limit handling in the _pickle module.
+
 - Issue #10983: Fix several bugs making tunnel requests in http.client.
 
 - Issue #10955: zipimport uses ASCII encoding instead of cp437 to decode

Modified: python/branches/py3k/Modules/_pickle.c
==============================================================================
--- python/branches/py3k/Modules/_pickle.c	(original)
+++ python/branches/py3k/Modules/_pickle.c	Sun Jan 23 18:12:25 2011
@@ -2244,19 +2244,21 @@
     if (len != 0) {
         /* Materialize the list elements. */
         if (PyList_CheckExact(obj) && self->proto > 0) {
-            if (Py_EnterRecursiveCall(" while pickling an object") == 0) {
-                status = batch_list_exact(self, obj);
-                Py_LeaveRecursiveCall();
-            }
+            if (Py_EnterRecursiveCall(" while pickling an object"))
+                goto error;
+            status = batch_list_exact(self, obj);
+            Py_LeaveRecursiveCall();
         } else {
             PyObject *iter = PyObject_GetIter(obj);
             if (iter == NULL)
                 goto error;
 
-            if (Py_EnterRecursiveCall(" while pickling an object") == 0) {
-                status = batch_list(self, iter);
-                Py_LeaveRecursiveCall();
+            if (Py_EnterRecursiveCall(" while pickling an object")) {
+                Py_DECREF(iter);
+                goto error;
             }
+            status = batch_list(self, iter);
+            Py_LeaveRecursiveCall();
             Py_DECREF(iter);
         }
     }
@@ -2504,10 +2506,10 @@
         if (PyDict_CheckExact(obj) && self->proto > 0) {
             /* We can take certain shortcuts if we know this is a dict and
                not a dict subclass. */
-            if (Py_EnterRecursiveCall(" while pickling an object") == 0) {
-                status = batch_dict_exact(self, obj);
-                Py_LeaveRecursiveCall();
-            }
+            if (Py_EnterRecursiveCall(" while pickling an object"))
+                goto error;
+            status = batch_dict_exact(self, obj);
+            Py_LeaveRecursiveCall();
         } else {
             items = PyObject_CallMethod(obj, "items", "()");
             if (items == NULL)
@@ -2516,7 +2518,12 @@
             Py_DECREF(items);
             if (iter == NULL)
                 goto error;
+            if (Py_EnterRecursiveCall(" while pickling an object")) {
+                Py_DECREF(iter);
+                goto error;
+            }
             status = batch_dict(self, iter);
+            Py_LeaveRecursiveCall();
             Py_DECREF(iter);
         }
     }
@@ -3044,7 +3051,7 @@
     PyObject *reduce_value = NULL;
     int status = 0;
 
-    if (Py_EnterRecursiveCall(" while pickling an object") < 0)
+    if (Py_EnterRecursiveCall(" while pickling an object"))
         return -1;
 
     /* The extra pers_save argument is necessary to avoid calling save_pers()

Modified: python/branches/py3k/Tools/scripts/find_recursionlimit.py
==============================================================================
--- python/branches/py3k/Tools/scripts/find_recursionlimit.py	(original)
+++ python/branches/py3k/Tools/scripts/find_recursionlimit.py	Sun Jan 23 18:12:25 2011
@@ -77,14 +77,15 @@
     except ImportError:
         print("cannot import _pickle, skipped!")
         return
-    l = None
+    k, l = None, None
     for n in itertools.count():
         try:
             l = _cache[n]
             continue  # Already tried and it works, let's save some time
         except KeyError:
             for i in range(100):
-                l = [l]
+                l = [k, l]
+                k = {i: l}
         _pickle.Pickler(io.BytesIO(), protocol=-1).dump(l)
         _cache[n] = l
 


More information about the Python-checkins mailing list