I know that not everyone uses the const keyword wherever possible, but I
would appreciate if the Valgrind core would support programmers that follow
this style. Currently it is not possible to pass pointers to const keys to
the OSet-manipulating functions without having to cast away constness in
order to avoid compiler errors. Can the attached patch please be reviewed
and committed on the trunk ?

Thanks,

Bart Van Assche.
Index: include/pub_tool_oset.h
===================================================================
--- include/pub_tool_oset.h	(revision 7307)
+++ include/pub_tool_oset.h	(working copy)
@@ -76,7 +76,7 @@
 // - Alloc: allocates a chunk of memory.
 // - Free: frees a chunk of memory allocated with Alloc.
 
-typedef Word  (*OSetCmp_t)         ( void* key, void* elem );
+typedef Word  (*OSetCmp_t)         ( const void* key, const void* elem );
 typedef void* (*OSetAlloc_t)       ( SizeT szB );
 typedef void  (*OSetFree_t)        ( void* p );
 
@@ -234,11 +234,11 @@
 //   they will return NULL if VG_(OSetGen_Next)() is called without an
 //   intervening call to VG_(OSetGen_ResetIter)().
 
-extern Int   VG_(OSetGen_Size)         ( OSet* os );
+extern Int   VG_(OSetGen_Size)         ( const OSet* os );
 extern void  VG_(OSetGen_Insert)       ( OSet* os, void* elem );
-extern Bool  VG_(OSetGen_Contains)     ( OSet* os, void* key  );
-extern void* VG_(OSetGen_Lookup)       ( OSet* os, void* key  );
-extern void* VG_(OSetGen_LookupWithCmp)( OSet* os, void* key, OSetCmp_t cmp );
+extern Bool  VG_(OSetGen_Contains)     ( const OSet* os, const void* key  );
+extern void* VG_(OSetGen_Lookup)       ( const OSet* os, const void* key  );
+extern void* VG_(OSetGen_LookupWithCmp)( OSet* os, const void* key, OSetCmp_t cmp );
 extern void* VG_(OSetGen_Remove)       ( OSet* os, void* key  );
 extern void  VG_(OSetGen_ResetIter)    ( OSet* os );
 extern void* VG_(OSetGen_Next)         ( OSet* os );
Index: cachegrind/cg_main.c
===================================================================
--- cachegrind/cg_main.c	(revision 7307)
+++ cachegrind/cg_main.c	(working copy)
@@ -112,7 +112,7 @@
 } LineCC;
 
 // First compare file, then fn, then line.
-static Word cmp_CodeLoc_LineCC(void *vloc, void *vcc)
+static Word cmp_CodeLoc_LineCC(const void *vloc, const void *vcc)
 {
    Word res;
    CodeLoc* a = (CodeLoc*)vloc;
@@ -182,7 +182,7 @@
 /*--- String table operations                              ---*/
 /*------------------------------------------------------------*/
 
-static Word stringCmp( void* key, void* elem )
+static Word stringCmp( const void* key, const void* elem )
 {
    return VG_(strcmp)(*(Char**)key, *(Char**)elem);
 }
Index: coregrind/m_oset.c
===================================================================
--- coregrind/m_oset.c	(revision 7307)
+++ coregrind/m_oset.c	(working copy)
@@ -189,7 +189,7 @@
 }
 
 // Compare a key and an element.  Inlining is *crucial*.
-static inline Word slow_cmp(AvlTree* t, void* k, AvlNode* n)
+static inline Word slow_cmp(const AvlTree* t, const void* k, const AvlNode* n)
 {
    return t->cmp(k, elem_of_node(n));
 }
@@ -490,7 +490,7 @@
 /*--------------------------------------------------------------------*/
 
 // Find the *node* in t matching k, or NULL if not found.
-static AvlNode* avl_lookup(AvlTree* t, void* k)
+static AvlNode* avl_lookup(const AvlTree* t, const void* k)
 {
    Word     cmpres;
    AvlNode* curr = t->root;
@@ -522,7 +522,7 @@
 }
 
 // Find the *element* in t matching k, or NULL if not found.
-void* VG_(OSetGen_Lookup)(AvlTree* t, void* k)
+void* VG_(OSetGen_Lookup)(const AvlTree* t, const void* k)
 {
    AvlNode* n;
    vg_assert(t);
@@ -532,7 +532,7 @@
 
 // Find the *element* in t matching k, or NULL if not found;  use the given
 // comparison function rather than the standard one.
-void* VG_(OSetGen_LookupWithCmp)(AvlTree* t, void* k, OSetCmp_t cmp)
+void* VG_(OSetGen_LookupWithCmp)(AvlTree* t, const void* k, OSetCmp_t cmp)
 {
    // Save the normal one to the side, then restore once we're done.
    void* e;
@@ -546,7 +546,7 @@
 }
 
 // Is there an element matching k?
-Bool VG_(OSetGen_Contains)(AvlTree* t, void* k)
+Bool VG_(OSetGen_Contains)(const AvlTree* t, const void* k)
 {
    return (NULL != VG_(OSetGen_Lookup)(t, k));
 }
@@ -775,7 +775,7 @@
 /*--- Miscellaneous operations                                     ---*/
 /*--------------------------------------------------------------------*/
 
-Int VG_(OSetGen_Size)(AvlTree* t)
+Int VG_(OSetGen_Size)(const AvlTree* t)
 {
    vg_assert(t);
    return t->nElems;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to