From 0a28307fca73aef92556216cb81fece01796c219 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Tue, 27 Feb 2007 16:40:53 +0000 Subject: [PATCH] VG_(addToXA): return index in the array where the item was added. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6619 --- coregrind/m_commandline.c | 2 +- coregrind/m_xarray.c | 3 ++- include/pub_tool_xarray.h | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/coregrind/m_commandline.c b/coregrind/m_commandline.c index aa62a1ae1..97a4eee76 100644 --- a/coregrind/m_commandline.c +++ b/coregrind/m_commandline.c @@ -45,7 +45,7 @@ static void add_string ( XArray* /* of HChar* */xa, HChar* str ) { - VG_(addToXA)( xa, (void*)(&str) ); + (void) VG_(addToXA)( xa, (void*)(&str) ); } diff --git a/coregrind/m_xarray.c b/coregrind/m_xarray.c index 405f4f1fc..09dc628ee 100644 --- a/coregrind/m_xarray.c +++ b/coregrind/m_xarray.c @@ -104,7 +104,7 @@ inline void* VG_(indexXA) ( XArray* xao, Word n ) return ((char*)xa->arr) + n * xa->elemSzB; } -void VG_(addToXA) ( XArray* xao, void* elem ) +Int VG_(addToXA) ( XArray* xao, void* elem ) { struct _XArray* xa = (struct _XArray*)xao; vg_assert(xa); @@ -137,6 +137,7 @@ void VG_(addToXA) ( XArray* xao, void* elem ) elem, xa->elemSzB ); xa->usedsizeE++; xa->sorted = False; + return xa->usedsizeE-1; } // Generic shell sort. Like stdlib.h's qsort(). diff --git a/include/pub_tool_xarray.h b/include/pub_tool_xarray.h index bdb75c3dc..234be204f 100644 --- a/include/pub_tool_xarray.h +++ b/include/pub_tool_xarray.h @@ -61,8 +61,10 @@ extern void VG_(deleteXA) ( XArray* ); before making further queries with lookupXA. */ extern void VG_(setCmpFnXA) ( XArray*, Word (*compar)(void*,void*) ); -/* Add an element to an XArray. Element is copied into the XArray. */ -extern void VG_(addToXA) ( XArray*, void* elem ); +/* Add an element to an XArray. Element is copied into the XArray. + Index at which it was added is returned. Note this will be + invalidated if the array is later sortXA'd. */ +extern Int VG_(addToXA) ( XArray*, void* elem ); /* Sort an XArray using its comparison function, if set; else bomb. Probably not a stable sort w.r.t. equal elements module cmpFn. */