]> Savannah Git Hosting - gnulib.git/commitdiff
call_once: Work around Cygwin 3.5.3 bug.
authorBruno Haible <bruno@clisp.org>
Thu, 30 May 2024 08:55:40 +0000 (10:55 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 31 May 2024 22:09:59 +0000 (00:09 +0200)
* 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
doc/posix-functions/call_once.texi
lib/call_once.c
m4/call_once.m4
modules/call_once

index 20177fa38c4612b8cd9d0408d6ffad203729c676..b41dfddad5cb62fa727a46a6938d7935d5c420ef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-05-31  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        lock: Work around Cygwin 3.5.3 bug.
index 5f01303062eae497dda0ae9b968a5c9329c81aad..5f1aceaf84b6d8988cd7f2b43f82e9d832aa9079 100644 (file)
@@ -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.
index d11d9506fb8f0569d7eac329d74051afd0cad2e8..54a864deda5fcdbca58a6683458071df84d66d51 100644 (file)
@@ -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
index 160e8f95cf8033d61bde22840910e5590ebe93d7..8619244d7915a5ba1d0907ff35a8c493c0a5b511 100644 (file)
@@ -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 <threads.h>]])
   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
       ;;
index c48847a54b4f0fcb4631baf3bb90a896d7a9d7ea..1fa4d477449b4b0124dbeefcdf95df2ace9507a2 100644 (file)
@@ -7,6 +7,7 @@ m4/call_once.m4
 
 Depends-on:
 threads-h
+pthread-once
 windows-once
 
 configure.ac: