10000 Catch up with main · python/cpython@b4474d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4474d0

Browse files
committed
Catch up with main
2 parents 0bba20f + 2e672f7 commit b4474d0

File tree

87 files changed

+1075
-396
lines changed

Some content is hidden

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

87 files changed

+1075
-396
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ jobs:
454454
uses: hendrikmuhs/ccache-action@v1.2
455455
with:
456456
save: ${{ github.event_name == 'push' }}
457+
max-size: "200M"
457458
- name: Configure CPython
458459
run: ./configure --config-cache --with-address-sanitizer --without-pymalloc
459460
- name: Build CPython

Doc/c-api/structures.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,40 @@ definition with the same method name.
399399
slot. This is helpful because calls to PyCFunctions are optimized more
400400
than wrapper object calls.
401401
402+
.. c:function:: PyObject * PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls)
403+
404+
Turn *ml* into a Python :term:`callable` object.
405+
The caller must ensure that *ml* outlives the :term:`callable`.
406+
Typically, *ml* is defined as a static variable.
407+
408+
The *self* parameter will be passed as the *self* argument
409+
to the C function in ``ml->ml_meth`` when invoked.
410+
*self* can be ``NULL``.
411+
412+
The :term:`callable` object's ``__module__`` attribute
413+
can be set from the given *module* argument.
414+
*module* should be a Python string,
415+
which will be used as name of the module the function is defined in.
416+
If unavailable, it can be set to :const:`None` or ``NULL``.
417+
418+
.. seealso:: :attr:`function.__module__`
419+
420+
The *cls* parameter will be passed as the *defining_class*
421+
argument to the C function.
422+
Must be set if :c:macro:`METH_METHOD` is set on ``ml->ml_flags``.
423+
424+
.. versionadded:: 3.9
425+
426+
427+
.. c:function:: PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
428+
429+
Equivalent to ``PyCMethod_New(ml, self, module, NULL)``.
430+
431+
432+
.. c:function:: PyObject * PyCFunction_New(PyMethodDef *ml, PyObject *self)
433+
434+
Equivalent to ``PyCMethod_New(ml, self, NULL, NULL)``.
435+
402436
403437
Accessing attributes of extension types
404438
---------------------------------------

Doc/copyright.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright
44

55
Python and this documentation is:
66

7-
Copyright © 2001-2023 Python Software Foundation. All rights reserved.
7+
Copyright © 2001-2024 Python Software Foundation. All rights reserved.
88

99
Copyright © 2000 BeOpen.com. All rights reserved.
1010

Doc/data/refcounts.dat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,21 @@ PyContextVar_Reset:int:::
402402
PyContextVar_Reset:PyObject*:var:0:
403403
PyContextVar_Reset:PyObject*:token:-1:
404404

405+
PyCFunction_New:PyObject*::+1:
406+
PyCFunction_New:PyMethodDef*:ml::
407+
PyCFunction_New:PyObject*:self:+1:
408+
409+
PyCFunction_NewEx:PyObject*::+1:
410+
PyCFunction_NewEx:PyMethodDef*:ml::
411+
PyCFunction_NewEx:PyObject*:self:+1:
412+
PyCFunction_NewEx:PyObject*:module:+1:
413+
414+
PyCMethod_New:PyObject*::+1:
415+
PyCMethod_New:PyMethodDef*:ml::
416+
PyCMethod_New:PyObject*:self:+1:
417+
PyCMethod_New:PyObject*:module:+1:
418+
PyCMethod_New:PyObject*:cls:+1:
419+
405420
PyDate_Check:int:::
406421
PyDate_Check:PyObject*:ob:0:
407422

