Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-12-28 Thread Paul Eggert

On 9/14/22 04:35, Bruno Haible wrote:

-#  define _Static_assert(...) \
- _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
+#  define _Static_assert(R, ...) \
+ _GL_VERIFY ((R), "static assertion failed", -)


Unfortunately this doesn't conform to strict C99, which requires the 
updated _Static_assert to be called with at least two arguments. I 
discovered this while compiling bleeding-edge gzip on AIX and on 
Solaris. I worked around the problem by installing the attached patch, 
though since I don't use MSVC I'm not sure I got the new #if exactly right.


Also, does MSVC require the "(R)" to be parenthesized? I also noticed 
what would ordinarily be unnecessary parentheses later on, in the 
MSVC-specific '#   define _GL_SA1(a1) static_assert ((a1), "static 
assertion failed")'. Ordinarily I like to leave those parentheses out 
but if MSVC needs them obviously we should keep them.
From 14a7b0ce5462c90ce86d97bf952185ec2500d341 Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Wed, 28 Dec 2022 14:15:43 -0800
Subject: [PATCH] assert-h: port static_assert to strict C99
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/verify.h (_GL_VERIFY): Port MSVC hack back to C99.
Problem found when testing bleeding-edge gzip on IBM XL C for AIX,
V12.1 (5765-J02, 5725-C72), which complained ‘"malloca.c", line
42.56: 1506-041 (E) The invocation of macro _Static_assert
contains fewer arguments than are required by the macro
definition.’  This diagnostic is valid because C99 requires
that if you #define _Static_assert(R, ...) you must call
_Static_assert with at least two arguments.  I found a similar
problem with Sun C 5.9 SunOS_sparc Patch 124867-12 2009/11/22.
---
 ChangeLog| 13 +
 lib/verify.h | 16 +++-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index be0fb22078..49f88777eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2022-12-28  Paul Eggert  
+
+	assert-h: port static_assert to strict C99
+	* lib/verify.h (_GL_VERIFY): Port MSVC hack back to C99.
+	Problem found when testing bleeding-edge gzip on IBM XL C for AIX,
+	V12.1 (5765-J02, 5725-C72), which complained ‘"malloca.c", line
+	42.56: 1506-041 (E) The invocation of macro _Static_assert
+	contains fewer arguments than are required by the macro
+	definition.’  This diagnostic is valid because C99 requires
+	that if you #define _Static_assert(R, ...) you must call
+	_Static_assert with at least two arguments.  I found a similar
+	problem with Sun C 5.9 SunOS_sparc Patch 124867-12 2009/11/22.
+
 2022-12-27  Paul Eggert  
 
 	file-has-acl: fix recently-introduced NFSv4 bug
diff --git a/lib/verify.h b/lib/verify.h
index 5225a8e616..cb635a9fc2 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -223,8 +223,15 @@ template 
 /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h.  */
 #ifdef _GL_STATIC_ASSERT_H
 # if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
-#  define _Static_assert(R, ...) \
- _GL_VERIFY ((R), "static assertion failed", -)
+#  if !defined _MSC_VER || defined __clang__
+#   define _Static_assert(...) \
+  _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
+#  else
+/* Work around MSVC preprocessor incompatibility with ISO C; see
+   .  */
+#   define _Static_assert(R, ...) \
+  _GL_VERIFY ((R), "static assertion failed", -)
+#  endif
 # endif
 # if (!defined static_assert \
   && __STDC_VERSION__ < 202311 \
@@ -235,9 +242,8 @@ template 
 /* MSVC 14 in C++ mode supports the two-arguments static_assert but not
the one-argument static_assert, and it does not support _Static_assert.
We have to play preprocessor tricks to distinguish the two cases.
-   Since the MSVC preprocessor is not ISO C compliant (cf.
-   ), the solution is specific
-   to MSVC.  */
+   Since the MSVC preprocessor is not ISO C compliant (see above),.
+   the solution is specific to MSVC.  */
 #   define _GL_EXPAND(x) x
 #   define _GL_SA1(a1) static_assert ((a1), "static assertion failed")
 #   define _GL_SA2 static_assert
-- 
2.25.1



Re: [PATCH] Basic support for checking NFSv4 ACLs in Linux

2022-12-28 Thread Paul Eggert

On 12/28/22 01:07, Ondrej Valousek wrote:

I was actually wondering why did not you reuse the suggestion from Andreas:
#  define ROUNDUP(x, y)  (((x) + (y) - 1) & - (y))


It didn't work when the + overflowed, and it assumed two's complement. 
The latter assumption is pretty safe nowadays (and will be required by 
C23, finally!) but I have a thing about portability. Although these 
issues are fixable the particular situation here (where values close to 
2**32-1 really do represent 2**32 bytes, and where gcc incorrectly 
complains about adding aligned byte counts to aligned pointers) 
suggested special code.





RE: [PATCH] Basic support for checking NFSv4 ACLs in Linux

2022-12-28 Thread Ondrej Valousek
Thanks Paul,
I was actually wondering why did not you reuse the suggestion from Andreas:
#  define ROUNDUP(x, y)  (((x) + (y) - 1) & - (y))
As it seemed to work pretty well to me (+ it makes obvious what we do here).
Anyhow, my 2 cents 

-Original Message-
From: Paul Eggert  
Sent: středa 28. prosince 2022 5:13
To: Ondrej Valousek 
Cc: Gnulib bugs 
Subject: Re: [PATCH] Basic support for checking NFSv4 ACLs in Linux

Some static checking helped find an off-by-one bug that I introduced to your 
Gnulib patch. The bug caused file_has_acl to sometimes incorrectly return -1 
when given a nontrivial ACL in which a WHOLEN is a multiple of 4. Sorry about 
that. I installed the attached further patch to fix it.