Skip to content

Commit 43b9010

Browse files
author
Anselm Kruis
committed
merge 3.3-slp (Stackless python#127, use C-Python pickling)
2 parents 9994a00 + 91712fb commit 43b9010

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

Lib/stackless.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def transmogrify():
7979
from copyreg import pickle
8080
for name in dir(_wrap):
8181
cls = getattr(_wrap, name, None)
82-
if isinstance(cls, type) and cls.__name__ != "frame":
82+
if (isinstance(cls, type) and
83+
cls.__name__ not in ("frame", "iterator", "callable_iterator")):
8384
pickle(cls.__bases__[0], cls.__reduce__)
8485

8586
try:

Stackless/changelog.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ What's New in Stackless 3.X.X?
1010
*Release date: 20XX-XX-XX*
1111

1212
- https://bitbucket.org/stackless-dev/stackless/issues/127
13-
Fix pickling of 'callable-iterator' and 'method-wrapper' objects.
14-
Fix copy.copy() for 'callable-iterator', 'method', 'dict_keys', 'dict_values'
15-
and 'dict_items' objects.
13+
Disable the Stackless specific code for pickling 'iterator' and
14+
'callable_iterator' objects. C-Python 3.3 already pickles them.
15+
Fix pickling of 'method-wrapper' objects.
16+
Fix copy.copy() for 'method', 'dict_keys', 'dict_values' and 'dict_items'
17+
objects.
1618

1719
- https://bitbucket.org/stackless-dev/stackless/issues/126
1820
Load the module stackless early in all C-Python tests. This ensures a defined

Stackless/unittests/test_pickle.py

+71
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,77 @@ def test_dict_items(self):
727727
obj = d.items()
728728
self._test(obj)
729729

730+
731+
class SimpleSequence:
732+
def __getitem__(self, n):
733+
if n < 3:
734+
return n
735+
raise IndexError
736+
737+
738+
class TestOldStackless_WrapFactories(StacklessPickleTestCase):
739+
def test_iterator(self):
740+
# Stackless prior to version 3.3.7 used to register its own __reduce__
741+
# method for 'iterator' with copy_reg. This method returned the function
742+
# stackless._wrap.iterator as iterator factory.
743+
#
744+
# This test case ensures that stackless can still unpickle old pickles:
745+
746+
# an old pickle, protocol 0 of iter(SimpleSequence())
747+
p = b'c_stackless._wrap\niterator\n(ccopy_reg\n_reconstructor\n(ctest_pickle\nSimpleSequence\nc__builtin__\nobject\nNtRL0L\ntR(tb.'
748+
749+
# Output of
750+
# from pickletools import dis; dis(p)
751+
# 0: c GLOBAL '_stackless._wrap iterator'
752+
# 27: ( MARK
753+
# 28: c GLOBAL 'copy_reg _reconstructor'
754+
# 53: ( MARK
755+
# 54: c GLOBAL 'test_pickle SimpleSequence'
756+
# 82: c GLOBAL '__builtin__ object'
757+
# 102: N NONE
758+
# 103: t TUPLE (MARK at 53)
759+
# 104: R REDUCE
760+
# 105: L LONG 0
761+
# 109: t TUPLE (MARK at 27)
762+
# 110: R REDUCE
763+
# 111: ( MARK
764+
# 112: t TUPLE (MARK at 111)
765+
# 113: b BUILD
766+
# 114: . STOP
767+
# highest protocol among opcodes = 0
768+
769+
x = self.loads(p)
770+
self.assertIs(type(x), type(iter(SimpleSequence())))
771+
self.assertListEqual(list(x), [0, 1, 2])
772+
773+
def test_callable_iterator(self):
774+
# Stackless prior to version 3.3.7 used to register its own __reduce__
775+
# method for 'callable_iterator' with copy_reg. This method returned the function
776+
# stackless._wrap.callable_iterator as callable_iterator factory.
777+
#
778+
# This test case ensures that stackless can still unpickle old pickles:
779+
780+
# an old pickle, protocol 0 of iter(bool, False)
781+
p = b'c_stackless._wrap\ncallable_iterator\n(c__builtin__\nbool\nI00\ntR.'
782+
783+
# Output of
784+
# from pickletools import dis; dis(p)
785+
# 0: c GLOBAL '_stackless._wrap callable_iterator'
786+
# 36: ( MARK
787+
# 37: c GLOBAL '__builtin__ bool'
788+
# 55: I INT False
789+
# 59: t TUPLE (MARK at 36)
790+
# 60: R REDUCE
791+
# 61: . STOP
792+
# highest protocol among opcodes = 0
793+
794+
x = self.loads(p)
795+
# Use assertIsInstance, because x may be a subclass of i.
796+
# See bug https://bitbucket.org/stackless-dev/stackless/issues/127
797+
self.assertIsInstance(x, type(iter(bool, False)))
798+
self.assertListEqual(list(x), [])
799+
800+
730801
if __name__ == '__main__':
731802
if not sys.argv[1:]:
732803
sys.argv.append('-v')

0 commit comments

Comments
 (0)