]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45434: Limited Python.h no longer includes stdio.h (GH-28960)
authorVictor Stinner <vstinner@python.org>
Thu, 14 Oct 2021 23:09:06 +0000 (01:09 +0200)
committerGitHub <noreply@github.com>
Thu, 14 Oct 2021 23:09:06 +0000 (01:09 +0200)
The <Python.h> header file no longer includes <stdio.h> if the
Py_LIMITED_API macro is defined.

Doc/whatsnew/3.11.rst
Include/Python.h
Misc/NEWS.d/next/C API/2021-10-15-00-30-45.bpo-45434.XLtsbK.rst [new file with mode: 0644]

index e8d64a80a69a36aaa54347afa01593db579f4e33..a6e30c77c55a0dc0193dcddd747597ebc2fbc78a 100644 (file)
@@ -565,6 +565,13 @@ Porting to Python 3.11
   ``exit()`` and ``abort()``.
   (Contributed by Victor Stinner in :issue:`45434`.)
 
+* The ``<Python.h>`` header file no longer includes ``<stdio.h>`` if the
+  ``Py_LIMITED_API`` macro is defined. Functions expecting ``FILE*`` are
+  excluded from the limited C API (:pep:`384`). C extensions using
+  ``<stdio.h>`` must now include it explicitly.  The system ``<stdio.h>``
+  header provides functions like ``printf()`` and ``fopen()``.
+  (Contributed by Victor Stinner in :issue:`45434`.)
+
 Deprecated
 ----------
 
index 4f62103e30276cdc48a1b943609513a3f58015c9..dc5c9b8e6384e8fe8cacf5c677b9030bb6046c43 100644 (file)
 #  define _SGI_MP_SOURCE
 #endif
 
-#include <stdio.h>                // NULL, FILE*
-#ifndef NULL
-#   error "Python.h requires that stdio.h define NULL."
-#endif
-
 #include <string.h>               // memcpy()
+#ifndef Py_LIMITED_API
+#  include <stdio.h>              // FILE*
+#endif
 #ifdef HAVE_ERRNO_H
 #  include <errno.h>              // errno
 #endif
@@ -29,8 +27,7 @@
 #  include <unistd.h>
 #endif
 #ifdef HAVE_STDDEF_H
-   // For size_t
-#  include <stddef.h>
+#  include <stddef.h>             // size_t
 #endif
 
 #include <assert.h>               // assert()
diff --git a/Misc/NEWS.d/next/C API/2021-10-15-00-30-45.bpo-45434.XLtsbK.rst b/Misc/NEWS.d/next/C API/2021-10-15-00-30-45.bpo-45434.XLtsbK.rst
new file mode 100644 (file)
index 0000000..4a06635
--- /dev/null
@@ -0,0 +1,5 @@
+The ``<Python.h>`` header file no longer includes ``<stdio.h>`` if the
+``Py_LIMITED_API`` macro is defined. Functions expecting ``FILE*`` are excluded
+from the limited C API (:pep:`384`). C extensions using ``<stdio.h>`` must now
+include it explicitly.
+Patch by Victor Stinner.