Skip to content

Commit 6134f87

Browse files
Merge branch 'main' into os-NODEV
2 parents f1b50c1 + 43013f7 commit 6134f87

File tree

122 files changed

+23634
-21880
lines changed

Some content is hidden

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

122 files changed

+23634
-21880
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/c-api/init.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ The following functions can be safely called before Python is initialized:
4141
* :c:func:`PyObject_SetArenaAllocator`
4242
* :c:func:`Py_SetProgramName`
4343
* :c:func:`Py_SetPythonHome`
44-
* :c:func:`PySys_ResetWarnOptions`
4544
* the configuration functions covered in :ref:`init-config`
4645

4746
* Informative functions:
@@ -2011,6 +2010,11 @@ Reference tracing
20112010
is set to :c:data:`PyRefTracer_DESTROY`). The **data** argument is the opaque pointer
20122011
that was provided when :c:func:`PyRefTracer_SetTracer` was called.
20132012
2013+
If a new tracing function is registered replacing the current a call to the
2014+
trace function will be made with the object set to **NULL** and **event** set to
2015+
:c:data:`PyRefTracer_TRACKER_REMOVED`. This will happen just before the new
2016+
function is registered.
2017+
20142018
.. versionadded:: 3.13
20152019
20162020
.. c:var:: int PyRefTracer_CREATE
@@ -2023,6 +2027,13 @@ Reference tracing
20232027
The value for the *event* parameter to :c:type:`PyRefTracer` functions when a Python
20242028
object has been destroyed.
20252029
2030+
.. c:var:: int PyRefTracer_TRACKER_REMOVED
2031+
2032+
The value for the *event* parameter to :c:type:`PyRefTracer` functions when the
2033+
current tracer is about to be replaced by a new one.
2034+
2035+
.. versionadded:: 3.14
2036+
20262037
.. c:function:: int PyRefTracer_SetTracer(PyRefTracer tracer, void *data)
20272038
20282039
Register a reference tracer function. The function will be called when a new
@@ -2038,6 +2049,10 @@ Reference tracing
20382049
20392050
There must be an :term:`attached thread state` when calling this function.
20402051
2052+
If another tracer function was already registered, the old function will be
2053+
called with **event** set to :c:data:`PyRefTracer_TRACKER_REMOVED` just before
2054+
the new function is registered.
2055+
20412056
.. versionadded:: 3.13
20422057
20432058
.. c:function:: PyRefTracer PyRefTracer_GetTracer(void** data)

Doc/c-api/init_config.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,11 @@ PyConfig
12781278
12791279
Default: ``0``.
12801280
1281+
.. deprecated-removed:: 3.15 3.17
1282+
1283+
The :option:`-b` and :option:`!-bb` options will become no-op in 3.17.
1284+
:c:member:`~PyConfig.bytes_warning` member will be removed in 3.17.
1285+
12811286
.. c:member:: int warn_default_encoding
12821287
12831288
If non-zero, emit a :exc:`EncodingWarning` warning when :class:`io.TextIOWrapper`

Doc/c-api/sys.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,6 @@ accessible to C code. They all work with the current interpreter thread's
316316
case *name* is deleted from the sys module. Returns ``0`` on success, ``-1``
317317
on error.
318318
319-
.. c:function:: void PySys_ResetWarnOptions()
320-
321-
Reset :data:`sys.warnoptions` to an empty list. This function may be
322-
called prior to :c:func:`Py_Initialize`.
323-
324-
.. deprecated-removed:: 3.13 3.15
325-
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
326-
327319
.. c:function:: void PySys_WriteStdout(const char *format, ...)
328320
329321
Write the output string described by *format* to :data:`sys.stdout`. No

Doc/data/stable_abi.dat

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/deprecations/c-api-pending-removal-in-3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Pending removal in Python 3.15
5959
Set :c:member:`PyConfig.program_name` instead.
6060
* :c:func:`!Py_SetPythonHome()`:
6161
Set :c:member:`PyConfig.home` instead.
62-
* :c:func:`PySys_ResetWarnOptions`:
62+
* :c:func:`!PySys_ResetWarnOptions`:
6363
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
6464

6565
The :c:func:`Py_InitializeFromConfig` API should be used with

Doc/faq/python-video-icon.png

-2.82 KB
Binary file not shown.

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, /)

0 commit comments

Comments
 (0)