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
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to