Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r90269:23a4859e0e29 Date: 2017-02-21 15:21 +0100 http://bitbucket.org/pypy/pypy/changeset/23a4859e0e29/
Log: merge heads diff --git a/pypy/interpreter/test/test_zzpickle_and_slow.py b/pypy/interpreter/test/test_zzpickle_and_slow.py --- a/pypy/interpreter/test/test_zzpickle_and_slow.py +++ b/pypy/interpreter/test/test_zzpickle_and_slow.py @@ -471,7 +471,7 @@ assert 'finished' in repr(y) assert y.gi_code is None - def test_memoryview(self): + def test_pickle_memoryview(self): import pickle raises(TypeError, pickle.dumps, memoryview(b"abc")) diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -689,6 +689,9 @@ bytes = self.as_str() return _array_to_hexstring(space, StringBuffer(bytes), 0, 1, len(bytes)) + def descr___getstate__(self, space): + raise oefmt(space.w_TypeError, "cannot pickle memoryview objects") + def is_byte_format(char): return char == 'b' or char == 'B' or char == 'c' @@ -711,6 +714,7 @@ __enter__ = interp2app(W_MemoryView.descr_enter), __exit__ = interp2app(W_MemoryView.descr_exit), __weakref__ = make_weakref_descr(W_MemoryView), + __getstate__= interp2app(W_MemoryView.descr___getstate__), cast = interp2app(W_MemoryView.descr_cast), hex = interp2app(W_MemoryView.descr_hex), tobytes = interp2app(W_MemoryView.descr_tobytes), diff --git a/pypy/objspace/std/objectobject.py b/pypy/objspace/std/objectobject.py --- a/pypy/objspace/std/objectobject.py +++ b/pypy/objspace/std/objectobject.py @@ -24,6 +24,9 @@ try: getstate = obj.__getstate__ except AttributeError: + # TODO restrict pickling of variable sized objects + # tp_itemsize != 0, for now e.g. memoryview is handled + # by raising a TypeError in __getstate__ state = getattr(obj, "__dict__", None) names = slotnames(cls) # not checking for list if names is not None: @@ -44,6 +47,9 @@ def reduce_2(obj, proto, args, kwargs): cls = obj.__class__ + if not hasattr(type(obj), "__new__"): + raise TypeError("can't pickle %s objects" % type(obj).__name__) + import copyreg if not isinstance(args, tuple): @@ -58,7 +64,6 @@ raise ValueError("must use protocol 4 or greater to copy this " "object; since __getnewargs_ex__ returned " "keyword arguments.") - state = _getstate(obj) listitems = iter(obj) if isinstance(obj, list) else None dictitems = iter(obj.items()) if isinstance(obj, dict) else None _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit