From cf1f6e74bf5fcf6c1491f37d27abc63567354224 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 30 May 2024 10:55:40 +0200 Subject: [PATCH] call_once: Work around Cygwin 3.5.3 bug. * m4/call_once.m4 (gl_FUNC_CALL_ONCE): Require AC_CANONICAL_HOST. On Cygwin, set REPLACE_CALL_ONCE to 1. * lib/call_once.c (call_once): On Cygwin, use a cast, to avoid a compiler warning. * modules/call_once (Depends-on): Add pthread-once. * doc/posix-functions/call_once.texi: Mention the Cygwin bug. --- ChangeLog | 10 ++++++++++ doc/posix-functions/call_once.texi | 3 +++ lib/call_once.c | 8 +++++++- m4/call_once.m4 | 17 ++++++++++++++++- modules/call_once | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20177fa38c..b41dfddad5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-05-31 Bruno Haible + + call_once: Work around Cygwin 3.5.3 bug. + * m4/call_once.m4 (gl_FUNC_CALL_ONCE): Require AC_CANONICAL_HOST. + On Cygwin, set REPLACE_CALL_ONCE to 1. + * lib/call_once.c (call_once): On Cygwin, use a cast, to avoid a + compiler warning. + * modules/call_once (Depends-on): Add pthread-once. + * doc/posix-functions/call_once.texi: Mention the Cygwin bug. + 2024-05-31 Bruno Haible lock: Work around Cygwin 3.5.3 bug. diff --git a/doc/posix-functions/call_once.texi b/doc/posix-functions/call_once.texi index 5f01303062..5f1aceaf84 100644 --- a/doc/posix-functions/call_once.texi +++ b/doc/posix-functions/call_once.texi @@ -22,6 +22,9 @@ glibc 2.27, macOS 11.1, FreeBSD 9.3, NetBSD 8.0, OpenBSD 6.7, Minix 3.1.8, AIX 7 Portability problems not fixed by Gnulib: @itemize @item +This function makes applications hang forever on some platforms: +Cygwin 3.5.3. +@item This function does not work on some platforms: @c https://dev.haiku-os.org/ticket/18348 Haiku. diff --git a/lib/call_once.c b/lib/call_once.c index d11d9506fb..54a864deda 100644 --- a/lib/call_once.c +++ b/lib/call_once.c @@ -1,5 +1,5 @@ /* ISO C 11 once-only initialization. - Copyright (C) 2005-2023 Free Software Foundation, Inc. + Copyright (C) 2005-2024 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -53,7 +53,13 @@ call_once (once_flag *flagp, void (*func) (void)) void call_once (once_flag *flagp, void (*func) (void)) { +# if defined __CYGWIN__ + /* Verify that once_flag and pthread_once_t are of the same size. */ + struct _ { int v [sizeof (once_flag) == sizeof (pthread_once_t) ? 1 : -1]; }; + pthread_once ((pthread_once_t *) flagp, func); +# else pthread_once (flagp, func); +# endif } #endif diff --git a/m4/call_once.m4 b/m4/call_once.m4 index 160e8f95cf..8619244d79 100644 --- a/m4/call_once.m4 +++ b/m4/call_once.m4 @@ -1,4 +1,4 @@ -# call_once.m4 serial 1 +# call_once.m4 serial 2 dnl Copyright (C) 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, @@ -7,8 +7,23 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_CALL_ONCE], [ AC_REQUIRE([gl_THREADS_H]) + AC_REQUIRE([AC_CANONICAL_HOST]) gl_CHECK_FUNCS_ANDROID([call_once], [[#include ]]) case "$gl_cv_onwards_func_call_once" in + yes) + dnl Work around Cygwin 3.5.3 bug. + AC_CACHE_CHECK([whether call_once works], + [gl_cv_func_call_once_works], + [case "$host_os" in + cygwin*) gl_cv_func_call_once_works="guessing no" ;; + *) gl_cv_func_call_once_works="yes" ;; + esac + ]) + case "$gl_cv_func_call_once_works" in + *yes) ;; + *) REPLACE_CALL_ONCE=1 ;; + esac + ;; future*) REPLACE_CALL_ONCE=1 ;; diff --git a/modules/call_once b/modules/call_once index c48847a54b..1fa4d47744 100644 --- a/modules/call_once +++ b/modules/call_once @@ -7,6 +7,7 @@ m4/call_once.m4 Depends-on: threads-h +pthread-once windows-once configure.ac: -- 2.39.5