Visitar URL original
Stackless issue #206: fix function object pickling in Python · akruis/cpython@ee58616 · GitHub
Skip to content

Commit ee58616

Browse files
committed
Stackless issue python#206: fix function object pickling in Python
Fix the error handling of the Python implementation of function-object pickling.
1 parent d194757 commit ee58616

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

‎Lib/pickle.py‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,29 +1024,40 @@ def save_type(self, obj):
10241024
return self.save_reduce(type, (...,), obj=obj)
10251025
return self.save_global(obj)
10261026

1027+
## Stackless addition BEGIN
10271028
def save_function(self, obj):
10281029
try:
10291030
return self.save_global(obj)
10301031
except PicklingError as e:
1031-
pass
1032-
# Check copy_reg.dispatch_table
1033-
reduce = dispatch_table.get(type(obj))
1034-
if reduce:
1035-
rv = reduce(obj)
1036-
else:
1037-
# Check for a __reduce_ex__ method, fall back to __reduce__
1038-
reduce = getattr(obj, "__reduce_ex__", None)
1032+
# Check copy_reg.dispatch_table
1033+
reduce = dispatch_table.get(type(obj))
10391034
if reduce:
1040-
rv = reduce(self.proto)
1035+
rv = reduce(obj)
10411036
else:
1042-
reduce = getattr(obj, "__reduce__", None)
1037+
# Check for a __reduce_ex__ method, fall back to __reduce__
1038+
reduce = getattr(obj, "__reduce_ex__", None)
10431039
if reduce:
1044-
rv = reduce()
1040+
try:
1041+
rv = reduce(self.proto)
1042+
except PicklingError:
1043+
raise
1044+
except Exception as e2:
1045+
raise PicklingError("Can't reduce function %r" % (obj,)) from e2
10451046
else:
1046-
raise e
1047+
reduce = getattr(obj, "__reduce__", None)
1048+
if reduce:
1049+
try:
1050+
rv = reduce()
1051+
except PicklingError:
1052+
raise
1053+
except Exception as e2:
1054+
raise PicklingError("Can't reduce function %r" % (obj,)) from e2
1055+
else:
1056+
raise e
10471057
return self.save_reduce(obj=obj, *rv)
10481058

10491059
dispatch[FunctionType] = save_function
1060+
## Stackless addition END
10501061
dispatch[type] = save_type
10511062

10521063

‎Stackless/changelog.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ What's New in Stackless 3.X.X?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
- https://github.com/stackless-dev/stackless/issues/206
13+
Fix the error handling of the Python implementation of function-object
14+
pickling.
15+
1216
- https://github.com/stackless-dev/stackless/issues/204
1317
Fix bpo-24596 for Stackless too.
1418

0 commit comments

Comments
 (0)