]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45434: pyport.h no longer includes <stdlib.h> (GH-28914)
authorVictor Stinner <vstinner@python.org>
Wed, 13 Oct 2021 17:25:53 +0000 (19:25 +0200)
committerGitHub <noreply@github.com>
Wed, 13 Oct 2021 17:25:53 +0000 (19:25 +0200)
Include <stdlib.h> explicitly in C files.

Python.h includes <wchar.h>.

29 files changed:
Doc/whatsnew/3.11.rst
Include/Python.h
Include/internal/pycore_fileutils.h
Include/pyport.h
Misc/NEWS.d/next/C API/2021-10-11-23-03-49.bpo-45434.tsS8I_.rst
Modules/_ctypes/_ctypes_test.c
Modules/_gdbmmodule.c
Modules/_lzmamodule.c
Modules/_pickle.c
Modules/_tracemalloc.c
Modules/faulthandler.c
Modules/getpath.c
Modules/nismodule.c
Modules/ossaudiodev.c
Modules/posixmodule.c
Modules/readline.c
Objects/floatobject.c
Objects/longobject.c
Objects/obmalloc.c
PC/WinMain.c
Programs/_freeze_module.c
Programs/_testembed.c
Python/dtoa.c
Python/errors.c
Python/fileutils.c
Python/initconfig.c
Python/preconfig.c
Python/pylifecycle.c
Python/pystrhex.c

index 21a0e1ab9c693f58f799ca35c9a4a58a98eb0146..d18711d0b8df22cab5eaeab9109778d3167dbe85 100644 (file)
@@ -556,6 +556,9 @@ Porting to Python 3.11
 
 * The ``<Python.h>`` header file no longer includes ``<stdlib.h>``. C
   extensions using ``<stdlib.h>`` must now include it explicitly.
+  The system ``<stdlib.h>`` header provides functions like:
+  ``malloc()``/``free()``, ``getenv()``, ``strtol()``, ``abs()``, ``strtol()``,
+  ``exit()`` and ``abort()``.
   (Contributed by Victor Stinner in :issue:`45434`.)
 
 Deprecated
index 8c84c90f9a57e68dd889691b0ad36054e9c37d30..4f62103e30276cdc48a1b943609513a3f58015c9 100644 (file)
@@ -33,7 +33,8 @@
 #  include <stddef.h>
 #endif
 
-#include <assert.h>
+#include <assert.h>               // assert()
+#include <wchar.h>                // wchar_t
 
 #include "pyport.h"
 #include "pymacro.h"
