This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / include / freetype / internal / ftmemory.h
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ftmemory.h                                                             */
4 /*                                                                         */
5 /*    The FreeType memory management macros (specification).               */
6 /*                                                                         */
7 /*  Copyright 1996-2000 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 <freetype/config/ftconfig.h>
24 #include <freetype/fttypes.h>
25
26
27   /*************************************************************************/
28   /*                                                                       */
29   /* <Macro>                                                               */
30   /*    FT_SET_ERROR                                                       */
31   /*                                                                       */
32   /* <Description>                                                         */
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.                   */
36   /*                                                                       */
37 #undef  FT_SET_ERROR
38 #define FT_SET_ERROR( expression ) \
39           ( ( error = (expression) ) != 0 )
40
41
42   /*************************************************************************/
43   /*************************************************************************/
44   /*************************************************************************/
45   /****                                                                 ****/
46   /****                                                                 ****/
47   /****                           M E M O R Y                           ****/
48   /****                                                                 ****/
49   /****                                                                 ****/
50   /*************************************************************************/
51   /*************************************************************************/
52   /*************************************************************************/
53
54   BASE_DEF( FT_Error )  FT_Alloc( FT_Memory  memory,
55                                   FT_Long    size,
56                                   void**     P );
57
58   BASE_DEF( FT_Error )  FT_Realloc( FT_Memory  memory,
59                                     FT_Long    current,
60                                     FT_Long    size,
61                                     void**     P );
62
63   BASE_DEF( void )  FT_Free( FT_Memory  memory,
64                              void**     P );
65
66
67
68   /* This `#include' is needed by the MEM_xxx() macros; it should be */
69   /* available on all platforms we know of.                          */
70 #include <string.h>
71
72 #define MEM_Set( dest, byte, count )  memset( dest, byte, count )
73
74 #define MEM_Copy( dest, source, count )  memcpy( dest, source, count )
75
76 #define MEM_Move( dest, source, count )  memmove( dest, source, count )
77
78
79   /*************************************************************************/
80   /*                                                                       */
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.                                                      */
86   /*                                                                       */
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.         */
91   /*                                                                       */
92 #define MEM_Alloc( _pointer_, _size_ )                     \
93           FT_Alloc( memory, _size_, (void**)&(_pointer_) )
94
95 #define MEM_Alloc_Array( _pointer_, _count_, _type_ )    \
96           FT_Alloc( memory, (_count_)*sizeof ( _type_ ), \
97                     (void**)&(_pointer_) )
98
99 #define MEM_Realloc( _pointer_, _current_, _size_ )                     \
100           FT_Realloc( memory, _current_, _size_, (void**)&(_pointer_) )
101
102 #define MEM_Realloc_Array( _pointer_, _current_, _new_, _type_ )        \
103           FT_Realloc( memory, (_current_)*sizeof ( _type_ ),            \
104                       (_new_)*sizeof ( _type_ ), (void**)&(_pointer_) )
105
106 #define ALLOC( _pointer_, _size_ )                       \
107           FT_SET_ERROR( MEM_Alloc( _pointer_, _size_ ) )
108
109 #define REALLOC( _pointer_, _current_, _size_ )                       \
110           FT_SET_ERROR( MEM_Realloc( _pointer_, _current_, _size_ ) )
111
112 #define ALLOC_ARRAY( _pointer_, _count_, _type_ )       \
113           FT_SET_ERROR( MEM_Alloc( _pointer_,           \
114                         (_count_)*sizeof ( _type_ ) ) )
115
116 #define REALLOC_ARRAY( _pointer_, _current_, _count_, _type_ ) \
117           FT_SET_ERROR( MEM_Realloc( _pointer_,                \
118                         (_current_)*sizeof ( _type_ ),         \
119                         (_count_)*sizeof ( _type_ ) ) )
120
121 #define FREE( _pointer_ )  FT_Free( memory, (void**)&(_pointer_) )
122
123
124 #endif /* FTMEMORY_H */
125
126
127 /* END */