2 |
7u83 |
1 |
/*
|
6 |
7u83 |
2 |
* Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
*
|
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
|
6 |
* modification, are permitted provided that the following conditions are met:
|
|
|
7 |
*
|
|
|
8 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
9 |
* this list of conditions and the following disclaimer.
|
|
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
11 |
* this list of conditions and the following disclaimer in the documentation
|
|
|
12 |
* and/or other materials provided with the distribution.
|
|
|
13 |
* 3. Neither the name of The TenDRA Project nor the names of its contributors
|
|
|
14 |
* may be used to endorse or promote products derived from this software
|
|
|
15 |
* without specific, prior written permission.
|
|
|
16 |
*
|
|
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
|
|
18 |
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
19 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
|
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
22 |
* EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
24 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
25 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
26 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
27 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
28 |
*
|
|
|
29 |
* $Id$
|
|
|
30 |
*/
|
|
|
31 |
/*
|
2 |
7u83 |
32 |
Crown Copyright (c) 1997
|
6 |
7u83 |
33 |
|
2 |
7u83 |
34 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
35 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
36 |
acting through the Defence Evaluation and Research Agency
|
|
|
37 |
(DERA). It is made available to Recipients with a
|
|
|
38 |
royalty-free licence for its use, reproduction, transfer
|
|
|
39 |
to other parties and amendment for any purpose not excluding
|
|
|
40 |
product development provided that any such use et cetera
|
|
|
41 |
shall be deemed to be acceptance of the following conditions:-
|
6 |
7u83 |
42 |
|
2 |
7u83 |
43 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
44 |
reproduced upon any copies or amended versions of it;
|
6 |
7u83 |
45 |
|
2 |
7u83 |
46 |
(2) Any amended version of it shall be clearly marked to
|
|
|
47 |
show both the nature of and the organisation responsible
|
|
|
48 |
for the relevant amendment or amendments;
|
6 |
7u83 |
49 |
|
2 |
7u83 |
50 |
(3) Its onward transfer from a recipient to another
|
|
|
51 |
party shall be deemed to be that party's acceptance of
|
|
|
52 |
these conditions;
|
6 |
7u83 |
53 |
|
2 |
7u83 |
54 |
(4) DERA gives no warranty or assurance as to its
|
|
|
55 |
quality or suitability for any purpose and DERA accepts
|
|
|
56 |
no liability whatsoever in relation to any use to which
|
|
|
57 |
it may be put.
|
|
|
58 |
*/
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
/**** dalloc.h --- Memory allocation and deallocation.
|
|
|
62 |
*
|
|
|
63 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
64 |
*
|
|
|
65 |
**** Commentary:
|
|
|
66 |
*
|
|
|
67 |
***=== INTRODUCTION =========================================================
|
|
|
68 |
*
|
|
|
69 |
* This file specifies the interface to a dynamic memory allocation facility.
|
|
|
70 |
* All dynamically allocated objects are initialised with zeroes, but
|
|
|
71 |
* non-integer typed fields will still need to be initialised explicitly.
|
|
|
72 |
*
|
|
|
73 |
* If the macro ``PO_DALLOC_DEBUG_ALIGN'' is defined, then extra debugging
|
|
|
74 |
* information is added into the space allocated to help detect errors in
|
|
|
75 |
* memory management. If this macro is defined, it requires two functions to
|
|
|
76 |
* be provided:
|
|
|
77 |
*
|
6 |
7u83 |
78 |
* void E_dalloc_multi_deallocate(GenericP, CStringP, unsigned, CStringP,
|
|
|
79 |
* unsigned);
|
|
|
80 |
* void E_dalloc_corrupt_block(GenericP, CStringP, unsigned);
|
2 |
7u83 |
81 |
*
|
|
|
82 |
* The first function will be called if a block is deallocated more than once.
|
|
|
83 |
* It takes the block's address, and the file and line number of the
|
|
|
84 |
* deallocation and allocation of the block as arguments. The second function
|
|
|
85 |
* is called if a block is corrupt when deallocated. It takes the address of
|
|
|
86 |
* the block and the file and line number of the deallocation of the block as
|
|
|
87 |
* arguments. Neither of these functions should return.
|
|
|
88 |
*
|
|
|
89 |
* This debugging mode should not be used on software that is shipped. It has
|
|
|
90 |
* machine specific implementations, and may be quite inefficient.
|
|
|
91 |
*
|
|
|
92 |
***=== MACROS ===============================================================
|
|
|
93 |
*
|
|
|
94 |
** Macro: ALLOCATE (type)
|
|
|
95 |
** Exceptions: XX_dalloc_no_memory
|
|
|
96 |
*
|
|
|
97 |
* This macro allocates an object of the specified type. A pointer to the
|
|
|
98 |
* object is returned.
|
|
|
99 |
*
|
|
|
100 |
** Macro: ALLOCATE_VECTOR (type, length)
|
|
|
101 |
** Exceptions: XX_dalloc_no_memory
|
|
|
102 |
*
|
|
|
103 |
* This macro allocates a vector of the specified length containing objects of
|
|
|
104 |
* the specified type. A pointer to the first element in the vector is
|
|
|
105 |
* returned.
|
|
|
106 |
*
|
|
|
107 |
** Macro: DEALLOCATE (pointer)
|
|
|
108 |
** Exceptions:
|
|
|
109 |
*
|
|
|
110 |
* This macro deallocates the specified pointer. If the pointer is a null
|
|
|
111 |
* pointer (``NIL (SomeTypeP)''), this does nothing.
|
|
|
112 |
*
|
|
|
113 |
***=== EXCEPTIONS ===========================================================
|
|
|
114 |
*
|
|
|
115 |
** Exception: XX_dalloc_no_memory
|
|
|
116 |
*
|
|
|
117 |
* This exception is raised if there is not enough memory to allocate an
|
|
|
118 |
* object (or a vector of objects).
|
|
|
119 |
*
|
|
|
120 |
**** Change Log:
|
|
|
121 |
* $Log: dalloc.h,v $
|
|
|
122 |
* Revision 1.1.1.1 1998/01/17 15:57:18 release
|
|
|
123 |
* First version to be checked into rolling release.
|
|
|
124 |
*
|
|
|
125 |
* Revision 1.2 1994/12/12 11:45:30 smf
|
|
|
126 |
* Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
|
|
|
127 |
* OSSG C Coding Standards.
|
|
|
128 |
*
|
|
|
129 |
* Revision 1.1.1.1 1994/07/25 16:06:09 smf
|
|
|
130 |
* Initial import of os-interface shared files.
|
|
|
131 |
*
|
|
|
132 |
**/
|
|
|
133 |
|
|
|
134 |
/****************************************************************************/
|
|
|
135 |
|
|
|
136 |
#ifndef H_DALLOC
|
|
|
137 |
#define H_DALLOC
|
|
|
138 |
|
6 |
7u83 |
139 |
#include <stdlib.h>
|
|
|
140 |
|
2 |
7u83 |
141 |
#include "os-interface.h"
|
|
|
142 |
#include "exception.h"
|
|
|
143 |
|
|
|
144 |
/*--------------------------------------------------------------------------*/
|
|
|
145 |
|
|
|
146 |
extern ExceptionP XX_dalloc_no_memory;
|
|
|
147 |
|
|
|
148 |
/*--------------------------------------------------------------------------*/
|
|
|
149 |
|
|
|
150 |
#ifdef PO_DALLOC_DEBUG_ALIGN
|
|
|
151 |
|
|
|
152 |
extern void E_dalloc_multi_deallocate
|
6 |
7u83 |
153 |
(GenericP, CStringP, unsigned, CStringP, unsigned);
|
2 |
7u83 |
154 |
extern void E_dalloc_corrupt_block
|
6 |
7u83 |
155 |
(GenericP, CStringP, unsigned);
|
2 |
7u83 |
156 |
extern GenericP X__dalloc_allocate
|
6 |
7u83 |
157 |
(SizeT, SizeT, CStringP, unsigned);
|
2 |
7u83 |
158 |
extern void X__dalloc_deallocate
|
6 |
7u83 |
159 |
(GenericP, CStringP, unsigned);
|
2 |
7u83 |
160 |
|
|
|
161 |
#else
|
|
|
162 |
|
|
|
163 |
extern GenericP X__dalloc_allocate
|
6 |
7u83 |
164 |
(SizeT, SizeT);
|
2 |
7u83 |
165 |
|
|
|
166 |
#endif /* defined (PO_DALLOC_DEBUG_ALIGN) */
|
|
|
167 |
|
|
|
168 |
/*--------------------------------------------------------------------------*/
|
|
|
169 |
|
|
|
170 |
#ifdef PO_DALLOC_DEBUG_ALIGN
|
|
|
171 |
|
6 |
7u83 |
172 |
#define ALLOCATE(type)\
|
|
|
173 |
((type *)X__dalloc_allocate(sizeof(type), (SizeT)1, __FILE__, \
|
|
|
174 |
(unsigned)__LINE__))
|
2 |
7u83 |
175 |
|
6 |
7u83 |
176 |
#define ALLOCATE_VECTOR(type,length)\
|
|
|
177 |
((type *)X__dalloc_allocate(sizeof(type), (SizeT)(length), __FILE__, \
|
|
|
178 |
(unsigned)__LINE__))
|
2 |
7u83 |
179 |
|
6 |
7u83 |
180 |
#define DEALLOCATE(pointer)\
|
|
|
181 |
X__dalloc_deallocate((GenericP)(pointer), __FILE__,(unsigned)__LINE__)
|
2 |
7u83 |
182 |
|
|
|
183 |
#else
|
|
|
184 |
|
6 |
7u83 |
185 |
#define ALLOCATE(type)\
|
|
|
186 |
((type *)X__dalloc_allocate(sizeof(type), (SizeT)1))
|
2 |
7u83 |
187 |
|
6 |
7u83 |
188 |
#define ALLOCATE_VECTOR(type,length)\
|
|
|
189 |
((type *)X__dalloc_allocate(sizeof(type), (SizeT)(length)))
|
2 |
7u83 |
190 |
|
6 |
7u83 |
191 |
#define DEALLOCATE(pointer)\
|
|
|
192 |
if (pointer) {free((GenericP)(pointer));}
|
2 |
7u83 |
193 |
|
|
|
194 |
#endif /* defined (PO_DALLOC_DEBUG_ALIGN) */
|
|
|
195 |
|
|
|
196 |
#endif /* !defined (H_DALLOC) */
|