|
From: <sv...@va...> - 2005-12-22 06:21:03
|
Author: njn
Date: 2005-12-22 06:20:59 +0000 (Thu, 22 Dec 2005)
New Revision: 5402
Log:
Add a destructor function to OSet_Destroy() which can be called for each
node.
Modified:
trunk/coregrind/m_oset.c
trunk/include/pub_tool_oset.h
trunk/memcheck/tests/oset_test.c
Modified: trunk/coregrind/m_oset.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_oset.c 2005-12-22 06:14:42 UTC (rev 5401)
+++ trunk/coregrind/m_oset.c 2005-12-22 06:20:59 UTC (rev 5402)
@@ -294,7 +294,7 @@
}
=20
// Destructor, frees up all memory held by remaining nodes.
-void VG_(OSet_Destroy)(AvlTree* t)
+void VG_(OSet_Destroy)(AvlTree* t, OSetNodeDestroy_t destroyNode)
{
AvlNode* n;
Int i, sz =3D 0;
@@ -317,6 +317,7 @@
if (n->right) stackPush(t, n->right, 1);
break;
case 3:
+ if (destroyNode) destroyNode(n);
t->free(n);
sz++;
break;
Modified: trunk/include/pub_tool_oset.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/pub_tool_oset.h 2005-12-22 06:14:42 UTC (rev 5401)
+++ trunk/include/pub_tool_oset.h 2005-12-22 06:20:59 UTC (rev 5402)
@@ -65,9 +65,10 @@
typedef struct _OSet OSet;
typedef struct _OSetNode OSetNode;
=20
-typedef Int (*OSetCmp_t) ( void* key, void* elem );
-typedef void* (*OSetAlloc_t) ( SizeT szB );
-typedef void (*OSetFree_t) ( void* p );
+typedef Int (*OSetCmp_t) ( void* key, void* elem );
+typedef void* (*OSetAlloc_t) ( SizeT szB );
+typedef void (*OSetFree_t) ( void* p );
+typedef void (*OSetNodeDestroy_t) ( void* elem );
=20
/*--------------------------------------------------------------------*/
/*--- Creating and destroying OSets and OSet members ---*/
@@ -85,7 +86,9 @@
// If cmp is NULL, keyOff must be zero. This is checked.
//
// * Destroy: frees all nodes in the table, plus the memory used by
-// the table itself.
+// the table itself. The passed-in function is called on each node fi=
rst
+// to allow the destruction of any attached resources; if NULL it is =
not
+// called.
//
// * AllocNode: Allocate and zero memory for a node to go into the OSet.
// Uses the alloc function given to VG_(OSet_Create)() to allocated a =
node
@@ -101,7 +104,7 @@
=20
extern OSet* VG_(OSet_Create) ( OffT keyOff, OSetCmp_t cmp,
OSetAlloc_t alloc, OSetFree_t free );
-extern void VG_(OSet_Destroy) ( OSet* os );
+extern void VG_(OSet_Destroy) ( OSet* os, OSetNodeDestroy_t destroyNo=
de );
extern void* VG_(OSet_AllocNode) ( OSet* os, SizeT elemSize );
extern void VG_(OSet_FreeNode) ( OSet* os, void* elem );
=20
Modified: trunk/memcheck/tests/oset_test.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/oset_test.c 2005-12-22 06:14:42 UTC (rev 5401)
+++ trunk/memcheck/tests/oset_test.c 2005-12-22 06:20:59 UTC (rev 5402)
@@ -182,7 +182,7 @@
OSet_Print(oset1, "foo", intToStr);
=20
// Destroy the OSet
- VG_(OSet_Destroy)(oset1);
+ VG_(OSet_Destroy)(oset1, NULL);
}
=20
=20
@@ -353,7 +353,7 @@
}
=20
// Destroy the OSet
- VG_(OSet_Destroy)(oset2);
+ VG_(OSet_Destroy)(oset2, NULL);
}
=20
//----------------------------------------------------------------------=
-
|