The BIG graph update
[rrdtool.git] / libraries / freetype-2.0.5 / include / freetype / internal / ftmemory.h
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ftmemory.h                                                             */
4 /*                                                                         */
5 /*    The FreeType memory management macros (specification).               */
6 /*                                                                         */
7 /*  Copyright 1996-2001 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
59   /*************************************************************************/
60   /*                                                                       */
61   /* <Function>                                                            */
62   /*    FT_Alloc                                                           */
63   /*                                                                       */
64   /* <Description>                                                         */
65   /*    Allocates a new block of memory.  The returned area is always      */
66   /*    zero-filled; this is a strong convention in many FreeType parts.   */
67   /*                                                                       */
68   /* <Input>                                                               */
69   /*    memory :: A handle to a given `memory object' which handles        */
70   /*              allocation.                                              */
71   /*                                                                       */
72   /*    size   :: The size in bytes of the block to allocate.              */
73   /*                                                                       */
74   /* <Output>                                                              */
75   /*    P      :: A pointer to the fresh new block.  It should be set to   */
76   /*              NULL if `size' is 0, or in case of error.                */
77   /*                                                                       */
78   /* <Return>                                                              */
79   /*    FreeType error code.  0 means success.                             */
80   /*                                                                       */
81   FT_BASE( FT_Error )
82   FT_Alloc( FT_Memory  memory,
83             FT_Long    size,
84             void*     *P );
85
86
87   /*************************************************************************/
88   /*                                                                       */
89   /* <Function>                                                            */
90   /*    FT_Realloc                                                         */
91   /*                                                                       */
92   /* <Description>                                                         */
93   /*    Reallocates a block of memory pointed to by `*P' to `Size' bytes   */
94   /*    from the heap, possibly changing `*P'.                             */
95   /*                                                                       */
96   /* <Input>                                                               */
97   /*    memory  :: A handle to a given `memory object' which handles       */
98   /*               reallocation.                                           */
99   /*                                                                       */
100   /*    current :: The current block size in bytes.                        */
101   /*                                                                       */
102   /*    size    :: The new block size in bytes.                            */
103   /*                                                                       */
104   /* <InOut>                                                               */
105   /*    P       :: A pointer to the fresh new block.  It should be set to  */
106   /*               NULL if `size' is 0, or in case of error.               */
107   /*                                                                       */
108   /* <Return>                                                              */
109   /*    FreeType error code.  0 means success.                             */
110   /*                                                                       */
111   /* <Note>                                                                */
112   /*    All callers of FT_Realloc() _must_ provide the current block size  */
113   /*    as well as the new one.                                            */
114   /*                                                                       */
115   FT_BASE( FT_Error )
116   FT_Realloc( FT_Memory  memory,
117               FT_Long    current,
118               FT_Long    size,
119               void**     P );
120
121
122   /*************************************************************************/
123   /*                                                                       */
124   /* <Function>                                                            */
125   /*    FT_Free                                                            */
126   /*                                                                       */
127   /* <Description>                                                         */
128   /*    Releases a given block of memory allocated through FT_Alloc().     */
129   /*                                                                       */
130   /* <Input>                                                               */
131   /*    memory :: A handle to a given `memory object' which handles        */
132   /*              memory deallocation                                      */
133   /*                                                                       */
134   /*    P      :: This is the _address_ of a _pointer_ which points to the */
135   /*              allocated block.  It is always set to NULL on exit.      */
136   /*                                                                       */
137   /* <Return>                                                              */
138   /*    FreeType error code.  0 means success.                             */
139   /*                                                                       */
140   /* <Note>                                                                */
141   /*    If P or *P are NULL, this function should return successfully.     */
142   /*    This is a strong convention within all of FreeType and its         */
143   /*    drivers.                                                           */
144   /*                                                                       */
145   FT_BASE( void )
146   FT_Free( FT_Memory  memory,
147            void**     P );
148
149
150
151   /* This `#include' is needed by the MEM_xxx() macros; it should be */
152   /* available on all platforms we know of.                          */
153 #include <string.h>
154
155 #define MEM_Set( dest, byte, count )  memset( dest, byte, count )
156
157 #define MEM_Copy( dest, source, count )  memcpy( dest, source, count )
158
159 #define MEM_Move( dest, source, count )  memmove( dest, source, count )
160
161
162   /*************************************************************************/
163   /*                                                                       */
164   /* We now support closures to produce completely reentrant code.  This   */
165   /* means the allocation functions now takes an additional argument       */
166   /* (`memory').  It is a handle to a given memory object, responsible for */
167   /* all low-level operations, including memory management and             */
168   /* synchronisation.                                                      */
169   /*                                                                       */
170   /* In order to keep our code readable and use the same macros in the     */
171   /* font drivers and the rest of the library, MEM_Alloc(), ALLOC(), and   */
172   /* ALLOC_ARRAY() now use an implicit variable, `memory'.  It must be     */
173   /* defined at all locations where a memory operation is queried.         */
174   /*                                                                       */
175 #define MEM_Alloc( _pointer_, _size_ )                     \
176           FT_Alloc( memory, _size_, (void**)&(_pointer_) )
177
178 #define MEM_Alloc_Array( _pointer_, _count_, _type_ )    \
179           FT_Alloc( memory, (_count_)*sizeof ( _type_ ), \
180                     (void**)&(_pointer_) )
181
182 #define MEM_Realloc( _pointer_, _current_, _size_ )                     \
183           FT_Realloc( memory, _current_, _size_, (void**)&(_pointer_) )
184
185 #define MEM_Realloc_Array( _pointer_, _current_, _new_, _type_ )        \
186           FT_Realloc( memory, (_current_)*sizeof ( _type_ ),            \
187                       (_new_)*sizeof ( _type_ ), (void**)&(_pointer_) )
188
189 #define ALLOC( _pointer_, _size_ )                       \
190           FT_SET_ERROR( MEM_Alloc( _pointer_, _size_ ) )
191
192 #define REALLOC( _pointer_, _current_, _size_ )                       \
193           FT_SET_ERROR( MEM_Realloc( _pointer_, _current_, _size_ ) )
194
195 #define ALLOC_ARRAY( _pointer_, _count_, _type_ )       \
196           FT_SET_ERROR( MEM_Alloc( _pointer_,           \
197                         (_count_)*sizeof ( _type_ ) ) )
198
199 #define REALLOC_ARRAY( _pointer_, _current_, _count_, _type_ ) \
200           FT_SET_ERROR( MEM_Realloc( _pointer_,                \
201                         (_current_)*sizeof ( _type_ ),         \
202                         (_count_)*sizeof ( _type_ ) ) )
203
204 #define FREE( _pointer_ )  FT_Free( memory, (void**)&(_pointer_) )
205
206
207 FT_END_HEADER
208
209 #endif /* __FTMEMORY_H__ */
210
211
212 /* END */