Message166477
| Author |
sbt |
| Recipients |
alexandre.vassalotti, belopolsky, bpb, brett.cannon, ehuss, facundobatista, fmitha, georg.brandl, gvanrossum, jafo, jaraco, jarpa, kylev, loewis, lukasz.langa, nnorwitz, pitrou, sbt, taleinat, tseaver, vstinner, zbysz, zseil |
| Date |
2012年07月26日.12:52:54 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1343307175.45.0.866377450976.issue1692335@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
I see that the originally proposed patch is more or less what I suggested above. Since this has been a critical issue for 5 years, I think such a minimal patch should be committed even though it is not a complete solution.
It seems to me that the more complicated patch exception_pickling_26.diff has a significant overlap with _common_reduce() in typeobject.c.
The patch actually attempts to be *more* general than _common_reduce() since it collects data from tp_getset and tp_members, whereas _common_reduce() only collects data from __slots__. The patch does not seem to take account of read-only members/getsetters, which I think would cause exceptions when unpickling.
An alternative implementation piggy-backing on _common_reduce() (and using __reduce__ rather than __getstate__) would be
def __reduce__(self):
slots = None
func, args, state = object.__reduce__(self, 2)[:3]
if type(state) is tuple:
state, slots = state
newstate = {'args': self.args}
if state:
newstate.update(state)
if slots:
newstate.update(slots)
return func, args, newstate
This deals correctly with slots and works with all protocols. However, the pickles produced can only be unpickled on versions where exceptions are new-style classes, ie Python 2.5 and later.
This would have the side effect that __init__() would no longer be called while unpickling. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年07月26日 12:52:55 | sbt | set | recipients:
+ sbt, gvanrossum, loewis, nnorwitz, brett.cannon, georg.brandl, facundobatista, jafo, ehuss, tseaver, jaraco, belopolsky, zseil, fmitha, pitrou, vstinner, taleinat, alexandre.vassalotti, jarpa, bpb, zbysz, kylev, lukasz.langa |
| 2012年07月26日 12:52:55 | sbt | set | messageid: <1343307175.45.0.866377450976.issue1692335@psf.upfronthosting.co.za> |
| 2012年07月26日 12:52:54 | sbt | link | issue1692335 messages |
| 2012年07月26日 12:52:54 | sbt | create |
|