From e15319ac9b8e95e28fa4817fdc924ef3773a37a9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Jul 2025 17:24:43 +0200 Subject: [PATCH] move this stuff behind ZDEBUG --- src/z_zone.c | 64 +++++++++++++++++++++++++++++++++++++++++++++------- src/z_zone.h | 10 ++++++++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/z_zone.c b/src/z_zone.c index f1d1114e3..ad756ceaa 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -394,11 +394,19 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb * \param lowtag The lowest tag to consider. * \param hightag The highest tag to consider. */ +#ifdef ZDEBUG void Z_FreeTags2(INT32 lowtag, INT32 hightag, const char *file, INT32 line) +#else +void Z_FreeTags(INT32 lowtag, INT32 hightag) +#endif { memblock_t *block, *next; +#ifdef ZDEBUG Z_CheckHeap2(file, line); +#else + Z_CheckHeap(420); +#endif for (block = head.next; block != &head; block = next) { next = block->next; // get link before freeing @@ -468,12 +476,20 @@ void Z_CheckMemCleanup(void) * \param i Identifies from where in the code Z_CheckHeap was called. * \author Graue */ +#ifdef ZDEBUG void Z_CheckHeap2(const char *file, INT32 line) +#else +void Z_CheckHeap(INT32 tag) +#endif { memblock_t *block; UINT32 blocknumon = 0; void *given; +#ifndef ZDEBUG + (void)tag; +#endif + for (block = head.next; block != &head; block = block->next) { blocknumon++; @@ -498,11 +514,19 @@ void Z_CheckHeap2(const char *file, INT32 line) #endif if (block->user != NULL && *(block->user) != given) { - I_Error("Z_CheckHeap %s %d: block %u" + I_Error("Z_CheckHeap" +#ifdef ZDEBUG + "at %s %d :" +#endif + "block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " doesn't have a proper user", file, line, blocknumon + " doesn't have a proper user" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -510,11 +534,19 @@ void Z_CheckHeap2(const char *file, INT32 line) } if (block->next->prev != block) { - I_Error("Z_CheckHeap %s %d: block %u" + I_Error("Z_CheckHeap" +#ifdef ZDEBUG + "at %s %d :" +#endif + "block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " lacks proper backlink", file, line, blocknumon + " lacks proper backlink" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -522,11 +554,19 @@ void Z_CheckHeap2(const char *file, INT32 line) } if (block->prev->next != block) { - I_Error("Z_CheckHeap %s %d: block %u" + I_Error("Z_CheckHeap" +#ifdef ZDEBUG + "at %s %d :" +#endif + "block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " lacks proper forward link", file, line, blocknumon + " lacks proper forward link" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -534,11 +574,19 @@ void Z_CheckHeap2(const char *file, INT32 line) } if (block->id != ZONEID) { - I_Error("Z_CheckHeap %s %d: block %u" + I_Error("Z_CheckHeap" +#ifdef ZDEBUG + "at %s %d :" +#endif + "block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " have the wrong ID", file, line, blocknumon + " have the wrong ID" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif diff --git a/src/z_zone.h b/src/z_zone.h index 993592d6b..c921a0b33 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -110,9 +110,14 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb // Free all memory by tag // these don't give line numbers for ZDEBUG currently though // (perhaps this should be changed in future?) +#ifdef ZDEBUG #define Z_FreeTag(tagnum) Z_FreeTags2(tagnum, tagnum, __FILE__, __LINE__) #define Z_FreeTags(tagnum, tagnum2) Z_FreeTags2(tagnum, tagnum2, __FILE__, __LINE__) void Z_FreeTags2(INT32 lowtag, INT32 hightag, const char *file, INT32 line); +#else +#define Z_FreeTag(tagnum) Z_FreeTags(tagnum, tagnum) +void Z_FreeTags(INT32 lowtag, INT32 hightag); +#endif // Iterate memory by tag #define Z_IterateTag(tagnum, func) Z_IterateTags(tagnum, tagnum, func) @@ -122,8 +127,13 @@ void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *)); // Utility functions // void Z_CheckMemCleanup(void); + +#ifdef ZDEBUG #define Z_CheckHeap(tag) Z_CheckHeap2(__FILE__, __LINE__) void Z_CheckHeap2(const char *file, INT32 line); +#else +void Z_CheckHeap(INT32 tag); +#endif // // Zone memory modification