Re: [PATCH] errno: make EEXIST != ENOTEMPTY on AIX

2024-08-07 Thread Bruno Haible
Hi Paul,

> +2024-07-31  Paul Eggert  
> +
> + errno: make EEXIST != ENOTEMPTY on AIX
> + ...
> + * tests/test-errno.c (e1, ..., e131): Remove, replacing with ...
> + (CHECK_POSIX_ERRNOS, POSITIVE_INTEGER_CONSTANT_EXPRESSION)
> + (INDEXED_BY_ERRNO, ERRNO_COUNT): These new macros.
> + Check that all errno values are positive integer constant expressions.
> + Check that they are all distinct, except perhaps for
> + EWOULDBLOCK == EAGAIN and ENOTSUP == EOPNOTSUPP.
> + Also check ESOCKTNOSUPPORT, added in POSIX.1-2024.
> + Also, check that errno values are distinct except when POSIX says
> + they needn’t be distinct, since POSIX.1-2024 gives license to
> + GNU/Linux’s non-distinct values.

This patch makes 'test-errno' uncompilable on GNU/Hurd.
The object file test-errno.o is 1073745616 bytes large (> 1 GB),
and I had to kill the link command that was meant to produce the
'test-errno' program before it caused an out-of-memory on my machine.

I think this change needs to be reworked. Did it possibly embody the
assumption that errno values are small integers or all near together?

Bruno






fchmodat: Fix cross-compilation guess

2024-08-07 Thread Bruno Haible
When checking a $host_os, it's better to allow a kernel version number
than not.


2024-08-07  Bruno Haible  

fchmodat: Fix cross-compilation guess.
* m4/fchmodat.m4 (gl_FUNC_FCHMODAT): Tolerate Linux version number
in $host_os.

diff --git a/m4/fchmodat.m4 b/m4/fchmodat.m4
index e71ee8e8ef..99dcf58aa7 100644
--- a/m4/fchmodat.m4
+++ b/m4/fchmodat.m4
@@ -1,5 +1,5 @@
 # fchmodat.m4
-# serial 8
+# serial 9
 dnl Copyright (C) 2004-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -70,12 +70,12 @@ AC_DEFUN([gl_FUNC_FCHMODAT]
   esac
  ],
  [case "$host_os" in
-  # Guess no on Linux with glibc and Cygwin.
-linux-gnu* | cygwin*) gl_cv_func_fchmodat_works="guessing no" ;;
-  # Guess 'nearly' on AIX.
-aix*) gl_cv_func_fchmodat_works="guessing nearly" 
;;
-  # If we don't know, obey 
--enable-cross-guesses.
-*)
gl_cv_func_fchmodat_works="$gl_cross_guess_normal" ;;
+   # Guess no on Linux with glibc and Cygwin.
+linux*-gnu* | cygwin*) gl_cv_func_fchmodat_works="guessing no" ;;
+   # Guess 'nearly' on AIX.
+aix*)  gl_cv_func_fchmodat_works="guessing nearly" 
;;
+   # If we don't know, obey 
--enable-cross-guesses.
+*) 
gl_cv_func_fchmodat_works="$gl_cross_guess_normal" ;;
   esac
  ])
rm -f conftest.fchmodat])






Re: [PATCH] errno: make EEXIST != ENOTEMPTY on AIX

2024-08-07 Thread Paul Eggert

On 2024-08-07 02:58, Bruno Haible wrote:

Did it possibly embody the
assumption that errno values are small integers or all near together?


Yes it did. My preference for static checking went overboard, it seems. 
I installed the attached, which I hope fixes it.From 37fcd9c9d822150f807211de0fec6c7d86de60ef Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Wed, 7 Aug 2024 07:23:51 -0700
Subject: [PATCH] errno-tests: port to GNU/Hurd

Test for errno distinctness dynamically rather than statically,
since the static test blows up the compiler on Hurd.
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2024-08/msg00039.html
Also, test that errno values can all be used in #if,
and improve diagnostics.
* tests/test-errno.c: Include stdio.h, stdlib.h, string.h.
(USABLE_IN_IF): New macro.  Use it to check errno values in #if.
(ERRTAB): New macro.
(struct nameval): New type.
(errtab): New global variable.
(errtab_cmp): New function.
(main): Test for errno distinctness dynamically not statically.
Diagnose lack of distinctness better.
---
 ChangeLog  | 18 +++
 tests/test-errno.c | 57 +++---
 2 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8e0896f127..df710ddfa6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2024-08-07  Paul Eggert  
