]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-134486: Fix missing alloca() symbol in _ctypes on NetBSD (#134487)
authorCollin Funk <collin.funk1@gmail.com>
Fri, 23 May 2025 11:11:04 +0000 (04:11 -0700)
committerGitHub <noreply@github.com>
Fri, 23 May 2025 11:11:04 +0000 (13:11 +0200)
Previously the module would fail to load because the `alloca()` symbol
was undefined. Now we check for GCC/Clang builtins for systems who do
not define `alloca()` in headers.

Misc/NEWS.d/next/Build/2025-05-21-22-13-30.gh-issue-134486.yvdL6f.rst [new file with mode: 0644]
Modules/_ctypes/callbacks.c
Modules/_ctypes/callproc.c
Modules/_ctypes/ctypes.h

diff --git a/Misc/NEWS.d/next/Build/2025-05-21-22-13-30.gh-issue-134486.yvdL6f.rst b/Misc/NEWS.d/next/Build/2025-05-21-22-13-30.gh-issue-134486.yvdL6f.rst
new file mode 100644 (file)
index 0000000..2754e61
--- /dev/null
@@ -0,0 +1,3 @@
+The :mod:`ctypes` module now performs a more portable test for the
+definition of :manpage:`alloca(3)`, fixing a compilation failure on
+NetBSD.
index ec113e41d163238eef0393038fa3e4e705842719..fd508ae61f2e0403668716fdbbf0e04d6b76e810 100644 (file)
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_runtime.h"       // _Py_ID()
 
-#ifdef MS_WIN32
-#  include <malloc.h>
-#endif
-
 #include <ffi.h>
 #include "ctypes.h"
 
-#ifdef HAVE_ALLOCA_H
-/* AIX needs alloca.h for alloca() */
-#include <alloca.h>
-#endif
-
 /**************************************************************/
 
 static int
index 9f5ad9f57b75e2bd1ca4553eca6a6bc8655fa970..65a0f14e2b076c8c4575947b34cede6b9d445e34 100644 (file)
@@ -77,16 +77,8 @@ module _ctypes
 #include <mach-o/dyld.h>
 #endif
 
-#ifdef MS_WIN32
-#include <malloc.h>
-#endif
-
 #include <ffi.h>
 #include "ctypes.h"
-#ifdef HAVE_ALLOCA_H
-/* AIX needs alloca.h for alloca() */
-#include <alloca.h>
-#endif
 
 #ifdef _Py_MEMORY_SANITIZER
 #include <sanitizer/msan_interface.h>
index 2d859ed63e1758df60483de3f88546adb9b4f073..6a45c11e61af5c7a0b72298b28b0dfc121133272 100644 (file)
@@ -1,5 +1,17 @@
-#if defined (__SVR4) && defined (__sun)
+/* Get a definition of alloca(). */
+#if (defined (__SVR4) && defined (__sun)) || defined(HAVE_ALLOCA_H)
 #   include <alloca.h>
+#elif defined(MS_WIN32)
+#   include <malloc.h>
+#endif
+
+/* If the system does not define alloca(), we have to hope for a compiler builtin. */
+#ifndef alloca
+#   if defined __GNUC__ || (__clang_major__ >= 4)
+#      define alloca __builtin_alloca
+#   else
+#     error "Could not define alloca() on your platform."
+#   endif
 #endif
 
 #include <stdbool.h>