Skip to content

Commit c4a8ee1

Browse files
authored
Merge branch 'main' into fix-issue-146452
2 parents 8f55561 + 73cc1fd commit c4a8ee1

File tree

115 files changed

+3481
-1813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+3481
-1813
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ jobs:
369369
sudo xcode-select --switch /Applications/Xcode_15.4.app
370370
371371
- name: Build and test
372-
run: python3 Apple ci iOS --fast-ci --simulator 'iPhone SE (3rd generation),OS=17.5'
372+
run: python3 Platforms/Apple ci iOS --fast-ci --simulator 'iPhone SE (3rd generation),OS=17.5'
373373

374374
build-emscripten:
375375
name: 'Emscripten'

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ repos:
33
rev: a27a2e47c7751b639d2b5badf0ef6ff11fee893f # frozen: v0.15.4
44
hooks:
55
- id: ruff-check
6-
name: Run Ruff (lint) on Apple/
7-
args: [--exit-non-zero-on-fix, --config=Apple/.ruff.toml]
8-
files: ^Apple/
6+
name: Run Ruff (lint) on Platforms/Apple/
7+
args: [--exit-non-zero-on-fix, --config=Platforms/Apple/.ruff.toml]
8+
files: ^Platforms/Apple/
99
- id: ruff-check
1010
name: Run Ruff (lint) on Doc/
1111
args: [--exit-non-zero-on-fix]
@@ -39,9 +39,9 @@ repos:
3939
args: [--exit-non-zero-on-fix, --config=Tools/wasm/.ruff.toml]
4040
files: ^Tools/wasm/
4141
- id: ruff-format
42-
name: Run Ruff (format) on Apple/
43-
args: [--exit-non-zero-on-fix, --config=Apple/.ruff.toml]
44-
files: ^Apple
42+
name: Run Ruff (format) on Platforms/Apple/
43+
args: [--exit-non-zero-on-fix, --config=Platforms/Apple/.ruff.toml]
44+
files: ^Platforms/Apple/
4545
- id: ruff-format
4646
name: Run Ruff (format) on Doc/
4747
args: [--exit-non-zero-on-fix]

Doc/c-api/bytearray.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Direct API functions
4444
4545
On failure, return ``NULL`` with an exception set.
4646
47+
.. note::
48+
If the object implements the buffer protocol, then the buffer
49+
must not be mutated while the bytearray object is being created.
50+
4751
4852
.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
4953
@@ -58,6 +62,10 @@ Direct API functions
5862
5963
On failure, return ``NULL`` with an exception set.
6064
65+
.. note::
66+
If the object implements the buffer protocol, then the buffer
67+
must not be mutated while the bytearray object is being created.
68+
6169
6270
.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
6371
@@ -70,6 +78,9 @@ Direct API functions
7078
``NULL`` pointer. The returned array always has an extra
7179
null byte appended.
7280
81+
.. note::
82+
It is not thread-safe to mutate the bytearray object while using the returned char array.
83+
7384
7485
.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
7586
@@ -89,6 +100,9 @@ These macros trade safety for speed and they don't check pointers.
89100
90101
Similar to :c:func:`PyByteArray_AsString`, but without error checking.
91102
103+
.. note::
104+
It is not thread-safe to mutate the bytearray object while using the returned char array.
105+
92106
93107
.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
94108

Doc/c-api/bytes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ called with a non-bytes parameter.
127127
Return the bytes representation of object *o* that implements the buffer
128128
protocol.
129129
130+
.. note::
131+
If the object implements the buffer protocol, then the buffer
132+
must not be mutated while the bytes object is being created.
133+
130134
131135
.. c:function:: Py_ssize_t PyBytes_Size(PyObject *o)
132136
@@ -185,13 +189,20 @@ called with a non-bytes parameter.
185189
created, the old reference to *bytes* will still be discarded and the value
186190
of *\*bytes* will be set to ``NULL``; the appropriate exception will be set.
187191
192+
.. note::
193+
If *newpart* implements the buffer protocol, then the buffer
194+
must not be mutated while the new bytes object is being created.
188195
189196
.. c:function:: void PyBytes_ConcatAndDel(PyObject **bytes, PyObject *newpart)
190197
191198
Create a new bytes object in *\*bytes* containing the contents of *newpart*
192199
appended to *bytes*. This version releases the :term:`strong reference`
193200
to *newpart* (i.e. decrements its reference count).
194201
202+
.. note::
203+
If *newpart* implements the buffer protocol, then the buffer
204+
must not be mutated while the new bytes object is being created.
205+
195206
196207
.. c:function:: PyObject* PyBytes_Join(PyObject *sep, PyObject *iterable)
197208
@@ -210,6 +221,9 @@ called with a non-bytes parameter.
210221
211222
.. versionadded:: 3.14
212223
224+
.. note::
225+
If *iterable* objects implement the buffer protocol, then the buffers
226+
must not be mutated while the new bytes object is being created.
213227
214228
.. c:function:: int _PyBytes_Resize(PyObject **bytes, Py_ssize_t newsize)
215229

Doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
('c:type', '__int64'),
178178
('c:type', 'unsigned __int64'),
179179
('c:type', 'double'),
180+
('c:type', '_Float16'),
180181
# Standard C structures
181182
('c:struct', 'in6_addr'),
182183
('c:struct', 'in_addr'),

Doc/data/threadsafety.dat

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,61 @@ PyList_Reverse:shared:
6666
# is a list
6767
PyList_SetSlice:shared:
6868

69-
# Sort - per-object lock held; comparison callbacks may execute
70-
# arbitrary Python code
69+
# Sort - per-object lock held; the list is emptied before sorting
70+
# so other threads may observe an empty list, but they won't see the
71+
# intermediate states of the sort
7172
PyList_Sort:shared:
7273

7374
# Extend - lock target list; also lock source when it is a
7475
# list, set, or dict
7576
PyList_Extend:shared:
77+
78+
# Creation - pure allocation, no shared state
79+
PyBytes_FromString:atomic:
80+
PyBytes_FromStringAndSize:atomic:
81+
PyBytes_DecodeEscape:atomic:
82+
83+
# Creation from formatting C primitives - pure allocation, no shared state
84+
PyBytes_FromFormat:atomic:
85+
PyBytes_FromFormatV:atomic:
86+
87+
# Creation from object - uses buffer protocol so may call arbitrary code;
88+
# safe as long as the buffer is not mutated by another thread during the operation
89+
PyBytes_FromObject:shared:
90+
91+
# Size - uses atomic load on free-threaded builds
92+
PyBytes_Size:atomic:
93+
PyBytes_GET_SIZE:atomic:
94+
95+
# Raw data - no locking; mutating it is unsafe if the bytes object is shared between threads
96+
PyBytes_AsString:compatible:
97+
PyBytes_AS_STRING:compatible:
98+
PyBytes_AsStringAndSize:compatible:
99+
100+
# Concatenation - uses buffer protocol; safe as long as buffer is not mutated by another thread during the operation
101+
PyBytes_Concat:shared:
102+
PyBytes_ConcatAndDel:shared:
103+
PyBytes_Join:shared:
104+
105+
# Resizing - safe if the object is unique
106+
_PyBytes_Resize:distinct:
107+
108+
# Repr - atomic as bytes are immutable
109+
PyBytes_Repr:atomic:
110+
111+
# Creation from object - may call arbitrary code
112+
PyByteArray_FromObject:shared:
113+
114+
# Creation - pure allocation, no shared state
115+
PyByteArray_FromStringAndSize:atomic:
116+
117+
# Concatenation - uses buffer protocol; safe as long as buffer is not mutated by another thread during the operation
118+
PyByteArray_Concat:shared:
119+
120+
# Size - uses atomic load on free-threaded builds
121+
PyByteArray_Size:atomic:
122+
PyByteArray_GET_SIZE:atomic:
123+
124+
# Raw data - no locking; mutating it is unsafe if the bytearray object is shared between threads
125+
PyByteArray_AsString:compatible:
126+
PyByteArray_AS_STRING:compatible:

Doc/library/array.rst

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
--------------
1010

1111
This module defines an object type which can compactly represent an array of
12-
basic values: characters, integers, floating-point numbers. Arrays are mutable :term:`sequence`
12+
basic values: characters, integers, floating-point numbers, complex numbers. Arrays are mutable :term:`sequence`
1313
types and behave very much like lists, except that the type of objects stored in
1414
them is constrained. The type is specified at object creation time by using a
1515
:dfn:`type code`, which is a single character. The following type codes are
@@ -46,6 +46,11 @@ defined:
4646
+-----------+--------------------+-------------------+-----------------------+-------+
4747
| ``'d'`` | double | float | 8 | |
4848
+-----------+--------------------+-------------------+-----------------------+-------+
49+
| ``'F'`` | float complex | complex | 8 | \(3) |
50+
+-----------+--------------------+-------------------+-----------------------+-------+
51+
| ``'D'`` | double complex | complex | 16 | \(3) |
52+
+-----------+--------------------+-------------------+-----------------------+-------+
53+
4954

5055
Notes:
5156

@@ -63,6 +68,15 @@ Notes:
6368
(2)
6469
.. versionadded:: 3.13
6570

71+
(3)
72+
Complex types (``F`` and ``D``) are available unconditionally,
73+
regardless on support for complex types (the Annex G of the C11 standard)
74+
by the C compiler.
75+
As specified in the C11 standard, each complex type is represented by a
76+
two-element C array containing, respectively, the real and imaginary parts.
77+
78+
.. versionadded:: 3.15
79+
6680
.. seealso::
6781

