Skip to content

Commit 603264c

Browse files
authored
Merge branch 'main' into queue-shutdown-multiprocessing
2 parents 297a460 + c3fca5d commit 603264c

33 files changed

+22217
-20969
lines changed

Doc/c-api/bytes.rst

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,162 @@ called with a non-bytes parameter.
219219
reallocation fails, the original bytes object at *\*bytes* is deallocated,
220220
*\*bytes* is set to ``NULL``, :exc:`MemoryError` is set, and ``-1`` is
221221
returned.
222+
223+
PyBytesWriter
224+
-------------
225+
226+
The :c:type:`PyBytesWriter` API can be used to create a Python :class:`bytes`
227+
object.
228+
229+
.. versionadded:: next
230+
231+
.. c:type:: PyBytesWriter
232+
233+
A bytes writer instance.
234+
235+
The API is **not thread safe**: a writer should only be used by a single
236+
thread at the same time.
237+
238+
The instance must be destroyed by :c:func:`PyBytesWriter_Finish` on
239+
success, or :c:func:`PyBytesWriter_Discard` on error.
240+
241+
242+
Create, Finish, Discard
243+
^^^^^^^^^^^^^^^^^^^^^^^
244+
245+
.. c:function:: PyBytesWriter* PyBytesWriter_Create(Py_ssize_t size)
246+
247+
Create a :c:type:`PyBytesWriter` to write *size* bytes.
248+
249+
If *size* is greater than zero, allocate *size* bytes, and set the
250+
writer size to *size*. The caller is responsible to write *size*
251+
bytes using :c:func:`PyBytesWriter_GetData`.
252+
253+
On error, set an exception and return NULL.
254+
255+
*size* must be positive or zero.
256+
257+
.. c:function:: PyObject* PyBytesWriter_Finish(PyBytesWriter *writer)
258+
259+
Finish a :c:type:`PyBytesWriter` created by
260+
:c:func:`PyBytesWriter_Create`.
261+
262+
On success, return a Python :class:`bytes` object.
263+
On error, set an exception and return ``NULL``.
264+
265+
The writer instance is invalid after the call in any case.
266+
No API can be called on the writer after :c:func:`PyBytesWriter_Finish`.
267+
268+
.. c:function:: PyObject* PyBytesWriter_FinishWithSize(PyBytesWriter *writer, Py_ssize_t size)
269+
270+
Similar to :c:func:`PyBytesWriter_Finish`, but resize the writer
271+
to *size* bytes before creating the :class:`bytes` object.
272+
273+
.. c:function:: PyObject* PyBytesWriter_FinishWithPointer(PyBytesWriter *writer, void *buf)
274+
275+
Similar to :c:func:`PyBytesWriter_Finish`, but resize the writer
276+
using *buf* pointer before creating the :class:`bytes` object.
277+
278+
Set an exception and return ``NULL`` if *buf* pointer is outside the
279+
internal buffer bounds.
280+
281+
Function pseudo-code::
282+
283+
Py_ssize_t size = (char*)buf - (char*)PyBytesWriter_GetData(writer);
284+
return PyBytesWriter_FinishWithSize(writer, size);
285+
286+
.. c:function:: void PyBytesWriter_Discard(PyBytesWriter *writer)
287+
288+
Discard a :c:type:`PyBytesWriter` created by :c:func:`PyBytesWriter_Create`.
289+
290+
Do nothing if *writer* is ``NULL``.
291+
292+
The writer instance is invalid after the call.
293+
No API can be called on the writer after :c:func:`PyBytesWriter_Discard`.
294+
295+
High-level API
296+
^^^^^^^^^^^^^^
297+
298+
.. c:function:: int PyBytesWriter_WriteBytes(PyBytesWriter *writer, const void *bytes, Py_ssize_t size)
299+
300+
Grow the *writer* internal buffer by *size* bytes,
301+
write *size* bytes of *bytes* at the *writer* end,
302+
and add *size* to the *writer* size.
303+
304+
If *size* is equal to ``-1``, call ``strlen(bytes)`` to get the
305+
string length.
306+
307+
On success, return ``0``.
308+
On error, set an exception and return ``-1``.
309+
310+
.. c:function:: int PyBytesWriter_Format(PyBytesWriter *writer, const char *format, ...)
311+
312+
Similar to :c:func:`PyBytes_FromFormat`, but write the output directly at
313+
the writer end. Grow the writer internal buffer on demand. Then add the
314+
written size to the writer size.
315+
316+
On success, return ``0``.
317+
On error, set an exception and return ``-1``.
318+
319+
320+
Getters
321+
^^^^^^^
322+
323+
.. c:function:: Py_ssize_t PyBytesWriter_GetSize(PyBytesWriter *writer)
324+
325+
Get the writer size.
326+
327+
.. c:function:: void* PyBytesWriter_GetData(PyBytesWriter *writer)
328+
329+
Get the writer data: start of the internal buffer.
330+
331+
The pointer is valid until :c:func:`PyBytesWriter_Finish` or
332+
:c:func:`PyBytesWriter_Discard` is called on *writer*.
333+
334+
335+
Low-level API
336+
^^^^^^^^^^^^^
337+
338+
.. c:function:: int PyBytesWriter_Resize(PyBytesWriter *writer, Py_ssize_t size)
339+
340+
Resize the writer to *size* bytes. It can be used to enlarge or to
341+
shrink the writer.
342+
343+
Newly allocated bytes are left uninitialized.
344+
345+
On success, return ``0``.
346+
On error, set an exception and return ``-1``.
347+
348+
*size* must be positive or zero.
349+
350+
.. c:function:: int PyBytesWriter_Grow(PyBytesWriter *writer, Py_ssize_t grow)
351+
352+
Resize the writer by adding *grow* bytes to the current writer size.
353+
354+
Newly allocated bytes are left uninitialized.
355+
356+
On success, return ``0``.
357+
On error, set an exception and return ``-1``.
358+
359+
*size* can be negative to shrink the writer.
360+
361+
.. c:function:: void* PyBytesWriter_GrowAndUpdatePointer(PyBytesWriter *writer, Py_ssize_t size, void *buf)
362+
363+
Similar to :c:func:`PyBytesWriter_Grow`, but update also the *buf*
364+
pointer.
365+
366+
The *buf* pointer is moved if the internal buffer is moved in memory.
367+
The *buf* relative position within the internal buffer is left
368+
unchanged.
369+
370+
On error, set an exception and return ``NULL``.
371+
372+
*buf* must not be ``NULL``.
373+
374+
Function pseudo-code::
375+
376+
Py_ssize_t pos = (char*)buf - (char*)PyBytesWriter_GetData(writer);
377+
if (PyBytesWriter_Grow(writer, size) < 0) {
378+
return NULL;
379+
}
380+
return (char*)PyBytesWriter_GetData(writer) + pos;

Doc/howto/remote_debugging.rst

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,78 @@
33
Remote debugging attachment protocol
44
====================================
55

6+
This protocol enables external tools to attach to a running CPython process and
7+
execute Python code remotely.
8+
9+
Most platforms require elevated privileges to attach to another Python process.
10+
11+
.. _permission-requirements:
12+
13+
Permission requirements
14+
=======================
15+
16+
Attaching to a running Python process for remote debugging requires elevated
17+
privileges on most platforms. The specific requirements and troubleshooting
18+
steps depend on your operating system:
19+
20+
.. rubric:: Linux
21+
22+
The tracer process must have the ``CAP_SYS_PTRACE`` capability or equivalent
23+
privileges. You can only trace processes you own and can signal. Tracing may
24+
fail if the process is already being traced, or if it is running with
25+
set-user-ID or set-group-ID. Security modules like Yama may further restrict
26+
tracing.
27+
28+
To temporarily relax ptrace restrictions (until reboot), run:
29+
30+
``echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope``
31+
32+
.. note::
33+
34+
Disabling ``ptrace_scope`` reduces system hardening and should only be done
35+
in trusted environments.
36+
37+
If running inside a container, use ``--cap-add=SYS_PTRACE`` or
38+
``--privileged``, and run as root if needed.
39+
40+
Try re-running the command with elevated privileges:
41+
42+
``sudo -E !!``
43+
44+
45+
.. rubric:: macOS
46+
47+
To attach to another process, you typically need to run your debugging tool
48+
with elevated privileges. This can be done by using ``sudo`` or running as
49+
root.
50+
51+
Even when attaching to processes you own, macOS may block debugging unless
52+
the debugger is run with root privileges due to system security restrictions.
53+
54+
55+
.. rubric:: Windows
56+
57+
To attach to another process, you usually need to run your debugging tool
58+
with administrative privileges. Start the command prompt or terminal as
59+
Administrator.
60+
61+
Some processes may still be inaccessible even with Administrator rights,
62+
unless you have the ``SeDebugPrivilege`` privilege enabled.
63+
64+
To resolve file or folder access issues, adjust the security permissions:
65+
66+
1. Right-click the file or folder and select **Properties**.
67+
2. Go to the **Security** tab to view users and groups with access.
68+
3. Click **Edit** to modify permissions.
69+
4. Select your user account.
70+
5. In **Permissions**, check **Read** or **Full control** as needed.
71+
6. Click **Apply**, then **OK** to confirm.
72+
73+
74+
.. note::
75+
76+
Ensure you've satisfied all :ref:`permission-requirements` before proceeding.
77+
678
This section describes the low-level protocol that enables external tools to
779
inject and execute a Python script within a running CPython process.
880

