Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Lib/multiprocessing/shared_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,22 @@ def _extract_recreation_code(value):
else:
return 3 # NoneType

def _get_str_or_bytes_format(self, item):
"""Used to ensure the correct length is inserted into the
the formatted _types_mapping for multibyte utf-8 characters."""
length = len(
item if isinstance(item, bytes) else item.encode(_encoding)
)
aligned_length = self._alignment * (length // self._alignment + 1)
return self._types_mapping[type(item)] % aligned_length

def __init__(self, sequence=None, *, name=None):
if name is None or sequence is not None:
sequence = sequence or ()
_formats = [
self._types_mapping[type(item)]
if not isinstance(item, (str, bytes))
else self._types_mapping[type(item)] % (
self._alignment * (len(item) // self._alignment + 1),
)
else self._get_str_or_bytes_format(item)
for item in sequence
]
self._list_len = len(_formats)
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Andres Ayala
Cathy Avery
John Aycock
Donovan Baarda
Donnelly Baart
Arne Babenhauserheide
Attila Babo
Matt Bachmann
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a bug where the length of multibyte utf-8 characters was not taken into
account in :class:`multiprocessing.shared_memory.ShareableList`.
Loading