Skip to content

Commit 2103a25

Browse files
committed
gh-134486: Fix missing alloca symbol in _ctypes on NetBSD.
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.
1 parent 979d81a commit 2103a25

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :mod:`ctypes` module now performs a more portable test for the
2+
definition of :man:`alloca(3)`, fixing a compilation failure on NetBSD.

Modules/_ctypes/callbacks.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,9 @@
1111
#include "pycore_call.h" // _PyObject_CallNoArgs()
1212
#include "pycore_runtime.h" // _Py_ID()
1313

14-
#ifdef MS_WIN32
15-
# include <malloc.h>
16-
#endif
17-
1814
#include <ffi.h>
1915
#include "ctypes.h"
2016

21-
#ifdef HAVE_ALLOCA_H
22-
/* AIX needs alloca.h for alloca() */
23-
#include <alloca.h>
24-
#endif
25-
2617
/**************************************************************/
2718

2819
static int

Modules/_ctypes/callproc.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,8 @@ module _ctypes
7777
#include <mach-o/dyld.h>
7878
#endif
7979

80-
#ifdef MS_WIN32
81-
#include <malloc.h>
82-
#endif
83-
8480
#include <ffi.h>
8581
#include "ctypes.h"
86-
#ifdef HAVE_ALLOCA_H
87-
/* AIX needs alloca.h for alloca() */
88-
#include <alloca.h>
89-
#endif
9082

9183
#ifdef _Py_MEMORY_SANITIZER
9284
#include <sanitizer/msan_interface.h>

Modules/_ctypes/ctypes.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
#if defined (__SVR4) && defined (__sun)
1+
/* Get a definition of alloca(). */
2+
#if (defined (__SVR4) && defined (__sun)) || defined(HAVE_ALLOCA_H)
23
# include <alloca.h>
4+
#elif defined(MS_WIN32)
5+
# include <malloc.h>
6+
#endif
7+
8+
/* If the system does not define alloca(), we have to hope for a compiler builtin. */
9+
#ifndef alloca
10+
# if defined __GNUC__ || (__clang_major__ >= 4)
11+
# define alloca __builtin_alloca
12+
# else
13+
# error "Could not define alloca() on your platform."
14+
# endif
315
#endif
416

517
#include <stdbool.h>

0 commit comments

Comments
 (0)