20#include FT_CONFIG_CONFIG_H
36#include FT_CONFIG_STANDARD_LIBRARY_H
45 typedef struct FT_MemSourceRec_* FT_MemSource;
46 typedef struct FT_MemNodeRec_* FT_MemNode;
47 typedef struct FT_MemTableRec_* FT_MemTable;
50#define FT_MEM_VAL( addr ) ( (FT_PtrDist)(FT_Pointer)( addr ) )
57 typedef struct FT_MemSourceRec_
82#define FT_MEM_SOURCE_BUCKETS 128
91 typedef struct FT_MemNodeRec_
99 const char* free_file_name;
112 typedef struct FT_MemTableRec_
129 FT_MemSource
sources[FT_MEM_SOURCE_BUCKETS];
142#define FT_MEM_SIZE_MIN 7
143#define FT_MEM_SIZE_MAX 13845163
145#define FT_FILENAME( x ) ( (x) ? (x) : "unknown file" )
152 static const FT_Int ft_mem_primes[] =
199 i <
sizeof ( ft_mem_primes ) /
sizeof ( ft_mem_primes[0] );
i++ )
200 if ( ft_mem_primes[
i] >
num )
201 return ft_mem_primes[
i];
203 return FT_MEM_SIZE_MAX;
208 ft_mem_debug_panic(
const char*
fmt,
214 printf(
"FreeType.Debug: " );
226 ft_mem_table_alloc( FT_MemTable
table,
242 ft_mem_table_free( FT_MemTable
table,
255 ft_mem_table_resize( FT_MemTable
table )
263 FT_MemNode* new_buckets;
267 new_buckets = (FT_MemNode *)
287 pnode = new_buckets +
hash;
289 node->link = pnode[0];
296 if (
table->buckets )
299 table->buckets = new_buckets;
317 table->size = FT_MEM_SIZE_MIN;
328 table->buckets = (FT_MemNode *)
332 if (
table->buckets )
346 ft_mem_table_destroy( FT_MemTable
table )
353 FT_DumpMemory(
table->memory );
366 if (
node->size > 0 )
369 "leaked memory block at address %p, size %8ld in (%s:%ld)\n",
370 (
void*)
node->address,
372 FT_FILENAME(
node->source->file_name ),
373 node->source->line_no );
378 ft_mem_table_free(
table,
node->address );
397 for (
i = 0;
i < FT_MEM_SOURCE_BUCKETS;
i++ )
411 printf(
"FreeType: total memory allocations = %ld\n",
412 table->alloc_total );
413 printf(
"FreeType: maximum memory footprint = %ld\n",
418 if ( leak_count > 0 )
420 "FreeType: %ld bytes of memory leaked in %ld blocks\n",
423 printf(
"FreeType: no memory leaks detected\n" );
428 ft_mem_table_get_nodep( FT_MemTable
table,
432 FT_MemNode *pnode,
node;
454 ft_mem_table_get_source( FT_MemTable
table )
457 FT_MemSource
node, *pnode;
463 (FT_UInt32)( 5 * _ft_debug_lineno );
464 pnode = &
table->sources[
hash % FT_MEM_SOURCE_BUCKETS];
472 if (
node->file_name == _ft_debug_file &&
473 node->line_no == _ft_debug_lineno )
479 node = (FT_MemSource)ft_mem_table_alloc(
table,
sizeof ( *
node ) );
482 "not enough memory to perform memory debugging\n" );
484 node->file_name = _ft_debug_file;
485 node->line_no = _ft_debug_lineno;
487 node->cur_blocks = 0;
488 node->max_blocks = 0;
489 node->all_blocks = 0;
507 ft_mem_table_set( FT_MemTable
table,
512 FT_MemNode *pnode,
node;
524 if (
node->size < 0 )
530 "memory heap corrupted (allocating freed block)" );
537 "memory heap corrupted (re-allocating allocated block at"
538 " %p, of size %ld)\n"
539 "org=%s:%d new=%s:%d\n",
541 FT_FILENAME(
node->source->file_name ),
node->source->line_no,
542 FT_FILENAME( _ft_debug_file ), _ft_debug_lineno );
547 node = (FT_MemNode)ft_mem_table_alloc(
table,
sizeof ( *
node ) );
549 ft_mem_debug_panic(
"not enough memory to run memory tests" );
570 source->cur_size += delta;
571 table->alloc_current += delta;
586 node->free_line_no = 0;
588 node->link = pnode[0];
595 if (
table->alloc_current >
table->alloc_max )
600 ft_mem_table_resize(
table );
606 ft_mem_table_remove( FT_MemTable
table,
612 FT_MemNode *pnode,
node;
622 if (
node->size < 0 )
624 "freeing memory block at %p more than once\n"
626 " Block was allocated at (%s:%ld)\n"
627 " and released at (%s:%ld).",
629 FT_FILENAME( _ft_debug_file ), _ft_debug_lineno,
630 FT_FILENAME(
node->source->file_name ),
node->source->line_no,
631 FT_FILENAME(
node->free_file_name ),
node->free_line_no );
646 if (
table->keep_alive )
651 node->free_file_name = _ft_debug_file;
652 node->free_line_no = _ft_debug_lineno;
667 ft_mem_table_resize(
table );
672 "trying to free unknown block at %p in (%s:%ld)\n",
674 FT_FILENAME( _ft_debug_file ), _ft_debug_lineno );
688 ft_mem_debug_panic(
"negative block size allocation (%ld)",
size );
691 if (
table->bound_count &&
692 table->alloc_count >=
table->alloc_count_max )
696 if (
table->bound_total &&
705 table->alloc_count++;
708 _ft_debug_file =
"<unknown>";
709 _ft_debug_lineno = 0;
723 ft_mem_debug_panic(
"trying to free NULL in (%s:%ld)",
724 FT_FILENAME( _ft_debug_file ),
729 if ( !
table->keep_alive )
732 table->alloc_count--;
734 _ft_debug_file =
"<unknown>";
735 _ft_debug_lineno = 0;
746 FT_MemNode
node, *pnode;
750 const char*
file_name = FT_FILENAME( _ft_debug_file );
751 FT_Long line_no = _ft_debug_lineno;
760 if ( !
block || !cur_size )
761 ft_mem_debug_panic(
"trying to reallocate NULL in (%s:%ld)",
769 "trying to reallocate %p to size 0 (current is %ld) in (%s:%ld)",
777 "trying to reallocate unknown block at %p in (%s:%ld)",
780 if (
node->size <= 0 )
782 "trying to reallocate freed block at %p in (%s:%ld)",
785 if (
node->size != cur_size )
786 ft_mem_debug_panic(
"invalid ft_realloc request for %p. cur_size is "
787 "%ld instead of %ld in (%s:%ld)",
791 if (
table->bound_count &&
792 table->alloc_count >=
table->alloc_count_max )
799 table->bound_total &&
800 table->alloc_current + delta >
table->alloc_total_max )
814 _ft_debug_file =
"<unknown>";
815 _ft_debug_lineno = 0;
817 if ( !
table->keep_alive )
840 memory->alloc = ft_mem_debug_alloc;
841 memory->realloc = ft_mem_debug_realloc;
842 memory->free = ft_mem_debug_free;
852 table->bound_total = 1;
853 table->alloc_total_max = total_max;
863 if ( total_count > 0 )
865 table->bound_count = 1;
866 table->alloc_count_max = total_count;
876 if ( keep_alive > 0 )
877 table->keep_alive = 1;
899 ft_mem_table_destroy(
table );
906 ft_mem_source_compare(
const void* p1,
909 FT_MemSource
s1 = *(FT_MemSource*)p1;
910 FT_MemSource
s2 = *(FT_MemSource*)p2;
913 if (
s2->max_size >
s1->max_size )
915 else if (
s2->max_size <
s1->max_size )
930 FT_MemSource* bucket =
table->sources;
931 FT_MemSource*
limit = bucket + FT_MEM_SOURCE_BUCKETS;
938 for ( ; bucket <
limit; bucket++ )
940 FT_MemSource
source = *bucket;
952 for ( bucket =
table->sources; bucket <
limit; bucket++ )
954 FT_MemSource
source = *bucket;
964 ft_mem_source_compare );
966 printf(
"FreeType Memory Dump: "
967 "current=%ld max=%ld total=%ld count=%ld\n",
970 printf(
" block block sizes sizes sizes source\n" );
971 printf(
" count high sum highsum max location\n" );
972 printf(
"-------------------------------------------------\n" );
974 fmt =
"%6ld %6ld %8ld %8ld %8ld %s:%d\n";
976 for ( nn = 0; nn <
count; nn++ )
984 FT_FILENAME(
source->file_name ),
987 printf(
"------------------------------------------------\n" );
int CDECL vprintf(const char *format, va_list valist)
#define FT_ARRAY_ZERO(dest, count)
#define FT_MEM_SET(dest, byte, count)
void *(* FT_Alloc_Func)(FT_Memory memory, long size)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
void *(* FT_Realloc_Func)(FT_Memory memory, long cur_size, long new_size, void *block)
void(* FT_Free_Func)(FT_Memory memory, void *block)
FT_BEGIN_HEADER typedef unsigned char FT_Bool
GLuint GLuint GLsizei count
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
static char memory[1024 *256]
static unsigned __int64 next
void int int ULONGLONG int va_list * ap
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
static unsigned int block