Doc/library/marshal.rst

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ transfer of Python objects through RPC calls, see the modules :mod:`pickle` and
2323
:mod:`shelve`. The :mod:`marshal` module exists mainly to support reading and
2424
writing the "pseudo-compiled" code for Python modules of :file:`.pyc` files.
2525
Therefore, the Python maintainers reserve the right to modify the marshal format
26-
in backward incompatible ways should the need arise. If you're serializing and
26+
in backward incompatible ways should the need arise.
27+
The format of code objects is not compatible between Python versions,
28+
even if the version of the format is the same.
29+
De-serializing a code object in the incorrect Python version has undefined behavior.
30+
If you're serializing and
2731
de-serializing Python objects, use the :mod:`pickle` module instead -- the
2832
performance is comparable, version independence is guaranteed, and pickle
2933
supports a substantially wider range of objects than marshal.
@@ -40,7 +44,8 @@ Not all Python object types are supported; in general, only objects whose value
4044
is independent from a particular invocation of Python can be written and read by
4145
this module. The following types are supported: booleans, integers, floating
4246
point numbers, complex numbers, strings, bytes, bytearrays, tuples, lists, sets,
43-
frozensets, dictionaries, and code objects, where it should be understood that
47+
frozensets, dictionaries, and code objects (if *allow_code* is true),
48+
where it should be understood that
4449
tuples, lists, sets, frozensets and dictionaries are only supported as long as
4550
the values contained therein are themselves supported. The
4651
singletons :const:`None`, :const:`Ellipsis` and :exc:`StopIteration` can also be
@@ -54,27 +59,32 @@ bytes-like objects.
5459
The module defines these functions:
5560

5661

57-
.. function:: dump(value, file[, version])
62+
.. function:: dump(value, file, version=version, /, *, allow_code=True)
5863

5964
Write the value on the open file. The value must be a supported type. The
6065
file must be a writeable :term:`binary file`.
6166

6267
If the value has (or contains an object that has) an unsupported type, a
6368
:exc:`ValueError` exception is raised --- but garbage data will also be written
6469
to the file. The object will not be properly read back by :func:`load`.
70+
:ref:`Code objects <code-objects>` are only supported if *allow_code* is true.
6571

6672
The *version* argument indicates the data format that ``dump`` should use
6773
(see below).
6874

6975
.. audit-event:: marshal.dumps value,version marshal.dump
7076

77+
.. versionchanged:: 3.13
78+
Added the *allow_code* parameter.
7179

72-
.. function:: load(file)
80+
81+
.. function:: load(file, /, *, allow_code=True)
7382

7483
Read one value from the open file and return it. If no valid value is read
7584
(e.g. because the data has a different Python version's incompatible marshal
76-
format), raise :exc:`EOFError`, :exc:`ValueError` or :exc:`TypeError`. The
77-
file must be a readable :term:`binary file`.
85+
format), raise :exc:`EOFError`, :exc:`ValueError` or :exc:`TypeError`.
86+
:ref:`Code objects <code-objects>` are only supported if *allow_code* is true.
87+
The file must be a readable :term:`binary file`.
7888

7989
.. audit-event:: marshal.load "" marshal.load
8090

@@ -88,24 +98,32 @@ The module defines these functions:
8898
This call used to raise a ``code.__new__`` audit event for each code object. Now
8999
it raises a single ``marshal.load`` event for the entire load operation.
90100

101+
.. versionchanged:: 3.13
102+
Added the *allow_code* parameter.
103+
91104

92-
.. function:: dumps(value[, version])
105+
.. function:: dumps(value, version=version, /, *, allow_code=True)
93106

94107
Return the bytes object that would be written to a file by ``dump(value, file)``. The
95108
value must be a supported type. Raise a :exc:`ValueError` exception if value
96109
has (or contains an object that has) an unsupported type.
110+
:ref:`Code objects <code-objects>` are only supported if *allow_code* is true.
97111

98112
The *version* argument indicates the data format that ``dumps`` should use
99113
(see below).
100114

101115
.. audit-event:: marshal.dumps value,version marshal.dump
102116

117+
.. versionchanged:: 3.13
118+
Added the *allow_code* parameter.
103119

