replaced liberal uses of "memset" by the "MEM_Set" macro call

(some platforms don't provide this ANSI function !!)

some changes to "ftsystem.c" implementations in order to use
the new memory debugger on Unix, VMS and Amiga too !!
This commit is contained in:
David Turner 2001-10-24 07:32:55 +00:00
parent 3a65746f1d
commit 5a1de37e7e
9 changed files with 134 additions and 31 deletions

View File

@ -346,6 +346,18 @@ void FreeVecPooled(APTR poolHeader, APTR memory)
}
#ifdef FT_DEBUG_MEMORY
extern FT_Int
ft_mem_debug_init( FT_Memory memory );
extern void
ft_mem_debug_done( FT_Memory memory );
#endif
/* documentation is in ftobjs.h */
FT_EXPORT_DEF( FT_Memory )
@ -360,14 +372,20 @@ void FreeVecPooled(APTR poolHeader, APTR memory)
{
// memory->user = 0;
memory->user = AsmCreatePool ( MEMF_PUBLIC, 2048, 2048, SysBase );
memory->alloc = ft_alloc;
memory->realloc = ft_realloc;
memory->free = ft_free;
if ( memory->user == NULL )
{
FreeVec ( memory );
memory = NULL;
}
else
{
memory->alloc = ft_alloc;
memory->realloc = ft_realloc;
memory->free = ft_free;
#ifdef FT_DEBUG_MEMORY
ft_mem_debug_init( memory );
#endif
}
}
return memory;
@ -379,7 +397,9 @@ void FreeVecPooled(APTR poolHeader, APTR memory)
FT_EXPORT_DEF( void )
FT_Done_Memory( FT_Memory memory )
{
// memory->free( memory, memory );
#ifdef FT_DEBUG_MEMORY
ft_mem_debug_done( memory );
#endif
AsmDeletePool( memory->user, SysBase );
FreeVec( memory );

View File

@ -271,6 +271,17 @@
}
#ifdef FT_DEBUG_MEMORY
extern FT_Int
ft_mem_debug_init( FT_Memory memory );
extern void
ft_mem_debug_done( FT_Memory memory );
#endif
/* documentation is in ftobjs.h */
FT_EXPORT_DEF( FT_Memory )
@ -281,11 +292,13 @@
memory = (FT_Memory)malloc( sizeof ( *memory ) );
if ( memory )
{
memory->user = 0;
memory->alloc = ft_alloc;
memory->realloc = ft_realloc;
memory->free = ft_free;
#ifdef FT_DEBUG_MEMORY
ft_mem_debug_init( memory );
#endif
}
return memory;
@ -297,6 +310,9 @@
FT_EXPORT_DEF( void )
FT_Done_Memory( FT_Memory memory )
{
#ifdef FT_DEBUG_MEMORY
ft_mem_debug_done( memory );
#endif
memory->free( memory, memory );
}

View File

@ -271,6 +271,17 @@
}
#ifdef FT_DEBUG_MEMORY
extern FT_Int
ft_mem_debug_init( FT_Memory memory );
extern void
ft_mem_debug_done( FT_Memory memory );
#endif
/* documentation is in ftobjs.h */
FT_EXPORT_DEF( FT_Memory )
@ -286,6 +297,9 @@
memory->alloc = ft_alloc;
memory->realloc = ft_realloc;
memory->free = ft_free;
#ifdef FT_DEBUG_MEMORY
ft_mem_debug_init( memory );
#endif
}
return memory;
@ -297,6 +311,9 @@
FT_EXPORT_DEF( void )
FT_Done_Memory( FT_Memory memory )
{
#ifdef FT_DEBUG_MEMORY
ft_mem_debug_done( memory );
#endif
memory->free( memory, memory );
}

View File

@ -816,7 +816,7 @@
segment_dir = point->out_dir;
/* clear all segment fields */
memset( segment, 0, sizeof ( *segment ) );
MEM_Set( segment, 0, sizeof ( *segment ) );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;
@ -878,7 +878,7 @@
if ( min_point )
{
/* clear all segment fields */
memset( segment, 0, sizeof ( *segment ) );
MEM_Set( segment, 0, sizeof ( *segment ) );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;
@ -894,7 +894,7 @@
if ( max_point )
{
/* clear all segment fields */
memset( segment, 0, sizeof ( *segment ) );
MEM_Set( segment, 0, sizeof ( *segment ) );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;
@ -1122,7 +1122,7 @@
edge_limit++;
/* clear all edge fields */
memset( edge, 0, sizeof ( *edge ) );
MEM_Set( edge, 0, sizeof ( *edge ) );
/* add the segment to the new edge's list */
edge->first = seg;

View File

@ -32,7 +32,6 @@
typedef struct FT_MemTableRec_
{
FT_Memory memory;
FT_ULong size;
FT_ULong nodes;
FT_MemNode* buckets;
@ -44,6 +43,12 @@
const char* file_name;
FT_Long line_no;
FT_Memory memory;
FT_Pointer memory_user;
FT_Alloc_Func alloc;
FT_Free_Func free;
FT_Realloc_Func realloc;
} FT_MemTableRec;
#define FT_MEM_SIZE_MIN 7
@ -122,6 +127,31 @@
}
static FT_Pointer
ft_mem_table_alloc( FT_MemTable table,
FT_Long size )
{
FT_Memory memory = table->memory;
FT_Pointer block;
memory->user = table->memory_user;
block = table->alloc( memory, size );
memory->user = table;
return block;
}
static void
ft_mem_table_free( FT_MemTable table,
FT_Pointer block )
{
FT_Memory memory = table->memory;
memory->user = table->memory_user;
table->free( memory, block );
memory->user = table;
}
static void
ft_mem_table_resize( FT_MemTable table )
@ -134,7 +164,7 @@
FT_MemNode* new_buckets ;
FT_ULong i;
new_buckets = malloc( new_size * sizeof(FT_MemNode) );
new_buckets = ft_mem_table_alloc( table, new_size * sizeof(FT_MemNode) );
if ( new_buckets == NULL )
return;
@ -160,7 +190,7 @@
}
if ( table->buckets )
free( table->buckets );
ft_mem_table_free( table, table->buckets );
table->buckets = new_buckets;
table->size = new_size;
@ -169,11 +199,11 @@
static FT_MemTable
ft_mem_table_new( void )
ft_mem_table_new( FT_Memory memory )
{
FT_MemTable table;
table = malloc( sizeof(*table) );
table = memory->alloc( memory, sizeof(*table) );
if ( table == NULL ) goto Exit;
memset( table, 0, sizeof(*table) );
@ -181,12 +211,20 @@
table->size = FT_MEM_SIZE_MIN;
table->nodes = 0;
table->buckets = malloc( table->size * sizeof(FT_MemNode) );
table->memory = memory;
table->memory_user = memory->user;
table->alloc = memory->alloc;
table->realloc = memory->realloc;
table->free = memory->free;
table->buckets = memory->alloc( memory, table->size * sizeof(FT_MemNode) );
if ( table->buckets )
memset( table->buckets, 0, sizeof(FT_MemNode)*table->size );
else
{
free( table );
memory->free( memory, table );
table = NULL;
}
@ -203,6 +241,7 @@
if ( table )
{
FT_Memory memory = table->memory;
FT_Long leak_count = 0;
FT_ULong leaks = 0;
@ -225,7 +264,7 @@
leak_count++;
leaks += node->size;
free( node->address );
ft_mem_table_free( table, node->address );
}
node->address = NULL;
@ -236,7 +275,7 @@
}
table->buckets[i] = 0;
}
free( table->buckets );
ft_mem_table_free( table, table->buckets );
table->buckets = NULL;
table->size = 0;
@ -311,7 +350,7 @@
}
/* we need to create a new node in this table */
node = malloc( sizeof(*node) );
node = ft_mem_table_alloc( table, sizeof(*node) );
if ( node == NULL )
ft_mem_debug_panic( "not enough memory to run memory tests" );
@ -378,7 +417,7 @@
if ( size <= 0 )
ft_mem_debug_panic( "negative block size allocation (%ld)", size );
block = malloc( size );
block = ft_mem_table_alloc( table, size );
if ( block )
ft_mem_table_set( table, block, (FT_ULong)size );
@ -454,7 +493,7 @@
if ( getenv( "FT_DEBUG_MEMORY") )
{
table = ft_mem_table_new();
table = ft_mem_table_new( memory );
if ( table )
{
memory->user = table;
@ -475,9 +514,12 @@
if ( table )
{
memory->free = table->free;
memory->realloc = table->realloc;
memory->alloc = table->alloc;
ft_mem_table_destroy( table );
memory->user = NULL;
memory->free = (FT_Free_Func) free;
}
}

View File

@ -276,14 +276,14 @@
memory = (FT_Memory)malloc( sizeof ( *memory ) );
if ( memory )
#ifdef FT_DEBUG_MEMORY
if ( !ft_mem_debug_init( memory ) )
#endif
{
memory->user = 0;
memory->alloc = ft_alloc;
memory->realloc = ft_realloc;
memory->free = ft_free;
#ifdef FT_DEBUG_MEMORY
ft_mem_debug_init( memory );
#endif
}
return memory;

View File

@ -105,6 +105,10 @@
/*************************************************************************/
/*************************************************************************/
#ifdef MEM_Set
# define MEM_Set(d,s,c) memset(d,s,c)
#endif
/* define DEBUG_RASTER if you want to compile a debugging version */
#define xxxDEBUG_RASTER
@ -3141,7 +3145,7 @@
*araster = &the_raster;
memset( &the_raster, sizeof ( the_raster ), 0 );
MEM_Set( &the_raster, sizeof ( the_raster ), 0 );
ft_black_init( &the_raster );
return 0;

View File

@ -140,6 +140,10 @@
#endif /* _STANDALONE_ */
#ifndef MEM_Set
# define MEM_Set(d,s,c) memset(d,s,c)
#endif
/* define this to dump debugging information */
#define xxxDEBUG_GRAYS
@ -1228,7 +1232,7 @@
{
if ( spans->coverage )
#if 1
memset( p + spans->x, (unsigned char)spans->coverage, spans->len );
MEM_Set( p + spans->x, (unsigned char)spans->coverage, spans->len );
#else /* 1 */
{
q = p + spans->x;
@ -1968,7 +1972,7 @@
*araster = (FT_Raster)&the_raster;
memset( &the_raster, 0, sizeof ( the_raster ) );
MEM_Set( &the_raster, 0, sizeof ( the_raster ) );
return 0;
}