~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/freetype/include/freetype/internal/ftmemory.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************/
 
2
/*                                                                         */
 
3
/*  ftmemory.h                                                             */
 
4
/*                                                                         */
 
5
/*    The FreeType memory management macros (specification).               */
 
6
/*                                                                         */
 
7
/*  Copyright 1996-2001, 2002, 2004 by                                     */
 
8
/*  David Turner, Robert Wilhelm, and Werner Lemberg                       */
 
9
/*                                                                         */
 
10
/*  This file is part of the FreeType project, and may only be used,       */
 
11
/*  modified, and distributed under the terms of the FreeType project      */
 
12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
 
13
/*  this file you indicate that you have read the license and              */
 
14
/*  understand and accept it fully.                                        */
 
15
/*                                                                         */
 
16
/***************************************************************************/
 
17
 
 
18
 
 
19
#ifndef __FTMEMORY_H__
 
20
#define __FTMEMORY_H__
 
21
 
 
22
 
 
23
#include <ft2build.h>
 
24
#include FT_CONFIG_CONFIG_H
 
25
#include FT_TYPES_H
 
26
 
 
27
 
 
28
FT_BEGIN_HEADER
 
29
 
 
30
 
 
31
  /*************************************************************************/
 
32
  /*                                                                       */
 
33
  /* <Macro>                                                               */
 
34
  /*    FT_SET_ERROR                                                       */
 
35
  /*                                                                       */
 
36
  /* <Description>                                                         */
 
37
  /*    This macro is used to set an implicit `error' variable to a given  */
 
38
  /*    expression's value (usually a function call), and convert it to a  */
 
39
  /*    boolean which is set whenever the value is != 0.                   */
 
40
  /*                                                                       */
 
41
#undef  FT_SET_ERROR
 
42
#define FT_SET_ERROR( expression ) \
 
43
          ( ( error = (expression) ) != 0 )
 
44
 
 
45
 
 
46
  /*************************************************************************/
 
47
  /*************************************************************************/
 
48
  /*************************************************************************/
 
49
  /****                                                                 ****/
 
50
  /****                                                                 ****/
 
51
  /****                           M E M O R Y                           ****/
 
52
  /****                                                                 ****/
 
53
  /****                                                                 ****/
 
54
  /*************************************************************************/
 
55
  /*************************************************************************/
 
56
  /*************************************************************************/
 
57
 
 
58
#ifdef FT_DEBUG_MEMORY
 
59
 
 
60
  FT_BASE( FT_Error )
 
61
  FT_Alloc_Debug( FT_Memory    memory,
 
62
                  FT_Long      size,
 
63
                  void*       *P,
 
64
                  const char*  file_name,
 
65
                  FT_Long      line_no );
 
66
 
 
67
  FT_BASE( FT_Error )
 
68
  FT_QAlloc_Debug( FT_Memory    memory,
 
69
                   FT_Long      size,
 
70
                   void*       *P,
 
71
                   const char*  file_name,
 
72
                   FT_Long      line_no );
 
73
 
 
74
  FT_BASE( FT_Error )
 
75
  FT_Realloc_Debug( FT_Memory    memory,
 
76
                    FT_Long      current,
 
77
                    FT_Long      size,
 
78
                    void*       *P,
 
79
                    const char*  file_name,
 
80
                    FT_Long      line_no );
 
81
 
 
82
  FT_BASE( FT_Error )
 
83
  FT_QRealloc_Debug( FT_Memory    memory,
 
84
                     FT_Long      current,
 
85
                     FT_Long      size,
 
86
                     void*       *P,
 
87
                     const char*  file_name,
 
88
                     FT_Long      line_no );
 
89
 
 
90
  FT_BASE( void )
 
91
  FT_Free_Debug( FT_Memory    memory,
 
92
                 FT_Pointer   block,
 
93
                 const char*  file_name,
 
94
                 FT_Long      line_no );
 
95
 
 
96
#endif
 
97
 
 
98
 
 
99
  /*************************************************************************/
 
100
  /*                                                                       */
 
101
  /* <Function>                                                            */
 
102
  /*    FT_Alloc                                                           */
 
103
  /*                                                                       */
 
104
  /* <Description>                                                         */
 
105
  /*    Allocates a new block of memory.  The returned area is always      */
 
106
  /*    zero-filled; this is a strong convention in many FreeType parts.   */
 
107
  /*                                                                       */
 
108
  /* <Input>                                                               */
 
109
  /*    memory :: A handle to a given `memory object' which handles        */
 
110
  /*              allocation.                                              */
 
111
  /*                                                                       */
 
