In a testdir on Android, I see compilation errors like this one: clang++ -ferror-limit=0 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/data/data/com.termux/files/home/local/include -Wall -Wno-error -g -O2 -c -o test-threads-c++.o ../../gltests/test-threads-c++.cc
In file included from ../../gltests/test-threads-c++.cc:22: In file included from ../gllib/threads.h:28: In file included from /data/data/com.termux/files/usr/include/threads.h:229: In file included from /data/data/com.termux/files/usr/include/android/legacy_threads_inlines.h:36: In file included from /data/data/com.termux/files/usr/include/bits/threads_inlines.h:31: ../gllib/threads.h:699:19: error: no member named 'thrd_create' in the global namespace; did you mean 'pthread_create'? _GL_CXXALIAS_SYS (thrd_create, int, (thrd_t *, thrd_start_t, void *)); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The first patch fixes them. The second patch is merely a portability improvement. 2023-01-09 Bruno Haible <br...@clisp.org> threads-h: Improve portability. * lib/threads.in.h: Use INCLUDE_NEXT_AS_FIRST_DIRECTIVE when possible. * modules/threads-h (Makefile.am): Substitute INCLUDE_NEXT_AS_FIRST_DIRECTIVE and NEXT_AS_FIRST_DIRECTIVE_THREADS_H. 2023-01-09 Bruno Haible <br...@clisp.org> threads-h: Fix compilation errors in C++ mode on Android. * lib/threads.in.h (_GL_ALREADY_INCLUDING_THREADS_H): New macro.
>From ede58b7442f9ff1e63cb5e6c391a039d8f00dc79 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Mon, 9 Jan 2023 19:12:49 +0100 Subject: [PATCH 1/2] threads-h: Fix compilation errors in C++ mode on Android. * lib/threads.in.h (_GL_ALREADY_INCLUDING_THREADS_H): New macro. --- ChangeLog | 5 +++++ lib/threads.in.h | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7554f5ba03..84226bb5e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-01-09 Bruno Haible <br...@clisp.org> + + threads-h: Fix compilation errors in C++ mode on Android. + * lib/threads.in.h (_GL_ALREADY_INCLUDING_THREADS_H): New macro. + 2023-01-09 Bruno Haible <br...@clisp.org> aligned-malloc: Don't disturb the module aligned_alloc. diff --git a/lib/threads.in.h b/lib/threads.in.h index b1e213fd2c..5786101d82 100644 --- a/lib/threads.in.h +++ b/lib/threads.in.h @@ -20,13 +20,30 @@ #endif @PRAGMA_COLUMNS@ +#if defined _GL_ALREADY_INCLUDING_THREADS_H +/* Special invocation convention: + - On Android we have a sequence of nested includes + <threads.h> -> <android/legacy_threads_inlines.h> + -> <bits/threads_inlines.h> -> "threads.h" + In this situation, the functions are not yet declared, therefore we cannot + provide the C++ aliases. */ + +#@INCLUDE_NEXT@ @NEXT_THREADS_H@ + +#else +/* Normal invocation convention. */ + #ifndef _@GUARD_PREFIX@_THREADS_H +#define _GL_ALREADY_INCLUDING_THREADS_H + /* The include_next requires a split double-inclusion guard. */ #if @HAVE_THREADS_H@ # @INCLUDE_NEXT@ @NEXT_THREADS_H@ #endif +#undef _GL_ALREADY_INCLUDING_THREADS_H + #ifndef _@GUARD_PREFIX@_THREADS_H #define _@GUARD_PREFIX@_THREADS_H @@ -662,3 +679,4 @@ _GL_WARN_ON_USE (tss_delete, "tss_delete is unportable - " #endif /* _@GUARD_PREFIX@_THREADS_H */ #endif /* _@GUARD_PREFIX@_THREADS_H */ +#endif -- 2.34.1
>From 7937757f4d37856e8d65f3da5f301c3c28cef532 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Mon, 9 Jan 2023 21:31:52 +0100 Subject: [PATCH 2/2] threads-h: Improve portability. * lib/threads.in.h: Use INCLUDE_NEXT_AS_FIRST_DIRECTIVE when possible. * modules/threads-h (Makefile.am): Substitute INCLUDE_NEXT_AS_FIRST_DIRECTIVE and NEXT_AS_FIRST_DIRECTIVE_THREADS_H. --- ChangeLog | 7 +++++++ lib/threads.in.h | 4 ++-- modules/threads-h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84226bb5e7..92c89d730b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-01-09 Bruno Haible <br...@clisp.org> + + threads-h: Improve portability. + * lib/threads.in.h: Use INCLUDE_NEXT_AS_FIRST_DIRECTIVE when possible. + * modules/threads-h (Makefile.am): Substitute + INCLUDE_NEXT_AS_FIRST_DIRECTIVE and NEXT_AS_FIRST_DIRECTIVE_THREADS_H. + 2023-01-09 Bruno Haible <br...@clisp.org> threads-h: Fix compilation errors in C++ mode on Android. diff --git a/lib/threads.in.h b/lib/threads.in.h index 5786101d82..e34c39de3f 100644 --- a/lib/threads.in.h +++ b/lib/threads.in.h @@ -28,7 +28,7 @@ In this situation, the functions are not yet declared, therefore we cannot provide the C++ aliases. */ -#@INCLUDE_NEXT@ @NEXT_THREADS_H@ +#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_THREADS_H@ #else /* Normal invocation convention. */ @@ -39,7 +39,7 @@ /* The include_next requires a split double-inclusion guard. */ #if @HAVE_THREADS_H@ -# @INCLUDE_NEXT@ @NEXT_THREADS_H@ +# @INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_THREADS_H@ #endif #undef _GL_ALREADY_INCLUDING_THREADS_H diff --git a/modules/threads-h b/modules/threads-h index 1cde2afc9f..e35a5e265b 100644 --- a/modules/threads-h +++ b/modules/threads-h @@ -43,10 +43,12 @@ threads.h: threads.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(_NORETURN_H @NMD@ $(AM_V_GEN)$(MKDIR_P) '%reldir%' $(gl_V_at)$(SED_HEADER_STDOUT) \ -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \ + -e 's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \ -e 's|@''HAVE_THREADS_H''@|$(HAVE_THREADS_H)|g' \ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_AS_FIRST_DIRECTIVE_THREADS_H''@|$(NEXT_AS_FIRST_DIRECTIVE_THREADS_H)|g' \ -e 's|@''NEXT_THREADS_H''@|$(NEXT_THREADS_H)|g' \ -e 's/@''GNULIB_CND''@/$(GNULIB_CND)/g' \ -e 's/@''GNULIB_MTX''@/$(GNULIB_MTX)/g' \ -- 2.34.1