~ubuntu-branches/ubuntu/hardy/speex/hardy-security

« back to all changes in this revision

Viewing changes to libspeex/stack_alloc.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2005-12-07 23:22:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051207232221-nme7vf9m182p7dpe
Tags: 1.1.11.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2002 Jean-Marc Valin 
2
 
   File: stack_alloc.h
3
 
   
4
 
   Temporary memory allocation on stack
5
 
 
 
1
/* Copyright (C) 2002 Jean-Marc Valin */
 
2
/**
 
3
   @file stack_alloc.h
 
4
   @brief Temporary memory allocation on stack
 
5
*/
 
6
/*
6
7
   Redistribution and use in source and binary forms, with or without
7
8
   modification, are permitted provided that the following conditions
8
9
   are met:
34
35
#ifndef STACK_ALLOC_H
35
36
#define STACK_ALLOC_H
36
37
 
 
38
#ifdef USE_ALLOCA
 
39
#include <alloca.h>
 
40
#endif
 
41
 
 
42
/**
 
43
 * @def ALIGN(stack, size)
 
44
 *
 
45
 * Aligns the stack to a 'size' boundary
 
46
 *
 
47
 * @param stack Stack
 
48
 * @param size  New size boundary
 
49
 */
 
50
 
 
51
/**
 
52
 * @def PUSH(stack, size, type)
 
53
 *
 
54
 * Allocates 'size' elements of type 'type' on the stack
 
55
 *
 
56
 * @param stack Stack
 
57
 * @param size  Number of elements
 
58
 * @param type  Type of element
 
59
 */
 
60
 
 
61
/**
 
62
 * @def PUSHS(stack, type)
 
63
 *
 
64
 * Allocates a struct stack 
 
65
 *
 
66
 * @param stack Stack
 
67
 * @param type  Struct type
 
68
 */
 
69
 
 
70
/**
 
71
 * @def VARDECL(var)
 
72
 *
 
73
 * Declare variable on stack
 
74
 *
 
75
 * @param var Variable to declare
 
76
 */
 
77
 
 
78
/**
 
79
 * @def ALLOC(var, size, type)
 
80
 *
 
81
 * Allocate 'size' elements of 'type' on stack
 
82
 *
 
83
 * @param var  Name of variable to allocate
 
84
 * @param size Number of elements
 
85
 * @param type Type of element
 
86
 */
 
87
 
37
88
#ifdef ENABLE_VALGRIND
38
89
 
39
90
#include <valgrind/memcheck.h>
40
 
/*Aligns the stack to a 'size' boundary */
 
91
 
41
92
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
42
93
 
43
 
/* Allocates 'size' elements of type 'type' on the stack */
44
94
#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))))
45
95
 
46
 
/* Allocates a struct stack */
47
96
#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))))
48
97
 
49
98
#else
50
99
 
51
 
 
52
 
/*Aligns the stack to a 'size' boundary */
53
100
#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
54
101
 
55
 
/* Allocates 'size' elements of type 'type' on the stack */
56
102
#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
57
103
 
58
 
/* Allocates a struct stack */
59
104
#define PUSHS(stack, type) (ALIGN((stack),sizeof(long)),(stack)+=(sizeof(type)),(type*)((stack)-(sizeof(type))))
60
105
 
61
106
#endif
62
107
 
 
108
#if defined(VAR_ARRAYS)
 
109
#define VARDECL(var) 
 
110
#define ALLOC(var, size, type) type var[size]
 
111
#elif defined(USE_ALLOCA)
 
112
#define VARDECL(var) var
 
113
#define ALLOC(var, size, type) var = alloca(sizeof(type)*size)
 
114
#else
 
115
#define VARDECL(var) var
 
116
#define ALLOC(var, size, type) var = PUSH(stack, size, type)
 
117
#endif
63
118
 
64
119
 
65
120
#endif