Doc/library/csv.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ Dialects support the following attributes:
468468
.. attribute:: Dialect.skipinitialspace
469469

470470
When :const:`True`, spaces immediately following the *delimiter* are ignored.
471-
The default is :const:`False`.
471+
The default is :const:`False`. When combining ``delimiter=' '`` with
472+
``skipinitialspace=True``, unquoted empty fields are not allowed.
472473

473474

474475
.. attribute:: Dialect.strict
@@ -637,7 +638,7 @@ done::
637638
.. rubric:: Footnotes
638639

639640
.. [1] If ``newline=''`` is not specified, newlines embedded inside quoted fields
640-
will not be interpreted correctly, and on platforms that use ``\r\n`` linendings
641+
will not be interpreted correctly, and on platforms that use ``\r\n`` line endings
641642
on write an extra ``\r`` will be added. It should always be safe to specify
642643
``newline=''``, since the csv module does its own
643644
(:term:`universal <universal newlines>`) newline handling.

Doc/library/stdtypes.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,9 +1843,9 @@ expression support in the :mod:`re` module).
18431843
lowercase, :meth:`lower` would do nothing to ``'ß'``; :meth:`casefold`
18441844
converts it to ``"ss"``.
18451845

1846-
The casefolding algorithm is
1847-
`described in section 3.13 'Default Case Folding' of the Unicode Standard
1848-
<https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-3/#G33992>`__.
1846+
The casefolding algorithm is `described in section 3.13.3 'Default Case
1847+
Folding' of the Unicode Standard
1848+
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G53253>`__.
18491849

18501850
.. versionadded:: 3.3
18511851

@@ -2056,7 +2056,7 @@ expression support in the :mod:`re` module).
20562056
property being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is different
20572057
from the `Alphabetic property defined in the section 4.10 'Letters, Alphabetic, and
20582058
Ideographic' of the Unicode Standard
2059-
<https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-4/#G91002>`_.
2059+
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-4/#G91002>`__.
20602060

20612061

20622062
.. method:: str.isascii()
@@ -2196,9 +2196,9 @@ expression support in the :mod:`re` module).
21962196
Return a copy of the string with all the cased characters [4]_ converted to
21972197
lowercase.
21982198

2199-
The lowercasing algorithm used is
2200-
`described in section 3.13 'Default Case Folding' of the Unicode Standard
2201-
<https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-3/#G33992>`__.
2199+
The lowercasing algorithm used is `described in section 3.13.2 'Default Case
2200+
Conversion' of the Unicode Standard
2201+
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G34078>`__.
22022202

22032203

22042204
.. method:: str.lstrip(chars=None, /)
@@ -2561,9 +2561,9 @@ expression support in the :mod:`re` module).
25612561
character(s) is not "Lu" (Letter, uppercase), but e.g. "Lt" (Letter,
25622562
titlecase).
25632563

