|
From: <sv...@va...> - 2008-02-17 00:25:50
|
Author: sewardj
Date: 2008-02-17 00:25:49 +0000 (Sun, 17 Feb 2008)
New Revision: 7415
Log:
Add a new method, VG_(cloneXA), which clones an existing XArray.
Modified:
branches/DATASYMS/coregrind/m_xarray.c
branches/DATASYMS/include/pub_tool_xarray.h
Modified: branches/DATASYMS/coregrind/m_xarray.c
===================================================================
--- branches/DATASYMS/coregrind/m_xarray.c 2008-02-17 00:24:22 UTC (rev 7414)
+++ branches/DATASYMS/coregrind/m_xarray.c 2008-02-17 00:25:49 UTC (rev 7415)
@@ -76,6 +76,32 @@
return xa;
}
+XArray* VG_(cloneXA)( XArray* xao )
+{
+ struct _XArray* xa = (struct _XArray*)xao;
+ struct _XArray* nyu;
+ vg_assert(xa);
+ vg_assert(xa->alloc);
+ vg_assert(xa->free);
+ vg_assert(xa->elemSzB >= 1);
+ nyu = xa->alloc( sizeof(struct _XArray) );
+ if (!nyu)
+ return NULL;
+ /* Copy everything verbatim ... */
+ *nyu = *xa;
+ /* ... except we have to clone the contents-array */
+ if (nyu->arr) {
+ nyu->arr = nyu->alloc( nyu->totsizeE * nyu->elemSzB );
+ if (!nyu->arr) {
+ nyu->free(nyu);
+ return NULL;
+ }
+ VG_(memcpy)( nyu->arr, xa->arr, nyu->totsizeE * nyu->elemSzB );
+ }
+ /* We're done! */
+ return nyu;
+}
+
void VG_(deleteXA) ( XArray* xao )
{
struct _XArray* xa = (struct _XArray*)xao;
Modified: branches/DATASYMS/include/pub_tool_xarray.h
===================================================================
--- branches/DATASYMS/include/pub_tool_xarray.h 2008-02-17 00:24:22 UTC (rev 7414)
+++ branches/DATASYMS/include/pub_tool_xarray.h 2008-02-17 00:25:49 UTC (rev 7415)
@@ -99,6 +99,11 @@
than n elements in the array. */
extern void VG_(dropTailXA) ( XArray*, Word );
+/* Make a new, completely independent copy of the given XArray, using
+ the existing allocation function to allocate the new space.
+ Returns NULL if the allocation function didn't manage to allocate
+ space (but did return NULL rather than merely abort.) */
+extern XArray* VG_(cloneXA)( XArray* xa );
#endif // __PUB_TOOL_XARRAY_H
|