From 41846cb61b0f511099eb9a203f11885de328ab45 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Tue, 2 Dec 2014 06:07:43 -0500 Subject: mem: Assume all dynamic packet data is array allocated This patch simplifies how we deal with dynamically allocated data in the packet, always assuming that it is array allocated, and hence should be array deallocated (delete[] as opposed to delete). The only uses of dataDynamic was in the Ruby testers. The ARRAY_DATA flag in the packet is removed accordingly. No defragmentation of the flags is done at this point, leaving a gap in the bit masks. As the last part the patch, it renames dataDynamicArray to dataDynamic. --- src/mem/packet.hh | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'src/mem/packet.hh') diff --git a/src/mem/packet.hh b/src/mem/packet.hh index e8fb00680..19423db58 100644 --- a/src/mem/packet.hh +++ b/src/mem/packet.hh @@ -247,11 +247,9 @@ class Packet : public Printable /// when the packet is destroyed? static const FlagsType STATIC_DATA = 0x00001000; /// The data pointer points to a value that should be freed when - /// the packet is destroyed. + /// the packet is destroyed. The pointer is assumed to be pointing + /// to an array, and delete [] is consequently called static const FlagsType DYNAMIC_DATA = 0x00002000; - /// the data pointer points to an array (thus delete []) needs to - /// be called on it rather than simply delete. - static const FlagsType ARRAY_DATA = 0x00004000; /// suppress the error if this packet encounters a functional /// access failure. static const FlagsType SUPPRESS_FUNC_ERROR = 0x00008000; @@ -813,7 +811,7 @@ class Packet : public Printable void dataStatic(T *p) { - assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); + assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); data = (PacketDataPtr)p; flags.set(STATIC_DATA); } @@ -830,7 +828,7 @@ class Packet : public Printable void dataStaticConst(const T *p) { - assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); + assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); data = const_cast(p); flags.set(STATIC_DATA); } @@ -841,22 +839,9 @@ class Packet : public Printable */ template void - dataDynamicArray(T *p) - { - assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); - data = (PacketDataPtr)p; - flags.set(DYNAMIC_DATA|ARRAY_DATA); - } - - /** - * set the data pointer to a value that should have delete called - * on it. - */ - template - void dataDynamic(T *p) { - assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); + assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); data = (PacketDataPtr)p; flags.set(DYNAMIC_DATA); } @@ -938,12 +923,10 @@ class Packet : public Printable void deleteData() { - if (flags.isSet(ARRAY_DATA)) + if (flags.isSet(DYNAMIC_DATA)) delete [] data; - else if (flags.isSet(DYNAMIC_DATA)) - delete data; - flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA); + flags.clear(STATIC_DATA|DYNAMIC_DATA); data = NULL; } @@ -952,7 +935,7 @@ class Packet : public Printable allocate() { assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); - flags.set(DYNAMIC_DATA|ARRAY_DATA); + flags.set(DYNAMIC_DATA); data = new uint8_t[getSize()]; } -- cgit v1.2.3