|
From: <sv...@va...> - 2005-08-11 00:06:48
|
Author: njn
Date: 2005-08-11 01:06:36 +0100 (Thu, 11 Aug 2005)
New Revision: 4378
Log:
Give variable a better name.
Modified:
trunk/coregrind/m_hashtable.c
trunk/include/pub_tool_hashtable.h
trunk/memcheck/mac_malloc_wrappers.c
trunk/memcheck/mac_shared.c
Modified: trunk/coregrind/m_hashtable.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_hashtable.c 2005-08-10 21:25:36 UTC (rev 4377)
+++ trunk/coregrind/m_hashtable.c 2005-08-11 00:06:36 UTC (rev 4378)
@@ -108,6 +108,38 @@
return curr;
}
=20
+/* Looks up a VgHashNode in the table. Returns NULL if not found. */
+VgHashNode* VG_(HT_lookup) ( VgHashTable table, UWord key )
+{
+ VgHashNode* curr =3D table->chains[ CHAIN_NO(key, table) ];
+
+ while (curr) {
+ if (key =3D=3D curr->key) {
+ return curr;
+ }
+ curr =3D curr->next;
+ }
+ return NULL;
+}
+
+/* Removes a VgHashNode from the table. Returns NULL if not found. */
+VgHashNode* VG_(HT_remove) ( VgHashTable table, UWord key )
+{
+ Int chain =3D CHAIN_NO(key, table);
+ VgHashNode* curr =3D table->chains[chain];
+ VgHashNode** prev_next_ptr =3D &(table->chains[chain]);
+
+ while (curr) {
+ if (key =3D=3D curr->key) {
+ *prev_next_ptr =3D curr->next;
+ return curr;
+ }
+ prev_next_ptr =3D &(curr->next);
+ curr =3D curr->next;
+ }
+ return NULL;
+}
+
/* Allocates a suitably-sized array, copies all the malloc'd block
shadows into it, then returns both the array and the size of it. Thi=
s is
used by the memory-leak detector.
Modified: trunk/include/pub_tool_hashtable.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_hashtable.h 2005-08-10 21:25:36 UTC (rev 4377)
+++ trunk/include/pub_tool_hashtable.h 2005-08-11 00:06:36 UTC (rev 4378)
@@ -67,6 +67,12 @@
extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
/*OUT*/VgHashNode*** next_ptr );
=20
+/* Looks up a VgHashNode in the table. Returns NULL if not found. */
+extern VgHashNode* VG_(HT_lookup) ( VgHashTable table, UWord key );
+
+/* Removes a VgHashNode from the table. Returns NULL if not found. */
+extern VgHashNode* VG_(HT_remove) ( VgHashTable table, UWord key );
+
/* Allocates an array of pointers to all the shadow chunks of malloc'd
blocks. Must be freed with VG_(free)(). */
extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_sh=
adows );
Modified: trunk/memcheck/mac_malloc_wrappers.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/mac_malloc_wrappers.c 2005-08-10 21:25:36 UTC (rev 437=
7)
+++ trunk/memcheck/mac_malloc_wrappers.c 2005-08-11 00:06:36 UTC (rev 437=
8)
@@ -282,9 +282,7 @@
}
=20
static
-void die_and_free_mem ( ThreadId tid,
- MAC_Chunk* mc,
- MAC_Chunk** prev_chunks_next_ptr, SizeT rzB )
+void die_and_free_mem ( ThreadId tid, MAC_Chunk* mc, SizeT rzB )
{
/* Note: ban redzones again -- just in case user de-banned them
with a client request... */
@@ -292,12 +290,6 @@
MAC_(die_mem_heap)( mc->data, mc->size );
MAC_(ban_mem_heap)( mc->data+mc->size, rzB );
=20
- /* Remove mc from the malloclist using prev_chunks_next_ptr to
- avoid repeating the hash table lookup. Can't remove until at leas=
t
- after free and free_mismatch errors are done because they use
- describe_addr() which looks for it in malloclist. */
- *prev_chunks_next_ptr =3D mc->next;
-
/* Put it out of harm's way for a while, if not from a client request=
*/
if (MAC_AllocCustom !=3D mc->allockind) {
/* Record where freed */
@@ -330,7 +322,13 @@
MAC_(record_freemismatch_error) ( tid, p );
}
=20
- die_and_free_mem ( tid, mc, prev_chunks_next_ptr, rzB );
+ /* Remove mc from the malloclist using prev_chunks_next_ptr to
+ avoid repeating the hash table lookup. Can't remove until at leas=
t
+ after free_mismatch errors are done because they use
+ describe_addr() which looks for it in malloclist. */
+ *prev_chunks_next_ptr =3D mc->next;
+ die_and_free_mem ( tid, mc, rzB );
+
VGP_POPCC(VgpCliMalloc);
}
=20
@@ -354,8 +352,8 @@
=20
void* MAC_(realloc) ( ThreadId tid, void* p, SizeT new_size )
{
- MAC_Chunk *mc;
- MAC_Chunk **prev_chunks_next_ptr;
+ MAC_Chunk* mc;
+ MAC_Chunk** prev_chunks_next_ptr;
=20
VGP_PUSHCC(VgpCliMalloc);
=20
@@ -416,7 +414,12 @@
VG_(memcpy)((void*)p_new, p, mc->size);
=20
/* Free old memory */
- die_and_free_mem ( tid, mc, prev_chunks_next_ptr, MAC_MALLOC_REDZO=
NE_SZB );
+ /* Remove mc from the malloclist using prev_chunks_next_ptr to
+ avoid repeating the hash table lookup. Can't remove until at l=
east
+ after free_mismatch errors are done because they use
+ describe_addr() which looks for it in malloclist. */
+ *prev_chunks_next_ptr =3D mc->next;
+ die_and_free_mem ( tid, mc, MAC_MALLOC_REDZONE_SZB );
=20
/* this has to be after die_and_free_mem, otherwise the
former succeeds in shorting out the new block, not the
@@ -492,10 +495,8 @@
void MAC_(mempool_alloc)(ThreadId tid, Addr pool, Addr addr, SizeT size)
{
MAC_Mempool* mp;
- MAC_Mempool** prev_next;
=20
- mp =3D (MAC_Mempool*)VG_(HT_get_node) ( MAC_(mempool_list), (UWord)po=
ol,
- (void*)&prev_next );
+ mp =3D (MAC_Mempool*)VG_(HT_lookup) ( MAC_(mempool_list), (UWord)pool=
);
=20
if (mp =3D=3D NULL) {
MAC_(record_illegal_mempool_error) ( tid, pool );
@@ -509,28 +510,22 @@
void MAC_(mempool_free)(Addr pool, Addr addr)
{
MAC_Mempool* mp;
- MAC_Mempool** prev_pool;
MAC_Chunk* mc;
- MAC_Chunk** prev_chunk;
ThreadId tid =3D VG_(get_running_tid)();
=20
- mp =3D (MAC_Mempool*)VG_(HT_get_node)(MAC_(mempool_list), (UWord)pool=
,
- (void*)&prev_pool);
-
+ mp =3D (MAC_Mempool*)VG_(HT_lookup)(MAC_(mempool_list), (UWord)pool);
if (mp =3D=3D NULL) {
MAC_(record_illegal_mempool_error)(tid, pool);
return;
}
=20
- mc =3D (MAC_Chunk*)VG_(HT_get_node)(mp->chunks, (UWord)addr,
- (void*)&prev_chunk);
-
+ mc =3D (MAC_Chunk*)VG_(HT_remove)(mp->chunks, (UWord)addr);
if (mc =3D=3D NULL) {
MAC_(record_free_error)(tid, (Addr)addr);
return;
}
=20
- die_and_free_mem ( tid, mc, prev_chunk, mp->rzB );
+ die_and_free_mem ( tid, mc, mp->rzB );
}
=20
/*------------------------------------------------------------*/
Modified: trunk/memcheck/mac_shared.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/mac_shared.c 2005-08-10 21:25:36 UTC (rev 4377)
+++ trunk/memcheck/mac_shared.c 2005-08-11 00:06:36 UTC (rev 4378)
@@ -437,7 +437,7 @@
putting the result in ai. */
static void describe_addr ( Addr a, AddrInfo* ai )
{
- MAC_Chunk* sc;
+ MAC_Chunk* mc;
ThreadId tid;
=20
/* Perhaps it's a user-def'd block ? (only check if requested, thoug=
h) */
@@ -453,21 +453,21 @@
return;
}
/* Search for a recently freed block which might bracket it. */
- sc =3D MAC_(first_matching_freed_MAC_Chunk)(addr_is_in_MAC_Chunk, &a)=
;
- if (NULL !=3D sc) {
+ mc =3D MAC_(first_matching_freed_MAC_Chunk)(addr_is_in_MAC_Chunk, &a)=
;
+ if (NULL !=3D mc) {
ai->akind =3D Freed;
- ai->blksize =3D sc->size;
- ai->rwoffset =3D (Int)a - (Int)sc->data;
- ai->lastchange =3D sc->where;
+ ai->blksize =3D mc->size;
+ ai->rwoffset =3D (Int)a - (Int)mc->data;
+ ai->lastchange =3D mc->where;
return;
}
/* Search for a currently malloc'd block which might bracket it. */
- sc =3D (MAC_Chunk*)VG_(HT_first_match)(MAC_(malloc_list), addr_is_in_=
HashNode, &a);
- if (NULL !=3D sc) {
+ mc =3D (MAC_Chunk*)VG_(HT_first_match)(MAC_(malloc_list), addr_is_in_=
HashNode, &a);
+ if (NULL !=3D mc) {
ai->akind =3D Mallocd;
- ai->blksize =3D sc->size;
- ai->rwoffset =3D (Int)(a) - (Int)sc->data;
- ai->lastchange =3D sc->where;
+ ai->blksize =3D mc->size;
+ ai->rwoffset =3D (Int)(a) - (Int)mc->data;
+ ai->lastchange =3D mc->where;
return;
}
/* Clueless ... */
|