+
+	errno-tests: port to GNU/Hurd
+	Test for errno distinctness dynamically rather than statically,
+	since the static test blows up the compiler on Hurd.
+	Problem reported by Bruno Haible in:
+	https://lists.gnu.org/r/bug-gnulib/2024-08/msg00039.html
+	Also, test that errno values can all be used in #if,
+	and improve diagnostics.
+	* tests/test-errno.c: Include stdio.h, stdlib.h, string.h.
+	(USABLE_IN_IF): New macro.  Use it to check errno values in #if.
+	(ERRTAB): New macro.
+	(struct nameval): New type.
+	(errtab): New global variable.
+	(errtab_cmp): New function.
+	(main): Test for errno distinctness dynamically not statically.
+	Diagnose lack of distinctness better.
+
 2024-08-07  Bruno Haible  
 
 	fchmodat: Fix cross-compilation guess.
diff --git a/tests/test-errno.c b/tests/test-errno.c
index 7403ee1432..acd07ab95b 100644
--- a/tests/test-errno.c
+++ b/tests/test-errno.c
@@ -20,6 +20,10 @@
 
 #include 
 
+#include 
+#include 
+#include 
+
 /* Check all POSIX-defined errno values, using M (v) to check value v.  */
 #define CHECK_POSIX_ERRNOS(m) \
   m (E2BIG) \
@@ -107,24 +111,51 @@
 #define POSITIVE_INTEGER_CONSTANT_EXPRESSION(e) static_assert (0 < (e) << 0);
 CHECK_POSIX_ERRNOS (POSITIVE_INTEGER_CONSTANT_EXPRESSION)
 
+/* Verify that errno values can all be used in #if.  */
+#define USABLE_IN_IF(e) ^ e
+#if 0 CHECK_POSIX_ERRNOS (USABLE_IN_IF)
+#endif
+
+/* Check that errno values all differ, except possibly for
+   EWOULDBLOCK == EAGAIN and ENOTSUP == EOPNOTSUPP.  */
+#define ERRTAB(e) { #e, e },
+static struct nameval { char const *name; int value; }
+  errtab[] = { CHECK_POSIX_ERRNOS (ERRTAB) };
+
+static int
+errtab_cmp (void const *va, void const *vb)
+{
+  struct nameval const *a = va, *b = vb;
+
+  /* Sort by value first, then by name (to simplify later tests).
+ Subtraction cannot overflow as both are positive.  */
+  int diff = a->value - b->value;
+  return diff ? diff : strcmp (a->name, b->name);
+}
+
 int
 main ()
 {
+  int test_exit_status = EXIT_SUCCESS;
+
   /* Verify that errno can be assigned.  */
   errno = EOVERFLOW;
 
   /* Check that errno values all differ, except possibly for
- EWOULDBLOCK == EAGAIN and ENOTSUP == EOPNOTSUPP.  */
-  #define INDEXED_BY_ERRNO(e) [e] = 1,
-  #define ERRNO_COUNT(e) 0,
-  static char const
-indexed_by_errno[] = { CHECK_POSIX_ERRNOS (INDEXED_BY_ERRNO) },
-errno_count[] = { CHECK_POSIX_ERRNOS (ERRNO_COUNT) };
-  int distinct_errnos = 0;
-  for (int i = 0; i < sizeof indexed_by_errno; i++)
-distinct_errnos += indexed_by_errno[i];
-  return ((sizeof errno_count
-   - (EWOULDBLOCK == EAGAIN)
-   - (ENOTSUP == EOPNOTSUPP))
-  != distinct_errnos);
+ EAGAIN == EWOULDBLOCK and ENOTSUP == EOPNOTSUPP.  */
+  int nerrtab = sizeof errtab / sizeof *errtab;
+  qsort (errtab, nerrtab, sizeof *errtab, errtab_cmp);
+  for (int i = 1; i < nerrtab; i++)
+if (errtab[i - 1].value == errtab[i].value)
+  {
+fprintf (stderr, "%s == %s == %d\n",
+ errtab[i - 1].name, errtab[i].name, errtab[i].value);
+if (! ((strcmp ("EAGAIN", errtab[i - 1].name) == 0
+&& strcmp ("EWOULDBLOCK", errtab[i].name) == 0)
+   || (strcmp ("ENOTSUP", errtab[i - 1].name) == 0
+   && strcmp ("EOPNOTSUPP", errtab[i].name) == 0)))
+  test_exit_status = EXIT_FAILURE;
+  }
+
+  return test_exit_status;
 }