112
  /*    size   :: The size in bytes of the block to allocate.              */
 
113
  /*                                                                       */
 
114
  /* <Output>                                                              */
 
115
  /*    P      :: A pointer to the fresh new block.  It should be set to   */
 
116
  /*              NULL if `size' is 0, or in case of error.                */
 
117
  /*                                                                       */
 
118
  /* <Return>                                                              */
 
119
  /*    FreeType error code.  0 means success.                             */
 
120
  /*                                                                       */
 
121
  FT_BASE( FT_Error )
 
122
  FT_Alloc( FT_Memory  memory,
 
123
            FT_Long    size,
 
124
            void*     *P );
 
125
 
 
126
 
 
127
  FT_BASE( FT_Error )
 
128
  FT_QAlloc( FT_Memory  memory,
 
129
             FT_Long    size,
 
130
             void*     *p );
 
131
 
 
132
 
 
133
  /*************************************************************************/
 
134
  /*                                                                       */
 
135
  /* <Function>                                                            */
 
136
  /*    FT_Realloc                                                         */
 
137
  /*                                                                       */
 
138
  /* <Description>                                                         */
 
139
  /*    Reallocates a block of memory pointed to by `*P' to `Size' bytes   */
 
140
  /*    from the heap, possibly changing `*P'.                             */
 
141
  /*                                                                       */
 
142
  /* <Input>                                                               */
 
143
  /*    memory  :: A handle to a given `memory object' which handles       */
 
144
  /*               reallocation.                                           */
 
145
  /*                                                                       */
 
146
  /*    current :: The current block size in bytes.                        */
 
147
  /*                                                                       */
 
148
  /*    size    :: The new block size in bytes.                            */
 
149
  /*                                                                       */
 
150
  /* <InOut>                                                               */
 
151
  /*    P       :: A pointer to the fresh new block.  It should be set to  */
 
152
  /*               NULL if `size' is 0, or in case of error.               */
 
153
  /*                                                                       */
 
154
  /* <Return>                                                              */
 
155
  /*    FreeType error code.  0 means success.                             */
 
156
  /*                                                                       */
 
157
  /* <Note>                                                                */
 
158
  /*    All callers of FT_Realloc() _must_ provide the current block size  */
 
159
  /*    as well as the new one.                                            */
 
160
  /*                                                                       */
 
161
  FT_BASE( FT_Error )
 
162
  FT_Realloc( FT_Memory  memory,
 
163
              FT_Long    current,
 
164
              FT_Long    size,
 
165
              void*     *P );
 
166
 
 
167
 
 
168
  FT_BASE( FT_Error )
 
169
  FT_QRealloc( FT_Memory  memory,
 
170
               FT_Long    current,
 
171
               FT_Long    size,
 
172
               void*     *p );
 
173
 
 
174
 
 
175
  /*************************************************************************/
 
176
  /*                                                                       */
 
177
  /* <Function>                                                            */
 
178
  /*    FT_Free                                                            */
 
179
  /*                                                                       */
 
180
  /* <Description>                                                         */
 
181
  /*    Releases a given block of memory allocated through FT_Alloc().     */
 
182
  /*                                                                       */
 
183
  /* <Input>                                                               */
 
184
  /*    memory :: A handle to a given `memory object' which handles        */
 
185
  /*              memory deallocation                                      */
 
186
  /*                                                                       */
 
187
  /*    P      :: This is the _address_ of a _pointer_ which points to the */
 
188
  /*              allocated block.  It is always set to NULL on exit.      */
 
189
  /*                                                                       */
 
190
  /* <Note>                                                                */
 
191
  /*    If P or *P is NULL, this function should return successfully.      */
 
192
  /*    This is a strong convention within all of FreeType and its         */
 
193
  /*    drivers.                                                           */
 
194
  /*                                                                       */
 
195
  FT_BASE( void )
 
196
  FT_Free( FT_Memory  memory,
 
197
           void*     *P );
 
198
 
 
199
 
 
200
#define FT_MEM_SET( dest, byte, count )     ft_memset( dest, byte, count )
 
201
 
 
202
#define FT_MEM_COPY( dest, source, count )  ft_memcpy( dest, source, count )
 
203
 
 
204
#define FT_MEM_MOVE( dest, source, count )  ft_memmove( dest, source, count )
 
205
 
 
206
 
 
207
#define FT_MEM_ZERO( dest, count )  FT_MEM_SET( dest, 0, count )
 
208
 
 
209
#define FT_ZERO( p )                FT_MEM_ZERO( p, sizeof ( *(p) ) )
 
