FastLED 3.9.15
Loading...
Searching...
No Matches
alloca.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/has_include.h" // IWYU pragma: keep
4
5// Conditional stack array support includes - must be before namespace
6#ifndef FASTLED_VARIABLE_LENGTH_ARRAY_NEEDS_EMULATION
7#if defined(FL_IS_CLANG) || defined(FL_IS_STM32_H7)
8// Clang doesn't have variable length arrays. Therefore we need to emulate them
9// using alloca. It's been found that Arduino Giga M7 also doesn't support
10// variable length arrays for some reason so we force it to emulate them as well
11// in this case.
12#define FASTLED_VARIABLE_LENGTH_ARRAY_NEEDS_EMULATION 1
13#else
14// Else, assume the compiler is gcc, which has variable length arrays
15#define FASTLED_VARIABLE_LENGTH_ARRAY_NEEDS_EMULATION 0
16#endif
17#endif // FASTLED_VARIABLE_LENGTH_ARRAY_NEEDS_EMULATION
18
31#if !FASTLED_VARIABLE_LENGTH_ARRAY_NEEDS_EMULATION
32#define FASTLED_STACK_ARRAY(TYPE, NAME, SIZE) \
33 TYPE NAME[SIZE]; \
34 fl::memset(NAME, 0, sizeof(TYPE) * (SIZE))
35#elif FL_HAS_INCLUDE(<alloca.h>)
36// IWYU pragma: begin_keep
37#include <alloca.h>
38// IWYU pragma: end_keep
39#define FASTLED_STACK_ARRAY(TYPE, NAME, SIZE) \
40 TYPE *NAME = fl::bit_cast_ptr<TYPE>(alloca(sizeof(TYPE) * (SIZE))); \
41 fl::memset(NAME, 0, sizeof(TYPE) * (SIZE))
42#elif FL_HAS_INCLUDE(<malloc.h>)
43// IWYU pragma: begin_keep
44#include <malloc.h>
45// IWYU pragma: end_keep
46#define FASTLED_STACK_ARRAY(TYPE, NAME, SIZE) \
47 TYPE *NAME = fl::bit_cast_ptr<TYPE>(alloca(sizeof(TYPE) * (SIZE))); \
48 fl::memset(NAME, 0, sizeof(TYPE) * (SIZE))
49#else
50#error "Compiler does not allow variable type arrays."
51#endif