From owner-cvs-all@FreeBSD.ORG Thu Jul 1 04:11:32 2004 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9C65416A4CE; Thu, 1 Jul 2004 04:11:32 +0000 (GMT) Received: from mailout1.pacific.net.au (mailout1.pacific.net.au [61.8.0.84]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1AAEC43D41; Thu, 1 Jul 2004 04:11:32 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87])i614BR4u020406; Thu, 1 Jul 2004 14:11:27 +1000 Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) i614BOnl006393; Thu, 1 Jul 2004 14:11:25 +1000 Date: Thu, 1 Jul 2004 14:11:24 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Brian Fundakowski Feldman In-Reply-To: <20040630080047.GC946@green.homeunix.org> Message-ID: <20040701140025.C3068@gamplex.bde.org> References: <200406281915.i5SJFeaV060231@repoman.freebsd.org> <20040628193858.GG5635@green.homeunix.org> <20040629114614.T2908@gamplex.bde.org> <20040630095111.U2619@gamplex.bde.org> <20040630080047.GC946@green.homeunix.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: cvs-src@freebsd.org cc: src-committers@freebsd.org cc: Andrew Gallatin cc: cvs-all@freebsd.org Subject: Re: cvs commit: src/sys/vm vm_map.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jul 2004 04:11:32 -0000 On Wed, 30 Jun 2004, Brian Fundakowski Feldman wrote: > On Tue, Jun 29, 2004 at 08:02:48PM -0700, David Schultz wrote: > > On Wed, Jun 30, 2004, Bruce Evans wrote: > > > On Tue, 29 Jun 2004, Andrew Gallatin wrote: > > > > > > > Bruce Evans writes: > > > > > MIN() and MAX() should not be used in the kernel. 4.4BSD removed them in > > > > > the kernel, but FreeBSD broke this in rev.1.141 of sys/param.h. They > > > > > remain removed in RELENG_4. > > > > > > > > OK. Then what's the correct fix? ulmin()? > > > > > > Fixing min() to handle all unsigned types is probably best. > > > > Hmm...but this means either > > > > a) slightly pessimizing 32-bit ports with a function on uintmax_t's, > > > > b) using a macro and introducing double-expansion problems, or > > > > c) using GCC extensions > > > > Option (c) seems best from a technical standpoint, except that > > we'd be making it harder than it already is to compile the kernel > > with compilers other than gcc and icc. (Do others have the > > statement expr extension?) > > No, the correct fix is using MIN() or MAX() that are well-documented > to provide the exact side-effects C programmers know to expect. They > automatically return the correct type, too, with no coercion! No. MIN() and MAX() are not documented. The don't even exist in the kernel in FreeBSD-[2-4]. They only return the correct type in some cases. E.g., the correct type and value for MIN((foo_t)1, (bar_t)-1) is unclear, since foo_t might be unsigned and bar_t might be signed, and/or have different sizes: Case foo_t is unsigned char and bar_t is signed char, and chars are smaller than ints: the result is MIN(1, -1) = -1 and has type int. Case foo_t is unsigned int and bar_t is signed int: the result is min(1u, -1) = UINT_MAX and has type unsigned int. So programmers must still be aware of the types of the operands if the operand types are significantly different. Bruce