Skip to content

Commit 6bde1b9

Browse files
[3.11] gh-106919: Use role :c:macro: for referencing the C "constants" (GH-106920) (GH-106952)
(cherry picked from commit fcc816d)
1 parent 0a57620 commit 6bde1b9

Some content is hidden

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

43 files changed

+265
-247
lines changed

Doc/c-api/arg.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ Other objects
380380
*items*. Format units for sequences may be nested.
381381

382382
It is possible to pass "long" integers (integers whose value exceeds the
383-
platform's :const:`LONG_MAX`) however no proper range checking is done --- the
383+
platform's :c:macro:`LONG_MAX`) however no proper range checking is done --- the
384384
most significant bits are silently truncated when the receiving field is too
385385
small to receive the value (actually, the semantics are inherited from downcasts
386386
in C --- your mileage may vary).
@@ -492,7 +492,7 @@ API Functions
492492
493493
A simpler form of parameter retrieval which does not use a format string to
494494
specify the types of the arguments. Functions which use this method to retrieve
495-
their parameters should be declared as :const:`METH_VARARGS` in function or
495+
their parameters should be declared as :c:macro:`METH_VARARGS` in function or
496496
method tables. The tuple containing the actual parameters should be passed as
497497
*args*; it must actually be a tuple. The length of the tuple must be at least
498498
*min* and no more than *max*; *min* and *max* may be equal. Additional

Doc/c-api/call.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ the arguments to an args tuple and kwargs dict anyway, then there is no point
6363
in implementing vectorcall.
6464

6565
Classes can implement the vectorcall protocol by enabling the
66-
:const:`Py_TPFLAGS_HAVE_VECTORCALL` flag and setting
66+
:c:macro:`Py_TPFLAGS_HAVE_VECTORCALL` flag and setting
6767
:c:member:`~PyTypeObject.tp_vectorcall_offset` to the offset inside the
6868
object structure where a *vectorcallfunc* appears.
6969
This is a pointer to a function with the following signature:
@@ -75,7 +75,7 @@ This is a pointer to a function with the following signature:
7575
values of the keyword arguments.
7676
This can be *NULL* if there are no arguments.
7777
- *nargsf* is the number of positional arguments plus possibly the
78-
:const:`PY_VECTORCALL_ARGUMENTS_OFFSET` flag.
78+
:c:macro:`PY_VECTORCALL_ARGUMENTS_OFFSET` flag.
7979
To get the actual number of positional arguments from *nargsf*,
8080
use :c:func:`PyVectorcall_NARGS`.
8181
- *kwnames* is a tuple containing the names of the keyword arguments;
@@ -95,7 +95,7 @@ This is a pointer to a function with the following signature:
9595
``args[0]`` may be changed.
9696

9797
Whenever they can do so cheaply (without additional allocation), callers
98-
are encouraged to use :const:`PY_VECTORCALL_ARGUMENTS_OFFSET`.
98+
are encouraged to use :c:macro:`PY_VECTORCALL_ARGUMENTS_OFFSET`.
9999
Doing so will allow callables such as bound methods to make their onward
100100
calls (which include a prepended *self* argument) very efficiently.
101101

@@ -165,7 +165,7 @@ Vectorcall Support API
165165
166166
This is a specialized function, intended to be put in the
167167
:c:member:`~PyTypeObject.tp_call` slot or be used in an implementation of ``tp_call``.
168-
It does not check the :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag
168+
It does not check the :c:macro:`Py_TPFLAGS_HAVE_VECTORCALL` flag
169169
and it does not fall back to ``tp_call``.
170170
171171
.. versionadded:: 3.8
@@ -383,11 +383,11 @@ please see individual documentation for details.
383383
*args[0]*, and the *args* array starting at *args[1]* represents the arguments
384384
of the call. There must be at least one positional argument.
385385
*nargsf* is the number of positional arguments including *args[0]*,
386-
plus :const:`PY_VECTORCALL_ARGUMENTS_OFFSET` if the value of ``args[0]`` may
386+
plus :c:macro:`PY_VECTORCALL_ARGUMENTS_OFFSET` if the value of ``args[0]`` may
387387
temporarily be changed. Keyword arguments can be passed just like in
388388
:c:func:`PyObject_Vectorcall`.
389389
390-
If the object has the :const:`Py_TPFLAGS_METHOD_DESCRIPTOR` feature,
390+
If the object has the :c:macro:`Py_TPFLAGS_METHOD_DESCRIPTOR` feature,
391391
this will call the unbound method object with the full
392392
*args* vector as arguments.
393393

Doc/c-api/complex.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pointers. This is consistent throughout the API.
6464
representation.
6565
6666
If *divisor* is null, this method returns zero and sets
67-
:c:data:`errno` to :c:data:`EDOM`.
67+
:c:data:`errno` to :c:macro:`EDOM`.
6868
6969
7070
.. c:function:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp)
@@ -73,7 +73,7 @@ pointers. This is consistent throughout the API.
7373
representation.
7474
7575
If *num* is null and *exp* is not a positive real number,
76-
this method returns zero and sets :c:data:`errno` to :c:data:`EDOM`.
76+
this method returns zero and sets :c:data:`errno` to :c:macro:`EDOM`.
7777
7878
7979
Complex Numbers as Python Objects

