24#include FT_CONFIG_CONFIG_H
43#define FT_SET_ERROR( expression ) \
44 ( ( error = (expression) ) != 0 )
66#define FT_OFFSET( base, count ) ( (base) ? (base) + (count) : NULL )
79 template <
typename T>
inline T*
83 return static_cast <T*
> (
v );
87#define FT_ASSIGNP( p, val ) (p) = cplusplus_typeof( (p), (val) )
91#define FT_ASSIGNP( p, val ) (p) = (val)
99 FT_BASE(
const char* ) _ft_debug_file;
100 FT_BASE(
long ) _ft_debug_lineno;
102#define FT_DEBUG_INNER( exp ) ( _ft_debug_file = __FILE__, \
103 _ft_debug_lineno = __LINE__, \
106#define FT_ASSIGNP_INNER( p, exp ) ( _ft_debug_file = __FILE__, \
107 _ft_debug_lineno = __LINE__, \
108 FT_ASSIGNP( p, exp ) )
112#define FT_DEBUG_INNER( exp ) (exp)
113#define FT_ASSIGNP_INNER( p, exp ) FT_ASSIGNP( p, exp )
160#define FT_MEM_ALLOC( ptr, size ) \
161 FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, \
165#define FT_MEM_FREE( ptr ) \
167 FT_DEBUG_INNER( ft_mem_free( memory, (ptr) ) ); \
171#define FT_MEM_NEW( ptr ) \
172 FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
174#define FT_MEM_REALLOC( ptr, cursz, newsz ) \
175 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
182#define FT_MEM_QALLOC( ptr, size ) \
183 FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, \
187#define FT_MEM_QNEW( ptr ) \
188 FT_MEM_QALLOC( ptr, sizeof ( *(ptr) ) )
190#define FT_MEM_QREALLOC( ptr, cursz, newsz ) \
191 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
198#define FT_MEM_ALLOC_MULT( ptr, count, item_size ) \
199 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
200 (FT_Long)(item_size), \
206#define FT_MEM_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
207 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
214#define FT_MEM_QALLOC_MULT( ptr, count, item_size ) \
215 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
216 (FT_Long)(item_size), \
222#define FT_MEM_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
223 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
231#define FT_MEM_SET_ERROR( cond ) ( (cond), error != 0 )
234#define FT_MEM_SET( dest, byte, count ) \
235 ft_memset( dest, byte, (FT_Offset)(count) )
237#define FT_MEM_COPY( dest, source, count ) \
238 ft_memcpy( dest, source, (FT_Offset)(count) )
240#define FT_MEM_MOVE( dest, source, count ) \
241 ft_memmove( dest, source, (FT_Offset)(count) )
244#define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count )
246#define FT_ZERO( p ) FT_MEM_ZERO( p, sizeof ( *(p) ) )
249#define FT_ARRAY_ZERO( dest, count ) \
251 (FT_Offset)(count) * sizeof ( *(dest) ) )
253#define FT_ARRAY_COPY( dest, source, count ) \
256 (FT_Offset)(count) * sizeof ( *(dest) ) )
258#define FT_ARRAY_MOVE( dest, source, count ) \
261 (FT_Offset)(count) * sizeof ( *(dest) ) )
268#define FT_ARRAY_MAX( ptr ) ( FT_INT_MAX / sizeof ( *(ptr) ) )
270#define FT_ARRAY_CHECK( ptr, count ) ( (count) <= FT_ARRAY_MAX( ptr ) )
279#define FT_MEM_NEW_ARRAY( ptr, count ) \
280 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
287#define FT_MEM_RENEW_ARRAY( ptr, cursz, newsz ) \
288 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
295#define FT_MEM_QNEW_ARRAY( ptr, count ) \
296 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
303#define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz ) \
304 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
311#define FT_ALLOC( ptr, size ) \
312 FT_MEM_SET_ERROR( FT_MEM_ALLOC( ptr, size ) )
314#define FT_REALLOC( ptr, cursz, newsz ) \
315 FT_MEM_SET_ERROR( FT_MEM_REALLOC( ptr, cursz, newsz ) )
317#define FT_ALLOC_MULT( ptr, count, item_size ) \
318 FT_MEM_SET_ERROR( FT_MEM_ALLOC_MULT( ptr, count, item_size ) )
320#define FT_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
321 FT_MEM_SET_ERROR( FT_MEM_REALLOC_MULT( ptr, oldcnt, \
324#define FT_QALLOC( ptr, size ) \
325 FT_MEM_SET_ERROR( FT_MEM_QALLOC( ptr, size ) )
327#define FT_QREALLOC( ptr, cursz, newsz ) \
328 FT_MEM_SET_ERROR( FT_MEM_QREALLOC( ptr, cursz, newsz ) )
330#define FT_QALLOC_MULT( ptr, count, item_size ) \
331 FT_MEM_SET_ERROR( FT_MEM_QALLOC_MULT( ptr, count, item_size ) )
333#define FT_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
334 FT_MEM_SET_ERROR( FT_MEM_QREALLOC_MULT( ptr, oldcnt, \
337#define FT_FREE( ptr ) FT_MEM_FREE( ptr )
339#define FT_NEW( ptr ) FT_MEM_SET_ERROR( FT_MEM_NEW( ptr ) )
341#define FT_NEW_ARRAY( ptr, count ) \
342 FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
344#define FT_RENEW_ARRAY( ptr, curcnt, newcnt ) \
345 FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
347#define FT_QNEW( ptr ) \
348 FT_MEM_SET_ERROR( FT_MEM_QNEW( ptr ) )
350#define FT_QNEW_ARRAY( ptr, count ) \
351 FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
353#define FT_QRENEW_ARRAY( ptr, curcnt, newcnt ) \
354 FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
369#define FT_MEM_STRDUP( dst, str ) \
370 (dst) = (char*)ft_mem_strdup( memory, (const char*)(str), &error )
372#define FT_STRDUP( dst, str ) \
373 FT_MEM_SET_ERROR( FT_MEM_STRDUP( dst, str ) )
375#define FT_MEM_DUP( dst, address, size ) \
376 (dst) = ft_mem_dup( memory, (address), (FT_ULong)(size), &error )
378#define FT_DUP( dst, address, size ) \
379 FT_MEM_SET_ERROR( FT_MEM_DUP( dst, address, size ) )
390#define FT_STRCPYN( dst, src, size ) \
391 ft_mem_strcpyn( (char*)dst, (const char*)(src), (FT_ULong)(size) )
ft_mem_qalloc(FT_Memory memory, FT_Long size, FT_Error *p_error)
ft_mem_dup(FT_Memory memory, const void *address, FT_ULong size, FT_Error *p_error)
ft_mem_strdup(FT_Memory memory, const char *str, FT_Error *p_error)
ft_mem_alloc(FT_Memory memory, FT_Long size, FT_Error *p_error)
ft_mem_free(FT_Memory memory, const void *P)
ft_mem_strcpyn(char *dst, const char *src, FT_ULong size)
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_qrealloc(FT_Memory memory, FT_Long item_size, FT_Long cur_count, FT_Long new_count, void *block, FT_Error *p_error)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
static char memory[1024 *256]
static unsigned int block