Skip to content

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

Merged
serhiy-storchaka merged 2 commits intopython:mainfrom
serhiy-storchaka:empty-picklebuffer-memoization
May 2, 2026
Merged

gh-148914: Fix memoization of in-band PickleBuffer in the Python implementation#149052
serhiy-storchaka merged 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?

@serhiy-storchaka serhiy-storchaka merged commit b897356 into python:main May 2, 2026
51 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the empty-picklebuffer-memoization branch May 2, 2026 09:04
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 2, 2026

GH-149274 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label May 2, 2026
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 2, 2026

GH-149275 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label May 2, 2026
serhiy-storchaka added a commit that referenced this pull request May 2, 2026
…on implementation (GH-149052) (GH-149274)

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.
(cherry picked from commit b897356)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull request May 2, 2026
…on implementation (GH-149052) (GH-149275)

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.
(cherry picked from commit b897356)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants