From 25b18b0aa1c52e6e1b0b1dfffec4ef4a1cfdbf7c Mon Sep 17 00:00:00 2001 From: Florian Krohm Date: Sat, 27 Oct 2012 23:07:42 +0000 Subject: [PATCH] Char/HChar and constness fixes. Mostly cost center on allocators which is always a const HChar * git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13089 --- coregrind/m_debuginfo/debuginfo.c | 2 +- coregrind/m_debuginfo/misc.c | 6 ++-- coregrind/m_debuginfo/priv_misc.h | 6 ++-- coregrind/m_errormgr.c | 2 +- coregrind/m_gdbserver/m_gdbserver.c | 2 +- coregrind/m_mallocfree.c | 46 ++++++++++++++++------------- coregrind/m_oset.c | 8 ++--- coregrind/m_poolalloc.c | 8 ++--- coregrind/m_redir.c | 20 ++++++------- coregrind/m_sparsewa.c | 8 ++--- coregrind/m_transtab.c | 2 +- coregrind/m_wordfm.c | 20 ++++++------- coregrind/m_xarray.c | 12 ++++---- coregrind/pub_core_mallocfree.h | 10 +++---- drd/tests/unit_bitmap.c | 2 +- drd/tests/unit_vc.c | 4 +-- exp-sgcheck/sg_main.c | 8 ++--- helgrind/hg_basics.c | 4 +-- helgrind/hg_basics.h | 4 +-- helgrind/hg_wordset.c | 20 ++++++------- helgrind/hg_wordset.h | 6 ++-- include/pub_tool_mallocfree.h | 10 +++---- include/pub_tool_oset.h | 9 +++--- include/pub_tool_poolalloc.h | 4 +-- include/pub_tool_sparsewa.h | 4 +-- include/pub_tool_wordfm.h | 8 ++--- include/pub_tool_xarray.h | 6 ++-- memcheck/mc_leakcheck.c | 2 +- memcheck/mc_main.c | 2 +- memcheck/tests/unit_oset.c | 32 ++++++++++---------- 30 files changed, 141 insertions(+), 136 deletions(-) diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index dc4f2053e..2bf206beb 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -1044,7 +1044,7 @@ void VG_(di_notify_pdb_debuginfo)( Int fd_obj, Addr avma_obj, { Int i, r, sz_exename; ULong obj_mtime, pdb_mtime; - Char exename[VKI_PATH_MAX]; + HChar exename[VKI_PATH_MAX]; Char* pdbname = NULL; Char* dot; SysRes sres; diff --git a/coregrind/m_debuginfo/misc.c b/coregrind/m_debuginfo/misc.c index 880a2ccb3..a003a2105 100644 --- a/coregrind/m_debuginfo/misc.c +++ b/coregrind/m_debuginfo/misc.c @@ -42,7 +42,7 @@ #include "priv_misc.h" /* self */ -void* ML_(dinfo_zalloc) ( HChar* cc, SizeT szB ) { +void* ML_(dinfo_zalloc) ( const HChar* cc, SizeT szB ) { void* v; vg_assert(szB > 0); v = VG_(arena_malloc)( VG_AR_DINFO, cc, szB ); @@ -55,11 +55,11 @@ void ML_(dinfo_free) ( void* v ) { VG_(arena_free)( VG_AR_DINFO, v ); } -UChar* ML_(dinfo_strdup) ( HChar* cc, const UChar* str ) { +UChar* ML_(dinfo_strdup) ( const HChar* cc, const UChar* str ) { return VG_(arena_strdup)( VG_AR_DINFO, cc, str ); } -UChar* ML_(dinfo_memdup) ( HChar* cc, UChar* str, SizeT nStr ) { +UChar* ML_(dinfo_memdup) ( const HChar* cc, UChar* str, SizeT nStr ) { UChar* dst = VG_(arena_malloc)( VG_AR_DINFO, cc, nStr ); tl_assert(dst); VG_(memcpy)(dst, str, nStr); diff --git a/coregrind/m_debuginfo/priv_misc.h b/coregrind/m_debuginfo/priv_misc.h index 48de94bc6..6c2e66c9e 100644 --- a/coregrind/m_debuginfo/priv_misc.h +++ b/coregrind/m_debuginfo/priv_misc.h @@ -38,10 +38,10 @@ /* Allocate(zeroed), free, strdup, memdup, all in VG_AR_DINFO. */ -void* ML_(dinfo_zalloc)( HChar* cc, SizeT szB ); +void* ML_(dinfo_zalloc)( const HChar* cc, SizeT szB ); void ML_(dinfo_free)( void* v ); -UChar* ML_(dinfo_strdup)( HChar* cc, const UChar* str ); -UChar* ML_(dinfo_memdup)( HChar* cc, UChar* str, SizeT nStr ); +UChar* ML_(dinfo_strdup)( const HChar* cc, const UChar* str ); +UChar* ML_(dinfo_memdup)( const HChar* cc, UChar* str, SizeT nStr ); /* Extract (possibly unaligned) data of various sizes from a buffer. */ Short ML_(read_Short)( UChar* data ); diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c index 84bf89187..a2520801b 100644 --- a/coregrind/m_errormgr.c +++ b/coregrind/m_errormgr.c @@ -346,7 +346,7 @@ static void printSuppForIp_nonXML(UInt n, Addr ip, void* textV) */ static void gen_suppression(Error* err) { - Char xtra[256]; /* assumed big enough (is overrun-safe) */ + HChar xtra[256]; /* assumed big enough (is overrun-safe) */ Bool anyXtra; const HChar* name; ExeContext* ec; diff --git a/coregrind/m_gdbserver/m_gdbserver.c b/coregrind/m_gdbserver/m_gdbserver.c index 388abafd6..212859e6f 100644 --- a/coregrind/m_gdbserver/m_gdbserver.c +++ b/coregrind/m_gdbserver/m_gdbserver.c @@ -159,7 +159,7 @@ static int gdbserver_called = 0; static int gdbserver_exited = 0; /* alloc and free functions for xarray and similar. */ -static void* gs_alloc (HChar* cc, SizeT sz) +static void* gs_alloc (const HChar* cc, SizeT sz) { void* res = VG_(arena_malloc)(VG_AR_CORE, cc, sz); vg_assert (res); diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c index e64b75ba9..880771335 100644 --- a/coregrind/m_mallocfree.c +++ b/coregrind/m_mallocfree.c @@ -191,7 +191,7 @@ typedef // elastic, in that it can be bigger than asked-for to ensure alignment. typedef struct { - Char* name; + const HChar* name; Bool clientmem; // Allocates in the client address space? SizeT rz_szB; // Red zone size in bytes SizeT min_sblock_szB; // Minimum superblock size in bytes @@ -424,18 +424,18 @@ Block* get_next_b ( Block* b ) // Set and get the cost-center field of a block. static __inline__ -void set_cc ( Block* b, HChar* cc ) +void set_cc ( Block* b, const HChar* cc ) { UByte* b2 = (UByte*)b; vg_assert( VG_(clo_profile_heap) ); - *(HChar**)&b2[0] = cc; + *(const HChar**)&b2[0] = cc; } static __inline__ -HChar* get_cc ( Block* b ) +const HChar* get_cc ( Block* b ) { UByte* b2 = (UByte*)b; vg_assert( VG_(clo_profile_heap) ); - return *(HChar**)&b2[0]; + return *(const HChar**)&b2[0]; } //--------------------------------------------------------------------------- @@ -509,7 +509,7 @@ SizeT VG_(malloc_effective_client_redzone_size)(void) // It might be overriden by VG_(clo_redzone_size) or VG_(clo_core_redzone_size). // it might be made bigger to ensure that VG_MIN_MALLOC_SZB is observed. static -void arena_init ( ArenaId aid, Char* name, SizeT rz_szB, +void arena_init ( ArenaId aid, const HChar* name, SizeT rz_szB, SizeT min_sblock_szB, SizeT min_unsplittable_sblock_szB ) { SizeT i; @@ -702,7 +702,7 @@ void ensure_mm_init ( ArenaId aid ) /*------------------------------------------------------------*/ __attribute__((noreturn)) -void VG_(out_of_memory_NORETURN) ( HChar* who, SizeT szB ) +void VG_(out_of_memory_NORETURN) ( const HChar* who, SizeT szB ) { static Int outputTrial = 0; // We try once to output the full memory state followed by the below message. @@ -711,7 +711,7 @@ void VG_(out_of_memory_NORETURN) ( HChar* who, SizeT szB ) // And then we abandon. ULong tot_alloc = VG_(am_get_anonsize_total)(); - Char* s1 = + const HChar* s1 = "\n" " Valgrind's memory management: out of memory:\n" " %s's request for %llu bytes failed.\n" @@ -1272,7 +1272,11 @@ static void sanity_check_malloc_arena ( ArenaId aid ) #define N_AN_CCS 1000 -typedef struct { ULong nBytes; ULong nBlocks; HChar* cc; } AnCC; +typedef struct { + ULong nBytes; + ULong nBlocks; + const HChar* cc; +} AnCC; static AnCC anCCs[N_AN_CCS]; @@ -1292,7 +1296,7 @@ static void cc_analyse_alloc_arena ( ArenaId aid ) Bool thisFree, lastWasFree; SizeT b_bszB; - HChar* cc; + const HChar* cc; UInt n_ccs = 0; //return; a = arenaId_to_ArenaP(aid); @@ -1480,7 +1484,7 @@ SizeT align_req_pszB ( SizeT req_pszB ) return ((req_pszB + n) & (~n)); } -void* VG_(arena_malloc) ( ArenaId aid, HChar* cc, SizeT req_pszB ) +void* VG_(arena_malloc) ( ArenaId aid, const HChar* cc, SizeT req_pszB ) { SizeT req_bszB, frag_bszB, b_bszB; UInt lno, i; @@ -1953,7 +1957,7 @@ void VG_(arena_free) ( ArenaId aid, void* ptr ) . . . . . . . */ -void* VG_(arena_memalign) ( ArenaId aid, HChar* cc, +void* VG_(arena_memalign) ( ArenaId aid, const HChar* cc, SizeT req_alignB, SizeT req_pszB ) { SizeT base_pszB_req, base_pszB_act, frag_bszB; @@ -2148,11 +2152,11 @@ void VG_(mallinfo) ( ThreadId tid, struct vg_mallinfo* mi ) /*--- Services layered on top of malloc/free. ---*/ /*------------------------------------------------------------*/ -void* VG_(arena_calloc) ( ArenaId aid, HChar* cc, +void* VG_(arena_calloc) ( ArenaId aid, const HChar* cc, SizeT nmemb, SizeT bytes_per_memb ) { SizeT size; - UChar* p; + void* p; size = nmemb * bytes_per_memb; vg_assert(size >= nmemb && size >= bytes_per_memb);// check against overflow @@ -2165,12 +2169,12 @@ void* VG_(arena_calloc) ( ArenaId aid, HChar* cc, } -void* VG_(arena_realloc) ( ArenaId aid, HChar* cc, +void* VG_(arena_realloc) ( ArenaId aid, const HChar* cc, void* ptr, SizeT req_pszB ) { Arena* a; SizeT old_pszB; - UChar *p_new; + void* p_new; Block* b; ensure_mm_init(aid); @@ -2208,7 +2212,7 @@ void* VG_(arena_realloc) ( ArenaId aid, HChar* cc, /* Inline just for the wrapper VG_(strdup) below */ -__inline__ Char* VG_(arena_strdup) ( ArenaId aid, HChar* cc, +__inline__ Char* VG_(arena_strdup) ( ArenaId aid, const HChar* cc, const Char* s ) { Int i; @@ -2233,7 +2237,7 @@ __inline__ Char* VG_(arena_strdup) ( ArenaId aid, HChar* cc, // All just wrappers to avoid exposing arenas to tools. -void* VG_(malloc) ( HChar* cc, SizeT nbytes ) +void* VG_(malloc) ( const HChar* cc, SizeT nbytes ) { return VG_(arena_malloc) ( VG_AR_TOOL, cc, nbytes ); } @@ -2243,17 +2247,17 @@ void VG_(free) ( void* ptr ) VG_(arena_free) ( VG_AR_TOOL, ptr ); } -void* VG_(calloc) ( HChar* cc, SizeT nmemb, SizeT bytes_per_memb ) +void* VG_(calloc) ( const HChar* cc, SizeT nmemb, SizeT bytes_per_memb ) { return VG_(arena_calloc) ( VG_AR_TOOL, cc, nmemb, bytes_per_memb ); } -void* VG_(realloc) ( HChar* cc, void* ptr, SizeT size ) +void* VG_(realloc) ( const HChar* cc, void* ptr, SizeT size ) { return VG_(arena_realloc) ( VG_AR_TOOL, cc, ptr, size ); } -Char* VG_(strdup) ( HChar* cc, const Char* s ) +Char* VG_(strdup) ( const HChar* cc, const Char* s ) { return VG_(arena_strdup) ( VG_AR_TOOL, cc, s ); } diff --git a/coregrind/m_oset.c b/coregrind/m_oset.c index acb724eb8..8e45700de 100644 --- a/coregrind/m_oset.c +++ b/coregrind/m_oset.c @@ -113,7 +113,7 @@ struct _OSet { SizeT keyOff; // key offset OSetCmp_t cmp; // compare a key and an element, or NULL OSetAlloc_t alloc; // allocator - HChar* cc; // cc for allocator + const HChar* cc; // cc for allocator OSetFree_t free; // deallocator PoolAlloc* node_pa; // (optional) pool allocator for nodes. SizeT maxEltSize; // for node_pa, must be > 0. Otherwise unused. @@ -286,7 +286,7 @@ static inline Bool stackPop(AvlTree* t, AvlNode** n, Int* i) // The underscores avoid GCC complaints about overshadowing global names. AvlTree* VG_(OSetGen_Create)(PtrdiffT _keyOff, OSetCmp_t _cmp, - OSetAlloc_t _alloc, HChar* _cc, + OSetAlloc_t _alloc, const HChar* _cc, OSetFree_t _free) { AvlTree* t; @@ -315,7 +315,7 @@ AvlTree* VG_(OSetGen_Create)(PtrdiffT _keyOff, OSetCmp_t _cmp, } AvlTree* VG_(OSetGen_Create_With_Pool)(PtrdiffT _keyOff, OSetCmp_t _cmp, - OSetAlloc_t _alloc, HChar* _cc, + OSetAlloc_t _alloc, const HChar* _cc, OSetFree_t _free, SizeT _poolSize, SizeT _maxEltSize) @@ -363,7 +363,7 @@ AvlTree* VG_(OSetGen_EmptyClone) (AvlTree* os) return t; } -AvlTree* VG_(OSetWord_Create)(OSetAlloc_t _alloc, HChar* _cc, +AvlTree* VG_(OSetWord_Create)(OSetAlloc_t _alloc, const HChar* _cc, OSetFree_t _free) { return VG_(OSetGen_Create)(/*keyOff*/0, /*cmp*/NULL, _alloc, _cc, _free); diff --git a/coregrind/m_poolalloc.c b/coregrind/m_poolalloc.c index a236a0b68..e3b07fcf0 100644 --- a/coregrind/m_poolalloc.c +++ b/coregrind/m_poolalloc.c @@ -36,8 +36,8 @@ struct _PoolAlloc { UWord nrRef; /* nr reference to this pool allocator */ UWord elemSzB; /* element size */ UWord nPerPool; /* # elems per pool */ - void* (*alloc)(HChar*, SizeT); /* pool allocator */ - HChar* cc; /* pool allocator's cc */ + void* (*alloc)(const HChar*, SizeT); /* pool allocator */ + const HChar* cc; /* pool allocator's cc */ void (*free)(void*); /* pool allocator's free-er */ /* XArray of void* (pointers to pools). The pools themselves. Each element is a pointer to a block of size (elemSzB * @@ -50,8 +50,8 @@ struct _PoolAlloc { PoolAlloc* VG_(newPA) ( UWord elemSzB, UWord nPerPool, - void* (*alloc)(HChar*, SizeT), - HChar* cc, + void* (*alloc)(const HChar*, SizeT), + const HChar* cc, void (*free_fn)(void*) ) { PoolAlloc* pa; diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c index 43df9d22e..1df8d9627 100644 --- a/coregrind/m_redir.c +++ b/coregrind/m_redir.c @@ -302,13 +302,13 @@ static Addr iFuncWrapper; static void maybe_add_active ( Active /*by value; callee copies*/ ); -static void* dinfo_zalloc(HChar* ec, SizeT); +static void* dinfo_zalloc(const HChar* ec, SizeT); static void dinfo_free(void*); -static HChar* dinfo_strdup(HChar* ec, HChar*); +static HChar* dinfo_strdup(const HChar* ec, const HChar*); static Bool is_plausible_guest_addr(Addr); -static void show_redir_state ( HChar* who ); -static void show_active ( HChar* left, Active* act ); +static void show_redir_state ( const HChar* who ); +static void show_active ( const HChar* left, Active* act ); static void handle_maybe_load_notifier( const UChar* soname, HChar* symbol, Addr addr ); @@ -447,7 +447,7 @@ void VG_(redir_notify_new_DebugInfo)( DebugInfo* newdi ) pointing to files inside the valgrind build directories. */ struct vg_stat newdi_stat; SysRes newdi_res; - Char in_vglib_filename[VKI_PATH_MAX]; + HChar in_vglib_filename[VKI_PATH_MAX]; struct vg_stat in_vglib_stat; SysRes in_vglib_res; @@ -1382,7 +1382,7 @@ void VG_(redir_initialise) ( void ) /*--- MISC HELPERS ---*/ /*------------------------------------------------------------*/ -static void* dinfo_zalloc(HChar* ec, SizeT n) { +static void* dinfo_zalloc(const HChar* ec, SizeT n) { void* p; vg_assert(n > 0); p = VG_(arena_malloc)(VG_AR_DINFO, ec, n); @@ -1396,7 +1396,7 @@ static void dinfo_free(void* p) { return VG_(arena_free)(VG_AR_DINFO, p); } -static HChar* dinfo_strdup(HChar* ec, HChar* str) +static HChar* dinfo_strdup(const HChar* ec, const HChar* str) { return VG_(arena_strdup)(VG_AR_DINFO, ec, str); } @@ -1574,7 +1574,7 @@ static void handle_require_text_symbols ( DebugInfo* di ) /*--- SANITY/DEBUG ---*/ /*------------------------------------------------------------*/ -static void show_spec ( HChar* left, Spec* spec ) +static void show_spec ( const HChar* left, Spec* spec ) { VG_(message)( Vg_DebugMsg, "%s%25s %30s %s-> (%04d.%d) 0x%08llx\n", @@ -1585,7 +1585,7 @@ static void show_spec ( HChar* left, Spec* spec ) (ULong)spec->to_addr ); } -static void show_active ( HChar* left, Active* act ) +static void show_active ( const HChar* left, Active* act ) { Bool ok; HChar name1[64] = ""; @@ -1604,7 +1604,7 @@ static void show_active ( HChar* left, Active* act ) (ULong)act->to_addr, name2 ); } -static void show_redir_state ( HChar* who ) +static void show_redir_state ( const HChar* who ) { TopSpec* ts; Spec* sp; diff --git a/coregrind/m_sparsewa.c b/coregrind/m_sparsewa.c index 56cef89d3..4ccb7a608 100644 --- a/coregrind/m_sparsewa.c +++ b/coregrind/m_sparsewa.c @@ -79,8 +79,8 @@ typedef SWAStackElem; struct _SparseWA { - void* (*alloc_nofail)(HChar*,SizeT); - HChar* cc; + void* (*alloc_nofail)(const HChar*,SizeT); + const HChar* cc; void (*dealloc)(void*); LevelN* root; SWAStackElem iterStack[8]; @@ -231,8 +231,8 @@ Bool VG_(nextIterSWA)( SparseWA* swa, } -SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(HChar* cc, SizeT), - HChar* cc, +SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(const HChar* cc, SizeT), + const HChar* cc, void(*dealloc)(void*) ) { SparseWA* swa; diff --git a/coregrind/m_transtab.c b/coregrind/m_transtab.c index 6eb169c98..87cf7ec4b 100644 --- a/coregrind/m_transtab.c +++ b/coregrind/m_transtab.c @@ -422,7 +422,7 @@ static ULong n_disc_osize = 0; /*--- Misc ---*/ /*-------------------------------------------------------------*/ -static void* ttaux_malloc ( HChar* tag, SizeT n ) +static void* ttaux_malloc ( const HChar* tag, SizeT n ) { return VG_(arena_malloc)(VG_AR_TTAUX, tag, n); } diff --git a/coregrind/m_wordfm.c b/coregrind/m_wordfm.c index f386ea8f4..c517fcbf8 100644 --- a/coregrind/m_wordfm.c +++ b/coregrind/m_wordfm.c @@ -81,8 +81,8 @@ typedef struct _WordFM { AvlNode* root; - void* (*alloc_nofail)( HChar*, SizeT ); - HChar* cc; + void* (*alloc_nofail)( const HChar*, SizeT ); + const HChar* cc; void (*dealloc)(void*); Word (*kCmp)(UWord,UWord); AvlNode* nodeStack[WFM_STKMAX]; // Iterator node stack @@ -502,8 +502,8 @@ static AvlNode* avl_dopy ( AvlNode* nd, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord), - void*(alloc_nofail)(HChar*,SizeT), - HChar* cc ) + void*(alloc_nofail)(const HChar*,SizeT), + const HChar* cc ) { AvlNode* nyu; if (! nd) @@ -554,8 +554,8 @@ AvlNode* avl_dopy ( AvlNode* nd, /* Initialise a WordFM. */ static void initFM ( WordFM* fm, - void* (*alloc_nofail)( HChar*, SizeT ), - HChar* cc, + void* (*alloc_nofail)( const HChar*, SizeT ), + const HChar* cc, void (*dealloc)(void*), Word (*kCmp)(UWord,UWord) ) { @@ -576,8 +576,8 @@ static void initFM ( WordFM* fm, sections of the map, or the whole thing. If kCmp is NULL then the ordering used is unsigned word ordering (UWord) on the key values. */ -WordFM* VG_(newFM) ( void* (*alloc_nofail)( HChar*, SizeT ), - HChar* cc, +WordFM* VG_(newFM) ( void* (*alloc_nofail)( const HChar*, SizeT ), + const HChar* cc, void (*dealloc)(void*), Word (*kCmp)(UWord,UWord) ) { @@ -849,8 +849,8 @@ struct _WordBag { WordFM* fm; }; -WordBag* VG_(newBag) ( void* (*alloc_nofail)( HChar*, SizeT ), - HChar* cc, +WordBag* VG_(newBag) ( void* (*alloc_nofail)( const HChar*, SizeT ), + const HChar* cc, void (*dealloc)(void*) ) { WordBag* bag = alloc_nofail(cc, sizeof(WordBag)); diff --git a/coregrind/m_xarray.c b/coregrind/m_xarray.c index bac4ab8e6..c784f90f4 100644 --- a/coregrind/m_xarray.c +++ b/coregrind/m_xarray.c @@ -38,8 +38,8 @@ /* See pub_tool_xarray.h for details of what this is all about. */ struct _XArray { - void* (*alloc) ( HChar*, SizeT ); /* alloc fn (nofail) */ - HChar* cc; /* cost centre for alloc */ + void* (*alloc) ( const HChar*, SizeT ); /* alloc fn (nofail) */ + const HChar* cc; /* cost centre for alloc */ void (*free) ( void* ); /* free fn */ Int (*cmpFn) ( void*, void* ); /* cmp fn (may be NULL) */ Word elemSzB; /* element size in bytes */ @@ -50,8 +50,8 @@ struct _XArray { }; -XArray* VG_(newXA) ( void*(*alloc_fn)(HChar*,SizeT), - HChar* cc, +XArray* VG_(newXA) ( void*(*alloc_fn)(const HChar*,SizeT), + const HChar* cc, void(*free_fn)(void*), Word elemSzB ) { @@ -79,11 +79,11 @@ XArray* VG_(newXA) ( void*(*alloc_fn)(HChar*,SizeT), return xa; } -XArray* VG_(cloneXA)( HChar* cc, XArray* xao ) +XArray* VG_(cloneXA)( const HChar* cc, XArray* xao ) { struct _XArray* xa = (struct _XArray*)xao; struct _XArray* nyu; - HChar* nyu_cc; + const HChar* nyu_cc; vg_assert(xa); vg_assert(xa->alloc); vg_assert(xa->free); diff --git a/coregrind/pub_core_mallocfree.h b/coregrind/pub_core_mallocfree.h index 7cd9536d6..f6270c8a3 100644 --- a/coregrind/pub_core_mallocfree.h +++ b/coregrind/pub_core_mallocfree.h @@ -103,15 +103,15 @@ struct vg_mallinfo { int keepcost; /* top-most, releasable (via malloc_trim) space */ }; -extern void* VG_(arena_malloc) ( ArenaId arena, HChar* cc, SizeT nbytes ); +extern void* VG_(arena_malloc) ( ArenaId arena, const HChar* cc, SizeT nbytes ); extern void VG_(arena_free) ( ArenaId arena, void* ptr ); -extern void* VG_(arena_calloc) ( ArenaId arena, HChar* cc, +extern void* VG_(arena_calloc) ( ArenaId arena, const HChar* cc, SizeT nmemb, SizeT bytes_per_memb ); -extern void* VG_(arena_realloc) ( ArenaId arena, HChar* cc, +extern void* VG_(arena_realloc) ( ArenaId arena, const HChar* cc, void* ptr, SizeT size ); -extern void* VG_(arena_memalign)( ArenaId aid, HChar* cc, +extern void* VG_(arena_memalign)( ArenaId aid, const HChar* cc, SizeT req_alignB, SizeT req_pszB ); -extern Char* VG_(arena_strdup) ( ArenaId aid, HChar* cc, +extern Char* VG_(arena_strdup) ( ArenaId aid, const HChar* cc, const Char* s); extern SizeT VG_(arena_malloc_usable_size) ( ArenaId aid, void* payload ); diff --git a/drd/tests/unit_bitmap.c b/drd/tests/unit_bitmap.c index 29892e47c..f2474f5cc 100644 --- a/drd/tests/unit_bitmap.c +++ b/drd/tests/unit_bitmap.c @@ -24,7 +24,7 @@ /* Replacements for Valgrind core functionality. */ -void* VG_(malloc)(HChar* cc, SizeT nbytes) +void* VG_(malloc)(const HChar* cc, SizeT nbytes) { return malloc(nbytes); } void VG_(free)(void* p) { return free(p); } diff --git a/drd/tests/unit_vc.c b/drd/tests/unit_vc.c index 1e0b984f8..4364fda30 100644 --- a/drd/tests/unit_vc.c +++ b/drd/tests/unit_vc.c @@ -10,9 +10,9 @@ /* Replacements for Valgrind core functionality. */ -void* VG_(malloc)(HChar* cc, SizeT nbytes) +void* VG_(malloc)(const HChar* cc, SizeT nbytes) { return malloc(nbytes); } -void* VG_(realloc)(HChar* cc, void* p, SizeT size) +void* VG_(realloc)(const HChar* cc, void* p, SizeT size) { return realloc(p, size); } void VG_(free)(void* p) { return free(p); } diff --git a/exp-sgcheck/sg_main.c b/exp-sgcheck/sg_main.c index cefa31809..d250d0e98 100644 --- a/exp-sgcheck/sg_main.c +++ b/exp-sgcheck/sg_main.c @@ -69,7 +69,7 @@ static inline Bool is_sane_TId ( ThreadId tid ) && tid != VG_INVALID_THREADID; } -static void* sg_malloc ( HChar* cc, SizeT n ) { +static void* sg_malloc ( const HChar* cc, SizeT n ) { void* p; tl_assert(n > 0); p = VG_(malloc)( cc, n ); @@ -477,7 +477,7 @@ typedef } StackTreeNode; -static void pp_StackTree ( WordFM* sitree, HChar* who ) +static void pp_StackTree ( WordFM* sitree, const HChar* who ) { UWord keyW, valW; VG_(printf)("<<< BEGIN pp_StackTree %s\n", who ); @@ -637,7 +637,7 @@ static void GlobalTreeNode__pp ( GlobalTreeNode* nd ) { } static void GlobalTree__pp ( WordFM* /* of (GlobalTreeNode,void) */ gitree, - HChar* who ) + const HChar* who ) { UWord keyW, valW; GlobalTreeNode* nd; @@ -1016,7 +1016,7 @@ static void QCache__invalidate ( QCache* qc ) { qc->nInUse = 0; } -static void QCache__pp ( QCache* qc, HChar* who ) +static void QCache__pp ( QCache* qc, const HChar* who ) { Word i; VG_(printf)("<<< QCache with %ld elements (%s)\n", qc->nInUse, who); diff --git a/helgrind/hg_basics.c b/helgrind/hg_basics.c index fdb935d6f..00f4a8b13 100644 --- a/helgrind/hg_basics.c +++ b/helgrind/hg_basics.c @@ -42,7 +42,7 @@ /*--- Very basic stuff ---*/ /*----------------------------------------------------------------*/ -void* HG_(zalloc) ( HChar* cc, SizeT n ) +void* HG_(zalloc) ( const HChar* cc, SizeT n ) { void* p; tl_assert(n > 0); @@ -58,7 +58,7 @@ void HG_(free) ( void* p ) VG_(free)(p); } -Char* HG_(strdup) ( HChar* cc, const Char* s ) +Char* HG_(strdup) ( const HChar* cc, const Char* s ) { return VG_(strdup)( cc, s ); } diff --git a/helgrind/hg_basics.h b/helgrind/hg_basics.h index aba074b20..6d9d5f45b 100644 --- a/helgrind/hg_basics.h +++ b/helgrind/hg_basics.h @@ -39,9 +39,9 @@ #define HG_(str) VGAPPEND(vgHelgrind_,str) -void* HG_(zalloc) ( HChar* cc, SizeT n ); +void* HG_(zalloc) ( const HChar* cc, SizeT n ); void HG_(free) ( void* p ); -Char* HG_(strdup) ( HChar* cc, const Char* s ); +Char* HG_(strdup) ( const HChar* cc, const Char* s ); static inline Bool HG_(is_sane_ThreadId) ( ThreadId coretid ) { return coretid >= 0 && coretid < VG_N_THREADS; diff --git a/helgrind/hg_wordset.c b/helgrind/hg_wordset.c index 5e14a62cb..45b714e2b 100644 --- a/helgrind/hg_wordset.c +++ b/helgrind/hg_wordset.c @@ -148,8 +148,8 @@ typedef vec2ix. The entry of the dead WVs in ix2vec are used to maintain a linked list of free (to be re-used) ix2vec entries. */ struct _WordSetU { - void* (*alloc)(HChar*,SizeT); - HChar* cc; + void* (*alloc)(const HChar*,SizeT); + const HChar* cc; void (*dealloc)(void*); WordFM* vec2ix; /* WordVec-to-WordSet mapping tree */ WordVec** ix2vec; /* WordSet-to-WordVec mapping array */ @@ -319,8 +319,8 @@ static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new ) causes failures on a 64-bit platform. */ tl_assert(wv_new->owner == wsu); have = VG_(lookupFM)( wsu->vec2ix, - (Word*)&wv_old, (Word*)&ix_old, - (Word)wv_new ); + (UWord*)&wv_old, (UWord*)&ix_old, + (UWord)wv_new ); if (have) { tl_assert(wv_old != wv_new); tl_assert(wv_old); @@ -336,7 +336,7 @@ static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new ) tl_assert(wsu->ix2vec[ws] == NULL || is_dead(wsu,wsu->ix2vec[ws])); wsu->ix2vec_free = (WordVec **) wsu->ix2vec[ws]; wsu->ix2vec[ws] = wv_new; - VG_(addToFM)( wsu->vec2ix, (Word)wv_new, ws ); + VG_(addToFM)( wsu->vec2ix, (UWord)wv_new, ws ); if (HG_DEBUG) VG_(printf)("aodW %s re-use free %d %p\n", wsu->cc, (Int)ws, wv_new ); return ws; } else { @@ -353,8 +353,8 @@ static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new ) } -WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( HChar*, SizeT ), - HChar* cc, +WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( const HChar*, SizeT ), + const HChar* cc, void (*dealloc)(void*), Word cacheSize ) { @@ -477,8 +477,8 @@ void HG_(dieWS) ( WordSetU* wsu, WordSet ws ) wsu->ix2vec_free = &wsu->ix2vec[ws]; VG_(delFromFM) ( wsu->vec2ix, - (Word*)&wv_in_vec2ix, (Word*)&wv_ix, - (Word)wv ); + (UWord*)&wv_in_vec2ix, (UWord*)&wv_ix, + (UWord)wv ); if (HG_DEBUG) VG_(printf)("dieWS wv_ix %d\n", (Int)wv_ix); tl_assert (wv_ix); @@ -580,7 +580,7 @@ void HG_(ppWS) ( WordSetU* wsu, WordSet ws ) VG_(printf)("}"); } -void HG_(ppWSUstats) ( WordSetU* wsu, HChar* name ) +void HG_(ppWSUstats) ( WordSetU* wsu, const HChar* name ) { VG_(printf)(" WordSet \"%s\":\n", name); VG_(printf)(" addTo %10lu (%lu uncached)\n", diff --git a/helgrind/hg_wordset.h b/helgrind/hg_wordset.h index c918d7c16..945836b9b 100644 --- a/helgrind/hg_wordset.h +++ b/helgrind/hg_wordset.h @@ -47,8 +47,8 @@ typedef struct _WordSetU WordSetU; /* opaque */ typedef UInt WordSet; /* opaque, small int index */ /* Allocate and initialise a WordSetU */ -WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( HChar*, SizeT ), - HChar* cc, +WordSetU* HG_(newWordSetU) ( void* (*alloc_nofail)( const HChar*, SizeT ), + const HChar* cc, void (*dealloc)(void*), Word cacheSize ); @@ -60,7 +60,7 @@ void HG_(deleteWordSetU) ( WordSetU* ); UWord HG_(cardinalityWSU) ( WordSetU* ); /* Show performance stats for this WordSetU. */ -void HG_(ppWSUstats) ( WordSetU* wsu, HChar* name ); +void HG_(ppWSUstats) ( WordSetU* wsu, const HChar* name ); /* Element-level operations on WordSets. Note that the WordSet diff --git a/include/pub_tool_mallocfree.h b/include/pub_tool_mallocfree.h index 212166538..76167edaa 100644 --- a/include/pub_tool_mallocfree.h +++ b/include/pub_tool_mallocfree.h @@ -37,11 +37,11 @@ // will abort if they can't allocate the memory). // The 'cc' is a string that identifies the allocation point. It's used when // --profile-heap=yes is specified. -extern void* VG_(malloc) ( HChar* cc, SizeT nbytes ); +extern void* VG_(malloc) ( const HChar* cc, SizeT nbytes ); extern void VG_(free) ( void* p ); -extern void* VG_(calloc) ( HChar* cc, SizeT n, SizeT bytes_per_elem ); -extern void* VG_(realloc) ( HChar* cc, void* p, SizeT size ); -extern Char* VG_(strdup) ( HChar* cc, const Char* s ); +extern void* VG_(calloc) ( const HChar* cc, SizeT n, SizeT bytes_per_elem ); +extern void* VG_(realloc) ( const HChar* cc, void* p, SizeT size ); +extern Char* VG_(strdup) ( const HChar* cc, const Char* s ); // Returns the usable size of a heap-block. It's the asked-for size plus // possibly some more due to rounding up. @@ -58,7 +58,7 @@ extern SizeT VG_(malloc_effective_client_redzone_size)(void); // TODO: move somewhere else // Call here to bomb the system when out of memory (mmap anon fails) __attribute__((noreturn)) -extern void VG_(out_of_memory_NORETURN) ( HChar* who, SizeT szB ); +extern void VG_(out_of_memory_NORETURN) ( const HChar* who, SizeT szB ); #endif // __PUB_TOOL_MALLOCFREE_H diff --git a/include/pub_tool_oset.h b/include/pub_tool_oset.h index 2f8152dc0..9eb789ba7 100644 --- a/include/pub_tool_oset.h +++ b/include/pub_tool_oset.h @@ -77,7 +77,7 @@ typedef struct _OSet OSet; // - Free: frees a chunk of memory allocated with Alloc. typedef Word (*OSetCmp_t) ( const void* key, const void* elem ); -typedef void* (*OSetAlloc_t) ( HChar* cc, SizeT szB ); +typedef void* (*OSetAlloc_t) ( const HChar* cc, SizeT szB ); typedef void (*OSetFree_t) ( void* p ); /*--------------------------------------------------------------------*/ @@ -99,7 +99,7 @@ typedef void (*OSetFree_t) ( void* p ); // to allow the destruction of any attached resources; if NULL it is not // called. -extern OSet* VG_(OSetWord_Create) ( OSetAlloc_t alloc, HChar* cc, +extern OSet* VG_(OSetWord_Create) ( OSetAlloc_t alloc, const HChar* cc, OSetFree_t _free ); extern void VG_(OSetWord_Destroy) ( OSet* os ); @@ -197,12 +197,13 @@ extern Bool VG_(OSetWord_Next) ( OSet* os, /*OUT*/UWord* val ); // lead to assertions in Valgrind's allocator. extern OSet* VG_(OSetGen_Create) ( PtrdiffT keyOff, OSetCmp_t cmp, - OSetAlloc_t alloc, HChar* cc, + OSetAlloc_t alloc, const HChar* cc, OSetFree_t _free); extern OSet* VG_(OSetGen_Create_With_Pool) ( PtrdiffT keyOff, OSetCmp_t cmp, - OSetAlloc_t alloc, HChar* cc, + OSetAlloc_t alloc, + const HChar* cc, OSetFree_t _free, SizeT poolSize, SizeT maxEltSize); diff --git a/include/pub_tool_poolalloc.h b/include/pub_tool_poolalloc.h index bc50daa1e..e661d9ed4 100644 --- a/include/pub_tool_poolalloc.h +++ b/include/pub_tool_poolalloc.h @@ -53,8 +53,8 @@ typedef struct _PoolAlloc PoolAlloc; is, if it returns it must have succeeded.) */ PoolAlloc* VG_(newPA) ( UWord elemSzB, UWord nPerPool, - void* (*alloc)(HChar*, SizeT), - HChar* cc, + void* (*alloc)(const HChar*, SizeT), + const HChar* cc, void (*free_fn)(void*) ); diff --git a/include/pub_tool_sparsewa.h b/include/pub_tool_sparsewa.h index 3c411b962..5336fee9c 100644 --- a/include/pub_tool_sparsewa.h +++ b/include/pub_tool_sparsewa.h @@ -49,8 +49,8 @@ typedef struct _SparseWA SparseWA; /* opaque */ // Create a new one, using the specified allocator/deallocator -SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(HChar* cc, SizeT), - HChar* cc, +SparseWA* VG_(newSWA) ( void*(*alloc_nofail)(const HChar* cc, SizeT), + const HChar* cc, void(*dealloc)(void*) ); // Delete one, and free all associated storage diff --git a/include/pub_tool_wordfm.h b/include/pub_tool_wordfm.h index ea6c5f347..15bf76a0e 100644 --- a/include/pub_tool_wordfm.h +++ b/include/pub_tool_wordfm.h @@ -76,8 +76,8 @@ typedef struct _WordFM WordFM; /* opaque */ sections of the map, or the whole thing. If kCmp is NULL then the ordering used is unsigned word ordering (UWord) on the key values. */ -WordFM* VG_(newFM) ( void* (*alloc_nofail)( HChar* cc, SizeT ), - HChar* cc, +WordFM* VG_(newFM) ( void* (*alloc_nofail)( const HChar* cc, SizeT ), + const HChar* cc, void (*dealloc)(void*), Word (*kCmp)(UWord,UWord) ); @@ -174,8 +174,8 @@ SizeT VG_(getNodeSizeFM)( void ); typedef struct _WordBag WordBag; /* opaque */ /* Allocate and initialise a WordBag */ -WordBag* VG_(newBag) ( void* (*alloc_nofail)( HChar* cc, SizeT ), - HChar* cc, +WordBag* VG_(newBag) ( void* (*alloc_nofail)( const HChar* cc, SizeT ), + const HChar* cc, void (*dealloc)(void*) ); /* Free up the Bag. */ diff --git a/include/pub_tool_xarray.h b/include/pub_tool_xarray.h index 2e1b7d433..81e05263b 100644 --- a/include/pub_tool_xarray.h +++ b/include/pub_tool_xarray.h @@ -49,8 +49,8 @@ typedef struct _XArray XArray; /* Create new XArray, using given allocation and free function, and for elements of the specified size. Alloc fn must not fail (that is, if it returns it must have succeeded.) */ -extern XArray* VG_(newXA) ( void*(*alloc_fn)(HChar*,SizeT), - HChar* cc, +extern XArray* VG_(newXA) ( void*(*alloc_fn)(const HChar*,SizeT), + const HChar* cc, void(*free_fn)(void*), Word elemSzB ); @@ -129,7 +129,7 @@ extern void VG_(removeIndexXA)( XArray*, Word ); space (but did return NULL rather than merely abort.) Space for the clone (and all additions to it) is billed to 'cc' unless that is NULL, in which case the parent's cost-center is used. */ -extern XArray* VG_(cloneXA)( HChar* cc, XArray* xa ); +extern XArray* VG_(cloneXA)( const HChar* cc, XArray* xa ); /* Get the raw array and size so callers can index it really fast. This is dangerous in the sense that there's no range or diff --git a/memcheck/mc_leakcheck.c b/memcheck/mc_leakcheck.c index 6252b2a54..1e3a3767a 100644 --- a/memcheck/mc_leakcheck.c +++ b/memcheck/mc_leakcheck.c @@ -327,7 +327,7 @@ Int find_chunk_for ( Addr ptr, static MC_Chunk** -find_active_chunks(UInt* pn_chunks) +find_active_chunks(Int* pn_chunks) { // Our goal is to construct a set of chunks that includes every // mempool chunk, and every malloc region that *doesn't* contain a diff --git a/memcheck/mc_main.c b/memcheck/mc_main.c index 1408a7d19..8d3455e2f 100644 --- a/memcheck/mc_main.c +++ b/memcheck/mc_main.c @@ -2190,7 +2190,7 @@ static void zeroise_OCacheLine ( OCacheLine* line, Addr tag ) { static OSet* ocacheL2 = NULL; -static void* ocacheL2_malloc ( HChar* cc, SizeT szB ) { +static void* ocacheL2_malloc ( const HChar* cc, SizeT szB ) { return VG_(malloc)(cc, szB); } static void ocacheL2_free ( void* v ) { diff --git a/memcheck/tests/unit_oset.c b/memcheck/tests/unit_oset.c index 854edf12c..57d4a76a3 100644 --- a/memcheck/tests/unit_oset.c +++ b/memcheck/tests/unit_oset.c @@ -54,7 +54,7 @@ static UInt myrandom( void ) return seed; } -static void* allocate_node(HChar* cc, SizeT szB) +static void* allocate_node(const HChar* cc, SizeT szB) { return malloc(szB); } static void free_node(void* p) @@ -62,7 +62,7 @@ static void free_node(void* p) //--------------------------------------------------------------------------- -// Word example +// UWord example //--------------------------------------------------------------------------- // This example shows that an element can be a single value (in this @@ -85,9 +85,9 @@ static Word wordCmp(void* vkey, void* velem) void example1singleset(OSet* oset, char *descr) { Int i, n; - Word v, prev; - Word* vs[NN]; - Word *pv; + UWord v, prev; + UWord* vs[NN]; + UWord *pv; // Try some operations on an empty OSet to ensure they don't screw up. vg_assert( ! VG_(OSetGen_Contains)(oset, &v) ); @@ -104,9 +104,9 @@ void example1singleset(OSet* oset, char *descr) } seed = 0; for (i = 0; i < NN; i++) { - Word r1 = myrandom() % NN; - Word r2 = myrandom() % NN; - Word* tmp= vs[r1]; + UWord r1 = myrandom() % NN; + UWord r2 = myrandom() % NN; + UWord* tmp= vs[r1]; vs[r1] = vs[r2]; vs[r2] = tmp; } @@ -229,7 +229,7 @@ void example1(void) NULL, allocate_node, "oset_test.1", free_node, - 101, sizeof(Word)); + 101, sizeof(UWord)); example1singleset(oset, "single oset, pool allocator"); // Destroy the OSet @@ -241,7 +241,7 @@ void example1(void) (0, NULL, allocate_node, "oset_test.1", free_node, - 101, sizeof(Word)); + 101, sizeof(UWord)); oset_empty_clone = VG_(OSetGen_EmptyClone) (oset); example1singleset(oset, "oset, shared pool"); example1singleset(oset_empty_clone, "cloned oset, shared pool"); @@ -255,8 +255,8 @@ void example1(void) void example1b(void) { Int i, n; - Word v = 0, prev; - Word vs[NN]; + UWord v = 0, prev; + UWord vs[NN]; // Create a static OSet of Ints. This one uses fast (built-in) // comparisons. @@ -275,9 +275,9 @@ void example1b(void) } seed = 0; for (i = 0; i < NN; i++) { - Word r1 = myrandom() % NN; - Word r2 = myrandom() % NN; - Word tmp = vs[r1]; + UWord r1 = myrandom() % NN; + UWord r2 = myrandom() % NN; + UWord tmp = vs[r1]; vs[r1] = vs[r2]; vs[r2] = tmp; } @@ -317,7 +317,7 @@ void example1b(void) prev = -1; VG_(OSetWord_ResetIter)(oset); while ( VG_(OSetWord_Next)(oset, &v) ) { - Word curr = v; + UWord curr = v; assert(prev < curr); prev = curr; n++;