Skip to content
Merged
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
14 changes: 14 additions & 0 deletions Doc/c-api/bytearray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Direct API functions
On failure, return ``NULL`` with an exception set.
.. note::
If the object implements the buffer protocol, then the buffer
must not be mutated while the bytearray object is being created.
.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
Expand All @@ -58,6 +62,10 @@ Direct API functions
On failure, return ``NULL`` with an exception set.
.. note::
If the object implements the buffer protocol, then the buffer
must not be mutated while the bytearray object is being created.
.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
Expand All @@ -70,6 +78,9 @@ Direct API functions
``NULL`` pointer. The returned array always has an extra
null byte appended.
.. note::
It is not thread-safe to mutate the bytearray object while using the returned char array.
.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
Expand All @@ -89,6 +100,9 @@ These macros trade safety for speed and they don't check pointers.
Similar to :c:func:`PyByteArray_AsString`, but without error checking.
.. note::
It is not thread-safe to mutate the bytearray object while using the returned char array.
.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
Expand Down
17 changes: 17 additions & 0 deletions Doc/data/threadsafety.dat
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,20 @@ _PyBytes_Resize:distinct:

# Repr - atomic as bytes are immutable
PyBytes_Repr:atomic:

# Creation from object - may call arbitrary code
PyByteArray_FromObject:shared:

# Creation - pure allocation, no shared state
PyByteArray_FromStringAndSize:atomic:

# Concatenation - uses buffer protocol; safe as long as buffer is not mutated by another thread during the operation
PyByteArray_Concat:shared:

# Size - uses atomic load on free-threaded builds
PyByteArray_Size:atomic:
PyByteArray_GET_SIZE:atomic:

# Raw data - no locking; mutating it is unsafe if the bytearray object is shared between threads
PyByteArray_AsString:compatible:
PyByteArray_AS_STRING:compatible:
Loading