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:
parent
3a65746f1d
commit
5a1de37e7e
|
@ -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 */
|
/* documentation is in ftobjs.h */
|
||||||
|
|
||||||
FT_EXPORT_DEF( FT_Memory )
|
FT_EXPORT_DEF( FT_Memory )
|
||||||
|
@ -360,14 +372,20 @@ void FreeVecPooled(APTR poolHeader, APTR memory)
|
||||||
{
|
{
|
||||||
// memory->user = 0;
|
// memory->user = 0;
|
||||||
memory->user = AsmCreatePool ( MEMF_PUBLIC, 2048, 2048, SysBase );
|
memory->user = AsmCreatePool ( MEMF_PUBLIC, 2048, 2048, SysBase );
|
||||||
memory->alloc = ft_alloc;
|
|
||||||
memory->realloc = ft_realloc;
|
|
||||||
memory->free = ft_free;
|
|
||||||
if ( memory->user == NULL )
|
if ( memory->user == NULL )
|
||||||
{
|
{
|
||||||
FreeVec ( memory );
|
FreeVec ( memory );
|
||||||
memory = NULL;
|
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;
|
return memory;
|
||||||
|
@ -379,7 +397,9 @@ void FreeVecPooled(APTR poolHeader, APTR memory)
|
||||||
FT_EXPORT_DEF( void )
|
FT_EXPORT_DEF( void )
|
||||||
FT_Done_Memory( FT_Memory memory )
|
FT_Done_Memory( FT_Memory memory )
|
||||||
{
|
{
|
||||||
// memory->free( memory, memory );
|
#ifdef FT_DEBUG_MEMORY
|
||||||
|
ft_mem_debug_done( memory );
|
||||||
|
#endif
|
||||||
|
|
||||||
AsmDeletePool( memory->user, SysBase );
|
AsmDeletePool( memory->user, SysBase );
|
||||||
FreeVec( memory );
|
FreeVec( memory );
|
||||||
|
|
|
@ -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 */
|
/* documentation is in ftobjs.h */
|
||||||
|
|
||||||
FT_EXPORT_DEF( FT_Memory )
|
FT_EXPORT_DEF( FT_Memory )
|
||||||
|
@ -281,11 +292,13 @@
|
||||||
|
|
||||||
memory = (FT_Memory)malloc( sizeof ( *memory ) );
|
memory = (FT_Memory)malloc( sizeof ( *memory ) );
|
||||||
if ( memory )
|
if ( memory )
|
||||||
{
|
|
||||||
memory->user = 0;
|
memory->user = 0;
|
||||||
memory->alloc = ft_alloc;
|
memory->alloc = ft_alloc;
|
||||||
memory->realloc = ft_realloc;
|
memory->realloc = ft_realloc;
|
||||||
memory->free = ft_free;
|
memory->free = ft_free;
|
||||||
|
#ifdef FT_DEBUG_MEMORY
|
||||||
|
ft_mem_debug_init( memory );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return memory;
|
return memory;
|
||||||
|
@ -297,6 +310,9 @@
|
||||||
FT_EXPORT_DEF( void )
|
FT_EXPORT_DEF( void )
|
||||||
FT_Done_Memory( FT_Memory memory )
|
FT_Done_Memory( FT_Memory memory )
|
||||||
{
|
{
|
||||||
|
#ifdef FT_DEBUG_MEMORY
|
||||||
|
ft_mem_debug_done( memory );
|
||||||
|
#endif
|
||||||
memory->free( memory, memory );
|
memory->free( memory, memory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
/* documentation is in ftobjs.h */
|
||||||
|
|
||||||
FT_EXPORT_DEF( FT_Memory )
|
FT_EXPORT_DEF( FT_Memory )
|
||||||
|
@ -286,6 +297,9 @@
|
||||||
memory->alloc = ft_alloc;
|
memory->alloc = ft_alloc;
|
||||||
memory->realloc = ft_realloc;
|
memory->realloc = ft_realloc;
|
||||||
memory->free = ft_free;
|
memory->free = ft_free;
|
||||||
|
#ifdef FT_DEBUG_MEMORY
|
||||||
|
ft_mem_debug_init( memory );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return memory;
|
return memory;
|
||||||
|
@ -297,6 +311,9 @@
|
||||||
FT_EXPORT_DEF( void )
|
FT_EXPORT_DEF( void )
|
||||||
FT_Done_Memory( FT_Memory memory )
|
FT_Done_Memory( FT_Memory memory )
|
||||||
{
|
{
|
||||||
|
#ifdef FT_DEBUG_MEMORY
|
||||||
|
ft_mem_debug_done( memory );
|
||||||
|
#endif
|
||||||
memory->free( memory, memory );
|
memory->free( memory, memory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,7 @@ FT_BEGIN_HEADER
|
||||||
/* available on all platforms we know of. */
|
/* available on all platforms we know of. */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define MEM_Set( dest, byte, count ) memset( dest, byte, count )
|
#define MEM_Set( dest, byte, count ) memset( dest, byte, count )
|
||||||
|
|
||||||
#define MEM_Copy( dest, source, count ) memcpy( dest, source, count )
|
#define MEM_Copy( dest, source, count ) memcpy( dest, source, count )
|
||||||
|
|
||||||
|
|
|
@ -816,7 +816,7 @@
|
||||||
segment_dir = point->out_dir;
|
segment_dir = point->out_dir;
|
||||||
|
|
||||||
/* clear all segment fields */
|
/* clear all segment fields */
|
||||||
memset( segment, 0, sizeof ( *segment ) );
|
MEM_Set( segment, 0, sizeof ( *segment ) );
|
||||||
|
|
||||||
segment->dir = segment_dir;
|
segment->dir = segment_dir;
|
||||||
segment->flags = ah_edge_normal;
|
segment->flags = ah_edge_normal;
|
||||||
|
@ -878,7 +878,7 @@
|
||||||
if ( min_point )
|
if ( min_point )
|
||||||
{
|
{
|
||||||
/* clear all segment fields */
|
/* clear all segment fields */
|
||||||
memset( segment, 0, sizeof ( *segment ) );
|
MEM_Set( segment, 0, sizeof ( *segment ) );
|
||||||
|
|
||||||
segment->dir = segment_dir;
|
segment->dir = segment_dir;
|
||||||
segment->flags = ah_edge_normal;
|
segment->flags = ah_edge_normal;
|
||||||
|
@ -894,7 +894,7 @@
|
||||||
if ( max_point )
|
if ( max_point )
|
||||||
{
|
{
|
||||||
/* clear all segment fields */
|
/* clear all segment fields */
|
||||||
memset( segment, 0, sizeof ( *segment ) );
|
MEM_Set( segment, 0, sizeof ( *segment ) );
|
||||||
|
|
||||||
segment->dir = segment_dir;
|
segment->dir = segment_dir;
|
||||||
segment->flags = ah_edge_normal;
|
segment->flags = ah_edge_normal;
|
||||||
|
@ -1122,7 +1122,7 @@
|
||||||
edge_limit++;
|
edge_limit++;
|
||||||
|
|
||||||
/* clear all edge fields */
|
/* clear all edge fields */
|
||||||
memset( edge, 0, sizeof ( *edge ) );
|
MEM_Set( edge, 0, sizeof ( *edge ) );
|
||||||
|
|
||||||
/* add the segment to the new edge's list */
|
/* add the segment to the new edge's list */
|
||||||
edge->first = seg;
|
edge->first = seg;
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
typedef struct FT_MemTableRec_
|
typedef struct FT_MemTableRec_
|
||||||
{
|
{
|
||||||
FT_Memory memory;
|
|
||||||
FT_ULong size;
|
FT_ULong size;
|
||||||
FT_ULong nodes;
|
FT_ULong nodes;
|
||||||
FT_MemNode* buckets;
|
FT_MemNode* buckets;
|
||||||
|
@ -43,6 +42,12 @@
|
||||||
|
|
||||||
const char* file_name;
|
const char* file_name;
|
||||||
FT_Long line_no;
|
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;
|
} FT_MemTableRec;
|
||||||
|
|
||||||
|
@ -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
|
static void
|
||||||
ft_mem_table_resize( FT_MemTable table )
|
ft_mem_table_resize( FT_MemTable table )
|
||||||
|
@ -134,7 +164,7 @@
|
||||||
FT_MemNode* new_buckets ;
|
FT_MemNode* new_buckets ;
|
||||||
FT_ULong i;
|
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 )
|
if ( new_buckets == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -160,7 +190,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( table->buckets )
|
if ( table->buckets )
|
||||||
free( table->buckets );
|
ft_mem_table_free( table, table->buckets );
|
||||||
|
|
||||||
table->buckets = new_buckets;
|
table->buckets = new_buckets;
|
||||||
table->size = new_size;
|
table->size = new_size;
|
||||||
|
@ -169,24 +199,32 @@
|
||||||
|
|
||||||
|
|
||||||
static FT_MemTable
|
static FT_MemTable
|
||||||
ft_mem_table_new( void )
|
ft_mem_table_new( FT_Memory memory )
|
||||||
{
|
{
|
||||||
FT_MemTable table;
|
FT_MemTable table;
|
||||||
|
|
||||||
table = malloc( sizeof(*table) );
|
table = memory->alloc( memory, sizeof(*table) );
|
||||||
if ( table == NULL ) goto Exit;
|
if ( table == NULL ) goto Exit;
|
||||||
|
|
||||||
memset( table, 0, sizeof(*table) );
|
memset( table, 0, sizeof(*table) );
|
||||||
|
|
||||||
table->size = FT_MEM_SIZE_MIN;
|
table->size = FT_MEM_SIZE_MIN;
|
||||||
table->nodes = 0;
|
table->nodes = 0;
|
||||||
|
|
||||||
|
table->memory = memory;
|
||||||
|
|
||||||
table->buckets = malloc( table->size * sizeof(FT_MemNode) );
|
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 )
|
if ( table->buckets )
|
||||||
memset( table->buckets, 0, sizeof(FT_MemNode)*table->size );
|
memset( table->buckets, 0, sizeof(FT_MemNode)*table->size );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
free( table );
|
memory->free( memory, table );
|
||||||
table = NULL;
|
table = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,8 +241,9 @@
|
||||||
|
|
||||||
if ( table )
|
if ( table )
|
||||||
{
|
{
|
||||||
FT_Long leak_count = 0;
|
FT_Memory memory = table->memory;
|
||||||
FT_ULong leaks = 0;
|
FT_Long leak_count = 0;
|
||||||
|
FT_ULong leaks = 0;
|
||||||
|
|
||||||
for ( i = 0; i < table->size; i++ )
|
for ( i = 0; i < table->size; i++ )
|
||||||
{
|
{
|
||||||
|
@ -225,7 +264,7 @@
|
||||||
leak_count++;
|
leak_count++;
|
||||||
leaks += node->size;
|
leaks += node->size;
|
||||||
|
|
||||||
free( node->address );
|
ft_mem_table_free( table, node->address );
|
||||||
}
|
}
|
||||||
|
|
||||||
node->address = NULL;
|
node->address = NULL;
|
||||||
|
@ -236,7 +275,7 @@
|
||||||
}
|
}
|
||||||
table->buckets[i] = 0;
|
table->buckets[i] = 0;
|
||||||
}
|
}
|
||||||
free( table->buckets );
|
ft_mem_table_free( table, table->buckets );
|
||||||
table->buckets = NULL;
|
table->buckets = NULL;
|
||||||
|
|
||||||
table->size = 0;
|
table->size = 0;
|
||||||
|
@ -311,7 +350,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we need to create a new node in this table */
|
/* 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 )
|
if ( node == NULL )
|
||||||
ft_mem_debug_panic( "not enough memory to run memory tests" );
|
ft_mem_debug_panic( "not enough memory to run memory tests" );
|
||||||
|
|
||||||
|
@ -378,7 +417,7 @@
|
||||||
if ( size <= 0 )
|
if ( size <= 0 )
|
||||||
ft_mem_debug_panic( "negative block size allocation (%ld)", size );
|
ft_mem_debug_panic( "negative block size allocation (%ld)", size );
|
||||||
|
|
||||||
block = malloc( size );
|
block = ft_mem_table_alloc( table, size );
|
||||||
if ( block )
|
if ( block )
|
||||||
ft_mem_table_set( table, block, (FT_ULong)size );
|
ft_mem_table_set( table, block, (FT_ULong)size );
|
||||||
|
|
||||||
|
@ -454,7 +493,7 @@
|
||||||
|
|
||||||
if ( getenv( "FT_DEBUG_MEMORY") )
|
if ( getenv( "FT_DEBUG_MEMORY") )
|
||||||
{
|
{
|
||||||
table = ft_mem_table_new();
|
table = ft_mem_table_new( memory );
|
||||||
if ( table )
|
if ( table )
|
||||||
{
|
{
|
||||||
memory->user = table;
|
memory->user = table;
|
||||||
|
@ -475,9 +514,12 @@
|
||||||
|
|
||||||
if ( table )
|
if ( table )
|
||||||
{
|
{
|
||||||
|
memory->free = table->free;
|
||||||
|
memory->realloc = table->realloc;
|
||||||
|
memory->alloc = table->alloc;
|
||||||
|
|
||||||
ft_mem_table_destroy( table );
|
ft_mem_table_destroy( table );
|
||||||
memory->user = NULL;
|
memory->user = NULL;
|
||||||
memory->free = (FT_Free_Func) free;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,14 +276,14 @@
|
||||||
|
|
||||||
memory = (FT_Memory)malloc( sizeof ( *memory ) );
|
memory = (FT_Memory)malloc( sizeof ( *memory ) );
|
||||||
if ( memory )
|
if ( memory )
|
||||||
#ifdef FT_DEBUG_MEMORY
|
|
||||||
if ( !ft_mem_debug_init( memory ) )
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
memory->user = 0;
|
memory->user = 0;
|
||||||
memory->alloc = ft_alloc;
|
memory->alloc = ft_alloc;
|
||||||
memory->realloc = ft_realloc;
|
memory->realloc = ft_realloc;
|
||||||
memory->free = ft_free;
|
memory->free = ft_free;
|
||||||
|
#ifdef FT_DEBUG_MEMORY
|
||||||
|
ft_mem_debug_init( memory );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return memory;
|
return memory;
|
||||||
|
|
|
@ -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 DEBUG_RASTER if you want to compile a debugging version */
|
||||||
#define xxxDEBUG_RASTER
|
#define xxxDEBUG_RASTER
|
||||||
|
|
||||||
|
@ -3141,7 +3145,7 @@
|
||||||
|
|
||||||
|
|
||||||
*araster = &the_raster;
|
*araster = &the_raster;
|
||||||
memset( &the_raster, sizeof ( the_raster ), 0 );
|
MEM_Set( &the_raster, sizeof ( the_raster ), 0 );
|
||||||
ft_black_init( &the_raster );
|
ft_black_init( &the_raster );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -140,6 +140,10 @@
|
||||||
#endif /* _STANDALONE_ */
|
#endif /* _STANDALONE_ */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MEM_Set
|
||||||
|
# define MEM_Set(d,s,c) memset(d,s,c)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* define this to dump debugging information */
|
/* define this to dump debugging information */
|
||||||
#define xxxDEBUG_GRAYS
|
#define xxxDEBUG_GRAYS
|
||||||
|
|
||||||
|
@ -1228,7 +1232,7 @@
|
||||||
{
|
{
|
||||||
if ( spans->coverage )
|
if ( spans->coverage )
|
||||||
#if 1
|
#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 */
|
#else /* 1 */
|
||||||
{
|
{
|
||||||
q = p + spans->x;
|
q = p + spans->x;
|
||||||
|
@ -1968,7 +1972,7 @@
|
||||||
|
|
||||||
|
|
||||||
*araster = (FT_Raster)&the_raster;
|
*araster = (FT_Raster)&the_raster;
|
||||||
memset( &the_raster, 0, sizeof ( the_raster ) );
|
MEM_Set( &the_raster, 0, sizeof ( the_raster ) );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue