cpython: b8d108a2a38e (original) (raw)

Mercurial > cpython

changeset 99677:b8d108a2a38e

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. [#22995]

Serhiy Storchaka storchaka@gmail.com
date Fri, 25 Dec 2015 21:05:35 +0200
parents 80d1faa9735d(current diff)0cd2de69fb66(diff)
children d0a84d0c5ceb
files Lib/test/test_csv.py Misc/NEWS Objects/typeobject.c
diffstat 4 files changed, 67 insertions(+), 15 deletions(-)[+] [-] Lib/test/test_csv.py 13 Lib/test/test_memoryview.py 13 Misc/NEWS 5 Objects/typeobject.c 51

line wrap: on

line diff

--- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -1,6 +1,7 @@

Copyright (C) 2001,2002 Python Software Foundation

csv package unit tests

+import copy import io import sys import os @@ -9,6 +10,7 @@ from io import StringIO from tempfile import TemporaryFile import csv import gc +import pickle from test import support class Test_Csv(unittest.TestCase): @@ -424,6 +426,17 @@ class TestDialectRegistry(unittest.TestC self.assertRaises(TypeError, csv.reader, [], quoting = -1) self.assertRaises(TypeError, csv.reader, [], quoting = 100)

+

+ class TestCsvBase(unittest.TestCase): def readerAssertEqual(self, input, expected_result): with TemporaryFile("w+", newline='') as fileobj:

--- a/Lib/test/test_memoryview.py +++ b/Lib/test/test_memoryview.py @@ -11,6 +11,8 @@ import gc import weakref import array import io +import copy +import pickle class AbstractMemoryTests: @@ -519,6 +521,17 @@ class OtherTest(unittest.TestCase): m2 = m1[::-1] self.assertEqual(m2.hex(), '30' * 200000)

+

+ if name == "main": unittest.main()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,11 @@ Release date: tba Core and Builtins ----------------- +- Issue #22995: Instances of extension types with a state that aren't

--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3839,7 +3839,7 @@ Py_LOCAL(PyObject *) } Py_LOCAL(PyObject *) -_PyObject_GetState(PyObject *obj) +_PyObject_GetState(PyObject *obj, int required) { PyObject *state; PyObject *getstate; @@ -3854,6 +3854,13 @@ Py_LOCAL(PyObject *) } PyErr_Clear();

+ { PyObject **dict; dict = _PyObject_GetDictPtr(obj); @@ -3878,6 +3885,24 @@ Py_LOCAL(PyObject *) } assert(slotnames == Py_None || PyList_Check(slotnames));

+ if (slotnames != Py_None && Py_SIZE(slotnames) > 0) { PyObject *slots; Py_ssize_t slotnames_size, i; @@ -4107,29 +4132,24 @@ reduce_newobj(PyObject *obj) PyObject *copyreg; PyObject *newobj, *newargs, *state, *listitems, *dictitems; PyObject *result;

if (Py_TYPE(obj)->tp_new == NULL) { PyErr_Format(PyExc_TypeError,

@@ -4139,13 +4159,13 @@ reduce_newobj(PyObject *obj) newobj = PyObject_GetAttrId(copyreg, &PyId___newobj_); Py_DECREF(copyreg); if (newobj == NULL) {

@@ -4157,7 +4177,7 @@ reduce_newobj(PyObject *obj) Py_INCREF(v); PyTuple_SET_ITEM(newargs, i+1, v); }

@@ -4178,7 +4198,8 @@ reduce_newobj(PyObject *obj) } }