Module Name:    src
Committed By:   rillig
Date:           Fri Feb  4 23:43:10 UTC 2022

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: varmod-order-numeric.mk

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.1008 -r1.1009 src/usr.bin/make/var.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/varmod-order-numeric.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1008 src/usr.bin/make/var.c:1.1009
--- src/usr.bin/make/var.c:1.1008	Sat Jan 29 10:19:49 2022
+++ src/usr.bin/make/var.c	Fri Feb  4 23:43:10 2022
@@ -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 @@ bad_modifier:
 	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_val(Substring s)
 	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':

Index: src/usr.bin/make/unit-tests/varmod-order-numeric.mk
diff -u src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.5 src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.6
--- src/usr.bin/make/unit-tests/varmod-order-numeric.mk:1.5	Tue Aug  3 04:46:49 2021
+++ src/usr.bin/make/unit-tests/varmod-order-numeric.mk	Fri Feb  4 23:43:10 2022
@@ -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

Reply via email to