Hi Pádraig,
I have 2 patches attached.
First, I noticed many instances of three-valued comparisons written
like:
return (a > b) - (a < b);
I think it will take a bit of thought for new contributors to understand
this. Instead we can use _GL_CMP which does the same thing (and Gnulib
will probably never remove).
A new contributor can grep for the _GL_CMP definition and read the
detailed comment in m4/gnulib-common.m4 or lib/config.h(in)? to
understand it.
After writing that patch, I noticed that building from a tarball will
fail with the following error:
make[2]: *** No rule to make target 'src/termios.c', needed by
'src/speedlist.h'. Stop.
make[2]: Leaving directory '/tmp/coreutils-9.7.51-10e69'
make[1]: *** [Makefile:23430: all-recursive] Error 1
make[1]: Leaving directory '/tmp/coreutils-9.7.51-10e69'
make: *** [Makefile:9345: all] Error 2
The recent patches to let 'stty' support arbitrary baud rates added
src/speedlist.h which is generated by src/termios.c passed into the C
preprocessor. Therefore it should be added to EXTRA_DIST. Done with the
second patch.
Collin
>From 10e69e75b23247083e62727a74ae624e2778333c Mon Sep 17 00:00:00 2001
Message-ID: <10e69e75b23247083e62727a74ae624e2778333c.1750571130.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Sat, 21 Jun 2025 21:50:27 -0700
Subject: [PATCH 1/2] maint: use _GL_CMP instead of handwriting three-valued
comparisons
* src/comm.c (compare_files): Use _GL_CMP.
* src/join.c (keycmp): Likewise.
* src/ls.c (off_cmp): Likewise.
* src/ptx.c (compare_words, compare_occurs): Likewise.
* src/set-fields.c (compare_ranges): Likewise.
* src/sort.c (compare_random, diff_reversed, compare): Likewise.
---
src/comm.c | 3 +--
src/join.c | 2 +-
src/ls.c | 2 +-
src/ptx.c | 5 ++---
src/set-fields.c | 2 +-
src/sort.c | 10 +++++-----
6 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/comm.c b/src/comm.c
index 92be28528..dd61dd9c8 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -318,8 +318,7 @@ compare_files (char **infiles)
size_t len = MIN (thisline[0]->length, thisline[1]->length) - 1;
order = memcmp (thisline[0]->buffer, thisline[1]->buffer, len);
if (order == 0)
- order = ((thisline[0]->length > thisline[1]->length)
- - (thisline[0]->length < thisline[1]->length));
+ order = _GL_CMP (thisline[0]->length, thisline[1]->length);
}
}
diff --git a/src/join.c b/src/join.c
index 93ffdafc1..faf402eea 100644
--- a/src/join.c
+++ b/src/join.c
@@ -384,7 +384,7 @@ keycmp (struct line const *line1, struct line const *line2,
if (diff)
return diff;
- return (len1 > len2) - (len1 < len2);
+ return _GL_CMP (len1, len2);
}
/* Check that successive input lines PREV and CURRENT from input file
diff --git a/src/ls.c b/src/ls.c
index bbc1bb2fd..e84e0facf 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -3898,7 +3898,7 @@ cmp_btime (struct fileinfo const *a, struct fileinfo const *b,
static int
off_cmp (off_t a, off_t b)
{
- return (a > b) - (a < b);
+ return _GL_CMP (a, b);
}
static int
diff --git a/src/ptx.c b/src/ptx.c
index 8c42db2d2..006eb66af 100644
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -558,7 +558,7 @@ compare_words (const void *void_first, const void *void_second)
}
}
- return (first->size > second->size) - (first->size < second->size);
+ return _GL_CMP (first->size, second->size);
}
/*-----------------------------------------------------------------------.
@@ -576,8 +576,7 @@ compare_occurs (const void *void_first, const void *void_second)
value = compare_words (&first->key, &second->key);
return (value ? value
- : ((first->key.start > second->key.start)
- - (first->key.start < second->key.start)));
+ : _GL_CMP (first->key.start, second->key.start));
#undef first
#undef second
}
diff --git a/src/set-fields.c b/src/set-fields.c
index 0063ed844..31547e4e9 100644
--- a/src/set-fields.c
+++ b/src/set-fields.c
@@ -61,7 +61,7 @@ static int
compare_ranges (const void *a, const void *b)
{
struct field_range_pair const *ap = a, *bp = b;
- return (ap->lo > bp->lo) - (ap->lo < bp->lo);
+ return _GL_CMP (ap->lo, bp->lo);
}
/* Reallocate Range Pair entries, with corresponding
diff --git a/src/sort.c b/src/sort.c
index 7af1a2512..4a1fdfd37 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -2295,7 +2295,7 @@ compare_random (char *restrict texta, size_t lena,
{
xfrm_diff = memcmp (buf, buf + sizea, MIN (sizea, sizeb));
if (! xfrm_diff)
- xfrm_diff = (sizea > sizeb) - (sizea < sizeb);
+ xfrm_diff = _GL_CMP (sizea, sizeb);
}
}
}
@@ -2312,7 +2312,7 @@ compare_random (char *restrict texta, size_t lena,
{
xfrm_diff = memcmp (texta, textb, MIN (lena, lenb));
if (! xfrm_diff)
- xfrm_diff = (lena > lenb) - (lena < lenb);
+ xfrm_diff = _GL_CMP (lena, lenb);
}
diff = xfrm_diff;
@@ -2678,7 +2678,7 @@ key_warnings (struct keyfield const *gkey, bool gkey_only)
static int
diff_reversed (int diff, bool reversed)
{
- return reversed ? (diff < 0) - (diff > 0) : diff;
+ return reversed ? _GL_CMP (0, diff) : diff;
}
/* Compare two lines A and B trying every key in sequence until there
@@ -2842,7 +2842,7 @@ keycompare (struct line const *a, struct line const *b)
diff = memcmp (texta, textb, lenmin);
if (! diff)
- diff = (lena > lenb) - (lena < lenb);
+ diff = _GL_CMP (lena, lenb);
}
if (diff)
@@ -2915,7 +2915,7 @@ compare (struct line const *a, struct line const *b)
{
diff = memcmp (a->text, b->text, MIN (alen, blen));
if (!diff)
- diff = (alen > blen) - (alen < blen);
+ diff = _GL_CMP (alen, blen);
}
return diff_reversed (diff, reverse);
--
2.49.0
>From 1e207bfca71aa517d021beebebb82da0e0d2a860 Mon Sep 17 00:00:00 2001
Message-ID: <1e207bfca71aa517d021beebebb82da0e0d2a860.1750571130.git.collin.fu...@gmail.com>
In-Reply-To: <10e69e75b23247083e62727a74ae624e2778333c.1750571130.git.collin.fu...@gmail.com>
References: <10e69e75b23247083e62727a74ae624e2778333c.1750571130.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Sat, 21 Jun 2025 22:05:19 -0700
Subject: [PATCH 2/2] build: add src/termios.c to the tarball
* src/local.mk (EXTRA_DIST): Add src/termios.c.
---
src/local.mk | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/local.mk b/src/local.mk
index 45dffd8bf..d0cf00a7a 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -73,7 +73,8 @@ EXTRA_DIST += \
src/crctab.c \
src/tac-pipe.c \
src/extract-magic \
- src/speedgen
+ src/speedgen \
+ src/termios.c
CLEANFILES += $(SCRIPTS)
--
2.49.0