Skip to content

Commit 01ff2e2

Browse files
gh-141004: Document remaining parts of the public C API (GH-159892)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 796b26b commit 01ff2e2

23 files changed

Lines changed: 393 additions & 105 deletions

‎Doc/c-api/code.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ bound into a function.
176176
177177
.. versionadded:: 3.12
178178
179+
.. c:macro:: PY_FOREACH_CODE_EVENT(V)
180+
181+
Apply the macro *V* to each suffix of :c:type:`PyCodeEvent`
182+
constants.
183+
Currently expands to ``V(CREATE) V(DESTROY)``.
184+
The macro *V* must accept one event name and supply any punctuation
185+
needed between expansions.
186+
179187
.. c:type:: int (*PyCode_WatchCallback)(PyCodeEvent event, PyCodeObject* co)
180188
181189
Type of a code object watcher callback function.

‎Doc/c-api/conversion.rst‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,23 @@ The argument must be a signed or unsigned :c:expr:`char`.
258258
.. c:macro:: Py_TOUPPER(c)
259259
260260
Return the uppercase equivalent of the character *c*.
261+
262+
263+
Bit masks
264+
---------
265+
266+
The following constants are bit masks used by the character classification
267+
macros above:
268+
269+
.. c:macro:: PY_CTF_ALNUM
270+
PY_CTF_ALPHA
271+
PY_CTF_DIGIT
272+
PY_CTF_LOWER
273+
PY_CTF_SPACE
274+
PY_CTF_UPPER
275+
PY_CTF_XDIGIT
276+
277+
Values used internally by the ``Py_IS*`` classification macros above.
278+
Exposed for backwards compatibility only.
279+
280+
.. soft-deprecated:: next

‎Doc/c-api/dict.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,15 @@ Dictionary objects
563563
564564
.. versionadded:: 3.12
565565
566+
.. c:macro:: PY_FOREACH_DICT_EVENT(V)
567+
568+
Apply the macro *V* to each suffix of :c:type:`PyDict_WatchEvent`
569+
constants.
570+
Currently expands to ``V(ADDED) V(MODIFIED) V(DELETED) V(CLONED)
571+
V(CLEARED) V(DEALLOCATED)``.
572+
The macro *V* must accept one event name and supply any punctuation
573+
needed between expansions.
574+
566575
.. c:type:: int (*PyDict_WatchCallback)(PyDict_WatchEvent event, PyObject *dict, PyObject *key, PyObject *new_value)
567576
568577
Type of a dict watcher callback function.

‎Doc/c-api/exceptions.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ an error value).
407407
documentation. There is no C API for warning control.
408408
409409
410+
.. c:function:: int PyErr_Warn(PyObject *category, const char *message)
411+
412+
Equivalent to :c:expr:`PyErr_WarnEx(category, message, 1)`.
413+
414+
410415
.. c:function:: int PyErr_WarnExplicitObject(PyObject *category, PyObject *message, PyObject *filename, int lineno, PyObject *module, PyObject *registry)
411416
412417
Issue a warning message with explicit control over all warning attributes. This

‎Doc/c-api/file.rst‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,30 @@ the :mod:`io` APIs instead.
162162
Soft-deprecated API
163163
^^^^^^^^^^^^^^^^^^^
164164
165-
.. soft-deprecated:: 3.15
166-
167165
These are APIs that were included in Python's C API
168166
by mistake. They are documented solely for completeness; use other
169167
``PyFile*`` APIs instead.
170168
169+
171170
.. c:function:: PyObject *PyFile_NewStdPrinter(int fd)
172171
173172
Use :c:func:`PyFile_FromFd` with defaults (``fd, NULL, "w", -1, NULL, NULL, NULL, 0``) instead.
174173
174+
.. soft-deprecated:: 3.15
175+
176+
175177
.. c:var:: PyTypeObject PyStdPrinter_Type
176178
177179
Type of file-like objects used internally at Python startup when :py:mod:`io` is
178180
not yet available.
179181
Use Python :py:func:`open` or :c:func:`PyFile_FromFd` to create file objects instead.
182+
183+
.. soft-deprecated:: 3.15
184+
185+
186+
.. c:macro:: PY_STDIOTEXTMODE
187+
188+
The string literal ``"b"``, used to open files in binary mode.
189+
Exposed for backwards compatibility only.
190+
191+
.. soft-deprecated:: next

‎Doc/c-api/function.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ There are a few functions specific to Python functions.
197197
198198
.. versionadded:: 3.15
199199
200+
.. c:macro:: PY_FOREACH_FUNC_EVENT(V)
201+
202+
Apply the macro *V* to each suffix of :c:type:`PyFunction_WatchEvent`
203+
constants.
204+
Currently expands to ``V(CREATE) V(DESTROY) V(MODIFY_CODE)
205+
V(MODIFY_DEFAULTS) V(MODIFY_KWDEFAULTS) V(MODIFY_QUALNAME)``.
206+
The macro *V* must accept one event name and supply any punctuation
207+
needed between expansions.
208+
200209
.. c:type:: int (*PyFunction_WatchCallback)(PyFunction_WatchEvent event, PyFunctionObject *func, PyObject *new_value)
201210
202211
Type of a function watcher callback function.