210
 
 
211
#define FT_ARRAY_COPY( dest, source, count )                       \
 
212
          FT_MEM_COPY( dest, source, (count) * sizeof( *(dest) ) )
 
213
 
 
214
#define FT_ARRAY_MOVE( dest, source, count )                       \
 
215
          FT_MEM_MOVE( dest, source, (count) * sizeof( *(dest) ) )
 
216
 
 
217
 
 
218
  /*************************************************************************/
 
219
  /*                                                                       */
 
220
  /* We first define FT_MEM_ALLOC, FT_MEM_REALLOC, and FT_MEM_FREE.  All   */
 
221
  /* macros use an _implicit_ `memory' parameter to access the current     */
 
222
  /* memory allocator.                                                     */
 
223
  /*                                                                       */
 
224
 
 
225
#ifdef FT_DEBUG_MEMORY
 
226
 
 
227
#define FT_MEM_ALLOC( _pointer_, _size_ )                            \
 
228
          FT_Alloc_Debug( memory, _size_,                            \
 
229
                          (void**)&(_pointer_), __FILE__, __LINE__ )
 
230
 
 
231
#define FT_MEM_REALLOC( _pointer_, _current_, _size_ )                 \
 
232
          FT_Realloc_Debug( memory, _current_, _size_,                 \
 
233
                            (void**)&(_pointer_), __FILE__, __LINE__ )
 
234
 
 
235
#define FT_MEM_QALLOC( _pointer_, _size_ )                            \
 
236
          FT_QAlloc_Debug( memory, _size_,                            \
 
237
                           (void**)&(_pointer_), __FILE__, __LINE__ )
 
238
 
 
239
#define FT_MEM_QREALLOC( _pointer_, _current_, _size_ )                 \
 
240
          FT_QRealloc_Debug( memory, _current_, _size_,                 \
 
241
                             (void**)&(_pointer_), __FILE__, __LINE__ )
 
242
 
 
243
#define FT_MEM_FREE( _pointer_ )                                            \
 
244
          FT_Free_Debug( memory, (void**)&(_pointer_), __FILE__, __LINE__ )
 
245
 
 
246
 
 
247
#else  /* !FT_DEBUG_MEMORY */
 
248
 
 
249
 
 
250
#define FT_MEM_ALLOC( _pointer_, _size_ )                  \
 
251
          FT_Alloc( memory, _size_, (void**)&(_pointer_) )
 
252
 
 
253
#define FT_MEM_FREE( _pointer_ )                  \
 
254
          FT_Free( memory, (void**)&(_pointer_) )
 
255
 
 
256
#define FT_MEM_REALLOC( _pointer_, _current_, _size_ )                  \
 
257
          FT_Realloc( memory, _current_, _size_, (void**)&(_pointer_) )
 
258
 
 
259
#define FT_MEM_QALLOC( _pointer_, _size_ )                  \
 
260
          FT_QAlloc( memory, _size_, (void**)&(_pointer_) )
 
261
 
 
262
#define FT_MEM_QREALLOC( _pointer_, _current_, _size_ )                  \
 
263
          FT_QRealloc( memory, _current_, _size_, (void**)&(_pointer_) )
 
264
 
 
265
#endif /* !FT_DEBUG_MEMORY */
 
266
 
 
267
 
 
268
  /*************************************************************************/
 
269
  /*                                                                       */
 
270
  /* The following functions macros expect that their pointer argument is  */
 
271
  /* _typed_ in order to automatically compute array element sizes.        */
 
272
  /*                                                                       */
 
273
 
 
274
#define FT_MEM_NEW( _pointer_ )                               \
 
275
          FT_MEM_ALLOC( _pointer_, sizeof ( *(_pointer_) ) )
 
276
 
 
277
#define FT_MEM_NEW_ARRAY( _pointer_, _count_ )                           \
 
278
          FT_MEM_ALLOC( _pointer_, (_count_) * sizeof ( *(_pointer_) ) )
 
279
 
 
280
#define FT_MEM_RENEW_ARRAY( _pointer_, _old_, _new_ )                    \
 
281
          FT_MEM_REALLOC( _pointer_, (_old_) * sizeof ( *(_pointer_) ),  \
 
282
                                     (_new_) * sizeof ( *(_pointer_) ) )
 
283
 
 
284
#define FT_MEM_QNEW( _pointer_ )                               \
 
285
          FT_MEM_QALLOC( _pointer_, sizeof ( *(_pointer_) ) )
 
286
 
 
287
#define FT_MEM_QNEW_ARRAY( _pointer_, _count_ )                           \
 
288
          FT_MEM_QALLOC( _pointer_, (_count_) * sizeof ( *(_pointer_) ) )
 
289
 
 
290
#define FT_MEM_QRENEW_ARRAY( _pointer_, _old_, _new_ )                    \
 
291
          FT_MEM_QREALLOC( _pointer_, (_old_) * sizeof ( *(_pointer_) ),  \
 
292
                                      (_new_) * sizeof ( *(_pointer_) ) )
 
293
 
 
294
 
 
295
  /*************************************************************************/
 
296
  /*                                                                       */
 
297
  /* the following macros are obsolete but kept for compatibility reasons  */
 
298
  /*                                                                       */
 
299
 
 
300
#define FT_MEM_ALLOC_ARRAY( _pointer_, _count_, _type_ )           \
 
301
          FT_MEM_ALLOC( _pointer_, (_count_) * sizeof ( _type_ ) )
 
302
 
 
303
#define FT_MEM_REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ )    \
 
304
          FT_MEM_REALLOC( _pointer_, (_old_) * sizeof ( _type ),   \
 
305
                                     (_new_) * sizeof ( _type_ ) )
 
306
 
 
307
 
 
308
  /*************************************************************************/
 
309
  /*                                                                       */
 
310
  /* The following macros are variants of their FT_MEM_XXXX equivalents;   */
 
311
  /* they are used to set an _implicit_ `error' variable and return TRUE   */
 
312
  /* if an error occured (i.e. if 'error != 0').                           */
 
313
  /*                                                                       */
 
314
 
 
315
#define FT_ALLOC( _pointer_, _size_ )                       \
 
316
          FT_SET_ERROR( FT_MEM_ALLOC( _pointer_, _size_ ) )
 
317
 
 
318
#define FT_REALLOC( _pointer_, _current_, _size_ )                       \
 
319
          FT_SET_ERROR( FT_MEM_REALLOC( _pointer_, _current_, _size_ ) )
 
320
 
 
321
#define FT_FREE( _pointer_ )       \
 
322
          FT_MEM_FREE( _pointer_ )
 
323
 
 
324
#define FT_QALLOC( _pointer_, _size_ )                       \
 
325
          FT_SET_ERROR( FT_MEM_QALLOC( _pointer_, _size_ ) )
 
326
 
 
327
#define FT_QREALLOC( _pointer_, _current_, _size_ )                       \
 
328
          FT_SET_ERROR( FT_MEM_QREALLOC( _pointer_, _current_, _size_ ) )
 
329
 
 
330
 
 
331
#define FT_NEW( _pointer_ )  \
 
332
          FT_SET_ERROR( FT_MEM_NEW( _pointer_ ) )
 
333
 
 
334
#define FT_NEW_ARRAY( _pointer_, _count_ )  \
 
335
          FT_SET_ERROR( FT_MEM_NEW_ARRAY( _pointer_, _count_ ) )
 
336
 
 
337
#define FT_RENEW_ARRAY( _pointer_, _old_, _new_ )   \
 
338
          FT_SET_ERROR( FT_MEM_RENEW_ARRAY( _pointer_, _old_, _new_ ) )
 
339
 
 
340
#define FT_QNEW( _pointer_ )  \
 
341
          FT_SET_ERROR( FT_MEM_QNEW( _pointer_ ) )
 
342
 
 
343
#define FT_QNEW_ARRAY( _pointer_, _count_ )  \
 
344
          FT_SET_ERROR( FT_MEM_QNEW_ARRAY( _pointer_, _count_ ) )
 
345
 
 
346
#define FT_QRENEW_ARRAY( _pointer_, _old_, _new_ )   \
 
347
          FT_SET_ERROR( FT_MEM_QRENEW_ARRAY( _pointer_, _old_, _new_ ) )
 
348
 
 
349
 
 
350
#define FT_ALLOC_ARRAY( _pointer_, _count_, _type_ )                    \
 
351
          FT_SET_ERROR( FT_MEM_ALLOC( _pointer_,                        \
 
352
                                      (_count_) * sizeof ( _type_ ) ) )
 
353
 
 
354
#define FT_REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ )             \
 
355
          FT_SET_ERROR( FT_MEM_REALLOC( _pointer_,                      \
 
356
                                        (_old_) * sizeof ( _type_ ),    \
 
357
                                        (_new_) * sizeof ( _type_ ) ) )
 
358
 
 
359
 /* */
 
360
 
 
361
 
 
362
FT_END_HEADER
 
363
 
 
364
#endif /* __FTMEMORY_H__ */
 
365
 
 
366
 
 
367
/* END */