mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
Issue #4842, patch 1/2: fix pickle in Python 3.x so that pickling with the
'L' opcode always appends an 'L' on output, just as 2.x does. When unpickling, remove the trailing 'L' (if present) before passing the result to PyLong_FromString.
This commit is contained in:
parent
6dc4396708
commit
8dd05147d6
5 changed files with 155 additions and 128 deletions
|
@ -470,7 +470,7 @@ class _Pickler:
|
|||
else:
|
||||
self.write(LONG4 + pack("<i", n) + encoded)
|
||||
return
|
||||
self.write(LONG + repr(obj).encode("ascii") + b'\n')
|
||||
self.write(LONG + repr(obj).encode("ascii") + b'L\n')
|
||||
dispatch[int] = save_long
|
||||
|
||||
def save_float(self, obj, pack=struct.pack):
|
||||
|
@ -890,6 +890,8 @@ class _Unpickler:
|
|||
|
||||
def load_long(self):
|
||||
val = self.readline()[:-1].decode("ascii")
|
||||
if val and val[-1] == 'L':
|
||||
val = val[:-1]
|
||||
self.append(int(val, 0))
|
||||
dispatch[LONG[0]] = load_long
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue