Commit 0f2a61a1 authored by Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 88147 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r88147 | antoine.pitrou | 2011-01-23 18:12:25 +0100 (dim., 23 janv. 2011) | 3 lines

  Issue #10987: Fix the recursion limit handling in the _pickle module.
........
parent eb9d5ad6
...@@ -37,6 +37,8 @@ Core and Builtins ...@@ -37,6 +37,8 @@ Core and Builtins
Library Library
------- -------
- Issue #10987: Fix the recursion limit handling in the _pickle module.
- Issue #10949: Improved robustness of rotating file handlers. - Issue #10949: Improved robustness of rotating file handlers.
- Issue #10955: Fix a potential crash when trying to mmap() a file past its - Issue #10955: Fix a potential crash when trying to mmap() a file past its
......
...@@ -1566,7 +1566,12 @@ save_list(PicklerObject *self, PyObject *obj) ...@@ -1566,7 +1566,12 @@ save_list(PicklerObject *self, PyObject *obj)
iter = PyObject_GetIter(obj); iter = PyObject_GetIter(obj);
if (iter == NULL) if (iter == NULL)
goto error; goto error;
if (Py_EnterRecursiveCall(" while pickling an object")) {
Py_DECREF(iter);
goto error;
}
status = batch_list(self, iter); status = batch_list(self, iter);
Py_LeaveRecursiveCall();
Py_DECREF(iter); Py_DECREF(iter);
} }
...@@ -1814,10 +1819,10 @@ save_dict(PicklerObject *self, PyObject *obj) ...@@ -1814,10 +1819,10 @@ save_dict(PicklerObject *self, PyObject *obj)
if (PyDict_CheckExact(obj) && self->proto > 0) { if (PyDict_CheckExact(obj) && self->proto > 0) {
/* We can take certain shortcuts if we know this is a dict and /* We can take certain shortcuts if we know this is a dict and
not a dict subclass. */ not a dict subclass. */
if (Py_EnterRecursiveCall(" while pickling an object") == 0) { if (Py_EnterRecursiveCall(" while pickling an object"))
status = batch_dict_exact(self, obj); goto error;
Py_LeaveRecursiveCall(); status = batch_dict_exact(self, obj);
} Py_LeaveRecursiveCall();
} else { } else {
items = PyObject_CallMethod(obj, "items", "()"); items = PyObject_CallMethod(obj, "items", "()");
if (items == NULL) if (items == NULL)
...@@ -1826,7 +1831,12 @@ save_dict(PicklerObject *self, PyObject *obj) ...@@ -1826,7 +1831,12 @@ save_dict(PicklerObject *self, PyObject *obj)
Py_DECREF(items); Py_DECREF(items);
if (iter == NULL) if (iter == NULL)
goto error; goto error;
if (Py_EnterRecursiveCall(" while pickling an object")) {
Py_DECREF(iter);
goto error;
}
status = batch_dict(self, iter); status = batch_dict(self, iter);
Py_LeaveRecursiveCall();
Py_DECREF(iter); Py_DECREF(iter);
} }
} }
...@@ -2353,7 +2363,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) ...@@ -2353,7 +2363,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
PyObject *memo_key = NULL; PyObject *memo_key = NULL;
int status = 0; int status = 0;
if (Py_EnterRecursiveCall(" while pickling an object") < 0) if (Py_EnterRecursiveCall(" while pickling an object"))
return -1; return -1;
/* The extra pers_save argument is necessary to avoid calling save_pers() /* The extra pers_save argument is necessary to avoid calling save_pers()
......
...@@ -77,14 +77,15 @@ def test_cpickle(_cache={}): ...@@ -77,14 +77,15 @@ def test_cpickle(_cache={}):
except ImportError: except ImportError:
print("cannot import _pickle, skipped!") print("cannot import _pickle, skipped!")
return return
l = None k, l = None, None
for n in itertools.count(): for n in itertools.count():
try: try:
l = _cache[n] l = _cache[n]
continue # Already tried and it works, let's save some time continue # Already tried and it works, let's save some time
except KeyError: except KeyError:
for i in range(100): for i in range(100):
l = [l] l = [k, l]
k = {i: l}
_pickle.Pickler(io.BytesIO(), protocol=-1).dump(l) _pickle.Pickler(io.BytesIO(), protocol=-1).dump(l)
_cache[n] = l _cache[n] = l
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment