20#include FT_CONFIG_CONFIG_H
21#include FT_INTERNAL_DEBUG_H
22#include FT_INTERNAL_MEMORY_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 )
260 new_size = ft_mem_closest_prime(
table->nodes );
261 if ( new_size !=
table->size )
263 FT_MemNode* new_buckets;
267 new_buckets = (FT_MemNode *)
270 new_size * (
FT_Long)
sizeof ( FT_MemNode ) );
287 pnode = new_buckets +
hash;
289 node->link = pnode[0];
296 if (
table->buckets )
299 table->buckets = new_buckets;
300 table->size = new_size;
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 at (%s:%ld)\n"
625 "block allocated at (%s:%ld) and released at (%s:%ld)",
627 FT_FILENAME( _ft_debug_file ), _ft_debug_lineno,
628 FT_FILENAME(
node->source->file_name ),
node->source->line_no,
629 FT_FILENAME(
node->free_file_name ),
node->free_line_no );
644 if (
table->keep_alive )
649 node->free_file_name = _ft_debug_file;
650 node->free_line_no = _ft_debug_lineno;
665 ft_mem_table_resize(
table );
670 "trying to free unknown block at %p in (%s:%ld)\n",
672 FT_FILENAME( _ft_debug_file ), _ft_debug_lineno );
686 ft_mem_debug_panic(
"negative block size allocation (%ld)",
size );
689 if (
table->bound_count &&
690 table->alloc_count >=
table->alloc_count_max )
694 if (
table->bound_total &&
703 table->alloc_count++;
706 _ft_debug_file =
"<unknown>";
707 _ft_debug_lineno = 0;
721 ft_mem_debug_panic(
"trying to free NULL in (%s:%ld)",
722 FT_FILENAME( _ft_debug_file ),
727 if ( !
table->keep_alive )
730 table->alloc_count--;
732 _ft_debug_file =
"<unknown>";
733 _ft_debug_lineno = 0;
744 FT_MemNode
node, *pnode;
748 const char*
file_name = FT_FILENAME( _ft_debug_file );
749 FT_Long line_no = _ft_debug_lineno;
753 if ( new_size == cur_size )
758 if ( !
block || !cur_size )
759 ft_mem_debug_panic(
"trying to reallocate NULL in (%s:%ld)",
767 "trying to reallocate %p to size 0 (current is %ld) in (%s:%ld)",
775 "trying to reallocate unknown block at %p in (%s:%ld)",
778 if (
node->size <= 0 )
780 "trying to reallocate freed block at %p in (%s:%ld)",
783 if (
node->size != cur_size )
784 ft_mem_debug_panic(
"invalid ft_realloc request for %p. cur_size is "
785 "%ld instead of %ld in (%s:%ld)",
789 if (
table->bound_count &&
790 table->alloc_count >=
table->alloc_count_max )
793 delta = new_size - cur_size;
797 table->bound_total &&
798 table->alloc_current + delta >
table->alloc_total_max )
805 ft_mem_table_set(
table, (
FT_Byte*)new_block, new_size, delta );
807 ft_memcpy( new_block,
block, cur_size < new_size ? (
size_t)cur_size
808 : (
size_t)new_size );
812 _ft_debug_file =
"<unknown>";
813 _ft_debug_lineno = 0;
815 if ( !
table->keep_alive )
838 memory->alloc = ft_mem_debug_alloc;
839 memory->realloc = ft_mem_debug_realloc;
840 memory->free = ft_mem_debug_free;
850 table->bound_total = 1;
851 table->alloc_total_max = total_max;
861 if ( total_count > 0 )
863 table->bound_count = 1;
864 table->alloc_count_max = total_count;
874 if ( keep_alive > 0 )
875 table->keep_alive = 1;
897 ft_mem_table_destroy(
table );
904 ft_mem_source_compare(
const void* p1,
907 FT_MemSource
s1 = *(FT_MemSource*)p1;
908 FT_MemSource
s2 = *(FT_MemSource*)p2;
911 if (
s2->max_size >
s1->max_size )
913 else if (
s2->max_size <
s1->max_size )
928 FT_MemSource* bucket =
table->sources;
929 FT_MemSource*
limit = bucket + FT_MEM_SOURCE_BUCKETS;
936 for ( ; bucket <
limit; bucket++ )
938 FT_MemSource
source = *bucket;
950 for ( bucket =
table->sources; bucket <
limit; bucket++ )
952 FT_MemSource
source = *bucket;
962 ft_mem_source_compare );
964 printf(
"FreeType Memory Dump: "
965 "current=%ld max=%ld total=%ld count=%ld\n",
968 printf(
" block block sizes sizes sizes source\n" );
969 printf(
" count high sum highsum max location\n" );
970 printf(
"-------------------------------------------------\n" );
972 fmt =
"%6ld %6ld %8ld %8ld %8ld %s:%d\n";
974 for ( nn = 0; nn <
count; nn++ )
982 FT_FILENAME(
source->file_name ),
985 printf(
"------------------------------------------------\n" );
#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
_Check_return_opt_ _CRTIMP int __cdecl vprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
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