Error checking for stale DOH object use - also with documentation.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13521 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
cdfa81e572
commit
766128065f
2 changed files with 35 additions and 8 deletions
|
|
@ -42,6 +42,7 @@
|
||||||
<li><a name="i7" href="#7">7. Debugging SWIG</a>
|
<li><a name="i7" href="#7">7. Debugging SWIG</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a name="i7.1" href="#7.1">7.1 Debugging DOH Types The Hard Way</a>
|
<li><a name="i7.1" href="#7.1">7.1 Debugging DOH Types The Hard Way</a>
|
||||||
|
<li><a name="i7.2" href="#7.2">7.2 Debugging DOH memory allocation problems</a>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
@ -1179,6 +1180,34 @@ Either <br>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<a name="7.2" href="#i7.2">
|
||||||
|
<h3>7.2 Debugging DOH memory allocation problems</h3>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The DOH objects are reference counted and use pools for memory allocation.
|
||||||
|
The implementation is in <tt>memory.c</tt>. 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 <tt>DOH_DEBUG_MEMORY_POOLS</tt> in
|
||||||
|
<tt>memory.c</tt>. 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...
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<pre>
|
||||||
|
swig: DOH/memory.c:91: DohCheck: Assertion `!DOH_object_already_deleted' failed.
|
||||||
|
</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
Copyright (C) 1999-2010 SWIG Development Team.
|
Copyright (C) 1999-2010 SWIG Development Team.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,7 @@ char cvsroot_memory_c[] = "$Id$";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */
|
/* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */
|
||||||
/*
|
#define DOH_DEBUG_MEMORY_POOLS
|
||||||
#define DEBUG_MEMORY_POOLS
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int PoolSize = DOH_POOL_SIZE;
|
static int PoolSize = DOH_POOL_SIZE;
|
||||||
|
|
||||||
|
|
@ -87,10 +85,10 @@ int DohCheck(const DOH *ptr) {
|
||||||
register char *cptr = (char *) ptr;
|
register char *cptr = (char *) ptr;
|
||||||
while (p) {
|
while (p) {
|
||||||
if ((cptr >= p->pbeg) && (cptr < p->pend)) {
|
if ((cptr >= p->pbeg) && (cptr < p->pend)) {
|
||||||
#ifdef DEBUG_MEMORY_POOLS
|
#ifdef DOH_DEBUG_MEMORY_POOLS
|
||||||
DohBase *b = (DohBase *) ptr;
|
DohBase *b = (DohBase *) ptr;
|
||||||
int already_deleted = b->type == 0;
|
int DOH_object_already_deleted = b->type == 0;
|
||||||
assert(!already_deleted);
|
assert(!DOH_object_already_deleted);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +119,7 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) {
|
||||||
DohBase *obj;
|
DohBase *obj;
|
||||||
if (!pools_initialized)
|
if (!pools_initialized)
|
||||||
InitPools();
|
InitPools();
|
||||||
#ifndef DEBUG_MEMORY_POOLS
|
#ifndef DOH_DEBUG_MEMORY_POOLS
|
||||||
if (FreeList) {
|
if (FreeList) {
|
||||||
obj = FreeList;
|
obj = FreeList;
|
||||||
FreeList = (DohBase *) obj->data;
|
FreeList = (DohBase *) obj->data;
|
||||||
|
|
@ -132,7 +130,7 @@ DOH *DohObjMalloc(DohObjInfo *type, void *data) {
|
||||||
}
|
}
|
||||||
obj = Pools->ptr + Pools->current;
|
obj = Pools->ptr + Pools->current;
|
||||||
++Pools->current;
|
++Pools->current;
|
||||||
#ifndef DEBUG_MEMORY_POOLS
|
#ifndef DOH_DEBUG_MEMORY_POOLS
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
obj->type = type;
|
obj->type = type;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue