ref: f7cec83c59772f18a626ccf2e2fce88bc6500fc5
parent: ba8295241c680785c146389869de527b6e3989bf
author: Jean-Marc Valin <[email protected]>
date: Fri Apr 18 13:29:56 EDT 2008
pseudo-stack no longer checks on every function entry whether it has been allocated
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -37,6 +37,7 @@
#include "modes.h"
#include "rate.h"
#include "os_support.h"
+#include "stack_alloc.h"
#ifdef STATIC_MODES
#include "static_modes.c"
@@ -225,6 +226,7 @@
const CELTMode *m = NULL;
CELTMode *mode=NULL;
int i;
+ ALLOC_STACK;
for (i=0;i<TOTAL_MODES;i++)
{
if (Fs == static_mode_list[i]->Fs &&
@@ -250,6 +252,7 @@
int i;
CELTMode *mode;
celt_word16_t *window;
+ ALLOC_STACK;
/* The good thing here is that permutation of the arguments will automatically be invalid */
--- a/libcelt/os_support.h
+++ b/libcelt/os_support.h
@@ -149,10 +149,10 @@
-#ifdef __GNUC__
+/*#ifdef __GNUC__
#pragma GCC poison printf sprintf
#pragma GCC poison malloc free realloc calloc
-#endif
+#endif*/
#endif /* OS_SUPPORT_H */
--- a/libcelt/stack_alloc.h
+++ b/libcelt/stack_alloc.h
@@ -91,6 +91,7 @@
#define ALLOC(var, size, type) type var[size]
#define SAVE_STACK
#define RESTORE_STACK
+#define ALLOC_STACK
#elif defined(USE_ALLOCA)
@@ -98,6 +99,7 @@
#define ALLOC(var, size, type) var = ((type*)alloca(sizeof(type)*(size)))
#define SAVE_STACK
#define RESTORE_STACK
+#define ALLOC_STACK
#else
@@ -105,7 +107,6 @@
#include <valgrind/memcheck.h>
-#define ALLOC_STACK(stack) (stack = (stack==0) ? celt_alloc_scratch(25000) : stack, VALGRIND_MAKE_NOACCESS(stack, 1000))
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
#define PUSH(stack, size, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(type)/sizeof(char)),VALGRIND_MAKE_WRITABLE(stack, ((size)*sizeof(type)/sizeof(char))),(stack)+=((size)*sizeof(type)/sizeof(char)),(type*)((stack)-((size)*sizeof(type)/sizeof(char))))
@@ -113,7 +114,6 @@
#else
-#define ALLOC_STACK(stack) (stack = (stack==0) ? celt_alloc_scratch(25000) : stack)
/* FIXME: Only align up to a certain size (not for structs) */
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/sizeof(char)),(stack)+=((size)*sizeof(type)/sizeof(char)),(type*)((stack)-((size)*sizeof(type)/sizeof(char))))
@@ -130,7 +130,9 @@
#include "os_support.h"
#define VARDECL(type, var) type *var
#define ALLOC(var, size, type) var = PUSH(global_stack, size, type)
-#define SAVE_STACK char *_saved_stack; ALLOC_STACK(global_stack);_saved_stack = global_stack;
+#define SAVE_STACK char *_saved_stack = global_stack;
+#define ALLOC_STACK (global_stack = (global_stack==0) ? celt_alloc_scratch(25000) : global_stack)
+
#endif
--- a/tests/laplace-test.c
+++ b/tests/laplace-test.c
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "laplace.h"
+#include "stack_alloc.h"
int main(void)
{
@@ -14,6 +15,7 @@
ec_dec dec;
ec_byte_buffer buf;
int val[10000], decay[10000];
+ ALLOC_STACK;
ec_byte_writeinit(&buf);
ec_enc_init(&enc,&buf);
--- a/tests/mdct-test.c
+++ b/tests/mdct-test.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include "mdct.h"
+#include "stack_alloc.h"
int ret = 0;
void check(kiss_fft_scalar * in,kiss_fft_scalar * out,int nfft,int isinverse)
@@ -114,6 +115,7 @@
int main(int argc,char ** argv)
{
+ ALLOC_STACK;
if (argc>1) {
int k;
for (k=1;k<argc;++k) {