Skip to content

Commit 2849947

Browse files
authored
bpo-45434: Limited Python.h no longer includes stdio.h (GH-28960)
The <Python.h> header file no longer includes <stdio.h> if the Py_LIMITED_API macro is defined.
1 parent af1083e commit 2849947

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,13 @@ Porting to Python 3.11
565565
``exit()`` and ``abort()``.
566566
(Contributed by Victor Stinner in :issue:`45434`.)
567567

568+
* The ``<Python.h>`` header file no longer includes ``<stdio.h>`` if the
569+
``Py_LIMITED_API`` macro is defined. Functions expecting ``FILE*`` are
570+
excluded from the limited C API (:pep:`384`). C extensions using
571+
``<stdio.h>`` must now include it explicitly. The system ``<stdio.h>``
572+
header provides functions like ``printf()`` and ``fopen()``.
573+
(Contributed by Victor Stinner in :issue:`45434`.)
574+
568575
Deprecated
569576
----------
570577

Include/Python.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616
# define _SGI_MP_SOURCE
1717
#endif
1818

19-
#include <stdio.h> // NULL, FILE*
20-
#ifndef NULL
21-
# error "Python.h requires that stdio.h define NULL."
22-
#endif
23-
2419
#include <string.h> // memcpy()
20+
#ifndef Py_LIMITED_API
21+
# include <stdio.h> // FILE*
22+
#endif
2523
#ifdef HAVE_ERRNO_H
2624
# include <errno.h> // errno
2725
#endif
2826
#ifndef MS_WINDOWS
2927
# include <unistd.h>
3028
#endif
3129
#ifdef HAVE_STDDEF_H
32-
// For size_t
33-
# include <stddef.h>
30+
# include <stddef.h> // size_t
3431
#endif
3532

3633
#include <assert.h> // assert()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The ``<Python.h>`` header file no longer includes ``<stdio.h>`` if the
2+
``Py_LIMITED_API`` macro is defined. Functions expecting ``FILE*`` are excluded
3+
from the limited C API (:pep:`384`). C extensions using ``<stdio.h>`` must now
4+
include it explicitly.
5+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)