From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XN0SX-00085w-Om for qemu-devel@nongnu.org; Thu, 28 Aug 2014 10:13:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XN0SQ-0002t0-Ij for qemu-devel@nongnu.org; Thu, 28 Aug 2014 10:13:53 -0400 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:46935) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XN0SQ-0002sn-Ca for qemu-devel@nongnu.org; Thu, 28 Aug 2014 10:13:46 -0400 Received: by mail-wi0-f178.google.com with SMTP id r20so965261wiv.17 for ; Thu, 28 Aug 2014 07:13:45 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 28 Aug 2014 16:13:25 +0200 Message-Id: <1409235205-21376-9-git-send-email-pbonzini@redhat.com> In-Reply-To: <1409235205-21376-1-git-send-email-pbonzini@redhat.com> References: <1409235205-21376-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 8/8] memory: Lazy init name from QOM name as needed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Crosthwaite From: Peter Crosthwaite To support name retrieval of MemoryRegions that were created dynamically (that is, not via memory_region_init and friends). We cache the name in MemoryRegion's state as object_get_canonical_path_component mallocs the returned value so it's not suitable for direct return to callers. Memory already frees the name field, so this will be garbage collected along with the MR object. Signed-off-by: Peter Crosthwaite Signed-off-by: Paolo Bonzini --- memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/memory.c b/memory.c index 42317a2..ef0be1c 100644 --- a/memory.c +++ b/memory.c @@ -1309,6 +1309,10 @@ uint64_t memory_region_size(MemoryRegion *mr) const char *memory_region_name(const MemoryRegion *mr) { + if (!mr->name) { + ((MemoryRegion *)mr)->name = + object_get_canonical_path_component(OBJECT(mr)); + } return mr->name; } -- 1.8.3.1