diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-15 14:58:31 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-15 15:05:15 +0000 |
commit | d8bc7e63c970444ae16a344360126d3b9e3c5224 (patch) | |
tree | 2da1cc6ab7af8125df8cbabb541295b5afe3fe0f /fitz | |
parent | fd7c931c35e79cf3e6ec1703a7f3dd498d98f59c (diff) | |
download | mupdf-d8bc7e63c970444ae16a344360126d3b9e3c5224.tar.xz |
Bring Memento up to date with changes in gs.
Memento_listBlocks and Memento_listNewBlocks.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/memento.c | 40 | ||||
-rw-r--r-- | fitz/memento.h | 5 |
2 files changed, 41 insertions, 4 deletions
diff --git a/fitz/memento.c b/fitz/memento.c index c6677a0f..7ef7e6cf 100644 --- a/fitz/memento.c +++ b/fitz/memento.c @@ -66,6 +66,10 @@ enum { Memento_PostSize = 16 }; +enum { + Memento_Flag_OldBlock = 1 +}; + typedef struct Memento_BlkHeader Memento_BlkHeader; struct Memento_BlkHeader @@ -73,6 +77,7 @@ struct Memento_BlkHeader size_t rawsize; int sequence; int lastCheckedOK; + int flags; Memento_BlkHeader *next; char preblk[Memento_PreSize]; }; @@ -404,7 +409,7 @@ static int Memento_listBlock(Memento_BlkHeader *b, return 0; } -static void Memento_listBlocks(void) { +void Memento_listBlocks(void) { int counts[2]; counts[0] = 0; counts[1] = 0; @@ -414,6 +419,25 @@ static void Memento_listBlocks(void) { fprintf(stderr, " Total size of blocks = %d\n", counts[1]); } +static int Memento_listNewBlock(Memento_BlkHeader *b, + void *arg) +{ + if (b->flags & Memento_Flag_OldBlock) + return 0; + b->flags |= Memento_Flag_OldBlock; + return Memento_listBlock(b, arg); +} + +void Memento_listNewBlocks(void) { + int counts[2]; + counts[0] = 0; + counts[1] = 0; + fprintf(stderr, "Blocks allocated and still extant since last list:\n"); + Memento_appBlocks(&globals.used, Memento_listNewBlock, &counts[0]); + fprintf(stderr, " Total number of blocks = %d\n", counts[0]); + fprintf(stderr, " Total size of blocks = %d\n", counts[1]); +} + static void Memento_fin(void) { Memento_checkAllMemory(); @@ -423,7 +447,7 @@ static void Memento_fin(void) globals.numFrees, globals.numReallocs); fprintf(stderr, "Average allocation size %d bytes\n", globals.totalAlloc/globals.numMallocs); - if (globals.used.head) { + if (globals.used.head != NULL) { Memento_listBlocks(); Memento_breakpoint(); } @@ -632,6 +656,7 @@ void *Memento_malloc(size_t s) memblk->rawsize = s; memblk->sequence = globals.sequence; memblk->lastCheckedOK = memblk->sequence; + memblk->flags = 0; Memento_addBlockHead(&globals.used, memblk, 0); return MEMBLK_TOBLK(memblk); } @@ -937,7 +962,7 @@ int Memento_find(void *a) data.blk = NULL; data.flags = 0; Memento_appBlocks(&globals.used, Memento_containsAddr, &data); - if (data.blk) { + if (data.blk != NULL) { fprintf(stderr, "Address 0x%p is in %sallocated block 0x%p(size=%d,num=%d)\n", data.addr, (data.flags == 1 ? "" : (data.flags == 2 ? @@ -948,7 +973,7 @@ int Memento_find(void *a) data.blk = NULL; data.flags = 0; Memento_appBlocks(&globals.free, Memento_containsAddr, &data); - if (data.blk) { + if (data.blk != NULL) { fprintf(stderr, "Address 0x%p is in %sfreed block 0x%p(size=%d,num=%d)\n", data.addr, (data.flags == 1 ? "" : (data.flags == 2 ? @@ -1045,5 +1070,12 @@ void *Memento_calloc(size_t n, size_t s) return MEMENTO_UNDERLYING_CALLOC(n, s); } +void (Memento_listBlocks)(void) +{ +} + +void (Memento_listNewBlocks)(void) +{ +} #endif diff --git a/fitz/memento.h b/fitz/memento.h index a2b4b724..eeab1cc4 100644 --- a/fitz/memento.h +++ b/fitz/memento.h @@ -175,6 +175,9 @@ void Memento_breakpoint(void); int Memento_failAt(int); int Memento_failThisEvent(void); +void Memento_listBlocks(void); +void Memento_listNewBlocks(void); + void *Memento_malloc(size_t s); void *Memento_realloc(void *, size_t s); void Memento_free(void *); @@ -207,6 +210,8 @@ void *Memento_calloc(size_t, size_t); #define Memento_breakpoint() do {} while (0) #define Memento_failAt(A) 0 #define Memento_failThisEvent() 0 +#define Memento_listBlocks() do {} while (0) +#define Memento_listNewBlocks() do {} while (0) #endif /* MEMENTO */ |