Skip to content

Commit

Permalink
pythongh-108765: Python.h no longer includes <unistd.h>
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Sep 1, 2023
1 parent 45b9e6a commit dddca41
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,10 @@ New Features
Porting to Python 3.13
----------------------

* ``Python.h`` no longer includes the ``<unistd.h>`` standard header file. If
needed, it should now be included explicitly.
(Contributed by Victor Stinner in :gh:`108765`.)

Deprecated
----------

Expand Down
11 changes: 5 additions & 6 deletions Include/Python.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
#ifdef HAVE_STDDEF_H
# include <stddef.h> // size_t
#endif
#ifndef MS_WINDOWS
# include <unistd.h> // sysconf()
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> // ssize_t
#endif

// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by Python
// headers, but kept for backward compatibility (no introduce new compiler
// warnings). They are not included by the limited C API version 3.11 and
// above.
// 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.
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
# include <errno.h> // errno
# include <stdio.h> // FILE*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``Python.h`` no longer includes the ``<unistd.h>`` standard header file. If
needed, it should now be included explicitly. Patch by Victor Stinner.
3 changes: 2 additions & 1 deletion Modules/grpmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "Python.h"
#include "posixmodule.h"

#include <grp.h>
#include <grp.h> // getgrgid_r()
#include <unistd.h> // sysconf()

#include "clinic/grpmodule.c.h"
/*[clinic input]
Expand Down
1 change: 1 addition & 0 deletions Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "pycore_fileutils.h" // _Py_stat_struct

#include <stddef.h> // offsetof()
#include <unistd.h> // close()

// to support MS_WINDOWS_SYSTEM OpenFileMappingA / CreateFileMappingA
// need to be replaced with OpenFileMappingW / CreateFileMappingW
Expand Down
4 changes: 3 additions & 1 deletion Modules/pwdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include "Python.h"
#include "posixmodule.h"

#include <pwd.h>
#include <pwd.h> // getpwuid()
#include <unistd.h> // sysconf()


#include "clinic/pwdmodule.c.h"
/*[clinic input]
Expand Down
1 change: 1 addition & 0 deletions Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "pycore_time.h" // _PyTime_t

#include <stddef.h> // offsetof()
#include <unistd.h> // close()

#ifdef HAVE_SYS_DEVPOLL_H
#include <sys/resource.h>
Expand Down

0 comments on commit dddca41

Please sign in to comment.