104-
.. function:: loads(bytes)
120+
121+
.. function:: loads(bytes, /, *, allow_code=True)
105122

106123
Convert the :term:`bytes-like object` to a value. If no valid value is found, raise
107-
:exc:`EOFError`, :exc:`ValueError` or :exc:`TypeError`. Extra bytes in the
108-
input are ignored.
124+
:exc:`EOFError`, :exc:`ValueError` or :exc:`TypeError`.
125+
:ref:`Code objects <code-objects>` are only supported if *allow_code* is true.
126+
Extra bytes in the input are ignored.
109127

110128
.. audit-event:: marshal.loads bytes marshal.load
111129

@@ -114,6 +132,9 @@ The module defines these functions:
114132
This call used to raise a ``code.__new__`` audit event for each code object. Now
115133
it raises a single ``marshal.loads`` event for the entire load operation.
116134

135+
.. versionchanged:: 3.13
136+
Added the *allow_code* parameter.
137+
117138

118139
In addition, the following constants are defined:
119140

Doc/library/mmap.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ update the underlying file.
4848

4949
To map anonymous memory, -1 should be passed as the fileno along with the length.
5050

51-
.. class:: mmap(fileno, length, tagname=None, access=ACCESS_DEFAULT[, offset])
51+
.. class:: mmap(fileno, length, tagname=None, access=ACCESS_DEFAULT, offset=0)
5252

5353
**(Windows version)** Maps *length* bytes from the file specified by the
5454
file handle *fileno*, and creates a mmap object. If *length* is larger
@@ -71,7 +71,8 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
7171

7272
.. audit-event:: mmap.__new__ fileno,length,access,offset mmap.mmap
7373

74-
.. class:: mmap(fileno, length, flags=MAP_SHARED, prot=PROT_WRITE|PROT_READ, access=ACCESS_DEFAULT[, offset])
74+
.. class:: mmap(fileno, length, flags=MAP_SHARED, prot=PROT_WRITE|PROT_READ, \
75+
access=ACCESS_DEFAULT, offset=0, *, trackfd=True)
7576
:noindex:
7677
7778
**(Unix version)** Maps *length* bytes from the file specified by the file
@@ -102,10 +103,20 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
102103
defaults to 0. *offset* must be a multiple of :const:`ALLOCATIONGRANULARITY`
103104
which is equal to :const:`PAGESIZE` on Unix systems.
104105

106+
If *trackfd* is ``False``, the file descriptor specified by *fileno* will
107+
not be duplicated, and the resulting :class:`!mmap` object will not
108+
be associated with the map's underlying file.
109+
This means that the :meth:`~mmap.mmap.size` and :meth:`~mmap.mmap.resize`
110+
methods will fail.
111+
This mode is useful to limit the number of open file descriptors.
112+
105113
To ensure validity of the created memory mapping the file specified
106114
by the descriptor *fileno* is internally automatically synchronized
107115
with the physical backing store on macOS.
108116

117+
.. versionchanged:: 3.13
118+
The *trackfd* parameter was added.
119+
109120
This example shows a simple way of using :class:`~mmap.mmap`::
110121

111122
import mmap
@@ -254,9 +265,12 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
254265

255266
.. method:: resize(newsize)
256267

257-
Resizes the map and the underlying file, if any. If the mmap was created
258-
with :const:`ACCESS_READ` or :const:`ACCESS_COPY`, resizing the map will
259-
raise a :exc:`TypeError` exception.
268+
Resizes the map and the underlying file, if any.
269+
270+
Resizing a map created with *access* of :const:`ACCESS_READ` or
271+
:const:`ACCESS_COPY`, will raise a :exc:`TypeError` exception.
272+
Resizing a map created with with *trackfd* set to ``False``,
273+
will raise a :exc:`ValueError` exception.
260274

261275
**On Windows**: Resizing the map will raise an :exc:`OSError` if there are other
262276
maps against the same named file. Resizing an anonymous map (ie against the

0 commit comments

Comments
 (0)
0