[vlc-devel] commit: Use stack array rather than alloca ( Rémi Denis-Courmont )
git version control
git at videolan.org
Fri Apr 10 20:17:01 CEST 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Apr 10 21:14:38 2009 +0300| [b870bc9ddf45f01d24adb398b5f442ddc87a00ae] | committer: Rémi Denis-Courmont
Use stack array rather than alloca
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b870bc9ddf45f01d24adb398b5f442ddc87a00ae
---
modules/audio_filter/converter/float.c | 18 +--------------
modules/audio_filter/resampler/bandlimited.c | 21 +++---------------
modules/audio_filter/resampler/linear.c | 20 +----------------
modules/audio_filter/resampler/ugly.c | 21 ++----------------
modules/demux/mkv/matroska_segment.cpp | 29 +++++++++++++------------
5 files changed, 26 insertions(+), 83 deletions(-)
diff --git a/modules/audio_filter/converter/float.c b/modules/audio_filter/converter/float.c
index 10dbe28..e2419a6 100644
--- a/modules/audio_filter/converter/float.c
+++ b/modules/audio_filter/converter/float.c
@@ -40,10 +40,6 @@
# include <unistd.h>
#endif
-#ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
-
#include <vlc_aout.h>
/*****************************************************************************
@@ -556,13 +552,9 @@ static void Do_S16ToFL32_SW( aout_instance_t * p_aout, aout_filter_t * p_filter,
float * p_out = (float *)p_out_buf->p_buffer + i - 1;
#ifdef HAVE_SWAB
-# ifdef HAVE_ALLOCA
- int16_t * p_swabbed = alloca( i * sizeof(int16_t) );
-# else
- int16_t * p_swabbed = malloc( i * sizeof(int16_t) );
-# endif
+ int16_t p_swabbed[i];
- swab( p_in_buf->p_buffer, (void *)p_swabbed, i * sizeof(int16_t) );
+ swab( p_in_buf->p_buffer, p_swabbed, i * sizeof(int16_t) );
p_in = p_swabbed + i - 1;
#else
@@ -582,12 +574,6 @@ static void Do_S16ToFL32_SW( aout_instance_t * p_aout, aout_filter_t * p_filter,
p_in--; p_out--;
}
-#ifdef HAVE_SWAB
-# ifndef HAVE_ALLOCA
- free( p_swabbed );
-# endif
-#endif
-
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 4 / 2;
}
diff --git a/modules/audio_filter/resampler/bandlimited.c b/modules/audio_filter/resampler/bandlimited.c
index 419fa44..9ec0714 100644
--- a/modules/audio_filter/resampler/bandlimited.c
+++ b/modules/audio_filter/resampler/bandlimited.c
@@ -184,7 +184,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{
filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
- float *p_in, *p_in_orig, *p_out = (float *)p_out_buf->p_buffer;
+ float *p_out = (float *)p_out_buf->p_buffer;
int i_nb_channels = aout_FormatNbChannels( &p_filter->input );
int i_in_nb = p_in_buf->i_nb_samples;
@@ -253,17 +253,9 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
/* Prepare the source buffer */
i_in_nb += (p_sys->i_old_wing * 2);
-#ifdef HAVE_ALLOCA
- p_in = p_in_orig = (float *)alloca( i_in_nb *
- p_filter->input.i_bytes_per_frame );
-#else
- p_in = p_in_orig = (float *)malloc( i_in_nb *
- p_filter->input.i_bytes_per_frame );
-#endif
- if( p_in == NULL )
- {
- return;
- }
+
+ float p_in_orig[i_in_nb * p_filter->input.i_bytes_per_frame / 4],
+ *p_in = p_in_orig;
/* Copy all our samples in p_in */
if( p_sys->i_old_wing )
@@ -460,11 +452,6 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
i_out * p_filter->input.i_bytes_per_frame );
#endif
- /* Free the temp buffer */
-#ifndef HAVE_ALLOCA
- free( p_in_orig );
-#endif
-
/* Finalize aout buffer */
p_out_buf->i_nb_samples = i_out;
p_out_buf->start_date = aout_DateGet( &p_sys->end_date );
diff --git a/modules/audio_filter/resampler/linear.c b/modules/audio_filter/resampler/linear.c
index 35ecee8..161b754 100644
--- a/modules/audio_filter/resampler/linear.c
+++ b/modules/audio_filter/resampler/linear.c
@@ -137,10 +137,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{
filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
-#ifndef HAVE_ALLOCA
- float *p_in_orig;
-#endif
- float *p_in, *p_out = (float *)p_out_buf->p_buffer;
+ float *p_out = (float *)p_out_buf->p_buffer;
float *p_prev_sample = (float *)p_sys->p_prev_sample;
int i_nb_channels = p_filter->input.i_channels;
@@ -164,15 +161,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
return;
}
-#ifdef HAVE_ALLOCA
- p_in = (float *)alloca( p_in_buf->i_nb_bytes );
-#else
- p_in_orig = p_in = (float *)malloc( p_in_buf->i_nb_bytes );
-#endif
- if( p_in == NULL )
- {
- return;
- }
+ float p_in_orig[p_in_buf->i_nb_bytes / 4], *p_in = p_in_orig;
vlc_memcpy( p_in, p_in_buf->p_buffer, p_in_buf->i_nb_bytes );
@@ -247,11 +236,6 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
p_out_buf->i_nb_bytes = p_out_buf->i_nb_samples *
i_nb_channels * sizeof(int32_t);
-
-#ifndef HAVE_ALLOCA
- free( p_in_orig );
-#endif
-
}
/*****************************************************************************
diff --git a/modules/audio_filter/resampler/ugly.c b/modules/audio_filter/resampler/ugly.c
index 3dab7af..28e38e7 100644
--- a/modules/audio_filter/resampler/ugly.c
+++ b/modules/audio_filter/resampler/ugly.c
@@ -86,10 +86,7 @@ static int Create( vlc_object_t *p_this )
static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{
- int32_t *p_in, *p_out = (int32_t*)p_out_buf->p_buffer;
-#ifndef HAVE_ALLOCA
- int32_t *p_in_orig;
-#endif
+ int32_t *p_out = (int32_t*)p_out_buf->p_buffer;
unsigned int i_nb_channels = aout_FormatNbChannels( &p_filter->input );
unsigned int i_in_nb = p_in_buf->i_nb_samples;
@@ -104,15 +101,8 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
return;
}
-#ifdef HAVE_ALLOCA
- p_in = (int32_t *)alloca( p_in_buf->i_nb_bytes );
-#else
- p_in_orig = p_in = (int32_t *)malloc( p_in_buf->i_nb_bytes );
-#endif
- if( p_in == NULL )
- {
- return;
- }
+ int32_t p_in_orig[p_in_buf->i_nb_bytes / sizeof(int32_t)],
+ *p_in = p_in_orig;
vlc_memcpy( p_in, p_in_buf->p_buffer, p_in_buf->i_nb_bytes );
@@ -138,9 +128,4 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
p_out_buf->start_date = p_in_buf->start_date;
p_out_buf->end_date = p_out_buf->start_date + p_out_buf->i_nb_samples *
1000000 / p_filter->output.i_rate;
-
-#ifndef HAVE_ALLOCA
- free( p_in_orig );
-#endif
-
}
diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index 984e078..3647aed 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -997,7 +997,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time )
/* disabled due to the potential "S_KATE" namespace issue */
else if( !strcmp( tracks[i_track]->psz_codec, "S_KATE" ) )
{
- int i, i_offset = 1, *i_size, i_extra, num_headers, size_so_far;
+ int i, i_offset = 1, i_extra, num_headers, size_so_far;
uint8_t *p_extra;
tracks[i_track]->fmt.i_codec = VLC_FOURCC( 'k', 'a', 't', 'e' );
@@ -1009,25 +1009,25 @@ bool matroska_segment_c::Select( mtime_t i_start_time )
num_headers, tracks[i_track]->i_extra_data);
/* this won't overflow the stack as is can allocate only 1020 bytes max */
- i_size = (int*)alloca(num_headers*sizeof(int));
+ uint16_t pi_size[num_headers];
/* Split the headers */
size_so_far = 0;
for( i = 0; i < num_headers-1; i++ )
{
- i_size[i] = 0;
+ pi_size[i] = 0;
while( i_offset < tracks[i_track]->i_extra_data )
{
- i_size[i] += tracks[i_track]->p_extra_data[i_offset];
+ pi_size[i] += tracks[i_track]->p_extra_data[i_offset];
if( tracks[i_track]->p_extra_data[i_offset++] != 0xff ) break;
}
- msg_Dbg( &sys.demuxer, "kate header %d is %d bytes", i, i_size[i]);
- size_so_far += i_size[i];
+ msg_Dbg( &sys.demuxer, "kate header %d is %d bytes", i, pi_size[i]);
+ size_so_far += pi_size[i];
}
- i_size[num_headers-1] = tracks[i_track]->i_extra_data - (size_so_far+i_offset);
- msg_Dbg( &sys.demuxer, "kate last header (%d) is %d bytes", num_headers-1, i_size[num_headers-1]);
+ pi_size[num_headers-1] = tracks[i_track]->i_extra_data - (size_so_far+i_offset);
+ msg_Dbg( &sys.demuxer, "kate last header (%d) is %d bytes", num_headers-1, pi_size[num_headers-1]);
- tracks[i_track]->fmt.i_extra = 1 + num_headers * 2 + size_so_far + i_size[num_headers-1];
+ tracks[i_track]->fmt.i_extra = 1 + num_headers * 2 + size_so_far + pi_size[num_headers-1];
tracks[i_track]->fmt.p_extra = malloc( tracks[i_track]->fmt.i_extra );
p_extra = (uint8_t *)tracks[i_track]->fmt.p_extra;
@@ -1036,12 +1036,13 @@ bool matroska_segment_c::Select( mtime_t i_start_time )
++i_extra;
for( i = 0; i < num_headers; i++ )
{
- *(p_extra++) = i_size[i] >> 8;
- *(p_extra++) = i_size[i] & 0xFF;
+ *(p_extra++) = pi_size[i] >> 8;
+ *(p_extra++) = pi_size[i] & 0xFF;
memcpy( p_extra, tracks[i_track]->p_extra_data + i_offset + i_extra-1,
- i_size[i] );
- p_extra += i_size[i];
- i_extra += i_size[i];
+ pi_size[i] );
+#endif
+ p_extra += pi_size[i];
+ i_extra += pi_size[i];
}
}
else if( !strcmp( tracks[i_track]->psz_codec, "S_TEXT/ASCII" ) )
More information about the vlc-devel
mailing list