-- 
2.43.0



Re: [PATCH] errno: make EEXIST != ENOTEMPTY on AIX

2024-08-07 Thread Bruno Haible
Hi Paul,

> > Did it possibly embody the
> > assumption that errno values are small integers or all near together?
> 
> Yes it did. My preference for static checking went overboard, it seems. 
> I installed the attached, which I hope fixes it.

Yes, it fixes it. Thanks. 'test-errno' links fine, succeeds, and prints

  EAGAIN == EWOULDBLOCK == 1073741859

Bruno






Re: test-pthread-rwlock failure on Pop!_OS 22.04 LTS

2024-08-07 Thread Bruno Haible
On 2024-07-07, I stated:
> This provides enough justification for gnulib to override the glibc behaviour
> here. I will therefore go ahead and override
>   PTHREAD_RWLOCK_INITIALIZER
>   pthread_rwlock_init
>   pthread_rwlock_attr_init
> to use PREFER_WRITER or PREFER_WRITER_NONRECURSIVE, which both behave in a
> sane way even in glibc ≥ 2.25.

Done through these two patches:


2024-08-07  Bruno Haible  

pthread-rwlock tests: Strengthen tests.
* tests/test-pthread-rwlock-waitqueue.c: New file.
* modules/pthread-rwlock-tests (Files): Add it.
(Depends-on): Add extensions, nanosleep, stdbool.
(Makefile.am): Arrange to test test-pthread-rwlock-waitqueue.

2024-08-07  Bruno Haible  

pthread-rwlock: Fix default wait queue behaviour on glibc/Linux.
* lib/pthread.in.h: If REPLACE_PTHREAD_RWLOCK_INIT is 1 but
REPLACE_PTHREAD_RWLOCK_DESTROY is 0, override
PTHREAD_RWLOCK_INITIALIZER.
* lib/pthread-rwlock.c
(pthread_rwlockattr_init) [PTHREAD_RWLOCK_BAD_WAITQUEUE]: New function.
(pthread_rwlock_init) [PTHREAD_RWLOCK_BAD_WAITQUEUE]: New function.
* m4/pthread-rwlock.m4 (gl_PTHREAD_RWLOCK): Check for reasonable
pthread_rwlock wait queue handling. Set REPLACE_PTHREAD_RWLOCK_INIT and
REPLACE_PTHREAD_RWLOCKATTR_INIT and define PTHREAD_RWLOCK_BAD_WAITQUEUE
if not.
* modules/pthread-rwlock (configure.ac): Update
GL_COND_OBJ_PTHREAD_RWLOCK condition.
* doc/posix-functions/pthread_rwlock_rdlock.texi: Mark the glibc problem
as fixed.
* doc/posix-functions/pthread_rwlock_tryrdlock.texi: Likewise.
* doc/posix-functions/pthread_rwlock_timedrdlock.texi: Likewise.

From f7576a2e4bc63fc0b15801a82abe865304ca Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Wed, 7 Aug 2024 19:53:37 +0200
Subject: [PATCH 1/2] pthread-rwlock: Fix default wait queue behaviour on
 glibc/Linux.

* lib/pthread.in.h: If REPLACE_PTHREAD_RWLOCK_INIT is 1 but
REPLACE_PTHREAD_RWLOCK_DESTROY is 0, override
PTHREAD_RWLOCK_INITIALIZER.
* lib/pthread-rwlock.c
(pthread_rwlockattr_init) [PTHREAD_RWLOCK_BAD_WAITQUEUE]: New function.
(pthread_rwlock_init) [PTHREAD_RWLOCK_BAD_WAITQUEUE]: New function.
* m4/pthread-rwlock.m4 (gl_PTHREAD_RWLOCK): Check for reasonable
pthread_rwlock wait queue handling. Set REPLACE_PTHREAD_RWLOCK_INIT and
REPLACE_PTHREAD_RWLOCKATTR_INIT and define PTHREAD_RWLOCK_BAD_WAITQUEUE
if not.
* modules/pthread-rwlock (configure.ac): Update
GL_COND_OBJ_PTHREAD_RWLOCK condition.
* doc/posix-functions/pthread_rwlock_rdlock.texi: Mark the glibc problem
as fixed.
* doc/posix-functions/pthread_rwlock_tryrdlock.texi: Likewise.
* doc/posix-functions/pthread_rwlock_timedrdlock.texi: Likewise.
---
 ChangeLog |  20 +
 .../pthread_rwlock_rdlock.texi|  12 +-
 .../pthread_rwlock_timedrdlock.texi   |  10 +-
 .../pthread_rwlock_tryrdlock.texi |  10 +-
 lib/pthread-rwlock.c  |  64 +++-
 lib/pthread.in.h  |   9 +-
 m4/pthread-rwlock.m4  | 358 +-
 modules/pthread-rwlock|   2 +-
 8 files changed, 463 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index df710ddfa6..64e680886a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2024-08-07  Bruno Haible  
+
+	pthread-rwlock: Fix default wait queue behaviour on glibc/Linux.
+	* lib/pthread.in.h: If REPLACE_PTHREAD_RWLOCK_INIT is 1 but
+	REPLACE_PTHREAD_RWLOCK_DESTROY is 0, override
+	PTHREAD_RWLOCK_INITIALIZER.
+	* lib/pthread-rwlock.c
+	(pthread_rwlockattr_init) [PTHREAD_RWLOCK_BAD_WAITQUEUE]: New function.
+	(pthread_rwlock_init) [PTHREAD_RWLOCK_BAD_WAITQUEUE]: New function.
+	* m4/pthread-rwlock.m4 (gl_PTHREAD_RWLOCK): Check for reasonable
+	pthread_rwlock wait queue handling. Set REPLACE_PTHREAD_RWLOCK_INIT and
+	REPLACE_PTHREAD_RWLOCKATTR_INIT and define PTHREAD_RWLOCK_BAD_WAITQUEUE
+	if not.
+	* modules/pthread-rwlock (configure.ac): Update
+	GL_COND_OBJ_PTHREAD_RWLOCK condition.
+	* doc/posix-functions/pthread_rwlock_rdlock.texi: Mark the glibc problem
+	as fixed.
+	* doc/posix-functions/pthread_rwlock_tryrdlock.texi: Likewise.
+	* doc/posix-functions/pthread_rwlock_timedrdlock.texi: Likewise.
+
 2024-08-07  Paul Eggert  
 
 	errno-tests: port to GNU/Hurd
diff --git a/doc/posix-functions/pthread_rwlock_rdlock.texi b/doc/posix-functions/pthread_rwlock_rdlock.texi
index 6cbeabddce..ad07611917 100644
--- a/doc/posix-functions/pthread_rwlock_rdlock.texi
+++ b/doc/posix-functions/pthread_rwlock_rdlock.texi
@@ -13,17 +13,15 @@
 Minix 3.1.8, mingw, MSVC 14, Android 4.3.
 But the provided replacement is just a dummy on some of these platforms:
 Minix 3.1.8.
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 This function prefers readers to writers (meaning, when this function is
 called on an rwlock that is alr

Re: TODO lists regarding POSIX:2024 work

2024-08-07 Thread Bruno Haible
I wrote:
> There are many changes in POSIX:2024 that can have an impact on Gnulib;

Some (biased) summary of the changes can be found here:
https://sortix.org/blog/posix-2024/






Avoid compiler warnings in some configure tests

2024-08-07 Thread Bruno Haible
In some config.log I was seeing this warning:

configure:24322: checking for pthread_mutex_timedlock
configure:24346: gcc -o conftest -g -O2 -I/inst-x86_64-64/include -Wall 
-L/inst-x86_64-64/lib conftest.c   >&5
conftest.c: In function 'main':
conftest.c:149:25: warning: argument 2 null where non-null expected [-Wnonnull]
  149 |  return pthread_mutex_timedlock (&lock, (struct 
timespec *) 0);
  | ^~~

This patch fixes it.


2024-08-07  Bruno Haible  

Avoid compiler warnings in some configure tests.
* m4/pthread-rwlock.m4 (gl_PTHREAD_RWLOCK): Allocate more room for local
array 'name'.
* m4/pthread_mutex_timedlock.m4 (gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK): Don't
pass a NULL pointer to pthread_mutex_timedlock.

diff --git a/m4/pthread-rwlock.m4 b/m4/pthread-rwlock.m4
index 51d84419c7..cbd08790e1 100644
--- a/m4/pthread-rwlock.m4
+++ b/m4/pthread-rwlock.m4
@@ -1,5 +1,5 @@
 # pthread-rwlock.m4
-# serial 5
+# serial 6
 dnl Copyright (C) 2019-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -249,7 +249,7 @@ AC_DEFUN([gl_PTHREAD_RWLOCK]
   char **names = (char **) malloc (n * sizeof (char *));
   for (size_t i = 0; i < n; i++)
 {
-  char name[10];
+  char name[12];
   sprintf (name, "%c%u", rw_string[i], (unsigned int) (i+1));
   names[i] = strdup (name);
 }
diff --git a/m4/pthread_mutex_timedlock.m4 b/m4/pthread_mutex_timedlock.m4
index 46b59d793c..9b175d5474 100644
--- a/m4/pthread_mutex_timedlock.m4
+++ b/m4/pthread_mutex_timedlock.m4
@@ -1,5 +1,5 @@
 # pthread_mutex_timedlock.m4
-# serial 5
+# serial 6
 dnl Copyright (C) 2019-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -28,7 +28,8 @@ AC_DEFUN([gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK]
  #include 
]],
[[pthread_mutex_t lock;
- return pthread_mutex_timedlock (&lock, (struct timespec *) 0);
+ struct timespec ts = { 0 };
+ return pthread_mutex_timedlock (&lock, &ts);
]])
 ],
 [gl_cv_func_pthread_mutex_timedlock_in_LIBMULTITHREAD=yes],






