Skip to content

Commit 977f80f

Browse files
vstinnerGlyphack
authored andcommitted
pythongh-112026: Add again <unistd.h> include in Python.h (python#112046)
Add again <ctype.h> and <unistd.h> includes in Python.h, but don't include them in the limited C API version 3.13 and newer.
1 parent 02026ac commit 977f80f

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,17 +1191,6 @@ Porting to Python 3.13
11911191
also the ``HAVE_IEEEFP_H`` macro.
11921192
(Contributed by Victor Stinner in :gh:`108765`.)
11931193

1194-
* ``Python.h`` no longer includes the ``<unistd.h>`` standard header file. If
1195-
needed, it should now be included explicitly. For example, it provides the
1196-
functions: ``read()``, ``write()``, ``close()``, ``isatty()``, ``lseek()``,
1197-
``getpid()``, ``getcwd()``, ``sysconf()``, ``getpagesize()``, ``alarm()`` and
1198-
``pause()``.
1199-
As a consequence, ``_POSIX_SEMAPHORES`` and ``_POSIX_THREADS`` macros are no
1200-
longer defined by ``Python.h``. The ``HAVE_UNISTD_H`` and ``HAVE_PTHREAD_H``
1201-
macros defined by ``Python.h`` can be used to decide if ``<unistd.h>`` and
1202-
``<pthread.h>`` header files can be included.
1203-
(Contributed by Victor Stinner in :gh:`108765`.)
1204-
12051194
* ``Python.h`` no longer includes these standard header files: ``<time.h>``,
12061195
``<sys/select.h>`` and ``<sys/time.h>``. If needed, they should now be
12071196
included explicitly. For example, ``<time.h>`` provides the ``clock()`` and
@@ -1210,13 +1199,6 @@ Porting to Python 3.13
12101199
and ``setitimer()`` functions.
12111200
(Contributed by Victor Stinner in :gh:`108765`.)
12121201

1213-
* ``Python.h`` no longer includes the ``<ctype.h>`` standard header file. If
1214-
needed, it should now be included explicitly. For example, it provides
1215-
``isalpha()`` and ``tolower()`` functions which are locale dependent. Python
1216-
provides locale independent functions, like :c:func:`!Py_ISALPHA` and
1217-
:c:func:`!Py_TOLOWER`.
1218-
(Contributed by Victor Stinner in :gh:`108765`.)
1219-
12201202
* If the :c:macro:`Py_LIMITED_API` macro is defined, :c:macro:`!Py_BUILD_CORE`,
12211203
:c:macro:`!Py_BUILD_CORE_BUILTIN` and :c:macro:`!Py_BUILD_CORE_MODULE` macros
12221204
are now undefined by ``<Python.h>``.

Include/Python.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,24 @@
2626
# include <sys/types.h> // ssize_t
2727
#endif
2828

29-
// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by
30-
// Python, but kept for backward compatibility (avoid compiler warnings).
31-
// They are no longer included by limited C API version 3.11 and newer.
29+
// <errno.h>, <stdio.h>, <stdlib.h> and <string.h> headers are no longer used
30+
// by Python, but kept for the backward compatibility of existing third party C
31+
// extensions. They are not included by limited C API version 3.11 and newer.
32+
//
33+
// The <ctype.h> and <unistd.h> headers are not included by limited C API
34+
// version 3.13 and newer.
3235
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
3336
# include <errno.h> // errno
3437
# include <stdio.h> // FILE*
3538
# include <stdlib.h> // getenv()
3639
# include <string.h> // memcpy()
3740
#endif
41+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030d0000
42+
# include <ctype.h> // tolower()
43+
# ifndef MS_WINDOWS
44+
# include <unistd.h> // close()
45+
# endif
46+
#endif
3847

3948

4049
// Include Python header files
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add again ``<ctype.h>`` and ``<unistd.h>`` includes in ``Python.h``, but
2+
don't include them in the limited C API version 3.13 and newer. Patch by
3+
Victor Stinner.

0 commit comments

Comments
 (0)