‎Doc/c-api/hash.rst‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.
3232
.. c:macro:: Py_HASH_FNV
3333
Py_HASH_SIPHASH24
3434
Py_HASH_SIPHASH13
35+
Py_HASH_EXTERNAL
3536
3637
Numerical values to compare to :c:macro:`Py_HASH_ALGORITHM` to determine
37-
which algorithm is used for hashing. The hash algorithm can be configured
38-
via the configure :option:`--with-hash-algorithm` option.
38+
which algorithm is used for hashing. The built-in hash algorithm can be
39+
configured via the configure :option:`--with-hash-algorithm` option.
40+
41+
:c:macro:`!Py_HASH_EXTERNAL` has value ``0`` and indicates a hash
42+
implementation supplied by the application embedding Python; see
43+
:c:var:`PyHash_Func`.
3944

4045
.. versionadded:: 3.4
41-
Add :c:macro:`!Py_HASH_FNV` and :c:macro:`!Py_HASH_SIPHASH24`.
46+
Add :c:macro:`!Py_HASH_FNV`, :c:macro:`!Py_HASH_SIPHASH24`, and
47+
:c:macro:`!Py_HASH_EXTERNAL`.
4248

4349
.. versionadded:: 3.11
4450
Add :c:macro:`!Py_HASH_SIPHASH13`.
@@ -132,6 +138,19 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.
132138
.. versionadded:: 3.4
133139

134140

141+
.. c:var:: PyHash_FuncDef PyHash_Func
142+
143+
When Python is built with :c:macro:`Py_HASH_ALGORITHM` set to
144+
:c:macro:`Py_HASH_EXTERNAL`, the application embedding Python must define
145+
this variable to supply a hash implementation instead of using one of
146+
Python's built-in hash algorithms.
147+
148+
.. versionadded:: 3.4
149+
150+
.. deprecated-removed:: 3.15 3.19
151+
Use one of the built-in hash algorithms instead.
152+
153+
135154
.. c:function:: PyHash_FuncDef* PyHash_GetFuncDef(void)
136155
137156
Get the hash function definition.

‎Doc/c-api/intro.rst‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,13 +924,26 @@ use them.
924924
C99 doesn't define such a thing directly (size_t is an unsigned integral type).
925925
See :pep:`353` for details.
926926

927+
928+
.. c:macro:: Py_INVALID_SIZE
929+
930+
A constant of type :c:type:`Py_ssize_t` with value ``-1``, representing an
931+
invalid size.
932+
933+
927934
.. c:macro:: PY_SSIZE_T_MAX
928935
PY_SSIZE_T_MIN
929936
930937
The limit values (largest positive one and smallest negative one,
931938
respecitvely) of type :c:type:`Py_ssize_t`.
932939

933940

941+
.. c:macro:: PY_DWORD_MAX
942+
943+
The maximum value of the Windows ``DWORD`` type.
944+
Expands to ``0xffffffff`` on all platforms.
945+
946+
934947
.. _api-exceptions:
935948

936949
Exceptions

‎Doc/c-api/long.rst‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,21 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
680680
.. versionadded:: 3.12
681681
682682
683+
Build configuration
684+
^^^^^^^^^^^^^^^^^^^
685+
686+
.. c:macro:: PYLONG_BITS_IN_DIGIT
687+
688+
The number of bits in each digit of CPython's native representation of
689+
integers.
690+
The value can currently be either ``30`` (the default) or ``15``,
691+
selected with :option:`--enable-big-digits` when building Python.
692+
693+
To access the native representation of integers, use
694+
:c:func:`PyLong_GetNativeLayout` and its
695+
:c:member:`~PyLongLayout.bits_per_digit` member instead.
696+
697+
683698
Export API
684699
^^^^^^^^^^
685700

