Skip to content

Commit dddca41

Browse files
committed
gh-108765: Python.h no longer includes <unistd.h>
1 parent 45b9e6a commit dddca41

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,10 @@ New Features
915915
Porting to Python 3.13
916916
----------------------
917917

918+
* ``Python.h`` no longer includes the ``<unistd.h>`` standard header file. If
919+
needed, it should now be included explicitly.
920+
(Contributed by Victor Stinner in :gh:`108765`.)
921+
918922
Deprecated
919923
----------
920924

Include/Python.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
#ifdef HAVE_STDDEF_H
2626
# include <stddef.h> // size_t
2727
#endif
28-
#ifndef MS_WINDOWS
29-
# include <unistd.h> // sysconf()
28+
#ifdef HAVE_SYS_TYPES_H
29+
# include <sys/types.h> // ssize_t
3030
#endif
3131

32-
// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by Python
33-
// headers, but kept for backward compatibility (no introduce new compiler
34-
// warnings). They are not included by the limited C API version 3.11 and
35-
// above.
32+
// errno.h, stdio.h, stdlib.h and string.h headers are no longer used by
33+
// Python, but kept for backward compatibility (avoid compiler warnings).
34+
// They are no longer included by limited C API version 3.11 and newer.
3635
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
3736
# include <errno.h> // errno
3837
# include <stdio.h> // FILE*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``Python.h`` no longer includes the ``<unistd.h>`` standard header file. If
2+
needed, it should now be included explicitly. Patch by Victor Stinner.

Modules/grpmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include "Python.h"
55
#include "posixmodule.h"
66

7-
#include <grp.h>
7+
#include <grp.h> // getgrgid_r()
8+
#include <unistd.h> // sysconf()
89

910
#include "clinic/grpmodule.c.h"
1011
/*[clinic input]

Modules/mmapmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "pycore_fileutils.h" // _Py_stat_struct
2929

3030
#include <stddef.h> // offsetof()
31+
#include <unistd.h> // close()
3132

3233
// to support MS_WINDOWS_SYSTEM OpenFileMappingA / CreateFileMappingA
3334
// need to be replaced with OpenFileMappingW / CreateFileMappingW

Modules/pwdmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "Python.h"
55
#include "posixmodule.h"
66

7-
#include <pwd.h>
7+
#include <pwd.h> // getpwuid()
8+
#include <unistd.h> // sysconf()
9+
810

911
#include "clinic/pwdmodule.c.h"
1012
/*[clinic input]

Modules/selectmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "pycore_time.h" // _PyTime_t
1818

1919
#include <stddef.h> // offsetof()
20+
#include <unistd.h> // close()
2021

2122
#ifdef HAVE_SYS_DEVPOLL_H
2223
#include <sys/resource.h>

0 commit comments

Comments
 (0)