Main Page | Class List | File List | Class Members | File Members

stack_alloc.h

Go to the documentation of this file.
00001 /* Copyright (C) 2002 Jean-Marc Valin 00002 File: stack_alloc.h 00003 00004 Temporary memory allocation on stack 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions 00008 are met: 00009 00010 - Redistributions of source code must retain the above copyright 00011 notice, this list of conditions and the following disclaimer. 00012 00013 - Redistributions in binary form must reproduce the above copyright 00014 notice, this list of conditions and the following disclaimer in the 00015 documentation and/or other materials provided with the distribution. 00016 00017 - Neither the name of the Xiph.org Foundation nor the names of its 00018 contributors may be used to endorse or promote products derived from 00019 this software without specific prior written permission. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00024 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 00025 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00026 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00027 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 */ 00033 00034 #ifndef STACK_ALLOC_H 00035 #define STACK_ALLOC_H 00036 00037 #ifdef ENABLE_VALGRIND 00038 00039 #include <valgrind/memcheck.h> 00040 /*Aligns the stack to a 'size' boundary */ 00041 #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) 00042 00043 /* Allocates 'size' elements of type 'type' on the stack */ 00044 #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)))) 00045 00046 /* Allocates a struct stack */ 00047 #define PUSHS(stack, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(long)),VALGRIND_MAKE_WRITABLE(stack, (sizeof(type))),(stack)+=(sizeof(type)),(type*)((stack)-(sizeof(type)))) 00048 00049 #else 00050 00051 00052 /*Aligns the stack to a 'size' boundary */ 00053 #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) 00054 00055 /* Allocates 'size' elements of type 'type' on the stack */ 00056 #define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type)))) 00057 00058 /* Allocates a struct stack */ 00059 #define PUSHS(stack, type) (ALIGN((stack),sizeof(long)),(stack)+=(sizeof(type)),(type*)((stack)-(sizeof(type)))) 00060 00061 #endif 00062 00063 00064 00065 #endif

Generated on Thu Aug 12 11:55:01 2004 for speex by doxygen 1.3.8