Skip to content

Commit 1d9d7b4

Browse files
committed
Deploying to gh-pages from @ cbe9d02 🚀
1 parent 409b752 commit 1d9d7b4

File tree

825 files changed

+79086
-39733
lines changed

Some content is hidden

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

825 files changed

+79086
-39733
lines changed

.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 53b1d72fa8dd5b628c5bce15e491c5e4
3+
config: 72c96231f81f6934f059b068a0617190
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

_sources/bugs.rst.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@ Documentation bugs
1616
==================
1717

1818
If you find a bug in this documentation or would like to propose an improvement,
19-
please submit a bug report on the :ref:`tracker <using-the-tracker>`. If you
19+
please submit a bug report on the :ref:`issue tracker <using-the-tracker>`. If you
2020
have a suggestion on how to fix it, include that as well.
2121

2222
You can also open a discussion item on our
2323
`Documentation Discourse forum <https://discuss.python.org/c/documentation/26>`_.
2424

2525
If you find a bug in the theme (HTML / CSS / JavaScript) of the
26-
documentation, please submit a bug report on the `python-doc-theme bug
26+
documentation, please submit a bug report on the `python-doc-theme issue
2727
tracker <https://github.com/python/python-docs-theme>`_.
2828

29-
If you're short on time, you can also email documentation bug reports to
30-
docs@python.org (behavioral bugs can be sent to python-list@python.org).
31-
'docs@' is a mailing list run by volunteers; your request will be noticed,
32-
though it may take a while to be processed.
33-
3429
.. seealso::
3530

3631
`Documentation bugs`_

_sources/c-api/allocation.rst.txt

Lines changed: 107 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,133 @@ Allocating Objects on the Heap
1616
1717
Initialize a newly allocated object *op* with its type and initial
1818
reference. Returns the initialized object. Other fields of the object are
19-
not affected.
19+
not initialized. Despite its name, this function is unrelated to the
20+
object's :meth:`~object.__init__` method (:c:member:`~PyTypeObject.tp_init`
21+
slot). Specifically, this function does **not** call the object's
22+
:meth:`!__init__` method.
23+
24+
In general, consider this function to be a low-level routine. Use
25+
:c:member:`~PyTypeObject.tp_alloc` where possible.
26+
For implementing :c:member:`!tp_alloc` for your type, prefer
27+
:c:func:`PyType_GenericAlloc` or :c:func:`PyObject_New`.
28+
29+
.. note::
30+
31+
This function only initializes the object's memory corresponding to the
32+
initial :c:type:`PyObject` structure. It does not zero the rest.
2033
2134
2235
.. c:function:: PyVarObject* PyObject_InitVar(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)
2336
2437
This does everything :c:func:`PyObject_Init` does, and also initializes the
2538
length information for a variable-size object.
2639
40+
.. note::
41+
42+
This function only initializes some of the object's memory. It does not
43+
zero the rest.
44+
2745
2846
.. c:macro:: PyObject_New(TYPE, typeobj)
2947
30-
Allocate a new Python object using the C structure type *TYPE*
31-
and the Python type object *typeobj* (``PyTypeObject*``).
32-
Fields not defined by the Python object header are not initialized.
33-
The caller will own the only reference to the object
34-
(i.e. its reference count will be one).
35-
The size of the memory allocation is determined from the
36-
:c:member:`~PyTypeObject.tp_basicsize` field of the type object.
48+
Allocates a new Python object using the C structure type *TYPE* and the
49+
Python type object *typeobj* (``PyTypeObject*``) by calling
50+
:c:func:`PyObject_Malloc` to allocate memory and initializing it like
51+
:c:func:`PyObject_Init`. The caller will own the only reference to the
52+
object (i.e. its reference count will be one).
53+
54+
Avoid calling this directly to allocate memory for an object; call the type's
55+
:c:member:`~PyTypeObject.tp_alloc` slot instead.
56+
57+
When populating a type's :c:member:`~PyTypeObject.tp_alloc` slot,
58+
:c:func:`PyType_GenericAlloc` is preferred over a custom function that
59+
simply calls this macro.
60+
61+
This macro does not call :c:member:`~PyTypeObject.tp_alloc`,
62+
:c:member:`~PyTypeObject.tp_new` (:meth:`~object.__new__`), or
63+
:c:member:`~PyTypeObject.tp_init` (:meth:`~object.__init__`).
64+
65+
This cannot be used for objects with :c:macro:`Py_TPFLAGS_HAVE_GC` set in
66+
:c:member:`~PyTypeObject.tp_flags`; use :c:macro:`PyObject_GC_New` instead.
67+
68+
Memory allocated by this macro must be freed with :c:func:`PyObject_Free`
69+
(usually called via the object's :c:member:`~PyTypeObject.tp_free` slot).
70+
71+
.. note::
72+
73+
The returned memory is not guaranteed to have been completely zeroed
74+
before it was initialized.
75+
76+
.. note::
77+
78+
This macro does not construct a fully initialized object of the given
79+
type; it merely allocates memory and prepares it for further
80+
initialization by :c:member:`~PyTypeObject.tp_init`. To construct a
81+
fully initialized object, call *typeobj* instead. For example::
82+
83+
PyObject *foo = PyObject_CallNoArgs((PyObject *)&PyFoo_Type);
3784
38-
Note that this function is unsuitable if *typeobj* has
39-
:c:macro:`Py_TPFLAGS_HAVE_GC` set. For such objects,
40-
use :c:func:`PyObject_GC_New` instead.
85+
.. seealso::
86+
87+
* :c:func:`PyObject_Free`
88+
* :c:macro:`PyObject_GC_New`
89+
* :c:func:`PyType_GenericAlloc`
90+
* :c:member:`~PyTypeObject.tp_alloc`
4191

4292

4393
.. c:macro:: PyObject_NewVar(TYPE, typeobj, size)
4494
45-
Allocate a new Python object using the C structure type *TYPE* and the
46-
Python type object *typeobj* (``PyTypeObject*``).
47-
Fields not defined by the Python object header
48-
are not initialized. The allocated memory allows for the *TYPE* structure
49-
plus *size* (``Py_ssize_t``) fields of the size
50-
given by the :c:member:`~PyTypeObject.tp_itemsize` field of
51-
*typeobj*. This is useful for implementing objects like tuples, which are
52-
able to determine their size at construction time. Embedding the array of
53-
fields into the same allocation decreases the number of allocations,
54-
improving the memory management efficiency.
95+
Like :c:macro:`PyObject_New` except:
5596

56-
Note that this function is unsuitable if *typeobj* has
57-
:c:macro:`Py_TPFLAGS_HAVE_GC` set. For such objects,
58-
use :c:func:`PyObject_GC_NewVar` instead.
97+
* It allocates enough memory for the *TYPE* structure plus *size*
98+
(``Py_ssize_t``) fields of the size given by the
99+
:c:member:`~PyTypeObject.tp_itemsize` field of *typeobj*.
100+
* The memory is initialized like :c:func:`PyObject_InitVar`.
59101

102+
This is useful for implementing objects like tuples, which are able to
103+
determine their size at construction time. Embedding the array of fields
104+
into the same allocation decreases the number of allocations, improving the
105+
memory management efficiency.
60106

61-
.. c:function:: void PyObject_Del(void *op)
107+
Avoid calling this directly to allocate memory for an object; call the type's
108+
:c:member:`~PyTypeObject.tp_alloc` slot instead.
109+
110+
When populating a type's :c:member:`~PyTypeObject.tp_alloc` slot,
111+
:c:func:`PyType_GenericAlloc` is preferred over a custom function that
112+
simply calls this macro.
113+
114+
This cannot be used for objects with :c:macro:`Py_TPFLAGS_HAVE_GC` set in
115+
:c:member:`~PyTypeObject.tp_flags`; use :c:macro:`PyObject_GC_NewVar`
116+
instead.
117+
118+
Memory allocated by this function must be freed with :c:func:`PyObject_Free`
119+
(usually called via the object's :c:member:`~PyTypeObject.tp_free` slot).
120+
121+
.. note::
122+
123+
The returned memory is not guaranteed to have been completely zeroed
124+
before it was initialized.
62125

63-
Releases memory allocated to an object using :c:macro:`PyObject_New` or
64-
:c:macro:`PyObject_NewVar`. This is normally called from the
65-
:c:member:`~PyTypeObject.tp_dealloc` handler specified in the object's type. The fields of
66-
the object should not be accessed after this call as the memory is no
67-
longer a valid Python object.
126+
.. note::
127+
128+
This macro does not construct a fully initialized object of the given
129+
type; it merely allocates memory and prepares it for further
130+
initialization by :c:member:`~PyTypeObject.tp_init`. To construct a
131+
fully initialized object, call *typeobj* instead. For example::
132+
133+
PyObject *list_instance = PyObject_CallNoArgs((PyObject *)&PyList_Type);
134+
135+
.. seealso::
136+
137+
* :c:func:`PyObject_Free`
138+
* :c:macro:`PyObject_GC_NewVar`
139+
* :c:func:`PyType_GenericAlloc`
140+
* :c:member:`~PyTypeObject.tp_alloc`
141+
142+
143+
.. c:function:: void PyObject_Del(void *op)
68144
145+
Same as :c:func:`PyObject_Free`.
69146
70147
.. c:var:: PyObject _Py_NoneStruct
71148

_sources/c-api/apiabiversion.rst.txt

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
API and ABI Versioning
77
***********************
88

9+
10+
Build-time version constants
11+
----------------------------
12+
913
CPython exposes its version number in the following macros.
10-
Note that these correspond to the version code is **built** with,
11-
not necessarily the version used at **run time**.
14+
Note that these correspond to the version code is **built** with.
15+
See :c:var:`Py_Version` for the version used at **run time**.
1216

1317
See :ref:`stable` for a discussion of API and ABI stability across versions.
1418

@@ -37,37 +41,83 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
3741
.. c:macro:: PY_VERSION_HEX
3842
3943
The Python version number encoded in a single integer.
44+
See :c:func:`Py_PACK_FULL_VERSION` for the encoding details.
4045

41-
The underlying version information can be found by treating it as a 32 bit
42-
number in the following manner:
43-
44-
+-------+-------------------------+-------------------------+--------------------------+
45-
| Bytes | Bits (big endian order) | Meaning | Value for ``3.4.1a2`` |
46-
+=======+=========================+=========================+==========================+
47-
| 1 | 1-8 | ``PY_MAJOR_VERSION`` | ``0x03`` |
48-
+-------+-------------------------+-------------------------+--------------------------+
49-
| 2 | 9-16 | ``PY_MINOR_VERSION`` | ``0x04`` |
50-
+-------+-------------------------+-------------------------+--------------------------+
51-
| 3 | 17-24 | ``PY_MICRO_VERSION`` | ``0x01`` |
52-
+-------+-------------------------+-------------------------+--------------------------+
53-
| 4 | 25-28 | ``PY_RELEASE_LEVEL`` | ``0xA`` |
54-
+ +-------------------------+-------------------------+--------------------------+
55-
| | 29-32 | ``PY_RELEASE_SERIAL`` | ``0x2`` |
56-
+-------+-------------------------+-------------------------+--------------------------+
46+
Use this for numeric comparisons, for example,
47+
``#if PY_VERSION_HEX >= ...``.
5748

58-
Thus ``3.4.1a2`` is hexversion ``0x030401a2`` and ``3.10.0`` is
59-
hexversion ``0x030a00f0``.
6049

61-
Use this for numeric comparisons, e.g. ``#if PY_VERSION_HEX >= ...``.
62-
63-
This version is also available via the symbol :c:var:`Py_Version`.
50+
Run-time version
51+
----------------
6452

6553
.. c:var:: const unsigned long Py_Version
6654
67-
The Python runtime version number encoded in a single constant integer, with
68-
the same format as the :c:macro:`PY_VERSION_HEX` macro.
55+
The Python runtime version number encoded in a single constant integer.
56+
See :c:func:`Py_PACK_FULL_VERSION` for the encoding details.
6957
This contains the Python version used at run time.
7058

59+
Use this for numeric comparisons, for example, ``if (Py_Version >= ...)``.
60+
7161
.. versionadded:: 3.11
7262

73-
All the given macros are defined in :source:`Include/patchlevel.h`.
63+
64+
Bit-packing macros
65+
------------------
66+
67+
.. c:function:: uint32_t Py_PACK_FULL_VERSION(int major, int minor, int micro, int release_level, int release_serial)
68+
69+
Return the given version, encoded as a single 32-bit integer with
70+
the following structure:
71+
72+
+------------------+-------+----------------+-----------+--------------------------+
73+
| | No. | | | Example values |
74+
| | of | | +-------------+------------+
75+
| Argument | bits | Bit mask | Bit shift | ``3.4.1a2`` | ``3.10.0`` |
76+
+==================+=======+================+===========+=============+============+
77+
| *major* | 8 | ``0xFF000000`` | 24 | ``0x03`` | ``0x03`` |
78+
+------------------+-------+----------------+-----------+-------------+------------+
79+
| *minor* | 8 | ``0x00FF0000`` | 16 | ``0x04`` | ``0x0A`` |
80+
+------------------+-------+----------------+-----------+-------------+------------+
81+
| *micro* | 8 | ``0x0000FF00`` | 8 | ``0x01`` | ``0x00`` |
82+
+------------------+-------+----------------+-----------+-------------+------------+
83+
| *release_level* | 4 | ``0x000000F0`` | 4 | ``0xA`` | ``0xF`` |
84+
+------------------+-------+----------------+-----------+-------------+------------+
85+
| *release_serial* | 4 | ``0x0000000F`` | 0 | ``0x2`` | ``0x0`` |
86+
+------------------+-------+----------------+-----------+-------------+------------+
87+
88+
For example:
89+
90+
+-------------+------------------------------------+-----------------+
91+
| Version | ``Py_PACK_FULL_VERSION`` arguments | Encoded version |
92+
+=============+====================================+=================+
93+
| ``3.4.1a2`` | ``(3, 4, 1, 0xA, 2)`` | ``0x030401a2`` |
94+
+-------------+------------------------------------+-----------------+
95+
| ``3.10.0`` | ``(3, 10, 0, 0xF, 0)`` | ``0x030a00f0`` |
96+
+-------------+------------------------------------+-----------------+
97+
98+
Out-of range bits in the arguments are ignored.
99+
That is, the macro can be defined as:
100+
101+
.. code-block:: c
102+
103+
#ifndef Py_PACK_FULL_VERSION
104+
#define Py_PACK_FULL_VERSION(X, Y, Z, LEVEL, SERIAL) ( \
105+
(((X) & 0xff) << 24) | \
106+
(((Y) & 0xff) << 16) | \
107+
(((Z) & 0xff) << 8) | \
108+
(((LEVEL) & 0xf) << 4) | \
109+
(((SERIAL) & 0xf) << 0))
110+
#endif
111+
112+
``Py_PACK_FULL_VERSION`` is primarily a macro, intended for use in
113+
``#if`` directives, but it is also available as an exported function.
114+
115+
.. versionadded:: 3.14
116+
117+
.. c:function:: uint32_t Py_PACK_VERSION(int major, int minor)
118+
119+
Equivalent to ``Py_PACK_FULL_VERSION(major, minor, 0, 0, 0)``.
120+
The result does not correspond to any Python release, but is useful
121+
in numeric comparisons.
122+
123+
.. versionadded:: 3.14

_sources/c-api/arg.rst.txt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,19 @@ small to receive the value.
270270
Convert a Python integer to a C :c:expr:`unsigned long` without
271271
overflow checking.
272272

273+
.. versionchanged:: 3.14
274+
Use :meth:`~object.__index__` if available.
275+
273276
``L`` (:class:`int`) [long long]
274277
Convert a Python integer to a C :c:expr:`long long`.
275278

276279
``K`` (:class:`int`) [unsigned long long]
277280
Convert a Python integer to a C :c:expr:`unsigned long long`
278281
without overflow checking.
279282

283+
.. versionchanged:: 3.14
284+
Use :meth:`~object.__index__` if available.
285+
280286
``n`` (:class:`int`) [:c:type:`Py_ssize_t`]
281287
Convert a Python integer to a C :c:type:`Py_ssize_t`.
282288

@@ -357,11 +363,26 @@ Other objects
357363

358364
.. versionadded:: 3.3
359365

360-
``(items)`` (:class:`tuple`) [*matching-items*]
361-
The object must be a Python sequence whose length is the number of format units
366+
``(items)`` (sequence) [*matching-items*]
367+
The object must be a Python sequence (except :class:`str`, :class:`bytes`
368+
or :class:`bytearray`) whose length is the number of format units
362369
in *items*. The C arguments must correspond to the individual format units in
363370
*items*. Format units for sequences may be nested.
364371

372+
If *items* contains format units which store a :ref:`borrowed buffer
373+
<c-arg-borrowed-buffer>` (``s``, ``s#``, ``z``, ``z#``, ``y``, or ``y#``)
374+
or a :term:`borrowed reference` (``S``, ``Y``, ``U``, ``O``, or ``O!``),
375+
the object must be a Python tuple.
376+
The *converter* for the ``O&`` format unit in *items* must not store
377+
a borrowed buffer or a borrowed reference.
378+
379+
.. versionchanged:: 3.14
380+
:class:`str` and :class:`bytearray` objects no longer accepted as a sequence.
381+
382+
.. deprecated:: 3.14
383+
Non-tuple sequences are deprecated if *items* contains format units
384+
which store a borrowed buffer or a borrowed reference.
385+
365386
A few other characters have a meaning in a format string. These may not occur
366387
inside nested parentheses. They are:
367388

@@ -647,6 +668,17 @@ Building values
647668
``n`` (:class:`int`) [:c:type:`Py_ssize_t`]
648669
Convert a C :c:type:`Py_ssize_t` to a Python integer.
649670
671+
``p`` (:class:`bool`) [int]
672+
Convert a C :c:expr:`int` to a Python :class:`bool` object.
673+
674+
Be aware that this format requires an ``int`` argument.
675+
Unlike most other contexts in C, variadic arguments are not coerced to
676+
a suitable type automatically.
677+
You can convert another type (for example, a pointer or a float) to a
678+
suitable ``int`` value using ``(x) ? 1 : 0`` or ``!!x``.
679+
680+
.. versionadded:: 3.14
681+
650682
``c`` (:class:`bytes` of length 1) [char]
651683
Convert a C :c:expr:`int` representing a byte to a Python :class:`bytes` object of
652684
length 1.

_sources/c-api/bytearray.rst.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ Direct API functions
7474
.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
7575
7676
Resize the internal buffer of *bytearray* to *len*.
77+
Failure is a ``-1`` return with an exception set.
78+
79+
.. versionchanged:: 3.14
80+
A negative *len* will now result in an exception being set and -1 returned.
81+
7782
7883
Macros
7984
^^^^^^

0 commit comments

Comments
 (0)