Skip to content

Commit

Permalink
there is no 'dealloca' in stb_vorbis: we need alloca().
Browse files Browse the repository at this point in the history
also, if HAVE_LIBC is defined, alloca -> SDL_stack_alloc
definition used to become a chicken-egg problem...
  • Loading branch information
sezero committed Mar 15, 2021
1 parent 37223b0 commit cd752f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/SDL_sound_vorbis.c
Expand Up @@ -43,9 +43,6 @@
#ifdef memcpy
#undef memcpy
#endif
#ifdef alloca
#undef alloca
#endif
#define assert SDL_assert
#define memset SDL_memset
#define memcmp SDL_memcmp
Expand All @@ -56,8 +53,12 @@
#define malloc SDL_malloc
#define realloc SDL_realloc
#define free SDL_free
/* there is no 'dealloca' in stb_vorbis: we need alloca()
#ifdef alloca
#undef alloca
#endif
#define alloca(x) ((void *) SDL_stack_alloc(Uint8, (x)))
#define dealloca(x) SDL_stack_free((x))
*/
#define ldexp(v, e) SDL_scalbn((v), (e))
#define abs(x) SDL_abs(x)
#define cos(x) SDL_cos(x)
Expand Down
23 changes: 13 additions & 10 deletions src/stb_vorbis.h
Expand Up @@ -559,14 +559,6 @@ enum STBVorbisError
#include <string.h>
#include <assert.h>
#include <math.h>

// find definition of alloca if it's not in stdlib.h:
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <malloc.h>
#endif
#if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__)
#include <alloca.h>
#endif
#else // STB_VORBIS_NO_CRT
#ifndef NULL
#define NULL 0
Expand All @@ -584,8 +576,19 @@ enum STBVorbisError

#include <limits.h>

#if defined(__MINGW32__) && !defined(alloca)
#define alloca __builtin_alloca
/* we need alloca() regardless of STB_VORBIS_NO_CRT,
* because there is not a corresponding 'dealloca' */
#if !defined(alloca)
# if defined(HAVE_ALLOCA_H)
# include <alloca.h>
# elif defined(__GNUC__)
# define alloca __builtin_alloca
# elif defined(_MSC_VER)
# include <malloc.h>
# define alloca _alloca
# elif defined(__WATCOMC__)
# include <malloc.h>
# endif
#endif

#ifndef STB_FORCEINLINE
Expand Down

0 comments on commit cd752f6

Please sign in to comment.