@ -176,108 +176,117 @@ FT_BEGIN_HEADER
/* available on all platforms we know of. */
# include <string.h>
# define MEM_Set ( dest, byte, count ) memset( dest, byte, count )
# define FT_MEM_SET ( dest, byte, count ) memset( dest, byte, count )
# define MEM_Copy ( dest, source, count ) memcpy( dest, source, count )
# define FT_MEM_COPY ( dest, source, count ) memcpy( dest, source, count )
# define MEM_Move ( dest, source, count ) memmove( dest, source, count )
# define FT_MEM_MOVE ( dest, source, count ) memmove( dest, source, count )
/*************************************************************************/
/* */
/* We now support closures to produce completely reentrant code. This */
/* means the allocation functions now takes an additional argument */
/* (`memory'). It is a handle to a given memory object, responsible for */
/* all low-level operations, including memory management and */
/* synchronisation. */
/* */
/* In order to keep our code readable and use the same macros in the */
/* font drivers and the rest of the library, MEM_Alloc(), ALLOC(), and */
/* ALLOC_ARRAY() now use an implicit variable, `memory'. It must be */
/* defined at all locations where a memory operation is queried. */
/* */
/**************************************************************************
*
* we first define FT_MEM_ALLOC , FT_MEM_REALLOC and FT_MEM_FREE
* all macros use an _implicit_ ' memory ' parameter to access the
* current memory allocator
*
*/
# ifdef FT_DEBUG_MEMORY
# define MEM_Alloc( _pointer_, _size_ ) \
FT_Alloc_Debug ( memory , _size_ , \
# define FT_MEM_ALLOC( _pointer_, _size_ ) \
FT_Alloc_Debug ( memory , _size_ , \
( void * * ) & ( _pointer_ ) , __FILE__ , __LINE__ )
# define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \
FT_Alloc_Debug ( memory , ( _count_ ) * sizeof ( _type_ ) , \
( void * * ) & ( _pointer_ ) , __FILE__ , __LINE__ )
# define MEM_Realloc( _pointer_, _current_, _size_ ) \
FT_Realloc_Debug ( memory , _current_ , _size_ , \
( void * * ) & ( _pointer_ ) , __FILE__ , __LINE__ )
# define MEM_Realloc_Array( _pointer_, _current_, _new_, _type_ ) \
FT_Realloc_Debug ( memory , ( _current_ ) * sizeof ( _type_ ) , \
( _new_ ) * sizeof ( _type_ ) , \
# define FT_MEM_REALLOC( _pointer_, _current_, _size_ ) \
FT_Realloc_Debug ( memory , _current_ , _size_ , \
( void * * ) & ( _pointer_ ) , __FILE__ , __LINE__ )
# define MEM_Free( _pointer_ ) \
# define FT_MEM_FREE( _pointer_ ) \
FT_Free_Debug ( memory , ( void * * ) & ( _pointer_ ) , __FILE__ , __LINE__ )
# else /* !FT_DEBUG_MEMORY */
# define MEM_Alloc( _pointer_, _size_ ) \
# define FT_MEM_ALLOC( _pointer_, _size_ ) \
FT_Alloc ( memory , _size_ , ( void * * ) & ( _pointer_ ) )
# define MEM_New( _pointer_ ) MEM_Alloc( _pointer_, sizeof(*(_pointer_)) )
# define FT_MEM_FREE( _pointer_ ) \
FT_Free ( memory , ( void * * ) & ( _pointer_ ) )
# define FT_MEM_REALLOC( _pointer_, _current_, _size_ ) \
FT_Realloc ( memory , _current_ , _size_ , ( void * * ) & ( _pointer_ ) )
# define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \
FT_Alloc ( memory , ( _count_ ) * sizeof ( _type_ ) , \
( void * * ) & ( _pointer_ ) )
# endif /* !FT_DEBUG_MEMORY */
# define MEM_New_Array( _pointer_, _count_ ) \
MEM_Alloc_Array ( _pointer_ , _count_ , sizeof ( * ( _pointer_ ) ) )
# define MEM_Realloc( _pointer_, _current_, _size_ ) \
FT_Realloc ( memory , _current_ , _size_ , ( void * * ) & ( _pointer_ ) )
/**************************************************************************
*
* the following functions macros that their pointer argument is _typed_
* in order to automatically compute array element sizes . .
*/
# define FT_MEM_NEW( _pointer_ ) \
FT_MEM_ALLOC ( _pointer_ , sizeof ( * ( _pointer_ ) ) )
# define MEM_Realloc_Array( _pointer_, _current_, _new_, _type_ ) \
FT_Realloc ( memory , ( _current_ ) * sizeof ( _type_ ) , \
( _new_ ) * sizeof ( _type_ ) , ( void * * ) & ( _pointer_ ) )
# define FT_MEM_NEW_ARRAY( _pointer_, _count_ ) \
FT_MEM_ALLOC ( _pointer_ , ( _count_ ) * sizeof ( * ( _pointer_ ) ) )
# define MEM_Renew_Array( _pointer_, _current_, _new_ ) \
MEM_Realloc_Array ( _pointer_ , _current_ , _new_ , * ( _pointer_ ) )
# define FT_MEM_RENEW_ARRAY( _pointer_, _old_, _new_ ) \
FT_MEM_REALLOC ( _pointer_ , ( _old_ ) * sizeof ( * ( _pointer_ ) ) , \
( _new_ ) * sizeof ( * ( _pointer_ ) ) )
# define MEM_Free( _pointer_ ) \
FT_Free ( memory , ( void * * ) & ( _pointer_ ) )
# endif /* !FT_DEBUG_MEMORY */
/**************************************************************************
*
* the following macros are obsolete but kept for compatibility reasons
*/
# define FT_MEM_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_MEM_ALLOC ( _pointer_ , ( _count_ ) * sizeof ( _type_ ) )
# define ALLOC( _pointer_, _size_ ) \
FT_SET_ERROR ( MEM_Alloc ( _pointer_ , _size_ ) )
# define FT_MEM_REALLOC_ARRAY( _pointer_, _current_, _new_, _type_ ) \
FT_MEM_REALLOC ( _pointer_ , ( _current_ ) * sizeof ( _type ) , \
( _new_ ) * sizeof ( _type_ ) )
# define NEW( _pointer_ ) \
FT_SET_ERROR ( MEM_New ( _pointer_ ) )
# define REALLOC( _pointer_, _current_, _size_ ) \
FT_SET_ERROR ( MEM_Realloc ( _pointer_ , _current_ , _size_ ) )
# define ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_SET_ERROR ( MEM_Alloc ( _pointer_ , \
( _count_ ) * sizeof ( _type_ ) ) )
/**************************************************************************
*
* the following macros are variants of their FT_MEM_XXXX equivalents
* they ' re used to set an _implicit_ ' error ' variable and return TRUE
* if an error occured ( i . e . if ' error ! = 0 ' )
*/
# define NEW_ARRAY( _pointer_, _count_ ) \
FT_SET_ERROR ( MEM_New_Array ( _pointer_ , _count_ ) )
# define REALLOC_ARRAY( _pointer_, _current_, _count_, _type_ ) \
FT_SET_ERROR ( MEM_Realloc ( _pointer_ , \
( _current_ ) * sizeof ( _type_ ) , \
( _count_ ) * sizeof ( _type_ ) ) )
# define RENEW_ARRAY( _pointer_, _current_, _new_ ) \
FT_SET_ERROR ( MEM_Renew_Array ( _pointer_ , _current_ , _new_ ) )
# define FT_ALLOC( _pointer_, _size_ ) \
FT_SET_ERROR ( FT_MEM_ALLOC ( _pointer_ , _size_ ) )
# define FT_REALLOC( _pointer_, _current_, _size_ ) \
FT_SET_ERROR ( FT_MEM_REALLOC ( _pointer_ , _current_ , _size_ ) )
# define FT_FREE( _pointer_ ) \
FT_MEM_FREE ( _pointer_ )
# define FT_NEW( _pointer_ ) \
FT_SET_ERROR ( FT_MEM_NEW ( _pointer_ ) )
# define FREE( _pointer_ ) \
MEM_Free ( _pointer_ )
# define FT_RENEW_ARRAY( _pointer_, _current_, _new_ ) \
FT_SET_ERROR ( FT_MEM_RENEW_ARRAY ( _pointer_ , _current_ , _new_ ) )
# define FT_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_SET_ERROR ( FT_MEM_ALLOC ( _pointer_ , \
( _count_ ) * sizeof ( _type_ ) ) )
# define FT_NEW_ARRAY( _pointer_, _count_ ) \
FT_SET_ERROR ( FT_MEM_NEW_ARRAY ( _pointer_ , _count_ ) )
# define FT_REALLOC_ARRAY( _pointer_, _current_, _count_, _type_ ) \
FT_SET_ERROR ( FT_MEM_REALLOC ( _pointer_ , \
( _current_ ) * sizeof ( _type_ ) , \
( _count_ ) * sizeof ( _type_ ) ) )
/* */
FT_END_HEADER
# endif /* __FTMEMORY_H__ */