]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
thrd: Avoid conversion between different function pointer types.
authorBruno Haible <bruno@clisp.org>
Wed, 23 Jul 2025 07:12:55 +0000 (09:12 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 23 Jul 2025 07:12:55 +0000 (09:12 +0200)
Reported by Collin Funk in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-07/msg00170.html>.

* m4/thrd.m4 (gl_FUNC_THRD_JOIN): Define BROKEN_THRD_START_T or
BROKEN_THRD_JOIN. Don't define BROKEN_THRD_START_T_OR_JOIN.
* lib/thrd.c (thrd_main_func): Define with the right return type,
depending on BROKEN_THRD_START_T.

ChangeLog
lib/thrd.c
m4/thrd.m4

index 15c7c1a94106be704e09bdc1f768401c35b67961..8a226b449a9ab3f3aafc83213ffb17488ace27f5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2025-07-23  Bruno Haible  <bruno@clisp.org>
+
+       thrd: Avoid conversion between different function pointer types.
+       Reported by Collin Funk in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2025-07/msg00170.html>.
+       * m4/thrd.m4 (gl_FUNC_THRD_JOIN): Define BROKEN_THRD_START_T or
+       BROKEN_THRD_JOIN. Don't define BROKEN_THRD_START_T_OR_JOIN.
+       * lib/thrd.c (thrd_main_func): Define with the right return type,
+       depending on BROKEN_THRD_START_T.
+
 2025-07-22  Collin Funk  <collin.funk1@gmail.com>
            Paul Eggert  <eggert@cs.ucla.edu>
 
index ea7f0f53979675127ec320a1ff41aa73c2ca43c0..b8ddb3fd52de8e40a8fa55a4f7626ef82dbff447 100644 (file)
@@ -26,7 +26,7 @@
 #if HAVE_THREADS_H
 /* Provide workarounds.  */
 
-# if BROKEN_THRD_START_T_OR_JOIN
+# if BROKEN_THRD_START_T || BROKEN_THRD_JOIN
 
 #  undef thrd_t
 
@@ -70,7 +70,12 @@ typedef union
         }
         main_arg_t;
 
-static void *
+static
+#  if BROKEN_THRD_START_T
+void *
+#  else /* BROKEN_THRD_JOIN */
+int
+#  endif
 thrd_main_func (void *pmarg)
 {
   /* Unpack the object that combines mainfunc and arg.  */
@@ -91,7 +96,11 @@ thrd_main_func (void *pmarg)
         /* Clean up the thread, like thrd_join would do.  */
         free (&main_arg->t);
       }
+#  if BROKEN_THRD_START_T
     return NULL;
+#  else /* BROKEN_THRD_JOIN */
+    return 0;
+#  endif
   }
 }
 
index 18298dadb7b6c3e7fbeb69c4a3e995552c6d6ed5..a79e186ed2ea84c84966a9cf0e70f048ae233ecd 100644 (file)
@@ -1,5 +1,5 @@
 # thrd.m4
-# serial 6
+# serial 7
 dnl Copyright (C) 2019-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -39,8 +39,13 @@ AC_DEFUN([gl_FUNC_THRD_JOIN],
       REPLACE_THRD_EQUAL=1
       REPLACE_THRD_EXIT=1
       REPLACE_THRD_JOIN=1
-      AC_DEFINE([BROKEN_THRD_START_T_OR_JOIN], [1],
-        [Define if the thrd_start_t type is not as described in ISO C 11 or if thrd_join discards the thread's exit code.])
+      if test $BROKEN_THRD_START_T = 1; then
+        AC_DEFINE([BROKEN_THRD_START_T], [1],
+          [Define if the thrd_start_t type is not as described in ISO C 11.])
+      else
+        AC_DEFINE([BROKEN_THRD_JOIN], [1],
+          [Define if thrd_start_t is OK but thrd_join discards the thread's exit code.])
+      fi
       dnl The thrd_exit replacement relies on pthread_exit, which on AIX is in
       dnl libpthread.
       LIBSTDTHREAD="$LIBSTDTHREAD $LIBPTHREAD"