Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/**** dalloc.h --- Memory allocation and deallocation.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 **** Commentary:
36
 *
37
 ***=== INTRODUCTION =========================================================
38
 *
39
 * This file specifies the interface to a dynamic memory allocation facility.
40
 * All dynamically allocated objects are initialised with zeroes, but
41
 * non-integer typed fields will still need to be initialised explicitly.
42
 *
43
 * If the macro ``PO_DALLOC_DEBUG_ALIGN'' is defined, then extra debugging
44
 * information is added into the space allocated to help detect errors in
45
 * memory management.  If this macro is defined, it requires two functions to
46
 * be provided:
47
 *
48
 *	void				E_dalloc_multi_deallocate
49
 *			PROTO_S ((GenericP, CStringP, unsigned, CStringP,
50
 *				  unsigned));
51
 *	void				E_dalloc_corrupt_block
52
 *			PROTO_S ((GenericP, CStringP, unsigned));
53
 *
54
 * The first function will be called if a block is deallocated more than once.
55
 * It takes the block's address, and the file and line number of the
56
 * deallocation and allocation of the block as arguments.  The second function
57
 * is called if a block is corrupt when deallocated.  It takes the address of
58
 * the block and the file and line number of the deallocation of the block as
59
 * arguments.  Neither of these functions should return.
60
 *
61
 * This debugging mode should not be used on software that is shipped.  It has
62
 * machine specific implementations, and may be quite inefficient.
63
 *
64
 ***=== MACROS ===============================================================
65
 *
66
 ** Macro:	ALLOCATE (type)
67
 ** Exceptions:	XX_dalloc_no_memory
68
 *
69
 * This macro allocates an object of the specified type.  A pointer to the
70
 * object is returned.
71
 *
72
 ** Macro:	ALLOCATE_VECTOR (type, length)
73
 ** Exceptions:	XX_dalloc_no_memory
74
 *
75
 * This macro allocates a vector of the specified length containing objects of
76
 * the specified type.  A pointer to the first element in the vector is
77
 * returned.
78
 *
79
 ** Macro:	DEALLOCATE (pointer)
80
 ** Exceptions:
81
 *
82
 * This macro deallocates the specified pointer.  If the pointer is a null
83
 * pointer (``NIL (SomeTypeP)''), this does nothing.
84
 *
85
 ***=== EXCEPTIONS ===========================================================
86
 *
87
 ** Exception:	XX_dalloc_no_memory
88
 *
89
 * This exception is raised if there is not enough memory to allocate an
90
 * object (or a vector of objects).
91
 *
92
 **** Change Log:
93
 * $Log: dalloc.h,v $
94
 * Revision 1.1.1.1  1998/01/17  15:57:18  release
95
 * First version to be checked into rolling release.
96
 *
97
 * Revision 1.2  1994/12/12  11:45:30  smf
98
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
99
 * OSSG C Coding Standards.
100
 *
101
 * Revision 1.1.1.1  1994/07/25  16:06:09  smf
102
 * Initial import of os-interface shared files.
103
 *
104
**/
105
 
106
/****************************************************************************/
107
 
108
#ifndef H_DALLOC
109
#define H_DALLOC
110
 
111
#include "os-interface.h"
112
#include "exception.h"
113
 
114
/*--------------------------------------------------------------------------*/
115
 
116
extern ExceptionP		XX_dalloc_no_memory;
117
 
118
/*--------------------------------------------------------------------------*/
119
 
120
#ifdef PO_DALLOC_DEBUG_ALIGN
121
 
122
extern void			E_dalloc_multi_deallocate
123
	PROTO_S ((GenericP, CStringP, unsigned, CStringP, unsigned));
124
extern void			E_dalloc_corrupt_block
125
	PROTO_S ((GenericP, CStringP, unsigned));
126
extern GenericP			X__dalloc_allocate
127
	PROTO_S ((SizeT, SizeT, CStringP, unsigned));
128
extern void			X__dalloc_deallocate
129
	PROTO_S ((GenericP, CStringP, unsigned));
130
 
131
#else
132
 
133
extern GenericP			X__dalloc_allocate
134
	PROTO_S ((SizeT, SizeT));
135
 
136
#endif /* defined (PO_DALLOC_DEBUG_ALIGN) */
137
 
138
/*--------------------------------------------------------------------------*/
139
 
140
#ifdef PO_DALLOC_DEBUG_ALIGN
141
 
142
#define ALLOCATE(type) \
143
((type *) X__dalloc_allocate (sizeof (type), (SizeT) 1, __FILE__, \
144
			      (unsigned) __LINE__))
145
 
146
#define ALLOCATE_VECTOR(type,length) \
147
((type *) X__dalloc_allocate (sizeof (type), (SizeT) (length), __FILE__, \
148
			      (unsigned) __LINE__))
149
 
150
#define DEALLOCATE(pointer) \
151
X__dalloc_deallocate ((GenericP) (pointer), __FILE__, (unsigned) __LINE__)
152
 
153
#else
154
 
155
#define ALLOCATE(type) \
156
((type *) X__dalloc_allocate (sizeof (type), (SizeT) 1))
157
 
158
#define ALLOCATE_VECTOR(type,length) \
159
((type *) X__dalloc_allocate (sizeof (type), (SizeT) (length)))
160
 
161
#define DEALLOCATE(pointer) \
162
if (pointer) {free ((GenericP) (pointer));}
163
 
164
#endif /* defined (PO_DALLOC_DEBUG_ALIGN) */
165
 
166
#endif /* !defined (H_DALLOC) */