Doc/c-api/exceptions.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ For convenience, some of these functions will always return a
154154
tuple object whose first item is the integer :c:data:`errno` value and whose
155155
second item is the corresponding error message (gotten from :c:func:`strerror`),
156156
and then calls ``PyErr_SetObject(type, object)``. On Unix, when the
157-
:c:data:`errno` value is :const:`EINTR`, indicating an interrupted system call,
157+
:c:data:`errno` value is :c:macro:`EINTR`, indicating an interrupted system call,
158158
this calls :c:func:`PyErr_CheckSignals`, and if that set the error indicator,
159159
leaves it set to that. The function always returns ``NULL``, so a wrapper
160160
function around a system call can write ``return PyErr_SetFromErrno(type);``
@@ -567,7 +567,7 @@ Signal Handling
567567
be interruptible by user requests (such as by pressing Ctrl-C).
568568
569569
.. note::
570-
The default Python signal handler for :const:`SIGINT` raises the
570+
The default Python signal handler for :c:macro:`SIGINT` raises the
571571
:exc:`KeyboardInterrupt` exception.
572572
573573
@@ -578,7 +578,7 @@ Signal Handling
578578
single: SIGINT
579579
single: KeyboardInterrupt (built-in exception)
580580
581-
Simulate the effect of a :const:`SIGINT` signal arriving.
581+
Simulate the effect of a :c:macro:`SIGINT` signal arriving.
582582
This is equivalent to ``PyErr_SetInterruptEx(SIGINT)``.
583583
584584
.. note::
@@ -690,7 +690,7 @@ Exception Objects
690690
691691
.. c:function:: PyObject* PyException_GetCause(PyObject *ex)
692692
693-
Return the cause (either an exception instance, or :const:`None`,
693+
Return the cause (either an exception instance, or ``None``,
694694
set by ``raise ... from ...``) associated with the exception as a new
695695
reference, as accessible from Python through :attr:`__cause__`.
696696
@@ -699,7 +699,7 @@ Exception Objects
699699
700700
Set the cause associated with the exception to *cause*. Use ``NULL`` to clear
701701
it. There is no type check to make sure that *cause* is either an exception
702-
instance or :const:`None`. This steals a reference to *cause*.
702+
instance or ``None``. This steals a reference to *cause*.
703703
704704
:attr:`__suppress_context__` is implicitly set to ``True`` by this function.
705705
@@ -788,7 +788,7 @@ because the :ref:`call protocol <call>` takes care of recursion handling.
788788
789789
Marks a point where a recursive C-level call is about to be performed.
790790
791-
If :const:`USE_STACKCHECK` is defined, this function checks if the OS
791+
If :c:macro:`USE_STACKCHECK` is defined, this function checks if the OS
792792
stack overflowed using :c:func:`PyOS_CheckStack`. In this is the case, it
793793
sets a :exc:`MemoryError` and returns a nonzero value.
794794

Doc/c-api/file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ the :mod:`io` APIs instead.
9393
.. index:: single: Py_PRINT_RAW
9494
9595
Write object *obj* to file object *p*. The only supported flag for *flags* is
96-
:const:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written
96+
:c:macro:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written
9797
instead of the :func:`repr`. Return ``0`` on success or ``-1`` on failure; the
9898
appropriate exception will be set.
9999

Doc/c-api/float.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Pack functions
109109
The pack routines write 2, 4 or 8 bytes, starting at *p*. *le* is an
110110
:c:expr:`int` argument, non-zero if you want the bytes string in little-endian
111111
format (exponent last, at ``p+1``, ``p+3``, or ``p+6`` ``p+7``), zero if you
112-
want big-endian format (exponent first, at *p*). The :c:data:`PY_BIG_ENDIAN`
112+
want big-endian format (exponent first, at *p*). The :c:macro:`PY_BIG_ENDIAN`
113113
constant can be used to use the native endian: it is equal to ``1`` on big
114114
endian processor, or ``0`` on little endian processor.
115115
@@ -140,7 +140,7 @@ Unpack functions
140140
The unpack routines read 2, 4 or 8 bytes, starting at *p*. *le* is an
141141
:c:expr:`int` argument, non-zero if the bytes string is in little-endian format
142142
(exponent last, at ``p+1``, ``p+3`` or ``p+6`` and ``p+7``), zero if big-endian
143-
(exponent first, at *p*). The :c:data:`PY_BIG_ENDIAN` constant can be used to
143+
(exponent first, at *p*). The :c:macro:`PY_BIG_ENDIAN` constant can be used to
144144
use the native endian: it is equal to ``1`` on big endian processor, or ``0``
145145
on little endian processor.
146146

Doc/c-api/gcsupport.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ or strings), do not need to provide any explicit support for garbage
1313
collection.
1414

1515
To create a container type, the :c:member:`~PyTypeObject.tp_flags` field of the type object must
16-
include the :const:`Py_TPFLAGS_HAVE_GC` and provide an implementation of the
16+
include the :c:macro:`Py_TPFLAGS_HAVE_GC` and provide an implementation of the
1717
:c:member:`~PyTypeObject.tp_traverse` handler. If instances of the type are mutable, a
1818
:c:member:`~PyTypeObject.tp_clear` implementation must also be provided.
1919

2020

21-
.. data:: Py_TPFLAGS_HAVE_GC
22-
:noindex:
23-
21+
:c:macro:`Py_TPFLAGS_HAVE_GC`
2422
Objects with a type with this flag set must conform with the rules
2523
documented here. For convenience these objects will be referred to as
2624
container objects.
@@ -52,18 +50,18 @@ rules:
5250
:c:member:`~PyTypeObject.tp_flags`, :c:member:`~PyTypeObject.tp_traverse`
5351
and :c:member:`~PyTypeObject.tp_clear` fields if the type inherits from a
5452
class that implements the garbage collector protocol and the child class
55-
does *not* include the :const:`Py_TPFLAGS_HAVE_GC` flag.
53+
does *not* include the :c:macro:`Py_TPFLAGS_HAVE_GC` flag.
5654

