Skip to content

Commit f7cc646

Browse files
committed
Deploying to gh-pages from @ f6cec66 🚀
1 parent 3749ca0 commit f7cc646

File tree

584 files changed

+2128
-921
lines changed

Some content is hidden

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

584 files changed

+2128
-921
lines changed

_sources/c-api/allocation.rst.txt

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`

_sources/c-api/buffer.rst.txt

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

_sources/c-api/concrete.rst.txt

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

_sources/c-api/curses.rst.txt

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+

_sources/c-api/exceptions.rst.txt

Lines changed: 60 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
@@ -394,6 +411,15 @@ an error value).
394411
.. versionadded:: 3.2
395412
396413
414+
.. c:function:: int PyErr_WarnExplicitFormat(PyObject *category, const char *filename, int lineno, const char *module, PyObject *registry, const char *format, ...)
415+
416+
Similar to :c:func:`PyErr_WarnExplicit`, but uses
417+
:c:func:`PyUnicode_FromFormat` to format the warning message. *format* is
418+
an ASCII-encoded string.
419+
420+
.. versionadded:: 3.2
421+
422+
397423
.. c:function:: int PyErr_ResourceWarning(PyObject *source, Py_ssize_t stack_level, const char *format, ...)
398424
399425
Function similar to :c:func:`PyErr_WarnFormat`, but *category* is
@@ -1228,3 +1254,37 @@ Warning types
12281254
12291255
.. versionadded:: 3.10
12301256
:c:data:`PyExc_EncodingWarning`.
1257+
1258+
1259+
Tracebacks
1260+
==========
1261+
1262+
.. c:var:: PyTypeObject PyTraceBack_Type
1263+
1264+
Type object for traceback objects. This is available as
1265+
:class:`types.TracebackType` in the Python layer.
1266+
1267+
1268+
.. c:function:: int PyTraceBack_Check(PyObject *op)
1269+
1270+
Return true if *op* is a traceback object, false otherwise. This function
1271+
does not account for subtypes.
1272+
1273+
1274+
.. c:function:: int PyTraceBack_Here(PyFrameObject *f)
1275+
1276+
Replace the :attr:`~BaseException.__traceback__` attribute on the current
1277+
exception with a new traceback prepending *f* to the existing chain.
1278+
1279+
Calling this function without an exception set is undefined behavior.
1280+
1281+
This function returns ``0`` on success, and returns ``-1`` with an
1282+
exception set on failure.
1283+
1284+
1285+
.. c:function:: int PyTraceBack_Print(PyObject *tb, PyObject *f)
1286+
1287+
Write the traceback *tb* into the file *f*.
1288+
1289+
This function returns ``0`` on success, and returns ``-1`` with an
1290+
exception set on failure.

0 commit comments

Comments
 (0)