‎Doc/c-api/monitoring.rst‎

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,28 +170,56 @@ would typically correspond to a Python function.
170170
.. The table is here to make the docs searchable, and to allow automatic
171171
links to the identifiers.
172172
173-
================================================== =====================================
174-
Macro Event
175-
================================================== =====================================
176-
.. c:macro:: PY_MONITORING_EVENT_BRANCH_LEFT :monitoring-event:`BRANCH_LEFT`
177-
.. c:macro:: PY_MONITORING_EVENT_BRANCH_RIGHT :monitoring-event:`BRANCH_RIGHT`
178-
.. c:macro:: PY_MONITORING_EVENT_CALL :monitoring-event:`CALL`
179-
.. c:macro:: PY_MONITORING_EVENT_C_RAISE :monitoring-event:`C_RAISE`
180-
.. c:macro:: PY_MONITORING_EVENT_C_RETURN :monitoring-event:`C_RETURN`
181-
.. c:macro:: PY_MONITORING_EVENT_EXCEPTION_HANDLED :monitoring-event:`EXCEPTION_HANDLED`
182-
.. c:macro:: PY_MONITORING_EVENT_INSTRUCTION :monitoring-event:`INSTRUCTION`
183-
.. c:macro:: PY_MONITORING_EVENT_JUMP :monitoring-event:`JUMP`
184-
.. c:macro:: PY_MONITORING_EVENT_LINE :monitoring-event:`LINE`
185-
.. c:macro:: PY_MONITORING_EVENT_PY_RESUME :monitoring-event:`PY_RESUME`
186-
.. c:macro:: PY_MONITORING_EVENT_PY_RETURN :monitoring-event:`PY_RETURN`
187-
.. c:macro:: PY_MONITORING_EVENT_PY_START :monitoring-event:`PY_START`
188-
.. c:macro:: PY_MONITORING_EVENT_PY_THROW :monitoring-event:`PY_THROW`
189-
.. c:macro:: PY_MONITORING_EVENT_PY_UNWIND :monitoring-event:`PY_UNWIND`
190-
.. c:macro:: PY_MONITORING_EVENT_PY_YIELD :monitoring-event:`PY_YIELD`
191-
.. c:macro:: PY_MONITORING_EVENT_RAISE :monitoring-event:`RAISE`
192-
.. c:macro:: PY_MONITORING_EVENT_RERAISE :monitoring-event:`RERAISE`
193-
.. c:macro:: PY_MONITORING_EVENT_STOP_ITERATION :monitoring-event:`STOP_ITERATION`
194-
================================================== =====================================
173+
.. list-table::
174+
:header-rows: 1
175+
:widths: 50 37
176+
177+
* - Macro
178+
- Event
179+
* - .. c:macro:: PY_MONITORING_EVENT_BRANCH_LEFT
180+
- :monitoring-event:`BRANCH_LEFT`
181+
* - .. c:macro:: PY_MONITORING_EVENT_BRANCH_RIGHT
182+
- :monitoring-event:`BRANCH_RIGHT`
183+
* - .. c:macro:: PY_MONITORING_EVENT_CALL
184+
- :monitoring-event:`CALL`
185+
* - .. c:macro:: PY_MONITORING_EVENT_C_RAISE
186+
- :monitoring-event:`C_RAISE`
187+
* - .. c:macro:: PY_MONITORING_EVENT_C_RETURN
188+
- :monitoring-event:`C_RETURN`
189+
* - .. c:macro:: PY_MONITORING_EVENT_EXCEPTION_HANDLED
190+
- :monitoring-event:`EXCEPTION_HANDLED`
191+
* - .. c:macro:: PY_MONITORING_EVENT_INSTRUCTION
192+
- :monitoring-event:`INSTRUCTION`
193+
* - .. c:macro:: PY_MONITORING_EVENT_JUMP
194+
- :monitoring-event:`JUMP`
195+
* - .. c:macro:: PY_MONITORING_EVENT_LINE
196+
- :monitoring-event:`LINE`
197+
* - .. c:macro:: PY_MONITORING_EVENT_PY_RESUME
198+
- :monitoring-event:`PY_RESUME`
199+
* - .. c:macro:: PY_MONITORING_EVENT_PY_RETURN
200+
- :monitoring-event:`PY_RETURN`
201+
* - .. c:macro:: PY_MONITORING_EVENT_PY_START
202+
- :monitoring-event:`PY_START`
203+
* - .. c:macro:: PY_MONITORING_EVENT_PY_THROW
204+
- :monitoring-event:`PY_THROW`
205+
* - .. c:macro:: PY_MONITORING_EVENT_PY_UNWIND
206+
- :monitoring-event:`PY_UNWIND`
207+
* - .. c:macro:: PY_MONITORING_EVENT_PY_YIELD
208+
- :monitoring-event:`PY_YIELD`
209+
* - .. c:macro:: PY_MONITORING_EVENT_RAISE
210+
- :monitoring-event:`RAISE`
211+
* - .. c:macro:: PY_MONITORING_EVENT_RERAISE
212+
- :monitoring-event:`RERAISE`
213+
* - .. c:macro:: PY_MONITORING_EVENT_STOP_ITERATION
214+
- :monitoring-event:`STOP_ITERATION`
215+
* - .. c:macro:: PY_MONITORING_EVENT_BRANCH
216+
217+
.. deprecated:: 3.14
218+
Use :c:macro:`PY_MONITORING_EVENT_BRANCH_LEFT`
219+
and :c:macro:`PY_MONITORING_EVENT_BRANCH_RIGHT` instead.
220+
221+
- :monitoring-event:`BRANCH_LEFT` and :monitoring-event:`BRANCH_RIGHT`
222+
195223
196224
.. c:function:: int PyMonitoring_ExitScope(void)
197225

0 commit comments

Comments
 (0)