From 0706a252031b3f160bac65fac00b22f8a5ebf4f9 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Tue, 2 Dec 2014 06:07:38 -0500 Subject: mem: Use const pointers for port proxy write functions This patch changes the various write functions in the port proxies to use const pointers for all sources (similar to how memcpy works). The one unfortunate aspect is the need for a const_cast in the packet, to avoid having to juggle a const and a non-const data pointer. This design decision can always be re-evaluated at a later stage. --- src/mem/packet.hh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/mem/packet.hh') diff --git a/src/mem/packet.hh b/src/mem/packet.hh index fea9dbaae..b540ef6ca 100644 --- a/src/mem/packet.hh +++ b/src/mem/packet.hh @@ -813,6 +813,23 @@ class Packet : public Printable flags.set(STATIC_DATA); } + /** + * Set the data pointer to the following value that should not be + * freed. This version of the function allows the pointer passed + * to us to be const. To avoid issues down the line we cast the + * constness away, the alternative would be to keep both a const + * and non-const data pointer and cleverly choose between + * them. Note that this is only allowed for static data. + */ + template + void + dataStaticConst(const T *p) + { + assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); + data = const_cast(p); + flags.set(STATIC_DATA); + } + /** * Set the data pointer to a value that should have delete [] * called on it. -- cgit v1.2.3