Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make: use fixed type for comparing numbers usin...



details:   https://anonhg.NetBSD.org/src/rev/a05286a3f7b5
branches:  trunk
changeset: 359975:a05286a3f7b5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Feb 04 23:43:10 2022 +0000

description:
make: use fixed type for comparing numbers using the modifier ':On'

When the modifier ':On' was added on 2021-07-30, there were concerns
that pre-C99 environments would not have the type 'long long', therefore
the type was made configurable, but parsing such numbers was hard-coded
to using strtoll.

To improve compatibility with C90 environments, use 'long' and 'strtol'
in these environments.  In C99 environments, use 'long long' and
'strtoll', to account for larger file sizes.

If the flexibility of choosing yet another type for these numbers should
ever arise, it can still be implemented.  Until then, reduce the number
of possible build configurations.

diffstat:

 usr.bin/make/unit-tests/varmod-order-numeric.mk |   7 +++----
 usr.bin/make/var.c                              |  12 ++++++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diffs (62 lines):

diff -r da04b1c2a8b8 -r a05286a3f7b5 usr.bin/make/unit-tests/varmod-order-numeric.mk
--- a/usr.bin/make/unit-tests/varmod-order-numeric.mk   Fri Feb 04 23:22:19 2022 +0000
+++ b/usr.bin/make/unit-tests/varmod-order-numeric.mk   Fri Feb 04 23:43:10 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-order-numeric.mk,v 1.5 2021/08/03 04:46:49 rillig Exp $
+# $NetBSD: varmod-order-numeric.mk,v 1.6 2022/02/04 23:43:10 rillig Exp $
 #
 # Tests for the variable modifiers ':On', which returns the words, sorted in
 # ascending numeric order, and for ':Orn' and ':Onr', which additionally
@@ -8,9 +8,8 @@
 # from 2021-07-30.
 
 # This list contains only 32-bit numbers since the make code needs to conform
-# to C90, which does not provide integer types larger than 32 bit.  It uses
-# 'long long' by default, but that type is overridable if necessary to support
-# older environments.
+# to C90, which does not necessarily provide integer types larger than 32 bit.
+# Make uses 'long long' for C99 or later, and 'long' for older C versions.
 #
 # To get 53-bit integers even in C90, it would be possible to switch to
 # 'double' instead, but that would allow floating-point numbers as well, which
diff -r da04b1c2a8b8 -r a05286a3f7b5 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Fri Feb 04 23:22:19 2022 +0000
+++ b/usr.bin/make/var.c        Fri Feb 04 23:43:10 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.1008 2022/01/29 10:19:49 rillig Exp $        */
+/*     $NetBSD: var.c,v 1.1009 2022/02/04 23:43:10 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1008 2022/01/29 10:19:49 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1009 2022/02/04 23:43:10 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -3228,8 +3228,12 @@
        return AMR_BAD;
 }
 
-#ifndef NUM_TYPE
+#if __STDC__ >= 199901L
 # define NUM_TYPE long long
+# define PARSE_NUM_TYPE strtoll
+#else
+# define NUM_TYPE long
+# define PARSE_NUM_TYPE strtol
 #endif
 
 static NUM_TYPE
@@ -3238,7 +3242,7 @@
        NUM_TYPE val;
        char *ep;
 
-       val = strtoll(s.start, &ep, 0);
+       val = PARSE_NUM_TYPE(s.start, &ep, 0);
        if (ep != s.start) {
                switch (*ep) {
                case 'K':



Home | Main Index | Thread Index | Old Index