summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-07-17 23:01:39 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-07-17 23:01:39 (GMT)
commit82a6bf049e2ccceb99e9288440ffffad77bf9e90 (patch)
treee017932277b114c8f83fa95c1ae95d8092fda626 /Modules
parent6fd1df8c44dd986d1ba6458c9583dacda4255180 (diff)
downloadcpython-82a6bf049e2ccceb99e9288440ffffad77bf9e90.zip
cpython-82a6bf049e2ccceb99e9288440ffffad77bf9e90.tar.gz
cpython-82a6bf049e2ccceb99e9288440ffffad77bf9e90.tar.bz2
Merged revisions 82937 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82937 | alexander.belopolsky | 2010-07-17 18:50:45 -0400 (Sat, 17 Jul 2010) | 3 lines Issue #5180: Fixed a bug that prevented loading 2.x pickles in 3.x python when they contain instances of old-style classes. ........
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_pickle.c38
1 files changed, 14 insertions, 24 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 0e1c2cd..96f194e 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -3466,29 +3466,19 @@ load_dict(UnpicklerObject *self)
static PyObject *
instantiate(PyObject *cls, PyObject *args)
{
- PyObject *r = NULL;
-
- /* XXX: The pickle.py module does not create instances this way when the
- args tuple is empty. See Unpickler._instantiate(). */
- if ((r = PyObject_CallObject(cls, args)))
- return r;
-
- /* XXX: Is this still nescessary? */
- {
- PyObject *tp, *v, *tb, *tmp_value;
-
- PyErr_Fetch(&tp, &v, &tb);
- tmp_value = v;
- /* NULL occurs when there was a KeyboardInterrupt */
- if (tmp_value == NULL)
- tmp_value = Py_None;
- if ((r = PyTuple_Pack(3, tmp_value, cls, args))) {
- Py_XDECREF(v);
- v = r;
- }
- PyErr_Restore(tp, v, tb);
+ PyObject *result = NULL;
+ /* Caller must assure args are a tuple. Normally, args come from
+ Pdata_poptuple which packs objects from the top of the stack
+ into a newly created tuple. */
+ assert(PyTuple_Check(args));
+ if (Py_SIZE(args) > 0 || !PyType_Check(cls) ||
+ PyObject_HasAttrString(cls, "__getinitargs__")) {
+ result = PyObject_CallObject(cls, args);
}
- return NULL;
+ else {
+ result = PyObject_CallMethod(cls, "__new__", "O", cls);
+ }
+ return result;
}
static int
@@ -3547,7 +3537,7 @@ load_inst(UnpicklerObject *self)
if (len < 2)
return bad_readline();
class_name = PyUnicode_DecodeASCII(s, len - 1, "strict");
- if (class_name == NULL) {
+ if (class_name != NULL) {
cls = find_class(self, module_name, class_name);
Py_DECREF(class_name);
}
@@ -4276,7 +4266,7 @@ load_reduce(UnpicklerObject *self)
return -1;
PDATA_POP(self->stack, callable);
if (callable) {
- obj = instantiate(callable, argtup);
+ obj = PyObject_CallObject(callable, argtup);
Py_DECREF(callable);
}
Py_DECREF(argtup);