Skip to content

Commit 019117e

Browse files
authored
Merge branch 'main' into document-Py_INFINITY/141004
2 parents 33bbedc + 86513f6 commit 019117e

File tree

94 files changed

+1601
-391
lines changed

Some content is hidden

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

94 files changed

+1601
-391
lines changed

Doc/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ dist-pdf:
241241
# as otherwise the full latexmk process is run twice.
242242
# ($$ is needed to escape the $; https://www.gnu.org/software/make/manual/make.html#Basics-of-Variable-References)
243243
-sed -i 's/: all-$$(FMT)/:/' build/latex/Makefile
244-
(cd build/latex; $(MAKE) clean && $(MAKE) --jobs=$$((`nproc`+1)) --output-sync LATEXMKOPTS='-quiet' all-pdf && $(MAKE) FMT=pdf zip bz2)
244+
if [ -n "$(filter output-sync,$(value .FEATURES))" ]; then OUTPUTSYNC=--output-sync; else OUTPUTSYNC=; fi && \
245+
(cd build/latex; $(MAKE) clean && $(MAKE) --jobs=$$((`getconf _NPROCESSORS_ONLN`+1)) $$OUTPUTSYNC LATEXMKOPTS='-quiet' all-pdf && $(MAKE) FMT=pdf zip bz2)
245246
cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-a4.zip
246247
cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2
247248
@echo "Build finished and archived!"

Doc/c-api/allocation.rst

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ Allocating Objects on the Heap
140140
* :c:member:`~PyTypeObject.tp_alloc`
141141

142142

143-
.. c:function:: void PyObject_Del(void *op)
144-
145-
Same as :c:func:`PyObject_Free`.
146-
147143
.. c:var:: PyObject _Py_NoneStruct
148144
149145
Object which is visible in Python as ``None``. This should only be accessed
@@ -156,3 +152,35 @@ Allocating Objects on the Heap
156152
:ref:`moduleobjects`
157153
To allocate and create extension modules.
158154

155+
156+
Deprecated aliases
157+
^^^^^^^^^^^^^^^^^^
158+
159+
These are :term:`soft deprecated` aliases to existing functions and macros.
160+
They exist solely for backwards compatibility.
161+
162+
163+
.. list-table::
164+
:widths: auto
165+
:header-rows: 1
166+
167+
* * Deprecated alias
168+
* Function
169+
* * .. c:macro:: PyObject_NEW(type, typeobj)
170+
* :c:macro:`PyObject_New`
171+
* * .. c:macro:: PyObject_NEW_VAR(type, typeobj, n)
172+
* :c:macro:`PyObject_NewVar`
173+
* * .. c:macro:: PyObject_INIT(op, typeobj)
174+
* :c:func:`PyObject_Init`
175+
* * .. c:macro:: PyObject_INIT_VAR(op, typeobj, n)
176+
* :c:func:`PyObject_InitVar`
177+
* * .. c:macro:: PyObject_MALLOC(n)
178+
* :c:func:`PyObject_Malloc`
179+
* * .. c:macro:: PyObject_REALLOC(p, n)
180+
* :c:func:`PyObject_Realloc`
181+
* * .. c:macro:: PyObject_FREE(p)
182+
* :c:func:`PyObject_Free`
183+
* * .. c:macro:: PyObject_DEL(p)
184+
* :c:func:`PyObject_Free`
185+
* * .. c:macro:: PyObject_Del(p)
186+
* :c:func:`PyObject_Free`

Doc/c-api/buffer.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ readonly, format
261261
MUST be consistent for all consumers. For example, :c:expr:`PyBUF_SIMPLE | PyBUF_WRITABLE`
262262
can be used to request a simple writable buffer.
263263

264+
.. c:macro:: PyBUF_WRITEABLE
265+
266+
This is a :term:`soft deprecated` alias to :c:macro:`PyBUF_WRITABLE`.
267+
264268
.. c:macro:: PyBUF_FORMAT
265269
266270
Controls the :c:member:`~Py_buffer.format` field. If set, this field MUST

Doc/c-api/capsule.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Refer to :ref:`using-capsules` for more information on using these objects.
2222
loaded modules.
2323

2424

25+
.. c:var:: PyTypeObject PyCapsule_Type
26+
27+
The type object corresponding to capsule objects. This is the same object
28+
as :class:`types.CapsuleType` in the Python layer.
29+
30+
2531
.. c:type:: PyCapsule_Destructor
2632
2733
The type of a destructor callback for a capsule. Defined as::

Doc/c-api/concrete.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,13 @@ Other Objects
115115
gen.rst
116116
coro.rst
117117
contextvars.rst
118-
datetime.rst
119118
typehints.rst
119+
120+
121+
C API for extension modules
122+
===========================
123+
124+
.. toctree::
125+
126+
curses.rst
127+
datetime.rst

Doc/c-api/conversion.rst

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,28 @@ The following functions provide locale-independent string to number conversions.
128128
must be 0 and is ignored. The ``'r'`` format code specifies the
129129
standard :func:`repr` format.
130130
131-
*flags* can be zero or more of the values ``Py_DTSF_SIGN``,
132-
``Py_DTSF_ADD_DOT_0``, or ``Py_DTSF_ALT``, or-ed together:
131+
*flags* can be zero or more of the following values or-ed together:
133132
134-
* ``Py_DTSF_SIGN`` means to always precede the returned string with a sign
135-
character, even if *val* is non-negative.
133+
.. c:macro:: Py_DTSF_SIGN
136134
137-
* ``Py_DTSF_ADD_DOT_0`` means to ensure that the returned string will not look
138-
like an integer.
135+
Always precede the returned string with a sign
136+
character, even if *val* is non-negative.
139137
140-
* ``Py_DTSF_ALT`` means to apply "alternate" formatting rules. See the
141-
documentation for the :c:func:`PyOS_snprintf` ``'#'`` specifier for
142-
details.
138+
.. c:macro:: Py_DTSF_ADD_DOT_0
139+
140+
Ensure that the returned string will not look like an integer.
141+
142+
.. c:macro:: Py_DTSF_ALT
143+
144+
Apply "alternate" formatting rules.
145+
See the documentation for the :c:func:`PyOS_snprintf` ``'#'`` specifier for
146+
details.
147+
148+
.. c:macro:: Py_DTSF_NO_NEG_0
149+
150+
Negative zero is converted to positive zero.
151+
152+
.. versionadded:: 3.11
143153
144154
If *ptype* is non-``NULL``, then the value it points to will be set to one of
145155
``Py_DTST_FINITE``, ``Py_DTST_INFINITE``, or ``Py_DTST_NAN``, signifying that
@@ -162,3 +172,58 @@ The following functions provide locale-independent string to number conversions.
162172
163173
Case insensitive comparison of strings. The function works almost
164174
identically to :c:func:`!strncmp` except that it ignores the case.
175+
176+
177+
Character classification and conversion
178+
=======================================
179+
180+
The following macros provide locale-independent (unlike the C standard library
181+
``ctype.h``) character classification and conversion.
182+
The argument must be a signed or unsigned :c:expr:`char`.
183+
184+
185+
.. c:macro:: Py_ISALNUM(c)
186+
187+
Return true if the character *c* is an alphanumeric character.
188+
189+
190+
.. c:macro:: Py_ISALPHA(c)
191+
192+
Return true if the character *c* is an alphabetic character (``a-z`` and ``A-Z``).
193+
194+
195+
.. c:macro:: Py_ISDIGIT(c)
196+
197+
Return true if the character *c* is a decimal digit (``0-9``).
198+
199+
200+
.. c:macro:: Py_ISLOWER(c)
201+
202+
Return true if the character *c* is a lowercase ASCII letter (``a-z``).
203+
204+
205+
.. c:macro:: Py_ISUPPER(c)
206+
207+
Return true if the character *c* is an uppercase ASCII letter (``A-Z``).
208+
209+
210+
.. c:macro:: Py_ISSPACE(c)
211+
212+
Return true if the character *c* is a whitespace character (space, tab,
213+
carriage return, newline, vertical tab, or form feed).
214+
215+
216+
.. c:macro:: Py_ISXDIGIT(c)
217+
218+
Return true if the character *c* is a hexadecimal digit (``0-9``, ``a-f``, and
219+
``A-F``).
220+
221+
222+
.. c:macro:: Py_TOLOWER(c)
223+
224+
Return the lowercase equivalent of the character *c*.
225+
226+
227+
.. c:macro:: Py_TOUPPER(c)
228+
229+
Return the uppercase equivalent of the character *c*.

Doc/c-api/curses.rst

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
.. highlight:: c
2+
3+
Curses C API
4+
------------
5+
6+
:mod:`curses` exposes a small C interface for extension modules.
7+
Consumers must include the header file :file:`py_curses.h` (which is not
8+
included by default by :file:`Python.h`) and :c:func:`import_curses` must
9+
be invoked, usually as part of the module initialisation function, to populate
10+
:c:var:`PyCurses_API`.
11+
12+
.. warning::
13+
14+
Neither the C API nor the pure Python :mod:`curses` module are compatible
15+
with subinterpreters.
16+
17+
.. c:macro:: import_curses()
18+
19+
Import the curses C API. The macro does not need a semi-colon to be called.
20+
21+
On success, populate the :c:var:`PyCurses_API` pointer.
22+
23+
On failure, set :c:var:`PyCurses_API` to NULL and set an exception.
24+
The caller must check if an error occurred via :c:func:`PyErr_Occurred`:
25+
26+
.. code-block::
27+
28+
import_curses(); // semi-colon is optional but recommended
29+
if (PyErr_Occurred()) { /* cleanup */ }
30+
31+
32+
.. c:var:: void **PyCurses_API
33+
34+
Dynamically allocated object containing the curses C API.
35+
This variable is only available once :c:macro:`import_curses` succeeds.
36+
37+
``PyCurses_API[0]`` corresponds to :c:data:`PyCursesWindow_Type`.
38+
39+
``PyCurses_API[1]``, ``PyCurses_API[2]``, and ``PyCurses_API[3]``
40+
are pointers to predicate functions of type ``int (*)(void)``.
41+
42+
When called, these predicates return whether :func:`curses.setupterm`,
43+
:func:`curses.initscr`, and :func:`curses.start_color` have been called
44+
respectively.
45+
46+
See also the convenience macros :c:macro:`PyCursesSetupTermCalled`,
47+
:c:macro:`PyCursesInitialised`, and :c:macro:`PyCursesInitialisedColor`.
48+
49+
.. note::
50+
51+
The number of entries in this structure is subject to changes.
52+
Consider using :c:macro:`PyCurses_API_pointers` to check if
53+
new fields are available or not.
54+
55+
56+
.. c:macro:: PyCurses_API_pointers
57+
58+
The number of accessible fields (``4``) in :c:var:`PyCurses_API`.
59+
This number is incremented whenever new fields are added.
60+
61+
62+
.. c:var:: PyTypeObject PyCursesWindow_Type
63+
64+
The :ref:`heap type <heap-types>` corresponding to :class:`curses.window`.
65+
66+
67+
.. c:function:: int PyCursesWindow_Check(PyObject *op)
68+
69+
Return true if *op* is a :class:`curses.window` instance, false otherwise.
70+
71+
72+
The following macros are convenience macros expanding into C statements.
73+
In particular, they can only be used as ``macro;`` or ``macro``, but not
74+
``macro()`` or ``macro();``.
75+
76+
.. c:macro:: PyCursesSetupTermCalled
77+
78+
Macro checking if :func:`curses.setupterm` has been called.
79+
80+
The macro expansion is roughly equivalent to:
81+
82+
.. code-block::
83+
84+
{
85+
typedef int (*predicate_t)(void);
86+
predicate_t was_setupterm_called = (predicate_t)PyCurses_API[1];
87+
if (!was_setupterm_called()) {
88+
return NULL;
89+
}
90+
}
91+
92+
93+
.. c:macro:: PyCursesInitialised
94+
95+
Macro checking if :func:`curses.initscr` has been called.
96+
97+
The macro expansion is roughly equivalent to:
98+
99+
.. code-block::
100+
101+
{
102+
typedef int (*predicate_t)(void);
103+
predicate_t was_initscr_called = (predicate_t)PyCurses_API[2];
104+
if (!was_initscr_called()) {
105+
return NULL;
106+
}
107+
}
108+
109+
110+
.. c:macro:: PyCursesInitialisedColor
111+
112+
Macro checking if :func:`curses.start_color` has been called.
113+
114+
The macro expansion is roughly equivalent to:
115+
116+
.. code-block::
117+
118+
{
119+
typedef int (*predicate_t)(void);
120+
predicate_t was_start_color_called = (predicate_t)PyCurses_API[3];
121+
if (!was_start_color_called()) {
122+
return NULL;
123+
}
124+
}
125+
126+
127+
Internal data
128+
-------------
129+
130+
The following objects are exposed by the C API but should be considered
131+
internal-only.
132+
133+
.. c:macro:: PyCurses_CAPSULE_NAME
134+
135+
Name of the curses capsule to pass to :c:func:`PyCapsule_Import`.
136+
137+
Internal usage only. Use :c:macro:`import_curses` instead.
138+

Doc/c-api/descriptor.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,45 @@ found in the dictionary of type objects.
3838
3939
4040
.. c:function:: PyObject* PyWrapper_New(PyObject *, PyObject *)
41+
42+
43+
Built-in descriptors
44+
^^^^^^^^^^^^^^^^^^^^
45+
46+
.. c:var:: PyTypeObject PySuper_Type
47+
48+
The type object for super objects. This is the same object as
49+
:class:`super` in the Python layer.
50+
51+
52+
.. c:var:: PyTypeObject PyClassMethod_Type
53+
54+
The type of class method objects. This is the same object as
55+
:class:`classmethod` in the Python layer.
56+
57+
58+
.. c:function:: PyObject *PyClassMethod_New(PyObject *callable)
59+
60+
Create a new :class:`classmethod` object wrapping *callable*.
61+
*callable* must be a callable object and must not be ``NULL``.
62+
63+
On success, this function returns a :term:`strong reference` to a new class
64+
method descriptor. On failure, this function returns ``NULL`` with an
65+
exception set.
66+
67+
68+
.. c:var:: PyTypeObject PyStaticMethod_Type
69+
70+
The type of static method objects. This is the same object as
71+
:class:`staticmethod` in the Python layer.
72+
73+
74+
.. c:function:: PyObject *PyStaticMethod_New(PyObject *callable)
75+
76+
Create a new :class:`staticmethod` object wrapping *callable*.
77+
*callable* must be a callable object and must not be ``NULL``.
78+
79+
On success, this function returns a :term:`strong reference` to a new static
80+
method descriptor. On failure, this function returns ``NULL`` with an
81+
exception set.
82+

0 commit comments

Comments
 (0)