Laszlo Ersek
2023-Mar-01 11:40 UTC
[Libguestfs] [libnbd PATCH 6/6] common/include: Fix MIN and MAX macros so they can be nested [finish port]
From: "Richard W.M. Jones" <rjones at redhat.com> Original commit message: Thanks: Eric Blake Porting notes: We already have the nesting fix in the "common/include/minmax.h" header file, from nbdkit commit 9f462af12e3b ("common/include: Fix MIN and MAX macros so they can be nested", 2022-02-22), via libnbd commit 2f25695212db5. However, that port didn't include the update to the test case. Do it now. Signed-off-by: Laszlo Ersek <lersek at redhat.com> (cherry picked from nbdkit commit 9f462af12e3b8b9840435a266d7e6e7d45ed70bf) --- common/include/test-minmax.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/include/test-minmax.c b/common/include/test-minmax.c index 285f8074e503..095c91491acc 100644 --- a/common/include/test-minmax.c +++ b/common/include/test-minmax.c @@ -154,5 +154,19 @@ main (void) SIGNED_TEST (f, -FLT_MAX, FLT_MAX); SIGNED_TEST (d, -DBL_MAX, DBL_MAX); + /* Test that MIN and MAX can be nested. This is really a compile + * test, but we do check the answer. + */ + assert (MIN (MIN (1, 2), 3) == 1); + assert (MAX (MIN (1, 2), 3) == 3); + assert (MIN (MAX (1, 2), 3) == 2); + assert (MAX (MAX (1, 4), 3) == 4); + assert (MIN (3, MIN (1, 2)) == 1); + assert (MAX (3, MIN (1, 2)) == 3); + assert (MIN (3, MAX (1, 2)) == 2); + assert (MAX (3, MAX (1, 4)) == 4); + assert (MIN (MIN (1, MIN (2, 3)), 4) == 1); + assert (MAX (MAX (1, MAX (2, 3)), 4) == 4); + exit (EXIT_SUCCESS); }
Richard W.M. Jones
2023-Mar-01 16:46 UTC
[Libguestfs] [libnbd PATCH 6/6] common/include: Fix MIN and MAX macros so they can be nested [finish port]
While I normally port across dependent changes too (eg you mention that libnbd doesn't have get-current-dir-name.h - I would have ported the commit that introduced that too, even though it's not used except by the test), I'm also not that fussed. These are separate projects and as long as the common code is not unnecessarily different or inconsistent, it'll be fine. So ACK series, thanks! Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Reasonably Related Threads
- [libnbd PATCH 6/6] common/include: Fix MIN and MAX macros so they can be nested [finish port]
- [PATCH nbdkit] common/include: Add generic MIN and MAX macros.
- [PATCH nbdkit v5 2/3] common/include: Add generic MIN and MAX macros.
- [libnbd PATCH 0/6] common: catch up with nbdkit
- [PATCH libnbd 1/5] copy, info: Include common/utils/human-size.h