]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix Bug 404638 - Add VG_(replaceIndexXA)
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 16 Mar 2019 11:08:01 +0000 (12:08 +0100)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 16 Mar 2019 11:11:39 +0000 (12:11 +0100)
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.

NEWS
coregrind/m_xarray.c
include/pub_tool_xarray.h

diff --git a/NEWS b/NEWS
index 5bc357e45366f14a2f601788d07b7517e32654d8..1872c1ced593fd95f2e43598f502b86e55f76e06 100644 (file)
--- 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
 
index 34d01ba17dd7a462b4ca883235c9f9afe7f0b39a..325e8b16e8aece233b064bf04208c06fd4a4c7f9 100644 (file)
@@ -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 )
index fd3faaf7a026a230cd4650167cab455d2c6b5857..280db354e5b15619ddd4d9920e6ba34c207d95e2 100644 (file)
@@ -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