Skip to content

gh-148914: Fix memoization of in-band PickleBuffer in the Python implementation#149052

Open
serhiy-storchaka wants to merge 2 commits intopython:mainfrom
serhiy-storchaka:empty-picklebuffer-memoization
Open

gh-148914: Fix memoization of in-band PickleBuffer in the Python implementation#149052
serhiy-storchaka wants to merge 2 commits intopython:mainfrom
serhiy-storchaka:empty-picklebuffer-memoization

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka commented Apr 27, 2026

Previously, identical PickleBuffers did not preserve identity. Also, empty writable PickleBuffer memoized an empty bytearray object in place of b'' which is a singleton in CPython, so the following references to b'' were unpickled as an empty bytearray object.

Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I think I introduced this in 7595e67.

Comment thread Lib/pickle.py Outdated
…n implementation

Previously, identical PickleBuffers did not preserve identity.
Also, empty writable PickleBuffer memoized an empty bytearray object
in place of b'' which is a singleton in CPython, so the following
references to b'' were unpickled as an empty bytearray object.
@serhiy-storchaka serhiy-storchaka force-pushed the empty-picklebuffer-memoization branch from d1a37a0 to b819df5 Compare April 27, 2026 14:55
Comment thread Lib/test/pickletester.py Outdated
with self.subTest(proto=proto, array_type=array_type, s=s, independent=False):
b = array_type(s)
p = self.dumps((b, b), proto)
import pickletools; pickletools.dis(p)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's also a debugging relicate :)

Comment thread Lib/test/pickletester.py Outdated
if self.py_version >= (3, 4):
array_types += [ZeroCopyBytearray]
for proto in protocols:
for proto in protocols[5:]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one also a relicate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants