Skip to content

Commit 94f656b

Browse files
authored
Merge branch 'main' into docs/capi/expat-141004
2 parents cba5d4c + dbe4090 commit 94f656b

31 files changed

+352
-76
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,6 @@ C API for extension modules
123123

124124
.. toctree::
125125

126+
curses.rst
126127
datetime.rst
127-
expat.rst
128+
expat.rst

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,23 @@ For convenience, some of these functions will always return a
331331
use.
332332
333333
334+
.. c:function:: PyObject *PyErr_ProgramTextObject(PyObject *filename, int lineno)
335+
336+
Get the source line in *filename* at line *lineno*. *filename* should be a
337+
Python :class:`str` object.
338+
339+
On success, this function returns a Python string object with the found line.
340+
On failure, this function returns ``NULL`` without an exception set.
341+
342+
343+
.. c:function:: PyObject *PyErr_ProgramText(const char *filename, int lineno)
344+
345+
Similar to :c:func:`PyErr_ProgramTextObject`, but *filename* is a
346+
:c:expr:`const char *`, which is decoded with the
347+
:term:`filesystem encoding and error handler`, instead of a
348+
Python object reference.
349+
350+
334351
Issuing warnings
335352
================
336353

Doc/c-api/intro.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,32 @@ complete listing.
233233

234234
.. versionadded:: 3.4
235235

236+
.. c:macro:: Py_BUILD_ASSERT(cond)
237+
238+
Asserts a compile-time condition *cond*, as a statement.
239+
The build will fail if the condition is false or cannot be evaluated at compile time.
240+
241+
For example::
242+
243+
Py_BUILD_ASSERT(sizeof(PyTime_t) == sizeof(int64_t));
244+
245+
.. versionadded:: 3.3
246+
247+
.. c:macro:: Py_BUILD_ASSERT_EXPR(cond)
248+
249+
Asserts a compile-time condition *cond*, as an expression that evaluates to ``0``.
250+
The build will fail if the condition is false or cannot be evaluated at compile time.
251+
252+
For example::
253+
254+
#define foo_to_char(foo) \
255+
((char *)(foo) + Py_BUILD_ASSERT_EXPR(offsetof(struct foo, string) == 0))
256+
257+
.. versionadded:: 3.3
258+
236259
.. c:macro:: PyDoc_STRVAR(name, str)
237260
238-
Creates a variable with name ``name`` that can be used in docstrings.
261+
Creates a variable with name *name* that can be used in docstrings.
239262
If Python is built without docstrings, the value will be empty.
240263

241264
Use :c:macro:`PyDoc_STRVAR` for docstrings to support building
@@ -267,6 +290,15 @@ complete listing.
267290
{NULL, NULL}
268291
};
269292

293+
.. c:macro:: PyDoc_VAR(name)
294+
295+
Declares a static character array variable with the given name *name*.
296+
297+
For example::
298+
299+
PyDoc_VAR(python_doc) = PyDoc_STR("A genus of constricting snakes in the Pythonidae family native "
300+
"to the tropics and subtropics of the Eastern Hemisphere.");
301+
270302

271303
.. _api-objects:
272304

Doc/c-api/weakref.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ as much as it can.
1919
2020
.. c:function:: int PyWeakref_CheckRef(PyObject *ob)
2121
22-
Return non-zero if *ob* is a reference object. This function always succeeds.
22+
Return non-zero if *ob* is a reference object or a subclass of the reference
23+
type. This function always succeeds.
24+
25+
26+
.. c:function:: int PyWeakref_CheckRefExact(PyObject *ob)
27+
28+
Return non-zero if *ob* is a reference object, but not a subclass of the
29+
reference type. This function always succeeds.
2330
2431
2532
.. c:function:: int PyWeakref_CheckProxy(PyObject *ob)

Doc/conf.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,6 @@
250250
# Temporary undocumented names.
251251
# In future this list must be empty.
252252
nitpick_ignore += [
253-
# Undocumented public C macros
254-
('c:macro', 'Py_BUILD_ASSERT'),
255-
('c:macro', 'Py_BUILD_ASSERT_EXPR'),
256253
# Do not error nit-picky mode builds when _SubParsersAction.add_parser cannot
257254
# be resolved, as the method is currently undocumented. For context, see
258255
# https://github.com/python/cpython/pull/103289.

Doc/deprecations/pending-removal-in-3.17.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Pending removal in Python 3.17
2323
(Contributed by Shantanu Jain in :gh:`91896`.)
2424

2525

26+
* :mod:`encodings`:
27+
28+
- Passing non-ascii *encoding* names to :func:`encodings.normalize_encoding`
29+
is deprecated and scheduled for removal in Python 3.17.
30+
(Contributed by Stan Ulbrych in :gh:`136702`)
31+
2632
* :mod:`typing`:
2733

2834
- Before Python 3.14, old-style unions were implemented using the private class

Doc/library/asyncio-task.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,8 @@ Task Object
12211221

12221222
To cancel a running Task use the :meth:`cancel` method. Calling it
12231223
will cause the Task to throw a :exc:`CancelledError` exception into
1224-
the wrapped coroutine. If a coroutine is awaiting on a Future
1225-
object during cancellation, the Future object will be cancelled.
1224+
the wrapped coroutine. If a coroutine is awaiting on a future-like
1225+
object during cancellation, the awaited object will be cancelled.
12261226

12271227
:meth:`cancelled` can be used to check if the Task was cancelled.
12281228
The method returns ``True`` if the wrapped coroutine did not
@@ -1411,6 +1411,10 @@ Task Object
14111411
the cancellation, it needs to call :meth:`Task.uncancel` in addition
14121412
to catching the exception.
14131413

1414+
If the Task being cancelled is currently awaiting on a future-like
1415+
object, that awaited object will also be cancelled. This cancellation
1416+
propagates down the entire chain of awaited objects.
1417+
14141418
.. versionchanged:: 3.9
14151419
Added the *msg* parameter.
14161420

0 commit comments

Comments
 (0)