From 1857e62fdcb9a9fb0df987b2502ed98346457a6f Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Wed, 2 Oct 2024 23:46:14 +0200 Subject: [PATCH] examples/natmod/re: Fix build on RV32 with alloca. This fixes compilation of the `re` natmod example when built with Picolibc in the CI environment. Ubuntu 22.04's combination of its bare metal RISC-V toolchain and its version of Picolibc makes the `alloca` symbol more elusive than it should be. This commit makes the `re` natmod try harder to get an `alloca` implementation. Signed-off-by: Alessandro Gatti --- examples/natmod/re/re.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/natmod/re/re.c b/examples/natmod/re/re.c index eb6d13778..c0279ee7e 100644 --- a/examples/natmod/re/re.c +++ b/examples/natmod/re/re.c @@ -4,7 +4,20 @@ #define MICROPY_PY_RE_MATCH_SPAN_START_END (1) #define MICROPY_PY_RE_SUB (0) // requires vstr interface +#if defined __has_builtin +#if __has_builtin(__builtin_alloca) +#define alloca __builtin_alloca +#endif +#endif + +#if !defined(alloca) +#if defined(_PICOLIBC__) && !defined(HAVE_BUILTIN_ALLOCA) +#define alloca(n) m_malloc(n) +#else #include +#endif +#endif + #include "py/dynruntime.h" #define STACK_LIMIT (2048)