6882
The :ref:`ctypes <ctypes-fundamental-data-types>` and
@@ -119,9 +133,9 @@ The module defines the following type:
119133
The length in bytes of one array item in the internal representation.
120134

121135

122-
.. method:: append(x)
136+
.. method:: append(value, /)
123137

124-
Append a new item with value *x* to the end of the array.
138+
Append a new item with the specified value to the end of the array.
125139

126140

127141
.. method:: buffer_info()
@@ -146,25 +160,26 @@ The module defines the following type:
146160
.. method:: byteswap()
147161

148162
"Byteswap" all items of the array. This is only supported for values which are
149-
1, 2, 4, or 8 bytes in size; for other types of values, :exc:`RuntimeError` is
163+
1, 2, 4, 8 or 16 bytes in size; for other types of values, :exc:`RuntimeError` is
150164
raised. It is useful when reading data from a file written on a machine with a
151-
different byte order.
165+
different byte order. Note, that for complex types the order of
166+
components (the real part, followed by imaginary part) is preserved.
152167

153168

154-
.. method:: count(x)
169+
.. method:: count(value, /)
155170

156-
Return the number of occurrences of *x* in the array.
171+
Return the number of occurrences of *value* in the array.
157172

158173

159-
.. method:: extend(iterable)
174+
.. method:: extend(iterable, /)
160175

161176
Append items from *iterable* to the end of the array. If *iterable* is another
162177
array, it must have *exactly* the same type code; if not, :exc:`TypeError` will
163178
be raised. If *iterable* is not an array, it must be iterable and its elements
164179
must be the right type to be appended to the array.
165180

166181

167-
.. method:: frombytes(buffer)
182+
.. method:: frombytes(buffer, /)
168183

169184
Appends items from the :term:`bytes-like object`, interpreting
170185
its content as an array of machine values (as if it had been read
@@ -174,55 +189,55 @@ The module defines the following type:
174189
:meth:`!fromstring` is renamed to :meth:`frombytes` for clarity.
175190

176191

177-
.. method:: fromfile(f, n)
192+
.. method:: fromfile(f, n, /)
178193

179194
Read *n* items (as machine values) from the :term:`file object` *f* and append
180195
them to the end of the array. If less than *n* items are available,
181196
:exc:`EOFError` is raised, but the items that were available are still
182197
inserted into the array.
183198

184199

185-
.. method:: fromlist(list)
200+
.. method:: fromlist(list, /)
186201

187202
Append items from the list. This is equivalent to ``for x in list:
188203
a.append(x)`` except that if there is a type error, the array is unchanged.
189204

190205

191-
.. method:: fromunicode(s)
206+
.. method:: fromunicode(ustr, /)
192207

193208
Extends this array with data from the given Unicode string.
194209
The array must have type code ``'u'`` or ``'w'``; otherwise a :exc:`ValueError` is raised.
195210
Use ``array.frombytes(unicodestring.encode(enc))`` to append Unicode data to an
196211
array of some other type.
197212

198213

199-
.. method:: index(x[, start[, stop]])
214+
.. method:: index(value[, start[, stop]])
200215

201216
Return the smallest *i* such that *i* is the index of the first occurrence of
202-
*x* in the array. The optional arguments *start* and *stop* can be
203-
specified to search for *x* within a subsection of the array. Raise
204-
:exc:`ValueError` if *x* is not found.
217+
*value* in the array. The optional arguments *start* and *stop* can be
218+
specified to search for *value* within a subsection of the array. Raise
219+
:exc:`ValueError` if *value* is not found.
205220

206221
.. versionchanged:: 3.10
207222
Added optional *start* and *stop* parameters.
208223

209224

210-
.. method:: insert(i, x)
225+
.. method:: insert(index, value, /)
211226

212-
Insert a new item with value *x* in the array before position *i*. Negative
227+
Insert a new item *value* in the array before position *index*. Negative
213228
values are treated as being relative to the end of the array.
214229

215230

216-
.. method:: pop([i])
231+
.. method:: pop(index=-1, /)
217232

218233
Removes the item with the index *i* from the array and returns it. The optional
219234
argument defaults to ``-1``, so that by default the last item is removed and
220235
returned.
221236

222237

223-
.. method:: remove(x)
238+
.. method:: remove(value, /)
224239

225-
Remove the first occurrence of *x* from the array.
240+
Remove the first occurrence of *value* from the array.
226241

227242

228243
.. method:: clear()
@@ -247,7 +262,7 @@ The module defines the following type:
247262
:meth:`!tostring` is renamed to :meth:`tobytes` for clarity.
248263

249264

250-
.. method:: tofile(f)
265+
.. method:: tofile(f, /)
251266

252267
Write all items (as machine values) to the :term:`file object` *f*.
253268

0 commit comments

Comments
 (0)