From: Serhiy Storchaka Date: Fri, 25 Dec 2015 19:05:35 +0000 (+0200) Subject: Issue #22995: Instances of extension types with a state that aren't X-Git-Tag: v3.6.0a1~865 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9253c96fdff3ae1fcdacc72c06632f41df0424c;p=python Issue #22995: Instances of extension types with a state that aren't subclasses of list or dict and haven't implemented any pickle-related methods (__reduce__, __reduce_ex__, __getnewargs__, __getnewargs_ex__, or __getstate__), can no longer be pickled. Including memoryview. --- f9253c96fdff3ae1fcdacc72c06632f41df0424c diff --cc Objects/typeobject.c index 2e75ec378d,f3c0c38ee6..4fac9e889b --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@@ -4157,9 -4169,9 +4177,9 @@@ reduce_newobj(PyObject *obj Py_INCREF(v); PyTuple_SET_ITEM(newargs, i+1, v); } - Py_DECREF(args); + Py_XDECREF(args); } - else if (proto >= 4) { + else { _Py_IDENTIFIER(__newobj_ex__); newobj = _PyObject_GetAttrId(copyreg, &PyId___newobj_ex__); @@@ -4177,8 -4189,19 +4197,9 @@@ return NULL; } } - else { - PyErr_SetString(PyExc_ValueError, - "must use protocol 4 or greater to copy this " - "object; since __getnewargs_ex__ returned " - "keyword arguments."); - Py_DECREF(args); - Py_DECREF(kwargs); - Py_DECREF(copyreg); - return NULL; - } - state = _PyObject_GetState(obj); + state = _PyObject_GetState(obj, + !hasargs && !PyList_Check(obj) && !PyDict_Check(obj)); if (state == NULL) { Py_DECREF(newobj); Py_DECREF(newargs);