From nobody Sun Feb 8 15:46:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554480294573685.5803090859995; Fri, 5 Apr 2019 09:04:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E6F573689B; Fri, 5 Apr 2019 16:04:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C24AA60D62; Fri, 5 Apr 2019 16:04:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7FEBB181B9F0; Fri, 5 Apr 2019 16:04:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x35G4fnN003465 for ; Fri, 5 Apr 2019 12:04:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15BA860CBA; Fri, 5 Apr 2019 16:04:41 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 924A960CAD for ; Fri, 5 Apr 2019 16:04:38 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 18:04:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/11] internal: Introduce VIR_RETURN_PTR X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 05 Apr 2019 16:04:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" With the introduction of more and more internal data types which support VIR_AUTOPTR it's becoming common to see the following pattern: VIR_AUTOPTR(virSomething) some =3D NULL virSomethingPtr ret =3D NULL; ... (ret is not touched ) ... VIR_STEAL_PTR(ret, some); return ret; This patch introduces a macro named VIR_RETURN_PTR which returns the pointer directly without the need for an explicitly defined return variable and use of VIR_STEAL_PTR. Internally obviously a temporary pointer is created to allow setting the original pointer to NULL so that the VIR_AUTOPTR function does not free the memory which we want to actually return. The name of the temporary variable is deliberately long and complex to minimize the possibility of collision. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/internal.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/internal.h b/src/internal.h index cf03a82105..5a868bb00c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -279,6 +279,21 @@ (b) =3D NULL; \ } while (0) +/** + * VIR_RETURN_PTR: + * @ret: pointer to return + * + * Returns value of @ret while clearing @ret. This ensures that pointers + * freed by using VIR_AUTOPTR can be easily passed back to the caller with= out + * any temporary variable. @ptr is evaluated more than once. + */ +# define VIR_RETURN_PTR(ptr) \ + do { \ + typeof(ptr) virTemporaryReturnPointer =3D (ptr); \ + (ptr) =3D NULL; \ + return virTemporaryReturnPointer; \ + } while (0) + /** * virCheckFlags: * @supported: an OR'ed set of supported flags --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list