Skip to content

Commit df829b0

Browse files
committed
gh-107298: Fix more Sphinx warnings in the C API doc
Declare the following functions as macros, since they are actually macros. it avoids a warning on the non existent "TYPE" type name. * PyMem_New() * PyMem_Resize() * PyModule_AddIntMacro() * PyModule_AddStringMacro() * PyObject_GC_New() * PyObject_GC_NewVar() * PyObject_New() * PyObject_NewVar() Add C standard C types to nitpick_ignore in Doc/conf.py: * int64_t * uint64_t * uintptr_t No longer ignore non existing "__int" type in nitpick_ignore. Update Doc/tools/.nitignore
1 parent 391e03f commit df829b0

23 files changed

+124
-121
lines changed

Doc/c-api/allocation.rst

+11-8
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,34 @@ Allocating Objects on the Heap
2727
length information for a variable-size object.
2828
2929
30-
.. c:function:: TYPE* PyObject_New(TYPE, PyTypeObject *type)
30+
.. c:macro:: PyObject_New(TYPE, typeobj)
3131
3232
Allocate a new Python object using the C structure type *TYPE* and the
33-
Python type object *type*. Fields not defined by the Python object header
33+
Python type object *typeobj* (``PyTypeObject*``).
34+
Fields not defined by the Python object header
3435
are not initialized; the object's reference count will be one. The size of
3536
the memory allocation is determined from the :c:member:`~PyTypeObject.tp_basicsize` field of
3637
the type object.
3738
3839
39-
.. c:function:: TYPE* PyObject_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)
40+
.. c:macro:: PyObject_NewVar(TYPE, typeobj, size)
4041
4142
Allocate a new Python object using the C structure type *TYPE* and the
42-
Python type object *type*. Fields not defined by the Python object header
43+
Python type object *typeobj* (``PyTypeObject*``).
44+
Fields not defined by the Python object header
4345
are not initialized. The allocated memory allows for the *TYPE* structure
44-
plus *size* fields of the size given by the :c:member:`~PyTypeObject.tp_itemsize` field of
45-
*type*. This is useful for implementing objects like tuples, which are
46+
plus *size* (``Py_ssize_t``) fields of the size
47+
given by the :c:member:`~PyTypeObject.tp_itemsize` field of
48+
*typeobj*. This is useful for implementing objects like tuples, which are
4649
able to determine their size at construction time. Embedding the array of
4750
fields into the same allocation decreases the number of allocations,
4851
improving the memory management efficiency.
4952
5053
5154
.. c:function:: void PyObject_Del(void *op)
5255
53-
Releases memory allocated to an object using :c:func:`PyObject_New` or
54-
:c:func:`PyObject_NewVar`. This is normally called from the
56+
Releases memory allocated to an object using :c:macro:`PyObject_New` or
57+
:c:macro:`PyObject_NewVar`. This is normally called from the
5558
:c:member:`~PyTypeObject.tp_dealloc` handler specified in the object's type. The fields of
5659
the object should not be accessed after this call as the memory is no
5760
longer a valid Python object.

Doc/c-api/capsule.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Refer to :ref:`using-capsules` for more information on using these objects.
6464
6565
The *name* parameter must compare exactly to the name stored in the capsule.
6666
If the name stored in the capsule is ``NULL``, the *name* passed in must also
67-
be ``NULL``. Python uses the C function :c:func:`strcmp` to compare capsule
67+
be ``NULL``. Python uses the C function :c:func:`!strcmp` to compare capsule
6868
names.
6969
7070

Doc/c-api/complex.rst

+2-2
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:macro:`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:macro:`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/conversion.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ The following functions provide locale-independent string to number conversions.
119119
.. c:function:: int PyOS_stricmp(const char *s1, const char *s2)
120120
121121
Case insensitive comparison of strings. The function works almost
122-
identically to :c:func:`strcmp` except that it ignores the case.
122+
identically to :c:func:`!strcmp` except that it ignores the case.
123123
124124
125125
.. c:function:: int PyOS_strnicmp(const char *s1, const char *s2, Py_ssize_t size)
126126
127127
Case insensitive comparison of strings. The function works almost
128-
identically to :c:func:`strncmp` except that it ignores the case.
128+
identically to :c:func:`!strncmp` except that it ignores the case.

