Skip to content

multiprocessing: Add note that Array(c_char, 128).value is null-terminated #117291

@prauscher

Description

@prauscher

Documentation

Documentation of multiprocessing.Array describes the optional Attributes value and raw for c_char-Arrays with a short line:

Note that an array of ctypes.c_char has value and raw attributes which allow one to use it to store and retrieve strings.

While it might be obvious to C-developers, there is no note that setting Array.value to a bytes-object containing a nullbyte will skip the rest of the content when retrieving the value-Attribute:

from multiprocessing import Array
from ctypes import c_char

uut = Array(c_char, 50)
uut.value = bytes.fromhex('48656c6c6f 00 576f726c64')
print(uut.value.hex())  # Gives only 48656c6c6f

As c_char is intended for usage of strings, this might not be too large of an issue, but as Array.value accepts and gives bytes-objects, I expected to have no changes.

My suggestion would be to add a sentence to the documentation, I'll provide a small PR shortly to discussion.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions