From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhFMQ-0007pJ-07 for qemu-devel@nongnu.org; Thu, 23 Oct 2014 06:11:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhFML-0004tC-2r for qemu-devel@nongnu.org; Thu, 23 Oct 2014 06:11:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhFMK-0004t0-Oa for qemu-devel@nongnu.org; Thu, 23 Oct 2014 06:11:08 -0400 Message-ID: <5448D432.9050705@redhat.com> Date: Thu, 23 Oct 2014 12:10:58 +0200 From: Max Reitz MIME-Version: 1.0 References: <1413446090-30050-1-git-send-email-pl@kamp.de> <1413446090-30050-2-git-send-email-pl@kamp.de> In-Reply-To: <1413446090-30050-2-git-send-email-pl@kamp.de> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCHv4 1/4] util: introduce MIN_NON_ZERO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven , qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, ronniesahlberg@gmail.com, stefanha@redhat.com On 2014-10-16 at 09:54, Peter Lieven wrote: > at least in block layer we have the case of limits being defined for a > BlockDriverState. However, in this context often zero (0) has the special > meanining of undefined which means no limit. If two of those limits are > combined and the minimum is needed the minimum function should only return > zero if both parameters are zero. > > Signed-off-by: Peter Lieven > --- > include/qemu/osdep.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index 1565404..9a238df 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -68,6 +68,10 @@ typedef signed int int_fast16_t; > #define MAX(a, b) (((a) > (b)) ? (a) : (b)) > #endif > > +#ifndef MIN_NON_ZERO > +#define MIN_NON_ZERO(a, b) ((!!(a) && (a) < (b)) ? (a) : (b)) I contrast to Eric I'd even like (a) != 0 instead of !!(a). I normally use just "foo" instead of "foo != 0" or "foo != NULL", but in this case I'd like (a) != 0 (or (a) > 0) because of the name "NON_ZERO". Now you have three alternatives to choose from. You're welcome. :-) Anyway, I'm fine with any, so: Reviewed-by: Max Reitz > +#endif > + > #ifndef ROUND_UP > #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d)) > #endif