Skip to content

Commit 1bb2ae5

Browse files
miss-islingtonSZeltaatAA-Turner
authored
[3.13] gh-136823: Update documentation on excluded headers in Python.h (GH-136824) (#137438)
Co-authored-by: Sina Zel taat <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent c4c554d commit 1bb2ae5

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

Doc/extending/extending.rst

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,37 @@ the module and a copyright notice if you like).
7575
See :ref:`arg-parsing-string-and-buffers` for a description of this macro.
7676

7777
All user-visible symbols defined by :file:`Python.h` have a prefix of ``Py`` or
78-
``PY``, except those defined in standard header files. For convenience, and
79-
since they are used extensively by the Python interpreter, ``"Python.h"``
80-
includes a few standard header files: ``<stdio.h>``, ``<string.h>``,
81-
``<errno.h>``, and ``<stdlib.h>``. If the latter header file does not exist on
82-
your system, it declares the functions :c:func:`malloc`, :c:func:`free` and
83-
:c:func:`realloc` directly.
78+
``PY``, except those defined in standard header files.
79+
80+
.. tip::
81+
82+
For backward compatibility, :file:`Python.h` includes several standard header files.
83+
C extensions should include the standard headers that they use,
84+
and should not rely on these implicit includes.
85+
If using the limited C API version 3.13 or newer, the implicit includes are:
86+
87+
* ``<assert.h>``
88+
* ``<intrin.h>`` (on Windows)
89+
* ``<inttypes.h>``
90+
* ``<limits.h>``
91+
* ``<math.h>``
92+
* ``<stdarg.h>``
93+
* ``<wchar.h>``
94+
* ``<sys/types.h>`` (if present)
95+
96+
If :c:macro:`Py_LIMITED_API` is not defined, or is set to version 3.12 or older,
97+
the headers below are also included:
98+
99+
* ``<ctype.h>``
100+
* ``<unistd.h>`` (on POSIX)
101+
102+
If :c:macro:`Py_LIMITED_API` is not defined, or is set to version 3.10 or older,
103+
the headers below are also included:
104+
105+
* ``<errno.h>``
106+
* ``<stdio.h>``
107+
* ``<stdlib.h>``
108+
* ``<string.h>``
84109

85110
The next thing we add to our module file is the C function that will be called
86111
when the Python expression ``spam.system(string)`` is evaluated (we'll see

Include/Python.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
// Include standard header files
19+
// When changing these files, remember to update Doc/extending/extending.rst.
1920
#include <assert.h> // assert()
2021
#include <inttypes.h> // uintptr_t
2122
#include <limits.h> // INT_MAX

0 commit comments

Comments
 (0)