Doc/c-api/exceptions.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Printing and clearing
8383
This utility function prints a warning message to ``sys.stderr`` when an
8484
exception has been set but it is impossible for the interpreter to actually
8585
raise the exception. It is used, for example, when an exception occurs in an
86-
:meth:`__del__` method.
86+
:meth:`~object.__del__` method.
8787
8888
The function is called with a single argument *obj* that identifies the context
8989
in which the unraisable exception occurred. If possible,
@@ -165,7 +165,7 @@ For convenience, some of these functions will always return a
165165
tuple object whose first item is the integer :c:data:`errno` value and whose
166166
second item is the corresponding error message (gotten from :c:func:`!strerror`),
167167
and then calls ``PyErr_SetObject(type, object)``. On Unix, when the
168-
:c:data:`errno` value is :c:macro:`EINTR`, indicating an interrupted system call,
168+
:c:data:`errno` value is :c:macro:`!EINTR`, indicating an interrupted system call,
169169
this calls :c:func:`PyErr_CheckSignals`, and if that set the error indicator,
170170
leaves it set to that. The function always returns ``NULL``, so a wrapper
171171
function around a system call can write ``return PyErr_SetFromErrno(type);``
@@ -177,7 +177,7 @@ For convenience, some of these functions will always return a
177177
Similar to :c:func:`PyErr_SetFromErrno`, with the additional behavior that if
178178
*filenameObject* is not ``NULL``, it is passed to the constructor of *type* as
179179
a third parameter. In the case of :exc:`OSError` exception,
180-
this is used to define the :attr:`filename` attribute of the
180+
this is used to define the :attr:`!filename` attribute of the
181181
exception instance.
182182
183183
@@ -200,12 +200,12 @@ For convenience, some of these functions will always return a
200200
.. c:function:: PyObject* PyErr_SetFromWindowsErr(int ierr)
201201
202202
This is a convenience function to raise :exc:`WindowsError`. If called with
203-
*ierr* of ``0``, the error code returned by a call to :c:func:`GetLastError`
204-
is used instead. It calls the Win32 function :c:func:`FormatMessage` to retrieve
205-
the Windows description of error code given by *ierr* or :c:func:`GetLastError`,
203+
*ierr* of ``0``, the error code returned by a call to :c:func:`!GetLastError`
204+
is used instead. It calls the Win32 function :c:func:`!FormatMessage` to retrieve
205+
the Windows description of error code given by *ierr* or :c:func:`!GetLastError`,
206206
then it constructs a tuple object whose first item is the *ierr* value and whose
207207
second item is the corresponding error message (gotten from
208-
:c:func:`FormatMessage`), and then calls ``PyErr_SetObject(PyExc_WindowsError,
208+
:c:func:`!FormatMessage`), and then calls ``PyErr_SetObject(PyExc_WindowsError,
209209
object)``. This function always returns ``NULL``.
210210
211211
.. availability:: Windows.
@@ -631,7 +631,7 @@ Signal Handling
631631
be interruptible by user requests (such as by pressing Ctrl-C).
632632
633633
.. note::
634-
The default Python signal handler for :c:macro:`SIGINT` raises the
634+
The default Python signal handler for :c:macro:`!SIGINT` raises the
635635
:exc:`KeyboardInterrupt` exception.
636636
637637
@@ -642,7 +642,7 @@ Signal Handling
642642
single: SIGINT
643643
single: KeyboardInterrupt (built-in exception)
644644
645-
Simulate the effect of a :c:macro:`SIGINT` signal arriving.
645+
Simulate the effect of a :c:macro:`!SIGINT` signal arriving.
646646
This is equivalent to ``PyErr_SetInterruptEx(SIGINT)``.
647647
648648
.. note::

Doc/c-api/gcsupport.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ include the :c:macro:`Py_TPFLAGS_HAVE_GC` and provide an implementation of the
2525

2626
Constructors for container types must conform to two rules:
2727

28-
#. The memory for the object must be allocated using :c:func:`PyObject_GC_New`
29-
or :c:func:`PyObject_GC_NewVar`.
28+
#. The memory for the object must be allocated using :c:macro:`PyObject_GC_New`
29+
or :c:macro:`PyObject_GC_NewVar`.
3030

3131
#. Once all the fields which may contain references to other containers are
3232
initialized, it must call :c:func:`PyObject_GC_Track`.
@@ -52,19 +52,19 @@ rules:
5252
class that implements the garbage collector protocol and the child class
5353
does *not* include the :c:macro:`Py_TPFLAGS_HAVE_GC` flag.
5454

55-
.. c:function:: TYPE* PyObject_GC_New(TYPE, PyTypeObject *type)
55+
.. c:macro:: PyObject_GC_New(TYPE, typeobj)
5656
57-
Analogous to :c:func:`PyObject_New` but for container objects with the
57+
Analogous to :c:macro:`PyObject_New` but for container objects with the
5858
:c:macro:`Py_TPFLAGS_HAVE_GC` flag set.
5959

60-
.. c:function:: TYPE* PyObject_GC_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)
60+
.. c:macro:: PyObject_GC_NewVar(TYPE, typeobj, size)
6161
62-
Analogous to :c:func:`PyObject_NewVar` but for container objects with the
62+
Analogous to :c:macro:`PyObject_NewVar` but for container objects with the
6363
:c:macro:`Py_TPFLAGS_HAVE_GC` flag set.
6464

6565
.. c:function:: PyObject* PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *type, size_t extra_size)
6666
67-
Analogous to :c:func:`PyObject_GC_New` but allocates *extra_size*
67+
Analogous to :c:macro:`PyObject_GC_New` but allocates *extra_size*
6868
bytes at the end of the object (at offset
6969
:c:member:`~PyTypeObject.tp_basicsize`).
7070
The allocated memory is initialized to zeros,
@@ -85,7 +85,7 @@ rules:
8585
8686
.. c:function:: TYPE* PyObject_GC_Resize(TYPE, PyVarObject *op, Py_ssize_t newsize)
8787
88-
Resize an object allocated by :c:func:`PyObject_NewVar`. Returns the
88+
Resize an object allocated by :c:macro:`PyObject_NewVar`. Returns the
8989
resized object or ``NULL`` on failure. *op* must not be tracked by the collector yet.
9090
9191
@@ -128,8 +128,8 @@ rules:
128128
129129
.. c:function:: void PyObject_GC_Del(void *op)
130130
131-
Releases memory allocated to an object using :c:func:`PyObject_GC_New` or
132-
:c:func:`PyObject_GC_NewVar`.
131+
Releases memory allocated to an object using :c:macro:`PyObject_GC_New` or
132+
:c:macro:`PyObject_GC_NewVar`.
133133
134134
135135
.. c:function:: void PyObject_GC_UnTrack(void *op)

Doc/c-api/import.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ Importing Modules
151151
The module's :attr:`__spec__` and :attr:`__loader__` will be set, if
152152
not set already, with the appropriate values. The spec's loader will
153153
be set to the module's ``__loader__`` (if set) and to an instance of
154-
:class:`SourceFileLoader` otherwise.
154+
:class:`~importlib.machinery.SourceFileLoader` otherwise.
155155
156156
The module's :attr:`__file__` attribute will be set to the code object's
157-
:attr:`co_filename`. If applicable, :attr:`__cached__` will also
157+
:attr:`!co_filename`. If applicable, :attr:`__cached__` will also
158158
be set.
159159
160160
This function will reload the module if it was already imported. See
@@ -241,7 +241,7 @@ Importing Modules
241241
242242
.. c:function:: PyObject* PyImport_GetImporter(PyObject *path)
243243
244-
Return a finder object for a :data:`sys.path`/:attr:`pkg.__path__` item
244+
Return a finder object for a :data:`sys.path`/:attr:`!pkg.__path__` item
245245
*path*, possibly by fetching it from the :data:`sys.path_importer_cache`
246246
dict. If it wasn't yet cached, traverse :data:`sys.path_hooks` until a hook
247247
is found that can handle the path item. Return ``None`` if no hook could;

Doc/c-api/init.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The following functions can be safely called before Python is initialized:
2525

2626
* :c:func:`PyImport_AppendInittab`
2727
* :c:func:`PyImport_ExtendInittab`
28-
* :c:func:`PyInitFrozenExtensions`
28+
* :c:func:`!PyInitFrozenExtensions`
2929
* :c:func:`PyMem_SetAllocator`
3030
* :c:func:`PyMem_SetupDebugHooks`
3131
* :c:func:`PyObject_SetArenaAllocator`
@@ -151,7 +151,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
151151
:c:member:`PyConfig.use_environment` should be used instead, see
152152
:ref:`Python Initialization Configuration <init-config>`.
153153

