Skip to content

Commit edf20b7

Browse files
Merge branch 'main' into fix-pyrepl
2 parents 713b649 + 8b5ce31 commit edf20b7

File tree

142 files changed

+26475
-22507
lines changed

Some content is hidden

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

142 files changed

+26475
-22507
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ Python/stdlib_module_names.h generated
103103
Tools/peg_generator/pegen/grammar_parser.py generated
104104
aclocal.m4 generated
105105
configure generated
106+
*.min.js generated

.github/workflows/jit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ jobs:
7272
include:
7373
- target: i686-pc-windows-msvc/msvc
7474
architecture: Win32
75-
runner: windows-latest
75+
runner: windows-2022
7676
- target: x86_64-pc-windows-msvc/msvc
7777
architecture: x64
78-
runner: windows-latest
78+
runner: windows-2022
7979
- target: aarch64-pc-windows-msvc/msvc
8080
architecture: ARM64
8181
runner: windows-11-arm

.github/workflows/reusable-windows-msi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717
jobs:
1818
build:
1919
name: installer for ${{ inputs.arch }}
20-
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-latest' }}
20+
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2022' }}
2121
timeout-minutes: 60
2222
env:
2323
ARCH: ${{ inputs.arch }}

.github/workflows/reusable-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121
jobs:
2222
build:
2323
name: Build and test (${{ inputs.arch }})
24-
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-latest' }}
24+
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2022' }}
2525
timeout-minutes: 60
2626
env:
2727
ARCH: ${{ inputs.arch }}

.github/workflows/tail-call.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ jobs:
4949
include:
5050
# - target: i686-pc-windows-msvc/msvc
5151
# architecture: Win32
52-
# runner: windows-latest
52+
# runner: windows-2022
5353
- target: x86_64-pc-windows-msvc/msvc
5454
architecture: x64
55-
runner: windows-latest
55+
runner: windows-2022
5656
# - target: aarch64-pc-windows-msvc/msvc
5757
# architecture: ARM64
58-
# runner: windows-latest
58+
# runner: windows-2022
5959
- target: x86_64-apple-darwin/clang
6060
architecture: x86_64
6161
runner: macos-13

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/long.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
4040
4141
Return a new :c:type:`PyLongObject` object from *v*, or ``NULL`` on failure.
4242
43-
The current implementation keeps an array of integer objects for all integers
44-
between ``-5`` and ``256``. When you create an int in that range you actually
45-
just get back a reference to the existing object.
43+
.. impl-detail::
44+
45+
CPython keeps an array of integer objects for all integers
46+
between ``-5`` and ``256``. When you create an int in that range
47+
you actually just get back a reference to the existing object.
4648
4749
4850
.. c:function:: PyObject* PyLong_FromUnsignedLong(unsigned long v)

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/codecs.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,21 @@ The full details for each codec can also be looked up directly:
6868
Looks up the codec info in the Python codec registry and returns a
6969
:class:`CodecInfo` object as defined below.
7070

71-
Encodings are first looked up in the registry's cache. If not found, the list of
71+
This function first normalizes the *encoding*: all ASCII letters are
72+
converted to lower case, spaces are replaced with hyphens.
73+
Then encoding is looked up in the registry's cache. If not found, the list of
7274
registered search functions is scanned. If no :class:`CodecInfo` object is
7375
found, a :exc:`LookupError` is raised. Otherwise, the :class:`CodecInfo` object
7476
is stored in the cache and returned to the caller.
7577

78+
.. versionchanged:: 3.9
79+
Any characters except ASCII letters and digits and a dot are converted to underscore.
80+
81+
.. versionchanged:: next
82+
No characters are converted to underscore anymore.
83+
Spaces are converted to hyphens.
84+
85+
7686
.. class:: CodecInfo(encode, decode, streamreader=None, streamwriter=None, incrementalencoder=None, incrementaldecoder=None, name=None)
7787

7888
Codec details when looking up the codec registry. The constructor
@@ -167,14 +177,11 @@ function:
167177
.. function:: register(search_function, /)
168178

169179
Register a codec search function. Search functions are expected to take one
170-
argument, being the encoding name in all lower case letters with hyphens
171-
and spaces converted to underscores, and return a :class:`CodecInfo` object.
180+
argument, being the encoding name in all lower case letters with spaces
181+
converted to hyphens, and return a :class:`CodecInfo` object.
172182
In case a search function cannot find a given encoding, it should return
173183
``None``.
174184

175-
.. versionchanged:: 3.9
176-
Hyphens and spaces are converted to underscore.
177-
178185

179186
.. function:: unregister(search_function, /)
180187

@@ -1065,7 +1072,7 @@ or with dictionaries as mapping tables. The following table lists the codecs by
10651072
name, together with a few common aliases, and the languages for which the
10661073
encoding is likely used. Neither the list of aliases nor the list of languages
10671074
is meant to be exhaustive. Notice that spelling alternatives that only differ in
1068-
case or use a hyphen instead of an underscore are also valid aliases
1075+
case or use a space or a hyphen instead of an underscore are also valid aliases
10691076
because they are equivalent when normalized by
10701077
:func:`~encodings.normalize_encoding`. For example, ``'utf-8'`` is a valid
10711078
alias for the ``'utf_8'`` codec.

0 commit comments

Comments
 (0)