Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-112026: Add again <unistd.h> include in Python.h #112046

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1178,17 +1178,6 @@ Porting to Python 3.13
also the ``HAVE_IEEEFP_H`` macro.
(Contributed by Victor Stinner in :gh:`108765`.)

* ``Python.h`` no longer includes the ``<unistd.h>`` standard header file. If
needed, it should now be included explicitly. For example, it provides the
functions: ``read()``, ``write()``, ``close()``, ``isatty()``, ``lseek()``,
``getpid()``, ``getcwd()``, ``sysconf()``, ``getpagesize()``, ``alarm()`` and
``pause()``.
As a consequence, ``_POSIX_SEMAPHORES`` and ``_POSIX_THREADS`` macros are no
longer defined by ``Python.h``. The ``HAVE_UNISTD_H`` and ``HAVE_PTHREAD_H``
macros defined by ``Python.h`` can be used to decide if ``<unistd.h>`` and
``<pthread.h>`` header files can be included.
(Contributed by Victor Stinner in :gh:`108765`.)

* ``Python.h`` no longer includes these standard header files: ``<time.h>``,
``<sys/select.h>`` and ``<sys/time.h>``. If needed, they should now be
included explicitly. For example, ``<time.h>`` provides the ``clock()`` and
Expand All @@ -1197,13 +1186,6 @@ Porting to Python 3.13
and ``setitimer()`` functions.
(Contributed by Victor Stinner in :gh:`108765`.)

* ``Python.h`` no longer includes the ``<ctype.h>`` standard header file. If
needed, it should now be included explicitly. For example, it provides
``isalpha()`` and ``tolower()`` functions which are locale dependent. Python
provides locale independent functions, like :c:func:`!Py_ISALPHA` and
:c:func:`!Py_TOLOWER`.
(Contributed by Victor Stinner in :gh:`108765`.)

* If the :c:macro:`Py_LIMITED_API` macro is defined, :c:macro:`!Py_BUILD_CORE`,
:c:macro:`!Py_BUILD_CORE_BUILTIN` and :c:macro:`!Py_BUILD_CORE_MODULE` macros
are now undefined by ``<Python.h>``.
Expand Down
15 changes: 12 additions & 3 deletions Include/Python.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@
# include <sys/types.h> // ssize_t
#endif

// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by
// Python, but kept for backward compatibility (avoid compiler warnings).
// They are no longer included by limited C API version 3.11 and newer.
// <errno.h>, <stdio.h>, <stdlib.h> and <string.h> headers are no longer used
// by Python, but kept for the backward compatibility of existing third party C
// extensions. They are not included by limited C API version 3.11 and newer.
//
// The <ctype.h> and <unistd.h> headers are not included by limited C API
// version 3.13 and newer.
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
# include <errno.h> // errno
# include <stdio.h> // FILE*
# include <stdlib.h> // getenv()
# include <string.h> // memcpy()
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030d0000
# include <ctype.h> // tolower()
# ifndef MS_WINDOWS
# include <unistd.h> // close()
# endif
#endif


// Include Python header files
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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. Patch by
Victor Stinner.
Loading