Skip to content

gh-163051: Fix ShareableList layout for empty str/bytes - #163052

Open
hyongtao-code wants to merge 4 commits into
python:mainfrom
hyongtao-code:fix-empty
Open

hyongtao-code wants to merge 4 commits into
python:mainfrom
hyongtao-code:fix-empty

Conversation

@hyongtao-code

@hyongtao-code hyongtao-code commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

An empty str/bytes was given a zero-length slot: the item size is now
computed as a ceiling division,

self._alignment * ((len(encoded) - 1) // self._alignment + 1)

which yields 0 when len(encoded) == 0. The item then shares its offset
with the next item, or with the packing-format metadata when it is the
last one, so filling that slot either raises a misleading ValueError or
silently overwrites the neighbour (and, in the trailing case, destroys
the block). Clamp the result to one alignment unit.

The layout of non-empty items is unchanged, so blocks created by earlier
releases keep working.

Add a regression test covering empty str and bytes in the first, middle
and last position.

Signed-off-by: Yongtao Huang yongtaoh2022@gmail.com

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant