19 #ifndef __FTMEMORY_H__
20 #define __FTMEMORY_H__
24 #include FT_CONFIG_CONFIG_H
42 #define FT_SET_ERROR( expression ) \
43 ( ( error = (expression) ) != 0 )
69 template <
typename T>
inline T*
73 return static_cast <T*> (
v );
76 #define FT_ASSIGNP( p, val ) (p) = cplusplus_typeof( (p), (val) )
80 #define FT_ASSIGNP( p, val ) (p) = (val)
86 #ifdef FT_DEBUG_MEMORY
88 FT_BASE(
const char* ) _ft_debug_file;
89 FT_BASE(
long ) _ft_debug_lineno;
91 #define FT_DEBUG_INNER( exp ) ( _ft_debug_file = __FILE__, \
92 _ft_debug_lineno = __LINE__, \
95 #define FT_ASSIGNP_INNER( p, exp ) ( _ft_debug_file = __FILE__, \
96 _ft_debug_lineno = __LINE__, \
97 FT_ASSIGNP( p, exp ) )
101 #define FT_DEBUG_INNER( exp ) (exp)
102 #define FT_ASSIGNP_INNER( p, exp ) FT_ASSIGNP( p, exp )
144 #define FT_MEM_ALLOC( ptr, size ) \
145 FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, (size), &error ) )
147 #define FT_MEM_FREE( ptr ) \
149 ft_mem_free( memory, (ptr) ); \
153 #define FT_MEM_NEW( ptr ) \
154 FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
156 #define FT_MEM_REALLOC( ptr, cursz, newsz ) \
157 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, 1, \
161 #define FT_MEM_QALLOC( ptr, size ) \
162 FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, (size), &error ) )
164 #define FT_MEM_QNEW( ptr ) \
165 FT_MEM_QALLOC( ptr, sizeof ( *(ptr) ) )
167 #define FT_MEM_QREALLOC( ptr, cursz, newsz ) \
168 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, 1, \
172 #define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz ) \
173 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
177 #define FT_MEM_ALLOC_MULT( ptr, count, item_size ) \
178 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, (item_size), \
182 #define FT_MEM_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
183 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, (itmsz), \
184 (oldcnt), (newcnt), \
187 #define FT_MEM_QALLOC_MULT( ptr, count, item_size ) \
188 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, (item_size), \
192 #define FT_MEM_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz) \
193 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, (itmsz), \
194 (oldcnt), (newcnt), \
198 #define FT_MEM_SET_ERROR( cond ) ( (cond), error != 0 )
201 #define FT_MEM_SET( dest, byte, count ) ft_memset( dest, byte, count )
203 #define FT_MEM_COPY( dest, source, count ) ft_memcpy( dest, source, count )
205 #define FT_MEM_MOVE( dest, source, count ) ft_memmove( dest, source, count )
208 #define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count )
210 #define FT_ZERO( p ) FT_MEM_ZERO( p, sizeof ( *(p) ) )
213 #define FT_ARRAY_ZERO( dest, count ) \
214 FT_MEM_ZERO( dest, (count) * sizeof ( *(dest) ) )
216 #define FT_ARRAY_COPY( dest, source, count ) \
217 FT_MEM_COPY( dest, source, (count) * sizeof ( *(dest) ) )
219 #define FT_ARRAY_MOVE( dest, source, count ) \
220 FT_MEM_MOVE( dest, source, (count) * sizeof ( *(dest) ) )
228 #define FT_ARRAY_MAX( ptr ) ( FT_INT_MAX / sizeof ( *(ptr) ) )
230 #define FT_ARRAY_CHECK( ptr, count ) ( (count) <= FT_ARRAY_MAX( ptr ) )
239 #define FT_MEM_NEW_ARRAY( ptr, count ) \
240 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, sizeof ( *(ptr) ), \
244 #define FT_MEM_RENEW_ARRAY( ptr, cursz, newsz ) \
245 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, sizeof ( *(ptr) ), \
249 #define FT_MEM_QNEW_ARRAY( ptr, count ) \
250 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
254 #define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz ) \
255 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
260 #define FT_ALLOC( ptr, size ) \
261 FT_MEM_SET_ERROR( FT_MEM_ALLOC( ptr, size ) )
263 #define FT_REALLOC( ptr, cursz, newsz ) \
264 FT_MEM_SET_ERROR( FT_MEM_REALLOC( ptr, cursz, newsz ) )
266 #define FT_ALLOC_MULT( ptr, count, item_size ) \
267 FT_MEM_SET_ERROR( FT_MEM_ALLOC_MULT( ptr, count, item_size ) )
269 #define FT_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
270 FT_MEM_SET_ERROR( FT_MEM_REALLOC_MULT( ptr, oldcnt, \
273 #define FT_QALLOC( ptr, size ) \
274 FT_MEM_SET_ERROR( FT_MEM_QALLOC( ptr, size ) )
276 #define FT_QREALLOC( ptr, cursz, newsz ) \
277 FT_MEM_SET_ERROR( FT_MEM_QREALLOC( ptr, cursz, newsz ) )
279 #define FT_QALLOC_MULT( ptr, count, item_size ) \
280 FT_MEM_SET_ERROR( FT_MEM_QALLOC_MULT( ptr, count, item_size ) )
282 #define FT_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
283 FT_MEM_SET_ERROR( FT_MEM_QREALLOC_MULT( ptr, oldcnt, \
286 #define FT_FREE( ptr ) FT_MEM_FREE( ptr )
288 #define FT_NEW( ptr ) FT_MEM_SET_ERROR( FT_MEM_NEW( ptr ) )
290 #define FT_NEW_ARRAY( ptr, count ) \
291 FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
293 #define FT_RENEW_ARRAY( ptr, curcnt, newcnt ) \
294 FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
296 #define FT_QNEW( ptr ) \
297 FT_MEM_SET_ERROR( FT_MEM_QNEW( ptr ) )
299 #define FT_QNEW_ARRAY( ptr, count ) \
300 FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
302 #define FT_QRENEW_ARRAY( ptr, curcnt, newcnt ) \
303 FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
306 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
348 #define FT_MEM_STRDUP( dst, str ) \
349 (dst) = (char*)ft_mem_strdup( memory, (const char*)(str), &error )
351 #define FT_STRDUP( dst, str ) \
352 FT_MEM_SET_ERROR( FT_MEM_STRDUP( dst, str ) )
354 #define FT_MEM_DUP( dst, address, size ) \
355 (dst) = ft_mem_dup( memory, (address), (FT_ULong)(size), &error )
357 #define FT_DUP( dst, address, size ) \
358 FT_MEM_SET_ERROR( FT_MEM_DUP( dst, address, size ) )
369 #define FT_STRCPYN( dst, src, size ) \
370 ft_mem_strcpyn( (char*)dst, (const char*)(src), (FT_ULong)(size) )
ft_mem_strdup(FT_Memory memory, const char *str, FT_Error *p_error)
ft_mem_free(FT_Memory memory, const void *P)
ft_mem_qalloc(FT_Memory memory, FT_Long size, FT_Error *p_error)
ft_mem_alloc(FT_Memory memory, FT_Long size, FT_Error *p_error)
GLuint GLuint64EXT address
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
ft_mem_realloc(FT_Memory memory, FT_Long item_size, FT_Long cur_count, FT_Long new_count, void *block, FT_Error *p_error)
ft_mem_dup(FT_Memory memory, const void *address, FT_ULong size, FT_Error *p_error)
ft_mem_qrealloc(FT_Memory memory, FT_Long item_size, FT_Long cur_count, FT_Long new_count, void *block, FT_Error *p_error)
ft_mem_strcpyn(char *dst, const char *src, FT_ULong size)