Use C99 VLA instead of alloca when available
This commit is contained in:
+26
-11
@@ -159,6 +159,17 @@ IF(CMAKE_COMPILER_IS_GNUCC)
|
||||
SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
|
||||
ENDIF()
|
||||
|
||||
# Check if we have C99 variable length arrays
|
||||
CHECK_C_SOURCE_COMPILES(
|
||||
"int main(int argc, char *argv[])
|
||||
{
|
||||
volatile int tmp[argc];
|
||||
tmp[0] = argv[0][0];
|
||||
return tmp[0];
|
||||
}"
|
||||
HAVE_C99_VLA)
|
||||
|
||||
|
||||
# Add definitions, compiler switches, etc.
|
||||
INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}")
|
||||
IF(CMAKE_VERSION VERSION_LESS "2.8.8")
|
||||
@@ -302,8 +313,10 @@ ENDIF()
|
||||
CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
|
||||
int main() {return 0;}" HAVE_GCC_FORMAT)
|
||||
|
||||
IF(NOT HAVE_C99_VLA)
|
||||
CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H)
|
||||
ENDIF()
|
||||
CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
|
||||
CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H)
|
||||
CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
|
||||
CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
|
||||
CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
|
||||
@@ -327,18 +340,20 @@ CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
|
||||
CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
|
||||
CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
|
||||
CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
|
||||
IF(HAVE_ALLOCA_H)
|
||||
CHECK_SYMBOL_EXISTS(alloca alloca.h HAVE_ALLOCA)
|
||||
ELSEIF(HAVE_MALLOC_H)
|
||||
CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
|
||||
ENDIF()
|
||||
IF(NOT HAVE_ALLOCA)
|
||||
CHECK_SYMBOL_EXISTS(_alloca malloc.h HAVE__ALLOCA)
|
||||
IF(NOT HAVE__ALLOCA)
|
||||
MESSAGE(FATAL_ERROR "No alloca function found, please report!")
|
||||
IF(NOT HAVE_C99_VLA)
|
||||
IF(HAVE_ALLOCA_H)
|
||||
CHECK_SYMBOL_EXISTS(alloca alloca.h HAVE_ALLOCA)
|
||||
ELSEIF(HAVE_MALLOC_H)
|
||||
CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
|
||||
ENDIF()
|
||||
IF(NOT HAVE_ALLOCA)
|
||||
CHECK_SYMBOL_EXISTS(_alloca malloc.h HAVE__ALLOCA)
|
||||
IF(NOT HAVE__ALLOCA)
|
||||
MESSAGE(FATAL_ERROR "No alloca function found, please report!")
|
||||
ENDIF()
|
||||
|
||||
ADD_DEFINITIONS(-Dalloca=_alloca)
|
||||
ADD_DEFINITIONS(-Dalloca=_alloca)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
IF(HAVE_FLOAT_H)
|
||||
|
||||
@@ -314,6 +314,12 @@ typedef ptrdiff_t ALsizeiptrEXT;
|
||||
#define FORCE_ALIGN
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_C99_VLA
|
||||
#define DECL_VLA(T, _name, _size) T _name[(_size)]
|
||||
#else
|
||||
#define DECL_VLA(T, _name, _size) T *_name = alloca((_size) * sizeof(T))
|
||||
#endif
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#ifdef MAX_PATH
|
||||
#define PATH_MAX MAX_PATH
|
||||
|
||||
@@ -917,10 +917,9 @@ static void Convert_##T##_ALima4(T *dst, const ALima4 *src, ALuint numchans, \
|
||||
ALuint len, ALuint align) \
|
||||
{ \
|
||||
ALsizei byte_align = ((align-1)/2 + 4) * numchans; \
|
||||
DECL_VLA(ALshort, tmp, align*numchans); \
|
||||
ALuint i, j, k; \
|
||||
ALshort *tmp; \
|
||||
\
|
||||
tmp = alloca(align*numchans*sizeof(*tmp)); \
|
||||
for(i = 0;i < len;i += align) \
|
||||
{ \
|
||||
DecodeIMA4Block(tmp, src, numchans, align); \
|
||||
@@ -968,10 +967,9 @@ static void Convert_ALima4_##T(ALima4 *dst, const T *src, ALuint numchans, \
|
||||
ALint sample[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0}; \
|
||||
ALint index[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0}; \
|
||||
ALsizei byte_align = ((align-1)/2 + 4) * numchans; \
|
||||
DECL_VLA(ALshort, tmp, align*numchans); \
|
||||
ALuint i, j, k; \
|
||||
ALshort *tmp; \
|
||||
\
|
||||
tmp = alloca(align*numchans*sizeof(*tmp)); \
|
||||
for(i = 0;i < len;i += align) \
|
||||
{ \
|
||||
for(j = 0;j < align;j++) \
|
||||
@@ -1020,10 +1018,9 @@ static void Convert_##T##_ALmsadpcm(T *dst, const ALmsadpcm *src, \
|
||||
ALuint align) \
|
||||
{ \
|
||||
ALsizei byte_align = ((align-2)/2 + 7) * numchans; \
|
||||
DECL_VLA(ALshort, tmp, align*numchans); \
|
||||
ALuint i, j, k; \
|
||||
ALshort *tmp; \
|
||||
\
|
||||
tmp = alloca(align*numchans*sizeof(*tmp)); \
|
||||
for(i = 0;i < len;i += align) \
|
||||
{ \
|
||||
DecodeMSADPCMBlock(tmp, src, numchans, align); \
|
||||
@@ -1071,10 +1068,9 @@ static void Convert_ALmsadpcm_##T(ALmsadpcm *dst, const T *src, \
|
||||
{ \
|
||||
ALint sample[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0}; \
|
||||
ALsizei byte_align = ((align-2)/2 + 7) * numchans; \
|
||||
DECL_VLA(ALshort, tmp, align*numchans); \
|
||||
ALuint i, j, k; \
|
||||
ALshort *tmp; \
|
||||
\
|
||||
tmp = alloca(align*numchans*sizeof(*tmp)); \
|
||||
for(i = 0;i < len;i += align) \
|
||||
{ \
|
||||
for(j = 0;j < align;j++) \
|
||||
|
||||
@@ -89,6 +89,9 @@
|
||||
/* Define to the size of a long long int type */
|
||||
#cmakedefine SIZEOF_LONG_LONG ${SIZEOF_LONG_LONG}
|
||||
|
||||
/* Define if we have C99 variable-length array support */
|
||||
#cmakedefine HAVE_C99_VLA
|
||||
|
||||
/* Define if we have GCC's destructor attribute */
|
||||
#cmakedefine HAVE_GCC_DESTRUCTOR
|
||||
|
||||
|
||||
Reference in New Issue
Block a user