index 2316a978294e2091b84e17b41c7b4dc3cd613ea9..3464477bce57558a42c37d4b8c28c71ec1b1e71d 100644 (file)
@@ -88,6 +88,9 @@ extern int _Py_add_relfile(wchar_t *dirname,
 //      ...
 //      _Py_END_SUPPRESS_IPH
 #if defined _MSC_VER && _MSC_VER >= 1900
+
+#  include <stdlib.h>   // _set_thread_local_invalid_parameter_handler()
+
    extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
 #  define _Py_BEGIN_SUPPRESS_IPH \
     { _invalid_parameter_handler _Py_old_handler = \
index 6e4e98020cb1fb906acd3699eb1ef635751f760f..0bec2a9b38f7c9a8280baa1e6461aca65d95777c 100644 (file)
@@ -205,8 +205,6 @@ typedef Py_ssize_t Py_ssize_clean_t;
  * see https://bugs.python.org/issue28126 */
 #define Py_MEMCPY memcpy
 
-#include <stdlib.h>
-
 #ifdef HAVE_IEEEFP_H
 #include <ieeefp.h>  /* needed for 'finite' declaration on some platforms */
 #endif
index c04dda532557ddb42acf3865abefa4dd2026e0fd..95c5f0d1150c819d9040d5b728d6964898ce926a 100644 (file)
@@ -1,3 +1,6 @@
 The ``<Python.h>`` header file no longer includes ``<stdlib.h>``. C
-extensions using ``<stdlib.h>`` must now include it explicitly. Patch by
-Victor Stinner.
+extensions using ``<stdlib.h>`` must now include it explicitly.
+The system ``<stdlib.h>`` header provides functions like:
+``malloc()``/``free()``, ``getenv()``, ``strtol()``, ``abs()``, ``strtol()``,
+``exit()`` and ``abort()``.
+Patch by Victor Stinner.
index a33d15de9c0d413e4956630536e2903180332614..770c96c60d1f7d2ab125c0d8f3452658238f6595 100644 (file)
@@ -4,6 +4,8 @@
 #include <windows.h>
 #endif
 
+#include <stdlib.h>               // qsort()
+
 #define EXPORT(x) Py_EXPORTED_SYMBOL x
 
 /* some functions handy for testing */
index efbf331ca302d1efdea1fe613126dd007a81a681..445500c7ee4c157658d4cb96d052055be130b13e 100644 (file)
@@ -5,11 +5,12 @@
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
+#include "gdbm.h"
 
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <fcntl.h>
-#include "gdbm.h"
+#include <stdlib.h>               // free()
+#include <sys/stat.h>
+#include <sys/types.h>
 
 #if defined(WIN32) && !defined(__CYGWIN__)
 #include "gdbmerrno.h"
index a7156ec7ddf042399c43c03433f9af8f32bc7ece..e50f55b75c5dc5b0d89c6179a972dd3baf4ce901 100644 (file)
@@ -10,6 +10,7 @@
 #include "Python.h"
 #include "structmember.h"         // PyMemberDef
 
+#include <stdlib.h>               // free()
 #include <string.h>
 
 #include <lzma.h>
index e693b506a1e91ff0c82e7f50f7cdee0c8aa92032..b5131696981dc561a1f09588a1593d9e565662d5 100644 (file)
@@ -12,6 +12,8 @@
 #include "pycore_moduleobject.h"  // _PyModule_GetState()
 #include "structmember.h"         // PyMemberDef
 
+#include <stdlib.h>               // strtol()
+
 PyDoc_STRVAR(pickle_module_doc,
 "Optimized C implementation for the Python pickle module.");
 
index 9ba0ebbbaab5c5ed494b6c48f47fcfa6021f22d4..09d273ad280bbe42c6705858a8d617327055886f 100644 (file)
@@ -5,7 +5,10 @@
 #include "pycore_hashtable.h"
 #include <pycore_frame.h>
 
+#include <stdlib.h>               // malloc()
+
 #include "clinic/_tracemalloc.c.h"
+
 /*[clinic input]
 module _tracemalloc
 [clinic start generated code]*/
index 868b4f4f42de68af161b66327455381a23c58b25..cb2e2588e19b24cfed65cedbcd425714bd8ca8d7 100644 (file)
@@ -3,10 +3,13 @@
 #include "pycore_pyerrors.h"      // _Py_DumpExtensionModules
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 #include "pycore_traceback.h"     // _Py_DumpTracebackThreads
-#include <signal.h>
+
+#include "frameobject.h"
+
 #include <object.h>
-#include <frameobject.h>
 #include <signal.h>
+#include <signal.h>
+#include <stdlib.h>               // abort()
 #if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK)
 #  include <pthread.h>
 #endif
index 22e5ef24b5d57831b055238a697b0ab617ae7117..1405023b39b580d7ca1b2bf8bb4fe72ed54bce00 100644 (file)
@@ -6,8 +6,9 @@
 #include "pycore_pathconfig.h"
 #include "osdefs.h"               // DELIM
 
-#include <sys/types.h>
+#include <stdlib.h>               // getenv()
 #include <string.h>
+#include <sys/types.h>
 
 #ifdef __APPLE__
 #  include <mach-o/dyld.h>
index 6655451ebd2fbf7bd84fad8ff729f7be73e9243e..cdda1a6a2fb7d40b2f192ceeaa4cb0118435eb67 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "Python.h"
 
+#include <stdlib.h>               // free()
 #include <sys/time.h>
 #include <sys/types.h>
 #include <rpc/rpc.h>
index 4f2d9cb8b7c9c74f8c59760b21f110ab48cf5ab3..4bab9a58eb1045decbfd639774b578d1f5a5c59a 100644 (file)
@@ -21,6 +21,7 @@
 #include "Python.h"
 #include "structmember.h"         // PyMemberDef
 
+#include <stdlib.h>               // getenv()
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #else
index 9c174ee6b18df37106719b626a44e50d8e85a902..667a3339f5ba8e24601225e205721ae563b70314 100644 (file)
@@ -46,7 +46,8 @@
 #  undef HAVE_FACCESSAT
 #endif
 
-#include <stdio.h>  /* needed for ctermid() */
+#include <stdio.h>                // ctermid()
+#include <stdlib.h>               // system()
 
 /*
  * A number of APIs are available on macOS from a certain macOS version.
index c79d22f85f84ea3b1b4a5809cf1dc7dcf72168b7..1b616fc4f3b4e13b235732c9069d2bd3d64b4dae 100644 (file)
@@ -6,9 +6,11 @@
 
 /* Standard definitions */
 #include "Python.h"
-#include <stddef.h>
-#include <signal.h>
+
 #include <errno.h>
+#include <signal.h>
+#include <stddef.h>
+#include <stdlib.h>               // free()
 #include <sys/time.h>
 
 #if defined(HAVE_SETLOCALE)
index d25d97f4cbf61ff339952b3853afc4f932aa7dd2..5a8113eca8bd043101bbaa7c42b513397778f44c 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <ctype.h>
 #include <float.h>
+#include <stdlib.h>               // strtol()
 
 /*[clinic input]
 class float "PyObject *" "&PyFloat_Type"
index 33fea6491b73d223da2ecdda86f53a5990673fea..111ef4566cda8c995471fd8773b9780b445895be 100644 (file)
 #include "pycore_pystate.h"       // _Py_IsMainInterpreter()
 #include "longintrepr.h"
 
-#include <float.h>
 #include <ctype.h>
+#include <float.h>
 #include <stddef.h>
+#include <stdlib.h>               // abs()
 
 #include "clinic/longobject.c.h"
 /*[clinic input]
index 2d6fedd6cf0a19d6ded2bc60b9037b108cdf206d..d8d6f6dea0d532491f504c0a89d9f4434a8aba8c 100644 (file)
@@ -2,6 +2,7 @@
 #include "pycore_pymem.h"         // _PyTraceMalloc_Config
 
 #include <stdbool.h>
+#include <stdlib.h>               // malloc()
 
 
 /* Defined in tracemalloc.c */
index e439bed9ed113794118d34b80d8ad5068ed16aa8..07e21ce3e9f2d52ea4ec140b366baf71187748c4 100644 (file)
@@ -4,6 +4,7 @@
 
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
+#include <stdlib.h>  /* __argc, __wargv */
 
 int WINAPI wWinMain(
     HINSTANCE hInstance,      /* handle to current instance */
index dd90d92e512c09252409a817bb14316a938f540f..316c70d2c7824f7f27aa25926f056eba6dd194ea 100644 (file)
@@ -12,6 +12,7 @@
 #include <pycore_import.h>
 
 #include <stdio.h>
+#include <stdlib.h>               // malloc()
 #include <sys/types.h>
 #include <sys/stat.h>
 #ifndef MS_WINDOWS
index fa418e276114a20928974082fd9101dc369228d8..b61fe3461bdc98dd292471dbbf76f888e5af10b7 100644 (file)
@@ -11,6 +11,7 @@
 #include <Python.h>
 #include <inttypes.h>
 #include <stdio.h>
+#include <stdlib.h>               // putenv()
 #include <wchar.h>
 
 /*********************************************************
index e629b296426f318153903cad5f53832df1a17900..6c44f689651766eb5e28ee3bd87f963ae3479e3a 100644 (file)
 
 #include "Python.h"
 #include "pycore_dtoa.h"
+#include <stdlib.h>               // exit()
 
 /* if PY_NO_SHORT_FLOAT_REPR is defined, then don't even try to compile
    the following code */
index f072c214965925c6ed2bf5cceda32d20dcdde578..519f2d459effd662412ad39941d831cd16f83e80 100644 (file)
@@ -15,12 +15,13 @@ extern char *strerror(int);
 #endif
 #endif
 
+#include <ctype.h>
 #ifdef MS_WINDOWS
-#include <windows.h>
-#include <winbase.h>
+#  include <windows.h>
+#  include <winbase.h>
+#  include <stdlib.h>             // _sys_nerr
 #endif
 
-#include <ctype.h>
 
 #ifdef __cplusplus
 extern "C" {
index a36415946e2184499f629f89e5ba20371de67f6a..173d34dd23f18be8f31bbcb7ba171869c70ecdb2 100644 (file)
@@ -3,6 +3,7 @@
 #include "pycore_runtime.h"       // _PyRuntime
 #include "osdefs.h"               // SEP
 #include <locale.h>
+#include <stdlib.h>               // mbstowcs()
 
 #ifdef MS_WINDOWS
 #  include <malloc.h>
index ba6d19db20048b14314c576cbb92a28f2320aa74..b0d54b0472fb094a50e07023ba48fa836ed4af7d 100644 (file)
@@ -10,7 +10,9 @@
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 
 #include "osdefs.h"               // DELIM
+
 #include <locale.h>               // setlocale()
+#include <stdlib.h>               // getenv()
 #if defined(MS_WINDOWS) || defined(__CYGWIN__)
 #  ifdef HAVE_IO_H
 #    include <io.h>
index d59273159a671132498ef168f90902562e2555f5..afa16cccf32e96c6859b93860b3e6f14e9338a07 100644 (file)
@@ -4,7 +4,9 @@
 #include "pycore_initconfig.h"    // _PyArgv
 #include "pycore_pymem.h"         // _PyMem_GetAllocatorName()
 #include "pycore_runtime.h"       // _PyRuntime_Initialize()
+
 #include <locale.h>               // setlocale()
+#include <stdlib.h>               // getenv()
 
 
 /* Forward declarations */
index c67a9b7fbfa2d870af17371fb10defbff8749c24..c5a209abae61a36a14ca5fa5729df18fec553b8d 100644 (file)
@@ -16,6 +16,7 @@
 #include "pycore_traceback.h"     // _Py_DumpTracebackThreads()
 
 #include <locale.h>               // setlocale()
+#include <stdlib.h>               // getenv()
 
 #if defined(__APPLE__)
 #include <mach-o/loader.h>
index f7fe3b6eb85d0604787d1d60b0b1daef23339590..880af44ea0e94f6aec0ddf3ef84611af9e1e78a2 100644 (file)
@@ -1,8 +1,8 @@
 /* Format bytes as hexadecimal */
 
 #include "Python.h"
-#include "pycore_strhex.h"       // _Py_strhex_with_sep()
-
+#include "pycore_strhex.h"        // _Py_strhex_with_sep()
+#include <stdlib.h>               // abs()
 
 static PyObject *_Py_strhex_impl(const char* argbuf, const Py_ssize_t arglen,
                                  const PyObject* sep, int bytes_per_sep_group,