From nobody Thu Apr 18 16:34:23 2024 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 1546617624398769.8692993336085; Fri, 4 Jan 2019 08:00:24 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B316EC0AE087; Fri, 4 Jan 2019 16:00:20 +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 B68D01001943; Fri, 4 Jan 2019 16:00:19 +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 46BA7181B9E9; Fri, 4 Jan 2019 16:00:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x04G0GeI020634 for ; Fri, 4 Jan 2019 11:00:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id DF3F35C22F; Fri, 4 Jan 2019 16:00:16 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-216.phx2.redhat.com [10.3.116.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id A64545C1A1 for ; Fri, 4 Jan 2019 16:00:12 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Fri, 4 Jan 2019 10:00:12 -0600 Message-Id: <20190104160012.23452-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH] maint: let MIN/MAX evaluate only once, on modern compilers 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 04 Jan 2019 16:00:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We might as well take advantage of gcc's extensions for a safer MIN()/MAX() macro. Signed-off-by: Eric Blake --- RFC because we could also try to fall back to older gcc's typeof(a)_a=3D(a) when the newer __auto_type _a=3D(a) is not present, and because I don't know how to properly probe for __auto_type and/or typeof support in clang (I know that clang added __auto_type in 2015, per https://reviews.llvm.org/D12686); I also don't know if we have officially stated that we require gcc/clang (because of attribute((cleanup)), which really cannot be emulated without extensions), or if we still try to allow compilation with other compilers; if we have, I don't know if we have declared a minimum compiler version that we demand (qemu has recently demanded gcc 4.8 or clang 3.4 [branded 5.1 on Apple]). src/util/virutil.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/util/virutil.h b/src/util/virutil.h index 908d8920ec..364e354bcb 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -28,10 +28,26 @@ # include # ifndef MIN -# define MIN(a, b) ((a) < (b) ? (a) : (b)) +# if __GNUC_PREREQ(4, 9) +# define MIN(a, b) ({ \ + __auto_type _a =3D (a); \ + __auto_type _b =3D (b); \ + _a < _b ? _a : _b; \ + }) +# else +# define MIN(a, b) ((a) < (b) ? (a) : (b)) +# endif # endif # ifndef MAX -# define MAX(a, b) ((a) > (b) ? (a) : (b)) +# if __GNUC_PREREQ(4, 9) +# define MAX(a, b) ({ \ + __auto_type _a =3D (a); \ + __auto_type _b =3D (b); \ + _a > _b ? _a : _b; \ + }) +# else +# define MAX(a, b) ((a) > (b) ? (a) : (b)) +# endif # endif --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list