SOUND: Use alloca() for stack allocations

Using an array with a variable size is a gcc extension and is not
portable. The _alloca() method works but should be reworked at some point
to make use of a static buffer
This commit is contained in:
darkstar
2018-02-21 23:33:16 +01:00
parent 3b0c18d419
commit b8432a21a5
2 changed files with 36 additions and 0 deletions

View File

@@ -683,7 +683,17 @@ void adgold_timer_poll(void *p)
static void adgold_get_buffer(int32_t *buffer, int len, void *p)
{
adgold_t *adgold = (adgold_t *)p;
#ifdef _MSC_VER
/* TODO: Fix this to use a static buffer */
if (len > 512 * 1024)
{
pclog("adgold_get_buffer: possible stack overflow detected. Buffer size was %d bytes", 2 * len);
return;
}
int16_t *adgold_buffer = (int16_t *)_alloca(len * 2);
#else
int16_t adgold_buffer[len*2];
#endif
int c;

View File

@@ -40,6 +40,12 @@
#include "dbopl.h"
#include "nukedopl.h"
#include "snd_dbopl.h"
#ifdef _MSC_VER
/* for _alloca() and printing of the related error message with pclog() */
#include <stdio.h>
#include <malloc.h>
#include "../emu.h"
#endif
int opl3_type = 0;
@@ -184,7 +190,17 @@ uint8_t opl_read(int nr, uint16_t addr)
void opl2_update(int nr, int16_t *buffer, int samples)
{
int c;
#ifdef _MSC_VER
/* TODO: Fix this to use a static buffer */
if (samples > 512*1024)
{
pclog("opl2_update: possible stack overflow detected. sample count was %d", samples);
return;
}
Bit32s *buffer_32 = (Bit32s *)_alloca(samples);
#else
Bit32s buffer_32[samples];
#endif
opl[nr].chip.GenerateBlock2(samples, buffer_32);
@@ -195,7 +211,17 @@ void opl2_update(int nr, int16_t *buffer, int samples)
void opl3_update(int nr, int16_t *buffer, int samples)
{
int c;
#ifdef _MSC_VER
/* TODO: Fix this to use a static buffer */
if (samples > 512 * 1024)
{
pclog("opl2_update: possible stack overflow detected. sample count was %d", samples);
return;
}
Bit32s *buffer_32 = (Bit32s *)_alloca(samples);
#else
Bit32s buffer_32[samples*2];
#endif
if (opl3_type)
{