From b8766aef6760d4920abe7440c6b44528e635e66b Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sun, 12 Nov 2017 16:16:34 +0100 Subject: [PATCH] Use alloca()/_alloca() on C89/C90 compilers without VLA --- CMakeLists.txt | 12 ++++++++++++ src/config.cmake | 6 ++++++ src/utils/fluidsynth_priv.h | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a1b2282..12f0f7d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,6 +133,18 @@ include ( TestVLA ) include ( TestBigEndian ) test_big_endian ( WORDS_BIGENDIAN ) +unset ( HAVE_ALLOCA CACHE ) +CHECK_FUNCTION_EXISTS ( "alloca" HAVE_ALLOCA ) +if ( HAVE_ALLOCA ) + set ( HAVE_ALLOCA 1 ) +endif ( HAVE_ALLOCA ) + +unset ( HAVE__ALLOCA CACHE ) +CHECK_FUNCTION_EXISTS ( "_alloca" HAVE__ALLOCA ) +if ( HAVE__ALLOCA ) + set ( HAVE__ALLOCA 1 ) +endif ( HAVE__ALLOCA ) + unset ( LIBFLUID_CPPFLAGS CACHE ) unset ( LIBFLUID_LIBS CACHE ) unset ( FLUID_CPPFLAGS CACHE ) diff --git a/src/config.cmake b/src/config.cmake index 0d970333..ec443e57 100644 --- a/src/config.cmake +++ b/src/config.cmake @@ -133,6 +133,12 @@ /* Define to 1 if you have the inet_ntop() function. */ #cmakedefine HAVE_INETNTOP @HAVE_INETNTOP@ +/* Define to 1 if you have the alloca() function. */ +#cmakedefine HAVE_ALLOCA @HAVE_ALLOCA@ + +/* Define to 1 if you have the _alloca() function. */ +#cmakedefine HAVE__ALLOCA @HAVE__ALLOCA@ + /* Define to enable JACK driver */ #cmakedefine JACK_SUPPORT @JACK_SUPPORT@ diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h index 90514a50..2e1b4f4b 100644 --- a/src/utils/fluidsynth_priv.h +++ b/src/utils/fluidsynth_priv.h @@ -180,6 +180,12 @@ typedef int fluid_socket_t; #if defined(SUPPORTS_VLA) # define FLUID_DECLARE_VLA(_type, _name, _len) \ _type _name[_len] +#elif defined HAVE_ALLOCA +# define FLUID_DECLARE_VLA(_type, _name, _len) \ + _type * _name = (_type *)alloca(_len * sizeof(_type)) +#elif defined HAVE__ALLOCA +# define FLUID_DECLARE_VLA(_type, _name, _len) \ + _type * _name = (_type *)_alloca(_len * sizeof(_type)) #else # define FLUID_DECLARE_VLA(_type, _name, _len) \ _type* _name = g_newa(_type, (_len))