diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html index d24869d10..94a82519d 100644 --- a/Doc/Devel/internals.html +++ b/Doc/Devel/internals.html @@ -42,6 +42,7 @@
  • 7. Debugging SWIG @@ -1179,6 +1180,34 @@ Either
    + +

    7.2 Debugging DOH memory allocation problems

    +
    + +

    +The DOH objects are reference counted and use pools for memory allocation. +The implementation is in memory.c. When there are memory corruption problems, +various memory allocator tools are normally used to diagnose problems. These can be used +on SWIG and can be very useful. However, they won't necessarily find use of stale DOH objects, +that is, DOH objects +that are used after they have been deleted. This is because the DOH memory allocator +grabs a chunk of memory from the C memory allocator and manages the usage internally. +Stale DOH object usage can be checked for by defining DOH_DEBUG_MEMORY_POOLS in +memory.c. If an attempt to use an object is made after the reference count is +zero, an assertion is triggered instead of quietly re-using the stale object... +

    + +
    +
    +swig: DOH/memory.c:91: DohCheck: Assertion `!DOH_object_already_deleted' failed.
    +
    +
    + +

    +This can be memory intensive as previously used memory in the pool is not re-used so is +only recommended for diagnosing memory corruption problems. +

    +
    Copyright (C) 1999-2010 SWIG Development Team. diff --git a/Source/DOH/memory.c b/Source/DOH/memory.c index 5197c34d8..e366f88e7 100644 --- a/Source/DOH/memory.c +++ b/Source/DOH/memory.c @@ -21,9 +21,7 @@ char cvsroot_memory_c[] = "$Id$"; #endif /* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */ -/* -#define DEBUG_MEMORY_POOLS -*/ +#define DOH_DEBUG_MEMORY_POOLS static int PoolSize = DOH_POOL_SIZE; @@ -87,10 +85,10 @@ int DohCheck(const DOH *ptr) { register char *cptr = (char *) ptr; while (p) { if ((cptr >= p->pbeg) && (cptr < p->pend)) { -#ifdef DEBUG_MEMORY_POOLS +#ifdef DOH_DEBUG_MEMORY_POOLS DohBase *b = (DohBase *) ptr; - int already_deleted = b->type == 0; - assert(!already_deleted); + int DOH_object_already_deleted = b->type == 0; + assert(!DOH_object_already_deleted); #endif return 1; } @@ -121,7 +119,7 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) { DohBase *obj; if (!pools_initialized) InitPools(); -#ifndef DEBUG_MEMORY_POOLS +#ifndef DOH_DEBUG_MEMORY_POOLS if (FreeList) { obj = FreeList; FreeList = (DohBase *) obj->data; @@ -132,7 +130,7 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) { } obj = Pools->ptr + Pools->current; ++Pools->current; -#ifndef DEBUG_MEMORY_POOLS +#ifndef DOH_DEBUG_MEMORY_POOLS } #endif obj->type = type;