1 /****************************************************************************
2 *
3 * ftmemory.h
4 *
5 * The FreeType memory management macros (specification).
6 *
7 * Copyright (C) 1996-2019 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
40 */
41 #undef FT_SET_ERROR
42 #define FT_SET_ERROR( expression ) \
43 ( ( error = (expression) ) != 0 )
44
45
46
47 /*************************************************************************/
48 /*************************************************************************/
49 /*************************************************************************/
50 /**** ****/
51 /**** ****/
52 /**** M E M O R Y ****/
53 /**** ****/
54 /**** ****/
55 /*************************************************************************/
56 /*************************************************************************/
57 /*************************************************************************/
58
59
60 /*
61 * C++ refuses to handle statements like p = (void*)anything, with `p' a
62 * typed pointer. Since we don't have a `typeof' operator in standard C++,
63 * we have to use a template to emulate it.
64 */
65
66 #ifdef __cplusplus
67
68 extern "C++"
69 {
70 template <typename T> inline T*
71 cplusplus_typeof( T*,
72 void *v )
73 {
74 return static_cast <T*> ( v );
75 }
76 }
77
78 #define FT_ASSIGNP( p, val ) (p) = cplusplus_typeof( (p), (val) )
79
138 FT_Long cur_count,
139 FT_Long new_count,
140 void* block,
141 FT_Error *p_error );
142
143 FT_BASE( void )
144 ft_mem_free( FT_Memory memory,
145 const void* P );
146
147
148 /* The `Q' variants of the macros below (`Q' for `quick') don't fill */
149 /* the allocated or reallocated memory with zero bytes. */
150
151 #define FT_MEM_ALLOC( ptr, size ) \
152 FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, \
153 (FT_Long)(size), \
154 &error ) )
155
156 #define FT_MEM_FREE( ptr ) \
157 FT_BEGIN_STMNT \
158 ft_mem_free( memory, (ptr) ); \
159 (ptr) = NULL; \
160 FT_END_STMNT
161
162 #define FT_MEM_NEW( ptr ) \
163 FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
164
165 #define FT_MEM_REALLOC( ptr, cursz, newsz ) \
166 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
167 1, \
168 (FT_Long)(cursz), \
169 (FT_Long)(newsz), \
170 (ptr), \
171 &error ) )
172
173 #define FT_MEM_QALLOC( ptr, size ) \
174 FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, \
175 (FT_Long)(size), \
176 &error ) )
177
178 #define FT_MEM_QNEW( ptr ) \
|
1 /****************************************************************************
2 *
3 * ftmemory.h
4 *
5 * The FreeType memory management macros (specification).
6 *
7 * Copyright (C) 1996-2020 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
40 */
41 #undef FT_SET_ERROR
42 #define FT_SET_ERROR( expression ) \
43 ( ( error = (expression) ) != 0 )
44
45
46
47 /*************************************************************************/
48 /*************************************************************************/
49 /*************************************************************************/
50 /**** ****/
51 /**** ****/
52 /**** M E M O R Y ****/
53 /**** ****/
54 /**** ****/
55 /*************************************************************************/
56 /*************************************************************************/
57 /*************************************************************************/
58
59
60 /* The calculation `NULL + n' is undefined in C. Even if the resulting */
61 /* pointer doesn't get dereferenced, this causes warnings with */
62 /* sanitizers. */
63 /* */
64 /* We thus provide a macro that should be used if `base' can be NULL. */
65 #define FT_OFFSET( base, count ) ( (base) ? (base) + (count) : NULL )
66
67
68 /*
69 * C++ refuses to handle statements like p = (void*)anything, with `p' a
70 * typed pointer. Since we don't have a `typeof' operator in standard C++,
71 * we have to use a template to emulate it.
72 */
73
74 #ifdef __cplusplus
75
76 extern "C++"
77 {
78 template <typename T> inline T*
79 cplusplus_typeof( T*,
80 void *v )
81 {
82 return static_cast <T*> ( v );
83 }
84 }
85
86 #define FT_ASSIGNP( p, val ) (p) = cplusplus_typeof( (p), (val) )
87
146 FT_Long cur_count,
147 FT_Long new_count,
148 void* block,
149 FT_Error *p_error );
150
151 FT_BASE( void )
152 ft_mem_free( FT_Memory memory,
153 const void* P );
154
155
156 /* The `Q' variants of the macros below (`Q' for `quick') don't fill */
157 /* the allocated or reallocated memory with zero bytes. */
158
159 #define FT_MEM_ALLOC( ptr, size ) \
160 FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, \
161 (FT_Long)(size), \
162 &error ) )
163
164 #define FT_MEM_FREE( ptr ) \
165 FT_BEGIN_STMNT \
166 FT_DEBUG_INNER( ft_mem_free( memory, (ptr) ) ); \
167 (ptr) = NULL; \
168 FT_END_STMNT
169
170 #define FT_MEM_NEW( ptr ) \
171 FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
172
173 #define FT_MEM_REALLOC( ptr, cursz, newsz ) \
174 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
175 1, \
176 (FT_Long)(cursz), \
177 (FT_Long)(newsz), \
178 (ptr), \
179 &error ) )
180
181 #define FT_MEM_QALLOC( ptr, size ) \
182 FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, \
183 (FT_Long)(size), \
184 &error ) )
185
186 #define FT_MEM_QNEW( ptr ) \
|