24#include FT_CONFIG_CONFIG_H
42#define FT_SET_ERROR( expression ) \
43 ( ( error = (expression) ) != 0 )
70 template <
typename T>
inline T*
74 return static_cast <T*
> (
v );
78#define FT_ASSIGNP( p, val ) (p) = cplusplus_typeof( (p), (val) )
82#define FT_ASSIGNP( p, val ) (p) = (val)
90 FT_BASE(
const char* ) _ft_debug_file;
91 FT_BASE(
long ) _ft_debug_lineno;
93#define FT_DEBUG_INNER( exp ) ( _ft_debug_file = __FILE__, \
94 _ft_debug_lineno = __LINE__, \
97#define FT_ASSIGNP_INNER( p, exp ) ( _ft_debug_file = __FILE__, \
98 _ft_debug_lineno = __LINE__, \
99 FT_ASSIGNP( p, exp ) )
103#define FT_DEBUG_INNER( exp ) (exp)
104#define FT_ASSIGNP_INNER( p, exp ) FT_ASSIGNP( p, exp )
151#define FT_MEM_ALLOC( ptr, size ) \
152 FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, \
156#define FT_MEM_FREE( ptr ) \
158 ft_mem_free( memory, (ptr) ); \
162#define FT_MEM_NEW( ptr ) \
163 FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
165#define FT_MEM_REALLOC( ptr, cursz, newsz ) \
166 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
173#define FT_MEM_QALLOC( ptr, size ) \
174 FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, \
178#define FT_MEM_QNEW( ptr ) \
179 FT_MEM_QALLOC( ptr, sizeof ( *(ptr) ) )
181#define FT_MEM_QREALLOC( ptr, cursz, newsz ) \
182 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
189#define FT_MEM_ALLOC_MULT( ptr, count, item_size ) \
190 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
191 (FT_Long)(item_size), \
197#define FT_MEM_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
198 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
205#define FT_MEM_QALLOC_MULT( ptr, count, item_size ) \
206 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
207 (FT_Long)(item_size), \
213#define FT_MEM_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
214 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
222#define FT_MEM_SET_ERROR( cond ) ( (cond), error != 0 )
225#define FT_MEM_SET( dest, byte, count ) \
226 ft_memset( dest, byte, (FT_Offset)(count) )
228#define FT_MEM_COPY( dest, source, count ) \
229 ft_memcpy( dest, source, (FT_Offset)(count) )
231#define FT_MEM_MOVE( dest, source, count ) \
232 ft_memmove( dest, source, (FT_Offset)(count) )
235#define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count )
237#define FT_ZERO( p ) FT_MEM_ZERO( p, sizeof ( *(p) ) )
240#define FT_ARRAY_ZERO( dest, count ) \
242 (FT_Offset)(count) * sizeof ( *(dest) ) )
244#define FT_ARRAY_COPY( dest, source, count ) \
247 (FT_Offset)(count) * sizeof ( *(dest) ) )
249#define FT_ARRAY_MOVE( dest, source, count ) \
252 (FT_Offset)(count) * sizeof ( *(dest) ) )
260#define FT_ARRAY_MAX( ptr ) ( FT_INT_MAX / sizeof ( *(ptr) ) )
262#define FT_ARRAY_CHECK( ptr, count ) ( (count) <= FT_ARRAY_MAX( ptr ) )
271#define FT_MEM_NEW_ARRAY( ptr, count ) \
272 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
279#define FT_MEM_RENEW_ARRAY( ptr, cursz, newsz ) \
280 FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
287#define FT_MEM_QNEW_ARRAY( ptr, count ) \
288 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
295#define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz ) \
296 FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
303#define FT_ALLOC( ptr, size ) \
304 FT_MEM_SET_ERROR( FT_MEM_ALLOC( ptr, size ) )
306#define FT_REALLOC( ptr, cursz, newsz ) \
307 FT_MEM_SET_ERROR( FT_MEM_REALLOC( ptr, cursz, newsz ) )
309#define FT_ALLOC_MULT( ptr, count, item_size ) \
310 FT_MEM_SET_ERROR( FT_MEM_ALLOC_MULT( ptr, count, item_size ) )
312#define FT_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
313 FT_MEM_SET_ERROR( FT_MEM_REALLOC_MULT( ptr, oldcnt, \
316#define FT_QALLOC( ptr, size ) \
317 FT_MEM_SET_ERROR( FT_MEM_QALLOC( ptr, size ) )
319#define FT_QREALLOC( ptr, cursz, newsz ) \
320 FT_MEM_SET_ERROR( FT_MEM_QREALLOC( ptr, cursz, newsz ) )
322#define FT_QALLOC_MULT( ptr, count, item_size ) \
323 FT_MEM_SET_ERROR( FT_MEM_QALLOC_MULT( ptr, count, item_size ) )
325#define FT_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
326 FT_MEM_SET_ERROR( FT_MEM_QREALLOC_MULT( ptr, oldcnt, \
329#define FT_FREE( ptr ) FT_MEM_FREE( ptr )
331#define FT_NEW( ptr ) FT_MEM_SET_ERROR( FT_MEM_NEW( ptr ) )
333#define FT_NEW_ARRAY( ptr, count ) \
334 FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
336#define FT_RENEW_ARRAY( ptr, curcnt, newcnt ) \
337 FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
339#define FT_QNEW( ptr ) \
340 FT_MEM_SET_ERROR( FT_MEM_QNEW( ptr ) )
342#define FT_QNEW_ARRAY( ptr, count ) \
343 FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
345#define FT_QRENEW_ARRAY( ptr, curcnt, newcnt ) \
346 FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
361#define FT_MEM_STRDUP( dst, str ) \
362 (dst) = (char*)ft_mem_strdup( memory, (const char*)(str), &error )
364#define FT_STRDUP( dst, str ) \
365 FT_MEM_SET_ERROR( FT_MEM_STRDUP( dst, str ) )
367#define FT_MEM_DUP( dst, address, size ) \
368 (dst) = ft_mem_dup( memory, (address), (FT_ULong)(size), &error )
370#define FT_DUP( dst, address, size ) \
371 FT_MEM_SET_ERROR( FT_MEM_DUP( dst, address, size ) )
382#define FT_STRCPYN( dst, src, size ) \
383 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