doc: Update for OpenBSD 7.5

2024-08-07 Thread Bruno Haible
This patch updates the doc regarding OpenBSD 7.5.
This version now has
  - the header file ,
  - the functions mbrtoc16, mbrtoc32, c16rtomb, c32rtomb, waitid.


2024-08-07  Bruno Haible  

doc: Update for OpenBSD 7.5.
* doc/posix-headers/*.texi: Update.
* doc/glibc-headers/*.texi: Likewise.
* doc/posix-functions/*.texi: Likewise.
* doc/pastposix-functions/*.texi: Likewise.
* doc/glibc-functions/*.texi: Likewise.

https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commitdiff;h=496a7aee40885a2e7bbb8863f525738a0d6095cc






Re: math: Fix INFINITY and NAN on FreeBSD and AIX

2024-08-07 Thread Bruno Haible
And on mingw 5.0, I see this test failure:


FAIL: test-math
===

../../gltests/test-math.c:103: assertion 'sizeof (INFINITY) == sizeof (float)' 
failed
FAIL test-math.exe (exit status: 3)

And once this is fixed, likewise for NAN.


This patch fixes it.


2024-08-07  Bruno Haible  

math: Fix INFINITY and NAN on mingw.
* doc/posix-headers/math.texi: Mention this mingw bug.
* lib/math.in.h (INFINITY, NAN): Replace also on mingw.

diff --git a/doc/posix-headers/math.texi b/doc/posix-headers/math.texi
index 6f07b1e58c..fb72b94a08 100644
--- a/doc/posix-headers/math.texi
+++ b/doc/posix-headers/math.texi
@@ -55,7 +55,7 @@
 @item
 @code{INFINITY} and @code{NAN} are of type @code{double} instead of 
@code{float}
 on some platforms:
-FreeBSD 7.1.
+FreeBSD 7.1, mingw 5.0.
 
 @item
 The macros @code{NAN}, @code{HUGE_VALL}, and @code{INFINITY} are not
diff --git a/lib/math.in.h b/lib/math.in.h
index 7b1302d883..2fcba31c76 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -161,7 +161,7 @@ static void (*_gl_math_fix_itold) (long double *, int) = 
_Qp_itoq;
 
 
 /* Ensure that INFINITY is a constant expression, of type 'float'.  */
-#if !defined INFINITY || (defined __FreeBSD__ && __FreeBSD__ < 8) || defined 
_AIX
+#if !defined INFINITY || (defined __FreeBSD__ && __FreeBSD__ < 8) || defined 
_AIX || defined __MINGW32__
 # undef INFINITY
 # if defined __GNUC__ || defined __clang__
 #  define INFINITY (__builtin_inff ())
@@ -176,7 +176,7 @@ static void (*_gl_math_fix_itold) (long double *, int) = 
_Qp_itoq;
it on platforms like Solaris 10, where NAN is present but defined
as a function pointer rather than a floating point constant.
Also ensure that it is a constant expression, of type 'float'.  */
-#if !defined NAN || @REPLACE_NAN@ || (defined __FreeBSD__ && __FreeBSD__ < 8) 
|| defined _AIX
+#if !defined NAN || @REPLACE_NAN@ || (defined __FreeBSD__ && __FreeBSD__ < 8) 
|| defined _AIX || defined __MINGW32__
 # if !GNULIB_defined_NAN
 #  undef NAN
   /* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler