|
From: Philippe W. <phi...@so...> - 2019-03-16 11:31:36
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=081c34ea477f1512944e704e0b6972604824b9be commit 081c34ea477f1512944e704e0b6972604824b9be Author: Philippe Waroquiers <phi...@sk...> Date: Sat Mar 16 12:08:01 2019 +0100 Fix Bug 404638 - Add VG_(replaceIndexXA) Based on a patch from Åukasz Marek. Note that this function differs from: *(T*)VG_(indexXA)(arr, index) = new_value; as the function will mark the array as unsorted. Note that this function is currently unused in the current valgrind code basis, but it is useful for tools outside of valgrind tree. Diff: --- NEWS | 1 + coregrind/m_xarray.c | 11 +++++++++++ include/pub_tool_xarray.h | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/NEWS b/NEWS index 5bc357e..1872c1c 100644 --- a/NEWS +++ b/NEWS @@ -108,6 +108,7 @@ where XXXXXX is the bug number as listed below. 403123 vex amd64->IR: unhandled instruction bytes: 0xF3 0x48 0xF 0xAE 0xD3 (wrfsbase) 403552 s390x: wrong facility bit checked for vector facility 404054 memcheck powerpc subfe x, x, x initializes x to 0 or -1 based on CA +404638 Add VG_(replaceIndexXA) 405079 unhandled ppc64le-linux syscall: 131 (quotactl) 405403 s390x disassembler cannot be used on x86 diff --git a/coregrind/m_xarray.c b/coregrind/m_xarray.c index 34d01ba..325e8b1 100644 --- a/coregrind/m_xarray.c +++ b/coregrind/m_xarray.c @@ -350,6 +350,17 @@ void VG_(insertIndexXA)( XArray* xa, Word n, const void* elem ) xa->sorted = False; } +void VG_(replaceIndexXA)( XArray* xa, Word n, const void* elem ) +{ + vg_assert(xa); + vg_assert(n >= 0); + vg_assert(n < xa->usedsizeE); + vg_assert(xa->usedsizeE >= 0 && xa->usedsizeE <= xa->totsizeE); + VG_(memcpy)( ((UChar*)xa->arr) + n * xa->elemSzB, + elem, xa->elemSzB ); + xa->sorted = False; +} + void VG_(getContentsXA_UNSAFE)( XArray* xa, /*OUT*/void** ctsP, /*OUT*/Word* usedP ) diff --git a/include/pub_tool_xarray.h b/include/pub_tool_xarray.h index fd3faaf..280db35 100644 --- a/include/pub_tool_xarray.h +++ b/include/pub_tool_xarray.h @@ -142,6 +142,14 @@ extern void VG_(removeIndexXA)( XArray*, Word ); specified element, in the array. */ extern void VG_(insertIndexXA)( XArray*, Word, const void* elem ); +/* Replace the element of an XArray at the given index with a copy + of the new element. This is an O(1) operation. + Compared to the caller doing: + *(T*)VG_(indexXA)(arr, index) = new_value; + this function will also mark the array as unsorted. */ +extern void VG_(replaceIndexXA)( XArray*, Word, const void* elem ); + + /* Make a new, completely independent copy of the given XArray, using the existing allocation function to allocate the new space. Space for the clone (and all additions to it) is billed to 'cc' unless |