From: Bruno Haible Date: Wed, 23 Jul 2025 07:12:55 +0000 (+0200) Subject: thrd: Avoid conversion between different function pointer types. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a35c02d2a0132bdb7a1b49fa3effa678be7831;p=thirdparty%2Fgnulib.git thrd: Avoid conversion between different function pointer types. Reported by Collin Funk in . * 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. --- diff --git a/ChangeLog b/ChangeLog index 15c7c1a941..8a226b449a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2025-07-23 Bruno Haible + + thrd: Avoid conversion between different function pointer types. + Reported by Collin Funk in + . + * 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 Paul Eggert diff --git a/lib/thrd.c b/lib/thrd.c index ea7f0f5397..b8ddb3fd52 100644 --- a/lib/thrd.c +++ b/lib/thrd.c @@ -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 } } diff --git a/m4/thrd.m4 b/m4/thrd.m4 index 18298dadb7..a79e186ed2 100644 --- a/m4/thrd.m4 +++ b/m4/thrd.m4 @@ -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"