ref: 7b5dc851ceb07c3aa1bda704a0d2794e4e08f2d4
parent: ecd214d585456c6be3bf00f72b41d48d2e839276
author: Jean-Marc Valin <[email protected]>
date: Sun Mar 9 13:18:39 EDT 2008
manual stack allocator should now work for sizeof(char)!=1
--- a/libcelt/celt_types.h
+++ b/libcelt/celt_types.h
@@ -23,7 +23,7 @@
#define _CELT_TYPES_H
/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */
-#if (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) )
+#if (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H))
#include <stdint.h>
typedef int16_t celt_int16_t;
--- a/libcelt/stack_alloc.h
+++ b/libcelt/stack_alloc.h
@@ -108,14 +108,15 @@
#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)),VALGRIND_MAKE_WRITABLE(stack, ((size)*sizeof(type))),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
+#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))))
#define RESTORE_STACK ((global_stack = _saved_stack),VALGRIND_MAKE_NOACCESS(global_stack, 1000))
#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)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
+#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/sizeof(char)),(stack)+=((size)*sizeof(type)/sizeof(char)),(type*)((stack)-((size)*sizeof(type)/sizeof(char))))
#define RESTORE_STACK (global_stack = _saved_stack)
#endif