On Wed, Dec 30, 2015 at 10:02:48AM +0800, Michael W. Bombardieri wrote:
> Hi tech,
>
> In diff & friends, use <sys/param.h> macros MIN() and MAX() instead of
> defining these locally. Worth doing?
No, you're essentially reverting part of a large series of diffs that
did the exact opposite in order to minimize the use of <sys/param.h>.
quoting deraadt's commit message for diffreg.c, revision 1.84:
Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons.
Switch to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc.
Change MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM()
where sensible to avoid pulling in the pollution. These are the files
confirmed through binary verification.
ok guenther, millert, doug (helped with the verification protocol)
> - Michael
>
>
> Index: diff/diffreg.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/diff/diffreg.c,v
> retrieving revision 1.90
> diff -u -p -r1.90 diffreg.c
> --- diff/diffreg.c 26 Oct 2015 12:52:27 -0000 1.90
> +++ diff/diffreg.c 30 Dec 2015 02:28:03 -0000
> @@ -64,6 +64,7 @@
> * @(#)diffreg.c 8.1 (Berkeley) 6/6/93
> */
>
> +#include <sys/param.h>
> #include <sys/stat.h>
> #include <sys/wait.h>
>
> @@ -83,9 +84,6 @@
> #include "diff.h"
> #include "xmalloc.h"
>
> -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
> -#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
> -
> /*
> * diff - compare two files.
> */
> @@ -595,7 +593,7 @@ stone(int *a, int n, int *b, int *c, int
> bound = UINT_MAX;
> else {
> sq = isqrt(n);
> - bound = MAXIMUM(256, sq);
> + bound = MAX(256, sq);
> }
>
> k = 0;
> @@ -1302,10 +1300,10 @@ dump_context_vec(FILE *f1, FILE *f2, int
> return;
>
> b = d = 0; /* gcc */
> - lowa = MAXIMUM(1, cvp->a - diff_context);
> - upb = MINIMUM(len[0], context_vec_ptr->b + diff_context);
> - lowc = MAXIMUM(1, cvp->c - diff_context);
> - upd = MINIMUM(len[1], context_vec_ptr->d + diff_context);
> + lowa = MAX(1, cvp->a - diff_context);
> + upb = MIN(len[0], context_vec_ptr->b + diff_context);
> + lowc = MAX(1, cvp->c - diff_context);
> + upd = MIN(len[1], context_vec_ptr->d + diff_context);
>
> diff_output("***************");
> if ((flags & D_PROTOTYPE)) {
> @@ -1405,10 +1403,10 @@ dump_unified_vec(FILE *f1, FILE *f2, int
> return;
>
> b = d = 0; /* gcc */
> - lowa = MAXIMUM(1, cvp->a - diff_context);
> - upb = MINIMUM(len[0], context_vec_ptr->b + diff_context);
> - lowc = MAXIMUM(1, cvp->c - diff_context);
> - upd = MINIMUM(len[1], context_vec_ptr->d + diff_context);
> + lowa = MAX(1, cvp->a - diff_context);
> + upb = MIN(len[0], context_vec_ptr->b + diff_context);
> + lowc = MAX(1, cvp->c - diff_context);
> + upd = MIN(len[1], context_vec_ptr->d + diff_context);
>
> diff_output("@@ -");
> uni_range(lowa, upb);
> Index: rcs/diff.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rcs/diff.c,v
> retrieving revision 1.38
> diff -u -p -r1.38 diff.c
> --- rcs/diff.c 13 Jun 2015 20:15:21 -0000 1.38
> +++ rcs/diff.c 30 Dec 2015 02:28:04 -0000
> @@ -64,6 +64,7 @@
> * @(#)diffreg.c 8.1 (Berkeley) 6/6/93
> */
>
> +#include <sys/param.h>
> #include <sys/stat.h>
>
> #include <ctype.h>
> @@ -81,9 +82,6 @@
> #include "diff.h"
> #include "xmalloc.h"
>
> -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
> -#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
> -
> /*
> * diff - compare two files.
> */
> @@ -532,7 +530,7 @@ stone(int *a, int n, int *b, int *c, int
> bound = UINT_MAX;
> else {
> sq = isqrt(n);
> - bound = MAXIMUM(256, sq);
> + bound = MAX(256, sq);
> }
>
> k = 0;
> @@ -1205,10 +1203,10 @@ dump_context_vec(FILE *f1, FILE *f2, int
> return;
>
> b = d = 0; /* gcc */
> - lowa = MAXIMUM(1, cvp->a - diff_context);
> - upb = MINIMUM(len[0], context_vec_ptr->b + diff_context);
> - lowc = MAXIMUM(1, cvp->c - diff_context);
> - upd = MINIMUM(len[1], context_vec_ptr->d + diff_context);
> + lowa = MAX(1, cvp->a - diff_context);
> + upb = MIN(len[0], context_vec_ptr->b + diff_context);
> + lowc = MAX(1, cvp->c - diff_context);
> + upd = MIN(len[1], context_vec_ptr->d + diff_context);
>
> diff_output("***************");
> if ((flags & D_PROTOTYPE)) {
> @@ -1308,10 +1306,10 @@ dump_unified_vec(FILE *f1, FILE *f2, int
> return;
>
> d = 0; /* gcc */
> - lowa = MAXIMUM(1, cvp->a - diff_context);
> - upb = MINIMUM(len[0], context_vec_ptr->b + diff_context);
> - lowc = MAXIMUM(1, cvp->c - diff_context);
> - upd = MINIMUM(len[1], context_vec_ptr->d + diff_context);
> + lowa = MAX(1, cvp->a - diff_context);
> + upb = MIN(len[0], context_vec_ptr->b + diff_context);
> + lowc = MAX(1, cvp->c - diff_context);
> + upd = MIN(len[1], context_vec_ptr->d + diff_context);
>
> diff_output("@@ -");
> uni_range(lowa, upb);
> Index: cvs/diff_internals.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/cvs/diff_internals.c,v
> retrieving revision 1.38
> diff -u -p -r1.38 diff_internals.c
> --- cvs/diff_internals.c 5 Nov 2015 09:48:21 -0000 1.38
> +++ cvs/diff_internals.c 30 Dec 2015 02:28:04 -0000
> @@ -64,6 +64,7 @@
> * @(#)diffreg.c 8.1 (Berkeley) 6/6/93
> */
>
> +#include <sys/param.h>
> #include <sys/types.h>
> #include <sys/stat.h>
>
> @@ -81,9 +82,6 @@
> #include "cvs.h"
> #include "diff.h"
>
> -#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
> -#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
> -
> /*
> * diff - compare two files.
> */
> @@ -550,7 +548,7 @@ stone(int *a, int n, int *b, int *c, int
> bound = UINT_MAX;
> else {
> sq = isqrt(n);
> - bound = MAXIMUM(256, sq);
> + bound = MAX(256, sq);
> }
>
> k = 0;
> @@ -1278,10 +1276,10 @@ dump_context_vec(FILE *f1, FILE *f2, int
> return;
>
> b = d = 0; /* gcc */
> - lowa = MAXIMUM(1, cvp->a - diff_context);
> - upb = MINIMUM(len[0], context_vec_ptr->b + diff_context);
> - lowc = MAXIMUM(1, cvp->c - diff_context);
> - upd = MINIMUM(len[1], context_vec_ptr->d + diff_context);
> + lowa = MAX(1, cvp->a - diff_context);
> + upb = MIN(len[0], context_vec_ptr->b + diff_context);
> + lowc = MAX(1, cvp->c - diff_context);
> + upd = MIN(len[1], context_vec_ptr->d + diff_context);
>
> diff_output("***************");
> if ((flags & D_PROTOTYPE)) {
> @@ -1381,10 +1379,10 @@ dump_unified_vec(FILE *f1, FILE *f2, int
> return;
>
> b = d = 0; /* gcc */
> - lowa = MAXIMUM(1, cvp->a - diff_context);
> - upb = MINIMUM(len[0], context_vec_ptr->b + diff_context);
> - lowc = MAXIMUM(1, cvp->c - diff_context);
> - upd = MINIMUM(len[1], context_vec_ptr->d + diff_context);
> + lowa = MAX(1, cvp->a - diff_context);
> + upb = MIN(len[0], context_vec_ptr->b + diff_context);
> + lowc = MAX(1, cvp->c - diff_context);
> + upd = MIN(len[1], context_vec_ptr->d + diff_context);
>
> diff_output("@@ -");
> uni_range(lowa, upb);
>