5755
.. c:function:: TYPE* PyObject_GC_New(TYPE, PyTypeObject *type)
5856
5957
Analogous to :c:func:`PyObject_New` but for container objects with the
60-
:const:`Py_TPFLAGS_HAVE_GC` flag set.
58+
:c:macro:`Py_TPFLAGS_HAVE_GC` flag set.
6159
6260
6361
.. c:function:: TYPE* PyObject_GC_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)
6462
6563
Analogous to :c:func:`PyObject_NewVar` but for container objects with the
66-
:const:`Py_TPFLAGS_HAVE_GC` flag set.
64+
:c:macro:`Py_TPFLAGS_HAVE_GC` flag set.
6765
6866
6967
.. c:function:: TYPE* PyObject_GC_Resize(TYPE, PyVarObject *op, Py_ssize_t newsize)

Doc/c-api/init.rst

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
12871287
function does not steal any references to *exc*. To prevent naive misuse, you
12881288
must write your own C extension to call this. Must be called with the GIL held.
12891289
Returns the number of thread states modified; this is normally one, but will be
1290-
zero if the thread id isn't found. If *exc* is :const:`NULL`, the pending
1290+
zero if the thread id isn't found. If *exc* is ``NULL``, the pending
12911291
exception (if any) for the thread is cleared. This raises no exceptions.
12921292
12931293
.. versionchanged:: 3.7
@@ -1566,32 +1566,32 @@ Python-level trace functions in previous versions.
15661566
The type of the trace function registered using :c:func:`PyEval_SetProfile` and
15671567
:c:func:`PyEval_SetTrace`. The first parameter is the object passed to the
15681568
registration function as *obj*, *frame* is the frame object to which the event
1569-
pertains, *what* is one of the constants :const:`PyTrace_CALL`,
1570-
:const:`PyTrace_EXCEPTION`, :const:`PyTrace_LINE`, :const:`PyTrace_RETURN`,
1571-
:const:`PyTrace_C_CALL`, :const:`PyTrace_C_EXCEPTION`, :const:`PyTrace_C_RETURN`,
1572-
or :const:`PyTrace_OPCODE`, and *arg* depends on the value of *what*:
1573-
1574-
+------------------------------+----------------------------------------+
1575-
| Value of *what* | Meaning of *arg* |
1576-
+==============================+========================================+
1577-
| :const:`PyTrace_CALL` | Always :c:data:`Py_None`. |
1578-
+------------------------------+----------------------------------------+
1579-
| :const:`PyTrace_EXCEPTION` | Exception information as returned by |
1580-
| | :func:`sys.exc_info`. |
1581-
+------------------------------+----------------------------------------+
1582-
| :const:`PyTrace_LINE` | Always :c:data:`Py_None`. |
1583-
+------------------------------+----------------------------------------+
1584-
| :const:`PyTrace_RETURN` | Value being returned to the caller, |
1585-
| | or ``NULL`` if caused by an exception. |
1586-
+------------------------------+----------------------------------------+
1587-
| :const:`PyTrace_C_CALL` | Function object being called. |
1588-
+------------------------------+----------------------------------------+
1589-
| :const:`PyTrace_C_EXCEPTION` | Function object being called. |
1590-
+------------------------------+----------------------------------------+
1591-
| :const:`PyTrace_C_RETURN` | Function object being called. |
1592-
+------------------------------+----------------------------------------+
1593-
| :const:`PyTrace_OPCODE` | Always :c:data:`Py_None`. |
1594-
+------------------------------+----------------------------------------+
1569+
pertains, *what* is one of the constants :c:data:`PyTrace_CALL`,
1570+
:c:data:`PyTrace_EXCEPTION`, :c:data:`PyTrace_LINE`, :c:data:`PyTrace_RETURN`,
1571+
:c:data:`PyTrace_C_CALL`, :c:data:`PyTrace_C_EXCEPTION`, :c:data:`PyTrace_C_RETURN`,
1572+
or :c:data:`PyTrace_OPCODE`, and *arg* depends on the value of *what*:
1573+
1574+
+-------------------------------+----------------------------------------+
1575+
| Value of *what* | Meaning of *arg* |
1576+
+===============================+========================================+
1577+
| :c:data:`PyTrace_CALL` | Always :c:data:`Py_None`. |
1578+
+-------------------------------+----------------------------------------+
1579+
| :c:data:`PyTrace_EXCEPTION` | Exception information as returned by |
1580+
| | :func:`sys.exc_info`. |
1581+
+-------------------------------+----------------------------------------+
1582+
| :c:data:`PyTrace_LINE` | Always :c:data:`Py_None`. |
1583+
+-------------------------------+----------------------------------------+
1584+
| :c:data:`PyTrace_RETURN` | Value being returned to the caller, |
1585+
| | or ``NULL`` if caused by an exception. |
1586+
+-------------------------------+----------------------------------------+
1587+
| :c:data:`PyTrace_C_CALL` | Function object being called. |
1588+
+-------------------------------+----------------------------------------+
1589+
| :c:data:`PyTrace_C_EXCEPTION` | Function object being called. |
1590+
+-------------------------------+----------------------------------------+
1591+
| :c:data:`PyTrace_C_RETURN` | Function object being called. |
1592+
+-------------------------------+----------------------------------------+
1593+
| :c:data:`PyTrace_OPCODE` | Always :c:data:`Py_None`. |
1594+
+-------------------------------+----------------------------------------+
15951595
15961596
.. c:var:: int PyTrace_CALL
15971597
@@ -1658,8 +1658,8 @@ Python-level trace functions in previous versions.
16581658
function as its first parameter, and may be any Python object, or ``NULL``. If
16591659
the profile function needs to maintain state, using a different value for *obj*
16601660
for each thread provides a convenient and thread-safe place to store it. The
1661-
profile function is called for all monitored events except :const:`PyTrace_LINE`
1662-
:const:`PyTrace_OPCODE` and :const:`PyTrace_EXCEPTION`.
1661+
profile function is called for all monitored events except :c:data:`PyTrace_LINE`
1662+
:c:data:`PyTrace_OPCODE` and :c:data:`PyTrace_EXCEPTION`.
16631663
16641664
See also the :func:`sys.setprofile` function.
16651665
@@ -1672,8 +1672,8 @@ Python-level trace functions in previous versions.
16721672
:c:func:`PyEval_SetProfile`, except the tracing function does receive line-number
16731673
events and per-opcode events, but does not receive any event related to C function
16741674
objects being called. Any trace function registered using :c:func:`PyEval_SetTrace`
1675-
will not receive :const:`PyTrace_C_CALL`, :const:`PyTrace_C_EXCEPTION` or
1676-
:const:`PyTrace_C_RETURN` as a value for the *what* parameter.
1675+
will not receive :c:data:`PyTrace_C_CALL`, :c:data:`PyTrace_C_EXCEPTION` or
1676+
:c:data:`PyTrace_C_RETURN` as a value for the *what* parameter.
16771677
16781678
See also the :func:`sys.settrace` function.
16791679

Doc/c-api/long.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
141141
instance of :c:type:`PyLongObject`, first call its :meth:`~object.__index__`
142142
method (if present) to convert it to a :c:type:`PyLongObject`.
143143
144-
If the value of *obj* is greater than :const:`LONG_MAX` or less than
145-
:const:`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, and
144+
If the value of *obj* is greater than :c:macro:`LONG_MAX` or less than
145+
:c:macro:`LONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively, and
146146
return ``-1``; otherwise, set *\*overflow* to ``0``. If any other exception
147147
occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
148148
@@ -182,8 +182,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
182182
instance of :c:type:`PyLongObject`, first call its :meth:`~object.__index__` method
183183
(if present) to convert it to a :c:type:`PyLongObject`.
184184
185-
If the value of *obj* is greater than :const:`LLONG_MAX` or less than
186-
:const:`LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively,
185+
If the value of *obj* is greater than :c:macro:`LLONG_MAX` or less than
186+
:c:macro:`LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively,
187187
and return ``-1``; otherwise, set *\*overflow* to ``0``. If any other
188188
exception occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
189189

0 commit comments

Comments
 (0)