summaryrefslogtreecommitdiffstats
path: root/src/base/ftdbgmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/ftdbgmem.c')
-rw-r--r--src/base/ftdbgmem.c126
1 files changed, 66 insertions, 60 deletions
diff --git a/src/base/ftdbgmem.c b/src/base/ftdbgmem.c
index 6fb86fe..6f20313 100644
--- a/src/base/ftdbgmem.c
+++ b/src/base/ftdbgmem.c
@@ -4,7 +4,7 @@
/* */
/* Memory debugger (body). */
/* */
-/* Copyright 2001-2006, 2009, 2013 by */
+/* Copyright 2001-2015 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -35,7 +35,7 @@
#include FT_CONFIG_STANDARD_LIBRARY_H
- FT_BASE_DEF( const char* ) _ft_debug_file = 0;
+ FT_BASE_DEF( const char* ) _ft_debug_file = NULL;
FT_BASE_DEF( long ) _ft_debug_lineno = 0;
extern void
@@ -47,7 +47,7 @@
typedef struct FT_MemTableRec_* FT_MemTable;
-#define FT_MEM_VAL( addr ) ((FT_PtrDist)(FT_Pointer)( addr ))
+#define FT_MEM_VAL( addr ) ( (FT_PtrDist)(FT_Pointer)( addr ) )
/*
* This structure holds statistics for a single allocation/release
@@ -76,7 +76,7 @@
/*
- * We don't need a resizable array for the memory sources, because
+ * We don't need a resizable array for the memory sources because
* their number is pretty limited within FreeType.
*/
#define FT_MEM_SOURCE_BUCKETS 128
@@ -85,8 +85,8 @@
* This structure holds information related to a single allocated
* memory block. If KEEPALIVE is defined, blocks that are freed by
* FreeType are never released to the system. Instead, their `size'
- * field is set to -size. This is mainly useful to detect double frees,
- * at the price of large memory footprint during execution.
+ * field is set to `-size'. This is mainly useful to detect double
+ * frees, at the price of a large memory footprint during execution.
*/
typedef struct FT_MemNodeRec_
{
@@ -111,20 +111,20 @@
*/
typedef struct FT_MemTableRec_
{
- FT_ULong size;
- FT_ULong nodes;
+ FT_Long size;
+ FT_Long nodes;
FT_MemNode* buckets;
- FT_ULong alloc_total;
- FT_ULong alloc_current;
- FT_ULong alloc_max;
- FT_ULong alloc_count;
+ FT_Long alloc_total;
+ FT_Long alloc_current;
+ FT_Long alloc_max;
+ FT_Long alloc_count;
FT_Bool bound_total;
- FT_ULong alloc_total_max;
+ FT_Long alloc_total_max;
FT_Bool bound_count;
- FT_ULong alloc_count_max;
+ FT_Long alloc_count_max;
FT_MemSource sources[FT_MEM_SOURCE_BUCKETS];
@@ -142,14 +142,14 @@
#define FT_MEM_SIZE_MIN 7
#define FT_MEM_SIZE_MAX 13845163
-#define FT_FILENAME( x ) ((x) ? (x) : "unknown file")
+#define FT_FILENAME( x ) ( (x) ? (x) : "unknown file" )
/*
* Prime numbers are ugly to handle. It would be better to implement
* L-Hashing, which is 10% faster and doesn't require divisions.
*/
- static const FT_UInt ft_mem_primes[] =
+ static const FT_Int ft_mem_primes[] =
{
7,
11,
@@ -189,10 +189,10 @@
};
- static FT_ULong
- ft_mem_closest_prime( FT_ULong num )
+ static FT_Long
+ ft_mem_closest_prime( FT_Long num )
{
- FT_UInt i;
+ size_t i;
for ( i = 0;
@@ -204,7 +204,7 @@
}
- extern void
+ static void
ft_mem_debug_panic( const char* fmt,
... )
{
@@ -254,19 +254,20 @@
static void
ft_mem_table_resize( FT_MemTable table )
{
- FT_ULong new_size;
+ FT_Long new_size;
new_size = ft_mem_closest_prime( table->nodes );
if ( new_size != table->size )
{
FT_MemNode* new_buckets;
- FT_ULong i;
+ FT_Long i;
new_buckets = (FT_MemNode *)
- ft_mem_table_alloc( table,
- new_size * sizeof ( FT_MemNode ) );
+ ft_mem_table_alloc(
+ table,
+ new_size * (FT_Long)sizeof ( FT_MemNode ) );
if ( new_buckets == NULL )
return;
@@ -282,7 +283,7 @@
while ( node )
{
next = node->link;
- hash = FT_MEM_VAL( node->address ) % new_size;
+ hash = FT_MEM_VAL( node->address ) % (FT_PtrDist)new_size;
pnode = new_buckets + hash;
node->link = pnode[0];
@@ -325,8 +326,9 @@
table->free = memory->free;
table->buckets = (FT_MemNode *)
- memory->alloc( memory,
- table->size * sizeof ( FT_MemNode ) );
+ memory->alloc(
+ memory,
+ table->size * (FT_Long)sizeof ( FT_MemNode ) );
if ( table->buckets )
FT_ARRAY_ZERO( table->buckets, table->size );
else
@@ -343,9 +345,9 @@
static void
ft_mem_table_destroy( FT_MemTable table )
{
- FT_ULong i;
- FT_Long leak_count = 0;
- FT_ULong leaks = 0;
+ FT_Long i;
+ FT_Long leak_count = 0;
+ FT_Long leaks = 0;
FT_DumpMemory( table->memory );
@@ -359,7 +361,7 @@
while ( node )
{
next = node->link;
- node->link = 0;
+ node->link = NULL;
if ( node->size > 0 )
{
@@ -381,7 +383,7 @@
ft_mem_table_free( table, node );
node = next;
}
- table->buckets[i] = 0;
+ table->buckets[i] = NULL;
}
ft_mem_table_free( table, table->buckets );
@@ -430,7 +432,7 @@
hash = FT_MEM_VAL( address );
- pnode = table->buckets + ( hash % table->size );
+ pnode = table->buckets + ( hash % (FT_PtrDist)table->size );
for (;;)
{
@@ -466,8 +468,8 @@
if ( node == NULL )
break;
- if ( node->file_name == _ft_debug_file &&
- node->line_no == _ft_debug_lineno )
+ if ( node->file_name == _ft_debug_file &&
+ node->line_no == _ft_debug_lineno )
goto Exit;
pnode = &node->link;
@@ -485,11 +487,11 @@
node->max_blocks = 0;
node->all_blocks = 0;
- node->cur_size = 0;
- node->max_size = 0;
- node->all_size = 0;
+ node->cur_size = 0;
+ node->max_size = 0;
+ node->all_size = 0;
- node->cur_max = 0;
+ node->cur_max = 0;
node->link = NULL;
node->hash = hash;
@@ -503,7 +505,7 @@
static void
ft_mem_table_set( FT_MemTable table,
FT_Byte* address,
- FT_ULong size,
+ FT_Long size,
FT_Long delta )
{
FT_MemNode *pnode, node;
@@ -558,7 +560,7 @@
source->max_blocks = source->cur_blocks;
}
- if ( size > (FT_ULong)source->cur_max )
+ if ( size > source->cur_max )
source->cur_max = size;
if ( delta != 0 )
@@ -671,7 +673,7 @@
}
- extern FT_Pointer
+ static FT_Pointer
ft_mem_debug_alloc( FT_Memory memory,
FT_Long size )
{
@@ -688,14 +690,14 @@
return NULL;
/* return NULL if this allocation would overflow the maximum heap size */
- if ( table->bound_total &&
- table->alloc_total_max - table->alloc_current > (FT_ULong)size )
+ if ( table->bound_total &&
+ table->alloc_total_max - table->alloc_current > size )
return NULL;
block = (FT_Byte *)ft_mem_table_alloc( table, size );
if ( block )
{
- ft_mem_table_set( table, block, (FT_ULong)size, 0 );
+ ft_mem_table_set( table, block, size, 0 );
table->alloc_count++;
}
@@ -707,7 +709,7 @@
}
- extern void
+ static void
ft_mem_debug_free( FT_Memory memory,
FT_Pointer block )
{
@@ -731,7 +733,7 @@
}
- extern FT_Pointer
+ static FT_Pointer
ft_mem_debug_realloc( FT_Memory memory,
FT_Long cur_size,
FT_Long new_size,
@@ -787,21 +789,22 @@
table->alloc_count >= table->alloc_count_max )
return NULL;
- delta = (FT_Long)( new_size - cur_size );
+ delta = new_size - cur_size;
/* return NULL if this allocation would overflow the maximum heap size */
- if ( delta > 0 &&
- table->bound_total &&
- table->alloc_current + (FT_ULong)delta > table->alloc_total_max )
+ if ( delta > 0 &&
+ table->bound_total &&
+ table->alloc_current + delta > table->alloc_total_max )
return NULL;
- new_block = (FT_Byte *)ft_mem_table_alloc( table, new_size );
+ new_block = (FT_Pointer)ft_mem_table_alloc( table, new_size );
if ( new_block == NULL )
return NULL;
ft_mem_table_set( table, (FT_Byte*)new_block, new_size, delta );
- ft_memcpy( new_block, block, cur_size < new_size ? cur_size : new_size );
+ ft_memcpy( new_block, block, cur_size < new_size ? (size_t)cur_size
+ : (size_t)new_size );
ft_mem_table_remove( table, (FT_Byte*)block, delta );
@@ -844,7 +847,7 @@
if ( total_max > 0 )
{
table->bound_total = 1;
- table->alloc_total_max = (FT_ULong)total_max;
+ table->alloc_total_max = total_max;
}
}
@@ -857,7 +860,7 @@
if ( total_count > 0 )
{
table->bound_count = 1;
- table->alloc_count_max = (FT_ULong)total_count;
+ table->alloc_count_max = total_count;
}
}
@@ -896,7 +899,6 @@
}
-
static int
ft_mem_source_compare( const void* p1,
const void* p2 )
@@ -925,7 +927,7 @@
FT_MemSource* bucket = table->sources;
FT_MemSource* limit = bucket + FT_MEM_SOURCE_BUCKETS;
FT_MemSource* sources;
- FT_UInt nn, count;
+ FT_Int nn, count;
const char* fmt;
@@ -939,8 +941,9 @@
count++;
}
- sources = (FT_MemSource*)ft_mem_table_alloc(
- table, sizeof ( *sources ) * count );
+ sources = (FT_MemSource*)
+ ft_mem_table_alloc(
+ table, count * (FT_Long)sizeof ( *sources ) );
count = 0;
for ( bucket = table->sources; bucket < limit; bucket++ )
@@ -952,7 +955,10 @@
sources[count++] = source;
}
- ft_qsort( sources, count, sizeof ( *sources ), ft_mem_source_compare );
+ ft_qsort( sources,
+ (size_t)count,
+ sizeof ( *sources ),
+ ft_mem_source_compare );
printf( "FreeType Memory Dump: "
"current=%ld max=%ld total=%ld count=%ld\n",