Skip to content

Commit 780059a

Browse files
committed
handle non-vla compilers
Leverages the C std version and the standard __STDC_NO_VLA__ macro to detect whether VLA is supported, and if not falls back to using alloca.
1 parent 49bba95 commit 780059a

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/arch.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,15 @@ static OPUS_INLINE int celt_isnan(float x)
258258
#endif
259259
#endif
260260

261+
#if __STDC_VERSION__ < 199901L || (__STDC_VERSION__ > 201000L && __STDC_NO_VLA__ == 1)
262+
#define NO_VLA
263+
#endif
264+
265+
#ifdef NO_VLA
266+
#include <malloc.h>
267+
#define stackalloc(type, id, len) type *id = alloca(len)
268+
#else
269+
#define stackalloc(type, id, len) type id[len]
270+
#endif
271+
261272
#endif /* ARCH_H */

src/celt_lpc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void celt_fir(
9696
int ord)
9797
{
9898
int i,j;
99-
opus_val16 rnum[ord];
99+
stackalloc(opus_val16, rnum, ord);
100100
for(i=0;i<ord;i++)
101101
rnum[i] = num[ord-i-1];
102102
for (i=0;i<N-3;i+=4)
@@ -147,8 +147,8 @@ void tn_celt_iir(const opus_val32 *_x,
147147
#else
148148
int i,j;
149149
celt_assert((ord&3)==0);
150-
opus_val16 rden[ord];
151-
opus_val16 y[N+ord];
150+
stackalloc(opus_val16, rden, ord);
151+
stackalloc(opus_val16, y, N+ord);
152152
for(i=0;i<ord;i++)
153153
rden[i] = den[ord-i-1];
154154
for(i=0;i<ord;i++)
@@ -208,7 +208,7 @@ int _tn_celt_autocorr(
208208
int fastN=n-lag;
209209
int shift;
210210
const opus_val16 *xptr;
211-
opus_val16 xx[n];
211+
stackalloc(opus_val16, xx, n);
212212
celt_assert(n>0);
213213
celt_assert(overlap>=0);
214214
if (overlap == 0)

src/pitch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ void tn_pitch_search(const opus_val16 *x_lp, opus_val16 *y,
297297
celt_assert(max_pitch>0);
298298
lag = len+max_pitch;
299299

300-
opus_val16 x_lp4[len>>2];
301-
opus_val16 y_lp4[lag>>2];
302-
opus_val32 xcorr[max_pitch>>1];
300+
stackalloc(opus_val16, x_lp4, len>>2);
301+
stackalloc(opus_val16, y_lp4, lag>>2);
302+
stackalloc(opus_val32, xcorr, max_pitch>>1);
303303

304304
/* Downsample by 2 again */
305305
for (j=0;j<len>>2;j++)
@@ -443,7 +443,7 @@ opus_val16 tn_remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
443443
*T0_=maxperiod-1;
444444

445445
T = T0 = *T0_;
446-
opus_val32 yy_lookup[maxperiod+1];
446+
stackalloc(opus_val32, yy_lookup, maxperiod+1);
447447
dual_inner_prod(x, x, x-T0, N, &xx, &xy);
448448
yy_lookup[0] = xx;
449449
yy=xx;

0 commit comments

Comments
 (0)