bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* malloc-h: Fix compilation error in C++ mode on Android
@ 2023-01-09  8:56 Bruno Haible
  2023-01-09 20:22 ` Bruno Haible
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2023-01-09  8:56 UTC (permalink / raw)
  To: bug-gnulib

Building a testdir on Android, I get this compilation error:

clang++ -DNO_INLINE_GETPASS=1 -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-malloc-h-c++.o ../../gltests/test-malloc-h-c++.cc
In file included from ../../gltests/test-malloc-h-c++.cc:22:
In file included from ../gllib/malloc.h:27:
In file included from /data/data/com.termux/files/usr/include/malloc.h:30:
In file included from ../gllib/stdio.h:71:
In file included from ../gllib/sys/stat.h:44:
In file included from ../gllib/time.h:47:
In file included from /data/data/com.termux/files/usr/include/time.h:33:
In file included from ../gllib/sys/time.h:39:
In file included from /data/data/com.termux/files/usr/include/sys/time.h:37:
In file included from ../gllib/sys/select.h:102:
In file included from /data/data/com.termux/files/usr/include/sys/select.h:40:
In file included from ../gllib/signal.h:75:
In file included from ../gllib/pthread.h:56:
In file included from ../gllib/stdlib.h:28:
In file included from /data/data/com.termux/files/usr/include/c++/v1/stdlib.h:97:
In file included from /data/data/com.termux/files/usr/include/stdlib.h:34:
../gllib/malloc.h:542:19: error: no member named 'memalign' in the global namespace
_GL_CXXALIAS_SYS (memalign, void *, (size_t alignment, size_t size));
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gllib/strings.h:258:20: note: expanded from macro '_GL_CXXALIAS_SYS'
          return ::func;                                      \
                 ~~^

The function memalign is declared where it should. The problem is merely that
a sequence of nested includes causes the declaration to come too late. This
patch fixes it.


2023-01-09  Bruno Haible  <bruno@clisp.org>

	malloc-h: Fix compilation error in C++ mode on Android.
	* lib/malloc.in.h (_GL_ALREADY_INCLUDING_MALLOC_H): New macro.

diff --git a/lib/malloc.in.h b/lib/malloc.in.h
index de661f0f4b..c39d6e218f 100644
--- a/lib/malloc.in.h
+++ b/lib/malloc.in.h
@@ -14,18 +14,35 @@
    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
-#ifndef _@GUARD_PREFIX@_MALLOC_H
-
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
 #endif
 @PRAGMA_COLUMNS@
 
+#if defined _GL_ALREADY_INCLUDING_MALLOC_H
+/* Special invocation convention:
+   - On Android we have a sequence of nested includes
+       <malloc.h> -> <stdio.h> -> <sys/stat.h> -> <time.h> -> <sys/time.h> ->
+       <sys/select.h> -> <signal.h> -> <pthread.h> -> <stdlib.h> -> "malloc.h"
+     In this situation, in C++ mode, the declaration of memalign might be used
+     before it actually occurs.  */
+
+#@INCLUDE_NEXT@ @NEXT_MALLOC_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef _@GUARD_PREFIX@_MALLOC_H
+
+#define _GL_ALREADY_INCLUDING_MALLOC_H
+
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_MALLOC_H@
 # @INCLUDE_NEXT@ @NEXT_MALLOC_H@
 #endif
 
+#undef _GL_ALREADY_INCLUDING_MALLOC_H
+
 #ifndef _@GUARD_PREFIX@_MALLOC_H
 #define _@GUARD_PREFIX@_MALLOC_H
 
@@ -83,3 +100,4 @@ _GL_WARN_ON_USE (memalign, "memalign is not portable - "
 
 #endif /* _@GUARD_PREFIX@_MALLOC_H */
 #endif /* _@GUARD_PREFIX@_MALLOC_H */
+#endif





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: malloc-h: Fix compilation error in C++ mode on Android
  2023-01-09  8:56 malloc-h: Fix compilation error in C++ mode on Android Bruno Haible
@ 2023-01-09 20:22 ` Bruno Haible
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno Haible @ 2023-01-09 20:22 UTC (permalink / raw)
  To: bug-gnulib

I wrote:
> +
> +#@INCLUDE_NEXT@ @NEXT_MALLOC_H@
> +
> +#else
> +/* Normal invocation convention.  */
> +
> +#ifndef _@GUARD_PREFIX@_MALLOC_H
> +
> +#define _GL_ALREADY_INCLUDING_MALLOC_H
> +
>  /* The include_next requires a split double-inclusion guard.  */
>  #if @HAVE_MALLOC_H@
>  # @INCLUDE_NEXT@ @NEXT_MALLOC_H@

For better portability, these @INCLUDE_NEXT@ @NEXT_MALLOC_H@ lines should
be written differently:


2023-01-09  Bruno Haible  <bruno@clisp.org>

	malloc-h: Improve portability.
	* lib/malloc.in.h: Use INCLUDE_NEXT_AS_FIRST_DIRECTIVE when possible.
	* modules/malloc-h (Makefile.am): Substitute
	INCLUDE_NEXT_AS_FIRST_DIRECTIVE and NEXT_AS_FIRST_DIRECTIVE_MALLOC_H.

diff --git a/lib/malloc.in.h b/lib/malloc.in.h
index 52319a1fc4..4921f6e994 100644
--- a/lib/malloc.in.h
+++ b/lib/malloc.in.h
@@ -27,7 +27,7 @@
      In this situation, in C++ mode, the declaration of memalign might be used
      before it actually occurs.  */
 
-#@INCLUDE_NEXT@ @NEXT_MALLOC_H@
+#@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MALLOC_H@
 
 #else
 /* Normal invocation convention.  */
@@ -38,7 +38,7 @@
 
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_MALLOC_H@
-# @INCLUDE_NEXT@ @NEXT_MALLOC_H@
+# @INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_MALLOC_H@
 #endif
 
 #undef _GL_ALREADY_INCLUDING_MALLOC_H
diff --git a/modules/malloc-h b/modules/malloc-h
index 9717c90b67..7c241d2943 100644
--- a/modules/malloc-h
+++ b/modules/malloc-h
@@ -26,10 +26,12 @@ malloc.h: malloc.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_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_MALLOC_H''@|$(HAVE_MALLOC_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_MALLOC_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MALLOC_H)|g' \
 	      -e 's|@''NEXT_MALLOC_H''@|$(NEXT_MALLOC_H)|g' \
 	      -e 's/@''GNULIB_FREE_POSIX''@/$(GNULIB_FREE_POSIX)/g' \
 	      -e 's/@''GNULIB_MEMALIGN''@/$(GNULIB_MEMALIGN)/g' \





^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-09 20:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09  8:56 malloc-h: Fix compilation error in C++ mode on Android Bruno Haible
2023-01-09 20:22 ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).