1 /***************************************************************************/
5 /* The FreeType memory management macros (specification). */
7 /* Copyright 1996-2000 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg */
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. */
16 /***************************************************************************/
23 #include <freetype/config/ftconfig.h>
24 #include <freetype/fttypes.h>
27 /*************************************************************************/
33 /* This macro is used to set an implicit `error' variable to a given */
34 /* expression's value (usually a function call), and convert it to a */
35 /* boolean which is set whenever the value is != 0. */
38 #define FT_SET_ERROR( expression ) \
39 ( ( error = (expression) ) != 0 )
42 /*************************************************************************/
43 /*************************************************************************/
44 /*************************************************************************/
47 /**** M E M O R Y ****/
50 /*************************************************************************/
51 /*************************************************************************/
52 /*************************************************************************/
54 BASE_DEF( FT_Error ) FT_Alloc( FT_Memory memory,
58 BASE_DEF( FT_Error ) FT_Realloc( FT_Memory memory,
63 BASE_DEF( void ) FT_Free( FT_Memory memory,
68 /* This `#include' is needed by the MEM_xxx() macros; it should be */
69 /* available on all platforms we know of. */
72 #define MEM_Set( dest, byte, count ) memset( dest, byte, count )
74 #define MEM_Copy( dest, source, count ) memcpy( dest, source, count )
76 #define MEM_Move( dest, source, count ) memmove( dest, source, count )
79 /*************************************************************************/
81 /* We now support closures to produce completely reentrant code. This */
82 /* means the allocation functions now takes an additional argument */
83 /* (`memory'). It is a handle to a given memory object, responsible for */
84 /* all low-level operations, including memory management and */
85 /* synchronisation. */
87 /* In order to keep our code readable and use the same macros in the */
88 /* font drivers and the rest of the library, MEM_Alloc(), ALLOC(), and */
89 /* ALLOC_ARRAY() now use an implicit variable, `memory'. It must be */
90 /* defined at all locations where a memory operation is queried. */
92 #define MEM_Alloc( _pointer_, _size_ ) \
93 FT_Alloc( memory, _size_, (void**)&(_pointer_) )
95 #define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \
96 FT_Alloc( memory, (_count_)*sizeof ( _type_ ), \
97 (void**)&(_pointer_) )
99 #define MEM_Realloc( _pointer_, _current_, _size_ ) \
100 FT_Realloc( memory, _current_, _size_, (void**)&(_pointer_) )
102 #define MEM_Realloc_Array( _pointer_, _current_, _new_, _type_ ) \
103 FT_Realloc( memory, (_current_)*sizeof ( _type_ ), \
104 (_new_)*sizeof ( _type_ ), (void**)&(_pointer_) )
106 #define ALLOC( _pointer_, _size_ ) \
107 FT_SET_ERROR( MEM_Alloc( _pointer_, _size_ ) )
109 #define REALLOC( _pointer_, _current_, _size_ ) \
110 FT_SET_ERROR( MEM_Realloc( _pointer_, _current_, _size_ ) )
112 #define ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
113 FT_SET_ERROR( MEM_Alloc( _pointer_, \
114 (_count_)*sizeof ( _type_ ) ) )
116 #define REALLOC_ARRAY( _pointer_, _current_, _count_, _type_ ) \
117 FT_SET_ERROR( MEM_Realloc( _pointer_, \
118 (_current_)*sizeof ( _type_ ), \
119 (_count_)*sizeof ( _type_ ) ) )
121 #define FREE( _pointer_ ) FT_Free( memory, (void**)&(_pointer_) )
124 #endif /* FTMEMORY_H */