From owner-svn-src-all@FreeBSD.ORG Sat Jul 10 13:32:45 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CE88C106564A; Sat, 10 Jul 2010 13:32:45 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail05.syd.optusnet.com.au (mail05.syd.optusnet.com.au [211.29.132.186]) by mx1.freebsd.org (Postfix) with ESMTP id 6115F8FC12; Sat, 10 Jul 2010 13:32:44 +0000 (UTC) Received: from c122-106-145-25.carlnfd1.nsw.optusnet.com.au (c122-106-145-25.carlnfd1.nsw.optusnet.com.au [122.106.145.25]) by mail05.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o6ADWeaI027070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 10 Jul 2010 23:32:42 +1000 Date: Sat, 10 Jul 2010 23:32:40 +1000 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Jung-uk Kim In-Reply-To: <201007090525.o695PEmj038278@svn.freebsd.org> Message-ID: <20100710230758.S60090@delplex.bde.org> References: <201007090525.o695PEmj038278@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r209842 - head/lib/libstand X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Jul 2010 13:32:45 -0000 On Fri, 9 Jul 2010, Jung-uk Kim wrote: > Log: > Fix build by defining MAX() macro here. > > Modified: > head/lib/libstand/printf.c Arrgh. The unsafe macros MAX() and MIN() were deprecated in the kernel, but this has been broken (in 2001 for NetBSD and 2003 for FreeBSD). Use of MAX() in kern/subr_prf.c was a style bug. Older code in subr_prf.c still uses the min()/max() family of inline functions (just 1 instance). > Modified: head/lib/libstand/printf.c > ============================================================================== > --- head/lib/libstand/printf.c Fri Jul 9 00:38:00 2010 (r209841) > +++ head/lib/libstand/printf.c Fri Jul 9 05:25:14 2010 (r209842) Use of MAX() here was more than a style bug, since MAX() didn't exist. libstand seems to have a full min()/max() family, modulo the usual bugs and some bitrot (libkern never had uqmax()/min(), ...; libstand is missing the addition of omax()/min(), which is unimportant since it doesn't use them, but OTOH it doesn't use most of the ones that it has). > @@ -151,6 +151,7 @@ ksprintn(char *nbuf, uintmax_t num, int > static int > kvprintf(char const *fmt, void (*func)(int), void *arg, int radix, va_list ap) > { > +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) One reason FreeBSD brought back the MAX() and MIN() mistakes was that definitions like the above were duplicated in many places in code not following normal kernel APIs. > #define PCHAR(c) {int cc=(c); if (func) (*func)(cc); else *d++ = cc; retval++; } > char nbuf[MAXNBUF]; > char *d; > The max() and min() families are hard to use because using them requires knowing the types of the arg. It is possible to write safe type-generic macros for max() and min() using gcc features (mainly __typeof()). gcc info gives examples of these. I didn't want to unportabilize the kernel by committing my versions of these, but once used them to find some type mismatches in the misuse of the max()/min() family. The type-generic versions should be safe macros named max() and min(), but unfortunately these good names are taken for the old API. Bruce