154-
Ignore all :envvar:`PYTHON*` environment variables, e.g.
154+
Ignore all :envvar:`!PYTHON*` environment variables, e.g.
155155
:envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`, that might be set.
156156

157157
Set by the :option:`-E` and :option:`-I` options.
@@ -224,7 +224,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
224224
:ref:`Python Initialization Configuration <init-config>`.
225225

226226
If the flag is non-zero, use :class:`io.FileIO` instead of
227-
:class:`WindowsConsoleIO` for :mod:`sys` standard streams.
227+
:class:`!io._WindowsConsoleIO` for :mod:`sys` standard streams.
228228

229229
Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSSTDIO` environment
230230
variable is set to a non-empty string.
@@ -393,7 +393,7 @@ Initializing and finalizing the interpreter
393393
the application.
394394
395395
**Bugs and caveats:** The destruction of modules and objects in modules is done
396-
in random order; this may cause destructors (:meth:`__del__` methods) to fail
396+
in random order; this may cause destructors (:meth:`~object.__del__` methods) to fail
397397
when they depend on other objects (even functions) or modules. Dynamically
398398
loaded extension modules loaded by Python are not unloaded. Small amounts of
399399
memory allocated by the Python interpreter may not be freed (if you find a leak,
@@ -417,7 +417,7 @@ Process-wide parameters
417417
=======================
418418
419419
420-
.. c:function:: wchar* Py_GetProgramName()
420+
.. c:function:: wchar_t* Py_GetProgramName()
421421
422422
Return the program name set with :c:member:`PyConfig.program_name`, or the default.
423423
The returned string points into static storage; the caller should not modify its
@@ -785,7 +785,7 @@ the fork, and releasing them afterwards. In addition, it resets any
785785
:ref:`lock-objects` in the child. When extending or embedding Python, there
786786
is no way to inform Python of additional (non-Python) locks that need to be
787787
acquired before or reset after a fork. OS facilities such as
788-
:c:func:`pthread_atfork` would need to be used to accomplish the same thing.
788+
:c:func:`!pthread_atfork` would need to be used to accomplish the same thing.
789789
Additionally, when extending or embedding Python, calling :c:func:`fork`
790790
directly rather than through :func:`os.fork` (and returning to or calling
791791
into Python) may result in a deadlock by one of Python's internal locks
@@ -849,7 +849,7 @@ code, or when embedding the Python interpreter:
849849
.. note::
850850
Calling this function from a thread when the runtime is finalizing
851851
will terminate the thread, even if the thread was not created by Python.
852-
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
852+
You can use :c:func:`!_Py_IsFinalizing` or :func:`sys.is_finalizing` to
853853
check if the interpreter is in process of being finalized before calling
854854
this function to avoid unwanted termination.
855855
@@ -895,7 +895,7 @@ with sub-interpreters:
895895
.. note::
896896
Calling this function from a thread when the runtime is finalizing
897897
will terminate the thread, even if the thread was not created by Python.
898-
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
898+
You can use :c:func:`!_Py_IsFinalizing` or :func:`sys.is_finalizing` to
899899
check if the interpreter is in process of being finalized before calling
900900
this function to avoid unwanted termination.
901901
@@ -1177,7 +1177,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
11771177
.. note::
11781178
Calling this function from a thread when the runtime is finalizing
11791179
will terminate the thread, even if the thread was not created by Python.
1180-
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
1180+
You can use :c:func:`!_Py_IsFinalizing` or :func:`sys.is_finalizing` to
11811181
check if the interpreter is in process of being finalized before calling
11821182
this function to avoid unwanted termination.
11831183

Doc/c-api/init_config.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ PyConfig
889889
.. c:member:: int legacy_windows_stdio
890890
891891
If non-zero, use :class:`io.FileIO` instead of
892-
:class:`io.WindowsConsoleIO` for :data:`sys.stdin`, :data:`sys.stdout`
892+
:class:`!io._WindowsConsoleIO` for :data:`sys.stdin`, :data:`sys.stdout`
893893
and :data:`sys.stderr`.
894894
895895
Set to ``1`` if the :envvar:`PYTHONLEGACYWINDOWSSTDIO` environment
@@ -1139,7 +1139,7 @@ PyConfig
11391139
11401140
Set to ``0`` by the :option:`-S` command line option.
11411141
1142-
:data:`sys.flags.no_site` is set to the inverted value of
1142+
:data:`sys.flags.no_site <sys.flags>` is set to the inverted value of
11431143
:c:member:`~PyConfig.site_import`.
11441144
11451145
Default: ``1``.

Doc/c-api/memory.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ API functions listed in this document.
4747
single: free()
4848

4949
To avoid memory corruption, extension writers should never try to operate on
50-
Python objects with the functions exported by the C library: :c:func:`malloc`,
50+
Python objects with the functions exported by the C library: :c:func:`!malloc`,
5151
:c:func:`calloc`, :c:func:`realloc` and :c:func:`free`. This will result in mixed
5252
calls between the C allocator and the Python memory manager with fatal
5353
consequences, because they implement different algorithms and operate on
@@ -135,8 +135,8 @@ functions are thread-safe, the :term:`GIL <global interpreter lock>` does not
135135
need to be held.
136136

137137
The :ref:`default raw memory allocator <default-memory-allocators>` uses
138-
the following functions: :c:func:`malloc`, :c:func:`calloc`, :c:func:`realloc`
139-
and :c:func:`free`; call ``malloc(1)`` (or ``calloc(1, 1)``) when requesting
138+
the following functions: :c:func:`!malloc`, :c:func:`!calloc`, :c:func:`!realloc`
139+
and :c:func:`!free`; call ``malloc(1)`` (or ``calloc(1, 1)``) when requesting
140140
zero bytes.
141141

142142
.. versionadded:: 3.4
@@ -264,14 +264,14 @@ The following type-oriented macros are provided for convenience. Note that
264264
*TYPE* refers to any C type.
265265
266266
267-
.. c:function:: TYPE* PyMem_New(TYPE, size_t n)
267+
.. c:mcaro:: PyMem_New(TYPE, n)
268268
269269
Same as :c:func:`PyMem_Malloc`, but allocates ``(n * sizeof(TYPE))`` bytes of
270270
memory. Returns a pointer cast to :c:expr:`TYPE*`. The memory will not have
271271
been initialized in any way.
272272
273273
274-
.. c:function:: TYPE* PyMem_Resize(void *p, TYPE, size_t n)
274+
.. c:macro:: PyMem_Resize(p, TYPE, n)
275275
276276
Same as :c:func:`PyMem_Realloc`, but the memory block is resized to ``(n *
277277
sizeof(TYPE))`` bytes. Returns a pointer cast to :c:expr:`TYPE*`. On return,
@@ -423,7 +423,7 @@ Customize Memory Allocators
423423
+----------------------------------------------------------+---------------------------------------+
424424
425425
.. versionchanged:: 3.5
426-
The :c:type:`PyMemAllocator` structure was renamed to
426+
The :c:type:`!PyMemAllocator` structure was renamed to
427427
:c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
428428
429429
@@ -627,8 +627,8 @@ with a fixed size of 256 KiB. It falls back to :c:func:`PyMem_RawMalloc` and
627627
628628
The arena allocator uses the following functions:
629629
630-
* :c:func:`VirtualAlloc` and :c:func:`VirtualFree` on Windows,
631-
* :c:func:`mmap` and :c:func:`munmap` if available,
630+
* :c:func:`!VirtualAlloc` and :c:func:`!VirtualFree` on Windows,
631+
* :c:func:`!mmap` and :c:func:`!munmap` if available,
632632
* :c:func:`malloc` and :c:func:`free` otherwise.
633633
634634
This allocator is disabled if Python is configured with the
@@ -732,8 +732,8 @@ allocators operating on different heaps. ::
732732
free(buf1); /* Fatal -- should be PyMem_Del() */
733733
734734
In addition to the functions aimed at handling raw memory blocks from the Python
735-
heap, objects in Python are allocated and released with :c:func:`PyObject_New`,
736-
:c:func:`PyObject_NewVar` and :c:func:`PyObject_Del`.
735+
heap, objects in Python are allocated and released with :c:macro:`PyObject_New`,
736+
:c:macro:`PyObject_NewVar` and :c:func:`PyObject_Del`.
737737
738738
These will be explained in the next chapter on defining and implementing new
739739
object types in C.

0 commit comments

Comments
 (0)