2564-
The uppercasing algorithm used is
2565-
`described in section 3.13 'Default Case Folding' of the Unicode Standard
2566-
<https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-3/#G33992>`__.
2564+
The uppercasing algorithm used is `described in section 3.13.2 'Default Case
2565+
Conversion' of the Unicode Standard
2566+
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G34078>`__.
25672567

25682568

25692569
.. method:: str.zfill(width, /)

Doc/library/unicodedata.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
This module provides access to the Unicode Character Database (UCD) which
1919
defines character properties for all Unicode characters. The data contained in
20-
this database is compiled from the `UCD version 16.0.0
21-
<https://www.unicode.org/Public/16.0.0/ucd>`_.
20+
this database is compiled from the `UCD version 17.0.0
21+
<https://www.unicode.org/Public/17.0.0/ucd>`_.
2222

2323
The module uses the same names and symbols as defined by Unicode
2424
Standard Annex #44, `"Unicode Character Database"
@@ -211,6 +211,6 @@ In addition, the module exposes the following constant:
211211

212212
.. rubric:: Footnotes
213213

214-
.. [#] https://www.unicode.org/Public/16.0.0/ucd/NameAliases.txt
214+
.. [#] https://www.unicode.org/Public/17.0.0/ucd/NameAliases.txt
215215
216-
.. [#] https://www.unicode.org/Public/16.0.0/ucd/NamedSequences.txt
216+
.. [#] https://www.unicode.org/Public/17.0.0/ucd/NamedSequences.txt

Doc/reference/lexical_analysis.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ Character Database.
384384

385385

386386
.. _UAX-31: https://www.unicode.org/reports/tr31/
387-
.. _PropList.txt: https://www.unicode.org/Public/16.0.0/ucd/PropList.txt
388-
.. _DerivedCoreProperties.txt: https://www.unicode.org/Public/16.0.0/ucd/DerivedCoreProperties.txt
387+
.. _PropList.txt: https://www.unicode.org/Public/17.0.0/ucd/PropList.txt
388+
.. _DerivedCoreProperties.txt: https://www.unicode.org/Public/17.0.0/ucd/DerivedCoreProperties.txt
389389
.. _normalization form: https://www.unicode.org/reports/tr15/#Norm_Forms
390390

391391

@@ -793,7 +793,7 @@ with the given *name*::
793793
This sequence cannot appear in :ref:`bytes literals <bytes-literal>`.
794794

795795
.. versionchanged:: 3.3
796-
Support for `name aliases <https://www.unicode.org/Public/16.0.0/ucd/NameAliases.txt>`__
796+
Support for `name aliases <https://www.unicode.org/Public/17.0.0/ucd/NameAliases.txt>`__
797797
has been added.
798798

799799
.. _string-escape-long-hex:

Doc/whatsnew/3.15.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,12 @@ typing
648648
(Contributed by Nikita Sobolev in :gh:`137191`.)
649649

650650

651+
unicodedata
652+
-----------
653+
654+
* The Unicode database has been updated to Unicode 17.0.0.
655+
656+
651657
wave
652658
----
653659

@@ -701,6 +707,23 @@ New features
701707
and :c:data:`Py_mod_abi`.
702708
(Contributed by Petr Viktorin in :gh:`137210`.)
703709

710+
* Implement :pep:`782`, the :c:type:`PyBytesWriter` API. Add functions:
711+
712+
* :c:func:`PyBytesWriter_Create`
713+
* :c:func:`PyBytesWriter_Discard`
714+
* :c:func:`PyBytesWriter_FinishWithPointer`
715+
* :c:func:`PyBytesWriter_FinishWithSize`
716+
* :c:func:`PyBytesWriter_Finish`
717+
* :c:func:`PyBytesWriter_Format`
718+
* :c:func:`PyBytesWriter_GetData`
719+
* :c:func:`PyBytesWriter_GetSize`
720+
* :c:func:`PyBytesWriter_GrowAndUpdatePointer`
721+
* :c:func:`PyBytesWriter_Grow`
722+
* :c:func:`PyBytesWriter_Resize`
723+
* :c:func:`PyBytesWriter_WriteBytes`
724+
725+
(Contributed by Victor Stinner in :gh:`129813`.)
726+
704727

705728
Porting to Python 3.15
706729
----------------------

0 commit comments

Comments
 (0)